Bug 29295

Summary: Need public function to set/update size of Quartz surface
Product: cairo Reporter: Kristian Rietveld <kris>
Component: quartz backendAssignee: Vladimir Vukicevic <vladimir>
Status: RESOLVED INVALID QA Contact: cairo-bugs mailing list <cairo-bugs>
Severity: normal    
Priority: medium CC: freedesktop, otte
Version: 1.9.14   
Hardware: Other   
OS: Mac OS X (All)   
Whiteboard:
i915 platform: i915 features:
Attachments: Proposed patch

Description Kristian Rietveld 2010-07-29 05:27:58 UTC
Created attachment 37436 [details] [review]
Proposed patch

A public function is needed to set/update the size of a Quartz surface.  This is because surface->extents is used in clipping calculations.  In GTK+, the toplevel window is backed by a cairo surface.  If the toplevel window is resized, the extents must be updated otherwise the clipping calculations will not be correct and affect the drawing.

Patch is attached.
Comment 1 Behdad Esfahbod 2010-07-29 11:54:53 UTC
For reference, we have such a function for X11 backend.  Please check for consistency if it makes sense.
Comment 2 Kristian Rietveld 2010-07-30 03:15:21 UTC
(In reply to comment #1)
> For reference, we have such a function for X11 backend.  Please check for
> consistency if it makes sense.

Yep, I know, that's why I figured we should have it on Quartz (perhaps win32) as well:

void
cairo_xlib_surface_set_size (cairo_surface_t *abstract_surface,
                             int              width,
                             int              height)
Comment 3 Andrea Canciani 2010-08-08 04:59:18 UTC
Does it make sense at all?
Quartz surfaces can't actually change their extents.
What is that function supposed to do?
Comment 4 Kristian Rietveld 2010-08-08 05:05:19 UTC
(In reply to comment #3)
> Does it make sense at all?
> Quartz surfaces can't actually change their extents.
> What is that function supposed to do?

Wait, I might have misunderstood a part here.  Are Quartz surfaces always backed by a CGBitmap with a memory buffer for a fixed width, height?

(I was under the impression that Quartz surfaces were unlimited in size for some reason, and modifying the extents made things work here, but perhaps it was just writing outside memory bounds?).
Comment 5 Andrea Canciani 2010-08-08 05:21:35 UTC
(In reply to comment #4)
> (In reply to comment #3)
> > Does it make sense at all?
> > Quartz surfaces can't actually change their extents.
> > What is that function supposed to do?
> 
> Wait, I might have misunderstood a part here.  Are Quartz surfaces always
> backed by a CGBitmap with a memory buffer for a fixed width, height?
No, they can also be backed by any CGContext. In this case some operation will fail (example: operator SATURATE), but they should mostly work.
> 
> (I was under the impression that Quartz surfaces were unlimited in size for
> some reason, and modifying the extents made things work here, but perhaps it
> was just writing outside memory bounds?).
AFAICT all CGContext implementations seem to have a fixed size. Even in your use case I would expect you to invalidate the old surface (since it has an incorrect size) and create a new one.
Comment 6 Kristian Rietveld 2010-08-08 05:24:20 UTC
(In reply to comment #5)
> > (I was under the impression that Quartz surfaces were unlimited in size for
> > some reason, and modifying the extents made things work here, but perhaps it
> > was just writing outside memory bounds?).
> AFAICT all CGContext implementations seem to have a fixed size. Even in your
> use case I would expect you to invalidate the old surface (since it has an
> incorrect size) and create a new one.

Ok, I guess the resizing worked by accident then ;)   We will take the surface re-creation route then, which indeed seems the best way.

Thanks for the help, sorry for the noise.
Comment 7 Andrea Canciani 2010-08-08 05:39:00 UTC
If you didn't create the CGContext yourself (in which case I would expect it to be a CGBitmapContext or something whose size is known to be constant anyway), I can probably assume safely that you're using a context that you got from Cocoa. Please notice that cocoa graphic context are not valid anymore as soon as you return from the drawing function, or, as Apple example says (http://developer.apple.com/mac/library/samplecode/JAWTExample/Listings/NativeDrawnCanvas_m.html): "DO NOT CACHE NSGraphicsContexts -- they may go away."

I can't find a similar statement in the documentation, only in the examples, but anyway I would consider it a good reason for the safe way (context recreation).

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.