OLD | NEW |
---|---|
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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
170 // Run until they stop changing things. | 170 // Run until they stop changing things. |
171 while (apply(&onlyDraws, record) || apply(&noDraws, record)); | 171 while (apply(&onlyDraws, record) || apply(&noDraws, record)); |
172 } | 172 } |
173 | 173 |
174 // For some SaveLayer-[drawing command]-Restore patterns, merge the SaveLayer's alpha into the | 174 // For some SaveLayer-[drawing command]-Restore patterns, merge the SaveLayer's alpha into the |
175 // draw, and no-op the SaveLayer and Restore. | 175 // draw, and no-op the SaveLayer and Restore. |
176 struct SaveLayerDrawRestoreNooper { | 176 struct SaveLayerDrawRestoreNooper { |
177 typedef Pattern<Is<SaveLayer>, IsDraw, Is<Restore>> Match; | 177 typedef Pattern<Is<SaveLayer>, IsDraw, Is<Restore>> Match; |
178 | 178 |
179 bool onMatch(SkRecord* record, Match* match, int begin, int end) { | 179 bool onMatch(SkRecord* record, Match* match, int begin, int end) { |
180 if (match->first<SaveLayer>()->backdrop) { | |
181 // can't throw away the layer if we have a backdrop | |
182 return false; | |
183 } | |
184 | |
180 // A SaveLayer's bounds field is just a hint, so we should be free to ig nore it. | 185 // A SaveLayer's bounds field is just a hint, so we should be free to ig nore it. |
181 SkPaint* layerPaint = match->first<SaveLayer>()->paint; | 186 SkPaint* layerPaint = match->first<SaveLayer>()->paint; |
182 if (nullptr == layerPaint) { | 187 if (nullptr == layerPaint) { |
183 // There wasn't really any point to this SaveLayer at all. | 188 // There wasn't really any point to this SaveLayer at all. |
184 return KillSaveLayerAndRestore(record, begin); | 189 return KillSaveLayerAndRestore(record, begin); |
185 } | 190 } |
186 | 191 |
187 SkPaint* drawPaint = match->second<SkPaint>(); | 192 SkPaint* drawPaint = match->second<SkPaint>(); |
188 if (drawPaint == nullptr) { | 193 if (drawPaint == nullptr) { |
189 // We can just give the draw the SaveLayer's paint. | 194 // We can just give the draw the SaveLayer's paint. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
240 } | 245 } |
241 | 246 |
242 if (!fold_opacity_layer_color_to_paint(*opacityPaint, true /*isSaveLayer */, | 247 if (!fold_opacity_layer_color_to_paint(*opacityPaint, true /*isSaveLayer */, |
243 filterLayerPaint)) { | 248 filterLayerPaint)) { |
244 return false; | 249 return false; |
245 } | 250 } |
246 | 251 |
247 return KillSaveLayerAndRestore(record, begin); | 252 return KillSaveLayerAndRestore(record, begin); |
248 } | 253 } |
249 | 254 |
250 static bool KillSaveLayerAndRestore(SkRecord* record, int saveLayerIndex) { | 255 static bool KillSaveLayerAndRestore(SkRecord* record, int saveLayerIndex) { |
mtklein
2016/01/07 18:27:42
This one too?
reed1
2016/01/07 19:09:18
Done.
| |
251 record->replace<NoOp>(saveLayerIndex); // SaveLayer | 256 record->replace<NoOp>(saveLayerIndex); // SaveLayer |
252 record->replace<NoOp>(saveLayerIndex + 6); // Restore | 257 record->replace<NoOp>(saveLayerIndex + 6); // Restore |
253 return true; | 258 return true; |
254 } | 259 } |
255 }; | 260 }; |
256 | 261 |
257 void SkRecordMergeSvgOpacityAndFilterLayers(SkRecord* record) { | 262 void SkRecordMergeSvgOpacityAndFilterLayers(SkRecord* record) { |
258 SvgOpacityAndFilterLayerMergePass pass; | 263 SvgOpacityAndFilterLayerMergePass pass; |
259 apply(&pass, record); | 264 apply(&pass, record); |
260 } | 265 } |
(...skipping 15 matching lines...) Expand all Loading... | |
276 | 281 |
277 void SkRecordOptimize2(SkRecord* record) { | 282 void SkRecordOptimize2(SkRecord* record) { |
278 multiple_set_matrices(record); | 283 multiple_set_matrices(record); |
279 SkRecordNoopSaveRestores(record); | 284 SkRecordNoopSaveRestores(record); |
280 SkRecordNoopSaveLayerDrawRestores(record); | 285 SkRecordNoopSaveLayerDrawRestores(record); |
281 SkRecordMergeSvgOpacityAndFilterLayers(record); | 286 SkRecordMergeSvgOpacityAndFilterLayers(record); |
282 | 287 |
283 record->defrag(); | 288 record->defrag(); |
284 } | 289 } |
285 | 290 |
OLD | NEW |