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

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

Issue 495793002: Our SkPicture::Analysis visitors should recurse into nested pictures. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 4 months 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 | « include/core/SkPicture.h ('k') | src/core/SkRecords.h » ('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 /* 2 /*
3 * Copyright 2007 The Android Open Source Project 3 * Copyright 2007 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "SkPictureFlat.h" 10 #include "SkPictureFlat.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 Expected use is to determine whether images need to be decoded before 61 Expected use is to determine whether images need to be decoded before
62 rasterizing a particular SkRecord. 62 rasterizing a particular SkRecord.
63 */ 63 */
64 struct BitmapTester { 64 struct BitmapTester {
65 // Helpers. These create HasMember_bitmap and HasMember_paint. 65 // Helpers. These create HasMember_bitmap and HasMember_paint.
66 SK_CREATE_MEMBER_DETECTOR(bitmap); 66 SK_CREATE_MEMBER_DETECTOR(bitmap);
67 SK_CREATE_MEMBER_DETECTOR(paint); 67 SK_CREATE_MEMBER_DETECTOR(paint);
68 68
69 69
70 // Main entry for visitor: 70 // Main entry for visitor:
71 // If the command is a DrawPicture, recurse.
71 // If the command has a bitmap directly, return true. 72 // If the command has a bitmap directly, return true.
72 // If the command has a paint and the paint has a bitmap, return true. 73 // If the command has a paint and the paint has a bitmap, return true.
73 // Otherwise, return false. 74 // Otherwise, return false.
75 bool operator()(const SkRecords::DrawPicture& op) { return op.picture->willP layBackBitmaps(); }
76
74 template <typename T> 77 template <typename T>
75 bool operator()(const T& r) { return CheckBitmap(r); } 78 bool operator()(const T& r) { return CheckBitmap(r); }
76 79
77 80
78 // If the command has a bitmap, of course we're going to play back bitmaps. 81 // If the command has a bitmap, of course we're going to play back bitmaps.
79 template <typename T> 82 template <typename T>
80 static SK_WHEN(HasMember_bitmap<T>, bool) CheckBitmap(const T&) { return tru e; } 83 static SK_WHEN(HasMember_bitmap<T>, bool) CheckBitmap(const T&) { return tru e; }
81 84
82 // If not, look for one in its paint (if it has a paint). 85 // If not, look for one in its paint (if it has a paint).
83 template <typename T> 86 template <typename T>
(...skipping 21 matching lines...) Expand all
105 bool WillPlaybackBitmaps(const SkRecord& record) { 108 bool WillPlaybackBitmaps(const SkRecord& record) {
106 BitmapTester tester; 109 BitmapTester tester;
107 for (unsigned i = 0; i < record.count(); i++) { 110 for (unsigned i = 0; i < record.count(); i++) {
108 if (record.visit<bool>(i, tester)) { 111 if (record.visit<bool>(i, tester)) {
109 return true; 112 return true;
110 } 113 }
111 } 114 }
112 return false; 115 return false;
113 } 116 }
114 117
118 // SkRecord visitor to find recorded text.
119 struct TextHunter {
120 // All ops with text have that text as a char array member named "text".
reed1 2014/08/20 22:30:31 clever, and possible fragile. All the more reason
121 SK_CREATE_MEMBER_DETECTOR(text);
122 bool operator()(const SkRecords::DrawPicture& op) { return op.picture->hasTe xt(); }
123 template <typename T> SK_WHEN(HasMember_text<T>, bool) operator()(const T&) { return true; }
124 template <typename T> SK_WHEN(!HasMember_text<T>, bool) operator()(const T&) { return false; }
125 };
126
127 } // namespace
128
115 /** SkRecords visitor to determine heuristically whether or not a SkPicture 129 /** SkRecords visitor to determine heuristically whether or not a SkPicture
116 will be performant when rasterized on the GPU. 130 will be performant when rasterized on the GPU.
117 */ 131 */
118 struct PathCounter { 132 struct SkPicture::PathCounter {
119 SK_CREATE_MEMBER_DETECTOR(paint); 133 SK_CREATE_MEMBER_DETECTOR(paint);
120 134
121 PathCounter() 135 PathCounter()
122 : numPaintWithPathEffectUses (0) 136 : numPaintWithPathEffectUses (0)
123 , numFastPathDashEffects (0) 137 , numFastPathDashEffects (0)
124 , numAAConcavePaths (0) 138 , numAAConcavePaths (0)
125 , numAAHairlineConcavePaths (0) { 139 , numAAHairlineConcavePaths (0) {
126 } 140 }
127 141
142 // Recurse into nested pictures.
143 void operator()(const SkRecords::DrawPicture& op) {
144 SkASSERT(op.picture->fRecord.get() != NULL);
145 const SkRecord& nested = *op.picture->fRecord;
146 for (unsigned i = 0; i < nested.count(); i++) {
147 nested.visit<void>(i, *this);
148 }
149 }
150
128 void checkPaint(const SkPaint* paint) { 151 void checkPaint(const SkPaint* paint) {
129 if (paint && paint->getPathEffect()) { 152 if (paint && paint->getPathEffect()) {
130 numPaintWithPathEffectUses++; 153 numPaintWithPathEffectUses++;
131 } 154 }
132 } 155 }
133 156
134 void operator()(const SkRecords::DrawPoints& op) { 157 void operator()(const SkRecords::DrawPoints& op) {
135 this->checkPaint(&op.paint); 158 this->checkPaint(&op.paint);
136 const SkPathEffect* effect = op.paint.getPathEffect(); 159 const SkPathEffect* effect = op.paint.getPathEffect();
137 if (effect) { 160 if (effect) {
(...skipping 19 matching lines...) Expand all
157 } 180 }
158 181
159 template <typename T> 182 template <typename T>
160 SK_WHEN(HasMember_paint<T>, void) operator()(const T& op) { 183 SK_WHEN(HasMember_paint<T>, void) operator()(const T& op) {
161 this->checkPaint(AsPtr(op.paint)); 184 this->checkPaint(AsPtr(op.paint));
162 } 185 }
163 186
164 template <typename T> 187 template <typename T>
165 SK_WHEN(!HasMember_paint<T>, void) operator()(const T& op) { /* do nothing * / } 188 SK_WHEN(!HasMember_paint<T>, void) operator()(const T& op) { /* do nothing * / }
166 189
167
168 int numPaintWithPathEffectUses; 190 int numPaintWithPathEffectUses;
169 int numFastPathDashEffects; 191 int numFastPathDashEffects;
170 int numAAConcavePaths; 192 int numAAConcavePaths;
171 int numAAHairlineConcavePaths; 193 int numAAHairlineConcavePaths;
172 }; 194 };
173 195
174 // SkRecord visitor to find recorded text.
175 struct TextHunter {
176 // All ops with text have that text as a char array member named "text".
177 SK_CREATE_MEMBER_DETECTOR(text);
178 template <typename T> SK_WHEN(HasMember_text<T>, bool) operator()(const T&) { return true; }
179 template <typename T> SK_WHEN(!HasMember_text<T>, bool) operator()(const T&) { return false; }
180 };
181
182 } // namespace
183
184 SkPicture::Analysis::Analysis(const SkRecord& record) { 196 SkPicture::Analysis::Analysis(const SkRecord& record) {
185 fWillPlaybackBitmaps = WillPlaybackBitmaps(record); 197 fWillPlaybackBitmaps = WillPlaybackBitmaps(record);
186 198
187 PathCounter counter; 199 PathCounter counter;
188 for (unsigned i = 0; i < record.count(); i++) { 200 for (unsigned i = 0; i < record.count(); i++) {
189 record.visit<void>(i, counter); 201 record.visit<void>(i, counter);
190 } 202 }
191 fNumPaintWithPathEffectUses = counter.numPaintWithPathEffectUses; 203 fNumPaintWithPathEffectUses = counter.numPaintWithPathEffectUses;
192 fNumFastPathDashEffects = counter.numFastPathDashEffects; 204 fNumFastPathDashEffects = counter.numFastPathDashEffects;
193 fNumAAConcavePaths = counter.numAAConcavePaths; 205 fNumAAConcavePaths = counter.numAAConcavePaths;
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 int SkPicture::approximateOpCount() const { 634 int SkPicture::approximateOpCount() const {
623 SkASSERT(fRecord.get() || fData.get()); 635 SkASSERT(fRecord.get() || fData.get());
624 if (fRecord.get()) { 636 if (fRecord.get()) {
625 return fRecord->count(); 637 return fRecord->count();
626 } 638 }
627 if (fData.get()) { 639 if (fData.get()) {
628 return fData->opCount(); 640 return fData->opCount();
629 } 641 }
630 return 0; 642 return 0;
631 } 643 }
OLDNEW
« no previous file with comments | « include/core/SkPicture.h ('k') | src/core/SkRecords.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698