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

Side by Side Diff: src/core/SkRecordOpts.cpp

Issue 2314073002: check for null-layer-paint after prev fix to savelayer ops (Closed)
Patch Set: Created 4 years, 3 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 | « no previous file | no next file » | 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 2014 Google Inc. 2 * Copyright 2014 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 "SkRecordOpts.h" 8 #include "SkRecordOpts.h"
9 9
10 #include "SkRecordPattern.h" 10 #include "SkRecordPattern.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 Is<Restore>> 80 Is<Restore>>
81 Match; 81 Match;
82 82
83 bool onMatch(SkRecord* record, Match*, int begin, int end) { 83 bool onMatch(SkRecord* record, Match*, int begin, int end) {
84 record->replace<NoOp>(begin); // Save 84 record->replace<NoOp>(begin); // Save
85 record->replace<NoOp>(end-1); // Restore 85 record->replace<NoOp>(end-1); // Restore
86 return true; 86 return true;
87 } 87 }
88 }; 88 };
89 89
90 static bool fold_opacity_layer_color_to_paint(const SkPaint& layerPaint, 90 static bool fold_opacity_layer_color_to_paint(const SkPaint* layerPaint,
91 bool isSaveLayer, 91 bool isSaveLayer,
92 SkPaint* paint) { 92 SkPaint* paint) {
93 // We assume layerPaint is always from a saveLayer. If isSaveLayer is 93 // We assume layerPaint is always from a saveLayer. If isSaveLayer is
94 // true, we assume paint is too. 94 // true, we assume paint is too.
95 95
96 // The alpha folding can proceed if the filter layer paint does not have pro perties which cause 96 // The alpha folding can proceed if the filter layer paint does not have pro perties which cause
97 // the resulting filter layer to be "blended" in complex ways to the parent layer. For example, 97 // the resulting filter layer to be "blended" in complex ways to the parent layer. For example,
98 // looper drawing unmodulated filter layer twice and then modulating the res ult produces 98 // looper drawing unmodulated filter layer twice and then modulating the res ult produces
99 // different image to drawing modulated filter layer twice. 99 // different image to drawing modulated filter layer twice.
100 // TODO: most likely the looper and only some xfer modes are the hard constr aints 100 // TODO: most likely the looper and only some xfer modes are the hard constr aints
(...skipping 13 matching lines...) Expand all
114 if (paint->getColorFilter()) { 114 if (paint->getColorFilter()) {
115 // Filter input depends on the paint color. 115 // Filter input depends on the paint color.
116 116
117 // Here we could filter the color if we knew the draw is going to be uni form color. This 117 // Here we could filter the color if we knew the draw is going to be uni form color. This
118 // should be detectable as drawPath/drawRect/.. without a shader being u niform, while 118 // should be detectable as drawPath/drawRect/.. without a shader being u niform, while
119 // drawBitmap/drawSprite or a shader being non-uniform. However, current matchers don't 119 // drawBitmap/drawSprite or a shader being non-uniform. However, current matchers don't
120 // give the type out easily, so just do not optimize that at the moment. 120 // give the type out easily, so just do not optimize that at the moment.
121 return false; 121 return false;
122 } 122 }
123 123
124 const uint32_t layerColor = layerPaint.getColor(); 124 const uint32_t layerColor = layerPaint ? layerPaint->getColor() : SK_ColorBL ACK;
mtklein 2016/09/06 16:00:53 How about if (layerPaint) { SkColor layerColor
reed1 2016/09/06 16:49:44 Done.
125 // The layer paint color must have only alpha component. 125 // The layer paint color must have only alpha component.
126 if (SK_ColorTRANSPARENT != SkColorSetA(layerColor, SK_AlphaTRANSPARENT)) { 126 if (SK_ColorTRANSPARENT != SkColorSetA(layerColor, SK_AlphaTRANSPARENT)) {
127 return false; 127 return false;
128 } 128 }
129 129
130 // The layer paint can not have any effects. 130 if (layerPaint) {
131 if (layerPaint.getPathEffect() || 131 // The layer paint can not have any effects.
132 layerPaint.getShader() || 132 if (layerPaint->getPathEffect() ||
133 layerPaint.getXfermode() || 133 layerPaint->getShader() ||
134 layerPaint.getMaskFilter() || 134 layerPaint->getXfermode() ||
135 layerPaint.getColorFilter() || 135 layerPaint->getMaskFilter() ||
136 layerPaint.getRasterizer() || 136 layerPaint->getColorFilter() ||
137 layerPaint.getLooper() || 137 layerPaint->getRasterizer() ||
138 layerPaint.getImageFilter()) { 138 layerPaint->getLooper() ||
139 return false; 139 layerPaint->getImageFilter()) {
140 return false;
141 }
140 } 142 }
141 143
142 paint->setAlpha(SkMulDiv255Round(paint->getAlpha(), SkColorGetA(layerColor)) ); 144 paint->setAlpha(SkMulDiv255Round(paint->getAlpha(), SkColorGetA(layerColor)) );
143 145
144 return true; 146 return true;
145 } 147 }
146 148
147 // Turns logical no-op Save-[non-drawing command]*-Restore patterns into actual no-ops. 149 // Turns logical no-op Save-[non-drawing command]*-Restore patterns into actual no-ops.
148 struct SaveNoDrawsRestoreNooper { 150 struct SaveNoDrawsRestoreNooper {
149 // Greedy matches greedily, so we also have to exclude Save and Restore. 151 // Greedy matches greedily, so we also have to exclude Save and Restore.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 // There wasn't really any point to this SaveLayer at all. 206 // There wasn't really any point to this SaveLayer at all.
205 return KillSaveLayerAndRestore(record, begin); 207 return KillSaveLayerAndRestore(record, begin);
206 } 208 }
207 209
208 if (drawPaint == nullptr) { 210 if (drawPaint == nullptr) {
209 // We can just give the draw the SaveLayer's paint. 211 // We can just give the draw the SaveLayer's paint.
210 // TODO(mtklein): figure out how to do this clearly 212 // TODO(mtklein): figure out how to do this clearly
211 return false; 213 return false;
212 } 214 }
213 215
214 if (!fold_opacity_layer_color_to_paint(*layerPaint, false /*isSaveLayer* /, drawPaint)) { 216 if (!fold_opacity_layer_color_to_paint(layerPaint, false /*isSaveLayer*/ , drawPaint)) {
215 return false; 217 return false;
216 } 218 }
217 219
218 return KillSaveLayerAndRestore(record, begin); 220 return KillSaveLayerAndRestore(record, begin);
219 } 221 }
220 222
221 static bool KillSaveLayerAndRestore(SkRecord* record, int saveLayerIndex) { 223 static bool KillSaveLayerAndRestore(SkRecord* record, int saveLayerIndex) {
222 record->replace<NoOp>(saveLayerIndex); // SaveLayer 224 record->replace<NoOp>(saveLayerIndex); // SaveLayer
223 record->replace<NoOp>(saveLayerIndex+2); // Restore 225 record->replace<NoOp>(saveLayerIndex+2); // Restore
224 return true; 226 return true;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 259
258 // This layer typically contains a filter, but this should work for laye rs with for other 260 // This layer typically contains a filter, but this should work for laye rs with for other
259 // purposes too. 261 // purposes too.
260 SkPaint* filterLayerPaint = match->fourth<SaveLayer>()->paint; 262 SkPaint* filterLayerPaint = match->fourth<SaveLayer>()->paint;
261 if (filterLayerPaint == nullptr) { 263 if (filterLayerPaint == nullptr) {
262 // We can just give the inner SaveLayer the paint of the outer SaveL ayer. 264 // We can just give the inner SaveLayer the paint of the outer SaveL ayer.
263 // TODO(mtklein): figure out how to do this clearly 265 // TODO(mtklein): figure out how to do this clearly
264 return false; 266 return false;
265 } 267 }
266 268
267 if (!fold_opacity_layer_color_to_paint(*opacityPaint, true /*isSaveLayer */, 269 if (!fold_opacity_layer_color_to_paint(opacityPaint, true /*isSaveLayer* /,
268 filterLayerPaint)) { 270 filterLayerPaint)) {
269 return false; 271 return false;
270 } 272 }
271 273
272 return KillSaveLayerAndRestore(record, begin); 274 return KillSaveLayerAndRestore(record, begin);
273 } 275 }
274 276
275 static bool KillSaveLayerAndRestore(SkRecord* record, int saveLayerIndex) { 277 static bool KillSaveLayerAndRestore(SkRecord* record, int saveLayerIndex) {
276 record->replace<NoOp>(saveLayerIndex); // SaveLayer 278 record->replace<NoOp>(saveLayerIndex); // SaveLayer
277 record->replace<NoOp>(saveLayerIndex + 6); // Restore 279 record->replace<NoOp>(saveLayerIndex + 6); // Restore
(...skipping 25 matching lines...) Expand all
303 } 305 }
304 306
305 void SkRecordOptimize2(SkRecord* record) { 307 void SkRecordOptimize2(SkRecord* record) {
306 multiple_set_matrices(record); 308 multiple_set_matrices(record);
307 SkRecordNoopSaveRestores(record); 309 SkRecordNoopSaveRestores(record);
308 SkRecordNoopSaveLayerDrawRestores(record); 310 SkRecordNoopSaveLayerDrawRestores(record);
309 SkRecordMergeSvgOpacityAndFilterLayers(record); 311 SkRecordMergeSvgOpacityAndFilterLayers(record);
310 312
311 record->defrag(); 313 record->defrag();
312 } 314 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698