aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/utils
diff options
context:
space:
mode:
authorGravatar fmalita@google.com <fmalita@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-03-11 21:04:41 +0000
committerGravatar fmalita@google.com <fmalita@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-03-11 21:04:41 +0000
commit80b10518a27a47b25a7dbf3591b425a741ebf406 (patch)
tree36fa760bd4967c817b6d272c957d28c154991ed6 /src/utils
parent53ba425c91202ef4f78e45f71c330d847a1f8faa (diff)
De-virtualize SkCanvas save/restore.
This moves the state management logic into non-virtual SkCanvas methods, and turns the virtuals into protected notifiers. R=robertphillips@google.com, reed@google.com Review URL: https://codereview.chromium.org/194713008 git-svn-id: http://skia.googlecode.com/svn/trunk@13747 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/SkDeferredCanvas.cpp21
-rw-r--r--src/utils/SkDumpCanvas.cpp14
-rw-r--r--src/utils/SkLuaCanvas.cpp17
-rw-r--r--src/utils/SkNWayCanvas.cpp18
-rw-r--r--src/utils/SkNoSaveLayerCanvas.h18
-rw-r--r--src/utils/SkProxyCanvas.cpp17
-rw-r--r--src/utils/debugger/SkDebugCanvas.cpp21
-rw-r--r--src/utils/debugger/SkDebugCanvas.h10
8 files changed, 69 insertions, 67 deletions
diff --git a/src/utils/SkDeferredCanvas.cpp b/src/utils/SkDeferredCanvas.cpp
index efe750188e..8b617b30e8 100644
--- a/src/utils/SkDeferredCanvas.cpp
+++ b/src/utils/SkDeferredCanvas.cpp
@@ -739,28 +739,25 @@ bool SkDeferredCanvas::isFullFrame(const SkRect* rect,
SkIntToScalar(canvasSize.fWidth), SkIntToScalar(canvasSize.fHeight)));
}
-int SkDeferredCanvas::save(SaveFlags flags) {
+void SkDeferredCanvas::onSave(SaveFlags flags) {
this->drawingCanvas()->save(flags);
- int val = this->INHERITED::save(flags);
this->recordedDrawCommand();
-
- return val;
+ this->INHERITED::onSave(flags);
}
-int SkDeferredCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint,
- SaveFlags flags) {
+bool SkDeferredCanvas::onSaveLayer(const SkRect* bounds, const SkPaint* paint,
+ SaveFlags flags) {
this->drawingCanvas()->saveLayer(bounds, paint, flags);
- int count = this->INHERITED::save(flags);
- this->clipRectBounds(bounds, flags, NULL);
this->recordedDrawCommand();
-
- return count;
+ this->INHERITED::onSaveLayer(bounds, paint, flags);
+ // No need for a full layer.
+ return false;
}
-void SkDeferredCanvas::restore() {
+void SkDeferredCanvas::onRestore() {
this->drawingCanvas()->restore();
- this->INHERITED::restore();
this->recordedDrawCommand();
+ this->INHERITED::onRestore();
}
bool SkDeferredCanvas::isDrawingToLayer() const {
diff --git a/src/utils/SkDumpCanvas.cpp b/src/utils/SkDumpCanvas.cpp
index 4805d6287c..ccc5124f30 100644
--- a/src/utils/SkDumpCanvas.cpp
+++ b/src/utils/SkDumpCanvas.cpp
@@ -192,13 +192,13 @@ void SkDumpCanvas::dump(Verb verb, const SkPaint* paint,
///////////////////////////////////////////////////////////////////////////////
-int SkDumpCanvas::save(SaveFlags flags) {
+void SkDumpCanvas::onSave(SaveFlags flags) {
this->dump(kSave_Verb, NULL, "save(0x%X)", flags);
- return this->INHERITED::save(flags);
+ this->INHERITED::onSave(flags);
}
-int SkDumpCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint,
- SaveFlags flags) {
+bool SkDumpCanvas::onSaveLayer(const SkRect* bounds, const SkPaint* paint,
+ SaveFlags flags) {
SkString str;
str.printf("saveLayer(0x%X)", flags);
if (bounds) {
@@ -214,12 +214,12 @@ int SkDumpCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint,
}
}
this->dump(kSave_Verb, paint, str.c_str());
- return this->INHERITED::saveLayer(bounds, paint, flags);
+ return this->INHERITED::onSaveLayer(bounds, paint, flags);
}
-void SkDumpCanvas::restore() {
- this->INHERITED::restore();
+void SkDumpCanvas::onRestore() {
this->dump(kRestore_Verb, NULL, "restore");
+ this->INHERITED::onRestore();
}
bool SkDumpCanvas::translate(SkScalar dx, SkScalar dy) {
diff --git a/src/utils/SkLuaCanvas.cpp b/src/utils/SkLuaCanvas.cpp
index 0f13073049..2679fd25bd 100644
--- a/src/utils/SkLuaCanvas.cpp
+++ b/src/utils/SkLuaCanvas.cpp
@@ -81,13 +81,13 @@ SkLuaCanvas::SkLuaCanvas(int width, int height, lua_State* L, const char func[])
SkLuaCanvas::~SkLuaCanvas() {}
-int SkLuaCanvas::save(SaveFlags flags) {
+void SkLuaCanvas::onSave(SaveFlags flags) {
AUTO_LUA("save");
- return this->INHERITED::save(flags);
+ this->INHERITED::onSave(flags);
}
-int SkLuaCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint,
- SaveFlags flags) {
+bool SkLuaCanvas::onSaveLayer(const SkRect* bounds, const SkPaint* paint,
+ SaveFlags flags) {
AUTO_LUA("saveLayer");
if (bounds) {
lua.pushRect(*bounds, "bounds");
@@ -95,12 +95,15 @@ int SkLuaCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint,
if (paint) {
lua.pushPaint(*paint, "paint");
}
- return this->INHERITED::save(flags);
+
+ this->INHERITED::onSaveLayer(bounds, paint, flags);
+ // No need for a layer.
+ return false;
}
-void SkLuaCanvas::restore() {
+void SkLuaCanvas::onRestore() {
AUTO_LUA("restore");
- this->INHERITED::restore();
+ this->INHERITED::onRestore();
}
bool SkLuaCanvas::translate(SkScalar dx, SkScalar dy) {
diff --git a/src/utils/SkNWayCanvas.cpp b/src/utils/SkNWayCanvas.cpp
index a9543f9c02..6fbec96204 100644
--- a/src/utils/SkNWayCanvas.cpp
+++ b/src/utils/SkNWayCanvas.cpp
@@ -57,29 +57,33 @@ private:
SkCanvas* fCanvas;
};
-int SkNWayCanvas::save(SaveFlags flags) {
+void SkNWayCanvas::onSave(SaveFlags flags) {
Iter iter(fList);
while (iter.next()) {
iter->save(flags);
}
- return this->INHERITED::save(flags);
+
+ this->INHERITED::onSave(flags);
}
-int SkNWayCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint,
- SaveFlags flags) {
+bool SkNWayCanvas::onSaveLayer(const SkRect* bounds, const SkPaint* paint,
+ SaveFlags flags) {
Iter iter(fList);
while (iter.next()) {
iter->saveLayer(bounds, paint, flags);
}
- return this->INHERITED::saveLayer(bounds, paint, flags);
+
+ this->INHERITED::onSaveLayer(bounds, paint, flags);
+ // No need for a layer.
+ return false;
}
-void SkNWayCanvas::restore() {
+void SkNWayCanvas::onRestore() {
Iter iter(fList);
while (iter.next()) {
iter->restore();
}
- this->INHERITED::restore();
+ this->INHERITED::onRestore();
}
bool SkNWayCanvas::translate(SkScalar dx, SkScalar dy) {
diff --git a/src/utils/SkNoSaveLayerCanvas.h b/src/utils/SkNoSaveLayerCanvas.h
index 60fad87237..037fcecab5 100644
--- a/src/utils/SkNoSaveLayerCanvas.h
+++ b/src/utils/SkNoSaveLayerCanvas.h
@@ -18,21 +18,13 @@ class SkNoSaveLayerCanvas : public SkCanvas {
public:
SkNoSaveLayerCanvas(SkBaseDevice* device) : INHERITED(device) {}
- // turn saveLayer() into save() for speed, should not affect correctness.
- virtual int saveLayer(const SkRect* bounds,
- const SkPaint* paint,
- SaveFlags flags) SK_OVERRIDE {
-
- // Like SkPictureRecord, we don't want to create layers, but we do need
- // to respect the save and (possibly) its rect-clip.
- int count = this->INHERITED::save(flags);
- if (NULL != bounds) {
- this->INHERITED::clipRectBounds(bounds, flags, NULL);
- }
- return count;
+protected:
+ virtual bool onSaveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags flags)
+ SK_OVERRIDE {
+ this->INHERITED::onSaveLayer(bounds, paint, flags);
+ return false;
}
-protected:
// disable aa for speed
virtual void onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle) SK_OVERRIDE {
this->INHERITED::onClipRect(rect, op, kHard_ClipEdgeStyle);
diff --git a/src/utils/SkProxyCanvas.cpp b/src/utils/SkProxyCanvas.cpp
index 0a9d7a80c2..f61a31d9b3 100644
--- a/src/utils/SkProxyCanvas.cpp
+++ b/src/utils/SkProxyCanvas.cpp
@@ -21,17 +21,22 @@ void SkProxyCanvas::setProxy(SkCanvas* proxy) {
///////////////////////////////// Overrides ///////////
-int SkProxyCanvas::save(SaveFlags flags) {
- return fProxy->save(flags);
+void SkProxyCanvas::onSave(SaveFlags flags) {
+ fProxy->save(flags);
+ this->INHERITED::onSave(flags);
}
-int SkProxyCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint,
- SaveFlags flags) {
- return fProxy->saveLayer(bounds, paint, flags);
+bool SkProxyCanvas::onSaveLayer(const SkRect* bounds, const SkPaint* paint,
+ SaveFlags flags) {
+ fProxy->saveLayer(bounds, paint, flags);
+ this->INHERITED::onSaveLayer(bounds, paint, flags);
+ // No need for a layer.
+ return false;
}
-void SkProxyCanvas::restore() {
+void SkProxyCanvas::onRestore() {
fProxy->restore();
+ this->INHERITED::onRestore();
}
bool SkProxyCanvas::translate(SkScalar dx, SkScalar dy) {
diff --git a/src/utils/debugger/SkDebugCanvas.cpp b/src/utils/debugger/SkDebugCanvas.cpp
index 08e6d94f9e..67ecc65b08 100644
--- a/src/utils/debugger/SkDebugCanvas.cpp
+++ b/src/utils/debugger/SkDebugCanvas.cpp
@@ -530,8 +530,9 @@ void SkDebugCanvas::onPopCull() {
this->addDrawCommand(new SkPopCullCommand());
}
-void SkDebugCanvas::restore() {
- addDrawCommand(new SkRestoreCommand());
+void SkDebugCanvas::onRestore() {
+ this->addDrawCommand(new SkRestoreCommand());
+ this->INHERITED::onRestore();
}
bool SkDebugCanvas::rotate(SkScalar degrees) {
@@ -539,15 +540,17 @@ bool SkDebugCanvas::rotate(SkScalar degrees) {
return true;
}
-int SkDebugCanvas::save(SaveFlags flags) {
- addDrawCommand(new SkSaveCommand(flags));
- return true;
+void SkDebugCanvas::onSave(SaveFlags flags) {
+ this->addDrawCommand(new SkSaveCommand(flags));
+ this->INHERITED::onSave(flags);
}
-int SkDebugCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint,
- SaveFlags flags) {
- addDrawCommand(new SkSaveLayerCommand(bounds, paint, flags));
- return true;
+bool SkDebugCanvas::onSaveLayer(const SkRect* bounds, const SkPaint* paint,
+ SaveFlags flags) {
+ this->addDrawCommand(new SkSaveLayerCommand(bounds, paint, flags));
+ this->INHERITED::onSaveLayer(bounds, paint, flags);
+ // No need for a full layer.
+ return false;
}
bool SkDebugCanvas::scale(SkScalar sx, SkScalar sy) {
diff --git a/src/utils/debugger/SkDebugCanvas.h b/src/utils/debugger/SkDebugCanvas.h
index 0bbb640a98..24824c964d 100644
--- a/src/utils/debugger/SkDebugCanvas.h
+++ b/src/utils/debugger/SkDebugCanvas.h
@@ -206,14 +206,8 @@ public:
const uint16_t indices[], int indexCount,
const SkPaint&) SK_OVERRIDE;
- virtual void restore() SK_OVERRIDE;
-
virtual bool rotate(SkScalar degrees) SK_OVERRIDE;
- virtual int save(SaveFlags) SK_OVERRIDE;
-
- virtual int saveLayer(const SkRect* bounds, const SkPaint*, SaveFlags) SK_OVERRIDE;
-
virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE;
virtual void setMatrix(const SkMatrix& matrix) SK_OVERRIDE;
@@ -248,6 +242,10 @@ public:
}
protected:
+ virtual void onSave(SaveFlags) SK_OVERRIDE;
+ virtual bool onSaveLayer(const SkRect*, const SkPaint*, SaveFlags) SK_OVERRIDE;
+ virtual void onRestore() SK_OVERRIDE;
+
virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE;
virtual void onPushCull(const SkRect& cullRect) SK_OVERRIDE;
virtual void onPopCull() SK_OVERRIDE;