[cairo] Threaded animation with cairo_gl backend over a GtkWidget
Carlos López González
genetita at gmail.com
Mon Jan 14 12:24:40 PST 2013
Running Ubuntu 12.04 32 bits. Using Cmake to generate the makefile.
CMAKE_BUILD_TYPE set to 'Debug' in Cmake gui. This is what I get:
carlos at laptop:~/my-test-area/build$ LANG=C gdb ./cairo-sample
GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html
>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /home/carlos/my-test-area/build/cairo-sample...done.
(gdb) run
Starting program: /home/carlos/my-test-area/build/cairo-sample
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/i386-linux-gnu/libthread_db.so.1".
[New Thread 0xb5e14b40 (LWP 3623)]
[New Thread 0xb54ffb40 (LWP 3624)]
[New Thread 0xb4738b40 (LWP 3625)]
The program 'cairo-sample' received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadMatch (invalid parameter attributes)'.
(Details: serial 230 error_code 8 request_code 135 minor_code 5)
(Note to programmers: normally, X errors are reported asynchronously;
that is, you will receive the error a while after causing it.
To debug your program, run it with the --sync command line
option to change this behavior. You can then get a meaningful
backtrace from your debugger if you break on the gdk_x_error() function.)
[Thread 0xb4738b40 (LWP 3625) exited]
[Thread 0xb54ffb40 (LWP 3624) exited]
[Thread 0xb6224880 (LWP 3620) exited]
[Inferior 1 (process 3620) exited with code 01]
(gdb) where
No stack.
(gdb)
How can I add the --sync option?
2013/1/14 Henry (Yu) Song - SISA <hsong at sisa.samsung.com>
> That is weird. I have no problem on intel/nvidia/fglrx drivers. Did
> you try to run gdb on it and where is the seg fault point?
>
> Henry
>
> ------------------------------
> *From:* cairo-bounces+henry.song=samsung.com at cairographics.org[cairo-bounces+henry.song=
> samsung.com at cairographics.org] on behalf of Carlos López González [
> genetita at gmail.com]
> *Sent:* Saturday, January 12, 2013 2:29 AM
> *To:* Henry (Yu) Song - SISA
> *Cc:* cairo at cairographics.org
> *Subject:* Re: [cairo] Threaded animation with cairo_gl backend over a
> GtkWidget
>
> 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 <genetita at gmail.com>
>
>> Thanks Henry, I'll give it a try.
>>
>>
>> 2013/1/11 Henry (Yu) Song - SISA <hsong at sisa.samsung.com>
>>
>> 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: cairo-bounces+henry.song=samsung.com at cairographics.org[cairo-bounces+henry.song=
>>> samsung.com at cairographics.org] on behalf of Carlos López González [
>>> genetita at gmail.com]
>>> Sent: Thursday, January 10, 2013 11:26 AM
>>> To: cairo at cairographics.org
>>> 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
>
--
Carlos
http://synfig.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20130114/8c49df28/attachment.html>
More information about the cairo
mailing list