Hi
I have written an application that works well on older versions Mac OS X but a custom NSView flickers when it is drawn on Yosemite.
My drawing method looks like this:
Should I implement double buffering and how is that done in cocoa?
I have written an application that works well on older versions Mac OS X but a custom NSView flickers when it is drawn on Yosemite.
My drawing method looks like this:
Code:
- (void)drawRect: (NSRect) rect {
cairo_surface_t* surface;
cairo_surface_t* surface_alpha;
cairo_t* cr;
cairo_t* cr_alpha;
NSRect allocation = [self bounds];
CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
surface = cairo_quartz_surface_create_for_cg_context (context,
(int)allocation.size.width,
(int)allocation.size.height);
cr = cairo_create (surface);
surface_alpha = cairo_surface_create_similar (surface,
CAIRO_CONTENT_COLOR_ALPHA,
(int)allocation.size.width,
(int)allocation.size.height);
cr_alpha = cairo_create (surface_alpha);
cairo_save (cr);
cairo_set_source_rgba (cr, 1, 1, 1, 1);
cairo_rectangle (cr, 0, 0, allocation.size.width, allocation.size.height);
cairo_restore (cr);
// Draw many objects here, it can take 250ms.
cairo_set_source_surface (cr, surface_alpha, 0, 0);
cairo_paint (cr);
cairo_destroy (cr_alpha);
cairo_surface_destroy (surface_alpha);
cairo_destroy (cr);
cairo_surface_destroy (surface);
}
Should I implement double buffering and how is that done in cocoa?