[AD] X primitives patch

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


Attached is a patch that improves the performance of the primitive drawing routines for Allegro's X11 driver, when the screen and X display are in matching depths. What it does is use the X drawing primtiives directly, instead of doing the X equivilant of blit, after drawing onto the memory bitmap screen. The functions I have so far done are putpixel (which has almost doubled in speed), hline/vline (which /have/ more than doubled in speed), rectfill, and clear_to_color (by using X's rectfill). I will try to do more in time.

Scrolling should still work, as well as non-matching depths. There may be a problem with using DGA in non-matching depths though, but from what I've seen DGA in non-matching depths doesn't work anyway.

- Kitty Cat
Index: src/x/xvtable.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/x/xvtable.c,v
retrieving revision 1.10
diff -u -r1.10 xvtable.c
--- src/x/xvtable.c	30 Sep 2003 11:44:35 -0000	1.10
+++ src/x/xvtable.c	4 Aug 2004 02:20:54 -0000
@@ -44,11 +44,11 @@
 static void _xwin_draw_character(BITMAP *dst, BITMAP *src, int dx, int dy, int color, int bg);
 static void _xwin_draw_glyph(BITMAP *dst, AL_CONST FONT_GLYPH *src, int dx, int dy, int color, int bg);
 static void _xwin_blit_anywhere(BITMAP *src, BITMAP *dst, int sx, int sy,
-				int dx, int dy, int w, int h);
+                                int dx, int dy, int w, int h);
 static void _xwin_blit_backward(BITMAP *src, BITMAP *dst, int sx, int sy,
-				int dx, int dy, int w, int h);
+                                int dx, int dy, int w, int h);
 static void _xwin_masked_blit(BITMAP *src, BITMAP *dst, int sx, int sy,
-			      int dx, int dy, int w, int h);
+                              int dx, int dy, int w, int h);
 static void _xwin_clear_to_color(BITMAP *dst, int color);
 
 
@@ -80,9 +80,7 @@
    vtable->draw_character = _xwin_draw_character;
    vtable->draw_glyph = _xwin_draw_glyph;
    vtable->blit_from_memory = _xwin_blit_anywhere;
-   vtable->blit_to_memory = _xwin_blit_anywhere;
    vtable->blit_from_system = _xwin_blit_anywhere;
-   vtable->blit_to_system = _xwin_blit_anywhere;
    vtable->blit_to_self = _xwin_blit_anywhere;
    vtable->blit_to_self_forward = _xwin_blit_anywhere;
    vtable->blit_to_self_backward = _xwin_blit_backward;
@@ -118,7 +116,21 @@
    _xwin_in_gfx_call = 1;
    _xwin_vtable.putpixel(dst, dx, dy, color);
    _xwin_in_gfx_call = 0;
-   _xwin_update_video_bitmap(dst, dx, dy, 1, 1);
+
+   if (_xwin.matching_formats)
+   {
+      dx += dst->x_ofs - _xwin.scroll_x;
+      dy += dst->y_ofs - _xwin.scroll_y;
+
+      if((dx >= _xwin.screen_width) || (dx < 0) || 
+         (dy >= _xwin.screen_height) || (dy < 0))
+         return;
+
+      XSetForeground(_xwin.display, _xwin.gc, color);
+      XDrawPoint(_xwin.display, _xwin.window, _xwin.gc, dx, dy);
+   }
+   else
+      _xwin_update_video_bitmap(dst, dx, dy, 1, 1);
 }
 
 
@@ -141,17 +153,34 @@
 
    if (dst->clip) {
       if (dx1 < dst->cl)
-	 dx1 = dst->cl;
+         dx1 = dst->cl;
       if (dx2 >= dst->cr)
-	 dx2 = dst->cr - 1;
+         dx2 = dst->cr - 1;
       if ((dx1 > dx2) || (dy < dst->ct) || (dy >= dst->cb))
-	 return;
+         return;
    }
 
    _xwin_in_gfx_call = 1;
    _xwin_vtable.hline(dst, dx1, dy, dx2, color);
    _xwin_in_gfx_call = 0;
-   _xwin_update_video_bitmap(dst, dx1, dy, dx2 - dx1 + 1, 1);
+
+   if (_xwin.matching_formats) {
+      dx1 += dst->x_ofs - _xwin.scroll_x;
+      dx2 += dst->x_ofs - _xwin.scroll_x;
+      dy += dst->y_ofs - _xwin.scroll_y;
+
+      if (dx1 < 0)
+         dx1 = 0;
+      if (dx2 >= _xwin.screen_width)
+         dx2 = _xwin.screen_width - 1;
+      if ((dx1 > dx2) || (dy < 0) || (dy >= _xwin.screen_height))
+         return;
+
+      XSetForeground(_xwin.display, _xwin.gc, color);
+      XDrawLine(_xwin.display, _xwin.window, _xwin.gc, dx1, dy, dx2, dy);
+   }
+   else
+      _xwin_update_video_bitmap(dst, dx1, dy, dx2 - dx1 + 1, 1);
 }
 
 
@@ -174,17 +203,34 @@
 
    if (dst->clip) {
       if (dy1 < dst->ct)
-	 dy1 = dst->ct;
+         dy1 = dst->ct;
       if (dy2 >= dst->cb)
-	 dy2 = dst->cb - 1;
+         dy2 = dst->cb - 1;
       if ((dx < dst->cl) || (dx >= dst->cr) || (dy1 > dy2))
-	 return;
+         return;
    }
 
    _xwin_in_gfx_call = 1;
    _xwin_vtable.vline(dst, dx, dy1, dy2, color);
    _xwin_in_gfx_call = 0;
-   _xwin_update_video_bitmap(dst, dx, dy1, 1, dy2 - dy1 + 1);
+
+   if (_xwin.matching_formats) {
+      dx += dst->x_ofs - _xwin.scroll_x;
+      dy1 += dst->y_ofs - _xwin.scroll_y;
+      dy2 += dst->y_ofs - _xwin.scroll_y;
+
+      if (dy1 < 0)
+         dy1 = 0;
+      if (dy2 >= _xwin.screen_height)
+         dy2 = _xwin.screen_height - 1;
+      if ((dy1 > dy2) || (dx < 0) || (dx >= _xwin.screen_width))
+         return;
+
+      XSetForeground(_xwin.display, _xwin.gc, color);
+      XDrawLine(_xwin.display, _xwin.window, _xwin.gc, dx, dy1, dx, dy2);
+   }
+   else
+      _xwin_update_video_bitmap(dst, dx, dy1, 1, dy2 - dy1 + 1);
 }
 
 
@@ -213,24 +259,49 @@
 
    if (dst->clip) {
       if (dx1 < dst->cl)
-	 dx1 = dst->cl;
+         dx1 = dst->cl;
       if (dx2 >= dst->cr)
-	 dx2 = dst->cr - 1;
+         dx2 = dst->cr - 1;
       if (dx1 > dx2)
-	 return;
+         return;
 
       if (dy1 < dst->ct)
-	 dy1 = dst->ct;
+         dy1 = dst->ct;
       if (dy2 >= dst->cb)
-	 dy2 = dst->cb - 1;
+         dy2 = dst->cb - 1;
       if (dy1 > dy2)
-	 return;
+         return;
    }
 
    _xwin_in_gfx_call = 1;
    _xwin_vtable.rectfill(dst, dx1, dy1, dx2, dy2, color);
    _xwin_in_gfx_call = 0;
-   _xwin_update_video_bitmap(dst, dx1, dy1, dx2 - dx1 + 1, dy2 - dy1 + 1);
+
+   if (_xwin.matching_formats) {
+      dx1 += dst->x_ofs - _xwin.scroll_x;
+      dx2 += dst->x_ofs - _xwin.scroll_x;
+      dy1 += dst->y_ofs - _xwin.scroll_y;
+      dy2 += dst->y_ofs - _xwin.scroll_y;
+
+      if (dx1 < 0)
+         dx1 = 0;
+      if (dx2 >= _xwin.screen_width)
+         dx2 = _xwin.screen_width - 1;
+      if (dx1 > dx2)
+         return;
+
+      if (dy1 < 0)
+         dy1 = 0;
+      if (dy2 >= _xwin.screen_height)
+         dy2 = _xwin.screen_height - 1;
+      if (dy1 > dy2)
+         return;
+
+      XSetForeground(_xwin.display, _xwin.gc, color);
+      XFillRectangle(_xwin.display, _xwin.window, _xwin.gc, dx1, dy1, dx2-dx1+1, dy2-dy1+1);
+   }
+   else
+      _xwin_update_video_bitmap(dst, dx1, dy1, dx2 - dx1 + 1, dy2 - dy1 + 1);
 }
 
 
@@ -248,7 +319,32 @@
    _xwin_in_gfx_call = 1;
    _xwin_vtable.clear_to_color(dst, color);
    _xwin_in_gfx_call = 0;
-   _xwin_update_video_bitmap(dst, dst->cl, dst->ct, dst->cr - dst->cl, dst->cb - dst->ct);
+
+   if (_xwin.matching_formats) {
+      int dx1 = dst->cl + dst->x_ofs - _xwin.scroll_x;
+      int dx2 = dst->cr + dst->x_ofs - 1 - _xwin.scroll_x;
+      int dy1 = dst->ct + dst->y_ofs - _xwin.scroll_y;
+      int dy2 = dst->cb + dst->y_ofs - 1 - _xwin.scroll_y;
+
+      if (dx1 < 0)
+         dx1 = 0;
+      if (dx2 >= _xwin.screen_width)
+         dx2 = _xwin.screen_width - 1;
+      if (dx1 > dx2)
+         return;
+
+      if (dy1 < 0)
+         dy1 = 0;
+      if (dy2 >= _xwin.screen_height)
+         dy2 = _xwin.screen_height - 1;
+      if (dy1 > dy2)
+         return;
+
+      XSetForeground(_xwin.display, _xwin.gc, color);
+      XFillRectangle(_xwin.display, _xwin.window, _xwin.gc, dx1, dy1, dx2-dx1+1, dy2-dy1+1);
+   }
+   else
+      _xwin_update_video_bitmap(dst, dst->cl, dst->ct, dst->cr - dst->cl, dst->cb - dst->ct);
 }
 
 
@@ -257,7 +353,7 @@
  *  Wrapper for blit.
  */
 static void _xwin_blit_anywhere(BITMAP *src, BITMAP *dst, int sx, int sy,
-				int dx, int dy, int w, int h)
+                                int dx, int dy, int w, int h)
 {
    if (_xwin_in_gfx_call) {
       _xwin_vtable.blit_from_memory(src, dst, sx, sy, dx, dy, w, h);
@@ -276,7 +372,7 @@
  *  Wrapper for blit_backward.
  */
 static void _xwin_blit_backward(BITMAP *src, BITMAP *dst, int sx, int sy,
-				int dx, int dy, int w, int h)
+                                int dx, int dy, int w, int h)
 {
    if (_xwin_in_gfx_call) {
       _xwin_vtable.blit_to_self_backward(src, dst, sx, sy, dx, dy, w, h);
@@ -295,7 +391,7 @@
  *  Wrapper for masked_blit.
  */
 static void _xwin_masked_blit(BITMAP *src, BITMAP *dst, int sx, int sy,
-			      int dx, int dy, int w, int h)
+                              int dx, int dy, int w, int h)
 {
    if (_xwin_in_gfx_call) {
       _xwin_vtable.masked_blit(src, dst, sx, sy, dx, dy, w, h);
@@ -322,7 +418,7 @@
       tmp = dst->cr - x_orig;                                      \
       w = ((tmp > w_orig) ? w_orig : tmp) - x_delta;               \
       if (w <= 0)                                                  \
-	 return;                                                   \
+         return;                                                   \
                                                                    \
       tmp = dst->ct - y_orig;                                      \
       y_delta = ((tmp < 0) ? 0 : tmp);                             \
@@ -331,7 +427,7 @@
       tmp = dst->cb - y_orig;                                      \
       h = ((tmp > h_orig) ? h_orig : tmp) - y_delta;               \
       if (h <= 0)                                                  \
-	 return;                                                   \
+         return;                                                   \
    }                                                               \
    else {                                                          \
       x = x_orig;                                                  \


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