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