aboutsummaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authortedbo <tedbo@google.com>2010-11-10 17:07:37 -0800
committertedbo <tedbo@google.com>2010-11-11 09:21:15 -0800
commit20ab88413000fcc8668eeab25d9cb714097d0c45 (patch)
tree6510be768788bfe613b3061b1dbda0b848378b74 /src/core
parent25c9ae8253171f35b9a14dd2adc5775929330e7b (diff)
downloadexternal_skia-20ab88413000fcc8668eeab25d9cb714097d0c45.zip
external_skia-20ab88413000fcc8668eeab25d9cb714097d0c45.tar.gz
external_skia-20ab88413000fcc8668eeab25d9cb714097d0c45.tar.bz2
Skia: Merge upstream patch series that refactors SkCanvas to avoid subclassing.
This change merges upstream Skia revisions r604,r605,r618, and r623. The patch series refactors SkCanvas so that backends don't need to override it. The r623 patch was upstreamed explicitly so that this series can be made into a clean patch for Android to avoid merge conflicts in the future. The log messages from the original commits are as follows: * r604: http://code.google.com/p/skia/source/detail?r=604 Refactor SkCanvas so that backends don't need to override it. Methods or classes that should go away are marked deprecated. The only thing I know of that breaks backward compatibility is SkCanvas((SkDevice*)NULL), but that is fairly unlikely to occur in the wild because that constructor had a default value of NULL. * r605: http://code.google.com/p/skia/source/detail?r=605 Fix a memory leak in the new Canvas/Device workflow. The previous change made it difficult to inherit from SkCanvas without leaking memory. By making SkDeviceFactory not reference counted, the right thing happens more naturally, just NewCanvas : public SkCanvas(new NewDeviceFactory()) {...} * r618: http://code.google.com/p/skia/source/detail?r=618 Move the device capability method to SkDevice. These are not the capabilities of the factory, but of the device. Additionally, it is more often needed when you have a device then when you have a factory, which caused creating of a new factory. * r623: http://code.google.com/p/skia/source/detail?r=623 Remove include of SkGLDevice.h from SkGLCanvas.h The '#include "SkGLDevice.h"' from include/core/SkDevice.h requires internal Skia code to be added to the include search paths when using the deprecated API. This change adds back SkGLCanvas.cpp to avoid exposing SkGLDevice.h to the public API. The change also includes an explicit virtual destructor on SkDeviceFactory to silence a -Wnon-virtual-dtor warning and allow for -Werror. Change-Id: I3442e2801c1d8d8c9cb2a20259f15bc870c393dc
Diffstat (limited to 'src/core')
-rw-r--r--src/core/SkCanvas.cpp48
-rw-r--r--src/core/SkDevice.cpp14
2 files changed, 45 insertions, 17 deletions
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index 26e39b5..94c2439 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -404,8 +404,20 @@ SkDevice* SkCanvas::init(SkDevice* device) {
return this->setDevice(device);
}
+SkCanvas::SkCanvas(SkDeviceFactory* factory)
+ : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)),
+ fDeviceFactory(factory) {
+ inc_canvas();
+
+ if (!factory)
+ fDeviceFactory = SkNEW(SkRasterDeviceFactory);
+
+ this->init(NULL);
+}
+
SkCanvas::SkCanvas(SkDevice* device)
- : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) {
+ : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)),
+ fDeviceFactory(device->getDeviceFactory()) {
inc_canvas();
this->init(device);
@@ -415,7 +427,9 @@ SkCanvas::SkCanvas(const SkBitmap& bitmap)
: fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) {
inc_canvas();
- this->init(SkNEW_ARGS(SkDevice, (bitmap)))->unref();
+ SkDevice* device = SkNEW_ARGS(SkDevice, (bitmap));
+ fDeviceFactory = device->getDeviceFactory();
+ this->init(device)->unref();
}
SkCanvas::~SkCanvas() {
@@ -423,8 +437,9 @@ SkCanvas::~SkCanvas() {
this->restoreToCount(1); // restore everything but the last
this->internalRestore(); // restore the last, since we're going away
- fBounder->safeUnref();
-
+ SkSafeUnref(fBounder);
+ SkDELETE(fDeviceFactory);
+
dec_canvas();
}
@@ -521,11 +536,19 @@ SkDevice* SkCanvas::setBitmapDevice(const SkBitmap& bitmap) {
//////////////////////////////////////////////////////////////////////////////
bool SkCanvas::getViewport(SkIPoint* size) const {
- return false;
+ if ((getDevice()->getDeviceCapabilities() & SkDevice::kGL_Capability) == 0)
+ return false;
+ if (size)
+ size->set(getDevice()->width(), getDevice()->height());
+ return true;
}
bool SkCanvas::setViewport(int width, int height) {
- return false;
+ if ((getDevice()->getDeviceCapabilities() & SkDevice::kGL_Capability) == 0)
+ return false;
+ this->setDevice(createDevice(SkBitmap::kARGB_8888_Config, width, height,
+ false, false))->unref();
+ return true;
}
void SkCanvas::updateDeviceCMCache() {
@@ -1004,18 +1027,9 @@ const SkRegion& SkCanvas::getTotalClip() const {
SkDevice* SkCanvas::createDevice(SkBitmap::Config config, int width,
int height, bool isOpaque, bool isForLayer) {
- SkBitmap bitmap;
-
- bitmap.setConfig(config, width, height);
- bitmap.setIsOpaque(isOpaque);
-
- // should this happen in the device subclass?
- bitmap.allocPixels();
- if (!bitmap.isOpaque()) {
- bitmap.eraseARGB(0, 0, 0, 0);
- }
- return SkNEW_ARGS(SkDevice, (bitmap));
+ return fDeviceFactory->newDevice(config, width, height, isOpaque,
+ isForLayer);
}
//////////////////////////////////////////////////////////////////////////////
diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp
index 8ce1bd8..b629e9a 100644
--- a/src/core/SkDevice.cpp
+++ b/src/core/SkDevice.cpp
@@ -2,6 +2,8 @@
#include "SkDraw.h"
#include "SkRect.h"
+SkDeviceFactory::~SkDeviceFactory() {}
+
SkDevice::SkDevice() {}
SkDevice::SkDevice(const SkBitmap& bitmap) : fBitmap(bitmap) {}
@@ -113,4 +115,16 @@ void SkDevice::drawDevice(const SkDraw& draw, SkDevice* device,
draw.drawSprite(device->accessBitmap(false), x, y, paint);
}
+SkDevice* SkRasterDeviceFactory::newDevice(SkBitmap::Config config, int width,
+ int height, bool isOpaque,
+ bool isForLayer) {
+ SkBitmap bitmap;
+ bitmap.setConfig(config, width, height);
+ bitmap.setIsOpaque(isOpaque);
+
+ bitmap.allocPixels();
+ if (!bitmap.isOpaque())
+ bitmap.eraseARGB(0, 0, 0, 0);
+ return SkNEW_ARGS(SkDevice, (bitmap));
+}