blob: e7591990406a6a7501375b8d2ff0095ac6a5d6ef [file] [log] [blame]
Robert Phillips7ffbcf92017-12-04 12:52:46 -05001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/core/SkBitmap.h"
9#include "include/core/SkCanvas.h"
Ben Wagner9707a7e2019-05-06 17:17:19 -040010#include "include/core/SkColor.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkColorSpace.h"
Robert Phillips4d5594d2020-02-21 14:24:40 -050012#include "include/core/SkDeferredDisplayList.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#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 Wagner9707a7e2019-05-06 17:17:19 -040023#include "include/core/SkTypes.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050024#include "include/gpu/GrBackendSurface.h"
Ben Wagner9707a7e2019-05-06 17:17:19 -040025#include "include/gpu/GrContextThreadSafeProxy.h"
Robert Phillips6d344c32020-07-06 10:56:46 -040026#include "include/gpu/GrDirectContext.h"
Robert Phillipsc8ae4942020-07-20 10:56:01 -040027#include "include/gpu/GrRecordingContext.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050028#include "include/gpu/GrTypes.h"
29#include "include/gpu/gl/GrGLTypes.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050030#include "include/private/GrTypesPriv.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050031#include "src/core/SkDeferredDisplayListPriv.h"
32#include "src/gpu/GrCaps.h"
Adlai Hollera0693042020-10-14 11:23:11 -040033#include "src/gpu/GrDirectContextPriv.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050034#include "src/gpu/GrGpu.h"
Robert Phillipsc8ae4942020-07-20 10:56:01 -040035#include "src/gpu/GrRecordingContextPriv.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050036#include "src/gpu/GrRenderTargetContext.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040037#include "src/gpu/GrRenderTargetProxy.h"
38#include "src/gpu/GrTextureProxy.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050039#include "src/gpu/SkGpuDevice.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050040#include "src/gpu/gl/GrGLDefines.h"
Ben Wagner9707a7e2019-05-06 17:17:19 -040041#include "src/image/SkImage_GpuBase.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050042#include "src/image/SkSurface_Gpu.h"
43#include "tests/Test.h"
Robert Phillipsee5fd132019-05-07 13:29:22 -040044#include "tests/TestUtils.h"
Brian Salomonf9b00422020-10-08 16:00:14 -040045#include "tools/gpu/BackendSurfaceFactory.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050046#include "tools/gpu/GrContextFactory.h"
Brian Salomon72050802020-10-12 20:45:06 -040047#include "tools/gpu/ManagedBackendTexture.h"
Ben Wagner9707a7e2019-05-06 17:17:19 -040048
49#include <initializer_list>
50#include <memory>
51#include <utility>
Robert Phillipsfc711a22018-02-13 17:03:00 -050052
Robert Phillips3cd54322019-07-10 09:28:59 -040053#ifdef SK_VULKAN
54#include "src/gpu/vk/GrVkCaps.h"
55#endif
56
Robert Phillips7ffbcf92017-12-04 12:52:46 -050057class SurfaceParameters {
58public:
Robert Phillips3cd54322019-07-10 09:28:59 -040059 static const int kNumParams = 12;
Robert Phillips3cd54322019-07-10 09:28:59 -040060 static const int kFBO0Count = 9;
Robert Phillips7ffbcf92017-12-04 12:52:46 -050061
Robert Phillipsc8ae4942020-07-20 10:56:01 -040062 SurfaceParameters(GrRecordingContext* rContext)
63 : fBackend(rContext->backend())
Brian Salomonf9b00422020-10-08 16:00:14 -040064 , fCanBeProtected(false)
Robert Phillipsb45f47d2019-02-03 17:17:54 -050065 , fWidth(64)
Robert Phillips7ffbcf92017-12-04 12:52:46 -050066 , fHeight(64)
67 , fOrigin(kTopLeft_GrSurfaceOrigin)
68 , fColorType(kRGBA_8888_SkColorType)
69 , fColorSpace(SkColorSpace::MakeSRGB())
Brian Salomonbdecacf2018-02-02 20:32:49 -050070 , fSampleCount(1)
Robert Phillipse8fabb22018-02-04 14:33:21 -050071 , fSurfaceProps(0x0, kUnknown_SkPixelGeometry)
Robert Phillipsb45f47d2019-02-03 17:17:54 -050072 , fShouldCreateMipMaps(true)
73 , fUsesGLFBO0(false)
Robert Phillips3cd54322019-07-10 09:28:59 -040074 , fIsTextureable(true)
Greg Daniel638b2e82020-08-27 14:29:00 -040075 , fIsProtected(GrProtected::kNo)
76 , fVkRTSupportsInputAttachment(false) {
Robert Phillips3cd54322019-07-10 09:28:59 -040077#ifdef SK_VULKAN
Brian Salomonf9b00422020-10-08 16:00:14 -040078 if (rContext->backend() == GrBackendApi::kVulkan) {
79 auto vkCaps = static_cast<const GrVkCaps*>(rContext->priv().caps());
80 fCanBeProtected = vkCaps->supportsProtectedMemory();
81 if (fCanBeProtected) {
82 fIsProtected = GrProtected::kYes;
83 }
Robert Phillips3cd54322019-07-10 09:28:59 -040084 }
85#endif
Brian Salomonf9b00422020-10-08 16:00:14 -040086 if (!rContext->priv().caps()->mipmapSupport()) {
87 fShouldCreateMipMaps = false;
88 }
Robert Phillipse8fabb22018-02-04 14:33:21 -050089 }
Robert Phillips7ffbcf92017-12-04 12:52:46 -050090
91 int sampleCount() const { return fSampleCount; }
92
Robert Phillipsbe77a022018-04-03 17:17:05 -040093 void setColorType(SkColorType ct) { fColorType = ct; }
Robert Phillipsd8f79a22019-06-24 13:25:42 -040094 SkColorType colorType() const { return fColorType; }
Robert Phillipsbe77a022018-04-03 17:17:05 -040095 void setColorSpace(sk_sp<SkColorSpace> cs) { fColorSpace = std::move(cs); }
Brian Salomonf9b00422020-10-08 16:00:14 -040096 void disableTextureability() {
97 fIsTextureable = false;
98 fShouldCreateMipMaps = false;
99 }
Brian Salomon4687bdd2019-05-09 16:28:04 -0400100 void setShouldCreateMipMaps(bool shouldCreateMipMaps) {
101 fShouldCreateMipMaps = shouldCreateMipMaps;
102 }
Greg Daniel638b2e82020-08-27 14:29:00 -0400103 void setVkRTInputAttachmentSupport(bool inputSupport) {
104 fVkRTSupportsInputAttachment = inputSupport;
105 }
Robert Phillipsbe77a022018-04-03 17:17:05 -0400106
Brian Salomonf9b00422020-10-08 16:00:14 -0400107 // Modify the SurfaceParameters in just one way. Returns false if the requested modification had
108 // no effect.
109 bool modify(int i) {
110 bool changed = false;
111 auto set = [&changed](auto& var, auto value) {
112 if (var != value) {
113 changed = true;
114 }
115 var = value;
116 };
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500117 switch (i) {
118 case 0:
Brian Salomonf9b00422020-10-08 16:00:14 -0400119 set(fWidth, 63);
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500120 break;
121 case 1:
Brian Salomonf9b00422020-10-08 16:00:14 -0400122 set(fHeight, 63);
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500123 break;
124 case 2:
Brian Salomonf9b00422020-10-08 16:00:14 -0400125 set(fOrigin, kBottomLeft_GrSurfaceOrigin);
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500126 break;
127 case 3:
Brian Salomonf9b00422020-10-08 16:00:14 -0400128 set(fColorType, kRGBA_F16_SkColorType);
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500129 break;
130 case 4:
Brian Osman37f99882018-08-09 10:26:57 -0400131 // This just needs to be a colorSpace different from that returned by MakeSRGB().
132 // In this case we just change the gamut.
Brian Salomonf9b00422020-10-08 16:00:14 -0400133 set(fColorSpace, SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB,
134 SkNamedGamut::kAdobeRGB));
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500135 break;
Brian Salomonf9b00422020-10-08 16:00:14 -0400136 case 5:
137 set(fSampleCount, 4);
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500138 break;
139 case 6:
Brian Salomonf9b00422020-10-08 16:00:14 -0400140 set(fSurfaceProps, SkSurfaceProps(0x0, kRGB_H_SkPixelGeometry));
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500141 break;
142 case 7:
Brian Salomonf9b00422020-10-08 16:00:14 -0400143 set(fSurfaceProps, SkSurfaceProps(SkSurfaceProps::kUseDeviceIndependentFonts_Flag,
144 kUnknown_SkPixelGeometry));
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500145 break;
Robert Phillipse8fabb22018-02-04 14:33:21 -0500146 case 8:
Brian Salomonf9b00422020-10-08 16:00:14 -0400147 set(fShouldCreateMipMaps, false);
Robert Phillipse8fabb22018-02-04 14:33:21 -0500148 break;
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500149 case 9:
150 if (GrBackendApi::kOpenGL == fBackend) {
Brian Salomonf9b00422020-10-08 16:00:14 -0400151 set(fUsesGLFBO0, true);
152 set(fShouldCreateMipMaps, false); // needs to changed in tandem w/ textureability
153 set(fIsTextureable, false);
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500154 }
155 break;
156 case 10:
Brian Salomonf9b00422020-10-08 16:00:14 -0400157 set(fShouldCreateMipMaps, false); // needs to changed in tandem w/ textureability
158 set(fIsTextureable, false);
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500159 break;
Robert Phillips3cd54322019-07-10 09:28:59 -0400160 case 11:
Brian Salomonf9b00422020-10-08 16:00:14 -0400161 if (fCanBeProtected) {
162 set(fIsProtected, GrProtected(!static_cast<bool>(fIsProtected)));
163 }
Robert Phillips3cd54322019-07-10 09:28:59 -0400164 break;
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500165 }
Brian Salomonf9b00422020-10-08 16:00:14 -0400166 return changed;
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500167 }
168
Robert Phillipsc8ae4942020-07-20 10:56:01 -0400169 SkSurfaceCharacterization createCharacterization(GrDirectContext* dContext) const {
170 size_t maxResourceBytes = dContext->getResourceCacheLimit();
Robert Phillipsfc711a22018-02-13 17:03:00 -0500171
Robert Phillipsc8ae4942020-07-20 10:56:01 -0400172 if (!dContext->colorTypeSupportedAsSurface(fColorType)) {
Robert Phillipsd470e1b2019-09-04 15:05:35 -0400173 return SkSurfaceCharacterization();
174 }
175
Robert Phillipsfc711a22018-02-13 17:03:00 -0500176 // Note that Ganesh doesn't make use of the SkImageInfo's alphaType
177 SkImageInfo ii = SkImageInfo::Make(fWidth, fHeight, fColorType,
178 kPremul_SkAlphaType, fColorSpace);
179
Robert Phillipsc8ae4942020-07-20 10:56:01 -0400180 GrBackendFormat backendFormat = dContext->defaultBackendFormat(fColorType,
181 GrRenderable::kYes);
Robert Phillipsbe77a022018-04-03 17:17:05 -0400182 if (!backendFormat.isValid()) {
183 return SkSurfaceCharacterization();
184 }
Robert Phillipsfc711a22018-02-13 17:03:00 -0500185
Robert Phillipsc8ae4942020-07-20 10:56:01 -0400186 SkSurfaceCharacterization c = dContext->threadSafeProxy()->createCharacterization(
Robert Phillipsfc711a22018-02-13 17:03:00 -0500187 maxResourceBytes, ii, backendFormat, fSampleCount,
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500188 fOrigin, fSurfaceProps, fShouldCreateMipMaps,
Greg Daniel638b2e82020-08-27 14:29:00 -0400189 fUsesGLFBO0, fIsTextureable, fIsProtected,
190 fVkRTSupportsInputAttachment);
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400191 return c;
192 }
193
194 // Create a DDL whose characterization captures the current settings
Robert Phillipsc8ae4942020-07-20 10:56:01 -0400195 sk_sp<SkDeferredDisplayList> createDDL(GrDirectContext* dContext) const {
196 SkSurfaceCharacterization c = this->createCharacterization(dContext);
Robert Phillipsfc711a22018-02-13 17:03:00 -0500197 SkAssertResult(c.isValid());
Robert Phillipse8fabb22018-02-04 14:33:21 -0500198
199 SkDeferredDisplayListRecorder r(c);
200 SkCanvas* canvas = r.getCanvas();
201 if (!canvas) {
202 return nullptr;
203 }
204
205 canvas->drawRect(SkRect::MakeXYWH(10, 10, 10, 10), SkPaint());
206 return r.detach();
207 }
208
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500209 // Create the surface with the current set of parameters
Brian Salomonf9b00422020-10-08 16:00:14 -0400210 sk_sp<SkSurface> make(GrDirectContext* dContext) const {
Robert Phillipsc8ae4942020-07-20 10:56:01 -0400211 const SkSurfaceCharacterization c = this->createCharacterization(dContext);
Robert Phillipsd8f79a22019-06-24 13:25:42 -0400212
John Rosasco24cbdab2019-09-25 14:14:35 -0700213#ifdef SK_GL
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500214 if (fUsesGLFBO0) {
Robert Phillipsc8ae4942020-07-20 10:56:01 -0400215 if (GrBackendApi::kOpenGL != dContext->backend()) {
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500216 return nullptr;
217 }
218
219 GrGLFramebufferInfo fboInfo;
220 fboInfo.fFBOID = 0;
221 fboInfo.fFormat = GR_GL_RGBA8;
222 static constexpr int kStencilBits = 8;
223 GrBackendRenderTarget backendRT(fWidth, fHeight, 1, kStencilBits, fboInfo);
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500224
225 if (!backendRT.isValid()) {
226 return nullptr;
227 }
228
Robert Phillipsc8ae4942020-07-20 10:56:01 -0400229 sk_sp<SkSurface> result = SkSurface::MakeFromBackendRenderTarget(dContext, backendRT,
Robert Phillipsd8f79a22019-06-24 13:25:42 -0400230 fOrigin, fColorType,
231 fColorSpace,
232 &fSurfaceProps);
Robert Phillips9907e6e2019-06-25 14:47:04 -0400233 SkASSERT(result->isCompatible(c));
Robert Phillipsd8f79a22019-06-24 13:25:42 -0400234 return result;
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500235 }
John Rosasco24cbdab2019-09-25 14:14:35 -0700236#endif
Robert Phillipsc046ff02019-07-01 10:34:03 -0400237
Robert Phillipsbe77a022018-04-03 17:17:05 -0400238 sk_sp<SkSurface> surface;
Brian Salomonf9b00422020-10-08 16:00:14 -0400239 if (fIsTextureable) {
240 surface = sk_gpu_test::MakeBackendTextureSurface(dContext,
241 {fWidth, fHeight},
242 fOrigin,
243 fSampleCount,
244 fColorType,
245 fColorSpace,
246 GrMipmapped(fShouldCreateMipMaps),
247 fIsProtected,
248 &fSurfaceProps);
Robert Phillipsbe77a022018-04-03 17:17:05 -0400249 } else {
Brian Salomonf9b00422020-10-08 16:00:14 -0400250 // Create a surface w/ the current parameters but make it non-textureable
251 SkASSERT(!fShouldCreateMipMaps);
252 surface = sk_gpu_test::MakeBackendRenderTargetSurface(dContext,
253 {fWidth, fHeight},
254 fOrigin,
255 fSampleCount,
256 fColorType,
257 fColorSpace,
258 fIsProtected,
259 &fSurfaceProps);
Robert Phillipsbe77a022018-04-03 17:17:05 -0400260 }
Robert Phillipse8fabb22018-02-04 14:33:21 -0500261
262 if (!surface) {
Robert Phillipsc046ff02019-07-01 10:34:03 -0400263 SkASSERT(!c.isValid());
Robert Phillipse8fabb22018-02-04 14:33:21 -0500264 return nullptr;
265 }
266
Brian Salomonf9b00422020-10-08 16:00:14 -0400267 GrBackendTexture texture =
268 surface->getBackendTexture(SkSurface::kFlushRead_BackendHandleAccess);
269 if (texture.isValid()) {
270 SkASSERT(c.isCompatible(texture));
271 }
Robert Phillipsc046ff02019-07-01 10:34:03 -0400272 SkASSERT(c.isValid());
Robert Phillips9907e6e2019-06-25 14:47:04 -0400273 SkASSERT(surface->isCompatible(c));
Robert Phillipse8fabb22018-02-04 14:33:21 -0500274 return surface;
275 }
276
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500277private:
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500278 GrBackendApi fBackend;
Brian Salomonf9b00422020-10-08 16:00:14 -0400279 bool fCanBeProtected;
280
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500281 int fWidth;
282 int fHeight;
283 GrSurfaceOrigin fOrigin;
284 SkColorType fColorType;
285 sk_sp<SkColorSpace> fColorSpace;
286 int fSampleCount;
287 SkSurfaceProps fSurfaceProps;
Robert Phillipse8fabb22018-02-04 14:33:21 -0500288 bool fShouldCreateMipMaps;
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500289 bool fUsesGLFBO0;
290 bool fIsTextureable;
Robert Phillips3cd54322019-07-10 09:28:59 -0400291 GrProtected fIsProtected;
Greg Daniel638b2e82020-08-27 14:29:00 -0400292 bool fVkRTSupportsInputAttachment;
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500293};
294
Robert Phillipsc1267c62018-04-04 11:12:39 -0400295// Test out operator== && operator!=
296DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLOperatorEqTest, reporter, ctxInfo) {
Robert Phillips6d344c32020-07-06 10:56:46 -0400297 auto context = ctxInfo.directContext();
Robert Phillipsc1267c62018-04-04 11:12:39 -0400298
Brian Salomonf9b00422020-10-08 16:00:14 -0400299 for (int i = -1; i < SurfaceParameters::kNumParams; ++i) {
Robert Phillips3cd54322019-07-10 09:28:59 -0400300 SurfaceParameters params1(context);
Brian Salomonf9b00422020-10-08 16:00:14 -0400301 bool didModify1 = i >= 0 && params1.modify(i);
Robert Phillipsc1267c62018-04-04 11:12:39 -0400302
303 SkSurfaceCharacterization char1 = params1.createCharacterization(context);
304 if (!char1.isValid()) {
305 continue; // can happen on some platforms (ChromeOS)
306 }
307
Brian Salomonf9b00422020-10-08 16:00:14 -0400308 for (int j = -1; j < SurfaceParameters::kNumParams; ++j) {
Robert Phillips3cd54322019-07-10 09:28:59 -0400309 SurfaceParameters params2(context);
Brian Salomonf9b00422020-10-08 16:00:14 -0400310 bool didModify2 = j >= 0 && params2.modify(j);
Robert Phillipsc1267c62018-04-04 11:12:39 -0400311
312 SkSurfaceCharacterization char2 = params2.createCharacterization(context);
313 if (!char2.isValid()) {
314 continue; // can happen on some platforms (ChromeOS)
315 }
316
Brian Salomonf9b00422020-10-08 16:00:14 -0400317 if (i == j || (!didModify1 && !didModify2)) {
Robert Phillipsc1267c62018-04-04 11:12:39 -0400318 REPORTER_ASSERT(reporter, char1 == char2);
319 } else {
320 REPORTER_ASSERT(reporter, char1 != char2);
321 }
Robert Phillipsc1267c62018-04-04 11:12:39 -0400322 }
323 }
324
325 {
Robert Phillips3cd54322019-07-10 09:28:59 -0400326 SurfaceParameters params(context);
Robert Phillipsc1267c62018-04-04 11:12:39 -0400327
328 SkSurfaceCharacterization valid = params.createCharacterization(context);
329 SkASSERT(valid.isValid());
330
331 SkSurfaceCharacterization inval1, inval2;
332 SkASSERT(!inval1.isValid() && !inval2.isValid());
333
334 REPORTER_ASSERT(reporter, inval1 != inval2);
335 REPORTER_ASSERT(reporter, valid != inval1);
336 REPORTER_ASSERT(reporter, inval1 != valid);
337 }
338}
339
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400340////////////////////////////////////////////////////////////////////////////////
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500341// This tests SkSurfaceCharacterization/SkSurface compatibility
Robert Phillipsc8ae4942020-07-20 10:56:01 -0400342void DDLSurfaceCharacterizationTestImpl(GrDirectContext* dContext, skiatest::Reporter* reporter) {
Robert Phillips9e441ee2018-02-01 15:14:55 -0500343 // Create a bitmap that we can readback into
344 SkImageInfo imageInfo = SkImageInfo::Make(64, 64, kRGBA_8888_SkColorType,
345 kPremul_SkAlphaType);
346 SkBitmap bitmap;
347 bitmap.allocPixels(imageInfo);
348
Adlai Hollerf19bbb52020-06-29 10:00:08 -0400349 sk_sp<SkDeferredDisplayList> ddl;
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500350
351 // First, create a DDL using the stock SkSurface parameters
352 {
Robert Phillipsc8ae4942020-07-20 10:56:01 -0400353 SurfaceParameters params(dContext);
Greg Daniel638b2e82020-08-27 14:29:00 -0400354 if (dContext->backend() == GrBackendApi::kVulkan) {
355 params.setVkRTInputAttachmentSupport(true);
356 }
Robert Phillipsc8ae4942020-07-20 10:56:01 -0400357 ddl = params.createDDL(dContext);
Robert Phillipsfc711a22018-02-13 17:03:00 -0500358 SkAssertResult(ddl);
Robert Phillipse8fabb22018-02-04 14:33:21 -0500359
360 // The DDL should draw into an SkSurface created with the same parameters
Brian Salomonf9b00422020-10-08 16:00:14 -0400361 sk_sp<SkSurface> s = params.make(dContext);
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500362 if (!s) {
363 return;
364 }
365
Adlai Holler7580ad42020-06-24 13:45:25 -0400366 REPORTER_ASSERT(reporter, s->draw(ddl));
Robert Phillips9e441ee2018-02-01 15:14:55 -0500367 s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
Brian Salomonf9b00422020-10-08 16:00:14 -0400368
369 dContext->flush();
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500370 }
371
372 // Then, alter each parameter in turn and check that the DDL & surface are incompatible
373 for (int i = 0; i < SurfaceParameters::kNumParams; ++i) {
Robert Phillipsc8ae4942020-07-20 10:56:01 -0400374 SurfaceParameters params(dContext);
Brian Salomonf9b00422020-10-08 16:00:14 -0400375 if (!params.modify(i)) {
376 continue;
Robert Phillips3cd54322019-07-10 09:28:59 -0400377 }
378
Brian Salomonf9b00422020-10-08 16:00:14 -0400379 sk_sp<SkSurface> s = params.make(dContext);
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500380 if (!s) {
381 continue;
382 }
383
Adlai Holler7580ad42020-06-24 13:45:25 -0400384 REPORTER_ASSERT(reporter, !s->draw(ddl),
Robert Phillipse8fabb22018-02-04 14:33:21 -0500385 "DDLSurfaceCharacterizationTest failed on parameter: %d\n", i);
Brian Salomonf9b00422020-10-08 16:00:14 -0400386 dContext->flush();
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500387 }
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500388
389 // Next test the compatibility of resource cache parameters
390 {
Robert Phillipsc8ae4942020-07-20 10:56:01 -0400391 const SurfaceParameters params(dContext);
Robert Phillipsbe77a022018-04-03 17:17:05 -0400392
Brian Salomonf9b00422020-10-08 16:00:14 -0400393 sk_sp<SkSurface> s = params.make(dContext);
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500394
Robert Phillipsc8ae4942020-07-20 10:56:01 -0400395 size_t maxResourceBytes = dContext->getResourceCacheLimit();
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500396
Robert Phillipsc8ae4942020-07-20 10:56:01 -0400397 dContext->setResourceCacheLimit(maxResourceBytes/2);
Adlai Holler7580ad42020-06-24 13:45:25 -0400398 REPORTER_ASSERT(reporter, !s->draw(ddl));
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500399
Robert Phillips9e441ee2018-02-01 15:14:55 -0500400 // DDL TODO: once proxies/ops can be de-instantiated we can re-enable these tests.
401 // For now, DDLs are drawn once.
402#if 0
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500403 // resource limits >= those at characterization time are accepted
404 context->setResourceCacheLimits(2*maxResourceCount, maxResourceBytes);
Adlai Holler7580ad42020-06-24 13:45:25 -0400405 REPORTER_ASSERT(reporter, s->draw(ddl));
Robert Phillips9e441ee2018-02-01 15:14:55 -0500406 s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500407
408 context->setResourceCacheLimits(maxResourceCount, 2*maxResourceBytes);
Adlai Holler7580ad42020-06-24 13:45:25 -0400409 REPORTER_ASSERT(reporter, s->draw(ddl));
Robert Phillips9e441ee2018-02-01 15:14:55 -0500410 s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500411
412 context->setResourceCacheLimits(maxResourceCount, maxResourceBytes);
Adlai Holler7580ad42020-06-24 13:45:25 -0400413 REPORTER_ASSERT(reporter, s->draw(ddl));
Robert Phillips9e441ee2018-02-01 15:14:55 -0500414 s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
415#endif
Robert Phillipsbe77a022018-04-03 17:17:05 -0400416
Brian Salomonf9b00422020-10-08 16:00:14 -0400417 dContext->flush();
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500418 }
419
Robert Phillipse8fabb22018-02-04 14:33:21 -0500420 // Test that the textureability of the DDL characterization can block a DDL draw
421 {
Robert Phillipsc8ae4942020-07-20 10:56:01 -0400422 SurfaceParameters params(dContext);
Brian Salomonf9b00422020-10-08 16:00:14 -0400423 params.disableTextureability();
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500424
Brian Salomonf9b00422020-10-08 16:00:14 -0400425 sk_sp<SkSurface> s = params.make(dContext);
Robert Phillipse8fabb22018-02-04 14:33:21 -0500426 if (s) {
Adlai Holler7580ad42020-06-24 13:45:25 -0400427 REPORTER_ASSERT(reporter, !s->draw(ddl)); // bc the DDL was made w/ textureability
Robert Phillipse8fabb22018-02-04 14:33:21 -0500428
Brian Salomonf9b00422020-10-08 16:00:14 -0400429 dContext->flush();
Robert Phillipse8fabb22018-02-04 14:33:21 -0500430 }
431 }
432
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500433 // Make sure non-GPU-backed surfaces fail characterization
434 {
435 SkImageInfo ii = SkImageInfo::MakeN32(64, 64, kOpaque_SkAlphaType);
436
437 sk_sp<SkSurface> rasterSurface = SkSurface::MakeRaster(ii);
438 SkSurfaceCharacterization c;
439 REPORTER_ASSERT(reporter, !rasterSurface->characterize(&c));
440 }
Robert Phillips94458ee2018-03-06 13:41:51 -0500441
442 // Exercise the createResized method
443 {
Robert Phillipsc8ae4942020-07-20 10:56:01 -0400444 SurfaceParameters params(dContext);
Robert Phillips94458ee2018-03-06 13:41:51 -0500445
Brian Salomonf9b00422020-10-08 16:00:14 -0400446 sk_sp<SkSurface> s = params.make(dContext);
Robert Phillips94458ee2018-03-06 13:41:51 -0500447 if (!s) {
448 return;
449 }
450
451 SkSurfaceCharacterization char0;
452 SkAssertResult(s->characterize(&char0));
453
454 // Too small
455 SkSurfaceCharacterization char1 = char0.createResized(-1, -1);
456 REPORTER_ASSERT(reporter, !char1.isValid());
457
458 // Too large
459 SkSurfaceCharacterization char2 = char0.createResized(1000000, 32);
460 REPORTER_ASSERT(reporter, !char2.isValid());
461
462 // Just right
463 SkSurfaceCharacterization char3 = char0.createResized(32, 32);
464 REPORTER_ASSERT(reporter, char3.isValid());
465 REPORTER_ASSERT(reporter, 32 == char3.width());
466 REPORTER_ASSERT(reporter, 32 == char3.height());
467 }
Robert Phillipsa975ef32019-10-03 11:09:17 -0400468
469 // Exercise the createColorSpace method
470 {
Robert Phillipsc8ae4942020-07-20 10:56:01 -0400471 SurfaceParameters params(dContext);
Robert Phillipsa975ef32019-10-03 11:09:17 -0400472
Brian Salomonf9b00422020-10-08 16:00:14 -0400473 sk_sp<SkSurface> s = params.make(dContext);
Robert Phillipsa975ef32019-10-03 11:09:17 -0400474 if (!s) {
475 return;
476 }
477
478 SkSurfaceCharacterization char0;
479 SkAssertResult(s->characterize(&char0));
480
481 // The default params create an sRGB color space
482 REPORTER_ASSERT(reporter, char0.colorSpace()->isSRGB());
483 REPORTER_ASSERT(reporter, !char0.colorSpace()->gammaIsLinear());
484
485 {
486 sk_sp<SkColorSpace> newCS = SkColorSpace::MakeSRGBLinear();
487
488 SkSurfaceCharacterization char1 = char0.createColorSpace(std::move(newCS));
489 REPORTER_ASSERT(reporter, char1.isValid());
490 REPORTER_ASSERT(reporter, !char1.colorSpace()->isSRGB());
491 REPORTER_ASSERT(reporter, char1.colorSpace()->gammaIsLinear());
492 }
493
494 {
495 SkSurfaceCharacterization char2 = char0.createColorSpace(nullptr);
496 REPORTER_ASSERT(reporter, char2.isValid());
497 REPORTER_ASSERT(reporter, !char2.colorSpace());
498 }
499
500 {
501 sk_sp<SkColorSpace> newCS = SkColorSpace::MakeSRGBLinear();
502
503 SkSurfaceCharacterization invalid;
504 REPORTER_ASSERT(reporter, !invalid.isValid());
505 SkSurfaceCharacterization stillInvalid = invalid.createColorSpace(std::move(newCS));
506 REPORTER_ASSERT(reporter, !stillInvalid.isValid());
507 }
Robert Phillipsa975ef32019-10-03 11:09:17 -0400508 }
Robert Phillipsb3c061a2020-02-13 13:24:47 -0500509
510 // Exercise the createBackendFormat method
511 {
Robert Phillipsc8ae4942020-07-20 10:56:01 -0400512 SurfaceParameters params(dContext);
Robert Phillipsb3c061a2020-02-13 13:24:47 -0500513
Brian Salomonf9b00422020-10-08 16:00:14 -0400514 sk_sp<SkSurface> s = params.make(dContext);
Robert Phillipsb3c061a2020-02-13 13:24:47 -0500515 if (!s) {
516 return;
517 }
518
519 SkSurfaceCharacterization char0;
520 SkAssertResult(s->characterize(&char0));
521
522 // The default params create a renderable RGBA8 surface
Robert Phillipsc8ae4942020-07-20 10:56:01 -0400523 auto originalBackendFormat = dContext->defaultBackendFormat(kRGBA_8888_SkColorType,
524 GrRenderable::kYes);
Robert Phillipsb3c061a2020-02-13 13:24:47 -0500525 REPORTER_ASSERT(reporter, originalBackendFormat.isValid());
526 REPORTER_ASSERT(reporter, char0.backendFormat() == originalBackendFormat);
527
Robert Phillipsc8ae4942020-07-20 10:56:01 -0400528 auto newBackendFormat = dContext->defaultBackendFormat(kRGB_565_SkColorType,
529 GrRenderable::kYes);
Robert Phillipsb3c061a2020-02-13 13:24:47 -0500530
531 if (newBackendFormat.isValid()) {
532 SkSurfaceCharacterization char1 = char0.createBackendFormat(kRGB_565_SkColorType,
533 newBackendFormat);
534 REPORTER_ASSERT(reporter, char1.isValid());
535 REPORTER_ASSERT(reporter, char1.backendFormat() == newBackendFormat);
536
537 SkSurfaceCharacterization invalid;
538 REPORTER_ASSERT(reporter, !invalid.isValid());
539 auto stillInvalid = invalid.createBackendFormat(kRGB_565_SkColorType,
540 newBackendFormat);
541 REPORTER_ASSERT(reporter, !stillInvalid.isValid());
542 }
Robert Phillipsb3c061a2020-02-13 13:24:47 -0500543 }
544
545 // Exercise the createFBO0 method
Robert Phillipsc8ae4942020-07-20 10:56:01 -0400546 if (dContext->backend() == GrBackendApi::kOpenGL) {
547 SurfaceParameters params(dContext);
Greg Daniel638b2e82020-08-27 14:29:00 -0400548 // If the original characterization is textureable then we will fail trying to make an
549 // FBO0 characterization
Brian Salomonf9b00422020-10-08 16:00:14 -0400550 params.disableTextureability();
Robert Phillipsb3c061a2020-02-13 13:24:47 -0500551
Brian Salomonf9b00422020-10-08 16:00:14 -0400552 sk_sp<SkSurface> s = params.make(dContext);
Robert Phillipsb3c061a2020-02-13 13:24:47 -0500553 if (!s) {
554 return;
555 }
556
557 SkSurfaceCharacterization char0;
558 SkAssertResult(s->characterize(&char0));
559
560 // The default params create a non-FBO0 surface
561 REPORTER_ASSERT(reporter, !char0.usesGLFBO0());
562
563 {
564 SkSurfaceCharacterization char1 = char0.createFBO0(true);
565 REPORTER_ASSERT(reporter, char1.isValid());
566 REPORTER_ASSERT(reporter, char1.usesGLFBO0());
567 }
568
569 {
570 SkSurfaceCharacterization invalid;
571 REPORTER_ASSERT(reporter, !invalid.isValid());
572 SkSurfaceCharacterization stillInvalid = invalid.createFBO0(true);
573 REPORTER_ASSERT(reporter, !stillInvalid.isValid());
574 }
Robert Phillipsb3c061a2020-02-13 13:24:47 -0500575 }
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500576}
577
Robert Phillips2dbcbe82020-03-05 11:16:39 -0500578#ifdef SK_GL
579
580// Test out the surface compatibility checks regarding FBO0-ness. This test constructs
581// two parallel arrays of characterizations and surfaces in the order:
582// FBO0 w/ MSAA, FBO0 w/o MSAA, not-FBO0 w/ MSAA, not-FBO0 w/o MSAA
583// and then tries all sixteen combinations to check the expected compatibility.
584// Note: this is a GL-only test
585DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(CharacterizationFBO0nessTest, reporter, ctxInfo) {
Robert Phillips6d344c32020-07-06 10:56:46 -0400586 auto context = ctxInfo.directContext();
Robert Phillips2dbcbe82020-03-05 11:16:39 -0500587 const GrCaps* caps = context->priv().caps();
588 sk_sp<GrContextThreadSafeProxy> proxy = context->threadSafeProxy();
589 const size_t resourceCacheLimit = context->getResourceCacheLimit();
590
591 GrBackendFormat format = GrBackendFormat::MakeGL(GR_GL_RGBA8, GR_GL_TEXTURE_2D);
592
593 int availableSamples = caps->getRenderTargetSampleCount(4, format);
594 if (availableSamples <= 1) {
595 // This context doesn't support MSAA for RGBA8
596 return;
597 }
598
599 SkImageInfo ii = SkImageInfo::Make({ 128, 128 }, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
600
601 static constexpr int kStencilBits = 8;
602 static constexpr bool kNotMipMapped = false;
603 static constexpr bool kNotTextureable = false;
604 const SkSurfaceProps surfaceProps(0x0, kRGB_H_SkPixelGeometry);
605
Robert Phillips1b1bd4e2020-03-05 13:21:12 -0500606 // Rows are characterizations and columns are surfaces
Robert Phillips2dbcbe82020-03-05 11:16:39 -0500607 static const bool kExpectedCompatibility[4][4] = {
Robert Phillips1b1bd4e2020-03-05 13:21:12 -0500608 // FBO0 & MSAA, FBO0 & not-MSAA, not-FBO0 & MSAA, not-FBO0 & not-MSAA
609/* FBO0 & MSAA */ { true, false, false, false },
610/* FBO0 & not-MSAA */ { false, true, false, true },
611/* not-FBO0 & MSAA */ { false, false, true, false },
612/* not-FBO0 & not- */ { false, false, false, true }
Robert Phillips2dbcbe82020-03-05 11:16:39 -0500613 };
614
615 SkSurfaceCharacterization characterizations[4];
616 sk_sp<SkSurface> surfaces[4];
617
618 int index = 0;
619 for (bool isFBO0 : { true, false }) {
620 for (int numSamples : { availableSamples, 1 }) {
621 characterizations[index] = proxy->createCharacterization(resourceCacheLimit,
622 ii, format, numSamples,
623 kTopLeft_GrSurfaceOrigin,
624 surfaceProps, kNotMipMapped,
625 isFBO0, kNotTextureable);
626 SkASSERT(characterizations[index].sampleCount() == numSamples);
627 SkASSERT(characterizations[index].usesGLFBO0() == isFBO0);
628
629 GrGLFramebufferInfo fboInfo{ isFBO0 ? 0 : (GrGLuint) 1, GR_GL_RGBA8 };
630 GrBackendRenderTarget backendRT(128, 128, numSamples, kStencilBits, fboInfo);
631 SkAssertResult(backendRT.isValid());
632
633 surfaces[index] = SkSurface::MakeFromBackendRenderTarget(context, backendRT,
634 kTopLeft_GrSurfaceOrigin,
635 kRGBA_8888_SkColorType,
636 nullptr, &surfaceProps);
637 ++index;
638 }
639 }
640
Robert Phillips1b1bd4e2020-03-05 13:21:12 -0500641 for (int c = 0; c < 4; ++c) {
642 for (int s = 0; s < 4; ++s) {
Robert Phillips2dbcbe82020-03-05 11:16:39 -0500643 REPORTER_ASSERT(reporter,
Robert Phillips1b1bd4e2020-03-05 13:21:12 -0500644 kExpectedCompatibility[c][s] ==
645 surfaces[s]->isCompatible(characterizations[c]));
Robert Phillips2dbcbe82020-03-05 11:16:39 -0500646 }
647 }
648}
649#endif
650
Robert Phillips3cd54322019-07-10 09:28:59 -0400651DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLSurfaceCharacterizationTest, reporter, ctxInfo) {
Robert Phillips6d344c32020-07-06 10:56:46 -0400652 auto context = ctxInfo.directContext();
Robert Phillips3cd54322019-07-10 09:28:59 -0400653
654 DDLSurfaceCharacterizationTestImpl(context, reporter);
655}
656
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500657// Test that a DDL created w/o textureability can be replayed into both a textureable and
658// non-textureable destination. Note that DDLSurfaceCharacterizationTest tests that a
659// textureable DDL cannot be played into a non-textureable destination but can be replayed
660// into a textureable destination.
661DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLNonTextureabilityTest, reporter, ctxInfo) {
Robert Phillips6d344c32020-07-06 10:56:46 -0400662 auto context = ctxInfo.directContext();
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500663
664 // Create a bitmap that we can readback into
665 SkImageInfo imageInfo = SkImageInfo::Make(64, 64, kRGBA_8888_SkColorType,
666 kPremul_SkAlphaType);
667 SkBitmap bitmap;
668 bitmap.allocPixels(imageInfo);
669
670 for (bool textureability : { true, false }) {
Adlai Hollerf19bbb52020-06-29 10:00:08 -0400671 sk_sp<SkDeferredDisplayList> ddl;
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500672
Robert Phillipsc046ff02019-07-01 10:34:03 -0400673 // First, create a DDL w/o textureability (and thus no mipmaps). TODO: once we have
674 // reusable DDLs, move this outside of the loop.
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500675 {
Robert Phillips3cd54322019-07-10 09:28:59 -0400676 SurfaceParameters params(context);
Brian Salomonf9b00422020-10-08 16:00:14 -0400677 params.disableTextureability();
Greg Daniel638b2e82020-08-27 14:29:00 -0400678 if (context->backend() == GrBackendApi::kVulkan) {
679 params.setVkRTInputAttachmentSupport(true);
680 }
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500681
682 ddl = params.createDDL(context);
683 SkAssertResult(ddl);
684 }
685
686 // Then verify it can draw into either flavor of destination
Robert Phillips3cd54322019-07-10 09:28:59 -0400687 SurfaceParameters params(context);
Brian Salomonf9b00422020-10-08 16:00:14 -0400688 if (!textureability) {
689 params.disableTextureability();
690 }
Greg Daniel638b2e82020-08-27 14:29:00 -0400691 if (context->backend() == GrBackendApi::kVulkan) {
692 params.setVkRTInputAttachmentSupport(true);
693 }
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500694
Brian Salomonf9b00422020-10-08 16:00:14 -0400695 sk_sp<SkSurface> s = params.make(context);
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500696 if (!s) {
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500697 continue;
698 }
699
Adlai Holler7580ad42020-06-24 13:45:25 -0400700 REPORTER_ASSERT(reporter, s->draw(ddl));
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500701 s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
Brian Salomonf9b00422020-10-08 16:00:14 -0400702
703 context->flush();
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500704 }
705
706}
707
Robert Phillipsd8f79a22019-06-24 13:25:42 -0400708static void test_make_render_target(skiatest::Reporter* reporter,
Robert Phillipsc8ae4942020-07-20 10:56:01 -0400709 GrDirectContext* dContext,
Robert Phillipsd8f79a22019-06-24 13:25:42 -0400710 const SurfaceParameters& params) {
711 {
Robert Phillipsc8ae4942020-07-20 10:56:01 -0400712 const SkSurfaceCharacterization c = params.createCharacterization(dContext);
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400713
Robert Phillipsbe77a022018-04-03 17:17:05 -0400714 if (!c.isValid()) {
Brian Salomonf9b00422020-10-08 16:00:14 -0400715 sk_sp<SkSurface> tmp = params.make(dContext);
Robert Phillipsbe77a022018-04-03 17:17:05 -0400716 // If we couldn't characterize the surface we shouldn't be able to create it either
717 REPORTER_ASSERT(reporter, !tmp);
Robert Phillipsd8f79a22019-06-24 13:25:42 -0400718 return;
719 }
720 }
721
Robert Phillipsc8ae4942020-07-20 10:56:01 -0400722 const SkSurfaceCharacterization c = params.createCharacterization(dContext);
Robert Phillipsd8f79a22019-06-24 13:25:42 -0400723 {
Brian Salomonf9b00422020-10-08 16:00:14 -0400724 sk_sp<SkSurface> s = params.make(dContext);
Robert Phillipsd8f79a22019-06-24 13:25:42 -0400725 REPORTER_ASSERT(reporter, s);
726 if (!s) {
727 REPORTER_ASSERT(reporter, !c.isValid());
Robert Phillipsd8f79a22019-06-24 13:25:42 -0400728 return;
729 }
730
731 REPORTER_ASSERT(reporter, c.isValid());
Brian Salomonf9b00422020-10-08 16:00:14 -0400732 GrBackendTexture backend = s->getBackendTexture(SkSurface::kFlushRead_BackendHandleAccess);
733 if (backend.isValid()) {
734 REPORTER_ASSERT(reporter, c.isCompatible(backend));
735 }
Robert Phillips9907e6e2019-06-25 14:47:04 -0400736 REPORTER_ASSERT(reporter, s->isCompatible(c));
Robert Phillipsd8f79a22019-06-24 13:25:42 -0400737 // Note that we're leaving 'backend' live here
738 }
739
740 // Make an SkSurface from scratch
741 {
Robert Phillipsc8ae4942020-07-20 10:56:01 -0400742 sk_sp<SkSurface> s = SkSurface::MakeRenderTarget(dContext, c, SkBudgeted::kYes);
Robert Phillipsd8f79a22019-06-24 13:25:42 -0400743 REPORTER_ASSERT(reporter, s);
Robert Phillips9907e6e2019-06-25 14:47:04 -0400744 REPORTER_ASSERT(reporter, s->isCompatible(c));
Robert Phillipsd8f79a22019-06-24 13:25:42 -0400745 }
Robert Phillipsd8f79a22019-06-24 13:25:42 -0400746}
747
748////////////////////////////////////////////////////////////////////////////////
749// This tests the SkSurface::MakeRenderTarget variants that take an SkSurfaceCharacterization.
750// In particular, the SkSurface, backendTexture and SkSurfaceCharacterization
751// should always be compatible.
Robert Phillipsc8ae4942020-07-20 10:56:01 -0400752void DDLMakeRenderTargetTestImpl(GrDirectContext* dContext, skiatest::Reporter* reporter) {
Brian Salomonf9b00422020-10-08 16:00:14 -0400753 for (int i = -1; i < SurfaceParameters::kNumParams; ++i) {
Robert Phillipsd8f79a22019-06-24 13:25:42 -0400754 if (SurfaceParameters::kFBO0Count == i) {
755 // MakeRenderTarget doesn't support FBO0
Robert Phillipsbe77a022018-04-03 17:17:05 -0400756 continue;
757 }
758
Robert Phillipsc8ae4942020-07-20 10:56:01 -0400759 SurfaceParameters params(dContext);
Brian Salomonf9b00422020-10-08 16:00:14 -0400760 if (i >= 0 && !params.modify(i)) {
761 continue;
Brian Salomon4687bdd2019-05-09 16:28:04 -0400762 }
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400763
Robert Phillipsc8ae4942020-07-20 10:56:01 -0400764 test_make_render_target(reporter, dContext, params);
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400765 }
766}
767
Robert Phillips3cd54322019-07-10 09:28:59 -0400768DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLMakeRenderTargetTest, reporter, ctxInfo) {
Robert Phillips6d344c32020-07-06 10:56:46 -0400769 auto context = ctxInfo.directContext();
Robert Phillips3cd54322019-07-10 09:28:59 -0400770
771 DDLMakeRenderTargetTestImpl(context, reporter);
772}
773
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400774////////////////////////////////////////////////////////////////////////////////
Greg Danielf2336e42018-01-23 16:38:14 -0500775static constexpr int kSize = 8;
776
777struct TextureReleaseChecker {
778 TextureReleaseChecker() : fReleaseCount(0) {}
779 int fReleaseCount;
780 static void Release(void* self) {
781 static_cast<TextureReleaseChecker*>(self)->fReleaseCount++;
782 }
783};
784
785enum class DDLStage { kMakeImage, kDrawImage, kDetach, kDrawDDL };
786
787// This tests the ability to create and use wrapped textures in a DDL world
788DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLWrapBackendTest, reporter, ctxInfo) {
Adlai Holler14dc7912020-08-11 15:48:49 +0000789 auto dContext = ctxInfo.directContext();
Robert Phillips9b16f812019-05-17 10:01:21 -0400790
Brian Salomon72050802020-10-12 20:45:06 -0400791 auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData(dContext,
792 kSize,
793 kSize,
794 kRGBA_8888_SkColorType,
795 GrMipmapped::kNo,
796 GrRenderable::kNo,
797 GrProtected::kNo);
798 if (!mbet) {
Brian Salomonf7778972018-03-08 10:13:17 -0500799 return;
Greg Danielf2336e42018-01-23 16:38:14 -0500800 }
Brian Salomonf7778972018-03-08 10:13:17 -0500801
Adlai Holler14dc7912020-08-11 15:48:49 +0000802 SurfaceParameters params(dContext);
Brian Salomonf7778972018-03-08 10:13:17 -0500803
Brian Salomonf9b00422020-10-08 16:00:14 -0400804 sk_sp<SkSurface> s = params.make(dContext);
Brian Salomonf7778972018-03-08 10:13:17 -0500805 if (!s) {
Brian Salomonf7778972018-03-08 10:13:17 -0500806 return;
807 }
808
809 SkSurfaceCharacterization c;
810 SkAssertResult(s->characterize(&c));
811
Adlai Holler14dc7912020-08-11 15:48:49 +0000812 SkDeferredDisplayListRecorder recorder(c);
Brian Salomonf7778972018-03-08 10:13:17 -0500813
Adlai Holler14dc7912020-08-11 15:48:49 +0000814 SkCanvas* canvas = recorder.getCanvas();
815 SkASSERT(canvas);
Adlai Holler74b83a42020-08-06 17:24:53 +0000816
Adlai Holler14dc7912020-08-11 15:48:49 +0000817 auto rContext = canvas->recordingContext();
818 if (!rContext) {
Brian Salomonf7778972018-03-08 10:13:17 -0500819 return;
820 }
821
822 // Wrapped Backend Textures are not supported in DDL
Brian Salomonf7778972018-03-08 10:13:17 -0500823 TextureReleaseChecker releaseChecker;
Brian Salomon72050802020-10-12 20:45:06 -0400824 sk_sp<SkImage> image = SkImage::MakeFromTexture(
825 rContext,
826 mbet->texture(),
827 kTopLeft_GrSurfaceOrigin,
828 kRGBA_8888_SkColorType,
829 kPremul_SkAlphaType,
830 nullptr,
831 sk_gpu_test::ManagedBackendTexture::ReleaseProc,
832 mbet->releaseContext(TextureReleaseChecker::Release, &releaseChecker));
Brian Salomonf7778972018-03-08 10:13:17 -0500833 REPORTER_ASSERT(reporter, !image);
Greg Danielf2336e42018-01-23 16:38:14 -0500834}
835
Brian Salomon59ef8c32019-01-30 12:20:56 -0500836static sk_sp<SkPromiseImageTexture> dummy_fulfill_proc(void*) {
837 SkASSERT(0);
838 return nullptr;
839}
Robert Phillips6ceaafa2018-03-15 16:53:06 -0400840static void dummy_release_proc(void*) { SkASSERT(0); }
Brian Salomon59ef8c32019-01-30 12:20:56 -0500841static void dummy_done_proc(void*) {}
Robert Phillips6ceaafa2018-03-15 16:53:06 -0400842
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400843////////////////////////////////////////////////////////////////////////////////
Robert Phillips6ceaafa2018-03-15 16:53:06 -0400844// Test out the behavior of an invalid DDLRecorder
845DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLInvalidRecorder, reporter, ctxInfo) {
Robert Phillipsdc369702020-08-13 13:34:27 -0400846 auto dContext = ctxInfo.directContext();
Robert Phillips6ceaafa2018-03-15 16:53:06 -0400847
848 {
849 SkImageInfo ii = SkImageInfo::MakeN32Premul(32, 32);
Robert Phillipsdc369702020-08-13 13:34:27 -0400850 sk_sp<SkSurface> s = SkSurface::MakeRenderTarget(dContext, SkBudgeted::kNo, ii);
Robert Phillips6ceaafa2018-03-15 16:53:06 -0400851
852 SkSurfaceCharacterization characterization;
853 SkAssertResult(s->characterize(&characterization));
854
855 // never calling getCanvas means the backing surface is never allocated
856 SkDeferredDisplayListRecorder recorder(characterization);
857 }
858
859 {
860 SkSurfaceCharacterization invalid;
861
862 SkDeferredDisplayListRecorder recorder(invalid);
863
864 const SkSurfaceCharacterization c = recorder.characterization();
865 REPORTER_ASSERT(reporter, !c.isValid());
866 REPORTER_ASSERT(reporter, !recorder.getCanvas());
867 REPORTER_ASSERT(reporter, !recorder.detach());
868
Robert Phillipsdc369702020-08-13 13:34:27 -0400869 GrBackendFormat format = dContext->defaultBackendFormat(kRGBA_8888_SkColorType,
870 GrRenderable::kNo);
Robert Phillips0a15cc62019-07-30 12:49:10 -0400871 SkASSERT(format.isValid());
Greg Daniel60ea40c2019-02-12 13:38:44 -0500872
Brian Salomonf55e8d52019-01-30 17:28:20 -0500873 sk_sp<SkImage> image = recorder.makePromiseTexture(
Brian Salomon7e67dca2020-07-21 09:27:25 -0400874 format, 32, 32, GrMipmapped::kNo,
Brian Salomonf55e8d52019-01-30 17:28:20 -0500875 kTopLeft_GrSurfaceOrigin,
876 kRGBA_8888_SkColorType,
877 kPremul_SkAlphaType, nullptr,
878 dummy_fulfill_proc,
879 dummy_release_proc,
880 dummy_done_proc,
Brian Salomon0cc57542019-03-08 13:28:46 -0500881 nullptr,
882 SkDeferredDisplayListRecorder::PromiseImageApiVersion::kNew);
Robert Phillips6ceaafa2018-03-15 16:53:06 -0400883 REPORTER_ASSERT(reporter, !image);
884 }
Robert Phillipsdc369702020-08-13 13:34:27 -0400885}
Robert Phillips6ceaafa2018-03-15 16:53:06 -0400886
Robert Phillipsdc369702020-08-13 13:34:27 -0400887DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLCreateCharacterizationFailures, reporter, ctxInfo) {
888 auto dContext = ctxInfo.directContext();
889 size_t maxResourceBytes = dContext->getResourceCacheLimit();
890 auto proxy = dContext->threadSafeProxy().get();
891
Greg Daniel638b2e82020-08-27 14:29:00 -0400892 auto check_create_fails =
893 [proxy, reporter, maxResourceBytes](const GrBackendFormat& backendFormat,
894 int width, int height,
895 SkColorType ct, bool willUseGLFBO0,
896 GrProtected prot,
897 bool vkRTSupportsInputAttachment) {
Robert Phillipsdc369702020-08-13 13:34:27 -0400898 const SkSurfaceProps surfaceProps(0x0, kRGB_H_SkPixelGeometry);
899
900 SkImageInfo ii = SkImageInfo::Make(width, height, ct,
901 kPremul_SkAlphaType, nullptr);
902
903 SkSurfaceCharacterization c = proxy->createCharacterization(
904 maxResourceBytes, ii, backendFormat, 1,
905 kBottomLeft_GrSurfaceOrigin, surfaceProps, false,
Greg Daniel638b2e82020-08-27 14:29:00 -0400906 willUseGLFBO0, true, prot,
907 vkRTSupportsInputAttachment);
Robert Phillipsdc369702020-08-13 13:34:27 -0400908 REPORTER_ASSERT(reporter, !c.isValid());
909 };
910
911 GrBackendFormat goodBackendFormat = dContext->defaultBackendFormat(kRGBA_8888_SkColorType,
912 GrRenderable::kYes);
913 SkASSERT(goodBackendFormat.isValid());
914
915 GrBackendFormat badBackendFormat;
916 SkASSERT(!badBackendFormat.isValid());
917
918 SkColorType kGoodCT = kRGBA_8888_SkColorType;
919 SkColorType kBadCT = kUnknown_SkColorType;
920
921 static const bool kGoodUseFBO0 = false;
922 static const bool kBadUseFBO0 = true;
923
Greg Daniel638b2e82020-08-27 14:29:00 -0400924 static const bool kGoodVkInputAttachment = false;
925 static const bool kBadVkInputAttachment = true;
926
Robert Phillipsdc369702020-08-13 13:34:27 -0400927 int goodWidth = 64;
928 int goodHeight = 64;
929 int badWidths[] = { 0, 1048576 };
930 int badHeights[] = { 0, 1048576 };
931
Greg Daniel638b2e82020-08-27 14:29:00 -0400932
933 // In each of the check_create_fails calls there is one bad parameter that should cause the
934 // creation of the characterization to fail.
935 check_create_fails(goodBackendFormat, goodWidth, badHeights[0], kGoodCT, kGoodUseFBO0,
936 GrProtected::kNo, kGoodVkInputAttachment);
937 check_create_fails(goodBackendFormat, goodWidth, badHeights[1], kGoodCT, kGoodUseFBO0,
938 GrProtected::kNo, kGoodVkInputAttachment);
939 check_create_fails(goodBackendFormat, badWidths[0], goodHeight, kGoodCT, kGoodUseFBO0,
940 GrProtected::kNo, kGoodVkInputAttachment);
941 check_create_fails(goodBackendFormat, badWidths[1], goodHeight, kGoodCT, kGoodUseFBO0,
942 GrProtected::kNo, kGoodVkInputAttachment);
943 check_create_fails(badBackendFormat, goodWidth, goodHeight, kGoodCT, kGoodUseFBO0,
944 GrProtected::kNo, kGoodVkInputAttachment);
945 check_create_fails(goodBackendFormat, goodWidth, goodHeight, kBadCT, kGoodUseFBO0,
946 GrProtected::kNo, kGoodVkInputAttachment);
947 // This fails because we always try to make a characterization that is textureable and we can't
948 // have UseFBO0 be true and textureable.
949 check_create_fails(goodBackendFormat, goodWidth, goodHeight, kGoodCT, kBadUseFBO0,
950 GrProtected::kNo, kGoodVkInputAttachment);
Robert Phillipsdc369702020-08-13 13:34:27 -0400951 if (dContext->backend() == GrBackendApi::kVulkan) {
Greg Daniel638b2e82020-08-27 14:29:00 -0400952 // The bad parameter in this case is the GrProtected::kYes since none of our test contexts
953 // are made protected we can't have a protected surface.
954 check_create_fails(goodBackendFormat, goodWidth, goodHeight, kGoodCT, kGoodUseFBO0,
955 GrProtected::kYes, kGoodVkInputAttachment);
956 } else {
957 check_create_fails(goodBackendFormat, goodWidth, goodHeight, kGoodCT, kGoodUseFBO0,
958 GrProtected::kNo, kBadVkInputAttachment);
Robert Phillipsdc369702020-08-13 13:34:27 -0400959 }
Robert Phillips6ceaafa2018-03-15 16:53:06 -0400960}
961
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400962////////////////////////////////////////////////////////////////////////////////
Robert Phillipsee5fd132019-05-07 13:29:22 -0400963// Test that flushing a DDL via SkSurface::flush works
964
965struct FulfillInfo {
966 sk_sp<SkPromiseImageTexture> fTex;
967 bool fFulfilled = false;
968 bool fReleased = false;
969 bool fDone = false;
970};
971
972static sk_sp<SkPromiseImageTexture> tracking_fulfill_proc(void* context) {
973 FulfillInfo* info = (FulfillInfo*) context;
974 info->fFulfilled = true;
975 return info->fTex;
976}
977
978static void tracking_release_proc(void* context) {
979 FulfillInfo* info = (FulfillInfo*) context;
980 info->fReleased = true;
981}
982
983static void tracking_done_proc(void* context) {
984 FulfillInfo* info = (FulfillInfo*) context;
985 info->fDone = true;
986}
987
988DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLSkSurfaceFlush, reporter, ctxInfo) {
Robert Phillips6d344c32020-07-06 10:56:46 -0400989 auto context = ctxInfo.directContext();
Robert Phillipsee5fd132019-05-07 13:29:22 -0400990
991 SkImageInfo ii = SkImageInfo::Make(32, 32, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
992 sk_sp<SkSurface> s = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, ii);
993
994 SkSurfaceCharacterization characterization;
995 SkAssertResult(s->characterize(&characterization));
996
Brian Salomon72050802020-10-12 20:45:06 -0400997 auto mbet = sk_gpu_test::ManagedBackendTexture::MakeFromInfo(context, ii);
998 if (!mbet) {
999 ERRORF(reporter, "Could not make texture.");
Robert Phillipsee5fd132019-05-07 13:29:22 -04001000 return;
1001 }
1002
1003 FulfillInfo fulfillInfo;
Brian Salomon72050802020-10-12 20:45:06 -04001004 fulfillInfo.fTex = SkPromiseImageTexture::Make(mbet->texture());
Robert Phillipsee5fd132019-05-07 13:29:22 -04001005
Adlai Hollerf19bbb52020-06-29 10:00:08 -04001006 sk_sp<SkDeferredDisplayList> ddl;
Robert Phillipsee5fd132019-05-07 13:29:22 -04001007
1008 {
1009 SkDeferredDisplayListRecorder recorder(characterization);
1010
Robert Phillips0a15cc62019-07-30 12:49:10 -04001011 GrBackendFormat format = context->defaultBackendFormat(kRGBA_8888_SkColorType,
1012 GrRenderable::kNo);
1013 SkASSERT(format.isValid());
Robert Phillipsee5fd132019-05-07 13:29:22 -04001014
1015 sk_sp<SkImage> promiseImage = recorder.makePromiseTexture(
Brian Salomon7e67dca2020-07-21 09:27:25 -04001016 format, 32, 32, GrMipmapped::kNo,
Robert Phillipsee5fd132019-05-07 13:29:22 -04001017 kTopLeft_GrSurfaceOrigin,
1018 kRGBA_8888_SkColorType,
1019 kPremul_SkAlphaType, nullptr,
1020 tracking_fulfill_proc,
1021 tracking_release_proc,
1022 tracking_done_proc,
1023 &fulfillInfo,
1024 SkDeferredDisplayListRecorder::PromiseImageApiVersion::kNew);
1025
1026 SkCanvas* canvas = recorder.getCanvas();
1027
1028 canvas->clear(SK_ColorRED);
1029 canvas->drawImage(promiseImage, 0, 0);
1030 ddl = recorder.detach();
1031 }
1032
Greg Daniel0a2464f2020-05-14 15:45:44 -04001033 context->flushAndSubmit();
Robert Phillips15c91422019-05-07 16:54:48 -04001034
Adlai Holler7580ad42020-06-24 13:45:25 -04001035 s->draw(ddl);
Robert Phillipsee5fd132019-05-07 13:29:22 -04001036
1037 GrFlushInfo flushInfo;
Robert Phillips8e49a692019-05-07 15:57:25 -04001038 s->flush(SkSurface::BackendSurfaceAccess::kPresent, flushInfo);
Greg Daniel0a2464f2020-05-14 15:45:44 -04001039 context->submit();
Robert Phillipsee5fd132019-05-07 13:29:22 -04001040
1041 REPORTER_ASSERT(reporter, fulfillInfo.fFulfilled);
1042 REPORTER_ASSERT(reporter, fulfillInfo.fReleased);
1043
Robert Phillips8e49a692019-05-07 15:57:25 -04001044 if (GrBackendApi::kVulkan == context->backend() ||
1045 GrBackendApi::kMetal == context->backend()) {
Robert Phillips15c91422019-05-07 16:54:48 -04001046 // In order to receive the done callback with Vulkan we need to perform the equivalent
Robert Phillipsee5fd132019-05-07 13:29:22 -04001047 // of a glFinish
Greg Danielce9f0162020-06-30 13:42:46 -04001048 s->flush();
Greg Daniel0a2464f2020-05-14 15:45:44 -04001049 context->submit(true);
Robert Phillipsee5fd132019-05-07 13:29:22 -04001050 }
1051
1052 REPORTER_ASSERT(reporter, fulfillInfo.fDone);
1053
1054 REPORTER_ASSERT(reporter, fulfillInfo.fTex->unique());
1055 fulfillInfo.fTex.reset();
Robert Phillipsee5fd132019-05-07 13:29:22 -04001056}
1057
1058////////////////////////////////////////////////////////////////////////////////
Robert Phillipsf54883c2018-12-18 08:29:09 -05001059// Ensure that reusing a single DDLRecorder to create multiple DDLs works cleanly
1060DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLMultipleDDLs, reporter, ctxInfo) {
Robert Phillips6d344c32020-07-06 10:56:46 -04001061 auto context = ctxInfo.directContext();
Robert Phillipsf54883c2018-12-18 08:29:09 -05001062
1063 SkImageInfo ii = SkImageInfo::MakeN32Premul(32, 32);
1064 sk_sp<SkSurface> s = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, ii);
1065
1066 SkBitmap bitmap;
1067 bitmap.allocPixels(ii);
1068
1069 SkSurfaceCharacterization characterization;
1070 SkAssertResult(s->characterize(&characterization));
1071
1072 SkDeferredDisplayListRecorder recorder(characterization);
1073
1074 SkCanvas* canvas1 = recorder.getCanvas();
1075
1076 canvas1->clear(SK_ColorRED);
1077
1078 canvas1->save();
1079 canvas1->clipRect(SkRect::MakeXYWH(8, 8, 16, 16));
1080
Adlai Hollerf19bbb52020-06-29 10:00:08 -04001081 sk_sp<SkDeferredDisplayList> ddl1 = recorder.detach();
Robert Phillipsf54883c2018-12-18 08:29:09 -05001082
1083 SkCanvas* canvas2 = recorder.getCanvas();
1084
1085 SkPaint p;
1086 p.setColor(SK_ColorGREEN);
1087 canvas2->drawRect(SkRect::MakeWH(32, 32), p);
1088
Adlai Hollerf19bbb52020-06-29 10:00:08 -04001089 sk_sp<SkDeferredDisplayList> ddl2 = recorder.detach();
Robert Phillipsf54883c2018-12-18 08:29:09 -05001090
1091 REPORTER_ASSERT(reporter, ddl1->priv().lazyProxyData());
1092 REPORTER_ASSERT(reporter, ddl2->priv().lazyProxyData());
1093
1094 // The lazy proxy data being different ensures that the SkSurface, SkCanvas and backing-
1095 // lazy proxy are all different between the two DDLs
1096 REPORTER_ASSERT(reporter, ddl1->priv().lazyProxyData() != ddl2->priv().lazyProxyData());
1097
Adlai Holler7580ad42020-06-24 13:45:25 -04001098 s->draw(ddl1);
1099 s->draw(ddl2);
Robert Phillipsf54883c2018-12-18 08:29:09 -05001100
1101 // Make sure the clipRect from DDL1 didn't percolate into DDL2
1102 s->readPixels(ii, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
1103 for (int y = 0; y < 32; ++y) {
1104 for (int x = 0; x < 32; ++x) {
1105 REPORTER_ASSERT(reporter, bitmap.getColor(x, y) == SK_ColorGREEN);
1106 if (bitmap.getColor(x, y) != SK_ColorGREEN) {
1107 return; // we only really need to report the error once
1108 }
1109 }
1110 }
1111}
1112
John Rosascoa9b348f2019-11-08 13:18:15 -08001113#ifdef SK_GL
Robert Phillipsf54883c2018-12-18 08:29:09 -05001114////////////////////////////////////////////////////////////////////////////////
Robert Phillipsabf7b762018-03-21 12:13:37 -04001115// Check that the texture-specific flags (i.e., for external & rectangle textures) work
1116// for promise images. As such, this is a GL-only test.
1117DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(DDLTextureFlagsTest, reporter, ctxInfo) {
Robert Phillips6d344c32020-07-06 10:56:46 -04001118 auto context = ctxInfo.directContext();
Robert Phillipsabf7b762018-03-21 12:13:37 -04001119
1120 SkImageInfo ii = SkImageInfo::MakeN32Premul(32, 32);
1121 sk_sp<SkSurface> s = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, ii);
1122
1123 SkSurfaceCharacterization characterization;
1124 SkAssertResult(s->characterize(&characterization));
1125
1126 SkDeferredDisplayListRecorder recorder(characterization);
1127
1128 for (GrGLenum target : { GR_GL_TEXTURE_EXTERNAL, GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_2D } ) {
Brian Salomon7e67dca2020-07-21 09:27:25 -04001129 for (auto mipMapped : { GrMipmapped::kNo, GrMipmapped::kYes }) {
Greg Daniel09c94002018-06-08 22:11:51 +00001130 GrBackendFormat format = GrBackendFormat::MakeGL(GR_GL_RGBA8, target);
Robert Phillipsabf7b762018-03-21 12:13:37 -04001131
Brian Salomonf55e8d52019-01-30 17:28:20 -05001132 sk_sp<SkImage> image = recorder.makePromiseTexture(
1133 format, 32, 32, mipMapped,
1134 kTopLeft_GrSurfaceOrigin,
1135 kRGBA_8888_SkColorType,
1136 kPremul_SkAlphaType, nullptr,
1137 dummy_fulfill_proc,
1138 dummy_release_proc,
1139 dummy_done_proc,
Brian Salomon0cc57542019-03-08 13:28:46 -05001140 nullptr,
1141 SkDeferredDisplayListRecorder::PromiseImageApiVersion::kNew);
Brian Salomon7e67dca2020-07-21 09:27:25 -04001142 if (GR_GL_TEXTURE_2D != target && mipMapped == GrMipmapped::kYes) {
Greg Daniel09c94002018-06-08 22:11:51 +00001143 REPORTER_ASSERT(reporter, !image);
1144 continue;
1145 }
1146 REPORTER_ASSERT(reporter, image);
Robert Phillipsabf7b762018-03-21 12:13:37 -04001147
Jim Van Verth21bd60d2018-10-12 15:00:20 -04001148 GrTextureProxy* backingProxy = ((SkImage_GpuBase*) image.get())->peekProxy();
Robert Phillipsabf7b762018-03-21 12:13:37 -04001149
Brian Salomon8c82a872020-07-21 12:09:58 -04001150 REPORTER_ASSERT(reporter, backingProxy->mipmapped() == mipMapped);
Greg Daniel09c94002018-06-08 22:11:51 +00001151 if (GR_GL_TEXTURE_2D == target) {
Brian Salomonfd98c2c2018-07-31 17:25:29 -04001152 REPORTER_ASSERT(reporter, !backingProxy->hasRestrictedSampling());
Greg Daniel09c94002018-06-08 22:11:51 +00001153 } else {
Brian Salomonfd98c2c2018-07-31 17:25:29 -04001154 REPORTER_ASSERT(reporter, backingProxy->hasRestrictedSampling());
Greg Daniel09c94002018-06-08 22:11:51 +00001155 }
Robert Phillipsabf7b762018-03-21 12:13:37 -04001156 }
1157 }
Robert Phillipsbe77a022018-04-03 17:17:05 -04001158}
John Rosascoa9b348f2019-11-08 13:18:15 -08001159#endif // SK_GL
Robert Phillipsbe77a022018-04-03 17:17:05 -04001160
1161////////////////////////////////////////////////////////////////////////////////
Robert Phillips646f6372018-09-25 09:31:10 -04001162// Test colorType and pixelConfig compatibility.
Robert Phillipsbe77a022018-04-03 17:17:05 -04001163DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(DDLCompatibilityTest, reporter, ctxInfo) {
Robert Phillips6d344c32020-07-06 10:56:46 -04001164 auto context = ctxInfo.directContext();
Robert Phillipsbe77a022018-04-03 17:17:05 -04001165
1166 for (int ct = 0; ct <= kLastEnum_SkColorType; ++ct) {
1167 SkColorType colorType = static_cast<SkColorType>(ct);
1168
Robert Phillips3cd54322019-07-10 09:28:59 -04001169 SurfaceParameters params(context);
Greg Daniel60ea40c2019-02-12 13:38:44 -05001170 params.setColorType(colorType);
1171 params.setColorSpace(nullptr);
Robert Phillipsbe77a022018-04-03 17:17:05 -04001172
Robert Phillipsd8f79a22019-06-24 13:25:42 -04001173 test_make_render_target(reporter, context, params);
Robert Phillipsbe77a022018-04-03 17:17:05 -04001174 }
Robert Phillipsabf7b762018-03-21 12:13:37 -04001175
1176}