From: Pierre Ossman Date: Fri, 17 Aug 2012 13:37:42 +0000 (+0000) Subject: A CGImage is read-only, but it just happened to work anyway. Until 10.8 X-Git-Tag: v1.2.90~129 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=cb9eefabc58f276a17ffc96b755a7ef0f4b44433;p=tigervnc.git A CGImage is read-only, but it just happened to work anyway. Until 10.8 that is. Do it the documented way by having a CGBitmapContext instead. git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4956 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- diff --git a/vncviewer/OSXPixelBuffer.cxx b/vncviewer/OSXPixelBuffer.cxx index 77b435dd..0e03fc98 100644 --- a/vncviewer/OSXPixelBuffer.cxx +++ b/vncviewer/OSXPixelBuffer.cxx @@ -40,29 +40,24 @@ PlatformPixelBuffer::PlatformPixelBuffer(int width, int height) : ManagedPixelBuffer(rfb::PixelFormat(32, 24, false, true, 255, 255, 255, 16, 8, 0), width, height), - image(NULL) + bitmap(NULL) { CGColorSpaceRef lut; - CGDataProviderRef provider; lut = CGColorSpaceCreateDeviceRGB(); assert(lut); - provider = CGDataProviderCreateWithData(NULL, data, datasize, NULL); - assert(provider); - image = CGImageCreate(width, height, 8, 32, width*4, lut, - kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Little, - provider, NULL, false, kCGRenderingIntentDefault); - assert(image); + bitmap = CGBitmapContextCreate(data, width, height, 8, width*4, lut, + kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Little); + assert(bitmap); - CGDataProviderRelease(provider); CGColorSpaceRelease(lut); } PlatformPixelBuffer::~PlatformPixelBuffer() { - CGImageRelease((CGImageRef)image); + CFRelease((CGContextRef)bitmap); } @@ -71,6 +66,7 @@ void PlatformPixelBuffer::draw(int src_x, int src_y, int x, int y, int w, int h) CGRect rect; CGContextRef gc; CGAffineTransform at; + CGImageRef image; gc = (CGContextRef)fl_gc; @@ -102,7 +98,9 @@ void PlatformPixelBuffer::draw(int src_x, int src_y, int x, int y, int w, int h) rect.size.width = width(); rect.size.height = -height(); // Negative height does _not_ flip the image - CGContextDrawImage(gc, rect, (CGImageRef)image); + image = CGBitmapContextCreateImage((CGContextRef)bitmap); + CGContextDrawImage(gc, rect, image); + CGImageRelease(image); CGContextRestoreGState(gc); } diff --git a/vncviewer/OSXPixelBuffer.h b/vncviewer/OSXPixelBuffer.h index a74830c2..e59015e5 100644 --- a/vncviewer/OSXPixelBuffer.h +++ b/vncviewer/OSXPixelBuffer.h @@ -29,8 +29,8 @@ public: void draw(int src_x, int src_y, int x, int y, int w, int h); protected: - // This is really a CGImageRerf, but Apple headers conflict with FLTK - void *image; + // This is really a CGContextRef, but Apple headers conflict with FLTK + void *bitmap; };