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

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: rebase 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".
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 // If you're not also SkRecord-backed, tough luck. Get on the bandwagon .
145 if (op.picture->fRecord.get() == NULL) {
146 return;
147 }
148 const SkRecord& nested = *op.picture->fRecord;
149 for (unsigned i = 0; i < nested.count(); i++) {
150 nested.visit<void>(i, *this);
151 }
152 }
153
128 void checkPaint(const SkPaint* paint) { 154 void checkPaint(const SkPaint* paint) {
129 if (paint && paint->getPathEffect()) { 155 if (paint && paint->getPathEffect()) {
130 numPaintWithPathEffectUses++; 156 numPaintWithPathEffectUses++;
131 } 157 }
132 } 158 }
133 159
134 void operator()(const SkRecords::DrawPoints& op) { 160 void operator()(const SkRecords::DrawPoints& op) {
135 this->checkPaint(&op.paint); 161 this->checkPaint(&op.paint);
136 const SkPathEffect* effect = op.paint.getPathEffect(); 162 const SkPathEffect* effect = op.paint.getPathEffect();
137 if (effect) { 163 if (effect) {
(...skipping 19 matching lines...) Expand all
157 } 183 }
158 184
159 template <typename T> 185 template <typename T>
160 SK_WHEN(HasMember_paint<T>, void) operator()(const T& op) { 186 SK_WHEN(HasMember_paint<T>, void) operator()(const T& op) {
161 this->checkPaint(AsPtr(op.paint)); 187 this->checkPaint(AsPtr(op.paint));
162 } 188 }
163 189
164 template <typename T> 190 template <typename T>
165 SK_WHEN(!HasMember_paint<T>, void) operator()(const T& op) { /* do nothing * / } 191 SK_WHEN(!HasMember_paint<T>, void) operator()(const T& op) { /* do nothing * / }
166 192
167
168 int numPaintWithPathEffectUses; 193 int numPaintWithPathEffectUses;
169 int numFastPathDashEffects; 194 int numFastPathDashEffects;
170 int numAAConcavePaths; 195 int numAAConcavePaths;
171 int numAAHairlineConcavePaths; 196 int numAAHairlineConcavePaths;
172 }; 197 };
173 198
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) { 199 SkPicture::Analysis::Analysis(const SkRecord& record) {
185 fWillPlaybackBitmaps = WillPlaybackBitmaps(record); 200 fWillPlaybackBitmaps = WillPlaybackBitmaps(record);
186 201
187 PathCounter counter; 202 PathCounter counter;
188 for (unsigned i = 0; i < record.count(); i++) { 203 for (unsigned i = 0; i < record.count(); i++) {
189 record.visit<void>(i, counter); 204 record.visit<void>(i, counter);
190 } 205 }
191 fNumPaintWithPathEffectUses = counter.numPaintWithPathEffectUses; 206 fNumPaintWithPathEffectUses = counter.numPaintWithPathEffectUses;
192 fNumFastPathDashEffects = counter.numFastPathDashEffects; 207 fNumFastPathDashEffects = counter.numFastPathDashEffects;
193 fNumAAConcavePaths = counter.numAAConcavePaths; 208 fNumAAConcavePaths = counter.numAAConcavePaths;
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 int SkPicture::approximateOpCount() const { 647 int SkPicture::approximateOpCount() const {
633 SkASSERT(fRecord.get() || fData.get()); 648 SkASSERT(fRecord.get() || fData.get());
634 if (fRecord.get()) { 649 if (fRecord.get()) {
635 return fRecord->count(); 650 return fRecord->count();
636 } 651 }
637 if (fData.get()) { 652 if (fData.get()) {
638 return fData->opCount(); 653 return fData->opCount();
639 } 654 }
640 return 0; 655 return 0;
641 } 656 }
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