aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-01-31 19:42:58 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-01-31 19:42:58 +0000
commite254310a55d55a710309714c48f7fbbe7a6126f7 (patch)
tree4676918f0af988ca0f21fefb948477e818244cf0
parent2fc672dd460ea91e9fc824a35e39518ab838762c (diff)
add SkCanvas constructor that explicitly creates no_config with dimensions
BUG=skia: R=scroggo@google.com, halcanary@google.com Author: reed@google.com Review URL: https://codereview.chromium.org/137833016 git-svn-id: http://skia.googlecode.com/svn/trunk@13272 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--include/core/SkCanvas.h11
-rw-r--r--src/core/SkCanvas.cpp21
-rw-r--r--src/utils/SkDumpCanvas.cpp10
-rw-r--r--src/utils/SkLuaCanvas.cpp8
-rw-r--r--src/utils/SkNWayCanvas.cpp8
-rw-r--r--src/utils/debugger/SkDebugCanvas.cpp8
-rw-r--r--tests/PictureTest.cpp7
7 files changed, 36 insertions, 37 deletions
diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h
index 5a5cc65f0b..c98ad996f0 100644
--- a/include/core/SkCanvas.h
+++ b/include/core/SkCanvas.h
@@ -49,8 +49,19 @@ class SK_API SkCanvas : public SkRefCnt {
public:
SK_DECLARE_INST_COUNT(SkCanvas)
+ /**
+ * Creates an empty canvas with no backing device/pixels, and zero
+ * dimensions.
+ */
SkCanvas();
+ /**
+ * Creates a canvas of the specified dimensions, but explicitly not backed
+ * by any device/pixels. Typically this use used by subclasses who handle
+ * the draw calls in some other way.
+ */
+ SkCanvas(int width, int height);
+
/** Construct a canvas with the specified device to draw into.
@param device Specifies a device for the canvas to draw into.
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index a5fa30ff2d..45c196448d 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -505,21 +505,34 @@ SkBaseDevice* SkCanvas::init(SkBaseDevice* device) {
}
SkCanvas::SkCanvas()
-: fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) {
+ : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage))
+{
inc_canvas();
-
+
this->init(NULL);
}
+SkCanvas::SkCanvas(int width, int height)
+ : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage))
+{
+ inc_canvas();
+
+ SkBitmap bitmap;
+ bitmap.setConfig(SkBitmap::kNo_Config, width, height);
+ this->init(SkNEW_ARGS(SkBitmapDevice, (bitmap)))->unref();
+}
+
SkCanvas::SkCanvas(SkBaseDevice* device)
- : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) {
+ : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage))
+{
inc_canvas();
this->init(device);
}
SkCanvas::SkCanvas(const SkBitmap& bitmap)
- : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) {
+ : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage))
+{
inc_canvas();
this->init(SkNEW_ARGS(SkBitmapDevice, (bitmap)))->unref();
diff --git a/src/utils/SkDumpCanvas.cpp b/src/utils/SkDumpCanvas.cpp
index dabf0d7989..5f3a572ab9 100644
--- a/src/utils/SkDumpCanvas.cpp
+++ b/src/utils/SkDumpCanvas.cpp
@@ -163,15 +163,9 @@ static void toString(const void* text, size_t byteLen, SkPaint::TextEncoding enc
///////////////////////////////////////////////////////////////////////////////
-static SkBitmap make_wideopen_bm() {
- static const int WIDE_OPEN = 16384;
+#define WIDE_OPEN 16384
- SkBitmap bm;
- bm.setConfig(SkBitmap::kNo_Config, WIDE_OPEN, WIDE_OPEN);
- return bm;
-}
-
-SkDumpCanvas::SkDumpCanvas(Dumper* dumper) : INHERITED(make_wideopen_bm()) {
+SkDumpCanvas::SkDumpCanvas(Dumper* dumper) : INHERITED(WIDE_OPEN, WIDE_OPEN) {
fNestLevel = 0;
SkSafeRef(dumper);
fDumper = dumper;
diff --git a/src/utils/SkLuaCanvas.cpp b/src/utils/SkLuaCanvas.cpp
index 0136231ce1..7f127403ae 100644
--- a/src/utils/SkLuaCanvas.cpp
+++ b/src/utils/SkLuaCanvas.cpp
@@ -73,14 +73,8 @@ void SkLuaCanvas::pushThis() {
///////////////////////////////////////////////////////////////////////////////
-static SkBitmap make_bm(int width, int height) {
- SkBitmap bm;
- bm.setConfig(SkBitmap::kNo_Config, width, height);
- return bm;
-}
-
SkLuaCanvas::SkLuaCanvas(int width, int height, lua_State* L, const char func[])
- : INHERITED(make_bm(width, height))
+ : INHERITED(width, height)
, fL(L)
, fFunc(func) {
}
diff --git a/src/utils/SkNWayCanvas.cpp b/src/utils/SkNWayCanvas.cpp
index da8bdb6f41..831d7bf6cf 100644
--- a/src/utils/SkNWayCanvas.cpp
+++ b/src/utils/SkNWayCanvas.cpp
@@ -7,14 +7,8 @@
*/
#include "SkNWayCanvas.h"
-static SkBitmap make_noconfig_bm(int width, int height) {
- SkBitmap bm;
- bm.setConfig(SkBitmap::kNo_Config, width, height);
- return bm;
-}
-
SkNWayCanvas::SkNWayCanvas(int width, int height)
- : INHERITED(make_noconfig_bm(width, height)) {}
+ : INHERITED(width, height) {}
SkNWayCanvas::~SkNWayCanvas() {
this->removeAll();
diff --git a/src/utils/debugger/SkDebugCanvas.cpp b/src/utils/debugger/SkDebugCanvas.cpp
index 1c3e26e643..32a6570954 100644
--- a/src/utils/debugger/SkDebugCanvas.cpp
+++ b/src/utils/debugger/SkDebugCanvas.cpp
@@ -14,14 +14,8 @@
#include "SkDevice.h"
#include "SkXfermode.h"
-static SkBitmap make_noconfig_bm(int width, int height) {
- SkBitmap bm;
- bm.setConfig(SkBitmap::kNo_Config, width, height);
- return bm;
-}
-
SkDebugCanvas::SkDebugCanvas(int width, int height)
- : INHERITED(make_noconfig_bm(width, height))
+ : INHERITED(width, height)
, fWidth(width)
, fHeight(height)
, fFilter(false)
diff --git a/tests/PictureTest.cpp b/tests/PictureTest.cpp
index 5aaf73bdfb..7665b13d7e 100644
--- a/tests/PictureTest.cpp
+++ b/tests/PictureTest.cpp
@@ -922,8 +922,8 @@ static void test_clip_bound_opt(skiatest::Reporter* reporter) {
*/
class ClipCountingCanvas : public SkCanvas {
public:
- explicit ClipCountingCanvas(SkBaseDevice* device)
- : SkCanvas(device)
+ explicit ClipCountingCanvas(int width, int height)
+ : INHERITED(width, height)
, fClipCount(0){
}
@@ -965,8 +965,7 @@ static void test_clip_expansion(skiatest::Reporter* reporter) {
p.setColor(SK_ColorBLUE);
canvas->drawPaint(p);
- SkBitmapDevice testDevice(SkBitmap::kNo_Config, 10, 10);
- ClipCountingCanvas testCanvas(&testDevice);
+ ClipCountingCanvas testCanvas(10, 10);
picture.draw(&testCanvas);
// Both clips should be present on playback.