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

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


On Sun, 2004-11-28 at 18:16 -0800, Chris wrote:

> I think my solution would handle this perfectly. Basically what it'd do is:
> 
> void _some_draw_function()
> {
>     XLOCK();
>     bmp->vtable = &orig_vtable;
>     orig_vtable.draw_func(bmp, ...);
>     bmp->vtable = &video_vtable;
>     update_display();
>     XUNLOCK();
> }
> 
> This way, another thread wouldn't be able to even attempt to draw while 
> the vtable is switched and the display is updating. Granted this would 
> mean holding the lock for a touch longer per drawing operation, but 
> multiple drawing operations should all be enclosed in a single 
> acquire/release_bitmap pair anyway.
> 

Hm. I think it can't work. Just think of cases like this:

thread 1:
XLOCK();
bmp->vtable = &orig_vtable;
*** context switch ***

thread 2:
draw(bmp); /* will use the wrong vtable method */

Maybe we could copy the bitmap, like this:

void _some_draw_function()
{
    BITMAP temp = *bmp;
    for (i = h; i < bmp->h; i++) temp.line[i] = bmp->line[i];
    XLOCK();
    orig_vtable.draw_func(temp, ...);
    update_display();
    XUNLOCK();
}

Of course, the copying of the line pointers may take too long for this
to be of much use.

For Allegro 4.3.x, I think, we could require all access to a bitmap to
be locked. That is, a function like putpixel would look like this:

acquire_bitmap ();
vtable->putpixel
release_bitmap ()

instead of right now:

vtable->putpixel /* locking is done by the vtable method */

Someone calling vtable->putpixel directly, or using the line pointers,
would be required to manually call acquire/release. With this setup, it
would work just like you said, and clearly would be the most safe and
understandable way.

The above also shows that my _private versions idea can't work. Since,
the problem is, I want to call e.g. the original rect(), and somehow
make it use a different version of hline(). This version of hline should
not be used by other threads though. The main thread directly calls the
vtable methods without locking first, so that's why your suggesion won't
work. Currently, a global X11 flag is modified, but without locking. So
it doesn't work.

Now, I think the only solution left (for 4.2) is the one I mentioned
already: Use a global X11 flag, but access it only while locked.

-- 
Elias Pschernig





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