aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkRecorder.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/SkRecorder.cpp')
-rw-r--r--src/core/SkRecorder.cpp36
1 files changed, 28 insertions, 8 deletions
diff --git a/src/core/SkRecorder.cpp b/src/core/SkRecorder.cpp
index 0a2d43edbf..45283f8118 100644
--- a/src/core/SkRecorder.cpp
+++ b/src/core/SkRecorder.cpp
@@ -5,6 +5,7 @@
* found in the LICENSE file.
*/
+#include "SkBigPicture.h"
#include "SkPatchUtils.h"
#include "SkPicture.h"
#include "SkPictureUtils.h"
@@ -14,7 +15,7 @@ SkDrawableList::~SkDrawableList() {
fArray.unrefAll();
}
-SkPicture::SnapshotArray* SkDrawableList::newDrawableSnapshot() {
+SkBigPicture::SnapshotArray* SkDrawableList::newDrawableSnapshot() {
const int count = fArray.count();
if (0 == count) {
return NULL;
@@ -23,7 +24,7 @@ SkPicture::SnapshotArray* SkDrawableList::newDrawableSnapshot() {
for (int i = 0; i < count; ++i) {
pics[i] = fArray[i]->newPictureSnapshot();
}
- return SkNEW_ARGS(SkPicture::SnapshotArray, (pics.detach(), count));
+ return SkNEW_ARGS(SkBigPicture::SnapshotArray, (pics.detach(), count));
}
void SkDrawableList::append(SkDrawable* drawable) {
@@ -32,20 +33,23 @@ void SkDrawableList::append(SkDrawable* drawable) {
///////////////////////////////////////////////////////////////////////////////////////////////
-SkRecorder::SkRecorder(SkRecord* record, int width, int height)
+SkRecorder::SkRecorder(SkRecord* record, int width, int height, SkMiniRecorder* mr)
: SkCanvas(SkIRect::MakeWH(width, height), SkCanvas::kConservativeRasterClip_InitFlag)
, fApproxBytesUsedBySubPictures(0)
- , fRecord(record) {}
+ , fRecord(record)
+ , fMiniRecorder(mr) {}
-SkRecorder::SkRecorder(SkRecord* record, const SkRect& bounds)
+SkRecorder::SkRecorder(SkRecord* record, const SkRect& bounds, SkMiniRecorder* mr)
: SkCanvas(bounds.roundOut(), SkCanvas::kConservativeRasterClip_InitFlag)
, fApproxBytesUsedBySubPictures(0)
- , fRecord(record) {}
+ , fRecord(record)
+ , fMiniRecorder(mr) {}
-void SkRecorder::reset(SkRecord* record, const SkRect& bounds) {
+void SkRecorder::reset(SkRecord* record, const SkRect& bounds, SkMiniRecorder* mr) {
this->forgetRecord();
fRecord = record;
this->resetForNextPicture(bounds.roundOut());
+ fMiniRecorder = mr;
}
void SkRecorder::forgetRecord() {
@@ -55,9 +59,13 @@ void SkRecorder::forgetRecord() {
}
// To make appending to fRecord a little less verbose.
-#define APPEND(T, ...) \
+#define APPEND(T, ...) \
+ if (fMiniRecorder) { this->flushMiniRecorder(); } \
SkNEW_PLACEMENT_ARGS(fRecord->append<SkRecords::T>(), SkRecords::T, (__VA_ARGS__))
+#define TRY_MINIRECORDER(method, ...) \
+ if (fMiniRecorder && fMiniRecorder->method(__VA_ARGS__)) { return; }
+
// For methods which must call back into SkCanvas.
#define INHERITED(method, ...) this->SkCanvas::method(__VA_ARGS__)
@@ -125,6 +133,15 @@ char* SkRecorder::copy(const char* src) {
return this->copy(src, strlen(src)+1);
}
+void SkRecorder::flushMiniRecorder() {
+ if (fMiniRecorder) {
+ SkMiniRecorder* mr = fMiniRecorder;
+ fMiniRecorder = nullptr; // Needs to happen before p->playback(this) or we loop forever.
+ // TODO: this can probably be done more efficiently by SkMiniRecorder if it matters.
+ SkAutoTUnref<SkPicture> p(mr->detachAsPicture(SkRect::MakeEmpty()));
+ p->playback(this);
+ }
+}
void SkRecorder::onDrawPaint(const SkPaint& paint) {
APPEND(DrawPaint, delay_copy(paint));
@@ -138,6 +155,7 @@ void SkRecorder::onDrawPoints(PointMode mode,
}
void SkRecorder::onDrawRect(const SkRect& rect, const SkPaint& paint) {
+ TRY_MINIRECORDER(drawRect, rect, paint);
APPEND(DrawRect, delay_copy(paint), rect);
}
@@ -162,6 +180,7 @@ void SkRecorder::onDrawDrawable(SkDrawable* drawable) {
}
void SkRecorder::onDrawPath(const SkPath& path, const SkPaint& paint) {
+ TRY_MINIRECORDER(drawPath, path, paint);
APPEND(DrawPath, delay_copy(paint), delay_copy(path));
}
@@ -248,6 +267,7 @@ void SkRecorder::onDrawTextOnPath(const void* text, size_t byteLength, const SkP
void SkRecorder::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
const SkPaint& paint) {
+ TRY_MINIRECORDER(drawTextBlob, blob, x, y, paint);
APPEND(DrawTextBlob, delay_copy(paint), blob, x, y);
}