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