robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file |
| 6 | */ |
| 7 | |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 8 | #include "SkAutoPixmapStorage.h" |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 9 | #include "SkBitmap.h" |
| 10 | #include "SkCanvas.h" |
| 11 | #include "SkImage.h" |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 12 | #include "SkPixmap.h" |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 13 | #include "SkSpecialImage.h" |
| 14 | #include "SkSpecialSurface.h" |
robertphillips | b4bd11e | 2016-03-21 13:44:18 -0700 | [diff] [blame] | 15 | #include "SkSurface.h" |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 16 | #include "Test.h" |
| 17 | |
| 18 | #if SK_SUPPORT_GPU |
| 19 | #include "GrContext.h" |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 20 | #include "GrSurfaceProxy.h" |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 21 | #endif |
| 22 | |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 23 | |
| 24 | // This test creates backing resources exactly sized to [kFullSize x kFullSize]. |
| 25 | // It then wraps them in an SkSpecialImage with only the center (red) region being active. |
| 26 | // It then draws the SkSpecialImage to a full sized (all blue) canvas and checks that none |
| 27 | // of the inactive (green) region leaked out. |
| 28 | |
| 29 | static const int kSmallerSize = 10; |
| 30 | static const int kPad = 3; |
| 31 | static const int kFullSize = kSmallerSize + 2 * kPad; |
| 32 | |
| 33 | // Create a bitmap with red in the center and green around it |
| 34 | static SkBitmap create_bm() { |
| 35 | SkBitmap bm; |
| 36 | bm.allocN32Pixels(kFullSize, kFullSize, true); |
| 37 | |
| 38 | SkCanvas temp(bm); |
| 39 | |
| 40 | temp.clear(SK_ColorGREEN); |
| 41 | SkPaint p; |
| 42 | p.setColor(SK_ColorRED); |
| 43 | p.setAntiAlias(false); |
| 44 | |
| 45 | temp.drawRect(SkRect::MakeXYWH(SkIntToScalar(kPad), SkIntToScalar(kPad), |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 46 | SkIntToScalar(kSmallerSize), SkIntToScalar(kSmallerSize)), |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 47 | p); |
| 48 | |
| 49 | return bm; |
| 50 | } |
| 51 | |
| 52 | // Basic test of the SkSpecialImage public API (e.g., peekTexture, peekPixels & draw) |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 53 | static void test_image(const sk_sp<SkSpecialImage>& img, skiatest::Reporter* reporter, |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 54 | GrContext* context, bool peekTextureSucceeds, |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 55 | int offset, int size) { |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame] | 56 | const SkIRect subset = img->subset(); |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 57 | REPORTER_ASSERT(reporter, offset == subset.left()); |
| 58 | REPORTER_ASSERT(reporter, offset == subset.top()); |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 59 | REPORTER_ASSERT(reporter, kSmallerSize == subset.width()); |
| 60 | REPORTER_ASSERT(reporter, kSmallerSize == subset.height()); |
| 61 | |
| 62 | //-------------- |
robertphillips | b4bd11e | 2016-03-21 13:44:18 -0700 | [diff] [blame] | 63 | // Test that peekTexture reports the correct backing type |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 64 | REPORTER_ASSERT(reporter, peekTextureSucceeds == img->isTextureBacked()); |
| 65 | |
| 66 | #if SK_SUPPORT_GPU |
| 67 | //-------------- |
| 68 | // Test getTextureAsRef - as long as there is a context this should succeed |
| 69 | if (context) { |
| 70 | sk_sp<GrTexture> texture(img->asTextureRef(context)); |
| 71 | REPORTER_ASSERT(reporter, texture); |
| 72 | } |
| 73 | #endif |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 74 | |
| 75 | //-------------- |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 76 | // Test getROPixels - this should always succeed regardless of backing store |
| 77 | SkBitmap bitmap; |
| 78 | REPORTER_ASSERT(reporter, img->getROPixels(&bitmap)); |
robertphillips | ed086ca | 2016-04-26 15:02:25 -0700 | [diff] [blame] | 79 | if (context) { |
| 80 | REPORTER_ASSERT(reporter, kSmallerSize == bitmap.width()); |
| 81 | REPORTER_ASSERT(reporter, kSmallerSize == bitmap.height()); |
| 82 | } else { |
| 83 | REPORTER_ASSERT(reporter, size == bitmap.width()); |
| 84 | REPORTER_ASSERT(reporter, size == bitmap.height()); |
| 85 | } |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 86 | |
| 87 | //-------------- |
robertphillips | b4bd11e | 2016-03-21 13:44:18 -0700 | [diff] [blame] | 88 | // Test that draw restricts itself to the subset |
brianosman | eed6b0e | 2016-09-23 13:04:05 -0700 | [diff] [blame] | 89 | SkImageFilter::OutputProperties outProps(img->getColorSpace()); |
| 90 | sk_sp<SkSpecialSurface> surf(img->makeSurface(outProps, SkISize::Make(kFullSize, kFullSize), |
| 91 | kOpaque_SkAlphaType)); |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 92 | |
| 93 | SkCanvas* canvas = surf->getCanvas(); |
| 94 | |
| 95 | canvas->clear(SK_ColorBLUE); |
robertphillips | e8c3497 | 2016-02-16 12:09:36 -0800 | [diff] [blame] | 96 | img->draw(canvas, SkIntToScalar(kPad), SkIntToScalar(kPad), nullptr); |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 97 | |
| 98 | SkBitmap bm; |
| 99 | bm.allocN32Pixels(kFullSize, kFullSize, true); |
| 100 | |
| 101 | bool result = canvas->readPixels(bm.info(), bm.getPixels(), bm.rowBytes(), 0, 0); |
| 102 | SkASSERT_RELEASE(result); |
| 103 | |
| 104 | // Only the center (red) portion should've been drawn into the canvas |
| 105 | REPORTER_ASSERT(reporter, SK_ColorBLUE == bm.getColor(kPad-1, kPad-1)); |
| 106 | REPORTER_ASSERT(reporter, SK_ColorRED == bm.getColor(kPad, kPad)); |
| 107 | REPORTER_ASSERT(reporter, SK_ColorRED == bm.getColor(kSmallerSize+kPad-1, |
| 108 | kSmallerSize+kPad-1)); |
| 109 | REPORTER_ASSERT(reporter, SK_ColorBLUE == bm.getColor(kSmallerSize+kPad, |
| 110 | kSmallerSize+kPad)); |
robertphillips | b4bd11e | 2016-03-21 13:44:18 -0700 | [diff] [blame] | 111 | |
| 112 | //-------------- |
| 113 | // Test that makeTightSubset & makeTightSurface return appropriately sized objects |
| 114 | // of the correct backing type |
| 115 | SkIRect newSubset = SkIRect::MakeWH(subset.width(), subset.height()); |
| 116 | { |
| 117 | sk_sp<SkImage> tightImg(img->makeTightSubset(newSubset)); |
| 118 | |
| 119 | REPORTER_ASSERT(reporter, tightImg->width() == subset.width()); |
| 120 | REPORTER_ASSERT(reporter, tightImg->height() == subset.height()); |
| 121 | REPORTER_ASSERT(reporter, peekTextureSucceeds == !!tightImg->getTexture()); |
| 122 | SkPixmap tmpPixmap; |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 123 | REPORTER_ASSERT(reporter, peekTextureSucceeds != !!tightImg->peekPixels(&tmpPixmap)); |
robertphillips | b4bd11e | 2016-03-21 13:44:18 -0700 | [diff] [blame] | 124 | } |
| 125 | { |
brianosman | eed6b0e | 2016-09-23 13:04:05 -0700 | [diff] [blame] | 126 | SkImageFilter::OutputProperties outProps(img->getColorSpace()); |
| 127 | sk_sp<SkSurface> tightSurf(img->makeTightSurface(outProps, subset.size())); |
robertphillips | b4bd11e | 2016-03-21 13:44:18 -0700 | [diff] [blame] | 128 | |
| 129 | REPORTER_ASSERT(reporter, tightSurf->width() == subset.width()); |
| 130 | REPORTER_ASSERT(reporter, tightSurf->height() == subset.height()); |
| 131 | REPORTER_ASSERT(reporter, peekTextureSucceeds == |
| 132 | !!tightSurf->getTextureHandle(SkSurface::kDiscardWrite_BackendHandleAccess)); |
| 133 | SkPixmap tmpPixmap; |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 134 | REPORTER_ASSERT(reporter, peekTextureSucceeds != !!tightSurf->peekPixels(&tmpPixmap)); |
robertphillips | b4bd11e | 2016-03-21 13:44:18 -0700 | [diff] [blame] | 135 | } |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | DEF_TEST(SpecialImage_Raster, reporter) { |
| 139 | SkBitmap bm = create_bm(); |
| 140 | |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 141 | sk_sp<SkSpecialImage> fullSImage(SkSpecialImage::MakeFromRaster( |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 142 | SkIRect::MakeWH(kFullSize, kFullSize), |
| 143 | bm)); |
| 144 | |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 145 | const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize); |
| 146 | |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 147 | { |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame] | 148 | sk_sp<SkSpecialImage> subSImg1(SkSpecialImage::MakeFromRaster(subset, bm)); |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 149 | test_image(subSImg1, reporter, nullptr, false, kPad, kFullSize); |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | { |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 153 | sk_sp<SkSpecialImage> subSImg2(fullSImage->makeSubset(subset)); |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 154 | test_image(subSImg2, reporter, nullptr, false, 0, kSmallerSize); |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 155 | } |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 156 | } |
| 157 | |
Brian Osman | 7992da3 | 2016-11-18 11:28:24 -0500 | [diff] [blame] | 158 | static void test_specialimage_image(skiatest::Reporter* reporter, |
| 159 | SkDestinationSurfaceColorMode colorMode) { |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 160 | SkBitmap bm = create_bm(); |
| 161 | |
reed | 9ce9d67 | 2016-03-17 10:51:11 -0700 | [diff] [blame] | 162 | sk_sp<SkImage> fullImage(SkImage::MakeFromBitmap(bm)); |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 163 | |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 164 | sk_sp<SkSpecialImage> fullSImage(SkSpecialImage::MakeFromImage( |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 165 | SkIRect::MakeWH(kFullSize, kFullSize), |
Brian Osman | 7992da3 | 2016-11-18 11:28:24 -0500 | [diff] [blame] | 166 | fullImage, colorMode)); |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 167 | |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 168 | const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize); |
| 169 | |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 170 | { |
Brian Osman | 7992da3 | 2016-11-18 11:28:24 -0500 | [diff] [blame] | 171 | sk_sp<SkSpecialImage> subSImg1(SkSpecialImage::MakeFromImage(subset, fullImage, colorMode)); |
robertphillips | ed086ca | 2016-04-26 15:02:25 -0700 | [diff] [blame] | 172 | test_image(subSImg1, reporter, nullptr, false, kPad, kFullSize); |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | { |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 176 | sk_sp<SkSpecialImage> subSImg2(fullSImage->makeSubset(subset)); |
robertphillips | ed086ca | 2016-04-26 15:02:25 -0700 | [diff] [blame] | 177 | test_image(subSImg2, reporter, nullptr, false, 0, kSmallerSize); |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 178 | } |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 179 | } |
| 180 | |
Brian Osman | 7992da3 | 2016-11-18 11:28:24 -0500 | [diff] [blame] | 181 | DEF_TEST(SpecialImage_Image_Legacy, reporter) { |
| 182 | test_specialimage_image(reporter, SkDestinationSurfaceColorMode::kLegacy); |
| 183 | } |
| 184 | |
| 185 | DEF_TEST(SpecialImage_Image_ColorSpaceAware, reporter) { |
| 186 | test_specialimage_image(reporter, SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware); |
| 187 | } |
| 188 | |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 189 | #if SK_SUPPORT_GPU |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 190 | |
| 191 | static void test_texture_backed(skiatest::Reporter* reporter, |
| 192 | const sk_sp<SkSpecialImage>& orig, |
| 193 | const sk_sp<SkSpecialImage>& gpuBacked) { |
| 194 | REPORTER_ASSERT(reporter, gpuBacked); |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 195 | REPORTER_ASSERT(reporter, gpuBacked->isTextureBacked()); |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 196 | REPORTER_ASSERT(reporter, gpuBacked->uniqueID() == orig->uniqueID()); |
| 197 | REPORTER_ASSERT(reporter, gpuBacked->subset().width() == orig->subset().width() && |
| 198 | gpuBacked->subset().height() == orig->subset().height()); |
brianosman | afbf71d | 2016-07-21 07:15:37 -0700 | [diff] [blame] | 199 | REPORTER_ASSERT(reporter, gpuBacked->getColorSpace() == orig->getColorSpace()); |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | // Test out the SkSpecialImage::makeTextureImage entry point |
bsalomon | 68d9134 | 2016-04-12 09:59:58 -0700 | [diff] [blame] | 203 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_MakeTexture, reporter, ctxInfo) { |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 204 | GrContext* context = ctxInfo.grContext(); |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 205 | SkBitmap bm = create_bm(); |
| 206 | |
| 207 | const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize); |
| 208 | |
| 209 | { |
| 210 | // raster |
| 211 | sk_sp<SkSpecialImage> rasterImage(SkSpecialImage::MakeFromRaster( |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 212 | SkIRect::MakeWH(kFullSize, |
| 213 | kFullSize), |
| 214 | bm)); |
| 215 | |
| 216 | { |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame] | 217 | sk_sp<SkSpecialImage> fromRaster(rasterImage->makeTextureImage(context)); |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 218 | test_texture_backed(reporter, rasterImage, fromRaster); |
| 219 | } |
| 220 | |
| 221 | { |
| 222 | sk_sp<SkSpecialImage> subRasterImage(rasterImage->makeSubset(subset)); |
| 223 | |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame] | 224 | sk_sp<SkSpecialImage> fromSubRaster(subRasterImage->makeTextureImage(context)); |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 225 | test_texture_backed(reporter, subRasterImage, fromSubRaster); |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | { |
| 230 | // gpu |
| 231 | GrSurfaceDesc desc; |
| 232 | desc.fConfig = kSkia8888_GrPixelConfig; |
| 233 | desc.fFlags = kNone_GrSurfaceFlags; |
| 234 | desc.fWidth = kFullSize; |
| 235 | desc.fHeight = kFullSize; |
| 236 | |
robertphillips | c91fd34 | 2016-04-25 12:32:54 -0700 | [diff] [blame] | 237 | sk_sp<GrTexture> texture(context->textureProvider()->createTexture(desc, |
| 238 | SkBudgeted::kNo, |
| 239 | bm.getPixels(), |
| 240 | 0)); |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 241 | if (!texture) { |
| 242 | return; |
| 243 | } |
| 244 | |
| 245 | sk_sp<SkSpecialImage> gpuImage(SkSpecialImage::MakeFromGpu( |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 246 | SkIRect::MakeWH(kFullSize, |
| 247 | kFullSize), |
| 248 | kNeedNewImageUniqueID_SpecialImage, |
brianosman | afbf71d | 2016-07-21 07:15:37 -0700 | [diff] [blame] | 249 | std::move(texture), nullptr)); |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 250 | |
| 251 | { |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame] | 252 | sk_sp<SkSpecialImage> fromGPU(gpuImage->makeTextureImage(context)); |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 253 | test_texture_backed(reporter, gpuImage, fromGPU); |
| 254 | } |
| 255 | |
| 256 | { |
| 257 | sk_sp<SkSpecialImage> subGPUImage(gpuImage->makeSubset(subset)); |
| 258 | |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame] | 259 | sk_sp<SkSpecialImage> fromSubGPU(subGPUImage->makeTextureImage(context)); |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 260 | test_texture_backed(reporter, subGPUImage, fromSubGPU); |
| 261 | } |
| 262 | } |
| 263 | } |
| 264 | |
bsalomon | 68d9134 | 2016-04-12 09:59:58 -0700 | [diff] [blame] | 265 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_Gpu, reporter, ctxInfo) { |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 266 | GrContext* context = ctxInfo.grContext(); |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 267 | SkBitmap bm = create_bm(); |
| 268 | |
| 269 | GrSurfaceDesc desc; |
| 270 | desc.fConfig = kSkia8888_GrPixelConfig; |
| 271 | desc.fFlags = kNone_GrSurfaceFlags; |
| 272 | desc.fWidth = kFullSize; |
| 273 | desc.fHeight = kFullSize; |
| 274 | |
robertphillips | c91fd34 | 2016-04-25 12:32:54 -0700 | [diff] [blame] | 275 | sk_sp<GrTexture> texture(context->textureProvider()->createTexture(desc, |
| 276 | SkBudgeted::kNo, |
| 277 | bm.getPixels(), 0)); |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 278 | if (!texture) { |
| 279 | return; |
| 280 | } |
| 281 | |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 282 | sk_sp<SkSpecialImage> fullSImg(SkSpecialImage::MakeFromGpu( |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 283 | SkIRect::MakeWH(kFullSize, kFullSize), |
| 284 | kNeedNewImageUniqueID_SpecialImage, |
brianosman | afbf71d | 2016-07-21 07:15:37 -0700 | [diff] [blame] | 285 | texture, nullptr)); |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 286 | |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 287 | const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize); |
| 288 | |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 289 | { |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 290 | sk_sp<SkSpecialImage> subSImg1(SkSpecialImage::MakeFromGpu( |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame] | 291 | subset, |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 292 | kNeedNewImageUniqueID_SpecialImage, |
brianosman | afbf71d | 2016-07-21 07:15:37 -0700 | [diff] [blame] | 293 | texture, nullptr)); |
robertphillips | ed086ca | 2016-04-26 15:02:25 -0700 | [diff] [blame] | 294 | test_image(subSImg1, reporter, context, true, kPad, kFullSize); |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | { |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 298 | sk_sp<SkSpecialImage> subSImg2(fullSImg->makeSubset(subset)); |
robertphillips | ed086ca | 2016-04-26 15:02:25 -0700 | [diff] [blame] | 299 | test_image(subSImg2, reporter, context, true, kPad, kFullSize); |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 300 | } |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 301 | } |
| 302 | |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 303 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_DeferredGpu, reporter, ctxInfo) { |
| 304 | GrContext* context = ctxInfo.grContext(); |
| 305 | SkBitmap bm = create_bm(); |
| 306 | |
| 307 | GrSurfaceDesc desc; |
| 308 | desc.fConfig = kSkia8888_GrPixelConfig; |
| 309 | desc.fFlags = kNone_GrSurfaceFlags; |
| 310 | desc.fWidth = kFullSize; |
| 311 | desc.fHeight = kFullSize; |
| 312 | |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 313 | sk_sp<GrSurfaceProxy> proxy(GrSurfaceProxy::MakeDeferred(*context->caps(), |
| 314 | context->textureProvider(), |
| 315 | desc, SkBudgeted::kNo, |
| 316 | bm.getPixels(), 0)); |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 317 | if (!proxy) { |
| 318 | return; |
| 319 | } |
| 320 | |
| 321 | sk_sp<SkSpecialImage> fullSImg(SkSpecialImage::MakeDeferredFromGpu( |
| 322 | context, |
| 323 | SkIRect::MakeWH(kFullSize, kFullSize), |
| 324 | kNeedNewImageUniqueID_SpecialImage, |
| 325 | proxy, nullptr)); |
| 326 | |
| 327 | const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize); |
| 328 | |
| 329 | { |
| 330 | sk_sp<SkSpecialImage> subSImg1(SkSpecialImage::MakeDeferredFromGpu( |
| 331 | context, |
| 332 | subset, |
| 333 | kNeedNewImageUniqueID_SpecialImage, |
| 334 | proxy, nullptr)); |
| 335 | test_image(subSImg1, reporter, context, true, kPad, kFullSize); |
| 336 | } |
| 337 | |
| 338 | { |
| 339 | sk_sp<SkSpecialImage> subSImg2(fullSImg->makeSubset(subset)); |
| 340 | test_image(subSImg2, reporter, context, true, kPad, kFullSize); |
| 341 | } |
| 342 | } |
| 343 | |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 344 | #endif |