1 /*
2 * Copyright 2015 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 "src/gpu/ganesh/GrCaps.h"
9
10 #include "include/core/SkColor.h"
11 #include "include/core/SkRect.h"
12 #include "include/core/SkSize.h"
13 #include "include/core/SkTextureCompressionType.h"
14 #include "include/gpu/GpuTypes.h"
15 #include "include/gpu/ganesh/GrBackendSurface.h"
16 #include "include/gpu/ganesh/GrContextOptions.h"
17 #include "include/private/base/SkDebug.h"
18 #include "include/private/gpu/ganesh/GrTypesPriv.h"
19 #include "src/core/SkCompressedDataUtils.h"
20 #include "src/gpu/ganesh/GrBackendUtils.h"
21 #include "src/gpu/ganesh/GrRenderTargetProxy.h"
22 #include "src/gpu/ganesh/GrSurface.h"
23 #include "src/gpu/ganesh/GrSurfaceProxy.h"
24 #include "src/gpu/ganesh/GrWindowRectangles.h"
25
GrCaps(const GrContextOptions & options)26 GrCaps::GrCaps(const GrContextOptions& options) {
27 fNPOTTextureTileSupport = false;
28 fMipmapSupport = false;
29 fAnisoSupport = false;
30 fReuseScratchTextures = true;
31 fReuseScratchBuffers = true;
32 fGpuTracingSupport = false;
33 fOversizedStencilSupport = false;
34 fTextureBarrierSupport = false;
35 fSampleLocationsSupport = false;
36 fDrawInstancedSupport = false;
37 fNativeDrawIndirectSupport = false;
38 fUseClientSideIndirectBuffers = false;
39 fConservativeRasterSupport = false;
40 fWireframeSupport = false;
41 fMSAAResolvesAutomatically = false;
42 fPreferDiscardableMSAAAttachment = false;
43 fUsePrimitiveRestart = false;
44 fPreferClientSideDynamicBuffers = false;
45 fPreferFullscreenClears = false;
46 fTwoSidedStencilRefsAndMasksMustMatch = false;
47 fMustClearUploadedBufferData = false;
48 fShouldInitializeTextures = false;
49 fBuffersAreInitiallyZero = false;
50 fSupportsAHardwareBufferImages = false;
51 fSemaphoreSupport = false;
52 fBackendSemaphoreSupport = false;
53 fFinishedProcAsyncCallbackSupport = false;
54 fCrossContextTextureSupport = false;
55 fHalfFloatVertexAttributeSupport = false;
56 fDynamicStateArrayGeometryProcessorTextureSupport = false;
57 fSupportsProtectedContent = false;
58 fPerformPartialClearsAsDraws = false;
59 fPerformColorClearsAsDraws = false;
60 fAvoidLargeIndexBufferDraws = false;
61 fPerformStencilClearsAsDraws = false;
62 fTransferFromBufferToTextureSupport = false;
63 fTransferFromSurfaceToBufferSupport = false;
64 fTransferFromBufferToBufferSupport = false;
65 fWritePixelsRowBytesSupport = false;
66 fTransferPixelsToRowBytesSupport = false;
67 fReadPixelsRowBytesSupport = false;
68 fShouldCollapseSrcOverToSrcWhenAble = false;
69 fMustSyncGpuDuringAbandon = true;
70 fDisableTessellationPathRenderer = false;
71
72 fBlendEquationSupport = kBasic_BlendEquationSupport;
73 fAdvBlendEqDisableFlags = 0;
74
75 fMapBufferFlags = kNone_MapFlags;
76
77 fMaxVertexAttributes = 0;
78 fMaxRenderTargetSize = 1;
79 fMaxPreferredRenderTargetSize = 1;
80 fMaxTextureSize = 1;
81 fMaxWindowRectangles = 0;
82 fInternalMultisampleCount = 0;
83
84 fSuppressPrints = options.fSuppressPrints;
85 #if defined(GPU_TEST_UTILS)
86 fWireframeMode = options.fWireframeMode;
87 #else
88 fWireframeMode = false;
89 #endif
90 fBufferMapThreshold = options.fBufferMapThreshold;
91 fAvoidStencilBuffers = false;
92 fAvoidWritePixelsFastPath = false;
93 fNativeDrawIndexedIndirectIsBroken = false;
94 fAvoidReorderingRenderTasks = false;
95 fAvoidDithering = false;
96 fAvoidLineDraws = false;
97 fDisablePerspectiveSDFText = false;
98
99 fPreferVRAMUseOverFlushes = true;
100
101 // Default to true, allow older versions of OpenGL to disable explicitly
102 fClampToBorderSupport = true;
103
104 fDriverBugWorkarounds = options.fDriverBugWorkarounds;
105 }
106
finishInitialization(const GrContextOptions & options)107 void GrCaps::finishInitialization(const GrContextOptions& options) {
108 if (!fNativeDrawIndirectSupport) {
109 // We will implement indirect draws with a polyfill, so the commands need to reside in CPU
110 // memory.
111 fUseClientSideIndirectBuffers = true;
112 }
113
114 this->applyOptionsOverrides(options);
115
116 // Our render targets are always created with textures as the color attachment, hence this min:
117 fMaxRenderTargetSize = std::min(fMaxRenderTargetSize, fMaxTextureSize);
118 fMaxPreferredRenderTargetSize = std::min(fMaxPreferredRenderTargetSize, fMaxRenderTargetSize);
119
120 this->initSkCaps(this->shaderCaps());
121 }
122
applyOptionsOverrides(const GrContextOptions & options)123 void GrCaps::applyOptionsOverrides(const GrContextOptions& options) {
124 fShaderCaps->applyOptionsOverrides(options);
125 this->onApplyOptionsOverrides(options);
126 if (options.fDisableDriverCorrectnessWorkarounds) {
127 SkASSERT(!fDisableTessellationPathRenderer);
128 SkASSERT(!fAvoidStencilBuffers);
129 SkASSERT(!fAvoidWritePixelsFastPath);
130 SkASSERT(!fNativeDrawIndexedIndirectIsBroken);
131 SkASSERT(!fAdvBlendEqDisableFlags);
132 SkASSERT(!fPerformColorClearsAsDraws);
133 SkASSERT(!fPerformStencilClearsAsDraws);
134 // Don't check the partial-clear workaround, since that is a backend limitation, not a
135 // driver workaround (it just so happens the fallbacks are the same).
136 }
137 if (GrContextOptions::Enable::kNo == options.fUseDrawInsteadOfClear) {
138 fPerformColorClearsAsDraws = false;
139 fPerformStencilClearsAsDraws = false;
140 } else if (GrContextOptions::Enable::kYes == options.fUseDrawInsteadOfClear) {
141 fPerformColorClearsAsDraws = true;
142 fPerformStencilClearsAsDraws = true;
143 }
144
145 fMaxTextureSize = std::min(fMaxTextureSize, options.fMaxTextureSizeOverride);
146 #if defined(GPU_TEST_UTILS)
147 if (options.fSuppressAdvancedBlendEquations) {
148 fBlendEquationSupport = kBasic_BlendEquationSupport;
149 }
150 if (options.fClearAllTextures) {
151 fShouldInitializeTextures = true;
152 }
153 if (options.fDisallowWriteAndTransferPixelRowBytes) {
154 fWritePixelsRowBytesSupport = false;
155 fTransferPixelsToRowBytesSupport = false;
156 }
157 #endif
158 if (options.fSuppressMipmapSupport) {
159 fMipmapSupport = false;
160 }
161
162 if (fMaxWindowRectangles > GrWindowRectangles::kMaxWindows) {
163 SkDebugf("WARNING: capping window rectangles at %i. HW advertises support for %i.\n",
164 GrWindowRectangles::kMaxWindows, fMaxWindowRectangles);
165 fMaxWindowRectangles = GrWindowRectangles::kMaxWindows;
166 }
167
168 fInternalMultisampleCount = options.fInternalMultisampleCount;
169
170 fAvoidStencilBuffers = options.fAvoidStencilBuffers;
171
172 fDriverBugWorkarounds.applyOverrides(options.fDriverBugWorkarounds);
173
174 if (options.fDisableTessellationPathRenderer) {
175 fDisableTessellationPathRenderer = true;
176 }
177 }
178
179
180 #ifdef SK_ENABLE_DUMP_GPU
181 #include "src/gpu/ganesh/GrTestUtils.h"
182 #include "src/utils/SkJSONWriter.h"
183
map_flags_to_string(uint32_t flags)184 static SkString map_flags_to_string(uint32_t flags) {
185 SkString str;
186 if (GrCaps::kNone_MapFlags == flags) {
187 str = "none";
188 } else {
189 SkASSERT(GrCaps::kCanMap_MapFlag & flags);
190 SkDEBUGCODE(flags &= ~GrCaps::kCanMap_MapFlag);
191 str = "can_map";
192
193 if (GrCaps::kSubset_MapFlag & flags) {
194 str.append(" partial");
195 } else {
196 str.append(" full");
197 }
198 SkDEBUGCODE(flags &= ~GrCaps::kSubset_MapFlag);
199 if (GrCaps::kAsyncRead_MapFlag & flags) {
200 str.append(" async_read");
201 } else {
202 str.append(" sync_read");
203 }
204 SkDEBUGCODE(flags &= ~GrCaps::kAsyncRead_MapFlag);
205 }
206 SkASSERT(0 == flags); // Make sure we handled all the flags.
207 return str;
208 }
209
dumpJSON(SkJSONWriter * writer) const210 void GrCaps::dumpJSON(SkJSONWriter* writer) const {
211 writer->beginObject();
212
213 writer->appendBool("NPOT Texture Tile Support", fNPOTTextureTileSupport);
214 writer->appendBool("MIP Map Support", fMipmapSupport);
215 writer->appendBool("Aniso Support", fAnisoSupport);
216 writer->appendBool("Reuse Scratch Textures", fReuseScratchTextures);
217 writer->appendBool("Reuse Scratch Buffers", fReuseScratchBuffers);
218 writer->appendBool("Gpu Tracing Support", fGpuTracingSupport);
219 writer->appendBool("Oversized Stencil Support", fOversizedStencilSupport);
220 writer->appendBool("Texture Barrier Support", fTextureBarrierSupport);
221 writer->appendBool("Sample Locations Support", fSampleLocationsSupport);
222 writer->appendBool("Draw Instanced Support", fDrawInstancedSupport);
223 writer->appendBool("Native Draw Indirect Support", fNativeDrawIndirectSupport);
224 writer->appendBool("Use client side indirect buffers", fUseClientSideIndirectBuffers);
225 writer->appendBool("Conservative Raster Support", fConservativeRasterSupport);
226 writer->appendBool("Wireframe Support", fWireframeSupport);
227 writer->appendBool("MSAA Resolves Automatically", fMSAAResolvesAutomatically);
228 writer->appendBool("Use primitive restart", fUsePrimitiveRestart);
229 writer->appendBool("Prefer client-side dynamic buffers", fPreferClientSideDynamicBuffers);
230 writer->appendBool("Prefer fullscreen clears (and stencil discard)", fPreferFullscreenClears);
231 writer->appendBool("Two-sided Stencil Refs And Masks Must Match",
232 fTwoSidedStencilRefsAndMasksMustMatch);
233 writer->appendBool("Must clear buffer memory", fMustClearUploadedBufferData);
234 writer->appendBool("Should initialize textures", fShouldInitializeTextures);
235 writer->appendBool("Buffers are initially zero", fBuffersAreInitiallyZero);
236 writer->appendBool("Supports importing AHardwareBuffers", fSupportsAHardwareBufferImages);
237 writer->appendBool("Semaphore support", fSemaphoreSupport);
238 writer->appendBool("Backend Semaphore support", fBackendSemaphoreSupport);
239 writer->appendBool("FinishedProc async callback support", fFinishedProcAsyncCallbackSupport);
240 writer->appendBool("Cross context texture support", fCrossContextTextureSupport);
241 writer->appendBool("Half float vertex attribute support", fHalfFloatVertexAttributeSupport);
242 writer->appendBool("Specify GeometryProcessor textures as a dynamic state array",
243 fDynamicStateArrayGeometryProcessorTextureSupport);
244 writer->appendBool("Supports Protected content", fSupportsProtectedContent);
245 writer->appendBool("Use draws for partial clears", fPerformPartialClearsAsDraws);
246 writer->appendBool("Use draws for color clears", fPerformColorClearsAsDraws);
247 writer->appendBool("Avoid Large IndexBuffer Draws", fAvoidLargeIndexBufferDraws);
248 writer->appendBool("Use draws for stencil clip clears", fPerformStencilClearsAsDraws);
249 writer->appendBool("Supports transfers from buffers to textures",
250 fTransferFromBufferToTextureSupport);
251 writer->appendBool("Supports transfers from textures to buffers",
252 fTransferFromSurfaceToBufferSupport);
253 writer->appendBool("Write pixels row bytes support", fWritePixelsRowBytesSupport);
254 writer->appendBool("Transfer pixels to row bytes support", fTransferPixelsToRowBytesSupport);
255 writer->appendBool("Read pixels row bytes support", fReadPixelsRowBytesSupport);
256 writer->appendBool("Disable TessellationPathRenderer current driver [workaround]",
257 fDisableTessellationPathRenderer);
258 writer->appendBool("Clamp-to-border", fClampToBorderSupport);
259
260 writer->appendBool("Prefer VRAM Use over flushes [workaround]", fPreferVRAMUseOverFlushes);
261 writer->appendBool("Avoid stencil buffers [workaround]", fAvoidStencilBuffers);
262 writer->appendBool("Avoid writePixels fast path [workaround]", fAvoidWritePixelsFastPath);
263 writer->appendBool("Native draw indexed indirect is broken [workaround]",
264 fNativeDrawIndexedIndirectIsBroken);
265 writer->appendBool("Avoid DAG reordering [workaround]", fAvoidReorderingRenderTasks);
266 writer->appendBool("Avoid Dithering [workaround]", fAvoidDithering);
267 writer->appendBool("Disable perspective SDF Text [workaround]", fDisablePerspectiveSDFText);
268
269 if (this->advancedBlendEquationSupport()) {
270 writer->appendHexU32("Advanced Blend Equation Disable Flags", fAdvBlendEqDisableFlags);
271 }
272
273 writer->appendS32("Max Vertex Attributes", fMaxVertexAttributes);
274 writer->appendS32("Max Texture Size", fMaxTextureSize);
275 writer->appendS32("Max Render Target Size", fMaxRenderTargetSize);
276 writer->appendS32("Max Preferred Render Target Size", fMaxPreferredRenderTargetSize);
277 writer->appendS32("Max Window Rectangles", fMaxWindowRectangles);
278 writer->appendS32("Sample Count for Internal MSAA", fInternalMultisampleCount);
279
280 static const char* kBlendEquationSupportNames[] = {
281 "Basic",
282 "Advanced",
283 "Advanced Coherent",
284 };
285 static_assert(0 == kBasic_BlendEquationSupport);
286 static_assert(1 == kAdvanced_BlendEquationSupport);
287 static_assert(2 == kAdvancedCoherent_BlendEquationSupport);
288 static_assert(std::size(kBlendEquationSupportNames) == kLast_BlendEquationSupport + 1);
289
290 writer->appendCString("Blend Equation Support",
291 kBlendEquationSupportNames[fBlendEquationSupport]);
292 writer->appendString("Map Buffer Support", map_flags_to_string(fMapBufferFlags));
293
294 this->onDumpJSON(writer);
295
296 writer->appendName("shaderCaps");
297 this->shaderCaps()->dumpJSON(writer);
298
299 writer->endObject();
300 }
301 #else
dumpJSON(SkJSONWriter * writer) const302 void GrCaps::dumpJSON(SkJSONWriter* writer) const { }
303 #endif
304
surfaceSupportsWritePixels(const GrSurface * surface) const305 bool GrCaps::surfaceSupportsWritePixels(const GrSurface* surface) const {
306 return surface->readOnly() ? false : this->onSurfaceSupportsWritePixels(surface);
307 }
308
canCopySurface(const GrSurfaceProxy * dst,const SkIRect & dstRect,const GrSurfaceProxy * src,const SkIRect & srcRect) const309 bool GrCaps::canCopySurface(const GrSurfaceProxy* dst, const SkIRect& dstRect,
310 const GrSurfaceProxy* src, const SkIRect& srcRect) const {
311 if (dst->readOnly()) {
312 return false;
313 }
314
315 if (dst->backendFormat() != src->backendFormat()) {
316 return false;
317 }
318 // For simplicity, all GrGpu::copySurface() calls can assume that srcRect and dstRect
319 // are already contained within their respective surfaces.
320 if (!SkIRect::MakeSize(dst->dimensions()).contains(dstRect) ||
321 !SkIRect::MakeSize(src->dimensions()).contains(srcRect)) {
322 return false;
323 }
324 return this->onCanCopySurface(dst, dstRect, src, srcRect);
325 }
326
validateSurfaceParams(const SkISize & dimensions,const GrBackendFormat & format,GrRenderable renderable,int renderTargetSampleCnt,skgpu::Mipmapped mipped,GrTextureType textureType) const327 bool GrCaps::validateSurfaceParams(const SkISize& dimensions, const GrBackendFormat& format,
328 GrRenderable renderable, int renderTargetSampleCnt,
329 skgpu::Mipmapped mipped, GrTextureType textureType) const {
330 if (textureType != GrTextureType::kNone) {
331 if (!this->isFormatTexturable(format, textureType)) {
332 return false;
333 }
334 }
335
336 if (skgpu::Mipmapped::kYes == mipped && !this->mipmapSupport()) {
337 return false;
338 }
339
340 if (dimensions.width() < 1 || dimensions.height() < 1) {
341 return false;
342 }
343
344 if (renderable == GrRenderable::kYes) {
345 if (!this->isFormatRenderable(format, renderTargetSampleCnt)) {
346 return false;
347 }
348 int maxRTSize = this->maxRenderTargetSize();
349 if (dimensions.width() > maxRTSize || dimensions.height() > maxRTSize) {
350 return false;
351 }
352 } else {
353 // We currently do not support multisampled textures
354 if (renderTargetSampleCnt != 1) {
355 return false;
356 }
357 int maxSize = this->maxTextureSize();
358 if (dimensions.width() > maxSize || dimensions.height() > maxSize) {
359 return false;
360 }
361 }
362
363 return true;
364 }
365
supportedReadPixelsColorType(GrColorType srcColorType,const GrBackendFormat & srcFormat,GrColorType dstColorType) const366 GrCaps::SupportedRead GrCaps::supportedReadPixelsColorType(GrColorType srcColorType,
367 const GrBackendFormat& srcFormat,
368 GrColorType dstColorType) const {
369 SupportedRead read = this->onSupportedReadPixelsColorType(srcColorType, srcFormat,
370 dstColorType);
371
372 // There are known problems with 24 vs 32 bit BPP with this color type. Just fail for now if
373 // using a transfer buffer.
374 if (GrColorType::kRGB_888x == read.fColorType) {
375 read.fOffsetAlignmentForTransferBuffer = 0;
376 }
377 // It's very convenient to access 1 byte-per-channel 32 bit color types as uint32_t on the CPU.
378 // Make those aligned reads out of the buffer even if the underlying API doesn't require it.
379 auto channelFlags = GrColorTypeChannelFlags(read.fColorType);
380 if ((channelFlags == kRGBA_SkColorChannelFlags || channelFlags == kRGB_SkColorChannelFlags ||
381 channelFlags == kAlpha_SkColorChannelFlag || channelFlags == kGray_SkColorChannelFlag) &&
382 GrColorTypeBytesPerPixel(read.fColorType) == 4) {
383 switch (read.fOffsetAlignmentForTransferBuffer & 0b11) {
384 // offset alignment already a multiple of 4
385 case 0:
386 break;
387 // offset alignment is a multiple of 2 but not 4.
388 case 2:
389 read.fOffsetAlignmentForTransferBuffer *= 2;
390 break;
391 // offset alignment is not a multiple of 2.
392 default:
393 read.fOffsetAlignmentForTransferBuffer *= 4;
394 break;
395 }
396 }
397 return read;
398 }
399
getDefaultBackendFormat(GrColorType colorType,GrRenderable renderable) const400 GrBackendFormat GrCaps::getDefaultBackendFormat(GrColorType colorType,
401 GrRenderable renderable) const {
402 // Unknown color types are always an invalid format, so early out before calling virtual.
403 if (colorType == GrColorType::kUnknown) {
404 return {};
405 }
406
407 auto format = this->onGetDefaultBackendFormat(colorType);
408 if (!this->isFormatTexturable(format, GrTextureType::k2D)) {
409 return {};
410 }
411 if (!this->areColorTypeAndFormatCompatible(colorType, format)) {
412 return {};
413 }
414 // Currently we require that it be possible to write pixels into the "default" format. Perhaps,
415 // that could be a separate requirement from the caller. It seems less necessary if
416 // renderability was requested.
417 if (this->supportedWritePixelsColorType(colorType, format, colorType).fColorType ==
418 GrColorType::kUnknown) {
419 return {};
420 }
421 if (renderable == GrRenderable::kYes &&
422 !this->isFormatAsColorTypeRenderable(colorType, format)) {
423 return {};
424 }
425 return format;
426 }
427
areColorTypeAndFormatCompatible(GrColorType grCT,const GrBackendFormat & format) const428 bool GrCaps::areColorTypeAndFormatCompatible(GrColorType grCT,
429 const GrBackendFormat& format) const {
430 if (GrColorType::kUnknown == grCT) {
431 return false;
432 }
433
434 SkTextureCompressionType compression = GrBackendFormatToCompressionType(format);
435 if (compression != SkTextureCompressionType::kNone) {
436 return grCT == (SkTextureCompressionTypeIsOpaque(compression) ? GrColorType::kRGB_888x
437 : GrColorType::kRGBA_8888);
438 }
439
440 return this->onAreColorTypeAndFormatCompatible(grCT, format);
441 }
442
getReadSwizzle(const GrBackendFormat & format,GrColorType colorType) const443 skgpu::Swizzle GrCaps::getReadSwizzle(const GrBackendFormat& format, GrColorType colorType) const {
444 SkTextureCompressionType compression = GrBackendFormatToCompressionType(format);
445 if (compression != SkTextureCompressionType::kNone) {
446 if (colorType == GrColorType::kRGB_888x || colorType == GrColorType::kRGBA_8888) {
447 return skgpu::Swizzle::RGBA();
448 }
449 SkDEBUGFAILF("Illegal color type (%d) and compressed format (%d) combination.",
450 (int)colorType, (int)compression);
451 return {};
452 }
453
454 return this->onGetReadSwizzle(format, colorType);
455 }
456
isFormatCompressed(const GrBackendFormat & format) const457 bool GrCaps::isFormatCompressed(const GrBackendFormat& format) const {
458 return GrBackendFormatToCompressionType(format) != SkTextureCompressionType::kNone;
459 }
460
getDstSampleFlagsForProxy(const GrRenderTargetProxy * rt,bool drawUsesMSAA) const461 GrDstSampleFlags GrCaps::getDstSampleFlagsForProxy(const GrRenderTargetProxy* rt,
462 bool drawUsesMSAA) const {
463 SkASSERT(rt);
464 if (this->textureBarrierSupport() && (!drawUsesMSAA || this->msaaResolvesAutomatically())) {
465 return this->onGetDstSampleFlagsForProxy(rt);
466 }
467 return GrDstSampleFlags::kNone;
468 }
469
supportsDynamicMSAA(const GrRenderTargetProxy * rtProxy) const470 bool GrCaps::supportsDynamicMSAA(const GrRenderTargetProxy* rtProxy) const {
471 return rtProxy->numSamples() == 1 &&
472 this->internalMultisampleCount(rtProxy->backendFormat()) > 1 &&
473 this->onSupportsDynamicMSAA(rtProxy);
474 }
475
color_type_fallback(GrColorType ct)476 static inline GrColorType color_type_fallback(GrColorType ct) {
477 switch (ct) {
478 // kRGBA_8888 is our default fallback for many color types that may not have renderable
479 // backend formats.
480 case GrColorType::kAlpha_8:
481 case GrColorType::kBGR_565:
482 case GrColorType::kRGB_565:
483 case GrColorType::kABGR_4444:
484 case GrColorType::kBGRA_8888:
485 case GrColorType::kRGBA_1010102:
486 case GrColorType::kBGRA_1010102:
487 case GrColorType::kRGBA_F16:
488 case GrColorType::kRGBA_F16_Clamped:
489 return GrColorType::kRGBA_8888;
490 case GrColorType::kAlpha_F16:
491 return GrColorType::kRGBA_F16;
492 case GrColorType::kGray_8:
493 case GrColorType::kRGB_F16F16F16x:
494 case GrColorType::kRGB_101010x:
495 return GrColorType::kRGB_888x;
496 default:
497 return GrColorType::kUnknown;
498 }
499 }
500
getFallbackColorTypeAndFormat(GrColorType ct,int sampleCnt) const501 std::tuple<GrColorType, GrBackendFormat> GrCaps::getFallbackColorTypeAndFormat(
502 GrColorType ct,
503 int sampleCnt) const {
504 do {
505 auto format = this->getDefaultBackendFormat(ct, GrRenderable::kYes);
506 // We continue to the fallback color type if there no default renderable format or we
507 // requested msaa and the format doesn't support msaa.
508 if (format.isValid() && this->isFormatRenderable(format, sampleCnt)) {
509 return {ct, format};
510 }
511 ct = color_type_fallback(ct);
512 } while (ct != GrColorType::kUnknown);
513 return {GrColorType::kUnknown, {}};
514 }
515