summaryrefslogtreecommitdiffstats
path: root/skia/ext
diff options
context:
space:
mode:
authorvandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-21 06:02:41 +0000
committervandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-21 06:02:41 +0000
commitd03154499968cd317de9fc722ed2b39563bf3265 (patch)
tree0fb574bcd9e01309badae3090af29ace9ccad5ba /skia/ext
parent89b5fab4ba1bdfe3a958e3b94a1860bfdeed1e3b (diff)
downloadchromium_src-d03154499968cd317de9fc722ed2b39563bf3265.zip
chromium_src-d03154499968cd317de9fc722ed2b39563bf3265.tar.gz
chromium_src-d03154499968cd317de9fc722ed2b39563bf3265.tar.bz2
Unfork VectorPlatformCanvas.
Unfork VectorPlatformCanvas by making NativeMetafile know how to create an appropriate VectorPlatformDevice. This will also be useful when we have multiple NativeMetafile implemenations (each requiring a different VectorPlatformDevices). BUG=NONE TEST=NONE Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=78662 Reverted: http://src.chromium.org/viewvc/chrome?view=rev&revision=78663 Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=78812 Reverted: http://src.chromium.org/viewvc/chrome?view=rev&revision=78815 Review URL: http://codereview.chromium.org/6665046 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78859 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia/ext')
-rw-r--r--skia/ext/vector_canvas.cc10
-rw-r--r--skia/ext/vector_canvas.h25
-rw-r--r--skia/ext/vector_canvas_linux.cc28
-rw-r--r--skia/ext/vector_canvas_unittest.cc7
-rw-r--r--skia/ext/vector_canvas_win.cc30
-rw-r--r--skia/ext/vector_platform_device_linux.cc6
-rw-r--r--skia/ext/vector_platform_device_linux.h4
-rw-r--r--skia/ext/vector_platform_device_win.cc5
-rw-r--r--skia/ext/vector_platform_device_win.h6
9 files changed, 24 insertions, 97 deletions
diff --git a/skia/ext/vector_canvas.cc b/skia/ext/vector_canvas.cc
index 851da79..216a2ee 100644
--- a/skia/ext/vector_canvas.cc
+++ b/skia/ext/vector_canvas.cc
@@ -4,13 +4,13 @@
#include "skia/ext/vector_canvas.h"
-namespace skia {
+#include "skia/ext/vector_platform_device.h"
-VectorCanvas::VectorCanvas()
- : PlatformCanvas(SkNEW(VectorPlatformDeviceFactory)) {
-}
+namespace skia {
-VectorCanvas::VectorCanvas(SkDeviceFactory* factory) : PlatformCanvas(factory) {
+VectorCanvas::VectorCanvas(PlatformDevice* device)
+ : PlatformCanvas(device->getDeviceFactory()) {
+ setDevice(device)->unref(); // Created with refcount 1, and setDevice refs.
}
VectorCanvas::~VectorCanvas() {
diff --git a/skia/ext/vector_canvas.h b/skia/ext/vector_canvas.h
index 4f8bc7a..4b4419d 100644
--- a/skia/ext/vector_canvas.h
+++ b/skia/ext/vector_canvas.h
@@ -7,38 +7,21 @@
#pragma once
#include "skia/ext/platform_canvas.h"
-#include "skia/ext/vector_platform_device.h"
-
-#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
-typedef struct _cairo cairo_t;
-#endif
namespace skia {
+class PlatformDevice;
+
// This class is a specialization of the regular PlatformCanvas. It is designed
// to work with a VectorDevice to manage platform-specific drawing. It allows
// using both Skia operations and platform-specific operations. It *doesn't*
// support reading back from the bitmap backstore since it is not used.
class SK_API VectorCanvas : public PlatformCanvas {
public:
- VectorCanvas();
- explicit VectorCanvas(SkDeviceFactory* factory);
-#if defined(WIN32)
- VectorCanvas(HDC dc, int width, int height);
-#elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
- // Caller owns |context|. Ownership is not transferred.
- VectorCanvas(cairo_t* context, int width, int height);
-#endif
+ // Ownership of |device| is transfered to VectorCanvas.
+ explicit VectorCanvas(PlatformDevice* device);
virtual ~VectorCanvas();
- // For two-part init, call if you use the no-argument constructor above
-#if defined(WIN32)
- bool initialize(HDC context, int width, int height);
-#elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
- // Ownership of |context| is not transferred.
- bool initialize(cairo_t* context, int width, int height);
-#endif
-
virtual SkBounder* setBounder(SkBounder* bounder);
virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter);
diff --git a/skia/ext/vector_canvas_linux.cc b/skia/ext/vector_canvas_linux.cc
deleted file mode 100644
index aff4fbe..0000000
--- a/skia/ext/vector_canvas_linux.cc
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright (c) 2009 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/vector_canvas.h"
-
-#include "skia/ext/vector_platform_device.h"
-
-namespace skia {
-
-VectorCanvas::VectorCanvas(cairo_t* context, int width, int height) {
- bool initialized = initialize(context, width, height);
-
- SkASSERT(initialized);
-}
-
-bool VectorCanvas::initialize(cairo_t* context, int width, int height) {
- SkDevice* device = VectorPlatformDeviceFactory::CreateDevice(context, width,
- height, true);
- 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/vector_canvas_unittest.cc b/skia/ext/vector_canvas_unittest.cc
index 0266c81..1066c0c 100644
--- a/skia/ext/vector_canvas_unittest.cc
+++ b/skia/ext/vector_canvas_unittest.cc
@@ -14,6 +14,7 @@
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "skia/ext/vector_canvas.h"
+#include "skia/ext/vector_platform_device.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/effects/SkDashPathEffect.h"
#include "ui/gfx/codec/png_codec.h"
@@ -386,7 +387,8 @@ class VectorCanvasTest : public ImageTest {
size_ = size;
context_ = new Context();
bitmap_ = new Bitmap(*context_, size_, size_);
- vcanvas_ = new VectorCanvas(context_->context(), size_, size_);
+ vcanvas_ = new VectorCanvas(VectorPlatformDeviceFactory::CreateDevice(
+ size_, size_, true, context_->context()));
pcanvas_ = new PlatformCanvas(size_, size_, false);
// Clear white.
@@ -452,7 +454,8 @@ TEST_F(VectorCanvasTest, Uninitialized) {
context_ = new Context();
bitmap_ = new Bitmap(*context_, size_, size_);
- vcanvas_ = new VectorCanvas(context_->context(), size_, size_);
+ vcanvas_ = new VectorCanvas(VectorPlatformDeviceFactory::CreateDevice(
+ size_, size_, true, context_->context()));
pcanvas_ = new PlatformCanvas(size_, size_, false);
// VectorCanvas default initialization is black.
diff --git a/skia/ext/vector_canvas_win.cc b/skia/ext/vector_canvas_win.cc
deleted file mode 100644
index 400b2a4..0000000
--- a/skia/ext/vector_canvas_win.cc
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright (c) 2006-2009 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/vector_canvas.h"
-
-#include "skia/ext/bitmap_platform_device.h"
-#include "skia/ext/vector_platform_device.h"
-
-namespace skia {
-
-VectorCanvas::VectorCanvas(HDC dc, int width, int height) {
- bool initialized = initialize(dc, width, height);
- if (!initialized)
- __debugbreak();
-}
-
-bool VectorCanvas::initialize(HDC context, int width, int height) {
- SkDevice* device = VectorPlatformDeviceFactory::CreateDevice(width, height,
- true, context);
- 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/vector_platform_device_linux.cc b/skia/ext/vector_platform_device_linux.cc
index 068ae89..bc6a41e 100644
--- a/skia/ext/vector_platform_device_linux.cc
+++ b/skia/ext/vector_platform_device_linux.cc
@@ -78,9 +78,9 @@ SkDevice* VectorPlatformDeviceFactory::newDevice(SkCanvas* ignored,
}
// static
-SkDevice* VectorPlatformDeviceFactory::CreateDevice(cairo_t* context,
- int width, int height,
- bool isOpaque) {
+PlatformDevice* VectorPlatformDeviceFactory::CreateDevice(cairo_t* context,
+ int width, int height,
+ bool isOpaque) {
// TODO(myhuang): Here we might also have similar issues as those on Windows
// (vector_canvas_win.cc, http://crbug.com/18382 & http://crbug.com/18383).
// Please note that is_opaque is true when we use this class for printing.
diff --git a/skia/ext/vector_platform_device_linux.h b/skia/ext/vector_platform_device_linux.h
index 222f68f..ae2bafb 100644
--- a/skia/ext/vector_platform_device_linux.h
+++ b/skia/ext/vector_platform_device_linux.h
@@ -15,8 +15,8 @@ namespace skia {
class VectorPlatformDeviceFactory : public SkDeviceFactory {
public:
- static SkDevice* CreateDevice(cairo_t* context, int width, int height,
- bool isOpaque);
+ static PlatformDevice* CreateDevice(cairo_t* context, int width, int height,
+ bool isOpaque);
// Overridden from SkDeviceFactory:
virtual SkDevice* newDevice(SkCanvas* ignored, SkBitmap::Config config,
diff --git a/skia/ext/vector_platform_device_win.cc b/skia/ext/vector_platform_device_win.cc
index 2476152..90f824e 100644
--- a/skia/ext/vector_platform_device_win.cc
+++ b/skia/ext/vector_platform_device_win.cc
@@ -22,9 +22,8 @@ SkDevice* VectorPlatformDeviceFactory::newDevice(SkCanvas* unused,
}
//static
-SkDevice* VectorPlatformDeviceFactory::CreateDevice(int width, int height,
- bool is_opaque,
- HANDLE shared_section) {
+PlatformDevice* VectorPlatformDeviceFactory::CreateDevice(
+ int width, int height, bool is_opaque, HANDLE shared_section) {
if (!is_opaque) {
// TODO(maruel): http://crbug.com/18382 When restoring a semi-transparent
// layer, i.e. merging it, we need to rasterize it because GDI doesn't
diff --git a/skia/ext/vector_platform_device_win.h b/skia/ext/vector_platform_device_win.h
index 6045f24..83d51f7 100644
--- a/skia/ext/vector_platform_device_win.h
+++ b/skia/ext/vector_platform_device_win.h
@@ -13,13 +13,13 @@
namespace skia {
-class VectorPlatformDeviceFactory : public SkDeviceFactory {
+class SK_API VectorPlatformDeviceFactory : public SkDeviceFactory {
public:
virtual SkDevice* newDevice(SkCanvas* ignored, SkBitmap::Config config,
int width, int height,
bool isOpaque, bool isForLayer) OVERRIDE;
- static SkDevice* CreateDevice(int width, int height, bool isOpaque,
- HANDLE shared_section);
+ static PlatformDevice* CreateDevice(int width, int height, bool isOpaque,
+ HANDLE shared_section);
};
// A device is basically a wrapper around SkBitmap that provides a surface for