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

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: 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 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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 } 222 }
223 223
224 SkLayerDrawLooper::SkLayerDrawLooper(SkReadBuffer& buffer) 224 SkLayerDrawLooper::SkLayerDrawLooper(SkReadBuffer& buffer)
225 : INHERITED(buffer), 225 : INHERITED(buffer),
226 fRecs(NULL), 226 fRecs(NULL),
227 fTopRec(NULL), 227 fTopRec(NULL),
228 fCount(0), 228 fCount(0),
229 fCurrRec(NULL) { 229 fCurrRec(NULL) {
230 int count = buffer.readInt(); 230 int count = buffer.readInt();
231 231
232 Builder builder;
232 for (int i = 0; i < count; i++) { 233 for (int i = 0; i < count; i++) {
233 LayerInfo info; 234 LayerInfo info;
234 info.fFlagsMask = buffer.readInt(); 235 info.fFlagsMask = buffer.readInt();
235 info.fPaintBits = buffer.readInt(); 236 info.fPaintBits = buffer.readInt();
236 info.fColorMode = (SkXfermode::Mode)buffer.readInt(); 237 info.fColorMode = (SkXfermode::Mode)buffer.readInt();
237 buffer.readPoint(&info.fOffset); 238 buffer.readPoint(&info.fOffset);
238 info.fPostTranslate = buffer.readBool(); 239 info.fPostTranslate = buffer.readBool();
239 buffer.readPaint(this->addLayerOnTop(info)); 240 buffer.readPaint(builder.addLayerOnTop(info));
240 } 241 }
242 builder.initLooperAndReset(this);
scroggo 2014/02/11 14:48:37 I think the main place this will be called is read
241 SkASSERT(count == fCount); 243 SkASSERT(count == fCount);
242 244
243 #ifdef SK_DEBUG 245 #ifdef SK_DEBUG
244 { 246 {
245 Rec* rec = fRecs; 247 Rec* rec = fRecs;
246 int n = 0; 248 int n = 0;
247 while (rec) { 249 while (rec) {
248 rec = rec->fNext; 250 rec = rec->fNext;
249 n += 1; 251 n += 1;
250 } 252 }
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 str->append("true "); 342 str->append("true ");
341 } else { 343 } else {
342 str->append("false "); 344 str->append("false ");
343 } 345 }
344 346
345 rec->fPaint.toString(str); 347 rec->fPaint.toString(str);
346 rec = rec->fNext; 348 rec = rec->fNext;
347 } 349 }
348 } 350 }
349 #endif 351 #endif
352
353 SkLayerDrawLooper::Builder::Builder()
354 : fRecs(NULL),
355 fTopRec(NULL),
356 fCount(0) {
357 }
358
359 SkLayerDrawLooper::Builder::~Builder() {
360 Rec* rec = fRecs;
361 while (rec) {
362 Rec* next = rec->fNext;
363 SkDELETE(rec);
364 rec = next;
365 }
366 }
367
368 SkPaint* SkLayerDrawLooper::Builder::addLayer(const LayerInfo& info) {
369 fCount += 1;
370
371 Rec* rec = SkNEW(Rec);
372 rec->fNext = fRecs;
373 rec->fInfo = info;
374 fRecs = rec;
375 if (NULL == fTopRec) {
376 fTopRec = rec;
377 }
378
379 return &rec->fPaint;
380 }
381
382 void SkLayerDrawLooper::Builder::addLayer(SkScalar dx, SkScalar dy) {
383 LayerInfo info;
384
385 info.fOffset.set(dx, dy);
386 (void)this->addLayer(info);
387 }
388
389 SkPaint* SkLayerDrawLooper::Builder::addLayerOnTop(const LayerInfo& info) {
390 fCount += 1;
391
392 Rec* rec = SkNEW(Rec);
393 rec->fNext = NULL;
394 rec->fInfo = info;
395 if (NULL == fRecs) {
396 fRecs = rec;
397 } else {
398 SkASSERT(NULL != fTopRec);
399 fTopRec->fNext = rec;
400 }
401 fTopRec = rec;
402
403 return &rec->fPaint;
404 }
405
406 SkLayerDrawLooper* SkLayerDrawLooper::Builder::detachLooper() {
407 SkLayerDrawLooper* looper = SkNEW(SkLayerDrawLooper);
408 initLooperAndReset(looper);
409 return looper;
410 }
411
412 void SkLayerDrawLooper::Builder::initLooperAndReset(SkLayerDrawLooper* looper) {
413 looper->fCount = fCount;
414 looper->fRecs = fRecs;
415
416 fCount = 0;
417 fRecs = NULL;
418 fTopRec = NULL;
419 }
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