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 "SkData.h" | 10 #include "SkData.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 make_texture, | 65 make_texture, |
66 make_pict_gen, | 66 make_pict_gen, |
67 make_encode_gen, | 67 make_encode_gen, |
68 }; | 68 }; |
69 | 69 |
70 /* | 70 /* |
71 * Exercise drawing pictures inside an image, showing that the image version is
pixelated | 71 * Exercise drawing pictures inside an image, showing that the image version is
pixelated |
72 * (correctly) when it is inside an image. | 72 * (correctly) when it is inside an image. |
73 */ | 73 */ |
74 class ImageShaderGM : public skiagm::GM { | 74 class ImageShaderGM : public skiagm::GM { |
75 SkAutoTUnref<SkPicture> fPicture; | 75 sk_sp<SkPicture> fPicture; |
76 | 76 |
77 public: | 77 public: |
78 ImageShaderGM() {} | 78 ImageShaderGM() {} |
79 | 79 |
80 protected: | 80 protected: |
81 SkString onShortName() override { | 81 SkString onShortName() override { |
82 return SkString("image-shader"); | 82 return SkString("image-shader"); |
83 } | 83 } |
84 | 84 |
85 SkISize onISize() override { | 85 SkISize onISize() override { |
86 return SkISize::Make(850, 450); | 86 return SkISize::Make(850, 450); |
87 } | 87 } |
88 | 88 |
89 void onOnceBeforeDraw() override { | 89 void onOnceBeforeDraw() override { |
90 const SkRect bounds = SkRect::MakeWH(100, 100); | 90 const SkRect bounds = SkRect::MakeWH(100, 100); |
91 SkPictureRecorder recorder; | 91 SkPictureRecorder recorder; |
92 draw_something(recorder.beginRecording(bounds), bounds); | 92 draw_something(recorder.beginRecording(bounds), bounds); |
93 fPicture.reset(recorder.endRecording()); | 93 fPicture = recorder.finishRecordingAsPicture(); |
94 } | 94 } |
95 | 95 |
96 void testImage(SkCanvas* canvas, SkImage* image) { | 96 void testImage(SkCanvas* canvas, SkImage* image) { |
97 SkAutoCanvasRestore acr(canvas, true); | 97 SkAutoCanvasRestore acr(canvas, true); |
98 | 98 |
99 canvas->drawImage(image, 0, 0); | 99 canvas->drawImage(image, 0, 0); |
100 canvas->translate(0, 120); | 100 canvas->translate(0, 120); |
101 | 101 |
102 const SkShader::TileMode tile = SkShader::kRepeat_TileMode; | 102 const SkShader::TileMode tile = SkShader::kRepeat_TileMode; |
103 const SkMatrix localM = SkMatrix::MakeTrans(-50, -50); | 103 const SkMatrix localM = SkMatrix::MakeTrans(-50, -50); |
104 SkPaint paint; | 104 SkPaint paint; |
105 paint.setShader(image->makeShader(tile, tile, &localM)); | 105 paint.setShader(image->makeShader(tile, tile, &localM)); |
106 paint.setAntiAlias(true); | 106 paint.setAntiAlias(true); |
107 canvas->drawCircle(50, 50, 50, paint); | 107 canvas->drawCircle(50, 50, 50, paint); |
108 } | 108 } |
109 | 109 |
110 void onDraw(SkCanvas* canvas) override { | 110 void onDraw(SkCanvas* canvas) override { |
111 canvas->translate(20, 20); | 111 canvas->translate(20, 20); |
112 | 112 |
113 const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); | 113 const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); |
114 | 114 |
115 for (size_t i = 0; i < SK_ARRAY_COUNT(gProcs); ++i) { | 115 for (size_t i = 0; i < SK_ARRAY_COUNT(gProcs); ++i) { |
116 sk_sp<SkImage> image(gProcs[i](canvas->getGrContext(), fPicture, inf
o)); | 116 sk_sp<SkImage> image(gProcs[i](canvas->getGrContext(), fPicture.get(
), info)); |
117 if (image) { | 117 if (image) { |
118 this->testImage(canvas, image.get()); | 118 this->testImage(canvas, image.get()); |
119 } | 119 } |
120 canvas->translate(120, 0); | 120 canvas->translate(120, 0); |
121 } | 121 } |
122 } | 122 } |
123 | 123 |
124 private: | 124 private: |
125 typedef skiagm::GM INHERITED; | 125 typedef skiagm::GM INHERITED; |
126 }; | 126 }; |
127 DEF_GM( return new ImageShaderGM; ) | 127 DEF_GM( return new ImageShaderGM; ) |
128 | 128 |
OLD | NEW |