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 24 matching lines...) Expand all Loading... |
35 typename Pass::Pattern pattern; | 35 typename Pass::Pattern pattern; |
36 bool changed = false; | 36 bool changed = false; |
37 unsigned begin, end = 0; | 37 unsigned begin, end = 0; |
38 | 38 |
39 while (pattern.search(record, &begin, &end)) { | 39 while (pattern.search(record, &begin, &end)) { |
40 changed |= pass->onMatch(record, &pattern, begin, end); | 40 changed |= pass->onMatch(record, &pattern, begin, end); |
41 } | 41 } |
42 return changed; | 42 return changed; |
43 } | 43 } |
44 | 44 |
| 45 // Turns the logical NoOp Save and Restore in Save-Draw*-Restore patterns into a
ctual NoOps. |
| 46 struct SaveOnlyDrawsRestoreNooper { |
| 47 typedef Pattern3<Is<Save>, |
| 48 Star<Or<Is<NoOp>, IsDraw> >, |
| 49 Is<Restore> > |
| 50 Pattern; |
| 51 |
| 52 bool onMatch(SkRecord* record, Pattern* pattern, unsigned begin, unsigned en
d) { |
| 53 record->replace<NoOp>(begin); // Save |
| 54 record->replace<NoOp>(end-1); // Restore |
| 55 return true; |
| 56 } |
| 57 }; |
45 // Turns logical no-op Save-[non-drawing command]*-Restore patterns into actual
no-ops. | 58 // Turns logical no-op Save-[non-drawing command]*-Restore patterns into actual
no-ops. |
46 struct SaveRestoreNooper { | 59 struct SaveNoDrawsRestoreNooper { |
47 // Star matches greedily, so we also have to exclude Save and Restore. | 60 // Star matches greedily, so we also have to exclude Save and Restore. |
48 typedef Pattern3<Is<Save>, | 61 typedef Pattern3<Is<Save>, |
49 Star<Not<Or3<Is<Save>, | 62 Star<Not<Or3<Is<Save>, |
50 Is<Restore>, | 63 Is<Restore>, |
51 IsDraw> > >, | 64 IsDraw> > >, |
52 Is<Restore> > | 65 Is<Restore> > |
53 Pattern; | 66 Pattern; |
54 | 67 |
55 bool onMatch(SkRecord* record, Pattern* pattern, unsigned begin, unsigned en
d) { | 68 bool onMatch(SkRecord* record, Pattern* pattern, unsigned begin, unsigned en
d) { |
56 // If restore doesn't revert both matrix and clip, this isn't safe to no
op away. | 69 // If restore doesn't revert both matrix and clip, this isn't safe to no
op away. |
57 if (pattern->first<Save>()->flags != SkCanvas::kMatrixClip_SaveFlag) { | 70 if (pattern->first<Save>()->flags != SkCanvas::kMatrixClip_SaveFlag) { |
58 return false; | 71 return false; |
59 } | 72 } |
60 | 73 |
61 // The entire span between Save and Restore (inclusively) does nothing. | 74 // The entire span between Save and Restore (inclusively) does nothing. |
62 for (unsigned i = begin; i < end; i++) { | 75 for (unsigned i = begin; i < end; i++) { |
63 record->replace<NoOp>(i); | 76 record->replace<NoOp>(i); |
64 } | 77 } |
65 return true; | 78 return true; |
66 } | 79 } |
67 }; | 80 }; |
68 void SkRecordNoopSaveRestores(SkRecord* record) { | 81 void SkRecordNoopSaveRestores(SkRecord* record) { |
69 SaveRestoreNooper pass; | 82 SaveOnlyDrawsRestoreNooper onlyDraws; |
70 while (apply(&pass, record)); // Run until it stops changing things. | 83 SaveNoDrawsRestoreNooper noDraws; |
| 84 |
| 85 // Run until they stop changing things. |
| 86 while (apply(&onlyDraws, record) || apply(&noDraws, record)); |
71 } | 87 } |
72 | 88 |
73 // For some SaveLayer-[drawing command]-Restore patterns, merge the SaveLayer's
alpha into the | 89 // For some SaveLayer-[drawing command]-Restore patterns, merge the SaveLayer's
alpha into the |
74 // draw, and no-op the SaveLayer and Restore. | 90 // draw, and no-op the SaveLayer and Restore. |
75 struct SaveLayerDrawRestoreNooper { | 91 struct SaveLayerDrawRestoreNooper { |
76 typedef Pattern3<Is<SaveLayer>, IsDraw, Is<Restore> > Pattern; | 92 typedef Pattern3<Is<SaveLayer>, IsDraw, Is<Restore> > Pattern; |
77 | 93 |
78 bool onMatch(SkRecord* record, Pattern* pattern, unsigned begin, unsigned en
d) { | 94 bool onMatch(SkRecord* record, Pattern* pattern, unsigned begin, unsigned en
d) { |
79 SaveLayer* saveLayer = pattern->first<SaveLayer>(); | 95 SaveLayer* saveLayer = pattern->first<SaveLayer>(); |
80 if (saveLayer->bounds != NULL) { | 96 if (saveLayer->bounds != NULL) { |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 }; | 275 }; |
260 | 276 |
261 SkTDArray<Pair> fPushStack; | 277 SkTDArray<Pair> fPushStack; |
262 SkRecord* fRecord; | 278 SkRecord* fRecord; |
263 unsigned fIndex; | 279 unsigned fIndex; |
264 }; | 280 }; |
265 void SkRecordAnnotateCullingPairs(SkRecord* record) { | 281 void SkRecordAnnotateCullingPairs(SkRecord* record) { |
266 CullAnnotator pass; | 282 CullAnnotator pass; |
267 pass.apply(record); | 283 pass.apply(record); |
268 } | 284 } |
OLD | NEW |