[AD] Another patch for DGA2 driver

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


This one adds triple buffering support. I also cleaned up the code a bit, and I
modified readme.uni to mention the DGA2 driver support.
Thanks for applying!

-- 
Angelo Mottola
a.mottola@xxxxxxxxxx
--- /usr/src/allegro_CVS/allegro.current/src/x/xdga2.c	Sun Oct  8 01:41:52 2000
+++ xdga2.c	Sun Oct  8 19:17:46 2000
@@ -26,10 +26,7 @@
 #include <X11/extensions/xf86dga.h>
 
 
-#define RESYNC()                                                           \
-XDGASync(_xwin.display, _xwin.screen);
-#define GET_SHIFT(col_mask)                                                \
-for (mask = (col_mask), shift = 0; (mask & 1) == 0; mask >>= 1, shift++);
+#define RESYNC()     XDGASync(_xwin.display, _xwin.screen);
 
 
 extern int _xwin_keycode_pressed[];
@@ -224,7 +221,7 @@
 static BITMAP *_xdga2_private_gfxdrv_init_drv(GFX_DRIVER *drv, int w, int h, int vw, int vh, int depth, int accel)
 {
    int dga_error_base, dga_major_version, dga_minor_version;
-   int mode, mask, shift;
+   int mode, mask, red_shift = 0, green_shift = 0, blue_shift = 0;
    long input_mask;
    char tmp[80];
    BITMAP *bmp;
@@ -318,42 +315,38 @@
    XDGAInstallColormap(_xwin.display, _xwin.screen, _dga_cmap);
 
    /* Sets up direct color shifts */
+   if (depth != 8) {
+      for (mask = dga_device->mode.redMask, red_shift = 0; (mask & 1) == 0;
+         mask >>= 1, red_shift++);
+      for (mask = dga_device->mode.greenMask, green_shift = 0; (mask & 1) == 0;
+         mask >>= 1, green_shift++);
+      for (mask = dga_device->mode.blueMask, blue_shift = 0; (mask & 1) == 0;
+         mask >>= 1, blue_shift++);
+   }
    switch (depth) {
 
       case 15:
-         GET_SHIFT(dga_device->mode.redMask);
-         _rgb_r_shift_15 = shift;
-         GET_SHIFT(dga_device->mode.greenMask);
-         _rgb_g_shift_15 = shift;
-         GET_SHIFT(dga_device->mode.blueMask);
-         _rgb_b_shift_15 = shift;
+         _rgb_r_shift_15 = red_shift;
+         _rgb_g_shift_15 = green_shift;
+         _rgb_b_shift_15 = blue_shift;
          break;
 
       case 16:
-         GET_SHIFT(dga_device->mode.redMask);
-         _rgb_r_shift_16 = shift;
-         GET_SHIFT(dga_device->mode.greenMask);
-         _rgb_g_shift_16 = shift;
-         GET_SHIFT(dga_device->mode.blueMask);
-         _rgb_b_shift_16 = shift;
+         _rgb_r_shift_16 = red_shift;
+         _rgb_g_shift_16 = green_shift;
+         _rgb_b_shift_16 = blue_shift;
          break;
 
       case 24:
-         GET_SHIFT(dga_device->mode.redMask);
-         _rgb_r_shift_24 = shift;
-         GET_SHIFT(dga_device->mode.greenMask);
-         _rgb_g_shift_24 = shift;
-         GET_SHIFT(dga_device->mode.blueMask);
-         _rgb_b_shift_24 = shift;
+         _rgb_r_shift_24 = red_shift;
+         _rgb_g_shift_24 = green_shift;
+         _rgb_b_shift_24 = blue_shift;
          break;
 
       case 32:
-         GET_SHIFT(dga_device->mode.redMask);
-         _rgb_r_shift_32 = shift;
-         GET_SHIFT(dga_device->mode.greenMask);
-         _rgb_g_shift_32 = shift;
-         GET_SHIFT(dga_device->mode.blueMask);
-         _rgb_b_shift_32 = shift;
+         _rgb_r_shift_32 = red_shift;
+         _rgb_g_shift_32 = green_shift;
+         _rgb_b_shift_32 = blue_shift;
          break;
    }
 
@@ -429,6 +422,10 @@
       RESYNC();
    }
 
+   /* Checks for triple buffering */
+   if (dga_device->mode.viewportFlags & XDGAFlipRetrace)
+      gfx_capabilities |= GFX_CAN_TRIPLE_BUFFER;
+
    /* Sets up driver description */
    usprintf(_xdga2_driver_desc,
       uconvert_ascii("X-Windows DGA 2.0 graphics%s", tmp),
@@ -479,10 +476,25 @@
 
 
 
-/* _xdga2_scroll_screen:
- *  Scrolls DGA viewport.
+/* _xdga2_poll_scroll:
+ *  Returns true if there are pending scrolling requests left.
  */
-int _xdga2_scroll_screen(int x, int y)
+int _xdga2_poll_scroll(void)
+{
+   int result;
+
+   DISABLE();
+   result = XDGAGetViewportStatus(_xwin.display, _xwin.screen);
+   ENABLE();
+   return result;
+}
+
+
+
+/* _xdga2_request_scroll:
+ *  Starts a screen scroll but doesn't wait for the retrace.
+ */
+int _xdga2_request_scroll(int x, int y)
 {
    DISABLE();
    
@@ -493,7 +505,6 @@
    else if (y > dga_device->mode.maxViewportY)
       y = dga_device->mode.maxViewportY;
 
-   while (XDGAGetViewportStatus(_xwin.display, _xwin.screen));
    XDGASetViewport(_xwin.display, _xwin.screen, x, y, XDGAFlipRetrace);
 
    ENABLE();
@@ -503,14 +514,39 @@
 
 
 
-/* _xdga2_vsync:
- *  Waits for vertical retrace.
+/* _xdga2_request_video_bitmap:
+ *  Page flips to display specified bitmap, but doesn't wait for retrace.
  */
-void _xdga2_vsync(void)
+int _xdga2_request_video_bitmap(BITMAP *bmp)
 {
    DISABLE();
-   XSync(_xwin.display, False);
+   XDGASetViewport(_xwin.display, _xwin.screen, bmp->x_ofs, bmp->y_ofs, XDGAFlipRetrace);
    ENABLE();
+   return 0;
+}
+
+
+
+/* _xdga2_scroll_screen:
+ *  Scrolls DGA viewport.
+ */
+int _xdga2_scroll_screen(int x, int y)
+{
+   DISABLE();
+   
+   if (x < 0) x = 0;
+   else if (x > dga_device->mode.maxViewportX)
+      x = dga_device->mode.maxViewportX;
+   if (y < 0) y = 0;
+   else if (y > dga_device->mode.maxViewportY)
+      y = dga_device->mode.maxViewportY;
+
+   while (XDGAGetViewportStatus(_xwin.display, _xwin.screen));
+   XDGASetViewport(_xwin.display, _xwin.screen, x, y, XDGAFlipRetrace);
+
+   ENABLE();
+   
+   return 0;
 }
 
 
--- /usr/src/allegro_CVS/allegro.current/src/x/xgfxdrv.c	Wed Oct  4 14:34:26 2000
+++ xgfxdrv.c	Sun Oct  8 12:52:44 2000
@@ -123,10 +123,13 @@
    _xdga2_gfxdrv_init,
    _xdga2_gfxdrv_exit,
    _xdga2_scroll_screen,
-   _xdga2_vsync,
+   _xwin_vsync,
    _xdga2_set_palette_range,
+   _xdga2_request_scroll,
+   _xdga2_poll_scroll,
+   NULL,
    NULL, NULL, NULL,
-   NULL, NULL, NULL, NULL,
+   _xdga2_request_video_bitmap,
    NULL, NULL,
    NULL, NULL, NULL, NULL,
    NULL,
@@ -148,10 +151,13 @@
    _xdga2_soft_gfxdrv_init,
    _xdga2_gfxdrv_exit,
    _xdga2_scroll_screen,
-   _xdga2_vsync,
+   _xwin_vsync,
    _xdga2_set_palette_range,
+   _xdga2_request_scroll,
+   _xdga2_poll_scroll,
+   NULL,
    NULL, NULL, NULL,
-   NULL, NULL, NULL, NULL,
+   _xdga2_request_video_bitmap,
    NULL, NULL,
    NULL, NULL, NULL, NULL,
    NULL,
--- /usr/src/allegro_CVS/allegro.current/src/x/xwin.h	Wed Oct  4 14:34:26 2000
+++ xwin.h	Sun Oct  8 12:24:52 2000
@@ -62,9 +62,11 @@
                     int vw, int vh, int depth, int accel));
    AL_FUNC(void, _xdga2_gfxdrv_exit, (BITMAP *bmp));
    AL_FUNC(int, _xdga2_scroll_screen, (int x, int y));
-   AL_FUNC(void, _xdga2_vsync, (void));
    AL_FUNC(void, _xdga2_set_palette_range, (AL_CONST PALETTE p, int from, int to, int vsync));
    AL_FUNC(void, _xdga2_handle_input, (void));
+   AL_FUNC(int, _xdga2_poll_scroll, (void));
+   AL_FUNC(int, _xdga2_request_scroll, (int x, int y));
+   AL_FUNC(int, _xdga2_request_video_bitmap, (BITMAP *bmp));
    
 #ifdef __cplusplus
 }
--- /usr/src/allegro_CVS/allegro.current/readme.uni	Sun May 14 22:16:34 2000
+++ readme.uni	Sun Oct  8 21:43:50 2000
@@ -170,11 +170,18 @@
 	what server you would like to use.
 
    * Graphics:
-	There are two different X graphics drivers: GFX_XWINDOWS uses only 
-	standard X calls, while GFX_XDGA uses the XFree86 DGA extension, 
-	which allows it to write directly to the screen surface. DGA is 
-	normally much faster than the standard X mode, but does not produce 
-	such well behaved windowed programs, and will not work remotely.
+	There are three different X graphics drivers: GFX_XWINDOWS uses 
+	only standard X calls, while GFX_XDGA and GFX_XDGA2 use the XFree86
+	DGA extension, which allows them to write directly to the screen
+	surface. DGA is normally much faster than the standard X mode, but
+	it requires root permissions and it will not work remotely.
+	GFX_XDGA uses DGA 1.0 extension provided with XFree86 3.3.x, and
+	it will not produce such well behaved windowed programs as the
+	GFX_XWINDOWS driver; the driver can also run in fullscreen mode.
+	GFX_XDGA2 uses new DGA 2.0 shipped with XFree86 4.0.x, and directly
+	runs in fullscreen mode (as long as X is configured to support
+	the requested resolution), and it will also use hardware acceleration
+	if available.
 
 	If your program requests a different color depth to the current X 
 	display, Allegro will emulate the depth you asked for, so that your 
@@ -185,4 +192,6 @@
 	the color formats are identical, so no conversions are required. If 
 	it says "fast", some simple conversions are taking place, but 
 	nothing too painful. If it says "slow", you are in trouble :-)
+	This is not valid for the DGA 2.0 driver, as it'll always change the
+	video mode to the specified resolution and color depth.
 


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/