Robert Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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 | |
Brian Salomon | 59ef8c3 | 2019-01-30 12:20:56 -0500 | [diff] [blame] | 8 | #include <initializer_list> |
| 9 | #include <memory> |
| 10 | #include <utility> |
Greg Daniel | f2336e4 | 2018-01-23 16:38:14 -0500 | [diff] [blame] | 11 | #include "GrBackendSurface.h" |
Ben Wagner | d90cd3b | 2018-05-22 10:48:08 -0400 | [diff] [blame] | 12 | #include "GrCaps.h" |
| 13 | #include "GrContext.h" |
| 14 | #include "GrContextFactory.h" |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 15 | #include "GrContextPriv.h" |
Greg Daniel | f2336e4 | 2018-01-23 16:38:14 -0500 | [diff] [blame] | 16 | #include "GrGpu.h" |
Ben Wagner | d90cd3b | 2018-05-22 10:48:08 -0400 | [diff] [blame] | 17 | #include "GrRenderTargetContext.h" |
| 18 | #include "GrRenderTargetProxy.h" |
| 19 | #include "GrTextureProxy.h" |
Robert Phillips | abf7b76 | 2018-03-21 12:13:37 -0400 | [diff] [blame] | 20 | #include "GrTextureProxyPriv.h" |
Ben Wagner | d90cd3b | 2018-05-22 10:48:08 -0400 | [diff] [blame] | 21 | #include "GrTypes.h" |
| 22 | #include "GrTypesPriv.h" |
| 23 | #include "SkBitmap.h" |
Robert Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 24 | #include "SkCanvas.h" |
Ben Wagner | d90cd3b | 2018-05-22 10:48:08 -0400 | [diff] [blame] | 25 | #include "SkColorSpace.h" |
| 26 | #include "SkDeferredDisplayList.h" |
Robert Phillips | f54883c | 2018-12-18 08:29:09 -0500 | [diff] [blame] | 27 | #include "SkDeferredDisplayListPriv.h" |
Robert Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 28 | #include "SkDeferredDisplayListRecorder.h" |
| 29 | #include "SkGpuDevice.h" |
Ben Wagner | d90cd3b | 2018-05-22 10:48:08 -0400 | [diff] [blame] | 30 | #include "SkImage.h" |
| 31 | #include "SkImageInfo.h" |
Robert Phillips | abf7b76 | 2018-03-21 12:13:37 -0400 | [diff] [blame] | 32 | #include "SkImage_Gpu.h" |
Ben Wagner | d90cd3b | 2018-05-22 10:48:08 -0400 | [diff] [blame] | 33 | #include "SkPaint.h" |
Brian Salomon | 59ef8c3 | 2019-01-30 12:20:56 -0500 | [diff] [blame] | 34 | #include "SkPromiseImageTexture.h" |
Ben Wagner | d90cd3b | 2018-05-22 10:48:08 -0400 | [diff] [blame] | 35 | #include "SkRect.h" |
| 36 | #include "SkRefCnt.h" |
Robert Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 37 | #include "SkSurface.h" |
Robert Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 38 | #include "SkSurfaceCharacterization.h" |
| 39 | #include "SkSurfaceProps.h" |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 40 | #include "SkSurface_Gpu.h" |
Robert Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 41 | #include "Test.h" |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 42 | #include "gl/GrGLCaps.h" |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 43 | #include "gl/GrGLDefines.h" |
Ben Wagner | d90cd3b | 2018-05-22 10:48:08 -0400 | [diff] [blame] | 44 | #include "gl/GrGLTypes.h" |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 45 | #ifdef SK_VULKAN |
Greg Daniel | 54bfb18 | 2018-11-20 17:12:36 -0500 | [diff] [blame] | 46 | #include <vulkan/vulkan_core.h> |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 47 | #endif |
| 48 | |
Robert Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 49 | class SurfaceParameters { |
| 50 | public: |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 51 | static const int kNumParams = 11; |
Robert Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 52 | static const int kSampleCount = 5; |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 53 | static const int kMipMipCount = 8; |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 54 | static const int kFBO0Count = 9; |
Robert Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 55 | |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 56 | SurfaceParameters(GrBackendApi backend) |
| 57 | : fBackend(backend) |
| 58 | , fWidth(64) |
Robert Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 59 | , fHeight(64) |
| 60 | , fOrigin(kTopLeft_GrSurfaceOrigin) |
| 61 | , fColorType(kRGBA_8888_SkColorType) |
| 62 | , fColorSpace(SkColorSpace::MakeSRGB()) |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 63 | , fSampleCount(1) |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 64 | , fSurfaceProps(0x0, kUnknown_SkPixelGeometry) |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 65 | , fShouldCreateMipMaps(true) |
| 66 | , fUsesGLFBO0(false) |
| 67 | , fIsTextureable(true) { |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 68 | } |
Robert Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 69 | |
| 70 | int sampleCount() const { return fSampleCount; } |
| 71 | |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 72 | void setColorType(SkColorType ct) { fColorType = ct; } |
| 73 | void setColorSpace(sk_sp<SkColorSpace> cs) { fColorSpace = std::move(cs); } |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 74 | void setTextureable(bool isTextureable) { fIsTextureable = isTextureable; } |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 75 | |
Robert Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 76 | // Modify the SurfaceParameters in just one way |
| 77 | void modify(int i) { |
| 78 | switch (i) { |
| 79 | case 0: |
| 80 | fWidth = 63; |
| 81 | break; |
| 82 | case 1: |
| 83 | fHeight = 63; |
| 84 | break; |
| 85 | case 2: |
| 86 | fOrigin = kBottomLeft_GrSurfaceOrigin; |
| 87 | break; |
| 88 | case 3: |
| 89 | fColorType = kRGBA_F16_SkColorType; |
| 90 | break; |
| 91 | case 4: |
Brian Osman | 37f9988 | 2018-08-09 10:26:57 -0400 | [diff] [blame] | 92 | // This just needs to be a colorSpace different from that returned by MakeSRGB(). |
| 93 | // In this case we just change the gamut. |
Brian Osman | 82ebe04 | 2019-01-04 17:03:00 -0500 | [diff] [blame] | 94 | fColorSpace = SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kAdobeRGB); |
Robert Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 95 | break; |
| 96 | case kSampleCount: |
| 97 | fSampleCount = 4; |
| 98 | break; |
| 99 | case 6: |
| 100 | fSurfaceProps = SkSurfaceProps(0x0, kRGB_H_SkPixelGeometry); |
| 101 | break; |
| 102 | case 7: |
| 103 | fSurfaceProps = SkSurfaceProps(SkSurfaceProps::kUseDeviceIndependentFonts_Flag, |
| 104 | kUnknown_SkPixelGeometry); |
| 105 | break; |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 106 | case 8: |
| 107 | fShouldCreateMipMaps = false; |
| 108 | break; |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 109 | case 9: |
| 110 | if (GrBackendApi::kOpenGL == fBackend) { |
| 111 | fUsesGLFBO0 = true; |
| 112 | fIsTextureable = false; |
| 113 | } |
| 114 | break; |
| 115 | case 10: |
| 116 | fIsTextureable = false; |
| 117 | break; |
Robert Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 118 | } |
| 119 | } |
| 120 | |
Robert Phillips | 6b6fcc7 | 2018-03-30 13:57:00 -0400 | [diff] [blame] | 121 | SkSurfaceCharacterization createCharacterization(GrContext* context) const { |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 122 | int maxResourceCount; |
| 123 | size_t maxResourceBytes; |
| 124 | context->getResourceCacheLimits(&maxResourceCount, &maxResourceBytes); |
| 125 | |
| 126 | // Note that Ganesh doesn't make use of the SkImageInfo's alphaType |
| 127 | SkImageInfo ii = SkImageInfo::Make(fWidth, fHeight, fColorType, |
| 128 | kPremul_SkAlphaType, fColorSpace); |
| 129 | |
Greg Daniel | 60ea40c | 2019-02-12 13:38:44 -0500 | [diff] [blame] | 130 | const GrCaps* caps = context->priv().caps(); |
| 131 | GrBackendFormat backendFormat = caps->getBackendFormatFromColorType(fColorType); |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 132 | if (!backendFormat.isValid()) { |
| 133 | return SkSurfaceCharacterization(); |
| 134 | } |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 135 | |
| 136 | SkSurfaceCharacterization c = context->threadSafeProxy()->createCharacterization( |
| 137 | maxResourceBytes, ii, backendFormat, fSampleCount, |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 138 | fOrigin, fSurfaceProps, fShouldCreateMipMaps, |
| 139 | fUsesGLFBO0, fIsTextureable); |
Robert Phillips | 6b6fcc7 | 2018-03-30 13:57:00 -0400 | [diff] [blame] | 140 | return c; |
| 141 | } |
| 142 | |
| 143 | // Create a DDL whose characterization captures the current settings |
| 144 | std::unique_ptr<SkDeferredDisplayList> createDDL(GrContext* context) const { |
| 145 | SkSurfaceCharacterization c = this->createCharacterization(context); |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 146 | SkAssertResult(c.isValid()); |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 147 | |
| 148 | SkDeferredDisplayListRecorder r(c); |
| 149 | SkCanvas* canvas = r.getCanvas(); |
| 150 | if (!canvas) { |
| 151 | return nullptr; |
| 152 | } |
| 153 | |
| 154 | canvas->drawRect(SkRect::MakeXYWH(10, 10, 10, 10), SkPaint()); |
| 155 | return r.detach(); |
| 156 | } |
| 157 | |
Robert Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 158 | // Create the surface with the current set of parameters |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 159 | sk_sp<SkSurface> make(GrContext* context, GrBackendTexture* backend) const { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 160 | GrGpu* gpu = context->priv().getGpu(); |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 161 | |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 162 | GrMipMapped mipmapped = !fIsTextureable |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 163 | ? GrMipMapped::kNo |
| 164 | : GrMipMapped(fShouldCreateMipMaps); |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 165 | |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 166 | if (fUsesGLFBO0) { |
| 167 | if (GrBackendApi::kOpenGL != context->backend()) { |
| 168 | return nullptr; |
| 169 | } |
| 170 | |
| 171 | GrGLFramebufferInfo fboInfo; |
| 172 | fboInfo.fFBOID = 0; |
| 173 | fboInfo.fFormat = GR_GL_RGBA8; |
| 174 | static constexpr int kStencilBits = 8; |
| 175 | GrBackendRenderTarget backendRT(fWidth, fHeight, 1, kStencilBits, fboInfo); |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 176 | |
| 177 | if (!backendRT.isValid()) { |
| 178 | return nullptr; |
| 179 | } |
| 180 | |
| 181 | return SkSurface::MakeFromBackendRenderTarget(context, backendRT, fOrigin, |
| 182 | fColorType, fColorSpace, &fSurfaceProps); |
| 183 | } |
| 184 | |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 185 | *backend = gpu->createTestingOnlyBackendTexture(nullptr, fWidth, fHeight, |
Robert Phillips | 646f637 | 2018-09-25 09:31:10 -0400 | [diff] [blame] | 186 | fColorType, true, mipmapped); |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 187 | if (!backend->isValid() || !gpu->isTestingOnlyBackendTexture(*backend)) { |
| 188 | return nullptr; |
| 189 | } |
| 190 | |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 191 | sk_sp<SkSurface> surface; |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 192 | if (!fIsTextureable) { |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 193 | // Create a surface w/ the current parameters but make it non-textureable |
| 194 | surface = SkSurface::MakeFromBackendTextureAsRenderTarget( |
| 195 | context, *backend, fOrigin, fSampleCount, fColorType, |
| 196 | fColorSpace, &fSurfaceProps); |
| 197 | } else { |
| 198 | surface = SkSurface::MakeFromBackendTexture( |
| 199 | context, *backend, fOrigin, fSampleCount, fColorType, |
| 200 | fColorSpace, &fSurfaceProps); |
| 201 | } |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 202 | |
| 203 | if (!surface) { |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 204 | gpu->deleteTestingOnlyBackendTexture(*backend); |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 205 | return nullptr; |
| 206 | } |
| 207 | |
| 208 | return surface; |
| 209 | } |
| 210 | |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 211 | void cleanUpBackEnd(GrContext* context, const GrBackendTexture& backend) const { |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 212 | if (!backend.isValid()) { |
| 213 | return; |
| 214 | } |
| 215 | |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 216 | GrGpu* gpu = context->priv().getGpu(); |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 217 | |
| 218 | gpu->deleteTestingOnlyBackendTexture(backend); |
Robert Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | private: |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 222 | GrBackendApi fBackend; |
Robert Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 223 | int fWidth; |
| 224 | int fHeight; |
| 225 | GrSurfaceOrigin fOrigin; |
| 226 | SkColorType fColorType; |
| 227 | sk_sp<SkColorSpace> fColorSpace; |
| 228 | int fSampleCount; |
| 229 | SkSurfaceProps fSurfaceProps; |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 230 | bool fShouldCreateMipMaps; |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 231 | bool fUsesGLFBO0; |
| 232 | bool fIsTextureable; |
Robert Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 233 | }; |
| 234 | |
Robert Phillips | c1267c6 | 2018-04-04 11:12:39 -0400 | [diff] [blame] | 235 | // Test out operator== && operator!= |
| 236 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLOperatorEqTest, reporter, ctxInfo) { |
| 237 | GrContext* context = ctxInfo.grContext(); |
| 238 | |
| 239 | for (int i = 0; i < SurfaceParameters::kNumParams; ++i) { |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 240 | SurfaceParameters params1(context->backend()); |
Robert Phillips | c1267c6 | 2018-04-04 11:12:39 -0400 | [diff] [blame] | 241 | params1.modify(i); |
| 242 | |
| 243 | SkSurfaceCharacterization char1 = params1.createCharacterization(context); |
| 244 | if (!char1.isValid()) { |
| 245 | continue; // can happen on some platforms (ChromeOS) |
| 246 | } |
| 247 | |
| 248 | for (int j = 0; j < SurfaceParameters::kNumParams; ++j) { |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 249 | SurfaceParameters params2(context->backend()); |
Robert Phillips | c1267c6 | 2018-04-04 11:12:39 -0400 | [diff] [blame] | 250 | params2.modify(j); |
| 251 | |
| 252 | SkSurfaceCharacterization char2 = params2.createCharacterization(context); |
| 253 | if (!char2.isValid()) { |
| 254 | continue; // can happen on some platforms (ChromeOS) |
| 255 | } |
| 256 | |
| 257 | if (i == j) { |
| 258 | REPORTER_ASSERT(reporter, char1 == char2); |
| 259 | } else { |
| 260 | REPORTER_ASSERT(reporter, char1 != char2); |
| 261 | } |
| 262 | |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | { |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 267 | SurfaceParameters params(context->backend()); |
Robert Phillips | c1267c6 | 2018-04-04 11:12:39 -0400 | [diff] [blame] | 268 | |
| 269 | SkSurfaceCharacterization valid = params.createCharacterization(context); |
| 270 | SkASSERT(valid.isValid()); |
| 271 | |
| 272 | SkSurfaceCharacterization inval1, inval2; |
| 273 | SkASSERT(!inval1.isValid() && !inval2.isValid()); |
| 274 | |
| 275 | REPORTER_ASSERT(reporter, inval1 != inval2); |
| 276 | REPORTER_ASSERT(reporter, valid != inval1); |
| 277 | REPORTER_ASSERT(reporter, inval1 != valid); |
| 278 | } |
| 279 | } |
| 280 | |
Robert Phillips | 6b6fcc7 | 2018-03-30 13:57:00 -0400 | [diff] [blame] | 281 | //////////////////////////////////////////////////////////////////////////////// |
Robert Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 282 | // This tests SkSurfaceCharacterization/SkSurface compatibility |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 283 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLSurfaceCharacterizationTest, reporter, ctxInfo) { |
Robert Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 284 | GrContext* context = ctxInfo.grContext(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 285 | GrGpu* gpu = context->priv().getGpu(); |
Robert Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 286 | |
Robert Phillips | 9e441ee | 2018-02-01 15:14:55 -0500 | [diff] [blame] | 287 | // Create a bitmap that we can readback into |
| 288 | SkImageInfo imageInfo = SkImageInfo::Make(64, 64, kRGBA_8888_SkColorType, |
| 289 | kPremul_SkAlphaType); |
| 290 | SkBitmap bitmap; |
| 291 | bitmap.allocPixels(imageInfo); |
| 292 | |
Robert Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 293 | std::unique_ptr<SkDeferredDisplayList> ddl; |
| 294 | |
| 295 | // First, create a DDL using the stock SkSurface parameters |
| 296 | { |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 297 | SurfaceParameters params(context->backend()); |
Robert Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 298 | |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 299 | ddl = params.createDDL(context); |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 300 | SkAssertResult(ddl); |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 301 | |
| 302 | // The DDL should draw into an SkSurface created with the same parameters |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 303 | GrBackendTexture backend; |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 304 | sk_sp<SkSurface> s = params.make(context, &backend); |
Robert Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 305 | if (!s) { |
| 306 | return; |
| 307 | } |
| 308 | |
Robert Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 309 | REPORTER_ASSERT(reporter, s->draw(ddl.get())); |
Robert Phillips | 9e441ee | 2018-02-01 15:14:55 -0500 | [diff] [blame] | 310 | s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0); |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 311 | context->flush(); |
| 312 | gpu->testingOnly_flushGpuAndSync(); |
| 313 | s = nullptr; |
| 314 | params.cleanUpBackEnd(context, backend); |
Robert Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | // Then, alter each parameter in turn and check that the DDL & surface are incompatible |
| 318 | for (int i = 0; i < SurfaceParameters::kNumParams; ++i) { |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 319 | SurfaceParameters params(context->backend()); |
Robert Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 320 | params.modify(i); |
| 321 | |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 322 | GrBackendTexture backend; |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 323 | sk_sp<SkSurface> s = params.make(context, &backend); |
Robert Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 324 | if (!s) { |
| 325 | continue; |
| 326 | } |
| 327 | |
| 328 | if (SurfaceParameters::kSampleCount == i) { |
| 329 | SkSurface_Gpu* gpuSurf = static_cast<SkSurface_Gpu*>(s.get()); |
| 330 | |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 331 | int supportedSampleCount = context->priv().caps()->getRenderTargetSampleCount( |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 332 | params.sampleCount(), |
| 333 | gpuSurf->getDevice() |
| 334 | ->accessRenderTargetContext() |
| 335 | ->asRenderTargetProxy() |
| 336 | ->config()); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 337 | if (1 == supportedSampleCount) { |
Robert Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 338 | // If changing the sample count won't result in a different |
| 339 | // surface characterization, skip this step |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 340 | s = nullptr; |
| 341 | params.cleanUpBackEnd(context, backend); |
Robert Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 342 | continue; |
| 343 | } |
| 344 | } |
| 345 | |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 346 | if (SurfaceParameters::kMipMipCount == i && |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 347 | !context->priv().caps()->mipMapSupport()) { |
Robert Phillips | 6b6fcc7 | 2018-03-30 13:57:00 -0400 | [diff] [blame] | 348 | // If changing the mipmap setting won't result in a different surface characterization, |
| 349 | // skip this step |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 350 | s = nullptr; |
| 351 | params.cleanUpBackEnd(context, backend); |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 352 | continue; |
| 353 | } |
| 354 | |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 355 | if (SurfaceParameters::kFBO0Count == i && context->backend() != GrBackendApi::kOpenGL) { |
| 356 | // FBO0 only affects the surface characterization when using OpenGL |
| 357 | s = nullptr; |
| 358 | params.cleanUpBackEnd(context, backend); |
| 359 | continue; |
| 360 | } |
| 361 | |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 362 | REPORTER_ASSERT(reporter, !s->draw(ddl.get()), |
| 363 | "DDLSurfaceCharacterizationTest failed on parameter: %d\n", i); |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 364 | |
| 365 | context->flush(); |
| 366 | gpu->testingOnly_flushGpuAndSync(); |
| 367 | s = nullptr; |
| 368 | params.cleanUpBackEnd(context, backend); |
Robert Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 369 | } |
Robert Phillips | 8d1e67e | 2017-12-04 13:48:14 -0500 | [diff] [blame] | 370 | |
| 371 | // Next test the compatibility of resource cache parameters |
| 372 | { |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 373 | const SurfaceParameters params(context->backend()); |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 374 | GrBackendTexture backend; |
| 375 | |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 376 | sk_sp<SkSurface> s = params.make(context, &backend); |
Robert Phillips | 8d1e67e | 2017-12-04 13:48:14 -0500 | [diff] [blame] | 377 | |
| 378 | int maxResourceCount; |
| 379 | size_t maxResourceBytes; |
| 380 | context->getResourceCacheLimits(&maxResourceCount, &maxResourceBytes); |
| 381 | |
Robert Phillips | 8d1e67e | 2017-12-04 13:48:14 -0500 | [diff] [blame] | 382 | context->setResourceCacheLimits(maxResourceCount, maxResourceBytes/2); |
| 383 | REPORTER_ASSERT(reporter, !s->draw(ddl.get())); |
| 384 | |
Robert Phillips | 9e441ee | 2018-02-01 15:14:55 -0500 | [diff] [blame] | 385 | // DDL TODO: once proxies/ops can be de-instantiated we can re-enable these tests. |
| 386 | // For now, DDLs are drawn once. |
| 387 | #if 0 |
Robert Phillips | 8d1e67e | 2017-12-04 13:48:14 -0500 | [diff] [blame] | 388 | // resource limits >= those at characterization time are accepted |
| 389 | context->setResourceCacheLimits(2*maxResourceCount, maxResourceBytes); |
| 390 | REPORTER_ASSERT(reporter, s->draw(ddl.get())); |
Robert Phillips | 9e441ee | 2018-02-01 15:14:55 -0500 | [diff] [blame] | 391 | s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0); |
Robert Phillips | 8d1e67e | 2017-12-04 13:48:14 -0500 | [diff] [blame] | 392 | |
| 393 | context->setResourceCacheLimits(maxResourceCount, 2*maxResourceBytes); |
| 394 | REPORTER_ASSERT(reporter, s->draw(ddl.get())); |
Robert Phillips | 9e441ee | 2018-02-01 15:14:55 -0500 | [diff] [blame] | 395 | s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0); |
Robert Phillips | 8d1e67e | 2017-12-04 13:48:14 -0500 | [diff] [blame] | 396 | |
| 397 | context->setResourceCacheLimits(maxResourceCount, maxResourceBytes); |
| 398 | REPORTER_ASSERT(reporter, s->draw(ddl.get())); |
Robert Phillips | 9e441ee | 2018-02-01 15:14:55 -0500 | [diff] [blame] | 399 | s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0); |
| 400 | #endif |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 401 | |
| 402 | context->flush(); |
| 403 | gpu->testingOnly_flushGpuAndSync(); |
| 404 | s = nullptr; |
| 405 | params.cleanUpBackEnd(context, backend); |
Robert Phillips | 8d1e67e | 2017-12-04 13:48:14 -0500 | [diff] [blame] | 406 | } |
| 407 | |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 408 | // Test that the textureability of the DDL characterization can block a DDL draw |
| 409 | { |
| 410 | GrBackendTexture backend; |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 411 | SurfaceParameters params(context->backend()); |
| 412 | params.setTextureable(false); |
| 413 | |
| 414 | sk_sp<SkSurface> s = params.make(context, &backend); |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 415 | if (s) { |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 416 | REPORTER_ASSERT(reporter, !s->draw(ddl.get())); // bc the DDL was made w/ textureability |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 417 | |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 418 | context->flush(); |
| 419 | gpu->testingOnly_flushGpuAndSync(); |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 420 | s = nullptr; |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 421 | params.cleanUpBackEnd(context, backend); |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 422 | } |
| 423 | } |
| 424 | |
Robert Phillips | 8d1e67e | 2017-12-04 13:48:14 -0500 | [diff] [blame] | 425 | // Make sure non-GPU-backed surfaces fail characterization |
| 426 | { |
| 427 | SkImageInfo ii = SkImageInfo::MakeN32(64, 64, kOpaque_SkAlphaType); |
| 428 | |
| 429 | sk_sp<SkSurface> rasterSurface = SkSurface::MakeRaster(ii); |
| 430 | SkSurfaceCharacterization c; |
| 431 | REPORTER_ASSERT(reporter, !rasterSurface->characterize(&c)); |
| 432 | } |
Robert Phillips | 94458ee | 2018-03-06 13:41:51 -0500 | [diff] [blame] | 433 | |
| 434 | // Exercise the createResized method |
| 435 | { |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 436 | SurfaceParameters params(context->backend()); |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 437 | GrBackendTexture backend; |
Robert Phillips | 94458ee | 2018-03-06 13:41:51 -0500 | [diff] [blame] | 438 | |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 439 | sk_sp<SkSurface> s = params.make(context, &backend); |
Robert Phillips | 94458ee | 2018-03-06 13:41:51 -0500 | [diff] [blame] | 440 | if (!s) { |
| 441 | return; |
| 442 | } |
| 443 | |
| 444 | SkSurfaceCharacterization char0; |
| 445 | SkAssertResult(s->characterize(&char0)); |
| 446 | |
| 447 | // Too small |
| 448 | SkSurfaceCharacterization char1 = char0.createResized(-1, -1); |
| 449 | REPORTER_ASSERT(reporter, !char1.isValid()); |
| 450 | |
| 451 | // Too large |
| 452 | SkSurfaceCharacterization char2 = char0.createResized(1000000, 32); |
| 453 | REPORTER_ASSERT(reporter, !char2.isValid()); |
| 454 | |
| 455 | // Just right |
| 456 | SkSurfaceCharacterization char3 = char0.createResized(32, 32); |
| 457 | REPORTER_ASSERT(reporter, char3.isValid()); |
| 458 | REPORTER_ASSERT(reporter, 32 == char3.width()); |
| 459 | REPORTER_ASSERT(reporter, 32 == char3.height()); |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 460 | |
| 461 | s = nullptr; |
| 462 | params.cleanUpBackEnd(context, backend); |
Robert Phillips | 94458ee | 2018-03-06 13:41:51 -0500 | [diff] [blame] | 463 | } |
Robert Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 464 | } |
| 465 | |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 466 | // Test that a DDL created w/o textureability can be replayed into both a textureable and |
| 467 | // non-textureable destination. Note that DDLSurfaceCharacterizationTest tests that a |
| 468 | // textureable DDL cannot be played into a non-textureable destination but can be replayed |
| 469 | // into a textureable destination. |
| 470 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLNonTextureabilityTest, reporter, ctxInfo) { |
| 471 | GrContext* context = ctxInfo.grContext(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 472 | GrGpu* gpu = context->priv().getGpu(); |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 473 | |
| 474 | // Create a bitmap that we can readback into |
| 475 | SkImageInfo imageInfo = SkImageInfo::Make(64, 64, kRGBA_8888_SkColorType, |
| 476 | kPremul_SkAlphaType); |
| 477 | SkBitmap bitmap; |
| 478 | bitmap.allocPixels(imageInfo); |
| 479 | |
| 480 | for (bool textureability : { true, false }) { |
| 481 | std::unique_ptr<SkDeferredDisplayList> ddl; |
| 482 | |
| 483 | // First, create a DDL w/o textureability. TODO: once we have reusable DDLs, move this |
| 484 | // outside of the loop. |
| 485 | { |
| 486 | SurfaceParameters params(context->backend()); |
| 487 | params.setTextureable(false); |
| 488 | |
| 489 | ddl = params.createDDL(context); |
| 490 | SkAssertResult(ddl); |
| 491 | } |
| 492 | |
| 493 | // Then verify it can draw into either flavor of destination |
| 494 | SurfaceParameters params(context->backend()); |
| 495 | params.setTextureable(textureability); |
| 496 | |
| 497 | GrBackendTexture backend; |
| 498 | sk_sp<SkSurface> s = params.make(context, &backend); |
| 499 | if (!s) { |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 500 | continue; |
| 501 | } |
| 502 | |
| 503 | REPORTER_ASSERT(reporter, s->draw(ddl.get())); |
| 504 | s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0); |
| 505 | context->flush(); |
| 506 | gpu->testingOnly_flushGpuAndSync(); |
| 507 | s = nullptr; |
| 508 | params.cleanUpBackEnd(context, backend); |
| 509 | } |
| 510 | |
| 511 | } |
| 512 | |
Robert Phillips | 6b6fcc7 | 2018-03-30 13:57:00 -0400 | [diff] [blame] | 513 | //////////////////////////////////////////////////////////////////////////////// |
| 514 | // This tests the SkSurface::MakeRenderTarget variant that takes an SkSurfaceCharacterization. |
| 515 | // In particular, the SkSurface and the SkSurfaceCharacterization should always be compatible. |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 516 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLMakeRenderTargetTest, reporter, ctxInfo) { |
Robert Phillips | 6b6fcc7 | 2018-03-30 13:57:00 -0400 | [diff] [blame] | 517 | GrContext* context = ctxInfo.grContext(); |
| 518 | |
| 519 | for (int i = 0; i < SurfaceParameters::kNumParams; ++i) { |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 520 | SurfaceParameters params(context->backend()); |
Robert Phillips | 6b6fcc7 | 2018-03-30 13:57:00 -0400 | [diff] [blame] | 521 | params.modify(i); |
| 522 | |
| 523 | SkSurfaceCharacterization c = params.createCharacterization(context); |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 524 | GrBackendTexture backend; |
Robert Phillips | 6b6fcc7 | 2018-03-30 13:57:00 -0400 | [diff] [blame] | 525 | |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 526 | if (!c.isValid()) { |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 527 | sk_sp<SkSurface> tmp = params.make(context, &backend); |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 528 | |
| 529 | // If we couldn't characterize the surface we shouldn't be able to create it either |
| 530 | REPORTER_ASSERT(reporter, !tmp); |
| 531 | if (tmp) { |
| 532 | tmp = nullptr; |
| 533 | params.cleanUpBackEnd(context, backend); |
| 534 | } |
| 535 | continue; |
| 536 | } |
| 537 | |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 538 | sk_sp<SkSurface> s = params.make(context, &backend); |
Robert Phillips | 6b6fcc7 | 2018-03-30 13:57:00 -0400 | [diff] [blame] | 539 | if (!s) { |
| 540 | REPORTER_ASSERT(reporter, !c.isValid()); |
| 541 | continue; |
| 542 | } |
| 543 | |
| 544 | REPORTER_ASSERT(reporter, c.isValid()); |
| 545 | |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 546 | if (SurfaceParameters::kFBO0Count == i) { |
| 547 | // MakeRenderTarget doesn't support FBO0 |
| 548 | params.cleanUpBackEnd(context, backend); |
| 549 | continue; |
| 550 | } |
| 551 | |
Robert Phillips | 6b6fcc7 | 2018-03-30 13:57:00 -0400 | [diff] [blame] | 552 | s = SkSurface::MakeRenderTarget(context, c, SkBudgeted::kYes); |
| 553 | REPORTER_ASSERT(reporter, s); |
| 554 | |
| 555 | SkSurface_Gpu* g = static_cast<SkSurface_Gpu*>(s.get()); |
| 556 | REPORTER_ASSERT(reporter, g->isCompatible(c)); |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 557 | |
| 558 | s = nullptr; |
| 559 | params.cleanUpBackEnd(context, backend); |
Robert Phillips | 6b6fcc7 | 2018-03-30 13:57:00 -0400 | [diff] [blame] | 560 | } |
| 561 | } |
| 562 | |
| 563 | //////////////////////////////////////////////////////////////////////////////// |
Greg Daniel | f2336e4 | 2018-01-23 16:38:14 -0500 | [diff] [blame] | 564 | static constexpr int kSize = 8; |
| 565 | |
| 566 | struct TextureReleaseChecker { |
| 567 | TextureReleaseChecker() : fReleaseCount(0) {} |
| 568 | int fReleaseCount; |
| 569 | static void Release(void* self) { |
| 570 | static_cast<TextureReleaseChecker*>(self)->fReleaseCount++; |
| 571 | } |
| 572 | }; |
| 573 | |
| 574 | enum class DDLStage { kMakeImage, kDrawImage, kDetach, kDrawDDL }; |
| 575 | |
| 576 | // This tests the ability to create and use wrapped textures in a DDL world |
| 577 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLWrapBackendTest, reporter, ctxInfo) { |
| 578 | GrContext* context = ctxInfo.grContext(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 579 | GrGpu* gpu = context->priv().getGpu(); |
Brian Salomon | f777897 | 2018-03-08 10:13:17 -0500 | [diff] [blame] | 580 | GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture( |
Robert Phillips | 646f637 | 2018-09-25 09:31:10 -0400 | [diff] [blame] | 581 | nullptr, kSize, kSize, GrColorType::kRGBA_8888, false, GrMipMapped::kNo); |
Brian Salomon | f777897 | 2018-03-08 10:13:17 -0500 | [diff] [blame] | 582 | if (!backendTex.isValid()) { |
| 583 | return; |
Greg Daniel | f2336e4 | 2018-01-23 16:38:14 -0500 | [diff] [blame] | 584 | } |
Brian Salomon | f777897 | 2018-03-08 10:13:17 -0500 | [diff] [blame] | 585 | |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 586 | SurfaceParameters params(context->backend()); |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 587 | GrBackendTexture backend; |
Brian Salomon | f777897 | 2018-03-08 10:13:17 -0500 | [diff] [blame] | 588 | |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 589 | sk_sp<SkSurface> s = params.make(context, &backend); |
Brian Salomon | f777897 | 2018-03-08 10:13:17 -0500 | [diff] [blame] | 590 | if (!s) { |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 591 | gpu->deleteTestingOnlyBackendTexture(backendTex); |
Brian Salomon | f777897 | 2018-03-08 10:13:17 -0500 | [diff] [blame] | 592 | return; |
| 593 | } |
| 594 | |
| 595 | SkSurfaceCharacterization c; |
| 596 | SkAssertResult(s->characterize(&c)); |
| 597 | |
| 598 | std::unique_ptr<SkDeferredDisplayListRecorder> recorder(new SkDeferredDisplayListRecorder(c)); |
| 599 | |
| 600 | SkCanvas* canvas = recorder->getCanvas(); |
| 601 | if (!canvas) { |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 602 | s = nullptr; |
| 603 | params.cleanUpBackEnd(context, backend); |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 604 | gpu->deleteTestingOnlyBackendTexture(backendTex); |
Brian Salomon | f777897 | 2018-03-08 10:13:17 -0500 | [diff] [blame] | 605 | return; |
| 606 | } |
| 607 | |
| 608 | GrContext* deferredContext = canvas->getGrContext(); |
| 609 | if (!deferredContext) { |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 610 | s = nullptr; |
| 611 | params.cleanUpBackEnd(context, backend); |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 612 | gpu->deleteTestingOnlyBackendTexture(backendTex); |
Brian Salomon | f777897 | 2018-03-08 10:13:17 -0500 | [diff] [blame] | 613 | return; |
| 614 | } |
| 615 | |
| 616 | // Wrapped Backend Textures are not supported in DDL |
| 617 | sk_sp<SkImage> image = |
| 618 | SkImage::MakeFromAdoptedTexture(deferredContext, backendTex, kTopLeft_GrSurfaceOrigin, |
| 619 | kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr); |
| 620 | REPORTER_ASSERT(reporter, !image); |
| 621 | |
| 622 | TextureReleaseChecker releaseChecker; |
| 623 | image = SkImage::MakeFromTexture(deferredContext, backendTex, kTopLeft_GrSurfaceOrigin, |
| 624 | kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr, |
| 625 | TextureReleaseChecker::Release, &releaseChecker); |
| 626 | REPORTER_ASSERT(reporter, !image); |
| 627 | |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 628 | gpu->deleteTestingOnlyBackendTexture(backendTex); |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 629 | |
| 630 | s = nullptr; |
| 631 | params.cleanUpBackEnd(context, backend); |
Greg Daniel | f2336e4 | 2018-01-23 16:38:14 -0500 | [diff] [blame] | 632 | } |
| 633 | |
Brian Salomon | 59ef8c3 | 2019-01-30 12:20:56 -0500 | [diff] [blame] | 634 | static sk_sp<SkPromiseImageTexture> dummy_fulfill_proc(void*) { |
| 635 | SkASSERT(0); |
| 636 | return nullptr; |
| 637 | } |
Robert Phillips | 6ceaafa | 2018-03-15 16:53:06 -0400 | [diff] [blame] | 638 | static void dummy_release_proc(void*) { SkASSERT(0); } |
Brian Salomon | 59ef8c3 | 2019-01-30 12:20:56 -0500 | [diff] [blame] | 639 | static void dummy_done_proc(void*) {} |
Robert Phillips | 6ceaafa | 2018-03-15 16:53:06 -0400 | [diff] [blame] | 640 | |
Robert Phillips | 6b6fcc7 | 2018-03-30 13:57:00 -0400 | [diff] [blame] | 641 | //////////////////////////////////////////////////////////////////////////////// |
Robert Phillips | 6ceaafa | 2018-03-15 16:53:06 -0400 | [diff] [blame] | 642 | // Test out the behavior of an invalid DDLRecorder |
| 643 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLInvalidRecorder, reporter, ctxInfo) { |
| 644 | GrContext* context = ctxInfo.grContext(); |
| 645 | |
| 646 | { |
| 647 | SkImageInfo ii = SkImageInfo::MakeN32Premul(32, 32); |
| 648 | sk_sp<SkSurface> s = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, ii); |
| 649 | |
| 650 | SkSurfaceCharacterization characterization; |
| 651 | SkAssertResult(s->characterize(&characterization)); |
| 652 | |
| 653 | // never calling getCanvas means the backing surface is never allocated |
| 654 | SkDeferredDisplayListRecorder recorder(characterization); |
| 655 | } |
| 656 | |
| 657 | { |
| 658 | SkSurfaceCharacterization invalid; |
| 659 | |
| 660 | SkDeferredDisplayListRecorder recorder(invalid); |
| 661 | |
| 662 | const SkSurfaceCharacterization c = recorder.characterization(); |
| 663 | REPORTER_ASSERT(reporter, !c.isValid()); |
| 664 | REPORTER_ASSERT(reporter, !recorder.getCanvas()); |
| 665 | REPORTER_ASSERT(reporter, !recorder.detach()); |
| 666 | |
Greg Daniel | 60ea40c | 2019-02-12 13:38:44 -0500 | [diff] [blame] | 667 | const GrCaps* caps = context->priv().caps(); |
| 668 | GrBackendFormat format = caps->getBackendFormatFromColorType(kRGBA_8888_SkColorType); |
| 669 | |
Brian Salomon | f55e8d5 | 2019-01-30 17:28:20 -0500 | [diff] [blame] | 670 | sk_sp<SkImage> image = recorder.makePromiseTexture( |
| 671 | format, 32, 32, GrMipMapped::kNo, |
| 672 | kTopLeft_GrSurfaceOrigin, |
| 673 | kRGBA_8888_SkColorType, |
| 674 | kPremul_SkAlphaType, nullptr, |
| 675 | dummy_fulfill_proc, |
| 676 | dummy_release_proc, |
| 677 | dummy_done_proc, |
| 678 | nullptr, |
| 679 | SkDeferredDisplayListRecorder::DelayReleaseCallback::kNo); |
Robert Phillips | 6ceaafa | 2018-03-15 16:53:06 -0400 | [diff] [blame] | 680 | REPORTER_ASSERT(reporter, !image); |
| 681 | } |
| 682 | |
| 683 | } |
| 684 | |
Robert Phillips | 6b6fcc7 | 2018-03-30 13:57:00 -0400 | [diff] [blame] | 685 | //////////////////////////////////////////////////////////////////////////////// |
Robert Phillips | 874b535 | 2018-03-16 08:48:24 -0400 | [diff] [blame] | 686 | // Ensure that flushing while DDL recording doesn't cause a crash |
| 687 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLFlushWhileRecording, reporter, ctxInfo) { |
| 688 | GrContext* context = ctxInfo.grContext(); |
| 689 | |
| 690 | SkImageInfo ii = SkImageInfo::MakeN32Premul(32, 32); |
| 691 | sk_sp<SkSurface> s = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, ii); |
| 692 | |
| 693 | SkSurfaceCharacterization characterization; |
| 694 | SkAssertResult(s->characterize(&characterization)); |
| 695 | |
| 696 | SkDeferredDisplayListRecorder recorder(characterization); |
| 697 | SkCanvas* canvas = recorder.getCanvas(); |
| 698 | |
| 699 | canvas->flush(); |
| 700 | canvas->getGrContext()->flush(); |
| 701 | } |
Greg Daniel | f2336e4 | 2018-01-23 16:38:14 -0500 | [diff] [blame] | 702 | |
Robert Phillips | 6b6fcc7 | 2018-03-30 13:57:00 -0400 | [diff] [blame] | 703 | //////////////////////////////////////////////////////////////////////////////// |
Robert Phillips | f54883c | 2018-12-18 08:29:09 -0500 | [diff] [blame] | 704 | // Ensure that reusing a single DDLRecorder to create multiple DDLs works cleanly |
| 705 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLMultipleDDLs, reporter, ctxInfo) { |
| 706 | GrContext* context = ctxInfo.grContext(); |
| 707 | |
| 708 | SkImageInfo ii = SkImageInfo::MakeN32Premul(32, 32); |
| 709 | sk_sp<SkSurface> s = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, ii); |
| 710 | |
| 711 | SkBitmap bitmap; |
| 712 | bitmap.allocPixels(ii); |
| 713 | |
| 714 | SkSurfaceCharacterization characterization; |
| 715 | SkAssertResult(s->characterize(&characterization)); |
| 716 | |
| 717 | SkDeferredDisplayListRecorder recorder(characterization); |
| 718 | |
| 719 | SkCanvas* canvas1 = recorder.getCanvas(); |
| 720 | |
| 721 | canvas1->clear(SK_ColorRED); |
| 722 | |
| 723 | canvas1->save(); |
| 724 | canvas1->clipRect(SkRect::MakeXYWH(8, 8, 16, 16)); |
| 725 | |
| 726 | std::unique_ptr<SkDeferredDisplayList> ddl1 = recorder.detach(); |
| 727 | |
| 728 | SkCanvas* canvas2 = recorder.getCanvas(); |
| 729 | |
| 730 | SkPaint p; |
| 731 | p.setColor(SK_ColorGREEN); |
| 732 | canvas2->drawRect(SkRect::MakeWH(32, 32), p); |
| 733 | |
| 734 | std::unique_ptr<SkDeferredDisplayList> ddl2 = recorder.detach(); |
| 735 | |
| 736 | REPORTER_ASSERT(reporter, ddl1->priv().lazyProxyData()); |
| 737 | REPORTER_ASSERT(reporter, ddl2->priv().lazyProxyData()); |
| 738 | |
| 739 | // The lazy proxy data being different ensures that the SkSurface, SkCanvas and backing- |
| 740 | // lazy proxy are all different between the two DDLs |
| 741 | REPORTER_ASSERT(reporter, ddl1->priv().lazyProxyData() != ddl2->priv().lazyProxyData()); |
| 742 | |
| 743 | s->draw(ddl1.get()); |
| 744 | s->draw(ddl2.get()); |
| 745 | |
| 746 | // Make sure the clipRect from DDL1 didn't percolate into DDL2 |
| 747 | s->readPixels(ii, bitmap.getPixels(), bitmap.rowBytes(), 0, 0); |
| 748 | for (int y = 0; y < 32; ++y) { |
| 749 | for (int x = 0; x < 32; ++x) { |
| 750 | REPORTER_ASSERT(reporter, bitmap.getColor(x, y) == SK_ColorGREEN); |
| 751 | if (bitmap.getColor(x, y) != SK_ColorGREEN) { |
| 752 | return; // we only really need to report the error once |
| 753 | } |
| 754 | } |
| 755 | } |
| 756 | } |
| 757 | |
| 758 | //////////////////////////////////////////////////////////////////////////////// |
Robert Phillips | abf7b76 | 2018-03-21 12:13:37 -0400 | [diff] [blame] | 759 | // Check that the texture-specific flags (i.e., for external & rectangle textures) work |
| 760 | // for promise images. As such, this is a GL-only test. |
| 761 | DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(DDLTextureFlagsTest, reporter, ctxInfo) { |
| 762 | GrContext* context = ctxInfo.grContext(); |
| 763 | |
| 764 | SkImageInfo ii = SkImageInfo::MakeN32Premul(32, 32); |
| 765 | sk_sp<SkSurface> s = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, ii); |
| 766 | |
| 767 | SkSurfaceCharacterization characterization; |
| 768 | SkAssertResult(s->characterize(&characterization)); |
| 769 | |
| 770 | SkDeferredDisplayListRecorder recorder(characterization); |
| 771 | |
| 772 | for (GrGLenum target : { GR_GL_TEXTURE_EXTERNAL, GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_2D } ) { |
Greg Daniel | 09c9400 | 2018-06-08 22:11:51 +0000 | [diff] [blame] | 773 | for (auto mipMapped : { GrMipMapped::kNo, GrMipMapped::kYes }) { |
| 774 | GrBackendFormat format = GrBackendFormat::MakeGL(GR_GL_RGBA8, target); |
Robert Phillips | abf7b76 | 2018-03-21 12:13:37 -0400 | [diff] [blame] | 775 | |
Brian Salomon | f55e8d5 | 2019-01-30 17:28:20 -0500 | [diff] [blame] | 776 | sk_sp<SkImage> image = recorder.makePromiseTexture( |
| 777 | format, 32, 32, mipMapped, |
| 778 | kTopLeft_GrSurfaceOrigin, |
| 779 | kRGBA_8888_SkColorType, |
| 780 | kPremul_SkAlphaType, nullptr, |
| 781 | dummy_fulfill_proc, |
| 782 | dummy_release_proc, |
| 783 | dummy_done_proc, |
| 784 | nullptr, |
| 785 | SkDeferredDisplayListRecorder::DelayReleaseCallback::kNo); |
Greg Daniel | 09c9400 | 2018-06-08 22:11:51 +0000 | [diff] [blame] | 786 | if (GR_GL_TEXTURE_2D != target && mipMapped == GrMipMapped::kYes) { |
| 787 | REPORTER_ASSERT(reporter, !image); |
| 788 | continue; |
| 789 | } |
| 790 | REPORTER_ASSERT(reporter, image); |
Robert Phillips | abf7b76 | 2018-03-21 12:13:37 -0400 | [diff] [blame] | 791 | |
Jim Van Verth | 21bd60d | 2018-10-12 15:00:20 -0400 | [diff] [blame] | 792 | GrTextureProxy* backingProxy = ((SkImage_GpuBase*) image.get())->peekProxy(); |
Robert Phillips | abf7b76 | 2018-03-21 12:13:37 -0400 | [diff] [blame] | 793 | |
Greg Daniel | 09c9400 | 2018-06-08 22:11:51 +0000 | [diff] [blame] | 794 | REPORTER_ASSERT(reporter, backingProxy->mipMapped() == mipMapped); |
| 795 | if (GR_GL_TEXTURE_2D == target) { |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 796 | REPORTER_ASSERT(reporter, !backingProxy->hasRestrictedSampling()); |
Greg Daniel | 09c9400 | 2018-06-08 22:11:51 +0000 | [diff] [blame] | 797 | } else { |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 798 | REPORTER_ASSERT(reporter, backingProxy->hasRestrictedSampling()); |
Greg Daniel | 09c9400 | 2018-06-08 22:11:51 +0000 | [diff] [blame] | 799 | } |
Robert Phillips | abf7b76 | 2018-03-21 12:13:37 -0400 | [diff] [blame] | 800 | } |
| 801 | } |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | //////////////////////////////////////////////////////////////////////////////// |
| 805 | |
Robert Phillips | 646f637 | 2018-09-25 09:31:10 -0400 | [diff] [blame] | 806 | // Test colorType and pixelConfig compatibility. |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 807 | DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(DDLCompatibilityTest, reporter, ctxInfo) { |
| 808 | GrContext* context = ctxInfo.grContext(); |
| 809 | |
| 810 | for (int ct = 0; ct <= kLastEnum_SkColorType; ++ct) { |
| 811 | SkColorType colorType = static_cast<SkColorType>(ct); |
| 812 | |
Greg Daniel | 60ea40c | 2019-02-12 13:38:44 -0500 | [diff] [blame] | 813 | SurfaceParameters params(context->backend()); |
| 814 | params.setColorType(colorType); |
| 815 | params.setColorSpace(nullptr); |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 816 | |
Greg Daniel | 60ea40c | 2019-02-12 13:38:44 -0500 | [diff] [blame] | 817 | SkSurfaceCharacterization c = params.createCharacterization(context); |
| 818 | GrBackendTexture backend; |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 819 | |
Greg Daniel | 60ea40c | 2019-02-12 13:38:44 -0500 | [diff] [blame] | 820 | if (!c.isValid()) { |
| 821 | sk_sp<SkSurface> tmp = params.make(context, &backend); |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 822 | |
Greg Daniel | 60ea40c | 2019-02-12 13:38:44 -0500 | [diff] [blame] | 823 | // If we couldn't characterize the surface we shouldn't be able to create it either |
| 824 | REPORTER_ASSERT(reporter, !tmp); |
| 825 | if (tmp) { |
| 826 | tmp = nullptr; |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 827 | params.cleanUpBackEnd(context, backend); |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 828 | } |
Greg Daniel | 60ea40c | 2019-02-12 13:38:44 -0500 | [diff] [blame] | 829 | continue; |
| 830 | } |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 831 | |
Greg Daniel | 60ea40c | 2019-02-12 13:38:44 -0500 | [diff] [blame] | 832 | sk_sp<SkSurface> s = params.make(context, &backend); |
| 833 | REPORTER_ASSERT(reporter, s); |
| 834 | if (!s) { |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 835 | s = nullptr; |
| 836 | params.cleanUpBackEnd(context, backend); |
Greg Daniel | 60ea40c | 2019-02-12 13:38:44 -0500 | [diff] [blame] | 837 | continue; |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 838 | } |
Greg Daniel | 60ea40c | 2019-02-12 13:38:44 -0500 | [diff] [blame] | 839 | |
| 840 | SkSurface_Gpu* gpuSurface = static_cast<SkSurface_Gpu*>(s.get()); |
| 841 | REPORTER_ASSERT(reporter, gpuSurface->isCompatible(c)); |
| 842 | |
| 843 | s = nullptr; |
| 844 | params.cleanUpBackEnd(context, backend); |
| 845 | |
| 846 | s = SkSurface::MakeRenderTarget(context, c, SkBudgeted::kYes); |
| 847 | REPORTER_ASSERT(reporter, s); |
| 848 | if (!s) { |
| 849 | continue; |
| 850 | } |
| 851 | |
| 852 | gpuSurface = static_cast<SkSurface_Gpu*>(s.get()); |
| 853 | REPORTER_ASSERT(reporter, gpuSurface->isCompatible(c)); |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 854 | } |
Robert Phillips | abf7b76 | 2018-03-21 12:13:37 -0400 | [diff] [blame] | 855 | |
| 856 | } |