Threaded animation with cairo_gl backend over a GtkWidget
Carlos López González <[email protected]>
| Newsgroups | gmane.comp.lib.cairo |
|---|---|
| Message-ID | <CAF52pzJN-ngd4p3g_GWRnd7pj_WQJhHA8RqRzYW7F3FycVmZvQ@mail.gmail.com> |
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 -- cairo mailing list [email protected] http://lists.cairographics.org/mailman/listinfo/cairo