summaryrefslogtreecommitdiffstats
path: root/skia
diff options
context:
space:
mode:
authorvandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-15 22:27:25 +0000
committervandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-15 22:27:25 +0000
commit9ffeb66751381d847a30560029eb6f98de2f1a2b (patch)
treecc5524cec5b9959f34bb7a3947f7fa39a2274cc9 /skia
parent8cde687634d8a736aae7538a69d6a360814010c9 (diff)
downloadchromium_src-9ffeb66751381d847a30560029eb6f98de2f1a2b.zip
chromium_src-9ffeb66751381d847a30560029eb6f98de2f1a2b.tar.gz
chromium_src-9ffeb66751381d847a30560029eb6f98de2f1a2b.tar.bz2
Update use of SkCanvas and SkDevice to match change in Skia:
Refactor SkCanvas so that backends don't need to override it - instead take a device factory class. see: http://codereview.appspot.com/2103045/ BUG=New Skia devices required a corresponding canvas TEST=None Review URL: http://codereview.chromium.org/3590011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62813 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia')
-rw-r--r--skia/ext/bitmap_platform_device_linux.cc8
-rw-r--r--skia/ext/bitmap_platform_device_linux.h10
-rw-r--r--skia/ext/bitmap_platform_device_mac.cc8
-rw-r--r--skia/ext/bitmap_platform_device_mac.h11
-rw-r--r--skia/ext/bitmap_platform_device_win.cc8
-rw-r--r--skia/ext/bitmap_platform_device_win.h10
-rw-r--r--skia/ext/platform_canvas.cc9
-rw-r--r--skia/ext/platform_canvas.h15
-rw-r--r--skia/ext/platform_canvas_linux.cc16
-rw-r--r--skia/ext/platform_canvas_mac.cc17
-rw-r--r--skia/ext/platform_canvas_win.cc15
-rw-r--r--skia/ext/vector_canvas.cc6
-rw-r--r--skia/ext/vector_canvas.h18
-rw-r--r--skia/ext/vector_canvas_linux.cc29
-rw-r--r--skia/ext/vector_canvas_win.cc40
-rw-r--r--skia/ext/vector_platform_device.h5
-rw-r--r--skia/ext/vector_platform_device_linux.cc31
-rw-r--r--skia/ext/vector_platform_device_linux.h13
-rw-r--r--skia/ext/vector_platform_device_win.cc40
-rw-r--r--skia/ext/vector_platform_device_win.h12
20 files changed, 182 insertions, 139 deletions
diff --git a/skia/ext/bitmap_platform_device_linux.cc b/skia/ext/bitmap_platform_device_linux.cc
index 4c566b4..d976b9c 100644
--- a/skia/ext/bitmap_platform_device_linux.cc
+++ b/skia/ext/bitmap_platform_device_linux.cc
@@ -37,6 +37,14 @@ void LoadClipToContext(cairo_t* context, const SkRegion& clip) {
} // namespace
+SkDevice* SkBitmapPlatformDeviceFactory::newDevice(SkBitmap::Config config,
+ int width, int height,
+ bool isOpaque,
+ bool isForLayer) {
+ SkASSERT(config == SkBitmap::kARGB_8888_Config);
+ return BitmapPlatformDevice::Create(width, height, isOpaque);
+}
+
BitmapPlatformDevice::BitmapPlatformDeviceData::BitmapPlatformDeviceData(
cairo_surface_t* surface)
: surface_(surface),
diff --git a/skia/ext/bitmap_platform_device_linux.h b/skia/ext/bitmap_platform_device_linux.h
index 1c6579cc..daea4c4 100644
--- a/skia/ext/bitmap_platform_device_linux.h
+++ b/skia/ext/bitmap_platform_device_linux.h
@@ -43,6 +43,12 @@ typedef struct _cairo_surface cairo_surface_t;
namespace skia {
+class SkBitmapPlatformDeviceFactory : public SkRasterDeviceFactory {
+ public:
+ virtual SkDevice* newDevice(SkBitmap::Config config, int width, int height,
+ bool isOpaque, bool isForLayer);
+};
+
// -----------------------------------------------------------------------------
// This is the Linux bitmap backing for Skia. We create a Cairo image surface
// to store the backing buffer. This buffer is BGRA in memory (on little-endian
@@ -79,6 +85,10 @@ class BitmapPlatformDevice : public PlatformDevice {
// A stub copy constructor. Needs to be properly implemented.
BitmapPlatformDevice(const BitmapPlatformDevice& other);
+ virtual SkDeviceFactory* getDeviceFactory() {
+ return SkNEW(SkBitmapPlatformDeviceFactory);
+ }
+
virtual void makeOpaque(int x, int y, int width, int height);
// Bitmaps aren't vector graphics.
diff --git a/skia/ext/bitmap_platform_device_mac.cc b/skia/ext/bitmap_platform_device_mac.cc
index 841c75a..a482283 100644
--- a/skia/ext/bitmap_platform_device_mac.cc
+++ b/skia/ext/bitmap_platform_device_mac.cc
@@ -49,6 +49,14 @@ static CGContextRef CGContextForData(void* data, int width, int height) {
} // namespace
+SkDevice* SkBitmapPlatformDeviceFactory::newDevice(SkBitmap::Config config,
+ int width, int height,
+ bool isOpaque,
+ bool isForLayer) {
+ SkASSERT(config == SkBitmap::kARGB_8888_Config);
+ return BitmapPlatformDevice::Create(NULL, width, height, isOpaque);
+}
+
BitmapPlatformDevice::BitmapPlatformDeviceData::BitmapPlatformDeviceData(
CGContextRef bitmap)
: bitmap_context_(bitmap),
diff --git a/skia/ext/bitmap_platform_device_mac.h b/skia/ext/bitmap_platform_device_mac.h
index 195dca8..68c717c 100644
--- a/skia/ext/bitmap_platform_device_mac.h
+++ b/skia/ext/bitmap_platform_device_mac.h
@@ -10,6 +10,13 @@
namespace skia {
+class SkBitmapPlatformDeviceFactory : public SkRasterDeviceFactory {
+ public:
+ virtual SkDevice* newDevice(SkBitmap::Config config, int width, int height,
+ bool isOpaque, bool isForLayer);
+};
+
+
// A device is basically a wrapper around SkBitmap that provides a surface for
// SkCanvas to draw into. Our device provides a surface CoreGraphics can also
// write to. BitmapPlatformDevice creates a bitmap using
@@ -50,6 +57,10 @@ class BitmapPlatformDevice : public PlatformDevice {
BitmapPlatformDevice(const BitmapPlatformDevice& other);
virtual ~BitmapPlatformDevice();
+ virtual SkDeviceFactory* getDeviceFactory() {
+ return SkNEW(SkBitmapPlatformDeviceFactory);
+ }
+
// See warning for copy constructor above.
BitmapPlatformDevice& operator=(const BitmapPlatformDevice& other);
diff --git a/skia/ext/bitmap_platform_device_win.cc b/skia/ext/bitmap_platform_device_win.cc
index 490ad77..df7e0a2 100644
--- a/skia/ext/bitmap_platform_device_win.cc
+++ b/skia/ext/bitmap_platform_device_win.cc
@@ -15,6 +15,14 @@
namespace skia {
+SkDevice* SkBitmapPlatformDeviceFactory::newDevice(SkBitmap::Config config,
+ int width, int height,
+ bool isOpaque,
+ bool isForLayer) {
+ SkASSERT(config == SkBitmap::kARGB_8888_Config);
+ return BitmapPlatformDevice::create(width, height, isOpaque, NULL);
+}
+
BitmapPlatformDevice::BitmapPlatformDeviceData::BitmapPlatformDeviceData(
HBITMAP hbitmap)
: bitmap_context_(hbitmap),
diff --git a/skia/ext/bitmap_platform_device_win.h b/skia/ext/bitmap_platform_device_win.h
index 059b600..74806b5 100644
--- a/skia/ext/bitmap_platform_device_win.h
+++ b/skia/ext/bitmap_platform_device_win.h
@@ -10,6 +10,12 @@
namespace skia {
+class SkBitmapPlatformDeviceFactory : public SkRasterDeviceFactory {
+ public:
+ virtual SkDevice* newDevice(SkBitmap::Config config, int width, int height,
+ bool isOpaque, bool isForLayer);
+};
+
// A device is basically a wrapper around SkBitmap that provides a surface for
// SkCanvas to draw into. Our device provides a surface Windows can also write
// to. BitmapPlatformDevice creates a bitmap using CreateDIBSection() in a
@@ -62,6 +68,10 @@ class BitmapPlatformDevice : public PlatformDevice {
// See warning for copy constructor above.
BitmapPlatformDevice& operator=(const BitmapPlatformDevice& other);
+ virtual SkDeviceFactory* getDeviceFactory() {
+ return SkNEW(SkBitmapPlatformDeviceFactory);
+ }
+
// Retrieves the bitmap DC, which is the memory DC for our bitmap data. The
// bitmap DC is lazy created.
virtual HDC getBitmapDC();
diff --git a/skia/ext/platform_canvas.cc b/skia/ext/platform_canvas.cc
index 9121a0d..de0ed13 100644
--- a/skia/ext/platform_canvas.cc
+++ b/skia/ext/platform_canvas.cc
@@ -3,10 +3,19 @@
// found in the LICENSE file.
#include "skia/ext/platform_canvas.h"
+
+#include "skia/ext/bitmap_platform_device.h"
#include "third_party/skia/include/core/SkTypes.h"
namespace skia {
+PlatformCanvas::PlatformCanvas()
+ : SkCanvas(SkNEW(SkBitmapPlatformDeviceFactory)) {
+}
+
+PlatformCanvas::PlatformCanvas(SkDeviceFactory* factory) : SkCanvas(factory) {
+}
+
SkDevice* PlatformCanvas::setBitmapDevice(const SkBitmap&) {
SkASSERT(false); // Should not be called.
return NULL;
diff --git a/skia/ext/platform_canvas.h b/skia/ext/platform_canvas.h
index 1863d77..b602ed46 100644
--- a/skia/ext/platform_canvas.h
+++ b/skia/ext/platform_canvas.h
@@ -18,10 +18,11 @@ namespace skia {
// using both Skia operations and platform-specific operations.
class PlatformCanvas : public SkCanvas {
public:
- // Set is_opaque if you are going to erase the bitmap and not use
- // transparency: this will enable some optimizations.
// If you use the version with no arguments, you MUST call initialize()
PlatformCanvas();
+ explicit PlatformCanvas(SkDeviceFactory* factory);
+ // 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);
virtual ~PlatformCanvas();
@@ -96,16 +97,6 @@ class PlatformCanvas : public SkCanvas {
// FIXME(brettw) is this necessary?
using SkCanvas::clipRect;
- protected:
- // Creates a device store for use by the canvas. We override this so that
- // the device is always our own so we know that we can use platform
- // operations on it.
- virtual SkDevice* createDevice(SkBitmap::Config,
- int width,
- int height,
- bool is_opaque,
- bool isForLayer);
-
private:
// Unimplemented. This is to try to prevent people from calling this function
// on SkCanvas. SkCanvas' version is not virtual, so we can't prevent this
diff --git a/skia/ext/platform_canvas_linux.cc b/skia/ext/platform_canvas_linux.cc
index 109b232..5acbd14 100644
--- a/skia/ext/platform_canvas_linux.cc
+++ b/skia/ext/platform_canvas_linux.cc
@@ -12,18 +12,15 @@
namespace skia {
-PlatformCanvas::PlatformCanvas() : SkCanvas() {
-}
-
PlatformCanvas::PlatformCanvas(int width, int height, bool is_opaque)
- : SkCanvas() {
+ : SkCanvas(SkNEW(SkBitmapPlatformDeviceFactory)) {
if (!initialize(width, height, is_opaque))
SK_CRASH();
}
PlatformCanvas::PlatformCanvas(int width, int height, bool is_opaque,
uint8_t* data)
- : SkCanvas() {
+ : SkCanvas(SkNEW(SkBitmapPlatformDeviceFactory)) {
if (!initialize(width, height, is_opaque, data))
SK_CRASH();
}
@@ -50,13 +47,4 @@ void PlatformCanvas::endPlatformPaint() {
// We don't need to do anything on Linux here.
}
-SkDevice* PlatformCanvas::createDevice(SkBitmap::Config config,
- int width,
- int height,
- bool is_opaque,
- bool isForLayer) {
- SkASSERT(config == SkBitmap::kARGB_8888_Config);
- return BitmapPlatformDevice::Create(width, height, is_opaque);
-}
-
} // namespace skia
diff --git a/skia/ext/platform_canvas_mac.cc b/skia/ext/platform_canvas_mac.cc
index 33d7eb2..df3d0ce 100644
--- a/skia/ext/platform_canvas_mac.cc
+++ b/skia/ext/platform_canvas_mac.cc
@@ -9,11 +9,8 @@
namespace skia {
-PlatformCanvas::PlatformCanvas() : SkCanvas() {
-}
-
PlatformCanvas::PlatformCanvas(int width, int height, bool is_opaque)
- : SkCanvas() {
+ : SkCanvas(SkNEW(SkBitmapPlatformDeviceFactory)) {
initialize(width, height, is_opaque);
}
@@ -21,7 +18,7 @@ PlatformCanvas::PlatformCanvas(int width,
int height,
bool is_opaque,
CGContextRef context)
- : SkCanvas() {
+ : SkCanvas(SkNEW(SkBitmapPlatformDeviceFactory)) {
initialize(width, height, is_opaque);
}
@@ -29,7 +26,7 @@ PlatformCanvas::PlatformCanvas(int width,
int height,
bool is_opaque,
uint8_t* data)
- : SkCanvas() {
+ : SkCanvas(SkNEW(SkBitmapPlatformDeviceFactory)) {
initialize(width, height, is_opaque, data);
}
@@ -58,12 +55,4 @@ void PlatformCanvas::endPlatformPaint() {
// Flushing will be done in onAccessBitmap.
}
-SkDevice* PlatformCanvas::createDevice(SkBitmap::Config config,
- int width,
- int height,
- bool is_opaque, bool isForLayer) {
- SkASSERT(config == SkBitmap::kARGB_8888_Config);
- return BitmapPlatformDevice::Create(NULL, width, height, is_opaque);
-}
-
} // namespace skia
diff --git a/skia/ext/platform_canvas_win.cc b/skia/ext/platform_canvas_win.cc
index 3495403..fe63daf 100644
--- a/skia/ext/platform_canvas_win.cc
+++ b/skia/ext/platform_canvas_win.cc
@@ -76,11 +76,8 @@ void CrashIfInvalidSection(HANDLE shared_section) {
// Restore the optimization options.
#pragma optimize("", on)
-PlatformCanvas::PlatformCanvas() : SkCanvas() {
-}
-
PlatformCanvas::PlatformCanvas(int width, int height, bool is_opaque)
- : SkCanvas() {
+ : SkCanvas(SkNEW(SkBitmapPlatformDeviceFactory)) {
bool initialized = initialize(width, height, is_opaque, NULL);
if (!initialized)
CrashForBitmapAllocationFailure(width, height);
@@ -90,7 +87,7 @@ PlatformCanvas::PlatformCanvas(int width,
int height,
bool is_opaque,
HANDLE shared_section)
- : SkCanvas() {
+ : SkCanvas(SkNEW(SkBitmapPlatformDeviceFactory)) {
bool initialized = initialize(width, height, is_opaque, shared_section);
if (!initialized) {
CrashIfInvalidSection(shared_section);
@@ -124,12 +121,4 @@ void PlatformCanvas::endPlatformPaint() {
// flushing will be done in onAccessBitmap
}
-SkDevice* PlatformCanvas::createDevice(SkBitmap::Config config,
- int width,
- int height,
- bool is_opaque, bool isForLayer) {
- SkASSERT(config == SkBitmap::kARGB_8888_Config);
- return BitmapPlatformDevice::create(width, height, is_opaque, NULL);
-}
-
} // namespace skia
diff --git a/skia/ext/vector_canvas.cc b/skia/ext/vector_canvas.cc
index c80d0c3..0c6d306 100644
--- a/skia/ext/vector_canvas.cc
+++ b/skia/ext/vector_canvas.cc
@@ -6,7 +6,11 @@
namespace skia {
-VectorCanvas::VectorCanvas() {
+VectorCanvas::VectorCanvas()
+ : PlatformCanvas(SkNEW(SkVectorPlatformDeviceFactory)) {
+}
+
+VectorCanvas::VectorCanvas(SkDeviceFactory* factory) : PlatformCanvas(factory) {
}
VectorCanvas::~VectorCanvas() {
diff --git a/skia/ext/vector_canvas.h b/skia/ext/vector_canvas.h
index 8931832..db098c7 100644
--- a/skia/ext/vector_canvas.h
+++ b/skia/ext/vector_canvas.h
@@ -22,6 +22,7 @@ namespace skia {
class 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__)
@@ -39,26 +40,9 @@ class VectorCanvas : public PlatformCanvas {
#endif
virtual SkBounder* setBounder(SkBounder* bounder);
-#if defined(WIN32) || defined(__linux__) || defined(__FreeBSD__) || \
- defined(__OpenBSD__)
- virtual SkDevice* createDevice(SkBitmap::Config config,
- int width, int height,
- bool is_opaque, bool isForLayer);
-#endif
virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter);
private:
-#if defined(WIN32)
- // |shared_section| is in fact the HDC used for output. |is_opaque| is unused.
- virtual SkDevice* createPlatformDevice(int width, int height, bool is_opaque,
- HANDLE shared_section);
-#elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
- // Ownership of |context| is not transferred. |is_opaque| is unused.
- virtual SkDevice* createPlatformDevice(cairo_t* context,
- int width, int height,
- bool is_opaque);
-#endif
-
// Returns true if the top device is vector based and not bitmap based.
bool IsTopDeviceVectorial() const;
diff --git a/skia/ext/vector_canvas_linux.cc b/skia/ext/vector_canvas_linux.cc
index c3024f3..f2b8371 100644
--- a/skia/ext/vector_canvas_linux.cc
+++ b/skia/ext/vector_canvas_linux.cc
@@ -4,7 +4,6 @@
#include "skia/ext/vector_canvas.h"
-#include "skia/ext/bitmap_platform_device.h"
#include "skia/ext/vector_platform_device.h"
namespace skia {
@@ -16,7 +15,8 @@ VectorCanvas::VectorCanvas(cairo_t* context, int width, int height) {
}
bool VectorCanvas::initialize(cairo_t* context, int width, int height) {
- SkDevice* device = createPlatformDevice(context, width, height, true);
+ SkDevice* device = SkVectorPlatformDeviceFactory::CreateDevice(context, width,
+ height, true);
if (!device)
return false;
@@ -25,29 +25,4 @@ bool VectorCanvas::initialize(cairo_t* context, int width, int height) {
return true;
}
-SkDevice* VectorCanvas::createDevice(SkBitmap::Config config,
- int width, int height,
- bool is_opaque, bool isForLayer) {
- SkASSERT(config == SkBitmap::kARGB_8888_Config);
- return createPlatformDevice(NULL, width, height, is_opaque);
-}
-
-SkDevice* VectorCanvas::createPlatformDevice(cairo_t* context,
- int width,
- int height,
- bool is_opaque) {
- // 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.
- // Fallback to bitmap when context is NULL.
- if (!is_opaque || NULL == context) {
- return BitmapPlatformDevice::Create(width, height, is_opaque);
- }
-
- PlatformDevice* device =
- VectorPlatformDevice::create(context, width, height);
- return device;
-}
-
} // namespace skia
-
diff --git a/skia/ext/vector_canvas_win.cc b/skia/ext/vector_canvas_win.cc
index 3fe14b0..d58ebc5 100644
--- a/skia/ext/vector_canvas_win.cc
+++ b/skia/ext/vector_canvas_win.cc
@@ -16,7 +16,8 @@ VectorCanvas::VectorCanvas(HDC dc, int width, int height) {
}
bool VectorCanvas::initialize(HDC context, int width, int height) {
- SkDevice* device = createPlatformDevice(width, height, true, context);
+ SkDevice* device = SkVectorPlatformDeviceFactory::CreateDevice(width, height,
+ true, context);
if (!device)
return false;
@@ -25,42 +26,5 @@ bool VectorCanvas::initialize(HDC context, int width, int height) {
return true;
}
-SkDevice* VectorCanvas::createDevice(SkBitmap::Config config,
- int width, int height,
- bool is_opaque, bool isForLayer) {
- SkASSERT(config == SkBitmap::kARGB_8888_Config);
- return createPlatformDevice(width, height, is_opaque, NULL);
-}
-
-SkDevice* VectorCanvas::createPlatformDevice(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
- // support transparency except for AlphaBlend(). Right now, a
- // BitmapPlatformDevice is created when VectorCanvas think a saveLayers()
- // call is being done. The way to save a layer would be to create an
- // EMF-based VectorDevice and have this device registers the drawing. When
- // playing back the device into a bitmap, do it at the printer's dpi instead
- // of the layout's dpi (which is much lower).
- return BitmapPlatformDevice::create(width, height,
- is_opaque, shared_section);
- }
-
- // TODO(maruel): http://crbug.com/18383 Look if it would be worth to
- // increase the resolution by ~10x (any worthy factor) to increase the
- // rendering precision (think about printing) while using a relatively
- // low dpi. This happens because we receive float as input but the GDI
- // functions works with integers. The idea is to premultiply the matrix
- // with this factor and multiply each SkScalar that are passed to
- // SkScalarRound(value) as SkScalarRound(value * 10). Safari is already
- // doing the same for text rendering.
- SkASSERT(shared_section);
- PlatformDevice* device = VectorPlatformDevice::create(
- reinterpret_cast<HDC>(shared_section), width, height);
- return device;
-}
-
} // namespace skia
diff --git a/skia/ext/vector_platform_device.h b/skia/ext/vector_platform_device.h
index 591f3e5..7888670 100644
--- a/skia/ext/vector_platform_device.h
+++ b/skia/ext/vector_platform_device.h
@@ -12,6 +12,11 @@
#include "skia/ext/vector_platform_device_win.h"
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
#include "skia/ext/vector_platform_device_linux.h"
+#elif defined(__APPLE__)
+#include "skia/ext/bitmap_platform_device_mac.h"
+namespace skia {
+typedef SkBitmapPlatformDeviceFactory SkVectorPlatformDeviceFactory;
+} // namespace skia
#endif
#endif
diff --git a/skia/ext/vector_platform_device_linux.cc b/skia/ext/vector_platform_device_linux.cc
index cbe465d..6eae954 100644
--- a/skia/ext/vector_platform_device_linux.cc
+++ b/skia/ext/vector_platform_device_linux.cc
@@ -12,13 +12,13 @@
#include <map>
+#include "base/logging.h"
+#include "base/singleton.h"
+#include "skia/ext/bitmap_platform_device.h"
#include "third_party/skia/include/core/SkFontHost.h"
#include "third_party/skia/include/core/SkStream.h"
#include "third_party/skia/include/core/SkTypeface.h"
-#include "base/logging.h"
-#include "base/singleton.h"
-
namespace {
struct FontInfo {
@@ -65,6 +65,31 @@ bool IsContextValid(cairo_t* context) {
namespace skia {
+SkDevice* SkVectorPlatformDeviceFactory::newDevice(SkBitmap::Config config,
+ int width, int height,
+ bool isOpaque,
+ bool isForLayer) {
+ SkASSERT(config == SkBitmap::kARGB_8888_Config);
+ return CreateDevice(NULL, width, height, isOpaque);
+}
+
+// static
+SkDevice* SkVectorPlatformDeviceFactory::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.
+ // Fallback to bitmap when context is NULL.
+ if (!isOpaque || NULL == context) {
+ return BitmapPlatformDevice::Create(width, height, isOpaque);
+ }
+
+ PlatformDevice* device =
+ VectorPlatformDevice::create(context, width, height);
+ return device;
+}
+
VectorPlatformDevice* VectorPlatformDevice::create(PlatformSurface context,
int width, int height) {
SkASSERT(cairo_status(context) == CAIRO_STATUS_SUCCESS);
diff --git a/skia/ext/vector_platform_device_linux.h b/skia/ext/vector_platform_device_linux.h
index 016edbd..0a2bb83 100644
--- a/skia/ext/vector_platform_device_linux.h
+++ b/skia/ext/vector_platform_device_linux.h
@@ -12,6 +12,15 @@
namespace skia {
+class SkVectorPlatformDeviceFactory : public SkRasterDeviceFactory {
+ public:
+ virtual SkDevice* newDevice(SkBitmap::Config config, int width, int height,
+ bool isOpaque, bool isForLayer);
+
+ static SkDevice* CreateDevice(cairo_t* context, int width, int height,
+ bool isOpaque);
+};
+
// This device is basically a wrapper that provides a surface for SkCanvas
// to draw into. It is basically an adaptor which converts skia APIs into
// cooresponding Cairo APIs and outputs to a Cairo surface. Please NOTE that
@@ -24,6 +33,10 @@ class VectorPlatformDevice : public PlatformDevice {
int width, int height);
virtual ~VectorPlatformDevice();
+ virtual SkDeviceFactory* getDeviceFactory() {
+ return SkNEW(SkVectorPlatformDeviceFactory);
+ }
+
virtual bool IsVectorial() { return true; }
virtual PlatformSurface beginPlatformPaint() { return context_; }
diff --git a/skia/ext/vector_platform_device_win.cc b/skia/ext/vector_platform_device_win.cc
index 49dbc13..e18b156 100644
--- a/skia/ext/vector_platform_device_win.cc
+++ b/skia/ext/vector_platform_device_win.cc
@@ -6,11 +6,51 @@
#include "skia/ext/vector_platform_device_win.h"
+#include "skia/ext/bitmap_platform_device.h"
#include "skia/ext/skia_utils_win.h"
#include "third_party/skia/include/core/SkUtils.h"
namespace skia {
+SkDevice* SkVectorPlatformDeviceFactory::newDevice(SkBitmap::Config config,
+ int width, int height,
+ bool isOpaque,
+ bool isForLayer) {
+ SkASSERT(config == SkBitmap::kARGB_8888_Config);
+ return CreateDevice(width, height, isOpaque, NULL);
+}
+
+//static
+SkDevice* SkVectorPlatformDeviceFactory::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
+ // support transparency except for AlphaBlend(). Right now, a
+ // BitmapPlatformDevice is created when VectorCanvas think a saveLayers()
+ // call is being done. The way to save a layer would be to create an
+ // EMF-based VectorDevice and have this device registers the drawing. When
+ // playing back the device into a bitmap, do it at the printer's dpi instead
+ // of the layout's dpi (which is much lower).
+ return BitmapPlatformDevice::create(width, height,
+ is_opaque, shared_section);
+ }
+
+ // TODO(maruel): http://crbug.com/18383 Look if it would be worth to
+ // increase the resolution by ~10x (any worthy factor) to increase the
+ // rendering precision (think about printing) while using a relatively
+ // low dpi. This happens because we receive float as input but the GDI
+ // functions works with integers. The idea is to premultiply the matrix
+ // with this factor and multiply each SkScalar that are passed to
+ // SkScalarRound(value) as SkScalarRound(value * 10). Safari is already
+ // doing the same for text rendering.
+ SkASSERT(shared_section);
+ PlatformDevice* device = VectorPlatformDevice::create(
+ reinterpret_cast<HDC>(shared_section), width, height);
+ return device;
+}
+
static void FillBitmapInfoHeader(int width, int height, BITMAPINFOHEADER* hdr) {
hdr->biSize = sizeof(BITMAPINFOHEADER);
hdr->biWidth = width;
diff --git a/skia/ext/vector_platform_device_win.h b/skia/ext/vector_platform_device_win.h
index ac8a8ec..7ee7d549 100644
--- a/skia/ext/vector_platform_device_win.h
+++ b/skia/ext/vector_platform_device_win.h
@@ -12,6 +12,14 @@
namespace skia {
+class SkVectorPlatformDeviceFactory : public SkRasterDeviceFactory {
+ public:
+ virtual SkDevice* newDevice(SkBitmap::Config config, int width, int height,
+ bool isOpaque, bool isForLayer);
+ static SkDevice* CreateDevice(int width, int height, bool isOpaque,
+ HANDLE shared_section);
+};
+
// A device is basically a wrapper around SkBitmap that provides a surface for
// SkCanvas to draw into. This specific device is not not backed by a surface
// and is thus unreadable. This is because the backend is completely vectorial.
@@ -24,6 +32,10 @@ class VectorPlatformDevice : public PlatformDevice {
VectorPlatformDevice(HDC dc, const SkBitmap& bitmap);
virtual ~VectorPlatformDevice();
+ virtual SkDeviceFactory* getDeviceFactory() {
+ return SkNEW(SkVectorPlatformDeviceFactory);
+ }
+
virtual HDC getBitmapDC() {
return hdc_;
}