OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "gm.h" | 8 #include "gm.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkImage.h" | 10 #include "SkImage.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 paint.setStyle(SkPaint::kFill_Style); | 28 paint.setStyle(SkPaint::kFill_Style); |
29 paint.setColor(SK_ColorBLUE); | 29 paint.setColor(SK_ColorBLUE); |
30 canvas->drawOval(bounds, paint); | 30 canvas->drawOval(bounds, paint); |
31 } | 31 } |
32 | 32 |
33 /* | 33 /* |
34 * Exercise drawing pictures inside an image, showing that the image version is
pixelated | 34 * Exercise drawing pictures inside an image, showing that the image version is
pixelated |
35 * (correctly) when it is inside an image. | 35 * (correctly) when it is inside an image. |
36 */ | 36 */ |
37 class ImagePictGM : public skiagm::GM { | 37 class ImagePictGM : public skiagm::GM { |
38 SkAutoTUnref<SkPicture> fPicture; | 38 sk_sp<SkPicture> fPicture; |
39 sk_sp<SkImage> fImage0; | 39 sk_sp<SkImage> fImage0; |
40 sk_sp<SkImage> fImage1; | 40 sk_sp<SkImage> fImage1; |
41 public: | 41 public: |
42 ImagePictGM() {} | 42 ImagePictGM() {} |
43 | 43 |
44 protected: | 44 protected: |
45 SkString onShortName() override { | 45 SkString onShortName() override { |
46 return SkString("image-picture"); | 46 return SkString("image-picture"); |
47 } | 47 } |
48 | 48 |
49 SkISize onISize() override { | 49 SkISize onISize() override { |
50 return SkISize::Make(850, 450); | 50 return SkISize::Make(850, 450); |
51 } | 51 } |
52 | 52 |
53 void onOnceBeforeDraw() override { | 53 void onOnceBeforeDraw() override { |
54 const SkRect bounds = SkRect::MakeXYWH(100, 100, 100, 100); | 54 const SkRect bounds = SkRect::MakeXYWH(100, 100, 100, 100); |
55 SkPictureRecorder recorder; | 55 SkPictureRecorder recorder; |
56 draw_something(recorder.beginRecording(bounds), bounds); | 56 draw_something(recorder.beginRecording(bounds), bounds); |
57 fPicture.reset(recorder.endRecording()); | 57 fPicture = recorder.finishRecordingAsPicture(); |
58 | 58 |
59 // extract enough just for the oval. | 59 // extract enough just for the oval. |
60 const SkISize size = SkISize::Make(100, 100); | 60 const SkISize size = SkISize::Make(100, 100); |
61 | 61 |
62 SkMatrix matrix; | 62 SkMatrix matrix; |
63 matrix.setTranslate(-100, -100); | 63 matrix.setTranslate(-100, -100); |
64 fImage0 = SkImage::MakeFromPicture(sk_ref_sp(fPicture.get()), size, &mat
rix, nullptr); | 64 fImage0 = SkImage::MakeFromPicture(fPicture, size, &matrix, nullptr); |
65 matrix.postTranslate(-50, -50); | 65 matrix.postTranslate(-50, -50); |
66 matrix.postRotate(45); | 66 matrix.postRotate(45); |
67 matrix.postTranslate(50, 50); | 67 matrix.postTranslate(50, 50); |
68 fImage1 = SkImage::MakeFromPicture(sk_ref_sp(fPicture.get()), size, &mat
rix, nullptr); | 68 fImage1 = SkImage::MakeFromPicture(fPicture, size, &matrix, nullptr); |
69 } | 69 } |
70 | 70 |
71 void drawSet(SkCanvas* canvas) const { | 71 void drawSet(SkCanvas* canvas) const { |
72 SkMatrix matrix = SkMatrix::MakeTrans(-100, -100); | 72 SkMatrix matrix = SkMatrix::MakeTrans(-100, -100); |
73 canvas->drawPicture(fPicture, &matrix, nullptr); | 73 canvas->drawPicture(fPicture, &matrix, nullptr); |
74 canvas->drawImage(fImage0.get(), 150, 0); | 74 canvas->drawImage(fImage0.get(), 150, 0); |
75 canvas->drawImage(fImage1.get(), 300, 0); | 75 canvas->drawImage(fImage1.get(), 300, 0); |
76 } | 76 } |
77 | 77 |
78 void onDraw(SkCanvas* canvas) override { | 78 void onDraw(SkCanvas* canvas) override { |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 if (!ctx) { | 247 if (!ctx) { |
248 return new EmptyGenerator(info); | 248 return new EmptyGenerator(info); |
249 } | 249 } |
250 return new TextureGenerator(ctx, info, pic); | 250 return new TextureGenerator(ctx, info, pic); |
251 } | 251 } |
252 #endif | 252 #endif |
253 | 253 |
254 class ImageCacheratorGM : public skiagm::GM { | 254 class ImageCacheratorGM : public skiagm::GM { |
255 SkString fName; | 255 SkString fName; |
256 SkImageGenerator* (*fFactory)(GrContext*, SkPicture*); | 256 SkImageGenerator* (*fFactory)(GrContext*, SkPicture*); |
257 SkAutoTUnref<SkPicture> fPicture; | 257 sk_sp<SkPicture> fPicture; |
258 SkAutoTDelete<SkImageCacherator> fCache; | 258 SkAutoTDelete<SkImageCacherator> fCache; |
259 SkAutoTDelete<SkImageCacherator> fCacheSubset; | 259 SkAutoTDelete<SkImageCacherator> fCacheSubset; |
260 | 260 |
261 public: | 261 public: |
262 ImageCacheratorGM(const char suffix[], SkImageGenerator* (*factory)(GrContex
t*, SkPicture*)) | 262 ImageCacheratorGM(const char suffix[], SkImageGenerator* (*factory)(GrContex
t*, SkPicture*)) |
263 : fFactory(factory) | 263 : fFactory(factory) |
264 { | 264 { |
265 fName.printf("image-cacherator-from-%s", suffix); | 265 fName.printf("image-cacherator-from-%s", suffix); |
266 } | 266 } |
267 | 267 |
268 protected: | 268 protected: |
269 SkString onShortName() override { | 269 SkString onShortName() override { |
270 return fName; | 270 return fName; |
271 } | 271 } |
272 | 272 |
273 SkISize onISize() override { | 273 SkISize onISize() override { |
274 return SkISize::Make(960, 450); | 274 return SkISize::Make(960, 450); |
275 } | 275 } |
276 | 276 |
277 void onOnceBeforeDraw() override { | 277 void onOnceBeforeDraw() override { |
278 const SkRect bounds = SkRect::MakeXYWH(100, 100, 100, 100); | 278 const SkRect bounds = SkRect::MakeXYWH(100, 100, 100, 100); |
279 SkPictureRecorder recorder; | 279 SkPictureRecorder recorder; |
280 draw_something(recorder.beginRecording(bounds), bounds); | 280 draw_something(recorder.beginRecording(bounds), bounds); |
281 fPicture.reset(recorder.endRecording()); | 281 fPicture = recorder.finishRecordingAsPicture(); |
282 } | 282 } |
283 | 283 |
284 void makeCaches(GrContext* ctx) { | 284 void makeCaches(GrContext* ctx) { |
285 auto gen = fFactory(ctx, fPicture); | 285 auto gen = fFactory(ctx, fPicture.get()); |
286 SkDEBUGCODE(const uint32_t genID = gen->uniqueID();) | 286 SkDEBUGCODE(const uint32_t genID = gen->uniqueID();) |
287 fCache.reset(SkImageCacherator::NewFromGenerator(gen)); | 287 fCache.reset(SkImageCacherator::NewFromGenerator(gen)); |
288 | 288 |
289 const SkIRect subset = SkIRect::MakeLTRB(50, 50, 100, 100); | 289 const SkIRect subset = SkIRect::MakeLTRB(50, 50, 100, 100); |
290 | 290 |
291 gen = fFactory(ctx, fPicture); | 291 gen = fFactory(ctx, fPicture.get()); |
292 SkDEBUGCODE(const uint32_t genSubsetID = gen->uniqueID();) | 292 SkDEBUGCODE(const uint32_t genSubsetID = gen->uniqueID();) |
293 fCacheSubset.reset(SkImageCacherator::NewFromGenerator(gen, &subset)); | 293 fCacheSubset.reset(SkImageCacherator::NewFromGenerator(gen, &subset)); |
294 | 294 |
295 // whole caches should have the same ID as the generator. Subsets should
be diff | 295 // whole caches should have the same ID as the generator. Subsets should
be diff |
296 SkASSERT(fCache->uniqueID() == genID); | 296 SkASSERT(fCache->uniqueID() == genID); |
297 SkASSERT(fCacheSubset->uniqueID() != genID); | 297 SkASSERT(fCacheSubset->uniqueID() != genID); |
298 SkASSERT(fCacheSubset->uniqueID() != genSubsetID); | 298 SkASSERT(fCacheSubset->uniqueID() != genSubsetID); |
299 | 299 |
300 SkASSERT(fCache->info().dimensions() == SkISize::Make(100, 100)); | 300 SkASSERT(fCache->info().dimensions() == SkISize::Make(100, 100)); |
301 SkASSERT(fCacheSubset->info().dimensions() == SkISize::Make(50, 50)); | 301 SkASSERT(fCacheSubset->info().dimensions() == SkISize::Make(50, 50)); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 }; | 370 }; |
371 DEF_GM( return new ImageCacheratorGM("picture", make_pic_generator); ) | 371 DEF_GM( return new ImageCacheratorGM("picture", make_pic_generator); ) |
372 DEF_GM( return new ImageCacheratorGM("raster", make_ras_generator); ) | 372 DEF_GM( return new ImageCacheratorGM("raster", make_ras_generator); ) |
373 DEF_GM( return new ImageCacheratorGM("ctable", make_ctable_generator); ) | 373 DEF_GM( return new ImageCacheratorGM("ctable", make_ctable_generator); ) |
374 #if SK_SUPPORT_GPU | 374 #if SK_SUPPORT_GPU |
375 DEF_GM( return new ImageCacheratorGM("texture", make_tex_generator); ) | 375 DEF_GM( return new ImageCacheratorGM("texture", make_tex_generator); ) |
376 #endif | 376 #endif |
377 | 377 |
378 | 378 |
379 | 379 |
OLD | NEW |