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" |
11 #include "SkRecords.h" | 11 #include "SkRecords.h" |
12 #include "SkTDArray.h" | 12 #include "SkTDArray.h" |
13 | 13 |
14 using namespace SkRecords; | 14 using namespace SkRecords; |
15 | 15 |
16 void SkRecordOptimize(SkRecord* record) { | 16 void SkRecordOptimize(SkRecord* record) { |
17 // TODO(mtklein): fuse independent optimizations to reduce number of passes? | 17 // TODO(mtklein): fuse independent optimizations to reduce number of passes? |
| 18 SkRecordNoopCulls(record); |
18 SkRecordNoopSaveRestores(record); | 19 SkRecordNoopSaveRestores(record); |
19 SkRecordNoopSaveLayerDrawRestores(record); | 20 SkRecordNoopSaveLayerDrawRestores(record); |
| 21 |
20 SkRecordAnnotateCullingPairs(record); | 22 SkRecordAnnotateCullingPairs(record); |
21 SkRecordReduceDrawPosTextStrength(record); // Helpful to run this before Bo
undDrawPosTextH. | 23 SkRecordReduceDrawPosTextStrength(record); // Helpful to run this before Bo
undDrawPosTextH. |
22 SkRecordBoundDrawPosTextH(record); | 24 SkRecordBoundDrawPosTextH(record); |
23 } | 25 } |
24 | 26 |
25 // Most of the optimizations in this file are pattern-based. These are all defi
ned as structs with: | 27 // Most of the optimizations in this file are pattern-based. These are all defi
ned as structs with: |
26 // - a Pattern typedef | 28 // - a Pattern typedef |
27 // - a bool onMatch(SkRceord*, Pattern*, unsigned begin, unsigned end) method, | 29 // - a bool onMatch(SkRceord*, Pattern*, unsigned begin, unsigned end) method, |
28 // which returns true if it made changes and false if not. | 30 // which returns true if it made changes and false if not. |
29 | 31 |
30 // Run a pattern-based optimization once across the SkRecord, returning true if
it made any changes. | 32 // Run a pattern-based optimization once across the SkRecord, returning true if
it made any changes. |
31 // It looks for spans which match Pass::Pattern, and when found calls onMatch()
with the pattern, | 33 // It looks for spans which match Pass::Pattern, and when found calls onMatch()
with the pattern, |
32 // record, and [begin,end) span of the commands that matched. | 34 // record, and [begin,end) span of the commands that matched. |
33 template <typename Pass> | 35 template <typename Pass> |
34 static bool apply(Pass* pass, SkRecord* record) { | 36 static bool apply(Pass* pass, SkRecord* record) { |
35 typename Pass::Pattern pattern; | 37 typename Pass::Pattern pattern; |
36 bool changed = false; | 38 bool changed = false; |
37 unsigned begin, end = 0; | 39 unsigned begin, end = 0; |
38 | 40 |
39 while (pattern.search(record, &begin, &end)) { | 41 while (pattern.search(record, &begin, &end)) { |
40 changed |= pass->onMatch(record, &pattern, begin, end); | 42 changed |= pass->onMatch(record, &pattern, begin, end); |
41 } | 43 } |
42 return changed; | 44 return changed; |
43 } | 45 } |
44 | 46 |
| 47 struct CullNooper { |
| 48 typedef Pattern3<Is<PushCull>, Star<Is<NoOp> >, Is<PopCull> > Pattern; |
| 49 |
| 50 bool onMatch(SkRecord* record, Pattern* pattern, unsigned begin, unsigned en
d) { |
| 51 record->replace<NoOp>(begin); // PushCull |
| 52 record->replace<NoOp>(end-1); // PopCull |
| 53 return true; |
| 54 } |
| 55 }; |
| 56 |
| 57 void SkRecordNoopCulls(SkRecord* record) { |
| 58 CullNooper pass; |
| 59 while (apply(&pass, record)); |
| 60 } |
| 61 |
45 // Turns the logical NoOp Save and Restore in Save-Draw*-Restore patterns into a
ctual NoOps. | 62 // Turns the logical NoOp Save and Restore in Save-Draw*-Restore patterns into a
ctual NoOps. |
46 struct SaveOnlyDrawsRestoreNooper { | 63 struct SaveOnlyDrawsRestoreNooper { |
47 typedef Pattern3<Is<Save>, | 64 typedef Pattern3<Is<Save>, |
48 Star<Or<Is<NoOp>, IsDraw> >, | 65 Star<Or<Is<NoOp>, IsDraw> >, |
49 Is<Restore> > | 66 Is<Restore> > |
50 Pattern; | 67 Pattern; |
51 | 68 |
52 bool onMatch(SkRecord* record, Pattern* pattern, unsigned begin, unsigned en
d) { | 69 bool onMatch(SkRecord* record, Pattern* pattern, unsigned begin, unsigned en
d) { |
53 record->replace<NoOp>(begin); // Save | 70 record->replace<NoOp>(begin); // Save |
54 record->replace<NoOp>(end-1); // Restore | 71 record->replace<NoOp>(end-1); // Restore |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 }; | 292 }; |
276 | 293 |
277 SkTDArray<Pair> fPushStack; | 294 SkTDArray<Pair> fPushStack; |
278 SkRecord* fRecord; | 295 SkRecord* fRecord; |
279 unsigned fIndex; | 296 unsigned fIndex; |
280 }; | 297 }; |
281 void SkRecordAnnotateCullingPairs(SkRecord* record) { | 298 void SkRecordAnnotateCullingPairs(SkRecord* record) { |
282 CullAnnotator pass; | 299 CullAnnotator pass; |
283 pass.apply(record); | 300 pass.apply(record); |
284 } | 301 } |
OLD | NEW |