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

Side by Side Diff: src/utils/SkPaintFilterCanvas.cpp

Issue 1577933002: SkPaintFilterCanvas skip-draw support (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: lazy paint copy + missing onDrawImageNine override Created 4 years, 11 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 | « samplecode/SampleApp.cpp ('k') | src/utils/debugger/SkDebugCanvas.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 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkPaintFilterCanvas.h" 8 #include "SkPaintFilterCanvas.h"
9 9
10 #include "SkPaint.h" 10 #include "SkPaint.h"
11 #include "SkTLazy.h" 11 #include "SkTLazy.h"
12 12
13 class SkPaintFilterCanvas::AutoPaintFilter { 13 class SkPaintFilterCanvas::AutoPaintFilter {
14 public: 14 public:
15 AutoPaintFilter(const SkPaintFilterCanvas* canvas, Type type, const SkPaint* paint) { 15 AutoPaintFilter(const SkPaintFilterCanvas* canvas, Type type, const SkPaint* paint)
16 if (paint) { 16 : fOrigPaint(paint) {
17 canvas->onFilterPaint(fLazyPaint.set(*paint), type); 17 fShouldDraw = canvas->onFilter(fOrigPaint, type, &fFilteredPaint);
18 }
19 } 18 }
20 19
21 AutoPaintFilter(const SkPaintFilterCanvas* canvas, Type type, const SkPaint& paint) { 20 AutoPaintFilter(const SkPaintFilterCanvas* canvas, Type type, const SkPaint& paint)
22 canvas->onFilterPaint(fLazyPaint.set(paint), type); 21 : AutoPaintFilter(canvas, type, &paint) { }
22
23 const SkPaint* paint() const {
24 return fFilteredPaint.isValid() ? fFilteredPaint.get() : fOrigPaint;
23 } 25 }
24 26
25 const SkPaint* paint() const { return fLazyPaint.getMaybeNull(); } 27 bool shouldDraw() const { return fShouldDraw; }
26 28
27 private: 29 private:
28 SkTLazy<SkPaint> fLazyPaint; 30 const SkPaint* fOrigPaint;
31 SkTLazy<SkPaint> fFilteredPaint;
32 bool fShouldDraw;
29 }; 33 };
30 34
31 SkPaintFilterCanvas::SkPaintFilterCanvas(int width, int height) : INHERITED(widt h, height) { } 35 SkPaintFilterCanvas::SkPaintFilterCanvas(int width, int height) : INHERITED(widt h, height) { }
32 36
33 SkPaintFilterCanvas::SkPaintFilterCanvas(SkCanvas *canvas) 37 SkPaintFilterCanvas::SkPaintFilterCanvas(SkCanvas *canvas)
34 : INHERITED(canvas->imageInfo().width(), canvas->imageInfo().height()) { 38 : INHERITED(canvas->imageInfo().width(), canvas->imageInfo().height()) {
35 39
36 // Transfer matrix & clip state before adding the target canvas. 40 // Transfer matrix & clip state before adding the target canvas.
37 SkIRect devClip; 41 SkIRect devClip;
38 canvas->getClipDeviceBounds(&devClip); 42 canvas->getClipDeviceBounds(&devClip);
39 this->clipRect(SkRect::Make(devClip)); 43 this->clipRect(SkRect::Make(devClip));
40 this->setMatrix(canvas->getTotalMatrix()); 44 this->setMatrix(canvas->getTotalMatrix());
41 45
42 this->addCanvas(canvas); 46 this->addCanvas(canvas);
43 } 47 }
44 48
45 void SkPaintFilterCanvas::onDrawPaint(const SkPaint& paint) { 49 void SkPaintFilterCanvas::onDrawPaint(const SkPaint& paint) {
46 AutoPaintFilter apf(this, kPaint_Type, paint); 50 AutoPaintFilter apf(this, kPaint_Type, paint);
47 this->INHERITED::onDrawPaint(*apf.paint()); 51 if (apf.shouldDraw()) {
52 this->INHERITED::onDrawPaint(*apf.paint());
53 }
48 } 54 }
49 55
50 void SkPaintFilterCanvas::onDrawPoints(PointMode mode, size_t count, const SkPoi nt pts[], 56 void SkPaintFilterCanvas::onDrawPoints(PointMode mode, size_t count, const SkPoi nt pts[],
51 const SkPaint& paint) { 57 const SkPaint& paint) {
52 AutoPaintFilter apf(this, kPoint_Type, paint); 58 AutoPaintFilter apf(this, kPoint_Type, paint);
53 this->INHERITED::onDrawPoints(mode, count, pts, *apf.paint()); 59 if (apf.shouldDraw()) {
60 this->INHERITED::onDrawPoints(mode, count, pts, *apf.paint());
61 }
54 } 62 }
55 63
56 void SkPaintFilterCanvas::onDrawRect(const SkRect& rect, const SkPaint& paint) { 64 void SkPaintFilterCanvas::onDrawRect(const SkRect& rect, const SkPaint& paint) {
57 AutoPaintFilter apf(this, kRect_Type, paint); 65 AutoPaintFilter apf(this, kRect_Type, paint);
58 this->INHERITED::onDrawRect(rect, *apf.paint()); 66 if (apf.shouldDraw()) {
67 this->INHERITED::onDrawRect(rect, *apf.paint());
68 }
59 } 69 }
60 70
61 void SkPaintFilterCanvas::onDrawRRect(const SkRRect& rrect, const SkPaint& paint ) { 71 void SkPaintFilterCanvas::onDrawRRect(const SkRRect& rrect, const SkPaint& paint ) {
62 AutoPaintFilter apf(this, kRRect_Type, paint); 72 AutoPaintFilter apf(this, kRRect_Type, paint);
63 this->INHERITED::onDrawRRect(rrect, *apf.paint()); 73 if (apf.shouldDraw()) {
74 this->INHERITED::onDrawRRect(rrect, *apf.paint());
75 }
64 } 76 }
65 77
66 void SkPaintFilterCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inne r, 78 void SkPaintFilterCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inne r,
67 const SkPaint& paint) { 79 const SkPaint& paint) {
68 AutoPaintFilter apf(this, kDRRect_Type, paint); 80 AutoPaintFilter apf(this, kDRRect_Type, paint);
69 this->INHERITED::onDrawDRRect(outer, inner, *apf.paint()); 81 if (apf.shouldDraw()) {
82 this->INHERITED::onDrawDRRect(outer, inner, *apf.paint());
83 }
70 } 84 }
71 85
72 void SkPaintFilterCanvas::onDrawOval(const SkRect& rect, const SkPaint& paint) { 86 void SkPaintFilterCanvas::onDrawOval(const SkRect& rect, const SkPaint& paint) {
73 AutoPaintFilter apf(this, kOval_Type, paint); 87 AutoPaintFilter apf(this, kOval_Type, paint);
74 this->INHERITED::onDrawOval(rect, *apf.paint()); 88 if (apf.shouldDraw()) {
89 this->INHERITED::onDrawOval(rect, *apf.paint());
90 }
75 } 91 }
76 92
77 void SkPaintFilterCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) { 93 void SkPaintFilterCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) {
78 AutoPaintFilter apf(this, kPath_Type, paint); 94 AutoPaintFilter apf(this, kPath_Type, paint);
79 this->INHERITED::onDrawPath(path, *apf.paint()); 95 if (apf.shouldDraw()) {
96 this->INHERITED::onDrawPath(path, *apf.paint());
97 }
80 } 98 }
81 99
82 void SkPaintFilterCanvas::onDrawBitmap(const SkBitmap& bm, SkScalar left, SkScal ar top, 100 void SkPaintFilterCanvas::onDrawBitmap(const SkBitmap& bm, SkScalar left, SkScal ar top,
83 const SkPaint* paint) { 101 const SkPaint* paint) {
84 AutoPaintFilter apf(this, kBitmap_Type, paint); 102 AutoPaintFilter apf(this, kBitmap_Type, paint);
85 this->INHERITED::onDrawBitmap(bm, left, top, apf.paint()); 103 if (apf.shouldDraw()) {
104 this->INHERITED::onDrawBitmap(bm, left, top, apf.paint());
105 }
86 } 106 }
87 107
88 void SkPaintFilterCanvas::onDrawBitmapRect(const SkBitmap& bm, const SkRect* src , const SkRect& dst, 108 void SkPaintFilterCanvas::onDrawBitmapRect(const SkBitmap& bm, const SkRect* src , const SkRect& dst,
89 const SkPaint* paint, SrcRectConstrai nt constraint) { 109 const SkPaint* paint, SrcRectConstrai nt constraint) {
90 AutoPaintFilter apf(this, kBitmap_Type, paint); 110 AutoPaintFilter apf(this, kBitmap_Type, paint);
91 this->INHERITED::onDrawBitmapRect(bm, src, dst, apf.paint(), constraint); 111 if (apf.shouldDraw()) {
112 this->INHERITED::onDrawBitmapRect(bm, src, dst, apf.paint(), constraint) ;
113 }
114 }
115
116 void SkPaintFilterCanvas::onDrawBitmapNine(const SkBitmap& bm, const SkIRect& ce nter,
117 const SkRect& dst, const SkPaint* pai nt) {
118 AutoPaintFilter apf(this, kBitmap_Type, paint);
119 if (apf.shouldDraw()) {
120 this->INHERITED::onDrawBitmapNine(bm, center, dst, apf.paint());
121 }
92 } 122 }
93 123
94 void SkPaintFilterCanvas::onDrawImage(const SkImage* image, SkScalar left, SkSca lar top, 124 void SkPaintFilterCanvas::onDrawImage(const SkImage* image, SkScalar left, SkSca lar top,
95 const SkPaint* paint) { 125 const SkPaint* paint) {
96 AutoPaintFilter apf(this, kBitmap_Type, paint); 126 AutoPaintFilter apf(this, kBitmap_Type, paint);
97 this->INHERITED::onDrawImage(image, left, top, apf.paint()); 127 if (apf.shouldDraw()) {
128 this->INHERITED::onDrawImage(image, left, top, apf.paint());
129 }
98 } 130 }
99 131
100 void SkPaintFilterCanvas::onDrawImageRect(const SkImage* image, const SkRect* sr c, 132 void SkPaintFilterCanvas::onDrawImageRect(const SkImage* image, const SkRect* sr c,
101 const SkRect& dst, const SkPaint* pain t, 133 const SkRect& dst, const SkPaint* pain t,
102 SrcRectConstraint constraint) { 134 SrcRectConstraint constraint) {
103 AutoPaintFilter apf(this, kBitmap_Type, paint); 135 AutoPaintFilter apf(this, kBitmap_Type, paint);
104 this->INHERITED::onDrawImageRect(image, src, dst, apf.paint(), constraint); 136 if (apf.shouldDraw()) {
137 this->INHERITED::onDrawImageRect(image, src, dst, apf.paint(), constrain t);
138 }
105 } 139 }
106 140
107 void SkPaintFilterCanvas::onDrawBitmapNine(const SkBitmap& bm, const SkIRect& ce nter, 141 void SkPaintFilterCanvas::onDrawImageNine(const SkImage* image, const SkIRect& c enter,
108 const SkRect& dst, const SkPaint* pai nt) { 142 const SkRect& dst, const SkPaint* paint) {
109 AutoPaintFilter apf(this, kBitmap_Type, paint); 143 AutoPaintFilter apf(this, kBitmap_Type, paint);
110 this->INHERITED::onDrawBitmapNine(bm, center, dst, apf.paint()); 144 if (apf.shouldDraw()) {
145 this->INHERITED::onDrawImageNine(image, center, dst, apf.paint());
146 }
111 } 147 }
112 148
113 void SkPaintFilterCanvas::onDrawVertices(VertexMode vmode, int vertexCount, 149 void SkPaintFilterCanvas::onDrawVertices(VertexMode vmode, int vertexCount,
114 const SkPoint vertices[], const SkPoint texs[], 150 const SkPoint vertices[], const SkPoint texs[],
115 const SkColor colors[], SkXfermode* xmo de, 151 const SkColor colors[], SkXfermode* xmo de,
116 const uint16_t indices[], int indexCoun t, 152 const uint16_t indices[], int indexCoun t,
117 const SkPaint& paint) { 153 const SkPaint& paint) {
118 AutoPaintFilter apf(this, kVertices_Type, paint); 154 AutoPaintFilter apf(this, kVertices_Type, paint);
119 this->INHERITED::onDrawVertices(vmode, vertexCount, vertices, texs, colors, xmode, indices, 155 if (apf.shouldDraw()) {
120 indexCount, *apf.paint()); 156 this->INHERITED::onDrawVertices(vmode, vertexCount, vertices, texs, colo rs, xmode, indices,
157 indexCount, *apf.paint());
158 }
121 } 159 }
122 160
123 void SkPaintFilterCanvas::onDrawPatch(const SkPoint cubics[], const SkColor colo rs[], 161 void SkPaintFilterCanvas::onDrawPatch(const SkPoint cubics[], const SkColor colo rs[],
124 const SkPoint texCoords[], SkXfermode* xmo de, 162 const SkPoint texCoords[], SkXfermode* xmo de,
125 const SkPaint& paint) { 163 const SkPaint& paint) {
126 AutoPaintFilter apf(this, kPatch_Type, paint); 164 AutoPaintFilter apf(this, kPatch_Type, paint);
127 this->INHERITED::onDrawPatch(cubics, colors, texCoords, xmode, *apf.paint()) ; 165 if (apf.shouldDraw()) {
166 this->INHERITED::onDrawPatch(cubics, colors, texCoords, xmode, *apf.pain t());
167 }
128 } 168 }
129 169
130 void SkPaintFilterCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix * m, 170 void SkPaintFilterCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix * m,
131 const SkPaint* paint) { 171 const SkPaint* paint) {
132 AutoPaintFilter apf(this, kPicture_Type, paint); 172 AutoPaintFilter apf(this, kPicture_Type, paint);
133 this->INHERITED::onDrawPicture(picture, m, apf.paint()); 173 if (apf.shouldDraw()) {
174 this->INHERITED::onDrawPicture(picture, m, apf.paint());
175 }
134 } 176 }
135 177
136 void SkPaintFilterCanvas::onDrawText(const void* text, size_t byteLength, SkScal ar x, SkScalar y, 178 void SkPaintFilterCanvas::onDrawText(const void* text, size_t byteLength, SkScal ar x, SkScalar y,
137 const SkPaint& paint) { 179 const SkPaint& paint) {
138 AutoPaintFilter apf(this, kText_Type, paint); 180 AutoPaintFilter apf(this, kText_Type, paint);
139 this->INHERITED::onDrawText(text, byteLength, x, y, *apf.paint()); 181 if (apf.shouldDraw()) {
182 this->INHERITED::onDrawText(text, byteLength, x, y, *apf.paint());
183 }
140 } 184 }
141 185
142 void SkPaintFilterCanvas::onDrawPosText(const void* text, size_t byteLength, con st SkPoint pos[], 186 void SkPaintFilterCanvas::onDrawPosText(const void* text, size_t byteLength, con st SkPoint pos[],
143 const SkPaint& paint) { 187 const SkPaint& paint) {
144 AutoPaintFilter apf(this, kText_Type, paint); 188 AutoPaintFilter apf(this, kText_Type, paint);
145 this->INHERITED::onDrawPosText(text, byteLength, pos, *apf.paint()); 189 if (apf.shouldDraw()) {
190 this->INHERITED::onDrawPosText(text, byteLength, pos, *apf.paint());
191 }
146 } 192 }
147 193
148 void SkPaintFilterCanvas::onDrawPosTextH(const void* text, size_t byteLength, co nst SkScalar xpos[], 194 void SkPaintFilterCanvas::onDrawPosTextH(const void* text, size_t byteLength, co nst SkScalar xpos[],
149 SkScalar constY, const SkPaint& paint) { 195 SkScalar constY, const SkPaint& paint) {
150 AutoPaintFilter apf(this, kText_Type, paint); 196 AutoPaintFilter apf(this, kText_Type, paint);
151 this->INHERITED::onDrawPosTextH(text, byteLength, xpos, constY, *apf.paint() ); 197 if (apf.shouldDraw()) {
198 this->INHERITED::onDrawPosTextH(text, byteLength, xpos, constY, *apf.pai nt());
199 }
152 } 200 }
153 201
154 void SkPaintFilterCanvas::onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path, 202 void SkPaintFilterCanvas::onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
155 const SkMatrix* matrix, const SkPaint & paint) { 203 const SkMatrix* matrix, const SkPaint & paint) {
156 AutoPaintFilter apf(this, kText_Type, paint); 204 AutoPaintFilter apf(this, kText_Type, paint);
157 this->INHERITED::onDrawTextOnPath(text, byteLength, path, matrix, *apf.paint ()); 205 if (apf.shouldDraw()) {
206 this->INHERITED::onDrawTextOnPath(text, byteLength, path, matrix, *apf.p aint());
207 }
158 } 208 }
159 209
160 void SkPaintFilterCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkS calar y, 210 void SkPaintFilterCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkS calar y,
161 const SkPaint& paint) { 211 const SkPaint& paint) {
162 AutoPaintFilter apf(this, kTextBlob_Type, paint); 212 AutoPaintFilter apf(this, kTextBlob_Type, paint);
163 this->INHERITED::onDrawTextBlob(blob, x, y, *apf.paint()); 213 if (apf.shouldDraw()) {
214 this->INHERITED::onDrawTextBlob(blob, x, y, *apf.paint());
215 }
164 } 216 }
OLDNEW
« no previous file with comments | « samplecode/SampleApp.cpp ('k') | src/utils/debugger/SkDebugCanvas.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698