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