[cairo] Threaded animation with cairo_gl backend over a GtkWidget

Henry (Yu) Song - SISA hsong at sisa.samsung.com
Fri Feb 15 17:53:29 PST 2013


I think both binding are fine, two concerns lead me to use NSOpenGLContext

1. no extra work on app side, there is no need to get CGLObjRef from an NSGLView, using nsgl, you can cairo_gl_surface_create_for_view () directly
2. Apple is definitely going with OBJC-based API, In the future, CGL interface might be deprecated, just like lots of AGL APIs have been deprecated.  In addition, EAGL is OBJC-only, there is no CGL for that.  Once EAGL is mature/feature complete, it can be easier to get EAGL with cairo.

Chris suggested to have runtime switch between glx and NSOpenGLContext - I am not sure it will be doable unless we have new cairo API to indicate which library to load.  Otherwise, there will be two libraries (libGL.so and OpenGLFramework) that both have identical symbols.

One more thing I need cairo community help before it can be upstreamed - I am not so familiar with autoconf/automake, I could not make autoconf to use CCLD instead of OBJCLD when compile for glx, wgl or egl.  OBJCLD is always used for linking libcairo.so and cairo-test-suite.  Please help on that.  nsgl binding location is https://github.com/csyuschmjuh/cairo-nsgl.  Please feel free to experiment and please help out on OBJCLD issue.

Thanks a lot

Henry


From: Andrea Canciani [ranma42 at gmail.com]
Sent: Saturday, February 02, 2013 8:55 AM
To: Henry (Yu) Song - SISA
Cc: Carlos López González; cairo at cairographics.org
Subject: Re: [cairo] Threaded animation with cairo_gl backend over a GtkWidget

On Sat, Jan 19, 2013 at 10:53 PM, Andrea Canciani <ranma42 at gmail.com> wrote:
> On Wed, Jan 16, 2013 at 12:55 AM, Henry (Yu) Song - SISA
> <hsong at sisa.samsung.com> wrote:
>> I also created a cairo to NSOpenGLContext binding such that you don't need
>> glx, gtk on mac, you can use cocoa directly.  It is located
>> https://github.com/csyuschmjuh/cairo-nsgl, I need someone to test/confirm
>> its is working - NSView is working, but not implemented for virtual screen
>> yet.
>
> Wouldn't it be better to bind it to CoreGL?
> It is lower level (in fact NSOpenGLContext is based on it, you can
> even get the underlying CGL context using the CGLContextObj selector)
> and it has primitives which are easier to map to cairo-gl.
> The documentation is available here:
> https://developer.apple.com/library/mac/#documentation/graphicsimaging/Reference/CGL_OpenGL/Reference/reference.html#//apple_ref/doc/uid/TP40001186
>

I finally had some time to try CGL.
The result is the branch
http://cgit.freedesktop.org/~ranma42/cairo/log/?h=wip/cgl

Andrea


>>
>> To compile for nsopengl on mac "./configure --prefix=/your_install_directory
>> --enable-gl=yes --enable-glx=no --enable-nsgl=yes"
>>
>> To compile for glx on mac "./configure --prefix=/your_install_directory
>> --enable-gl=yes"
>>
>> Attached is the cocoa-based sample code with cairo. compile it with "gcc -o
>> cairo-nsgl-fill cairo-nsgl-fill.m `pkg-config --libs --cflags cairo`
>> -framework OpenGL -framework AppKit"
>
> I will try ASAP.
> I'm still very busy with my PhD, but I'm trying to catch up with the
> cairo/pixman-related mail and work I left behind.
>
>>
>> Thanks
>>
>> Henry
>>
>> ________________________________
>> From: cairo-bounces+hsong=sisa.samsung.com at cairographics.org
>> [cairo-bounces+hsong=sisa.samsung.com at cairographics.org] on behalf of Henry
>> (Yu) Song - SISA [hsong at sisa.samsung.com]
>> Sent: Tuesday, January 15, 2013 3:43 PM
>> To: Carlos López González
>>
>> Cc: cairo at cairographics.org
>> Subject: Re: [cairo] Threaded animation with cairo_gl backend over a
>> GtkWidget
>>
>> You are using a driver that does not support window/pixmap multisampling.
>> Remove GLX_SAMPLE_BUFFERS and GLX_SAMPLES, that should work for you.
>>
>> cairo-gles supports both glx/gl and egl/gles.  You still can use MSAA for
>> rendering to texture, but you will fallback to spans/traps compositors for
>> rendering to pixmap/window because your driver does not support msaa on
>> window/pixmap.
>>
>> In your sample, you are creating a texture-based gl_surface, I am not sure
>> what kind of surface is created by gdk binding to cairo - most likely it is
>> an image surface.  in that case, you will get a performance hit by
>> downloading texture to image in system memory.
>>
>> Henry
>>
>>
>> ________________________________
>> From: Carlos López González [genetita at gmail.com]
>> Sent: Tuesday, January 15, 2013 3:04 PM
>> To: Henry (Yu) Song - SISA
>> Cc: cairo at cairographics.org
>> Subject: Re: [cairo] Threaded animation with cairo_gl backend over a
>> GtkWidget
>>
>> The code modifications applied to the laptop gives a null surface because
>> glXChooseVisual returns a NULL pointer when creating the XVisualInfo for the
>> modified attributes. Possibly my graphic card doesn't support those
>> requirements.
>> Attached are the glxinfo output and the interesting line from lspci.
>> I'll test it on OSX tomorrow.
>> Thanks!
>>
>>
>> 2013/1/15 Carlos López González <genetita at gmail.com>
>>>
>>> Hi Henry,
>>> thank you very much for your detailed reply and the code additions. I'll
>>> give it a try and would let you know the results.
>>> I considered cairogles but isn't it created for embedded systems? When it
>>> were added upstream, would it be suitable to be used in non embedded system?
>>> In case of use cairogles, where can I find its API?
>>> Thanks!
>>>
>>>
>>> 2013/1/15 Henry (Yu) Song - SISA <hsong at sisa.samsung.com>
>>>
>>>> I modified your code a little as attached.  Two changes
>>>>
>>>> 1. add cairo_gl_device_set_thread_aware ()
>>>> 2. add GLX_SAMPLES/GLX_SAMPLE_BUFFER
>>>>
>>>> 1. The first add is to reduce GL context switch if you have dedicated one
>>>> thread for rendering (regardless where you create your gl_surface).  If you
>>>> have multiple threads that render to the same gl surface, you cannot
>>>> set_thread_aware (device, FALSE)
>>>>
>>>> 2. If your driver (proprietary nvidia, fglrx and latest intel (mesa >
>>>> 9.0) on sandbridge/ivybridge) supports MSAA, you might want to try our new
>>>> cairo which uses MSAA for antialiasing. It is at
>>>> http://code.google.com/p/cairogles.  It is faster than gl backend in the
>>>> cairo upstream and we are in process of upstreaming it.  It is also more
>>>> stable.  If you want to MSAA on window/pixmap, you need to add GLX_SAMPLES
>>>> and GLX_SAMPLE_BUFFERS to your glx attrib.  If you want to experiment more
>>>> complex drawing, I recommend you use our gles, it is more stable and fast (I
>>>> think it is the fastest backend at this moment given your driver supports
>>>> MSAA, and you don't want to have ANTIALIAS_BEST/subpixel). When you use our
>>>> cairogles, please set CAIRO_GL_COMPOSITOR=msaa in your environment.
>>>>
>>>> 3. There is a caveat when you are using gl surface in cairo at this
>>>> moment.  You need to dedicate a gl context to cairo.  You cannot interleave
>>>> cairo with gl calls/or other library that uses the same gl context as cairo.
>>>> If you do that, you MUST same context/drawable/any other GL states before
>>>> you call gl directly and you MUST restore these before you enter cairo
>>>> drawing.
>>>>
>>>> Let me how pixman compare to gl in your test case,  Don't have
>>>> radeon/nouveau drivers, not sure how they turn out.
>>>>
>>>> Henry
>>>> ________________________________________
>>>> From: cairo-bounces+hsong=sisa.samsung.com at cairographics.org
>>>> [cairo-bounces+hsong=sisa.samsung.com at cairographics.org] on behalf of Carlos
>>>> López González [genetita at gmail.com]
>>>> Sent: Tuesday, January 15, 2013 11:39 AM
>>>> To: cairo at cairographics.org
>>>> Subject: Re: [cairo] Threaded animation with cairo_gl backend over a
>>>> GtkWidget
>>>>
>>>> Hi!
>>>> I've modified the mentioned Cairo animation with miltithreading example
>>>> [1] to use a cairo_gl_surface, expecting to have some GPU acceleration. It
>>>> works fine (doesn't crash) but when I use a cairo_gl_surface it runs much
>>>> slow than when I use a image surface (!). See code here:
>>>>
>>>> https://github.com/genete/my-test-area/blob/direct_draw/src/cairo_sample.c
>>>>
>>>> commenting the line at 135 and 137 I can use cairo_image or cairo_gl.
>>>>
>>>> Same code has been compiled and run in a iMac 2011 using XQuarz as
>>>> Xserver with the same result.
>>>>
>>>> Am I missing something at the cairo_gl code or simply I would never could
>>>> make use of my GPU in my linux laptop or my iMac?
>>>>
>>>> I appreciate any help.
>>>> Thanks!
>>>>
>>>> [1] http://cairographics.org/threaded_animation_with_cairo/
>>>>
>>>> 2013/1/15 Carlos López González
>>>> <genetita at gmail.com<mailto:genetita at gmail.com>>
>>>> I forgot to CC cairo list
>>>>
>>>> ---------- Forwarded message ----------
>>>> From: Carlos López González
>>>> <genetita at gmail.com<mailto:genetita at gmail.com>>
>>>> Date: 2013/1/15
>>>> Subject: Re: [cairo] Threaded animation with cairo_gl backend over a
>>>> GtkWidget
>>>> To: Uli Schlachter <psychon at znc.in<mailto:psychon at znc.in>>
>>>>
>>>>
>>>> Hi!
>>>> I've upgraded to Ubuntu 12.10 and as part of the upgrade Ubuntu disabled
>>>> the proprietary nvidia driver.
>>>> With the  the nouveau driver enabled and simply enable multithreading, it
>>>> crash.
>>>>
>>>> carlos at laptop:~/my-test-area/build$ LANG=C ./cairo-sample
>>>> [xcb] Unknown request in queue while dequeuing
>>>> [xcb] Most likely this is a multi-threaded client and XInitThreads has
>>>> not been called
>>>> [xcb] Aborting, sorry about that.
>>>> cairo-sample: ../../src/xcb_io.c:178: dequeue_pending_request: Assertion
>>>> `!xcb_xlib_unknown_req_in_deq' failed.
>>>> Abortado (`core' generado)
>>>>
>>>> But when add XIniThreads()  as shown in the previous post, it doesn't
>>>> crash but it runs *extremely* slow (?). I'm using a GeForce 8400M GS graphic
>>>> card (glxgears runs smoothly).
>>>>
>>>> If I enable the private nvidia-current driver it crashes in any case with
>>>> the same message than I had before. The suggested breakpoint or the --sync
>>>> option doesn't help much.
>>>>
>>>> So which are my alternatives?
>>>>
>>>> If I create the cairo_gl_surface but not using
>>>> cairo_gl_surface_create_for_window but the cairo_gl_create_surface, would it
>>>> have GPU acceleration as well?
>>>>
>>>> I just want to create a minimal example of multithreading drawing over a
>>>> gtkwidget using cairo_gl to later translate to a bigger application, but it
>>>> seems that it is impossible.
>>>>
>>>> Is there any *real* application that uses Cairo with GPU acceleration in
>>>> production?
>>>>
>>>> Thanks!
>>>>
>>>>
>>>> 2013/1/14 Uli Schlachter <psychon at znc.in<mailto:psychon at znc.in>>
>>>> Hi,
>>>>
>>>> On 14.01.2013 21:24, Carlos López González wrote:
>>>> [...]
>>>> > 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)
>>>>
>>>> minor_code 5 likely is DRI2's GetBuffer request, but could also be a
>>>> RANDRGetScreenInfo, RenderChangePicture, SHAPEQueryExtents,
>>>> SHMCreatePixmap or
>>>> SyncQueryCounter. Of course, this doesn't really help us (does it?).
>>>>
>>>> [...]
>>>> >   (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.)
>>>>
>>>> do "break gdk_x_error" before you "run" the program.
>>>>
>>>> > [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?
>>>>
>>>> If the program supports this option: "run --sync".
>>>>
>>>> Uli
>>>> --
>>>> "Why make things difficult, when it is possible to make them cryptic
>>>> and totally illogical, with just a little bit more effort?" -- A. P. J.
>>>> --
>>>> cairo mailing list
>>>> cairo at cairographics.org<mailto:cairo at cairographics.org>
>>>> http://lists.cairographics.org/mailman/listinfo/cairo
>>>>
>>>>
>>>>
>>>> --
>>>> Carlos
>>>> http://synfig.org
>>>>
>>>>
>>>>
>>>> --
>>>> Carlos
>>>> http://synfig.org
>>>>
>>>>
>>>>
>>>> --
>>>> Carlos
>>>> http://synfig.org
>>>
>>>
>>>
>>>
>>> --
>>> Carlos
>>> http://synfig.org
>>
>>
>>
>>
>> --
>> Carlos
>> http://synfig.org
>>
>> --
>> cairo mailing list
>> cairo at cairographics.org
>> http://lists.cairographics.org/mailman/listinfo/cairo


More information about the cairo mailing list