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