Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | Related Pages | Examples

drivers.h

00001 /*
00002   $Id: drivers.h,v 1.5 2004/12/16 07:45:14 majo Exp $
00003 
00004   $Log: drivers.h,v $
00005   Revision 1.5  2004/12/16 07:45:14  majo
00006   fixed bug with uninitialized members with FGLinuxDriver
00007 
00008   Revision 1.4  2004/08/25 21:16:10  majo
00009   priebezne zmeny
00010 
00011   Revision 1.3  2004/02/26 21:41:28  majo
00012   class FGInternalState
00013   char* -> const char*
00014   int ink = -1  -> unsigned ink = UNDEFINED_COLOR
00015 
00016   Revision 1.2  2004/02/23 20:08:01  majo
00017   all classes are with prefix FG* on now
00018   polygon functions uses FGPointArray from now
00019   class GuiEvent is renamed to FGEvent
00020   some by parameters overloaded methods was removed (class FGWindow)
00021   many other small changes
00022 
00023   Revision 1.1.1.1  2004/01/22 16:25:08  majo
00024   initial release
00025 
00026 */
00027 
00028 #define MODELIST_SIZE       256
00029 #define FG_LINEAR           1
00030 #define CAPABLE_LINEAR      16
00031 
00032 #ifdef FG_NAMESPACE
00033 namespace fgl {
00034 #endif
00035 
00039 class FGScreen : public FGDrawBuffer
00040 {
00041     public:
00042         FGScreen() : FGDrawBuffer(0, 0, FGFRAMEBUFFER)
00043         {
00044             assert(image==0);
00045         }
00046         void Resize(int xx, int yy)
00047         {
00048             wwrk = w = xx;
00049             hwrk = h = yy;
00050             X_width = w;
00051             Y_width = h;
00052             fgl::set_clip_rect(w, h, 0, 0);
00053             set_font(FONT0816);
00054             set_colors(0, CWHITE);
00055             set_ppop(_GSET);
00056             image = videobase;
00057         }
00058 };
00059 
00060 union gii_event;
00064 class FGDriver
00065 {
00066         friend class FGDGADriver;
00067         friend void _giiEvQueueAdd(gii_event *ev);
00068         friend class FGApp;
00069         friend int graph_set_mode(int mode);
00070 
00071         static int sort(const void *a, const void *b)
00072         {
00073             int val1 = ((vmode *)a)->w;
00074             int val2 = ((vmode *)b)->w;
00075             int rc   = val2 - val1;
00076             if (rc==0)
00077                 rc = ((vmode *)b)->h - ((vmode *)a)->h;
00078             if (rc==0)
00079                 rc = ((vmode *)b)->refresh - ((vmode *)a)->refresh;
00080             return rc;
00081         }
00082         FGDrawBuffer *back_store;
00083     protected:
00087         struct vmode
00088         {
00089             short w,h,mode;
00090             char flag, refresh;
00091         };
00092 
00093         char    *name, *subname;
00094         int     accel_hint;     // suggested accel type
00095         int     total_modes;
00096         bool    ismouse, iskeyboard, isgraph,
00097                 islinear, mapped, verbose, ps2_mouse;
00098         int     w,h,                // logical size of screen
00099                 virt_w, virt_h,     // real size of screen
00100                 x_offset, y_offset; // offset of top-left corner
00101         int     req_w, req_h,       // requested size
00102                 pitch,              // in bytes !!!
00103                 mode_num,           // index to table mode !!!
00104                 bpp;                // bytes per pixel
00105         unsigned long synch;        // monitor vertical freq.
00106         int     current_buffer,     // current buffer index
00107                 bufnum;             // num. of buffers, 0 if disabled
00108         void    *linear_base,       // aperture addr.
00109                 *mmio_base;
00110         unsigned long linear_size,  // aperture size
00111                 mmio_size;
00112         unsigned char *mmio;        // virtualna adresa pre MMIO
00113         int     driver;
00114         FGPixel *videobase;         // virtualna adresa pre VRAM
00115         FGPixel *buffer[4];         // max quad-buffers
00116         vmode   modelist[MODELIST_SIZE];
00117         char    *accel_name;
00118         unsigned    ops;    // 0 fillrect
00119         int     root;
00120         int     msefd;
00121         int     oldx, oldy;
00122         int     mousex, mousey, but;
00123         char    *mouse_string;
00124         static bool is_ctrl, is_alt, is_shift;
00125 
00126         void vram_line(int x, int y, int w, int h, FGPixel ink, unsigned ppop);
00127         virtual int find(int& ww, int& hh);
00128         int postinit();
00129         int detect(void);
00130         int preinit(void);
00131         virtual int text_mode(void)
00132         {
00133             isgraph = 0;
00134             return true;
00135         }
00136         virtual int set_mouse(void)
00137         {
00138             if (verbose) printf("DRIVER %s: set_mouse() called\n", name);
00139             ismouse = 1;
00140             return true;
00141         }
00142         virtual void reset_mouse(void)
00143         {
00144             if (verbose) printf("DRIVER %s: reset_mouse() called\n", name);
00145             ismouse = 0;
00146         }
00147         virtual int set_keyboard(void)
00148         {
00149             if (verbose) printf("DRIVER %s: set_keyboard() called\n", name);
00150             iskeyboard = 1;
00151             return true;
00152         }
00153         virtual void reset_keyboard(void)
00154         {
00155             if (verbose) printf("DRIVER %s: reset_keyboard() called\n", name);
00156             iskeyboard = 0;
00157         }
00158         virtual void get_all_modes(vmode *) // default
00159         {
00160         }
00161         int build_modelist(void)
00162         {
00163             total_modes = 0;
00164             get_all_modes(modelist);
00165             if ( total_modes == 0 )
00166             {
00167                 printf("No video modes available for %d BPP\n", FASTGL_BPP);
00168                 return 0;
00169             }
00170             // sort modes via size from bigger to smaller
00171             if (total_modes>1) qsort(modelist, total_modes, sizeof(vmode), sort);
00172             if (verbose)
00173             {
00174                 printf("\nVideo modes:\n");
00175                 for(int i=0; i<total_modes; i++)
00176                 {
00177                     if (modelist[i].w) printf("\tmode \"%dx%d-%d@%d\" available as %s\n", modelist[i].w, modelist[i].h, bpp*8, modelist[i].refresh ,modelist[i].flag&FG_LINEAR?"linear":"banked");
00178                 }
00179             }
00180             return total_modes;
00181         }
00182         virtual int available(void)
00183         {
00184             if (verbose) printf("DRIVER %s: available() called\n", name);
00185             return false;
00186         }
00187         virtual int link(void)
00188         {
00189             if (verbose) printf("DRIVER %s: link() called\n", name);
00190             return false;
00191         }
00192     public:
00193         int     offset;
00194         FGDriver(char *nm);
00195         virtual ~FGDriver()
00196         {
00197             if (verbose) printf("DRIVER %s: unload() called\n", name);
00198         }
00199         int launch(int ww, int hh, int syn, int verb);
00200         void message(void);
00201         virtual int get_event(int& , int& , int& , int& , int& )
00202         {
00203             return false;
00204         }
00205         virtual int set_mode(int w, int h)
00206         {
00207             if (isgraph)
00208             {
00209                 back_store = new FGDrawBuffer(w, h);
00210                 get_block(0,0, w, h, back_store->GetArray());
00211             }
00212             return true;
00213         }
00214         virtual void change_mouse(void)
00215         {
00216             if (verbose) printf("DRIVER %s: change_mouse() called\n", name);
00217         }
00218         virtual void shutdown(void)
00219         {
00220             if (ismouse) reset_mouse();
00221             if (iskeyboard) reset_keyboard();
00222             text_mode();
00223         }
00224         void    SetVerbose(int v) { verbose = !!v; }
00225         void    SetFrequency(int v) { synch = v; }
00226 
00227         virtual void SetCaption(char *)
00228         {
00229         }
00230 
00231         virtual int EnableBuffering(int mode);
00232         virtual void DisableBuffering(void)
00233         {
00234             set_page(current_buffer=0);
00235             fgl::videobase = videobase = buffer[0];
00236             offset = 0;
00237         }
00238 
00239         virtual int set_page(int)
00240         {
00241             return 0;
00242         }
00243         virtual int Flip(void);
00244         virtual int set_virtual_size(int , int )
00245         {
00246             return 0;             // default is disabled
00247         }
00248         virtual int set_virtual_pos(int , int )
00249         {
00250             return 0;             // default is disabled
00251         }
00252         int GetBuffersNum(void)
00253         {
00254             return bufnum;
00255         }
00256 #ifdef INDEX_COLORS
00257         void ReservedColors(void);
00258 #endif
00259         int GetW(void) const { return w; }
00260         int GetH(void) const { return h; }
00261         virtual void UpdateRect(int x, int y, int xm, int ym, int w, int h) { }
00262         int GetPriv(void) const { return root; }
00263 
00264         static void SetShiftState(bool pressed) { is_shift = pressed; }
00265         static void SetControlState(bool pressed) { is_ctrl = pressed; }
00266         static void SetAltState(bool pressed) { is_alt = pressed; }
00267 };
00268 
00269 #ifdef FG_NAMESPACE
00270 }
00271 #endif
00272 

Generated on Wed Feb 9 11:31:35 2005 for OpenGUI by  doxygen 1.4.0