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" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 | 47 |
48 // For a while willPlayBackBitmaps() ignored SkImages and just looked for SkBitm
aps. | 48 // For a while willPlayBackBitmaps() ignored SkImages and just looked for SkBitm
aps. |
49 static void test_images_are_found_by_willPlayBackBitmaps(skiatest::Reporter* rep
orter) { | 49 static void test_images_are_found_by_willPlayBackBitmaps(skiatest::Reporter* rep
orter) { |
50 // We just need _some_ SkImage | 50 // We just need _some_ SkImage |
51 const SkPMColor pixel = 0; | 51 const SkPMColor pixel = 0; |
52 const SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1); | 52 const SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1); |
53 sk_sp<SkImage> image(SkImage::MakeRasterCopy(SkPixmap(info, &pixel, sizeof(p
ixel)))); | 53 sk_sp<SkImage> image(SkImage::MakeRasterCopy(SkPixmap(info, &pixel, sizeof(p
ixel)))); |
54 | 54 |
55 SkPictureRecorder recorder; | 55 SkPictureRecorder recorder; |
56 recorder.beginRecording(100,100)->drawImage(image, 0,0); | 56 recorder.beginRecording(100,100)->drawImage(image, 0,0); |
57 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 57 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); |
58 | 58 |
59 REPORTER_ASSERT(reporter, picture->willPlayBackBitmaps()); | 59 REPORTER_ASSERT(reporter, picture->willPlayBackBitmaps()); |
60 } | 60 } |
61 | 61 |
62 /* Hit a few SkPicture::Analysis cases not handled elsewhere. */ | 62 /* Hit a few SkPicture::Analysis cases not handled elsewhere. */ |
63 static void test_analysis(skiatest::Reporter* reporter) { | 63 static void test_analysis(skiatest::Reporter* reporter) { |
64 SkPictureRecorder recorder; | 64 SkPictureRecorder recorder; |
65 | 65 |
66 SkCanvas* canvas = recorder.beginRecording(100, 100); | 66 SkCanvas* canvas = recorder.beginRecording(100, 100); |
67 { | 67 { |
68 canvas->drawRect(SkRect::MakeWH(10, 10), SkPaint ()); | 68 canvas->drawRect(SkRect::MakeWH(10, 10), SkPaint ()); |
69 } | 69 } |
70 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 70 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); |
71 REPORTER_ASSERT(reporter, !picture->willPlayBackBitmaps()); | 71 REPORTER_ASSERT(reporter, !picture->willPlayBackBitmaps()); |
72 | 72 |
73 canvas = recorder.beginRecording(100, 100); | 73 canvas = recorder.beginRecording(100, 100); |
74 { | 74 { |
75 SkPaint paint; | 75 SkPaint paint; |
76 // CreateBitmapShader is too smart for us; an empty (or 1x1) bitmap shad
er | 76 // CreateBitmapShader is too smart for us; an empty (or 1x1) bitmap shad
er |
77 // gets optimized into a non-bitmap form, so we create a 2x2 bitmap here
. | 77 // gets optimized into a non-bitmap form, so we create a 2x2 bitmap here
. |
78 SkBitmap bitmap; | 78 SkBitmap bitmap; |
79 bitmap.allocPixels(SkImageInfo::MakeN32Premul(2, 2)); | 79 bitmap.allocPixels(SkImageInfo::MakeN32Premul(2, 2)); |
80 bitmap.eraseColor(SK_ColorBLUE); | 80 bitmap.eraseColor(SK_ColorBLUE); |
81 *(bitmap.getAddr32(0, 0)) = SK_ColorGREEN; | 81 *(bitmap.getAddr32(0, 0)) = SK_ColorGREEN; |
82 paint.setShader(SkShader::MakeBitmapShader(bitmap, SkShader::kClamp_Tile
Mode, | 82 paint.setShader(SkShader::MakeBitmapShader(bitmap, SkShader::kClamp_Tile
Mode, |
83 SkShader::kClamp_TileMode)); | 83 SkShader::kClamp_TileMode)); |
84 REPORTER_ASSERT(reporter, paint.getShader()->isABitmap()); | 84 REPORTER_ASSERT(reporter, paint.getShader()->isABitmap()); |
85 | 85 |
86 canvas->drawRect(SkRect::MakeWH(10, 10), paint); | 86 canvas->drawRect(SkRect::MakeWH(10, 10), paint); |
87 } | 87 } |
88 picture.reset(recorder.endRecording()); | 88 REPORTER_ASSERT(reporter, recorder.finishRecordingAsPicture()->willPlayBackB
itmaps()); |
89 REPORTER_ASSERT(reporter, picture->willPlayBackBitmaps()); | |
90 } | 89 } |
91 | 90 |
92 | 91 |
93 #ifdef SK_DEBUG | 92 #ifdef SK_DEBUG |
94 // Ensure that deleting an empty SkPicture does not assert. Asserts only fire | 93 // Ensure that deleting an empty SkPicture does not assert. Asserts only fire |
95 // in debug mode, so only run in debug mode. | 94 // in debug mode, so only run in debug mode. |
96 static void test_deleting_empty_picture() { | 95 static void test_deleting_empty_picture() { |
97 SkPictureRecorder recorder; | 96 SkPictureRecorder recorder; |
98 // Creates an SkPictureRecord | 97 // Creates an SkPictureRecord |
99 recorder.beginRecording(0, 0); | 98 recorder.beginRecording(0, 0); |
100 // Turns that into an SkPicture | 99 // Turns that into an SkPicture |
101 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 100 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); |
102 // Ceates a new SkPictureRecord | 101 // Ceates a new SkPictureRecord |
103 recorder.beginRecording(0, 0); | 102 recorder.beginRecording(0, 0); |
104 } | 103 } |
105 | 104 |
106 // Ensure that serializing an empty picture does not assert. Likewise only runs
in debug mode. | 105 // Ensure that serializing an empty picture does not assert. Likewise only runs
in debug mode. |
107 static void test_serializing_empty_picture() { | 106 static void test_serializing_empty_picture() { |
108 SkPictureRecorder recorder; | 107 SkPictureRecorder recorder; |
109 recorder.beginRecording(0, 0); | 108 recorder.beginRecording(0, 0); |
110 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 109 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); |
111 SkDynamicMemoryWStream stream; | 110 SkDynamicMemoryWStream stream; |
112 picture->serialize(&stream); | 111 picture->serialize(&stream); |
113 } | 112 } |
114 #endif | 113 #endif |
115 | 114 |
116 static void rand_op(SkCanvas* canvas, SkRandom& rand) { | 115 static void rand_op(SkCanvas* canvas, SkRandom& rand) { |
117 SkPaint paint; | 116 SkPaint paint; |
118 SkRect rect = SkRect::MakeWH(50, 50); | 117 SkRect rect = SkRect::MakeWH(50, 50); |
119 | 118 |
120 SkScalar unit = rand.nextUScalar1(); | 119 SkScalar unit = rand.nextUScalar1(); |
(...skipping 27 matching lines...) Expand all Loading... |
148 SkAutoTUnref<SkPathEffect> dash(SkDashPathEffect::Create(intervals, 2, 0
)); | 147 SkAutoTUnref<SkPathEffect> dash(SkDashPathEffect::Create(intervals, 2, 0
)); |
149 | 148 |
150 SkPaint paint; | 149 SkPaint paint; |
151 paint.setStyle(SkPaint::kStroke_Style); | 150 paint.setStyle(SkPaint::kStroke_Style); |
152 paint.setPathEffect(dash); | 151 paint.setPathEffect(dash); |
153 | 152 |
154 for (int i = 0; i < 50; ++i) { | 153 for (int i = 0; i < 50; ++i) { |
155 canvas->drawPath(path, paint); | 154 canvas->drawPath(path, paint); |
156 } | 155 } |
157 } | 156 } |
158 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 157 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); |
159 // path effects currently render an SkPicture undesireable for GPU rendering | 158 // path effects currently render an SkPicture undesireable for GPU rendering |
160 | 159 |
161 const char *reason = nullptr; | 160 const char *reason = nullptr; |
162 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(nullptr, &re
ason)); | 161 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(nullptr, &re
ason)); |
163 REPORTER_ASSERT(reporter, reason); | 162 REPORTER_ASSERT(reporter, reason); |
164 | 163 |
165 canvas = recorder.beginRecording(100, 100); | 164 canvas = recorder.beginRecording(100, 100); |
166 { | 165 { |
167 SkPath path; | 166 SkPath path; |
168 | 167 |
169 path.moveTo(0, 0); | 168 path.moveTo(0, 0); |
170 path.lineTo(0, 50); | 169 path.lineTo(0, 50); |
171 path.lineTo(25, 25); | 170 path.lineTo(25, 25); |
172 path.lineTo(50, 50); | 171 path.lineTo(50, 50); |
173 path.lineTo(50, 0); | 172 path.lineTo(50, 0); |
174 path.close(); | 173 path.close(); |
175 REPORTER_ASSERT(reporter, !path.isConvex()); | 174 REPORTER_ASSERT(reporter, !path.isConvex()); |
176 | 175 |
177 SkPaint paint; | 176 SkPaint paint; |
178 paint.setAntiAlias(true); | 177 paint.setAntiAlias(true); |
179 for (int i = 0; i < 50; ++i) { | 178 for (int i = 0; i < 50; ++i) { |
180 canvas->drawPath(path, paint); | 179 canvas->drawPath(path, paint); |
181 } | 180 } |
182 } | 181 } |
183 picture.reset(recorder.endRecording()); | 182 picture = recorder.finishRecordingAsPicture(); |
184 // A lot of small AA concave paths should be fine for GPU rendering | 183 // A lot of small AA concave paths should be fine for GPU rendering |
185 REPORTER_ASSERT(reporter, picture->suitableForGpuRasterization(nullptr)); | 184 REPORTER_ASSERT(reporter, picture->suitableForGpuRasterization(nullptr)); |
186 | 185 |
187 canvas = recorder.beginRecording(100, 100); | 186 canvas = recorder.beginRecording(100, 100); |
188 { | 187 { |
189 SkPath path; | 188 SkPath path; |
190 | 189 |
191 path.moveTo(0, 0); | 190 path.moveTo(0, 0); |
192 path.lineTo(0, 100); | 191 path.lineTo(0, 100); |
193 path.lineTo(50, 50); | 192 path.lineTo(50, 50); |
194 path.lineTo(100, 100); | 193 path.lineTo(100, 100); |
195 path.lineTo(100, 0); | 194 path.lineTo(100, 0); |
196 path.close(); | 195 path.close(); |
197 REPORTER_ASSERT(reporter, !path.isConvex()); | 196 REPORTER_ASSERT(reporter, !path.isConvex()); |
198 | 197 |
199 SkPaint paint; | 198 SkPaint paint; |
200 paint.setAntiAlias(true); | 199 paint.setAntiAlias(true); |
201 for (int i = 0; i < 50; ++i) { | 200 for (int i = 0; i < 50; ++i) { |
202 canvas->drawPath(path, paint); | 201 canvas->drawPath(path, paint); |
203 } | 202 } |
204 } | 203 } |
205 picture.reset(recorder.endRecording()); | 204 picture = recorder.finishRecordingAsPicture(); |
206 // A lot of large AA concave paths currently render an SkPicture undesireabl
e for GPU rendering | 205 // A lot of large AA concave paths currently render an SkPicture undesireabl
e for GPU rendering |
207 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(nullptr)); | 206 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(nullptr)); |
208 | 207 |
209 canvas = recorder.beginRecording(100, 100); | 208 canvas = recorder.beginRecording(100, 100); |
210 { | 209 { |
211 SkPath path; | 210 SkPath path; |
212 | 211 |
213 path.moveTo(0, 0); | 212 path.moveTo(0, 0); |
214 path.lineTo(0, 50); | 213 path.lineTo(0, 50); |
215 path.lineTo(25, 25); | 214 path.lineTo(25, 25); |
216 path.lineTo(50, 50); | 215 path.lineTo(50, 50); |
217 path.lineTo(50, 0); | 216 path.lineTo(50, 0); |
218 path.close(); | 217 path.close(); |
219 REPORTER_ASSERT(reporter, !path.isConvex()); | 218 REPORTER_ASSERT(reporter, !path.isConvex()); |
220 | 219 |
221 SkPaint paint; | 220 SkPaint paint; |
222 paint.setAntiAlias(true); | 221 paint.setAntiAlias(true); |
223 paint.setStyle(SkPaint::kStroke_Style); | 222 paint.setStyle(SkPaint::kStroke_Style); |
224 paint.setStrokeWidth(0); | 223 paint.setStrokeWidth(0); |
225 for (int i = 0; i < 50; ++i) { | 224 for (int i = 0; i < 50; ++i) { |
226 canvas->drawPath(path, paint); | 225 canvas->drawPath(path, paint); |
227 } | 226 } |
228 } | 227 } |
229 picture.reset(recorder.endRecording()); | 228 picture = recorder.finishRecordingAsPicture(); |
230 // hairline stroked AA concave paths are fine for GPU rendering | 229 // hairline stroked AA concave paths are fine for GPU rendering |
231 REPORTER_ASSERT(reporter, picture->suitableForGpuRasterization(nullptr)); | 230 REPORTER_ASSERT(reporter, picture->suitableForGpuRasterization(nullptr)); |
232 | 231 |
233 canvas = recorder.beginRecording(100, 100); | 232 canvas = recorder.beginRecording(100, 100); |
234 { | 233 { |
235 SkPaint paint; | 234 SkPaint paint; |
236 SkScalar intervals [] = { 10, 20 }; | 235 SkScalar intervals [] = { 10, 20 }; |
237 SkPathEffect* pe = SkDashPathEffect::Create(intervals, 2, 25); | 236 SkPathEffect* pe = SkDashPathEffect::Create(intervals, 2, 25); |
238 paint.setPathEffect(pe)->unref(); | 237 paint.setPathEffect(pe)->unref(); |
239 | 238 |
240 SkPoint points [2] = { { 0, 0 }, { 100, 0 } }; | 239 SkPoint points [2] = { { 0, 0 }, { 100, 0 } }; |
241 | 240 |
242 for (int i = 0; i < 50; ++i) { | 241 for (int i = 0; i < 50; ++i) { |
243 canvas->drawPoints(SkCanvas::kLines_PointMode, 2, points, paint); | 242 canvas->drawPoints(SkCanvas::kLines_PointMode, 2, points, paint); |
244 } | 243 } |
245 } | 244 } |
246 picture.reset(recorder.endRecording()); | 245 picture = recorder.finishRecordingAsPicture(); |
247 // fast-path dashed effects are fine for GPU rendering ... | 246 // fast-path dashed effects are fine for GPU rendering ... |
248 REPORTER_ASSERT(reporter, picture->suitableForGpuRasterization(nullptr)); | 247 REPORTER_ASSERT(reporter, picture->suitableForGpuRasterization(nullptr)); |
249 | 248 |
250 canvas = recorder.beginRecording(100, 100); | 249 canvas = recorder.beginRecording(100, 100); |
251 { | 250 { |
252 SkPaint paint; | 251 SkPaint paint; |
253 SkScalar intervals [] = { 10, 20 }; | 252 SkScalar intervals [] = { 10, 20 }; |
254 SkPathEffect* pe = SkDashPathEffect::Create(intervals, 2, 25); | 253 SkPathEffect* pe = SkDashPathEffect::Create(intervals, 2, 25); |
255 paint.setPathEffect(pe)->unref(); | 254 paint.setPathEffect(pe)->unref(); |
256 | 255 |
257 for (int i = 0; i < 50; ++i) { | 256 for (int i = 0; i < 50; ++i) { |
258 canvas->drawRect(SkRect::MakeWH(10, 10), paint); | 257 canvas->drawRect(SkRect::MakeWH(10, 10), paint); |
259 } | 258 } |
260 } | 259 } |
261 picture.reset(recorder.endRecording()); | 260 picture = recorder.finishRecordingAsPicture(); |
262 // ... but only when applied to drawPoint() calls | 261 // ... but only when applied to drawPoint() calls |
263 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(nullptr)); | 262 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(nullptr)); |
264 | 263 |
265 // Nest the previous picture inside a new one. | 264 // Nest the previous picture inside a new one. |
266 canvas = recorder.beginRecording(100, 100); | 265 canvas = recorder.beginRecording(100, 100); |
267 { | 266 { |
268 canvas->drawPicture(picture.get()); | 267 canvas->drawPicture(picture.get()); |
269 } | 268 } |
270 picture.reset(recorder.endRecording()); | 269 picture = recorder.finishRecordingAsPicture(); |
271 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(nullptr)); | 270 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(nullptr)); |
272 } | 271 } |
273 | 272 |
274 #endif | 273 #endif |
275 | 274 |
276 static void test_savelayer_extraction(skiatest::Reporter* reporter) { | 275 static void test_savelayer_extraction(skiatest::Reporter* reporter) { |
277 static const int kWidth = 100; | 276 static const int kWidth = 100; |
278 static const int kHeight = 100; | 277 static const int kHeight = 100; |
279 | 278 |
280 // Create complex paint that the bounding box computation code can't | 279 // Create complex paint that the bounding box computation code can't |
281 // optimize away | 280 // optimize away |
282 SkScalar blueToRedMatrix[20] = { 0 }; | 281 SkScalar blueToRedMatrix[20] = { 0 }; |
283 blueToRedMatrix[2] = blueToRedMatrix[18] = SK_Scalar1; | 282 blueToRedMatrix[2] = blueToRedMatrix[18] = SK_Scalar1; |
284 SkAutoTUnref<SkColorFilter> blueToRed(SkColorMatrixFilter::Create(blueToRedM
atrix)); | 283 SkAutoTUnref<SkColorFilter> blueToRed(SkColorMatrixFilter::Create(blueToRedM
atrix)); |
285 SkAutoTUnref<SkImageFilter> filter(SkColorFilterImageFilter::Create(blueToRe
d.get())); | 284 SkAutoTUnref<SkImageFilter> filter(SkColorFilterImageFilter::Create(blueToRe
d.get())); |
286 | 285 |
287 SkPaint complexPaint; | 286 SkPaint complexPaint; |
288 complexPaint.setImageFilter(filter); | 287 complexPaint.setImageFilter(filter); |
289 | 288 |
290 SkAutoTUnref<SkPicture> pict, child; | 289 sk_sp<SkPicture> pict, child; |
291 SkRTreeFactory bbhFactory; | 290 SkRTreeFactory bbhFactory; |
292 | 291 |
293 { | 292 { |
294 SkPictureRecorder recorder; | 293 SkPictureRecorder recorder; |
295 | 294 |
296 SkCanvas* c = recorder.beginRecording(SkIntToScalar(kWidth), SkIntToScal
ar(kHeight), | 295 SkCanvas* c = recorder.beginRecording(SkIntToScalar(kWidth), SkIntToScal
ar(kHeight), |
297 &bbhFactory, | 296 &bbhFactory, |
298 SkPictureRecorder::kComputeSaveLay
erInfo_RecordFlag); | 297 SkPictureRecorder::kComputeSaveLay
erInfo_RecordFlag); |
299 | 298 |
300 c->saveLayer(nullptr, &complexPaint); | 299 c->saveLayer(nullptr, &complexPaint); |
301 c->restore(); | 300 c->restore(); |
302 | 301 |
303 child.reset(recorder.endRecording()); | 302 child = recorder.finishRecordingAsPicture(); |
304 } | 303 } |
305 | 304 |
306 // create a picture with the structure: | 305 // create a picture with the structure: |
307 // 1) | 306 // 1) |
308 // SaveLayer | 307 // SaveLayer |
309 // Restore | 308 // Restore |
310 // 2) | 309 // 2) |
311 // SaveLayer | 310 // SaveLayer |
312 // Translate | 311 // Translate |
313 // SaveLayer w/ bound | 312 // SaveLayer w/ bound |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 { | 360 { |
362 SkPaint picturePaint; | 361 SkPaint picturePaint; |
363 SkMatrix trans; | 362 SkMatrix trans; |
364 trans.setTranslate(10, 10); | 363 trans.setTranslate(10, 10); |
365 | 364 |
366 c->saveLayer(nullptr, &layerPaint); // layer #6 | 365 c->saveLayer(nullptr, &layerPaint); // layer #6 |
367 c->drawPicture(child, &trans, &picturePaint); // layer #7 inside
picture | 366 c->drawPicture(child, &trans, &picturePaint); // layer #7 inside
picture |
368 c->restore(); | 367 c->restore(); |
369 } | 368 } |
370 | 369 |
371 pict.reset(recorder.endRecording()); | 370 pict = recorder.finishRecordingAsPicture(); |
372 } | 371 } |
373 | 372 |
374 // Now test out the SaveLayer extraction | 373 // Now test out the SaveLayer extraction |
375 if (!SkCanvas::Internal_Private_GetIgnoreSaveLayerBounds()) { | 374 if (!SkCanvas::Internal_Private_GetIgnoreSaveLayerBounds()) { |
376 const SkBigPicture* bp = pict->asSkBigPicture(); | 375 const SkBigPicture* bp = pict->asSkBigPicture(); |
377 REPORTER_ASSERT(reporter, bp); | 376 REPORTER_ASSERT(reporter, bp); |
378 | 377 |
379 const SkBigPicture::AccelData* data = bp->accelData(); | 378 const SkBigPicture::AccelData* data = bp->accelData(); |
380 REPORTER_ASSERT(reporter, data); | 379 REPORTER_ASSERT(reporter, data); |
381 | 380 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 REPORTER_ASSERT(reporter, nullptr == info4.fPicture); | 438 REPORTER_ASSERT(reporter, nullptr == info4.fPicture); |
440 REPORTER_ASSERT(reporter, kWidth == info4.fBounds.width() && | 439 REPORTER_ASSERT(reporter, kWidth == info4.fBounds.width() && |
441 kHeight == info4.fBounds.height()); | 440 kHeight == info4.fBounds.height()); |
442 REPORTER_ASSERT(reporter, 0 == info4.fBounds.fLeft && 0 == info4.fBounds
.fTop); | 441 REPORTER_ASSERT(reporter, 0 == info4.fBounds.fLeft && 0 == info4.fBounds
.fTop); |
443 REPORTER_ASSERT(reporter, info4.fLocalMat.isIdentity()); | 442 REPORTER_ASSERT(reporter, info4.fLocalMat.isIdentity()); |
444 REPORTER_ASSERT(reporter, info4.fPreMat.isIdentity()); | 443 REPORTER_ASSERT(reporter, info4.fPreMat.isIdentity()); |
445 REPORTER_ASSERT(reporter, info4.fPaint); | 444 REPORTER_ASSERT(reporter, info4.fPaint); |
446 REPORTER_ASSERT(reporter, !info4.fIsNested && | 445 REPORTER_ASSERT(reporter, !info4.fIsNested && |
447 info4.fHasNestedLayers); // has a nested SL | 446 info4.fHasNestedLayers); // has a nested SL |
448 | 447 |
449 REPORTER_ASSERT(reporter, child == info5.fPicture); // in a child pictur
e | 448 REPORTER_ASSERT(reporter, child.get() == info5.fPicture); // in a child
picture |
450 REPORTER_ASSERT(reporter, kWidth == info5.fBounds.width() && | 449 REPORTER_ASSERT(reporter, kWidth == info5.fBounds.width() && |
451 kHeight == info5.fBounds.height()); | 450 kHeight == info5.fBounds.height()); |
452 REPORTER_ASSERT(reporter, 0 == info5.fBounds.fLeft && 0 == info5.fBounds
.fTop); | 451 REPORTER_ASSERT(reporter, 0 == info5.fBounds.fLeft && 0 == info5.fBounds
.fTop); |
453 REPORTER_ASSERT(reporter, info5.fLocalMat.isIdentity()); | 452 REPORTER_ASSERT(reporter, info5.fLocalMat.isIdentity()); |
454 REPORTER_ASSERT(reporter, info5.fPreMat.isIdentity()); | 453 REPORTER_ASSERT(reporter, info5.fPreMat.isIdentity()); |
455 REPORTER_ASSERT(reporter, nullptr != info5.fPaint); | 454 REPORTER_ASSERT(reporter, nullptr != info5.fPaint); |
456 REPORTER_ASSERT(reporter, info5.fIsNested && !info5.fHasNestedLayers); /
/ is nested | 455 REPORTER_ASSERT(reporter, info5.fIsNested && !info5.fHasNestedLayers); /
/ is nested |
457 | 456 |
458 REPORTER_ASSERT(reporter, nullptr == info6.fPicture); | 457 REPORTER_ASSERT(reporter, nullptr == info6.fPicture); |
459 REPORTER_ASSERT(reporter, kWidth-10 == info6.fBounds.width() && | 458 REPORTER_ASSERT(reporter, kWidth-10 == info6.fBounds.width() && |
460 kHeight-10 == info6.fBounds.height()); | 459 kHeight-10 == info6.fBounds.height()); |
461 REPORTER_ASSERT(reporter, 10 == info6.fBounds.fLeft && 10 == info6.fBoun
ds.fTop); | 460 REPORTER_ASSERT(reporter, 10 == info6.fBounds.fLeft && 10 == info6.fBoun
ds.fTop); |
462 REPORTER_ASSERT(reporter, info6.fLocalMat.isIdentity()); | 461 REPORTER_ASSERT(reporter, info6.fLocalMat.isIdentity()); |
463 REPORTER_ASSERT(reporter, info6.fPreMat.isIdentity()); | 462 REPORTER_ASSERT(reporter, info6.fPreMat.isIdentity()); |
464 REPORTER_ASSERT(reporter, info6.fPaint); | 463 REPORTER_ASSERT(reporter, info6.fPaint); |
465 REPORTER_ASSERT(reporter, !info6.fIsNested && | 464 REPORTER_ASSERT(reporter, !info6.fIsNested && |
466 info6.fHasNestedLayers); // has a nested SL | 465 info6.fHasNestedLayers); // has a nested SL |
467 | 466 |
468 REPORTER_ASSERT(reporter, child == info7.fPicture); // in a child pictur
e | 467 REPORTER_ASSERT(reporter, child.get() == info7.fPicture); // in a child
picture |
469 REPORTER_ASSERT(reporter, kWidth == info7.fBounds.width() && | 468 REPORTER_ASSERT(reporter, kWidth == info7.fBounds.width() && |
470 kHeight == info7.fBounds.height()); | 469 kHeight == info7.fBounds.height()); |
471 REPORTER_ASSERT(reporter, 0 == info7.fBounds.fLeft && 0 == info7.fBounds
.fTop); | 470 REPORTER_ASSERT(reporter, 0 == info7.fBounds.fLeft && 0 == info7.fBounds
.fTop); |
472 REPORTER_ASSERT(reporter, info7.fLocalMat.isIdentity()); | 471 REPORTER_ASSERT(reporter, info7.fLocalMat.isIdentity()); |
473 REPORTER_ASSERT(reporter, info7.fPreMat.isIdentity()); | 472 REPORTER_ASSERT(reporter, info7.fPreMat.isIdentity()); |
474 REPORTER_ASSERT(reporter, nullptr != info7.fPaint); | 473 REPORTER_ASSERT(reporter, nullptr != info7.fPaint); |
475 REPORTER_ASSERT(reporter, info7.fIsNested && !info7.fHasNestedLayers); /
/ is nested | 474 REPORTER_ASSERT(reporter, info7.fIsNested && !info7.fHasNestedLayers); /
/ is nested |
476 } | 475 } |
477 } | 476 } |
478 | 477 |
479 static void test_has_text(skiatest::Reporter* reporter) { | 478 static void test_has_text(skiatest::Reporter* reporter) { |
480 SkPictureRecorder recorder; | 479 SkPictureRecorder recorder; |
481 | 480 |
482 SkCanvas* canvas = recorder.beginRecording(100,100); | 481 SkCanvas* canvas = recorder.beginRecording(100,100); |
483 { | 482 { |
484 canvas->drawRect(SkRect::MakeWH(20, 20), SkPaint()); | 483 canvas->drawRect(SkRect::MakeWH(20, 20), SkPaint()); |
485 } | 484 } |
486 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 485 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); |
487 REPORTER_ASSERT(reporter, !picture->hasText()); | 486 REPORTER_ASSERT(reporter, !picture->hasText()); |
488 | 487 |
489 SkPoint point = SkPoint::Make(10, 10); | 488 SkPoint point = SkPoint::Make(10, 10); |
490 canvas = recorder.beginRecording(100,100); | 489 canvas = recorder.beginRecording(100,100); |
491 { | 490 { |
492 canvas->drawText("Q", 1, point.fX, point.fY, SkPaint()); | 491 canvas->drawText("Q", 1, point.fX, point.fY, SkPaint()); |
493 } | 492 } |
494 picture.reset(recorder.endRecording()); | 493 picture = recorder.finishRecordingAsPicture(); |
495 REPORTER_ASSERT(reporter, picture->hasText()); | 494 REPORTER_ASSERT(reporter, picture->hasText()); |
496 | 495 |
497 canvas = recorder.beginRecording(100,100); | 496 canvas = recorder.beginRecording(100,100); |
498 { | 497 { |
499 canvas->drawPosText("Q", 1, &point, SkPaint()); | 498 canvas->drawPosText("Q", 1, &point, SkPaint()); |
500 } | 499 } |
501 picture.reset(recorder.endRecording()); | 500 picture = recorder.finishRecordingAsPicture(); |
502 REPORTER_ASSERT(reporter, picture->hasText()); | 501 REPORTER_ASSERT(reporter, picture->hasText()); |
503 | 502 |
504 canvas = recorder.beginRecording(100,100); | 503 canvas = recorder.beginRecording(100,100); |
505 { | 504 { |
506 canvas->drawPosTextH("Q", 1, &point.fX, point.fY, SkPaint()); | 505 canvas->drawPosTextH("Q", 1, &point.fX, point.fY, SkPaint()); |
507 } | 506 } |
508 picture.reset(recorder.endRecording()); | 507 picture = recorder.finishRecordingAsPicture(); |
509 REPORTER_ASSERT(reporter, picture->hasText()); | 508 REPORTER_ASSERT(reporter, picture->hasText()); |
510 | 509 |
511 canvas = recorder.beginRecording(100,100); | 510 canvas = recorder.beginRecording(100,100); |
512 { | 511 { |
513 SkPath path; | 512 SkPath path; |
514 path.moveTo(0, 0); | 513 path.moveTo(0, 0); |
515 path.lineTo(50, 50); | 514 path.lineTo(50, 50); |
516 | 515 |
517 canvas->drawTextOnPathHV("Q", 1, path, point.fX, point.fY, SkPaint()); | 516 canvas->drawTextOnPathHV("Q", 1, path, point.fX, point.fY, SkPaint()); |
518 } | 517 } |
519 picture.reset(recorder.endRecording()); | 518 picture = recorder.finishRecordingAsPicture(); |
520 REPORTER_ASSERT(reporter, picture->hasText()); | 519 REPORTER_ASSERT(reporter, picture->hasText()); |
521 | 520 |
522 canvas = recorder.beginRecording(100,100); | 521 canvas = recorder.beginRecording(100,100); |
523 { | 522 { |
524 SkPath path; | 523 SkPath path; |
525 path.moveTo(0, 0); | 524 path.moveTo(0, 0); |
526 path.lineTo(50, 50); | 525 path.lineTo(50, 50); |
527 | 526 |
528 canvas->drawTextOnPath("Q", 1, path, nullptr, SkPaint()); | 527 canvas->drawTextOnPath("Q", 1, path, nullptr, SkPaint()); |
529 } | 528 } |
530 picture.reset(recorder.endRecording()); | 529 picture = recorder.finishRecordingAsPicture(); |
531 REPORTER_ASSERT(reporter, picture->hasText()); | 530 REPORTER_ASSERT(reporter, picture->hasText()); |
532 | 531 |
533 // Nest the previous picture inside a new one. | 532 // Nest the previous picture inside a new one. |
534 canvas = recorder.beginRecording(100,100); | 533 canvas = recorder.beginRecording(100,100); |
535 { | 534 { |
536 canvas->drawPicture(picture.get()); | 535 canvas->drawPicture(picture.get()); |
537 } | 536 } |
538 picture.reset(recorder.endRecording()); | 537 picture = recorder.finishRecordingAsPicture(); |
539 REPORTER_ASSERT(reporter, picture->hasText()); | 538 REPORTER_ASSERT(reporter, picture->hasText()); |
540 } | 539 } |
541 | 540 |
542 static void set_canvas_to_save_count_4(SkCanvas* canvas) { | 541 static void set_canvas_to_save_count_4(SkCanvas* canvas) { |
543 canvas->restoreToCount(1); | 542 canvas->restoreToCount(1); |
544 canvas->save(); | 543 canvas->save(); |
545 canvas->save(); | 544 canvas->save(); |
546 canvas->save(); | 545 canvas->save(); |
547 } | 546 } |
548 | 547 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 // so expect to have seen no more than num{Saves,SaveLayers,Restores}. | 596 // so expect to have seen no more than num{Saves,SaveLayers,Restores}. |
598 REPORTER_ASSERT(reporter, numSaves >= canvas.getSaveCount()); | 597 REPORTER_ASSERT(reporter, numSaves >= canvas.getSaveCount()); |
599 REPORTER_ASSERT(reporter, numSaveLayers >= canvas.getSaveLayerCount()); | 598 REPORTER_ASSERT(reporter, numSaveLayers >= canvas.getSaveLayerCount()); |
600 REPORTER_ASSERT(reporter, numRestores >= canvas.getRestoreCount()); | 599 REPORTER_ASSERT(reporter, numRestores >= canvas.getRestoreCount()); |
601 } | 600 } |
602 | 601 |
603 // This class exists so SkPicture can friend it and give it access to | 602 // This class exists so SkPicture can friend it and give it access to |
604 // the 'partialReplay' method. | 603 // the 'partialReplay' method. |
605 class SkPictureRecorderReplayTester { | 604 class SkPictureRecorderReplayTester { |
606 public: | 605 public: |
607 static SkPicture* Copy(SkPictureRecorder* recorder) { | 606 static sk_sp<SkPicture> Copy(SkPictureRecorder* recorder) { |
608 SkPictureRecorder recorder2; | 607 SkPictureRecorder recorder2; |
609 | 608 |
610 SkCanvas* canvas = recorder2.beginRecording(10, 10); | 609 SkCanvas* canvas = recorder2.beginRecording(10, 10); |
611 | 610 |
612 recorder->partialReplay(canvas); | 611 recorder->partialReplay(canvas); |
613 | 612 |
614 return recorder2.endRecording(); | 613 return recorder2.finishRecordingAsPicture(); |
615 } | 614 } |
616 }; | 615 }; |
617 | 616 |
618 static void create_imbalance(SkCanvas* canvas) { | 617 static void create_imbalance(SkCanvas* canvas) { |
619 SkRect clipRect = SkRect::MakeWH(2, 2); | 618 SkRect clipRect = SkRect::MakeWH(2, 2); |
620 SkRect drawRect = SkRect::MakeWH(10, 10); | 619 SkRect drawRect = SkRect::MakeWH(10, 10); |
621 canvas->save(); | 620 canvas->save(); |
622 canvas->clipRect(clipRect, SkRegion::kReplace_Op); | 621 canvas->clipRect(clipRect, SkRegion::kReplace_Op); |
623 canvas->translate(1.0f, 1.0f); | 622 canvas->translate(1.0f, 1.0f); |
624 SkPaint p; | 623 SkPaint p; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 // Test out SkPictureRecorder::partialReplay | 656 // Test out SkPictureRecorder::partialReplay |
658 DEF_TEST(PictureRecorder_replay, reporter) { | 657 DEF_TEST(PictureRecorder_replay, reporter) { |
659 // check save/saveLayer state | 658 // check save/saveLayer state |
660 { | 659 { |
661 SkPictureRecorder recorder; | 660 SkPictureRecorder recorder; |
662 | 661 |
663 SkCanvas* canvas = recorder.beginRecording(10, 10); | 662 SkCanvas* canvas = recorder.beginRecording(10, 10); |
664 | 663 |
665 canvas->saveLayer(nullptr, nullptr); | 664 canvas->saveLayer(nullptr, nullptr); |
666 | 665 |
667 SkAutoTUnref<SkPicture> copy(SkPictureRecorderReplayTester::Copy(&record
er)); | 666 sk_sp<SkPicture> copy(SkPictureRecorderReplayTester::Copy(&recorder)); |
668 | 667 |
669 // The extra save and restore comes from the Copy process. | 668 // The extra save and restore comes from the Copy process. |
670 check_save_state(reporter, copy, 2, 1, 3); | 669 check_save_state(reporter, copy.get(), 2, 1, 3); |
671 | 670 |
672 canvas->saveLayer(nullptr, nullptr); | 671 canvas->saveLayer(nullptr, nullptr); |
673 | 672 |
674 SkAutoTUnref<SkPicture> final(recorder.endRecording()); | 673 sk_sp<SkPicture> final(recorder.finishRecordingAsPicture()); |
675 | 674 |
676 check_save_state(reporter, final, 1, 2, 3); | 675 check_save_state(reporter, final.get(), 1, 2, 3); |
677 | 676 |
678 // The copy shouldn't pick up any operations added after it was made | 677 // The copy shouldn't pick up any operations added after it was made |
679 check_save_state(reporter, copy, 2, 1, 3); | 678 check_save_state(reporter, copy.get(), 2, 1, 3); |
680 } | 679 } |
681 | 680 |
682 // (partially) check leakage of draw ops | 681 // (partially) check leakage of draw ops |
683 { | 682 { |
684 SkPictureRecorder recorder; | 683 SkPictureRecorder recorder; |
685 | 684 |
686 SkCanvas* canvas = recorder.beginRecording(10, 10); | 685 SkCanvas* canvas = recorder.beginRecording(10, 10); |
687 | 686 |
688 SkRect r = SkRect::MakeWH(5, 5); | 687 SkRect r = SkRect::MakeWH(5, 5); |
689 SkPaint p; | 688 SkPaint p; |
690 | 689 |
691 canvas->drawRect(r, p); | 690 canvas->drawRect(r, p); |
692 | 691 |
693 SkAutoTUnref<SkPicture> copy(SkPictureRecorderReplayTester::Copy(&record
er)); | 692 sk_sp<SkPicture> copy(SkPictureRecorderReplayTester::Copy(&recorder)); |
694 | 693 |
695 REPORTER_ASSERT(reporter, !copy->willPlayBackBitmaps()); | 694 REPORTER_ASSERT(reporter, !copy->willPlayBackBitmaps()); |
696 | 695 |
697 SkBitmap bm; | 696 SkBitmap bm; |
698 make_bm(&bm, 10, 10, SK_ColorRED, true); | 697 make_bm(&bm, 10, 10, SK_ColorRED, true); |
699 | 698 |
700 r.offset(5.0f, 5.0f); | 699 r.offset(5.0f, 5.0f); |
701 canvas->drawBitmapRect(bm, r, nullptr); | 700 canvas->drawBitmapRect(bm, r, nullptr); |
702 | 701 |
703 SkAutoTUnref<SkPicture> final(recorder.endRecording()); | 702 sk_sp<SkPicture> final(recorder.finishRecordingAsPicture()); |
704 REPORTER_ASSERT(reporter, final->willPlayBackBitmaps()); | 703 REPORTER_ASSERT(reporter, final->willPlayBackBitmaps()); |
705 | 704 |
706 REPORTER_ASSERT(reporter, copy->uniqueID() != final->uniqueID()); | 705 REPORTER_ASSERT(reporter, copy->uniqueID() != final->uniqueID()); |
707 | 706 |
708 // The snapshot shouldn't pick up any operations added after it was made | 707 // The snapshot shouldn't pick up any operations added after it was made |
709 REPORTER_ASSERT(reporter, !copy->willPlayBackBitmaps()); | 708 REPORTER_ASSERT(reporter, !copy->willPlayBackBitmaps()); |
710 } | 709 } |
711 | 710 |
712 // Recreate the Android partialReplay test case | 711 // Recreate the Android partialReplay test case |
713 { | 712 { |
714 SkPictureRecorder recorder; | 713 SkPictureRecorder recorder; |
715 | 714 |
716 SkCanvas* canvas = recorder.beginRecording(4, 3, nullptr, 0); | 715 SkCanvas* canvas = recorder.beginRecording(4, 3, nullptr, 0); |
717 create_imbalance(canvas); | 716 create_imbalance(canvas); |
718 | 717 |
719 int expectedSaveCount = canvas->getSaveCount(); | 718 int expectedSaveCount = canvas->getSaveCount(); |
720 | 719 |
721 SkAutoTUnref<SkPicture> copy(SkPictureRecorderReplayTester::Copy(&record
er)); | 720 sk_sp<SkPicture> copy(SkPictureRecorderReplayTester::Copy(&recorder)); |
722 check_balance(reporter, copy); | 721 check_balance(reporter, copy.get()); |
723 | 722 |
724 REPORTER_ASSERT(reporter, expectedSaveCount = canvas->getSaveCount()); | 723 REPORTER_ASSERT(reporter, expectedSaveCount = canvas->getSaveCount()); |
725 | 724 |
726 // End the recording of source to test the picture finalization | 725 // End the recording of source to test the picture finalization |
727 // process isn't complicated by the partialReplay step | 726 // process isn't complicated by the partialReplay step |
728 SkAutoTUnref<SkPicture> final(recorder.endRecording()); | 727 sk_sp<SkPicture> final(recorder.finishRecordingAsPicture()); |
729 } | 728 } |
730 } | 729 } |
731 | 730 |
732 static void test_unbalanced_save_restores(skiatest::Reporter* reporter) { | 731 static void test_unbalanced_save_restores(skiatest::Reporter* reporter) { |
733 SkCanvas testCanvas(100, 100); | 732 SkCanvas testCanvas(100, 100); |
734 set_canvas_to_save_count_4(&testCanvas); | 733 set_canvas_to_save_count_4(&testCanvas); |
735 | 734 |
736 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); | 735 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); |
737 | 736 |
738 SkPaint paint; | 737 SkPaint paint; |
739 SkRect rect = SkRect::MakeLTRB(-10000000, -10000000, 10000000, 10000000); | 738 SkRect rect = SkRect::MakeLTRB(-10000000, -10000000, 10000000, 10000000); |
740 | 739 |
741 SkPictureRecorder recorder; | 740 SkPictureRecorder recorder; |
742 | 741 |
743 { | 742 { |
744 // Create picture with 2 unbalanced saves | 743 // Create picture with 2 unbalanced saves |
745 SkCanvas* canvas = recorder.beginRecording(100, 100); | 744 SkCanvas* canvas = recorder.beginRecording(100, 100); |
746 canvas->save(); | 745 canvas->save(); |
747 canvas->translate(10, 10); | 746 canvas->translate(10, 10); |
748 canvas->drawRect(rect, paint); | 747 canvas->drawRect(rect, paint); |
749 canvas->save(); | 748 canvas->save(); |
750 canvas->translate(10, 10); | 749 canvas->translate(10, 10); |
751 canvas->drawRect(rect, paint); | 750 canvas->drawRect(rect, paint); |
752 SkAutoTUnref<SkPicture> extraSavePicture(recorder.endRecording()); | 751 sk_sp<SkPicture> extraSavePicture(recorder.finishRecordingAsPicture()); |
753 | 752 |
754 testCanvas.drawPicture(extraSavePicture); | 753 testCanvas.drawPicture(extraSavePicture); |
755 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); | 754 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); |
756 } | 755 } |
757 | 756 |
758 set_canvas_to_save_count_4(&testCanvas); | 757 set_canvas_to_save_count_4(&testCanvas); |
759 | 758 |
760 { | 759 { |
761 // Create picture with 2 unbalanced restores | 760 // Create picture with 2 unbalanced restores |
762 SkCanvas* canvas = recorder.beginRecording(100, 100); | 761 SkCanvas* canvas = recorder.beginRecording(100, 100); |
763 canvas->save(); | 762 canvas->save(); |
764 canvas->translate(10, 10); | 763 canvas->translate(10, 10); |
765 canvas->drawRect(rect, paint); | 764 canvas->drawRect(rect, paint); |
766 canvas->save(); | 765 canvas->save(); |
767 canvas->translate(10, 10); | 766 canvas->translate(10, 10); |
768 canvas->drawRect(rect, paint); | 767 canvas->drawRect(rect, paint); |
769 canvas->restore(); | 768 canvas->restore(); |
770 canvas->restore(); | 769 canvas->restore(); |
771 canvas->restore(); | 770 canvas->restore(); |
772 canvas->restore(); | 771 canvas->restore(); |
773 SkAutoTUnref<SkPicture> extraRestorePicture(recorder.endRecording()); | 772 sk_sp<SkPicture> extraRestorePicture(recorder.finishRecordingAsPicture()
); |
774 | 773 |
775 testCanvas.drawPicture(extraRestorePicture); | 774 testCanvas.drawPicture(extraRestorePicture); |
776 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); | 775 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); |
777 } | 776 } |
778 | 777 |
779 set_canvas_to_save_count_4(&testCanvas); | 778 set_canvas_to_save_count_4(&testCanvas); |
780 | 779 |
781 { | 780 { |
782 SkCanvas* canvas = recorder.beginRecording(100, 100); | 781 SkCanvas* canvas = recorder.beginRecording(100, 100); |
783 canvas->translate(10, 10); | 782 canvas->translate(10, 10); |
784 canvas->drawRect(rect, paint); | 783 canvas->drawRect(rect, paint); |
785 SkAutoTUnref<SkPicture> noSavePicture(recorder.endRecording()); | 784 sk_sp<SkPicture> noSavePicture(recorder.finishRecordingAsPicture()); |
786 | 785 |
787 testCanvas.drawPicture(noSavePicture); | 786 testCanvas.drawPicture(noSavePicture); |
788 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); | 787 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); |
789 REPORTER_ASSERT(reporter, testCanvas.getTotalMatrix().isIdentity()); | 788 REPORTER_ASSERT(reporter, testCanvas.getTotalMatrix().isIdentity()); |
790 } | 789 } |
791 } | 790 } |
792 | 791 |
793 static void test_peephole() { | 792 static void test_peephole() { |
794 SkRandom rand; | 793 SkRandom rand; |
795 | 794 |
796 SkPictureRecorder recorder; | 795 SkPictureRecorder recorder; |
797 | 796 |
798 for (int j = 0; j < 100; j++) { | 797 for (int j = 0; j < 100; j++) { |
799 SkRandom rand2(rand); // remember the seed | 798 SkRandom rand2(rand); // remember the seed |
800 | 799 |
801 SkCanvas* canvas = recorder.beginRecording(100, 100); | 800 SkCanvas* canvas = recorder.beginRecording(100, 100); |
802 | 801 |
803 for (int i = 0; i < 1000; ++i) { | 802 for (int i = 0; i < 1000; ++i) { |
804 rand_op(canvas, rand); | 803 rand_op(canvas, rand); |
805 } | 804 } |
806 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 805 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); |
807 | 806 |
808 rand = rand2; | 807 rand = rand2; |
809 } | 808 } |
810 | 809 |
811 { | 810 { |
812 SkCanvas* canvas = recorder.beginRecording(100, 100); | 811 SkCanvas* canvas = recorder.beginRecording(100, 100); |
813 SkRect rect = SkRect::MakeWH(50, 50); | 812 SkRect rect = SkRect::MakeWH(50, 50); |
814 | 813 |
815 for (int i = 0; i < 100; ++i) { | 814 for (int i = 0; i < 100; ++i) { |
816 canvas->save(); | 815 canvas->save(); |
817 } | 816 } |
818 while (canvas->getSaveCount() > 1) { | 817 while (canvas->getSaveCount() > 1) { |
819 canvas->clipRect(rect); | 818 canvas->clipRect(rect); |
820 canvas->restore(); | 819 canvas->restore(); |
821 } | 820 } |
822 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 821 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); |
823 } | 822 } |
824 } | 823 } |
825 | 824 |
826 #ifndef SK_DEBUG | 825 #ifndef SK_DEBUG |
827 // Only test this is in release mode. We deliberately crash in debug mode, since
a valid caller | 826 // Only test this is in release mode. We deliberately crash in debug mode, since
a valid caller |
828 // should never do this. | 827 // should never do this. |
829 static void test_bad_bitmap() { | 828 static void test_bad_bitmap() { |
830 // This bitmap has a width and height but no pixels. As a result, attempting
to record it will | 829 // This bitmap has a width and height but no pixels. As a result, attempting
to record it will |
831 // fail. | 830 // fail. |
832 SkBitmap bm; | 831 SkBitmap bm; |
833 bm.setInfo(SkImageInfo::MakeN32Premul(100, 100)); | 832 bm.setInfo(SkImageInfo::MakeN32Premul(100, 100)); |
834 SkPictureRecorder recorder; | 833 SkPictureRecorder recorder; |
835 SkCanvas* recordingCanvas = recorder.beginRecording(100, 100); | 834 SkCanvas* recordingCanvas = recorder.beginRecording(100, 100); |
836 recordingCanvas->drawBitmap(bm, 0, 0); | 835 recordingCanvas->drawBitmap(bm, 0, 0); |
837 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 836 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); |
838 | 837 |
839 SkCanvas canvas; | 838 SkCanvas canvas; |
840 canvas.drawPicture(picture); | 839 canvas.drawPicture(picture); |
841 } | 840 } |
842 #endif | 841 #endif |
843 | 842 |
844 static SkData* serialized_picture_from_bitmap(const SkBitmap& bitmap) { | 843 static SkData* serialized_picture_from_bitmap(const SkBitmap& bitmap) { |
845 SkPictureRecorder recorder; | 844 SkPictureRecorder recorder; |
846 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(bitmap.width()), | 845 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(bitmap.width()), |
847 SkIntToScalar(bitmap.height())); | 846 SkIntToScalar(bitmap.height())); |
848 canvas->drawBitmap(bitmap, 0, 0); | 847 canvas->drawBitmap(bitmap, 0, 0); |
849 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 848 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); |
850 | 849 |
851 SkDynamicMemoryWStream wStream; | 850 SkDynamicMemoryWStream wStream; |
852 SkAutoTUnref<SkPixelSerializer> serializer( | 851 SkAutoTUnref<SkPixelSerializer> serializer( |
853 SkImageEncoder::CreatePixelSerializer()); | 852 SkImageEncoder::CreatePixelSerializer()); |
854 picture->serialize(&wStream, serializer); | 853 picture->serialize(&wStream, serializer); |
855 return wStream.copyToData(); | 854 return wStream.copyToData(); |
856 } | 855 } |
857 | 856 |
858 struct ErrorContext { | 857 struct ErrorContext { |
859 int fErrors; | 858 int fErrors; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
904 REPORTER_ASSERT(reporter, picture1->equals(picture2)); | 903 REPORTER_ASSERT(reporter, picture1->equals(picture2)); |
905 | 904 |
906 // Now test that a parse error was generated when trying to create a new SkP
icture without | 905 // Now test that a parse error was generated when trying to create a new SkP
icture without |
907 // providing a function to decode the bitmap. | 906 // providing a function to decode the bitmap. |
908 ErrorContext context; | 907 ErrorContext context; |
909 context.fErrors = 0; | 908 context.fErrors = 0; |
910 context.fReporter = reporter; | 909 context.fReporter = reporter; |
911 SkSetErrorCallback(assert_one_parse_error_cb, &context); | 910 SkSetErrorCallback(assert_one_parse_error_cb, &context); |
912 SkMemoryStream pictureStream(picture1); | 911 SkMemoryStream pictureStream(picture1); |
913 SkClearLastError(); | 912 SkClearLastError(); |
914 SkAutoTUnref<SkPicture> pictureFromStream(SkPicture::CreateFromStream(&pictu
reStream, nullptr)); | 913 sk_sp<SkPicture> pictureFromStream(SkPicture::MakeFromStream(&pictureStream,
nullptr)); |
915 REPORTER_ASSERT(reporter, pictureFromStream.get() != nullptr); | 914 REPORTER_ASSERT(reporter, pictureFromStream.get() != nullptr); |
916 SkClearLastError(); | 915 SkClearLastError(); |
917 SkSetErrorCallback(nullptr, nullptr); | 916 SkSetErrorCallback(nullptr, nullptr); |
918 | 917 |
919 // Test that using the version of CreateFromStream that just takes a stream
also decodes the | 918 // Test that using the version of CreateFromStream that just takes a stream
also decodes the |
920 // bitmap. Drawing this picture should look exactly like the original bitmap
. | 919 // bitmap. Drawing this picture should look exactly like the original bitmap
. |
921 SkMD5::Digest referenceDigest; | 920 SkMD5::Digest referenceDigest; |
922 md5(original, &referenceDigest); | 921 md5(original, &referenceDigest); |
923 | 922 |
924 SkBitmap dst; | 923 SkBitmap dst; |
925 dst.allocPixels(original.info()); | 924 dst.allocPixels(original.info()); |
926 dst.eraseColor(SK_ColorRED); | 925 dst.eraseColor(SK_ColorRED); |
927 SkCanvas canvas(dst); | 926 SkCanvas canvas(dst); |
928 | 927 |
929 pictureStream.rewind(); | 928 pictureStream.rewind(); |
930 pictureFromStream.reset(SkPicture::CreateFromStream(&pictureStream)); | 929 pictureFromStream = SkPicture::MakeFromStream(&pictureStream); |
931 canvas.drawPicture(pictureFromStream.get()); | 930 canvas.drawPicture(pictureFromStream.get()); |
932 | 931 |
933 SkMD5::Digest digest2; | 932 SkMD5::Digest digest2; |
934 md5(dst, &digest2); | 933 md5(dst, &digest2); |
935 REPORTER_ASSERT(reporter, referenceDigest == digest2); | 934 REPORTER_ASSERT(reporter, referenceDigest == digest2); |
936 } | 935 } |
937 | 936 |
938 static void test_clip_bound_opt(skiatest::Reporter* reporter) { | 937 static void test_clip_bound_opt(skiatest::Reporter* reporter) { |
939 // Test for crbug.com/229011 | 938 // Test for crbug.com/229011 |
940 SkRect rect1 = SkRect::MakeXYWH(SkIntToScalar(4), SkIntToScalar(4), | 939 SkRect rect1 = SkRect::MakeXYWH(SkIntToScalar(4), SkIntToScalar(4), |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1025 | 1024 |
1026 static void test_cull_rect_reset(skiatest::Reporter* reporter) { | 1025 static void test_cull_rect_reset(skiatest::Reporter* reporter) { |
1027 SkPictureRecorder recorder; | 1026 SkPictureRecorder recorder; |
1028 SkRect bounds = SkRect::MakeWH(10, 10); | 1027 SkRect bounds = SkRect::MakeWH(10, 10); |
1029 SkRTreeFactory factory; | 1028 SkRTreeFactory factory; |
1030 SkCanvas* canvas = recorder.beginRecording(bounds, &factory); | 1029 SkCanvas* canvas = recorder.beginRecording(bounds, &factory); |
1031 bounds = SkRect::MakeWH(100, 100); | 1030 bounds = SkRect::MakeWH(100, 100); |
1032 SkPaint paint; | 1031 SkPaint paint; |
1033 canvas->drawRect(bounds, paint); | 1032 canvas->drawRect(bounds, paint); |
1034 canvas->drawRect(bounds, paint); | 1033 canvas->drawRect(bounds, paint); |
1035 SkAutoTUnref<const SkPicture> p(recorder.endRecordingAsPicture(bounds)); | 1034 sk_sp<SkPicture> p(recorder.finishRecordingAsPictureWithCull(bounds)); |
1036 const SkBigPicture* picture = p->asSkBigPicture(); | 1035 const SkBigPicture* picture = p->asSkBigPicture(); |
1037 REPORTER_ASSERT(reporter, picture); | 1036 REPORTER_ASSERT(reporter, picture); |
1038 | 1037 |
1039 SkRect finalCullRect = picture->cullRect(); | 1038 SkRect finalCullRect = picture->cullRect(); |
1040 REPORTER_ASSERT(reporter, 0 == finalCullRect.fLeft); | 1039 REPORTER_ASSERT(reporter, 0 == finalCullRect.fLeft); |
1041 REPORTER_ASSERT(reporter, 0 == finalCullRect.fTop); | 1040 REPORTER_ASSERT(reporter, 0 == finalCullRect.fTop); |
1042 REPORTER_ASSERT(reporter, 100 == finalCullRect.fBottom); | 1041 REPORTER_ASSERT(reporter, 100 == finalCullRect.fBottom); |
1043 REPORTER_ASSERT(reporter, 100 == finalCullRect.fRight); | 1042 REPORTER_ASSERT(reporter, 100 == finalCullRect.fRight); |
1044 | 1043 |
1045 const SkBBoxHierarchy* pictureBBH = picture->bbh(); | 1044 const SkBBoxHierarchy* pictureBBH = picture->bbh(); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1099 SkPictureRecorder recorder; | 1098 SkPictureRecorder recorder; |
1100 SkCanvas* canvas = recorder.beginRecording(10, 10); | 1099 SkCanvas* canvas = recorder.beginRecording(10, 10); |
1101 | 1100 |
1102 canvas->clipRect(SkRect::MakeEmpty(), SkRegion::kReplace_Op); | 1101 canvas->clipRect(SkRect::MakeEmpty(), SkRegion::kReplace_Op); |
1103 // The following expanding clip should not be skipped. | 1102 // The following expanding clip should not be skipped. |
1104 canvas->clipRect(SkRect::MakeXYWH(4, 4, 3, 3), SkRegion::kUnion_Op); | 1103 canvas->clipRect(SkRect::MakeXYWH(4, 4, 3, 3), SkRegion::kUnion_Op); |
1105 // Draw something so the optimizer doesn't just fold the world. | 1104 // Draw something so the optimizer doesn't just fold the world. |
1106 SkPaint p; | 1105 SkPaint p; |
1107 p.setColor(SK_ColorBLUE); | 1106 p.setColor(SK_ColorBLUE); |
1108 canvas->drawPaint(p); | 1107 canvas->drawPaint(p); |
1109 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 1108 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); |
1110 | 1109 |
1111 ClipCountingCanvas testCanvas(10, 10); | 1110 ClipCountingCanvas testCanvas(10, 10); |
1112 picture->playback(&testCanvas); | 1111 picture->playback(&testCanvas); |
1113 | 1112 |
1114 // Both clips should be present on playback. | 1113 // Both clips should be present on playback. |
1115 REPORTER_ASSERT(reporter, testCanvas.getClipCount() == 2); | 1114 REPORTER_ASSERT(reporter, testCanvas.getClipCount() == 2); |
1116 } | 1115 } |
1117 | 1116 |
1118 static void test_hierarchical(skiatest::Reporter* reporter) { | 1117 static void test_hierarchical(skiatest::Reporter* reporter) { |
1119 SkBitmap bm; | 1118 SkBitmap bm; |
1120 make_bm(&bm, 10, 10, SK_ColorRED, true); | 1119 make_bm(&bm, 10, 10, SK_ColorRED, true); |
1121 | 1120 |
1122 SkPictureRecorder recorder; | 1121 SkPictureRecorder recorder; |
1123 | 1122 |
1124 recorder.beginRecording(10, 10); | 1123 recorder.beginRecording(10, 10); |
1125 SkAutoTUnref<SkPicture> childPlain(recorder.endRecording()); | 1124 sk_sp<SkPicture> childPlain(recorder.finishRecordingAsPicture()); |
1126 REPORTER_ASSERT(reporter, !childPlain->willPlayBackBitmaps()); // 0 | 1125 REPORTER_ASSERT(reporter, !childPlain->willPlayBackBitmaps()); // 0 |
1127 | 1126 |
1128 recorder.beginRecording(10, 10)->drawBitmap(bm, 0, 0); | 1127 recorder.beginRecording(10, 10)->drawBitmap(bm, 0, 0); |
1129 SkAutoTUnref<SkPicture> childWithBitmap(recorder.endRecording()); | 1128 sk_sp<SkPicture> childWithBitmap(recorder.finishRecordingAsPicture()); |
1130 REPORTER_ASSERT(reporter, childWithBitmap->willPlayBackBitmaps()); // 1 | 1129 REPORTER_ASSERT(reporter, childWithBitmap->willPlayBackBitmaps()); // 1 |
1131 | 1130 |
1132 { | 1131 { |
1133 SkCanvas* canvas = recorder.beginRecording(10, 10); | 1132 SkCanvas* canvas = recorder.beginRecording(10, 10); |
1134 canvas->drawPicture(childPlain); | 1133 canvas->drawPicture(childPlain); |
1135 SkAutoTUnref<SkPicture> parentPP(recorder.endRecording()); | 1134 sk_sp<SkPicture> parentPP(recorder.finishRecordingAsPicture()); |
1136 REPORTER_ASSERT(reporter, !parentPP->willPlayBackBitmaps()); // 0 | 1135 REPORTER_ASSERT(reporter, !parentPP->willPlayBackBitmaps()); // 0 |
1137 } | 1136 } |
1138 { | 1137 { |
1139 SkCanvas* canvas = recorder.beginRecording(10, 10); | 1138 SkCanvas* canvas = recorder.beginRecording(10, 10); |
1140 canvas->drawPicture(childWithBitmap); | 1139 canvas->drawPicture(childWithBitmap); |
1141 SkAutoTUnref<SkPicture> parentPWB(recorder.endRecording()); | 1140 sk_sp<SkPicture> parentPWB(recorder.finishRecordingAsPicture()); |
1142 REPORTER_ASSERT(reporter, parentPWB->willPlayBackBitmaps()); // 1 | 1141 REPORTER_ASSERT(reporter, parentPWB->willPlayBackBitmaps()); // 1 |
1143 } | 1142 } |
1144 { | 1143 { |
1145 SkCanvas* canvas = recorder.beginRecording(10, 10); | 1144 SkCanvas* canvas = recorder.beginRecording(10, 10); |
1146 canvas->drawBitmap(bm, 0, 0); | 1145 canvas->drawBitmap(bm, 0, 0); |
1147 canvas->drawPicture(childPlain); | 1146 canvas->drawPicture(childPlain); |
1148 SkAutoTUnref<SkPicture> parentWBP(recorder.endRecording()); | 1147 sk_sp<SkPicture> parentWBP(recorder.finishRecordingAsPicture()); |
1149 REPORTER_ASSERT(reporter, parentWBP->willPlayBackBitmaps()); // 1 | 1148 REPORTER_ASSERT(reporter, parentWBP->willPlayBackBitmaps()); // 1 |
1150 } | 1149 } |
1151 { | 1150 { |
1152 SkCanvas* canvas = recorder.beginRecording(10, 10); | 1151 SkCanvas* canvas = recorder.beginRecording(10, 10); |
1153 canvas->drawBitmap(bm, 0, 0); | 1152 canvas->drawBitmap(bm, 0, 0); |
1154 canvas->drawPicture(childWithBitmap); | 1153 canvas->drawPicture(childWithBitmap); |
1155 SkAutoTUnref<SkPicture> parentWBWB(recorder.endRecording()); | 1154 sk_sp<SkPicture> parentWBWB(recorder.finishRecordingAsPicture()); |
1156 REPORTER_ASSERT(reporter, parentWBWB->willPlayBackBitmaps()); // 2 | 1155 REPORTER_ASSERT(reporter, parentWBWB->willPlayBackBitmaps()); // 2 |
1157 } | 1156 } |
1158 } | 1157 } |
1159 | 1158 |
1160 static void test_gen_id(skiatest::Reporter* reporter) { | 1159 static void test_gen_id(skiatest::Reporter* reporter) { |
1161 | 1160 |
1162 SkPictureRecorder recorder; | 1161 SkPictureRecorder recorder; |
1163 recorder.beginRecording(0, 0); | 1162 recorder.beginRecording(0, 0); |
1164 SkAutoTUnref<SkPicture> empty(recorder.endRecording()); | 1163 sk_sp<SkPicture> empty(recorder.finishRecordingAsPicture()); |
1165 | 1164 |
1166 // Empty pictures should still have a valid ID | 1165 // Empty pictures should still have a valid ID |
1167 REPORTER_ASSERT(reporter, empty->uniqueID() != SK_InvalidGenID); | 1166 REPORTER_ASSERT(reporter, empty->uniqueID() != SK_InvalidGenID); |
1168 | 1167 |
1169 SkCanvas* canvas = recorder.beginRecording(1, 1); | 1168 SkCanvas* canvas = recorder.beginRecording(1, 1); |
1170 canvas->drawARGB(255, 255, 255, 255); | 1169 canvas->drawARGB(255, 255, 255, 255); |
1171 SkAutoTUnref<SkPicture> hasData(recorder.endRecording()); | 1170 sk_sp<SkPicture> hasData(recorder.finishRecordingAsPicture()); |
1172 // picture should have a non-zero id after recording | 1171 // picture should have a non-zero id after recording |
1173 REPORTER_ASSERT(reporter, hasData->uniqueID() != SK_InvalidGenID); | 1172 REPORTER_ASSERT(reporter, hasData->uniqueID() != SK_InvalidGenID); |
1174 | 1173 |
1175 // both pictures should have different ids | 1174 // both pictures should have different ids |
1176 REPORTER_ASSERT(reporter, hasData->uniqueID() != empty->uniqueID()); | 1175 REPORTER_ASSERT(reporter, hasData->uniqueID() != empty->uniqueID()); |
1177 } | 1176 } |
1178 | 1177 |
1179 static void test_typeface(skiatest::Reporter* reporter) { | 1178 static void test_typeface(skiatest::Reporter* reporter) { |
1180 SkPictureRecorder recorder; | 1179 SkPictureRecorder recorder; |
1181 SkCanvas* canvas = recorder.beginRecording(10, 10); | 1180 SkCanvas* canvas = recorder.beginRecording(10, 10); |
1182 SkPaint paint; | 1181 SkPaint paint; |
1183 paint.setTypeface(SkTypeface::CreateFromName("Arial", SkTypeface::kItalic)); | 1182 paint.setTypeface(SkTypeface::CreateFromName("Arial", SkTypeface::kItalic)); |
1184 canvas->drawText("Q", 1, 0, 10, paint); | 1183 canvas->drawText("Q", 1, 0, 10, paint); |
1185 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 1184 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); |
1186 REPORTER_ASSERT(reporter, picture->hasText()); | 1185 REPORTER_ASSERT(reporter, picture->hasText()); |
1187 SkDynamicMemoryWStream stream; | 1186 SkDynamicMemoryWStream stream; |
1188 picture->serialize(&stream); | 1187 picture->serialize(&stream); |
1189 } | 1188 } |
1190 | 1189 |
1191 DEF_TEST(Picture, reporter) { | 1190 DEF_TEST(Picture, reporter) { |
1192 test_typeface(reporter); | 1191 test_typeface(reporter); |
1193 #ifdef SK_DEBUG | 1192 #ifdef SK_DEBUG |
1194 test_deleting_empty_picture(); | 1193 test_deleting_empty_picture(); |
1195 test_serializing_empty_picture(); | 1194 test_serializing_empty_picture(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1227 static void test_draw_bitmaps(SkCanvas* canvas) { | 1226 static void test_draw_bitmaps(SkCanvas* canvas) { |
1228 SkBitmap empty; | 1227 SkBitmap empty; |
1229 draw_bitmaps(empty, canvas); | 1228 draw_bitmaps(empty, canvas); |
1230 empty.setInfo(SkImageInfo::MakeN32Premul(10, 10)); | 1229 empty.setInfo(SkImageInfo::MakeN32Premul(10, 10)); |
1231 draw_bitmaps(empty, canvas); | 1230 draw_bitmaps(empty, canvas); |
1232 } | 1231 } |
1233 | 1232 |
1234 DEF_TEST(Picture_EmptyBitmap, r) { | 1233 DEF_TEST(Picture_EmptyBitmap, r) { |
1235 SkPictureRecorder recorder; | 1234 SkPictureRecorder recorder; |
1236 test_draw_bitmaps(recorder.beginRecording(10, 10)); | 1235 test_draw_bitmaps(recorder.beginRecording(10, 10)); |
1237 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 1236 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); |
1238 } | 1237 } |
1239 | 1238 |
1240 DEF_TEST(Canvas_EmptyBitmap, r) { | 1239 DEF_TEST(Canvas_EmptyBitmap, r) { |
1241 SkBitmap dst; | 1240 SkBitmap dst; |
1242 dst.allocN32Pixels(10, 10); | 1241 dst.allocN32Pixels(10, 10); |
1243 SkCanvas canvas(dst); | 1242 SkCanvas canvas(dst); |
1244 | 1243 |
1245 test_draw_bitmaps(&canvas); | 1244 test_draw_bitmaps(&canvas); |
1246 } | 1245 } |
1247 | 1246 |
(...skipping 22 matching lines...) Expand all Loading... |
1270 | 1269 |
1271 SkPictureRecorder recorder; | 1270 SkPictureRecorder recorder; |
1272 SkCanvas* canvas = recorder.beginRecording(100, 100); | 1271 SkCanvas* canvas = recorder.beginRecording(100, 100); |
1273 canvas->drawARGB(0, 0, 0, 0); | 1272 canvas->drawARGB(0, 0, 0, 0); |
1274 | 1273 |
1275 canvas->saveLayer(0, &semiTransparent); | 1274 canvas->saveLayer(0, &semiTransparent); |
1276 canvas->drawBitmap(blueBM, 25, 25); | 1275 canvas->drawBitmap(blueBM, 25, 25); |
1277 canvas->drawBitmap(redBM, 50, 50); | 1276 canvas->drawBitmap(redBM, 50, 50); |
1278 canvas->restore(); | 1277 canvas->restore(); |
1279 | 1278 |
1280 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 1279 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); |
1281 | 1280 |
1282 // Now replay the picture back on another canvas | 1281 // Now replay the picture back on another canvas |
1283 // and check a couple of its pixels. | 1282 // and check a couple of its pixels. |
1284 SkBitmap replayBM; | 1283 SkBitmap replayBM; |
1285 make_bm(&replayBM, 100, 100, SK_ColorBLACK, false); | 1284 make_bm(&replayBM, 100, 100, SK_ColorBLACK, false); |
1286 SkCanvas replayCanvas(replayBM); | 1285 SkCanvas replayCanvas(replayBM); |
1287 picture->playback(&replayCanvas); | 1286 picture->playback(&replayCanvas); |
1288 replayCanvas.flush(); | 1287 replayCanvas.flush(); |
1289 | 1288 |
1290 // With the bug present, at (55, 55) we would get a fully opaque red | 1289 // With the bug present, at (55, 55) we would get a fully opaque red |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1322 DEF_TEST(Picture_SkipBBH, r) { | 1321 DEF_TEST(Picture_SkipBBH, r) { |
1323 SkRect bound = SkRect::MakeWH(320, 240); | 1322 SkRect bound = SkRect::MakeWH(320, 240); |
1324 CountingBBH bbh(bound); | 1323 CountingBBH bbh(bound); |
1325 SpoonFedBBHFactory factory(&bbh); | 1324 SpoonFedBBHFactory factory(&bbh); |
1326 | 1325 |
1327 SkPictureRecorder recorder; | 1326 SkPictureRecorder recorder; |
1328 SkCanvas* c = recorder.beginRecording(bound, &factory); | 1327 SkCanvas* c = recorder.beginRecording(bound, &factory); |
1329 // Record a few ops so we don't hit a small- or empty- picture optimization. | 1328 // Record a few ops so we don't hit a small- or empty- picture optimization. |
1330 c->drawRect(bound, SkPaint()); | 1329 c->drawRect(bound, SkPaint()); |
1331 c->drawRect(bound, SkPaint()); | 1330 c->drawRect(bound, SkPaint()); |
1332 SkAutoTUnref<const SkPicture> picture(recorder.endRecording()); | 1331 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); |
1333 | 1332 |
1334 SkCanvas big(640, 480), small(300, 200); | 1333 SkCanvas big(640, 480), small(300, 200); |
1335 | 1334 |
1336 picture->playback(&big); | 1335 picture->playback(&big); |
1337 REPORTER_ASSERT(r, bbh.searchCalls == 0); | 1336 REPORTER_ASSERT(r, bbh.searchCalls == 0); |
1338 | 1337 |
1339 picture->playback(&small); | 1338 picture->playback(&small); |
1340 REPORTER_ASSERT(r, bbh.searchCalls == 1); | 1339 REPORTER_ASSERT(r, bbh.searchCalls == 1); |
1341 } | 1340 } |
1342 | 1341 |
1343 DEF_TEST(Picture_BitmapLeak, r) { | 1342 DEF_TEST(Picture_BitmapLeak, r) { |
1344 SkBitmap mut, immut; | 1343 SkBitmap mut, immut; |
1345 mut.allocN32Pixels(300, 200); | 1344 mut.allocN32Pixels(300, 200); |
1346 immut.allocN32Pixels(300, 200); | 1345 immut.allocN32Pixels(300, 200); |
1347 immut.setImmutable(); | 1346 immut.setImmutable(); |
1348 SkASSERT(!mut.isImmutable()); | 1347 SkASSERT(!mut.isImmutable()); |
1349 SkASSERT(immut.isImmutable()); | 1348 SkASSERT(immut.isImmutable()); |
1350 | 1349 |
1351 // No one can hold a ref on our pixels yet. | 1350 // No one can hold a ref on our pixels yet. |
1352 REPORTER_ASSERT(r, mut.pixelRef()->unique()); | 1351 REPORTER_ASSERT(r, mut.pixelRef()->unique()); |
1353 REPORTER_ASSERT(r, immut.pixelRef()->unique()); | 1352 REPORTER_ASSERT(r, immut.pixelRef()->unique()); |
1354 | 1353 |
1355 SkAutoTUnref<const SkPicture> pic; | 1354 sk_sp<SkPicture> pic; |
1356 { | 1355 { |
1357 // we want the recorder to go out of scope before our subsequent checks,
so we | 1356 // we want the recorder to go out of scope before our subsequent checks,
so we |
1358 // place it inside local braces. | 1357 // place it inside local braces. |
1359 SkPictureRecorder rec; | 1358 SkPictureRecorder rec; |
1360 SkCanvas* canvas = rec.beginRecording(1920, 1200); | 1359 SkCanvas* canvas = rec.beginRecording(1920, 1200); |
1361 canvas->drawBitmap(mut, 0, 0); | 1360 canvas->drawBitmap(mut, 0, 0); |
1362 canvas->drawBitmap(immut, 800, 600); | 1361 canvas->drawBitmap(immut, 800, 600); |
1363 pic.reset(rec.endRecording()); | 1362 pic = rec.finishRecordingAsPicture(); |
1364 } | 1363 } |
1365 | 1364 |
1366 // The picture shares the immutable pixels but copies the mutable ones. | 1365 // The picture shares the immutable pixels but copies the mutable ones. |
1367 REPORTER_ASSERT(r, mut.pixelRef()->unique()); | 1366 REPORTER_ASSERT(r, mut.pixelRef()->unique()); |
1368 REPORTER_ASSERT(r, !immut.pixelRef()->unique()); | 1367 REPORTER_ASSERT(r, !immut.pixelRef()->unique()); |
1369 | 1368 |
1370 // When the picture goes away, it's just our bitmaps holding the refs. | 1369 // When the picture goes away, it's just our bitmaps holding the refs. |
1371 pic.reset(nullptr); | 1370 pic = nullptr; |
1372 REPORTER_ASSERT(r, mut.pixelRef()->unique()); | 1371 REPORTER_ASSERT(r, mut.pixelRef()->unique()); |
1373 REPORTER_ASSERT(r, immut.pixelRef()->unique()); | 1372 REPORTER_ASSERT(r, immut.pixelRef()->unique()); |
1374 } | 1373 } |
1375 | 1374 |
1376 // getRecordingCanvas() should return a SkCanvas when recording, null when not r
ecording. | 1375 // getRecordingCanvas() should return a SkCanvas when recording, null when not r
ecording. |
1377 DEF_TEST(Picture_getRecordingCanvas, r) { | 1376 DEF_TEST(Picture_getRecordingCanvas, r) { |
1378 SkPictureRecorder rec; | 1377 SkPictureRecorder rec; |
1379 REPORTER_ASSERT(r, !rec.getRecordingCanvas()); | 1378 REPORTER_ASSERT(r, !rec.getRecordingCanvas()); |
1380 for (int i = 0; i < 3; i++) { | 1379 for (int i = 0; i < 3; i++) { |
1381 rec.beginRecording(100, 100); | 1380 rec.beginRecording(100, 100); |
1382 REPORTER_ASSERT(r, rec.getRecordingCanvas()); | 1381 REPORTER_ASSERT(r, rec.getRecordingCanvas()); |
1383 rec.endRecording()->unref(); | 1382 rec.finishRecordingAsPicture(); |
1384 REPORTER_ASSERT(r, !rec.getRecordingCanvas()); | 1383 REPORTER_ASSERT(r, !rec.getRecordingCanvas()); |
1385 } | 1384 } |
1386 } | 1385 } |
1387 | 1386 |
1388 DEF_TEST(MiniRecorderLeftHanging, r) { | 1387 DEF_TEST(MiniRecorderLeftHanging, r) { |
1389 // Any shader or other ref-counted effect will do just fine here. | 1388 // Any shader or other ref-counted effect will do just fine here. |
1390 SkPaint paint; | 1389 SkPaint paint; |
1391 paint.setShader(SkShader::MakeColorShader(SK_ColorRED)); | 1390 paint.setShader(SkShader::MakeColorShader(SK_ColorRED)); |
1392 | 1391 |
1393 SkMiniRecorder rec; | 1392 SkMiniRecorder rec; |
1394 REPORTER_ASSERT(r, rec.drawRect(SkRect::MakeWH(20,30), paint)); | 1393 REPORTER_ASSERT(r, rec.drawRect(SkRect::MakeWH(20,30), paint)); |
1395 // Don't call rec.detachPicture(). Test succeeds by not asserting or leakin
g the shader. | 1394 // Don't call rec.detachPicture(). Test succeeds by not asserting or leakin
g the shader. |
1396 } | 1395 } |
1397 | 1396 |
1398 DEF_TEST(Picture_preserveCullRect, r) { | 1397 DEF_TEST(Picture_preserveCullRect, r) { |
1399 SkPictureRecorder recorder; | 1398 SkPictureRecorder recorder; |
1400 | 1399 |
1401 SkCanvas* c = recorder.beginRecording(SkRect::MakeLTRB(1, 2, 3, 4)); | 1400 SkCanvas* c = recorder.beginRecording(SkRect::MakeLTRB(1, 2, 3, 4)); |
1402 c->clear(SK_ColorCYAN); | 1401 c->clear(SK_ColorCYAN); |
1403 | 1402 |
1404 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 1403 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); |
1405 SkDynamicMemoryWStream wstream; | 1404 SkDynamicMemoryWStream wstream; |
1406 picture->serialize(&wstream); | 1405 picture->serialize(&wstream); |
1407 | 1406 |
1408 SkAutoTDelete<SkStream> rstream(wstream.detachAsStream()); | 1407 SkAutoTDelete<SkStream> rstream(wstream.detachAsStream()); |
1409 SkAutoTUnref<SkPicture> deserializedPicture(SkPicture::CreateFromStream(rstr
eam)); | 1408 sk_sp<SkPicture> deserializedPicture(SkPicture::MakeFromStream(rstream)); |
1410 | 1409 |
1411 REPORTER_ASSERT(r, deserializedPicture != nullptr); | 1410 REPORTER_ASSERT(r, deserializedPicture != nullptr); |
1412 REPORTER_ASSERT(r, deserializedPicture->cullRect().left() == 1); | 1411 REPORTER_ASSERT(r, deserializedPicture->cullRect().left() == 1); |
1413 REPORTER_ASSERT(r, deserializedPicture->cullRect().top() == 2); | 1412 REPORTER_ASSERT(r, deserializedPicture->cullRect().top() == 2); |
1414 REPORTER_ASSERT(r, deserializedPicture->cullRect().right() == 3); | 1413 REPORTER_ASSERT(r, deserializedPicture->cullRect().right() == 3); |
1415 REPORTER_ASSERT(r, deserializedPicture->cullRect().bottom() == 4); | 1414 REPORTER_ASSERT(r, deserializedPicture->cullRect().bottom() == 4); |
1416 } | 1415 } |
OLD | NEW |