diff options
author | reed@google.com <reed@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-05 12:41:29 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-05 12:41:29 +0000 |
commit | c6c09d400f06555f8be1005356152bb480f109ab (patch) | |
tree | 3f5f13a9512624c40d037050dc3a93fecfc3e8b4 /skia | |
parent | eeba5376ef0501077c43cd85274a770c0f76b54a (diff) | |
download | chromium_src-c6c09d400f06555f8be1005356152bb480f109ab.zip chromium_src-c6c09d400f06555f8be1005356152bb480f109ab.tar.gz chromium_src-c6c09d400f06555f8be1005356152bb480f109ab.tar.bz2 |
Stop using deprecated factory API for SkDevice
Review URL: http://codereview.chromium.org/7273013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@91504 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia')
-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, 70 insertions, 176 deletions
diff --git a/skia/ext/bitmap_platform_device_linux.cc b/skia/ext/bitmap_platform_device_linux.cc index ae4d892..782b78f 100644 --- a/skia/ext/bitmap_platform_device_linux.cc +++ b/skia/ext/bitmap_platform_device_linux.cc @@ -37,15 +37,6 @@ 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), @@ -136,8 +127,11 @@ BitmapPlatformDevice::BitmapPlatformDevice( BitmapPlatformDevice::~BitmapPlatformDevice() { } -SkDeviceFactory* BitmapPlatformDevice::onNewDeviceFactory() { - return SkNEW(BitmapPlatformDeviceFactory); +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); } cairo_t* BitmapPlatformDevice::BeginPlatformPaint() { diff --git a/skia/ext/bitmap_platform_device_linux.h b/skia/ext/bitmap_platform_device_linux.h index f96b9b7..e5e4437 100644 --- a/skia/ext/bitmap_platform_device_linux.h +++ b/skia/ext/bitmap_platform_device_linux.h @@ -44,13 +44,6 @@ 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 @@ -93,8 +86,9 @@ class BitmapPlatformDevice : public PlatformDevice { virtual cairo_t* BeginPlatformPaint(); protected: - // Override SkDevice. - virtual SkDeviceFactory* onNewDeviceFactory(); + virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config, int width, + int height, bool isOpaque, + Usage usage); 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 9a10bf1..d6bfc50 100644 --- a/skia/ext/bitmap_platform_device_mac.cc +++ b/skia/ext/bitmap_platform_device_mac.cc @@ -50,15 +50,6 @@ 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), @@ -243,8 +234,11 @@ void BitmapPlatformDevice::onAccessBitmap(SkBitmap*) { // Not needed in CoreGraphics } -SkDeviceFactory* BitmapPlatformDevice::onNewDeviceFactory() { - return SkNEW(BitmapPlatformDeviceFactory); +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); } } // namespace skia diff --git a/skia/ext/bitmap_platform_device_mac.h b/skia/ext/bitmap_platform_device_mac.h index 45fbcab..fddbaad 100644 --- a/skia/ext/bitmap_platform_device_mac.h +++ b/skia/ext/bitmap_platform_device_mac.h @@ -11,14 +11,6 @@ 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 @@ -71,8 +63,9 @@ class BitmapPlatformDevice : public PlatformDevice { // starts accessing pixel data. virtual void onAccessBitmap(SkBitmap*); - // Override SkDevice. - virtual SkDeviceFactory* onNewDeviceFactory(); + virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config, int width, + int height, bool isOpaque, + Usage usage); // 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 366bdd0..f1345fa 100644 --- a/skia/ext/bitmap_platform_device_win.cc +++ b/skia/ext/bitmap_platform_device_win.cc @@ -15,15 +15,6 @@ 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), @@ -263,8 +254,11 @@ void BitmapPlatformDevice::onAccessBitmap(SkBitmap* bitmap) { GdiFlush(); } -SkDeviceFactory* BitmapPlatformDevice::onNewDeviceFactory() { - return SkNEW(BitmapPlatformDeviceFactory); +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); } } // namespace skia diff --git a/skia/ext/bitmap_platform_device_win.h b/skia/ext/bitmap_platform_device_win.h index ea6bcc3..270dc08 100644 --- a/skia/ext/bitmap_platform_device_win.h +++ b/skia/ext/bitmap_platform_device_win.h @@ -11,13 +11,6 @@ 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 @@ -75,8 +68,9 @@ class SK_API BitmapPlatformDevice : public PlatformDevice { // starts accessing pixel data. virtual void onAccessBitmap(SkBitmap* bitmap); - // Override SkDevice. - virtual SkDeviceFactory* onNewDeviceFactory(); + virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config, int width, + int height, bool isOpaque, + Usage usage); 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 2a50ede..df7ded6 100644 --- a/skia/ext/platform_canvas.cc +++ b/skia/ext/platform_canvas.cc @@ -9,12 +9,7 @@ namespace skia { -PlatformCanvas::PlatformCanvas() { - setDeviceFactory(SkNEW(BitmapPlatformDeviceFactory))->unref(); -} - -PlatformCanvas::PlatformCanvas(SkDeviceFactory* factory) : SkCanvas(factory) { -} +PlatformCanvas::PlatformCanvas() {} 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 7197ae93..54650ff 100644 --- a/skia/ext/platform_canvas.h +++ b/skia/ext/platform_canvas.h @@ -20,7 +20,6 @@ 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 ea0f0c8..f471b33 100644 --- a/skia/ext/platform_canvas_linux.cc +++ b/skia/ext/platform_canvas_linux.cc @@ -13,14 +13,12 @@ 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 fba49f2..9dcce61 100644 --- a/skia/ext/platform_canvas_mac.cc +++ b/skia/ext/platform_canvas_mac.cc @@ -10,7 +10,6 @@ namespace skia { PlatformCanvas::PlatformCanvas(int width, int height, bool is_opaque) { - setDeviceFactory(SkNEW(BitmapPlatformDeviceFactory))->unref(); initialize(width, height, is_opaque); } @@ -18,7 +17,6 @@ PlatformCanvas::PlatformCanvas(int width, int height, bool is_opaque, CGContextRef context) { - setDeviceFactory(SkNEW(BitmapPlatformDeviceFactory))->unref(); initialize(context, width, height, is_opaque); } @@ -26,7 +24,6 @@ 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 116ba66..23e7674 100644 --- a/skia/ext/platform_canvas_win.cc +++ b/skia/ext/platform_canvas_win.cc @@ -77,7 +77,6 @@ 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); @@ -87,7 +86,6 @@ 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 980ca30..96c23e9 100644 --- a/skia/ext/vector_canvas.cc +++ b/skia/ext/vector_canvas.cc @@ -7,8 +7,7 @@ namespace skia { -VectorCanvas::VectorCanvas(SkDevice* device) - : PlatformCanvas(device->getDeviceFactory()) { +VectorCanvas::VectorCanvas(SkDevice* device) { 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 627c1d9..87fac81 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(VectorPlatformDeviceEmfFactory::CreateDevice( + vcanvas_ = new VectorCanvas(VectorPlatformDeviceEmf::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(VectorPlatformDeviceEmfFactory::CreateDevice( + vcanvas_ = new VectorCanvas(VectorPlatformDeviceEmf::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 b9341ec..f4a4e0b 100644 --- a/skia/ext/vector_platform_device_cairo_linux.cc +++ b/skia/ext/vector_platform_device_cairo_linux.cc @@ -68,20 +68,10 @@ 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* VectorPlatformDeviceCairoFactory::CreateDevice(cairo_t* context, - int width, - int height, - bool isOpaque) { +PlatformDevice* VectorPlatformDeviceCairo::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. @@ -90,22 +80,10 @@ PlatformDevice* VectorPlatformDeviceCairoFactory::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); @@ -129,15 +107,19 @@ 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 6e5cbcd..ff6a2df 100644 --- a/skia/ext/vector_platform_device_cairo_linux.h +++ b/skia/ext/vector_platform_device_cairo_linux.h @@ -14,17 +14,6 @@ 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 @@ -34,9 +23,8 @@ class SK_API VectorPlatformDeviceCairo : public PlatformDevice { public: virtual ~VectorPlatformDeviceCairo(); - // Factory function. Ownership of |context| is not transferred. - static VectorPlatformDeviceCairo* create(PlatformSurface context, - int width, int height); + static PlatformDevice* CreateDevice(cairo_t* context, int width, int height, + bool isOpaque); // Clean up cached fonts. It is an error to call this while some // VectorPlatformDeviceCairo callee is still using fonts created for it by @@ -88,8 +76,9 @@ class SK_API VectorPlatformDeviceCairo : public PlatformDevice { explicit VectorPlatformDeviceCairo(PlatformSurface context, const SkBitmap& bitmap); - // Override from SkDevice (through PlatformDevice). - virtual SkDeviceFactory* onNewDeviceFactory(); + virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config, int width, + int height, bool isOpaque, + Usage usage); 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 6684913..0789197 100644 --- a/skia/ext/vector_platform_device_emf_win.cc +++ b/skia/ext/vector_platform_device_emf_win.cc @@ -12,18 +12,10 @@ 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* VectorPlatformDeviceEmfFactory::CreateDevice( - int width, int height, bool is_opaque, HANDLE shared_section) { +PlatformDevice* VectorPlatformDeviceEmf::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 @@ -115,10 +107,6 @@ VectorPlatformDeviceEmf::~VectorPlatformDeviceEmf() { SkASSERT(previous_pen_ == NULL); } -SkDeviceFactory* VectorPlatformDeviceEmf::onNewDeviceFactory() { - return SkNEW(VectorPlatformDeviceEmfFactory); -} - HDC VectorPlatformDeviceEmf::BeginPlatformPaint() { return hdc_; } @@ -450,6 +438,13 @@ 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 580f240..1aa8444 100644 --- a/skia/ext/vector_platform_device_emf_win.h +++ b/skia/ext/vector_platform_device_emf_win.h @@ -14,21 +14,15 @@ 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); @@ -81,8 +75,9 @@ class VectorPlatformDeviceEmf : public PlatformDevice { bool alpha_blend_used() const { return alpha_blend_used_; } protected: - // Override from SkDevice (through PlatformDevice). - virtual SkDeviceFactory* onNewDeviceFactory(); + virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config, int width, + int height, bool isOpaque, + Usage usage); 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 22c029c..dbc5843 100644 --- a/skia/ext/vector_platform_device_skia.cc +++ b/skia/ext/vector_platform_device_skia.cc @@ -13,19 +13,6 @@ 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); @@ -224,8 +211,13 @@ CGContextRef VectorPlatformDeviceSkia::GetBitmapContext() { #endif -SkDeviceFactory* VectorPlatformDeviceSkia::onNewDeviceFactory() { - return SkNEW(VectorPlatformDeviceSkiaFactory); +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())); } } // namespace skia diff --git a/skia/ext/vector_platform_device_skia.h b/skia/ext/vector_platform_device_skia.h index ee19389..7aaa2a2 100644 --- a/skia/ext/vector_platform_device_skia.h +++ b/skia/ext/vector_platform_device_skia.h @@ -22,15 +22,6 @@ 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); @@ -89,8 +80,9 @@ class VectorPlatformDeviceSkia : public PlatformDevice { const SkPaint&); protected: - // Override from SkDevice (through PlatformDevice). - virtual SkDeviceFactory* onNewDeviceFactory(); + virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config, int width, + int height, bool isOpaque, + Usage usage); private: SkRefPtr<SkPDFDevice> pdf_device_; |