OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "SkAutoPixmapStorage.h" | 8 #include "SkAutoPixmapStorage.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 sk_free(addr); | 167 sk_free(addr); |
168 }, | 168 }, |
169 nullptr)); | 169 nullptr)); |
170 pixmap.release(); | 170 pixmap.release(); |
171 test_image(img, reporter, true, false, kPad, kFullSize); | 171 test_image(img, reporter, true, false, kPad, kFullSize); |
172 } | 172 } |
173 } | 173 } |
174 | 174 |
175 | 175 |
176 #if SK_SUPPORT_GPU | 176 #if SK_SUPPORT_GPU |
177 | |
178 static void test_texture_backed(skiatest::Reporter* reporter, | |
179 const sk_sp<SkSpecialImage>& orig, | |
180 const sk_sp<SkSpecialImage>& gpuBacked) { | |
181 REPORTER_ASSERT(reporter, gpuBacked); | |
182 REPORTER_ASSERT(reporter, gpuBacked->peekTexture()); | |
183 REPORTER_ASSERT(reporter, gpuBacked->uniqueID() == orig->uniqueID()); | |
184 REPORTER_ASSERT(reporter, gpuBacked->subset().width() == orig->subset().widt
h() && | |
185 gpuBacked->subset().height() == orig->subset().hei
ght()); | |
186 } | |
187 | |
188 // Test out the SkSpecialImage::makeTextureImage entry point | |
189 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_MakeTexture, reporter, context)
{ | |
190 SkBitmap bm = create_bm(); | |
191 | |
192 const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmaller
Size); | |
193 | |
194 { | |
195 // raster | |
196 sk_sp<SkSpecialImage> rasterImage(SkSpecialImage::MakeFromRaster( | |
197 nullptr, | |
198 SkIRect:
:MakeWH(kFullSize, | |
199
kFullSize), | |
200 bm)); | |
201 | |
202 { | |
203 sk_sp<SkSpecialImage> fromRaster(rasterImage->makeTextureImage(nullp
tr, context)); | |
204 test_texture_backed(reporter, rasterImage, fromRaster); | |
205 } | |
206 | |
207 { | |
208 sk_sp<SkSpecialImage> subRasterImage(rasterImage->makeSubset(subset)
); | |
209 | |
210 sk_sp<SkSpecialImage> fromSubRaster(subRasterImage->makeTextureImage
(nullptr, context)); | |
211 test_texture_backed(reporter, subRasterImage, fromSubRaster); | |
212 } | |
213 } | |
214 | |
215 { | |
216 // gpu | |
217 GrSurfaceDesc desc; | |
218 desc.fConfig = kSkia8888_GrPixelConfig; | |
219 desc.fFlags = kNone_GrSurfaceFlags; | |
220 desc.fWidth = kFullSize; | |
221 desc.fHeight = kFullSize; | |
222 | |
223 SkAutoTUnref<GrTexture> texture(context->textureProvider()->createTextur
e(desc, | |
224
SkBudgeted::kNo, | |
225
bm.getPixels(), | |
226
0)); | |
227 if (!texture) { | |
228 return; | |
229 } | |
230 | |
231 sk_sp<SkSpecialImage> gpuImage(SkSpecialImage::MakeFromGpu( | |
232 nullptr, | |
233 SkIRect::MakeWH(
kFullSize, | |
234
kFullSize), | |
235 kNeedNewImageUni
queID_SpecialImage, | |
236 texture)); | |
237 | |
238 { | |
239 sk_sp<SkSpecialImage> fromGPU(gpuImage->makeTextureImage(nullptr, co
ntext)); | |
240 test_texture_backed(reporter, gpuImage, fromGPU); | |
241 } | |
242 | |
243 { | |
244 sk_sp<SkSpecialImage> subGPUImage(gpuImage->makeSubset(subset)); | |
245 | |
246 sk_sp<SkSpecialImage> fromSubGPU(subGPUImage->makeTextureImage(nullp
tr, context)); | |
247 test_texture_backed(reporter, subGPUImage, fromSubGPU); | |
248 } | |
249 } | |
250 } | |
251 | |
252 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_Gpu, reporter, context) { | 177 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_Gpu, reporter, context) { |
253 SkBitmap bm = create_bm(); | 178 SkBitmap bm = create_bm(); |
254 | 179 |
255 GrSurfaceDesc desc; | 180 GrSurfaceDesc desc; |
256 desc.fConfig = kSkia8888_GrPixelConfig; | 181 desc.fConfig = kSkia8888_GrPixelConfig; |
257 desc.fFlags = kNone_GrSurfaceFlags; | 182 desc.fFlags = kNone_GrSurfaceFlags; |
258 desc.fWidth = kFullSize; | 183 desc.fWidth = kFullSize; |
259 desc.fHeight = kFullSize; | 184 desc.fHeight = kFullSize; |
260 | 185 |
261 SkAutoTUnref<GrTexture> texture(context->textureProvider()->createTexture(de
sc, | 186 SkAutoTUnref<GrTexture> texture(context->textureProvider()->createTexture(de
sc, SkBudgeted::kNo, |
262 Sk
Budgeted::kNo, | |
263 bm
.getPixels(), 0)); | 187 bm
.getPixels(), 0)); |
264 if (!texture) { | 188 if (!texture) { |
265 return; | 189 return; |
266 } | 190 } |
267 | 191 |
268 sk_sp<SkSpecialImage> fullSImg(SkSpecialImage::MakeFromGpu( | 192 sk_sp<SkSpecialImage> fullSImg(SkSpecialImage::MakeFromGpu( |
269 nullptr, | 193 nullptr, |
270 SkIRect::MakeWH(kFul
lSize, kFullSize), | 194 SkIRect::MakeWH(kFul
lSize, kFullSize), |
271 kNeedNewImageUniqueI
D_SpecialImage, | 195 kNeedNewImageUniqueI
D_SpecialImage, |
272 texture)); | 196 texture)); |
273 | 197 |
274 const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmaller
Size); | 198 const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmaller
Size); |
275 | 199 |
276 { | 200 { |
277 sk_sp<SkSpecialImage> subSImg1(SkSpecialImage::MakeFromGpu( | 201 sk_sp<SkSpecialImage> subSImg1(SkSpecialImage::MakeFromGpu( |
278 nullptr, subset, | 202 nullptr, subset, |
279 kNeedNewImageUniq
ueID_SpecialImage, | 203 kNeedNewImageUniq
ueID_SpecialImage, |
280 texture)); | 204 texture)); |
281 test_image(subSImg1, reporter, false, true, kPad, kFullSize); | 205 test_image(subSImg1, reporter, false, true, kPad, kFullSize); |
282 } | 206 } |
283 | 207 |
284 { | 208 { |
285 sk_sp<SkSpecialImage> subSImg2(fullSImg->makeSubset(subset)); | 209 sk_sp<SkSpecialImage> subSImg2(fullSImg->makeSubset(subset)); |
286 test_image(subSImg2, reporter, false, true, kPad, kFullSize); | 210 test_image(subSImg2, reporter, false, true, kPad, kFullSize); |
287 } | 211 } |
288 } | 212 } |
289 | 213 |
290 #endif | 214 #endif |
OLD | NEW |