Stop using deprecated factory API for SkDevice
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=91504 Review URL: http://codereview.chromium.org/7273013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@91508 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
printing
skia/ext
bitmap_platform_device_linux.ccbitmap_platform_device_linux.hbitmap_platform_device_mac.ccbitmap_platform_device_mac.hbitmap_platform_device_win.ccbitmap_platform_device_win.hplatform_canvas.ccplatform_canvas.hplatform_canvas_linux.ccplatform_canvas_mac.ccplatform_canvas_win.ccvector_canvas.ccvector_canvas_unittest.ccvector_platform_device_cairo_linux.ccvector_platform_device_cairo_linux.hvector_platform_device_emf_win.ccvector_platform_device_emf_win.hvector_platform_device_skia.ccvector_platform_device_skia.h
@ -409,9 +409,9 @@ SkDevice* Emf::StartPageForVectorCanvas(
|
||||
if (!StartPage(page_size, content_area, scale_factor))
|
||||
return NULL;
|
||||
|
||||
return skia::VectorPlatformDeviceEmfFactory::CreateDevice(page_size.width(),
|
||||
page_size.height(),
|
||||
true, hdc_);
|
||||
return skia::VectorPlatformDeviceEmf::CreateDevice(page_size.width(),
|
||||
page_size.height(),
|
||||
true, hdc_);
|
||||
}
|
||||
|
||||
bool Emf::StartPage(const gfx::Size& /*page_size*/,
|
||||
|
@ -124,7 +124,7 @@ SkDevice* PdfMetafileCairo::StartPageForVectorCanvas(
|
||||
if (!StartPage(page_size, content_area, scale_factor))
|
||||
return NULL;
|
||||
|
||||
return skia::VectorPlatformDeviceCairoFactory::CreateDevice(
|
||||
return skia::VectorPlatformDeviceCairo::CreateDevice(
|
||||
context_, page_size.width(), page_size.height(), true);
|
||||
}
|
||||
|
||||
|
@ -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() {
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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.
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -14,21 +14,16 @@
|
||||
|
||||
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:
|
||||
SK_API 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 +76,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
|
||||
|
@ -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
|
||||
|
@ -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_;
|
||||
|
Reference in New Issue
Block a user