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