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

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: 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
27 // 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:
28 // - a Pattern typedef 17 // - a Pattern typedef
29 // - a bool onMatch(SkRceord*, Pattern*, int begin, int end) method, 18 // - a bool onMatch(SkRceord*, Pattern*, int begin, int end) method,
30 // which returns true if it made changes and false if not. 19 // which returns true if it made changes and false if not.
31 20
32 // 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.
33 // It looks for spans which match Pass::Pattern, and when found calls onMatch() with the pattern, 22 // It looks for spans which match Pass::Pattern, and when found calls onMatch() with the pattern,
34 // record, and [begin,end) span of the commands that matched. 23 // record, and [begin,end) span of the commands that matched.
35 template <typename Pass> 24 template <typename Pass>
36 static bool apply(Pass* pass, SkRecord* record) { 25 static bool apply(Pass* pass, SkRecord* record) {
37 typename Pass::Pattern pattern; 26 typename Pass::Pattern pattern;
38 bool changed = false; 27 bool changed = false;
39 int begin, end = 0; 28 int begin, end = 0;
40 29
41 while (pattern.search(record, &begin, &end)) { 30 while (pattern.search(record, &begin, &end)) {
42 changed |= pass->onMatch(record, &pattern, begin, end); 31 changed |= pass->onMatch(record, &pattern, begin, end);
43 } 32 }
44 return changed; 33 return changed;
45 } 34 }
46 35
36 //////////////////////////////////////////////////////////////////////////////// ///////////////////
37
38 static void multiple_set_matrices(SkRecord* record) {
39 struct {
40 typedef Pattern3<Is<SetMatrix>,
mtklein 2015/11/19 17:39:22 Sorry, moved the goalposts. This is now typedef
41 Star<Is<NoOp>>,
42 Is<SetMatrix> >
43 Pattern;
44
45 bool onMatch(SkRecord* record, Pattern* pattern, int begin, int end) {
46 record->replace<NoOp>(begin); // first SetMatrix
47 return true;
48 }
49 } pass;
50 // No need to loop, as we never "open up" opportunities for more of this typ e of optimization.
mtklein 2015/11/19 17:39:22 I do think this is still true that a single pass g
51 apply(&pass, record);
52 }
53
54 //////////////////////////////////////////////////////////////////////////////// ///////////////////
55
56 #if 0 // experimental, but needs knowledge of previous matrix to operate corre ctly
57 static void apply_matrix_to_draw_params(SkRecord* record) {
58 struct {
59 typedef Pattern3<Is<SetMatrix>,
60 Is<DrawBitmapRect>,
61 Is<Restore> >
62 Pattern;
63
64 bool onMatch(SkRecord* record, Pattern* pattern, int begin, int end) {
65 const SkMatrix& m = pattern->first<SetMatrix>()->matrix;
66 if (m.getType() > (SkMatrix::kScale_Mask | SkMatrix::kTranslate_Mask )) {
67 SkDebugf("too complex\n");
68 return false; // can't handle rotation or perspective
69 }
70 if (m.getScaleX() < 0 || m.getScaleY() < 0) {
71 SkDebugf("negative\n");
72 return false; // can't represent a flip in a rect
73 }
74 DrawBitmapRect* dbr = pattern->second<DrawBitmapRect>();
75 m.dump();
76 // wack the rect, and eliminate the matrix
77 m.mapRect(&dbr->dst);
78 record->replace<NoOp>(begin);
79 return true;
80 }
81 } pass;
82 apply(&pass, record);
83 }
84 #endif
85
86 //////////////////////////////////////////////////////////////////////////////// ///////////////////
87
47 // Turns the logical NoOp Save and Restore in Save-Draw*-Restore patterns into a ctual NoOps. 88 // Turns the logical NoOp Save and Restore in Save-Draw*-Restore patterns into a ctual NoOps.
48 struct SaveOnlyDrawsRestoreNooper { 89 struct SaveOnlyDrawsRestoreNooper {
49 typedef Pattern3<Is<Save>, 90 typedef Pattern3<Is<Save>,
50 Star<Or<Is<NoOp>, IsDraw> >, 91 Star<Or<Is<NoOp>, IsDraw> >,
51 Is<Restore> > 92 Is<Restore> >
52 Pattern; 93 Pattern;
53 94
54 bool onMatch(SkRecord* record, Pattern* pattern, int begin, int end) { 95 bool onMatch(SkRecord* record, Pattern* pattern, int begin, int end) {
55 record->replace<NoOp>(begin); // Save 96 record->replace<NoOp>(begin); // Save
56 record->replace<NoOp>(end-1); // Restore 97 record->replace<NoOp>(end-1); // Restore
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 record->replace<NoOp>(saveLayerIndex); // SaveLayer 264 record->replace<NoOp>(saveLayerIndex); // SaveLayer
224 record->replace<NoOp>(saveLayerIndex + 6); // Restore 265 record->replace<NoOp>(saveLayerIndex + 6); // Restore
225 return true; 266 return true;
226 } 267 }
227 }; 268 };
228 269
229 void SkRecordMergeSvgOpacityAndFilterLayers(SkRecord* record) { 270 void SkRecordMergeSvgOpacityAndFilterLayers(SkRecord* record) {
230 SvgOpacityAndFilterLayerMergePass pass; 271 SvgOpacityAndFilterLayerMergePass pass;
231 apply(&pass, record); 272 apply(&pass, record);
232 } 273 }
274
275 //////////////////////////////////////////////////////////////////////////////// ///////////////////
276
277 void SkRecordOptimize(SkRecord* record) {
278 // This might be useful as a first pass in the future if we want to weed
279 // out junk for other optimization passes. Right now, nothing needs it,
280 // and the bounding box hierarchy will do the work of skipping no-op
281 // Save-NoDraw-Restore sequences better than we can here.
282 //SkRecordNoopSaveRestores(record);
283
284 SkRecordNoopSaveLayerDrawRestores(record);
285 SkRecordMergeSvgOpacityAndFilterLayers(record);
286 }
287
288 void SkRecordOptimize2(SkRecord* record) {
289 multiple_set_matrices(record);
290
291 SkRecordNoopSaveRestores(record);
292
293 SkRecordNoopSaveLayerDrawRestores(record);
294 SkRecordMergeSvgOpacityAndFilterLayers(record);
295 }
296
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