aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2014-09-04 14:12:44 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-09-04 14:12:44 -0700
commit29dfaa80f5776904f42b72b387a99e75f8dc5f5f (patch)
treeebdb3333ae2326d0f0438d738d4360836119ae07 /src
parent52354b6df7da17a69b3f34f4e22de86fa5674006 (diff)
Implement all SkCanvas overrides that SkPictureRecord does.
Primarily this is for isDrawingToLayer(). drawData() and onNewSurface() are for completeness. BUG=409138 R=robertphillips@google.com, mtklein@google.com, reed@google.com Author: mtklein@chromium.org Review URL: https://codereview.chromium.org/545613002
Diffstat (limited to 'src')
-rw-r--r--src/core/SkRecordDraw.cpp2
-rw-r--r--src/core/SkRecorder.cpp20
-rw-r--r--src/core/SkRecorder.h9
-rw-r--r--src/core/SkRecords.h5
4 files changed, 34 insertions, 2 deletions
diff --git a/src/core/SkRecordDraw.cpp b/src/core/SkRecordDraw.cpp
index 67402dd808..3845a5c3dc 100644
--- a/src/core/SkRecordDraw.cpp
+++ b/src/core/SkRecordDraw.cpp
@@ -108,6 +108,7 @@ DRAW(DrawTextBlob, drawTextBlob(r.blob, r.x, r.y, r.paint));
DRAW(DrawTextOnPath, drawTextOnPath(r.text, r.byteLength, r.path, r.matrix, r.paint));
DRAW(DrawVertices, drawVertices(r.vmode, r.vertexCount, r.vertices, r.texs, r.colors,
r.xmode.get(), r.indices, r.indexCount, r.paint));
+DRAW(DrawData, drawData(r.data, r.length));
#undef DRAW
@@ -212,6 +213,7 @@ private:
void trackBounds(const BeginCommentGroup&) { this->pushControl(); }
void trackBounds(const AddComment&) { this->pushControl(); }
void trackBounds(const EndCommentGroup&) { this->pushControl(); }
+ void trackBounds(const DrawData&) { this->pushControl(); }
// For all other ops, we can calculate and store the bounds directly now.
template <typename T> void trackBounds(const T& op) {
diff --git a/src/core/SkRecorder.cpp b/src/core/SkRecorder.cpp
index df3e1d8fa5..86578a53b8 100644
--- a/src/core/SkRecorder.cpp
+++ b/src/core/SkRecorder.cpp
@@ -11,7 +11,9 @@
// SkCanvas will fail in mysterious ways if it doesn't know the real width and height.
SkRecorder::SkRecorder(SkRecord* record, int width, int height)
- : SkCanvas(width, height), fRecord(record) {}
+ : SkCanvas(width, height)
+ , fRecord(record)
+ , fSaveLayerCount(0) {}
void SkRecorder::forgetRecord() {
fRecord = NULL;
@@ -229,17 +231,25 @@ void SkRecorder::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
}
void SkRecorder::willSave() {
+ fSaveIsSaveLayer.push(false);
APPEND(Save);
}
SkCanvas::SaveLayerStrategy SkRecorder::willSaveLayer(const SkRect* bounds,
const SkPaint* paint,
SkCanvas::SaveFlags flags) {
+ fSaveLayerCount++;
+ fSaveIsSaveLayer.push(true);
APPEND(SaveLayer, this->copy(bounds), this->copy(paint), flags);
return SkCanvas::kNoLayer_SaveLayerStrategy;
}
void SkRecorder::didRestore() {
+ SkBool8 saveLayer;
+ fSaveIsSaveLayer.pop(&saveLayer);
+ if (saveLayer) {
+ fSaveLayerCount--;
+ }
APPEND(Restore, this->devBounds(), this->getTotalMatrix());
}
@@ -295,3 +305,11 @@ void SkRecorder::addComment(const char* key, const char* value) {
void SkRecorder::endCommentGroup() {
APPEND(EndCommentGroup);
}
+
+bool SkRecorder::isDrawingToLayer() const {
+ return fSaveLayerCount > 0;
+}
+
+void SkRecorder::drawData(const void* data, size_t length) {
+ APPEND(DrawData, copy((const char*)data), length);
+}
diff --git a/src/core/SkRecorder.h b/src/core/SkRecorder.h
index 683d29b411..db57eb0702 100644
--- a/src/core/SkRecorder.h
+++ b/src/core/SkRecorder.h
@@ -11,6 +11,7 @@
#include "SkCanvas.h"
#include "SkRecord.h"
#include "SkRecords.h"
+#include "SkTDArray.h"
// SkRecorder provides an SkCanvas interface for recording into an SkRecord.
@@ -64,6 +65,7 @@ public:
void willSave() SK_OVERRIDE;
SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SkCanvas::SaveFlags) SK_OVERRIDE;
+ void willRestore() SK_OVERRIDE {}
void didRestore() SK_OVERRIDE;
void didConcat(const SkMatrix&) SK_OVERRIDE;
@@ -110,6 +112,10 @@ public:
void beginCommentGroup(const char*) SK_OVERRIDE;
void addComment(const char*, const char*) SK_OVERRIDE;
void endCommentGroup() SK_OVERRIDE;
+ void drawData(const void*, size_t) SK_OVERRIDE;
+
+ bool isDrawingToLayer() const SK_OVERRIDE;
+ SkSurface* onNewSurface(const SkImageInfo&) SK_OVERRIDE { return NULL; }
private:
template <typename T>
@@ -125,6 +131,9 @@ private:
}
SkRecord* fRecord;
+
+ int fSaveLayerCount;
+ SkTDArray<SkBool8> fSaveIsSaveLayer;
};
#endif//SkRecorder_DEFINED
diff --git a/src/core/SkRecords.h b/src/core/SkRecords.h
index bd65fc5cb6..c1c5596b15 100644
--- a/src/core/SkRecords.h
+++ b/src/core/SkRecords.h
@@ -58,7 +58,8 @@ namespace SkRecords {
M(DrawRRect) \
M(DrawRect) \
M(DrawSprite) \
- M(DrawTextBlob) \
+ M(DrawTextBlob) \
+ M(DrawData) \
M(DrawVertices)
// Defines SkRecords::Type, an enum of all record types.
@@ -270,6 +271,8 @@ RECORD5(DrawTextOnPath, SkPaint, paint,
SkPath, path,
Optional<SkMatrix>, matrix);
+RECORD2(DrawData, PODArray<char>, data, size_t, length);
+
// This guy is so ugly we just write it manually.
struct DrawVertices {
static const Type kType = DrawVertices_Type;