| 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 27 matching lines...) Expand all Loading... |
| 217 SaveLayer (typically for SVG filter) | 222 SaveLayer (typically for SVG filter) |
| 218 Restore | 223 Restore |
| 219 Restore | 224 Restore |
| 220 Restore | 225 Restore |
| 221 */ | 226 */ |
| 222 struct SvgOpacityAndFilterLayerMergePass { | 227 struct SvgOpacityAndFilterLayerMergePass { |
| 223 typedef Pattern<Is<SaveLayer>, Is<Save>, Is<ClipRect>, Is<SaveLayer>, | 228 typedef Pattern<Is<SaveLayer>, Is<Save>, Is<ClipRect>, Is<SaveLayer>, |
| 224 Is<Restore>, Is<Restore>, Is<Restore>> Match; | 229 Is<Restore>, Is<Restore>, Is<Restore>> Match; |
| 225 | 230 |
| 226 bool onMatch(SkRecord* record, Match* match, int begin, int end) { | 231 bool onMatch(SkRecord* record, Match* match, int begin, int end) { |
| 232 if (match->first<SaveLayer>()->backdrop) { |
| 233 // can't throw away the layer if we have a backdrop |
| 234 return false; |
| 235 } |
| 236 |
| 227 SkPaint* opacityPaint = match->first<SaveLayer>()->paint; | 237 SkPaint* opacityPaint = match->first<SaveLayer>()->paint; |
| 228 if (nullptr == opacityPaint) { | 238 if (nullptr == opacityPaint) { |
| 229 // There wasn't really any point to this SaveLayer at all. | 239 // There wasn't really any point to this SaveLayer at all. |
| 230 return KillSaveLayerAndRestore(record, begin); | 240 return KillSaveLayerAndRestore(record, begin); |
| 231 } | 241 } |
| 232 | 242 |
| 233 // This layer typically contains a filter, but this should work for laye
rs with for other | 243 // This layer typically contains a filter, but this should work for laye
rs with for other |
| 234 // purposes too. | 244 // purposes too. |
| 235 SkPaint* filterLayerPaint = match->fourth<SaveLayer>()->paint; | 245 SkPaint* filterLayerPaint = match->fourth<SaveLayer>()->paint; |
| 236 if (filterLayerPaint == nullptr) { | 246 if (filterLayerPaint == nullptr) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 | 286 |
| 277 void SkRecordOptimize2(SkRecord* record) { | 287 void SkRecordOptimize2(SkRecord* record) { |
| 278 multiple_set_matrices(record); | 288 multiple_set_matrices(record); |
| 279 SkRecordNoopSaveRestores(record); | 289 SkRecordNoopSaveRestores(record); |
| 280 SkRecordNoopSaveLayerDrawRestores(record); | 290 SkRecordNoopSaveLayerDrawRestores(record); |
| 281 SkRecordMergeSvgOpacityAndFilterLayers(record); | 291 SkRecordMergeSvgOpacityAndFilterLayers(record); |
| 282 | 292 |
| 283 record->defrag(); | 293 record->defrag(); |
| 284 } | 294 } |
| 285 | 295 |
| OLD | NEW |