Skip to content

Commit

Permalink
Stop using deprecated factory API for SkDevice
Browse files Browse the repository at this point in the history
Review URL: http://codereview.chromium.org/7273013

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@91504 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
reed@google.com committed Jul 5, 2011
1 parent eeba537 commit c6c09d4
Show file tree
Hide file tree
Showing 21 changed files with 74 additions and 180 deletions.
6 changes: 3 additions & 3 deletions printing/emf_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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*/,
Expand Down
2 changes: 1 addition & 1 deletion printing/pdf_metafile_cairo_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
16 changes: 5 additions & 11 deletions skia/ext/bitmap_platform_device_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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() {
Expand Down
12 changes: 3 additions & 9 deletions skia/ext/bitmap_platform_device_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 5 additions & 11 deletions skia/ext/bitmap_platform_device_mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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
13 changes: 3 additions & 10 deletions skia/ext/bitmap_platform_device_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
16 changes: 5 additions & 11 deletions skia/ext/bitmap_platform_device_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand Down
12 changes: 3 additions & 9 deletions skia/ext/bitmap_platform_device_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions skia/ext/platform_canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion skia/ext/platform_canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions skia/ext/platform_canvas_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
3 changes: 0 additions & 3 deletions skia/ext/platform_canvas_mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,20 @@
namespace skia {

PlatformCanvas::PlatformCanvas(int width, int height, bool is_opaque) {
setDeviceFactory(SkNEW(BitmapPlatformDeviceFactory))->unref();
initialize(width, height, is_opaque);
}

PlatformCanvas::PlatformCanvas(int width,
int height,
bool is_opaque,
CGContextRef context) {
setDeviceFactory(SkNEW(BitmapPlatformDeviceFactory))->unref();
initialize(context, width, height, is_opaque);
}

PlatformCanvas::PlatformCanvas(int width,
int height,
bool is_opaque,
uint8_t* data) {
setDeviceFactory(SkNEW(BitmapPlatformDeviceFactory))->unref();
initialize(width, height, is_opaque, data);
}

Expand Down
2 changes: 0 additions & 2 deletions skia/ext/platform_canvas_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions skia/ext/vector_canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}

Expand Down
4 changes: 2 additions & 2 deletions skia/ext/vector_canvas_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
40 changes: 11 additions & 29 deletions skia/ext/vector_platform_device_cairo_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);

Expand All @@ -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;
}
Expand Down
Loading

0 comments on commit c6c09d4

Please sign in to comment.