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

Unified Diff: src/effects/SkLayerDrawLooper.cpp

Issue 15314003: Add methods to SkLayerDrawLooper to allow adding layers on top (Closed) Base URL: http://skia.googlecode.com/svn/trunk
Patch Set: changes requested by tomhudson Created 7 years, 7 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 34aaad899ab1425a20d862cf84b0ee31cdaf6f71..401bea4e656e97cd4f7728454c5983f44ec2617b 100644
--- a/src/effects/SkLayerDrawLooper.cpp
+++ b/src/effects/SkLayerDrawLooper.cpp
@@ -25,6 +25,7 @@ SkLayerDrawLooper::LayerInfo::LayerInfo() {
SkLayerDrawLooper::SkLayerDrawLooper()
: fRecs(NULL),
+ fTopRec(NULL),
fCount(0),
fCurrRec(NULL) {
}
@@ -45,6 +46,9 @@ SkPaint* SkLayerDrawLooper::addLayer(const LayerInfo& info) {
rec->fNext = fRecs;
rec->fInfo = info;
fRecs = rec;
+ if (NULL == fTopRec) {
+ fTopRec = rec;
+ }
return &rec->fPaint;
}
@@ -56,6 +60,23 @@ void SkLayerDrawLooper::addLayer(SkScalar dx, SkScalar dy) {
(void)this->addLayer(info);
}
+SkPaint* SkLayerDrawLooper::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;
+}
+
void SkLayerDrawLooper::init(SkCanvas* canvas) {
fCurrRec = fRecs;
canvas->save(SkCanvas::kMatrix_SaveFlag);
@@ -170,18 +191,6 @@ bool SkLayerDrawLooper::next(SkCanvas* canvas, SkPaint* paint) {
return true;
}
-SkLayerDrawLooper::Rec* SkLayerDrawLooper::Rec::Reverse(Rec* head) {
- Rec* rec = head;
- Rec* prev = NULL;
- while (rec) {
- Rec* next = rec->fNext;
- rec->fNext = prev;
- prev = rec;
- rec = next;
- }
- return prev;
-}
-
///////////////////////////////////////////////////////////////////////////////
void SkLayerDrawLooper::flatten(SkFlattenableWriteBuffer& buffer) const {
@@ -216,6 +225,7 @@ void SkLayerDrawLooper::flatten(SkFlattenableWriteBuffer& buffer) const {
SkLayerDrawLooper::SkLayerDrawLooper(SkFlattenableReadBuffer& buffer)
: INHERITED(buffer),
fRecs(NULL),
+ fTopRec(NULL),
fCount(0),
fCurrRec(NULL) {
int count = buffer.readInt();
@@ -227,13 +237,10 @@ SkLayerDrawLooper::SkLayerDrawLooper(SkFlattenableReadBuffer& buffer)
info.fColorMode = (SkXfermode::Mode)buffer.readInt();
buffer.readPoint(&info.fOffset);
info.fPostTranslate = buffer.readBool();
- buffer.readPaint(this->addLayer(info));
+ buffer.readPaint(this->addLayerOnTop(info));
}
SkASSERT(count == fCount);
- // we're in reverse order, so fix it now
- fRecs = Rec::Reverse(fRecs);
-
#ifdef SK_DEBUG
{
Rec* rec = fRecs;
« 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