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

Side by Side Diff: src/effects/SkLayerDrawLooper.cpp

Issue 155513012: [WIP] Add Context to SkDrawLooper. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: static allocation of DrawContext; update rest of code. 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 unified diff | Download patch
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "SkCanvas.h" 8 #include "SkCanvas.h"
9 #include "SkColor.h" 9 #include "SkColor.h"
10 #include "SkReadBuffer.h" 10 #include "SkReadBuffer.h"
11 #include "SkWriteBuffer.h" 11 #include "SkWriteBuffer.h"
12 #include "SkLayerDrawLooper.h" 12 #include "SkLayerDrawLooper.h"
13 #include "SkString.h" 13 #include "SkString.h"
14 #include "SkStringUtils.h" 14 #include "SkStringUtils.h"
15 #include "SkTemplatesPriv.h"
15 #include "SkUnPreMultiply.h" 16 #include "SkUnPreMultiply.h"
16 17
17 SkLayerDrawLooper::LayerInfo::LayerInfo() { 18 SkLayerDrawLooper::LayerInfo::LayerInfo() {
18 fFlagsMask = 0; // ignore our paint flags 19 fFlagsMask = 0; // ignore our paint flags
19 fPaintBits = 0; // ignore our paint fields 20 fPaintBits = 0; // ignore our paint fields
20 fColorMode = SkXfermode::kDst_Mode; // ignore our color 21 fColorMode = SkXfermode::kDst_Mode; // ignore our color
21 fOffset.set(0, 0); 22 fOffset.set(0, 0);
22 fPostTranslate = false; 23 fPostTranslate = false;
23 } 24 }
24 25
25 SkLayerDrawLooper::SkLayerDrawLooper() 26 SkLayerDrawLooper::SkLayerDrawLooper()
26 : fRecs(NULL), 27 : fRecs(NULL),
27 fTopRec(NULL), 28 fTopRec(NULL),
28 fCount(0), 29 fCount(0) {
29 fCurrRec(NULL) {
30 } 30 }
31 31
32 SkLayerDrawLooper::~SkLayerDrawLooper() { 32 SkLayerDrawLooper::~SkLayerDrawLooper() {
33 Rec* rec = fRecs; 33 Rec* rec = fRecs;
34 while (rec) { 34 while (rec) {
35 Rec* next = rec->fNext; 35 Rec* next = rec->fNext;
36 SkDELETE(rec); 36 SkDELETE(rec);
37 rec = next; 37 rec = next;
38 } 38 }
39 } 39 }
(...skipping 29 matching lines...) Expand all
69 fRecs = rec; 69 fRecs = rec;
70 } else { 70 } else {
71 SkASSERT(NULL != fTopRec); 71 SkASSERT(NULL != fTopRec);
72 fTopRec->fNext = rec; 72 fTopRec->fNext = rec;
73 } 73 }
74 fTopRec = rec; 74 fTopRec = rec;
75 75
76 return &rec->fPaint; 76 return &rec->fPaint;
77 } 77 }
78 78
79 void SkLayerDrawLooper::init(SkCanvas* canvas) { 79 SkLayerDrawLooper::DrawContext* SkLayerDrawLooper::init(
80 fCurrRec = fRecs; 80 SkCanvas* canvas, void* storage, size_t storageSize) const {
81 LayerDrawLooperContext* context;
82 SK_PLACEMENT_NEW_ARGS(context, LayerDrawLooperContext, storage,
83 storageSize, (this));
81 canvas->save(SkCanvas::kMatrix_SaveFlag); 84 canvas->save(SkCanvas::kMatrix_SaveFlag);
85 return context;
82 } 86 }
83 87
84 static SkColor xferColor(SkColor src, SkColor dst, SkXfermode::Mode mode) { 88 static SkColor xferColor(SkColor src, SkColor dst, SkXfermode::Mode mode) {
85 switch (mode) { 89 switch (mode) {
86 case SkXfermode::kSrc_Mode: 90 case SkXfermode::kSrc_Mode:
87 return src; 91 return src;
88 case SkXfermode::kDst_Mode: 92 case SkXfermode::kDst_Mode:
89 return dst; 93 return dst;
90 default: { 94 default: {
91 SkPMColor pmS = SkPreMultiplyColor(src); 95 SkPMColor pmS = SkPreMultiplyColor(src);
92 SkPMColor pmD = SkPreMultiplyColor(dst); 96 SkPMColor pmD = SkPreMultiplyColor(dst);
93 SkPMColor result = SkXfermode::GetProc(mode)(pmS, pmD); 97 SkPMColor result = SkXfermode::GetProc(mode)(pmS, pmD);
94 return SkUnPreMultiply::PMColorToColor(result); 98 return SkUnPreMultiply::PMColorToColor(result);
95 } 99 }
96 } 100 }
97 } 101 }
98 102
99 // Even with kEntirePaint_Bits, we always ensure that the master paint's 103 // Even with kEntirePaint_Bits, we always ensure that the master paint's
100 // text-encoding is respected, since that controls how we interpret the 104 // text-encoding is respected, since that controls how we interpret the
101 // text/length parameters of a draw[Pos]Text call. 105 // text/length parameters of a draw[Pos]Text call.
102 void SkLayerDrawLooper::ApplyInfo(SkPaint* dst, const SkPaint& src, 106 void SkLayerDrawLooper::LayerDrawLooperContext::ApplyInfo(
103 const LayerInfo& info) { 107 SkPaint* dst, const SkPaint& src, const LayerInfo& info) {
104 108
105 uint32_t mask = info.fFlagsMask; 109 uint32_t mask = info.fFlagsMask;
106 dst->setFlags((dst->getFlags() & ~mask) | (src.getFlags() & mask)); 110 dst->setFlags((dst->getFlags() & ~mask) | (src.getFlags() & mask));
107 dst->setColor(xferColor(src.getColor(), dst->getColor(), info.fColorMode)); 111 dst->setColor(xferColor(src.getColor(), dst->getColor(), info.fColorMode));
108 112
109 BitFlags bits = info.fPaintBits; 113 BitFlags bits = info.fPaintBits;
110 SkPaint::TextEncoding encoding = dst->getTextEncoding(); 114 SkPaint::TextEncoding encoding = dst->getTextEncoding();
111 115
112 if (0 == bits) { 116 if (0 == bits) {
113 return; 117 return;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 #endif 167 #endif
164 } 168 }
165 169
166 // Should we add this to canvas? 170 // Should we add this to canvas?
167 static void postTranslate(SkCanvas* canvas, SkScalar dx, SkScalar dy) { 171 static void postTranslate(SkCanvas* canvas, SkScalar dx, SkScalar dy) {
168 SkMatrix m = canvas->getTotalMatrix(); 172 SkMatrix m = canvas->getTotalMatrix();
169 m.postTranslate(dx, dy); 173 m.postTranslate(dx, dy);
170 canvas->setMatrix(m); 174 canvas->setMatrix(m);
171 } 175 }
172 176
173 bool SkLayerDrawLooper::next(SkCanvas* canvas, SkPaint* paint) { 177 SkLayerDrawLooper::LayerDrawLooperContext::LayerDrawLooperContext(
178 const SkLayerDrawLooper* looper) : fCurrRec(looper->fRecs) {}
179
180 bool SkLayerDrawLooper::LayerDrawLooperContext::next(SkCanvas* canvas,
181 SkPaint* paint) {
174 canvas->restore(); 182 canvas->restore();
175 if (NULL == fCurrRec) { 183 if (NULL == fCurrRec) {
176 return false; 184 return false;
177 } 185 }
178 186
179 ApplyInfo(paint, fCurrRec->fPaint, fCurrRec->fInfo); 187 ApplyInfo(paint, fCurrRec->fPaint, fCurrRec->fInfo);
180 188
181 canvas->save(SkCanvas::kMatrix_SaveFlag); 189 canvas->save(SkCanvas::kMatrix_SaveFlag);
182 if (fCurrRec->fInfo.fPostTranslate) { 190 if (fCurrRec->fInfo.fPostTranslate) {
183 postTranslate(canvas, fCurrRec->fInfo.fOffset.fX, 191 postTranslate(canvas, fCurrRec->fInfo.fOffset.fX,
184 fCurrRec->fInfo.fOffset.fY); 192 fCurrRec->fInfo.fOffset.fY);
185 } else { 193 } else {
186 canvas->translate(fCurrRec->fInfo.fOffset.fX, fCurrRec->fInfo.fOffset.fY ); 194 canvas->translate(fCurrRec->fInfo.fOffset.fX,
195 fCurrRec->fInfo.fOffset.fY);
187 } 196 }
188 fCurrRec = fCurrRec->fNext; 197 fCurrRec = fCurrRec->fNext;
189 198
190 return true; 199 return true;
191 } 200 }
192 201
193 /////////////////////////////////////////////////////////////////////////////// 202 ///////////////////////////////////////////////////////////////////////////////
194 203
195 void SkLayerDrawLooper::flatten(SkWriteBuffer& buffer) const { 204 void SkLayerDrawLooper::flatten(SkWriteBuffer& buffer) const {
196 this->INHERITED::flatten(buffer); 205 this->INHERITED::flatten(buffer);
(...skipping 21 matching lines...) Expand all
218 buffer.writeBool(rec->fInfo.fPostTranslate); 227 buffer.writeBool(rec->fInfo.fPostTranslate);
219 buffer.writePaint(rec->fPaint); 228 buffer.writePaint(rec->fPaint);
220 rec = rec->fNext; 229 rec = rec->fNext;
221 } 230 }
222 } 231 }
223 232
224 SkLayerDrawLooper::SkLayerDrawLooper(SkReadBuffer& buffer) 233 SkLayerDrawLooper::SkLayerDrawLooper(SkReadBuffer& buffer)
225 : INHERITED(buffer), 234 : INHERITED(buffer),
226 fRecs(NULL), 235 fRecs(NULL),
227 fTopRec(NULL), 236 fTopRec(NULL),
228 fCount(0), 237 fCount(0) {
229 fCurrRec(NULL) {
230 int count = buffer.readInt(); 238 int count = buffer.readInt();
231 239
232 for (int i = 0; i < count; i++) { 240 for (int i = 0; i < count; i++) {
233 LayerInfo info; 241 LayerInfo info;
234 info.fFlagsMask = buffer.readInt(); 242 info.fFlagsMask = buffer.readInt();
235 info.fPaintBits = buffer.readInt(); 243 info.fPaintBits = buffer.readInt();
236 info.fColorMode = (SkXfermode::Mode)buffer.readInt(); 244 info.fColorMode = (SkXfermode::Mode)buffer.readInt();
237 buffer.readPoint(&info.fOffset); 245 buffer.readPoint(&info.fOffset);
238 info.fPostTranslate = buffer.readBool(); 246 info.fPostTranslate = buffer.readBool();
239 buffer.readPaint(this->addLayerOnTop(info)); 247 buffer.readPaint(this->addLayerOnTop(info));
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 str->append("true "); 348 str->append("true ");
341 } else { 349 } else {
342 str->append("false "); 350 str->append("false ");
343 } 351 }
344 352
345 rec->fPaint.toString(str); 353 rec->fPaint.toString(str);
346 rec = rec->fNext; 354 rec = rec->fNext;
347 } 355 }
348 } 356 }
349 #endif 357 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698