summaryrefslogtreecommitdiffstats
path: root/skia
diff options
context:
space:
mode:
authorreed@google.com <reed@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-14 13:46:56 +0000
committerreed@google.com <reed@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-14 13:46:56 +0000
commit9d611ca0375cf3594423fa8571a30ed356e568f6 (patch)
tree6e04e592faf658dd786ea2cb1115af7ac7247124 /skia
parentbd3db410a3334cbcbd50247306d286326003eb2c (diff)
downloadchromium_src-9d611ca0375cf3594423fa8571a30ed356e568f6.zip
chromium_src-9d611ca0375cf3594423fa8571a30ed356e568f6.tar.gz
chromium_src-9d611ca0375cf3594423fa8571a30ed356e568f6.tar.bz2
Simplify platform_canvas.h by recognizing that PlatformCanvas does not actually extend
SkCanvas in any way, other than provide a host of constructors (and delayed constructors in the form of 'initialize' methods). These late initializers are a problem, as SkCanvas is deprecating its setDevice() call, moving to model where the backingstore/device for the canvas must be created before the canvas is created. This is necessary to allow skia to continue to extend SkCanvas for its backends (e.g. GPU, PDF, Picture, Pipe, etc.). The practical change in this CL is to make PlatformCanvas just a typedef for SkCanvas, and change the call-sites that want to call initialize() to instead create the canvas using one of the provided Factory functions (e.g. CreatePlatformCanvas). The modifier Platform is maintained, to document that this canvas may be backed by platform-specific pixels (e.g. allocated by GDI or cairo). Review URL: https://codereview.chromium.org/11138024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@167669 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia')
-rw-r--r--skia/ext/bitmap_platform_device_android.cc8
-rw-r--r--skia/ext/bitmap_platform_device_linux.cc8
-rw-r--r--skia/ext/bitmap_platform_device_mac.cc21
-rw-r--r--skia/ext/bitmap_platform_device_win.cc21
-rw-r--r--skia/ext/platform_canvas.cc43
-rw-r--r--skia/ext/platform_canvas.h142
-rw-r--r--skia/ext/platform_canvas_linux.cc38
-rw-r--r--skia/ext/platform_canvas_mac.cc56
-rw-r--r--skia/ext/platform_canvas_skia.cc113
-rw-r--r--skia/ext/platform_canvas_unittest.cc182
-rw-r--r--skia/ext/platform_canvas_win.cc40
-rw-r--r--skia/ext/vector_canvas_unittest.cc2
-rw-r--r--skia/skia.gyp15
13 files changed, 234 insertions, 455 deletions
diff --git a/skia/ext/bitmap_platform_device_android.cc b/skia/ext/bitmap_platform_device_android.cc
index 6a71fb2..c12abd6 100644
--- a/skia/ext/bitmap_platform_device_android.cc
+++ b/skia/ext/bitmap_platform_device_android.cc
@@ -72,6 +72,14 @@ void BitmapPlatformDevice::DrawToNativeContext(
SkASSERT(false);
}
+// PlatformCanvas impl
+
+SkCanvas* CreatePlatformCanvas(int width, int height, bool is_opaque,
+ uint8_t* data, OnFailureType failureType) {
+ SkDevice* dev = BitmapPlatformDevice::Create(width, height, is_opaque, data);
+ return CreateCanvas(dev, failureType);
+}
+
// Port of PlatformBitmap to android
PlatformBitmap::~PlatformBitmap() {}
diff --git a/skia/ext/bitmap_platform_device_linux.cc b/skia/ext/bitmap_platform_device_linux.cc
index 63b44a6..23a7683 100644
--- a/skia/ext/bitmap_platform_device_linux.cc
+++ b/skia/ext/bitmap_platform_device_linux.cc
@@ -176,6 +176,14 @@ void BitmapPlatformDevice::setMatrixClip(const SkMatrix& transform,
data_->SetMatrixClip(transform, region);
}
+// PlatformCanvas impl
+
+SkCanvas* CreatePlatformCanvas(int width, int height, bool is_opaque,
+ uint8_t* data, OnFailureType failureType) {
+ SkDevice* dev = BitmapPlatformDevice::Create(width, height, is_opaque, data);
+ return CreateCanvas(dev, failureType);
+}
+
// Port of PlatformBitmap to linux
PlatformBitmap::~PlatformBitmap() {
diff --git a/skia/ext/bitmap_platform_device_mac.cc b/skia/ext/bitmap_platform_device_mac.cc
index d8f16a2..c97e6fb 100644
--- a/skia/ext/bitmap_platform_device_mac.cc
+++ b/skia/ext/bitmap_platform_device_mac.cc
@@ -28,6 +28,12 @@ static CGContextRef CGContextForData(void* data, int width, int height) {
#if defined(SK_CPU_LENDIAN) && HAS_ARGB_SHIFTS(24, 16, 8, 0)
// Allocate a bitmap context with 4 components per pixel (BGRA). Apple
// recommends these flags for improved CG performance.
+
+ // CGBitmapContextCreate returns NULL if width/height are 0. However, our
+ // callers expect to get a canvas back (which they later resize/reallocate)
+ // so we pin the dimensions here.
+ width = SkMax32(1, width);
+ height = SkMax32(1, height);
CGContextRef context =
CGBitmapContextCreate(data, width, height, 8, width * 4,
base::mac::GetSystemColorSpace(),
@@ -255,6 +261,21 @@ SkDevice* BitmapPlatformDevice::onCreateCompatibleDevice(
return bitmap_device;
}
+// PlatformCanvas impl
+
+SkCanvas* CreatePlatformCanvas(CGContextRef ctx, int width, int height,
+ bool is_opaque, OnFailureType failureType) {
+ SkDevice* dev = BitmapPlatformDevice::Create(ctx, width, height, is_opaque);
+ return CreateCanvas(dev, failureType);
+}
+
+SkCanvas* CreatePlatformCanvas(int width, int height, bool is_opaque,
+ uint8_t* data, OnFailureType failureType) {
+ SkDevice* dev = BitmapPlatformDevice::CreateWithData(data, width, height,
+ is_opaque);
+ return CreateCanvas(dev, failureType);
+}
+
// Port of PlatformBitmap to mac
PlatformBitmap::~PlatformBitmap() {
diff --git a/skia/ext/bitmap_platform_device_win.cc b/skia/ext/bitmap_platform_device_win.cc
index dc21673..4e5bbce 100644
--- a/skia/ext/bitmap_platform_device_win.cc
+++ b/skia/ext/bitmap_platform_device_win.cc
@@ -260,12 +260,23 @@ const SkBitmap& BitmapPlatformDevice::onAccessBitmap(SkBitmap* bitmap) {
}
SkDevice* BitmapPlatformDevice::onCreateCompatibleDevice(
- SkBitmap::Config config, int width, int height, bool isOpaque,
- Usage /*usage*/) {
+ SkBitmap::Config config, int width, int height, bool isOpaque, Usage) {
SkASSERT(config == SkBitmap::kARGB_8888_Config);
- SkDevice* bitmap_device = BitmapPlatformDevice::CreateAndClear(width, height,
- isOpaque);
- return bitmap_device;
+ return BitmapPlatformDevice::CreateAndClear(width, height, isOpaque);
+}
+
+// PlatformCanvas impl
+
+SkCanvas* CreatePlatformCanvas(int width,
+ int height,
+ bool is_opaque,
+ HANDLE shared_section,
+ OnFailureType failureType) {
+ SkDevice* dev = BitmapPlatformDevice::Create(width,
+ height,
+ is_opaque,
+ shared_section);
+ return CreateCanvas(dev, failureType);
}
// Port of PlatformBitmap to win
diff --git a/skia/ext/platform_canvas.cc b/skia/ext/platform_canvas.cc
index 11b1f5e..461dba4 100644
--- a/skia/ext/platform_canvas.cc
+++ b/skia/ext/platform_canvas.cc
@@ -9,35 +9,6 @@
namespace skia {
-PlatformCanvas::PlatformCanvas() {}
-
-// static
-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;
-}
-
-SkCanvas* CreateBitmapCanvas(int width, int height, bool is_opaque) {
- return new PlatformCanvas(width, height, is_opaque);
-}
-
-SkCanvas* TryCreateBitmapCanvas(int width, int height, bool is_opaque) {
- PlatformCanvas* canvas = new PlatformCanvas();
- if (!canvas->initialize(width, height, is_opaque)) {
- delete canvas;
- canvas = NULL;
- }
- return canvas;
-}
-
SkDevice* GetTopDevice(const SkCanvas& canvas) {
return canvas.getTopDevice(true);
}
@@ -87,6 +58,20 @@ void MakeOpaque(SkCanvas* canvas, int x, int y, int width, int height) {
canvas->drawRect(rect, paint);
}
+size_t PlatformCanvasStrideForWidth(unsigned width) {
+ return 4 * width;
+}
+
+SkCanvas* CreateCanvas(SkDevice* device, OnFailureType failureType) {
+ if (!device) {
+ if (CRASH_ON_FAILURE == failureType)
+ SK_CRASH();
+ return NULL;
+ }
+ SkAutoUnref aur(device);
+ return new SkCanvas(device);
+}
+
PlatformBitmap::PlatformBitmap() : surface_(0), platform_extra_(0) {}
} // namespace skia
diff --git a/skia/ext/platform_canvas.h b/skia/ext/platform_canvas.h
index f20d62e..c83e6bf 100644
--- a/skia/ext/platform_canvas.h
+++ b/skia/ext/platform_canvas.h
@@ -13,74 +13,91 @@
namespace skia {
-// This class is a specialization of the regular SkCanvas that is designed to
-// work with a PlatformDevice to manage platform-specific drawing. It allows
-// using both Skia operations and platform-specific operations.
-class SK_API PlatformCanvas : public SkCanvas {
- public:
- // If you use the version with no arguments, you MUST call initialize()
- PlatformCanvas();
- // Set is_opaque if you are going to erase the bitmap and not use
- // transparency: this will enable some optimizations.
- PlatformCanvas(int width, int height, bool is_opaque);
+typedef SkCanvas PlatformCanvas;
+
+//
+// Note about error handling.
+//
+// Creating a canvas can fail at times, most often because we fail to allocate
+// the backing-store (pixels). This can be from out-of-memory, or something
+// more opaque, like GDI or cairo reported a failure.
+//
+// To allow the caller to handle the failure, every Create... factory takes an
+// enum as its last parameter. The default value is kCrashOnFailure. If the
+// caller passes kReturnNullOnFailure, then the caller is responsible to check
+// the return result.
+//
+enum OnFailureType {
+ CRASH_ON_FAILURE,
+ RETURN_NULL_ON_FAILURE
+};
#if defined(WIN32)
// The shared_section parameter is passed to gfx::PlatformDevice::create.
// See it for details.
- PlatformCanvas(int width, int height, bool is_opaque, HANDLE shared_section);
+ SK_API SkCanvas* CreatePlatformCanvas(int width,
+ int height,
+ bool is_opaque,
+ HANDLE shared_section,
+ OnFailureType failure_type);
#elif defined(__APPLE__)
- PlatformCanvas(int width, int height, bool is_opaque,
- CGContextRef context);
- PlatformCanvas(int width, int height, bool is_opaque, uint8_t* context);
+ SK_API SkCanvas* CreatePlatformCanvas(CGContextRef context,
+ int width,
+ int height,
+ bool is_opaque,
+ OnFailureType failure_type);
+
+ SK_API SkCanvas* CreatePlatformCanvas(int width,
+ int height,
+ bool is_opaque,
+ uint8_t* context,
+ OnFailureType failure_type);
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \
defined(__sun) || defined(ANDROID)
// Linux ---------------------------------------------------------------------
// Construct a canvas from the given memory region. The memory is not cleared
// first. @data must be, at least, @height * StrideForWidth(@width) bytes.
- PlatformCanvas(int width, int height, bool is_opaque, uint8_t* data);
+ SK_API SkCanvas* CreatePlatformCanvas(int width,
+ int height,
+ bool is_opaque,
+ uint8_t* data,
+ OnFailureType failure_type);
#endif
- virtual ~PlatformCanvas();
-
-#if defined(WIN32)
- // For two-part init, call if you use the no-argument constructor above. Note
- // that we want this to optionally match the Linux initialize if you only
- // pass 3 arguments, hence the evil default argument.
- bool initialize(int width, int height, bool is_opaque,
- HANDLE shared_section = NULL);
-#elif defined(__APPLE__)
- // 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__) || \
- defined(__sun) || defined(ANDROID)
- // For two-part init, call if you use the no-argument constructor above
- bool initialize(int width, int height, bool is_opaque, uint8_t* data = NULL);
-#endif
-
- // Shared --------------------------------------------------------------------
-
- // Return the stride (length of a line in bytes) for the given width. Because
- // we use 32-bits per pixel, this will be roughly 4*width. However, for
- // alignment reasons we may wish to increase that.
- static size_t StrideForWidth(unsigned width);
-
- // Allow callers to see the non-virtual function even though we have an
- // override of a virtual one.
- // FIXME(brettw) is this necessary?
- using SkCanvas::clipRect;
-
- private:
- // Helper method used internally by the initialize() methods.
- bool initializeWithDevice(SkDevice* device);
-
- // Disallow copy and assign
- PlatformCanvas(const PlatformCanvas&);
- PlatformCanvas& operator=(const PlatformCanvas&);
+static inline SkCanvas* CreatePlatformCanvas(int width,
+ int height,
+ bool is_opaque) {
+ return CreatePlatformCanvas(width, height, is_opaque, 0, CRASH_ON_FAILURE);
+}
+
+// Takes ownership of the device, so the caller need not call unref().
+SK_API SkCanvas* CreateCanvas(SkDevice* device, OnFailureType failure_type);
+
+static inline SkCanvas* CreateBitmapCanvas(int width,
+ int height,
+ bool is_opaque) {
+ return CreatePlatformCanvas(width, height, is_opaque, 0, CRASH_ON_FAILURE);
+}
+
+static inline SkCanvas* TryCreateBitmapCanvas(int width,
+ int height,
+ bool is_opaque) {
+ return CreatePlatformCanvas(width, height, is_opaque, 0,
+ RETURN_NULL_ON_FAILURE);
+}
+
+class SK_API ScopedPlatformCanvas : public SkAutoTUnref<SkCanvas> {
+ public:
+ ScopedPlatformCanvas(int width, int height, bool is_opaque)
+ : SkAutoTUnref<SkCanvas>(CreatePlatformCanvas(width, height, is_opaque)){}
};
+// Return the stride (length of a line in bytes) for the given width. Because
+// we use 32-bits per pixel, this will be roughly 4*width. However, for
+// alignment reasons we may wish to increase that.
+SK_API size_t PlatformCanvasStrideForWidth(unsigned width);
+
// Returns the SkDevice pointer of the topmost rect with a non-empty
// clip. In practice, this is usually either the top layer or nothing, since
// we usually set the clip to new layers when we make them.
@@ -96,18 +113,6 @@ class SK_API PlatformCanvas : public SkCanvas {
// by the next call to save() or restore().
SK_API SkDevice* GetTopDevice(const SkCanvas& canvas);
-// Creates a canvas with raster bitmap backing.
-// Set is_opaque if you are going to erase the bitmap and not use
-// transparency: this will enable some optimizations.
-SK_API SkCanvas* CreateBitmapCanvas(int width, int height, bool is_opaque);
-
-// Non-crashing version of CreateBitmapCanvas
-// returns NULL if allocation fails for any reason.
-// Use this instead of CreateBitmapCanvas in places that are likely to
-// attempt to allocate very large canvases (therefore likely to fail),
-// and where it is possible to recover gracefully from the failed allocation.
-SK_API SkCanvas* TryCreateBitmapCanvas(int width, int height, bool is_opaque);
-
// Returns true if native platform routines can be used to draw on the
// given canvas. If this function returns false, BeginPlatformPaint will
// return NULL PlatformSurface.
@@ -116,8 +121,11 @@ SK_API bool SupportsPlatformPaint(const SkCanvas* canvas);
// Draws into the a native platform surface, |context|. Forwards to
// DrawToNativeContext on a PlatformDevice instance bound to the top device.
// If no PlatformDevice instance is bound, is a no-operation.
-SK_API void DrawToNativeContext(SkCanvas* canvas, PlatformSurface context,
- int x, int y, const PlatformRect* src_rect);
+SK_API void DrawToNativeContext(SkCanvas* canvas,
+ PlatformSurface context,
+ int x,
+ int y,
+ const PlatformRect* src_rect);
// Sets the opacity of each pixel in the specified region to be opaque.
SK_API void MakeOpaque(SkCanvas* canvas, int x, int y, int width, int height);
diff --git a/skia/ext/platform_canvas_linux.cc b/skia/ext/platform_canvas_linux.cc
deleted file mode 100644
index 9912c16..0000000
--- a/skia/ext/platform_canvas_linux.cc
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "skia/ext/platform_canvas.h"
-
-#include "base/debug/trace_event.h"
-#include "skia/ext/bitmap_platform_device.h"
-#include "skia/ext/platform_device.h"
-#include "third_party/skia/include/core/SkTypes.h"
-
-namespace skia {
-
-PlatformCanvas::PlatformCanvas(int width, int height, bool is_opaque) {
- TRACE_EVENT2("skia", "PlatformCanvas::PlatformCanvas",
- "width", width, "height", height);
- if (!initialize(width, height, is_opaque))
- SK_CRASH();
-}
-
-PlatformCanvas::PlatformCanvas(int width, int height, bool is_opaque,
- uint8_t* data) {
- TRACE_EVENT2("skia", "PlatformCanvas::PlatformCanvas",
- "width", width, "height", height);
- if (!initialize(width, height, is_opaque, data))
- SK_CRASH();
-}
-
-PlatformCanvas::~PlatformCanvas() {
-}
-
-bool PlatformCanvas::initialize(int width, int height, bool is_opaque,
- uint8_t* data) {
- return initializeWithDevice(BitmapPlatformDevice::Create(
- width, height, is_opaque, data));
-}
-
-} // namespace skia
diff --git a/skia/ext/platform_canvas_mac.cc b/skia/ext/platform_canvas_mac.cc
deleted file mode 100644
index d1667c2..0000000
--- a/skia/ext/platform_canvas_mac.cc
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "skia/ext/platform_canvas.h"
-
-#include "base/debug/trace_event.h"
-#include "skia/ext/bitmap_platform_device.h"
-#include "third_party/skia/include/core/SkTypes.h"
-
-namespace skia {
-
-PlatformCanvas::PlatformCanvas(int width, int height, bool is_opaque) {
- TRACE_EVENT2("skia", "PlatformCanvas::PlatformCanvas",
- "width", width, "height", height);
- initialize(width, height, is_opaque);
-}
-
-PlatformCanvas::PlatformCanvas(int width,
- int height,
- bool is_opaque,
- CGContextRef context) {
- TRACE_EVENT2("skia", "PlatformCanvas::PlatformCanvas",
- "width", width, "height", height);
- initialize(context, width, height, is_opaque);
-}
-
-PlatformCanvas::PlatformCanvas(int width,
- int height,
- bool is_opaque,
- uint8_t* data) {
- TRACE_EVENT2("skia", "PlatformCanvas::PlatformCanvas",
- "width", width, "height", height);
- initialize(width, height, is_opaque, data);
-}
-
-PlatformCanvas::~PlatformCanvas() {
-}
-
-bool PlatformCanvas::initialize(int width,
- int height,
- bool is_opaque,
- uint8_t* data) {
- 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));
-}
-
-} // namespace skia
diff --git a/skia/ext/platform_canvas_skia.cc b/skia/ext/platform_canvas_skia.cc
deleted file mode 100644
index 9cd51ac..0000000
--- a/skia/ext/platform_canvas_skia.cc
+++ /dev/null
@@ -1,113 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "skia/ext/platform_canvas.h"
-
-#include "base/debug/trace_event.h"
-#include "skia/ext/bitmap_platform_device.h"
-
-// TODO(reveman): a lot of unnecessary duplication of code from
-// platform_canvas_[win|linux|mac].cc in here. Need to refactor
-// PlatformCanvas to avoid this:
-// http://code.google.com/p/chromium/issues/detail?id=119555
-
-namespace skia {
-
-PlatformCanvas::PlatformCanvas(int width, int height, bool is_opaque) {
- TRACE_EVENT2("skia", "PlatformCanvas::PlatformCanvas",
- "width", width, "height", height);
- if (!initialize(width, height, is_opaque))
- SK_CRASH();
-}
-
-#if defined(WIN32)
-PlatformCanvas::PlatformCanvas(int width,
- int height,
- bool is_opaque,
- HANDLE shared_section) {
- TRACE_EVENT2("skia", "PlatformCanvas::PlatformCanvas",
- "width", width, "height", height);
- if (!initialize(width, height, is_opaque, shared_section))
- SK_CRASH();
-}
-#elif defined(__APPLE__)
-PlatformCanvas::PlatformCanvas(int width, int height, bool is_opaque,
- uint8_t* data) {
- TRACE_EVENT2("skia", "PlatformCanvas::PlatformCanvas",
- "width", width, "height", height);
- if (!initialize(width, height, is_opaque, data))
- SK_CRASH();
-}
-PlatformCanvas::PlatformCanvas(int width,
- int height,
- bool is_opaque,
- CGContextRef context) {
- TRACE_EVENT2("skia", "PlatformCanvas::PlatformCanvas",
- "width", width, "height", height);
- if (!initialize(context, width, height, is_opaque))
- SK_CRASH();
-}
-#elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \
- defined(__sun) || defined(ANDROID)
-PlatformCanvas::PlatformCanvas(int width, int height, bool is_opaque,
- uint8_t* data) {
- TRACE_EVENT2("skia", "PlatformCanvas::PlatformCanvas",
- "width", width, "height", height);
- if (!initialize(width, height, is_opaque, data))
- SK_CRASH();
-}
-#endif
-
-PlatformCanvas::~PlatformCanvas() {
-}
-
-#if defined(WIN32)
-bool PlatformCanvas::initialize(int width,
- int height,
- bool is_opaque,
- HANDLE shared_section) {
- // Use platform specific device for shared_section.
- if (shared_section)
- return initializeWithDevice(BitmapPlatformDevice::Create(
- width, height, is_opaque, shared_section));
-
- return initializeWithDevice(new SkDevice(
- SkBitmap::kARGB_8888_Config, width, height, is_opaque));
-}
-#elif defined(__APPLE__)
-bool PlatformCanvas::initialize(int width,
- int height,
- bool is_opaque,
- uint8_t* data) {
- // Use platform specific device for data.
- if (data)
- return initializeWithDevice(BitmapPlatformDevice::CreateWithData(
- data, width, height, is_opaque));
-
- return initializeWithDevice(new SkDevice(
- SkBitmap::kARGB_8888_Config, 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));
-}
-#elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \
- defined(__sun) || defined(ANDROID)
-bool PlatformCanvas::initialize(int width, int height, bool is_opaque,
- uint8_t* data) {
- // Use platform specific device for data.
- if (data)
- return initializeWithDevice(BitmapPlatformDevice::Create(
- width, height, is_opaque, data));
-
- return initializeWithDevice(new SkDevice(
- SkBitmap::kARGB_8888_Config, width, height, is_opaque));
-}
-#endif
-
-} // namespace skia
diff --git a/skia/ext/platform_canvas_unittest.cc b/skia/ext/platform_canvas_unittest.cc
index 5679721..5d71613 100644
--- a/skia/ext/platform_canvas_unittest.cc
+++ b/skia/ext/platform_canvas_unittest.cc
@@ -194,16 +194,16 @@ const SkScalar kRadius = 2.0;
// regular skia primitives.
TEST(PlatformCanvas, SkLayer) {
// Create the canvas initialized to opaque white.
- PlatformCanvas canvas(16, 16, true);
- canvas.drawColor(SK_ColorWHITE);
+ ScopedPlatformCanvas canvas(16, 16, true);
+ canvas->drawColor(SK_ColorWHITE);
// Make a layer and fill it completely to make sure that the bounds are
// correct.
{
- LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH);
- canvas.drawColor(SK_ColorBLACK);
+ LayerSaver layer(*canvas, kLayerX, kLayerY, kLayerW, kLayerH);
+ canvas->drawColor(SK_ColorBLACK);
}
- EXPECT_TRUE(VerifyBlackRect(canvas, kLayerX, kLayerY, kLayerW, kLayerH));
+ EXPECT_TRUE(VerifyBlackRect(*canvas, kLayerX, kLayerY, kLayerW, kLayerH));
}
#if !defined(USE_AURA) // http://crbug.com/154358
@@ -211,26 +211,26 @@ TEST(PlatformCanvas, SkLayer) {
// Test native clipping.
TEST(PlatformCanvas, ClipRegion) {
// Initialize a white canvas
- PlatformCanvas canvas(16, 16, true);
- canvas.drawColor(SK_ColorWHITE);
- EXPECT_TRUE(VerifyCanvasColor(canvas, SK_ColorWHITE));
+ ScopedPlatformCanvas canvas(16, 16, true);
+ canvas->drawColor(SK_ColorWHITE);
+ EXPECT_TRUE(VerifyCanvasColor(*canvas, SK_ColorWHITE));
// Test that initially the canvas has no clip region, by filling it
// with a black rectangle.
// Note: Don't use LayerSaver, since internally it sets a clip region.
- DrawNativeRect(canvas, 0, 0, 16, 16);
- EXPECT_TRUE(VerifyCanvasColor(canvas, SK_ColorBLACK));
+ DrawNativeRect(*canvas, 0, 0, 16, 16);
+ EXPECT_TRUE(VerifyCanvasColor(*canvas, SK_ColorBLACK));
// Test that intersecting disjoint clip rectangles sets an empty clip region
- canvas.drawColor(SK_ColorWHITE);
- EXPECT_TRUE(VerifyCanvasColor(canvas, SK_ColorWHITE));
+ canvas->drawColor(SK_ColorWHITE);
+ EXPECT_TRUE(VerifyCanvasColor(*canvas, SK_ColorWHITE));
{
- LayerSaver layer(canvas, 0, 0, 16, 16);
- AddClip(canvas, 2, 3, 4, 5);
- AddClip(canvas, 4, 9, 10, 10);
- DrawNativeRect(canvas, 0, 0, 16, 16);
+ LayerSaver layer(*canvas, 0, 0, 16, 16);
+ AddClip(*canvas, 2, 3, 4, 5);
+ AddClip(*canvas, 4, 9, 10, 10);
+ DrawNativeRect(*canvas, 0, 0, 16, 16);
}
- EXPECT_TRUE(VerifyCanvasColor(canvas, SK_ColorWHITE));
+ EXPECT_TRUE(VerifyCanvasColor(*canvas, SK_ColorWHITE));
}
#endif // !defined(USE_AURA)
@@ -238,58 +238,58 @@ TEST(PlatformCanvas, ClipRegion) {
// Test the layers get filled properly by native rendering.
TEST(PlatformCanvas, FillLayer) {
// Create the canvas initialized to opaque white.
- PlatformCanvas canvas(16, 16, true);
+ ScopedPlatformCanvas canvas(16, 16, true);
// Make a layer and fill it completely to make sure that the bounds are
// correct.
- canvas.drawColor(SK_ColorWHITE);
+ canvas->drawColor(SK_ColorWHITE);
{
- LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH);
- DrawNativeRect(canvas, 0, 0, 100, 100);
+ LayerSaver layer(*canvas, kLayerX, kLayerY, kLayerW, kLayerH);
+ DrawNativeRect(*canvas, 0, 0, 100, 100);
#if defined(OS_WIN)
- MakeOpaque(&canvas, 0, 0, 100, 100);
+ MakeOpaque(canvas, 0, 0, 100, 100);
#endif
}
- EXPECT_TRUE(VerifyBlackRect(canvas, kLayerX, kLayerY, kLayerW, kLayerH));
+ EXPECT_TRUE(VerifyBlackRect(*canvas, kLayerX, kLayerY, kLayerW, kLayerH));
// Make a layer and fill it partially to make sure the translation is correct.
- canvas.drawColor(SK_ColorWHITE);
+ canvas->drawColor(SK_ColorWHITE);
{
- LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH);
- DrawNativeRect(canvas, kInnerX, kInnerY, kInnerW, kInnerH);
+ LayerSaver layer(*canvas, kLayerX, kLayerY, kLayerW, kLayerH);
+ DrawNativeRect(*canvas, kInnerX, kInnerY, kInnerW, kInnerH);
#if defined(OS_WIN)
- MakeOpaque(&canvas, kInnerX, kInnerY, kInnerW, kInnerH);
+ MakeOpaque(canvas, kInnerX, kInnerY, kInnerW, kInnerH);
#endif
}
- EXPECT_TRUE(VerifyBlackRect(canvas, kInnerX, kInnerY, kInnerW, kInnerH));
+ EXPECT_TRUE(VerifyBlackRect(*canvas, kInnerX, kInnerY, kInnerW, kInnerH));
// Add a clip on the layer and fill to make sure clip is correct.
- canvas.drawColor(SK_ColorWHITE);
+ canvas->drawColor(SK_ColorWHITE);
{
- LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH);
- canvas.save();
- AddClip(canvas, kInnerX, kInnerY, kInnerW, kInnerH);
- DrawNativeRect(canvas, 0, 0, 100, 100);
+ LayerSaver layer(*canvas, kLayerX, kLayerY, kLayerW, kLayerH);
+ canvas->save();
+ AddClip(*canvas, kInnerX, kInnerY, kInnerW, kInnerH);
+ DrawNativeRect(*canvas, 0, 0, 100, 100);
#if defined(OS_WIN)
- MakeOpaque(&canvas, kInnerX, kInnerY, kInnerW, kInnerH);
+ MakeOpaque(canvas, kInnerX, kInnerY, kInnerW, kInnerH);
#endif
- canvas.restore();
+ canvas->restore();
}
- EXPECT_TRUE(VerifyBlackRect(canvas, kInnerX, kInnerY, kInnerW, kInnerH));
+ EXPECT_TRUE(VerifyBlackRect(*canvas, kInnerX, kInnerY, kInnerW, kInnerH));
// Add a clip and then make the layer to make sure the clip is correct.
- canvas.drawColor(SK_ColorWHITE);
- canvas.save();
- AddClip(canvas, kInnerX, kInnerY, kInnerW, kInnerH);
+ canvas->drawColor(SK_ColorWHITE);
+ canvas->save();
+ AddClip(*canvas, kInnerX, kInnerY, kInnerW, kInnerH);
{
- LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH);
- DrawNativeRect(canvas, 0, 0, 100, 100);
+ LayerSaver layer(*canvas, kLayerX, kLayerY, kLayerW, kLayerH);
+ DrawNativeRect(*canvas, 0, 0, 100, 100);
#if defined(OS_WIN)
- MakeOpaque(&canvas, 0, 0, 100, 100);
+ MakeOpaque(canvas, 0, 0, 100, 100);
#endif
}
- canvas.restore();
- EXPECT_TRUE(VerifyBlackRect(canvas, kInnerX, kInnerY, kInnerW, kInnerH));
+ canvas->restore();
+ EXPECT_TRUE(VerifyBlackRect(*canvas, kInnerX, kInnerY, kInnerW, kInnerH));
}
#if !defined(USE_AURA) // http://crbug.com/154358
@@ -297,98 +297,98 @@ TEST(PlatformCanvas, FillLayer) {
// Test that translation + make layer works properly.
TEST(PlatformCanvas, TranslateLayer) {
// Create the canvas initialized to opaque white.
- PlatformCanvas canvas(16, 16, true);
+ ScopedPlatformCanvas canvas(16, 16, true);
// Make a layer and fill it completely to make sure that the bounds are
// correct.
- canvas.drawColor(SK_ColorWHITE);
- canvas.save();
- canvas.translate(1, 1);
+ canvas->drawColor(SK_ColorWHITE);
+ canvas->save();
+ canvas->translate(1, 1);
{
- LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH);
- DrawNativeRect(canvas, 0, 0, 100, 100);
+ LayerSaver layer(*canvas, kLayerX, kLayerY, kLayerW, kLayerH);
+ DrawNativeRect(*canvas, 0, 0, 100, 100);
#if defined(OS_WIN)
- MakeOpaque(&canvas, 0, 0, 100, 100);
+ MakeOpaque(canvas, 0, 0, 100, 100);
#endif
}
- canvas.restore();
- EXPECT_TRUE(VerifyBlackRect(canvas, kLayerX + 1, kLayerY + 1,
+ canvas->restore();
+ EXPECT_TRUE(VerifyBlackRect(*canvas, kLayerX + 1, kLayerY + 1,
kLayerW, kLayerH));
// Translate then make the layer.
- canvas.drawColor(SK_ColorWHITE);
- canvas.save();
- canvas.translate(1, 1);
+ canvas->drawColor(SK_ColorWHITE);
+ canvas->save();
+ canvas->translate(1, 1);
{
- LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH);
- DrawNativeRect(canvas, kInnerX, kInnerY, kInnerW, kInnerH);
+ LayerSaver layer(*canvas, kLayerX, kLayerY, kLayerW, kLayerH);
+ DrawNativeRect(*canvas, kInnerX, kInnerY, kInnerW, kInnerH);
#if defined(OS_WIN)
- MakeOpaque(&canvas, kInnerX, kInnerY, kInnerW, kInnerH);
+ MakeOpaque(canvas, kInnerX, kInnerY, kInnerW, kInnerH);
#endif
}
- canvas.restore();
- EXPECT_TRUE(VerifyBlackRect(canvas, kInnerX + 1, kInnerY + 1,
+ canvas->restore();
+ EXPECT_TRUE(VerifyBlackRect(*canvas, kInnerX + 1, kInnerY + 1,
kInnerW, kInnerH));
// Make the layer then translate.
- canvas.drawColor(SK_ColorWHITE);
- canvas.save();
+ canvas->drawColor(SK_ColorWHITE);
+ canvas->save();
{
- LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH);
- canvas.translate(1, 1);
- DrawNativeRect(canvas, kInnerX, kInnerY, kInnerW, kInnerH);
+ LayerSaver layer(*canvas, kLayerX, kLayerY, kLayerW, kLayerH);
+ canvas->translate(1, 1);
+ DrawNativeRect(*canvas, kInnerX, kInnerY, kInnerW, kInnerH);
#if defined(OS_WIN)
- MakeOpaque(&canvas, kInnerX, kInnerY, kInnerW, kInnerH);
+ MakeOpaque(canvas, kInnerX, kInnerY, kInnerW, kInnerH);
#endif
}
- canvas.restore();
- EXPECT_TRUE(VerifyBlackRect(canvas, kInnerX + 1, kInnerY + 1,
+ canvas->restore();
+ EXPECT_TRUE(VerifyBlackRect(*canvas, kInnerX + 1, kInnerY + 1,
kInnerW, kInnerH));
// Translate both before and after, and have a clip.
- canvas.drawColor(SK_ColorWHITE);
- canvas.save();
- canvas.translate(1, 1);
+ canvas->drawColor(SK_ColorWHITE);
+ canvas->save();
+ canvas->translate(1, 1);
{
- LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH);
- canvas.drawColor(SK_ColorWHITE);
- canvas.translate(1, 1);
- AddClip(canvas, kInnerX + 1, kInnerY + 1, kInnerW - 1, kInnerH - 1);
- DrawNativeRect(canvas, 0, 0, 100, 100);
+ LayerSaver layer(*canvas, kLayerX, kLayerY, kLayerW, kLayerH);
+ canvas->drawColor(SK_ColorWHITE);
+ canvas->translate(1, 1);
+ AddClip(*canvas, kInnerX + 1, kInnerY + 1, kInnerW - 1, kInnerH - 1);
+ DrawNativeRect(*canvas, 0, 0, 100, 100);
#if defined(OS_WIN)
- MakeOpaque(&canvas, kLayerX, kLayerY, kLayerW, kLayerH);
+ MakeOpaque(canvas, kLayerX, kLayerY, kLayerW, kLayerH);
#endif
}
- canvas.restore();
- EXPECT_TRUE(VerifyBlackRect(canvas, kInnerX + 3, kInnerY + 3,
+ canvas->restore();
+ EXPECT_TRUE(VerifyBlackRect(*canvas, kInnerX + 3, kInnerY + 3,
kInnerW - 1, kInnerH - 1));
// TODO(dglazkov): Figure out why this fails on Mac (antialiased clipping?),
// modify test and remove this guard.
#if !defined(OS_MACOSX)
// Translate both before and after, and have a path clip.
- canvas.drawColor(SK_ColorWHITE);
- canvas.save();
- canvas.translate(1, 1);
+ canvas->drawColor(SK_ColorWHITE);
+ canvas->save();
+ canvas->translate(1, 1);
{
- LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH);
- canvas.drawColor(SK_ColorWHITE);
- canvas.translate(1, 1);
+ LayerSaver layer(*canvas, kLayerX, kLayerY, kLayerW, kLayerH);
+ canvas->drawColor(SK_ColorWHITE);
+ canvas->translate(1, 1);
SkPath path;
SkRect rect;
rect.iset(kInnerX - 1, kInnerY - 1,
kInnerX + kInnerW, kInnerY + kInnerH);
path.addRoundRect(rect, kRadius, kRadius);
- canvas.clipPath(path);
+ canvas->clipPath(path);
- DrawNativeRect(canvas, 0, 0, 100, 100);
+ DrawNativeRect(*canvas, 0, 0, 100, 100);
#if defined(OS_WIN)
- MakeOpaque(&canvas, kLayerX, kLayerY, kLayerW, kLayerH);
+ MakeOpaque(canvas, kLayerX, kLayerY, kLayerW, kLayerH);
#endif
}
- canvas.restore();
- EXPECT_TRUE(VerifyRoundedRect(canvas, SK_ColorWHITE, SK_ColorBLACK,
+ canvas->restore();
+ EXPECT_TRUE(VerifyRoundedRect(*canvas, SK_ColorWHITE, SK_ColorBLACK,
kInnerX + 1, kInnerY + 1, kInnerW, kInnerH));
#endif
}
diff --git a/skia/ext/platform_canvas_win.cc b/skia/ext/platform_canvas_win.cc
deleted file mode 100644
index 7b9a787..0000000
--- a/skia/ext/platform_canvas_win.cc
+++ /dev/null
@@ -1,40 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include <windows.h>
-#include <psapi.h>
-
-#include "base/debug/trace_event.h"
-#include "skia/ext/bitmap_platform_device_win.h"
-#include "skia/ext/platform_canvas.h"
-
-namespace skia {
-
-PlatformCanvas::PlatformCanvas(int width, int height, bool is_opaque) {
- TRACE_EVENT2("skia", "PlatformCanvas::PlatformCanvas",
- "width", width, "height", height);
- initialize(width, height, is_opaque, NULL);
-}
-
-PlatformCanvas::PlatformCanvas(int width,
- int height,
- bool is_opaque,
- HANDLE shared_section) {
- TRACE_EVENT2("skia", "PlatformCanvas::PlatformCanvas",
- "width", width, "height", height);
- initialize(width, height, is_opaque, shared_section);
-}
-
-PlatformCanvas::~PlatformCanvas() {
-}
-
-bool PlatformCanvas::initialize(int width,
- int height,
- bool is_opaque,
- HANDLE shared_section) {
- return initializeWithDevice(BitmapPlatformDevice::Create(
- width, height, is_opaque, shared_section));
-}
-
-} // namespace skia
diff --git a/skia/ext/vector_canvas_unittest.cc b/skia/ext/vector_canvas_unittest.cc
index d5f7f41..8efbcdb 100644
--- a/skia/ext/vector_canvas_unittest.cc
+++ b/skia/ext/vector_canvas_unittest.cc
@@ -392,7 +392,7 @@ class VectorCanvasTest : public ImageTest {
bitmap_ = new Bitmap(*context_, size_, size_);
vcanvas_ = new VectorCanvas(VectorPlatformDeviceEmf::CreateDevice(
size_, size_, true, context_->context()));
- pcanvas_ = new PlatformCanvas(size_, size_, false);
+ pcanvas_ = CreatePlatformCanvas(size_, size_, false);
// Clear white.
vcanvas_->drawARGB(255, 255, 255, 255, SkXfermode::kSrc_Mode);
diff --git a/skia/skia.gyp b/skia/skia.gyp
index 37d6c2e..e4c8063 100644
--- a/skia/skia.gyp
+++ b/skia/skia.gyp
@@ -170,10 +170,6 @@
'ext/SkThread_chrome.cc',
'ext/platform_canvas.cc',
'ext/platform_canvas.h',
- 'ext/platform_canvas_linux.cc',
- 'ext/platform_canvas_mac.cc',
- 'ext/platform_canvas_skia.cc',
- 'ext/platform_canvas_win.cc',
'ext/platform_device.cc',
'ext/platform_device.h',
'ext/platform_device_linux.cc',
@@ -378,15 +374,6 @@
'../third_party/skia/src/ports/SkFontHost_FreeType_common.cpp',
],
}],
- [ 'use_aura == 1 and use_canvas_skia == 1', {
- 'sources/': [
- ['exclude', 'ext/platform_canvas_mac\\.cc$'],
- ['exclude', 'ext/platform_canvas_linux\\.cc$'],
- ['exclude', 'ext/platform_canvas_win\\.cc$'],
- ],
- }, { # use_aura == 0 and use_canvas_skia == 1
- 'sources/': [ ['exclude', 'ext/platform_canvas_skia\\.cc$'] ],
- }],
[ 'toolkit_uses_gtk == 1', {
'dependencies': [
'../build/linux/system.gyp:gdk',
@@ -428,7 +415,6 @@
],
'sources/': [
['include', 'ext/platform_device_linux\\.cc$'],
- ['include', 'ext/platform_canvas_linux\\.cc$'],
['exclude', '../third_party/skia/src/pdf/'],
],
'sources!': [
@@ -446,7 +432,6 @@
[ '_toolset=="host" and host_os=="linux"', {
'sources': [
'ext/platform_device_linux.cc',
- 'ext/platform_canvas_linux.cc',
],
}],
],