| 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 "Test.h" | 8 #include "Test.h" |
| 9 | 9 |
| 10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmaller
Size); | 140 const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmaller
Size); |
| 141 | 141 |
| 142 SkAutoTUnref<SkSpecialImage> subsetImg(SkSpecialImage::NewFromRaster(nullptr
, subset, srcBM)); | 142 SkAutoTUnref<SkSpecialImage> subsetImg(SkSpecialImage::NewFromRaster(nullptr
, subset, srcBM)); |
| 143 | 143 |
| 144 test_find_existing(reporter, fullImg, subsetImg); | 144 test_find_existing(reporter, fullImg, subsetImg); |
| 145 test_dont_find_if_diff_key(reporter, fullImg, subsetImg); | 145 test_dont_find_if_diff_key(reporter, fullImg, subsetImg); |
| 146 test_internal_purge(reporter, fullImg); | 146 test_internal_purge(reporter, fullImg); |
| 147 test_explicit_purging(reporter, fullImg, subsetImg); | 147 test_explicit_purging(reporter, fullImg, subsetImg); |
| 148 } | 148 } |
| 149 | 149 |
| 150 DEF_TEST(ImageFilterCache_ImageBacked, reporter) { | |
| 151 SkBitmap srcBM = create_bm(); | |
| 152 | 150 |
| 153 SkAutoTUnref<SkImage> srcImage(SkImage::NewFromBitmap(srcBM)); | 151 // Shared test code for both the raster and gpu-backed image cases |
| 154 | 152 static void test_image_backed(skiatest::Reporter* reporter, SkImage* srcImage) { |
| 155 const SkIRect& full = SkIRect::MakeWH(kFullSize, kFullSize); | 153 const SkIRect& full = SkIRect::MakeWH(kFullSize, kFullSize); |
| 156 | 154 |
| 157 SkAutoTUnref<SkSpecialImage> fullImg(SkSpecialImage::NewFromImage(full, srcI
mage)); | 155 SkAutoTUnref<SkSpecialImage> fullImg(SkSpecialImage::NewFromImage(full, srcI
mage)); |
| 158 | 156 |
| 159 const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmaller
Size); | 157 const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmaller
Size); |
| 160 | 158 |
| 161 SkAutoTUnref<SkSpecialImage> subsetImg(SkSpecialImage::NewFromImage(subset,
srcImage)); | 159 SkAutoTUnref<SkSpecialImage> subsetImg(SkSpecialImage::NewFromImage(subset,
srcImage)); |
| 162 | 160 |
| 163 test_find_existing(reporter, fullImg, subsetImg); | 161 test_find_existing(reporter, fullImg, subsetImg); |
| 164 test_dont_find_if_diff_key(reporter, fullImg, subsetImg); | 162 test_dont_find_if_diff_key(reporter, fullImg, subsetImg); |
| 165 test_internal_purge(reporter, fullImg); | 163 test_internal_purge(reporter, fullImg); |
| 166 test_explicit_purging(reporter, fullImg, subsetImg); | 164 test_explicit_purging(reporter, fullImg, subsetImg); |
| 167 } | 165 } |
| 168 | 166 |
| 167 DEF_TEST(ImageFilterCache_ImageBackedRaster, reporter) { |
| 168 SkBitmap srcBM = create_bm(); |
| 169 |
| 170 SkAutoTUnref<SkImage> srcImage(SkImage::NewFromBitmap(srcBM)); |
| 171 |
| 172 test_image_backed(reporter, srcImage); |
| 173 } |
| 174 |
| 169 #if SK_SUPPORT_GPU | 175 #if SK_SUPPORT_GPU |
| 170 #include "GrContext.h" | 176 #include "GrContext.h" |
| 171 | 177 |
| 172 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCache_GPUBacked, reporter, context
) { | 178 static GrTexture* create_texture(GrContext* context) { |
| 173 SkBitmap srcBM = create_bm(); | 179 SkBitmap srcBM = create_bm(); |
| 174 | 180 |
| 175 GrSurfaceDesc desc; | 181 GrSurfaceDesc desc; |
| 176 desc.fConfig = kSkia8888_GrPixelConfig; | 182 desc.fConfig = kSkia8888_GrPixelConfig; |
| 177 desc.fFlags = kNone_GrSurfaceFlags; | 183 desc.fFlags = kNone_GrSurfaceFlags; |
| 178 desc.fWidth = kFullSize; | 184 desc.fWidth = kFullSize; |
| 179 desc.fHeight = kFullSize; | 185 desc.fHeight = kFullSize; |
| 180 | 186 |
| 181 SkAutoTUnref<GrTexture> srcTexture(context->textureProvider()->createTexture
(desc, false, | 187 return context->textureProvider()->createTexture(desc, false, srcBM.getPixel
s(), 0); |
| 182
srcBM.getPixels(), | 188 } |
| 183
0)); | 189 |
| 190 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCache_ImageBackedGPU, reporter, co
ntext) { |
| 191 SkAutoTUnref<GrTexture> srcTexture(create_texture(context)); |
| 184 if (!srcTexture) { | 192 if (!srcTexture) { |
| 185 return; | 193 return; |
| 186 } | 194 } |
| 195 |
| 196 GrBackendTextureDesc backendDesc; |
| 197 backendDesc.fConfig = kSkia8888_GrPixelConfig; |
| 198 backendDesc.fFlags = kNone_GrBackendTextureFlag; |
| 199 backendDesc.fWidth = kFullSize; |
| 200 backendDesc.fHeight = kFullSize; |
| 201 backendDesc.fSampleCnt = 0; |
| 202 backendDesc.fTextureHandle = srcTexture->getTextureHandle(); |
| 203 SkAutoTUnref<SkImage> srcImage(SkImage::NewFromTexture(context, backendDesc, |
| 204 kPremul_SkAlphaType))
; |
| 205 if (!srcImage) { |
| 206 return; |
| 207 } |
| 208 |
| 209 test_image_backed(reporter, srcImage); |
| 210 } |
| 211 |
| 212 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCache_GPUBacked, reporter, context
) { |
| 213 |
| 214 SkAutoTUnref<GrTexture> srcTexture(create_texture(context)); |
| 215 if (!srcTexture) { |
| 216 return; |
| 217 } |
| 187 | 218 |
| 188 const SkIRect& full = SkIRect::MakeWH(kFullSize, kFullSize); | 219 const SkIRect& full = SkIRect::MakeWH(kFullSize, kFullSize); |
| 189 | 220 |
| 190 SkAutoTUnref<SkSpecialImage> fullImg(SkSpecialImage::NewFromGpu( | 221 SkAutoTUnref<SkSpecialImage> fullImg(SkSpecialImage::NewFromGpu( |
| 191 nullptr, full, | 222 nullptr, full, |
| 192 kNeedNewImageUni
queID_SpecialImage, | 223 kNeedNewImageUni
queID_SpecialImage, |
| 193 srcTexture)); | 224 srcTexture)); |
| 194 | 225 |
| 195 const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmaller
Size); | 226 const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmaller
Size); |
| 196 | 227 |
| 197 SkAutoTUnref<SkSpecialImage> subsetImg(SkSpecialImage::NewFromGpu( | 228 SkAutoTUnref<SkSpecialImage> subsetImg(SkSpecialImage::NewFromGpu( |
| 198 nullptr, subset,
| 229 nullptr, subset,
|
| 199 kNeedNewImageUni
queID_SpecialImage, | 230 kNeedNewImageUni
queID_SpecialImage, |
| 200 srcTexture)); | 231 srcTexture)); |
| 201 | 232 |
| 202 test_find_existing(reporter, fullImg, subsetImg); | 233 test_find_existing(reporter, fullImg, subsetImg); |
| 203 test_dont_find_if_diff_key(reporter, fullImg, subsetImg); | 234 test_dont_find_if_diff_key(reporter, fullImg, subsetImg); |
| 204 test_internal_purge(reporter, fullImg); | 235 test_internal_purge(reporter, fullImg); |
| 205 test_explicit_purging(reporter, fullImg, subsetImg); | 236 test_explicit_purging(reporter, fullImg, subsetImg); |
| 206 } | 237 } |
| 207 #endif | 238 #endif |
| 208 | 239 |
| OLD | NEW |