blob: d033f890d88016d0ae53eacf4ea8622779c6b335 [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"
Brian Salomonc7fe0f72018-05-11 10:14:21 -040013#include "GrContextPriv.h"
Greg Danielf2336e42018-01-23 16:38:14 -050014#include "GrGpu.h"
Robert Phillipsabf7b762018-03-21 12:13:37 -040015#include "GrTextureProxyPriv.h"
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"
Robert Phillips7ffbcf92017-12-04 12:52:46 -050022#include "SkSurfaceCharacterization.h"
23#include "SkSurfaceProps.h"
Brian Salomonc7fe0f72018-05-11 10:14:21 -040024#include "SkSurface_Gpu.h"
Robert Phillips7ffbcf92017-12-04 12:52:46 -050025#include "Test.h"
Robert Phillipsbe77a022018-04-03 17:17:05 -040026#include "gl/GrGLCaps.h"
Brian Salomonc7fe0f72018-05-11 10:14:21 -040027#include "gl/GrGLDefines.h"
Robert Phillipsfc711a22018-02-13 17:03:00 -050028#ifdef SK_VULKAN
29#include "vk/GrVkDefines.h"
30#endif
31
Robert Phillipsbe77a022018-04-03 17:17:05 -040032// Try to create a backend format from the provided colorType and config. Return an invalid
33// backend format if the combination is infeasible.
34static GrBackendFormat create_backend_format(GrContext* context,
35 SkColorType ct, SkColorSpace* cs,
36 GrPixelConfig config) {
Brian Salomonc7fe0f72018-05-11 10:14:21 -040037 const GrCaps* caps = context->contextPriv().caps();
Robert Phillipsfc711a22018-02-13 17:03:00 -050038
Robert Phillipsbe77a022018-04-03 17:17:05 -040039 // TODO: what should be done if we have a colorspace that doesn't have a gammaCloseToSRGB?
40
Robert Phillipsfc711a22018-02-13 17:03:00 -050041 switch (context->contextPriv().getBackend()) {
Robert Phillipsbe77a022018-04-03 17:17:05 -040042 case kOpenGL_GrBackend: {
Brian Salomonc7fe0f72018-05-11 10:14:21 -040043 const GrGLCaps* glCaps = static_cast<const GrGLCaps*>(caps);
Robert Phillipsbe77a022018-04-03 17:17:05 -040044 GrGLStandard standard = glCaps->standard();
45
46 switch (ct) {
47 case kUnknown_SkColorType:
48 return GrBackendFormat();
49 case kAlpha_8_SkColorType:
50 if (kAlpha_8_as_Alpha_GrPixelConfig == config) {
51 return GrBackendFormat::MakeGL(GR_GL_ALPHA8, GR_GL_TEXTURE_2D);
52 } else if (kAlpha_8_GrPixelConfig == config ||
53 kAlpha_8_as_Red_GrPixelConfig == config) {
54 return GrBackendFormat::MakeGL(GR_GL_R8, GR_GL_TEXTURE_2D);
55 }
56 break;
57 case kRGB_565_SkColorType:
58 if (kRGB_565_GrPixelConfig == config) {
59 return GrBackendFormat::MakeGL(GR_GL_RGB565, GR_GL_TEXTURE_2D);
60 }
61 break;
62 case kARGB_4444_SkColorType:
63 if (kRGBA_4444_GrPixelConfig == config) {
64 return GrBackendFormat::MakeGL(GR_GL_RGBA4, GR_GL_TEXTURE_2D);
65 }
66 break;
67 case kRGBA_8888_SkColorType:
68 if (kRGBA_8888_GrPixelConfig == config) {
69 if (!cs || (cs->gammaCloseToSRGB() && !caps->srgbSupport())) {
70 return GrBackendFormat::MakeGL(GR_GL_RGBA8, GR_GL_TEXTURE_2D);
71 }
72 } else if (kSRGBA_8888_GrPixelConfig == config) {
73 if (caps->srgbSupport() && cs && cs->gammaCloseToSRGB()) {
74 return GrBackendFormat::MakeGL(GR_GL_SRGB8_ALPHA8, GR_GL_TEXTURE_2D);
75 }
76 }
77 break;
78 case kRGB_888x_SkColorType:
79 if (kRGB_888_GrPixelConfig == config) {
80 return GrBackendFormat::MakeGL(GR_GL_RGB8, GR_GL_TEXTURE_2D);
81 }
82 break;
83 case kBGRA_8888_SkColorType:
84 if (kBGRA_8888_GrPixelConfig == config) {
85 if (kGL_GrGLStandard == standard) {
86 return GrBackendFormat::MakeGL(GR_GL_RGBA8, GR_GL_TEXTURE_2D);
87 } else if (kGLES_GrGLStandard == standard) {
88 return GrBackendFormat::MakeGL(GR_GL_BGRA8, GR_GL_TEXTURE_2D);
89 }
90 } else if (kSBGRA_8888_GrPixelConfig == config) {
91 if (caps->srgbSupport() && cs && cs->gammaCloseToSRGB()) {
92 return GrBackendFormat::MakeGL(GR_GL_SRGB8_ALPHA8, GR_GL_TEXTURE_2D);
93 }
94 }
95 break;
96 case kRGBA_1010102_SkColorType:
97 if (kRGBA_1010102_GrPixelConfig == config) {
98 return GrBackendFormat::MakeGL(GR_GL_RGB10_A2, GR_GL_TEXTURE_2D);
99 }
100 break;
101 case kRGB_101010x_SkColorType:
102 return GrBackendFormat();
103 case kGray_8_SkColorType:
104 if (kGray_8_as_Lum_GrPixelConfig == config) {
105 return GrBackendFormat::MakeGL(GR_GL_LUMINANCE8, GR_GL_TEXTURE_2D);
106 } else if (kGray_8_GrPixelConfig == config ||
107 kGray_8_as_Red_GrPixelConfig == config) {
108 return GrBackendFormat::MakeGL(GR_GL_R8, GR_GL_TEXTURE_2D);
109 }
110 break;
111 case kRGBA_F16_SkColorType:
112 if (kRGBA_half_GrPixelConfig == config) {
113 return GrBackendFormat::MakeGL(GR_GL_RGBA16F, GR_GL_TEXTURE_2D);
114 }
115 break;
Robert Phillipsfc711a22018-02-13 17:03:00 -0500116 }
Robert Phillipsbe77a022018-04-03 17:17:05 -0400117 }
118 break;
Robert Phillipsfc711a22018-02-13 17:03:00 -0500119#ifdef SK_VULKAN
120 case kVulkan_GrBackend:
Robert Phillipsbe77a022018-04-03 17:17:05 -0400121 switch (ct) {
122 case kUnknown_SkColorType:
123 return GrBackendFormat();
124 case kAlpha_8_SkColorType:
125 // TODO: what about kAlpha_8_GrPixelConfig and kAlpha_8_as_Alpha_GrPixelConfig
126 if (kAlpha_8_as_Red_GrPixelConfig == config) {
127 return GrBackendFormat::MakeVk(VK_FORMAT_R8_UNORM);
128 }
129 break;
130 case kRGB_565_SkColorType:
131 if (kRGB_565_GrPixelConfig == config) {
132 return GrBackendFormat::MakeVk(VK_FORMAT_R5G6B5_UNORM_PACK16);
133 }
134 break;
135 case kARGB_4444_SkColorType:
136 if (kRGBA_4444_GrPixelConfig == config) {
137 return GrBackendFormat::MakeVk(VK_FORMAT_B4G4R4A4_UNORM_PACK16);
138 }
139 break;
140 case kRGBA_8888_SkColorType:
141 if (kRGBA_8888_GrPixelConfig == config) {
142 if (!cs || (cs->gammaCloseToSRGB() && !caps->srgbSupport())) {
143 return GrBackendFormat::MakeVk(VK_FORMAT_R8G8B8A8_UNORM);
144 }
145 } else if (kSRGBA_8888_GrPixelConfig == config) {
146 if (caps->srgbSupport() && cs && cs->gammaCloseToSRGB()) {
147 return GrBackendFormat::MakeVk(VK_FORMAT_R8G8B8A8_SRGB);
148 }
149 }
150 break;
151 case kRGB_888x_SkColorType:
152 if (kRGB_888_GrPixelConfig == config) {
153 return GrBackendFormat::MakeVk(VK_FORMAT_R8G8B8_UNORM);
154 }
155 break;
156 case kBGRA_8888_SkColorType:
157 if (kBGRA_8888_GrPixelConfig == config) {
158 return GrBackendFormat::MakeVk(VK_FORMAT_B8G8R8A8_UNORM);
159 } else if (kSBGRA_8888_GrPixelConfig == config) {
160 if (caps->srgbSupport() && cs && cs->gammaCloseToSRGB()) {
161 return GrBackendFormat::MakeVk(VK_FORMAT_B8G8R8A8_SRGB);
162 }
163 }
164 break;
165 case kRGBA_1010102_SkColorType:
166 if (kRGBA_1010102_GrPixelConfig == config) {
167 return GrBackendFormat::MakeVk(VK_FORMAT_A2B10G10R10_UNORM_PACK32);
168 }
169 break;
170 case kRGB_101010x_SkColorType:
171 return GrBackendFormat();
172 case kGray_8_SkColorType:
173 // TODO: what about kAlpha_8_GrPixelConfig and kGray_8_as_Lum_GrPixelConfig?
174 if (kGray_8_as_Red_GrPixelConfig == config) {
175 return GrBackendFormat::MakeVk(VK_FORMAT_R8_UNORM);
176 }
177 break;
178 case kRGBA_F16_SkColorType:
179 if (kRGBA_half_GrPixelConfig == config) {
180 return GrBackendFormat::MakeVk(VK_FORMAT_R16G16B16A16_SFLOAT);
181 }
182 break;
Robert Phillipsfc711a22018-02-13 17:03:00 -0500183 }
184 break;
185#endif
186 case kMock_GrBackend:
Robert Phillipsbe77a022018-04-03 17:17:05 -0400187 switch (ct) {
188 case kUnknown_SkColorType:
189 return GrBackendFormat();
190 case kAlpha_8_SkColorType:
191 if (kAlpha_8_GrPixelConfig == config ||
192 kAlpha_8_as_Alpha_GrPixelConfig == config ||
193 kAlpha_8_as_Red_GrPixelConfig == config) {
194 return GrBackendFormat::MakeMock(config);
195 }
196 break;
197 case kRGB_565_SkColorType:
198 if (kRGB_565_GrPixelConfig == config) {
199 return GrBackendFormat::MakeMock(config);
200 }
201 break;
202 case kARGB_4444_SkColorType:
203 if (kRGBA_4444_GrPixelConfig == config) {
204 return GrBackendFormat::MakeMock(config);
205 }
206 break;
207 case kRGBA_8888_SkColorType:
208 if (kRGBA_8888_GrPixelConfig == config) {
209 if (!cs || (cs->gammaCloseToSRGB() && !caps->srgbSupport())) {
210 return GrBackendFormat::MakeMock(config);
211 }
212 } else if (kSRGBA_8888_GrPixelConfig == config) {
213 if (caps->srgbSupport() && cs && cs->gammaCloseToSRGB()) {
214 return GrBackendFormat::MakeMock(config);
215 }
216 }
217 break;
218 case kRGB_888x_SkColorType:
219 if (kRGB_888_GrPixelConfig == config) {
220 return GrBackendFormat::MakeMock(config);
221 }
222 break;
223 case kBGRA_8888_SkColorType:
224 if (kBGRA_8888_GrPixelConfig == config) {
225 return GrBackendFormat::MakeMock(config);
226 } else if (kSBGRA_8888_GrPixelConfig == config) {
227 if (caps->srgbSupport() && cs && cs->gammaCloseToSRGB()) {
228 return GrBackendFormat::MakeMock(config);
229 }
230 }
231 break;
232 case kRGBA_1010102_SkColorType:
233 if (kRGBA_1010102_GrPixelConfig == config) {
234 return GrBackendFormat::MakeMock(config);
235 }
236 break;
237 case kRGB_101010x_SkColorType:
238 return GrBackendFormat();
239 case kGray_8_SkColorType:
240 if (kGray_8_GrPixelConfig == config ||
241 kGray_8_as_Lum_GrPixelConfig == config ||
242 kGray_8_as_Red_GrPixelConfig == config) {
243 return GrBackendFormat::MakeMock(config);
244 }
245 break;
246 case kRGBA_F16_SkColorType:
247 if (kRGBA_half_GrPixelConfig == config) {
248 return GrBackendFormat::MakeMock(config);
249 }
250 break;
Robert Phillipsfc711a22018-02-13 17:03:00 -0500251 }
252 break;
253 default:
254 return GrBackendFormat(); // return an invalid format
255 }
256
257 return GrBackendFormat(); // return an invalid format
258}
259
260
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500261class SurfaceParameters {
262public:
Robert Phillipse8fabb22018-02-04 14:33:21 -0500263 static const int kNumParams = 9;
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500264 static const int kSampleCount = 5;
Robert Phillipse8fabb22018-02-04 14:33:21 -0500265 static const int kMipMipCount = 8;
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500266
Robert Phillipsbe77a022018-04-03 17:17:05 -0400267 SurfaceParameters(const GrCaps* caps)
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500268 : fWidth(64)
269 , fHeight(64)
270 , fOrigin(kTopLeft_GrSurfaceOrigin)
271 , fColorType(kRGBA_8888_SkColorType)
Robert Phillipsbe77a022018-04-03 17:17:05 -0400272 , fConfig(caps->srgbSupport() ? kSRGBA_8888_GrPixelConfig : kRGBA_8888_GrPixelConfig)
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500273 , fColorSpace(SkColorSpace::MakeSRGB())
Brian Salomonbdecacf2018-02-02 20:32:49 -0500274 , fSampleCount(1)
Robert Phillipse8fabb22018-02-04 14:33:21 -0500275 , fSurfaceProps(0x0, kUnknown_SkPixelGeometry)
276 , fShouldCreateMipMaps(true) {
277 }
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500278
279 int sampleCount() const { return fSampleCount; }
280
Robert Phillipsbe77a022018-04-03 17:17:05 -0400281 void setColorType(SkColorType ct) { fColorType = ct; }
282 void setColorSpace(sk_sp<SkColorSpace> cs) { fColorSpace = std::move(cs); }
283 void setConfig(GrPixelConfig config) { fConfig = config; }
284
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500285 // Modify the SurfaceParameters in just one way
286 void modify(int i) {
287 switch (i) {
288 case 0:
289 fWidth = 63;
290 break;
291 case 1:
292 fHeight = 63;
293 break;
294 case 2:
295 fOrigin = kBottomLeft_GrSurfaceOrigin;
296 break;
297 case 3:
Robert Phillipsc1267c62018-04-04 11:12:39 -0400298 // The color type and config need to be changed together.
299 // The original SRGB color space no longer makes sense for F16
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500300 fColorType = kRGBA_F16_SkColorType;
Robert Phillipsbe77a022018-04-03 17:17:05 -0400301 fConfig = kRGBA_half_GrPixelConfig;
302 fColorSpace = SkColorSpace::MakeSRGBLinear();
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500303 break;
304 case 4:
Robert Phillipsc1267c62018-04-04 11:12:39 -0400305 // This just needs to be a colorSpace different from that returned by MakeSRGB()
306 // but still be considered SRGB. In this case we just change the gamut.
307 fColorSpace = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
308 SkColorSpace::kAdobeRGB_Gamut);
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500309 break;
310 case kSampleCount:
311 fSampleCount = 4;
312 break;
313 case 6:
314 fSurfaceProps = SkSurfaceProps(0x0, kRGB_H_SkPixelGeometry);
315 break;
316 case 7:
317 fSurfaceProps = SkSurfaceProps(SkSurfaceProps::kUseDeviceIndependentFonts_Flag,
318 kUnknown_SkPixelGeometry);
319 break;
Robert Phillipse8fabb22018-02-04 14:33:21 -0500320 case 8:
321 fShouldCreateMipMaps = false;
322 break;
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500323 }
324 }
325
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400326 SkSurfaceCharacterization createCharacterization(GrContext* context) const {
Robert Phillipsfc711a22018-02-13 17:03:00 -0500327 int maxResourceCount;
328 size_t maxResourceBytes;
329 context->getResourceCacheLimits(&maxResourceCount, &maxResourceBytes);
330
331 // Note that Ganesh doesn't make use of the SkImageInfo's alphaType
332 SkImageInfo ii = SkImageInfo::Make(fWidth, fHeight, fColorType,
333 kPremul_SkAlphaType, fColorSpace);
334
Robert Phillipsbe77a022018-04-03 17:17:05 -0400335 GrBackendFormat backendFormat = create_backend_format(context, fColorType,
336 fColorSpace.get(), fConfig);
337 if (!backendFormat.isValid()) {
338 return SkSurfaceCharacterization();
339 }
Robert Phillipsfc711a22018-02-13 17:03:00 -0500340
341 SkSurfaceCharacterization c = context->threadSafeProxy()->createCharacterization(
342 maxResourceBytes, ii, backendFormat, fSampleCount,
343 fOrigin, fSurfaceProps, fShouldCreateMipMaps);
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400344 return c;
345 }
346
347 // Create a DDL whose characterization captures the current settings
348 std::unique_ptr<SkDeferredDisplayList> createDDL(GrContext* context) const {
349 SkSurfaceCharacterization c = this->createCharacterization(context);
Robert Phillipsfc711a22018-02-13 17:03:00 -0500350 SkAssertResult(c.isValid());
Robert Phillipse8fabb22018-02-04 14:33:21 -0500351
352 SkDeferredDisplayListRecorder r(c);
353 SkCanvas* canvas = r.getCanvas();
354 if (!canvas) {
355 return nullptr;
356 }
357
358 canvas->drawRect(SkRect::MakeXYWH(10, 10, 10, 10), SkPaint());
359 return r.detach();
360 }
361
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500362 // Create the surface with the current set of parameters
Robert Phillipsbe77a022018-04-03 17:17:05 -0400363 sk_sp<SkSurface> make(GrContext* context, GrBackendTexture* backend,
364 bool nonTextureable) const {
Robert Phillipse8fabb22018-02-04 14:33:21 -0500365 GrGpu* gpu = context->contextPriv().getGpu();
366
Robert Phillipsbe77a022018-04-03 17:17:05 -0400367 GrMipMapped mipmapped = nonTextureable
368 ? GrMipMapped::kNo
369 : GrMipMapped(fShouldCreateMipMaps);
Robert Phillipse8fabb22018-02-04 14:33:21 -0500370
371 *backend = gpu->createTestingOnlyBackendTexture(nullptr, fWidth, fHeight,
Robert Phillipsbe77a022018-04-03 17:17:05 -0400372 fConfig, true, mipmapped);
Robert Phillipse8fabb22018-02-04 14:33:21 -0500373 if (!backend->isValid() || !gpu->isTestingOnlyBackendTexture(*backend)) {
374 return nullptr;
375 }
376
Robert Phillipsbe77a022018-04-03 17:17:05 -0400377 sk_sp<SkSurface> surface;
378 if (nonTextureable) {
379 // Create a surface w/ the current parameters but make it non-textureable
380 surface = SkSurface::MakeFromBackendTextureAsRenderTarget(
381 context, *backend, fOrigin, fSampleCount, fColorType,
382 fColorSpace, &fSurfaceProps);
383 } else {
384 surface = SkSurface::MakeFromBackendTexture(
385 context, *backend, fOrigin, fSampleCount, fColorType,
386 fColorSpace, &fSurfaceProps);
387 }
Robert Phillipse8fabb22018-02-04 14:33:21 -0500388
389 if (!surface) {
Brian Salomon26102cb2018-03-09 09:33:19 -0500390 gpu->deleteTestingOnlyBackendTexture(*backend);
Robert Phillipse8fabb22018-02-04 14:33:21 -0500391 return nullptr;
392 }
393
394 return surface;
395 }
396
Brian Salomon26102cb2018-03-09 09:33:19 -0500397 void cleanUpBackEnd(GrContext* context, const GrBackendTexture& backend) const {
Robert Phillipse8fabb22018-02-04 14:33:21 -0500398 GrGpu* gpu = context->contextPriv().getGpu();
399
400 gpu->deleteTestingOnlyBackendTexture(backend);
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500401 }
402
403private:
404 int fWidth;
405 int fHeight;
406 GrSurfaceOrigin fOrigin;
407 SkColorType fColorType;
Robert Phillipsbe77a022018-04-03 17:17:05 -0400408 GrPixelConfig fConfig;
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500409 sk_sp<SkColorSpace> fColorSpace;
410 int fSampleCount;
411 SkSurfaceProps fSurfaceProps;
Robert Phillipse8fabb22018-02-04 14:33:21 -0500412 bool fShouldCreateMipMaps;
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500413};
414
Robert Phillipsc1267c62018-04-04 11:12:39 -0400415// Test out operator== && operator!=
416DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLOperatorEqTest, reporter, ctxInfo) {
417 GrContext* context = ctxInfo.grContext();
418
419 for (int i = 0; i < SurfaceParameters::kNumParams; ++i) {
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400420 SurfaceParameters params1(context->contextPriv().caps());
Robert Phillipsc1267c62018-04-04 11:12:39 -0400421 params1.modify(i);
422
423 SkSurfaceCharacterization char1 = params1.createCharacterization(context);
424 if (!char1.isValid()) {
425 continue; // can happen on some platforms (ChromeOS)
426 }
427
428 for (int j = 0; j < SurfaceParameters::kNumParams; ++j) {
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400429 SurfaceParameters params2(context->contextPriv().caps());
Robert Phillipsc1267c62018-04-04 11:12:39 -0400430 params2.modify(j);
431
432 SkSurfaceCharacterization char2 = params2.createCharacterization(context);
433 if (!char2.isValid()) {
434 continue; // can happen on some platforms (ChromeOS)
435 }
436
437 if (i == j) {
438 REPORTER_ASSERT(reporter, char1 == char2);
439 } else {
440 REPORTER_ASSERT(reporter, char1 != char2);
441 }
442
443 }
444 }
445
446 {
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400447 SurfaceParameters params(context->contextPriv().caps());
Robert Phillipsc1267c62018-04-04 11:12:39 -0400448
449 SkSurfaceCharacterization valid = params.createCharacterization(context);
450 SkASSERT(valid.isValid());
451
452 SkSurfaceCharacterization inval1, inval2;
453 SkASSERT(!inval1.isValid() && !inval2.isValid());
454
455 REPORTER_ASSERT(reporter, inval1 != inval2);
456 REPORTER_ASSERT(reporter, valid != inval1);
457 REPORTER_ASSERT(reporter, inval1 != valid);
458 }
459}
460
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400461////////////////////////////////////////////////////////////////////////////////
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500462// This tests SkSurfaceCharacterization/SkSurface compatibility
Robert Phillipsbe77a022018-04-03 17:17:05 -0400463DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLSurfaceCharacterizationTest, reporter, ctxInfo) {
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500464 GrContext* context = ctxInfo.grContext();
Robert Phillipsbe77a022018-04-03 17:17:05 -0400465 GrGpu* gpu = context->contextPriv().getGpu();
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500466
Robert Phillips9e441ee2018-02-01 15:14:55 -0500467 // Create a bitmap that we can readback into
468 SkImageInfo imageInfo = SkImageInfo::Make(64, 64, kRGBA_8888_SkColorType,
469 kPremul_SkAlphaType);
470 SkBitmap bitmap;
471 bitmap.allocPixels(imageInfo);
472
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500473 std::unique_ptr<SkDeferredDisplayList> ddl;
474
475 // First, create a DDL using the stock SkSurface parameters
476 {
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400477 SurfaceParameters params(context->contextPriv().caps());
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500478
Robert Phillipse8fabb22018-02-04 14:33:21 -0500479 ddl = params.createDDL(context);
Robert Phillipsfc711a22018-02-13 17:03:00 -0500480 SkAssertResult(ddl);
Robert Phillipse8fabb22018-02-04 14:33:21 -0500481
482 // The DDL should draw into an SkSurface created with the same parameters
Robert Phillipsbe77a022018-04-03 17:17:05 -0400483 GrBackendTexture backend;
484 sk_sp<SkSurface> s = params.make(context, &backend, false);
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500485 if (!s) {
486 return;
487 }
488
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500489 REPORTER_ASSERT(reporter, s->draw(ddl.get()));
Robert Phillips9e441ee2018-02-01 15:14:55 -0500490 s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
Robert Phillipsbe77a022018-04-03 17:17:05 -0400491 context->flush();
492 gpu->testingOnly_flushGpuAndSync();
493 s = nullptr;
494 params.cleanUpBackEnd(context, backend);
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500495 }
496
497 // Then, alter each parameter in turn and check that the DDL & surface are incompatible
498 for (int i = 0; i < SurfaceParameters::kNumParams; ++i) {
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400499 SurfaceParameters params(context->contextPriv().caps());
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500500 params.modify(i);
501
Robert Phillipsbe77a022018-04-03 17:17:05 -0400502 GrBackendTexture backend;
503 sk_sp<SkSurface> s = params.make(context, &backend, false);
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500504 if (!s) {
505 continue;
506 }
507
508 if (SurfaceParameters::kSampleCount == i) {
509 SkSurface_Gpu* gpuSurf = static_cast<SkSurface_Gpu*>(s.get());
510
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400511 int supportedSampleCount = context->contextPriv().caps()->getRenderTargetSampleCount(
512 params.sampleCount(),
513 gpuSurf->getDevice()
514 ->accessRenderTargetContext()
515 ->asRenderTargetProxy()
516 ->config());
Brian Salomonbdecacf2018-02-02 20:32:49 -0500517 if (1 == supportedSampleCount) {
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500518 // If changing the sample count won't result in a different
519 // surface characterization, skip this step
Robert Phillipsbe77a022018-04-03 17:17:05 -0400520 s = nullptr;
521 params.cleanUpBackEnd(context, backend);
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500522 continue;
523 }
524 }
525
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400526 if (SurfaceParameters::kMipMipCount == i &&
527 !context->contextPriv().caps()->mipMapSupport()) {
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400528 // If changing the mipmap setting won't result in a different surface characterization,
529 // skip this step
Robert Phillipsbe77a022018-04-03 17:17:05 -0400530 s = nullptr;
531 params.cleanUpBackEnd(context, backend);
Robert Phillipse8fabb22018-02-04 14:33:21 -0500532 continue;
533 }
534
535 REPORTER_ASSERT(reporter, !s->draw(ddl.get()),
536 "DDLSurfaceCharacterizationTest failed on parameter: %d\n", i);
Robert Phillipsbe77a022018-04-03 17:17:05 -0400537
538 context->flush();
539 gpu->testingOnly_flushGpuAndSync();
540 s = nullptr;
541 params.cleanUpBackEnd(context, backend);
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500542 }
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500543
544 // Next test the compatibility of resource cache parameters
545 {
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400546 const SurfaceParameters params(context->contextPriv().caps());
Robert Phillipsbe77a022018-04-03 17:17:05 -0400547 GrBackendTexture backend;
548
549 sk_sp<SkSurface> s = params.make(context, &backend, false);
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500550
551 int maxResourceCount;
552 size_t maxResourceBytes;
553 context->getResourceCacheLimits(&maxResourceCount, &maxResourceBytes);
554
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500555 context->setResourceCacheLimits(maxResourceCount, maxResourceBytes/2);
556 REPORTER_ASSERT(reporter, !s->draw(ddl.get()));
557
Robert Phillips9e441ee2018-02-01 15:14:55 -0500558 // DDL TODO: once proxies/ops can be de-instantiated we can re-enable these tests.
559 // For now, DDLs are drawn once.
560#if 0
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500561 // resource limits >= those at characterization time are accepted
562 context->setResourceCacheLimits(2*maxResourceCount, maxResourceBytes);
563 REPORTER_ASSERT(reporter, s->draw(ddl.get()));
Robert Phillips9e441ee2018-02-01 15:14:55 -0500564 s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500565
566 context->setResourceCacheLimits(maxResourceCount, 2*maxResourceBytes);
567 REPORTER_ASSERT(reporter, s->draw(ddl.get()));
Robert Phillips9e441ee2018-02-01 15:14:55 -0500568 s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500569
570 context->setResourceCacheLimits(maxResourceCount, maxResourceBytes);
571 REPORTER_ASSERT(reporter, s->draw(ddl.get()));
Robert Phillips9e441ee2018-02-01 15:14:55 -0500572 s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
573#endif
Robert Phillipsbe77a022018-04-03 17:17:05 -0400574
575 context->flush();
576 gpu->testingOnly_flushGpuAndSync();
577 s = nullptr;
578 params.cleanUpBackEnd(context, backend);
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500579 }
580
Robert Phillipse8fabb22018-02-04 14:33:21 -0500581 // Test that the textureability of the DDL characterization can block a DDL draw
582 {
583 GrBackendTexture backend;
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400584 const SurfaceParameters params(context->contextPriv().caps());
Robert Phillipsbe77a022018-04-03 17:17:05 -0400585 sk_sp<SkSurface> s = params.make(context, &backend, true);
Robert Phillipse8fabb22018-02-04 14:33:21 -0500586 if (s) {
587 REPORTER_ASSERT(reporter, !s->draw(ddl.get()));
588
Robert Phillipsbe77a022018-04-03 17:17:05 -0400589 context->flush();
590 gpu->testingOnly_flushGpuAndSync();
Robert Phillipse8fabb22018-02-04 14:33:21 -0500591 s = nullptr;
Brian Salomon26102cb2018-03-09 09:33:19 -0500592 params.cleanUpBackEnd(context, backend);
Robert Phillipse8fabb22018-02-04 14:33:21 -0500593 }
594 }
595
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500596 // Make sure non-GPU-backed surfaces fail characterization
597 {
598 SkImageInfo ii = SkImageInfo::MakeN32(64, 64, kOpaque_SkAlphaType);
599
600 sk_sp<SkSurface> rasterSurface = SkSurface::MakeRaster(ii);
601 SkSurfaceCharacterization c;
602 REPORTER_ASSERT(reporter, !rasterSurface->characterize(&c));
603 }
Robert Phillips94458ee2018-03-06 13:41:51 -0500604
605 // Exercise the createResized method
606 {
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400607 SurfaceParameters params(context->contextPriv().caps());
Robert Phillipsbe77a022018-04-03 17:17:05 -0400608 GrBackendTexture backend;
Robert Phillips94458ee2018-03-06 13:41:51 -0500609
Robert Phillipsbe77a022018-04-03 17:17:05 -0400610 sk_sp<SkSurface> s = params.make(context, &backend, false);
Robert Phillips94458ee2018-03-06 13:41:51 -0500611 if (!s) {
612 return;
613 }
614
615 SkSurfaceCharacterization char0;
616 SkAssertResult(s->characterize(&char0));
617
618 // Too small
619 SkSurfaceCharacterization char1 = char0.createResized(-1, -1);
620 REPORTER_ASSERT(reporter, !char1.isValid());
621
622 // Too large
623 SkSurfaceCharacterization char2 = char0.createResized(1000000, 32);
624 REPORTER_ASSERT(reporter, !char2.isValid());
625
626 // Just right
627 SkSurfaceCharacterization char3 = char0.createResized(32, 32);
628 REPORTER_ASSERT(reporter, char3.isValid());
629 REPORTER_ASSERT(reporter, 32 == char3.width());
630 REPORTER_ASSERT(reporter, 32 == char3.height());
Robert Phillipsbe77a022018-04-03 17:17:05 -0400631
632 s = nullptr;
633 params.cleanUpBackEnd(context, backend);
Robert Phillips94458ee2018-03-06 13:41:51 -0500634 }
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500635}
636
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400637////////////////////////////////////////////////////////////////////////////////
638// This tests the SkSurface::MakeRenderTarget variant that takes an SkSurfaceCharacterization.
639// In particular, the SkSurface and the SkSurfaceCharacterization should always be compatible.
Robert Phillipsbe77a022018-04-03 17:17:05 -0400640DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLMakeRenderTargetTest, reporter, ctxInfo) {
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400641 GrContext* context = ctxInfo.grContext();
642
643 for (int i = 0; i < SurfaceParameters::kNumParams; ++i) {
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400644 SurfaceParameters params(context->contextPriv().caps());
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400645 params.modify(i);
646
647 SkSurfaceCharacterization c = params.createCharacterization(context);
Robert Phillipsbe77a022018-04-03 17:17:05 -0400648 GrBackendTexture backend;
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400649
Robert Phillipsbe77a022018-04-03 17:17:05 -0400650 if (!c.isValid()) {
651 sk_sp<SkSurface> tmp = params.make(context, &backend, false);
652
653 // If we couldn't characterize the surface we shouldn't be able to create it either
654 REPORTER_ASSERT(reporter, !tmp);
655 if (tmp) {
656 tmp = nullptr;
657 params.cleanUpBackEnd(context, backend);
658 }
659 continue;
660 }
661
662 sk_sp<SkSurface> s = params.make(context, &backend, false);
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400663 if (!s) {
664 REPORTER_ASSERT(reporter, !c.isValid());
665 continue;
666 }
667
668 REPORTER_ASSERT(reporter, c.isValid());
669
670 s = SkSurface::MakeRenderTarget(context, c, SkBudgeted::kYes);
671 REPORTER_ASSERT(reporter, s);
672
673 SkSurface_Gpu* g = static_cast<SkSurface_Gpu*>(s.get());
674 REPORTER_ASSERT(reporter, g->isCompatible(c));
Robert Phillipsbe77a022018-04-03 17:17:05 -0400675
676 s = nullptr;
677 params.cleanUpBackEnd(context, backend);
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400678 }
679}
680
681////////////////////////////////////////////////////////////////////////////////
Greg Danielf2336e42018-01-23 16:38:14 -0500682static constexpr int kSize = 8;
683
684struct TextureReleaseChecker {
685 TextureReleaseChecker() : fReleaseCount(0) {}
686 int fReleaseCount;
687 static void Release(void* self) {
688 static_cast<TextureReleaseChecker*>(self)->fReleaseCount++;
689 }
690};
691
692enum class DDLStage { kMakeImage, kDrawImage, kDetach, kDrawDDL };
693
694// This tests the ability to create and use wrapped textures in a DDL world
695DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLWrapBackendTest, reporter, ctxInfo) {
696 GrContext* context = ctxInfo.grContext();
697 GrGpu* gpu = context->contextPriv().getGpu();
Brian Salomonf7778972018-03-08 10:13:17 -0500698 GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(
699 nullptr, kSize, kSize, kRGBA_8888_GrPixelConfig, false, GrMipMapped::kNo);
700 if (!backendTex.isValid()) {
701 return;
Greg Danielf2336e42018-01-23 16:38:14 -0500702 }
Brian Salomonf7778972018-03-08 10:13:17 -0500703
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400704 SurfaceParameters params(context->contextPriv().caps());
Robert Phillipsbe77a022018-04-03 17:17:05 -0400705 GrBackendTexture backend;
Brian Salomonf7778972018-03-08 10:13:17 -0500706
Robert Phillipsbe77a022018-04-03 17:17:05 -0400707 sk_sp<SkSurface> s = params.make(context, &backend, false);
Brian Salomonf7778972018-03-08 10:13:17 -0500708 if (!s) {
Brian Salomon26102cb2018-03-09 09:33:19 -0500709 gpu->deleteTestingOnlyBackendTexture(backendTex);
Brian Salomonf7778972018-03-08 10:13:17 -0500710 return;
711 }
712
713 SkSurfaceCharacterization c;
714 SkAssertResult(s->characterize(&c));
715
716 std::unique_ptr<SkDeferredDisplayListRecorder> recorder(new SkDeferredDisplayListRecorder(c));
717
718 SkCanvas* canvas = recorder->getCanvas();
719 if (!canvas) {
Robert Phillipsbe77a022018-04-03 17:17:05 -0400720 s = nullptr;
721 params.cleanUpBackEnd(context, backend);
Brian Salomon26102cb2018-03-09 09:33:19 -0500722 gpu->deleteTestingOnlyBackendTexture(backendTex);
Brian Salomonf7778972018-03-08 10:13:17 -0500723 return;
724 }
725
726 GrContext* deferredContext = canvas->getGrContext();
727 if (!deferredContext) {
Robert Phillipsbe77a022018-04-03 17:17:05 -0400728 s = nullptr;
729 params.cleanUpBackEnd(context, backend);
Brian Salomon26102cb2018-03-09 09:33:19 -0500730 gpu->deleteTestingOnlyBackendTexture(backendTex);
Brian Salomonf7778972018-03-08 10:13:17 -0500731 return;
732 }
733
734 // Wrapped Backend Textures are not supported in DDL
735 sk_sp<SkImage> image =
736 SkImage::MakeFromAdoptedTexture(deferredContext, backendTex, kTopLeft_GrSurfaceOrigin,
737 kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr);
738 REPORTER_ASSERT(reporter, !image);
739
740 TextureReleaseChecker releaseChecker;
741 image = SkImage::MakeFromTexture(deferredContext, backendTex, kTopLeft_GrSurfaceOrigin,
742 kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr,
743 TextureReleaseChecker::Release, &releaseChecker);
744 REPORTER_ASSERT(reporter, !image);
745
Brian Salomon26102cb2018-03-09 09:33:19 -0500746 gpu->deleteTestingOnlyBackendTexture(backendTex);
Robert Phillipsbe77a022018-04-03 17:17:05 -0400747
748 s = nullptr;
749 params.cleanUpBackEnd(context, backend);
Greg Danielf2336e42018-01-23 16:38:14 -0500750}
751
Robert Phillips6ceaafa2018-03-15 16:53:06 -0400752static void dummy_fulfill_proc(void*, GrBackendTexture*) { SkASSERT(0); }
753static void dummy_release_proc(void*) { SkASSERT(0); }
Robert Phillipsabf7b762018-03-21 12:13:37 -0400754static void dummy_done_proc(void*) { }
Robert Phillips6ceaafa2018-03-15 16:53:06 -0400755
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400756////////////////////////////////////////////////////////////////////////////////
Robert Phillips6ceaafa2018-03-15 16:53:06 -0400757// Test out the behavior of an invalid DDLRecorder
758DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLInvalidRecorder, reporter, ctxInfo) {
759 GrContext* context = ctxInfo.grContext();
760
761 {
762 SkImageInfo ii = SkImageInfo::MakeN32Premul(32, 32);
763 sk_sp<SkSurface> s = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, ii);
764
765 SkSurfaceCharacterization characterization;
766 SkAssertResult(s->characterize(&characterization));
767
768 // never calling getCanvas means the backing surface is never allocated
769 SkDeferredDisplayListRecorder recorder(characterization);
770 }
771
772 {
773 SkSurfaceCharacterization invalid;
774
775 SkDeferredDisplayListRecorder recorder(invalid);
776
777 const SkSurfaceCharacterization c = recorder.characterization();
778 REPORTER_ASSERT(reporter, !c.isValid());
779 REPORTER_ASSERT(reporter, !recorder.getCanvas());
780 REPORTER_ASSERT(reporter, !recorder.detach());
781
Robert Phillipsbe77a022018-04-03 17:17:05 -0400782 GrBackendFormat format = create_backend_format(context, kRGBA_8888_SkColorType,
783 nullptr, kRGBA_8888_GrPixelConfig);
Robert Phillips6ceaafa2018-03-15 16:53:06 -0400784 sk_sp<SkImage> image = recorder.makePromiseTexture(format, 32, 32, GrMipMapped::kNo,
785 kTopLeft_GrSurfaceOrigin,
786 kRGBA_8888_SkColorType,
787 kPremul_SkAlphaType, nullptr,
788 dummy_fulfill_proc,
789 dummy_release_proc,
Greg Daniel7278d682018-03-16 14:57:21 -0400790 dummy_done_proc,
Robert Phillips6ceaafa2018-03-15 16:53:06 -0400791 nullptr);
792 REPORTER_ASSERT(reporter, !image);
793 }
794
795}
796
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400797////////////////////////////////////////////////////////////////////////////////
Robert Phillips874b5352018-03-16 08:48:24 -0400798// Ensure that flushing while DDL recording doesn't cause a crash
799DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLFlushWhileRecording, reporter, ctxInfo) {
800 GrContext* context = ctxInfo.grContext();
801
802 SkImageInfo ii = SkImageInfo::MakeN32Premul(32, 32);
803 sk_sp<SkSurface> s = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, ii);
804
805 SkSurfaceCharacterization characterization;
806 SkAssertResult(s->characterize(&characterization));
807
808 SkDeferredDisplayListRecorder recorder(characterization);
809 SkCanvas* canvas = recorder.getCanvas();
810
811 canvas->flush();
812 canvas->getGrContext()->flush();
813}
Greg Danielf2336e42018-01-23 16:38:14 -0500814
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400815////////////////////////////////////////////////////////////////////////////////
Robert Phillipsabf7b762018-03-21 12:13:37 -0400816// Check that the texture-specific flags (i.e., for external & rectangle textures) work
817// for promise images. As such, this is a GL-only test.
818DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(DDLTextureFlagsTest, reporter, ctxInfo) {
819 GrContext* context = ctxInfo.grContext();
820
821 SkImageInfo ii = SkImageInfo::MakeN32Premul(32, 32);
822 sk_sp<SkSurface> s = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, ii);
823
824 SkSurfaceCharacterization characterization;
825 SkAssertResult(s->characterize(&characterization));
826
827 SkDeferredDisplayListRecorder recorder(characterization);
828
829 for (GrGLenum target : { GR_GL_TEXTURE_EXTERNAL, GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_2D } ) {
830 GrBackendFormat format = GrBackendFormat::MakeGL(GR_GL_RGBA8, target);
831
Greg Daniele3204862018-04-16 11:24:10 -0400832 sk_sp<SkImage> image = recorder.makePromiseTexture(format, 32, 32, GrMipMapped::kYes,
Robert Phillipsabf7b762018-03-21 12:13:37 -0400833 kTopLeft_GrSurfaceOrigin,
834 kRGBA_8888_SkColorType,
835 kPremul_SkAlphaType, nullptr,
836 dummy_fulfill_proc,
837 dummy_release_proc,
838 dummy_done_proc,
839 nullptr);
840 REPORTER_ASSERT(reporter, image);
841
842 GrTextureProxy* backingProxy = ((SkImage_Gpu*) image.get())->peekProxy();
843
844 if (GR_GL_TEXTURE_2D == target) {
845 REPORTER_ASSERT(reporter, !backingProxy->texPriv().doesNotSupportMipMaps());
846 REPORTER_ASSERT(reporter, !backingProxy->texPriv().isClampOnly());
847 } else {
848 REPORTER_ASSERT(reporter, backingProxy->texPriv().doesNotSupportMipMaps());
849 REPORTER_ASSERT(reporter, backingProxy->texPriv().isClampOnly());
850 }
851 }
Robert Phillipsbe77a022018-04-03 17:17:05 -0400852}
853
854////////////////////////////////////////////////////////////////////////////////
855
856// Exhaustively test colorType and pixelConfig compatibility.
857DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(DDLCompatibilityTest, reporter, ctxInfo) {
858 GrContext* context = ctxInfo.grContext();
859
860 for (int ct = 0; ct <= kLastEnum_SkColorType; ++ct) {
861 SkColorType colorType = static_cast<SkColorType>(ct);
862
863 for (int config = 0; config < kGrPixelConfigCnt; ++config) {
864 GrPixelConfig pixelConfig = static_cast<GrPixelConfig>(config);
865
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400866 SurfaceParameters params(context->contextPriv().caps());
Robert Phillipsbe77a022018-04-03 17:17:05 -0400867 params.setColorType(colorType);
868 params.setConfig(pixelConfig);
869
870 params.setColorSpace(nullptr);
871 if (kSRGBA_8888_GrPixelConfig == pixelConfig ||
872 kSBGRA_8888_GrPixelConfig == pixelConfig) {
873 params.setColorSpace(SkColorSpace::MakeSRGB());
874 }
875
876 SkSurfaceCharacterization c = params.createCharacterization(context);
877 GrBackendTexture backend;
878
879 if (!c.isValid()) {
880 // TODO: this would be cool to enable but there is, currently, too much crossover
881 // allowed internally (e.g., kAlpha_8_SkColorType/kGray_8_as_Red_GrPixelConfig
882 // is permitted on GL).
883#if 0
884 sk_sp<SkSurface> tmp = params.make(context, &backend, false);
885
886 // If we couldn't characterize the surface we shouldn't be able to create it either
887 REPORTER_ASSERT(reporter, !tmp);
888 if (tmp) {
889 tmp = nullptr;
890 params.cleanUpBackEnd(context, backend);
891 }
892#endif
893 continue;
894 }
895
896 sk_sp<SkSurface> s = params.make(context, &backend, false);
897 REPORTER_ASSERT(reporter, s);
898 if (!s) {
899 s = nullptr;
900 params.cleanUpBackEnd(context, backend);
901 continue;
902 }
903
904 SkSurface_Gpu* gpuSurface = static_cast<SkSurface_Gpu*>(s.get());
905 REPORTER_ASSERT(reporter, gpuSurface->isCompatible(c));
906
907 s = nullptr;
908 params.cleanUpBackEnd(context, backend);
909
910 s = SkSurface::MakeRenderTarget(context, c, SkBudgeted::kYes);
911 REPORTER_ASSERT(reporter, s);
912 if (!s) {
913 continue;
914 }
915
916 gpuSurface = static_cast<SkSurface_Gpu*>(s.get());
917 REPORTER_ASSERT(reporter, gpuSurface->isCompatible(c));
918 }
919 }
Robert Phillipsabf7b762018-03-21 12:13:37 -0400920
921}
Robert Phillipsbe77a022018-04-03 17:17:05 -0400922
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500923#endif