blob: 11d4c92054d8845b608da959fbc8898512f0a9cf [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
Brian Salomon59ef8c32019-01-30 12:20:56 -05008#include <initializer_list>
9#include <memory>
10#include <utility>
Greg Danielf2336e42018-01-23 16:38:14 -050011#include "GrBackendSurface.h"
Ben Wagnerd90cd3b2018-05-22 10:48:08 -040012#include "GrCaps.h"
13#include "GrContext.h"
14#include "GrContextFactory.h"
Brian Salomonc7fe0f72018-05-11 10:14:21 -040015#include "GrContextPriv.h"
Greg Danielf2336e42018-01-23 16:38:14 -050016#include "GrGpu.h"
Ben Wagnerd90cd3b2018-05-22 10:48:08 -040017#include "GrRenderTargetContext.h"
18#include "GrRenderTargetProxy.h"
19#include "GrTextureProxy.h"
Robert Phillipsabf7b762018-03-21 12:13:37 -040020#include "GrTextureProxyPriv.h"
Ben Wagnerd90cd3b2018-05-22 10:48:08 -040021#include "GrTypes.h"
22#include "GrTypesPriv.h"
23#include "SkBitmap.h"
Robert Phillips7ffbcf92017-12-04 12:52:46 -050024#include "SkCanvas.h"
Ben Wagnerd90cd3b2018-05-22 10:48:08 -040025#include "SkColorSpace.h"
26#include "SkDeferredDisplayList.h"
Robert Phillipsf54883c2018-12-18 08:29:09 -050027#include "SkDeferredDisplayListPriv.h"
Robert Phillips7ffbcf92017-12-04 12:52:46 -050028#include "SkDeferredDisplayListRecorder.h"
29#include "SkGpuDevice.h"
Ben Wagnerd90cd3b2018-05-22 10:48:08 -040030#include "SkImage.h"
31#include "SkImageInfo.h"
Robert Phillipsabf7b762018-03-21 12:13:37 -040032#include "SkImage_Gpu.h"
Ben Wagnerd90cd3b2018-05-22 10:48:08 -040033#include "SkPaint.h"
Brian Salomon59ef8c32019-01-30 12:20:56 -050034#include "SkPromiseImageTexture.h"
Ben Wagnerd90cd3b2018-05-22 10:48:08 -040035#include "SkRect.h"
36#include "SkRefCnt.h"
Robert Phillips7ffbcf92017-12-04 12:52:46 -050037#include "SkSurface.h"
Robert Phillips7ffbcf92017-12-04 12:52:46 -050038#include "SkSurfaceCharacterization.h"
39#include "SkSurfaceProps.h"
Brian Salomonc7fe0f72018-05-11 10:14:21 -040040#include "SkSurface_Gpu.h"
Robert Phillips7ffbcf92017-12-04 12:52:46 -050041#include "Test.h"
Robert Phillipsbe77a022018-04-03 17:17:05 -040042#include "gl/GrGLCaps.h"
Brian Salomonc7fe0f72018-05-11 10:14:21 -040043#include "gl/GrGLDefines.h"
Ben Wagnerd90cd3b2018-05-22 10:48:08 -040044#include "gl/GrGLTypes.h"
Robert Phillipsfc711a22018-02-13 17:03:00 -050045#ifdef SK_VULKAN
Greg Daniel54bfb182018-11-20 17:12:36 -050046#include <vulkan/vulkan_core.h>
Robert Phillipsfc711a22018-02-13 17:03:00 -050047#endif
48
Robert Phillips7ffbcf92017-12-04 12:52:46 -050049class SurfaceParameters {
50public:
Robert Phillipsb45f47d2019-02-03 17:17:54 -050051 static const int kNumParams = 11;
Robert Phillips7ffbcf92017-12-04 12:52:46 -050052 static const int kSampleCount = 5;
Robert Phillipse8fabb22018-02-04 14:33:21 -050053 static const int kMipMipCount = 8;
Robert Phillipsb45f47d2019-02-03 17:17:54 -050054 static const int kFBO0Count = 9;
Robert Phillips7ffbcf92017-12-04 12:52:46 -050055
Robert Phillipsb45f47d2019-02-03 17:17:54 -050056 SurfaceParameters(GrBackendApi backend)
57 : fBackend(backend)
58 , fWidth(64)
Robert Phillips7ffbcf92017-12-04 12:52:46 -050059 , fHeight(64)
60 , fOrigin(kTopLeft_GrSurfaceOrigin)
61 , fColorType(kRGBA_8888_SkColorType)
62 , fColorSpace(SkColorSpace::MakeSRGB())
Brian Salomonbdecacf2018-02-02 20:32:49 -050063 , fSampleCount(1)
Robert Phillipse8fabb22018-02-04 14:33:21 -050064 , fSurfaceProps(0x0, kUnknown_SkPixelGeometry)
Robert Phillipsb45f47d2019-02-03 17:17:54 -050065 , fShouldCreateMipMaps(true)
66 , fUsesGLFBO0(false)
67 , fIsTextureable(true) {
Robert Phillipse8fabb22018-02-04 14:33:21 -050068 }
Robert Phillips7ffbcf92017-12-04 12:52:46 -050069
70 int sampleCount() const { return fSampleCount; }
71
Robert Phillipsbe77a022018-04-03 17:17:05 -040072 void setColorType(SkColorType ct) { fColorType = ct; }
73 void setColorSpace(sk_sp<SkColorSpace> cs) { fColorSpace = std::move(cs); }
Robert Phillipsb45f47d2019-02-03 17:17:54 -050074 void setTextureable(bool isTextureable) { fIsTextureable = isTextureable; }
Robert Phillipsbe77a022018-04-03 17:17:05 -040075
Robert Phillips7ffbcf92017-12-04 12:52:46 -050076 // Modify the SurfaceParameters in just one way
77 void modify(int i) {
78 switch (i) {
79 case 0:
80 fWidth = 63;
81 break;
82 case 1:
83 fHeight = 63;
84 break;
85 case 2:
86 fOrigin = kBottomLeft_GrSurfaceOrigin;
87 break;
88 case 3:
89 fColorType = kRGBA_F16_SkColorType;
90 break;
91 case 4:
Brian Osman37f99882018-08-09 10:26:57 -040092 // This just needs to be a colorSpace different from that returned by MakeSRGB().
93 // In this case we just change the gamut.
Brian Osman82ebe042019-01-04 17:03:00 -050094 fColorSpace = SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kAdobeRGB);
Robert Phillips7ffbcf92017-12-04 12:52:46 -050095 break;
96 case kSampleCount:
97 fSampleCount = 4;
98 break;
99 case 6:
100 fSurfaceProps = SkSurfaceProps(0x0, kRGB_H_SkPixelGeometry);
101 break;
102 case 7:
103 fSurfaceProps = SkSurfaceProps(SkSurfaceProps::kUseDeviceIndependentFonts_Flag,
104 kUnknown_SkPixelGeometry);
105 break;
Robert Phillipse8fabb22018-02-04 14:33:21 -0500106 case 8:
107 fShouldCreateMipMaps = false;
108 break;
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500109 case 9:
110 if (GrBackendApi::kOpenGL == fBackend) {
111 fUsesGLFBO0 = true;
112 fIsTextureable = false;
113 }
114 break;
115 case 10:
116 fIsTextureable = false;
117 break;
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500118 }
119 }
120
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400121 SkSurfaceCharacterization createCharacterization(GrContext* context) const {
Robert Phillipsfc711a22018-02-13 17:03:00 -0500122 int maxResourceCount;
123 size_t maxResourceBytes;
124 context->getResourceCacheLimits(&maxResourceCount, &maxResourceBytes);
125
126 // Note that Ganesh doesn't make use of the SkImageInfo's alphaType
127 SkImageInfo ii = SkImageInfo::Make(fWidth, fHeight, fColorType,
128 kPremul_SkAlphaType, fColorSpace);
129
Greg Daniel60ea40c2019-02-12 13:38:44 -0500130 const GrCaps* caps = context->priv().caps();
131 GrBackendFormat backendFormat = caps->getBackendFormatFromColorType(fColorType);
Robert Phillipsbe77a022018-04-03 17:17:05 -0400132 if (!backendFormat.isValid()) {
133 return SkSurfaceCharacterization();
134 }
Robert Phillipsfc711a22018-02-13 17:03:00 -0500135
136 SkSurfaceCharacterization c = context->threadSafeProxy()->createCharacterization(
137 maxResourceBytes, ii, backendFormat, fSampleCount,
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500138 fOrigin, fSurfaceProps, fShouldCreateMipMaps,
139 fUsesGLFBO0, fIsTextureable);
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400140 return c;
141 }
142
143 // Create a DDL whose characterization captures the current settings
144 std::unique_ptr<SkDeferredDisplayList> createDDL(GrContext* context) const {
145 SkSurfaceCharacterization c = this->createCharacterization(context);
Robert Phillipsfc711a22018-02-13 17:03:00 -0500146 SkAssertResult(c.isValid());
Robert Phillipse8fabb22018-02-04 14:33:21 -0500147
148 SkDeferredDisplayListRecorder r(c);
149 SkCanvas* canvas = r.getCanvas();
150 if (!canvas) {
151 return nullptr;
152 }
153
154 canvas->drawRect(SkRect::MakeXYWH(10, 10, 10, 10), SkPaint());
155 return r.detach();
156 }
157
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500158 // Create the surface with the current set of parameters
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500159 sk_sp<SkSurface> make(GrContext* context, GrBackendTexture* backend) const {
Robert Phillips9da87e02019-02-04 13:26:26 -0500160 GrGpu* gpu = context->priv().getGpu();
Robert Phillipse8fabb22018-02-04 14:33:21 -0500161
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500162 GrMipMapped mipmapped = !fIsTextureable
Robert Phillipsbe77a022018-04-03 17:17:05 -0400163 ? GrMipMapped::kNo
164 : GrMipMapped(fShouldCreateMipMaps);
Robert Phillipse8fabb22018-02-04 14:33:21 -0500165
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500166 if (fUsesGLFBO0) {
167 if (GrBackendApi::kOpenGL != context->backend()) {
168 return nullptr;
169 }
170
171 GrGLFramebufferInfo fboInfo;
172 fboInfo.fFBOID = 0;
173 fboInfo.fFormat = GR_GL_RGBA8;
174 static constexpr int kStencilBits = 8;
175 GrBackendRenderTarget backendRT(fWidth, fHeight, 1, kStencilBits, fboInfo);
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500176
177 if (!backendRT.isValid()) {
178 return nullptr;
179 }
180
181 return SkSurface::MakeFromBackendRenderTarget(context, backendRT, fOrigin,
182 fColorType, fColorSpace, &fSurfaceProps);
183 }
184
Robert Phillipse8fabb22018-02-04 14:33:21 -0500185 *backend = gpu->createTestingOnlyBackendTexture(nullptr, fWidth, fHeight,
Robert Phillips646f6372018-09-25 09:31:10 -0400186 fColorType, true, mipmapped);
Robert Phillipse8fabb22018-02-04 14:33:21 -0500187 if (!backend->isValid() || !gpu->isTestingOnlyBackendTexture(*backend)) {
188 return nullptr;
189 }
190
Robert Phillipsbe77a022018-04-03 17:17:05 -0400191 sk_sp<SkSurface> surface;
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500192 if (!fIsTextureable) {
Robert Phillipsbe77a022018-04-03 17:17:05 -0400193 // Create a surface w/ the current parameters but make it non-textureable
194 surface = SkSurface::MakeFromBackendTextureAsRenderTarget(
195 context, *backend, fOrigin, fSampleCount, fColorType,
196 fColorSpace, &fSurfaceProps);
197 } else {
198 surface = SkSurface::MakeFromBackendTexture(
199 context, *backend, fOrigin, fSampleCount, fColorType,
200 fColorSpace, &fSurfaceProps);
201 }
Robert Phillipse8fabb22018-02-04 14:33:21 -0500202
203 if (!surface) {
Brian Salomon26102cb2018-03-09 09:33:19 -0500204 gpu->deleteTestingOnlyBackendTexture(*backend);
Robert Phillipse8fabb22018-02-04 14:33:21 -0500205 return nullptr;
206 }
207
208 return surface;
209 }
210
Brian Salomon26102cb2018-03-09 09:33:19 -0500211 void cleanUpBackEnd(GrContext* context, const GrBackendTexture& backend) const {
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500212 if (!backend.isValid()) {
213 return;
214 }
215
Robert Phillips9da87e02019-02-04 13:26:26 -0500216 GrGpu* gpu = context->priv().getGpu();
Robert Phillipse8fabb22018-02-04 14:33:21 -0500217
218 gpu->deleteTestingOnlyBackendTexture(backend);
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500219 }
220
221private:
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500222 GrBackendApi fBackend;
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500223 int fWidth;
224 int fHeight;
225 GrSurfaceOrigin fOrigin;
226 SkColorType fColorType;
227 sk_sp<SkColorSpace> fColorSpace;
228 int fSampleCount;
229 SkSurfaceProps fSurfaceProps;
Robert Phillipse8fabb22018-02-04 14:33:21 -0500230 bool fShouldCreateMipMaps;
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500231 bool fUsesGLFBO0;
232 bool fIsTextureable;
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500233};
234
Robert Phillipsc1267c62018-04-04 11:12:39 -0400235// Test out operator== && operator!=
236DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLOperatorEqTest, reporter, ctxInfo) {
237 GrContext* context = ctxInfo.grContext();
238
239 for (int i = 0; i < SurfaceParameters::kNumParams; ++i) {
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500240 SurfaceParameters params1(context->backend());
Robert Phillipsc1267c62018-04-04 11:12:39 -0400241 params1.modify(i);
242
243 SkSurfaceCharacterization char1 = params1.createCharacterization(context);
244 if (!char1.isValid()) {
245 continue; // can happen on some platforms (ChromeOS)
246 }
247
248 for (int j = 0; j < SurfaceParameters::kNumParams; ++j) {
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500249 SurfaceParameters params2(context->backend());
Robert Phillipsc1267c62018-04-04 11:12:39 -0400250 params2.modify(j);
251
252 SkSurfaceCharacterization char2 = params2.createCharacterization(context);
253 if (!char2.isValid()) {
254 continue; // can happen on some platforms (ChromeOS)
255 }
256
257 if (i == j) {
258 REPORTER_ASSERT(reporter, char1 == char2);
259 } else {
260 REPORTER_ASSERT(reporter, char1 != char2);
261 }
262
263 }
264 }
265
266 {
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500267 SurfaceParameters params(context->backend());
Robert Phillipsc1267c62018-04-04 11:12:39 -0400268
269 SkSurfaceCharacterization valid = params.createCharacterization(context);
270 SkASSERT(valid.isValid());
271
272 SkSurfaceCharacterization inval1, inval2;
273 SkASSERT(!inval1.isValid() && !inval2.isValid());
274
275 REPORTER_ASSERT(reporter, inval1 != inval2);
276 REPORTER_ASSERT(reporter, valid != inval1);
277 REPORTER_ASSERT(reporter, inval1 != valid);
278 }
279}
280
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400281////////////////////////////////////////////////////////////////////////////////
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500282// This tests SkSurfaceCharacterization/SkSurface compatibility
Robert Phillipsbe77a022018-04-03 17:17:05 -0400283DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLSurfaceCharacterizationTest, reporter, ctxInfo) {
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500284 GrContext* context = ctxInfo.grContext();
Robert Phillips9da87e02019-02-04 13:26:26 -0500285 GrGpu* gpu = context->priv().getGpu();
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500286
Robert Phillips9e441ee2018-02-01 15:14:55 -0500287 // Create a bitmap that we can readback into
288 SkImageInfo imageInfo = SkImageInfo::Make(64, 64, kRGBA_8888_SkColorType,
289 kPremul_SkAlphaType);
290 SkBitmap bitmap;
291 bitmap.allocPixels(imageInfo);
292
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500293 std::unique_ptr<SkDeferredDisplayList> ddl;
294
295 // First, create a DDL using the stock SkSurface parameters
296 {
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500297 SurfaceParameters params(context->backend());
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500298
Robert Phillipse8fabb22018-02-04 14:33:21 -0500299 ddl = params.createDDL(context);
Robert Phillipsfc711a22018-02-13 17:03:00 -0500300 SkAssertResult(ddl);
Robert Phillipse8fabb22018-02-04 14:33:21 -0500301
302 // The DDL should draw into an SkSurface created with the same parameters
Robert Phillipsbe77a022018-04-03 17:17:05 -0400303 GrBackendTexture backend;
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500304 sk_sp<SkSurface> s = params.make(context, &backend);
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500305 if (!s) {
306 return;
307 }
308
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500309 REPORTER_ASSERT(reporter, s->draw(ddl.get()));
Robert Phillips9e441ee2018-02-01 15:14:55 -0500310 s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
Robert Phillipsbe77a022018-04-03 17:17:05 -0400311 context->flush();
312 gpu->testingOnly_flushGpuAndSync();
313 s = nullptr;
314 params.cleanUpBackEnd(context, backend);
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500315 }
316
317 // Then, alter each parameter in turn and check that the DDL & surface are incompatible
318 for (int i = 0; i < SurfaceParameters::kNumParams; ++i) {
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500319 SurfaceParameters params(context->backend());
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500320 params.modify(i);
321
Robert Phillipsbe77a022018-04-03 17:17:05 -0400322 GrBackendTexture backend;
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500323 sk_sp<SkSurface> s = params.make(context, &backend);
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500324 if (!s) {
325 continue;
326 }
327
328 if (SurfaceParameters::kSampleCount == i) {
329 SkSurface_Gpu* gpuSurf = static_cast<SkSurface_Gpu*>(s.get());
330
Robert Phillips9da87e02019-02-04 13:26:26 -0500331 int supportedSampleCount = context->priv().caps()->getRenderTargetSampleCount(
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400332 params.sampleCount(),
333 gpuSurf->getDevice()
334 ->accessRenderTargetContext()
335 ->asRenderTargetProxy()
336 ->config());
Brian Salomonbdecacf2018-02-02 20:32:49 -0500337 if (1 == supportedSampleCount) {
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500338 // If changing the sample count won't result in a different
339 // surface characterization, skip this step
Robert Phillipsbe77a022018-04-03 17:17:05 -0400340 s = nullptr;
341 params.cleanUpBackEnd(context, backend);
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500342 continue;
343 }
344 }
345
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400346 if (SurfaceParameters::kMipMipCount == i &&
Robert Phillips9da87e02019-02-04 13:26:26 -0500347 !context->priv().caps()->mipMapSupport()) {
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400348 // If changing the mipmap setting won't result in a different surface characterization,
349 // skip this step
Robert Phillipsbe77a022018-04-03 17:17:05 -0400350 s = nullptr;
351 params.cleanUpBackEnd(context, backend);
Robert Phillipse8fabb22018-02-04 14:33:21 -0500352 continue;
353 }
354
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500355 if (SurfaceParameters::kFBO0Count == i && context->backend() != GrBackendApi::kOpenGL) {
356 // FBO0 only affects the surface characterization when using OpenGL
357 s = nullptr;
358 params.cleanUpBackEnd(context, backend);
359 continue;
360 }
361
Robert Phillipse8fabb22018-02-04 14:33:21 -0500362 REPORTER_ASSERT(reporter, !s->draw(ddl.get()),
363 "DDLSurfaceCharacterizationTest failed on parameter: %d\n", i);
Robert Phillipsbe77a022018-04-03 17:17:05 -0400364
365 context->flush();
366 gpu->testingOnly_flushGpuAndSync();
367 s = nullptr;
368 params.cleanUpBackEnd(context, backend);
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500369 }
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500370
371 // Next test the compatibility of resource cache parameters
372 {
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500373 const SurfaceParameters params(context->backend());
Robert Phillipsbe77a022018-04-03 17:17:05 -0400374 GrBackendTexture backend;
375
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500376 sk_sp<SkSurface> s = params.make(context, &backend);
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500377
378 int maxResourceCount;
379 size_t maxResourceBytes;
380 context->getResourceCacheLimits(&maxResourceCount, &maxResourceBytes);
381
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500382 context->setResourceCacheLimits(maxResourceCount, maxResourceBytes/2);
383 REPORTER_ASSERT(reporter, !s->draw(ddl.get()));
384
Robert Phillips9e441ee2018-02-01 15:14:55 -0500385 // DDL TODO: once proxies/ops can be de-instantiated we can re-enable these tests.
386 // For now, DDLs are drawn once.
387#if 0
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500388 // resource limits >= those at characterization time are accepted
389 context->setResourceCacheLimits(2*maxResourceCount, maxResourceBytes);
390 REPORTER_ASSERT(reporter, s->draw(ddl.get()));
Robert Phillips9e441ee2018-02-01 15:14:55 -0500391 s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500392
393 context->setResourceCacheLimits(maxResourceCount, 2*maxResourceBytes);
394 REPORTER_ASSERT(reporter, s->draw(ddl.get()));
Robert Phillips9e441ee2018-02-01 15:14:55 -0500395 s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500396
397 context->setResourceCacheLimits(maxResourceCount, maxResourceBytes);
398 REPORTER_ASSERT(reporter, s->draw(ddl.get()));
Robert Phillips9e441ee2018-02-01 15:14:55 -0500399 s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
400#endif
Robert Phillipsbe77a022018-04-03 17:17:05 -0400401
402 context->flush();
403 gpu->testingOnly_flushGpuAndSync();
404 s = nullptr;
405 params.cleanUpBackEnd(context, backend);
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500406 }
407
Robert Phillipse8fabb22018-02-04 14:33:21 -0500408 // Test that the textureability of the DDL characterization can block a DDL draw
409 {
410 GrBackendTexture backend;
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500411 SurfaceParameters params(context->backend());
412 params.setTextureable(false);
413
414 sk_sp<SkSurface> s = params.make(context, &backend);
Robert Phillipse8fabb22018-02-04 14:33:21 -0500415 if (s) {
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500416 REPORTER_ASSERT(reporter, !s->draw(ddl.get())); // bc the DDL was made w/ textureability
Robert Phillipse8fabb22018-02-04 14:33:21 -0500417
Robert Phillipsbe77a022018-04-03 17:17:05 -0400418 context->flush();
419 gpu->testingOnly_flushGpuAndSync();
Robert Phillipse8fabb22018-02-04 14:33:21 -0500420 s = nullptr;
Brian Salomon26102cb2018-03-09 09:33:19 -0500421 params.cleanUpBackEnd(context, backend);
Robert Phillipse8fabb22018-02-04 14:33:21 -0500422 }
423 }
424
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500425 // Make sure non-GPU-backed surfaces fail characterization
426 {
427 SkImageInfo ii = SkImageInfo::MakeN32(64, 64, kOpaque_SkAlphaType);
428
429 sk_sp<SkSurface> rasterSurface = SkSurface::MakeRaster(ii);
430 SkSurfaceCharacterization c;
431 REPORTER_ASSERT(reporter, !rasterSurface->characterize(&c));
432 }
Robert Phillips94458ee2018-03-06 13:41:51 -0500433
434 // Exercise the createResized method
435 {
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500436 SurfaceParameters params(context->backend());
Robert Phillipsbe77a022018-04-03 17:17:05 -0400437 GrBackendTexture backend;
Robert Phillips94458ee2018-03-06 13:41:51 -0500438
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500439 sk_sp<SkSurface> s = params.make(context, &backend);
Robert Phillips94458ee2018-03-06 13:41:51 -0500440 if (!s) {
441 return;
442 }
443
444 SkSurfaceCharacterization char0;
445 SkAssertResult(s->characterize(&char0));
446
447 // Too small
448 SkSurfaceCharacterization char1 = char0.createResized(-1, -1);
449 REPORTER_ASSERT(reporter, !char1.isValid());
450
451 // Too large
452 SkSurfaceCharacterization char2 = char0.createResized(1000000, 32);
453 REPORTER_ASSERT(reporter, !char2.isValid());
454
455 // Just right
456 SkSurfaceCharacterization char3 = char0.createResized(32, 32);
457 REPORTER_ASSERT(reporter, char3.isValid());
458 REPORTER_ASSERT(reporter, 32 == char3.width());
459 REPORTER_ASSERT(reporter, 32 == char3.height());
Robert Phillipsbe77a022018-04-03 17:17:05 -0400460
461 s = nullptr;
462 params.cleanUpBackEnd(context, backend);
Robert Phillips94458ee2018-03-06 13:41:51 -0500463 }
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500464}
465
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500466// Test that a DDL created w/o textureability can be replayed into both a textureable and
467// non-textureable destination. Note that DDLSurfaceCharacterizationTest tests that a
468// textureable DDL cannot be played into a non-textureable destination but can be replayed
469// into a textureable destination.
470DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLNonTextureabilityTest, reporter, ctxInfo) {
471 GrContext* context = ctxInfo.grContext();
Robert Phillips9da87e02019-02-04 13:26:26 -0500472 GrGpu* gpu = context->priv().getGpu();
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500473
474 // Create a bitmap that we can readback into
475 SkImageInfo imageInfo = SkImageInfo::Make(64, 64, kRGBA_8888_SkColorType,
476 kPremul_SkAlphaType);
477 SkBitmap bitmap;
478 bitmap.allocPixels(imageInfo);
479
480 for (bool textureability : { true, false }) {
481 std::unique_ptr<SkDeferredDisplayList> ddl;
482
483 // First, create a DDL w/o textureability. TODO: once we have reusable DDLs, move this
484 // outside of the loop.
485 {
486 SurfaceParameters params(context->backend());
487 params.setTextureable(false);
488
489 ddl = params.createDDL(context);
490 SkAssertResult(ddl);
491 }
492
493 // Then verify it can draw into either flavor of destination
494 SurfaceParameters params(context->backend());
495 params.setTextureable(textureability);
496
497 GrBackendTexture backend;
498 sk_sp<SkSurface> s = params.make(context, &backend);
499 if (!s) {
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500500 continue;
501 }
502
503 REPORTER_ASSERT(reporter, s->draw(ddl.get()));
504 s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
505 context->flush();
506 gpu->testingOnly_flushGpuAndSync();
507 s = nullptr;
508 params.cleanUpBackEnd(context, backend);
509 }
510
511}
512
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400513////////////////////////////////////////////////////////////////////////////////
514// This tests the SkSurface::MakeRenderTarget variant that takes an SkSurfaceCharacterization.
515// In particular, the SkSurface and the SkSurfaceCharacterization should always be compatible.
Robert Phillipsbe77a022018-04-03 17:17:05 -0400516DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLMakeRenderTargetTest, reporter, ctxInfo) {
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400517 GrContext* context = ctxInfo.grContext();
518
519 for (int i = 0; i < SurfaceParameters::kNumParams; ++i) {
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500520 SurfaceParameters params(context->backend());
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400521 params.modify(i);
522
523 SkSurfaceCharacterization c = params.createCharacterization(context);
Robert Phillipsbe77a022018-04-03 17:17:05 -0400524 GrBackendTexture backend;
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400525
Robert Phillipsbe77a022018-04-03 17:17:05 -0400526 if (!c.isValid()) {
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500527 sk_sp<SkSurface> tmp = params.make(context, &backend);
Robert Phillipsbe77a022018-04-03 17:17:05 -0400528
529 // If we couldn't characterize the surface we shouldn't be able to create it either
530 REPORTER_ASSERT(reporter, !tmp);
531 if (tmp) {
532 tmp = nullptr;
533 params.cleanUpBackEnd(context, backend);
534 }
535 continue;
536 }
537
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500538 sk_sp<SkSurface> s = params.make(context, &backend);
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400539 if (!s) {
540 REPORTER_ASSERT(reporter, !c.isValid());
541 continue;
542 }
543
544 REPORTER_ASSERT(reporter, c.isValid());
545
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500546 if (SurfaceParameters::kFBO0Count == i) {
547 // MakeRenderTarget doesn't support FBO0
548 params.cleanUpBackEnd(context, backend);
549 continue;
550 }
551
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400552 s = SkSurface::MakeRenderTarget(context, c, SkBudgeted::kYes);
553 REPORTER_ASSERT(reporter, s);
554
555 SkSurface_Gpu* g = static_cast<SkSurface_Gpu*>(s.get());
556 REPORTER_ASSERT(reporter, g->isCompatible(c));
Robert Phillipsbe77a022018-04-03 17:17:05 -0400557
558 s = nullptr;
559 params.cleanUpBackEnd(context, backend);
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400560 }
561}
562
563////////////////////////////////////////////////////////////////////////////////
Greg Danielf2336e42018-01-23 16:38:14 -0500564static constexpr int kSize = 8;
565
566struct TextureReleaseChecker {
567 TextureReleaseChecker() : fReleaseCount(0) {}
568 int fReleaseCount;
569 static void Release(void* self) {
570 static_cast<TextureReleaseChecker*>(self)->fReleaseCount++;
571 }
572};
573
574enum class DDLStage { kMakeImage, kDrawImage, kDetach, kDrawDDL };
575
576// This tests the ability to create and use wrapped textures in a DDL world
577DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLWrapBackendTest, reporter, ctxInfo) {
578 GrContext* context = ctxInfo.grContext();
Robert Phillips9da87e02019-02-04 13:26:26 -0500579 GrGpu* gpu = context->priv().getGpu();
Brian Salomonf7778972018-03-08 10:13:17 -0500580 GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(
Robert Phillips646f6372018-09-25 09:31:10 -0400581 nullptr, kSize, kSize, GrColorType::kRGBA_8888, false, GrMipMapped::kNo);
Brian Salomonf7778972018-03-08 10:13:17 -0500582 if (!backendTex.isValid()) {
583 return;
Greg Danielf2336e42018-01-23 16:38:14 -0500584 }
Brian Salomonf7778972018-03-08 10:13:17 -0500585
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500586 SurfaceParameters params(context->backend());
Robert Phillipsbe77a022018-04-03 17:17:05 -0400587 GrBackendTexture backend;
Brian Salomonf7778972018-03-08 10:13:17 -0500588
Robert Phillipsb45f47d2019-02-03 17:17:54 -0500589 sk_sp<SkSurface> s = params.make(context, &backend);
Brian Salomonf7778972018-03-08 10:13:17 -0500590 if (!s) {
Brian Salomon26102cb2018-03-09 09:33:19 -0500591 gpu->deleteTestingOnlyBackendTexture(backendTex);
Brian Salomonf7778972018-03-08 10:13:17 -0500592 return;
593 }
594
595 SkSurfaceCharacterization c;
596 SkAssertResult(s->characterize(&c));
597
598 std::unique_ptr<SkDeferredDisplayListRecorder> recorder(new SkDeferredDisplayListRecorder(c));
599
600 SkCanvas* canvas = recorder->getCanvas();
601 if (!canvas) {
Robert Phillipsbe77a022018-04-03 17:17:05 -0400602 s = nullptr;
603 params.cleanUpBackEnd(context, backend);
Brian Salomon26102cb2018-03-09 09:33:19 -0500604 gpu->deleteTestingOnlyBackendTexture(backendTex);
Brian Salomonf7778972018-03-08 10:13:17 -0500605 return;
606 }
607
608 GrContext* deferredContext = canvas->getGrContext();
609 if (!deferredContext) {
Robert Phillipsbe77a022018-04-03 17:17:05 -0400610 s = nullptr;
611 params.cleanUpBackEnd(context, backend);
Brian Salomon26102cb2018-03-09 09:33:19 -0500612 gpu->deleteTestingOnlyBackendTexture(backendTex);
Brian Salomonf7778972018-03-08 10:13:17 -0500613 return;
614 }
615
616 // Wrapped Backend Textures are not supported in DDL
617 sk_sp<SkImage> image =
618 SkImage::MakeFromAdoptedTexture(deferredContext, backendTex, kTopLeft_GrSurfaceOrigin,
619 kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr);
620 REPORTER_ASSERT(reporter, !image);
621
622 TextureReleaseChecker releaseChecker;
623 image = SkImage::MakeFromTexture(deferredContext, backendTex, kTopLeft_GrSurfaceOrigin,
624 kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr,
625 TextureReleaseChecker::Release, &releaseChecker);
626 REPORTER_ASSERT(reporter, !image);
627
Brian Salomon26102cb2018-03-09 09:33:19 -0500628 gpu->deleteTestingOnlyBackendTexture(backendTex);
Robert Phillipsbe77a022018-04-03 17:17:05 -0400629
630 s = nullptr;
631 params.cleanUpBackEnd(context, backend);
Greg Danielf2336e42018-01-23 16:38:14 -0500632}
633
Brian Salomon59ef8c32019-01-30 12:20:56 -0500634static sk_sp<SkPromiseImageTexture> dummy_fulfill_proc(void*) {
635 SkASSERT(0);
636 return nullptr;
637}
Robert Phillips6ceaafa2018-03-15 16:53:06 -0400638static void dummy_release_proc(void*) { SkASSERT(0); }
Brian Salomon59ef8c32019-01-30 12:20:56 -0500639static void dummy_done_proc(void*) {}
Robert Phillips6ceaafa2018-03-15 16:53:06 -0400640
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400641////////////////////////////////////////////////////////////////////////////////
Robert Phillips6ceaafa2018-03-15 16:53:06 -0400642// Test out the behavior of an invalid DDLRecorder
643DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLInvalidRecorder, reporter, ctxInfo) {
644 GrContext* context = ctxInfo.grContext();
645
646 {
647 SkImageInfo ii = SkImageInfo::MakeN32Premul(32, 32);
648 sk_sp<SkSurface> s = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, ii);
649
650 SkSurfaceCharacterization characterization;
651 SkAssertResult(s->characterize(&characterization));
652
653 // never calling getCanvas means the backing surface is never allocated
654 SkDeferredDisplayListRecorder recorder(characterization);
655 }
656
657 {
658 SkSurfaceCharacterization invalid;
659
660 SkDeferredDisplayListRecorder recorder(invalid);
661
662 const SkSurfaceCharacterization c = recorder.characterization();
663 REPORTER_ASSERT(reporter, !c.isValid());
664 REPORTER_ASSERT(reporter, !recorder.getCanvas());
665 REPORTER_ASSERT(reporter, !recorder.detach());
666
Greg Daniel60ea40c2019-02-12 13:38:44 -0500667 const GrCaps* caps = context->priv().caps();
668 GrBackendFormat format = caps->getBackendFormatFromColorType(kRGBA_8888_SkColorType);
669
Brian Salomonf55e8d52019-01-30 17:28:20 -0500670 sk_sp<SkImage> image = recorder.makePromiseTexture(
671 format, 32, 32, GrMipMapped::kNo,
672 kTopLeft_GrSurfaceOrigin,
673 kRGBA_8888_SkColorType,
674 kPremul_SkAlphaType, nullptr,
675 dummy_fulfill_proc,
676 dummy_release_proc,
677 dummy_done_proc,
678 nullptr,
679 SkDeferredDisplayListRecorder::DelayReleaseCallback::kNo);
Robert Phillips6ceaafa2018-03-15 16:53:06 -0400680 REPORTER_ASSERT(reporter, !image);
681 }
682
683}
684
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400685////////////////////////////////////////////////////////////////////////////////
Robert Phillips874b5352018-03-16 08:48:24 -0400686// Ensure that flushing while DDL recording doesn't cause a crash
687DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLFlushWhileRecording, reporter, ctxInfo) {
688 GrContext* context = ctxInfo.grContext();
689
690 SkImageInfo ii = SkImageInfo::MakeN32Premul(32, 32);
691 sk_sp<SkSurface> s = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, ii);
692
693 SkSurfaceCharacterization characterization;
694 SkAssertResult(s->characterize(&characterization));
695
696 SkDeferredDisplayListRecorder recorder(characterization);
697 SkCanvas* canvas = recorder.getCanvas();
698
699 canvas->flush();
700 canvas->getGrContext()->flush();
701}
Greg Danielf2336e42018-01-23 16:38:14 -0500702
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400703////////////////////////////////////////////////////////////////////////////////
Robert Phillipsf54883c2018-12-18 08:29:09 -0500704// Ensure that reusing a single DDLRecorder to create multiple DDLs works cleanly
705DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLMultipleDDLs, reporter, ctxInfo) {
706 GrContext* context = ctxInfo.grContext();
707
708 SkImageInfo ii = SkImageInfo::MakeN32Premul(32, 32);
709 sk_sp<SkSurface> s = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, ii);
710
711 SkBitmap bitmap;
712 bitmap.allocPixels(ii);
713
714 SkSurfaceCharacterization characterization;
715 SkAssertResult(s->characterize(&characterization));
716
717 SkDeferredDisplayListRecorder recorder(characterization);
718
719 SkCanvas* canvas1 = recorder.getCanvas();
720
721 canvas1->clear(SK_ColorRED);
722
723 canvas1->save();
724 canvas1->clipRect(SkRect::MakeXYWH(8, 8, 16, 16));
725
726 std::unique_ptr<SkDeferredDisplayList> ddl1 = recorder.detach();
727
728 SkCanvas* canvas2 = recorder.getCanvas();
729
730 SkPaint p;
731 p.setColor(SK_ColorGREEN);
732 canvas2->drawRect(SkRect::MakeWH(32, 32), p);
733
734 std::unique_ptr<SkDeferredDisplayList> ddl2 = recorder.detach();
735
736 REPORTER_ASSERT(reporter, ddl1->priv().lazyProxyData());
737 REPORTER_ASSERT(reporter, ddl2->priv().lazyProxyData());
738
739 // The lazy proxy data being different ensures that the SkSurface, SkCanvas and backing-
740 // lazy proxy are all different between the two DDLs
741 REPORTER_ASSERT(reporter, ddl1->priv().lazyProxyData() != ddl2->priv().lazyProxyData());
742
743 s->draw(ddl1.get());
744 s->draw(ddl2.get());
745
746 // Make sure the clipRect from DDL1 didn't percolate into DDL2
747 s->readPixels(ii, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
748 for (int y = 0; y < 32; ++y) {
749 for (int x = 0; x < 32; ++x) {
750 REPORTER_ASSERT(reporter, bitmap.getColor(x, y) == SK_ColorGREEN);
751 if (bitmap.getColor(x, y) != SK_ColorGREEN) {
752 return; // we only really need to report the error once
753 }
754 }
755 }
756}
757
758////////////////////////////////////////////////////////////////////////////////
Robert Phillipsabf7b762018-03-21 12:13:37 -0400759// Check that the texture-specific flags (i.e., for external & rectangle textures) work
760// for promise images. As such, this is a GL-only test.
761DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(DDLTextureFlagsTest, reporter, ctxInfo) {
762 GrContext* context = ctxInfo.grContext();
763
764 SkImageInfo ii = SkImageInfo::MakeN32Premul(32, 32);
765 sk_sp<SkSurface> s = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, ii);
766
767 SkSurfaceCharacterization characterization;
768 SkAssertResult(s->characterize(&characterization));
769
770 SkDeferredDisplayListRecorder recorder(characterization);
771
772 for (GrGLenum target : { GR_GL_TEXTURE_EXTERNAL, GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_2D } ) {
Greg Daniel09c94002018-06-08 22:11:51 +0000773 for (auto mipMapped : { GrMipMapped::kNo, GrMipMapped::kYes }) {
774 GrBackendFormat format = GrBackendFormat::MakeGL(GR_GL_RGBA8, target);
Robert Phillipsabf7b762018-03-21 12:13:37 -0400775
Brian Salomonf55e8d52019-01-30 17:28:20 -0500776 sk_sp<SkImage> image = recorder.makePromiseTexture(
777 format, 32, 32, mipMapped,
778 kTopLeft_GrSurfaceOrigin,
779 kRGBA_8888_SkColorType,
780 kPremul_SkAlphaType, nullptr,
781 dummy_fulfill_proc,
782 dummy_release_proc,
783 dummy_done_proc,
784 nullptr,
785 SkDeferredDisplayListRecorder::DelayReleaseCallback::kNo);
Greg Daniel09c94002018-06-08 22:11:51 +0000786 if (GR_GL_TEXTURE_2D != target && mipMapped == GrMipMapped::kYes) {
787 REPORTER_ASSERT(reporter, !image);
788 continue;
789 }
790 REPORTER_ASSERT(reporter, image);
Robert Phillipsabf7b762018-03-21 12:13:37 -0400791
Jim Van Verth21bd60d2018-10-12 15:00:20 -0400792 GrTextureProxy* backingProxy = ((SkImage_GpuBase*) image.get())->peekProxy();
Robert Phillipsabf7b762018-03-21 12:13:37 -0400793
Greg Daniel09c94002018-06-08 22:11:51 +0000794 REPORTER_ASSERT(reporter, backingProxy->mipMapped() == mipMapped);
795 if (GR_GL_TEXTURE_2D == target) {
Brian Salomonfd98c2c2018-07-31 17:25:29 -0400796 REPORTER_ASSERT(reporter, !backingProxy->hasRestrictedSampling());
Greg Daniel09c94002018-06-08 22:11:51 +0000797 } else {
Brian Salomonfd98c2c2018-07-31 17:25:29 -0400798 REPORTER_ASSERT(reporter, backingProxy->hasRestrictedSampling());
Greg Daniel09c94002018-06-08 22:11:51 +0000799 }
Robert Phillipsabf7b762018-03-21 12:13:37 -0400800 }
801 }
Robert Phillipsbe77a022018-04-03 17:17:05 -0400802}
803
804////////////////////////////////////////////////////////////////////////////////
805
Robert Phillips646f6372018-09-25 09:31:10 -0400806// Test colorType and pixelConfig compatibility.
Robert Phillipsbe77a022018-04-03 17:17:05 -0400807DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(DDLCompatibilityTest, reporter, ctxInfo) {
808 GrContext* context = ctxInfo.grContext();
809
810 for (int ct = 0; ct <= kLastEnum_SkColorType; ++ct) {
811 SkColorType colorType = static_cast<SkColorType>(ct);
812
Greg Daniel60ea40c2019-02-12 13:38:44 -0500813 SurfaceParameters params(context->backend());
814 params.setColorType(colorType);
815 params.setColorSpace(nullptr);
Robert Phillipsbe77a022018-04-03 17:17:05 -0400816
Greg Daniel60ea40c2019-02-12 13:38:44 -0500817 SkSurfaceCharacterization c = params.createCharacterization(context);
818 GrBackendTexture backend;
Robert Phillipsbe77a022018-04-03 17:17:05 -0400819
Greg Daniel60ea40c2019-02-12 13:38:44 -0500820 if (!c.isValid()) {
821 sk_sp<SkSurface> tmp = params.make(context, &backend);
Robert Phillipsbe77a022018-04-03 17:17:05 -0400822
Greg Daniel60ea40c2019-02-12 13:38:44 -0500823 // If we couldn't characterize the surface we shouldn't be able to create it either
824 REPORTER_ASSERT(reporter, !tmp);
825 if (tmp) {
826 tmp = nullptr;
Robert Phillipsbe77a022018-04-03 17:17:05 -0400827 params.cleanUpBackEnd(context, backend);
Robert Phillipsbe77a022018-04-03 17:17:05 -0400828 }
Greg Daniel60ea40c2019-02-12 13:38:44 -0500829 continue;
830 }
Robert Phillipsbe77a022018-04-03 17:17:05 -0400831
Greg Daniel60ea40c2019-02-12 13:38:44 -0500832 sk_sp<SkSurface> s = params.make(context, &backend);
833 REPORTER_ASSERT(reporter, s);
834 if (!s) {
Robert Phillipsbe77a022018-04-03 17:17:05 -0400835 s = nullptr;
836 params.cleanUpBackEnd(context, backend);
Greg Daniel60ea40c2019-02-12 13:38:44 -0500837 continue;
Robert Phillipsbe77a022018-04-03 17:17:05 -0400838 }
Greg Daniel60ea40c2019-02-12 13:38:44 -0500839
840 SkSurface_Gpu* gpuSurface = static_cast<SkSurface_Gpu*>(s.get());
841 REPORTER_ASSERT(reporter, gpuSurface->isCompatible(c));
842
843 s = nullptr;
844 params.cleanUpBackEnd(context, backend);
845
846 s = SkSurface::MakeRenderTarget(context, c, SkBudgeted::kYes);
847 REPORTER_ASSERT(reporter, s);
848 if (!s) {
849 continue;
850 }
851
852 gpuSurface = static_cast<SkSurface_Gpu*>(s.get());
853 REPORTER_ASSERT(reporter, gpuSurface->isCompatible(c));
Robert Phillipsbe77a022018-04-03 17:17:05 -0400854 }
Robert Phillipsabf7b762018-03-21 12:13:37 -0400855
856}