diff options
author | reed@google.com <reed@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-05 13:11:30 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-05 13:11:30 +0000 |
commit | 9dec727ff54efb1365599dcbdf6307c92a64a9ce (patch) | |
tree | f4997a248100ca55939cfa847d0b9e923e94083f /skia/ext | |
parent | c6c09d400f06555f8be1005356152bb480f109ab (diff) | |
download | chromium_src-9dec727ff54efb1365599dcbdf6307c92a64a9ce.zip chromium_src-9dec727ff54efb1365599dcbdf6307c92a64a9ce.tar.gz chromium_src-9dec727ff54efb1365599dcbdf6307c92a64a9ce.tar.bz2 |
Revert 91504 - Stop using deprecated factory API for SkDevice
Review URL: http://codereview.chromium.org/7273013
TBR=reed@google.com
Review URL: http://codereview.chromium.org/7193040
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@91505 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia/ext')
-rw-r--r-- | skia/ext/bitmap_platform_device_linux.cc | 16 | ||||
-rw-r--r-- | skia/ext/bitmap_platform_device_linux.h | 12 | ||||
-rw-r--r-- | skia/ext/bitmap_platform_device_mac.cc | 16 | ||||
-rw-r--r-- | skia/ext/bitmap_platform_device_mac.h | 13 | ||||
-rw-r--r-- | skia/ext/bitmap_platform_device_win.cc | 16 | ||||
-rw-r--r-- | skia/ext/bitmap_platform_device_win.h | 12 | ||||
-rw-r--r-- | skia/ext/platform_canvas.cc | 7 | ||||
-rw-r--r-- | skia/ext/platform_canvas.h | 1 | ||||
-rw-r--r-- | skia/ext/platform_canvas_linux.cc | 2 | ||||
-rw-r--r-- | skia/ext/platform_canvas_mac.cc | 3 | ||||
-rw-r--r-- | skia/ext/platform_canvas_win.cc | 2 | ||||
-rw-r--r-- | skia/ext/vector_canvas.cc | 3 | ||||
-rw-r--r-- | skia/ext/vector_canvas_unittest.cc | 4 | ||||
-rw-r--r-- | skia/ext/vector_platform_device_cairo_linux.cc | 40 | ||||
-rw-r--r-- | skia/ext/vector_platform_device_cairo_linux.h | 21 | ||||
-rw-r--r-- | skia/ext/vector_platform_device_emf_win.cc | 25 | ||||
-rw-r--r-- | skia/ext/vector_platform_device_emf_win.h | 17 | ||||
-rw-r--r-- | skia/ext/vector_platform_device_skia.cc | 22 | ||||
-rw-r--r-- | skia/ext/vector_platform_device_skia.h | 14 |
19 files changed, 176 insertions, 70 deletions
diff --git a/skia/ext/bitmap_platform_device_linux.cc b/skia/ext/bitmap_platform_device_linux.cc index 782b78f..ae4d892 100644 --- a/skia/ext/bitmap_platform_device_linux.cc +++ b/skia/ext/bitmap_platform_device_linux.cc @@ -37,6 +37,15 @@ void LoadClipToContext(cairo_t* context, const SkRegion& clip) { } // namespace +SkDevice* BitmapPlatformDeviceFactory::newDevice(SkCanvas* ignored, + 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), @@ -127,11 +136,8 @@ BitmapPlatformDevice::BitmapPlatformDevice( BitmapPlatformDevice::~BitmapPlatformDevice() { } -SkDevice* BitmapPlatformDevice::onCreateCompatibleDevice( - SkBitmap::Config config, int width, int height, bool isOpaque, - Usage /*usage*/) { - SkASSERT(config == SkBitmap::kARGB_8888_Config); - return BitmapPlatformDevice::Create(width, height, isOpaque); +SkDeviceFactory* BitmapPlatformDevice::onNewDeviceFactory() { + return SkNEW(BitmapPlatformDeviceFactory); } cairo_t* BitmapPlatformDevice::BeginPlatformPaint() { diff --git a/skia/ext/bitmap_platform_device_linux.h b/skia/ext/bitmap_platform_device_linux.h index e5e4437..f96b9b7 100644 --- a/skia/ext/bitmap_platform_device_linux.h +++ b/skia/ext/bitmap_platform_device_linux.h @@ -44,6 +44,13 @@ typedef struct _cairo_surface cairo_surface_t; namespace skia { +class BitmapPlatformDeviceFactory : public SkDeviceFactory { + public: + virtual SkDevice* newDevice(SkCanvas* ignored, 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 @@ -86,9 +93,8 @@ class BitmapPlatformDevice : public PlatformDevice { virtual cairo_t* BeginPlatformPaint(); protected: - virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config, int width, - int height, bool isOpaque, - Usage usage); + // Override SkDevice. + virtual SkDeviceFactory* onNewDeviceFactory(); private: static BitmapPlatformDevice* Create(int width, int height, bool is_opaque, diff --git a/skia/ext/bitmap_platform_device_mac.cc b/skia/ext/bitmap_platform_device_mac.cc index d6bfc50..9a10bf1 100644 --- a/skia/ext/bitmap_platform_device_mac.cc +++ b/skia/ext/bitmap_platform_device_mac.cc @@ -50,6 +50,15 @@ static CGContextRef CGContextForData(void* data, int width, int height) { } // namespace +SkDevice* BitmapPlatformDeviceFactory::newDevice(SkCanvas* ignored, + 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), @@ -234,11 +243,8 @@ void BitmapPlatformDevice::onAccessBitmap(SkBitmap*) { // Not needed in CoreGraphics } -SkDevice* BitmapPlatformDevice::onCreateCompatibleDevice( - SkBitmap::Config config, int width, int height, bool isOpaque, - Usage /*usage*/) { - SkASSERT(config == SkBitmap::kARGB_8888_Config); - return BitmapPlatformDevice::Create(NULL, width, height, isOpaque); +SkDeviceFactory* BitmapPlatformDevice::onNewDeviceFactory() { + return SkNEW(BitmapPlatformDeviceFactory); } } // namespace skia diff --git a/skia/ext/bitmap_platform_device_mac.h b/skia/ext/bitmap_platform_device_mac.h index fddbaad..45fbcab 100644 --- a/skia/ext/bitmap_platform_device_mac.h +++ b/skia/ext/bitmap_platform_device_mac.h @@ -11,6 +11,14 @@ namespace skia { +class BitmapPlatformDeviceFactory : public SkDeviceFactory { + public: + virtual SkDevice* newDevice(SkCanvas* ignored, 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 @@ -63,9 +71,8 @@ class BitmapPlatformDevice : public PlatformDevice { // starts accessing pixel data. virtual void onAccessBitmap(SkBitmap*); - virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config, int width, - int height, bool isOpaque, - Usage usage); + // Override SkDevice. + virtual SkDeviceFactory* onNewDeviceFactory(); // Data associated with this device, guaranteed non-null. We hold a reference // to this object. diff --git a/skia/ext/bitmap_platform_device_win.cc b/skia/ext/bitmap_platform_device_win.cc index f1345fa..366bdd0 100644 --- a/skia/ext/bitmap_platform_device_win.cc +++ b/skia/ext/bitmap_platform_device_win.cc @@ -15,6 +15,15 @@ namespace skia { +SkDevice* BitmapPlatformDeviceFactory::newDevice(SkCanvas* ignored, + 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), @@ -254,11 +263,8 @@ void BitmapPlatformDevice::onAccessBitmap(SkBitmap* bitmap) { GdiFlush(); } -SkDevice* BitmapPlatformDevice::onCreateCompatibleDevice( - SkBitmap::Config config, int width, int height, bool isOpaque, - Usage /*usage*/) { - SkASSERT(config == SkBitmap::kARGB_8888_Config); - return BitmapPlatformDevice::create(width, height, isOpaque, NULL); +SkDeviceFactory* BitmapPlatformDevice::onNewDeviceFactory() { + return SkNEW(BitmapPlatformDeviceFactory); } } // namespace skia diff --git a/skia/ext/bitmap_platform_device_win.h b/skia/ext/bitmap_platform_device_win.h index 270dc08..ea6bcc3 100644 --- a/skia/ext/bitmap_platform_device_win.h +++ b/skia/ext/bitmap_platform_device_win.h @@ -11,6 +11,13 @@ namespace skia { +class BitmapPlatformDeviceFactory : public SkDeviceFactory { + public: + virtual SkDevice* newDevice(SkCanvas* ignored, 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 @@ -68,9 +75,8 @@ class SK_API BitmapPlatformDevice : public PlatformDevice { // starts accessing pixel data. virtual void onAccessBitmap(SkBitmap* bitmap); - virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config, int width, - int height, bool isOpaque, - Usage usage); + // Override SkDevice. + virtual SkDeviceFactory* onNewDeviceFactory(); private: // Reference counted data that can be shared between multiple devices. This diff --git a/skia/ext/platform_canvas.cc b/skia/ext/platform_canvas.cc index df7ded6..2a50ede 100644 --- a/skia/ext/platform_canvas.cc +++ b/skia/ext/platform_canvas.cc @@ -9,7 +9,12 @@ namespace skia { -PlatformCanvas::PlatformCanvas() {} +PlatformCanvas::PlatformCanvas() { + setDeviceFactory(SkNEW(BitmapPlatformDeviceFactory))->unref(); +} + +PlatformCanvas::PlatformCanvas(SkDeviceFactory* factory) : SkCanvas(factory) { +} SkDevice* PlatformCanvas::setBitmapDevice(const SkBitmap&) { SkASSERT(false); // Should not be called. diff --git a/skia/ext/platform_canvas.h b/skia/ext/platform_canvas.h index 54650ff..7197ae93 100644 --- a/skia/ext/platform_canvas.h +++ b/skia/ext/platform_canvas.h @@ -20,6 +20,7 @@ class SK_API PlatformCanvas : public SkCanvas { public: // 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); diff --git a/skia/ext/platform_canvas_linux.cc b/skia/ext/platform_canvas_linux.cc index f471b33..ea0f0c8 100644 --- a/skia/ext/platform_canvas_linux.cc +++ b/skia/ext/platform_canvas_linux.cc @@ -13,12 +13,14 @@ namespace skia { PlatformCanvas::PlatformCanvas(int width, int height, bool is_opaque) { + setDeviceFactory(SkNEW(BitmapPlatformDeviceFactory))->unref(); if (!initialize(width, height, is_opaque)) SK_CRASH(); } PlatformCanvas::PlatformCanvas(int width, int height, bool is_opaque, uint8_t* data) { + setDeviceFactory(SkNEW(BitmapPlatformDeviceFactory))->unref(); if (!initialize(width, height, is_opaque, data)) SK_CRASH(); } diff --git a/skia/ext/platform_canvas_mac.cc b/skia/ext/platform_canvas_mac.cc index 9dcce61..fba49f2 100644 --- a/skia/ext/platform_canvas_mac.cc +++ b/skia/ext/platform_canvas_mac.cc @@ -10,6 +10,7 @@ namespace skia { PlatformCanvas::PlatformCanvas(int width, int height, bool is_opaque) { + setDeviceFactory(SkNEW(BitmapPlatformDeviceFactory))->unref(); initialize(width, height, is_opaque); } @@ -17,6 +18,7 @@ PlatformCanvas::PlatformCanvas(int width, int height, bool is_opaque, CGContextRef context) { + setDeviceFactory(SkNEW(BitmapPlatformDeviceFactory))->unref(); initialize(context, width, height, is_opaque); } @@ -24,6 +26,7 @@ PlatformCanvas::PlatformCanvas(int width, int height, bool is_opaque, uint8_t* data) { + setDeviceFactory(SkNEW(BitmapPlatformDeviceFactory))->unref(); initialize(width, height, is_opaque, data); } diff --git a/skia/ext/platform_canvas_win.cc b/skia/ext/platform_canvas_win.cc index 23e7674..116ba66 100644 --- a/skia/ext/platform_canvas_win.cc +++ b/skia/ext/platform_canvas_win.cc @@ -77,6 +77,7 @@ void CrashIfInvalidSection(HANDLE shared_section) { #pragma optimize("", on) PlatformCanvas::PlatformCanvas(int width, int height, bool is_opaque) { + setDeviceFactory(SkNEW(BitmapPlatformDeviceFactory))->unref(); bool initialized = initialize(width, height, is_opaque, NULL); if (!initialized) CrashForBitmapAllocationFailure(width, height); @@ -86,6 +87,7 @@ PlatformCanvas::PlatformCanvas(int width, int height, bool is_opaque, HANDLE shared_section) { + setDeviceFactory(SkNEW(BitmapPlatformDeviceFactory))->unref(); bool initialized = initialize(width, height, is_opaque, shared_section); if (!initialized) { CrashIfInvalidSection(shared_section); diff --git a/skia/ext/vector_canvas.cc b/skia/ext/vector_canvas.cc index 96c23e9..980ca30 100644 --- a/skia/ext/vector_canvas.cc +++ b/skia/ext/vector_canvas.cc @@ -7,7 +7,8 @@ namespace skia { -VectorCanvas::VectorCanvas(SkDevice* device) { +VectorCanvas::VectorCanvas(SkDevice* device) + : PlatformCanvas(device->getDeviceFactory()) { setDevice(device)->unref(); // Created with refcount 1, and setDevice refs. } diff --git a/skia/ext/vector_canvas_unittest.cc b/skia/ext/vector_canvas_unittest.cc index 87fac81..627c1d9 100644 --- a/skia/ext/vector_canvas_unittest.cc +++ b/skia/ext/vector_canvas_unittest.cc @@ -389,7 +389,7 @@ class VectorCanvasTest : public ImageTest { size_ = size; context_ = new Context(); bitmap_ = new Bitmap(*context_, size_, size_); - vcanvas_ = new VectorCanvas(VectorPlatformDeviceEmf::CreateDevice( + vcanvas_ = new VectorCanvas(VectorPlatformDeviceEmfFactory::CreateDevice( size_, size_, true, context_->context())); pcanvas_ = new PlatformCanvas(size_, size_, false); @@ -456,7 +456,7 @@ TEST_F(VectorCanvasTest, Uninitialized) { context_ = new Context(); bitmap_ = new Bitmap(*context_, size_, size_); - vcanvas_ = new VectorCanvas(VectorPlatformDeviceEmf::CreateDevice( + vcanvas_ = new VectorCanvas(VectorPlatformDeviceEmfFactory::CreateDevice( size_, size_, true, context_->context())); pcanvas_ = new PlatformCanvas(size_, size_, false); diff --git a/skia/ext/vector_platform_device_cairo_linux.cc b/skia/ext/vector_platform_device_cairo_linux.cc index f4a4e0b..b9341ec 100644 --- a/skia/ext/vector_platform_device_cairo_linux.cc +++ b/skia/ext/vector_platform_device_cairo_linux.cc @@ -68,10 +68,20 @@ bool IsContextValid(cairo_t* context) { namespace skia { +SkDevice* VectorPlatformDeviceCairoFactory::newDevice(SkCanvas* ignored, + SkBitmap::Config config, + int width, int height, + bool isOpaque, + bool isForLayer) { + SkASSERT(config == SkBitmap::kARGB_8888_Config); + return CreateDevice(NULL, width, height, isOpaque); +} + // static -PlatformDevice* VectorPlatformDeviceCairo::CreateDevice(cairo_t* context, - int width, int height, - bool isOpaque) { +PlatformDevice* VectorPlatformDeviceCairoFactory::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. @@ -80,10 +90,22 @@ PlatformDevice* VectorPlatformDeviceCairo::CreateDevice(cairo_t* context, return BitmapPlatformDevice::Create(width, height, isOpaque); } + PlatformDevice* device = + VectorPlatformDeviceCairo::create(context, width, height); + return device; +} + +VectorPlatformDeviceCairo* VectorPlatformDeviceCairo::create( + PlatformSurface context, + int width, + int height) { SkASSERT(cairo_status(context) == CAIRO_STATUS_SUCCESS); SkASSERT(width > 0); SkASSERT(height > 0); + // TODO(myhuang): Can we get rid of the bitmap? In this vectorial device, + // the content of this bitmap might be meaningless. However, it does occupy + // lots of memory space. SkBitmap bitmap; bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); @@ -107,19 +129,15 @@ VectorPlatformDeviceCairo::~VectorPlatformDeviceCairo() { cairo_destroy(context_); } +SkDeviceFactory* VectorPlatformDeviceCairo::onNewDeviceFactory() { + return SkNEW(VectorPlatformDeviceCairoFactory); +} + PlatformDevice::PlatformSurface VectorPlatformDeviceCairo::BeginPlatformPaint() { return context_; } -SkDevice* VectorPlatformDeviceCairo::onCreateCompatibleDevice( - SkBitmap::Config config, - int width, int height, - bool isOpaque, Usage) { - SkASSERT(config == SkBitmap::kARGB_8888_Config); - return CreateDevice(NULL, width, height, isOpaque); -} - uint32_t VectorPlatformDeviceCairo::getDeviceCapabilities() { return SkDevice::getDeviceCapabilities() | kVector_Capability; } diff --git a/skia/ext/vector_platform_device_cairo_linux.h b/skia/ext/vector_platform_device_cairo_linux.h index ff6a2df..6e5cbcd 100644 --- a/skia/ext/vector_platform_device_cairo_linux.h +++ b/skia/ext/vector_platform_device_cairo_linux.h @@ -14,6 +14,17 @@ namespace skia { +class SK_API VectorPlatformDeviceCairoFactory : public SkDeviceFactory { + public: + static PlatformDevice* CreateDevice(cairo_t* context, int width, int height, + bool isOpaque); + + // Overridden from SkDeviceFactory: + virtual SkDevice* newDevice(SkCanvas* ignored, SkBitmap::Config config, + int width, int height, + bool isOpaque, bool isForLayer); +}; + // 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 @@ -23,8 +34,9 @@ class SK_API VectorPlatformDeviceCairo : public PlatformDevice { public: virtual ~VectorPlatformDeviceCairo(); - static PlatformDevice* CreateDevice(cairo_t* context, int width, int height, - bool isOpaque); + // Factory function. Ownership of |context| is not transferred. + static VectorPlatformDeviceCairo* create(PlatformSurface context, + int width, int height); // Clean up cached fonts. It is an error to call this while some // VectorPlatformDeviceCairo callee is still using fonts created for it by @@ -76,9 +88,8 @@ class SK_API VectorPlatformDeviceCairo : public PlatformDevice { explicit VectorPlatformDeviceCairo(PlatformSurface context, const SkBitmap& bitmap); - virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config, int width, - int height, bool isOpaque, - Usage usage); + // Override from SkDevice (through PlatformDevice). + virtual SkDeviceFactory* onNewDeviceFactory(); private: // Apply paint's color in the context. diff --git a/skia/ext/vector_platform_device_emf_win.cc b/skia/ext/vector_platform_device_emf_win.cc index 0789197..6684913 100644 --- a/skia/ext/vector_platform_device_emf_win.cc +++ b/skia/ext/vector_platform_device_emf_win.cc @@ -12,10 +12,18 @@ namespace skia { +SkDevice* VectorPlatformDeviceEmfFactory::newDevice(SkCanvas* unused, + SkBitmap::Config config, + int width, int height, + bool isOpaque, + bool isForLayer) { + SkASSERT(config == SkBitmap::kARGB_8888_Config); + return CreateDevice(width, height, isOpaque, NULL); +} + //static -PlatformDevice* VectorPlatformDeviceEmf::CreateDevice(int width, int height, - bool is_opaque, - HANDLE shared_section) { +PlatformDevice* VectorPlatformDeviceEmfFactory::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 @@ -107,6 +115,10 @@ VectorPlatformDeviceEmf::~VectorPlatformDeviceEmf() { SkASSERT(previous_pen_ == NULL); } +SkDeviceFactory* VectorPlatformDeviceEmf::onNewDeviceFactory() { + return SkNEW(VectorPlatformDeviceEmfFactory); +} + HDC VectorPlatformDeviceEmf::BeginPlatformPaint() { return hdc_; } @@ -438,13 +450,6 @@ void VectorPlatformDeviceEmf::LoadClipRegion() { LoadClippingRegionToDC(hdc_, clip_region_, t); } -SkDevice* VectorPlatformDeviceEmf::onCreateCompatibleDevice( - SkBitmap::Config config, int width, int height, bool isOpaque, - Usage /*usage*/) { - SkASSERT(config == SkBitmap::kARGB_8888_Config); - return VectorPlatformDeviceEmf::CreateDevice(width, height, isOpaque, NULL); -} - bool VectorPlatformDeviceEmf::CreateBrush(bool use_brush, COLORREF color) { SkASSERT(previous_brush_ == NULL); // We can't use SetDCBrushColor() or DC_BRUSH when drawing to a EMF buffer. diff --git a/skia/ext/vector_platform_device_emf_win.h b/skia/ext/vector_platform_device_emf_win.h index 1aa8444..580f240 100644 --- a/skia/ext/vector_platform_device_emf_win.h +++ b/skia/ext/vector_platform_device_emf_win.h @@ -14,15 +14,21 @@ namespace skia { +class SK_API VectorPlatformDeviceEmfFactory : public SkDeviceFactory { + public: + virtual SkDevice* newDevice(SkCanvas* ignored, SkBitmap::Config config, + int width, int height, + bool isOpaque, bool isForLayer) OVERRIDE; + 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 // 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. // This device is a simple wrapper over a Windows device context (HDC) handle. class VectorPlatformDeviceEmf : public PlatformDevice { public: - static PlatformDevice* CreateDevice(int width, int height, bool isOpaque, - HANDLE shared_section); - // Factory function. The DC is kept as the output context. static VectorPlatformDeviceEmf* create(HDC dc, int width, int height); @@ -75,9 +81,8 @@ class VectorPlatformDeviceEmf : public PlatformDevice { bool alpha_blend_used() const { return alpha_blend_used_; } protected: - virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config, int width, - int height, bool isOpaque, - Usage usage); + // Override from SkDevice (through PlatformDevice). + virtual SkDeviceFactory* onNewDeviceFactory(); private: // Applies the SkPaint's painting properties in the current GDI context, if diff --git a/skia/ext/vector_platform_device_skia.cc b/skia/ext/vector_platform_device_skia.cc index dbc5843..22c029c 100644 --- a/skia/ext/vector_platform_device_skia.cc +++ b/skia/ext/vector_platform_device_skia.cc @@ -13,6 +13,19 @@ namespace skia { +SkDevice* VectorPlatformDeviceSkiaFactory::newDevice(SkCanvas* canvas, + SkBitmap::Config config, + int width, int height, + bool isOpaque, + bool isForLayer) { + SkASSERT(config == SkBitmap::kARGB_8888_Config); + SkRefPtr<SkDevice> device = factory_.newDevice(canvas, config, width, height, + isOpaque, isForLayer); + device->unref(); // SkRefPtr and new both took a reference. + SkPDFDevice* pdf_device = static_cast<SkPDFDevice*>(device.get()); + return new VectorPlatformDeviceSkia(pdf_device); +} + static inline SkBitmap makeABitmap(int width, int height) { SkBitmap bitmap; bitmap.setConfig(SkBitmap::kNo_Config, width, height); @@ -211,13 +224,8 @@ CGContextRef VectorPlatformDeviceSkia::GetBitmapContext() { #endif -SkDevice* VectorPlatformDeviceSkia::onCreateCompatibleDevice( - SkBitmap::Config config, int width, int height, bool isOpaque, - Usage /*usage*/) { - SkAutoTUnref<SkDevice> dev(pdf_device_->createCompatibleDevice(config, width, - height, - isOpaque)); - return new VectorPlatformDeviceSkia(static_cast<SkPDFDevice*>(dev.get())); +SkDeviceFactory* VectorPlatformDeviceSkia::onNewDeviceFactory() { + return SkNEW(VectorPlatformDeviceSkiaFactory); } } // namespace skia diff --git a/skia/ext/vector_platform_device_skia.h b/skia/ext/vector_platform_device_skia.h index 7aaa2a2..ee19389 100644 --- a/skia/ext/vector_platform_device_skia.h +++ b/skia/ext/vector_platform_device_skia.h @@ -22,6 +22,15 @@ namespace skia { class BitmapPlatformDevice; +class VectorPlatformDeviceSkiaFactory : public SkDeviceFactory { + public: + virtual SkDevice* newDevice(SkCanvas* notUsed, SkBitmap::Config config, + int width, int height, bool isOpaque, + bool isForLayer); + private: + SkPDFDeviceFactory factory_; +}; + class VectorPlatformDeviceSkia : public PlatformDevice { public: SK_API VectorPlatformDeviceSkia(SkPDFDevice* pdf_device); @@ -80,9 +89,8 @@ class VectorPlatformDeviceSkia : public PlatformDevice { const SkPaint&); protected: - virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config, int width, - int height, bool isOpaque, - Usage usage); + // Override from SkDevice (through PlatformDevice). + virtual SkDeviceFactory* onNewDeviceFactory(); private: SkRefPtr<SkPDFDevice> pdf_device_; |