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

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

Issue 1462973002: add SkRecordOptimize2 and an experimental API for more aggressive opts (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix bugs in manual merge Created 5 years, 1 month 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 | « src/core/SkRecordOpts.h ('k') | tools/dump_record.cpp » ('j') | 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"
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) {
17 // This might be useful as a first pass in the future if we want to weed
18 // out junk for other optimization passes. Right now, nothing needs it,
19 // and the bounding box hierarchy will do the work of skipping no-op
20 // Save-NoDraw-Restore sequences better than we can here.
21 //SkRecordNoopSaveRestores(record);
22
23 SkRecordNoopSaveLayerDrawRestores(record);
24 SkRecordMergeSvgOpacityAndFilterLayers(record);
25
26 record->defrag();
27 }
28
29 // Most of the optimizations in this file are pattern-based. These are all defi ned as structs with: 16 // Most of the optimizations in this file are pattern-based. These are all defi ned as structs with:
30 // - a Match typedef 17 // - a Match typedef
31 // - a bool onMatch(SkRceord*, Match*, int begin, int end) method, 18 // - a bool onMatch(SkRceord*, Match*, int begin, int end) method,
32 // which returns true if it made changes and false if not. 19 // which returns true if it made changes and false if not.
33 20
34 // Run a pattern-based optimization once across the SkRecord, returning true if it made any changes. 21 // Run a pattern-based optimization once across the SkRecord, returning true if it made any changes.
35 // It looks for spans which match Pass::Match, and when found calls onMatch() wi th that pattern, 22 // It looks for spans which match Pass::Match, and when found calls onMatch() wi th that pattern,
36 // record, and [begin,end) span of the commands that matched. 23 // record, and [begin,end) span of the commands that matched.
37 template <typename Pass> 24 template <typename Pass>
38 static bool apply(Pass* pass, SkRecord* record) { 25 static bool apply(Pass* pass, SkRecord* record) {
39 typename Pass::Match match; 26 typename Pass::Match match;
40 bool changed = false; 27 bool changed = false;
41 int begin, end = 0; 28 int begin, end = 0;
42 29
43 while (match.search(record, &begin, &end)) { 30 while (match.search(record, &begin, &end)) {
44 changed |= pass->onMatch(record, &match, begin, end); 31 changed |= pass->onMatch(record, &match, begin, end);
45 } 32 }
46 return changed; 33 return changed;
47 } 34 }
48 35
36 //////////////////////////////////////////////////////////////////////////////// ///////////////////
37
38 static void multiple_set_matrices(SkRecord* record) {
39 struct {
40 typedef Pattern<Is<SetMatrix>,
41 Greedy<Is<NoOp>>,
42 Is<SetMatrix> >
43 Match;
44
45 bool onMatch(SkRecord* record, Match* pattern, int begin, int end) {
46 record->replace<NoOp>(begin); // first SetMatrix
47 return true;
48 }
49 } pass;
50 while (apply(&pass, record));
51 }
52
53 //////////////////////////////////////////////////////////////////////////////// ///////////////////
54
55 #if 0 // experimental, but needs knowledge of previous matrix to operate corre ctly
56 static void apply_matrix_to_draw_params(SkRecord* record) {
57 struct {
58 typedef Pattern<Is<SetMatrix>,
59 Greedy<Is<NoOp>>,
60 Is<SetMatrix> >
61 Pattern;
62
63 bool onMatch(SkRecord* record, Pattern* pattern, int begin, int end) {
64 record->replace<NoOp>(begin); // first SetMatrix
65 return true;
66 }
67 } pass;
68 // No need to loop, as we never "open up" opportunities for more of this typ e of optimization.
69 apply(&pass, record);
70 }
71 #endif
72
73 //////////////////////////////////////////////////////////////////////////////// ///////////////////
74
49 // Turns the logical NoOp Save and Restore in Save-Draw*-Restore patterns into a ctual NoOps. 75 // Turns the logical NoOp Save and Restore in Save-Draw*-Restore patterns into a ctual NoOps.
50 struct SaveOnlyDrawsRestoreNooper { 76 struct SaveOnlyDrawsRestoreNooper {
51 typedef Pattern<Is<Save>, 77 typedef Pattern<Is<Save>,
52 Greedy<Or<Is<NoOp>, IsDraw>>, 78 Greedy<Or<Is<NoOp>, IsDraw>>,
53 Is<Restore>> 79 Is<Restore>>
54 Match; 80 Match;
55 81
56 bool onMatch(SkRecord* record, Match*, int begin, int end) { 82 bool onMatch(SkRecord* record, Match*, int begin, int end) {
57 record->replace<NoOp>(begin); // Save 83 record->replace<NoOp>(begin); // Save
58 record->replace<NoOp>(end-1); // Restore 84 record->replace<NoOp>(end-1); // Restore
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 record->replace<NoOp>(saveLayerIndex); // SaveLayer 251 record->replace<NoOp>(saveLayerIndex); // SaveLayer
226 record->replace<NoOp>(saveLayerIndex + 6); // Restore 252 record->replace<NoOp>(saveLayerIndex + 6); // Restore
227 return true; 253 return true;
228 } 254 }
229 }; 255 };
230 256
231 void SkRecordMergeSvgOpacityAndFilterLayers(SkRecord* record) { 257 void SkRecordMergeSvgOpacityAndFilterLayers(SkRecord* record) {
232 SvgOpacityAndFilterLayerMergePass pass; 258 SvgOpacityAndFilterLayerMergePass pass;
233 apply(&pass, record); 259 apply(&pass, record);
234 } 260 }
261
262 //////////////////////////////////////////////////////////////////////////////// ///////////////////
263
264 void SkRecordOptimize(SkRecord* record) {
265 // This might be useful as a first pass in the future if we want to weed
266 // out junk for other optimization passes. Right now, nothing needs it,
267 // and the bounding box hierarchy will do the work of skipping no-op
268 // Save-NoDraw-Restore sequences better than we can here.
269 //SkRecordNoopSaveRestores(record);
270
271 SkRecordNoopSaveLayerDrawRestores(record);
272 SkRecordMergeSvgOpacityAndFilterLayers(record);
273
274 record->defrag();
275 }
276
277 void SkRecordOptimize2(SkRecord* record) {
278 multiple_set_matrices(record);
279 SkRecordNoopSaveRestores(record);
280 SkRecordNoopSaveLayerDrawRestores(record);
281 SkRecordMergeSvgOpacityAndFilterLayers(record);
282
283 record->defrag();
284 }
285
OLDNEW
« no previous file with comments | « src/core/SkRecordOpts.h ('k') | tools/dump_record.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698