aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornyamatongwe <unknown>2011-07-10 11:48:20 +1000
committernyamatongwe <unknown>2011-07-10 11:48:20 +1000
commitfc28bf2200135de81365558cb212c17b771a05b2 (patch)
treeb5ed5ae19e538b051f51da078b6b81cd5f32bba3
parentda4f98733fa1b1ea07eed51406ca5c313f2477d5 (diff)
downloadscintilla-mirror-fc28bf2200135de81365558cb212c17b771a05b2.tar.gz
Make copies of bitmap images so they can outlive their surface.
-rw-r--r--cocoa/PlatCocoa.mm12
1 files changed, 10 insertions, 2 deletions
diff --git a/cocoa/PlatCocoa.mm b/cocoa/PlatCocoa.mm
index 4465e36ae..a4de2ecdf 100644
--- a/cocoa/PlatCocoa.mm
+++ b/cocoa/PlatCocoa.mm
@@ -360,9 +360,13 @@ CGImageRef SurfaceImpl::GetImage()
const int bitmapBytesPerRow = ((int) bitmapWidth * BYTES_PER_PIXEL);
const int bitmapByteCount = (bitmapBytesPerRow * (int) bitmapHeight);
+ // Make a copy of the bitmap data for the image creation and divorce it
+ // From the SurfaceImpl lifetime
+ CFDataRef dataRef = CFDataCreate(kCFAllocatorDefault, bitmapData, bitmapByteCount);
+
// Create a data provider.
- CGDataProviderRef dataProvider = CGDataProviderCreateWithData(NULL, bitmapData, bitmapByteCount,
- NULL);
+ CGDataProviderRef dataProvider = CGDataProviderCreateWithCFData(dataRef);
+
CGImageRef image = NULL;
if (dataProvider != NULL)
{
@@ -388,6 +392,9 @@ CGImageRef SurfaceImpl::GetImage()
CGDataProviderRelease(dataProvider);
dataProvider = NULL;
+ // Done with the data provider.
+ CFRelease(dataRef);
+
return image;
}
@@ -791,6 +798,7 @@ void SurfaceImpl::CopyImageRectangle(Surface &surfaceSource, PRectangle srcRect,
CGContextClipToRect (gc, dst);
CGContextDrawImage (gc, drawRect, image);
CGContextRestoreGState (gc);
+ CGImageRelease(image);
}
void SurfaceImpl::Copy(PRectangle rc, Scintilla::Point from, Surface &surfaceSource) {