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

Side by Side 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: Implement own CreateProc & remove SkLayerDrawLooper(SkReadBuffer&). 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
« no previous file with comments | « include/effects/SkLayerDrawLooper.h ('k') | tests/LayerDrawLooperTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 buffer.writeInt(rec->fInfo.fFlagsMask); 214 buffer.writeInt(rec->fInfo.fFlagsMask);
215 buffer.writeInt(rec->fInfo.fPaintBits); 215 buffer.writeInt(rec->fInfo.fPaintBits);
216 buffer.writeInt(rec->fInfo.fColorMode); 216 buffer.writeInt(rec->fInfo.fColorMode);
217 buffer.writePoint(rec->fInfo.fOffset); 217 buffer.writePoint(rec->fInfo.fOffset);
218 buffer.writeBool(rec->fInfo.fPostTranslate); 218 buffer.writeBool(rec->fInfo.fPostTranslate);
219 buffer.writePaint(rec->fPaint); 219 buffer.writePaint(rec->fPaint);
220 rec = rec->fNext; 220 rec = rec->fNext;
221 } 221 }
222 } 222 }
223 223
224 SkLayerDrawLooper::SkLayerDrawLooper(SkReadBuffer& buffer) 224 SkFlattenable* SkLayerDrawLooper::CreateProc(SkReadBuffer& buffer) {
225 : INHERITED(buffer),
226 fRecs(NULL),
227 fTopRec(NULL),
228 fCount(0),
229 fCurrRec(NULL) {
230 int count = buffer.readInt(); 225 int count = buffer.readInt();
231 226
227 Builder builder;
232 for (int i = 0; i < count; i++) { 228 for (int i = 0; i < count; i++) {
233 LayerInfo info; 229 LayerInfo info;
234 info.fFlagsMask = buffer.readInt(); 230 info.fFlagsMask = buffer.readInt();
235 info.fPaintBits = buffer.readInt(); 231 info.fPaintBits = buffer.readInt();
236 info.fColorMode = (SkXfermode::Mode)buffer.readInt(); 232 info.fColorMode = (SkXfermode::Mode)buffer.readInt();
237 buffer.readPoint(&info.fOffset); 233 buffer.readPoint(&info.fOffset);
238 info.fPostTranslate = buffer.readBool(); 234 info.fPostTranslate = buffer.readBool();
239 buffer.readPaint(this->addLayerOnTop(info)); 235 buffer.readPaint(builder.addLayerOnTop(info));
240 } 236 }
241 SkASSERT(count == fCount); 237 SkLayerDrawLooper* looper = builder.detachLooper();
238 SkASSERT(count == looper->fCount);
242 239
243 #ifdef SK_DEBUG 240 #ifdef SK_DEBUG
244 { 241 {
245 Rec* rec = fRecs; 242 Rec* rec = looper->fRecs;
246 int n = 0; 243 int n = 0;
247 while (rec) { 244 while (rec) {
248 rec = rec->fNext; 245 rec = rec->fNext;
249 n += 1; 246 n += 1;
250 } 247 }
251 SkASSERT(count == n); 248 SkASSERT(count == n);
252 } 249 }
253 #endif 250 #endif
251
252 return looper;
254 } 253 }
255 254
256 #ifdef SK_DEVELOPER 255 #ifdef SK_DEVELOPER
257 void SkLayerDrawLooper::toString(SkString* str) const { 256 void SkLayerDrawLooper::toString(SkString* str) const {
258 str->appendf("SkLayerDrawLooper (%d): ", fCount); 257 str->appendf("SkLayerDrawLooper (%d): ", fCount);
259 258
260 Rec* rec = fRecs; 259 Rec* rec = fRecs;
261 for (int i = 0; i < fCount; i++) { 260 for (int i = 0; i < fCount; i++) {
262 str->appendf("%d: ", i); 261 str->appendf("%d: ", i);
263 262
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 str->append("true "); 339 str->append("true ");
341 } else { 340 } else {
342 str->append("false "); 341 str->append("false ");
343 } 342 }
344 343
345 rec->fPaint.toString(str); 344 rec->fPaint.toString(str);
346 rec = rec->fNext; 345 rec = rec->fNext;
347 } 346 }
348 } 347 }
349 #endif 348 #endif
349
350 SkLayerDrawLooper::Builder::Builder()
351 : fRecs(NULL),
352 fTopRec(NULL),
353 fCount(0) {
354 }
355
356 SkLayerDrawLooper::Builder::~Builder() {
357 Rec* rec = fRecs;
358 while (rec) {
359 Rec* next = rec->fNext;
360 SkDELETE(rec);
361 rec = next;
362 }
363 }
364
365 SkPaint* SkLayerDrawLooper::Builder::addLayer(const LayerInfo& info) {
366 fCount += 1;
367
368 Rec* rec = SkNEW(Rec);
369 rec->fNext = fRecs;
370 rec->fInfo = info;
371 fRecs = rec;
372 if (NULL == fTopRec) {
373 fTopRec = rec;
374 }
375
376 return &rec->fPaint;
377 }
378
379 void SkLayerDrawLooper::Builder::addLayer(SkScalar dx, SkScalar dy) {
380 LayerInfo info;
381
382 info.fOffset.set(dx, dy);
383 (void)this->addLayer(info);
384 }
385
386 SkPaint* SkLayerDrawLooper::Builder::addLayerOnTop(const LayerInfo& info) {
387 fCount += 1;
388
389 Rec* rec = SkNEW(Rec);
390 rec->fNext = NULL;
391 rec->fInfo = info;
392 if (NULL == fRecs) {
393 fRecs = rec;
394 } else {
395 SkASSERT(NULL != fTopRec);
396 fTopRec->fNext = rec;
397 }
398 fTopRec = rec;
399
400 return &rec->fPaint;
401 }
402
403 SkLayerDrawLooper* SkLayerDrawLooper::Builder::detachLooper() {
404 SkLayerDrawLooper* looper = SkNEW(SkLayerDrawLooper);
405 looper->fCount = fCount;
406 looper->fRecs = fRecs;
407
408 fCount = 0;
409 fRecs = NULL;
410 fTopRec = NULL;
411
412 return looper;
413 }
OLDNEW
« 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