summaryrefslogtreecommitdiffstats
path: root/skia/ext
diff options
context:
space:
mode:
authorpiman@chromium.org <piman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-05 19:05:07 +0000
committerpiman@chromium.org <piman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-05 19:05:07 +0000
commitbe172ba8194e48970d90e9d873160b259df69b96 (patch)
tree677a1fedc8a836a42de1dba22d8c0663173a0f96 /skia/ext
parent2c572bd1d4eec134ae40e00adbfa2c9d3d1ff1e7 (diff)
downloadchromium_src-be172ba8194e48970d90e9d873160b259df69b96.zip
chromium_src-be172ba8194e48970d90e9d873160b259df69b96.tar.gz
chromium_src-be172ba8194e48970d90e9d873160b259df69b96.tar.bz2
Allow CanvasSkia to bind to an existing SkCanvas.
BUG=None TEST=None Review URL: http://codereview.chromium.org/8122013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@104146 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia/ext')
-rw-r--r--skia/ext/canvas_paint_common.h18
-rw-r--r--skia/ext/canvas_paint_gtk.h10
-rw-r--r--skia/ext/canvas_paint_mac.h17
-rw-r--r--skia/ext/canvas_paint_wayland.h11
-rw-r--r--skia/ext/canvas_paint_win.h15
-rw-r--r--skia/ext/canvas_paint_x.h12
6 files changed, 58 insertions, 25 deletions
diff --git a/skia/ext/canvas_paint_common.h b/skia/ext/canvas_paint_common.h
new file mode 100644
index 0000000..6eed3f4
--- /dev/null
+++ b/skia/ext/canvas_paint_common.h
@@ -0,0 +1,18 @@
+// 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.
+
+#ifndef SKIA_EXT_CANVAS_PAINT_COMMON_H_
+#define SKIA_EXT_CANVAS_PAINT_COMMON_H_
+#pragma once
+
+namespace skia {
+class PlatformCanvas;
+
+template<class T> inline PlatformCanvas* GetPlatformCanvas(T* t) {
+ return t;
+}
+
+} // namespace skia
+
+#endif // SKIA_EXT_CANVAS_PAINT_COMMON_H_
diff --git a/skia/ext/canvas_paint_gtk.h b/skia/ext/canvas_paint_gtk.h
index fca12ca..ade49af 100644
--- a/skia/ext/canvas_paint_gtk.h
+++ b/skia/ext/canvas_paint_gtk.h
@@ -8,6 +8,7 @@
#pragma once
#include "base/logging.h"
+#include "skia/ext/canvas_paint_common.h"
#include "skia/ext/platform_canvas.h"
#include <gdk/gdk.h>
@@ -39,7 +40,7 @@ class CanvasPaintT : public T {
virtual ~CanvasPaintT() {
if (!is_empty()) {
- T::restoreToCount(1);
+ GetPlatformCanvas(this)->restoreToCount(1);
// Blit the dirty rect to the window.
CHECK(window_);
@@ -83,16 +84,17 @@ class CanvasPaintT : public T {
private:
void init(bool opaque) {
GdkRectangle bounds = rectangle();
- if (!T::initialize(bounds.width, bounds.height, opaque, NULL)) {
+ PlatformCanvas* canvas = GetPlatformCanvas(this);
+ if (!canvas->initialize(bounds.width, bounds.height, opaque, NULL)) {
// Cause a deliberate crash;
CHECK(false);
}
// Need to translate so that the dirty region appears at the origin of the
// surface.
- T::translate(-SkIntToScalar(bounds.x), -SkIntToScalar(bounds.y));
+ canvas->translate(-SkIntToScalar(bounds.x), -SkIntToScalar(bounds.y));
- context_ = BeginPlatformPaint(this);
+ context_ = BeginPlatformPaint(canvas);
}
cairo_t* context_;
diff --git a/skia/ext/canvas_paint_mac.h b/skia/ext/canvas_paint_mac.h
index c4f45b2..d679116 100644
--- a/skia/ext/canvas_paint_mac.h
+++ b/skia/ext/canvas_paint_mac.h
@@ -1,5 +1,5 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// 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.
@@ -7,6 +7,7 @@
#define SKIA_EXT_CANVAS_PAINT_MAC_H_
#pragma once
+#include "skia/ext/canvas_paint_common.h"
#include "skia/ext/platform_canvas.h"
#import <Cocoa/Cocoa.h>
@@ -36,7 +37,7 @@ class CanvasPaintT : public T {
virtual ~CanvasPaintT() {
if (!is_empty()) {
- T::restoreToCount(1);
+ GetPlatformCanvas(this)->restoreToCount(1);
// Blit the dirty rect to the current context.
CGImageRef image = CGBitmapContextCreateImage(context_);
@@ -81,18 +82,20 @@ class CanvasPaintT : public T {
private:
void init(bool opaque) {
- if (!T::initialize(rectangle_.size.width, rectangle_.size.height,
- opaque, NULL)) {
+ PlatformCanvas* canvas = GetPlatformCanvas(this);
+ if (!canvas->initialize(rectangle_.size.width,
+ rectangle_.size.height,
+ opaque, NULL)) {
// Cause a deliberate crash;
*(volatile char*) 0 = 0;
}
// Need to translate so that the dirty region appears at the origin of the
// surface.
- T::translate(-SkDoubleToScalar(rectangle_.origin.x),
- -SkDoubleToScalar(rectangle_.origin.y));
+ canvas->translate(-SkDoubleToScalar(rectangle_.origin.x),
+ -SkDoubleToScalar(rectangle_.origin.y));
- context_ = GetBitmapContext(GetTopDevice(*this));
+ context_ = GetBitmapContext(GetTopDevice(*canvas));
}
CGContext* context_;
diff --git a/skia/ext/canvas_paint_wayland.h b/skia/ext/canvas_paint_wayland.h
index 2afdb01..eca3665 100644
--- a/skia/ext/canvas_paint_wayland.h
+++ b/skia/ext/canvas_paint_wayland.h
@@ -7,6 +7,7 @@
#pragma once
#include "base/logging.h"
+#include "skia/ext/canvas_paint_common.h"
#include "skia/ext/platform_canvas.h"
namespace skia {
@@ -39,7 +40,8 @@ class CanvasPaintT : public T {
virtual ~CanvasPaintT() {
if (!is_empty()) {
- T::restoreToCount(1);
+ PlatformCanvas* canvas = GetPlatformCanvas(this);
+ canvas->restoreToCount(1);
// Blit the dirty rect to the window.
CHECK(cairo_window_surface_);
@@ -79,16 +81,17 @@ class CanvasPaintT : public T {
private:
void init(bool opaque) {
- if (!T::initialize(region_->width, region_->height, opaque, NULL)) {
+ PlatformCanvas* canvas = GetPlatformCanvas(this);
+ if (!canvas->initialize(region_->width, region_->height, opaque, NULL)) {
// Cause a deliberate crash;
CHECK(false);
}
// Need to translate so that the dirty region appears at the origin of the
// surface.
- T::translate(-SkIntToScalar(region_->x), -SkIntToScalar(region_->y));
+ canvas->translate(-SkIntToScalar(region_->x), -SkIntToScalar(region_->y));
- context_ = BeginPlatformPaint(this);
+ context_ = BeginPlatformPaint(canvas);
}
cairo_t* context_;
diff --git a/skia/ext/canvas_paint_win.h b/skia/ext/canvas_paint_win.h
index 5fe22fc..9610025 100644
--- a/skia/ext/canvas_paint_win.h
+++ b/skia/ext/canvas_paint_win.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// 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.
@@ -6,6 +6,7 @@
#define SKIA_EXT_CANVAS_PAINT_WIN_H_
#pragma once
+#include "skia/ext/canvas_paint_common.h"
#include "skia/ext/platform_canvas.h"
namespace skia {
@@ -60,9 +61,10 @@ class CanvasPaintT : public T {
virtual ~CanvasPaintT() {
if (!isEmpty()) {
- restoreToCount(1);
+ PlatformCanvas* canvas = GetPlatformCanvas(this);
+ canvas->restoreToCount(1);
// Commit the drawing to the screen
- skia::DrawToNativeContext(this, paint_dc_, ps_.rcPaint.left,
+ skia::DrawToNativeContext(canvas, paint_dc_, ps_.rcPaint.left,
ps_.rcPaint.top, NULL);
}
if (for_paint_)
@@ -100,21 +102,22 @@ class CanvasPaintT : public T {
}
void init(bool opaque) {
+ PlatformCanvas* canvas = GetPlatformCanvas(this);
// FIXME(brettw) for ClearType, we probably want to expand the bounds of
// painting by one pixel so that the boundaries will be correct (ClearType
// text can depend on the adjacent pixel). Then we would paint just the
// inset pixels to the screen.
const int width = ps_.rcPaint.right - ps_.rcPaint.left;
const int height = ps_.rcPaint.bottom - ps_.rcPaint.top;
- if (!initialize(width, height, opaque, NULL)) {
+ if (!canvas->initialize(width, height, opaque, NULL)) {
// Cause a deliberate crash;
*(char*) 0 = 0;
}
// This will bring the canvas into the screen coordinate system for the
// dirty rect
- translate(SkIntToScalar(-ps_.rcPaint.left),
- SkIntToScalar(-ps_.rcPaint.top));
+ canvas->translate(SkIntToScalar(-ps_.rcPaint.left),
+ SkIntToScalar(-ps_.rcPaint.top));
}
// If true, this canvas was created for a BeginPaint.
diff --git a/skia/ext/canvas_paint_x.h b/skia/ext/canvas_paint_x.h
index a9f51d2..e8e3c68 100644
--- a/skia/ext/canvas_paint_x.h
+++ b/skia/ext/canvas_paint_x.h
@@ -7,6 +7,7 @@
#pragma once
#include "base/logging.h"
+#include "skia/ext/canvas_paint_common.h"
#include "skia/ext/platform_canvas.h"
#include <cairo/cairo.h>
@@ -41,7 +42,8 @@ class CanvasPaintT : public T {
virtual ~CanvasPaintT() {
if (!is_empty()) {
- T::restoreToCount(1);
+ PlatformCanvas* canvas = GetPlatformCanvas(this);
+ canvas->restoreToCount(1);
// Blit the dirty rect to the window.
CHECK(cairo_window_surface_);
@@ -81,16 +83,18 @@ class CanvasPaintT : public T {
private:
void init(bool opaque) {
- if (!T::initialize(region_->width, region_->height, opaque, NULL)) {
+ PlatformCanvas* canvas = GetPlatformCanvas(this);
+ if (!canvas->initialize(region_->width, region_->height, opaque, NULL)) {
// Cause a deliberate crash;
CHECK(false);
}
// Need to translate so that the dirty region appears at the origin of the
// surface.
- T::translate(-SkDoubleToScalar(region_->x), -SkDoubleToScalar(region_->y));
+ canvas->translate(-SkDoubleToScalar(region_->x),
+ -SkDoubleToScalar(region_->y));
- context_ = BeginPlatformPaint(this);
+ context_ = BeginPlatformPaint(canvas);
}
cairo_t* context_;