summaryrefslogtreecommitdiffstats
path: root/skia
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-06 05:26:00 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-06 05:26:00 +0000
commit8a7ef121c533b8f26199ce187982b327015b29e7 (patch)
tree1f9aaf05d33fa09f1b56bade75450040df17c9c6 /skia
parentd0d61e7aac0754552bd669d871882bd0390a60e5 (diff)
downloadchromium_src-8a7ef121c533b8f26199ce187982b327015b29e7.zip
chromium_src-8a7ef121c533b8f26199ce187982b327015b29e7.tar.gz
chromium_src-8a7ef121c533b8f26199ce187982b327015b29e7.tar.bz2
Wire up missing functionality in BitmapPlatformContext to allow the creation of a skia::PlatformCanvas
from a CGContextRef. TEST=test_shell_tests, try (mac,win,linux) Original review=http://codereview.chromium.org/6064007/ Patch by sjl@chromium.org git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70596 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia')
-rw-r--r--skia/ext/platform_canvas.cc9
-rw-r--r--skia/ext/platform_canvas.h4
-rw-r--r--skia/ext/platform_canvas_linux.cc10
-rw-r--r--skia/ext/platform_canvas_mac.cc20
-rw-r--r--skia/ext/platform_canvas_win.cc12
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() {