Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(171)

Unified Diff: src/effects/SkLayerDrawLooper.cpp

Issue 133813005: Builder class for SkLayerDrawLooper. (Closed) Base URL: https://skia.googlesource.com/skia.git@draw_looper_context
Patch Set: Make builder inner class; update tests. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/effects/SkLayerDrawLooper.h ('k') | tests/LayerDrawLooperTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/effects/SkLayerDrawLooper.cpp
diff --git a/src/effects/SkLayerDrawLooper.cpp b/src/effects/SkLayerDrawLooper.cpp
index 6c7c3cef0cb04f2529fc3e21fd5688d3a7b19fed..6705060bf7919518925aac83c993cc1965a53bac 100644
--- a/src/effects/SkLayerDrawLooper.cpp
+++ b/src/effects/SkLayerDrawLooper.cpp
@@ -229,6 +229,7 @@ SkLayerDrawLooper::SkLayerDrawLooper(SkReadBuffer& buffer)
fCurrRec(NULL) {
int count = buffer.readInt();
+ Builder builder;
for (int i = 0; i < count; i++) {
LayerInfo info;
info.fFlagsMask = buffer.readInt();
@@ -236,8 +237,9 @@ SkLayerDrawLooper::SkLayerDrawLooper(SkReadBuffer& buffer)
info.fColorMode = (SkXfermode::Mode)buffer.readInt();
buffer.readPoint(&info.fOffset);
info.fPostTranslate = buffer.readBool();
- buffer.readPaint(this->addLayerOnTop(info));
+ buffer.readPaint(builder.addLayerOnTop(info));
}
+ builder.initLooperAndReset(this);
scroggo 2014/02/11 14:48:37 I think the main place this will be called is read
SkASSERT(count == fCount);
#ifdef SK_DEBUG
@@ -347,3 +349,71 @@ void SkLayerDrawLooper::toString(SkString* str) const {
}
}
#endif
+
+SkLayerDrawLooper::Builder::Builder()
+ : fRecs(NULL),
+ fTopRec(NULL),
+ fCount(0) {
+}
+
+SkLayerDrawLooper::Builder::~Builder() {
+ Rec* rec = fRecs;
+ while (rec) {
+ Rec* next = rec->fNext;
+ SkDELETE(rec);
+ rec = next;
+ }
+}
+
+SkPaint* SkLayerDrawLooper::Builder::addLayer(const LayerInfo& info) {
+ fCount += 1;
+
+ Rec* rec = SkNEW(Rec);
+ rec->fNext = fRecs;
+ rec->fInfo = info;
+ fRecs = rec;
+ if (NULL == fTopRec) {
+ fTopRec = rec;
+ }
+
+ return &rec->fPaint;
+}
+
+void SkLayerDrawLooper::Builder::addLayer(SkScalar dx, SkScalar dy) {
+ LayerInfo info;
+
+ info.fOffset.set(dx, dy);
+ (void)this->addLayer(info);
+}
+
+SkPaint* SkLayerDrawLooper::Builder::addLayerOnTop(const LayerInfo& info) {
+ fCount += 1;
+
+ Rec* rec = SkNEW(Rec);
+ rec->fNext = NULL;
+ rec->fInfo = info;
+ if (NULL == fRecs) {
+ fRecs = rec;
+ } else {
+ SkASSERT(NULL != fTopRec);
+ fTopRec->fNext = rec;
+ }
+ fTopRec = rec;
+
+ return &rec->fPaint;
+}
+
+SkLayerDrawLooper* SkLayerDrawLooper::Builder::detachLooper() {
+ SkLayerDrawLooper* looper = SkNEW(SkLayerDrawLooper);
+ initLooperAndReset(looper);
+ return looper;
+}
+
+void SkLayerDrawLooper::Builder::initLooperAndReset(SkLayerDrawLooper* looper) {
+ looper->fCount = fCount;
+ looper->fRecs = fRecs;
+
+ fCount = 0;
+ fRecs = NULL;
+ fTopRec = NULL;
+}
« no previous file with comments | « include/effects/SkLayerDrawLooper.h ('k') | tests/LayerDrawLooperTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698