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

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

Issue 232913003: Make sure SkDrawLooper objects can only be allocated on the heap. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 6 years, 8 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 | « src/effects/SkBlurDrawLooper.cpp ('k') | tests/PaintTest.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 18 matching lines...) Expand all
29 29
30 SkLayerDrawLooper::~SkLayerDrawLooper() { 30 SkLayerDrawLooper::~SkLayerDrawLooper() {
31 Rec* rec = fRecs; 31 Rec* rec = fRecs;
32 while (rec) { 32 while (rec) {
33 Rec* next = rec->fNext; 33 Rec* next = rec->fNext;
34 SkDELETE(rec); 34 SkDELETE(rec);
35 rec = next; 35 rec = next;
36 } 36 }
37 } 37 }
38 38
39 SkPaint* SkLayerDrawLooper::addLayer(const LayerInfo& info) {
40 fCount += 1;
41
42 Rec* rec = SkNEW(Rec);
43 rec->fNext = fRecs;
44 rec->fInfo = info;
45 fRecs = rec;
46 if (NULL == fTopRec) {
47 fTopRec = rec;
48 }
49
50 return &rec->fPaint;
51 }
52
53 void SkLayerDrawLooper::addLayer(SkScalar dx, SkScalar dy) {
54 LayerInfo info;
55
56 info.fOffset.set(dx, dy);
57 (void)this->addLayer(info);
58 }
59
60 SkPaint* SkLayerDrawLooper::addLayerOnTop(const LayerInfo& info) {
61 fCount += 1;
62
63 Rec* rec = SkNEW(Rec);
64 rec->fNext = NULL;
65 rec->fInfo = info;
66 if (NULL == fRecs) {
67 fRecs = rec;
68 } else {
69 SkASSERT(NULL != fTopRec);
70 fTopRec->fNext = rec;
71 }
72 fTopRec = rec;
73
74 return &rec->fPaint;
75 }
76
77 SkLayerDrawLooper::Context* SkLayerDrawLooper::createContext(SkCanvas* canvas, v oid* storage) const { 39 SkLayerDrawLooper::Context* SkLayerDrawLooper::createContext(SkCanvas* canvas, v oid* storage) const {
78 canvas->save(SkCanvas::kMatrix_SaveFlag); 40 canvas->save(SkCanvas::kMatrix_SaveFlag);
79 return SkNEW_PLACEMENT_ARGS(storage, LayerDrawLooperContext, (this)); 41 return SkNEW_PLACEMENT_ARGS(storage, LayerDrawLooperContext, (this));
80 } 42 }
81 43
82 static SkColor xferColor(SkColor src, SkColor dst, SkXfermode::Mode mode) { 44 static SkColor xferColor(SkColor src, SkColor dst, SkXfermode::Mode mode) {
83 switch (mode) { 45 switch (mode) {
84 case SkXfermode::kSrc_Mode: 46 case SkXfermode::kSrc_Mode:
85 return src; 47 return src;
86 case SkXfermode::kDst_Mode: 48 case SkXfermode::kDst_Mode:
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 SkLayerDrawLooper* looper = SkNEW(SkLayerDrawLooper); 334 SkLayerDrawLooper* looper = SkNEW(SkLayerDrawLooper);
373 looper->fCount = fCount; 335 looper->fCount = fCount;
374 looper->fRecs = fRecs; 336 looper->fRecs = fRecs;
375 337
376 fCount = 0; 338 fCount = 0;
377 fRecs = NULL; 339 fRecs = NULL;
378 fTopRec = NULL; 340 fTopRec = NULL;
379 341
380 return looper; 342 return looper;
381 } 343 }
OLDNEW
« no previous file with comments | « src/effects/SkBlurDrawLooper.cpp ('k') | tests/PaintTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698