Re: Threaded animation with cairo_gl backend over a GtkWidget
Carlos López González <[email protected]>
| Newsgroups | gmane.comp.lib.cairo |
|---|---|
| Message-ID | <CAF52pz+znVzKmNj9bAFx19vF_zi8-+s7OuV4zefkEVLDNQ3POg@mail.gmail.com> |
Hi!
looks like it doesn't work. I've added XInitThreads() and it still
crashing. Also added XLockDisplay and XUnlockDisplay with the same result.
Any idea?
Thanks!
int main (int argc, char *argv[])
{
if(!XInitThreads())
return 0;
gdk_threads_init();
gdk_threads_enter();
gtk_init(&argc, &argv);
GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
gtk_window_set_title(GTK_WINDOW(window), "cairo_gl");
gtk_window_set_default_size(GTK_WINDOW(window), 400, 300);
gtk_widget_set_app_paintable(window, TRUE);
gtk_widget_set_double_buffered(window, FALSE);
gtk_widget_show_all(window);
window_surface=create_source_surface_for_widget(window);
(void)g_timeout_add(33, (GSourceFunc)timer_exe, window);
//do_draw(NULL);
gtk_main();
gdk_threads_leave();
return 0;
}
void *do_draw(void *ptr)
{
rendering=TRUE;
cairo_t *cr = cairo_create(window_surface);
if(cairo_status(cr))
return NULL;
Display *dpy =cairo_glx_device_get_display((cairo_surface_get_device(
window_surface)));
XLockDisplay(dpy);
//do some time-consuming drawing here ...
// ...
// ...
cairo_destroy(cr);
cairo_gl_surface_swapbuffers (window_surface);
XUnlockDisplay(dpy);
rendering=FALSE;
return NULL;
}
2013/1/11 Carlos López González <[email protected]>
> Thanks Henry, I'll give it a try.
>
>
> 2013/1/11 Henry (Yu) Song - SISA <[email protected]>
>
> Hi,
>>
>> Please add XInitThreads() in your main. For multithreaded application
>> using gl_surface is not a good idea for the moment unless you have
>> intel/radeon/nouveau drivers, otherwise, you will have very sloooooow
>> performance.
>>
>> We will resolve that soon in cairo for gl backend, I hope.
>>
>> Henry
>> ________________________________________
>> From: [email protected][cairo-bounces+henry.song=
>> [email protected]] on behalf of Carlos López González [
>> [email protected]]
>> Sent: Thursday, January 10, 2013 11:26 AM
>> To: [email protected]
>> Subject: [cairo] Threaded animation with cairo_gl backend over a GtkWidget
>>
>> Hi!
>> I've made a modified version [1] of the example of threaded animation
>> using Cairo [2].
>>
>> First I've used the method to create a cairo_gl_surface from the
>> test/gl_source_surface.c file adapted to create the surface for a given
>> widget instead for a defined size.
>>
>> Also, for simplicity, I removed all the handled signals except the
>> destroy one.
>>
>> To handle the drawing for the window widget using the cairo_gl backend I
>> use the create_gl_surface_for_window function passing it the proper widget
>> information.
>>
>> So far, for a single drawing execution it works as expected:
>> 1) In main() create the window_surface
>> 2) The do_draw function creates a context based on window_surface
>> 3) Once done the drawings with Cairo then the buffers are swapped and the
>> content is shown on screen.
>>
>> Notice that the window_surface is never destroyed explicitly because it
>> is owned by the window widget and so it will be destroyed when the window
>> is destroyed by gtk.
>>
>> The problem comes when I enable the multithreading support by
>> uncommenting the line:
>>
>>
>> //(void)g_timeout_add(33, (GSourceFunc)timer_exe, window);
>>
>> It triggers the timer_exe function 33 times per second and then it
>> creates threads that will call do_draw each time.
>>
>> Once enabled it crashes at the first painting function from Cairo.
>>
>> I believe that the problem is that the window_surface belongs to the
>> window widget when I created it and then I can't modify it outside the main
>> gtk thread.
>>
>> How can I solve this? If I enclose the Cairo painting operations inside a
>> gdk_threads_enter and
>> gdk_threads_leave I would add a lot of time consuming operations to the
>> main gtk thread, which is precisely what I want to avoid using
>> multithreading.
>>
>> Any help? I would like to know at last, if my assumptions of the
>> window_surface ownership are true or not.
>>
>> Thanks!
>>
>> [1]
>> https://github.com/genete/my-test-area/blob/direct_draw/src/cairo_sample.c
>> [2] http://cairographics.org/threaded_animation_with_cairo/
>>
>> --
>> Carlos
>> http://synfig.org
>>
>
>
>
> --
> Carlos
> http://synfig.org
>
--
Carlos
http://synfig.org
--
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo