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" |
Mike Reed | 84dd857 | 2017-03-08 22:21:00 -0500 | [diff] [blame] | 21 | #include "GrTextureProxy.h" |
Brian Osman | 3b65598 | 2017-03-07 16:58:08 -0500 | [diff] [blame] | 22 | #include "SkGr.h" |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 23 | #endif |
| 24 | |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 25 | |
| 26 | // This test creates backing resources exactly sized to [kFullSize x kFullSize]. |
| 27 | // It then wraps them in an SkSpecialImage with only the center (red) region being active. |
| 28 | // It then draws the SkSpecialImage to a full sized (all blue) canvas and checks that none |
| 29 | // of the inactive (green) region leaked out. |
| 30 | |
| 31 | static const int kSmallerSize = 10; |
| 32 | static const int kPad = 3; |
| 33 | static const int kFullSize = kSmallerSize + 2 * kPad; |
| 34 | |
| 35 | // Create a bitmap with red in the center and green around it |
| 36 | static SkBitmap create_bm() { |
| 37 | SkBitmap bm; |
| 38 | bm.allocN32Pixels(kFullSize, kFullSize, true); |
| 39 | |
| 40 | SkCanvas temp(bm); |
| 41 | |
| 42 | temp.clear(SK_ColorGREEN); |
| 43 | SkPaint p; |
| 44 | p.setColor(SK_ColorRED); |
| 45 | p.setAntiAlias(false); |
| 46 | |
| 47 | temp.drawRect(SkRect::MakeXYWH(SkIntToScalar(kPad), SkIntToScalar(kPad), |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 48 | SkIntToScalar(kSmallerSize), SkIntToScalar(kSmallerSize)), |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 49 | p); |
| 50 | |
| 51 | return bm; |
| 52 | } |
| 53 | |
| 54 | // Basic test of the SkSpecialImage public API (e.g., peekTexture, peekPixels & draw) |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 55 | static void test_image(const sk_sp<SkSpecialImage>& img, skiatest::Reporter* reporter, |
Robert Phillips | 6de9904 | 2017-01-31 11:31:39 -0500 | [diff] [blame] | 56 | GrContext* context, bool isGPUBacked, |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 57 | int offset, int size) { |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame] | 58 | const SkIRect subset = img->subset(); |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 59 | REPORTER_ASSERT(reporter, offset == subset.left()); |
| 60 | REPORTER_ASSERT(reporter, offset == subset.top()); |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 61 | REPORTER_ASSERT(reporter, kSmallerSize == subset.width()); |
| 62 | REPORTER_ASSERT(reporter, kSmallerSize == subset.height()); |
| 63 | |
| 64 | //-------------- |
Robert Phillips | 2c6d2bf | 2017-02-21 10:19:29 -0500 | [diff] [blame] | 65 | // Test that isTextureBacked reports the correct backing type |
Robert Phillips | 6de9904 | 2017-01-31 11:31:39 -0500 | [diff] [blame] | 66 | REPORTER_ASSERT(reporter, isGPUBacked == img->isTextureBacked()); |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 67 | |
| 68 | #if SK_SUPPORT_GPU |
| 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 | } |
| 75 | #endif |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 76 | |
| 77 | //-------------- |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 78 | // Test getROPixels - this should always succeed regardless of backing store |
| 79 | SkBitmap bitmap; |
| 80 | REPORTER_ASSERT(reporter, img->getROPixels(&bitmap)); |
robertphillips | ed086ca | 2016-04-26 15:02:25 -0700 | [diff] [blame] | 81 | if (context) { |
| 82 | REPORTER_ASSERT(reporter, kSmallerSize == bitmap.width()); |
| 83 | REPORTER_ASSERT(reporter, kSmallerSize == bitmap.height()); |
| 84 | } else { |
| 85 | REPORTER_ASSERT(reporter, size == bitmap.width()); |
| 86 | REPORTER_ASSERT(reporter, size == bitmap.height()); |
| 87 | } |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 88 | |
| 89 | //-------------- |
robertphillips | b4bd11e | 2016-03-21 13:44:18 -0700 | [diff] [blame] | 90 | // Test that draw restricts itself to the subset |
brianosman | eed6b0e | 2016-09-23 13:04:05 -0700 | [diff] [blame] | 91 | SkImageFilter::OutputProperties outProps(img->getColorSpace()); |
| 92 | sk_sp<SkSpecialSurface> surf(img->makeSurface(outProps, SkISize::Make(kFullSize, kFullSize), |
Matt Sarett | cb6266b | 2017-01-17 10:48:53 -0500 | [diff] [blame] | 93 | kPremul_SkAlphaType)); |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 94 | |
| 95 | SkCanvas* canvas = surf->getCanvas(); |
| 96 | |
| 97 | canvas->clear(SK_ColorBLUE); |
robertphillips | e8c3497 | 2016-02-16 12:09:36 -0800 | [diff] [blame] | 98 | img->draw(canvas, SkIntToScalar(kPad), SkIntToScalar(kPad), nullptr); |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 99 | |
| 100 | SkBitmap bm; |
Matt Sarett | cb6266b | 2017-01-17 10:48:53 -0500 | [diff] [blame] | 101 | bm.allocN32Pixels(kFullSize, kFullSize, false); |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 102 | |
| 103 | bool result = canvas->readPixels(bm.info(), bm.getPixels(), bm.rowBytes(), 0, 0); |
| 104 | SkASSERT_RELEASE(result); |
| 105 | |
| 106 | // Only the center (red) portion should've been drawn into the canvas |
| 107 | REPORTER_ASSERT(reporter, SK_ColorBLUE == bm.getColor(kPad-1, kPad-1)); |
| 108 | REPORTER_ASSERT(reporter, SK_ColorRED == bm.getColor(kPad, kPad)); |
| 109 | REPORTER_ASSERT(reporter, SK_ColorRED == bm.getColor(kSmallerSize+kPad-1, |
| 110 | kSmallerSize+kPad-1)); |
| 111 | REPORTER_ASSERT(reporter, SK_ColorBLUE == bm.getColor(kSmallerSize+kPad, |
| 112 | kSmallerSize+kPad)); |
robertphillips | b4bd11e | 2016-03-21 13:44:18 -0700 | [diff] [blame] | 113 | |
| 114 | //-------------- |
Robert Phillips | a5fdc97 | 2017-02-18 16:58:09 -0500 | [diff] [blame] | 115 | // Test that asImage & makeTightSurface return appropriately sized objects |
robertphillips | b4bd11e | 2016-03-21 13:44:18 -0700 | [diff] [blame] | 116 | // of the correct backing type |
| 117 | SkIRect newSubset = SkIRect::MakeWH(subset.width(), subset.height()); |
| 118 | { |
Robert Phillips | a5fdc97 | 2017-02-18 16:58:09 -0500 | [diff] [blame] | 119 | sk_sp<SkImage> tightImg(img->asImage(&newSubset)); |
robertphillips | b4bd11e | 2016-03-21 13:44:18 -0700 | [diff] [blame] | 120 | |
| 121 | REPORTER_ASSERT(reporter, tightImg->width() == subset.width()); |
| 122 | REPORTER_ASSERT(reporter, tightImg->height() == subset.height()); |
Robert Phillips | 0ae6faa | 2017-03-21 16:22:00 -0400 | [diff] [blame] | 123 | REPORTER_ASSERT(reporter, isGPUBacked == tightImg->isTextureBacked()); |
robertphillips | b4bd11e | 2016-03-21 13:44:18 -0700 | [diff] [blame] | 124 | SkPixmap tmpPixmap; |
Robert Phillips | 6de9904 | 2017-01-31 11:31:39 -0500 | [diff] [blame] | 125 | REPORTER_ASSERT(reporter, isGPUBacked != !!tightImg->peekPixels(&tmpPixmap)); |
robertphillips | b4bd11e | 2016-03-21 13:44:18 -0700 | [diff] [blame] | 126 | } |
| 127 | { |
brianosman | eed6b0e | 2016-09-23 13:04:05 -0700 | [diff] [blame] | 128 | SkImageFilter::OutputProperties outProps(img->getColorSpace()); |
| 129 | sk_sp<SkSurface> tightSurf(img->makeTightSurface(outProps, subset.size())); |
robertphillips | b4bd11e | 2016-03-21 13:44:18 -0700 | [diff] [blame] | 130 | |
| 131 | REPORTER_ASSERT(reporter, tightSurf->width() == subset.width()); |
| 132 | REPORTER_ASSERT(reporter, tightSurf->height() == subset.height()); |
Robert Phillips | 6de9904 | 2017-01-31 11:31:39 -0500 | [diff] [blame] | 133 | REPORTER_ASSERT(reporter, isGPUBacked == |
robertphillips | b4bd11e | 2016-03-21 13:44:18 -0700 | [diff] [blame] | 134 | !!tightSurf->getTextureHandle(SkSurface::kDiscardWrite_BackendHandleAccess)); |
| 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 | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 193 | #if SK_SUPPORT_GPU |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 194 | |
| 195 | static void test_texture_backed(skiatest::Reporter* reporter, |
| 196 | const sk_sp<SkSpecialImage>& orig, |
| 197 | const sk_sp<SkSpecialImage>& gpuBacked) { |
| 198 | REPORTER_ASSERT(reporter, gpuBacked); |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 199 | REPORTER_ASSERT(reporter, gpuBacked->isTextureBacked()); |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 200 | REPORTER_ASSERT(reporter, gpuBacked->uniqueID() == orig->uniqueID()); |
| 201 | REPORTER_ASSERT(reporter, gpuBacked->subset().width() == orig->subset().width() && |
| 202 | gpuBacked->subset().height() == orig->subset().height()); |
brianosman | afbf71d | 2016-07-21 07:15:37 -0700 | [diff] [blame] | 203 | REPORTER_ASSERT(reporter, gpuBacked->getColorSpace() == orig->getColorSpace()); |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | // Test out the SkSpecialImage::makeTextureImage entry point |
bsalomon | 68d9134 | 2016-04-12 09:59:58 -0700 | [diff] [blame] | 207 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_MakeTexture, reporter, ctxInfo) { |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 208 | GrContext* context = ctxInfo.grContext(); |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 209 | SkBitmap bm = create_bm(); |
| 210 | |
| 211 | const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize); |
| 212 | |
| 213 | { |
| 214 | // raster |
| 215 | sk_sp<SkSpecialImage> rasterImage(SkSpecialImage::MakeFromRaster( |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 216 | SkIRect::MakeWH(kFullSize, |
| 217 | kFullSize), |
| 218 | bm)); |
| 219 | |
| 220 | { |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame] | 221 | sk_sp<SkSpecialImage> fromRaster(rasterImage->makeTextureImage(context)); |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 222 | test_texture_backed(reporter, rasterImage, fromRaster); |
| 223 | } |
| 224 | |
| 225 | { |
| 226 | sk_sp<SkSpecialImage> subRasterImage(rasterImage->makeSubset(subset)); |
| 227 | |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame] | 228 | sk_sp<SkSpecialImage> fromSubRaster(subRasterImage->makeTextureImage(context)); |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 229 | test_texture_backed(reporter, subRasterImage, fromSubRaster); |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | { |
| 234 | // gpu |
Robert Phillips | 2c6d2bf | 2017-02-21 10:19:29 -0500 | [diff] [blame] | 235 | const GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(bm.info(), *context->caps()); |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 236 | |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 237 | sk_sp<GrTextureProxy> proxy(GrSurfaceProxy::MakeDeferred(context->resourceProvider(), |
Robert Phillips | 2c6d2bf | 2017-02-21 10:19:29 -0500 | [diff] [blame] | 238 | desc, SkBudgeted::kNo, |
| 239 | bm.getPixels(), bm.rowBytes())); |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 240 | if (!proxy) { |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 241 | return; |
| 242 | } |
| 243 | |
Robert Phillips | 2c6d2bf | 2017-02-21 10:19:29 -0500 | [diff] [blame] | 244 | sk_sp<SkSpecialImage> gpuImage(SkSpecialImage::MakeDeferredFromGpu( |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 245 | context, |
| 246 | SkIRect::MakeWH(kFullSize, kFullSize), |
| 247 | kNeedNewImageUniqueID_SpecialImage, |
| 248 | std::move(proxy), nullptr)); |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 249 | |
| 250 | { |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame] | 251 | sk_sp<SkSpecialImage> fromGPU(gpuImage->makeTextureImage(context)); |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 252 | test_texture_backed(reporter, gpuImage, fromGPU); |
| 253 | } |
| 254 | |
| 255 | { |
| 256 | sk_sp<SkSpecialImage> subGPUImage(gpuImage->makeSubset(subset)); |
| 257 | |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame] | 258 | sk_sp<SkSpecialImage> fromSubGPU(subGPUImage->makeTextureImage(context)); |
robertphillips | 83c17fa | 2016-03-18 08:14:27 -0700 | [diff] [blame] | 259 | test_texture_backed(reporter, subGPUImage, fromSubGPU); |
| 260 | } |
| 261 | } |
| 262 | } |
| 263 | |
bsalomon | 68d9134 | 2016-04-12 09:59:58 -0700 | [diff] [blame] | 264 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_Gpu, reporter, ctxInfo) { |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 265 | GrContext* context = ctxInfo.grContext(); |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 266 | SkBitmap bm = create_bm(); |
| 267 | |
Robert Phillips | 2c6d2bf | 2017-02-21 10:19:29 -0500 | [diff] [blame] | 268 | const GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(bm.info(), *context->caps()); |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 269 | |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 270 | sk_sp<GrTextureProxy> proxy(GrSurfaceProxy::MakeDeferred(context->resourceProvider(), |
Robert Phillips | 2c6d2bf | 2017-02-21 10:19:29 -0500 | [diff] [blame] | 271 | desc, SkBudgeted::kNo, |
| 272 | bm.getPixels(), bm.rowBytes())); |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 273 | if (!proxy) { |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 274 | return; |
| 275 | } |
| 276 | |
Robert Phillips | 2c6d2bf | 2017-02-21 10:19:29 -0500 | [diff] [blame] | 277 | sk_sp<SkSpecialImage> fullSImg(SkSpecialImage::MakeDeferredFromGpu( |
| 278 | context, |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 279 | SkIRect::MakeWH(kFullSize, kFullSize), |
| 280 | kNeedNewImageUniqueID_SpecialImage, |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 281 | proxy, nullptr)); |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 282 | |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 283 | const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize); |
| 284 | |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 285 | { |
Robert Phillips | 2c6d2bf | 2017-02-21 10:19:29 -0500 | [diff] [blame] | 286 | sk_sp<SkSpecialImage> subSImg1(SkSpecialImage::MakeDeferredFromGpu( |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 287 | context, subset, |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 288 | kNeedNewImageUniqueID_SpecialImage, |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 289 | std::move(proxy), nullptr)); |
robertphillips | ed086ca | 2016-04-26 15:02:25 -0700 | [diff] [blame] | 290 | test_image(subSImg1, reporter, context, true, kPad, kFullSize); |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | { |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 294 | sk_sp<SkSpecialImage> subSImg2(fullSImg->makeSubset(subset)); |
robertphillips | ed086ca | 2016-04-26 15:02:25 -0700 | [diff] [blame] | 295 | test_image(subSImg2, reporter, context, true, kPad, kFullSize); |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 296 | } |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 297 | } |
| 298 | |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 299 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_DeferredGpu, reporter, ctxInfo) { |
| 300 | GrContext* context = ctxInfo.grContext(); |
| 301 | SkBitmap bm = create_bm(); |
| 302 | |
| 303 | GrSurfaceDesc desc; |
Robert Phillips | 96be9df | 2017-07-21 14:17:45 +0000 | [diff] [blame] | 304 | desc.fFlags = kNone_GrSurfaceFlags; |
Robert Phillips | e44ef10 | 2017-07-21 15:37:19 -0400 | [diff] [blame] | 305 | desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 306 | desc.fWidth = kFullSize; |
| 307 | desc.fHeight = kFullSize; |
Robert Phillips | 16d8ec6 | 2017-07-27 16:16:25 -0400 | [diff] [blame^] | 308 | desc.fConfig = kSkia8888_GrPixelConfig; |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 309 | |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 310 | sk_sp<GrTextureProxy> proxy(GrSurfaceProxy::MakeDeferred(context->resourceProvider(), |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 311 | desc, SkBudgeted::kNo, |
| 312 | bm.getPixels(), 0)); |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 313 | if (!proxy) { |
| 314 | return; |
| 315 | } |
| 316 | |
| 317 | sk_sp<SkSpecialImage> fullSImg(SkSpecialImage::MakeDeferredFromGpu( |
| 318 | context, |
| 319 | SkIRect::MakeWH(kFullSize, kFullSize), |
| 320 | kNeedNewImageUniqueID_SpecialImage, |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 321 | proxy, nullptr)); |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 322 | |
| 323 | const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize); |
| 324 | |
| 325 | { |
| 326 | sk_sp<SkSpecialImage> subSImg1(SkSpecialImage::MakeDeferredFromGpu( |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 327 | context, subset, |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 328 | kNeedNewImageUniqueID_SpecialImage, |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 329 | std::move(proxy), nullptr)); |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 330 | test_image(subSImg1, reporter, context, true, kPad, kFullSize); |
| 331 | } |
| 332 | |
| 333 | { |
| 334 | sk_sp<SkSpecialImage> subSImg2(fullSImg->makeSubset(subset)); |
| 335 | test_image(subSImg2, reporter, context, true, kPad, kFullSize); |
| 336 | } |
| 337 | } |
| 338 | |
robertphillips | b6c65e9 | 2016-02-04 10:52:42 -0800 | [diff] [blame] | 339 | #endif |