OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkBBoxHierarchy.h" | 8 #include "SkBBoxHierarchy.h" |
9 #include "SkBlurImageFilter.h" | 9 #include "SkBlurImageFilter.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
11 #include "SkColorMatrixFilter.h" | 11 #include "SkColorMatrixFilter.h" |
12 #include "SkColorPriv.h" | 12 #include "SkColorPriv.h" |
13 #include "SkDashPathEffect.h" | 13 #include "SkDashPathEffect.h" |
14 #include "SkData.h" | 14 #include "SkData.h" |
15 #include "SkImageGenerator.h" | 15 #include "SkImageGenerator.h" |
16 #include "SkError.h" | 16 #include "SkError.h" |
17 #include "SkImageEncoder.h" | 17 #include "SkImageEncoder.h" |
18 #include "SkImageGenerator.h" | 18 #include "SkImageGenerator.h" |
19 #include "SkLayerInfo.h" | 19 #include "SkLayerInfo.h" |
20 #include "SkMD5.h" | 20 #include "SkMD5.h" |
21 #include "SkPaint.h" | 21 #include "SkPaint.h" |
22 #include "SkPicture.h" | 22 #include "SkPicture.h" |
| 23 #include "SkPictureAnalyzer.h" |
23 #include "SkPictureRecorder.h" | 24 #include "SkPictureRecorder.h" |
24 #include "SkPictureUtils.h" | 25 #include "SkPictureUtils.h" |
25 #include "SkPixelRef.h" | 26 #include "SkPixelRef.h" |
26 #include "SkPixelSerializer.h" | 27 #include "SkPixelSerializer.h" |
27 #include "SkMiniRecorder.h" | 28 #include "SkMiniRecorder.h" |
28 #include "SkRRect.h" | 29 #include "SkRRect.h" |
29 #include "SkRandom.h" | 30 #include "SkRandom.h" |
30 #include "SkRecord.h" | 31 #include "SkRecord.h" |
31 #include "SkShader.h" | 32 #include "SkShader.h" |
32 #include "SkStream.h" | 33 #include "SkStream.h" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 paint.setPathEffect(dash); | 152 paint.setPathEffect(dash); |
152 | 153 |
153 for (int i = 0; i < 50; ++i) { | 154 for (int i = 0; i < 50; ++i) { |
154 canvas->drawPath(path, paint); | 155 canvas->drawPath(path, paint); |
155 } | 156 } |
156 } | 157 } |
157 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); | 158 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); |
158 // path effects currently render an SkPicture undesireable for GPU rendering | 159 // path effects currently render an SkPicture undesireable for GPU rendering |
159 | 160 |
160 const char *reason = nullptr; | 161 const char *reason = nullptr; |
161 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(nullptr, &re
ason)); | 162 REPORTER_ASSERT(reporter, |
| 163 !SkPictureGpuAnalyzer(picture).suitableForGpuRasterization(nullptr, &rea
son)); |
162 REPORTER_ASSERT(reporter, reason); | 164 REPORTER_ASSERT(reporter, reason); |
163 | 165 |
164 canvas = recorder.beginRecording(100, 100); | 166 canvas = recorder.beginRecording(100, 100); |
165 { | 167 { |
166 SkPath path; | 168 SkPath path; |
167 | 169 |
168 path.moveTo(0, 0); | 170 path.moveTo(0, 0); |
169 path.lineTo(0, 50); | 171 path.lineTo(0, 50); |
170 path.lineTo(25, 25); | 172 path.lineTo(25, 25); |
171 path.lineTo(50, 50); | 173 path.lineTo(50, 50); |
172 path.lineTo(50, 0); | 174 path.lineTo(50, 0); |
173 path.close(); | 175 path.close(); |
174 REPORTER_ASSERT(reporter, !path.isConvex()); | 176 REPORTER_ASSERT(reporter, !path.isConvex()); |
175 | 177 |
176 SkPaint paint; | 178 SkPaint paint; |
177 paint.setAntiAlias(true); | 179 paint.setAntiAlias(true); |
178 for (int i = 0; i < 50; ++i) { | 180 for (int i = 0; i < 50; ++i) { |
179 canvas->drawPath(path, paint); | 181 canvas->drawPath(path, paint); |
180 } | 182 } |
181 } | 183 } |
182 picture = recorder.finishRecordingAsPicture(); | 184 picture = recorder.finishRecordingAsPicture(); |
183 // A lot of small AA concave paths should be fine for GPU rendering | 185 // A lot of small AA concave paths should be fine for GPU rendering |
184 REPORTER_ASSERT(reporter, picture->suitableForGpuRasterization(nullptr)); | 186 REPORTER_ASSERT(reporter, SkPictureGpuAnalyzer(picture).suitableForGpuRaster
ization(nullptr)); |
185 | 187 |
186 canvas = recorder.beginRecording(100, 100); | 188 canvas = recorder.beginRecording(100, 100); |
187 { | 189 { |
188 SkPath path; | 190 SkPath path; |
189 | 191 |
190 path.moveTo(0, 0); | 192 path.moveTo(0, 0); |
191 path.lineTo(0, 100); | 193 path.lineTo(0, 100); |
192 path.lineTo(50, 50); | 194 path.lineTo(50, 50); |
193 path.lineTo(100, 100); | 195 path.lineTo(100, 100); |
194 path.lineTo(100, 0); | 196 path.lineTo(100, 0); |
195 path.close(); | 197 path.close(); |
196 REPORTER_ASSERT(reporter, !path.isConvex()); | 198 REPORTER_ASSERT(reporter, !path.isConvex()); |
197 | 199 |
198 SkPaint paint; | 200 SkPaint paint; |
199 paint.setAntiAlias(true); | 201 paint.setAntiAlias(true); |
200 for (int i = 0; i < 50; ++i) { | 202 for (int i = 0; i < 50; ++i) { |
201 canvas->drawPath(path, paint); | 203 canvas->drawPath(path, paint); |
202 } | 204 } |
203 } | 205 } |
204 picture = recorder.finishRecordingAsPicture(); | 206 picture = recorder.finishRecordingAsPicture(); |
205 // A lot of large AA concave paths currently render an SkPicture undesireabl
e for GPU rendering | 207 // A lot of large AA concave paths currently render an SkPicture undesireabl
e for GPU rendering |
206 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(nullptr)); | 208 REPORTER_ASSERT(reporter, !SkPictureGpuAnalyzer(picture).suitableForGpuRaste
rization(nullptr)); |
207 | 209 |
208 canvas = recorder.beginRecording(100, 100); | 210 canvas = recorder.beginRecording(100, 100); |
209 { | 211 { |
210 SkPath path; | 212 SkPath path; |
211 | 213 |
212 path.moveTo(0, 0); | 214 path.moveTo(0, 0); |
213 path.lineTo(0, 50); | 215 path.lineTo(0, 50); |
214 path.lineTo(25, 25); | 216 path.lineTo(25, 25); |
215 path.lineTo(50, 50); | 217 path.lineTo(50, 50); |
216 path.lineTo(50, 0); | 218 path.lineTo(50, 0); |
217 path.close(); | 219 path.close(); |
218 REPORTER_ASSERT(reporter, !path.isConvex()); | 220 REPORTER_ASSERT(reporter, !path.isConvex()); |
219 | 221 |
220 SkPaint paint; | 222 SkPaint paint; |
221 paint.setAntiAlias(true); | 223 paint.setAntiAlias(true); |
222 paint.setStyle(SkPaint::kStroke_Style); | 224 paint.setStyle(SkPaint::kStroke_Style); |
223 paint.setStrokeWidth(0); | 225 paint.setStrokeWidth(0); |
224 for (int i = 0; i < 50; ++i) { | 226 for (int i = 0; i < 50; ++i) { |
225 canvas->drawPath(path, paint); | 227 canvas->drawPath(path, paint); |
226 } | 228 } |
227 } | 229 } |
228 picture = recorder.finishRecordingAsPicture(); | 230 picture = recorder.finishRecordingAsPicture(); |
229 // hairline stroked AA concave paths are fine for GPU rendering | 231 // hairline stroked AA concave paths are fine for GPU rendering |
230 REPORTER_ASSERT(reporter, picture->suitableForGpuRasterization(nullptr)); | 232 REPORTER_ASSERT(reporter, SkPictureGpuAnalyzer(picture).suitableForGpuRaster
ization(nullptr)); |
231 | 233 |
232 canvas = recorder.beginRecording(100, 100); | 234 canvas = recorder.beginRecording(100, 100); |
233 { | 235 { |
234 SkPaint paint; | 236 SkPaint paint; |
235 SkScalar intervals [] = { 10, 20 }; | 237 SkScalar intervals [] = { 10, 20 }; |
236 paint.setPathEffect(SkDashPathEffect::Make(intervals, 2, 25)); | 238 paint.setPathEffect(SkDashPathEffect::Make(intervals, 2, 25)); |
237 | 239 |
238 SkPoint points [2] = { { 0, 0 }, { 100, 0 } }; | 240 SkPoint points [2] = { { 0, 0 }, { 100, 0 } }; |
239 | 241 |
240 for (int i = 0; i < 50; ++i) { | 242 for (int i = 0; i < 50; ++i) { |
241 canvas->drawPoints(SkCanvas::kLines_PointMode, 2, points, paint); | 243 canvas->drawPoints(SkCanvas::kLines_PointMode, 2, points, paint); |
242 } | 244 } |
243 } | 245 } |
244 picture = recorder.finishRecordingAsPicture(); | 246 picture = recorder.finishRecordingAsPicture(); |
245 // fast-path dashed effects are fine for GPU rendering ... | 247 // fast-path dashed effects are fine for GPU rendering ... |
246 REPORTER_ASSERT(reporter, picture->suitableForGpuRasterization(nullptr)); | 248 REPORTER_ASSERT(reporter, SkPictureGpuAnalyzer(picture).suitableForGpuRaster
ization(nullptr)); |
247 | 249 |
248 canvas = recorder.beginRecording(100, 100); | 250 canvas = recorder.beginRecording(100, 100); |
249 { | 251 { |
250 SkPaint paint; | 252 SkPaint paint; |
251 SkScalar intervals [] = { 10, 20 }; | 253 SkScalar intervals [] = { 10, 20 }; |
252 paint.setPathEffect(SkDashPathEffect::Make(intervals, 2, 25)); | 254 paint.setPathEffect(SkDashPathEffect::Make(intervals, 2, 25)); |
253 | 255 |
254 for (int i = 0; i < 50; ++i) { | 256 for (int i = 0; i < 50; ++i) { |
255 canvas->drawRect(SkRect::MakeWH(10, 10), paint); | 257 canvas->drawRect(SkRect::MakeWH(10, 10), paint); |
256 } | 258 } |
257 } | 259 } |
258 picture = recorder.finishRecordingAsPicture(); | 260 picture = recorder.finishRecordingAsPicture(); |
259 // ... but only when applied to drawPoint() calls | 261 // ... but only when applied to drawPoint() calls |
260 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(nullptr)); | 262 REPORTER_ASSERT(reporter, !SkPictureGpuAnalyzer(picture).suitableForGpuRaste
rization(nullptr)); |
261 | 263 |
262 // Nest the previous picture inside a new one. | 264 // Nest the previous picture inside a new one. |
263 canvas = recorder.beginRecording(100, 100); | 265 canvas = recorder.beginRecording(100, 100); |
264 { | 266 { |
265 canvas->drawPicture(picture.get()); | 267 canvas->drawPicture(picture); |
266 } | 268 } |
267 picture = recorder.finishRecordingAsPicture(); | 269 picture = recorder.finishRecordingAsPicture(); |
268 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(nullptr)); | 270 REPORTER_ASSERT(reporter, !SkPictureGpuAnalyzer(picture).suitableForGpuRaste
rization(nullptr)); |
269 } | 271 } |
270 | 272 |
271 #endif | 273 #endif |
272 | 274 |
273 static void test_savelayer_extraction(skiatest::Reporter* reporter) { | 275 static void test_savelayer_extraction(skiatest::Reporter* reporter) { |
274 static const int kWidth = 100; | 276 static const int kWidth = 100; |
275 static const int kHeight = 100; | 277 static const int kHeight = 100; |
276 | 278 |
277 // Create complex paint that the bounding box computation code can't | 279 // Create complex paint that the bounding box computation code can't |
278 // optimize away | 280 // optimize away |
(...skipping 1060 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1339 | 1341 |
1340 SkAutoTDelete<SkStream> rstream(wstream.detachAsStream()); | 1342 SkAutoTDelete<SkStream> rstream(wstream.detachAsStream()); |
1341 sk_sp<SkPicture> deserializedPicture(SkPicture::MakeFromStream(rstream)); | 1343 sk_sp<SkPicture> deserializedPicture(SkPicture::MakeFromStream(rstream)); |
1342 | 1344 |
1343 REPORTER_ASSERT(r, deserializedPicture != nullptr); | 1345 REPORTER_ASSERT(r, deserializedPicture != nullptr); |
1344 REPORTER_ASSERT(r, deserializedPicture->cullRect().left() == 1); | 1346 REPORTER_ASSERT(r, deserializedPicture->cullRect().left() == 1); |
1345 REPORTER_ASSERT(r, deserializedPicture->cullRect().top() == 2); | 1347 REPORTER_ASSERT(r, deserializedPicture->cullRect().top() == 2); |
1346 REPORTER_ASSERT(r, deserializedPicture->cullRect().right() == 3); | 1348 REPORTER_ASSERT(r, deserializedPicture->cullRect().right() == 3); |
1347 REPORTER_ASSERT(r, deserializedPicture->cullRect().bottom() == 4); | 1349 REPORTER_ASSERT(r, deserializedPicture->cullRect().bottom() == 4); |
1348 } | 1350 } |
| 1351 |
| 1352 DEF_TEST(PictureGpuAnalyzer, r) { |
| 1353 SkPictureRecorder recorder; |
| 1354 |
| 1355 { |
| 1356 SkCanvas* canvas = recorder.beginRecording(10, 10); |
| 1357 SkPaint paint; |
| 1358 SkScalar intervals [] = { 10, 20 }; |
| 1359 paint.setPathEffect(SkDashPathEffect::Make(intervals, 2, 25)); |
| 1360 |
| 1361 for (int i = 0; i < 50; ++i) { |
| 1362 canvas->drawRect(SkRect::MakeWH(10, 10), paint); |
| 1363 } |
| 1364 } |
| 1365 sk_sp<SkPicture> vetoPicture(recorder.finishRecordingAsPicture()); |
| 1366 |
| 1367 SkPictureGpuAnalyzer analyzer; |
| 1368 REPORTER_ASSERT(r, analyzer.suitableForGpuRasterization(nullptr)); |
| 1369 |
| 1370 analyzer.analyze(vetoPicture.get()); |
| 1371 REPORTER_ASSERT(r, !analyzer.suitableForGpuRasterization(nullptr)); |
| 1372 |
| 1373 analyzer.reset(); |
| 1374 REPORTER_ASSERT(r, analyzer.suitableForGpuRasterization(nullptr)); |
| 1375 |
| 1376 recorder.beginRecording(10, 10)->drawPicture(vetoPicture); |
| 1377 sk_sp<SkPicture> nestedVetoPicture(recorder.finishRecordingAsPicture()); |
| 1378 |
| 1379 analyzer.analyze(nestedVetoPicture.get()); |
| 1380 REPORTER_ASSERT(r, !analyzer.suitableForGpuRasterization(nullptr)); |
| 1381 } |
OLD | NEW |