| 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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 nullptr, subset, pixmap, | 165 nullptr, subset, pixmap, |
| 166 [] (void* addr, void*) -> void {
sk_free(addr); }, | 166 [] (void* addr, void*) -> void {
sk_free(addr); }, |
| 167 nullptr)); | 167 nullptr)); |
| 168 pixmap.release(); | 168 pixmap.release(); |
| 169 test_image(img, reporter, true, false, kPad, kFullSize); | 169 test_image(img, reporter, true, false, kPad, kFullSize); |
| 170 } | 170 } |
| 171 } | 171 } |
| 172 | 172 |
| 173 | 173 |
| 174 #if SK_SUPPORT_GPU | 174 #if SK_SUPPORT_GPU |
| 175 |
| 176 static void test_texture_backed(skiatest::Reporter* reporter, |
| 177 SkSpecialImage* orig, |
| 178 SkSpecialImage* gpuBacked) { |
| 179 REPORTER_ASSERT(reporter, gpuBacked); |
| 180 REPORTER_ASSERT(reporter, gpuBacked->peekTexture()); |
| 181 REPORTER_ASSERT(reporter, gpuBacked->uniqueID() == orig->uniqueID()); |
| 182 REPORTER_ASSERT(reporter, gpuBacked->subset().width() == orig->subset().widt
h() && |
| 183 gpuBacked->subset().height() == orig->subset().hei
ght()); |
| 184 } |
| 185 |
| 186 // Test out the SkSpecialImage::makeTextureImage entry point |
| 187 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_MakeTexture, reporter, context)
{ |
| 188 SkBitmap bm = create_bm(); |
| 189 |
| 190 const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmaller
Size); |
| 191 |
| 192 { |
| 193 // raster |
| 194 SkAutoTUnref<SkSpecialImage> rasterImage(SkSpecialImage::NewFromRaster( |
| 195 nullptr, |
| 196 SkIRect::MakeWH
(kFullSize, |
| 197
kFullSize), |
| 198 bm)); |
| 199 |
| 200 { |
| 201 SkAutoTUnref<SkSpecialImage> fromRaster(rasterImage->makeTextureImag
e(nullptr, |
| 202
context)); |
| 203 test_texture_backed(reporter, rasterImage, fromRaster); |
| 204 } |
| 205 |
| 206 { |
| 207 SkAutoTUnref<SkSpecialImage> subRasterImage(rasterImage->extractSubs
et(subset)); |
| 208 |
| 209 SkAutoTUnref<SkSpecialImage> fromSubRaster(subRasterImage->makeTextu
reImage(nullptr, |
| 210
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 SkAutoTUnref<SkSpecialImage> gpuImage(SkSpecialImage::NewFromGpu( |
| 232 nullptr, |
| 233 SkIRect::MakeWH(
kFullSize, |
| 234
kFullSize), |
| 235 kNeedNewImageUni
queID_SpecialImage, |
| 236 texture)); |
| 237 |
| 238 { |
| 239 SkAutoTUnref<SkSpecialImage> fromGPU(gpuImage->makeTextureImage(null
ptr, context)); |
| 240 test_texture_backed(reporter, gpuImage, fromGPU); |
| 241 } |
| 242 |
| 243 { |
| 244 SkAutoTUnref<SkSpecialImage> subGPUImage(gpuImage->extractSubset(sub
set)); |
| 245 |
| 246 SkAutoTUnref<SkSpecialImage> fromSubGPU(subGPUImage->makeTextureImag
e(nullptr, |
| 247
context)); |
| 248 test_texture_backed(reporter, subGPUImage, fromSubGPU); |
| 249 } |
| 250 } |
| 251 } |
| 252 |
| 175 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_Gpu, reporter, context) { | 253 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_Gpu, reporter, context) { |
| 176 SkBitmap bm = create_bm(); | 254 SkBitmap bm = create_bm(); |
| 177 | 255 |
| 178 GrSurfaceDesc desc; | 256 GrSurfaceDesc desc; |
| 179 desc.fConfig = kSkia8888_GrPixelConfig; | 257 desc.fConfig = kSkia8888_GrPixelConfig; |
| 180 desc.fFlags = kNone_GrSurfaceFlags; | 258 desc.fFlags = kNone_GrSurfaceFlags; |
| 181 desc.fWidth = kFullSize; | 259 desc.fWidth = kFullSize; |
| 182 desc.fHeight = kFullSize; | 260 desc.fHeight = kFullSize; |
| 183 | 261 |
| 184 SkAutoTUnref<GrTexture> texture(context->textureProvider()->createTexture(de
sc, SkBudgeted::kNo, | 262 SkAutoTUnref<GrTexture> texture(context->textureProvider()->createTexture(de
sc, |
| 263 Sk
Budgeted::kNo, |
| 185 bm
.getPixels(), 0)); | 264 bm
.getPixels(), 0)); |
| 186 if (!texture) { | 265 if (!texture) { |
| 187 return; | 266 return; |
| 188 } | 267 } |
| 189 | 268 |
| 190 SkAutoTUnref<SkSpecialImage> fullSImg(SkSpecialImage::NewFromGpu( | 269 SkAutoTUnref<SkSpecialImage> fullSImg(SkSpecialImage::NewFromGpu( |
| 191 nullptr, | 270 nullptr, |
| 192 SkIRect::MakeWH(kFul
lSize, kFullSize), | 271 SkIRect::MakeWH(kFul
lSize, kFullSize), |
| 193 kNeedNewImageUniqueI
D_SpecialImage, | 272 kNeedNewImageUniqueI
D_SpecialImage, |
| 194 texture)); | 273 texture)); |
| 195 | 274 |
| 196 const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmaller
Size); | 275 const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmaller
Size); |
| 197 | 276 |
| 198 { | 277 { |
| 199 SkAutoTUnref<SkSpecialImage> subSImg1(SkSpecialImage::NewFromGpu( | 278 SkAutoTUnref<SkSpecialImage> subSImg1(SkSpecialImage::NewFromGpu( |
| 200 nullptr, subset, | 279 nullptr, subset, |
| 201 kNeedNewImageUniq
ueID_SpecialImage, | 280 kNeedNewImageUniq
ueID_SpecialImage, |
| 202 texture)); | 281 texture)); |
| 203 test_image(subSImg1, reporter, false, true, kPad, kFullSize); | 282 test_image(subSImg1, reporter, false, true, kPad, kFullSize); |
| 204 } | 283 } |
| 205 | 284 |
| 206 { | 285 { |
| 207 SkAutoTUnref<SkSpecialImage> subSImg2(fullSImg->extractSubset(subset)); | 286 SkAutoTUnref<SkSpecialImage> subSImg2(fullSImg->extractSubset(subset)); |
| 208 test_image(subSImg2, reporter, false, true, kPad, kFullSize); | 287 test_image(subSImg2, reporter, false, true, kPad, kFullSize); |
| 209 } | 288 } |
| 210 } | 289 } |
| 211 | 290 |
| 212 #endif | 291 #endif |
| OLD | NEW |