Re: [AD] XOR drawing under X11 (and what is _xwin_in_gfx_call)

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


Elias Pschernig wrote:
Therefore, I made the attached patch, which simply removes direct XOR
drawing again. Immediately everything works perfectly. And since it's
hard for me to keep overview in long functions, I split the direct
updating into separate functions.. the optimizer will inline them again
anyway.

The patch looks mostly alright. A few things though.. The direct_* functions should probably be prefixed with _xwin just like all the other X11 functions. You also missed tagging them as inline. I also think drawing_mode_ok should only be set TRUE if matching_formats is true as well as _drawing_mode is DRAW_MODE_SOLID (this will make it so you only have to test drawing_mode_ok instead of both that and matching_formats).

I attached an updated patch.

I'm almost sure now this is only for the signals version - just not sure
how it works. If something wants to draw while drawing is in progress,
it only updates the back-buffer(?)

Right (and even then, only if it's drawing to the memory bitmap itself, not the display). Although if that ever happened, then the display would never be updated with the second drawing operation, unless it happened to be inside the same area as the first (which would cause its own problems).
Index: src/x/xvtable.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/x/xvtable.c,v
retrieving revision 1.17
diff -r1.17 xvtable.c
64,80c64,67
<    if (!_xwin.matching_formats) {
<       if (_drawing_mode == DRAW_MODE_SOLID)
< 	 _xwin.drawing_mode_ok = TRUE;
<       else
< 	 _xwin.drawing_mode_ok = FALSE;
< 
<       _xwin.real_drawing_mode = GXcopy;
<       XSetState(_xwin.display, _xwin.gc, 0, 0, GXcopy, -1);
<       return;
<    }
< 
<    _xwin.drawing_mode_ok = TRUE;
<    if(_drawing_mode == DRAW_MODE_SOLID)
<       _xwin.real_drawing_mode = GXcopy;
<    else if (_drawing_mode == DRAW_MODE_XOR)
<       _xwin.real_drawing_mode = GXxor;
<    else {
---
>    /* Only SOLID can be handled directly by X11. */
>    if(_xwin.matching_formats && _drawing_mode == DRAW_MODE_SOLID)
>       _xwin.drawing_mode_ok = TRUE;
>    else
82,83c69,178
<       _xwin.real_drawing_mode = GXcopy;
<    }
---
> }
> 
> 
> 
> /* Direct X11 version of the function. */
> static inline int _xwin_direct_putpixel(BITMAP *dst, int dx, int dy, int color)
> {
>    if (!_xwin.drawing_mode_ok)
>       return 0;
> 
>    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 1;
> 
>    XLOCK();
>    XSetForeground(_xwin.display, _xwin.gc, color);
>    XDrawPoint(_xwin.display, _xwin.window, _xwin.gc, dx, dy);
>    XUNLOCK();
> 
>    return 1;
> }
> 
> 
> 
> /* Direct X11 version of the function. */
> static inline int _xwin_direct_hline(BITMAP *dst, int dx1, int dy, int dx2, int color)
> {
>    if (!_xwin.drawing_mode_ok)
>       return 0;
> 
>    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 1;
> 
>    XLOCK();
>    XSetForeground(_xwin.display, _xwin.gc, color);
>    XDrawLine(_xwin.display, _xwin.window, _xwin.gc, dx1, dy, dx2, dy);
>    XUNLOCK();;
> 
>    return 1;
> }
> 
> 
> 
> /* Direct X11 version of the function. */
> static inline int _xwin_direct_vline(BITMAP *dst, int dx, int dy1, int dy2, int color)
> {
>    if (!_xwin.drawing_mode_ok)
>       return 0;
> 
>    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 1;
> 
>    XLOCK();
>    XSetForeground(_xwin.display, _xwin.gc, color);
>    XDrawLine(_xwin.display, _xwin.window, _xwin.gc, dx, dy1, dx, dy2);
>    XUNLOCK();
> 
>    return 1;
> }
> 
> 
> 
> /* Direct X11 version of the function. */
> static inline int _xwin_direct_rectfill(BITMAP *dst, int dx1, int dy1, int dx2, int dy2, int color)
> {
>    if (!_xwin.drawing_mode_ok)
>       return 0;
> 
>    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 1;
> 
>    if (dy1 < 0)
>       dy1 = 0;
>    if (dy2 >= _xwin.screen_height)
>       dy2 = _xwin.screen_height - 1;
>    if (dy1 > dy2)
>       return 1;
> 
>    XLOCK();
>    XSetForeground(_xwin.display, _xwin.gc, color);
>    XFillRectangle(_xwin.display, _xwin.window, _xwin.gc, dx1, dy1, dx2-dx1+1, dy2-dy1+1);
>    XUNLOCK();
85c180,216
<    XSetState(_xwin.display, _xwin.gc, 0, 0, _xwin.real_drawing_mode, -1);
---
>    return 1;
> }
> 
> 
> 
> /* Direct X11 version of the function. */
> static inline int _xwin_direct_clear_to_color(BITMAP *dst, int color)
> {
>    int dx1, dy1, dx2, dy2;
>    if (!_xwin.drawing_mode_ok)
>       return 0;
> 
>    dx1 = dst->cl + dst->x_ofs - _xwin.scroll_x;
>    dx2 = dst->cr + dst->x_ofs - 1 - _xwin.scroll_x;
>    dy1 = dst->ct + dst->y_ofs - _xwin.scroll_y;
>    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 1;
> 
>    if (dy1 < 0)
>       dy1 = 0;
>    if (dy2 >= _xwin.screen_height)
>       dy2 = _xwin.screen_height - 1;
>    if (dy1 > dy2)
>       return 1;
> 
>    XLOCK();
>    XSetForeground(_xwin.display, _xwin.gc, color);
>    XFillRectangle(_xwin.display, _xwin.window, _xwin.gc, dx1, dy1, dx2-dx1+1, dy2-dy1+1);
>    XUNLOCK();
> 
>    return 1;
155,157d285
<    if (_xwin.real_drawing_mode != GXcopy)
<       XSetState(_xwin.display, _xwin.gc, 0, 0, GXcopy, -1);
< 
159,161d286
< 
<    if (_xwin.real_drawing_mode != GXcopy)
<       XSetState(_xwin.display, _xwin.gc, 0, 0, _xwin.real_drawing_mode, -1);
183,190c308,309
<    if (_xwin.matching_formats && _xwin.drawing_mode_ok)
<    {
<       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;
---
>    if (_xwin_direct_putpixel(dst, dx, dy, color))
>       return;
192,198c311
<       _xwin_lock(NULL);
<       XSetForeground(_xwin.display, _xwin.gc, color);
<       XDrawPoint(_xwin.display, _xwin.window, _xwin.gc, dx, dy);
<       _xwin_unlock(NULL);
<    }
<    else
<       _xwin_update_video_bitmap(dst, dx, dy, 1, 1);
---
>    _xwin_update_video_bitmap(dst, dx, dy, 1, 1);
232,242c345,346
<    if (_xwin.matching_formats && _xwin.drawing_mode_ok) {
<       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;
---
>    if (_xwin_direct_hline(dst, dx1, dy, dx2, color))
>       return;
244,250c348
<       _xwin_lock(NULL);
<       XSetForeground(_xwin.display, _xwin.gc, color);
<       XDrawLine(_xwin.display, _xwin.window, _xwin.gc, dx1, dy, dx2, dy);
<       _xwin_unlock(NULL);
<    }
<    else
<       _xwin_update_video_bitmap(dst, dx1, dy, dx2 - dx1 + 1, 1);
---
>    _xwin_update_video_bitmap(dst, dx1, dy, dx2 - dx1 + 1, 1);
284,294c382,383
<    if (_xwin.matching_formats && _xwin.drawing_mode_ok) {
<       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;
---
>    if (_xwin_direct_vline(dst, dx, dy1, dy2, color))
>       return;
296,302c385
<       _xwin_lock(NULL);
<       XSetForeground(_xwin.display, _xwin.gc, color);
<       XDrawLine(_xwin.display, _xwin.window, _xwin.gc, dx, dy1, dx, dy2);
<       _xwin_unlock(NULL);
<    }
<    else
<       _xwin_update_video_bitmap(dst, dx, dy1, 1, dy2 - dy1 + 1);
---
>    _xwin_update_video_bitmap(dst, dx, dy1, 1, dy2 - dy1 + 1);
349,367c432,433
<    if (_xwin.matching_formats && _xwin.drawing_mode_ok) {
<       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;
---
>    if (_xwin_direct_rectfill(dst, dx1, dy1, dx2, dy2, color))
>       return;
369,375c435
<       _xwin_lock(NULL);
<       XSetForeground(_xwin.display, _xwin.gc, color);
<       XFillRectangle(_xwin.display, _xwin.window, _xwin.gc, dx1, dy1, dx2-dx1+1, dy2-dy1+1);
<       _xwin_unlock(NULL);
<    }
<    else
<       _xwin_update_video_bitmap(dst, dx1, dy1, dx2 - dx1 + 1, dy2 - dy1 + 1);
---
>    _xwin_update_video_bitmap(dst, dx1, dy1, dx2 - dx1 + 1, dy2 - dy1 + 1);
394,412c454,455
<    if (_xwin.matching_formats && (_drawing_mode == DRAW_MODE_SOLID)) {
<       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;
---
>    if (_xwin_direct_clear_to_color(dst, color))
>       return;
414,420c457
<       _xwin_lock(NULL);
<       XSetForeground(_xwin.display, _xwin.gc, color);
<       XFillRectangle(_xwin.display, _xwin.window, _xwin.gc, dx1, dy1, dx2-dx1+1, dy2-dy1+1);
<       _xwin_unlock(NULL);
<    }
<    else
<       _xwin_update_video_bitmap(dst, dst->cl, dst->ct, dst->cr - dst->cl, dst->cb - dst->ct);
---
>    _xwin_update_video_bitmap(dst, dst->cl, dst->ct, dst->cr - dst->cl, dst->cb - dst->ct);
Index: src/x/xwin.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/x/xwin.c,v
retrieving revision 1.81
diff -r1.81 xwin.c
139d138
<    GXcopy,      /* real_drawing_mode */
2316d2314
< 	 XSetState(_xwin.display, _xwin.gc, 0, 0, GXcopy, -1);
2320d2317
< 	 XSetState(_xwin.display, _xwin.gc, 0, 0, _xwin.real_drawing_mode, -1);
Index: include/xalleg.h
===================================================================
RCS file: /cvsroot/alleg/allegro/include/xalleg.h,v
retrieving revision 1.21
diff -r1.21 xalleg.h
135d134
<    int real_drawing_mode;


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