aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-06-17 13:10:25 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-06-17 13:10:25 +0000
commite97f0856a8044866b12527819d14cdfbcdfd96f2 (patch)
treed0273fcd80930ebfbb0e2640dd6d0adf3bbbf632 /src/core
parenta54e2f61f8d181b95dd1757d405eacf9f6a9d792 (diff)
Add createNewCompatibleDevice. Allow devices to have a NULL factory and saveLayer will fall back on createNewCompatibleDevice.
Review URL: http://codereview.appspot.com/4633044/ git-svn-id: http://skia.googlecode.com/svn/trunk@1625 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core')
-rw-r--r--src/core/SkCanvas.cpp44
-rw-r--r--src/core/SkDevice.cpp23
2 files changed, 54 insertions, 13 deletions
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index 5b2e96459e..0b6f086313 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -434,10 +434,9 @@ SkCanvas::SkCanvas(SkDevice* device)
: fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) {
inc_canvas();
- fDeviceFactory = device->getDeviceFactory();
- SkASSERT(fDeviceFactory);
- fDeviceFactory->ref();
-
+ fDeviceFactory = device->getDeviceFactory();
+ SkSafeRef(fDeviceFactory);
+
this->init(device);
}
@@ -446,9 +445,8 @@ SkCanvas::SkCanvas(const SkBitmap& bitmap)
inc_canvas();
SkDevice* device = SkNEW_ARGS(SkDevice, (bitmap));
- fDeviceFactory = device->getDeviceFactory();
- SkASSERT(fDeviceFactory);
- fDeviceFactory->ref();
+ fDeviceFactory = device->getDeviceFactory();
+ SkSafeRef(fDeviceFactory);
this->init(device)->unref();
}
@@ -736,8 +734,9 @@ int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint,
bool isOpaque;
SkBitmap::Config config = resolve_config(this, ir, flags, &isOpaque);
- SkDevice* device = this->createDevice(config, ir.width(), ir.height(),
- isOpaque);
+ SkDevice* device = this->createLayerDevice(config, ir.width(), ir.height(),
+ isOpaque);
+
device->setOrigin(ir.fLeft, ir.fTop);
DeviceCM* layer = SkNEW_ARGS(DeviceCM, (device, ir.fLeft, ir.fTop, paint));
device->unref();
@@ -1176,11 +1175,32 @@ void SkCanvas::setExternalMatrix(const SkMatrix* matrix) {
}
}
-SkDevice* SkCanvas::createDevice(SkBitmap::Config config, int width, int height,
- bool isOpaque) {
- return fDeviceFactory->newDevice(this, config, width, height, isOpaque, true);
+SkDevice* SkCanvas::createLayerDevice(SkBitmap::Config config,
+ int width, int height,
+ bool isOpaque) {
+ if (fDeviceFactory) {
+ return fDeviceFactory->newDevice(this, config, width, height,
+ isOpaque, true);
+ } else {
+ return this->getDevice()->createCompatibleDeviceForSaveLayer(
+ config, width, height,
+ isOpaque);
+ }
}
+SkDevice* SkCanvas::createCompatibleDevice(SkBitmap::Config config,
+ int width, int height,
+ bool isOpaque) {
+ SkDevice* device = this->getDevice();
+ if (device) {
+ return device->createCompatibleDevice(config, width, height,
+ isOpaque);
+ } else {
+ return NULL;
+ }
+}
+
+
//////////////////////////////////////////////////////////////////////////////
// These are the virtual drawing methods
//////////////////////////////////////////////////////////////////////////////
diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp
index 0c0133558b..ae283b04ef 100644
--- a/src/core/SkDevice.cpp
+++ b/src/core/SkDevice.cpp
@@ -57,7 +57,7 @@ SkDevice::~SkDevice() {
}
SkDeviceFactory* SkDevice::onNewDeviceFactory() {
- return SkNEW(SkRasterDeviceFactory);
+ return NULL;
}
SkDeviceFactory* SkDevice::getDeviceFactory() {
@@ -67,6 +67,27 @@ SkDeviceFactory* SkDevice::getDeviceFactory() {
return fCachedDeviceFactory;
}
+SkDevice* SkDevice::createCompatibleDevice(SkBitmap::Config config,
+ int width, int height,
+ bool isOpaque) {
+ return this->onCreateCompatibleDevice(config, width, height,
+ isOpaque, kGeneral_Usage);
+}
+
+SkDevice* SkDevice::createCompatibleDeviceForSaveLayer(SkBitmap::Config config,
+ int width, int height,
+ bool isOpaque) {
+ return this->onCreateCompatibleDevice(config, width, height,
+ isOpaque, kSaveLayer_Usage);
+}
+
+SkDevice* SkDevice::onCreateCompatibleDevice(SkBitmap::Config config,
+ int width, int height,
+ bool isOpaque,
+ Usage usage) {
+ return SkNEW_ARGS(SkDevice,(config, width, height, isOpaque));
+}
+
SkMetaData& SkDevice::getMetaData() {
// metadata users are rare, so we lazily allocate it. If that changes we
// can decide to just make it a field in the device (rather than a ptr)