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