| Index: skia/ext/bitmap_platform_device_mac.cc
|
| ===================================================================
|
| --- skia/ext/bitmap_platform_device_mac.cc (revision 18385)
|
| +++ skia/ext/bitmap_platform_device_mac.cc (working copy)
|
| @@ -44,6 +44,28 @@
|
| return true;
|
| }
|
|
|
| +static CGContextRef CGContextForData(void* data, int width, int height) {
|
| + CGColorSpaceRef color_space =
|
| + CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
|
| + // Allocate a bitmap context with 4 components per pixel (BGRA). Apple
|
| + // recommends these flags for improved CG performance.
|
| + CGContextRef context =
|
| + CGBitmapContextCreate(data, width, height, 8, width * 4,
|
| + color_space,
|
| + kCGImageAlphaPremultipliedFirst |
|
| + kCGBitmapByteOrder32Host);
|
| + CGColorSpaceRelease(color_space);
|
| +
|
| + if (!context)
|
| + return NULL;
|
| +
|
| + // Change the coordinate system to match WebCore's
|
| + CGContextTranslateCTM(context, 0, height);
|
| + CGContextScaleCTM(context, 1.0, -1.0);
|
| +
|
| + return context;
|
| +}
|
| +
|
| } // namespace
|
|
|
| class BitmapPlatformDevice::BitmapPlatformDeviceData : public SkRefCnt {
|
| @@ -153,16 +175,21 @@
|
| // that we can create the pixel data before calling the constructor. This is
|
| // required so that we can call the base class' constructor with the pixel
|
| // data.
|
| -BitmapPlatformDevice* BitmapPlatformDevice::Create(CGContextRef context,
|
| - int width,
|
| - int height,
|
| - bool is_opaque) {
|
| +BitmapPlatformDevice* BitmapPlatformDevice::CreateWithContext(
|
| + CGContextRef context, int width, int height, bool is_opaque) {
|
| SkBitmap bitmap;
|
| bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
|
| if (bitmap.allocPixels() != true)
|
| return NULL;
|
| - void* data = bitmap.getPixels();
|
|
|
| + void* data = NULL;
|
| + if (context) {
|
| + data = CGBitmapContextGetData(context);
|
| + bitmap.setPixels(data);
|
| + } else {
|
| + data = bitmap.getPixels();
|
| + }
|
| +
|
| // Note: The Windows implementation clears the Bitmap later on.
|
| // This bears mentioning since removal of this line makes the
|
| // unit tests only fail periodically (or when MallocPreScribble is set).
|
| @@ -170,36 +197,33 @@
|
|
|
| bitmap.setIsOpaque(is_opaque);
|
|
|
| +#ifndef NDEBUG
|
| if (is_opaque) {
|
| -#ifndef NDEBUG
|
| // To aid in finding bugs, we set the background color to something
|
| // obviously wrong so it will be noticable when it is not cleared
|
| bitmap.eraseARGB(255, 0, 255, 128); // bright bluish green
|
| + }
|
| #endif
|
| - }
|
|
|
| - if (!context) {
|
| - CGColorSpaceRef color_space =
|
| - CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
|
| - // allocate a bitmap context with 4 components per pixel (BGRA). Apple
|
| - // recommends these flags for improved CG performance.
|
| - context =
|
| - CGBitmapContextCreate(data, width, height, 8, width*4,
|
| - color_space,
|
| - kCGImageAlphaPremultipliedFirst |
|
| - kCGBitmapByteOrder32Host);
|
| + if (!context)
|
| + context = CGContextForData(data, width, height);
|
|
|
| - // Change the coordinate system to match WebCore's
|
| - CGContextTranslateCTM(context, 0, height);
|
| - CGContextScaleCTM(context, 1.0, -1.0);
|
| - CGColorSpaceRelease(color_space);
|
| - }
|
| -
|
| // The device object will take ownership of the graphics context.
|
| return new BitmapPlatformDevice(
|
| new BitmapPlatformDeviceData(context), bitmap);
|
| }
|
|
|
| +BitmapPlatformDevice* BitmapPlatformDevice::CreateWithData(uint8_t* data,
|
| + int width,
|
| + int height,
|
| + bool is_opaque) {
|
| + CGContextRef context = NULL;
|
| + if (data)
|
| + context = CGContextForData(data, width, height);
|
| +
|
| + return CreateWithContext(context, width, height, is_opaque);
|
| +}
|
| +
|
| // The device will own the bitmap, which corresponds to also owning the pixel
|
| // data. Therefore, we do not transfer ownership to the SkDevice's bitmap.
|
| BitmapPlatformDevice::BitmapPlatformDevice(
|
|
|