OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkDisplacementMapEffect.h" | 8 #include "SkDisplacementMapEffect.h" |
9 #include "SkImage.h" | 9 #include "SkImage.h" |
10 #include "SkImageSource.h" | 10 #include "SkImageSource.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 canvas->save(); | 50 canvas->save(); |
51 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); | 51 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); |
52 canvas->clipRect(SkRect::MakeWH(SkIntToScalar(fBitmap.width()), SkIntToS
calar(fBitmap.height()))); | 52 canvas->clipRect(SkRect::MakeWH(SkIntToScalar(fBitmap.width()), SkIntToS
calar(fBitmap.height()))); |
53 canvas->drawBitmap(fBitmap, 0, 0, &paint); | 53 canvas->drawBitmap(fBitmap, 0, 0, &paint); |
54 canvas->restore(); | 54 canvas->restore(); |
55 } | 55 } |
56 | 56 |
57 void onDraw(SkCanvas* canvas) override { | 57 void onDraw(SkCanvas* canvas) override { |
58 canvas->clear(SK_ColorBLACK); | 58 canvas->clear(SK_ColorBLACK); |
59 SkPaint paint; | 59 SkPaint paint; |
60 SkAutoTUnref<SkImageFilter> displ(SkImageSource::Create(fCheckerboard.ge
t())); | 60 sk_sp<SkImageFilter> displ(SkImageSource::Make(fCheckerboard)); |
61 paint.setImageFilter(SkDisplacementMapEffect::Create( | 61 paint.setImageFilter(SkDisplacementMapEffect::Create( |
62 SkDisplacementMapEffect::kR_ChannelSelectorType, | 62 SkDisplacementMapEffect::kR_ChannelSelectorType, |
63 SkDisplacementMapEffect::kG_ChannelSelectorType, 0.0f, displ))->unre
f(); | 63 SkDisplacementMapEffect::kG_ChannelSelectorType, 0.0f, displ.get()))
->unref(); |
64 drawClippedBitmap(canvas, 0, 0, paint); | 64 drawClippedBitmap(canvas, 0, 0, paint); |
65 paint.setImageFilter(SkDisplacementMapEffect::Create( | 65 paint.setImageFilter(SkDisplacementMapEffect::Create( |
66 SkDisplacementMapEffect::kB_ChannelSelectorType, | 66 SkDisplacementMapEffect::kB_ChannelSelectorType, |
67 SkDisplacementMapEffect::kA_ChannelSelectorType, 16.0f, displ))->unr
ef(); | 67 SkDisplacementMapEffect::kA_ChannelSelectorType, 16.0f, displ.get())
)->unref(); |
68 drawClippedBitmap(canvas, 100, 0, paint); | 68 drawClippedBitmap(canvas, 100, 0, paint); |
69 paint.setImageFilter(SkDisplacementMapEffect::Create( | 69 paint.setImageFilter(SkDisplacementMapEffect::Create( |
70 SkDisplacementMapEffect::kR_ChannelSelectorType, | 70 SkDisplacementMapEffect::kR_ChannelSelectorType, |
71 SkDisplacementMapEffect::kB_ChannelSelectorType, 32.0f, displ))->unr
ef(); | 71 SkDisplacementMapEffect::kB_ChannelSelectorType, 32.0f, displ.get())
)->unref(); |
72 drawClippedBitmap(canvas, 200, 0, paint); | 72 drawClippedBitmap(canvas, 200, 0, paint); |
73 paint.setImageFilter(SkDisplacementMapEffect::Create( | 73 paint.setImageFilter(SkDisplacementMapEffect::Create( |
74 SkDisplacementMapEffect::kG_ChannelSelectorType, | 74 SkDisplacementMapEffect::kG_ChannelSelectorType, |
75 SkDisplacementMapEffect::kA_ChannelSelectorType, 48.0f, displ))->unr
ef(); | 75 SkDisplacementMapEffect::kA_ChannelSelectorType, 48.0f, displ.get())
)->unref(); |
76 drawClippedBitmap(canvas, 300, 0, paint); | 76 drawClippedBitmap(canvas, 300, 0, paint); |
77 paint.setImageFilter(SkDisplacementMapEffect::Create( | 77 paint.setImageFilter(SkDisplacementMapEffect::Create( |
78 SkDisplacementMapEffect::kR_ChannelSelectorType, | 78 SkDisplacementMapEffect::kR_ChannelSelectorType, |
79 SkDisplacementMapEffect::kA_ChannelSelectorType, 64.0f, displ))->unr
ef(); | 79 SkDisplacementMapEffect::kA_ChannelSelectorType, 64.0f, displ.get())
)->unref(); |
80 drawClippedBitmap(canvas, 400, 0, paint); | 80 drawClippedBitmap(canvas, 400, 0, paint); |
81 | 81 |
82 paint.setImageFilter(SkDisplacementMapEffect::Create( | 82 paint.setImageFilter(SkDisplacementMapEffect::Create( |
83 SkDisplacementMapEffect::kR_ChannelSelectorType, | 83 SkDisplacementMapEffect::kR_ChannelSelectorType, |
84 SkDisplacementMapEffect::kG_ChannelSelectorType, 40.0f, displ))->unr
ef(); | 84 SkDisplacementMapEffect::kG_ChannelSelectorType, 40.0f, displ.get())
)->unref(); |
85 drawClippedBitmap(canvas, 0, 100, paint); | 85 drawClippedBitmap(canvas, 0, 100, paint); |
86 paint.setImageFilter(SkDisplacementMapEffect::Create( | 86 paint.setImageFilter(SkDisplacementMapEffect::Create( |
87 SkDisplacementMapEffect::kB_ChannelSelectorType, | 87 SkDisplacementMapEffect::kB_ChannelSelectorType, |
88 SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ))->unr
ef(); | 88 SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ.get())
)->unref(); |
89 drawClippedBitmap(canvas, 100, 100, paint); | 89 drawClippedBitmap(canvas, 100, 100, paint); |
90 paint.setImageFilter(SkDisplacementMapEffect::Create( | 90 paint.setImageFilter(SkDisplacementMapEffect::Create( |
91 SkDisplacementMapEffect::kR_ChannelSelectorType, | 91 SkDisplacementMapEffect::kR_ChannelSelectorType, |
92 SkDisplacementMapEffect::kB_ChannelSelectorType, 40.0f, displ))->unr
ef(); | 92 SkDisplacementMapEffect::kB_ChannelSelectorType, 40.0f, displ.get())
)->unref(); |
93 drawClippedBitmap(canvas, 200, 100, paint); | 93 drawClippedBitmap(canvas, 200, 100, paint); |
94 paint.setImageFilter(SkDisplacementMapEffect::Create( | 94 paint.setImageFilter(SkDisplacementMapEffect::Create( |
95 SkDisplacementMapEffect::kG_ChannelSelectorType, | 95 SkDisplacementMapEffect::kG_ChannelSelectorType, |
96 SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ))->unr
ef(); | 96 SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ.get())
)->unref(); |
97 drawClippedBitmap(canvas, 300, 100, paint); | 97 drawClippedBitmap(canvas, 300, 100, paint); |
98 paint.setImageFilter(SkDisplacementMapEffect::Create( | 98 paint.setImageFilter(SkDisplacementMapEffect::Create( |
99 SkDisplacementMapEffect::kR_ChannelSelectorType, | 99 SkDisplacementMapEffect::kR_ChannelSelectorType, |
100 SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ))->unr
ef(); | 100 SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ.get())
)->unref(); |
101 drawClippedBitmap(canvas, 400, 100, paint); | 101 drawClippedBitmap(canvas, 400, 100, paint); |
102 | 102 |
103 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(30, 30, 40, 40)); | 103 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(30, 30, 40, 40)); |
104 paint.setImageFilter(SkDisplacementMapEffect::Create( | 104 paint.setImageFilter(SkDisplacementMapEffect::Create( |
105 SkDisplacementMapEffect::kR_ChannelSelectorType, | 105 SkDisplacementMapEffect::kR_ChannelSelectorType, |
106 SkDisplacementMapEffect::kG_ChannelSelectorType, | 106 SkDisplacementMapEffect::kG_ChannelSelectorType, |
107 0.0f, displ, nullptr, &cropRect))->unref(); | 107 0.0f, displ.get(), nullptr, &cropRect))->unref(); |
108 drawClippedBitmap(canvas, 0, 200, paint); | 108 drawClippedBitmap(canvas, 0, 200, paint); |
109 paint.setImageFilter(SkDisplacementMapEffect::Create( | 109 paint.setImageFilter(SkDisplacementMapEffect::Create( |
110 SkDisplacementMapEffect::kB_ChannelSelectorType, | 110 SkDisplacementMapEffect::kB_ChannelSelectorType, |
111 SkDisplacementMapEffect::kA_ChannelSelectorType, | 111 SkDisplacementMapEffect::kA_ChannelSelectorType, |
112 16.0f, displ, nullptr, &cropRect))->unref(); | 112 16.0f, displ.get(), nullptr, &cropRect))->unref(); |
113 drawClippedBitmap(canvas, 100, 200, paint); | 113 drawClippedBitmap(canvas, 100, 200, paint); |
114 paint.setImageFilter(SkDisplacementMapEffect::Create( | 114 paint.setImageFilter(SkDisplacementMapEffect::Create( |
115 SkDisplacementMapEffect::kR_ChannelSelectorType, | 115 SkDisplacementMapEffect::kR_ChannelSelectorType, |
116 SkDisplacementMapEffect::kB_ChannelSelectorType, | 116 SkDisplacementMapEffect::kB_ChannelSelectorType, |
117 32.0f, displ, nullptr, &cropRect))->unref(); | 117 32.0f, displ.get(), nullptr, &cropRect))->unref(); |
118 drawClippedBitmap(canvas, 200, 200, paint); | 118 drawClippedBitmap(canvas, 200, 200, paint); |
119 paint.setImageFilter(SkDisplacementMapEffect::Create( | 119 paint.setImageFilter(SkDisplacementMapEffect::Create( |
120 SkDisplacementMapEffect::kG_ChannelSelectorType, | 120 SkDisplacementMapEffect::kG_ChannelSelectorType, |
121 SkDisplacementMapEffect::kA_ChannelSelectorType, | 121 SkDisplacementMapEffect::kA_ChannelSelectorType, |
122 48.0f, displ, nullptr, &cropRect))->unref(); | 122 48.0f, displ.get(), nullptr, &cropRect))->unref(); |
123 drawClippedBitmap(canvas, 300, 200, paint); | 123 drawClippedBitmap(canvas, 300, 200, paint); |
124 paint.setImageFilter(SkDisplacementMapEffect::Create( | 124 paint.setImageFilter(SkDisplacementMapEffect::Create( |
125 SkDisplacementMapEffect::kR_ChannelSelectorType, | 125 SkDisplacementMapEffect::kR_ChannelSelectorType, |
126 SkDisplacementMapEffect::kA_ChannelSelectorType, | 126 SkDisplacementMapEffect::kA_ChannelSelectorType, |
127 64.0f, displ, nullptr, &cropRect))->unref(); | 127 64.0f, displ.get(), nullptr, &cropRect))->unref(); |
128 drawClippedBitmap(canvas, 400, 200, paint); | 128 drawClippedBitmap(canvas, 400, 200, paint); |
129 | 129 |
130 paint.setImageFilter(SkDisplacementMapEffect::Create( | 130 paint.setImageFilter(SkDisplacementMapEffect::Create( |
131 SkDisplacementMapEffect::kR_ChannelSelectorType, | 131 SkDisplacementMapEffect::kR_ChannelSelectorType, |
132 SkDisplacementMapEffect::kG_ChannelSelectorType, | 132 SkDisplacementMapEffect::kG_ChannelSelectorType, |
133 40.0f, displ, nullptr, &cropRect))->unref(); | 133 40.0f, displ.get(), nullptr, &cropRect))->unref(); |
134 drawClippedBitmap(canvas, 0, 300, paint); | 134 drawClippedBitmap(canvas, 0, 300, paint); |
135 paint.setImageFilter(SkDisplacementMapEffect::Create( | 135 paint.setImageFilter(SkDisplacementMapEffect::Create( |
136 SkDisplacementMapEffect::kB_ChannelSelectorType, | 136 SkDisplacementMapEffect::kB_ChannelSelectorType, |
137 SkDisplacementMapEffect::kA_ChannelSelectorType, | 137 SkDisplacementMapEffect::kA_ChannelSelectorType, |
138 40.0f, displ, nullptr, &cropRect))->unref(); | 138 40.0f, displ.get(), nullptr, &cropRect))->unref(); |
139 drawClippedBitmap(canvas, 100, 300, paint); | 139 drawClippedBitmap(canvas, 100, 300, paint); |
140 paint.setImageFilter(SkDisplacementMapEffect::Create( | 140 paint.setImageFilter(SkDisplacementMapEffect::Create( |
141 SkDisplacementMapEffect::kR_ChannelSelectorType, | 141 SkDisplacementMapEffect::kR_ChannelSelectorType, |
142 SkDisplacementMapEffect::kB_ChannelSelectorType, | 142 SkDisplacementMapEffect::kB_ChannelSelectorType, |
143 40.0f, displ, nullptr, &cropRect))->unref(); | 143 40.0f, displ.get(), nullptr, &cropRect))->unref(); |
144 drawClippedBitmap(canvas, 200, 300, paint); | 144 drawClippedBitmap(canvas, 200, 300, paint); |
145 paint.setImageFilter(SkDisplacementMapEffect::Create( | 145 paint.setImageFilter(SkDisplacementMapEffect::Create( |
146 SkDisplacementMapEffect::kG_ChannelSelectorType, | 146 SkDisplacementMapEffect::kG_ChannelSelectorType, |
147 SkDisplacementMapEffect::kA_ChannelSelectorType, | 147 SkDisplacementMapEffect::kA_ChannelSelectorType, |
148 40.0f, displ, nullptr, &cropRect))->unref(); | 148 40.0f, displ.get(), nullptr, &cropRect))->unref(); |
149 drawClippedBitmap(canvas, 300, 300, paint); | 149 drawClippedBitmap(canvas, 300, 300, paint); |
150 paint.setImageFilter(SkDisplacementMapEffect::Create( | 150 paint.setImageFilter(SkDisplacementMapEffect::Create( |
151 SkDisplacementMapEffect::kR_ChannelSelectorType, | 151 SkDisplacementMapEffect::kR_ChannelSelectorType, |
152 SkDisplacementMapEffect::kA_ChannelSelectorType, | 152 SkDisplacementMapEffect::kA_ChannelSelectorType, |
153 40.0f, displ, nullptr, &cropRect))->unref(); | 153 40.0f, displ.get(), nullptr, &cropRect))->unref(); |
154 drawClippedBitmap(canvas, 400, 300, paint); | 154 drawClippedBitmap(canvas, 400, 300, paint); |
155 | 155 |
156 // Test for negative scale. | 156 // Test for negative scale. |
157 paint.setImageFilter(SkDisplacementMapEffect::Create( | 157 paint.setImageFilter(SkDisplacementMapEffect::Create( |
158 SkDisplacementMapEffect::kG_ChannelSelectorType, | 158 SkDisplacementMapEffect::kG_ChannelSelectorType, |
159 SkDisplacementMapEffect::kA_ChannelSelectorType, | 159 SkDisplacementMapEffect::kA_ChannelSelectorType, |
160 -40.0f, displ))->unref(); | 160 -40.0f, displ.get()))->unref(); |
161 this->drawClippedBitmap(canvas, 500, 0, paint); | 161 this->drawClippedBitmap(canvas, 500, 0, paint); |
162 | 162 |
163 // Tests for images of different sizes | 163 // Tests for images of different sizes |
164 displ.reset(SkImageSource::Create(fSmall.get())); | 164 displ = SkImageSource::Make(fSmall); |
165 paint.setImageFilter(SkDisplacementMapEffect::Create( | 165 paint.setImageFilter(SkDisplacementMapEffect::Create( |
166 SkDisplacementMapEffect::kR_ChannelSelectorType, | 166 SkDisplacementMapEffect::kR_ChannelSelectorType, |
167 SkDisplacementMapEffect::kG_ChannelSelectorType, | 167 SkDisplacementMapEffect::kG_ChannelSelectorType, |
168 40.0f, displ))->unref(); | 168 40.0f, displ.get()))->unref(); |
169 drawClippedBitmap(canvas, 0, 400, paint); | 169 drawClippedBitmap(canvas, 0, 400, paint); |
170 displ.reset(SkImageSource::Create(fLarge.get())); | 170 displ = SkImageSource::Make(fLarge); |
171 paint.setImageFilter(SkDisplacementMapEffect::Create( | 171 paint.setImageFilter(SkDisplacementMapEffect::Create( |
172 SkDisplacementMapEffect::kB_ChannelSelectorType, | 172 SkDisplacementMapEffect::kB_ChannelSelectorType, |
173 SkDisplacementMapEffect::kA_ChannelSelectorType, | 173 SkDisplacementMapEffect::kA_ChannelSelectorType, |
174 40.0f, displ))->unref(); | 174 40.0f, displ.get()))->unref(); |
175 drawClippedBitmap(canvas, 100, 400, paint); | 175 drawClippedBitmap(canvas, 100, 400, paint); |
176 displ.reset(SkImageSource::Create(fLargeW.get())); | 176 displ = SkImageSource::Make(fLargeW); |
177 paint.setImageFilter(SkDisplacementMapEffect::Create( | 177 paint.setImageFilter(SkDisplacementMapEffect::Create( |
178 SkDisplacementMapEffect::kR_ChannelSelectorType, | 178 SkDisplacementMapEffect::kR_ChannelSelectorType, |
179 SkDisplacementMapEffect::kB_ChannelSelectorType, | 179 SkDisplacementMapEffect::kB_ChannelSelectorType, |
180 40.0f, displ))->unref(); | 180 40.0f, displ.get()))->unref(); |
181 drawClippedBitmap(canvas, 200, 400, paint); | 181 drawClippedBitmap(canvas, 200, 400, paint); |
182 displ.reset(SkImageSource::Create(fLargeH.get())); | 182 displ = SkImageSource::Make(fLargeH); |
183 paint.setImageFilter(SkDisplacementMapEffect::Create( | 183 paint.setImageFilter(SkDisplacementMapEffect::Create( |
184 SkDisplacementMapEffect::kG_ChannelSelectorType, | 184 SkDisplacementMapEffect::kG_ChannelSelectorType, |
185 SkDisplacementMapEffect::kA_ChannelSelectorType, | 185 SkDisplacementMapEffect::kA_ChannelSelectorType, |
186 40.0f, displ))->unref(); | 186 40.0f, displ.get()))->unref(); |
187 drawClippedBitmap(canvas, 300, 400, paint); | 187 drawClippedBitmap(canvas, 300, 400, paint); |
188 | 188 |
189 // Test for no given displacement input. In this case, both displacement | 189 // Test for no given displacement input. In this case, both displacement |
190 // and color should use the same bitmap, given to SkCanvas::drawBitmap() | 190 // and color should use the same bitmap, given to SkCanvas::drawBitmap() |
191 // as an input argument. | 191 // as an input argument. |
192 paint.setImageFilter(SkDisplacementMapEffect::Create( | 192 paint.setImageFilter(SkDisplacementMapEffect::Create( |
193 SkDisplacementMapEffect::kG_ChannelSelectorType, | 193 SkDisplacementMapEffect::kG_ChannelSelectorType, |
194 SkDisplacementMapEffect::kA_ChannelSelectorType, | 194 SkDisplacementMapEffect::kA_ChannelSelectorType, |
195 40.0f, nullptr))->unref(); | 195 40.0f, nullptr))->unref(); |
196 drawClippedBitmap(canvas, 400, 400, paint); | 196 drawClippedBitmap(canvas, 400, 400, paint); |
197 } | 197 } |
198 | 198 |
199 private: | 199 private: |
200 SkBitmap fBitmap; | 200 SkBitmap fBitmap; |
201 sk_sp<SkImage> fCheckerboard, fSmall, fLarge, fLargeW, fLargeH; | 201 sk_sp<SkImage> fCheckerboard, fSmall, fLarge, fLargeW, fLargeH; |
202 | 202 |
203 typedef GM INHERITED; | 203 typedef GM INHERITED; |
204 }; | 204 }; |
205 | 205 |
206 ////////////////////////////////////////////////////////////////////////////// | 206 ////////////////////////////////////////////////////////////////////////////// |
207 | 207 |
208 DEF_GM(return new DisplacementMapGM;) | 208 DEF_GM(return new DisplacementMapGM;) |
209 } | 209 } |
OLD | NEW |