blob: c4a7efd67fa6318bc0fbbd5a2a346face66ef5cd [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
Greg Danielf2336e42018-01-23 16:38:14 -050010#include "GrBackendSurface.h"
Ben Wagnerd90cd3b2018-05-22 10:48:08 -040011#include "GrCaps.h"
12#include "GrContext.h"
13#include "GrContextFactory.h"
Brian Salomonc7fe0f72018-05-11 10:14:21 -040014#include "GrContextPriv.h"
Greg Danielf2336e42018-01-23 16:38:14 -050015#include "GrGpu.h"
Ben Wagnerd90cd3b2018-05-22 10:48:08 -040016#include "GrRenderTargetContext.h"
17#include "GrRenderTargetProxy.h"
18#include "GrTextureProxy.h"
Robert Phillipsabf7b762018-03-21 12:13:37 -040019#include "GrTextureProxyPriv.h"
Ben Wagnerd90cd3b2018-05-22 10:48:08 -040020#include "GrTypes.h"
21#include "GrTypesPriv.h"
22#include "SkBitmap.h"
Robert Phillips7ffbcf92017-12-04 12:52:46 -050023#include "SkCanvas.h"
Ben Wagnerd90cd3b2018-05-22 10:48:08 -040024#include "SkColorSpace.h"
25#include "SkDeferredDisplayList.h"
Robert Phillips7ffbcf92017-12-04 12:52:46 -050026#include "SkDeferredDisplayListRecorder.h"
27#include "SkGpuDevice.h"
Ben Wagnerd90cd3b2018-05-22 10:48:08 -040028#include "SkImage.h"
29#include "SkImageInfo.h"
Robert Phillipsabf7b762018-03-21 12:13:37 -040030#include "SkImage_Gpu.h"
Ben Wagnerd90cd3b2018-05-22 10:48:08 -040031#include "SkPaint.h"
32#include "SkRect.h"
33#include "SkRefCnt.h"
Robert Phillips7ffbcf92017-12-04 12:52:46 -050034#include "SkSurface.h"
Robert Phillips7ffbcf92017-12-04 12:52:46 -050035#include "SkSurfaceCharacterization.h"
36#include "SkSurfaceProps.h"
Brian Salomonc7fe0f72018-05-11 10:14:21 -040037#include "SkSurface_Gpu.h"
Robert Phillips7ffbcf92017-12-04 12:52:46 -050038#include "Test.h"
Robert Phillipsbe77a022018-04-03 17:17:05 -040039#include "gl/GrGLCaps.h"
Brian Salomonc7fe0f72018-05-11 10:14:21 -040040#include "gl/GrGLDefines.h"
Ben Wagnerd90cd3b2018-05-22 10:48:08 -040041#include "gl/GrGLTypes.h"
42
Robert Phillipsfc711a22018-02-13 17:03:00 -050043#ifdef SK_VULKAN
44#include "vk/GrVkDefines.h"
45#endif
46
Ben Wagnerd90cd3b2018-05-22 10:48:08 -040047#include <initializer_list>
48#include <memory>
49#include <utility>
50
Robert Phillipsbe77a022018-04-03 17:17:05 -040051// Try to create a backend format from the provided colorType and config. Return an invalid
52// backend format if the combination is infeasible.
53static GrBackendFormat create_backend_format(GrContext* context,
Brian Osman37f99882018-08-09 10:26:57 -040054 SkColorType ct,
Robert Phillipsbe77a022018-04-03 17:17:05 -040055 GrPixelConfig config) {
Brian Salomonc7fe0f72018-05-11 10:14:21 -040056 const GrCaps* caps = context->contextPriv().caps();
Robert Phillipsfc711a22018-02-13 17:03:00 -050057
58 switch (context->contextPriv().getBackend()) {
Robert Phillipsbe77a022018-04-03 17:17:05 -040059 case kOpenGL_GrBackend: {
Brian Salomonc7fe0f72018-05-11 10:14:21 -040060 const GrGLCaps* glCaps = static_cast<const GrGLCaps*>(caps);
Robert Phillipsbe77a022018-04-03 17:17:05 -040061 GrGLStandard standard = glCaps->standard();
62
63 switch (ct) {
64 case kUnknown_SkColorType:
65 return GrBackendFormat();
66 case kAlpha_8_SkColorType:
67 if (kAlpha_8_as_Alpha_GrPixelConfig == config) {
68 return GrBackendFormat::MakeGL(GR_GL_ALPHA8, GR_GL_TEXTURE_2D);
69 } else if (kAlpha_8_GrPixelConfig == config ||
70 kAlpha_8_as_Red_GrPixelConfig == config) {
71 return GrBackendFormat::MakeGL(GR_GL_R8, GR_GL_TEXTURE_2D);
72 }
73 break;
74 case kRGB_565_SkColorType:
75 if (kRGB_565_GrPixelConfig == config) {
76 return GrBackendFormat::MakeGL(GR_GL_RGB565, GR_GL_TEXTURE_2D);
77 }
78 break;
79 case kARGB_4444_SkColorType:
80 if (kRGBA_4444_GrPixelConfig == config) {
81 return GrBackendFormat::MakeGL(GR_GL_RGBA4, GR_GL_TEXTURE_2D);
82 }
83 break;
84 case kRGBA_8888_SkColorType:
85 if (kRGBA_8888_GrPixelConfig == config) {
Brian Osman37f99882018-08-09 10:26:57 -040086 return GrBackendFormat::MakeGL(GR_GL_RGBA8, GR_GL_TEXTURE_2D);
Robert Phillipsbe77a022018-04-03 17:17:05 -040087 }
88 break;
89 case kRGB_888x_SkColorType:
90 if (kRGB_888_GrPixelConfig == config) {
91 return GrBackendFormat::MakeGL(GR_GL_RGB8, GR_GL_TEXTURE_2D);
92 }
93 break;
94 case kBGRA_8888_SkColorType:
95 if (kBGRA_8888_GrPixelConfig == config) {
96 if (kGL_GrGLStandard == standard) {
97 return GrBackendFormat::MakeGL(GR_GL_RGBA8, GR_GL_TEXTURE_2D);
98 } else if (kGLES_GrGLStandard == standard) {
99 return GrBackendFormat::MakeGL(GR_GL_BGRA8, GR_GL_TEXTURE_2D);
100 }
Robert Phillipsbe77a022018-04-03 17:17:05 -0400101 }
102 break;
103 case kRGBA_1010102_SkColorType:
104 if (kRGBA_1010102_GrPixelConfig == config) {
105 return GrBackendFormat::MakeGL(GR_GL_RGB10_A2, GR_GL_TEXTURE_2D);
106 }
107 break;
108 case kRGB_101010x_SkColorType:
109 return GrBackendFormat();
110 case kGray_8_SkColorType:
111 if (kGray_8_as_Lum_GrPixelConfig == config) {
112 return GrBackendFormat::MakeGL(GR_GL_LUMINANCE8, GR_GL_TEXTURE_2D);
113 } else if (kGray_8_GrPixelConfig == config ||
114 kGray_8_as_Red_GrPixelConfig == config) {
115 return GrBackendFormat::MakeGL(GR_GL_R8, GR_GL_TEXTURE_2D);
116 }
117 break;
118 case kRGBA_F16_SkColorType:
119 if (kRGBA_half_GrPixelConfig == config) {
120 return GrBackendFormat::MakeGL(GR_GL_RGBA16F, GR_GL_TEXTURE_2D);
121 }
122 break;
Mike Klein37854712018-06-26 11:43:06 -0400123 case kRGBA_F32_SkColorType:
124 return GrBackendFormat();
Robert Phillipsfc711a22018-02-13 17:03:00 -0500125 }
Robert Phillipsbe77a022018-04-03 17:17:05 -0400126 }
127 break;
Robert Phillipsfc711a22018-02-13 17:03:00 -0500128#ifdef SK_VULKAN
129 case kVulkan_GrBackend:
Robert Phillipsbe77a022018-04-03 17:17:05 -0400130 switch (ct) {
131 case kUnknown_SkColorType:
132 return GrBackendFormat();
133 case kAlpha_8_SkColorType:
134 // TODO: what about kAlpha_8_GrPixelConfig and kAlpha_8_as_Alpha_GrPixelConfig
135 if (kAlpha_8_as_Red_GrPixelConfig == config) {
136 return GrBackendFormat::MakeVk(VK_FORMAT_R8_UNORM);
137 }
138 break;
139 case kRGB_565_SkColorType:
140 if (kRGB_565_GrPixelConfig == config) {
141 return GrBackendFormat::MakeVk(VK_FORMAT_R5G6B5_UNORM_PACK16);
142 }
143 break;
144 case kARGB_4444_SkColorType:
145 if (kRGBA_4444_GrPixelConfig == config) {
146 return GrBackendFormat::MakeVk(VK_FORMAT_B4G4R4A4_UNORM_PACK16);
147 }
148 break;
149 case kRGBA_8888_SkColorType:
150 if (kRGBA_8888_GrPixelConfig == config) {
Brian Osman37f99882018-08-09 10:26:57 -0400151 return GrBackendFormat::MakeVk(VK_FORMAT_R8G8B8A8_UNORM);
Robert Phillipsbe77a022018-04-03 17:17:05 -0400152 }
153 break;
154 case kRGB_888x_SkColorType:
155 if (kRGB_888_GrPixelConfig == config) {
156 return GrBackendFormat::MakeVk(VK_FORMAT_R8G8B8_UNORM);
157 }
158 break;
159 case kBGRA_8888_SkColorType:
160 if (kBGRA_8888_GrPixelConfig == config) {
161 return GrBackendFormat::MakeVk(VK_FORMAT_B8G8R8A8_UNORM);
Robert Phillipsbe77a022018-04-03 17:17:05 -0400162 }
163 break;
164 case kRGBA_1010102_SkColorType:
165 if (kRGBA_1010102_GrPixelConfig == config) {
166 return GrBackendFormat::MakeVk(VK_FORMAT_A2B10G10R10_UNORM_PACK32);
167 }
168 break;
169 case kRGB_101010x_SkColorType:
170 return GrBackendFormat();
171 case kGray_8_SkColorType:
172 // TODO: what about kAlpha_8_GrPixelConfig and kGray_8_as_Lum_GrPixelConfig?
173 if (kGray_8_as_Red_GrPixelConfig == config) {
174 return GrBackendFormat::MakeVk(VK_FORMAT_R8_UNORM);
175 }
176 break;
177 case kRGBA_F16_SkColorType:
178 if (kRGBA_half_GrPixelConfig == config) {
179 return GrBackendFormat::MakeVk(VK_FORMAT_R16G16B16A16_SFLOAT);
180 }
181 break;
Mike Klein37854712018-06-26 11:43:06 -0400182 case kRGBA_F32_SkColorType:
183 return GrBackendFormat();
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) {
Brian Osman37f99882018-08-09 10:26:57 -0400210 return GrBackendFormat::MakeMock(config);
Robert Phillipsbe77a022018-04-03 17:17:05 -0400211 }
212 break;
213 case kRGB_888x_SkColorType:
214 if (kRGB_888_GrPixelConfig == config) {
215 return GrBackendFormat::MakeMock(config);
216 }
217 break;
218 case kBGRA_8888_SkColorType:
219 if (kBGRA_8888_GrPixelConfig == config) {
220 return GrBackendFormat::MakeMock(config);
Robert Phillipsbe77a022018-04-03 17:17:05 -0400221 }
222 break;
223 case kRGBA_1010102_SkColorType:
224 if (kRGBA_1010102_GrPixelConfig == config) {
225 return GrBackendFormat::MakeMock(config);
226 }
227 break;
228 case kRGB_101010x_SkColorType:
229 return GrBackendFormat();
230 case kGray_8_SkColorType:
231 if (kGray_8_GrPixelConfig == config ||
232 kGray_8_as_Lum_GrPixelConfig == config ||
233 kGray_8_as_Red_GrPixelConfig == config) {
234 return GrBackendFormat::MakeMock(config);
235 }
236 break;
237 case kRGBA_F16_SkColorType:
238 if (kRGBA_half_GrPixelConfig == config) {
239 return GrBackendFormat::MakeMock(config);
240 }
241 break;
Mike Klein37854712018-06-26 11:43:06 -0400242 case kRGBA_F32_SkColorType:
243 return GrBackendFormat();
Robert Phillipsfc711a22018-02-13 17:03:00 -0500244 }
245 break;
246 default:
247 return GrBackendFormat(); // return an invalid format
248 }
249
250 return GrBackendFormat(); // return an invalid format
251}
252
253
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500254class SurfaceParameters {
255public:
Robert Phillipse8fabb22018-02-04 14:33:21 -0500256 static const int kNumParams = 9;
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500257 static const int kSampleCount = 5;
Robert Phillipse8fabb22018-02-04 14:33:21 -0500258 static const int kMipMipCount = 8;
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500259
Robert Phillipsbe77a022018-04-03 17:17:05 -0400260 SurfaceParameters(const GrCaps* caps)
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500261 : fWidth(64)
262 , fHeight(64)
263 , fOrigin(kTopLeft_GrSurfaceOrigin)
264 , fColorType(kRGBA_8888_SkColorType)
Brian Osman37f99882018-08-09 10:26:57 -0400265 , fConfig(kRGBA_8888_GrPixelConfig)
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500266 , fColorSpace(SkColorSpace::MakeSRGB())
Brian Salomonbdecacf2018-02-02 20:32:49 -0500267 , fSampleCount(1)
Robert Phillipse8fabb22018-02-04 14:33:21 -0500268 , fSurfaceProps(0x0, kUnknown_SkPixelGeometry)
269 , fShouldCreateMipMaps(true) {
270 }
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500271
272 int sampleCount() const { return fSampleCount; }
273
Robert Phillipsbe77a022018-04-03 17:17:05 -0400274 void setColorType(SkColorType ct) { fColorType = ct; }
275 void setColorSpace(sk_sp<SkColorSpace> cs) { fColorSpace = std::move(cs); }
276 void setConfig(GrPixelConfig config) { fConfig = config; }
277
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500278 // Modify the SurfaceParameters in just one way
279 void modify(int i) {
280 switch (i) {
281 case 0:
282 fWidth = 63;
283 break;
284 case 1:
285 fHeight = 63;
286 break;
287 case 2:
288 fOrigin = kBottomLeft_GrSurfaceOrigin;
289 break;
290 case 3:
Robert Phillipsc1267c62018-04-04 11:12:39 -0400291 // The color type and config need to be changed together.
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500292 fColorType = kRGBA_F16_SkColorType;
Robert Phillipsbe77a022018-04-03 17:17:05 -0400293 fConfig = kRGBA_half_GrPixelConfig;
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500294 break;
295 case 4:
Brian Osman37f99882018-08-09 10:26:57 -0400296 // This just needs to be a colorSpace different from that returned by MakeSRGB().
297 // In this case we just change the gamut.
Robert Phillipsc1267c62018-04-04 11:12:39 -0400298 fColorSpace = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
299 SkColorSpace::kAdobeRGB_Gamut);
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500300 break;
301 case kSampleCount:
302 fSampleCount = 4;
303 break;
304 case 6:
305 fSurfaceProps = SkSurfaceProps(0x0, kRGB_H_SkPixelGeometry);
306 break;
307 case 7:
308 fSurfaceProps = SkSurfaceProps(SkSurfaceProps::kUseDeviceIndependentFonts_Flag,
309 kUnknown_SkPixelGeometry);
310 break;
Robert Phillipse8fabb22018-02-04 14:33:21 -0500311 case 8:
312 fShouldCreateMipMaps = false;
313 break;
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500314 }
315 }
316
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400317 SkSurfaceCharacterization createCharacterization(GrContext* context) const {
Robert Phillipsfc711a22018-02-13 17:03:00 -0500318 int maxResourceCount;
319 size_t maxResourceBytes;
320 context->getResourceCacheLimits(&maxResourceCount, &maxResourceBytes);
321
322 // Note that Ganesh doesn't make use of the SkImageInfo's alphaType
323 SkImageInfo ii = SkImageInfo::Make(fWidth, fHeight, fColorType,
324 kPremul_SkAlphaType, fColorSpace);
325
Brian Osman37f99882018-08-09 10:26:57 -0400326 GrBackendFormat backendFormat = create_backend_format(context, fColorType, fConfig);
Robert Phillipsbe77a022018-04-03 17:17:05 -0400327 if (!backendFormat.isValid()) {
328 return SkSurfaceCharacterization();
329 }
Robert Phillipsfc711a22018-02-13 17:03:00 -0500330
331 SkSurfaceCharacterization c = context->threadSafeProxy()->createCharacterization(
332 maxResourceBytes, ii, backendFormat, fSampleCount,
333 fOrigin, fSurfaceProps, fShouldCreateMipMaps);
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400334 return c;
335 }
336
337 // Create a DDL whose characterization captures the current settings
338 std::unique_ptr<SkDeferredDisplayList> createDDL(GrContext* context) const {
339 SkSurfaceCharacterization c = this->createCharacterization(context);
Robert Phillipsfc711a22018-02-13 17:03:00 -0500340 SkAssertResult(c.isValid());
Robert Phillipse8fabb22018-02-04 14:33:21 -0500341
342 SkDeferredDisplayListRecorder r(c);
343 SkCanvas* canvas = r.getCanvas();
344 if (!canvas) {
345 return nullptr;
346 }
347
348 canvas->drawRect(SkRect::MakeXYWH(10, 10, 10, 10), SkPaint());
349 return r.detach();
350 }
351
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500352 // Create the surface with the current set of parameters
Robert Phillipsbe77a022018-04-03 17:17:05 -0400353 sk_sp<SkSurface> make(GrContext* context, GrBackendTexture* backend,
354 bool nonTextureable) const {
Robert Phillipse8fabb22018-02-04 14:33:21 -0500355 GrGpu* gpu = context->contextPriv().getGpu();
356
Robert Phillipsbe77a022018-04-03 17:17:05 -0400357 GrMipMapped mipmapped = nonTextureable
358 ? GrMipMapped::kNo
359 : GrMipMapped(fShouldCreateMipMaps);
Robert Phillipse8fabb22018-02-04 14:33:21 -0500360
361 *backend = gpu->createTestingOnlyBackendTexture(nullptr, fWidth, fHeight,
Robert Phillips646f6372018-09-25 09:31:10 -0400362 fColorType, true, mipmapped);
Robert Phillipse8fabb22018-02-04 14:33:21 -0500363 if (!backend->isValid() || !gpu->isTestingOnlyBackendTexture(*backend)) {
364 return nullptr;
365 }
366
Robert Phillipsbe77a022018-04-03 17:17:05 -0400367 sk_sp<SkSurface> surface;
368 if (nonTextureable) {
369 // Create a surface w/ the current parameters but make it non-textureable
370 surface = SkSurface::MakeFromBackendTextureAsRenderTarget(
371 context, *backend, fOrigin, fSampleCount, fColorType,
372 fColorSpace, &fSurfaceProps);
373 } else {
374 surface = SkSurface::MakeFromBackendTexture(
375 context, *backend, fOrigin, fSampleCount, fColorType,
376 fColorSpace, &fSurfaceProps);
377 }
Robert Phillipse8fabb22018-02-04 14:33:21 -0500378
379 if (!surface) {
Brian Salomon26102cb2018-03-09 09:33:19 -0500380 gpu->deleteTestingOnlyBackendTexture(*backend);
Robert Phillipse8fabb22018-02-04 14:33:21 -0500381 return nullptr;
382 }
383
384 return surface;
385 }
386
Brian Salomon26102cb2018-03-09 09:33:19 -0500387 void cleanUpBackEnd(GrContext* context, const GrBackendTexture& backend) const {
Robert Phillipse8fabb22018-02-04 14:33:21 -0500388 GrGpu* gpu = context->contextPriv().getGpu();
389
390 gpu->deleteTestingOnlyBackendTexture(backend);
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500391 }
392
393private:
394 int fWidth;
395 int fHeight;
396 GrSurfaceOrigin fOrigin;
397 SkColorType fColorType;
Robert Phillipsbe77a022018-04-03 17:17:05 -0400398 GrPixelConfig fConfig;
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500399 sk_sp<SkColorSpace> fColorSpace;
400 int fSampleCount;
401 SkSurfaceProps fSurfaceProps;
Robert Phillipse8fabb22018-02-04 14:33:21 -0500402 bool fShouldCreateMipMaps;
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500403};
404
Robert Phillipsc1267c62018-04-04 11:12:39 -0400405// Test out operator== && operator!=
406DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLOperatorEqTest, reporter, ctxInfo) {
407 GrContext* context = ctxInfo.grContext();
408
409 for (int i = 0; i < SurfaceParameters::kNumParams; ++i) {
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400410 SurfaceParameters params1(context->contextPriv().caps());
Robert Phillipsc1267c62018-04-04 11:12:39 -0400411 params1.modify(i);
412
413 SkSurfaceCharacterization char1 = params1.createCharacterization(context);
414 if (!char1.isValid()) {
415 continue; // can happen on some platforms (ChromeOS)
416 }
417
418 for (int j = 0; j < SurfaceParameters::kNumParams; ++j) {
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400419 SurfaceParameters params2(context->contextPriv().caps());
Robert Phillipsc1267c62018-04-04 11:12:39 -0400420 params2.modify(j);
421
422 SkSurfaceCharacterization char2 = params2.createCharacterization(context);
423 if (!char2.isValid()) {
424 continue; // can happen on some platforms (ChromeOS)
425 }
426
427 if (i == j) {
428 REPORTER_ASSERT(reporter, char1 == char2);
429 } else {
430 REPORTER_ASSERT(reporter, char1 != char2);
431 }
432
433 }
434 }
435
436 {
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400437 SurfaceParameters params(context->contextPriv().caps());
Robert Phillipsc1267c62018-04-04 11:12:39 -0400438
439 SkSurfaceCharacterization valid = params.createCharacterization(context);
440 SkASSERT(valid.isValid());
441
442 SkSurfaceCharacterization inval1, inval2;
443 SkASSERT(!inval1.isValid() && !inval2.isValid());
444
445 REPORTER_ASSERT(reporter, inval1 != inval2);
446 REPORTER_ASSERT(reporter, valid != inval1);
447 REPORTER_ASSERT(reporter, inval1 != valid);
448 }
449}
450
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400451////////////////////////////////////////////////////////////////////////////////
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500452// This tests SkSurfaceCharacterization/SkSurface compatibility
Robert Phillipsbe77a022018-04-03 17:17:05 -0400453DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLSurfaceCharacterizationTest, reporter, ctxInfo) {
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500454 GrContext* context = ctxInfo.grContext();
Robert Phillipsbe77a022018-04-03 17:17:05 -0400455 GrGpu* gpu = context->contextPriv().getGpu();
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500456
Robert Phillips9e441ee2018-02-01 15:14:55 -0500457 // Create a bitmap that we can readback into
458 SkImageInfo imageInfo = SkImageInfo::Make(64, 64, kRGBA_8888_SkColorType,
459 kPremul_SkAlphaType);
460 SkBitmap bitmap;
461 bitmap.allocPixels(imageInfo);
462
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500463 std::unique_ptr<SkDeferredDisplayList> ddl;
464
465 // First, create a DDL using the stock SkSurface parameters
466 {
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400467 SurfaceParameters params(context->contextPriv().caps());
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500468
Robert Phillipse8fabb22018-02-04 14:33:21 -0500469 ddl = params.createDDL(context);
Robert Phillipsfc711a22018-02-13 17:03:00 -0500470 SkAssertResult(ddl);
Robert Phillipse8fabb22018-02-04 14:33:21 -0500471
472 // The DDL should draw into an SkSurface created with the same parameters
Robert Phillipsbe77a022018-04-03 17:17:05 -0400473 GrBackendTexture backend;
474 sk_sp<SkSurface> s = params.make(context, &backend, false);
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500475 if (!s) {
476 return;
477 }
478
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500479 REPORTER_ASSERT(reporter, s->draw(ddl.get()));
Robert Phillips9e441ee2018-02-01 15:14:55 -0500480 s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
Robert Phillipsbe77a022018-04-03 17:17:05 -0400481 context->flush();
482 gpu->testingOnly_flushGpuAndSync();
483 s = nullptr;
484 params.cleanUpBackEnd(context, backend);
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500485 }
486
487 // Then, alter each parameter in turn and check that the DDL & surface are incompatible
488 for (int i = 0; i < SurfaceParameters::kNumParams; ++i) {
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400489 SurfaceParameters params(context->contextPriv().caps());
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500490 params.modify(i);
491
Robert Phillipsbe77a022018-04-03 17:17:05 -0400492 GrBackendTexture backend;
493 sk_sp<SkSurface> s = params.make(context, &backend, false);
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500494 if (!s) {
495 continue;
496 }
497
498 if (SurfaceParameters::kSampleCount == i) {
499 SkSurface_Gpu* gpuSurf = static_cast<SkSurface_Gpu*>(s.get());
500
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400501 int supportedSampleCount = context->contextPriv().caps()->getRenderTargetSampleCount(
502 params.sampleCount(),
503 gpuSurf->getDevice()
504 ->accessRenderTargetContext()
505 ->asRenderTargetProxy()
506 ->config());
Brian Salomonbdecacf2018-02-02 20:32:49 -0500507 if (1 == supportedSampleCount) {
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500508 // If changing the sample count won't result in a different
509 // surface characterization, skip this step
Robert Phillipsbe77a022018-04-03 17:17:05 -0400510 s = nullptr;
511 params.cleanUpBackEnd(context, backend);
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500512 continue;
513 }
514 }
515
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400516 if (SurfaceParameters::kMipMipCount == i &&
517 !context->contextPriv().caps()->mipMapSupport()) {
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400518 // If changing the mipmap setting won't result in a different surface characterization,
519 // skip this step
Robert Phillipsbe77a022018-04-03 17:17:05 -0400520 s = nullptr;
521 params.cleanUpBackEnd(context, backend);
Robert Phillipse8fabb22018-02-04 14:33:21 -0500522 continue;
523 }
524
525 REPORTER_ASSERT(reporter, !s->draw(ddl.get()),
526 "DDLSurfaceCharacterizationTest failed on parameter: %d\n", i);
Robert Phillipsbe77a022018-04-03 17:17:05 -0400527
528 context->flush();
529 gpu->testingOnly_flushGpuAndSync();
530 s = nullptr;
531 params.cleanUpBackEnd(context, backend);
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500532 }
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500533
534 // Next test the compatibility of resource cache parameters
535 {
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400536 const SurfaceParameters params(context->contextPriv().caps());
Robert Phillipsbe77a022018-04-03 17:17:05 -0400537 GrBackendTexture backend;
538
539 sk_sp<SkSurface> s = params.make(context, &backend, false);
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500540
541 int maxResourceCount;
542 size_t maxResourceBytes;
543 context->getResourceCacheLimits(&maxResourceCount, &maxResourceBytes);
544
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500545 context->setResourceCacheLimits(maxResourceCount, maxResourceBytes/2);
546 REPORTER_ASSERT(reporter, !s->draw(ddl.get()));
547
Robert Phillips9e441ee2018-02-01 15:14:55 -0500548 // DDL TODO: once proxies/ops can be de-instantiated we can re-enable these tests.
549 // For now, DDLs are drawn once.
550#if 0
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500551 // resource limits >= those at characterization time are accepted
552 context->setResourceCacheLimits(2*maxResourceCount, maxResourceBytes);
553 REPORTER_ASSERT(reporter, s->draw(ddl.get()));
Robert Phillips9e441ee2018-02-01 15:14:55 -0500554 s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500555
556 context->setResourceCacheLimits(maxResourceCount, 2*maxResourceBytes);
557 REPORTER_ASSERT(reporter, s->draw(ddl.get()));
Robert Phillips9e441ee2018-02-01 15:14:55 -0500558 s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500559
560 context->setResourceCacheLimits(maxResourceCount, maxResourceBytes);
561 REPORTER_ASSERT(reporter, s->draw(ddl.get()));
Robert Phillips9e441ee2018-02-01 15:14:55 -0500562 s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
563#endif
Robert Phillipsbe77a022018-04-03 17:17:05 -0400564
565 context->flush();
566 gpu->testingOnly_flushGpuAndSync();
567 s = nullptr;
568 params.cleanUpBackEnd(context, backend);
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500569 }
570
Robert Phillipse8fabb22018-02-04 14:33:21 -0500571 // Test that the textureability of the DDL characterization can block a DDL draw
572 {
573 GrBackendTexture backend;
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400574 const SurfaceParameters params(context->contextPriv().caps());
Robert Phillipsbe77a022018-04-03 17:17:05 -0400575 sk_sp<SkSurface> s = params.make(context, &backend, true);
Robert Phillipse8fabb22018-02-04 14:33:21 -0500576 if (s) {
577 REPORTER_ASSERT(reporter, !s->draw(ddl.get()));
578
Robert Phillipsbe77a022018-04-03 17:17:05 -0400579 context->flush();
580 gpu->testingOnly_flushGpuAndSync();
Robert Phillipse8fabb22018-02-04 14:33:21 -0500581 s = nullptr;
Brian Salomon26102cb2018-03-09 09:33:19 -0500582 params.cleanUpBackEnd(context, backend);
Robert Phillipse8fabb22018-02-04 14:33:21 -0500583 }
584 }
585
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500586 // Make sure non-GPU-backed surfaces fail characterization
587 {
588 SkImageInfo ii = SkImageInfo::MakeN32(64, 64, kOpaque_SkAlphaType);
589
590 sk_sp<SkSurface> rasterSurface = SkSurface::MakeRaster(ii);
591 SkSurfaceCharacterization c;
592 REPORTER_ASSERT(reporter, !rasterSurface->characterize(&c));
593 }
Robert Phillips94458ee2018-03-06 13:41:51 -0500594
595 // Exercise the createResized method
596 {
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400597 SurfaceParameters params(context->contextPriv().caps());
Robert Phillipsbe77a022018-04-03 17:17:05 -0400598 GrBackendTexture backend;
Robert Phillips94458ee2018-03-06 13:41:51 -0500599
Robert Phillipsbe77a022018-04-03 17:17:05 -0400600 sk_sp<SkSurface> s = params.make(context, &backend, false);
Robert Phillips94458ee2018-03-06 13:41:51 -0500601 if (!s) {
602 return;
603 }
604
605 SkSurfaceCharacterization char0;
606 SkAssertResult(s->characterize(&char0));
607
608 // Too small
609 SkSurfaceCharacterization char1 = char0.createResized(-1, -1);
610 REPORTER_ASSERT(reporter, !char1.isValid());
611
612 // Too large
613 SkSurfaceCharacterization char2 = char0.createResized(1000000, 32);
614 REPORTER_ASSERT(reporter, !char2.isValid());
615
616 // Just right
617 SkSurfaceCharacterization char3 = char0.createResized(32, 32);
618 REPORTER_ASSERT(reporter, char3.isValid());
619 REPORTER_ASSERT(reporter, 32 == char3.width());
620 REPORTER_ASSERT(reporter, 32 == char3.height());
Robert Phillipsbe77a022018-04-03 17:17:05 -0400621
622 s = nullptr;
623 params.cleanUpBackEnd(context, backend);
Robert Phillips94458ee2018-03-06 13:41:51 -0500624 }
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500625}
626
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400627////////////////////////////////////////////////////////////////////////////////
628// This tests the SkSurface::MakeRenderTarget variant that takes an SkSurfaceCharacterization.
629// In particular, the SkSurface and the SkSurfaceCharacterization should always be compatible.
Robert Phillipsbe77a022018-04-03 17:17:05 -0400630DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLMakeRenderTargetTest, reporter, ctxInfo) {
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400631 GrContext* context = ctxInfo.grContext();
632
633 for (int i = 0; i < SurfaceParameters::kNumParams; ++i) {
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400634 SurfaceParameters params(context->contextPriv().caps());
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400635 params.modify(i);
636
637 SkSurfaceCharacterization c = params.createCharacterization(context);
Robert Phillipsbe77a022018-04-03 17:17:05 -0400638 GrBackendTexture backend;
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400639
Robert Phillipsbe77a022018-04-03 17:17:05 -0400640 if (!c.isValid()) {
641 sk_sp<SkSurface> tmp = params.make(context, &backend, false);
642
643 // If we couldn't characterize the surface we shouldn't be able to create it either
644 REPORTER_ASSERT(reporter, !tmp);
645 if (tmp) {
646 tmp = nullptr;
647 params.cleanUpBackEnd(context, backend);
648 }
649 continue;
650 }
651
652 sk_sp<SkSurface> s = params.make(context, &backend, false);
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400653 if (!s) {
654 REPORTER_ASSERT(reporter, !c.isValid());
655 continue;
656 }
657
658 REPORTER_ASSERT(reporter, c.isValid());
659
660 s = SkSurface::MakeRenderTarget(context, c, SkBudgeted::kYes);
661 REPORTER_ASSERT(reporter, s);
662
663 SkSurface_Gpu* g = static_cast<SkSurface_Gpu*>(s.get());
664 REPORTER_ASSERT(reporter, g->isCompatible(c));
Robert Phillipsbe77a022018-04-03 17:17:05 -0400665
666 s = nullptr;
667 params.cleanUpBackEnd(context, backend);
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400668 }
669}
670
671////////////////////////////////////////////////////////////////////////////////
Greg Danielf2336e42018-01-23 16:38:14 -0500672static constexpr int kSize = 8;
673
674struct TextureReleaseChecker {
675 TextureReleaseChecker() : fReleaseCount(0) {}
676 int fReleaseCount;
677 static void Release(void* self) {
678 static_cast<TextureReleaseChecker*>(self)->fReleaseCount++;
679 }
680};
681
682enum class DDLStage { kMakeImage, kDrawImage, kDetach, kDrawDDL };
683
684// This tests the ability to create and use wrapped textures in a DDL world
685DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLWrapBackendTest, reporter, ctxInfo) {
686 GrContext* context = ctxInfo.grContext();
687 GrGpu* gpu = context->contextPriv().getGpu();
Brian Salomonf7778972018-03-08 10:13:17 -0500688 GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(
Robert Phillips646f6372018-09-25 09:31:10 -0400689 nullptr, kSize, kSize, GrColorType::kRGBA_8888, false, GrMipMapped::kNo);
Brian Salomonf7778972018-03-08 10:13:17 -0500690 if (!backendTex.isValid()) {
691 return;
Greg Danielf2336e42018-01-23 16:38:14 -0500692 }
Brian Salomonf7778972018-03-08 10:13:17 -0500693
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400694 SurfaceParameters params(context->contextPriv().caps());
Robert Phillipsbe77a022018-04-03 17:17:05 -0400695 GrBackendTexture backend;
Brian Salomonf7778972018-03-08 10:13:17 -0500696
Robert Phillipsbe77a022018-04-03 17:17:05 -0400697 sk_sp<SkSurface> s = params.make(context, &backend, false);
Brian Salomonf7778972018-03-08 10:13:17 -0500698 if (!s) {
Brian Salomon26102cb2018-03-09 09:33:19 -0500699 gpu->deleteTestingOnlyBackendTexture(backendTex);
Brian Salomonf7778972018-03-08 10:13:17 -0500700 return;
701 }
702
703 SkSurfaceCharacterization c;
704 SkAssertResult(s->characterize(&c));
705
706 std::unique_ptr<SkDeferredDisplayListRecorder> recorder(new SkDeferredDisplayListRecorder(c));
707
708 SkCanvas* canvas = recorder->getCanvas();
709 if (!canvas) {
Robert Phillipsbe77a022018-04-03 17:17:05 -0400710 s = nullptr;
711 params.cleanUpBackEnd(context, backend);
Brian Salomon26102cb2018-03-09 09:33:19 -0500712 gpu->deleteTestingOnlyBackendTexture(backendTex);
Brian Salomonf7778972018-03-08 10:13:17 -0500713 return;
714 }
715
716 GrContext* deferredContext = canvas->getGrContext();
717 if (!deferredContext) {
Robert Phillipsbe77a022018-04-03 17:17:05 -0400718 s = nullptr;
719 params.cleanUpBackEnd(context, backend);
Brian Salomon26102cb2018-03-09 09:33:19 -0500720 gpu->deleteTestingOnlyBackendTexture(backendTex);
Brian Salomonf7778972018-03-08 10:13:17 -0500721 return;
722 }
723
724 // Wrapped Backend Textures are not supported in DDL
725 sk_sp<SkImage> image =
726 SkImage::MakeFromAdoptedTexture(deferredContext, backendTex, kTopLeft_GrSurfaceOrigin,
727 kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr);
728 REPORTER_ASSERT(reporter, !image);
729
730 TextureReleaseChecker releaseChecker;
731 image = SkImage::MakeFromTexture(deferredContext, backendTex, kTopLeft_GrSurfaceOrigin,
732 kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr,
733 TextureReleaseChecker::Release, &releaseChecker);
734 REPORTER_ASSERT(reporter, !image);
735
Brian Salomon26102cb2018-03-09 09:33:19 -0500736 gpu->deleteTestingOnlyBackendTexture(backendTex);
Robert Phillipsbe77a022018-04-03 17:17:05 -0400737
738 s = nullptr;
739 params.cleanUpBackEnd(context, backend);
Greg Danielf2336e42018-01-23 16:38:14 -0500740}
741
Robert Phillips6ceaafa2018-03-15 16:53:06 -0400742static void dummy_fulfill_proc(void*, GrBackendTexture*) { SkASSERT(0); }
743static void dummy_release_proc(void*) { SkASSERT(0); }
Robert Phillipsabf7b762018-03-21 12:13:37 -0400744static void dummy_done_proc(void*) { }
Robert Phillips6ceaafa2018-03-15 16:53:06 -0400745
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400746////////////////////////////////////////////////////////////////////////////////
Robert Phillips6ceaafa2018-03-15 16:53:06 -0400747// Test out the behavior of an invalid DDLRecorder
748DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLInvalidRecorder, reporter, ctxInfo) {
749 GrContext* context = ctxInfo.grContext();
750
751 {
752 SkImageInfo ii = SkImageInfo::MakeN32Premul(32, 32);
753 sk_sp<SkSurface> s = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, ii);
754
755 SkSurfaceCharacterization characterization;
756 SkAssertResult(s->characterize(&characterization));
757
758 // never calling getCanvas means the backing surface is never allocated
759 SkDeferredDisplayListRecorder recorder(characterization);
760 }
761
762 {
763 SkSurfaceCharacterization invalid;
764
765 SkDeferredDisplayListRecorder recorder(invalid);
766
767 const SkSurfaceCharacterization c = recorder.characterization();
768 REPORTER_ASSERT(reporter, !c.isValid());
769 REPORTER_ASSERT(reporter, !recorder.getCanvas());
770 REPORTER_ASSERT(reporter, !recorder.detach());
771
Robert Phillipsbe77a022018-04-03 17:17:05 -0400772 GrBackendFormat format = create_backend_format(context, kRGBA_8888_SkColorType,
Brian Osman37f99882018-08-09 10:26:57 -0400773 kRGBA_8888_GrPixelConfig);
Robert Phillips6ceaafa2018-03-15 16:53:06 -0400774 sk_sp<SkImage> image = recorder.makePromiseTexture(format, 32, 32, GrMipMapped::kNo,
775 kTopLeft_GrSurfaceOrigin,
776 kRGBA_8888_SkColorType,
777 kPremul_SkAlphaType, nullptr,
778 dummy_fulfill_proc,
779 dummy_release_proc,
Greg Daniel7278d682018-03-16 14:57:21 -0400780 dummy_done_proc,
Robert Phillips6ceaafa2018-03-15 16:53:06 -0400781 nullptr);
782 REPORTER_ASSERT(reporter, !image);
783 }
784
785}
786
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400787////////////////////////////////////////////////////////////////////////////////
Robert Phillips874b5352018-03-16 08:48:24 -0400788// Ensure that flushing while DDL recording doesn't cause a crash
789DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLFlushWhileRecording, reporter, ctxInfo) {
790 GrContext* context = ctxInfo.grContext();
791
792 SkImageInfo ii = SkImageInfo::MakeN32Premul(32, 32);
793 sk_sp<SkSurface> s = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, ii);
794
795 SkSurfaceCharacterization characterization;
796 SkAssertResult(s->characterize(&characterization));
797
798 SkDeferredDisplayListRecorder recorder(characterization);
799 SkCanvas* canvas = recorder.getCanvas();
800
801 canvas->flush();
802 canvas->getGrContext()->flush();
803}
Greg Danielf2336e42018-01-23 16:38:14 -0500804
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400805////////////////////////////////////////////////////////////////////////////////
Robert Phillipsabf7b762018-03-21 12:13:37 -0400806// Check that the texture-specific flags (i.e., for external & rectangle textures) work
807// for promise images. As such, this is a GL-only test.
808DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(DDLTextureFlagsTest, reporter, ctxInfo) {
809 GrContext* context = ctxInfo.grContext();
810
811 SkImageInfo ii = SkImageInfo::MakeN32Premul(32, 32);
812 sk_sp<SkSurface> s = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, ii);
813
814 SkSurfaceCharacterization characterization;
815 SkAssertResult(s->characterize(&characterization));
816
817 SkDeferredDisplayListRecorder recorder(characterization);
818
819 for (GrGLenum target : { GR_GL_TEXTURE_EXTERNAL, GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_2D } ) {
Greg Daniel09c94002018-06-08 22:11:51 +0000820 for (auto mipMapped : { GrMipMapped::kNo, GrMipMapped::kYes }) {
821 GrBackendFormat format = GrBackendFormat::MakeGL(GR_GL_RGBA8, target);
Robert Phillipsabf7b762018-03-21 12:13:37 -0400822
Greg Daniel09c94002018-06-08 22:11:51 +0000823 sk_sp<SkImage> image = recorder.makePromiseTexture(format, 32, 32, mipMapped,
824 kTopLeft_GrSurfaceOrigin,
825 kRGBA_8888_SkColorType,
826 kPremul_SkAlphaType, nullptr,
827 dummy_fulfill_proc,
828 dummy_release_proc,
829 dummy_done_proc,
830 nullptr);
831 if (GR_GL_TEXTURE_2D != target && mipMapped == GrMipMapped::kYes) {
832 REPORTER_ASSERT(reporter, !image);
833 continue;
834 }
835 REPORTER_ASSERT(reporter, image);
Robert Phillipsabf7b762018-03-21 12:13:37 -0400836
Greg Daniel09c94002018-06-08 22:11:51 +0000837 GrTextureProxy* backingProxy = ((SkImage_Gpu*) image.get())->peekProxy();
Robert Phillipsabf7b762018-03-21 12:13:37 -0400838
Greg Daniel09c94002018-06-08 22:11:51 +0000839 REPORTER_ASSERT(reporter, backingProxy->mipMapped() == mipMapped);
840 if (GR_GL_TEXTURE_2D == target) {
Brian Salomonfd98c2c2018-07-31 17:25:29 -0400841 REPORTER_ASSERT(reporter, !backingProxy->hasRestrictedSampling());
Greg Daniel09c94002018-06-08 22:11:51 +0000842 } else {
Brian Salomonfd98c2c2018-07-31 17:25:29 -0400843 REPORTER_ASSERT(reporter, backingProxy->hasRestrictedSampling());
Greg Daniel09c94002018-06-08 22:11:51 +0000844 }
Robert Phillipsabf7b762018-03-21 12:13:37 -0400845 }
846 }
Robert Phillipsbe77a022018-04-03 17:17:05 -0400847}
848
849////////////////////////////////////////////////////////////////////////////////
850
Robert Phillips646f6372018-09-25 09:31:10 -0400851// Test colorType and pixelConfig compatibility.
Robert Phillipsbe77a022018-04-03 17:17:05 -0400852DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(DDLCompatibilityTest, reporter, ctxInfo) {
853 GrContext* context = ctxInfo.grContext();
854
855 for (int ct = 0; ct <= kLastEnum_SkColorType; ++ct) {
856 SkColorType colorType = static_cast<SkColorType>(ct);
857
Robert Phillips646f6372018-09-25 09:31:10 -0400858 for (int config = 0; config < kPrivateConfig1_GrPixelConfig; ++config) {
Robert Phillipsbe77a022018-04-03 17:17:05 -0400859 GrPixelConfig pixelConfig = static_cast<GrPixelConfig>(config);
860
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400861 SurfaceParameters params(context->contextPriv().caps());
Robert Phillipsbe77a022018-04-03 17:17:05 -0400862 params.setColorType(colorType);
863 params.setConfig(pixelConfig);
Robert Phillipsbe77a022018-04-03 17:17:05 -0400864 params.setColorSpace(nullptr);
Robert Phillipsbe77a022018-04-03 17:17:05 -0400865
866 SkSurfaceCharacterization c = params.createCharacterization(context);
867 GrBackendTexture backend;
868
869 if (!c.isValid()) {
870 // TODO: this would be cool to enable but there is, currently, too much crossover
871 // allowed internally (e.g., kAlpha_8_SkColorType/kGray_8_as_Red_GrPixelConfig
872 // is permitted on GL).
873#if 0
874 sk_sp<SkSurface> tmp = params.make(context, &backend, false);
875
876 // If we couldn't characterize the surface we shouldn't be able to create it either
877 REPORTER_ASSERT(reporter, !tmp);
878 if (tmp) {
879 tmp = nullptr;
880 params.cleanUpBackEnd(context, backend);
881 }
882#endif
883 continue;
884 }
885
886 sk_sp<SkSurface> s = params.make(context, &backend, false);
887 REPORTER_ASSERT(reporter, s);
888 if (!s) {
889 s = nullptr;
890 params.cleanUpBackEnd(context, backend);
891 continue;
892 }
893
894 SkSurface_Gpu* gpuSurface = static_cast<SkSurface_Gpu*>(s.get());
895 REPORTER_ASSERT(reporter, gpuSurface->isCompatible(c));
896
897 s = nullptr;
898 params.cleanUpBackEnd(context, backend);
899
900 s = SkSurface::MakeRenderTarget(context, c, SkBudgeted::kYes);
901 REPORTER_ASSERT(reporter, s);
902 if (!s) {
903 continue;
904 }
905
906 gpuSurface = static_cast<SkSurface_Gpu*>(s.get());
907 REPORTER_ASSERT(reporter, gpuSurface->isCompatible(c));
908 }
909 }
Robert Phillipsabf7b762018-03-21 12:13:37 -0400910
911}