blob: 97164775911627ce2aafd3c3e9d7eb654ab48adc [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
8#include "SkTypes.h"
9
10#if SK_SUPPORT_GPU
11
Greg Danielf2336e42018-01-23 16:38:14 -050012#include "GrBackendSurface.h"
13#include "GrGpu.h"
Robert Phillipsabf7b762018-03-21 12:13:37 -040014#include "GrTextureProxyPriv.h"
15
Robert Phillips7ffbcf92017-12-04 12:52:46 -050016#include "SkCanvas.h"
Robert Phillipsc1267c62018-04-04 11:12:39 -040017#include "SkColorSpacePriv.h"
Robert Phillips7ffbcf92017-12-04 12:52:46 -050018#include "SkDeferredDisplayListRecorder.h"
19#include "SkGpuDevice.h"
Robert Phillipsabf7b762018-03-21 12:13:37 -040020#include "SkImage_Gpu.h"
Robert Phillips7ffbcf92017-12-04 12:52:46 -050021#include "SkSurface.h"
22#include "SkSurface_Gpu.h"
23#include "SkSurfaceCharacterization.h"
24#include "SkSurfaceProps.h"
25#include "Test.h"
26
Robert Phillipsfc711a22018-02-13 17:03:00 -050027#include "gl/GrGLDefines.h"
Robert Phillipsbe77a022018-04-03 17:17:05 -040028#include "gl/GrGLCaps.h"
Robert Phillipsfc711a22018-02-13 17:03:00 -050029#ifdef SK_VULKAN
30#include "vk/GrVkDefines.h"
31#endif
32
Robert Phillipsbe77a022018-04-03 17:17:05 -040033// Try to create a backend format from the provided colorType and config. Return an invalid
34// backend format if the combination is infeasible.
35static GrBackendFormat create_backend_format(GrContext* context,
36 SkColorType ct, SkColorSpace* cs,
37 GrPixelConfig config) {
Robert Phillipsfc711a22018-02-13 17:03:00 -050038 const GrCaps* caps = context->caps();
39
Robert Phillipsbe77a022018-04-03 17:17:05 -040040 // TODO: what should be done if we have a colorspace that doesn't have a gammaCloseToSRGB?
41
Robert Phillipsfc711a22018-02-13 17:03:00 -050042 switch (context->contextPriv().getBackend()) {
Robert Phillipsbe77a022018-04-03 17:17:05 -040043 case kOpenGL_GrBackend: {
44 const GrGLCaps* glCaps = static_cast<const GrGLCaps*>(context->caps());
45 GrGLStandard standard = glCaps->standard();
46
47 switch (ct) {
48 case kUnknown_SkColorType:
49 return GrBackendFormat();
50 case kAlpha_8_SkColorType:
51 if (kAlpha_8_as_Alpha_GrPixelConfig == config) {
52 return GrBackendFormat::MakeGL(GR_GL_ALPHA8, GR_GL_TEXTURE_2D);
53 } else if (kAlpha_8_GrPixelConfig == config ||
54 kAlpha_8_as_Red_GrPixelConfig == config) {
55 return GrBackendFormat::MakeGL(GR_GL_R8, GR_GL_TEXTURE_2D);
56 }
57 break;
58 case kRGB_565_SkColorType:
59 if (kRGB_565_GrPixelConfig == config) {
60 return GrBackendFormat::MakeGL(GR_GL_RGB565, GR_GL_TEXTURE_2D);
61 }
62 break;
63 case kARGB_4444_SkColorType:
64 if (kRGBA_4444_GrPixelConfig == config) {
65 return GrBackendFormat::MakeGL(GR_GL_RGBA4, GR_GL_TEXTURE_2D);
66 }
67 break;
68 case kRGBA_8888_SkColorType:
69 if (kRGBA_8888_GrPixelConfig == config) {
70 if (!cs || (cs->gammaCloseToSRGB() && !caps->srgbSupport())) {
71 return GrBackendFormat::MakeGL(GR_GL_RGBA8, GR_GL_TEXTURE_2D);
72 }
73 } else if (kSRGBA_8888_GrPixelConfig == config) {
74 if (caps->srgbSupport() && cs && cs->gammaCloseToSRGB()) {
75 return GrBackendFormat::MakeGL(GR_GL_SRGB8_ALPHA8, GR_GL_TEXTURE_2D);
76 }
77 }
78 break;
79 case kRGB_888x_SkColorType:
80 if (kRGB_888_GrPixelConfig == config) {
81 return GrBackendFormat::MakeGL(GR_GL_RGB8, GR_GL_TEXTURE_2D);
82 }
83 break;
84 case kBGRA_8888_SkColorType:
85 if (kBGRA_8888_GrPixelConfig == config) {
86 if (kGL_GrGLStandard == standard) {
87 return GrBackendFormat::MakeGL(GR_GL_RGBA8, GR_GL_TEXTURE_2D);
88 } else if (kGLES_GrGLStandard == standard) {
89 return GrBackendFormat::MakeGL(GR_GL_BGRA8, GR_GL_TEXTURE_2D);
90 }
91 } else if (kSBGRA_8888_GrPixelConfig == config) {
92 if (caps->srgbSupport() && cs && cs->gammaCloseToSRGB()) {
93 return GrBackendFormat::MakeGL(GR_GL_SRGB8_ALPHA8, GR_GL_TEXTURE_2D);
94 }
95 }
96 break;
97 case kRGBA_1010102_SkColorType:
98 if (kRGBA_1010102_GrPixelConfig == config) {
99 return GrBackendFormat::MakeGL(GR_GL_RGB10_A2, GR_GL_TEXTURE_2D);
100 }
101 break;
102 case kRGB_101010x_SkColorType:
103 return GrBackendFormat();
104 case kGray_8_SkColorType:
105 if (kGray_8_as_Lum_GrPixelConfig == config) {
106 return GrBackendFormat::MakeGL(GR_GL_LUMINANCE8, GR_GL_TEXTURE_2D);
107 } else if (kGray_8_GrPixelConfig == config ||
108 kGray_8_as_Red_GrPixelConfig == config) {
109 return GrBackendFormat::MakeGL(GR_GL_R8, GR_GL_TEXTURE_2D);
110 }
111 break;
112 case kRGBA_F16_SkColorType:
113 if (kRGBA_half_GrPixelConfig == config) {
114 return GrBackendFormat::MakeGL(GR_GL_RGBA16F, GR_GL_TEXTURE_2D);
115 }
116 break;
Robert Phillipsfc711a22018-02-13 17:03:00 -0500117 }
Robert Phillipsbe77a022018-04-03 17:17:05 -0400118 }
119 break;
Robert Phillipsfc711a22018-02-13 17:03:00 -0500120#ifdef SK_VULKAN
121 case kVulkan_GrBackend:
Robert Phillipsbe77a022018-04-03 17:17:05 -0400122 switch (ct) {
123 case kUnknown_SkColorType:
124 return GrBackendFormat();
125 case kAlpha_8_SkColorType:
126 // TODO: what about kAlpha_8_GrPixelConfig and kAlpha_8_as_Alpha_GrPixelConfig
127 if (kAlpha_8_as_Red_GrPixelConfig == config) {
128 return GrBackendFormat::MakeVk(VK_FORMAT_R8_UNORM);
129 }
130 break;
131 case kRGB_565_SkColorType:
132 if (kRGB_565_GrPixelConfig == config) {
133 return GrBackendFormat::MakeVk(VK_FORMAT_R5G6B5_UNORM_PACK16);
134 }
135 break;
136 case kARGB_4444_SkColorType:
137 if (kRGBA_4444_GrPixelConfig == config) {
138 return GrBackendFormat::MakeVk(VK_FORMAT_B4G4R4A4_UNORM_PACK16);
139 }
140 break;
141 case kRGBA_8888_SkColorType:
142 if (kRGBA_8888_GrPixelConfig == config) {
143 if (!cs || (cs->gammaCloseToSRGB() && !caps->srgbSupport())) {
144 return GrBackendFormat::MakeVk(VK_FORMAT_R8G8B8A8_UNORM);
145 }
146 } else if (kSRGBA_8888_GrPixelConfig == config) {
147 if (caps->srgbSupport() && cs && cs->gammaCloseToSRGB()) {
148 return GrBackendFormat::MakeVk(VK_FORMAT_R8G8B8A8_SRGB);
149 }
150 }
151 break;
152 case kRGB_888x_SkColorType:
153 if (kRGB_888_GrPixelConfig == config) {
154 return GrBackendFormat::MakeVk(VK_FORMAT_R8G8B8_UNORM);
155 }
156 break;
157 case kBGRA_8888_SkColorType:
158 if (kBGRA_8888_GrPixelConfig == config) {
159 return GrBackendFormat::MakeVk(VK_FORMAT_B8G8R8A8_UNORM);
160 } else if (kSBGRA_8888_GrPixelConfig == config) {
161 if (caps->srgbSupport() && cs && cs->gammaCloseToSRGB()) {
162 return GrBackendFormat::MakeVk(VK_FORMAT_B8G8R8A8_SRGB);
163 }
164 }
165 break;
166 case kRGBA_1010102_SkColorType:
167 if (kRGBA_1010102_GrPixelConfig == config) {
168 return GrBackendFormat::MakeVk(VK_FORMAT_A2B10G10R10_UNORM_PACK32);
169 }
170 break;
171 case kRGB_101010x_SkColorType:
172 return GrBackendFormat();
173 case kGray_8_SkColorType:
174 // TODO: what about kAlpha_8_GrPixelConfig and kGray_8_as_Lum_GrPixelConfig?
175 if (kGray_8_as_Red_GrPixelConfig == config) {
176 return GrBackendFormat::MakeVk(VK_FORMAT_R8_UNORM);
177 }
178 break;
179 case kRGBA_F16_SkColorType:
180 if (kRGBA_half_GrPixelConfig == config) {
181 return GrBackendFormat::MakeVk(VK_FORMAT_R16G16B16A16_SFLOAT);
182 }
183 break;
Robert Phillipsfc711a22018-02-13 17:03:00 -0500184 }
185 break;
186#endif
187 case kMock_GrBackend:
Robert Phillipsbe77a022018-04-03 17:17:05 -0400188 switch (ct) {
189 case kUnknown_SkColorType:
190 return GrBackendFormat();
191 case kAlpha_8_SkColorType:
192 if (kAlpha_8_GrPixelConfig == config ||
193 kAlpha_8_as_Alpha_GrPixelConfig == config ||
194 kAlpha_8_as_Red_GrPixelConfig == config) {
195 return GrBackendFormat::MakeMock(config);
196 }
197 break;
198 case kRGB_565_SkColorType:
199 if (kRGB_565_GrPixelConfig == config) {
200 return GrBackendFormat::MakeMock(config);
201 }
202 break;
203 case kARGB_4444_SkColorType:
204 if (kRGBA_4444_GrPixelConfig == config) {
205 return GrBackendFormat::MakeMock(config);
206 }
207 break;
208 case kRGBA_8888_SkColorType:
209 if (kRGBA_8888_GrPixelConfig == config) {
210 if (!cs || (cs->gammaCloseToSRGB() && !caps->srgbSupport())) {
211 return GrBackendFormat::MakeMock(config);
212 }
213 } else if (kSRGBA_8888_GrPixelConfig == config) {
214 if (caps->srgbSupport() && cs && cs->gammaCloseToSRGB()) {
215 return GrBackendFormat::MakeMock(config);
216 }
217 }
218 break;
219 case kRGB_888x_SkColorType:
220 if (kRGB_888_GrPixelConfig == config) {
221 return GrBackendFormat::MakeMock(config);
222 }
223 break;
224 case kBGRA_8888_SkColorType:
225 if (kBGRA_8888_GrPixelConfig == config) {
226 return GrBackendFormat::MakeMock(config);
227 } else if (kSBGRA_8888_GrPixelConfig == config) {
228 if (caps->srgbSupport() && cs && cs->gammaCloseToSRGB()) {
229 return GrBackendFormat::MakeMock(config);
230 }
231 }
232 break;
233 case kRGBA_1010102_SkColorType:
234 if (kRGBA_1010102_GrPixelConfig == config) {
235 return GrBackendFormat::MakeMock(config);
236 }
237 break;
238 case kRGB_101010x_SkColorType:
239 return GrBackendFormat();
240 case kGray_8_SkColorType:
241 if (kGray_8_GrPixelConfig == config ||
242 kGray_8_as_Lum_GrPixelConfig == config ||
243 kGray_8_as_Red_GrPixelConfig == config) {
244 return GrBackendFormat::MakeMock(config);
245 }
246 break;
247 case kRGBA_F16_SkColorType:
248 if (kRGBA_half_GrPixelConfig == config) {
249 return GrBackendFormat::MakeMock(config);
250 }
251 break;
Robert Phillipsfc711a22018-02-13 17:03:00 -0500252 }
253 break;
254 default:
255 return GrBackendFormat(); // return an invalid format
256 }
257
258 return GrBackendFormat(); // return an invalid format
259}
260
261
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500262class SurfaceParameters {
263public:
Robert Phillipse8fabb22018-02-04 14:33:21 -0500264 static const int kNumParams = 9;
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500265 static const int kSampleCount = 5;
Robert Phillipse8fabb22018-02-04 14:33:21 -0500266 static const int kMipMipCount = 8;
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500267
Robert Phillipsbe77a022018-04-03 17:17:05 -0400268 SurfaceParameters(const GrCaps* caps)
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500269 : fWidth(64)
270 , fHeight(64)
271 , fOrigin(kTopLeft_GrSurfaceOrigin)
272 , fColorType(kRGBA_8888_SkColorType)
Robert Phillipsbe77a022018-04-03 17:17:05 -0400273 , fConfig(caps->srgbSupport() ? kSRGBA_8888_GrPixelConfig : kRGBA_8888_GrPixelConfig)
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500274 , fColorSpace(SkColorSpace::MakeSRGB())
Brian Salomonbdecacf2018-02-02 20:32:49 -0500275 , fSampleCount(1)
Robert Phillipse8fabb22018-02-04 14:33:21 -0500276 , fSurfaceProps(0x0, kUnknown_SkPixelGeometry)
277 , fShouldCreateMipMaps(true) {
278 }
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500279
280 int sampleCount() const { return fSampleCount; }
281
Robert Phillipsbe77a022018-04-03 17:17:05 -0400282 void setColorType(SkColorType ct) { fColorType = ct; }
283 void setColorSpace(sk_sp<SkColorSpace> cs) { fColorSpace = std::move(cs); }
284 void setConfig(GrPixelConfig config) { fConfig = config; }
285
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500286 // Modify the SurfaceParameters in just one way
287 void modify(int i) {
288 switch (i) {
289 case 0:
290 fWidth = 63;
291 break;
292 case 1:
293 fHeight = 63;
294 break;
295 case 2:
296 fOrigin = kBottomLeft_GrSurfaceOrigin;
297 break;
298 case 3:
Robert Phillipsc1267c62018-04-04 11:12:39 -0400299 // The color type and config need to be changed together.
300 // The original SRGB color space no longer makes sense for F16
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500301 fColorType = kRGBA_F16_SkColorType;
Robert Phillipsbe77a022018-04-03 17:17:05 -0400302 fConfig = kRGBA_half_GrPixelConfig;
303 fColorSpace = SkColorSpace::MakeSRGBLinear();
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500304 break;
305 case 4:
Robert Phillipsc1267c62018-04-04 11:12:39 -0400306 // This just needs to be a colorSpace different from that returned by MakeSRGB()
307 // but still be considered SRGB. In this case we just change the gamut.
308 fColorSpace = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
309 SkColorSpace::kAdobeRGB_Gamut);
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500310 break;
311 case kSampleCount:
312 fSampleCount = 4;
313 break;
314 case 6:
315 fSurfaceProps = SkSurfaceProps(0x0, kRGB_H_SkPixelGeometry);
316 break;
317 case 7:
318 fSurfaceProps = SkSurfaceProps(SkSurfaceProps::kUseDeviceIndependentFonts_Flag,
319 kUnknown_SkPixelGeometry);
320 break;
Robert Phillipse8fabb22018-02-04 14:33:21 -0500321 case 8:
322 fShouldCreateMipMaps = false;
323 break;
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500324 }
325 }
326
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400327 SkSurfaceCharacterization createCharacterization(GrContext* context) const {
Robert Phillipsfc711a22018-02-13 17:03:00 -0500328 int maxResourceCount;
329 size_t maxResourceBytes;
330 context->getResourceCacheLimits(&maxResourceCount, &maxResourceBytes);
331
332 // Note that Ganesh doesn't make use of the SkImageInfo's alphaType
333 SkImageInfo ii = SkImageInfo::Make(fWidth, fHeight, fColorType,
334 kPremul_SkAlphaType, fColorSpace);
335
Robert Phillipsbe77a022018-04-03 17:17:05 -0400336 GrBackendFormat backendFormat = create_backend_format(context, fColorType,
337 fColorSpace.get(), fConfig);
338 if (!backendFormat.isValid()) {
339 return SkSurfaceCharacterization();
340 }
Robert Phillipsfc711a22018-02-13 17:03:00 -0500341
342 SkSurfaceCharacterization c = context->threadSafeProxy()->createCharacterization(
343 maxResourceBytes, ii, backendFormat, fSampleCount,
344 fOrigin, fSurfaceProps, fShouldCreateMipMaps);
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400345 return c;
346 }
347
348 // Create a DDL whose characterization captures the current settings
349 std::unique_ptr<SkDeferredDisplayList> createDDL(GrContext* context) const {
350 SkSurfaceCharacterization c = this->createCharacterization(context);
Robert Phillipsfc711a22018-02-13 17:03:00 -0500351 SkAssertResult(c.isValid());
Robert Phillipse8fabb22018-02-04 14:33:21 -0500352
353 SkDeferredDisplayListRecorder r(c);
354 SkCanvas* canvas = r.getCanvas();
355 if (!canvas) {
356 return nullptr;
357 }
358
359 canvas->drawRect(SkRect::MakeXYWH(10, 10, 10, 10), SkPaint());
360 return r.detach();
361 }
362
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500363 // Create the surface with the current set of parameters
Robert Phillipsbe77a022018-04-03 17:17:05 -0400364 sk_sp<SkSurface> make(GrContext* context, GrBackendTexture* backend,
365 bool nonTextureable) const {
Robert Phillipse8fabb22018-02-04 14:33:21 -0500366 GrGpu* gpu = context->contextPriv().getGpu();
367
Robert Phillipsbe77a022018-04-03 17:17:05 -0400368 GrMipMapped mipmapped = nonTextureable
369 ? GrMipMapped::kNo
370 : GrMipMapped(fShouldCreateMipMaps);
Robert Phillipse8fabb22018-02-04 14:33:21 -0500371
372 *backend = gpu->createTestingOnlyBackendTexture(nullptr, fWidth, fHeight,
Robert Phillipsbe77a022018-04-03 17:17:05 -0400373 fConfig, true, mipmapped);
Robert Phillipse8fabb22018-02-04 14:33:21 -0500374 if (!backend->isValid() || !gpu->isTestingOnlyBackendTexture(*backend)) {
375 return nullptr;
376 }
377
Robert Phillipsbe77a022018-04-03 17:17:05 -0400378 sk_sp<SkSurface> surface;
379 if (nonTextureable) {
380 // Create a surface w/ the current parameters but make it non-textureable
381 surface = SkSurface::MakeFromBackendTextureAsRenderTarget(
382 context, *backend, fOrigin, fSampleCount, fColorType,
383 fColorSpace, &fSurfaceProps);
384 } else {
385 surface = SkSurface::MakeFromBackendTexture(
386 context, *backend, fOrigin, fSampleCount, fColorType,
387 fColorSpace, &fSurfaceProps);
388 }
Robert Phillipse8fabb22018-02-04 14:33:21 -0500389
390 if (!surface) {
Brian Salomon26102cb2018-03-09 09:33:19 -0500391 gpu->deleteTestingOnlyBackendTexture(*backend);
Robert Phillipse8fabb22018-02-04 14:33:21 -0500392 return nullptr;
393 }
394
395 return surface;
396 }
397
Brian Salomon26102cb2018-03-09 09:33:19 -0500398 void cleanUpBackEnd(GrContext* context, const GrBackendTexture& backend) const {
Robert Phillipse8fabb22018-02-04 14:33:21 -0500399 GrGpu* gpu = context->contextPriv().getGpu();
400
401 gpu->deleteTestingOnlyBackendTexture(backend);
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500402 }
403
404private:
405 int fWidth;
406 int fHeight;
407 GrSurfaceOrigin fOrigin;
408 SkColorType fColorType;
Robert Phillipsbe77a022018-04-03 17:17:05 -0400409 GrPixelConfig fConfig;
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500410 sk_sp<SkColorSpace> fColorSpace;
411 int fSampleCount;
412 SkSurfaceProps fSurfaceProps;
Robert Phillipse8fabb22018-02-04 14:33:21 -0500413 bool fShouldCreateMipMaps;
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500414};
415
Robert Phillipsc1267c62018-04-04 11:12:39 -0400416// Test out operator== && operator!=
417DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLOperatorEqTest, reporter, ctxInfo) {
418 GrContext* context = ctxInfo.grContext();
419
420 for (int i = 0; i < SurfaceParameters::kNumParams; ++i) {
421 SurfaceParameters params1(context->caps());
422 params1.modify(i);
423
424 SkSurfaceCharacterization char1 = params1.createCharacterization(context);
425 if (!char1.isValid()) {
426 continue; // can happen on some platforms (ChromeOS)
427 }
428
429 for (int j = 0; j < SurfaceParameters::kNumParams; ++j) {
430 SurfaceParameters params2(context->caps());
431 params2.modify(j);
432
433 SkSurfaceCharacterization char2 = params2.createCharacterization(context);
434 if (!char2.isValid()) {
435 continue; // can happen on some platforms (ChromeOS)
436 }
437
438 if (i == j) {
439 REPORTER_ASSERT(reporter, char1 == char2);
440 } else {
441 REPORTER_ASSERT(reporter, char1 != char2);
442 }
443
444 }
445 }
446
447 {
448 SurfaceParameters params(context->caps());
449
450 SkSurfaceCharacterization valid = params.createCharacterization(context);
451 SkASSERT(valid.isValid());
452
453 SkSurfaceCharacterization inval1, inval2;
454 SkASSERT(!inval1.isValid() && !inval2.isValid());
455
456 REPORTER_ASSERT(reporter, inval1 != inval2);
457 REPORTER_ASSERT(reporter, valid != inval1);
458 REPORTER_ASSERT(reporter, inval1 != valid);
459 }
460}
461
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400462////////////////////////////////////////////////////////////////////////////////
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500463// This tests SkSurfaceCharacterization/SkSurface compatibility
Robert Phillipsbe77a022018-04-03 17:17:05 -0400464DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLSurfaceCharacterizationTest, reporter, ctxInfo) {
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500465 GrContext* context = ctxInfo.grContext();
Robert Phillipsbe77a022018-04-03 17:17:05 -0400466 GrGpu* gpu = context->contextPriv().getGpu();
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500467
Robert Phillips9e441ee2018-02-01 15:14:55 -0500468 // Create a bitmap that we can readback into
469 SkImageInfo imageInfo = SkImageInfo::Make(64, 64, kRGBA_8888_SkColorType,
470 kPremul_SkAlphaType);
471 SkBitmap bitmap;
472 bitmap.allocPixels(imageInfo);
473
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500474 std::unique_ptr<SkDeferredDisplayList> ddl;
475
476 // First, create a DDL using the stock SkSurface parameters
477 {
Robert Phillipsbe77a022018-04-03 17:17:05 -0400478 SurfaceParameters params(context->caps());
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500479
Robert Phillipse8fabb22018-02-04 14:33:21 -0500480 ddl = params.createDDL(context);
Robert Phillipsfc711a22018-02-13 17:03:00 -0500481 SkAssertResult(ddl);
Robert Phillipse8fabb22018-02-04 14:33:21 -0500482
483 // The DDL should draw into an SkSurface created with the same parameters
Robert Phillipsbe77a022018-04-03 17:17:05 -0400484 GrBackendTexture backend;
485 sk_sp<SkSurface> s = params.make(context, &backend, false);
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500486 if (!s) {
487 return;
488 }
489
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500490 REPORTER_ASSERT(reporter, s->draw(ddl.get()));
Robert Phillips9e441ee2018-02-01 15:14:55 -0500491 s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
Robert Phillipsbe77a022018-04-03 17:17:05 -0400492 context->flush();
493 gpu->testingOnly_flushGpuAndSync();
494 s = nullptr;
495 params.cleanUpBackEnd(context, backend);
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500496 }
497
498 // Then, alter each parameter in turn and check that the DDL & surface are incompatible
499 for (int i = 0; i < SurfaceParameters::kNumParams; ++i) {
Robert Phillipsbe77a022018-04-03 17:17:05 -0400500 SurfaceParameters params(context->caps());
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500501 params.modify(i);
502
Robert Phillipsbe77a022018-04-03 17:17:05 -0400503 GrBackendTexture backend;
504 sk_sp<SkSurface> s = params.make(context, &backend, false);
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500505 if (!s) {
506 continue;
507 }
508
509 if (SurfaceParameters::kSampleCount == i) {
510 SkSurface_Gpu* gpuSurf = static_cast<SkSurface_Gpu*>(s.get());
511
Brian Salomonbdecacf2018-02-02 20:32:49 -0500512 int supportedSampleCount = context->caps()->getRenderTargetSampleCount(
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500513 params.sampleCount(),
514 gpuSurf->getDevice()->accessRenderTargetContext()->asRenderTargetProxy()->config());
Brian Salomonbdecacf2018-02-02 20:32:49 -0500515 if (1 == supportedSampleCount) {
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500516 // If changing the sample count won't result in a different
517 // surface characterization, skip this step
Robert Phillipsbe77a022018-04-03 17:17:05 -0400518 s = nullptr;
519 params.cleanUpBackEnd(context, backend);
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500520 continue;
521 }
522 }
523
Robert Phillipse8fabb22018-02-04 14:33:21 -0500524 if (SurfaceParameters::kMipMipCount == i && !context->caps()->mipMapSupport()) {
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400525 // If changing the mipmap setting won't result in a different surface characterization,
526 // skip this step
Robert Phillipsbe77a022018-04-03 17:17:05 -0400527 s = nullptr;
528 params.cleanUpBackEnd(context, backend);
Robert Phillipse8fabb22018-02-04 14:33:21 -0500529 continue;
530 }
531
532 REPORTER_ASSERT(reporter, !s->draw(ddl.get()),
533 "DDLSurfaceCharacterizationTest failed on parameter: %d\n", i);
Robert Phillipsbe77a022018-04-03 17:17:05 -0400534
535 context->flush();
536 gpu->testingOnly_flushGpuAndSync();
537 s = nullptr;
538 params.cleanUpBackEnd(context, backend);
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500539 }
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500540
541 // Next test the compatibility of resource cache parameters
542 {
Robert Phillipsbe77a022018-04-03 17:17:05 -0400543 const SurfaceParameters params(context->caps());
544 GrBackendTexture backend;
545
546 sk_sp<SkSurface> s = params.make(context, &backend, false);
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500547
548 int maxResourceCount;
549 size_t maxResourceBytes;
550 context->getResourceCacheLimits(&maxResourceCount, &maxResourceBytes);
551
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500552 context->setResourceCacheLimits(maxResourceCount, maxResourceBytes/2);
553 REPORTER_ASSERT(reporter, !s->draw(ddl.get()));
554
Robert Phillips9e441ee2018-02-01 15:14:55 -0500555 // DDL TODO: once proxies/ops can be de-instantiated we can re-enable these tests.
556 // For now, DDLs are drawn once.
557#if 0
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500558 // resource limits >= those at characterization time are accepted
559 context->setResourceCacheLimits(2*maxResourceCount, maxResourceBytes);
560 REPORTER_ASSERT(reporter, s->draw(ddl.get()));
Robert Phillips9e441ee2018-02-01 15:14:55 -0500561 s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500562
563 context->setResourceCacheLimits(maxResourceCount, 2*maxResourceBytes);
564 REPORTER_ASSERT(reporter, s->draw(ddl.get()));
Robert Phillips9e441ee2018-02-01 15:14:55 -0500565 s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500566
567 context->setResourceCacheLimits(maxResourceCount, maxResourceBytes);
568 REPORTER_ASSERT(reporter, s->draw(ddl.get()));
Robert Phillips9e441ee2018-02-01 15:14:55 -0500569 s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
570#endif
Robert Phillipsbe77a022018-04-03 17:17:05 -0400571
572 context->flush();
573 gpu->testingOnly_flushGpuAndSync();
574 s = nullptr;
575 params.cleanUpBackEnd(context, backend);
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500576 }
577
Robert Phillipse8fabb22018-02-04 14:33:21 -0500578 // Test that the textureability of the DDL characterization can block a DDL draw
579 {
580 GrBackendTexture backend;
Robert Phillipsbe77a022018-04-03 17:17:05 -0400581 const SurfaceParameters params(context->caps());
582 sk_sp<SkSurface> s = params.make(context, &backend, true);
Robert Phillipse8fabb22018-02-04 14:33:21 -0500583 if (s) {
584 REPORTER_ASSERT(reporter, !s->draw(ddl.get()));
585
Robert Phillipsbe77a022018-04-03 17:17:05 -0400586 context->flush();
587 gpu->testingOnly_flushGpuAndSync();
Robert Phillipse8fabb22018-02-04 14:33:21 -0500588 s = nullptr;
Brian Salomon26102cb2018-03-09 09:33:19 -0500589 params.cleanUpBackEnd(context, backend);
Robert Phillipse8fabb22018-02-04 14:33:21 -0500590 }
591 }
592
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500593 // Make sure non-GPU-backed surfaces fail characterization
594 {
595 SkImageInfo ii = SkImageInfo::MakeN32(64, 64, kOpaque_SkAlphaType);
596
597 sk_sp<SkSurface> rasterSurface = SkSurface::MakeRaster(ii);
598 SkSurfaceCharacterization c;
599 REPORTER_ASSERT(reporter, !rasterSurface->characterize(&c));
600 }
Robert Phillips94458ee2018-03-06 13:41:51 -0500601
602 // Exercise the createResized method
603 {
Robert Phillipsbe77a022018-04-03 17:17:05 -0400604 SurfaceParameters params(context->caps());
605 GrBackendTexture backend;
Robert Phillips94458ee2018-03-06 13:41:51 -0500606
Robert Phillipsbe77a022018-04-03 17:17:05 -0400607 sk_sp<SkSurface> s = params.make(context, &backend, false);
Robert Phillips94458ee2018-03-06 13:41:51 -0500608 if (!s) {
609 return;
610 }
611
612 SkSurfaceCharacterization char0;
613 SkAssertResult(s->characterize(&char0));
614
615 // Too small
616 SkSurfaceCharacterization char1 = char0.createResized(-1, -1);
617 REPORTER_ASSERT(reporter, !char1.isValid());
618
619 // Too large
620 SkSurfaceCharacterization char2 = char0.createResized(1000000, 32);
621 REPORTER_ASSERT(reporter, !char2.isValid());
622
623 // Just right
624 SkSurfaceCharacterization char3 = char0.createResized(32, 32);
625 REPORTER_ASSERT(reporter, char3.isValid());
626 REPORTER_ASSERT(reporter, 32 == char3.width());
627 REPORTER_ASSERT(reporter, 32 == char3.height());
Robert Phillipsbe77a022018-04-03 17:17:05 -0400628
629 s = nullptr;
630 params.cleanUpBackEnd(context, backend);
Robert Phillips94458ee2018-03-06 13:41:51 -0500631 }
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500632}
633
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400634////////////////////////////////////////////////////////////////////////////////
635// This tests the SkSurface::MakeRenderTarget variant that takes an SkSurfaceCharacterization.
636// In particular, the SkSurface and the SkSurfaceCharacterization should always be compatible.
Robert Phillipsbe77a022018-04-03 17:17:05 -0400637DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLMakeRenderTargetTest, reporter, ctxInfo) {
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400638 GrContext* context = ctxInfo.grContext();
639
640 for (int i = 0; i < SurfaceParameters::kNumParams; ++i) {
Robert Phillipsbe77a022018-04-03 17:17:05 -0400641 SurfaceParameters params(context->caps());
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400642 params.modify(i);
643
644 SkSurfaceCharacterization c = params.createCharacterization(context);
Robert Phillipsbe77a022018-04-03 17:17:05 -0400645 GrBackendTexture backend;
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400646
Robert Phillipsbe77a022018-04-03 17:17:05 -0400647 if (!c.isValid()) {
648 sk_sp<SkSurface> tmp = params.make(context, &backend, false);
649
650 // If we couldn't characterize the surface we shouldn't be able to create it either
651 REPORTER_ASSERT(reporter, !tmp);
652 if (tmp) {
653 tmp = nullptr;
654 params.cleanUpBackEnd(context, backend);
655 }
656 continue;
657 }
658
659 sk_sp<SkSurface> s = params.make(context, &backend, false);
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400660 if (!s) {
661 REPORTER_ASSERT(reporter, !c.isValid());
662 continue;
663 }
664
665 REPORTER_ASSERT(reporter, c.isValid());
666
667 s = SkSurface::MakeRenderTarget(context, c, SkBudgeted::kYes);
668 REPORTER_ASSERT(reporter, s);
669
670 SkSurface_Gpu* g = static_cast<SkSurface_Gpu*>(s.get());
671 REPORTER_ASSERT(reporter, g->isCompatible(c));
Robert Phillipsbe77a022018-04-03 17:17:05 -0400672
673 s = nullptr;
674 params.cleanUpBackEnd(context, backend);
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400675 }
676}
677
678////////////////////////////////////////////////////////////////////////////////
Greg Danielf2336e42018-01-23 16:38:14 -0500679static constexpr int kSize = 8;
680
681struct TextureReleaseChecker {
682 TextureReleaseChecker() : fReleaseCount(0) {}
683 int fReleaseCount;
684 static void Release(void* self) {
685 static_cast<TextureReleaseChecker*>(self)->fReleaseCount++;
686 }
687};
688
689enum class DDLStage { kMakeImage, kDrawImage, kDetach, kDrawDDL };
690
691// This tests the ability to create and use wrapped textures in a DDL world
692DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLWrapBackendTest, reporter, ctxInfo) {
693 GrContext* context = ctxInfo.grContext();
694 GrGpu* gpu = context->contextPriv().getGpu();
Brian Salomonf7778972018-03-08 10:13:17 -0500695 GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(
696 nullptr, kSize, kSize, kRGBA_8888_GrPixelConfig, false, GrMipMapped::kNo);
697 if (!backendTex.isValid()) {
698 return;
Greg Danielf2336e42018-01-23 16:38:14 -0500699 }
Brian Salomonf7778972018-03-08 10:13:17 -0500700
Robert Phillipsbe77a022018-04-03 17:17:05 -0400701 SurfaceParameters params(context->caps());
702 GrBackendTexture backend;
Brian Salomonf7778972018-03-08 10:13:17 -0500703
Robert Phillipsbe77a022018-04-03 17:17:05 -0400704 sk_sp<SkSurface> s = params.make(context, &backend, false);
Brian Salomonf7778972018-03-08 10:13:17 -0500705 if (!s) {
Brian Salomon26102cb2018-03-09 09:33:19 -0500706 gpu->deleteTestingOnlyBackendTexture(backendTex);
Brian Salomonf7778972018-03-08 10:13:17 -0500707 return;
708 }
709
710 SkSurfaceCharacterization c;
711 SkAssertResult(s->characterize(&c));
712
713 std::unique_ptr<SkDeferredDisplayListRecorder> recorder(new SkDeferredDisplayListRecorder(c));
714
715 SkCanvas* canvas = recorder->getCanvas();
716 if (!canvas) {
Robert Phillipsbe77a022018-04-03 17:17:05 -0400717 s = nullptr;
718 params.cleanUpBackEnd(context, backend);
Brian Salomon26102cb2018-03-09 09:33:19 -0500719 gpu->deleteTestingOnlyBackendTexture(backendTex);
Brian Salomonf7778972018-03-08 10:13:17 -0500720 return;
721 }
722
723 GrContext* deferredContext = canvas->getGrContext();
724 if (!deferredContext) {
Robert Phillipsbe77a022018-04-03 17:17:05 -0400725 s = nullptr;
726 params.cleanUpBackEnd(context, backend);
Brian Salomon26102cb2018-03-09 09:33:19 -0500727 gpu->deleteTestingOnlyBackendTexture(backendTex);
Brian Salomonf7778972018-03-08 10:13:17 -0500728 return;
729 }
730
731 // Wrapped Backend Textures are not supported in DDL
732 sk_sp<SkImage> image =
733 SkImage::MakeFromAdoptedTexture(deferredContext, backendTex, kTopLeft_GrSurfaceOrigin,
734 kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr);
735 REPORTER_ASSERT(reporter, !image);
736
737 TextureReleaseChecker releaseChecker;
738 image = SkImage::MakeFromTexture(deferredContext, backendTex, kTopLeft_GrSurfaceOrigin,
739 kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr,
740 TextureReleaseChecker::Release, &releaseChecker);
741 REPORTER_ASSERT(reporter, !image);
742
Brian Salomon26102cb2018-03-09 09:33:19 -0500743 gpu->deleteTestingOnlyBackendTexture(backendTex);
Robert Phillipsbe77a022018-04-03 17:17:05 -0400744
745 s = nullptr;
746 params.cleanUpBackEnd(context, backend);
Greg Danielf2336e42018-01-23 16:38:14 -0500747}
748
Robert Phillips6ceaafa2018-03-15 16:53:06 -0400749static void dummy_fulfill_proc(void*, GrBackendTexture*) { SkASSERT(0); }
750static void dummy_release_proc(void*) { SkASSERT(0); }
Robert Phillipsabf7b762018-03-21 12:13:37 -0400751static void dummy_done_proc(void*) { }
Robert Phillips6ceaafa2018-03-15 16:53:06 -0400752
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400753////////////////////////////////////////////////////////////////////////////////
Robert Phillips6ceaafa2018-03-15 16:53:06 -0400754// Test out the behavior of an invalid DDLRecorder
755DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLInvalidRecorder, reporter, ctxInfo) {
756 GrContext* context = ctxInfo.grContext();
757
758 {
759 SkImageInfo ii = SkImageInfo::MakeN32Premul(32, 32);
760 sk_sp<SkSurface> s = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, ii);
761
762 SkSurfaceCharacterization characterization;
763 SkAssertResult(s->characterize(&characterization));
764
765 // never calling getCanvas means the backing surface is never allocated
766 SkDeferredDisplayListRecorder recorder(characterization);
767 }
768
769 {
770 SkSurfaceCharacterization invalid;
771
772 SkDeferredDisplayListRecorder recorder(invalid);
773
774 const SkSurfaceCharacterization c = recorder.characterization();
775 REPORTER_ASSERT(reporter, !c.isValid());
776 REPORTER_ASSERT(reporter, !recorder.getCanvas());
777 REPORTER_ASSERT(reporter, !recorder.detach());
778
Robert Phillipsbe77a022018-04-03 17:17:05 -0400779 GrBackendFormat format = create_backend_format(context, kRGBA_8888_SkColorType,
780 nullptr, kRGBA_8888_GrPixelConfig);
Robert Phillips6ceaafa2018-03-15 16:53:06 -0400781 sk_sp<SkImage> image = recorder.makePromiseTexture(format, 32, 32, GrMipMapped::kNo,
782 kTopLeft_GrSurfaceOrigin,
783 kRGBA_8888_SkColorType,
784 kPremul_SkAlphaType, nullptr,
785 dummy_fulfill_proc,
786 dummy_release_proc,
Greg Daniel7278d682018-03-16 14:57:21 -0400787 dummy_done_proc,
Robert Phillips6ceaafa2018-03-15 16:53:06 -0400788 nullptr);
789 REPORTER_ASSERT(reporter, !image);
790 }
791
792}
793
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400794////////////////////////////////////////////////////////////////////////////////
Robert Phillips874b5352018-03-16 08:48:24 -0400795// Ensure that flushing while DDL recording doesn't cause a crash
796DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLFlushWhileRecording, reporter, ctxInfo) {
797 GrContext* context = ctxInfo.grContext();
798
799 SkImageInfo ii = SkImageInfo::MakeN32Premul(32, 32);
800 sk_sp<SkSurface> s = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, ii);
801
802 SkSurfaceCharacterization characterization;
803 SkAssertResult(s->characterize(&characterization));
804
805 SkDeferredDisplayListRecorder recorder(characterization);
806 SkCanvas* canvas = recorder.getCanvas();
807
808 canvas->flush();
809 canvas->getGrContext()->flush();
810}
Greg Danielf2336e42018-01-23 16:38:14 -0500811
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400812////////////////////////////////////////////////////////////////////////////////
Robert Phillipsabf7b762018-03-21 12:13:37 -0400813// Check that the texture-specific flags (i.e., for external & rectangle textures) work
814// for promise images. As such, this is a GL-only test.
815DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(DDLTextureFlagsTest, reporter, ctxInfo) {
816 GrContext* context = ctxInfo.grContext();
817
818 SkImageInfo ii = SkImageInfo::MakeN32Premul(32, 32);
819 sk_sp<SkSurface> s = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, ii);
820
821 SkSurfaceCharacterization characterization;
822 SkAssertResult(s->characterize(&characterization));
823
824 SkDeferredDisplayListRecorder recorder(characterization);
825
826 for (GrGLenum target : { GR_GL_TEXTURE_EXTERNAL, GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_2D } ) {
827 GrBackendFormat format = GrBackendFormat::MakeGL(GR_GL_RGBA8, target);
828
Greg Daniele3204862018-04-16 11:24:10 -0400829 sk_sp<SkImage> image = recorder.makePromiseTexture(format, 32, 32, GrMipMapped::kYes,
Robert Phillipsabf7b762018-03-21 12:13:37 -0400830 kTopLeft_GrSurfaceOrigin,
831 kRGBA_8888_SkColorType,
832 kPremul_SkAlphaType, nullptr,
833 dummy_fulfill_proc,
834 dummy_release_proc,
835 dummy_done_proc,
836 nullptr);
837 REPORTER_ASSERT(reporter, image);
838
839 GrTextureProxy* backingProxy = ((SkImage_Gpu*) image.get())->peekProxy();
840
841 if (GR_GL_TEXTURE_2D == target) {
842 REPORTER_ASSERT(reporter, !backingProxy->texPriv().doesNotSupportMipMaps());
843 REPORTER_ASSERT(reporter, !backingProxy->texPriv().isClampOnly());
844 } else {
845 REPORTER_ASSERT(reporter, backingProxy->texPriv().doesNotSupportMipMaps());
846 REPORTER_ASSERT(reporter, backingProxy->texPriv().isClampOnly());
847 }
848 }
Robert Phillipsbe77a022018-04-03 17:17:05 -0400849}
850
851////////////////////////////////////////////////////////////////////////////////
852
853// Exhaustively test colorType and pixelConfig compatibility.
854DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(DDLCompatibilityTest, reporter, ctxInfo) {
855 GrContext* context = ctxInfo.grContext();
856
857 for (int ct = 0; ct <= kLastEnum_SkColorType; ++ct) {
858 SkColorType colorType = static_cast<SkColorType>(ct);
859
860 for (int config = 0; config < kGrPixelConfigCnt; ++config) {
861 GrPixelConfig pixelConfig = static_cast<GrPixelConfig>(config);
862
863 SurfaceParameters params(context->caps());
864 params.setColorType(colorType);
865 params.setConfig(pixelConfig);
866
867 params.setColorSpace(nullptr);
868 if (kSRGBA_8888_GrPixelConfig == pixelConfig ||
869 kSBGRA_8888_GrPixelConfig == pixelConfig) {
870 params.setColorSpace(SkColorSpace::MakeSRGB());
871 }
872
873 SkSurfaceCharacterization c = params.createCharacterization(context);
874 GrBackendTexture backend;
875
876 if (!c.isValid()) {
877 // TODO: this would be cool to enable but there is, currently, too much crossover
878 // allowed internally (e.g., kAlpha_8_SkColorType/kGray_8_as_Red_GrPixelConfig
879 // is permitted on GL).
880#if 0
881 sk_sp<SkSurface> tmp = params.make(context, &backend, false);
882
883 // If we couldn't characterize the surface we shouldn't be able to create it either
884 REPORTER_ASSERT(reporter, !tmp);
885 if (tmp) {
886 tmp = nullptr;
887 params.cleanUpBackEnd(context, backend);
888 }
889#endif
890 continue;
891 }
892
893 sk_sp<SkSurface> s = params.make(context, &backend, false);
894 REPORTER_ASSERT(reporter, s);
895 if (!s) {
896 s = nullptr;
897 params.cleanUpBackEnd(context, backend);
898 continue;
899 }
900
901 SkSurface_Gpu* gpuSurface = static_cast<SkSurface_Gpu*>(s.get());
902 REPORTER_ASSERT(reporter, gpuSurface->isCompatible(c));
903
904 s = nullptr;
905 params.cleanUpBackEnd(context, backend);
906
907 s = SkSurface::MakeRenderTarget(context, c, SkBudgeted::kYes);
908 REPORTER_ASSERT(reporter, s);
909 if (!s) {
910 continue;
911 }
912
913 gpuSurface = static_cast<SkSurface_Gpu*>(s.get());
914 REPORTER_ASSERT(reporter, gpuSurface->isCompatible(c));
915 }
916 }
Robert Phillipsabf7b762018-03-21 12:13:37 -0400917
918}
Robert Phillipsbe77a022018-04-03 17:17:05 -0400919
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500920#endif