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), |
Matt Sarett | cb6266b | 2017-01-17 10:48:53 -0500 | [diff] [blame] | 91 | kPremul_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; |
Matt Sarett | cb6266b | 2017-01-17 10:48:53 -0500 | [diff] [blame] | 99 | bm.allocN32Pixels(kFullSize, kFullSize, false); |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 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 | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 158 | static void test_specialimage_image(skiatest::Reporter* reporter, SkColorSpace* dstColorSpace) { |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 159 | SkBitmap bm = create_bm(); |
| 160 | |
reed | 9ce9d67 | 2016-03-17 10:51:11 -0700 | [diff] [blame] | 161 | sk_sp<SkImage> fullImage(SkImage::MakeFromBitmap(bm)); |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 162 | |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 163 | sk_sp<SkSpecialImage> fullSImage(SkSpecialImage::MakeFromImage( |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 164 | SkIRect::MakeWH(kFullSize, kFullSize), |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 165 | fullImage, dstColorSpace)); |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 166 | |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 167 | const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize); |
| 168 | |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 169 | { |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 170 | sk_sp<SkSpecialImage> subSImg1(SkSpecialImage::MakeFromImage(subset, fullImage, |
| 171 | dstColorSpace)); |
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) { |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 182 | SkColorSpace* legacyColorSpace = nullptr; |
| 183 | test_specialimage_image(reporter, legacyColorSpace); |
Brian Osman | 7992da3 | 2016-11-18 11:28:24 -0500 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | DEF_TEST(SpecialImage_Image_ColorSpaceAware, reporter) { |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 187 | sk_sp<SkColorSpace> srgbColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named); |
| 188 | test_specialimage_image(reporter, srgbColorSpace.get()); |
Brian Osman | 7992da3 | 2016-11-18 11:28:24 -0500 | [diff] [blame] | 189 | } |
| 190 | |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 191 | #if SK_SUPPORT_GPU |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 192 | |
| 193 | static void test_texture_backed(skiatest::Reporter* reporter, |
| 194 | const sk_sp<SkSpecialImage>& orig, |
| 195 | const sk_sp<SkSpecialImage>& gpuBacked) { |
| 196 | REPORTER_ASSERT(reporter, gpuBacked); |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 197 | REPORTER_ASSERT(reporter, gpuBacked->isTextureBacked()); |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 198 | REPORTER_ASSERT(reporter, gpuBacked->uniqueID() == orig->uniqueID()); |
| 199 | REPORTER_ASSERT(reporter, gpuBacked->subset().width() == orig->subset().width() && |
| 200 | gpuBacked->subset().height() == orig->subset().height()); |
brianosman | afbf71d | 2016-07-21 07:15:37 -0700 | [diff] [blame] | 201 | REPORTER_ASSERT(reporter, gpuBacked->getColorSpace() == orig->getColorSpace()); |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | // Test out the SkSpecialImage::makeTextureImage entry point |
bsalomon | 68d9134 | 2016-04-12 09:59:58 -0700 | [diff] [blame] | 205 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_MakeTexture, reporter, ctxInfo) { |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 206 | GrContext* context = ctxInfo.grContext(); |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 207 | SkBitmap bm = create_bm(); |
| 208 | |
| 209 | const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize); |
| 210 | |
| 211 | { |
| 212 | // raster |
| 213 | sk_sp<SkSpecialImage> rasterImage(SkSpecialImage::MakeFromRaster( |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 214 | SkIRect::MakeWH(kFullSize, |
| 215 | kFullSize), |
| 216 | bm)); |
| 217 | |
| 218 | { |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame] | 219 | sk_sp<SkSpecialImage> fromRaster(rasterImage->makeTextureImage(context)); |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 220 | test_texture_backed(reporter, rasterImage, fromRaster); |
| 221 | } |
| 222 | |
| 223 | { |
| 224 | sk_sp<SkSpecialImage> subRasterImage(rasterImage->makeSubset(subset)); |
| 225 | |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame] | 226 | sk_sp<SkSpecialImage> fromSubRaster(subRasterImage->makeTextureImage(context)); |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 227 | test_texture_backed(reporter, subRasterImage, fromSubRaster); |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | { |
| 232 | // gpu |
| 233 | GrSurfaceDesc desc; |
| 234 | desc.fConfig = kSkia8888_GrPixelConfig; |
| 235 | desc.fFlags = kNone_GrSurfaceFlags; |
| 236 | desc.fWidth = kFullSize; |
| 237 | desc.fHeight = kFullSize; |
| 238 | |
robertphillips | c91fd34 | 2016-04-25 12:32:54 -0700 | [diff] [blame] | 239 | sk_sp<GrTexture> texture(context->textureProvider()->createTexture(desc, |
| 240 | SkBudgeted::kNo, |
| 241 | bm.getPixels(), |
| 242 | 0)); |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 243 | if (!texture) { |
| 244 | return; |
| 245 | } |
| 246 | |
| 247 | sk_sp<SkSpecialImage> gpuImage(SkSpecialImage::MakeFromGpu( |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 248 | SkIRect::MakeWH(kFullSize, |
| 249 | kFullSize), |
| 250 | kNeedNewImageUniqueID_SpecialImage, |
brianosman | afbf71d | 2016-07-21 07:15:37 -0700 | [diff] [blame] | 251 | std::move(texture), nullptr)); |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 252 | |
| 253 | { |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame] | 254 | sk_sp<SkSpecialImage> fromGPU(gpuImage->makeTextureImage(context)); |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 255 | test_texture_backed(reporter, gpuImage, fromGPU); |
| 256 | } |
| 257 | |
| 258 | { |
| 259 | sk_sp<SkSpecialImage> subGPUImage(gpuImage->makeSubset(subset)); |
| 260 | |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame] | 261 | sk_sp<SkSpecialImage> fromSubGPU(subGPUImage->makeTextureImage(context)); |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 262 | test_texture_backed(reporter, subGPUImage, fromSubGPU); |
| 263 | } |
| 264 | } |
| 265 | } |
| 266 | |
bsalomon | 68d9134 | 2016-04-12 09:59:58 -0700 | [diff] [blame] | 267 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_Gpu, reporter, ctxInfo) { |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 268 | GrContext* context = ctxInfo.grContext(); |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 269 | SkBitmap bm = create_bm(); |
| 270 | |
| 271 | GrSurfaceDesc desc; |
| 272 | desc.fConfig = kSkia8888_GrPixelConfig; |
| 273 | desc.fFlags = kNone_GrSurfaceFlags; |
| 274 | desc.fWidth = kFullSize; |
| 275 | desc.fHeight = kFullSize; |
| 276 | |
robertphillips | c91fd34 | 2016-04-25 12:32:54 -0700 | [diff] [blame] | 277 | sk_sp<GrTexture> texture(context->textureProvider()->createTexture(desc, |
| 278 | SkBudgeted::kNo, |
| 279 | bm.getPixels(), 0)); |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 280 | if (!texture) { |
| 281 | return; |
| 282 | } |
| 283 | |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 284 | sk_sp<SkSpecialImage> fullSImg(SkSpecialImage::MakeFromGpu( |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 285 | SkIRect::MakeWH(kFullSize, kFullSize), |
| 286 | kNeedNewImageUniqueID_SpecialImage, |
brianosman | afbf71d | 2016-07-21 07:15:37 -0700 | [diff] [blame] | 287 | texture, nullptr)); |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 288 | |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 289 | const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize); |
| 290 | |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 291 | { |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 292 | sk_sp<SkSpecialImage> subSImg1(SkSpecialImage::MakeFromGpu( |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame] | 293 | subset, |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 294 | kNeedNewImageUniqueID_SpecialImage, |
brianosman | afbf71d | 2016-07-21 07:15:37 -0700 | [diff] [blame] | 295 | texture, nullptr)); |
robertphillips | ed086ca | 2016-04-26 15:02:25 -0700 | [diff] [blame] | 296 | test_image(subSImg1, reporter, context, true, kPad, kFullSize); |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | { |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 300 | sk_sp<SkSpecialImage> subSImg2(fullSImg->makeSubset(subset)); |
robertphillips | ed086ca | 2016-04-26 15:02:25 -0700 | [diff] [blame] | 301 | test_image(subSImg2, reporter, context, true, kPad, kFullSize); |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 302 | } |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 303 | } |
| 304 | |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 305 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_DeferredGpu, reporter, ctxInfo) { |
| 306 | GrContext* context = ctxInfo.grContext(); |
| 307 | SkBitmap bm = create_bm(); |
| 308 | |
| 309 | GrSurfaceDesc desc; |
| 310 | desc.fConfig = kSkia8888_GrPixelConfig; |
| 311 | desc.fFlags = kNone_GrSurfaceFlags; |
| 312 | desc.fWidth = kFullSize; |
| 313 | desc.fHeight = kFullSize; |
| 314 | |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 315 | sk_sp<GrSurfaceProxy> proxy(GrSurfaceProxy::MakeDeferred(*context->caps(), |
| 316 | context->textureProvider(), |
| 317 | desc, SkBudgeted::kNo, |
| 318 | bm.getPixels(), 0)); |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 319 | if (!proxy) { |
| 320 | return; |
| 321 | } |
| 322 | |
| 323 | sk_sp<SkSpecialImage> fullSImg(SkSpecialImage::MakeDeferredFromGpu( |
| 324 | context, |
| 325 | SkIRect::MakeWH(kFullSize, kFullSize), |
| 326 | kNeedNewImageUniqueID_SpecialImage, |
| 327 | proxy, nullptr)); |
| 328 | |
| 329 | const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize); |
| 330 | |
| 331 | { |
| 332 | sk_sp<SkSpecialImage> subSImg1(SkSpecialImage::MakeDeferredFromGpu( |
| 333 | context, |
| 334 | subset, |
| 335 | kNeedNewImageUniqueID_SpecialImage, |
| 336 | proxy, nullptr)); |
| 337 | test_image(subSImg1, reporter, context, true, kPad, kFullSize); |
| 338 | } |
| 339 | |
| 340 | { |
| 341 | sk_sp<SkSpecialImage> subSImg2(fullSImg->makeSubset(subset)); |
| 342 | test_image(subSImg2, reporter, context, true, kPad, kFullSize); |
| 343 | } |
| 344 | } |
| 345 | |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 346 | #endif |