Bug 17203

Summary: CGLayer backed surface
Product: cairo Reporter: Richard Hult <richard>
Component: quartz backendAssignee: Vladimir Vukicevic <vladimir>
Status: RESOLVED MOVED QA Contact: cairo-bugs mailing list <cairo-bugs>
Severity: enhancement    
Priority: medium    
Version: 1.5.16   
Hardware: Other   
OS: All   
Whiteboard:
i915 platform: i915 features:

Description Richard Hult 2008-08-19 04:53:07 UTC
It would be nice to be able to create a cairo surface on quartz that is backed by a CGContext from a CGLayer to get better performance (CGBitmapContext seems to be very slow, most likely done completely in software, while CGLayers are closer to pixmaps on X11). This will require 10.4 though. GTK+ could then use CGLayer to represent GdkPixmap instead of a bitmap context.
Comment 1 Vladimir Vukicevic 2008-08-19 08:37:27 UTC
I have a patch for that sitting around here somewhere, but it wasn't really any faster on my benchmarks; I never finished it completely though, and there were a few oddities in the API.  Nothing stops the app (gtk in this case) from creating a CGLayer and just creating a cairo surface that renders to it...
Comment 2 Richard Hult 2008-08-19 09:01:38 UTC
OK, sorry to hear you didn't see any performance improvements. I was hoping it could at some point be used instead of a bitmap in create_similar etc.

Do you have that patch somewhere if I want to play around with it?

About creating a surface from a CGLayer, I did try that. I first tried creating a layer, then a cairo surface for its cgcontext, drew to the cairo surface, and then used the surface as source to paint to the "screen's" surface. But this made the surface end up in error state for some reason so I figure it needs some adjustments to be supported.
Comment 3 Vladimir Vukicevic 2008-08-19 09:06:23 UTC
I'll try to dig up the patch and attach it here.  But I would focus on the second thing that you tried.  I'm guessing that the issue was that you tried to use cairo to paint from the CGLayer surface to the screen (also CG) surface; code is probably missing to handle CGLayer-backed surfaces in that operation.  That shouldn't be hard to fix, but I would use CG directly at that point (since you have the Layer and you have the destination CG context).
Comment 4 Richard Hult 2008-08-19 09:26:22 UTC
Ah, I can try using CG directly off course, at least to see if I get any performance improvements, thanks for the idea.

Comment 5 Richard Hult 2008-08-19 12:56:16 UTC
OK, that worked nicely for my test. Unfortunately you are right, no noticable improvement, which is weird as all the docs talk about CGLayer as being much more efficient, and being stored in video memory etc etc. Maybe it depends on the hardware. Also I am applying transforms and clipping which seem to slow down quartz a lot anyway.

Comment 6 Richard Hult 2008-08-21 00:45:02 UTC
I did some testing to figure out why the cglayer approach was as slow as the bitmap way, and it seems like as soon as you flip the coords, drawing a cglayer to a cgcontext gets really slow :/
Comment 7 Robert O'Callahan 2010-07-29 13:05:14 UTC
I have a patch for this in http://hg.mozilla.org/mozilla-central/file/tip/gfx/cairo. CGLayers aren't super-fast as claimed in Apple docs, but they're better than CGBitmapContexts for some things, like self-copies, and they're not slower if you're careful about flipping coordinates. See http://weblogs.mozillazine.org/roc/archives/2010/05/cglayer_perform.html
Comment 8 GitLab Migration User 2018-08-25 13:25:38 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/cairo/cairo/issues/1.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.