diff options
-rw-r--r-- | skia/ext/platform_canvas.cc | 9 | ||||
-rw-r--r-- | skia/ext/platform_canvas.h | 4 | ||||
-rw-r--r-- | skia/ext/platform_canvas_linux.cc | 10 | ||||
-rw-r--r-- | skia/ext/platform_canvas_mac.cc | 20 | ||||
-rw-r--r-- | skia/ext/platform_canvas_win.cc | 12 |
5 files changed, 29 insertions, 26 deletions
diff --git a/skia/ext/platform_canvas.cc b/skia/ext/platform_canvas.cc index 44b0d16..b3577e5 100644 --- a/skia/ext/platform_canvas.cc +++ b/skia/ext/platform_canvas.cc @@ -32,4 +32,13 @@ size_t PlatformCanvas::StrideForWidth(unsigned width) { return 4 * width; } +bool PlatformCanvas::initializeWithDevice(SkDevice* device) { + if (!device) + return false; + + setDevice(device); + device->unref(); // Was created with refcount 1, and setDevice also refs. + return true; +} + } // namespace skia diff --git a/skia/ext/platform_canvas.h b/skia/ext/platform_canvas.h index b602ed46..1e51717 100644 --- a/skia/ext/platform_canvas.h +++ b/skia/ext/platform_canvas.h @@ -47,6 +47,7 @@ class PlatformCanvas : public SkCanvas { PlatformCanvas(int width, int height, bool is_opaque, uint8_t* context); // For two-part init, call if you use the no-argument constructor above + bool initialize(CGContextRef context, int width, int height, bool is_opaque); bool initialize(int width, int height, bool is_opaque, uint8_t* data = NULL); #elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \ @@ -106,6 +107,9 @@ class PlatformCanvas : public SkCanvas { // CoreGraphics. virtual SkDevice* setBitmapDevice(const SkBitmap& bitmap); + // Helper method used internally by the initialize() methods. + bool initializeWithDevice(SkDevice* device); + // Disallow copy and assign. PlatformCanvas(const PlatformCanvas&); PlatformCanvas& operator=(const PlatformCanvas&); diff --git a/skia/ext/platform_canvas_linux.cc b/skia/ext/platform_canvas_linux.cc index 8e9db62..5d3594e 100644 --- a/skia/ext/platform_canvas_linux.cc +++ b/skia/ext/platform_canvas_linux.cc @@ -29,14 +29,8 @@ PlatformCanvas::~PlatformCanvas() { } bool PlatformCanvas::initialize(int width, int height, bool is_opaque, uint8_t* data) { - SkDevice* device = - BitmapPlatformDevice::Create(width, height, is_opaque, data); - if (!device) - return false; - - setDevice(device); - device->unref(); // was created with refcount 1, and setDevice also refs - return true; + return initializeWithDevice(BitmapPlatformDevice::Create( + width, height, is_opaque, data)); } cairo_t* PlatformCanvas::beginPlatformPaint() { diff --git a/skia/ext/platform_canvas_mac.cc b/skia/ext/platform_canvas_mac.cc index 7e4c610..9373468 100644 --- a/skia/ext/platform_canvas_mac.cc +++ b/skia/ext/platform_canvas_mac.cc @@ -19,7 +19,7 @@ PlatformCanvas::PlatformCanvas(int width, bool is_opaque, CGContextRef context) : SkCanvas(SkNEW(BitmapPlatformDeviceFactory)) { - initialize(width, height, is_opaque); + initialize(context, width, height, is_opaque); } PlatformCanvas::PlatformCanvas(int width, @@ -37,14 +37,16 @@ bool PlatformCanvas::initialize(int width, int height, bool is_opaque, uint8_t* data) { - SkDevice* device = BitmapPlatformDevice::CreateWithData(data, width, height, - is_opaque); - if (!device) - return false; - - setDevice(device); - device->unref(); // Was created with refcount 1, and setDevice also refs. - return true; + return initializeWithDevice(BitmapPlatformDevice::CreateWithData( + data, width, height, is_opaque)); +} + +bool PlatformCanvas::initialize(CGContextRef context, + int width, + int height, + bool is_opaque) { + return initializeWithDevice(BitmapPlatformDevice::Create( + context, width, height, is_opaque)); } CGContextRef PlatformCanvas::beginPlatformPaint() { diff --git a/skia/ext/platform_canvas_win.cc b/skia/ext/platform_canvas_win.cc index 1c9f461..e761cee 100644 --- a/skia/ext/platform_canvas_win.cc +++ b/skia/ext/platform_canvas_win.cc @@ -67,7 +67,7 @@ void CrashForBitmapAllocationFailure(int w, int h) { // Crashes the process. This is called when a bitmap allocation fails but // unlike its cousin CrashForBitmapAllocationFailure() it tries to detect if -// the issue was a non-valid shared bitmap handle. +// the issue was a non-valid shared bitmap handle. void CrashIfInvalidSection(HANDLE shared_section) { DWORD handle_info = 0; CHECK(::GetHandleInformation(shared_section, &handle_info) == TRUE); @@ -102,14 +102,8 @@ bool PlatformCanvas::initialize(int width, int height, bool is_opaque, HANDLE shared_section) { - SkDevice* device = BitmapPlatformDevice::create(width, height, - is_opaque, shared_section); - if (!device) - return false; - - setDevice(device); - device->unref(); // was created with refcount 1, and setDevice also refs - return true; + return initializeWithDevice(BitmapPlatformDevice::create( + width, height, is_opaque, shared_section)); } HDC PlatformCanvas::beginPlatformPaint() { |