1*c8dee2aaSAndroid Build Coastguard Worker /*
2*c8dee2aaSAndroid Build Coastguard Worker * Copyright 2012 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/gl/GrGLCaps.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/GrContextOptions.h"
16*c8dee2aaSAndroid Build Coastguard Worker #include "include/gpu/ganesh/GrDriverBugWorkarounds.h"
17*c8dee2aaSAndroid Build Coastguard Worker #include "include/gpu/ganesh/GrTypes.h"
18*c8dee2aaSAndroid Build Coastguard Worker #include "include/gpu/ganesh/gl/GrGLBackendSurface.h"
19*c8dee2aaSAndroid Build Coastguard Worker #include "include/gpu/ganesh/gl/GrGLFunctions.h"
20*c8dee2aaSAndroid Build Coastguard Worker #include "include/gpu/ganesh/gl/GrGLInterface.h"
21*c8dee2aaSAndroid Build Coastguard Worker #include "include/private/base/SkDebug.h"
22*c8dee2aaSAndroid Build Coastguard Worker #include "include/private/base/SkMath.h"
23*c8dee2aaSAndroid Build Coastguard Worker #include "include/private/base/SkTemplates.h"
24*c8dee2aaSAndroid Build Coastguard Worker #include "include/private/base/SkTo.h"
25*c8dee2aaSAndroid Build Coastguard Worker #include "src/core/SkCompressedDataUtils.h"
26*c8dee2aaSAndroid Build Coastguard Worker #include "src/gpu/Blend.h"
27*c8dee2aaSAndroid Build Coastguard Worker #include "src/gpu/GpuTypesPriv.h"
28*c8dee2aaSAndroid Build Coastguard Worker #include "src/gpu/ganesh/GrBackendUtils.h"
29*c8dee2aaSAndroid Build Coastguard Worker #include "src/gpu/ganesh/GrProgramDesc.h"
30*c8dee2aaSAndroid Build Coastguard Worker #include "src/gpu/ganesh/GrRenderTarget.h"
31*c8dee2aaSAndroid Build Coastguard Worker #include "src/gpu/ganesh/GrRenderTargetProxy.h"
32*c8dee2aaSAndroid Build Coastguard Worker #include "src/gpu/ganesh/GrShaderCaps.h"
33*c8dee2aaSAndroid Build Coastguard Worker #include "src/gpu/ganesh/GrSurface.h"
34*c8dee2aaSAndroid Build Coastguard Worker #include "src/gpu/ganesh/GrSurfaceProxy.h"
35*c8dee2aaSAndroid Build Coastguard Worker #include "src/gpu/ganesh/GrSurfaceProxyPriv.h"
36*c8dee2aaSAndroid Build Coastguard Worker #include "src/gpu/ganesh/GrTextureProxy.h"
37*c8dee2aaSAndroid Build Coastguard Worker #include "src/gpu/ganesh/TestFormatColorTypeCombination.h"
38*c8dee2aaSAndroid Build Coastguard Worker #include "src/gpu/ganesh/gl/GrGLContext.h"
39*c8dee2aaSAndroid Build Coastguard Worker #include "src/gpu/ganesh/gl/GrGLDefines.h"
40*c8dee2aaSAndroid Build Coastguard Worker #include "src/gpu/ganesh/gl/GrGLRenderTarget.h"
41*c8dee2aaSAndroid Build Coastguard Worker #include "src/gpu/ganesh/gl/GrGLTexture.h"
42*c8dee2aaSAndroid Build Coastguard Worker #include "src/gpu/ganesh/gl/GrGLUtil.h"
43*c8dee2aaSAndroid Build Coastguard Worker #include "src/sksl/SkSLGLSL.h"
44*c8dee2aaSAndroid Build Coastguard Worker
45*c8dee2aaSAndroid Build Coastguard Worker #include <algorithm>
46*c8dee2aaSAndroid Build Coastguard Worker #include <cstddef>
47*c8dee2aaSAndroid Build Coastguard Worker #include <initializer_list>
48*c8dee2aaSAndroid Build Coastguard Worker #include <memory>
49*c8dee2aaSAndroid Build Coastguard Worker
50*c8dee2aaSAndroid Build Coastguard Worker class GrProgramInfo;
51*c8dee2aaSAndroid Build Coastguard Worker class SkJSONWriter;
52*c8dee2aaSAndroid Build Coastguard Worker
53*c8dee2aaSAndroid Build Coastguard Worker #if defined(SK_BUILD_FOR_IOS)
54*c8dee2aaSAndroid Build Coastguard Worker #include <TargetConditionals.h>
55*c8dee2aaSAndroid Build Coastguard Worker #endif
56*c8dee2aaSAndroid Build Coastguard Worker
GrGLCaps(const GrContextOptions & contextOptions,const GrGLContextInfo & ctxInfo,const GrGLInterface * glInterface)57*c8dee2aaSAndroid Build Coastguard Worker GrGLCaps::GrGLCaps(const GrContextOptions& contextOptions,
58*c8dee2aaSAndroid Build Coastguard Worker const GrGLContextInfo& ctxInfo,
59*c8dee2aaSAndroid Build Coastguard Worker const GrGLInterface* glInterface) : INHERITED(contextOptions) {
60*c8dee2aaSAndroid Build Coastguard Worker fStandard = ctxInfo.standard();
61*c8dee2aaSAndroid Build Coastguard Worker
62*c8dee2aaSAndroid Build Coastguard Worker fPackFlipYSupport = false;
63*c8dee2aaSAndroid Build Coastguard Worker fTextureUsageSupport = false;
64*c8dee2aaSAndroid Build Coastguard Worker fImagingSupport = false;
65*c8dee2aaSAndroid Build Coastguard Worker fVertexArrayObjectSupport = false;
66*c8dee2aaSAndroid Build Coastguard Worker fDebugSupport = false;
67*c8dee2aaSAndroid Build Coastguard Worker fES2CompatibilitySupport = false;
68*c8dee2aaSAndroid Build Coastguard Worker fStrictProtectedness = false;
69*c8dee2aaSAndroid Build Coastguard Worker fDrawRangeElementsSupport = false;
70*c8dee2aaSAndroid Build Coastguard Worker fBaseVertexBaseInstanceSupport = false;
71*c8dee2aaSAndroid Build Coastguard Worker fIsCoreProfile = false;
72*c8dee2aaSAndroid Build Coastguard Worker fBindFragDataLocationSupport = false;
73*c8dee2aaSAndroid Build Coastguard Worker fRectangleTextureSupport = false;
74*c8dee2aaSAndroid Build Coastguard Worker fBindUniformLocationSupport = false;
75*c8dee2aaSAndroid Build Coastguard Worker fMipmapLevelControlSupport = false;
76*c8dee2aaSAndroid Build Coastguard Worker fMipmapLodControlSupport = false;
77*c8dee2aaSAndroid Build Coastguard Worker fDoManualMipmapping = false;
78*c8dee2aaSAndroid Build Coastguard Worker fClearToBoundaryValuesIsBroken = false;
79*c8dee2aaSAndroid Build Coastguard Worker fClearTextureSupport = false;
80*c8dee2aaSAndroid Build Coastguard Worker fDrawArraysBaseVertexIsBroken = false;
81*c8dee2aaSAndroid Build Coastguard Worker fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = false;
82*c8dee2aaSAndroid Build Coastguard Worker fUseDrawInsteadOfAllRenderTargetWrites = false;
83*c8dee2aaSAndroid Build Coastguard Worker fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines = false;
84*c8dee2aaSAndroid Build Coastguard Worker fDontSetBaseOrMaxLevelForExternalTextures = false;
85*c8dee2aaSAndroid Build Coastguard Worker fNeverDisableColorWrites = false;
86*c8dee2aaSAndroid Build Coastguard Worker fMustSetAnyTexParameterToEnableMipmapping = false;
87*c8dee2aaSAndroid Build Coastguard Worker fAllowBGRA8CopyTexSubImage = false;
88*c8dee2aaSAndroid Build Coastguard Worker fAllowSRGBCopyTexSubImage = false;
89*c8dee2aaSAndroid Build Coastguard Worker fDisallowDynamicMSAA = false;
90*c8dee2aaSAndroid Build Coastguard Worker fMustResetBlendFuncBetweenDualSourceAndDisable = false;
91*c8dee2aaSAndroid Build Coastguard Worker fBindTexture0WhenChangingTextureFBOMultisampleCount = false;
92*c8dee2aaSAndroid Build Coastguard Worker fRebindColorAttachmentAfterCheckFramebufferStatus = false;
93*c8dee2aaSAndroid Build Coastguard Worker fFlushBeforeWritePixels = false;
94*c8dee2aaSAndroid Build Coastguard Worker fDisableScalingCopyAsDraws = false;
95*c8dee2aaSAndroid Build Coastguard Worker fPadRG88TransferAlignment = false;
96*c8dee2aaSAndroid Build Coastguard Worker fProgramBinarySupport = false;
97*c8dee2aaSAndroid Build Coastguard Worker fProgramParameterSupport = false;
98*c8dee2aaSAndroid Build Coastguard Worker fSamplerObjectSupport = false;
99*c8dee2aaSAndroid Build Coastguard Worker fUseSamplerObjects = false;
100*c8dee2aaSAndroid Build Coastguard Worker fTextureSwizzleSupport = false;
101*c8dee2aaSAndroid Build Coastguard Worker fTiledRenderingSupport = false;
102*c8dee2aaSAndroid Build Coastguard Worker fFenceSyncSupport = false;
103*c8dee2aaSAndroid Build Coastguard Worker fFBFetchRequiresEnablePerSample = false;
104*c8dee2aaSAndroid Build Coastguard Worker fSRGBWriteControl = false;
105*c8dee2aaSAndroid Build Coastguard Worker fSkipErrorChecks = false;
106*c8dee2aaSAndroid Build Coastguard Worker
107*c8dee2aaSAndroid Build Coastguard Worker fShaderCaps = std::make_unique<GrShaderCaps>();
108*c8dee2aaSAndroid Build Coastguard Worker
109*c8dee2aaSAndroid Build Coastguard Worker this->init(contextOptions, ctxInfo, glInterface);
110*c8dee2aaSAndroid Build Coastguard Worker }
111*c8dee2aaSAndroid Build Coastguard Worker
angle_backend_is_d3d(GrGLANGLEBackend backend)112*c8dee2aaSAndroid Build Coastguard Worker static bool angle_backend_is_d3d(GrGLANGLEBackend backend) {
113*c8dee2aaSAndroid Build Coastguard Worker return backend == GrGLANGLEBackend::kD3D9 || backend == GrGLANGLEBackend::kD3D11;
114*c8dee2aaSAndroid Build Coastguard Worker }
115*c8dee2aaSAndroid Build Coastguard Worker
angle_backend_is_metal(GrGLANGLEBackend backend)116*c8dee2aaSAndroid Build Coastguard Worker static bool angle_backend_is_metal(GrGLANGLEBackend backend) {
117*c8dee2aaSAndroid Build Coastguard Worker return backend == GrGLANGLEBackend::kMetal;
118*c8dee2aaSAndroid Build Coastguard Worker }
119*c8dee2aaSAndroid Build Coastguard Worker
init(const GrContextOptions & contextOptions,const GrGLContextInfo & ctxInfo,const GrGLInterface * gli)120*c8dee2aaSAndroid Build Coastguard Worker void GrGLCaps::init(const GrContextOptions& contextOptions,
121*c8dee2aaSAndroid Build Coastguard Worker const GrGLContextInfo& ctxInfo,
122*c8dee2aaSAndroid Build Coastguard Worker const GrGLInterface* gli) {
123*c8dee2aaSAndroid Build Coastguard Worker GrGLStandard standard = ctxInfo.standard();
124*c8dee2aaSAndroid Build Coastguard Worker // standard can be unused (optimized away) if SK_ASSUME_GL_ES is set
125*c8dee2aaSAndroid Build Coastguard Worker sk_ignore_unused_variable(standard);
126*c8dee2aaSAndroid Build Coastguard Worker GrGLVersion version = ctxInfo.version();
127*c8dee2aaSAndroid Build Coastguard Worker
128*c8dee2aaSAndroid Build Coastguard Worker #if defined(GPU_TEST_UTILS)
129*c8dee2aaSAndroid Build Coastguard Worker const GrGLubyte* deviceName;
130*c8dee2aaSAndroid Build Coastguard Worker GR_GL_CALL_RET(gli, deviceName, GetString(GR_GL_RENDERER));
131*c8dee2aaSAndroid Build Coastguard Worker this->setDeviceName(reinterpret_cast<const char*>(deviceName));
132*c8dee2aaSAndroid Build Coastguard Worker #endif
133*c8dee2aaSAndroid Build Coastguard Worker
134*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
135*c8dee2aaSAndroid Build Coastguard Worker GrGLint max;
136*c8dee2aaSAndroid Build Coastguard Worker GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
137*c8dee2aaSAndroid Build Coastguard Worker fMaxFragmentUniformVectors = max / 4;
138*c8dee2aaSAndroid Build Coastguard Worker if (version >= GR_GL_VER(3, 2)) {
139*c8dee2aaSAndroid Build Coastguard Worker GrGLint profileMask;
140*c8dee2aaSAndroid Build Coastguard Worker GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
141*c8dee2aaSAndroid Build Coastguard Worker fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
142*c8dee2aaSAndroid Build Coastguard Worker }
143*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard) || GR_IS_GR_WEBGL(standard)) {
144*c8dee2aaSAndroid Build Coastguard Worker GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
145*c8dee2aaSAndroid Build Coastguard Worker &fMaxFragmentUniformVectors);
146*c8dee2aaSAndroid Build Coastguard Worker }
147*c8dee2aaSAndroid Build Coastguard Worker
148*c8dee2aaSAndroid Build Coastguard Worker if (fDriverBugWorkarounds.max_fragment_uniform_vectors_32) {
149*c8dee2aaSAndroid Build Coastguard Worker fMaxFragmentUniformVectors = std::min(fMaxFragmentUniformVectors, 32);
150*c8dee2aaSAndroid Build Coastguard Worker }
151*c8dee2aaSAndroid Build Coastguard Worker GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
152*c8dee2aaSAndroid Build Coastguard Worker
153*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
154*c8dee2aaSAndroid Build Coastguard Worker fWritePixelsRowBytesSupport = true;
155*c8dee2aaSAndroid Build Coastguard Worker fReadPixelsRowBytesSupport = true;
156*c8dee2aaSAndroid Build Coastguard Worker fPackFlipYSupport = false;
157*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
158*c8dee2aaSAndroid Build Coastguard Worker fWritePixelsRowBytesSupport =
159*c8dee2aaSAndroid Build Coastguard Worker version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_unpack_subimage");
160*c8dee2aaSAndroid Build Coastguard Worker fReadPixelsRowBytesSupport =
161*c8dee2aaSAndroid Build Coastguard Worker version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_NV_pack_subimage");
162*c8dee2aaSAndroid Build Coastguard Worker fPackFlipYSupport =
163*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
164*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(standard)) {
165*c8dee2aaSAndroid Build Coastguard Worker // WebGL 2.0 has these
166*c8dee2aaSAndroid Build Coastguard Worker fWritePixelsRowBytesSupport = version >= GR_GL_VER(2, 0);
167*c8dee2aaSAndroid Build Coastguard Worker fReadPixelsRowBytesSupport = version >= GR_GL_VER(2, 0);
168*c8dee2aaSAndroid Build Coastguard Worker }
169*c8dee2aaSAndroid Build Coastguard Worker fTransferPixelsToRowBytesSupport = fWritePixelsRowBytesSupport;
170*c8dee2aaSAndroid Build Coastguard Worker
171*c8dee2aaSAndroid Build Coastguard Worker if (fDriverBugWorkarounds.pack_parameters_workaround_with_pack_buffer) {
172*c8dee2aaSAndroid Build Coastguard Worker // In some cases drivers handle copying the last row incorrectly
173*c8dee2aaSAndroid Build Coastguard Worker // when using GL_PACK_ROW_LENGTH. Chromium handles this by iterating
174*c8dee2aaSAndroid Build Coastguard Worker // through every row and conditionally clobbering that value, but
175*c8dee2aaSAndroid Build Coastguard Worker // Skia already has a scratch buffer workaround when pack row length
176*c8dee2aaSAndroid Build Coastguard Worker // is not supported, so just use that.
177*c8dee2aaSAndroid Build Coastguard Worker fReadPixelsRowBytesSupport = false;
178*c8dee2aaSAndroid Build Coastguard Worker }
179*c8dee2aaSAndroid Build Coastguard Worker
180*c8dee2aaSAndroid Build Coastguard Worker fTextureUsageSupport = GR_IS_GR_GL_ES(standard) &&
181*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_ANGLE_texture_usage");
182*c8dee2aaSAndroid Build Coastguard Worker
183*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
184*c8dee2aaSAndroid Build Coastguard Worker fTextureBarrierSupport = version >= GR_GL_VER(4,5) ||
185*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_ARB_texture_barrier") ||
186*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_NV_texture_barrier");
187*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
188*c8dee2aaSAndroid Build Coastguard Worker fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier");
189*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(standard)) {
190*c8dee2aaSAndroid Build Coastguard Worker fTextureBarrierSupport = false;
191*c8dee2aaSAndroid Build Coastguard Worker }
192*c8dee2aaSAndroid Build Coastguard Worker
193*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
194*c8dee2aaSAndroid Build Coastguard Worker fSampleLocationsSupport = version >= GR_GL_VER(3,2) ||
195*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_ARB_texture_multisample");
196*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
197*c8dee2aaSAndroid Build Coastguard Worker fSampleLocationsSupport = version >= GR_GL_VER(3,1);
198*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(standard)) {
199*c8dee2aaSAndroid Build Coastguard Worker fSampleLocationsSupport = false;
200*c8dee2aaSAndroid Build Coastguard Worker }
201*c8dee2aaSAndroid Build Coastguard Worker
202*c8dee2aaSAndroid Build Coastguard Worker fImagingSupport = GR_IS_GR_GL(standard) &&
203*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_ARB_imaging");
204*c8dee2aaSAndroid Build Coastguard Worker
205*c8dee2aaSAndroid Build Coastguard Worker if (((GR_IS_GR_GL(standard) && version >= GR_GL_VER(4,3)) ||
206*c8dee2aaSAndroid Build Coastguard Worker (GR_IS_GR_GL_ES(standard) && version >= GR_GL_VER(3,0)) ||
207*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) {
208*c8dee2aaSAndroid Build Coastguard Worker fInvalidateFBType = kInvalidate_InvalidateFBType;
209*c8dee2aaSAndroid Build Coastguard Worker } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
210*c8dee2aaSAndroid Build Coastguard Worker fInvalidateFBType = kDiscard_InvalidateFBType;
211*c8dee2aaSAndroid Build Coastguard Worker }
212*c8dee2aaSAndroid Build Coastguard Worker
213*c8dee2aaSAndroid Build Coastguard Worker // For future reference on Desktop GL, GL_PRIMITIVE_RESTART_FIXED_INDEX appears in 4.3, and
214*c8dee2aaSAndroid Build Coastguard Worker // GL_PRIMITIVE_RESTART (where the client must call glPrimitiveRestartIndex) appears in 3.1.
215*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL_ES(standard)) {
216*c8dee2aaSAndroid Build Coastguard Worker // Primitive restart can cause a 3x slowdown on Adreno. Enable conservatively.
217*c8dee2aaSAndroid Build Coastguard Worker // FIXME: Primitive restart would likely be a win on iOS if we had an enum value for it.
218*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.vendor() == GrGLVendor::kARM) {
219*c8dee2aaSAndroid Build Coastguard Worker fUsePrimitiveRestart = version >= GR_GL_VER(3,0);
220*c8dee2aaSAndroid Build Coastguard Worker }
221*c8dee2aaSAndroid Build Coastguard Worker }
222*c8dee2aaSAndroid Build Coastguard Worker
223*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.vendor() == GrGLVendor::kARM ||
224*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.vendor() == GrGLVendor::kImagination ||
225*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.vendor() == GrGLVendor::kQualcomm ) {
226*c8dee2aaSAndroid Build Coastguard Worker fPreferFullscreenClears = true;
227*c8dee2aaSAndroid Build Coastguard Worker }
228*c8dee2aaSAndroid Build Coastguard Worker
229*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
230*c8dee2aaSAndroid Build Coastguard Worker fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
231*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
232*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
233*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
234*c8dee2aaSAndroid Build Coastguard Worker fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
235*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_OES_vertex_array_object");
236*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(standard)) {
237*c8dee2aaSAndroid Build Coastguard Worker fVertexArrayObjectSupport = version >= GR_GL_VER(2, 0) ||
238*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_OES_vertex_array_object") ||
239*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("OES_vertex_array_object");
240*c8dee2aaSAndroid Build Coastguard Worker }
241*c8dee2aaSAndroid Build Coastguard Worker
242*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard) && version >= GR_GL_VER(4,3)) {
243*c8dee2aaSAndroid Build Coastguard Worker fDebugSupport = true;
244*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
245*c8dee2aaSAndroid Build Coastguard Worker fDebugSupport = ctxInfo.hasExtension("GL_KHR_debug");
246*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(standard)) {
247*c8dee2aaSAndroid Build Coastguard Worker fDebugSupport = false;
248*c8dee2aaSAndroid Build Coastguard Worker }
249*c8dee2aaSAndroid Build Coastguard Worker
250*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
251*c8dee2aaSAndroid Build Coastguard Worker fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
252*c8dee2aaSAndroid Build Coastguard Worker }
253*c8dee2aaSAndroid Build Coastguard Worker else if (GR_IS_GR_GL_ES(standard)) {
254*c8dee2aaSAndroid Build Coastguard Worker fES2CompatibilitySupport = true;
255*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(standard)) {
256*c8dee2aaSAndroid Build Coastguard Worker fES2CompatibilitySupport = true;
257*c8dee2aaSAndroid Build Coastguard Worker }
258*c8dee2aaSAndroid Build Coastguard Worker
259*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
260*c8dee2aaSAndroid Build Coastguard Worker fClientCanDisableMultisample = true;
261*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
262*c8dee2aaSAndroid Build Coastguard Worker fClientCanDisableMultisample = ctxInfo.hasExtension("GL_EXT_multisample_compatibility");
263*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(standard)) {
264*c8dee2aaSAndroid Build Coastguard Worker fClientCanDisableMultisample = false;
265*c8dee2aaSAndroid Build Coastguard Worker }
266*c8dee2aaSAndroid Build Coastguard Worker
267*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
268*c8dee2aaSAndroid Build Coastguard Worker // 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about
269*c8dee2aaSAndroid Build Coastguard Worker // instanced arrays, but we could make this more granular if we wanted
270*c8dee2aaSAndroid Build Coastguard Worker fDrawInstancedSupport =
271*c8dee2aaSAndroid Build Coastguard Worker version >= GR_GL_VER(3, 2) ||
272*c8dee2aaSAndroid Build Coastguard Worker (ctxInfo.hasExtension("GL_ARB_draw_instanced") &&
273*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_ARB_instanced_arrays"));
274*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
275*c8dee2aaSAndroid Build Coastguard Worker fDrawInstancedSupport =
276*c8dee2aaSAndroid Build Coastguard Worker version >= GR_GL_VER(3, 0) ||
277*c8dee2aaSAndroid Build Coastguard Worker (ctxInfo.hasExtension("GL_EXT_draw_instanced") &&
278*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_EXT_instanced_arrays")) ||
279*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_ANGLE_instanced_arrays");
280*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(standard)) {
281*c8dee2aaSAndroid Build Coastguard Worker // WebGL 2.0 has DrawArraysInstanced and drawElementsInstanced
282*c8dee2aaSAndroid Build Coastguard Worker fDrawInstancedSupport = version >= GR_GL_VER(2, 0);
283*c8dee2aaSAndroid Build Coastguard Worker }
284*c8dee2aaSAndroid Build Coastguard Worker
285*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
286*c8dee2aaSAndroid Build Coastguard Worker if (version >= GR_GL_VER(3, 0)) {
287*c8dee2aaSAndroid Build Coastguard Worker fBindFragDataLocationSupport = true;
288*c8dee2aaSAndroid Build Coastguard Worker }
289*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
290*c8dee2aaSAndroid Build Coastguard Worker if (version >= GR_GL_VER(3, 0) && ctxInfo.hasExtension("GL_EXT_blend_func_extended")) {
291*c8dee2aaSAndroid Build Coastguard Worker fBindFragDataLocationSupport = true;
292*c8dee2aaSAndroid Build Coastguard Worker }
293*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(standard)) {
294*c8dee2aaSAndroid Build Coastguard Worker fBindFragDataLocationSupport = false;
295*c8dee2aaSAndroid Build Coastguard Worker }
296*c8dee2aaSAndroid Build Coastguard Worker
297*c8dee2aaSAndroid Build Coastguard Worker fBindUniformLocationSupport = ctxInfo.hasExtension("GL_CHROMIUM_bind_uniform_location");
298*c8dee2aaSAndroid Build Coastguard Worker
299*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
300*c8dee2aaSAndroid Build Coastguard Worker if (version >= GR_GL_VER(3, 1) || ctxInfo.hasExtension("GL_ARB_texture_rectangle") ||
301*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_ANGLE_texture_rectangle")) {
302*c8dee2aaSAndroid Build Coastguard Worker fRectangleTextureSupport = true;
303*c8dee2aaSAndroid Build Coastguard Worker }
304*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
305*c8dee2aaSAndroid Build Coastguard Worker fRectangleTextureSupport = ctxInfo.hasExtension("GL_ARB_texture_rectangle") ||
306*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_ANGLE_texture_rectangle");
307*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(standard)) {
308*c8dee2aaSAndroid Build Coastguard Worker fRectangleTextureSupport = false;
309*c8dee2aaSAndroid Build Coastguard Worker }
310*c8dee2aaSAndroid Build Coastguard Worker
311*c8dee2aaSAndroid Build Coastguard Worker // GrCaps defaults fClampToBorderSupport to true, so disable when unsupported
312*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
313*c8dee2aaSAndroid Build Coastguard Worker // Clamp to border added in 1.3
314*c8dee2aaSAndroid Build Coastguard Worker if (version < GR_GL_VER(1, 3) && !ctxInfo.hasExtension("GL_ARB_texture_border_clamp")) {
315*c8dee2aaSAndroid Build Coastguard Worker fClampToBorderSupport = false;
316*c8dee2aaSAndroid Build Coastguard Worker }
317*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
318*c8dee2aaSAndroid Build Coastguard Worker // GLES didn't have clamp to border until 3.2, but provides several alternative extensions
319*c8dee2aaSAndroid Build Coastguard Worker if (version < GR_GL_VER(3, 2) && !ctxInfo.hasExtension("GL_EXT_texture_border_clamp") &&
320*c8dee2aaSAndroid Build Coastguard Worker !ctxInfo.hasExtension("GL_NV_texture_border_clamp") &&
321*c8dee2aaSAndroid Build Coastguard Worker !ctxInfo.hasExtension("GL_OES_texture_border_clamp")) {
322*c8dee2aaSAndroid Build Coastguard Worker fClampToBorderSupport = false;
323*c8dee2aaSAndroid Build Coastguard Worker }
324*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(standard)) {
325*c8dee2aaSAndroid Build Coastguard Worker // WebGL appears to only have REPEAT, CLAMP_TO_EDGE and MIRRORED_REPEAT
326*c8dee2aaSAndroid Build Coastguard Worker fClampToBorderSupport = false;
327*c8dee2aaSAndroid Build Coastguard Worker }
328*c8dee2aaSAndroid Build Coastguard Worker
329*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
330*c8dee2aaSAndroid Build Coastguard Worker if (version >= GR_GL_VER(3,3) || ctxInfo.hasExtension("GL_ARB_texture_swizzle")) {
331*c8dee2aaSAndroid Build Coastguard Worker fTextureSwizzleSupport = true;
332*c8dee2aaSAndroid Build Coastguard Worker }
333*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
334*c8dee2aaSAndroid Build Coastguard Worker if (version >= GR_GL_VER(3,0)) {
335*c8dee2aaSAndroid Build Coastguard Worker fTextureSwizzleSupport = true;
336*c8dee2aaSAndroid Build Coastguard Worker }
337*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(standard)) {
338*c8dee2aaSAndroid Build Coastguard Worker fTextureSwizzleSupport = false;
339*c8dee2aaSAndroid Build Coastguard Worker }
340*c8dee2aaSAndroid Build Coastguard Worker
341*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
342*c8dee2aaSAndroid Build Coastguard Worker fMipmapLevelControlSupport = true;
343*c8dee2aaSAndroid Build Coastguard Worker fMipmapLodControlSupport = true;
344*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
345*c8dee2aaSAndroid Build Coastguard Worker if (version >= GR_GL_VER(3,0)) {
346*c8dee2aaSAndroid Build Coastguard Worker fMipmapLevelControlSupport = true;
347*c8dee2aaSAndroid Build Coastguard Worker fMipmapLodControlSupport = true;
348*c8dee2aaSAndroid Build Coastguard Worker }
349*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(standard)) {
350*c8dee2aaSAndroid Build Coastguard Worker fMipmapLevelControlSupport = false;
351*c8dee2aaSAndroid Build Coastguard Worker fMipmapLodControlSupport = false;
352*c8dee2aaSAndroid Build Coastguard Worker }
353*c8dee2aaSAndroid Build Coastguard Worker
354*c8dee2aaSAndroid Build Coastguard Worker if ((GR_IS_GR_GL_ES(standard) || GR_IS_GR_GL(standard)) &&
355*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_ARB_invalidate_subdata")) {
356*c8dee2aaSAndroid Build Coastguard Worker fInvalidateBufferType = InvalidateBufferType::kInvalidate;
357*c8dee2aaSAndroid Build Coastguard Worker } else if (!GR_IS_GR_WEBGL(standard) && !ctxInfo.isOverCommandBuffer()) {
358*c8dee2aaSAndroid Build Coastguard Worker // Chrome's command buffer will push an array of zeros to a buffer if null is passed to
359*c8dee2aaSAndroid Build Coastguard Worker // glBufferData (to avoid letting an application see uninitialized memory). This is
360*c8dee2aaSAndroid Build Coastguard Worker // expensive so we avoid it. WebGL spec explicitly disallows null values.
361*c8dee2aaSAndroid Build Coastguard Worker fInvalidateBufferType = InvalidateBufferType::kNullData;
362*c8dee2aaSAndroid Build Coastguard Worker }
363*c8dee2aaSAndroid Build Coastguard Worker
364*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
365*c8dee2aaSAndroid Build Coastguard Worker fClearTextureSupport = (version >= GR_GL_VER(4,4) ||
366*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_ARB_clear_texture"));
367*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
368*c8dee2aaSAndroid Build Coastguard Worker fClearTextureSupport = ctxInfo.hasExtension("GL_EXT_clear_texture");
369*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(standard)) {
370*c8dee2aaSAndroid Build Coastguard Worker fClearTextureSupport = false;
371*c8dee2aaSAndroid Build Coastguard Worker }
372*c8dee2aaSAndroid Build Coastguard Worker
373*c8dee2aaSAndroid Build Coastguard Worker #if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26
374*c8dee2aaSAndroid Build Coastguard Worker fSupportsAHardwareBufferImages = true;
375*c8dee2aaSAndroid Build Coastguard Worker #endif
376*c8dee2aaSAndroid Build Coastguard Worker
377*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
378*c8dee2aaSAndroid Build Coastguard Worker fSRGBWriteControl = version >= GR_GL_VER(3, 0) ||
379*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
380*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB");
381*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
382*c8dee2aaSAndroid Build Coastguard Worker // ES through 3.2 requires EXT_srgb_write_control to support toggling
383*c8dee2aaSAndroid Build Coastguard Worker // sRGB writing for destinations.
384*c8dee2aaSAndroid Build Coastguard Worker fSRGBWriteControl = ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
385*c8dee2aaSAndroid Build Coastguard Worker } // No WebGL support
386*c8dee2aaSAndroid Build Coastguard Worker
387*c8dee2aaSAndroid Build Coastguard Worker fSkipErrorChecks = ctxInfo.isOverCommandBuffer();
388*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_WEBGL(standard)) {
389*c8dee2aaSAndroid Build Coastguard Worker // Error checks are quite costly in webgl, especially in Chrome.
390*c8dee2aaSAndroid Build Coastguard Worker fSkipErrorChecks = true;
391*c8dee2aaSAndroid Build Coastguard Worker }
392*c8dee2aaSAndroid Build Coastguard Worker
393*c8dee2aaSAndroid Build Coastguard Worker // When we are abandoning the context we cannot call into GL thus we should skip any sync work.
394*c8dee2aaSAndroid Build Coastguard Worker fMustSyncGpuDuringAbandon = false;
395*c8dee2aaSAndroid Build Coastguard Worker
396*c8dee2aaSAndroid Build Coastguard Worker fSupportsProtectedContent = [&]() {
397*c8dee2aaSAndroid Build Coastguard Worker if (!ctxInfo.hasExtension("GL_EXT_protected_textures")) {
398*c8dee2aaSAndroid Build Coastguard Worker return false;
399*c8dee2aaSAndroid Build Coastguard Worker }
400*c8dee2aaSAndroid Build Coastguard Worker
401*c8dee2aaSAndroid Build Coastguard Worker GrGLint contextFlags;
402*c8dee2aaSAndroid Build Coastguard Worker GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_FLAGS, &contextFlags);
403*c8dee2aaSAndroid Build Coastguard Worker return SkToBool(contextFlags & GR_GL_CONTEXT_FLAG_PROTECTED_CONTENT_BIT_EXT);
404*c8dee2aaSAndroid Build Coastguard Worker }();
405*c8dee2aaSAndroid Build Coastguard Worker
406*c8dee2aaSAndroid Build Coastguard Worker /**
407*c8dee2aaSAndroid Build Coastguard Worker * When Ganesh is backed by ANGLE mapping to Vulkan, the Protectedness handling has to be
408*c8dee2aaSAndroid Build Coastguard Worker * more like the Vulkan case (i.e., all internally allocated objects that will be written to
409*c8dee2aaSAndroid Build Coastguard Worker * in a Protected Context must be Protected). ANGLE just forwards any work to the
410*c8dee2aaSAndroid Build Coastguard Worker * active Vulkan Context. If that Vulkan Context is Protected that would mean, without
411*c8dee2aaSAndroid Build Coastguard Worker * using strict Protectedness, writes to unProtected objects would be submitted to a
412*c8dee2aaSAndroid Build Coastguard Worker * Protected Queue - which is not allowed in Vulkan.
413*c8dee2aaSAndroid Build Coastguard Worker */
414*c8dee2aaSAndroid Build Coastguard Worker fStrictProtectedness = fSupportsProtectedContent &&
415*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.angleBackend() != GrGLANGLEBackend::kUnknown;
416*c8dee2aaSAndroid Build Coastguard Worker
417*c8dee2aaSAndroid Build Coastguard Worker /**************************************************************************
418*c8dee2aaSAndroid Build Coastguard Worker * GrShaderCaps fields
419*c8dee2aaSAndroid Build Coastguard Worker **************************************************************************/
420*c8dee2aaSAndroid Build Coastguard Worker
421*c8dee2aaSAndroid Build Coastguard Worker // This must be called after fCoreProfile is set on the GrGLCaps
422*c8dee2aaSAndroid Build Coastguard Worker this->initGLSL(ctxInfo, gli);
423*c8dee2aaSAndroid Build Coastguard Worker GrShaderCaps* shaderCaps = fShaderCaps.get();
424*c8dee2aaSAndroid Build Coastguard Worker
425*c8dee2aaSAndroid Build Coastguard Worker // Enable supported shader-related caps
426*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
427*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fDualSourceBlendingSupport =
428*c8dee2aaSAndroid Build Coastguard Worker (version >= GR_GL_VER(3, 3) ||
429*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_ARB_blend_func_extended")) &&
430*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k130;
431*c8dee2aaSAndroid Build Coastguard Worker
432*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fShaderDerivativeSupport = true;
433*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fExplicitTextureLodSupport =
434*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k130;
435*c8dee2aaSAndroid Build Coastguard Worker
436*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fIntegerSupport = version >= GR_GL_VER(3, 0) &&
437*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k130;
438*c8dee2aaSAndroid Build Coastguard Worker
439*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fNonsquareMatrixSupport =
440*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k130;
441*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fInverseHyperbolicSupport =
442*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k130;
443*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
444*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended");
445*c8dee2aaSAndroid Build Coastguard Worker
446*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fShaderDerivativeSupport =
447*c8dee2aaSAndroid Build Coastguard Worker // We use this value for GLSL ES 3.0.
448*c8dee2aaSAndroid Build Coastguard Worker version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_OES_standard_derivatives");
449*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fExplicitTextureLodSupport =
450*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k300es;
451*c8dee2aaSAndroid Build Coastguard Worker
452*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fIntegerSupport = version >= GR_GL_VER(3, 0) &&
453*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k300es;
454*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fNonsquareMatrixSupport =
455*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k300es;
456*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fInverseHyperbolicSupport =
457*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k300es;
458*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(standard)) {
459*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fShaderDerivativeSupport = version >= GR_GL_VER(2, 0) ||
460*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_OES_standard_derivatives") ||
461*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("OES_standard_derivatives");
462*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fExplicitTextureLodSupport =
463*c8dee2aaSAndroid Build Coastguard Worker version >= GR_GL_VER(2, 0) &&
464*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k300es;
465*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fIntegerSupport = (version >= GR_GL_VER(2, 0));
466*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fNonsquareMatrixSupport =
467*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k300es;
468*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fInverseHyperbolicSupport =
469*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k300es;
470*c8dee2aaSAndroid Build Coastguard Worker }
471*c8dee2aaSAndroid Build Coastguard Worker
472*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.hasExtension("GL_NV_conservative_raster")) {
473*c8dee2aaSAndroid Build Coastguard Worker fConservativeRasterSupport = true;
474*c8dee2aaSAndroid Build Coastguard Worker }
475*c8dee2aaSAndroid Build Coastguard Worker
476*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
477*c8dee2aaSAndroid Build Coastguard Worker fWireframeSupport = true;
478*c8dee2aaSAndroid Build Coastguard Worker }
479*c8dee2aaSAndroid Build Coastguard Worker
480*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
481*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fRewriteSwitchStatements =
482*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.glslGeneration() < SkSL::GLSLGeneration::k130; // introduced in GLSL 1.3
483*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
484*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fRewriteSwitchStatements =
485*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.glslGeneration() < SkSL::GLSLGeneration::k300es; // introduced in GLSL ES3
486*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(standard)) {
487*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fRewriteSwitchStatements = version < GR_GL_VER(2, 0); // introduced in WebGL 2
488*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fCanUseVoidInSequenceExpressions =
489*c8dee2aaSAndroid Build Coastguard Worker false; // removed in WebGL 2, use workaround in all versions for safety
490*c8dee2aaSAndroid Build Coastguard Worker }
491*c8dee2aaSAndroid Build Coastguard Worker
492*c8dee2aaSAndroid Build Coastguard Worker // Protect ourselves against tracking huge amounts of texture state.
493*c8dee2aaSAndroid Build Coastguard Worker static const uint8_t kMaxSaneSamplers = 32;
494*c8dee2aaSAndroid Build Coastguard Worker GrGLint maxSamplers;
495*c8dee2aaSAndroid Build Coastguard Worker GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &maxSamplers);
496*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fMaxFragmentSamplers = std::min<GrGLint>(kMaxSaneSamplers, maxSamplers);
497*c8dee2aaSAndroid Build Coastguard Worker
498*c8dee2aaSAndroid Build Coastguard Worker // SGX and Mali GPUs have tiled architectures that have trouble with frequently changing VBOs.
499*c8dee2aaSAndroid Build Coastguard Worker // We've measured a performance increase using non-VBO vertex data for dynamic content on these
500*c8dee2aaSAndroid Build Coastguard Worker // GPUs. Perhaps we should read the renderer string and limit this decision to specific GPU
501*c8dee2aaSAndroid Build Coastguard Worker // families rather than basing it on the vendor alone.
502*c8dee2aaSAndroid Build Coastguard Worker // Angle can be initialized with client arrays disabled and needs to be queried. The Chrome
503*c8dee2aaSAndroid Build Coastguard Worker // command buffer blocks the use of client side buffers (but may emulate VBOs with them). Client
504*c8dee2aaSAndroid Build Coastguard Worker // side buffers are not allowed in core profiles.
505*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard) || GR_IS_GR_GL_ES(standard)) {
506*c8dee2aaSAndroid Build Coastguard Worker GrGLint clientArraysEnabled = GR_GL_TRUE;
507*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.hasExtension("GL_ANGLE_client_arrays")) {
508*c8dee2aaSAndroid Build Coastguard Worker GR_GL_GetIntegerv(gli, GR_GL_CLIENT_ARRAYS_ANGLE, &clientArraysEnabled);
509*c8dee2aaSAndroid Build Coastguard Worker }
510*c8dee2aaSAndroid Build Coastguard Worker
511*c8dee2aaSAndroid Build Coastguard Worker if (clientArraysEnabled && !ctxInfo.isOverCommandBuffer() && !fIsCoreProfile &&
512*c8dee2aaSAndroid Build Coastguard Worker (ctxInfo.vendor() == GrGLVendor::kARM || ctxInfo.vendor() == GrGLVendor::kImagination ||
513*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.vendor() == GrGLVendor::kQualcomm)) {
514*c8dee2aaSAndroid Build Coastguard Worker fPreferClientSideDynamicBuffers = true;
515*c8dee2aaSAndroid Build Coastguard Worker }
516*c8dee2aaSAndroid Build Coastguard Worker } // No client side arrays in WebGL https://www.khronos.org/registry/webgl/specs/1.0/#6.2
517*c8dee2aaSAndroid Build Coastguard Worker
518*c8dee2aaSAndroid Build Coastguard Worker if (!contextOptions.fAvoidStencilBuffers && !fSupportsProtectedContent) {
519*c8dee2aaSAndroid Build Coastguard Worker // To reduce surface area, if we avoid stencil buffers, we also disable MSAA.
520*c8dee2aaSAndroid Build Coastguard Worker // We also avoid both for Protected Contexts due to their use of RenderBuffers (which
521*c8dee2aaSAndroid Build Coastguard Worker // cannot be correctly created as Protected).
522*c8dee2aaSAndroid Build Coastguard Worker this->initFSAASupport(contextOptions, ctxInfo, gli);
523*c8dee2aaSAndroid Build Coastguard Worker this->initStencilSupport(ctxInfo);
524*c8dee2aaSAndroid Build Coastguard Worker }
525*c8dee2aaSAndroid Build Coastguard Worker
526*c8dee2aaSAndroid Build Coastguard Worker // Setup blit framebuffer
527*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
528*c8dee2aaSAndroid Build Coastguard Worker if (version >= GR_GL_VER(3,0) ||
529*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_ARB_framebuffer_object") ||
530*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
531*c8dee2aaSAndroid Build Coastguard Worker fBlitFramebufferFlags = 0;
532*c8dee2aaSAndroid Build Coastguard Worker }
533*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
534*c8dee2aaSAndroid Build Coastguard Worker if (version >= GR_GL_VER(3, 0) ||
535*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_NV_framebuffer_blit")) {
536*c8dee2aaSAndroid Build Coastguard Worker fBlitFramebufferFlags = kNoFormatConversionForMSAASrc_BlitFramebufferFlag |
537*c8dee2aaSAndroid Build Coastguard Worker kNoMSAADst_BlitFramebufferFlag |
538*c8dee2aaSAndroid Build Coastguard Worker kRectsMustMatchForMSAASrc_BlitFramebufferFlag;
539*c8dee2aaSAndroid Build Coastguard Worker } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample") ||
540*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_ANGLE_framebuffer_blit")) {
541*c8dee2aaSAndroid Build Coastguard Worker // The CHROMIUM extension uses the ANGLE version of glBlitFramebuffer and includes its
542*c8dee2aaSAndroid Build Coastguard Worker // limitations.
543*c8dee2aaSAndroid Build Coastguard Worker fBlitFramebufferFlags = kNoScalingOrMirroring_BlitFramebufferFlag |
544*c8dee2aaSAndroid Build Coastguard Worker kResolveMustBeFull_BlitFrambufferFlag |
545*c8dee2aaSAndroid Build Coastguard Worker kNoMSAADst_BlitFramebufferFlag |
546*c8dee2aaSAndroid Build Coastguard Worker kNoFormatConversion_BlitFramebufferFlag |
547*c8dee2aaSAndroid Build Coastguard Worker kRectsMustMatchForMSAASrc_BlitFramebufferFlag;
548*c8dee2aaSAndroid Build Coastguard Worker }
549*c8dee2aaSAndroid Build Coastguard Worker } // No WebGL 1.0 support for BlitFramebuffer
550*c8dee2aaSAndroid Build Coastguard Worker
551*c8dee2aaSAndroid Build Coastguard Worker this->initBlendEqationSupport(ctxInfo);
552*c8dee2aaSAndroid Build Coastguard Worker
553*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
554*c8dee2aaSAndroid Build Coastguard Worker fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
555*c8dee2aaSAndroid Build Coastguard Worker // extension includes glMapBuffer.
556*c8dee2aaSAndroid Build Coastguard Worker if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
557*c8dee2aaSAndroid Build Coastguard Worker fMapBufferFlags |= kSubset_MapFlag;
558*c8dee2aaSAndroid Build Coastguard Worker fMapBufferType = kMapBufferRange_MapBufferType;
559*c8dee2aaSAndroid Build Coastguard Worker } else {
560*c8dee2aaSAndroid Build Coastguard Worker fMapBufferType = kMapBuffer_MapBufferType;
561*c8dee2aaSAndroid Build Coastguard Worker }
562*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
563*c8dee2aaSAndroid Build Coastguard Worker // Unextended GLES2 doesn't have any buffer mapping.
564*c8dee2aaSAndroid Build Coastguard Worker fMapBufferFlags = kNone_MapFlags;
565*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
566*c8dee2aaSAndroid Build Coastguard Worker fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
567*c8dee2aaSAndroid Build Coastguard Worker fMapBufferType = kChromium_MapBufferType;
568*c8dee2aaSAndroid Build Coastguard Worker } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
569*c8dee2aaSAndroid Build Coastguard Worker fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
570*c8dee2aaSAndroid Build Coastguard Worker fMapBufferType = kMapBufferRange_MapBufferType;
571*c8dee2aaSAndroid Build Coastguard Worker } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
572*c8dee2aaSAndroid Build Coastguard Worker fMapBufferFlags = kCanMap_MapFlag;
573*c8dee2aaSAndroid Build Coastguard Worker fMapBufferType = kMapBuffer_MapBufferType;
574*c8dee2aaSAndroid Build Coastguard Worker }
575*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(standard)) {
576*c8dee2aaSAndroid Build Coastguard Worker // explicitly removed https://www.khronos.org/registry/webgl/specs/2.0/#5.14
577*c8dee2aaSAndroid Build Coastguard Worker fMapBufferFlags = kNone_MapFlags;
578*c8dee2aaSAndroid Build Coastguard Worker }
579*c8dee2aaSAndroid Build Coastguard Worker
580*c8dee2aaSAndroid Build Coastguard Worker // Buffers have more restrictions in WebGL than GLES. For example,
581*c8dee2aaSAndroid Build Coastguard Worker // https://www.khronos.org/registry/webgl/specs/latest/2.0/#BUFFER_OBJECT_BINDING
582*c8dee2aaSAndroid Build Coastguard Worker // We therefore haven't attempted to support mapping or transfers between buffers and surfaces
583*c8dee2aaSAndroid Build Coastguard Worker // or between buffers.
584*c8dee2aaSAndroid Build Coastguard Worker
585*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
586*c8dee2aaSAndroid Build Coastguard Worker if (version >= GR_GL_VER(2, 1) || ctxInfo.hasExtension("GL_ARB_pixel_buffer_object") ||
587*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_EXT_pixel_buffer_object")) {
588*c8dee2aaSAndroid Build Coastguard Worker fTransferFromBufferToTextureSupport = true;
589*c8dee2aaSAndroid Build Coastguard Worker fTransferFromSurfaceToBufferSupport = true;
590*c8dee2aaSAndroid Build Coastguard Worker fTransferBufferType = TransferBufferType::kARB_PBO;
591*c8dee2aaSAndroid Build Coastguard Worker }
592*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
593*c8dee2aaSAndroid Build Coastguard Worker if (version >= GR_GL_VER(3, 0) ||
594*c8dee2aaSAndroid Build Coastguard Worker (ctxInfo.hasExtension("GL_NV_pixel_buffer_object") &&
595*c8dee2aaSAndroid Build Coastguard Worker // GL_EXT_unpack_subimage needed to support subtexture rectangles
596*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_EXT_unpack_subimage"))) {
597*c8dee2aaSAndroid Build Coastguard Worker fTransferFromBufferToTextureSupport = true;
598*c8dee2aaSAndroid Build Coastguard Worker fTransferFromSurfaceToBufferSupport = true;
599*c8dee2aaSAndroid Build Coastguard Worker if (version < GR_GL_VER(3, 0)) {
600*c8dee2aaSAndroid Build Coastguard Worker fTransferBufferType = TransferBufferType::kNV_PBO;
601*c8dee2aaSAndroid Build Coastguard Worker } else {
602*c8dee2aaSAndroid Build Coastguard Worker fTransferBufferType = TransferBufferType::kARB_PBO;
603*c8dee2aaSAndroid Build Coastguard Worker }
604*c8dee2aaSAndroid Build Coastguard Worker // TODO: get transfer buffers working in Chrome
605*c8dee2aaSAndroid Build Coastguard Worker // } else if (ctxInfo.hasExtension("GL_CHROMIUM_pixel_transfer_buffer_object")) {
606*c8dee2aaSAndroid Build Coastguard Worker // fTransferFromBufferToTextureSupport = false;
607*c8dee2aaSAndroid Build Coastguard Worker // fTransferFromSurfaceToBufferSupport = false;
608*c8dee2aaSAndroid Build Coastguard Worker // fTransferBufferType = TransferBufferType::kChromium;
609*c8dee2aaSAndroid Build Coastguard Worker }
610*c8dee2aaSAndroid Build Coastguard Worker }
611*c8dee2aaSAndroid Build Coastguard Worker
612*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard) &&
613*c8dee2aaSAndroid Build Coastguard Worker (version >= GR_GL_VER(3, 1) || ctxInfo.hasExtension("GL_ARB_copy_buffer"))) {
614*c8dee2aaSAndroid Build Coastguard Worker fTransferFromBufferToBufferSupport = true;
615*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard) &&
616*c8dee2aaSAndroid Build Coastguard Worker (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_NV_copy_buffer"))) {
617*c8dee2aaSAndroid Build Coastguard Worker fTransferFromBufferToBufferSupport = true;
618*c8dee2aaSAndroid Build Coastguard Worker }
619*c8dee2aaSAndroid Build Coastguard Worker
620*c8dee2aaSAndroid Build Coastguard Worker // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
621*c8dee2aaSAndroid Build Coastguard Worker // threshold to the maximum unless the client gives us a hint that map memory is cheap.
622*c8dee2aaSAndroid Build Coastguard Worker if (fBufferMapThreshold < 0) {
623*c8dee2aaSAndroid Build Coastguard Worker #if 0
624*c8dee2aaSAndroid Build Coastguard Worker // We think mapping on Chromium will be cheaper once we know ahead of time how much space
625*c8dee2aaSAndroid Build Coastguard Worker // we will use for all GrMeshDrawOps. Right now we might wind up mapping a large buffer and
626*c8dee2aaSAndroid Build Coastguard Worker // using a small subset.
627*c8dee2aaSAndroid Build Coastguard Worker fBufferMapThreshold = ctxInfo.isOverCommandBuffer() ? 0 : SK_MaxS32;
628*c8dee2aaSAndroid Build Coastguard Worker #else
629*c8dee2aaSAndroid Build Coastguard Worker fBufferMapThreshold = SK_MaxS32;
630*c8dee2aaSAndroid Build Coastguard Worker #endif
631*c8dee2aaSAndroid Build Coastguard Worker }
632*c8dee2aaSAndroid Build Coastguard Worker
633*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
634*c8dee2aaSAndroid Build Coastguard Worker fNPOTTextureTileSupport = true;
635*c8dee2aaSAndroid Build Coastguard Worker fMipmapSupport = true;
636*c8dee2aaSAndroid Build Coastguard Worker fAnisoSupport = version >= GR_GL_VER(4,6) ||
637*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_ARB_texture_filter_anisotropic") ||
638*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_EXT_texture_filter_anisotropic");
639*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
640*c8dee2aaSAndroid Build Coastguard Worker // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
641*c8dee2aaSAndroid Build Coastguard Worker // ES3 has no limitations.
642*c8dee2aaSAndroid Build Coastguard Worker fNPOTTextureTileSupport = version >= GR_GL_VER(3,0) ||
643*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_OES_texture_npot");
644*c8dee2aaSAndroid Build Coastguard Worker // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
645*c8dee2aaSAndroid Build Coastguard Worker // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
646*c8dee2aaSAndroid Build Coastguard Worker // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
647*c8dee2aaSAndroid Build Coastguard Worker // to alllow arbitrary wrap modes, however.
648*c8dee2aaSAndroid Build Coastguard Worker fMipmapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
649*c8dee2aaSAndroid Build Coastguard Worker fAnisoSupport = ctxInfo.hasExtension("GL_EXT_texture_filter_anisotropic");
650*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(standard)) {
651*c8dee2aaSAndroid Build Coastguard Worker // Texture access works in the WebGL 2.0 API as in the OpenGL ES 3.0 API
652*c8dee2aaSAndroid Build Coastguard Worker fNPOTTextureTileSupport = version >= GR_GL_VER(2,0);
653*c8dee2aaSAndroid Build Coastguard Worker // All mipmapping and all wrapping modes are supported for non-power-of-
654*c8dee2aaSAndroid Build Coastguard Worker // two images [in WebGL 2.0].
655*c8dee2aaSAndroid Build Coastguard Worker fMipmapSupport = fNPOTTextureTileSupport;
656*c8dee2aaSAndroid Build Coastguard Worker fAnisoSupport = ctxInfo.hasExtension("GL_EXT_texture_filter_anisotropic") ||
657*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("EXT_texture_filter_anisotropic");
658*c8dee2aaSAndroid Build Coastguard Worker }
659*c8dee2aaSAndroid Build Coastguard Worker if (fAnisoSupport) {
660*c8dee2aaSAndroid Build Coastguard Worker GR_GL_GetFloatv(gli, GR_GL_MAX_TEXTURE_MAX_ANISOTROPY, &fMaxTextureMaxAnisotropy);
661*c8dee2aaSAndroid Build Coastguard Worker }
662*c8dee2aaSAndroid Build Coastguard Worker
663*c8dee2aaSAndroid Build Coastguard Worker GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
664*c8dee2aaSAndroid Build Coastguard Worker
665*c8dee2aaSAndroid Build Coastguard Worker GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
666*c8dee2aaSAndroid Build Coastguard Worker fMaxPreferredRenderTargetSize = fMaxRenderTargetSize;
667*c8dee2aaSAndroid Build Coastguard Worker
668*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.vendor() == GrGLVendor::kARM) {
669*c8dee2aaSAndroid Build Coastguard Worker // On Mali G71, RT's above 4k have been observed to incur a performance cost.
670*c8dee2aaSAndroid Build Coastguard Worker fMaxPreferredRenderTargetSize = std::min(4096, fMaxPreferredRenderTargetSize);
671*c8dee2aaSAndroid Build Coastguard Worker }
672*c8dee2aaSAndroid Build Coastguard Worker
673*c8dee2aaSAndroid Build Coastguard Worker fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
674*c8dee2aaSAndroid Build Coastguard Worker
675*c8dee2aaSAndroid Build Coastguard Worker // Disable scratch texture reuse on Mali and Adreno devices
676*c8dee2aaSAndroid Build Coastguard Worker fReuseScratchTextures = (ctxInfo.vendor() != GrGLVendor::kARM);
677*c8dee2aaSAndroid Build Coastguard Worker
678*c8dee2aaSAndroid Build Coastguard Worker #if 0
679*c8dee2aaSAndroid Build Coastguard Worker fReuseScratchBuffers = ctxInfo.vendor() != GrGLVendor::kARM
680*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.vendor() != GrGLVendor::kQualcomm;
681*c8dee2aaSAndroid Build Coastguard Worker #endif
682*c8dee2aaSAndroid Build Coastguard Worker
683*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.hasExtension("GL_EXT_window_rectangles")) {
684*c8dee2aaSAndroid Build Coastguard Worker GR_GL_GetIntegerv(gli, GR_GL_MAX_WINDOW_RECTANGLES, &fMaxWindowRectangles);
685*c8dee2aaSAndroid Build Coastguard Worker }
686*c8dee2aaSAndroid Build Coastguard Worker
687*c8dee2aaSAndroid Build Coastguard Worker #ifdef SK_BUILD_FOR_WIN
688*c8dee2aaSAndroid Build Coastguard Worker // We're assuming that on Windows Chromium we're using D3D ANGLE.
689*c8dee2aaSAndroid Build Coastguard Worker bool isD3DANGLE = angle_backend_is_d3d(ctxInfo.angleBackend()) ||
690*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.isOverCommandBuffer();
691*c8dee2aaSAndroid Build Coastguard Worker // On ANGLE deferring flushes can lead to GPU starvation
692*c8dee2aaSAndroid Build Coastguard Worker fPreferVRAMUseOverFlushes = !isD3DANGLE;
693*c8dee2aaSAndroid Build Coastguard Worker #endif
694*c8dee2aaSAndroid Build Coastguard Worker
695*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.isOverCommandBuffer()) {
696*c8dee2aaSAndroid Build Coastguard Worker fMustClearUploadedBufferData = true;
697*c8dee2aaSAndroid Build Coastguard Worker }
698*c8dee2aaSAndroid Build Coastguard Worker
699*c8dee2aaSAndroid Build Coastguard Worker // In a WASM build on Firefox, we see warnings like
700*c8dee2aaSAndroid Build Coastguard Worker // WebGL warning: texSubImage2D: This operation requires zeroing texture data. This is slow.
701*c8dee2aaSAndroid Build Coastguard Worker // WebGL warning: texSubImage2D: Texture has not been initialized prior to a partial upload,
702*c8dee2aaSAndroid Build Coastguard Worker // forcing the browser to clear it. This may be slow.
703*c8dee2aaSAndroid Build Coastguard Worker // Setting the initial clear seems to make those warnings go away and offers a substantial
704*c8dee2aaSAndroid Build Coastguard Worker // boost in performance in Firefox. Chrome sees a more modest increase.
705*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_WEBGL(standard)) {
706*c8dee2aaSAndroid Build Coastguard Worker fShouldInitializeTextures = true;
707*c8dee2aaSAndroid Build Coastguard Worker }
708*c8dee2aaSAndroid Build Coastguard Worker
709*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
710*c8dee2aaSAndroid Build Coastguard Worker // ARB allows mixed size FBO attachments, EXT does not.
711*c8dee2aaSAndroid Build Coastguard Worker if (version >= GR_GL_VER(3, 0) ||
712*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
713*c8dee2aaSAndroid Build Coastguard Worker fOversizedStencilSupport = true;
714*c8dee2aaSAndroid Build Coastguard Worker } else {
715*c8dee2aaSAndroid Build Coastguard Worker SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
716*c8dee2aaSAndroid Build Coastguard Worker }
717*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
718*c8dee2aaSAndroid Build Coastguard Worker // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
719*c8dee2aaSAndroid Build Coastguard Worker fOversizedStencilSupport = version >= GR_GL_VER(3, 0);
720*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(standard)) {
721*c8dee2aaSAndroid Build Coastguard Worker // WebGL 1.0 has some constraints for FBO attachments:
722*c8dee2aaSAndroid Build Coastguard Worker // https://www.khronos.org/registry/webgl/specs/1.0/index.html#6.6
723*c8dee2aaSAndroid Build Coastguard Worker // These constraints "no longer apply in WebGL 2"
724*c8dee2aaSAndroid Build Coastguard Worker fOversizedStencilSupport = version >= GR_GL_VER(2, 0);
725*c8dee2aaSAndroid Build Coastguard Worker }
726*c8dee2aaSAndroid Build Coastguard Worker
727*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
728*c8dee2aaSAndroid Build Coastguard Worker fBaseVertexBaseInstanceSupport = version >= GR_GL_VER(4,2) ||
729*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_ARB_base_instance");
730*c8dee2aaSAndroid Build Coastguard Worker if (fBaseVertexBaseInstanceSupport) {
731*c8dee2aaSAndroid Build Coastguard Worker fNativeDrawIndirectSupport = version >= GR_GL_VER(4,0) ||
732*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_ARB_draw_indirect");
733*c8dee2aaSAndroid Build Coastguard Worker if (version >= GR_GL_VER(4,3) || ctxInfo.hasExtension("GL_ARB_multi_draw_indirect")) {
734*c8dee2aaSAndroid Build Coastguard Worker fMultiDrawType = MultiDrawType::kMultiDrawIndirect;
735*c8dee2aaSAndroid Build Coastguard Worker }
736*c8dee2aaSAndroid Build Coastguard Worker }
737*c8dee2aaSAndroid Build Coastguard Worker fDrawRangeElementsSupport = version >= GR_GL_VER(2,0);
738*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
739*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.hasExtension("GL_ANGLE_base_vertex_base_instance")) {
740*c8dee2aaSAndroid Build Coastguard Worker fBaseVertexBaseInstanceSupport = true;
741*c8dee2aaSAndroid Build Coastguard Worker fNativeDrawIndirectSupport = true;
742*c8dee2aaSAndroid Build Coastguard Worker fMultiDrawType = MultiDrawType::kANGLEOrWebGL;
743*c8dee2aaSAndroid Build Coastguard Worker // The indirect structs need to reside in CPU memory for the ANGLE version.
744*c8dee2aaSAndroid Build Coastguard Worker fUseClientSideIndirectBuffers = true;
745*c8dee2aaSAndroid Build Coastguard Worker } else {
746*c8dee2aaSAndroid Build Coastguard Worker fBaseVertexBaseInstanceSupport = ctxInfo.hasExtension("GL_EXT_base_instance");
747*c8dee2aaSAndroid Build Coastguard Worker // Don't support indirect draws on ES. They don't allow VAO 0.
748*c8dee2aaSAndroid Build Coastguard Worker //
749*c8dee2aaSAndroid Build Coastguard Worker // "An INVALID_OPERATION error is generated if zero is bound to VERTEX_ARRAY_BINDING,
750*c8dee2aaSAndroid Build Coastguard Worker // DRAW_INDIRECT_BUFFER or to any enabled vertex array."
751*c8dee2aaSAndroid Build Coastguard Worker //
752*c8dee2aaSAndroid Build Coastguard Worker // https://www.khronos.org/registry/OpenGL/specs/es/3.1/es_spec_3.1.pdf
753*c8dee2aaSAndroid Build Coastguard Worker }
754*c8dee2aaSAndroid Build Coastguard Worker fDrawRangeElementsSupport = version >= GR_GL_VER(3,0);
755*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(standard)) {
756*c8dee2aaSAndroid Build Coastguard Worker fBaseVertexBaseInstanceSupport = ctxInfo.hasExtension(
757*c8dee2aaSAndroid Build Coastguard Worker "WEBGL_draw_instanced_base_vertex_base_instance");
758*c8dee2aaSAndroid Build Coastguard Worker if (fBaseVertexBaseInstanceSupport && ctxInfo.hasExtension(
759*c8dee2aaSAndroid Build Coastguard Worker "GL_WEBGL_multi_draw_instanced_base_vertex_base_instance")) {
760*c8dee2aaSAndroid Build Coastguard Worker fNativeDrawIndirectSupport = true;
761*c8dee2aaSAndroid Build Coastguard Worker fMultiDrawType = MultiDrawType::kANGLEOrWebGL;
762*c8dee2aaSAndroid Build Coastguard Worker }
763*c8dee2aaSAndroid Build Coastguard Worker // The indirect structs need to reside in CPU memory for the WebGL version.
764*c8dee2aaSAndroid Build Coastguard Worker fUseClientSideIndirectBuffers = true;
765*c8dee2aaSAndroid Build Coastguard Worker fDrawRangeElementsSupport = version >= GR_GL_VER(2,0);
766*c8dee2aaSAndroid Build Coastguard Worker }
767*c8dee2aaSAndroid Build Coastguard Worker // We used to disable this as a correctness workaround (http://anglebug.com/4536). Now it is
768*c8dee2aaSAndroid Build Coastguard Worker // disabled because of poor performance (http://skbug.com/11998).
769*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.angleBackend() == GrGLANGLEBackend::kD3D11) {
770*c8dee2aaSAndroid Build Coastguard Worker fBaseVertexBaseInstanceSupport = false;
771*c8dee2aaSAndroid Build Coastguard Worker fNativeDrawIndirectSupport = false;
772*c8dee2aaSAndroid Build Coastguard Worker fMultiDrawType = MultiDrawType::kNone;
773*c8dee2aaSAndroid Build Coastguard Worker }
774*c8dee2aaSAndroid Build Coastguard Worker
775*c8dee2aaSAndroid Build Coastguard Worker // We do not support GrBackendSemaphore for GL backends because the clients cannot really make
776*c8dee2aaSAndroid Build Coastguard Worker // GrGLsync objects ahead of time without talking to the GPU.
777*c8dee2aaSAndroid Build Coastguard Worker fBackendSemaphoreSupport = false;
778*c8dee2aaSAndroid Build Coastguard Worker // We prefer GL sync objects but also support NV_fence_sync. The former can be
779*c8dee2aaSAndroid Build Coastguard Worker // used to implement GrGLsync and GrSemaphore. The latter only implements GrGLsync.
780*c8dee2aaSAndroid Build Coastguard Worker // TODO: support CHROMIUM_sync_point and maybe KHR_fence_sync
781*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_WEBGL(standard)) {
782*c8dee2aaSAndroid Build Coastguard Worker // Only in WebGL 2.0
783*c8dee2aaSAndroid Build Coastguard Worker fSemaphoreSupport = fFenceSyncSupport = version >= GR_GL_VER(2, 0);
784*c8dee2aaSAndroid Build Coastguard Worker fFenceType = FenceType::kSyncObject;
785*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL(standard) &&
786*c8dee2aaSAndroid Build Coastguard Worker (version >= GR_GL_VER(3, 2) || ctxInfo.hasExtension("GL_ARB_sync"))) {
787*c8dee2aaSAndroid Build Coastguard Worker fSemaphoreSupport = fFenceSyncSupport = true;
788*c8dee2aaSAndroid Build Coastguard Worker fFenceType = FenceType::kSyncObject;
789*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard) &&
790*c8dee2aaSAndroid Build Coastguard Worker (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_APPLE_sync"))) {
791*c8dee2aaSAndroid Build Coastguard Worker fSemaphoreSupport = fFenceSyncSupport = true;
792*c8dee2aaSAndroid Build Coastguard Worker fFenceType = FenceType::kSyncObject;
793*c8dee2aaSAndroid Build Coastguard Worker } else if (ctxInfo.hasExtension("GL_NV_fence")) {
794*c8dee2aaSAndroid Build Coastguard Worker // This extension can exist in GL and GL ES. We have it last because we prefer the
795*c8dee2aaSAndroid Build Coastguard Worker // standard GLsync object implementation which also supports GPU semaphore semantics.
796*c8dee2aaSAndroid Build Coastguard Worker fFenceSyncSupport = true;
797*c8dee2aaSAndroid Build Coastguard Worker fFenceType = FenceType::kNVFence;
798*c8dee2aaSAndroid Build Coastguard Worker }
799*c8dee2aaSAndroid Build Coastguard Worker fFinishedProcAsyncCallbackSupport = fFenceSyncSupport;
800*c8dee2aaSAndroid Build Coastguard Worker
801*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_WEBGL(standard)) {
802*c8dee2aaSAndroid Build Coastguard Worker if (version >= GR_GL_VER(2, 0)) {
803*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.hasExtension("EXT_disjoint_timer_query_webgl2") ||
804*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_EXT_disjoint_timer_query_webgl2")) {
805*c8dee2aaSAndroid Build Coastguard Worker fTimerQueryType = TimerQueryType::kDisjoint;
806*c8dee2aaSAndroid Build Coastguard Worker }
807*c8dee2aaSAndroid Build Coastguard Worker } else {
808*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.hasExtension("EXT_disjoint_timer_query") ||
809*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_EXT_disjoint_timer_query")) {
810*c8dee2aaSAndroid Build Coastguard Worker fTimerQueryType = TimerQueryType::kDisjoint;
811*c8dee2aaSAndroid Build Coastguard Worker }
812*c8dee2aaSAndroid Build Coastguard Worker }
813*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
814*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.hasExtension("GL_EXT_disjoint_timer_query")) {
815*c8dee2aaSAndroid Build Coastguard Worker fTimerQueryType = TimerQueryType::kDisjoint;
816*c8dee2aaSAndroid Build Coastguard Worker }
817*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL(standard)) {
818*c8dee2aaSAndroid Build Coastguard Worker if (version >= GR_GL_VER(3, 3) || ctxInfo.hasExtension("GL_EXT_timer_query") ||
819*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_ARB_timer_query")) {
820*c8dee2aaSAndroid Build Coastguard Worker fTimerQueryType = TimerQueryType::kRegular;
821*c8dee2aaSAndroid Build Coastguard Worker }
822*c8dee2aaSAndroid Build Coastguard Worker }
823*c8dee2aaSAndroid Build Coastguard Worker if (fTimerQueryType != TimerQueryType::kNone) {
824*c8dee2aaSAndroid Build Coastguard Worker fSupportedGpuStats |= skgpu::GpuStatsFlags::kElapsedTime;
825*c8dee2aaSAndroid Build Coastguard Worker }
826*c8dee2aaSAndroid Build Coastguard Worker
827*c8dee2aaSAndroid Build Coastguard Worker // Safely moving textures between contexts requires semaphores.
828*c8dee2aaSAndroid Build Coastguard Worker fCrossContextTextureSupport = fSemaphoreSupport;
829*c8dee2aaSAndroid Build Coastguard Worker
830*c8dee2aaSAndroid Build Coastguard Worker // Half float vertex attributes requires GL3 or ES3
831*c8dee2aaSAndroid Build Coastguard Worker // It can also work with OES_VERTEX_HALF_FLOAT, but that requires a different enum.
832*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
833*c8dee2aaSAndroid Build Coastguard Worker fHalfFloatVertexAttributeSupport = (version >= GR_GL_VER(3, 0));
834*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
835*c8dee2aaSAndroid Build Coastguard Worker fHalfFloatVertexAttributeSupport = (version >= GR_GL_VER(3, 0));
836*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(standard)) {
837*c8dee2aaSAndroid Build Coastguard Worker // This appears to be supported in 2.0, looking at the spec.
838*c8dee2aaSAndroid Build Coastguard Worker fHalfFloatVertexAttributeSupport = (version >= GR_GL_VER(2, 0));
839*c8dee2aaSAndroid Build Coastguard Worker }
840*c8dee2aaSAndroid Build Coastguard Worker
841*c8dee2aaSAndroid Build Coastguard Worker fDynamicStateArrayGeometryProcessorTextureSupport = true;
842*c8dee2aaSAndroid Build Coastguard Worker
843*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
844*c8dee2aaSAndroid Build Coastguard Worker fProgramBinarySupport = (version >= GR_GL_VER(4, 1));
845*c8dee2aaSAndroid Build Coastguard Worker fProgramParameterSupport = (version >= GR_GL_VER(4, 1));
846*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
847*c8dee2aaSAndroid Build Coastguard Worker fProgramBinarySupport =
848*c8dee2aaSAndroid Build Coastguard Worker (version >= GR_GL_VER(3, 0)) || ctxInfo.hasExtension("GL_OES_get_program_binary");
849*c8dee2aaSAndroid Build Coastguard Worker fProgramParameterSupport = (version >= GR_GL_VER(3, 0));
850*c8dee2aaSAndroid Build Coastguard Worker } // Explicitly not supported in WebGL 2.0
851*c8dee2aaSAndroid Build Coastguard Worker // https://www.khronos.org/registry/webgl/specs/2.0/#5.4
852*c8dee2aaSAndroid Build Coastguard Worker if (fProgramBinarySupport) {
853*c8dee2aaSAndroid Build Coastguard Worker GrGLint count;
854*c8dee2aaSAndroid Build Coastguard Worker GR_GL_GetIntegerv(gli, GR_GL_NUM_PROGRAM_BINARY_FORMATS, &count);
855*c8dee2aaSAndroid Build Coastguard Worker if (count > 0) {
856*c8dee2aaSAndroid Build Coastguard Worker fProgramBinaryFormats.resize_back(count);
857*c8dee2aaSAndroid Build Coastguard Worker GR_GL_GetIntegerv(gli, GR_GL_PROGRAM_BINARY_FORMATS,
858*c8dee2aaSAndroid Build Coastguard Worker reinterpret_cast<GrGLint*>(fProgramBinaryFormats.data()));
859*c8dee2aaSAndroid Build Coastguard Worker } else {
860*c8dee2aaSAndroid Build Coastguard Worker fProgramBinarySupport = false;
861*c8dee2aaSAndroid Build Coastguard Worker }
862*c8dee2aaSAndroid Build Coastguard Worker }
863*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
864*c8dee2aaSAndroid Build Coastguard Worker fSamplerObjectSupport =
865*c8dee2aaSAndroid Build Coastguard Worker version >= GR_GL_VER(3,3) || ctxInfo.hasExtension("GL_ARB_sampler_objects");
866*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
867*c8dee2aaSAndroid Build Coastguard Worker fSamplerObjectSupport = version >= GR_GL_VER(3,0);
868*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(standard)) {
869*c8dee2aaSAndroid Build Coastguard Worker fSamplerObjectSupport = version >= GR_GL_VER(2,0);
870*c8dee2aaSAndroid Build Coastguard Worker }
871*c8dee2aaSAndroid Build Coastguard Worker // We currently use sampler objects whenever they are available.
872*c8dee2aaSAndroid Build Coastguard Worker fUseSamplerObjects = fSamplerObjectSupport;
873*c8dee2aaSAndroid Build Coastguard Worker
874*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL_ES(standard)) {
875*c8dee2aaSAndroid Build Coastguard Worker fTiledRenderingSupport = ctxInfo.hasExtension("GL_QCOM_tiled_rendering");
876*c8dee2aaSAndroid Build Coastguard Worker }
877*c8dee2aaSAndroid Build Coastguard Worker
878*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.vendor() == GrGLVendor::kARM) {
879*c8dee2aaSAndroid Build Coastguard Worker fShouldCollapseSrcOverToSrcWhenAble = true;
880*c8dee2aaSAndroid Build Coastguard Worker }
881*c8dee2aaSAndroid Build Coastguard Worker
882*c8dee2aaSAndroid Build Coastguard Worker #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
883*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.renderer() == GrGLRenderer::kPowerVRRogue) {
884*c8dee2aaSAndroid Build Coastguard Worker // https://b/195281495
885*c8dee2aaSAndroid Build Coastguard Worker // The TecnoSpark 3 Pro with a PowerVR GE8300 seems to have a steep dithering performance
886*c8dee2aaSAndroid Build Coastguard Worker // cliff in the Android Framework
887*c8dee2aaSAndroid Build Coastguard Worker fAvoidDithering = true;
888*c8dee2aaSAndroid Build Coastguard Worker }
889*c8dee2aaSAndroid Build Coastguard Worker #endif
890*c8dee2aaSAndroid Build Coastguard Worker
891*c8dee2aaSAndroid Build Coastguard Worker FormatWorkarounds formatWorkarounds;
892*c8dee2aaSAndroid Build Coastguard Worker
893*c8dee2aaSAndroid Build Coastguard Worker if (!contextOptions.fDisableDriverCorrectnessWorkarounds) {
894*c8dee2aaSAndroid Build Coastguard Worker this->applyDriverCorrectnessWorkarounds(ctxInfo, contextOptions, gli, shaderCaps,
895*c8dee2aaSAndroid Build Coastguard Worker &formatWorkarounds);
896*c8dee2aaSAndroid Build Coastguard Worker }
897*c8dee2aaSAndroid Build Coastguard Worker
898*c8dee2aaSAndroid Build Coastguard Worker // Requires msaa support, ES compatibility have already been detected.
899*c8dee2aaSAndroid Build Coastguard Worker this->initFormatTable(ctxInfo, gli, formatWorkarounds);
900*c8dee2aaSAndroid Build Coastguard Worker
901*c8dee2aaSAndroid Build Coastguard Worker this->finishInitialization(contextOptions);
902*c8dee2aaSAndroid Build Coastguard Worker
903*c8dee2aaSAndroid Build Coastguard Worker // For GL, besides the user-specifiable override, we also want to avoid stencil buffers
904*c8dee2aaSAndroid Build Coastguard Worker // in Protected mode (to avoid using RenderBuffers)
905*c8dee2aaSAndroid Build Coastguard Worker fAvoidStencilBuffers = contextOptions.fAvoidStencilBuffers || fSupportsProtectedContent;
906*c8dee2aaSAndroid Build Coastguard Worker
907*c8dee2aaSAndroid Build Coastguard Worker // For now these two are equivalent but we could have dst read in shader via some other method.
908*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fDstReadInShaderSupport = shaderCaps->fFBFetchSupport;
909*c8dee2aaSAndroid Build Coastguard Worker }
910*c8dee2aaSAndroid Build Coastguard Worker
get_glsl_version_decl_string(GrGLStandard standard,SkSL::GLSLGeneration generation,bool isCoreProfile)911*c8dee2aaSAndroid Build Coastguard Worker const char* get_glsl_version_decl_string(GrGLStandard standard, SkSL::GLSLGeneration generation,
912*c8dee2aaSAndroid Build Coastguard Worker bool isCoreProfile) {
913*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
914*c8dee2aaSAndroid Build Coastguard Worker switch (generation) {
915*c8dee2aaSAndroid Build Coastguard Worker case SkSL::GLSLGeneration::k110:
916*c8dee2aaSAndroid Build Coastguard Worker return "#version 110\n";
917*c8dee2aaSAndroid Build Coastguard Worker case SkSL::GLSLGeneration::k130:
918*c8dee2aaSAndroid Build Coastguard Worker return "#version 130\n";
919*c8dee2aaSAndroid Build Coastguard Worker case SkSL::GLSLGeneration::k140:
920*c8dee2aaSAndroid Build Coastguard Worker return "#version 140\n";
921*c8dee2aaSAndroid Build Coastguard Worker case SkSL::GLSLGeneration::k150:
922*c8dee2aaSAndroid Build Coastguard Worker if (isCoreProfile) {
923*c8dee2aaSAndroid Build Coastguard Worker return "#version 150\n";
924*c8dee2aaSAndroid Build Coastguard Worker } else {
925*c8dee2aaSAndroid Build Coastguard Worker return "#version 150 compatibility\n";
926*c8dee2aaSAndroid Build Coastguard Worker }
927*c8dee2aaSAndroid Build Coastguard Worker case SkSL::GLSLGeneration::k330:
928*c8dee2aaSAndroid Build Coastguard Worker if (isCoreProfile) {
929*c8dee2aaSAndroid Build Coastguard Worker return "#version 330\n";
930*c8dee2aaSAndroid Build Coastguard Worker } else {
931*c8dee2aaSAndroid Build Coastguard Worker return "#version 330 compatibility\n";
932*c8dee2aaSAndroid Build Coastguard Worker }
933*c8dee2aaSAndroid Build Coastguard Worker case SkSL::GLSLGeneration::k400:
934*c8dee2aaSAndroid Build Coastguard Worker if (isCoreProfile) {
935*c8dee2aaSAndroid Build Coastguard Worker return "#version 400\n";
936*c8dee2aaSAndroid Build Coastguard Worker } else {
937*c8dee2aaSAndroid Build Coastguard Worker return "#version 400 compatibility\n";
938*c8dee2aaSAndroid Build Coastguard Worker }
939*c8dee2aaSAndroid Build Coastguard Worker case SkSL::GLSLGeneration::k420:
940*c8dee2aaSAndroid Build Coastguard Worker if (isCoreProfile) {
941*c8dee2aaSAndroid Build Coastguard Worker return "#version 420\n";
942*c8dee2aaSAndroid Build Coastguard Worker } else {
943*c8dee2aaSAndroid Build Coastguard Worker return "#version 420 compatibility\n";
944*c8dee2aaSAndroid Build Coastguard Worker }
945*c8dee2aaSAndroid Build Coastguard Worker default:
946*c8dee2aaSAndroid Build Coastguard Worker break;
947*c8dee2aaSAndroid Build Coastguard Worker }
948*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard) || GR_IS_GR_WEBGL(standard)) {
949*c8dee2aaSAndroid Build Coastguard Worker switch (generation) {
950*c8dee2aaSAndroid Build Coastguard Worker case SkSL::GLSLGeneration::k100es:
951*c8dee2aaSAndroid Build Coastguard Worker return "#version 100\n";
952*c8dee2aaSAndroid Build Coastguard Worker case SkSL::GLSLGeneration::k300es:
953*c8dee2aaSAndroid Build Coastguard Worker return "#version 300 es\n";
954*c8dee2aaSAndroid Build Coastguard Worker case SkSL::GLSLGeneration::k310es:
955*c8dee2aaSAndroid Build Coastguard Worker return "#version 310 es\n";
956*c8dee2aaSAndroid Build Coastguard Worker case SkSL::GLSLGeneration::k320es:
957*c8dee2aaSAndroid Build Coastguard Worker return "#version 320 es\n";
958*c8dee2aaSAndroid Build Coastguard Worker default:
959*c8dee2aaSAndroid Build Coastguard Worker break;
960*c8dee2aaSAndroid Build Coastguard Worker }
961*c8dee2aaSAndroid Build Coastguard Worker }
962*c8dee2aaSAndroid Build Coastguard Worker return "<no version>";
963*c8dee2aaSAndroid Build Coastguard Worker }
964*c8dee2aaSAndroid Build Coastguard Worker
is_float_fp32(const GrGLContextInfo & ctxInfo,const GrGLInterface * gli,GrGLenum precision)965*c8dee2aaSAndroid Build Coastguard Worker bool is_float_fp32(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli, GrGLenum precision) {
966*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(ctxInfo.standard()) &&
967*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.version() < GR_GL_VER(4,1) &&
968*c8dee2aaSAndroid Build Coastguard Worker !ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
969*c8dee2aaSAndroid Build Coastguard Worker // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
970*c8dee2aaSAndroid Build Coastguard Worker return true;
971*c8dee2aaSAndroid Build Coastguard Worker }
972*c8dee2aaSAndroid Build Coastguard Worker // glGetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Hopefully the
973*c8dee2aaSAndroid Build Coastguard Worker // geometry shaders don't have lower precision than vertex and fragment.
974*c8dee2aaSAndroid Build Coastguard Worker for (GrGLenum shader : {GR_GL_FRAGMENT_SHADER, GR_GL_VERTEX_SHADER}) {
975*c8dee2aaSAndroid Build Coastguard Worker GrGLint range[2];
976*c8dee2aaSAndroid Build Coastguard Worker GrGLint bits;
977*c8dee2aaSAndroid Build Coastguard Worker GR_GL_GetShaderPrecisionFormat(gli, shader, precision, range, &bits);
978*c8dee2aaSAndroid Build Coastguard Worker if (range[0] < 127 || range[1] < 127 || bits < 23) {
979*c8dee2aaSAndroid Build Coastguard Worker return false;
980*c8dee2aaSAndroid Build Coastguard Worker }
981*c8dee2aaSAndroid Build Coastguard Worker }
982*c8dee2aaSAndroid Build Coastguard Worker return true;
983*c8dee2aaSAndroid Build Coastguard Worker }
984*c8dee2aaSAndroid Build Coastguard Worker
initGLSL(const GrGLContextInfo & ctxInfo,const GrGLInterface * gli)985*c8dee2aaSAndroid Build Coastguard Worker void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
986*c8dee2aaSAndroid Build Coastguard Worker GrGLStandard standard = ctxInfo.standard();
987*c8dee2aaSAndroid Build Coastguard Worker GrGLVersion version = ctxInfo.version();
988*c8dee2aaSAndroid Build Coastguard Worker
989*c8dee2aaSAndroid Build Coastguard Worker /**************************************************************************
990*c8dee2aaSAndroid Build Coastguard Worker * Caps specific to GrShaderCaps
991*c8dee2aaSAndroid Build Coastguard Worker **************************************************************************/
992*c8dee2aaSAndroid Build Coastguard Worker
993*c8dee2aaSAndroid Build Coastguard Worker GrShaderCaps* shaderCaps = fShaderCaps.get();
994*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fGLSLGeneration = ctxInfo.glslGeneration();
995*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL_ES(standard)) {
996*c8dee2aaSAndroid Build Coastguard Worker // fFBFetchRequiresEnablePerSample is not a shader cap but is initialized below to keep it
997*c8dee2aaSAndroid Build Coastguard Worker // with related FB fetch logic.
998*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
999*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
1000*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fFBFetchSupport = true;
1001*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fFBFetchColorName = "gl_LastFragData[0]";
1002*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
1003*c8dee2aaSAndroid Build Coastguard Worker fFBFetchRequiresEnablePerSample = false;
1004*c8dee2aaSAndroid Build Coastguard Worker } else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
1005*c8dee2aaSAndroid Build Coastguard Worker // Actually, we haven't seen an ES3.0 device with this extension yet, so we don't know.
1006*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fFBFetchNeedsCustomOutput = false;
1007*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fFBFetchSupport = true;
1008*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fFBFetchColorName = "gl_LastFragData[0]";
1009*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
1010*c8dee2aaSAndroid Build Coastguard Worker fFBFetchRequiresEnablePerSample = false;
1011*c8dee2aaSAndroid Build Coastguard Worker } else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
1012*c8dee2aaSAndroid Build Coastguard Worker // The arm extension also requires an additional flag which we will set onResetContext.
1013*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fFBFetchNeedsCustomOutput = false;
1014*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fFBFetchSupport = true;
1015*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fFBFetchColorName = "gl_LastFragColorARM";
1016*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
1017*c8dee2aaSAndroid Build Coastguard Worker fFBFetchRequiresEnablePerSample = true;
1018*c8dee2aaSAndroid Build Coastguard Worker }
1019*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fUsesPrecisionModifiers = true;
1020*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL(standard)) {
1021*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
1022*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
1023*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fFBFetchSupport = true;
1024*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fFBFetchColorName = "gl_LastFragData[0]";
1025*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
1026*c8dee2aaSAndroid Build Coastguard Worker fFBFetchRequiresEnablePerSample = false;
1027*c8dee2aaSAndroid Build Coastguard Worker }
1028*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(standard)) {
1029*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fUsesPrecisionModifiers = true;
1030*c8dee2aaSAndroid Build Coastguard Worker }
1031*c8dee2aaSAndroid Build Coastguard Worker
1032*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
1033*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fFlatInterpolationSupport =
1034*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k130;
1035*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard) || GR_IS_GR_WEBGL(standard)) {
1036*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fFlatInterpolationSupport =
1037*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k300es;
1038*c8dee2aaSAndroid Build Coastguard Worker } // not sure for WebGL
1039*c8dee2aaSAndroid Build Coastguard Worker
1040*c8dee2aaSAndroid Build Coastguard Worker // Flat interpolation appears to be slow on Qualcomm GPUs (tested Adreno 405 and 530).
1041*c8dee2aaSAndroid Build Coastguard Worker // Avoid on ANGLE too, it inserts a geometry shader into the pipeline to implement flat interp.
1042*c8dee2aaSAndroid Build Coastguard Worker // Is this only true on ANGLE's D3D backends or also on the GL backend?
1043*c8dee2aaSAndroid Build Coastguard Worker // Flat interpolation is slow with ANGLE's Metal backend and uses memory to rewrite index
1044*c8dee2aaSAndroid Build Coastguard Worker // buffers to support GL's provoking vertex semantics.
1045*c8dee2aaSAndroid Build Coastguard Worker // Never prefer flat shading on WebGL. GPU detection isn't as robust (e.g.
1046*c8dee2aaSAndroid Build Coastguard Worker // WEBGL_debug_renderer_info may not be enabled and strings may be masked), the perf benefits
1047*c8dee2aaSAndroid Build Coastguard Worker // are minimal, and potential cost is high (e.g. on ANGLE Metal backend).
1048*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fPreferFlatInterpolation = !GR_IS_GR_WEBGL(standard) &&
1049*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fFlatInterpolationSupport &&
1050*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.vendor() != GrGLVendor::kQualcomm &&
1051*c8dee2aaSAndroid Build Coastguard Worker !angle_backend_is_d3d(ctxInfo.angleBackend()) &&
1052*c8dee2aaSAndroid Build Coastguard Worker !angle_backend_is_metal(ctxInfo.angleBackend());
1053*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
1054*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fNoPerspectiveInterpolationSupport =
1055*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k130;
1056*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
1057*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.hasExtension("GL_NV_shader_noperspective_interpolation") &&
1058*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k300es) {
1059*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fNoPerspectiveInterpolationSupport = true;
1060*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fNoPerspectiveInterpolationExtensionString =
1061*c8dee2aaSAndroid Build Coastguard Worker "GL_NV_shader_noperspective_interpolation";
1062*c8dee2aaSAndroid Build Coastguard Worker }
1063*c8dee2aaSAndroid Build Coastguard Worker } // Not sure for WebGL
1064*c8dee2aaSAndroid Build Coastguard Worker
1065*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
1066*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fSampleMaskSupport = ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k400;
1067*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
1068*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k320es) {
1069*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fSampleMaskSupport = true;
1070*c8dee2aaSAndroid Build Coastguard Worker } else if (ctxInfo.hasExtension("GL_OES_sample_variables")) {
1071*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fSampleMaskSupport = true;
1072*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fSampleVariablesExtensionString = "GL_OES_sample_variables";
1073*c8dee2aaSAndroid Build Coastguard Worker }
1074*c8dee2aaSAndroid Build Coastguard Worker }
1075*c8dee2aaSAndroid Build Coastguard Worker
1076*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fVersionDeclString = get_glsl_version_decl_string(standard,
1077*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fGLSLGeneration,
1078*c8dee2aaSAndroid Build Coastguard Worker fIsCoreProfile);
1079*c8dee2aaSAndroid Build Coastguard Worker
1080*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL_ES(standard) || GR_IS_GR_WEBGL(standard)) {
1081*c8dee2aaSAndroid Build Coastguard Worker if (SkSL::GLSLGeneration::k100es == shaderCaps->fGLSLGeneration) {
1082*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
1083*c8dee2aaSAndroid Build Coastguard Worker }
1084*c8dee2aaSAndroid Build Coastguard Worker } // WebGL might have to check for OES_standard_derivatives
1085*c8dee2aaSAndroid Build Coastguard Worker
1086*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL_ES(standard)) {
1087*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fSecondaryOutputExtensionString = "GL_EXT_blend_func_extended";
1088*c8dee2aaSAndroid Build Coastguard Worker }
1089*c8dee2aaSAndroid Build Coastguard Worker
1090*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.hasExtension("GL_OES_EGL_image_external")) {
1091*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.glslGeneration() == SkSL::GLSLGeneration::k100es) {
1092*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fExternalTextureSupport = true;
1093*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
1094*c8dee2aaSAndroid Build Coastguard Worker } else if (ctxInfo.hasExtension("GL_OES_EGL_image_external_essl3") ||
1095*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("OES_EGL_image_external_essl3")) {
1096*c8dee2aaSAndroid Build Coastguard Worker // At least one driver has been found that has this extension without the "GL_" prefix.
1097*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fExternalTextureSupport = true;
1098*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
1099*c8dee2aaSAndroid Build Coastguard Worker }
1100*c8dee2aaSAndroid Build Coastguard Worker }
1101*c8dee2aaSAndroid Build Coastguard Worker
1102*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
1103*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fVertexIDSupport = true;
1104*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard) || GR_IS_GR_WEBGL(standard)) {
1105*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fVertexIDSupport = ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k300es;
1106*c8dee2aaSAndroid Build Coastguard Worker }
1107*c8dee2aaSAndroid Build Coastguard Worker
1108*c8dee2aaSAndroid Build Coastguard Worker // isinf() exists in GLSL 1.3 and above, but hardware without proper IEEE support is allowed to
1109*c8dee2aaSAndroid Build Coastguard Worker // always return false, so it's potentially meaningless. In GLSL 3.3 and GLSL ES3+, isinf() is
1110*c8dee2aaSAndroid Build Coastguard Worker // required to actually identify infinite values. (GPUs are not required to _produce_ infinite
1111*c8dee2aaSAndroid Build Coastguard Worker // values via operations like `num / 0.0` until GLSL 4.1.)
1112*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fInfinitySupport = (ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k330);
1113*c8dee2aaSAndroid Build Coastguard Worker
1114*c8dee2aaSAndroid Build Coastguard Worker // Using isinf or isnan with ANGLE will disable fast-math (which is a good thing!), but that
1115*c8dee2aaSAndroid Build Coastguard Worker // leads to hangs in the Metal shader compiler service for some of our tessellation shaders,
1116*c8dee2aaSAndroid Build Coastguard Worker // running on Intel Macs. For now, pretend that we don't have infinity support, even when we're
1117*c8dee2aaSAndroid Build Coastguard Worker // targeting ANGLE's ES3 to Metal.
1118*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.angleBackend() == GrGLANGLEBackend::kMetal &&
1119*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.angleVendor() == GrGLVendor::kIntel) {
1120*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fInfinitySupport = false;
1121*c8dee2aaSAndroid Build Coastguard Worker }
1122*c8dee2aaSAndroid Build Coastguard Worker
1123*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
1124*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fNonconstantArrayIndexSupport = true;
1125*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard) || GR_IS_GR_WEBGL(standard)) {
1126*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fNonconstantArrayIndexSupport =
1127*c8dee2aaSAndroid Build Coastguard Worker (ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k300es);
1128*c8dee2aaSAndroid Build Coastguard Worker }
1129*c8dee2aaSAndroid Build Coastguard Worker
1130*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
1131*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fBitManipulationSupport =
1132*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k400;
1133*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard) || GR_IS_GR_WEBGL(standard)) {
1134*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fBitManipulationSupport =
1135*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k310es;
1136*c8dee2aaSAndroid Build Coastguard Worker }
1137*c8dee2aaSAndroid Build Coastguard Worker
1138*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fFloatIs32Bits = is_float_fp32(ctxInfo, gli, GR_GL_HIGH_FLOAT);
1139*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fHalfIs32Bits = is_float_fp32(ctxInfo, gli, GR_GL_MEDIUM_FLOAT);
1140*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fHasLowFragmentPrecision = ctxInfo.renderer() == GrGLRenderer::kMali4xx;
1141*c8dee2aaSAndroid Build Coastguard Worker
1142*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
1143*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fBuiltinFMASupport =
1144*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k400;
1145*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
1146*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fBuiltinFMASupport =
1147*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k320es;
1148*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(standard)) {
1149*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fBuiltinFMASupport = false;
1150*c8dee2aaSAndroid Build Coastguard Worker }
1151*c8dee2aaSAndroid Build Coastguard Worker
1152*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fBuiltinDeterminantSupport = ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k150;
1153*c8dee2aaSAndroid Build Coastguard Worker }
1154*c8dee2aaSAndroid Build Coastguard Worker
initFSAASupport(const GrContextOptions & contextOptions,const GrGLContextInfo & ctxInfo,const GrGLInterface * gli)1155*c8dee2aaSAndroid Build Coastguard Worker void GrGLCaps::initFSAASupport(const GrContextOptions& contextOptions,
1156*c8dee2aaSAndroid Build Coastguard Worker const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
1157*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(ctxInfo.standard())) {
1158*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.version() >= GR_GL_VER(3,0) ||
1159*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
1160*c8dee2aaSAndroid Build Coastguard Worker fMSFBOType = kStandard_MSFBOType;
1161*c8dee2aaSAndroid Build Coastguard Worker } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
1162*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
1163*c8dee2aaSAndroid Build Coastguard Worker fMSFBOType = kStandard_MSFBOType;
1164*c8dee2aaSAndroid Build Coastguard Worker }
1165*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(ctxInfo.standard())) {
1166*c8dee2aaSAndroid Build Coastguard Worker // We prefer multisampled-render-to-texture extensions over ES3 MSAA because we've observed
1167*c8dee2aaSAndroid Build Coastguard Worker // ES3 driver bugs on at least one device with a tiled GPU (N10).
1168*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
1169*c8dee2aaSAndroid Build Coastguard Worker fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
1170*c8dee2aaSAndroid Build Coastguard Worker fMSAAResolvesAutomatically = true;
1171*c8dee2aaSAndroid Build Coastguard Worker } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
1172*c8dee2aaSAndroid Build Coastguard Worker fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
1173*c8dee2aaSAndroid Build Coastguard Worker fMSAAResolvesAutomatically = true;
1174*c8dee2aaSAndroid Build Coastguard Worker } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
1175*c8dee2aaSAndroid Build Coastguard Worker fMSFBOType = kStandard_MSFBOType;
1176*c8dee2aaSAndroid Build Coastguard Worker } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
1177*c8dee2aaSAndroid Build Coastguard Worker fMSFBOType = kStandard_MSFBOType;
1178*c8dee2aaSAndroid Build Coastguard Worker } else if (ctxInfo.hasExtension("GL_ANGLE_framebuffer_multisample")) {
1179*c8dee2aaSAndroid Build Coastguard Worker fMSFBOType = kStandard_MSFBOType;
1180*c8dee2aaSAndroid Build Coastguard Worker } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
1181*c8dee2aaSAndroid Build Coastguard Worker fMSFBOType = kES_Apple_MSFBOType;
1182*c8dee2aaSAndroid Build Coastguard Worker }
1183*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(ctxInfo.standard())) {
1184*c8dee2aaSAndroid Build Coastguard Worker // No support in WebGL 1, but there is for 2.0
1185*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.version() >= GR_GL_VER(2,0)) {
1186*c8dee2aaSAndroid Build Coastguard Worker fMSFBOType = kStandard_MSFBOType;
1187*c8dee2aaSAndroid Build Coastguard Worker } else {
1188*c8dee2aaSAndroid Build Coastguard Worker fMSFBOType = kNone_MSFBOType;
1189*c8dee2aaSAndroid Build Coastguard Worker }
1190*c8dee2aaSAndroid Build Coastguard Worker }
1191*c8dee2aaSAndroid Build Coastguard Worker }
1192*c8dee2aaSAndroid Build Coastguard Worker
initBlendEqationSupport(const GrGLContextInfo & ctxInfo)1193*c8dee2aaSAndroid Build Coastguard Worker void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
1194*c8dee2aaSAndroid Build Coastguard Worker GrShaderCaps* shaderCaps = static_cast<GrShaderCaps*>(fShaderCaps.get());
1195*c8dee2aaSAndroid Build Coastguard Worker
1196*c8dee2aaSAndroid Build Coastguard Worker bool layoutQualifierSupport = false;
1197*c8dee2aaSAndroid Build Coastguard Worker if ((GR_IS_GR_GL(fStandard) && shaderCaps->fGLSLGeneration >= SkSL::GLSLGeneration::k140) ||
1198*c8dee2aaSAndroid Build Coastguard Worker (GR_IS_GR_GL_ES(fStandard) && shaderCaps->fGLSLGeneration >= SkSL::GLSLGeneration::k300es)){
1199*c8dee2aaSAndroid Build Coastguard Worker layoutQualifierSupport = true;
1200*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(fStandard)) {
1201*c8dee2aaSAndroid Build Coastguard Worker return;
1202*c8dee2aaSAndroid Build Coastguard Worker }
1203*c8dee2aaSAndroid Build Coastguard Worker
1204*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
1205*c8dee2aaSAndroid Build Coastguard Worker fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
1206*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction;
1207*c8dee2aaSAndroid Build Coastguard Worker } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent") &&
1208*c8dee2aaSAndroid Build Coastguard Worker layoutQualifierSupport) {
1209*c8dee2aaSAndroid Build Coastguard Worker fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
1210*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kGeneralEnable_AdvBlendEqInteraction;
1211*c8dee2aaSAndroid Build Coastguard Worker } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
1212*c8dee2aaSAndroid Build Coastguard Worker fBlendEquationSupport = kAdvanced_BlendEquationSupport;
1213*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction;
1214*c8dee2aaSAndroid Build Coastguard Worker } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced") && layoutQualifierSupport) {
1215*c8dee2aaSAndroid Build Coastguard Worker fBlendEquationSupport = kAdvanced_BlendEquationSupport;
1216*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kGeneralEnable_AdvBlendEqInteraction;
1217*c8dee2aaSAndroid Build Coastguard Worker }
1218*c8dee2aaSAndroid Build Coastguard Worker }
1219*c8dee2aaSAndroid Build Coastguard Worker
1220*c8dee2aaSAndroid Build Coastguard Worker
initStencilSupport(const GrGLContextInfo & ctxInfo)1221*c8dee2aaSAndroid Build Coastguard Worker void GrGLCaps::initStencilSupport(const GrGLContextInfo& ctxInfo) {
1222*c8dee2aaSAndroid Build Coastguard Worker
1223*c8dee2aaSAndroid Build Coastguard Worker // Build up list of legal stencil formats (though perhaps not supported on
1224*c8dee2aaSAndroid Build Coastguard Worker // the particular gpu/driver) from most preferred to least.
1225*c8dee2aaSAndroid Build Coastguard Worker
1226*c8dee2aaSAndroid Build Coastguard Worker // We push back stencil formats onto the fStencilFormats array in order of most preferred to
1227*c8dee2aaSAndroid Build Coastguard Worker // least preferred.
1228*c8dee2aaSAndroid Build Coastguard Worker
1229*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(ctxInfo.standard())) {
1230*c8dee2aaSAndroid Build Coastguard Worker bool supportsPackedDS =
1231*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.version() >= GR_GL_VER(3,0) ||
1232*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
1233*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_ARB_framebuffer_object");
1234*c8dee2aaSAndroid Build Coastguard Worker
1235*c8dee2aaSAndroid Build Coastguard Worker // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
1236*c8dee2aaSAndroid Build Coastguard Worker // require FBO support we can expect these are legal formats and don't
1237*c8dee2aaSAndroid Build Coastguard Worker // check.
1238*c8dee2aaSAndroid Build Coastguard Worker fStencilFormats.push_back() = GrGLFormat::kSTENCIL_INDEX8;
1239*c8dee2aaSAndroid Build Coastguard Worker fStencilFormats.push_back() = GrGLFormat::kSTENCIL_INDEX16;
1240*c8dee2aaSAndroid Build Coastguard Worker if (supportsPackedDS) {
1241*c8dee2aaSAndroid Build Coastguard Worker fStencilFormats.push_back() = GrGLFormat::kDEPTH24_STENCIL8;
1242*c8dee2aaSAndroid Build Coastguard Worker }
1243*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(ctxInfo.standard())) {
1244*c8dee2aaSAndroid Build Coastguard Worker // ES2 has STENCIL_INDEX8 without extensions but requires extensions
1245*c8dee2aaSAndroid Build Coastguard Worker // for other formats.
1246*c8dee2aaSAndroid Build Coastguard Worker
1247*c8dee2aaSAndroid Build Coastguard Worker fStencilFormats.push_back() = GrGLFormat::kSTENCIL_INDEX8;
1248*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.version() >= GR_GL_VER(3,0) ||
1249*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
1250*c8dee2aaSAndroid Build Coastguard Worker fStencilFormats.push_back() = GrGLFormat::kDEPTH24_STENCIL8;
1251*c8dee2aaSAndroid Build Coastguard Worker }
1252*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(ctxInfo.standard())) {
1253*c8dee2aaSAndroid Build Coastguard Worker fStencilFormats.push_back() = GrGLFormat::kSTENCIL_INDEX8;
1254*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.version() >= GR_GL_VER(2,0)) {
1255*c8dee2aaSAndroid Build Coastguard Worker fStencilFormats.push_back() = GrGLFormat::kDEPTH24_STENCIL8;
1256*c8dee2aaSAndroid Build Coastguard Worker }
1257*c8dee2aaSAndroid Build Coastguard Worker }
1258*c8dee2aaSAndroid Build Coastguard Worker }
1259*c8dee2aaSAndroid Build Coastguard Worker
1260*c8dee2aaSAndroid Build Coastguard Worker #ifdef SK_ENABLE_DUMP_GPU
1261*c8dee2aaSAndroid Build Coastguard Worker #include "src/utils/SkJSONWriter.h"
1262*c8dee2aaSAndroid Build Coastguard Worker
multi_draw_type_name(GrGLCaps::MultiDrawType multiDrawType)1263*c8dee2aaSAndroid Build Coastguard Worker static const char* multi_draw_type_name(GrGLCaps::MultiDrawType multiDrawType) {
1264*c8dee2aaSAndroid Build Coastguard Worker switch (multiDrawType) {
1265*c8dee2aaSAndroid Build Coastguard Worker case GrGLCaps::MultiDrawType::kNone : return "kNone";
1266*c8dee2aaSAndroid Build Coastguard Worker case GrGLCaps::MultiDrawType::kMultiDrawIndirect : return "kMultiDrawIndirect";
1267*c8dee2aaSAndroid Build Coastguard Worker case GrGLCaps::MultiDrawType::kANGLEOrWebGL : return "kMultiDrawIndirect";
1268*c8dee2aaSAndroid Build Coastguard Worker }
1269*c8dee2aaSAndroid Build Coastguard Worker SkUNREACHABLE;
1270*c8dee2aaSAndroid Build Coastguard Worker }
1271*c8dee2aaSAndroid Build Coastguard Worker
onDumpJSON(SkJSONWriter * writer) const1272*c8dee2aaSAndroid Build Coastguard Worker void GrGLCaps::onDumpJSON(SkJSONWriter* writer) const {
1273*c8dee2aaSAndroid Build Coastguard Worker
1274*c8dee2aaSAndroid Build Coastguard Worker // We are called by the base class, which has already called beginObject(). We choose to nest
1275*c8dee2aaSAndroid Build Coastguard Worker // all of our caps information in a named sub-object.
1276*c8dee2aaSAndroid Build Coastguard Worker writer->beginObject("GL caps");
1277*c8dee2aaSAndroid Build Coastguard Worker
1278*c8dee2aaSAndroid Build Coastguard Worker writer->beginArray("Stencil Formats");
1279*c8dee2aaSAndroid Build Coastguard Worker
1280*c8dee2aaSAndroid Build Coastguard Worker for (int i = 0; i < fStencilFormats.size(); ++i) {
1281*c8dee2aaSAndroid Build Coastguard Worker writer->beginObject(nullptr, false);
1282*c8dee2aaSAndroid Build Coastguard Worker writer->appendS32("stencil bits", GrGLFormatStencilBits(fStencilFormats[i]));
1283*c8dee2aaSAndroid Build Coastguard Worker writer->appendS32("total bytes", GrGLFormatBytesPerBlock(fStencilFormats[i]));
1284*c8dee2aaSAndroid Build Coastguard Worker writer->endObject();
1285*c8dee2aaSAndroid Build Coastguard Worker }
1286*c8dee2aaSAndroid Build Coastguard Worker
1287*c8dee2aaSAndroid Build Coastguard Worker writer->endArray();
1288*c8dee2aaSAndroid Build Coastguard Worker
1289*c8dee2aaSAndroid Build Coastguard Worker auto msfboStr = [&] {
1290*c8dee2aaSAndroid Build Coastguard Worker switch (fMSFBOType) {
1291*c8dee2aaSAndroid Build Coastguard Worker case kNone_MSFBOType: return "None";
1292*c8dee2aaSAndroid Build Coastguard Worker case kStandard_MSFBOType: return "Standard";
1293*c8dee2aaSAndroid Build Coastguard Worker case kES_Apple_MSFBOType: return "Apple";
1294*c8dee2aaSAndroid Build Coastguard Worker case kES_IMG_MsToTexture_MSFBOType: return "IMG MS To Texture";
1295*c8dee2aaSAndroid Build Coastguard Worker case kES_EXT_MsToTexture_MSFBOType: return "EXT MS To Texture";
1296*c8dee2aaSAndroid Build Coastguard Worker }
1297*c8dee2aaSAndroid Build Coastguard Worker SkUNREACHABLE;
1298*c8dee2aaSAndroid Build Coastguard Worker };
1299*c8dee2aaSAndroid Build Coastguard Worker
1300*c8dee2aaSAndroid Build Coastguard Worker auto invalidateFBTypeStr = [&] {
1301*c8dee2aaSAndroid Build Coastguard Worker switch (fInvalidateFBType) {
1302*c8dee2aaSAndroid Build Coastguard Worker case kNone_InvalidateFBType: return "None";
1303*c8dee2aaSAndroid Build Coastguard Worker case kDiscard_InvalidateFBType: return "Discard";
1304*c8dee2aaSAndroid Build Coastguard Worker case kInvalidate_InvalidateFBType: return "Invalidate";
1305*c8dee2aaSAndroid Build Coastguard Worker }
1306*c8dee2aaSAndroid Build Coastguard Worker SkUNREACHABLE;
1307*c8dee2aaSAndroid Build Coastguard Worker };
1308*c8dee2aaSAndroid Build Coastguard Worker
1309*c8dee2aaSAndroid Build Coastguard Worker auto invalidateBufferTypeStr = [&] {
1310*c8dee2aaSAndroid Build Coastguard Worker switch (fInvalidateBufferType) {
1311*c8dee2aaSAndroid Build Coastguard Worker case InvalidateBufferType::kNone: return "None";
1312*c8dee2aaSAndroid Build Coastguard Worker case InvalidateBufferType::kNullData: return "Null data hint";
1313*c8dee2aaSAndroid Build Coastguard Worker case InvalidateBufferType::kInvalidate: return "Invalidate";
1314*c8dee2aaSAndroid Build Coastguard Worker }
1315*c8dee2aaSAndroid Build Coastguard Worker SkUNREACHABLE;
1316*c8dee2aaSAndroid Build Coastguard Worker };
1317*c8dee2aaSAndroid Build Coastguard Worker
1318*c8dee2aaSAndroid Build Coastguard Worker auto mapBufferTypeStr = [&] {
1319*c8dee2aaSAndroid Build Coastguard Worker switch (fMapBufferType) {
1320*c8dee2aaSAndroid Build Coastguard Worker case kNone_MapBufferType: return "None";
1321*c8dee2aaSAndroid Build Coastguard Worker case kMapBuffer_MapBufferType: return "MapBuffer";
1322*c8dee2aaSAndroid Build Coastguard Worker case kMapBufferRange_MapBufferType: return "MapBufferRange";
1323*c8dee2aaSAndroid Build Coastguard Worker case kChromium_MapBufferType: return "Chromium";
1324*c8dee2aaSAndroid Build Coastguard Worker }
1325*c8dee2aaSAndroid Build Coastguard Worker SkUNREACHABLE;
1326*c8dee2aaSAndroid Build Coastguard Worker };
1327*c8dee2aaSAndroid Build Coastguard Worker
1328*c8dee2aaSAndroid Build Coastguard Worker writer->appendBool("Core Profile", fIsCoreProfile);
1329*c8dee2aaSAndroid Build Coastguard Worker writer->appendCString("MSAA Type", msfboStr());
1330*c8dee2aaSAndroid Build Coastguard Worker writer->appendCString("Invalidate FB Type", invalidateFBTypeStr());
1331*c8dee2aaSAndroid Build Coastguard Worker writer->appendCString("Invalidate Buffer Type", invalidateBufferTypeStr());
1332*c8dee2aaSAndroid Build Coastguard Worker writer->appendCString("Map Buffer Type", mapBufferTypeStr());
1333*c8dee2aaSAndroid Build Coastguard Worker writer->appendCString("Multi Draw Type", multi_draw_type_name(fMultiDrawType));
1334*c8dee2aaSAndroid Build Coastguard Worker writer->appendS32("Max FS Uniform Vectors", fMaxFragmentUniformVectors);
1335*c8dee2aaSAndroid Build Coastguard Worker writer->appendBool("Pack Flip Y support", fPackFlipYSupport);
1336*c8dee2aaSAndroid Build Coastguard Worker
1337*c8dee2aaSAndroid Build Coastguard Worker writer->appendBool("Texture Usage support", fTextureUsageSupport);
1338*c8dee2aaSAndroid Build Coastguard Worker writer->appendBool("GL_ARB_imaging support", fImagingSupport);
1339*c8dee2aaSAndroid Build Coastguard Worker writer->appendBool("Vertex array object support", fVertexArrayObjectSupport);
1340*c8dee2aaSAndroid Build Coastguard Worker writer->appendBool("Debug support", fDebugSupport);
1341*c8dee2aaSAndroid Build Coastguard Worker writer->appendBool("ES2 compatibility support", fES2CompatibilitySupport);
1342*c8dee2aaSAndroid Build Coastguard Worker writer->appendBool("Strict Protectedness", fStrictProtectedness);
1343*c8dee2aaSAndroid Build Coastguard Worker writer->appendBool("drawRangeElements support", fDrawRangeElementsSupport);
1344*c8dee2aaSAndroid Build Coastguard Worker writer->appendBool("Base (vertex base) instance support", fBaseVertexBaseInstanceSupport);
1345*c8dee2aaSAndroid Build Coastguard Worker writer->appendBool("Bind uniform location support", fBindUniformLocationSupport);
1346*c8dee2aaSAndroid Build Coastguard Worker writer->appendBool("Rectangle texture support", fRectangleTextureSupport);
1347*c8dee2aaSAndroid Build Coastguard Worker writer->appendBool("Mipmap LOD control support", fMipmapLodControlSupport);
1348*c8dee2aaSAndroid Build Coastguard Worker writer->appendBool("Mipmap level control support", fMipmapLevelControlSupport);
1349*c8dee2aaSAndroid Build Coastguard Worker writer->appendBool("Clear texture support", fClearTextureSupport);
1350*c8dee2aaSAndroid Build Coastguard Worker writer->appendBool("Program binary support", fProgramBinarySupport);
1351*c8dee2aaSAndroid Build Coastguard Worker writer->appendBool("Program parameters support", fProgramParameterSupport);
1352*c8dee2aaSAndroid Build Coastguard Worker writer->appendBool("Sampler object support", fSamplerObjectSupport);
1353*c8dee2aaSAndroid Build Coastguard Worker writer->appendBool("Using sampler objects", fUseSamplerObjects);
1354*c8dee2aaSAndroid Build Coastguard Worker writer->appendBool("Texture swizzle support", fTextureSwizzleSupport);
1355*c8dee2aaSAndroid Build Coastguard Worker writer->appendBool("Tiled rendering support", fTiledRenderingSupport);
1356*c8dee2aaSAndroid Build Coastguard Worker writer->appendBool("Fence sync support", fFenceSyncSupport);
1357*c8dee2aaSAndroid Build Coastguard Worker writer->appendBool("FB fetch requires enable per sample", fFBFetchRequiresEnablePerSample);
1358*c8dee2aaSAndroid Build Coastguard Worker writer->appendBool("sRGB Write Control", fSRGBWriteControl);
1359*c8dee2aaSAndroid Build Coastguard Worker
1360*c8dee2aaSAndroid Build Coastguard Worker writer->appendBool("Intermediate texture for partial updates of unorm textures ever bound to FBOs",
1361*c8dee2aaSAndroid Build Coastguard Worker fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO);
1362*c8dee2aaSAndroid Build Coastguard Worker writer->appendBool("Intermediate texture for all updates of textures bound to FBOs",
1363*c8dee2aaSAndroid Build Coastguard Worker fUseDrawInsteadOfAllRenderTargetWrites);
1364*c8dee2aaSAndroid Build Coastguard Worker writer->appendBool("Max instances per draw without crashing (or zero)",
1365*c8dee2aaSAndroid Build Coastguard Worker fMaxInstancesPerDrawWithoutCrashing);
1366*c8dee2aaSAndroid Build Coastguard Worker
1367*c8dee2aaSAndroid Build Coastguard Worker writer->beginArray("formats");
1368*c8dee2aaSAndroid Build Coastguard Worker
1369*c8dee2aaSAndroid Build Coastguard Worker for (int i = 0; i < kGrGLColorFormatCount; ++i) {
1370*c8dee2aaSAndroid Build Coastguard Worker writer->beginObject(nullptr, false);
1371*c8dee2aaSAndroid Build Coastguard Worker writer->appendHexU32("flags", fFormatTable[i].fFlags);
1372*c8dee2aaSAndroid Build Coastguard Worker writer->appendHexU32("f_type", (uint32_t)fFormatTable[i].fFormatType);
1373*c8dee2aaSAndroid Build Coastguard Worker writer->appendHexU32("c_internal", fFormatTable[i].fCompressedInternalFormat);
1374*c8dee2aaSAndroid Build Coastguard Worker writer->appendHexU32("i_for_teximage", fFormatTable[i].fInternalFormatForTexImageOrStorage);
1375*c8dee2aaSAndroid Build Coastguard Worker writer->appendHexU32("i_for_renderbuffer", fFormatTable[i].fInternalFormatForRenderbuffer);
1376*c8dee2aaSAndroid Build Coastguard Worker writer->appendHexU32("default_ex_format", fFormatTable[i].fDefaultExternalFormat);
1377*c8dee2aaSAndroid Build Coastguard Worker writer->appendHexU32("default_ex_type", fFormatTable[i].fDefaultExternalType);
1378*c8dee2aaSAndroid Build Coastguard Worker writer->appendHexU32("default_color_type", (uint32_t)fFormatTable[i].fDefaultColorType);
1379*c8dee2aaSAndroid Build Coastguard Worker
1380*c8dee2aaSAndroid Build Coastguard Worker writer->beginArray("surface color types");
1381*c8dee2aaSAndroid Build Coastguard Worker for (int j = 0; j < fFormatTable[i].fColorTypeInfoCount; ++j) {
1382*c8dee2aaSAndroid Build Coastguard Worker const auto& ctInfo = fFormatTable[i].fColorTypeInfos[j];
1383*c8dee2aaSAndroid Build Coastguard Worker writer->beginObject(nullptr, false);
1384*c8dee2aaSAndroid Build Coastguard Worker writer->appendHexU32("colorType", (uint32_t)ctInfo.fColorType);
1385*c8dee2aaSAndroid Build Coastguard Worker writer->appendHexU32("flags", ctInfo.fFlags);
1386*c8dee2aaSAndroid Build Coastguard Worker
1387*c8dee2aaSAndroid Build Coastguard Worker writer->beginArray("data color types");
1388*c8dee2aaSAndroid Build Coastguard Worker for (int k = 0; k < ctInfo.fExternalIOFormatCount; ++k) {
1389*c8dee2aaSAndroid Build Coastguard Worker const auto& ioInfo = ctInfo.fExternalIOFormats[k];
1390*c8dee2aaSAndroid Build Coastguard Worker writer->beginObject(nullptr, false);
1391*c8dee2aaSAndroid Build Coastguard Worker writer->appendHexU32("colorType", (uint32_t)ioInfo.fColorType);
1392*c8dee2aaSAndroid Build Coastguard Worker writer->appendHexU32("ex_type", ioInfo.fExternalType);
1393*c8dee2aaSAndroid Build Coastguard Worker writer->appendHexU32("ex_teximage", ioInfo.fExternalTexImageFormat);
1394*c8dee2aaSAndroid Build Coastguard Worker writer->appendHexU32("ex_read", ioInfo.fExternalReadFormat);
1395*c8dee2aaSAndroid Build Coastguard Worker writer->endObject();
1396*c8dee2aaSAndroid Build Coastguard Worker }
1397*c8dee2aaSAndroid Build Coastguard Worker writer->endArray();
1398*c8dee2aaSAndroid Build Coastguard Worker writer->endObject();
1399*c8dee2aaSAndroid Build Coastguard Worker }
1400*c8dee2aaSAndroid Build Coastguard Worker writer->endArray();
1401*c8dee2aaSAndroid Build Coastguard Worker writer->endObject();
1402*c8dee2aaSAndroid Build Coastguard Worker }
1403*c8dee2aaSAndroid Build Coastguard Worker
1404*c8dee2aaSAndroid Build Coastguard Worker writer->endArray();
1405*c8dee2aaSAndroid Build Coastguard Worker writer->endObject();
1406*c8dee2aaSAndroid Build Coastguard Worker }
1407*c8dee2aaSAndroid Build Coastguard Worker #else
onDumpJSON(SkJSONWriter * writer) const1408*c8dee2aaSAndroid Build Coastguard Worker void GrGLCaps::onDumpJSON(SkJSONWriter* writer) const { }
1409*c8dee2aaSAndroid Build Coastguard Worker #endif
1410*c8dee2aaSAndroid Build Coastguard Worker
getTexImageExternalFormatAndType(GrGLFormat surfaceFormat,GrGLenum * externalFormat,GrGLenum * externalType) const1411*c8dee2aaSAndroid Build Coastguard Worker void GrGLCaps::getTexImageExternalFormatAndType(GrGLFormat surfaceFormat, GrGLenum* externalFormat,
1412*c8dee2aaSAndroid Build Coastguard Worker GrGLenum* externalType) const {
1413*c8dee2aaSAndroid Build Coastguard Worker const auto& info = this->getFormatInfo(surfaceFormat);
1414*c8dee2aaSAndroid Build Coastguard Worker *externalType = info.fDefaultExternalType;
1415*c8dee2aaSAndroid Build Coastguard Worker *externalFormat = info.fDefaultExternalFormat;
1416*c8dee2aaSAndroid Build Coastguard Worker }
1417*c8dee2aaSAndroid Build Coastguard Worker
getTexSubImageDefaultFormatTypeAndColorType(GrGLFormat format,GrGLenum * externalFormat,GrGLenum * externalType,GrColorType * colorType) const1418*c8dee2aaSAndroid Build Coastguard Worker void GrGLCaps::getTexSubImageDefaultFormatTypeAndColorType(GrGLFormat format,
1419*c8dee2aaSAndroid Build Coastguard Worker GrGLenum* externalFormat,
1420*c8dee2aaSAndroid Build Coastguard Worker GrGLenum* externalType,
1421*c8dee2aaSAndroid Build Coastguard Worker GrColorType* colorType) const {
1422*c8dee2aaSAndroid Build Coastguard Worker const auto& info = this->getFormatInfo(format);
1423*c8dee2aaSAndroid Build Coastguard Worker *externalType = info.fDefaultExternalType;
1424*c8dee2aaSAndroid Build Coastguard Worker *externalFormat = info.fDefaultExternalFormat;
1425*c8dee2aaSAndroid Build Coastguard Worker *colorType = info.fDefaultColorType;
1426*c8dee2aaSAndroid Build Coastguard Worker }
1427*c8dee2aaSAndroid Build Coastguard Worker
getTexSubImageExternalFormatAndType(GrGLFormat surfaceFormat,GrColorType surfaceColorType,GrColorType memoryColorType,GrGLenum * externalFormat,GrGLenum * externalType) const1428*c8dee2aaSAndroid Build Coastguard Worker void GrGLCaps::getTexSubImageExternalFormatAndType(GrGLFormat surfaceFormat,
1429*c8dee2aaSAndroid Build Coastguard Worker GrColorType surfaceColorType,
1430*c8dee2aaSAndroid Build Coastguard Worker GrColorType memoryColorType,
1431*c8dee2aaSAndroid Build Coastguard Worker GrGLenum* externalFormat,
1432*c8dee2aaSAndroid Build Coastguard Worker GrGLenum* externalType) const {
1433*c8dee2aaSAndroid Build Coastguard Worker this->getExternalFormat(surfaceFormat, surfaceColorType, memoryColorType,
1434*c8dee2aaSAndroid Build Coastguard Worker kTexImage_ExternalFormatUsage, externalFormat, externalType);
1435*c8dee2aaSAndroid Build Coastguard Worker }
1436*c8dee2aaSAndroid Build Coastguard Worker
getReadPixelsFormat(GrGLFormat surfaceFormat,GrColorType surfaceColorType,GrColorType memoryColorType,GrGLenum * externalFormat,GrGLenum * externalType) const1437*c8dee2aaSAndroid Build Coastguard Worker void GrGLCaps::getReadPixelsFormat(GrGLFormat surfaceFormat, GrColorType surfaceColorType,
1438*c8dee2aaSAndroid Build Coastguard Worker GrColorType memoryColorType, GrGLenum* externalFormat,
1439*c8dee2aaSAndroid Build Coastguard Worker GrGLenum* externalType) const {
1440*c8dee2aaSAndroid Build Coastguard Worker this->getExternalFormat(surfaceFormat, surfaceColorType, memoryColorType,
1441*c8dee2aaSAndroid Build Coastguard Worker kReadPixels_ExternalFormatUsage, externalFormat, externalType);
1442*c8dee2aaSAndroid Build Coastguard Worker }
1443*c8dee2aaSAndroid Build Coastguard Worker
getExternalFormat(GrGLFormat surfaceFormat,GrColorType surfaceColorType,GrColorType memoryColorType,ExternalFormatUsage usage,GrGLenum * externalFormat,GrGLenum * externalType) const1444*c8dee2aaSAndroid Build Coastguard Worker void GrGLCaps::getExternalFormat(GrGLFormat surfaceFormat, GrColorType surfaceColorType,
1445*c8dee2aaSAndroid Build Coastguard Worker GrColorType memoryColorType, ExternalFormatUsage usage,
1446*c8dee2aaSAndroid Build Coastguard Worker GrGLenum* externalFormat, GrGLenum* externalType) const {
1447*c8dee2aaSAndroid Build Coastguard Worker SkASSERT(externalFormat && externalType);
1448*c8dee2aaSAndroid Build Coastguard Worker *externalFormat = this->getFormatInfo(surfaceFormat).externalFormat(
1449*c8dee2aaSAndroid Build Coastguard Worker surfaceColorType, memoryColorType, usage);
1450*c8dee2aaSAndroid Build Coastguard Worker *externalType = this->getFormatInfo(surfaceFormat).externalType(
1451*c8dee2aaSAndroid Build Coastguard Worker surfaceColorType, memoryColorType);
1452*c8dee2aaSAndroid Build Coastguard Worker }
1453*c8dee2aaSAndroid Build Coastguard Worker
setStencilFormatIndexForFormat(GrGLFormat format,int index)1454*c8dee2aaSAndroid Build Coastguard Worker void GrGLCaps::setStencilFormatIndexForFormat(GrGLFormat format, int index) {
1455*c8dee2aaSAndroid Build Coastguard Worker SkASSERT(!this->hasStencilFormatBeenDeterminedForFormat(format));
1456*c8dee2aaSAndroid Build Coastguard Worker this->getFormatInfo(format).fStencilFormatIndex =
1457*c8dee2aaSAndroid Build Coastguard Worker index < 0 ? FormatInfo::kUnsupported_StencilFormatIndex : index;
1458*c8dee2aaSAndroid Build Coastguard Worker }
1459*c8dee2aaSAndroid Build Coastguard Worker
setColorTypeFormat(GrColorType colorType,GrGLFormat format)1460*c8dee2aaSAndroid Build Coastguard Worker void GrGLCaps::setColorTypeFormat(GrColorType colorType, GrGLFormat format) {
1461*c8dee2aaSAndroid Build Coastguard Worker int idx = static_cast<int>(colorType);
1462*c8dee2aaSAndroid Build Coastguard Worker SkASSERT(fColorTypeToFormatTable[idx] == GrGLFormat::kUnknown);
1463*c8dee2aaSAndroid Build Coastguard Worker fColorTypeToFormatTable[idx] = format;
1464*c8dee2aaSAndroid Build Coastguard Worker }
1465*c8dee2aaSAndroid Build Coastguard Worker
initFormatTable(const GrGLContextInfo & ctxInfo,const GrGLInterface * gli,const FormatWorkarounds & formatWorkarounds)1466*c8dee2aaSAndroid Build Coastguard Worker void GrGLCaps::initFormatTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
1467*c8dee2aaSAndroid Build Coastguard Worker const FormatWorkarounds& formatWorkarounds) {
1468*c8dee2aaSAndroid Build Coastguard Worker GrGLStandard standard = ctxInfo.standard();
1469*c8dee2aaSAndroid Build Coastguard Worker // standard can be unused (optimized away) if SK_ASSUME_GL_ES is set
1470*c8dee2aaSAndroid Build Coastguard Worker sk_ignore_unused_variable(standard);
1471*c8dee2aaSAndroid Build Coastguard Worker GrGLVersion version = ctxInfo.version();
1472*c8dee2aaSAndroid Build Coastguard Worker
1473*c8dee2aaSAndroid Build Coastguard Worker uint32_t nonMSAARenderFlags = FormatInfo::kFBOColorAttachment_Flag;
1474*c8dee2aaSAndroid Build Coastguard Worker uint32_t msaaRenderFlags = nonMSAARenderFlags;
1475*c8dee2aaSAndroid Build Coastguard Worker if (kNone_MSFBOType != fMSFBOType) {
1476*c8dee2aaSAndroid Build Coastguard Worker msaaRenderFlags |= FormatInfo::kFBOColorAttachmentWithMSAA_Flag;
1477*c8dee2aaSAndroid Build Coastguard Worker }
1478*c8dee2aaSAndroid Build Coastguard Worker
1479*c8dee2aaSAndroid Build Coastguard Worker bool texStorageSupported = false;
1480*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
1481*c8dee2aaSAndroid Build Coastguard Worker // The EXT version can apply to either GL or GLES.
1482*c8dee2aaSAndroid Build Coastguard Worker texStorageSupported = version >= GR_GL_VER(4,2) ||
1483*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_ARB_texture_storage") ||
1484*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_EXT_texture_storage");
1485*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
1486*c8dee2aaSAndroid Build Coastguard Worker texStorageSupported = version >= GR_GL_VER(3,0) ||
1487*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_EXT_texture_storage");
1488*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(standard)) {
1489*c8dee2aaSAndroid Build Coastguard Worker texStorageSupported = version >= GR_GL_VER(2,0);
1490*c8dee2aaSAndroid Build Coastguard Worker }
1491*c8dee2aaSAndroid Build Coastguard Worker if (fDriverBugWorkarounds.disable_texture_storage) {
1492*c8dee2aaSAndroid Build Coastguard Worker texStorageSupported = false;
1493*c8dee2aaSAndroid Build Coastguard Worker }
1494*c8dee2aaSAndroid Build Coastguard Worker
1495*c8dee2aaSAndroid Build Coastguard Worker if (formatWorkarounds.fDisableTexStorage) {
1496*c8dee2aaSAndroid Build Coastguard Worker texStorageSupported = false;
1497*c8dee2aaSAndroid Build Coastguard Worker }
1498*c8dee2aaSAndroid Build Coastguard Worker
1499*c8dee2aaSAndroid Build Coastguard Worker // ES 2.0 requires that the internal/external formats match so we can't use sized internal
1500*c8dee2aaSAndroid Build Coastguard Worker // formats for glTexImage until ES 3.0. TODO: Support sized internal formats in WebGL2.
1501*c8dee2aaSAndroid Build Coastguard Worker bool texImageSupportsSizedInternalFormat =
1502*c8dee2aaSAndroid Build Coastguard Worker (GR_IS_GR_GL(standard) || (GR_IS_GR_GL_ES(standard) && version >= GR_GL_VER(3,0)));
1503*c8dee2aaSAndroid Build Coastguard Worker
1504*c8dee2aaSAndroid Build Coastguard Worker // for now we don't support floating point MSAA on ES
1505*c8dee2aaSAndroid Build Coastguard Worker uint32_t fpRenderFlags = (GR_IS_GR_GL(standard)) ? msaaRenderFlags : nonMSAARenderFlags;
1506*c8dee2aaSAndroid Build Coastguard Worker
1507*c8dee2aaSAndroid Build Coastguard Worker for (int i = 0; i < kGrColorTypeCnt; ++i) {
1508*c8dee2aaSAndroid Build Coastguard Worker fColorTypeToFormatTable[i] = GrGLFormat::kUnknown;
1509*c8dee2aaSAndroid Build Coastguard Worker }
1510*c8dee2aaSAndroid Build Coastguard Worker
1511*c8dee2aaSAndroid Build Coastguard Worker ///////////////////////////////////////////////////////////////////////////
1512*c8dee2aaSAndroid Build Coastguard Worker
1513*c8dee2aaSAndroid Build Coastguard Worker GrGLenum halfFloatType = GR_GL_HALF_FLOAT;
1514*c8dee2aaSAndroid Build Coastguard Worker if ((GR_IS_GR_GL_ES(standard) && version < GR_GL_VER(3, 0)) ||
1515*c8dee2aaSAndroid Build Coastguard Worker (GR_IS_GR_WEBGL(standard) && version < GR_GL_VER(2, 0))) {
1516*c8dee2aaSAndroid Build Coastguard Worker halfFloatType = GR_GL_HALF_FLOAT_OES;
1517*c8dee2aaSAndroid Build Coastguard Worker }
1518*c8dee2aaSAndroid Build Coastguard Worker
1519*c8dee2aaSAndroid Build Coastguard Worker // Format: RGBA8
1520*c8dee2aaSAndroid Build Coastguard Worker {
1521*c8dee2aaSAndroid Build Coastguard Worker FormatInfo& info = this->getFormatInfo(GrGLFormat::kRGBA8);
1522*c8dee2aaSAndroid Build Coastguard Worker info.fFormatType = FormatType::kNormalizedFixedPoint;
1523*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForRenderbuffer = GR_GL_RGBA8;
1524*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultExternalFormat = GR_GL_RGBA;
1525*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
1526*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultColorType = GrColorType::kRGBA_8888;
1527*c8dee2aaSAndroid Build Coastguard Worker info.fFlags = FormatInfo::kTexturable_Flag | FormatInfo::kTransfers_Flag;
1528*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
1529*c8dee2aaSAndroid Build Coastguard Worker info.fFlags |= msaaRenderFlags;
1530*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
1531*c8dee2aaSAndroid Build Coastguard Worker if (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
1532*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_ARM_rgba8")) {
1533*c8dee2aaSAndroid Build Coastguard Worker info.fFlags |= msaaRenderFlags;
1534*c8dee2aaSAndroid Build Coastguard Worker }
1535*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(standard)) {
1536*c8dee2aaSAndroid Build Coastguard Worker info.fFlags |= msaaRenderFlags;
1537*c8dee2aaSAndroid Build Coastguard Worker }
1538*c8dee2aaSAndroid Build Coastguard Worker
1539*c8dee2aaSAndroid Build Coastguard Worker if (texStorageSupported) {
1540*c8dee2aaSAndroid Build Coastguard Worker info.fFlags |= FormatInfo::kUseTexStorage_Flag;
1541*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage = GR_GL_RGBA8;
1542*c8dee2aaSAndroid Build Coastguard Worker } else {
1543*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage =
1544*c8dee2aaSAndroid Build Coastguard Worker texImageSupportsSizedInternalFormat ? GR_GL_RGBA8 : GR_GL_RGBA;
1545*c8dee2aaSAndroid Build Coastguard Worker }
1546*c8dee2aaSAndroid Build Coastguard Worker
1547*c8dee2aaSAndroid Build Coastguard Worker bool supportsBGRAColorType = GR_IS_GR_GL(standard) &&
1548*c8dee2aaSAndroid Build Coastguard Worker (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra"));
1549*c8dee2aaSAndroid Build Coastguard Worker info.fColorTypeInfoCount = supportsBGRAColorType ? 3 : 2;
1550*c8dee2aaSAndroid Build Coastguard Worker info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount);
1551*c8dee2aaSAndroid Build Coastguard Worker int ctIdx = 0;
1552*c8dee2aaSAndroid Build Coastguard Worker // Format: RGBA8, Surface: kRGBA_8888
1553*c8dee2aaSAndroid Build Coastguard Worker {
1554*c8dee2aaSAndroid Build Coastguard Worker auto& ctInfo = info.fColorTypeInfos[ctIdx++];
1555*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fColorType = GrColorType::kRGBA_8888;
1556*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
1557*c8dee2aaSAndroid Build Coastguard Worker this->setColorTypeFormat(GrColorType::kRGBA_8888, GrGLFormat::kRGBA8);
1558*c8dee2aaSAndroid Build Coastguard Worker
1559*c8dee2aaSAndroid Build Coastguard Worker // External IO ColorTypes:
1560*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount = 2;
1561*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
1562*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount);
1563*c8dee2aaSAndroid Build Coastguard Worker int ioIdx = 0;
1564*c8dee2aaSAndroid Build Coastguard Worker // Format: RGBA8, Surface: kRGBA_8888, Data: kRGBA_8888
1565*c8dee2aaSAndroid Build Coastguard Worker {
1566*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
1567*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kRGBA_8888;
1568*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
1569*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = GR_GL_RGBA;
1570*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RGBA;
1571*c8dee2aaSAndroid Build Coastguard Worker }
1572*c8dee2aaSAndroid Build Coastguard Worker // Format: RGBA8, Surface: kRGBA_8888, Data: kBGRA_8888
1573*c8dee2aaSAndroid Build Coastguard Worker {
1574*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
1575*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kBGRA_8888;
1576*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
1577*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = 0; // TODO: Enable this on non-ES GL
1578*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat =
1579*c8dee2aaSAndroid Build Coastguard Worker formatWorkarounds.fDisallowBGRA8ReadPixels ? 0 : GR_GL_BGRA;
1580*c8dee2aaSAndroid Build Coastguard Worker // Not guaranteed by ES/WebGL.
1581*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fRequiresImplementationReadQuery = !GR_IS_GR_GL(standard);
1582*c8dee2aaSAndroid Build Coastguard Worker }
1583*c8dee2aaSAndroid Build Coastguard Worker }
1584*c8dee2aaSAndroid Build Coastguard Worker
1585*c8dee2aaSAndroid Build Coastguard Worker // Format: RGBA8, Surface: kBGRA_8888
1586*c8dee2aaSAndroid Build Coastguard Worker if (supportsBGRAColorType) {
1587*c8dee2aaSAndroid Build Coastguard Worker auto& ctInfo = info.fColorTypeInfos[ctIdx++];
1588*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fColorType = GrColorType::kBGRA_8888;
1589*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
1590*c8dee2aaSAndroid Build Coastguard Worker this->setColorTypeFormat(GrColorType::kBGRA_8888, GrGLFormat::kRGBA8);
1591*c8dee2aaSAndroid Build Coastguard Worker
1592*c8dee2aaSAndroid Build Coastguard Worker // External IO ColorTypes:
1593*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount = 2;
1594*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
1595*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount);
1596*c8dee2aaSAndroid Build Coastguard Worker int ioIdx = 0;
1597*c8dee2aaSAndroid Build Coastguard Worker // Format: RGBA8, Surface: kBGRA_8888, Data: kBGRA_8888
1598*c8dee2aaSAndroid Build Coastguard Worker {
1599*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
1600*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kBGRA_8888;
1601*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
1602*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = GR_GL_BGRA;
1603*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat =
1604*c8dee2aaSAndroid Build Coastguard Worker formatWorkarounds.fDisallowBGRA8ReadPixels ? 0 : GR_GL_BGRA;
1605*c8dee2aaSAndroid Build Coastguard Worker // Not guaranteed by ES/WebGL.
1606*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fRequiresImplementationReadQuery = !GR_IS_GR_GL(standard);
1607*c8dee2aaSAndroid Build Coastguard Worker }
1608*c8dee2aaSAndroid Build Coastguard Worker
1609*c8dee2aaSAndroid Build Coastguard Worker // Format: RGBA8, Surface: kBGRA_8888, Data: kRGBA_8888
1610*c8dee2aaSAndroid Build Coastguard Worker {
1611*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
1612*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kRGBA_8888;
1613*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
1614*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = 0;
1615*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RGBA;
1616*c8dee2aaSAndroid Build Coastguard Worker }
1617*c8dee2aaSAndroid Build Coastguard Worker }
1618*c8dee2aaSAndroid Build Coastguard Worker
1619*c8dee2aaSAndroid Build Coastguard Worker // Format: RGBA8, Surface: kRGB_888x
1620*c8dee2aaSAndroid Build Coastguard Worker {
1621*c8dee2aaSAndroid Build Coastguard Worker auto& ctInfo = info.fColorTypeInfos[ctIdx++];
1622*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fColorType = GrColorType::kRGB_888x;
1623*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag;
1624*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fReadSwizzle = skgpu::Swizzle::RGB1();
1625*c8dee2aaSAndroid Build Coastguard Worker
1626*c8dee2aaSAndroid Build Coastguard Worker // External IO ColorTypes:
1627*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount = 1;
1628*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
1629*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount);
1630*c8dee2aaSAndroid Build Coastguard Worker int ioIdx = 0;
1631*c8dee2aaSAndroid Build Coastguard Worker // Format: RGBA8, Surface: kRGB_888x, Data: kRGBA_888x
1632*c8dee2aaSAndroid Build Coastguard Worker {
1633*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
1634*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kRGB_888x;
1635*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
1636*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = GR_GL_RGBA;
1637*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RGBA;
1638*c8dee2aaSAndroid Build Coastguard Worker }
1639*c8dee2aaSAndroid Build Coastguard Worker }
1640*c8dee2aaSAndroid Build Coastguard Worker }
1641*c8dee2aaSAndroid Build Coastguard Worker
1642*c8dee2aaSAndroid Build Coastguard Worker // Format: R8
1643*c8dee2aaSAndroid Build Coastguard Worker {
1644*c8dee2aaSAndroid Build Coastguard Worker FormatInfo& info = this->getFormatInfo(GrGLFormat::kR8);
1645*c8dee2aaSAndroid Build Coastguard Worker info.fFormatType = FormatType::kNormalizedFixedPoint;
1646*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForRenderbuffer = GR_GL_R8;
1647*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultExternalFormat = GR_GL_RED;
1648*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
1649*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultColorType = GrColorType::kR_8;
1650*c8dee2aaSAndroid Build Coastguard Worker bool r8Support = false;
1651*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
1652*c8dee2aaSAndroid Build Coastguard Worker r8Support = version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_rg");
1653*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
1654*c8dee2aaSAndroid Build Coastguard Worker r8Support = version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_texture_rg");
1655*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(standard)) {
1656*c8dee2aaSAndroid Build Coastguard Worker r8Support = ctxInfo.version() >= GR_GL_VER(2, 0);
1657*c8dee2aaSAndroid Build Coastguard Worker }
1658*c8dee2aaSAndroid Build Coastguard Worker if (formatWorkarounds.fDisallowR8ForPowerVRSGX54x) {
1659*c8dee2aaSAndroid Build Coastguard Worker r8Support = false;
1660*c8dee2aaSAndroid Build Coastguard Worker }
1661*c8dee2aaSAndroid Build Coastguard Worker
1662*c8dee2aaSAndroid Build Coastguard Worker if (r8Support) {
1663*c8dee2aaSAndroid Build Coastguard Worker info.fFlags |= FormatInfo::kTexturable_Flag
1664*c8dee2aaSAndroid Build Coastguard Worker | FormatInfo::kTransfers_Flag
1665*c8dee2aaSAndroid Build Coastguard Worker | msaaRenderFlags;
1666*c8dee2aaSAndroid Build Coastguard Worker }
1667*c8dee2aaSAndroid Build Coastguard Worker
1668*c8dee2aaSAndroid Build Coastguard Worker if (texStorageSupported) {
1669*c8dee2aaSAndroid Build Coastguard Worker info.fFlags |= FormatInfo::kUseTexStorage_Flag;
1670*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage = GR_GL_R8;
1671*c8dee2aaSAndroid Build Coastguard Worker } else {
1672*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage =
1673*c8dee2aaSAndroid Build Coastguard Worker texImageSupportsSizedInternalFormat ? GR_GL_R8 : GR_GL_RED;
1674*c8dee2aaSAndroid Build Coastguard Worker }
1675*c8dee2aaSAndroid Build Coastguard Worker
1676*c8dee2aaSAndroid Build Coastguard Worker if (r8Support) {
1677*c8dee2aaSAndroid Build Coastguard Worker info.fColorTypeInfoCount = 3;
1678*c8dee2aaSAndroid Build Coastguard Worker info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount);
1679*c8dee2aaSAndroid Build Coastguard Worker int ctIdx = 0;
1680*c8dee2aaSAndroid Build Coastguard Worker // Format: R8, Surface: kR_8
1681*c8dee2aaSAndroid Build Coastguard Worker {
1682*c8dee2aaSAndroid Build Coastguard Worker auto& ctInfo = info.fColorTypeInfos[ctIdx++];
1683*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fColorType = GrColorType::kR_8;
1684*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
1685*c8dee2aaSAndroid Build Coastguard Worker this->setColorTypeFormat(GrColorType::kR_8, GrGLFormat::kR8);
1686*c8dee2aaSAndroid Build Coastguard Worker
1687*c8dee2aaSAndroid Build Coastguard Worker // External IO ColorTypes:
1688*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount = 2;
1689*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
1690*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount);
1691*c8dee2aaSAndroid Build Coastguard Worker int ioIdx = 0;
1692*c8dee2aaSAndroid Build Coastguard Worker // Format: R8, Surface: kR_8, Data: kR_8
1693*c8dee2aaSAndroid Build Coastguard Worker {
1694*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
1695*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kR_8;
1696*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
1697*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = GR_GL_RED;
1698*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RED;
1699*c8dee2aaSAndroid Build Coastguard Worker // Not guaranteed by ES/WebGL.
1700*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fRequiresImplementationReadQuery = !GR_IS_GR_GL(standard);
1701*c8dee2aaSAndroid Build Coastguard Worker }
1702*c8dee2aaSAndroid Build Coastguard Worker
1703*c8dee2aaSAndroid Build Coastguard Worker // Format: R8, Surface: kR_8, Data: kR_8xxx
1704*c8dee2aaSAndroid Build Coastguard Worker {
1705*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
1706*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kR_8xxx;
1707*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
1708*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = 0;
1709*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RGBA;
1710*c8dee2aaSAndroid Build Coastguard Worker }
1711*c8dee2aaSAndroid Build Coastguard Worker }
1712*c8dee2aaSAndroid Build Coastguard Worker
1713*c8dee2aaSAndroid Build Coastguard Worker // Format: R8, Surface: kAlpha_8
1714*c8dee2aaSAndroid Build Coastguard Worker {
1715*c8dee2aaSAndroid Build Coastguard Worker auto& ctInfo = info.fColorTypeInfos[ctIdx++];
1716*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fColorType = GrColorType::kAlpha_8;
1717*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
1718*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fReadSwizzle = skgpu::Swizzle("000r");
1719*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fWriteSwizzle = skgpu::Swizzle("a000");
1720*c8dee2aaSAndroid Build Coastguard Worker this->setColorTypeFormat(GrColorType::kAlpha_8, GrGLFormat::kR8);
1721*c8dee2aaSAndroid Build Coastguard Worker
1722*c8dee2aaSAndroid Build Coastguard Worker // External IO ColorTypes:
1723*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount = 2;
1724*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
1725*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount);
1726*c8dee2aaSAndroid Build Coastguard Worker int ioIdx = 0;
1727*c8dee2aaSAndroid Build Coastguard Worker // Format: R8, Surface: kAlpha_8, Data: kAlpha_8
1728*c8dee2aaSAndroid Build Coastguard Worker {
1729*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
1730*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kAlpha_8;
1731*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
1732*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = GR_GL_RED;
1733*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RED;
1734*c8dee2aaSAndroid Build Coastguard Worker // Not guaranteed by ES/WebGL.
1735*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fRequiresImplementationReadQuery = !GR_IS_GR_GL(standard);
1736*c8dee2aaSAndroid Build Coastguard Worker }
1737*c8dee2aaSAndroid Build Coastguard Worker
1738*c8dee2aaSAndroid Build Coastguard Worker // Format: R8, Surface: kAlpha_8, Data: kAlpha_8xxx
1739*c8dee2aaSAndroid Build Coastguard Worker {
1740*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
1741*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kAlpha_8xxx;
1742*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
1743*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = 0;
1744*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RGBA;
1745*c8dee2aaSAndroid Build Coastguard Worker }
1746*c8dee2aaSAndroid Build Coastguard Worker }
1747*c8dee2aaSAndroid Build Coastguard Worker
1748*c8dee2aaSAndroid Build Coastguard Worker // Format: R8, Surface: kGray_8
1749*c8dee2aaSAndroid Build Coastguard Worker {
1750*c8dee2aaSAndroid Build Coastguard Worker auto& ctInfo = info.fColorTypeInfos[ctIdx++];
1751*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fColorType = GrColorType::kGray_8;
1752*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag;
1753*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fReadSwizzle = skgpu::Swizzle("rrr1");
1754*c8dee2aaSAndroid Build Coastguard Worker this->setColorTypeFormat(GrColorType::kGray_8, GrGLFormat::kR8);
1755*c8dee2aaSAndroid Build Coastguard Worker
1756*c8dee2aaSAndroid Build Coastguard Worker // External IO ColorTypes:
1757*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount = 2;
1758*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
1759*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount);
1760*c8dee2aaSAndroid Build Coastguard Worker int ioIdx = 0;
1761*c8dee2aaSAndroid Build Coastguard Worker // Format: R8, Surface: kGray_8, Data: kGray_8
1762*c8dee2aaSAndroid Build Coastguard Worker {
1763*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
1764*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kGray_8;
1765*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
1766*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = GR_GL_RED;
1767*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RED;
1768*c8dee2aaSAndroid Build Coastguard Worker // Not guaranteed by ES/WebGL.
1769*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fRequiresImplementationReadQuery = !GR_IS_GR_GL(standard);
1770*c8dee2aaSAndroid Build Coastguard Worker }
1771*c8dee2aaSAndroid Build Coastguard Worker
1772*c8dee2aaSAndroid Build Coastguard Worker // Format: R8, Surface: kGray_8, Data: kGray_8xxx
1773*c8dee2aaSAndroid Build Coastguard Worker {
1774*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
1775*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kGray_8xxx;
1776*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
1777*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = 0;
1778*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RGBA;
1779*c8dee2aaSAndroid Build Coastguard Worker }
1780*c8dee2aaSAndroid Build Coastguard Worker }
1781*c8dee2aaSAndroid Build Coastguard Worker }
1782*c8dee2aaSAndroid Build Coastguard Worker }
1783*c8dee2aaSAndroid Build Coastguard Worker
1784*c8dee2aaSAndroid Build Coastguard Worker // Format: ALPHA8
1785*c8dee2aaSAndroid Build Coastguard Worker {
1786*c8dee2aaSAndroid Build Coastguard Worker bool alpha8IsValidForGL = GR_IS_GR_GL(standard) &&
1787*c8dee2aaSAndroid Build Coastguard Worker (!fIsCoreProfile || version <= GR_GL_VER(3, 0));
1788*c8dee2aaSAndroid Build Coastguard Worker bool alpha8IsValidForGLES = GR_IS_GR_GL_ES(standard);
1789*c8dee2aaSAndroid Build Coastguard Worker bool alpha8IsValidForWebGL = GR_IS_GR_WEBGL(standard);
1790*c8dee2aaSAndroid Build Coastguard Worker
1791*c8dee2aaSAndroid Build Coastguard Worker FormatInfo& info = this->getFormatInfo(GrGLFormat::kALPHA8);
1792*c8dee2aaSAndroid Build Coastguard Worker info.fFormatType = FormatType::kNormalizedFixedPoint;
1793*c8dee2aaSAndroid Build Coastguard Worker // GL_EXT_texture_storage adds GL_ALPHA8 for texture storage. However, ES3 has glTexStorage
1794*c8dee2aaSAndroid Build Coastguard Worker // but does not have GL_ALPHA8 (and requires a sized internal format for glTexStorage).
1795*c8dee2aaSAndroid Build Coastguard Worker // WebGL never has GL_ALPHA8.
1796*c8dee2aaSAndroid Build Coastguard Worker bool alpha8SizedEnumSupported =
1797*c8dee2aaSAndroid Build Coastguard Worker alpha8IsValidForGL ||
1798*c8dee2aaSAndroid Build Coastguard Worker (alpha8IsValidForGLES && ctxInfo.hasExtension("GL_EXT_texture_storage"));
1799*c8dee2aaSAndroid Build Coastguard Worker bool alpha8TexStorageSupported = alpha8SizedEnumSupported && texStorageSupported;
1800*c8dee2aaSAndroid Build Coastguard Worker
1801*c8dee2aaSAndroid Build Coastguard Worker bool alpha8IsRenderable = false;
1802*c8dee2aaSAndroid Build Coastguard Worker if (alpha8IsValidForGL) {
1803*c8dee2aaSAndroid Build Coastguard Worker // Core profile removes ALPHA8 support.
1804*c8dee2aaSAndroid Build Coastguard Worker // OpenGL 3.0+ (and GL_ARB_framebuffer_object) supports ALPHA8 as renderable.
1805*c8dee2aaSAndroid Build Coastguard Worker alpha8IsRenderable = ctxInfo.version() >= GR_GL_VER(3, 0) ||
1806*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_ARB_framebuffer_object");
1807*c8dee2aaSAndroid Build Coastguard Worker }
1808*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForRenderbuffer = GR_GL_ALPHA8;
1809*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultExternalFormat = GR_GL_ALPHA;
1810*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
1811*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultColorType = GrColorType::kAlpha_8;
1812*c8dee2aaSAndroid Build Coastguard Worker if (alpha8IsValidForGL || alpha8IsValidForGLES || alpha8IsValidForWebGL) {
1813*c8dee2aaSAndroid Build Coastguard Worker info.fFlags = FormatInfo::kTexturable_Flag | FormatInfo::kTransfers_Flag;
1814*c8dee2aaSAndroid Build Coastguard Worker }
1815*c8dee2aaSAndroid Build Coastguard Worker if (alpha8IsRenderable && alpha8IsValidForGL) {
1816*c8dee2aaSAndroid Build Coastguard Worker // We will use ALPHA8 to create MSAA renderbuffers.
1817*c8dee2aaSAndroid Build Coastguard Worker SkASSERT(alpha8SizedEnumSupported);
1818*c8dee2aaSAndroid Build Coastguard Worker info.fFlags |= msaaRenderFlags;
1819*c8dee2aaSAndroid Build Coastguard Worker }
1820*c8dee2aaSAndroid Build Coastguard Worker if (alpha8TexStorageSupported) {
1821*c8dee2aaSAndroid Build Coastguard Worker info.fFlags |= FormatInfo::kUseTexStorage_Flag;
1822*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage = GR_GL_ALPHA8;
1823*c8dee2aaSAndroid Build Coastguard Worker } else {
1824*c8dee2aaSAndroid Build Coastguard Worker // Even if GL_ALPHA8 is added to ES by GL_EXT_texture_storage it doesn't become legal
1825*c8dee2aaSAndroid Build Coastguard Worker // for glTexImage2D.
1826*c8dee2aaSAndroid Build Coastguard Worker if (!GR_IS_GR_GL_ES(standard) && texImageSupportsSizedInternalFormat &&
1827*c8dee2aaSAndroid Build Coastguard Worker alpha8SizedEnumSupported) {
1828*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage = GR_GL_ALPHA8;
1829*c8dee2aaSAndroid Build Coastguard Worker } else {
1830*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage = GR_GL_ALPHA;
1831*c8dee2aaSAndroid Build Coastguard Worker }
1832*c8dee2aaSAndroid Build Coastguard Worker }
1833*c8dee2aaSAndroid Build Coastguard Worker
1834*c8dee2aaSAndroid Build Coastguard Worker if (alpha8IsValidForGL || alpha8IsValidForGLES || alpha8IsValidForWebGL) {
1835*c8dee2aaSAndroid Build Coastguard Worker info.fColorTypeInfoCount = 1;
1836*c8dee2aaSAndroid Build Coastguard Worker info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount);
1837*c8dee2aaSAndroid Build Coastguard Worker int ctIdx = 0;
1838*c8dee2aaSAndroid Build Coastguard Worker // Format: ALPHA8, Surface: kAlpha_8
1839*c8dee2aaSAndroid Build Coastguard Worker {
1840*c8dee2aaSAndroid Build Coastguard Worker if (alpha8IsValidForGL || alpha8IsValidForGLES || alpha8IsValidForWebGL) {
1841*c8dee2aaSAndroid Build Coastguard Worker auto& ctInfo = info.fColorTypeInfos[ctIdx++];
1842*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fColorType = GrColorType::kAlpha_8;
1843*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag |
1844*c8dee2aaSAndroid Build Coastguard Worker ColorTypeInfo::kRenderable_Flag;
1845*c8dee2aaSAndroid Build Coastguard Worker int idx = static_cast<int>(GrColorType::kAlpha_8);
1846*c8dee2aaSAndroid Build Coastguard Worker if (fColorTypeToFormatTable[idx] == GrGLFormat::kUnknown) {
1847*c8dee2aaSAndroid Build Coastguard Worker this->setColorTypeFormat(GrColorType::kAlpha_8, GrGLFormat::kALPHA8);
1848*c8dee2aaSAndroid Build Coastguard Worker }
1849*c8dee2aaSAndroid Build Coastguard Worker
1850*c8dee2aaSAndroid Build Coastguard Worker // External IO ColorTypes:
1851*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount = 2;
1852*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
1853*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount);
1854*c8dee2aaSAndroid Build Coastguard Worker int ioIdx = 0;
1855*c8dee2aaSAndroid Build Coastguard Worker // Format: ALPHA8, Surface: kAlpha_8, Data: kAlpha_8
1856*c8dee2aaSAndroid Build Coastguard Worker {
1857*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
1858*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kAlpha_8;
1859*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
1860*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = GR_GL_ALPHA;
1861*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_ALPHA;
1862*c8dee2aaSAndroid Build Coastguard Worker // Not guaranteed by ES/WebGL.
1863*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fRequiresImplementationReadQuery = !GR_IS_GR_GL(standard);
1864*c8dee2aaSAndroid Build Coastguard Worker }
1865*c8dee2aaSAndroid Build Coastguard Worker
1866*c8dee2aaSAndroid Build Coastguard Worker // Format: ALPHA8, Surface: kAlpha_8, Data: kRGBA_8888
1867*c8dee2aaSAndroid Build Coastguard Worker {
1868*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
1869*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kRGBA_8888;
1870*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
1871*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = 0;
1872*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RGBA;
1873*c8dee2aaSAndroid Build Coastguard Worker }
1874*c8dee2aaSAndroid Build Coastguard Worker }
1875*c8dee2aaSAndroid Build Coastguard Worker }
1876*c8dee2aaSAndroid Build Coastguard Worker }
1877*c8dee2aaSAndroid Build Coastguard Worker }
1878*c8dee2aaSAndroid Build Coastguard Worker
1879*c8dee2aaSAndroid Build Coastguard Worker // Do we support the lumincance and luminance_alpha formats
1880*c8dee2aaSAndroid Build Coastguard Worker bool lum8Supported = false;
1881*c8dee2aaSAndroid Build Coastguard Worker bool lum8SizedFormatSupported = false;
1882*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard) && !fIsCoreProfile) {
1883*c8dee2aaSAndroid Build Coastguard Worker lum8Supported = true;
1884*c8dee2aaSAndroid Build Coastguard Worker lum8SizedFormatSupported = true;
1885*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
1886*c8dee2aaSAndroid Build Coastguard Worker lum8Supported = true;
1887*c8dee2aaSAndroid Build Coastguard Worker // Even on ES3 this extension is required to define LUMINANCE8. GL_LUMINANCE8 is not a
1888*c8dee2aaSAndroid Build Coastguard Worker // valid internal format for TexImage2D so we need to be using texture storage to use
1889*c8dee2aaSAndroid Build Coastguard Worker // it. Even though we check the extension for texture storage here, we also check to see
1890*c8dee2aaSAndroid Build Coastguard Worker // if texStorageSupported may have been disabled for a workaround.
1891*c8dee2aaSAndroid Build Coastguard Worker lum8SizedFormatSupported =
1892*c8dee2aaSAndroid Build Coastguard Worker texStorageSupported && ctxInfo.hasExtension("GL_EXT_texture_storage");
1893*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(standard)) {
1894*c8dee2aaSAndroid Build Coastguard Worker lum8Supported = true;
1895*c8dee2aaSAndroid Build Coastguard Worker }
1896*c8dee2aaSAndroid Build Coastguard Worker
1897*c8dee2aaSAndroid Build Coastguard Worker // Format: LUMINANCE8
1898*c8dee2aaSAndroid Build Coastguard Worker {
1899*c8dee2aaSAndroid Build Coastguard Worker FormatInfo& info = this->getFormatInfo(GrGLFormat::kLUMINANCE8);
1900*c8dee2aaSAndroid Build Coastguard Worker info.fFormatType = FormatType::kNormalizedFixedPoint;
1901*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForRenderbuffer = GR_GL_LUMINANCE8;
1902*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultExternalFormat = GR_GL_LUMINANCE;
1903*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
1904*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultColorType = GrColorType::kGray_8;
1905*c8dee2aaSAndroid Build Coastguard Worker
1906*c8dee2aaSAndroid Build Coastguard Worker if (lum8Supported) {
1907*c8dee2aaSAndroid Build Coastguard Worker info.fFlags = FormatInfo::kTexturable_Flag | FormatInfo::kTransfers_Flag;
1908*c8dee2aaSAndroid Build Coastguard Worker }
1909*c8dee2aaSAndroid Build Coastguard Worker if (texStorageSupported && lum8SizedFormatSupported) {
1910*c8dee2aaSAndroid Build Coastguard Worker info.fFlags |= FormatInfo::kUseTexStorage_Flag;
1911*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage = GR_GL_LUMINANCE8;
1912*c8dee2aaSAndroid Build Coastguard Worker } else if (texImageSupportsSizedInternalFormat && lum8SizedFormatSupported) {
1913*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage = GR_GL_LUMINANCE8;
1914*c8dee2aaSAndroid Build Coastguard Worker } else {
1915*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage = GR_GL_LUMINANCE;
1916*c8dee2aaSAndroid Build Coastguard Worker }
1917*c8dee2aaSAndroid Build Coastguard Worker // We are not enabling attaching to an FBO for LUMINANCE8 mostly because of confusion in the
1918*c8dee2aaSAndroid Build Coastguard Worker // spec. For GLES it does not seem to ever support LUMINANCE8 being color-renderable. For GL
1919*c8dee2aaSAndroid Build Coastguard Worker // versions less than 3.0 it is provided by GL_ARB_framebuffer_object. However, the original
1920*c8dee2aaSAndroid Build Coastguard Worker // version of that extension did not add LUMINANCE8, but was added in a later revsion. So
1921*c8dee2aaSAndroid Build Coastguard Worker // even the presence of that extension does not guarantee support. GL 3.0 and higher (core
1922*c8dee2aaSAndroid Build Coastguard Worker // or compatibility) do not list LUMINANCE8 as color-renderable (which is strange since the
1923*c8dee2aaSAndroid Build Coastguard Worker // GL_ARB_framebuffer_object extension was meant to bring 3.0 functionality to lower
1924*c8dee2aaSAndroid Build Coastguard Worker // versions).
1925*c8dee2aaSAndroid Build Coastguard Worker
1926*c8dee2aaSAndroid Build Coastguard Worker if (lum8Supported) {
1927*c8dee2aaSAndroid Build Coastguard Worker info.fColorTypeInfoCount = 1;
1928*c8dee2aaSAndroid Build Coastguard Worker info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount);
1929*c8dee2aaSAndroid Build Coastguard Worker int ctIdx = 0;
1930*c8dee2aaSAndroid Build Coastguard Worker // Format: LUMINANCE8, Surface: kGray_8
1931*c8dee2aaSAndroid Build Coastguard Worker {
1932*c8dee2aaSAndroid Build Coastguard Worker auto& ctInfo = info.fColorTypeInfos[ctIdx++];
1933*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fColorType = GrColorType::kGray_8;
1934*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag;
1935*c8dee2aaSAndroid Build Coastguard Worker int idx = static_cast<int>(GrColorType::kGray_8);
1936*c8dee2aaSAndroid Build Coastguard Worker if (fColorTypeToFormatTable[idx] == GrGLFormat::kUnknown) {
1937*c8dee2aaSAndroid Build Coastguard Worker this->setColorTypeFormat(GrColorType::kGray_8, GrGLFormat::kLUMINANCE8);
1938*c8dee2aaSAndroid Build Coastguard Worker }
1939*c8dee2aaSAndroid Build Coastguard Worker
1940*c8dee2aaSAndroid Build Coastguard Worker // External IO ColorTypes:
1941*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount = 2;
1942*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
1943*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount);
1944*c8dee2aaSAndroid Build Coastguard Worker int ioIdx = 0;
1945*c8dee2aaSAndroid Build Coastguard Worker // Format: LUMINANCE8, Surface: kGray_8, Data: kGray_8
1946*c8dee2aaSAndroid Build Coastguard Worker {
1947*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
1948*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kGray_8;
1949*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
1950*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = GR_GL_LUMINANCE;
1951*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = 0;
1952*c8dee2aaSAndroid Build Coastguard Worker }
1953*c8dee2aaSAndroid Build Coastguard Worker
1954*c8dee2aaSAndroid Build Coastguard Worker // Format: LUMINANCE8, Surface: kGray_8, Data: kRGBA_8888
1955*c8dee2aaSAndroid Build Coastguard Worker {
1956*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
1957*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kRGBA_8888;
1958*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
1959*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = 0;
1960*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RGBA;
1961*c8dee2aaSAndroid Build Coastguard Worker }
1962*c8dee2aaSAndroid Build Coastguard Worker }
1963*c8dee2aaSAndroid Build Coastguard Worker }
1964*c8dee2aaSAndroid Build Coastguard Worker }
1965*c8dee2aaSAndroid Build Coastguard Worker
1966*c8dee2aaSAndroid Build Coastguard Worker // Format: LUMINANCE8_ALPHA8
1967*c8dee2aaSAndroid Build Coastguard Worker {
1968*c8dee2aaSAndroid Build Coastguard Worker FormatInfo& info = this->getFormatInfo(GrGLFormat::kLUMINANCE8_ALPHA8);
1969*c8dee2aaSAndroid Build Coastguard Worker info.fFormatType = FormatType::kNormalizedFixedPoint;
1970*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForRenderbuffer = GR_GL_LUMINANCE8_ALPHA8;
1971*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultExternalFormat = GR_GL_LUMINANCE_ALPHA;
1972*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
1973*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultColorType = GrColorType::kGrayAlpha_88;
1974*c8dee2aaSAndroid Build Coastguard Worker if (lum8Supported) {
1975*c8dee2aaSAndroid Build Coastguard Worker info.fFlags = FormatInfo::kTexturable_Flag | FormatInfo::kTransfers_Flag;
1976*c8dee2aaSAndroid Build Coastguard Worker }
1977*c8dee2aaSAndroid Build Coastguard Worker if (texStorageSupported && lum8SizedFormatSupported) {
1978*c8dee2aaSAndroid Build Coastguard Worker info.fFlags |= FormatInfo::kUseTexStorage_Flag;
1979*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage = GR_GL_LUMINANCE8_ALPHA8;
1980*c8dee2aaSAndroid Build Coastguard Worker } else if (texImageSupportsSizedInternalFormat && lum8SizedFormatSupported) {
1981*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage = GR_GL_LUMINANCE8_ALPHA8;
1982*c8dee2aaSAndroid Build Coastguard Worker } else {
1983*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage = GR_GL_LUMINANCE_ALPHA;
1984*c8dee2aaSAndroid Build Coastguard Worker }
1985*c8dee2aaSAndroid Build Coastguard Worker // See note in LUMINANCE8 section about not attaching to framebuffers.
1986*c8dee2aaSAndroid Build Coastguard Worker
1987*c8dee2aaSAndroid Build Coastguard Worker if (lum8Supported) {
1988*c8dee2aaSAndroid Build Coastguard Worker info.fColorTypeInfoCount = 1;
1989*c8dee2aaSAndroid Build Coastguard Worker info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount);
1990*c8dee2aaSAndroid Build Coastguard Worker int ctIdx = 0;
1991*c8dee2aaSAndroid Build Coastguard Worker // Format: LUMINANCE8_ALPHA8, Surface: kGrayAlpha_88
1992*c8dee2aaSAndroid Build Coastguard Worker {
1993*c8dee2aaSAndroid Build Coastguard Worker auto& ctInfo = info.fColorTypeInfos[ctIdx++];
1994*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fColorType = GrColorType::kGrayAlpha_88;
1995*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag;
1996*c8dee2aaSAndroid Build Coastguard Worker int idx = static_cast<int>(GrColorType::kGrayAlpha_88);
1997*c8dee2aaSAndroid Build Coastguard Worker if (fColorTypeToFormatTable[idx] == GrGLFormat::kUnknown) {
1998*c8dee2aaSAndroid Build Coastguard Worker this->setColorTypeFormat(GrColorType::kGrayAlpha_88,
1999*c8dee2aaSAndroid Build Coastguard Worker GrGLFormat::kLUMINANCE8_ALPHA8);
2000*c8dee2aaSAndroid Build Coastguard Worker }
2001*c8dee2aaSAndroid Build Coastguard Worker
2002*c8dee2aaSAndroid Build Coastguard Worker // External IO ColorTypes:
2003*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount = 2;
2004*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
2005*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount);
2006*c8dee2aaSAndroid Build Coastguard Worker int ioIdx = 0;
2007*c8dee2aaSAndroid Build Coastguard Worker // Format: LUMINANCE8, Surface: kGrayAlpha_88, Data: kGrayAlpha_88
2008*c8dee2aaSAndroid Build Coastguard Worker {
2009*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2010*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kGrayAlpha_88;
2011*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
2012*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = GR_GL_LUMINANCE_ALPHA;
2013*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = 0;
2014*c8dee2aaSAndroid Build Coastguard Worker }
2015*c8dee2aaSAndroid Build Coastguard Worker
2016*c8dee2aaSAndroid Build Coastguard Worker // Format: LUMINANCE8, Surface: kGrayAlpha_88, Data: kRGBA_8888
2017*c8dee2aaSAndroid Build Coastguard Worker {
2018*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2019*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kRGBA_8888;
2020*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
2021*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = 0;
2022*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RGBA;
2023*c8dee2aaSAndroid Build Coastguard Worker }
2024*c8dee2aaSAndroid Build Coastguard Worker }
2025*c8dee2aaSAndroid Build Coastguard Worker }
2026*c8dee2aaSAndroid Build Coastguard Worker }
2027*c8dee2aaSAndroid Build Coastguard Worker // Format: BGRA8
2028*c8dee2aaSAndroid Build Coastguard Worker {
2029*c8dee2aaSAndroid Build Coastguard Worker FormatInfo& info = this->getFormatInfo(GrGLFormat::kBGRA8);
2030*c8dee2aaSAndroid Build Coastguard Worker info.fFormatType = FormatType::kNormalizedFixedPoint;
2031*c8dee2aaSAndroid Build Coastguard Worker
2032*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultExternalFormat = GR_GL_BGRA;
2033*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
2034*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultColorType = GrColorType::kBGRA_8888;
2035*c8dee2aaSAndroid Build Coastguard Worker
2036*c8dee2aaSAndroid Build Coastguard Worker GrGLenum bgraTexImageFormat;
2037*c8dee2aaSAndroid Build Coastguard Worker // If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image
2038*c8dee2aaSAndroid Build Coastguard Worker // as a base format. Which base format depends on which extension is used.
2039*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
2040*c8dee2aaSAndroid Build Coastguard Worker // GL_EXT_texture_format_BGRA8888:
2041*c8dee2aaSAndroid Build Coastguard Worker // This extension adds GL_BGRA as an unsized internal format. However, it is
2042*c8dee2aaSAndroid Build Coastguard Worker // written against ES 2.0 and therefore doesn't define a GL_BGRA8 as ES 2.0 doesn't
2043*c8dee2aaSAndroid Build Coastguard Worker // have sized internal formats. See later where we check for tex storage BGRA8
2044*c8dee2aaSAndroid Build Coastguard Worker // support.
2045*c8dee2aaSAndroid Build Coastguard Worker bgraTexImageFormat = GR_GL_BGRA;
2046*c8dee2aaSAndroid Build Coastguard Worker } else {
2047*c8dee2aaSAndroid Build Coastguard Worker // GL_APPLE_texture_format_BGRA8888:
2048*c8dee2aaSAndroid Build Coastguard Worker // ES 2.0: the extension makes BGRA an external format but not an internal format.
2049*c8dee2aaSAndroid Build Coastguard Worker // ES 3.0: the extension explicitly states GL_BGRA8 is not a valid internal format
2050*c8dee2aaSAndroid Build Coastguard Worker // for glTexImage (just for glTexStorage).
2051*c8dee2aaSAndroid Build Coastguard Worker bgraTexImageFormat = GR_GL_RGBA;
2052*c8dee2aaSAndroid Build Coastguard Worker }
2053*c8dee2aaSAndroid Build Coastguard Worker
2054*c8dee2aaSAndroid Build Coastguard Worker // TexStorage requires using a sized internal format and BGRA8 is only supported if we have
2055*c8dee2aaSAndroid Build Coastguard Worker // the GL_APPLE_texture_format_BGRA8888 extension or if we have GL_EXT_texture_storage and
2056*c8dee2aaSAndroid Build Coastguard Worker // GL_EXT_texture_format_BGRA8888.
2057*c8dee2aaSAndroid Build Coastguard Worker bool supportsBGRATexStorage = false;
2058*c8dee2aaSAndroid Build Coastguard Worker
2059*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL_ES(standard)) {
2060*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
2061*c8dee2aaSAndroid Build Coastguard Worker // The GL_EXT_texture_format_BGRA8888 extension adds BGRA color renderbuffer support
2062*c8dee2aaSAndroid Build Coastguard Worker // for ES 2.0. The extension adds BGRA to the supported renerable formats in table
2063*c8dee2aaSAndroid Build Coastguard Worker // 4.5. In ES 2.0. All the extensions that add multisample support, all reference
2064*c8dee2aaSAndroid Build Coastguard Worker // table 4.5 as the formats that are supported. Thus we can use msaaRenderFlags.
2065*c8dee2aaSAndroid Build Coastguard Worker // Additionally, the renderable support was added in a later revision of the
2066*c8dee2aaSAndroid Build Coastguard Worker // extension. So it is possible for older drivers to support the extension but only
2067*c8dee2aaSAndroid Build Coastguard Worker // an early revision of it without renderable support. We have no way of
2068*c8dee2aaSAndroid Build Coastguard Worker // distinguishing between the two and assume renderable.
2069*c8dee2aaSAndroid Build Coastguard Worker
2070*c8dee2aaSAndroid Build Coastguard Worker
2071*c8dee2aaSAndroid Build Coastguard Worker info.fFlags = FormatInfo::kTexturable_Flag
2072*c8dee2aaSAndroid Build Coastguard Worker | FormatInfo::kTransfers_Flag;
2073*c8dee2aaSAndroid Build Coastguard Worker // Only enable BGRA msaa if we know we're going through Angle. The spec for
2074*c8dee2aaSAndroid Build Coastguard Worker // GL_EXT_texture_format_BGRA8888 was updated in 2016 to add support for GL_BGRA_EXT
2075*c8dee2aaSAndroid Build Coastguard Worker // as a sized, renderable format. But we may end up running on old drivers written
2076*c8dee2aaSAndroid Build Coastguard Worker // against earlier version of the spec. Also the interactions between all these
2077*c8dee2aaSAndroid Build Coastguard Worker // extensions are very suibtle and it wouldn't be hard for a driver to mess them up.
2078*c8dee2aaSAndroid Build Coastguard Worker // We are confident that Angle does it as we expect. Our non-angle test bots do seem
2079*c8dee2aaSAndroid Build Coastguard Worker // to pass and draw correctly so we could consider enabling this more broadly in the
2080*c8dee2aaSAndroid Build Coastguard Worker // future.
2081*c8dee2aaSAndroid Build Coastguard Worker // In addition, we also need to disable BGRA MSAA on Mesa. When a client attempts
2082*c8dee2aaSAndroid Build Coastguard Worker // to wrap a GPU-backed texture into an SkSurface with MSAA, Ganesh will create
2083*c8dee2aaSAndroid Build Coastguard Worker // a MSAA renderbuffer to first render to before resolving to the single-sampled
2084*c8dee2aaSAndroid Build Coastguard Worker // texture. Mesa claims to support EXT_texture_format_BGRA8888, and according to
2085*c8dee2aaSAndroid Build Coastguard Worker // the spec, this should imply support for both BGRA textures and renderbuffers.
2086*c8dee2aaSAndroid Build Coastguard Worker // In practice, however, Mesa only supports BGRA textures and will error on
2087*c8dee2aaSAndroid Build Coastguard Worker // glRenderbufferStorage* if the internalformat is BGRA.
2088*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.angleBackend() != GrGLANGLEBackend::kUnknown &&
2089*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.angleDriver() != GrGLDriver::kMesa) {
2090*c8dee2aaSAndroid Build Coastguard Worker // Angle incorrectly requires GL_BGRA8_EXT for the interalFormat for both ES2
2091*c8dee2aaSAndroid Build Coastguard Worker // and ES3 even though this extension does not define that value. The extension
2092*c8dee2aaSAndroid Build Coastguard Worker // only defines GL_BGRA_EXT as an internal format.
2093*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForRenderbuffer = GR_GL_BGRA8;
2094*c8dee2aaSAndroid Build Coastguard Worker info.fFlags |= msaaRenderFlags;
2095*c8dee2aaSAndroid Build Coastguard Worker } else {
2096*c8dee2aaSAndroid Build Coastguard Worker // It is not clear what the correct format to use on ES3 is. This extension only
2097*c8dee2aaSAndroid Build Coastguard Worker // defines GL_BGRA_EXT. That is definitely the correct thing to use on ES2, but
2098*c8dee2aaSAndroid Build Coastguard Worker // its unclear whether that is valid in ES3 or if it wants something like
2099*c8dee2aaSAndroid Build Coastguard Worker // GL_BGRA8_EXT (which is only defined in the apple extenstion). For now we set
2100*c8dee2aaSAndroid Build Coastguard Worker // everything to use BGRA since its the only explicitly defined value. Until we
2101*c8dee2aaSAndroid Build Coastguard Worker // enable MSAA for non-angle this is a moot point.
2102*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForRenderbuffer = GR_GL_BGRA;
2103*c8dee2aaSAndroid Build Coastguard Worker info.fFlags |= nonMSAARenderFlags;
2104*c8dee2aaSAndroid Build Coastguard Worker }
2105*c8dee2aaSAndroid Build Coastguard Worker // GL_EXT_texture storage has defined interactions with
2106*c8dee2aaSAndroid Build Coastguard Worker // GL_EXT_texture_format_BGRA8888. However, ES3 supports glTexStorage but
2107*c8dee2aaSAndroid Build Coastguard Worker // without GL_EXT_texture_storage it does not allow the BGRA8 sized internal format.
2108*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.hasExtension("GL_EXT_texture_storage") &&
2109*c8dee2aaSAndroid Build Coastguard Worker !formatWorkarounds.fDisableBGRATextureStorageForIntelWindowsES) {
2110*c8dee2aaSAndroid Build Coastguard Worker supportsBGRATexStorage = true;
2111*c8dee2aaSAndroid Build Coastguard Worker }
2112*c8dee2aaSAndroid Build Coastguard Worker } else if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
2113*c8dee2aaSAndroid Build Coastguard Worker // This APPLE extension introduces complexity on ES2. It leaves the internal format
2114*c8dee2aaSAndroid Build Coastguard Worker // as RGBA, but allows BGRA as the external format. From testing, it appears that
2115*c8dee2aaSAndroid Build Coastguard Worker // the driver remembers the external format when the texture is created (with
2116*c8dee2aaSAndroid Build Coastguard Worker // TexImage). If you then try to upload data in the other swizzle (with
2117*c8dee2aaSAndroid Build Coastguard Worker // TexSubImage), it fails. We could work around this, but it adds even more state
2118*c8dee2aaSAndroid Build Coastguard Worker // tracking to code that is already too tricky. Instead, we opt not to support BGRA
2119*c8dee2aaSAndroid Build Coastguard Worker // on ES2 with this extension. This also side-steps some ambiguous interactions with
2120*c8dee2aaSAndroid Build Coastguard Worker // the texture storage extension.
2121*c8dee2aaSAndroid Build Coastguard Worker if (version >= GR_GL_VER(3,0)) {
2122*c8dee2aaSAndroid Build Coastguard Worker // The APPLE extension doesn't explicitly make this renderable, but
2123*c8dee2aaSAndroid Build Coastguard Worker // internally it appears to use RGBA8, which we'll patch up below.
2124*c8dee2aaSAndroid Build Coastguard Worker info.fFlags = FormatInfo::kTexturable_Flag
2125*c8dee2aaSAndroid Build Coastguard Worker | FormatInfo::kTransfers_Flag
2126*c8dee2aaSAndroid Build Coastguard Worker | msaaRenderFlags;
2127*c8dee2aaSAndroid Build Coastguard Worker // The GL_APPLE_texture_format_BGRA8888 does not add support for BGRA color
2128*c8dee2aaSAndroid Build Coastguard Worker // renderbuffers at all so we use RGBA here.
2129*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForRenderbuffer = GR_GL_RGBA8;
2130*c8dee2aaSAndroid Build Coastguard Worker supportsBGRATexStorage = true;
2131*c8dee2aaSAndroid Build Coastguard Worker }
2132*c8dee2aaSAndroid Build Coastguard Worker }
2133*c8dee2aaSAndroid Build Coastguard Worker }
2134*c8dee2aaSAndroid Build Coastguard Worker if (texStorageSupported && supportsBGRATexStorage) {
2135*c8dee2aaSAndroid Build Coastguard Worker info.fFlags |= FormatInfo::kUseTexStorage_Flag;
2136*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage = GR_GL_BGRA8;
2137*c8dee2aaSAndroid Build Coastguard Worker } else {
2138*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage = bgraTexImageFormat;
2139*c8dee2aaSAndroid Build Coastguard Worker }
2140*c8dee2aaSAndroid Build Coastguard Worker
2141*c8dee2aaSAndroid Build Coastguard Worker if (SkToBool(info.fFlags & FormatInfo::kTexturable_Flag)) {
2142*c8dee2aaSAndroid Build Coastguard Worker info.fColorTypeInfoCount = 2;
2143*c8dee2aaSAndroid Build Coastguard Worker info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount);
2144*c8dee2aaSAndroid Build Coastguard Worker int ctIdx = 0;
2145*c8dee2aaSAndroid Build Coastguard Worker // Format: BGRA8, Surface: kBGRA_8888
2146*c8dee2aaSAndroid Build Coastguard Worker {
2147*c8dee2aaSAndroid Build Coastguard Worker auto& ctInfo = info.fColorTypeInfos[ctIdx++];
2148*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fColorType = GrColorType::kBGRA_8888;
2149*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
2150*c8dee2aaSAndroid Build Coastguard Worker this->setColorTypeFormat(GrColorType::kBGRA_8888, GrGLFormat::kBGRA8);
2151*c8dee2aaSAndroid Build Coastguard Worker
2152*c8dee2aaSAndroid Build Coastguard Worker // External IO ColorTypes:
2153*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount = 2;
2154*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
2155*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount);
2156*c8dee2aaSAndroid Build Coastguard Worker int ioIdx = 0;
2157*c8dee2aaSAndroid Build Coastguard Worker // Format: BGRA8, Surface: kBGRA_8888, Data: kBGRA_8888
2158*c8dee2aaSAndroid Build Coastguard Worker {
2159*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2160*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kBGRA_8888;
2161*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
2162*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = GR_GL_BGRA;
2163*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = 0;
2164*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat =
2165*c8dee2aaSAndroid Build Coastguard Worker formatWorkarounds.fDisallowBGRA8ReadPixels ? 0 : GR_GL_BGRA;
2166*c8dee2aaSAndroid Build Coastguard Worker // Not guaranteed by ES/WebGL.
2167*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fRequiresImplementationReadQuery = !GR_IS_GR_GL(standard);
2168*c8dee2aaSAndroid Build Coastguard Worker }
2169*c8dee2aaSAndroid Build Coastguard Worker
2170*c8dee2aaSAndroid Build Coastguard Worker // Format: BGRA8, Surface: kBGRA_8888, Data: kRGBA_8888
2171*c8dee2aaSAndroid Build Coastguard Worker {
2172*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2173*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kRGBA_8888;
2174*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
2175*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = 0;
2176*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RGBA;
2177*c8dee2aaSAndroid Build Coastguard Worker }
2178*c8dee2aaSAndroid Build Coastguard Worker }
2179*c8dee2aaSAndroid Build Coastguard Worker
2180*c8dee2aaSAndroid Build Coastguard Worker // Format: BGRA8, Surface: kRGB_888x
2181*c8dee2aaSAndroid Build Coastguard Worker {
2182*c8dee2aaSAndroid Build Coastguard Worker auto& ctInfo = info.fColorTypeInfos[ctIdx++];
2183*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fColorType = GrColorType::kRGB_888x;
2184*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag;
2185*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fReadSwizzle = skgpu::Swizzle::RGB1();
2186*c8dee2aaSAndroid Build Coastguard Worker
2187*c8dee2aaSAndroid Build Coastguard Worker // External IO ColorTypes:
2188*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount = 1;
2189*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
2190*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount);
2191*c8dee2aaSAndroid Build Coastguard Worker int ioIdx = 0;
2192*c8dee2aaSAndroid Build Coastguard Worker // Format: BGRA8, Surface: kRGB_888x, Data: kRGBA_888x
2193*c8dee2aaSAndroid Build Coastguard Worker {
2194*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2195*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kRGB_888x;
2196*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
2197*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = GR_GL_RGBA;
2198*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RGBA;
2199*c8dee2aaSAndroid Build Coastguard Worker }
2200*c8dee2aaSAndroid Build Coastguard Worker }
2201*c8dee2aaSAndroid Build Coastguard Worker }
2202*c8dee2aaSAndroid Build Coastguard Worker }
2203*c8dee2aaSAndroid Build Coastguard Worker
2204*c8dee2aaSAndroid Build Coastguard Worker // Format: RGB565
2205*c8dee2aaSAndroid Build Coastguard Worker {
2206*c8dee2aaSAndroid Build Coastguard Worker FormatInfo& info = this->getFormatInfo(GrGLFormat::kRGB565);
2207*c8dee2aaSAndroid Build Coastguard Worker info.fFormatType = FormatType::kNormalizedFixedPoint;
2208*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForRenderbuffer = GR_GL_RGB565;
2209*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultExternalFormat = GR_GL_RGB;
2210*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultExternalType = GR_GL_UNSIGNED_SHORT_5_6_5;
2211*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultColorType = GrColorType::kBGR_565;
2212*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
2213*c8dee2aaSAndroid Build Coastguard Worker if (version >= GR_GL_VER(4, 2) || ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
2214*c8dee2aaSAndroid Build Coastguard Worker info.fFlags = FormatInfo::kTexturable_Flag
2215*c8dee2aaSAndroid Build Coastguard Worker | FormatInfo::kTransfers_Flag
2216*c8dee2aaSAndroid Build Coastguard Worker | msaaRenderFlags;
2217*c8dee2aaSAndroid Build Coastguard Worker }
2218*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
2219*c8dee2aaSAndroid Build Coastguard Worker info.fFlags = FormatInfo::kTexturable_Flag
2220*c8dee2aaSAndroid Build Coastguard Worker | FormatInfo::kTransfers_Flag
2221*c8dee2aaSAndroid Build Coastguard Worker | msaaRenderFlags;
2222*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(standard)) {
2223*c8dee2aaSAndroid Build Coastguard Worker info.fFlags = FormatInfo::kTexturable_Flag
2224*c8dee2aaSAndroid Build Coastguard Worker | FormatInfo::kTransfers_Flag
2225*c8dee2aaSAndroid Build Coastguard Worker | msaaRenderFlags;
2226*c8dee2aaSAndroid Build Coastguard Worker }
2227*c8dee2aaSAndroid Build Coastguard Worker // 565 is not a sized internal format on desktop GL. So on desktop with
2228*c8dee2aaSAndroid Build Coastguard Worker // 565 we always use an unsized internal format to let the system pick
2229*c8dee2aaSAndroid Build Coastguard Worker // the best sized format to convert the 565 data to. Since TexStorage
2230*c8dee2aaSAndroid Build Coastguard Worker // only allows sized internal formats we disallow it.
2231*c8dee2aaSAndroid Build Coastguard Worker //
2232*c8dee2aaSAndroid Build Coastguard Worker // TODO: As of 4.2, regular GL supports 565. This logic is due for an
2233*c8dee2aaSAndroid Build Coastguard Worker // update.
2234*c8dee2aaSAndroid Build Coastguard Worker if (texStorageSupported && GR_IS_GR_GL_ES(standard)) {
2235*c8dee2aaSAndroid Build Coastguard Worker info.fFlags |= FormatInfo::kUseTexStorage_Flag;
2236*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage = GR_GL_RGB565;
2237*c8dee2aaSAndroid Build Coastguard Worker } else {
2238*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage =
2239*c8dee2aaSAndroid Build Coastguard Worker texImageSupportsSizedInternalFormat ? GR_GL_RGB565 : GR_GL_RGB;
2240*c8dee2aaSAndroid Build Coastguard Worker }
2241*c8dee2aaSAndroid Build Coastguard Worker
2242*c8dee2aaSAndroid Build Coastguard Worker if (SkToBool(info.fFlags &FormatInfo::kTexturable_Flag)) {
2243*c8dee2aaSAndroid Build Coastguard Worker info.fColorTypeInfoCount = 1;
2244*c8dee2aaSAndroid Build Coastguard Worker info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount);
2245*c8dee2aaSAndroid Build Coastguard Worker int ctIdx = 0;
2246*c8dee2aaSAndroid Build Coastguard Worker // Format: RGB565, Surface: kBGR_565
2247*c8dee2aaSAndroid Build Coastguard Worker {
2248*c8dee2aaSAndroid Build Coastguard Worker auto& ctInfo = info.fColorTypeInfos[ctIdx++];
2249*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fColorType = GrColorType::kBGR_565;
2250*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
2251*c8dee2aaSAndroid Build Coastguard Worker this->setColorTypeFormat(GrColorType::kBGR_565, GrGLFormat::kRGB565);
2252*c8dee2aaSAndroid Build Coastguard Worker
2253*c8dee2aaSAndroid Build Coastguard Worker // External IO ColorTypes:
2254*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount = 2;
2255*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
2256*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount);
2257*c8dee2aaSAndroid Build Coastguard Worker int ioIdx = 0;
2258*c8dee2aaSAndroid Build Coastguard Worker // Format: RGB565, Surface: kBGR_565, Data: kBGR_565
2259*c8dee2aaSAndroid Build Coastguard Worker {
2260*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2261*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kBGR_565;
2262*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_SHORT_5_6_5;
2263*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = GR_GL_RGB;
2264*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RGB;
2265*c8dee2aaSAndroid Build Coastguard Worker // Not guaranteed by ES/WebGL.
2266*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fRequiresImplementationReadQuery = !GR_IS_GR_GL(standard);
2267*c8dee2aaSAndroid Build Coastguard Worker }
2268*c8dee2aaSAndroid Build Coastguard Worker
2269*c8dee2aaSAndroid Build Coastguard Worker // Format: RGB565, Surface: kBGR_565, Data: kRGBA_8888
2270*c8dee2aaSAndroid Build Coastguard Worker {
2271*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2272*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kRGBA_8888;
2273*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
2274*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = 0;
2275*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RGBA;
2276*c8dee2aaSAndroid Build Coastguard Worker }
2277*c8dee2aaSAndroid Build Coastguard Worker }
2278*c8dee2aaSAndroid Build Coastguard Worker }
2279*c8dee2aaSAndroid Build Coastguard Worker }
2280*c8dee2aaSAndroid Build Coastguard Worker
2281*c8dee2aaSAndroid Build Coastguard Worker // Format: RGBA16F
2282*c8dee2aaSAndroid Build Coastguard Worker {
2283*c8dee2aaSAndroid Build Coastguard Worker FormatInfo& info = this->getFormatInfo(GrGLFormat::kRGBA16F);
2284*c8dee2aaSAndroid Build Coastguard Worker info.fFormatType = FormatType::kFloat;
2285*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForRenderbuffer = GR_GL_RGBA16F;
2286*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultExternalFormat = GR_GL_RGBA;
2287*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultExternalType = halfFloatType;
2288*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultColorType = GrColorType::kRGBA_F16;
2289*c8dee2aaSAndroid Build Coastguard Worker bool rgba16FTextureSupport = false;
2290*c8dee2aaSAndroid Build Coastguard Worker bool rgba16FRenderTargetSupport = false;
2291*c8dee2aaSAndroid Build Coastguard Worker
2292*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
2293*c8dee2aaSAndroid Build Coastguard Worker if (version >= GR_GL_VER(3, 0)) {
2294*c8dee2aaSAndroid Build Coastguard Worker rgba16FTextureSupport = true;
2295*c8dee2aaSAndroid Build Coastguard Worker rgba16FRenderTargetSupport = true;
2296*c8dee2aaSAndroid Build Coastguard Worker } else if (ctxInfo.hasExtension("GL_ARB_texture_float")) {
2297*c8dee2aaSAndroid Build Coastguard Worker rgba16FTextureSupport = true;
2298*c8dee2aaSAndroid Build Coastguard Worker }
2299*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
2300*c8dee2aaSAndroid Build Coastguard Worker if (version >= GR_GL_VER(3, 0)) {
2301*c8dee2aaSAndroid Build Coastguard Worker rgba16FTextureSupport = true;
2302*c8dee2aaSAndroid Build Coastguard Worker rgba16FRenderTargetSupport =
2303*c8dee2aaSAndroid Build Coastguard Worker version >= GR_GL_VER(3, 2) ||
2304*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_EXT_color_buffer_half_float") ||
2305*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_EXT_color_buffer_float");
2306*c8dee2aaSAndroid Build Coastguard Worker } else if (ctxInfo.hasExtension("GL_OES_texture_half_float") &&
2307*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_OES_texture_half_float_linear")) {
2308*c8dee2aaSAndroid Build Coastguard Worker rgba16FTextureSupport = true;
2309*c8dee2aaSAndroid Build Coastguard Worker rgba16FRenderTargetSupport = ctxInfo.hasExtension("GL_EXT_color_buffer_half_float");
2310*c8dee2aaSAndroid Build Coastguard Worker }
2311*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(standard)) {
2312*c8dee2aaSAndroid Build Coastguard Worker if (version >= GR_GL_VER(2, 0)) {
2313*c8dee2aaSAndroid Build Coastguard Worker rgba16FTextureSupport = true;
2314*c8dee2aaSAndroid Build Coastguard Worker rgba16FRenderTargetSupport =
2315*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_EXT_color_buffer_half_float") ||
2316*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("EXT_color_buffer_half_float") ||
2317*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_EXT_color_buffer_float") ||
2318*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("EXT_color_buffer_float");
2319*c8dee2aaSAndroid Build Coastguard Worker } else if ((ctxInfo.hasExtension("GL_OES_texture_half_float") ||
2320*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("OES_texture_half_float")) &&
2321*c8dee2aaSAndroid Build Coastguard Worker (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") ||
2322*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("OES_texture_half_float_linear"))) {
2323*c8dee2aaSAndroid Build Coastguard Worker rgba16FTextureSupport = true;
2324*c8dee2aaSAndroid Build Coastguard Worker // We don't check for EXT_color_buffer_float as it's only defined for WebGL 2.
2325*c8dee2aaSAndroid Build Coastguard Worker rgba16FRenderTargetSupport =
2326*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_EXT_color_buffer_half_float") ||
2327*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("EXT_color_buffer_half_float");
2328*c8dee2aaSAndroid Build Coastguard Worker }
2329*c8dee2aaSAndroid Build Coastguard Worker }
2330*c8dee2aaSAndroid Build Coastguard Worker
2331*c8dee2aaSAndroid Build Coastguard Worker if (rgba16FTextureSupport) {
2332*c8dee2aaSAndroid Build Coastguard Worker info.fFlags = FormatInfo::kTexturable_Flag | FormatInfo::kTransfers_Flag;
2333*c8dee2aaSAndroid Build Coastguard Worker if (rgba16FRenderTargetSupport) {
2334*c8dee2aaSAndroid Build Coastguard Worker info.fFlags |= fpRenderFlags;
2335*c8dee2aaSAndroid Build Coastguard Worker }
2336*c8dee2aaSAndroid Build Coastguard Worker }
2337*c8dee2aaSAndroid Build Coastguard Worker if (texStorageSupported && !formatWorkarounds.fDisableRGBA16FTexStorageForCrBug1008003) {
2338*c8dee2aaSAndroid Build Coastguard Worker info.fFlags |= FormatInfo::kUseTexStorage_Flag;
2339*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage = GR_GL_RGBA16F;
2340*c8dee2aaSAndroid Build Coastguard Worker } else {
2341*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage =
2342*c8dee2aaSAndroid Build Coastguard Worker texImageSupportsSizedInternalFormat ? GR_GL_RGBA16F : GR_GL_RGBA;
2343*c8dee2aaSAndroid Build Coastguard Worker }
2344*c8dee2aaSAndroid Build Coastguard Worker
2345*c8dee2aaSAndroid Build Coastguard Worker if (rgba16FTextureSupport) {
2346*c8dee2aaSAndroid Build Coastguard Worker uint32_t flags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
2347*c8dee2aaSAndroid Build Coastguard Worker
2348*c8dee2aaSAndroid Build Coastguard Worker info.fColorTypeInfoCount = 3;
2349*c8dee2aaSAndroid Build Coastguard Worker info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount);
2350*c8dee2aaSAndroid Build Coastguard Worker int ctIdx = 0;
2351*c8dee2aaSAndroid Build Coastguard Worker // Format: RGBA16F, Surface: kRGBA_F16
2352*c8dee2aaSAndroid Build Coastguard Worker {
2353*c8dee2aaSAndroid Build Coastguard Worker auto& ctInfo = info.fColorTypeInfos[ctIdx++];
2354*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fColorType = GrColorType::kRGBA_F16;
2355*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fFlags = flags;
2356*c8dee2aaSAndroid Build Coastguard Worker this->setColorTypeFormat(GrColorType::kRGBA_F16, GrGLFormat::kRGBA16F);
2357*c8dee2aaSAndroid Build Coastguard Worker
2358*c8dee2aaSAndroid Build Coastguard Worker // External IO ColorTypes:
2359*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount = 2;
2360*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
2361*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount);
2362*c8dee2aaSAndroid Build Coastguard Worker int ioIdx = 0;
2363*c8dee2aaSAndroid Build Coastguard Worker // Format: RGBA16F, Surface: kRGBA_F16, Data: kRGBA_F16
2364*c8dee2aaSAndroid Build Coastguard Worker {
2365*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2366*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kRGBA_F16;
2367*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = halfFloatType;
2368*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = GR_GL_RGBA;
2369*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RGBA;
2370*c8dee2aaSAndroid Build Coastguard Worker // Not guaranteed by ES/WebGL.
2371*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fRequiresImplementationReadQuery = !GR_IS_GR_GL(standard);
2372*c8dee2aaSAndroid Build Coastguard Worker }
2373*c8dee2aaSAndroid Build Coastguard Worker
2374*c8dee2aaSAndroid Build Coastguard Worker // Format: RGBA16F, Surface: kRGBA_F16, Data: kRGBA_F32
2375*c8dee2aaSAndroid Build Coastguard Worker {
2376*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2377*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kRGBA_F32;
2378*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_FLOAT;
2379*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = 0;
2380*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RGBA;
2381*c8dee2aaSAndroid Build Coastguard Worker }
2382*c8dee2aaSAndroid Build Coastguard Worker }
2383*c8dee2aaSAndroid Build Coastguard Worker
2384*c8dee2aaSAndroid Build Coastguard Worker // Format: RGBA16F, Surface: kRGBA_F16_Clamped
2385*c8dee2aaSAndroid Build Coastguard Worker {
2386*c8dee2aaSAndroid Build Coastguard Worker auto& ctInfo = info.fColorTypeInfos[ctIdx++];
2387*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fColorType = GrColorType::kRGBA_F16_Clamped;
2388*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fFlags = flags;
2389*c8dee2aaSAndroid Build Coastguard Worker this->setColorTypeFormat(GrColorType::kRGBA_F16_Clamped, GrGLFormat::kRGBA16F);
2390*c8dee2aaSAndroid Build Coastguard Worker
2391*c8dee2aaSAndroid Build Coastguard Worker // External IO ColorTypes:
2392*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount = 2;
2393*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
2394*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount);
2395*c8dee2aaSAndroid Build Coastguard Worker int ioIdx = 0;
2396*c8dee2aaSAndroid Build Coastguard Worker // Format: RGBA16F, Surface: kRGBA_F16_Clamped, Data: kRGBA_F16_Clamped
2397*c8dee2aaSAndroid Build Coastguard Worker {
2398*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2399*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kRGBA_F16_Clamped;
2400*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = halfFloatType;
2401*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = GR_GL_RGBA;
2402*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RGBA;
2403*c8dee2aaSAndroid Build Coastguard Worker // Not guaranteed by ES/WebGL.
2404*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fRequiresImplementationReadQuery = !GR_IS_GR_GL(standard);
2405*c8dee2aaSAndroid Build Coastguard Worker }
2406*c8dee2aaSAndroid Build Coastguard Worker
2407*c8dee2aaSAndroid Build Coastguard Worker // Format: RGBA16F, Surface: kRGBA_F16_Clamped, Data: kRGBA_F32
2408*c8dee2aaSAndroid Build Coastguard Worker {
2409*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2410*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kRGBA_F32;
2411*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_FLOAT;
2412*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = 0;
2413*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RGBA;
2414*c8dee2aaSAndroid Build Coastguard Worker }
2415*c8dee2aaSAndroid Build Coastguard Worker }
2416*c8dee2aaSAndroid Build Coastguard Worker // Format: RGBA16F, Surface: kRGB_F16F16F16x
2417*c8dee2aaSAndroid Build Coastguard Worker {
2418*c8dee2aaSAndroid Build Coastguard Worker auto& ctInfo = info.fColorTypeInfos[ctIdx++];
2419*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fColorType = GrColorType::kRGB_F16F16F16x;
2420*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag;
2421*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fReadSwizzle = skgpu::Swizzle::RGB1();
2422*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fWriteSwizzle = skgpu::Swizzle::RGB1();
2423*c8dee2aaSAndroid Build Coastguard Worker this->setColorTypeFormat(GrColorType::kRGB_F16F16F16x, GrGLFormat::kRGBA16F);
2424*c8dee2aaSAndroid Build Coastguard Worker
2425*c8dee2aaSAndroid Build Coastguard Worker // External IO ColorTypes:
2426*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount = 2;
2427*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
2428*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount);
2429*c8dee2aaSAndroid Build Coastguard Worker int ioIdx = 0;
2430*c8dee2aaSAndroid Build Coastguard Worker // Format: RGBA16F, Surface: kRGB_F16F16F16x, Data: kRGB_F16F16F16x
2431*c8dee2aaSAndroid Build Coastguard Worker {
2432*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2433*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kRGB_F16F16F16x;
2434*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = halfFloatType;
2435*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = GR_GL_RGBA;
2436*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RGBA;
2437*c8dee2aaSAndroid Build Coastguard Worker // Not guaranteed by ES/WebGL.
2438*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fRequiresImplementationReadQuery = !GR_IS_GR_GL(standard);
2439*c8dee2aaSAndroid Build Coastguard Worker }
2440*c8dee2aaSAndroid Build Coastguard Worker // Format: RGBA16F, Surface: kRGB_F16F16F16x, Data: kRGBA_F32
2441*c8dee2aaSAndroid Build Coastguard Worker {
2442*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2443*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kRGBA_F32;
2444*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_FLOAT;
2445*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = 0;
2446*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RGBA;
2447*c8dee2aaSAndroid Build Coastguard Worker }
2448*c8dee2aaSAndroid Build Coastguard Worker }
2449*c8dee2aaSAndroid Build Coastguard Worker }
2450*c8dee2aaSAndroid Build Coastguard Worker }
2451*c8dee2aaSAndroid Build Coastguard Worker
2452*c8dee2aaSAndroid Build Coastguard Worker // Format: R16F
2453*c8dee2aaSAndroid Build Coastguard Worker {
2454*c8dee2aaSAndroid Build Coastguard Worker FormatInfo& info = this->getFormatInfo(GrGLFormat::kR16F);
2455*c8dee2aaSAndroid Build Coastguard Worker info.fFormatType = FormatType::kFloat;
2456*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForRenderbuffer = GR_GL_R16F;
2457*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultExternalFormat = GR_GL_RED;
2458*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultExternalType = halfFloatType;
2459*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultColorType = GrColorType::kR_F16;
2460*c8dee2aaSAndroid Build Coastguard Worker bool r16FTextureSupport = false;
2461*c8dee2aaSAndroid Build Coastguard Worker bool r16FRenderTargetSupport = false;
2462*c8dee2aaSAndroid Build Coastguard Worker
2463*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
2464*c8dee2aaSAndroid Build Coastguard Worker if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_rg")) {
2465*c8dee2aaSAndroid Build Coastguard Worker r16FTextureSupport = true;
2466*c8dee2aaSAndroid Build Coastguard Worker r16FRenderTargetSupport = true;
2467*c8dee2aaSAndroid Build Coastguard Worker }
2468*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
2469*c8dee2aaSAndroid Build Coastguard Worker // It seems possible that a combination of GL_EXT_texture_rg and
2470*c8dee2aaSAndroid Build Coastguard Worker // GL_EXT_color_buffer_half_float might add this format to ES 2.0 but it is not entirely
2471*c8dee2aaSAndroid Build Coastguard Worker // clear. The latter mentions interaction but that may only be for renderbuffers as
2472*c8dee2aaSAndroid Build Coastguard Worker // neither adds the texture format explicitly.
2473*c8dee2aaSAndroid Build Coastguard Worker // GL_OES_texture_format_half_float makes no reference to RED formats.
2474*c8dee2aaSAndroid Build Coastguard Worker if (version >= GR_GL_VER(3, 0)) {
2475*c8dee2aaSAndroid Build Coastguard Worker r16FTextureSupport = true;
2476*c8dee2aaSAndroid Build Coastguard Worker r16FRenderTargetSupport = version >= GR_GL_VER(3, 2) ||
2477*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_EXT_color_buffer_float") ||
2478*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_EXT_color_buffer_half_float");
2479*c8dee2aaSAndroid Build Coastguard Worker }
2480*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(standard)) {
2481*c8dee2aaSAndroid Build Coastguard Worker if (version >= GR_GL_VER(2, 0)) {
2482*c8dee2aaSAndroid Build Coastguard Worker r16FTextureSupport = true;
2483*c8dee2aaSAndroid Build Coastguard Worker r16FRenderTargetSupport = ctxInfo.hasExtension("GL_EXT_color_buffer_float") ||
2484*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("EXT_color_buffer_float");
2485*c8dee2aaSAndroid Build Coastguard Worker }
2486*c8dee2aaSAndroid Build Coastguard Worker }
2487*c8dee2aaSAndroid Build Coastguard Worker
2488*c8dee2aaSAndroid Build Coastguard Worker if (r16FTextureSupport) {
2489*c8dee2aaSAndroid Build Coastguard Worker info.fFlags = FormatInfo::kTexturable_Flag | FormatInfo::kTransfers_Flag;
2490*c8dee2aaSAndroid Build Coastguard Worker if (r16FRenderTargetSupport) {
2491*c8dee2aaSAndroid Build Coastguard Worker info.fFlags |= fpRenderFlags;
2492*c8dee2aaSAndroid Build Coastguard Worker }
2493*c8dee2aaSAndroid Build Coastguard Worker }
2494*c8dee2aaSAndroid Build Coastguard Worker if (texStorageSupported) {
2495*c8dee2aaSAndroid Build Coastguard Worker info.fFlags |= FormatInfo::kUseTexStorage_Flag;
2496*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage = GR_GL_R16F;
2497*c8dee2aaSAndroid Build Coastguard Worker } else {
2498*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage =
2499*c8dee2aaSAndroid Build Coastguard Worker texImageSupportsSizedInternalFormat ? GR_GL_R16F : GR_GL_RED;
2500*c8dee2aaSAndroid Build Coastguard Worker }
2501*c8dee2aaSAndroid Build Coastguard Worker
2502*c8dee2aaSAndroid Build Coastguard Worker if (r16FTextureSupport) {
2503*c8dee2aaSAndroid Build Coastguard Worker // Format: R16F, Surface: kAlpha_F16
2504*c8dee2aaSAndroid Build Coastguard Worker info.fColorTypeInfoCount = 1;
2505*c8dee2aaSAndroid Build Coastguard Worker info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount);
2506*c8dee2aaSAndroid Build Coastguard Worker int ctIdx = 0;
2507*c8dee2aaSAndroid Build Coastguard Worker {
2508*c8dee2aaSAndroid Build Coastguard Worker auto& ctInfo = info.fColorTypeInfos[ctIdx++];
2509*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fColorType = GrColorType::kAlpha_F16;
2510*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
2511*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fReadSwizzle = skgpu::Swizzle("000r");
2512*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fWriteSwizzle = skgpu::Swizzle("a000");
2513*c8dee2aaSAndroid Build Coastguard Worker this->setColorTypeFormat(GrColorType::kAlpha_F16, GrGLFormat::kR16F);
2514*c8dee2aaSAndroid Build Coastguard Worker
2515*c8dee2aaSAndroid Build Coastguard Worker // External IO ColorTypes:
2516*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount = 2;
2517*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
2518*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount);
2519*c8dee2aaSAndroid Build Coastguard Worker int ioIdx = 0;
2520*c8dee2aaSAndroid Build Coastguard Worker // Format: R16F, Surface: kAlpha_F16, Data: kAlpha_F16
2521*c8dee2aaSAndroid Build Coastguard Worker {
2522*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2523*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kAlpha_F16;
2524*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = halfFloatType;
2525*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = GR_GL_RED;
2526*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RED;
2527*c8dee2aaSAndroid Build Coastguard Worker // Not guaranteed by ES/WebGL.
2528*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fRequiresImplementationReadQuery = !GR_IS_GR_GL(standard);
2529*c8dee2aaSAndroid Build Coastguard Worker }
2530*c8dee2aaSAndroid Build Coastguard Worker
2531*c8dee2aaSAndroid Build Coastguard Worker // Format: R16F, Surface: kAlpha_F16, Data: kAlpha_F32xxx
2532*c8dee2aaSAndroid Build Coastguard Worker {
2533*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2534*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kAlpha_F32xxx;
2535*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_FLOAT;
2536*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = 0;
2537*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RGBA;
2538*c8dee2aaSAndroid Build Coastguard Worker }
2539*c8dee2aaSAndroid Build Coastguard Worker }
2540*c8dee2aaSAndroid Build Coastguard Worker }
2541*c8dee2aaSAndroid Build Coastguard Worker }
2542*c8dee2aaSAndroid Build Coastguard Worker
2543*c8dee2aaSAndroid Build Coastguard Worker // Format: LUMINANCE16F
2544*c8dee2aaSAndroid Build Coastguard Worker {
2545*c8dee2aaSAndroid Build Coastguard Worker // NOTE: We disallow lum16f on ES devices if linear filtering modes are not
2546*c8dee2aaSAndroid Build Coastguard Worker // supported. This is for simplicity, but a more granular approach is possible.
2547*c8dee2aaSAndroid Build Coastguard Worker bool lum16FSupported = false;
2548*c8dee2aaSAndroid Build Coastguard Worker bool lum16FSizedFormatSupported = false;
2549*c8dee2aaSAndroid Build Coastguard Worker GrGLenum lumHalfFloatType = halfFloatType;
2550*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
2551*c8dee2aaSAndroid Build Coastguard Worker if (!fIsCoreProfile && ctxInfo.hasExtension("GL_ARB_texture_float")) {
2552*c8dee2aaSAndroid Build Coastguard Worker lum16FSupported = true;
2553*c8dee2aaSAndroid Build Coastguard Worker lum16FSizedFormatSupported = true;
2554*c8dee2aaSAndroid Build Coastguard Worker }
2555*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
2556*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
2557*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_OES_texture_half_float")) {
2558*c8dee2aaSAndroid Build Coastguard Worker lum16FSupported = true;
2559*c8dee2aaSAndroid Build Coastguard Worker // Even in ES 3.0+ LUMINANCE and GL_HALF_FLOAT are not listed as a valid
2560*c8dee2aaSAndroid Build Coastguard Worker // combination. Thus we must use GL_HALF_FLOAT_OES provided by the extension
2561*c8dee2aaSAndroid Build Coastguard Worker // GL_OES_texture_half_float. Note: these two types are not defined to be the same
2562*c8dee2aaSAndroid Build Coastguard Worker // value.
2563*c8dee2aaSAndroid Build Coastguard Worker lumHalfFloatType = GR_GL_HALF_FLOAT_OES;
2564*c8dee2aaSAndroid Build Coastguard Worker // Even on ES3 this extension is required to define LUMINANCE16F.
2565*c8dee2aaSAndroid Build Coastguard Worker lum16FSizedFormatSupported = ctxInfo.hasExtension("GL_EXT_texture_storage");
2566*c8dee2aaSAndroid Build Coastguard Worker }
2567*c8dee2aaSAndroid Build Coastguard Worker } // No WebGL support
2568*c8dee2aaSAndroid Build Coastguard Worker
2569*c8dee2aaSAndroid Build Coastguard Worker if (formatWorkarounds.fDisableLuminance16F) {
2570*c8dee2aaSAndroid Build Coastguard Worker lum16FSupported = false;
2571*c8dee2aaSAndroid Build Coastguard Worker }
2572*c8dee2aaSAndroid Build Coastguard Worker
2573*c8dee2aaSAndroid Build Coastguard Worker FormatInfo& info = this->getFormatInfo(GrGLFormat::kLUMINANCE16F);
2574*c8dee2aaSAndroid Build Coastguard Worker info.fFormatType = FormatType::kFloat;
2575*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForRenderbuffer = GR_GL_LUMINANCE16F;
2576*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultExternalFormat = GR_GL_LUMINANCE;
2577*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultExternalType = lumHalfFloatType;
2578*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultColorType = GrColorType::kGray_F16;
2579*c8dee2aaSAndroid Build Coastguard Worker
2580*c8dee2aaSAndroid Build Coastguard Worker if (lum16FSupported) {
2581*c8dee2aaSAndroid Build Coastguard Worker info.fFlags = FormatInfo::kTexturable_Flag | FormatInfo::kTransfers_Flag;
2582*c8dee2aaSAndroid Build Coastguard Worker
2583*c8dee2aaSAndroid Build Coastguard Worker if (texStorageSupported && lum16FSizedFormatSupported) {
2584*c8dee2aaSAndroid Build Coastguard Worker info.fFlags |= FormatInfo::kUseTexStorage_Flag;
2585*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage = GR_GL_LUMINANCE16F;
2586*c8dee2aaSAndroid Build Coastguard Worker } else if (texImageSupportsSizedInternalFormat && lum16FSizedFormatSupported) {
2587*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage = GR_GL_LUMINANCE16F;
2588*c8dee2aaSAndroid Build Coastguard Worker } else {
2589*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage = GR_GL_LUMINANCE;
2590*c8dee2aaSAndroid Build Coastguard Worker }
2591*c8dee2aaSAndroid Build Coastguard Worker
2592*c8dee2aaSAndroid Build Coastguard Worker info.fColorTypeInfoCount = 1;
2593*c8dee2aaSAndroid Build Coastguard Worker info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount);
2594*c8dee2aaSAndroid Build Coastguard Worker int ctIdx = 0;
2595*c8dee2aaSAndroid Build Coastguard Worker // Format: LUMINANCE16F, Surface: kAlpha_F16
2596*c8dee2aaSAndroid Build Coastguard Worker {
2597*c8dee2aaSAndroid Build Coastguard Worker auto& ctInfo = info.fColorTypeInfos[ctIdx++];
2598*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fColorType = GrColorType::kAlpha_F16;
2599*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag;
2600*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fReadSwizzle = skgpu::Swizzle("000r");
2601*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fWriteSwizzle = skgpu::Swizzle("aaa0");
2602*c8dee2aaSAndroid Build Coastguard Worker
2603*c8dee2aaSAndroid Build Coastguard Worker int idx = static_cast<int>(GrColorType::kAlpha_F16);
2604*c8dee2aaSAndroid Build Coastguard Worker if (fColorTypeToFormatTable[idx] == GrGLFormat::kUnknown) {
2605*c8dee2aaSAndroid Build Coastguard Worker this->setColorTypeFormat(GrColorType::kAlpha_F16, GrGLFormat::kLUMINANCE16F);
2606*c8dee2aaSAndroid Build Coastguard Worker }
2607*c8dee2aaSAndroid Build Coastguard Worker
2608*c8dee2aaSAndroid Build Coastguard Worker // External IO ColorTypes:
2609*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount = 2;
2610*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
2611*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount);
2612*c8dee2aaSAndroid Build Coastguard Worker int ioIdx = 0;
2613*c8dee2aaSAndroid Build Coastguard Worker // Format: LUMINANCE16F, Surface: kAlpha_F16, Data: kAlpha_F16
2614*c8dee2aaSAndroid Build Coastguard Worker {
2615*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2616*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kAlpha_F16;
2617*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = lumHalfFloatType;
2618*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = GR_GL_LUMINANCE;
2619*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = 0;
2620*c8dee2aaSAndroid Build Coastguard Worker }
2621*c8dee2aaSAndroid Build Coastguard Worker
2622*c8dee2aaSAndroid Build Coastguard Worker // Format: LUMINANCE16F, Surface: kAlpha_F16, Data: kRGBA_F32
2623*c8dee2aaSAndroid Build Coastguard Worker {
2624*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2625*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kRGBA_F32;
2626*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_FLOAT;
2627*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = 0;
2628*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RGBA;
2629*c8dee2aaSAndroid Build Coastguard Worker }
2630*c8dee2aaSAndroid Build Coastguard Worker }
2631*c8dee2aaSAndroid Build Coastguard Worker }
2632*c8dee2aaSAndroid Build Coastguard Worker }
2633*c8dee2aaSAndroid Build Coastguard Worker
2634*c8dee2aaSAndroid Build Coastguard Worker // Format: RGBx8
2635*c8dee2aaSAndroid Build Coastguard Worker {
2636*c8dee2aaSAndroid Build Coastguard Worker FormatInfo& info = this->getFormatInfo(GrGLFormat::kRGBX8);
2637*c8dee2aaSAndroid Build Coastguard Worker info.fFormatType = FormatType::kNormalizedFixedPoint;
2638*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForRenderbuffer = GR_GL_RGBX8;
2639*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultExternalFormat = GR_GL_RGB;
2640*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
2641*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultColorType = GrColorType::kRGB_888;
2642*c8dee2aaSAndroid Build Coastguard Worker
2643*c8dee2aaSAndroid Build Coastguard Worker bool supportsSizedRGBX = false;
2644*c8dee2aaSAndroid Build Coastguard Worker // The GL_ANGLE_rgbx_internal_format extension only adds the sized GL_RGBX8 type and does
2645*c8dee2aaSAndroid Build Coastguard Worker // not have a way to create a texture of that format with texImage using an unsized type. So
2646*c8dee2aaSAndroid Build Coastguard Worker // we require that we either have texture storage support or that tex image supports sized
2647*c8dee2aaSAndroid Build Coastguard Worker // formats to say that this format is supported.
2648*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL_ES(standard) && ctxInfo.hasExtension("GL_ANGLE_rgbx_internal_format") &&
2649*c8dee2aaSAndroid Build Coastguard Worker (texStorageSupported || texImageSupportsSizedInternalFormat)) {
2650*c8dee2aaSAndroid Build Coastguard Worker supportsSizedRGBX = true;
2651*c8dee2aaSAndroid Build Coastguard Worker }
2652*c8dee2aaSAndroid Build Coastguard Worker
2653*c8dee2aaSAndroid Build Coastguard Worker if (supportsSizedRGBX) {
2654*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage = GR_GL_RGBX8;
2655*c8dee2aaSAndroid Build Coastguard Worker info.fFlags = FormatInfo::kTexturable_Flag |
2656*c8dee2aaSAndroid Build Coastguard Worker FormatInfo::kTransfers_Flag |
2657*c8dee2aaSAndroid Build Coastguard Worker msaaRenderFlags;
2658*c8dee2aaSAndroid Build Coastguard Worker if (texStorageSupported) {
2659*c8dee2aaSAndroid Build Coastguard Worker info.fFlags |= FormatInfo::kUseTexStorage_Flag;
2660*c8dee2aaSAndroid Build Coastguard Worker }
2661*c8dee2aaSAndroid Build Coastguard Worker info.fColorTypeInfoCount = 1;
2662*c8dee2aaSAndroid Build Coastguard Worker info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount);
2663*c8dee2aaSAndroid Build Coastguard Worker int ctIdx = 0;
2664*c8dee2aaSAndroid Build Coastguard Worker // Format: RGBX8, Surface: kRGB_888x
2665*c8dee2aaSAndroid Build Coastguard Worker {
2666*c8dee2aaSAndroid Build Coastguard Worker auto& ctInfo = info.fColorTypeInfos[ctIdx++];
2667*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fColorType = GrColorType::kRGB_888x;
2668*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
2669*c8dee2aaSAndroid Build Coastguard Worker this->setColorTypeFormat(GrColorType::kRGB_888x, GrGLFormat::kRGBX8);
2670*c8dee2aaSAndroid Build Coastguard Worker
2671*c8dee2aaSAndroid Build Coastguard Worker // External IO ColorTypes:
2672*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount = 2;
2673*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
2674*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount);
2675*c8dee2aaSAndroid Build Coastguard Worker int ioIdx = 0;
2676*c8dee2aaSAndroid Build Coastguard Worker // Format: RGBX8, Surface: kRGB_888x, Data: kRGB_888
2677*c8dee2aaSAndroid Build Coastguard Worker {
2678*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2679*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kRGB_888;
2680*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
2681*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = GR_GL_RGB;
2682*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = 0;
2683*c8dee2aaSAndroid Build Coastguard Worker }
2684*c8dee2aaSAndroid Build Coastguard Worker
2685*c8dee2aaSAndroid Build Coastguard Worker // Format: RGBX8, Surface: kRGB_888x, Data: kRGB_888x
2686*c8dee2aaSAndroid Build Coastguard Worker {
2687*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2688*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kRGB_888x;
2689*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
2690*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = 0;
2691*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RGBX8;
2692*c8dee2aaSAndroid Build Coastguard Worker }
2693*c8dee2aaSAndroid Build Coastguard Worker }
2694*c8dee2aaSAndroid Build Coastguard Worker }
2695*c8dee2aaSAndroid Build Coastguard Worker }
2696*c8dee2aaSAndroid Build Coastguard Worker
2697*c8dee2aaSAndroid Build Coastguard Worker // Format: RGB8
2698*c8dee2aaSAndroid Build Coastguard Worker {
2699*c8dee2aaSAndroid Build Coastguard Worker FormatInfo& info = this->getFormatInfo(GrGLFormat::kRGB8);
2700*c8dee2aaSAndroid Build Coastguard Worker info.fFormatType = FormatType::kNormalizedFixedPoint;
2701*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForRenderbuffer = GR_GL_RGB8;
2702*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultExternalFormat = GR_GL_RGB;
2703*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
2704*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultColorType = GrColorType::kRGB_888;
2705*c8dee2aaSAndroid Build Coastguard Worker info.fFlags = FormatInfo::kTexturable_Flag | FormatInfo::kTransfers_Flag;
2706*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
2707*c8dee2aaSAndroid Build Coastguard Worker // Even in OpenGL 4.6 GL_RGB8 is required to be color renderable but not required to be
2708*c8dee2aaSAndroid Build Coastguard Worker // a supported render buffer format. Since we usually use render buffers for MSAA on
2709*c8dee2aaSAndroid Build Coastguard Worker // non-ES GL we don't support MSAA for GL_RGB8. On 4.2+ we could check using
2710*c8dee2aaSAndroid Build Coastguard Worker // glGetInternalFormativ(GL_RENDERBUFFER, GL_RGB8, GL_INTERNALFORMAT_SUPPORTED, ...) if
2711*c8dee2aaSAndroid Build Coastguard Worker // this becomes an issue.
2712*c8dee2aaSAndroid Build Coastguard Worker info.fFlags |= nonMSAARenderFlags;
2713*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
2714*c8dee2aaSAndroid Build Coastguard Worker // 3.0 and the extension support this as a render buffer format.
2715*c8dee2aaSAndroid Build Coastguard Worker if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8")) {
2716*c8dee2aaSAndroid Build Coastguard Worker info.fFlags |= msaaRenderFlags;
2717*c8dee2aaSAndroid Build Coastguard Worker }
2718*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(standard)) {
2719*c8dee2aaSAndroid Build Coastguard Worker // WebGL seems to support RBG8
2720*c8dee2aaSAndroid Build Coastguard Worker info.fFlags |= msaaRenderFlags;
2721*c8dee2aaSAndroid Build Coastguard Worker }
2722*c8dee2aaSAndroid Build Coastguard Worker if (texStorageSupported) {
2723*c8dee2aaSAndroid Build Coastguard Worker info.fFlags |= FormatInfo::kUseTexStorage_Flag;
2724*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage = GR_GL_RGB8;
2725*c8dee2aaSAndroid Build Coastguard Worker } else {
2726*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage =
2727*c8dee2aaSAndroid Build Coastguard Worker texImageSupportsSizedInternalFormat ? GR_GL_RGB8 : GR_GL_RGB;
2728*c8dee2aaSAndroid Build Coastguard Worker }
2729*c8dee2aaSAndroid Build Coastguard Worker
2730*c8dee2aaSAndroid Build Coastguard Worker info.fColorTypeInfoCount = 1;
2731*c8dee2aaSAndroid Build Coastguard Worker info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount);
2732*c8dee2aaSAndroid Build Coastguard Worker int ctIdx = 0;
2733*c8dee2aaSAndroid Build Coastguard Worker // Format: RGB8, Surface: kRGB_888x
2734*c8dee2aaSAndroid Build Coastguard Worker {
2735*c8dee2aaSAndroid Build Coastguard Worker auto& ctInfo = info.fColorTypeInfos[ctIdx++];
2736*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fColorType = GrColorType::kRGB_888x;
2737*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
2738*c8dee2aaSAndroid Build Coastguard Worker
2739*c8dee2aaSAndroid Build Coastguard Worker int idx = static_cast<int>(GrColorType::kRGB_888x);
2740*c8dee2aaSAndroid Build Coastguard Worker if (fColorTypeToFormatTable[idx] == GrGLFormat::kUnknown) {
2741*c8dee2aaSAndroid Build Coastguard Worker this->setColorTypeFormat(GrColorType::kRGB_888x, GrGLFormat::kRGB8);
2742*c8dee2aaSAndroid Build Coastguard Worker }
2743*c8dee2aaSAndroid Build Coastguard Worker
2744*c8dee2aaSAndroid Build Coastguard Worker // External IO ColorTypes:
2745*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount = 2;
2746*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
2747*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount);
2748*c8dee2aaSAndroid Build Coastguard Worker int ioIdx = 0;
2749*c8dee2aaSAndroid Build Coastguard Worker // Format: RGB8, Surface: kRGB_888x, Data: kRGB_888
2750*c8dee2aaSAndroid Build Coastguard Worker {
2751*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2752*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kRGB_888;
2753*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
2754*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = GR_GL_RGB;
2755*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = 0;
2756*c8dee2aaSAndroid Build Coastguard Worker }
2757*c8dee2aaSAndroid Build Coastguard Worker
2758*c8dee2aaSAndroid Build Coastguard Worker // Format: RGB8, Surface: kRGB_888x, Data: kRGBA_8888
2759*c8dee2aaSAndroid Build Coastguard Worker {
2760*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2761*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kRGBA_8888;
2762*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
2763*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = 0;
2764*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RGBA;
2765*c8dee2aaSAndroid Build Coastguard Worker }
2766*c8dee2aaSAndroid Build Coastguard Worker }
2767*c8dee2aaSAndroid Build Coastguard Worker }
2768*c8dee2aaSAndroid Build Coastguard Worker
2769*c8dee2aaSAndroid Build Coastguard Worker // Format: RG8
2770*c8dee2aaSAndroid Build Coastguard Worker {
2771*c8dee2aaSAndroid Build Coastguard Worker FormatInfo& info = this->getFormatInfo(GrGLFormat::kRG8);
2772*c8dee2aaSAndroid Build Coastguard Worker info.fFormatType = FormatType::kNormalizedFixedPoint;
2773*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForRenderbuffer = GR_GL_RG8;
2774*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultExternalFormat = GR_GL_RG;
2775*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
2776*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultColorType = GrColorType::kRG_88;
2777*c8dee2aaSAndroid Build Coastguard Worker bool rg8Support = false;
2778*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
2779*c8dee2aaSAndroid Build Coastguard Worker rg8Support = version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_rg");
2780*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
2781*c8dee2aaSAndroid Build Coastguard Worker rg8Support = version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_texture_rg");
2782*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(standard)) {
2783*c8dee2aaSAndroid Build Coastguard Worker rg8Support = version >= GR_GL_VER(2, 0);
2784*c8dee2aaSAndroid Build Coastguard Worker }
2785*c8dee2aaSAndroid Build Coastguard Worker if (rg8Support) {
2786*c8dee2aaSAndroid Build Coastguard Worker info.fFlags |= FormatInfo::kTexturable_Flag
2787*c8dee2aaSAndroid Build Coastguard Worker | FormatInfo::kTransfers_Flag
2788*c8dee2aaSAndroid Build Coastguard Worker | msaaRenderFlags;
2789*c8dee2aaSAndroid Build Coastguard Worker if (texStorageSupported) {
2790*c8dee2aaSAndroid Build Coastguard Worker info.fFlags |= FormatInfo::kUseTexStorage_Flag;
2791*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage = GR_GL_RG8;
2792*c8dee2aaSAndroid Build Coastguard Worker }
2793*c8dee2aaSAndroid Build Coastguard Worker }
2794*c8dee2aaSAndroid Build Coastguard Worker if (!(info.fFlags & FormatInfo::kUseTexStorage_Flag)) {
2795*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage =
2796*c8dee2aaSAndroid Build Coastguard Worker texImageSupportsSizedInternalFormat ? GR_GL_RG8 : GR_GL_RG;
2797*c8dee2aaSAndroid Build Coastguard Worker }
2798*c8dee2aaSAndroid Build Coastguard Worker if (rg8Support) {
2799*c8dee2aaSAndroid Build Coastguard Worker info.fColorTypeInfoCount = 1;
2800*c8dee2aaSAndroid Build Coastguard Worker info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount);
2801*c8dee2aaSAndroid Build Coastguard Worker int ctIdx = 0;
2802*c8dee2aaSAndroid Build Coastguard Worker // Format: RG8, Surface: kRG_88
2803*c8dee2aaSAndroid Build Coastguard Worker {
2804*c8dee2aaSAndroid Build Coastguard Worker auto& ctInfo = info.fColorTypeInfos[ctIdx++];
2805*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fColorType = GrColorType::kRG_88;
2806*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
2807*c8dee2aaSAndroid Build Coastguard Worker this->setColorTypeFormat(GrColorType::kRG_88, GrGLFormat::kRG8);
2808*c8dee2aaSAndroid Build Coastguard Worker
2809*c8dee2aaSAndroid Build Coastguard Worker // External IO ColorTypes:
2810*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount = 2;
2811*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
2812*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount);
2813*c8dee2aaSAndroid Build Coastguard Worker int ioIdx = 0;
2814*c8dee2aaSAndroid Build Coastguard Worker // Format: RG8, Surface: kRG_88, Data: kRG_88
2815*c8dee2aaSAndroid Build Coastguard Worker {
2816*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2817*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kRG_88;
2818*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
2819*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = GR_GL_RG;
2820*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = 0;
2821*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard) && !formatWorkarounds.fDisallowDirectRG8ReadPixels) {
2822*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RG;
2823*c8dee2aaSAndroid Build Coastguard Worker }
2824*c8dee2aaSAndroid Build Coastguard Worker }
2825*c8dee2aaSAndroid Build Coastguard Worker
2826*c8dee2aaSAndroid Build Coastguard Worker // Format: RG8, Surface: kRG_88, Data: kRGBA_8888
2827*c8dee2aaSAndroid Build Coastguard Worker {
2828*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2829*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kRGBA_8888;
2830*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
2831*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = 0;
2832*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RGBA;
2833*c8dee2aaSAndroid Build Coastguard Worker }
2834*c8dee2aaSAndroid Build Coastguard Worker }
2835*c8dee2aaSAndroid Build Coastguard Worker }
2836*c8dee2aaSAndroid Build Coastguard Worker }
2837*c8dee2aaSAndroid Build Coastguard Worker
2838*c8dee2aaSAndroid Build Coastguard Worker // Format: RGB10_A2
2839*c8dee2aaSAndroid Build Coastguard Worker {
2840*c8dee2aaSAndroid Build Coastguard Worker FormatInfo& info = this->getFormatInfo(GrGLFormat::kRGB10_A2);
2841*c8dee2aaSAndroid Build Coastguard Worker info.fFormatType = FormatType::kNormalizedFixedPoint;
2842*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForRenderbuffer = GR_GL_RGB10_A2;
2843*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultExternalFormat = GR_GL_RGBA;
2844*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultExternalType = GR_GL_UNSIGNED_INT_2_10_10_10_REV;
2845*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultColorType = GrColorType::kRGBA_1010102;
2846*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard) ||
2847*c8dee2aaSAndroid Build Coastguard Worker (GR_IS_GR_GL_ES(standard) && version >= GR_GL_VER(3, 0))) {
2848*c8dee2aaSAndroid Build Coastguard Worker info.fFlags = FormatInfo::kTexturable_Flag
2849*c8dee2aaSAndroid Build Coastguard Worker | FormatInfo::kTransfers_Flag
2850*c8dee2aaSAndroid Build Coastguard Worker | msaaRenderFlags;
2851*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard) &&
2852*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_EXT_texture_type_2_10_10_10_REV")) {
2853*c8dee2aaSAndroid Build Coastguard Worker info.fFlags = FormatInfo::kTexturable_Flag | FormatInfo::kTransfers_Flag;
2854*c8dee2aaSAndroid Build Coastguard Worker } // No WebGL support
2855*c8dee2aaSAndroid Build Coastguard Worker
2856*c8dee2aaSAndroid Build Coastguard Worker if (texStorageSupported) {
2857*c8dee2aaSAndroid Build Coastguard Worker info.fFlags |= FormatInfo::kUseTexStorage_Flag;
2858*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage = GR_GL_RGB10_A2;
2859*c8dee2aaSAndroid Build Coastguard Worker } else {
2860*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage =
2861*c8dee2aaSAndroid Build Coastguard Worker texImageSupportsSizedInternalFormat ? GR_GL_RGB10_A2 : GR_GL_RGBA;
2862*c8dee2aaSAndroid Build Coastguard Worker }
2863*c8dee2aaSAndroid Build Coastguard Worker
2864*c8dee2aaSAndroid Build Coastguard Worker if (SkToBool(info.fFlags & FormatInfo::kTexturable_Flag)) {
2865*c8dee2aaSAndroid Build Coastguard Worker bool supportsBGRAColorType = GR_IS_GR_GL(standard) &&
2866*c8dee2aaSAndroid Build Coastguard Worker (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra"));
2867*c8dee2aaSAndroid Build Coastguard Worker
2868*c8dee2aaSAndroid Build Coastguard Worker info.fColorTypeInfoCount = supportsBGRAColorType ? 3 : 2;
2869*c8dee2aaSAndroid Build Coastguard Worker info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount);
2870*c8dee2aaSAndroid Build Coastguard Worker int ctIdx = 0;
2871*c8dee2aaSAndroid Build Coastguard Worker // Format: RGB10_A2, Surface: kRGBA_1010102
2872*c8dee2aaSAndroid Build Coastguard Worker {
2873*c8dee2aaSAndroid Build Coastguard Worker auto& ctInfo = info.fColorTypeInfos[ctIdx++];
2874*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fColorType = GrColorType::kRGBA_1010102;
2875*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
2876*c8dee2aaSAndroid Build Coastguard Worker this->setColorTypeFormat(GrColorType::kRGBA_1010102, GrGLFormat::kRGB10_A2);
2877*c8dee2aaSAndroid Build Coastguard Worker
2878*c8dee2aaSAndroid Build Coastguard Worker // External IO ColorTypes:
2879*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount = 2;
2880*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
2881*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount);
2882*c8dee2aaSAndroid Build Coastguard Worker int ioIdx = 0;
2883*c8dee2aaSAndroid Build Coastguard Worker // Format: RGB10_A2, Surface: kRGBA_1010102, Data: kRGBA_1010102
2884*c8dee2aaSAndroid Build Coastguard Worker {
2885*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2886*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kRGBA_1010102;
2887*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_INT_2_10_10_10_REV;
2888*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = GR_GL_RGBA;
2889*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RGBA;
2890*c8dee2aaSAndroid Build Coastguard Worker // Not guaranteed by ES/WebGL.
2891*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fRequiresImplementationReadQuery = !GR_IS_GR_GL(standard);
2892*c8dee2aaSAndroid Build Coastguard Worker }
2893*c8dee2aaSAndroid Build Coastguard Worker
2894*c8dee2aaSAndroid Build Coastguard Worker // Format: RGB10_A2, Surface: kRGBA_1010102, Data: kRGBA_8888
2895*c8dee2aaSAndroid Build Coastguard Worker {
2896*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2897*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kRGBA_8888;
2898*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
2899*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = 0;
2900*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RGBA;
2901*c8dee2aaSAndroid Build Coastguard Worker }
2902*c8dee2aaSAndroid Build Coastguard Worker }
2903*c8dee2aaSAndroid Build Coastguard Worker //------------------------------------------------------------------
2904*c8dee2aaSAndroid Build Coastguard Worker // Format: RGB10_A2, Surface: kBGRA_1010102
2905*c8dee2aaSAndroid Build Coastguard Worker if (supportsBGRAColorType) {
2906*c8dee2aaSAndroid Build Coastguard Worker auto& ctInfo = info.fColorTypeInfos[ctIdx++];
2907*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fColorType = GrColorType::kBGRA_1010102;
2908*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
2909*c8dee2aaSAndroid Build Coastguard Worker this->setColorTypeFormat(GrColorType::kBGRA_1010102, GrGLFormat::kRGB10_A2);
2910*c8dee2aaSAndroid Build Coastguard Worker
2911*c8dee2aaSAndroid Build Coastguard Worker // External IO ColorTypes:
2912*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount = 2;
2913*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
2914*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount);
2915*c8dee2aaSAndroid Build Coastguard Worker int ioIdx = 0;
2916*c8dee2aaSAndroid Build Coastguard Worker // Format: RGB10_A2, Surface: kBGRA_1010102, Data: kBGRA_1010102
2917*c8dee2aaSAndroid Build Coastguard Worker {
2918*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2919*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kBGRA_1010102;
2920*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_INT_2_10_10_10_REV;
2921*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = GR_GL_BGRA;
2922*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat =
2923*c8dee2aaSAndroid Build Coastguard Worker formatWorkarounds.fDisallowBGRA8ReadPixels ? 0 : GR_GL_BGRA;
2924*c8dee2aaSAndroid Build Coastguard Worker // Not guaranteed by ES/WebGL.
2925*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fRequiresImplementationReadQuery = !GR_IS_GR_GL(standard);
2926*c8dee2aaSAndroid Build Coastguard Worker }
2927*c8dee2aaSAndroid Build Coastguard Worker
2928*c8dee2aaSAndroid Build Coastguard Worker // Format: RGB10_A2, Surface: kBGRA_1010102, Data: kRGBA_8888
2929*c8dee2aaSAndroid Build Coastguard Worker {
2930*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2931*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kRGBA_8888;
2932*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
2933*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = 0;
2934*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RGBA;
2935*c8dee2aaSAndroid Build Coastguard Worker }
2936*c8dee2aaSAndroid Build Coastguard Worker }
2937*c8dee2aaSAndroid Build Coastguard Worker // Format: RGB10_A2, Surface: kRGB_101010x
2938*c8dee2aaSAndroid Build Coastguard Worker {
2939*c8dee2aaSAndroid Build Coastguard Worker auto& ctInfo = info.fColorTypeInfos[ctIdx++];
2940*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fColorType = GrColorType::kRGB_101010x;
2941*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag;
2942*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fReadSwizzle = skgpu::Swizzle::RGB1();
2943*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fWriteSwizzle = skgpu::Swizzle::RGB1();
2944*c8dee2aaSAndroid Build Coastguard Worker this->setColorTypeFormat(GrColorType::kRGB_101010x, GrGLFormat::kRGB10_A2);
2945*c8dee2aaSAndroid Build Coastguard Worker
2946*c8dee2aaSAndroid Build Coastguard Worker // External IO ColorTypes:
2947*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount = 2;
2948*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
2949*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount);
2950*c8dee2aaSAndroid Build Coastguard Worker int ioIdx = 0;
2951*c8dee2aaSAndroid Build Coastguard Worker // Format: RGB10_A2, Surface: kRGB_101010x, Data: kRGB_101010x
2952*c8dee2aaSAndroid Build Coastguard Worker {
2953*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2954*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kRGB_101010x;
2955*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_INT_2_10_10_10_REV;
2956*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = GR_GL_RGBA;
2957*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RGBA;
2958*c8dee2aaSAndroid Build Coastguard Worker // Not guaranteed by ES/WebGL.
2959*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fRequiresImplementationReadQuery = !GR_IS_GR_GL(standard);
2960*c8dee2aaSAndroid Build Coastguard Worker }
2961*c8dee2aaSAndroid Build Coastguard Worker // Format: RGB10_A2, Surface: kRGB_101010x, Data: kRGBA_8888
2962*c8dee2aaSAndroid Build Coastguard Worker {
2963*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
2964*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kRGBA_8888;
2965*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
2966*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = 0;
2967*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RGBA;
2968*c8dee2aaSAndroid Build Coastguard Worker }
2969*c8dee2aaSAndroid Build Coastguard Worker }
2970*c8dee2aaSAndroid Build Coastguard Worker
2971*c8dee2aaSAndroid Build Coastguard Worker }
2972*c8dee2aaSAndroid Build Coastguard Worker }
2973*c8dee2aaSAndroid Build Coastguard Worker
2974*c8dee2aaSAndroid Build Coastguard Worker // Format: RGBA4
2975*c8dee2aaSAndroid Build Coastguard Worker {
2976*c8dee2aaSAndroid Build Coastguard Worker FormatInfo& info = this->getFormatInfo(GrGLFormat::kRGBA4);
2977*c8dee2aaSAndroid Build Coastguard Worker info.fFormatType = FormatType::kNormalizedFixedPoint;
2978*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForRenderbuffer = GR_GL_RGBA4;
2979*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultExternalFormat = GR_GL_RGBA;
2980*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
2981*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultColorType = GrColorType::kABGR_4444;
2982*c8dee2aaSAndroid Build Coastguard Worker info.fFlags = FormatInfo::kTexturable_Flag | FormatInfo::kTransfers_Flag;
2983*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
2984*c8dee2aaSAndroid Build Coastguard Worker if (version >= GR_GL_VER(4, 2)) {
2985*c8dee2aaSAndroid Build Coastguard Worker info.fFlags |= msaaRenderFlags;
2986*c8dee2aaSAndroid Build Coastguard Worker }
2987*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
2988*c8dee2aaSAndroid Build Coastguard Worker info.fFlags |= msaaRenderFlags;
2989*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(standard)) {
2990*c8dee2aaSAndroid Build Coastguard Worker info.fFlags |= msaaRenderFlags;
2991*c8dee2aaSAndroid Build Coastguard Worker }
2992*c8dee2aaSAndroid Build Coastguard Worker if (texStorageSupported) {
2993*c8dee2aaSAndroid Build Coastguard Worker info.fFlags |= FormatInfo::kUseTexStorage_Flag;
2994*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage = GR_GL_RGBA4;
2995*c8dee2aaSAndroid Build Coastguard Worker } else {
2996*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage =
2997*c8dee2aaSAndroid Build Coastguard Worker texImageSupportsSizedInternalFormat ? GR_GL_RGBA4 : GR_GL_RGBA;
2998*c8dee2aaSAndroid Build Coastguard Worker }
2999*c8dee2aaSAndroid Build Coastguard Worker
3000*c8dee2aaSAndroid Build Coastguard Worker info.fColorTypeInfoCount = 1;
3001*c8dee2aaSAndroid Build Coastguard Worker info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount);
3002*c8dee2aaSAndroid Build Coastguard Worker int ctIdx = 0;
3003*c8dee2aaSAndroid Build Coastguard Worker // Format: RGBA4, Surface: kABGR_4444
3004*c8dee2aaSAndroid Build Coastguard Worker {
3005*c8dee2aaSAndroid Build Coastguard Worker auto& ctInfo = info.fColorTypeInfos[ctIdx++];
3006*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fColorType = GrColorType::kABGR_4444;
3007*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
3008*c8dee2aaSAndroid Build Coastguard Worker this->setColorTypeFormat(GrColorType::kABGR_4444, GrGLFormat::kRGBA4);
3009*c8dee2aaSAndroid Build Coastguard Worker
3010*c8dee2aaSAndroid Build Coastguard Worker // External IO ColorTypes:
3011*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount = 2;
3012*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
3013*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount);
3014*c8dee2aaSAndroid Build Coastguard Worker int ioIdx = 0;
3015*c8dee2aaSAndroid Build Coastguard Worker // Format: RGBA4, Surface: kABGR_4444, Data: kABGR_4444
3016*c8dee2aaSAndroid Build Coastguard Worker {
3017*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
3018*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kABGR_4444;
3019*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
3020*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = GR_GL_RGBA;
3021*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RGBA;
3022*c8dee2aaSAndroid Build Coastguard Worker // Not guaranteed by ES/WebGL.
3023*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fRequiresImplementationReadQuery = !GR_IS_GR_GL(standard);
3024*c8dee2aaSAndroid Build Coastguard Worker }
3025*c8dee2aaSAndroid Build Coastguard Worker
3026*c8dee2aaSAndroid Build Coastguard Worker // Format: RGBA4, Surface: kABGR_4444, Data: kRGBA_8888
3027*c8dee2aaSAndroid Build Coastguard Worker {
3028*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
3029*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kRGBA_8888;
3030*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
3031*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = 0;
3032*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RGBA;
3033*c8dee2aaSAndroid Build Coastguard Worker }
3034*c8dee2aaSAndroid Build Coastguard Worker }
3035*c8dee2aaSAndroid Build Coastguard Worker }
3036*c8dee2aaSAndroid Build Coastguard Worker
3037*c8dee2aaSAndroid Build Coastguard Worker // Format: SRGB8_ALPHA8
3038*c8dee2aaSAndroid Build Coastguard Worker {
3039*c8dee2aaSAndroid Build Coastguard Worker FormatInfo& info = this->getFormatInfo(GrGLFormat::kSRGB8_ALPHA8);
3040*c8dee2aaSAndroid Build Coastguard Worker info.fFormatType = FormatType::kNormalizedFixedPoint;
3041*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForRenderbuffer = GR_GL_SRGB8_ALPHA8;
3042*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
3043*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultColorType = GrColorType::kRGBA_8888_SRGB;
3044*c8dee2aaSAndroid Build Coastguard Worker
3045*c8dee2aaSAndroid Build Coastguard Worker // We may modify the default external format below.
3046*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultExternalFormat = GR_GL_RGBA;
3047*c8dee2aaSAndroid Build Coastguard Worker bool srgb8Alpha8TexStorageSupported = texStorageSupported;
3048*c8dee2aaSAndroid Build Coastguard Worker bool srgb8Alpha8TextureSupport = false;
3049*c8dee2aaSAndroid Build Coastguard Worker bool srgb8Alpha8RenderTargetSupport = false;
3050*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
3051*c8dee2aaSAndroid Build Coastguard Worker if (version >= GR_GL_VER(3, 0)) {
3052*c8dee2aaSAndroid Build Coastguard Worker srgb8Alpha8TextureSupport = true;
3053*c8dee2aaSAndroid Build Coastguard Worker srgb8Alpha8RenderTargetSupport = true;
3054*c8dee2aaSAndroid Build Coastguard Worker } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
3055*c8dee2aaSAndroid Build Coastguard Worker srgb8Alpha8TextureSupport = true;
3056*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
3057*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
3058*c8dee2aaSAndroid Build Coastguard Worker srgb8Alpha8RenderTargetSupport = true;
3059*c8dee2aaSAndroid Build Coastguard Worker }
3060*c8dee2aaSAndroid Build Coastguard Worker }
3061*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
3062*c8dee2aaSAndroid Build Coastguard Worker if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_sRGB")) {
3063*c8dee2aaSAndroid Build Coastguard Worker srgb8Alpha8TextureSupport = true;
3064*c8dee2aaSAndroid Build Coastguard Worker srgb8Alpha8RenderTargetSupport = true;
3065*c8dee2aaSAndroid Build Coastguard Worker }
3066*c8dee2aaSAndroid Build Coastguard Worker if (version < GR_GL_VER(3, 0)) {
3067*c8dee2aaSAndroid Build Coastguard Worker // ES 2.0 requires that the external format matches the internal format.
3068*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultExternalFormat = GR_GL_SRGB_ALPHA;
3069*c8dee2aaSAndroid Build Coastguard Worker // There is no defined interaction between GL_EXT_sRGB and GL_EXT_texture_storage.
3070*c8dee2aaSAndroid Build Coastguard Worker srgb8Alpha8TexStorageSupported = false;
3071*c8dee2aaSAndroid Build Coastguard Worker }
3072*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(standard)) {
3073*c8dee2aaSAndroid Build Coastguard Worker // sRGB extension should be on most WebGL 1.0 contexts, although sometimes under 2
3074*c8dee2aaSAndroid Build Coastguard Worker // names.
3075*c8dee2aaSAndroid Build Coastguard Worker if (version >= GR_GL_VER(2, 0) || ctxInfo.hasExtension("GL_EXT_sRGB") ||
3076*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("EXT_sRGB")) {
3077*c8dee2aaSAndroid Build Coastguard Worker srgb8Alpha8TextureSupport = true;
3078*c8dee2aaSAndroid Build Coastguard Worker srgb8Alpha8RenderTargetSupport = true;
3079*c8dee2aaSAndroid Build Coastguard Worker }
3080*c8dee2aaSAndroid Build Coastguard Worker if (version < GR_GL_VER(2, 0)) {
3081*c8dee2aaSAndroid Build Coastguard Worker // WebGL 1.0 requires that the external format matches the internal format.
3082*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultExternalFormat = GR_GL_SRGB_ALPHA;
3083*c8dee2aaSAndroid Build Coastguard Worker // There is no extension to WebGL 1 that adds glTexStorage.
3084*c8dee2aaSAndroid Build Coastguard Worker SkASSERT(!srgb8Alpha8TexStorageSupported);
3085*c8dee2aaSAndroid Build Coastguard Worker }
3086*c8dee2aaSAndroid Build Coastguard Worker }
3087*c8dee2aaSAndroid Build Coastguard Worker
3088*c8dee2aaSAndroid Build Coastguard Worker if (srgb8Alpha8TextureSupport) {
3089*c8dee2aaSAndroid Build Coastguard Worker info.fFlags = FormatInfo::kTexturable_Flag | FormatInfo::kTransfers_Flag;
3090*c8dee2aaSAndroid Build Coastguard Worker if (srgb8Alpha8RenderTargetSupport) {
3091*c8dee2aaSAndroid Build Coastguard Worker info.fFlags |= formatWorkarounds.fDisableSRGBRenderWithMSAAForMacAMD
3092*c8dee2aaSAndroid Build Coastguard Worker ? nonMSAARenderFlags
3093*c8dee2aaSAndroid Build Coastguard Worker : msaaRenderFlags;
3094*c8dee2aaSAndroid Build Coastguard Worker }
3095*c8dee2aaSAndroid Build Coastguard Worker }
3096*c8dee2aaSAndroid Build Coastguard Worker if (srgb8Alpha8TexStorageSupported) {
3097*c8dee2aaSAndroid Build Coastguard Worker info.fFlags |= FormatInfo::kUseTexStorage_Flag;
3098*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage = GR_GL_SRGB8_ALPHA8;
3099*c8dee2aaSAndroid Build Coastguard Worker } else {
3100*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage =
3101*c8dee2aaSAndroid Build Coastguard Worker texImageSupportsSizedInternalFormat ? GR_GL_SRGB8_ALPHA8 : GR_GL_SRGB_ALPHA;
3102*c8dee2aaSAndroid Build Coastguard Worker }
3103*c8dee2aaSAndroid Build Coastguard Worker
3104*c8dee2aaSAndroid Build Coastguard Worker if (srgb8Alpha8TextureSupport) {
3105*c8dee2aaSAndroid Build Coastguard Worker info.fColorTypeInfoCount = 1;
3106*c8dee2aaSAndroid Build Coastguard Worker info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount);
3107*c8dee2aaSAndroid Build Coastguard Worker int ctIdx = 0;
3108*c8dee2aaSAndroid Build Coastguard Worker // Format: SRGB8_ALPHA8, Surface: kRGBA_8888_SRGB
3109*c8dee2aaSAndroid Build Coastguard Worker {
3110*c8dee2aaSAndroid Build Coastguard Worker auto& ctInfo = info.fColorTypeInfos[ctIdx++];
3111*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fColorType = GrColorType::kRGBA_8888_SRGB;
3112*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
3113*c8dee2aaSAndroid Build Coastguard Worker this->setColorTypeFormat(GrColorType::kRGBA_8888_SRGB, GrGLFormat::kSRGB8_ALPHA8);
3114*c8dee2aaSAndroid Build Coastguard Worker
3115*c8dee2aaSAndroid Build Coastguard Worker // External IO ColorTypes:
3116*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount = 1;
3117*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
3118*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount);
3119*c8dee2aaSAndroid Build Coastguard Worker int ioIdx = 0;
3120*c8dee2aaSAndroid Build Coastguard Worker
3121*c8dee2aaSAndroid Build Coastguard Worker // Format: SRGB8_ALPHA8, Surface: kRGBA_8888_SRGB, Data: kRGBA_8888_SRGB
3122*c8dee2aaSAndroid Build Coastguard Worker {
3123*c8dee2aaSAndroid Build Coastguard Worker // GL does not do srgb<->rgb conversions when transferring between cpu and gpu.
3124*c8dee2aaSAndroid Build Coastguard Worker // Thus, the external format is GL_RGBA. See below for note about ES2.0 and
3125*c8dee2aaSAndroid Build Coastguard Worker // glTex[Sub]Image.
3126*c8dee2aaSAndroid Build Coastguard Worker GrGLenum texImageExternalFormat = GR_GL_RGBA;
3127*c8dee2aaSAndroid Build Coastguard Worker
3128*c8dee2aaSAndroid Build Coastguard Worker // OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the
3129*c8dee2aaSAndroid Build Coastguard Worker // <format> param to Tex(Sub)Image. ES 2.0 requires the <internalFormat> and
3130*c8dee2aaSAndroid Build Coastguard Worker // <format> params to match. Thus, on ES 2.0 we will use GL_SRGB_ALPHA as the
3131*c8dee2aaSAndroid Build Coastguard Worker // <format> param. On OpenGL and ES 3.0+ GL_SRGB_ALPHA does not work for the
3132*c8dee2aaSAndroid Build Coastguard Worker // <format> param to glTexImage.
3133*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL_ES(standard) && version == GR_GL_VER(2,0)) {
3134*c8dee2aaSAndroid Build Coastguard Worker texImageExternalFormat = GR_GL_SRGB_ALPHA;
3135*c8dee2aaSAndroid Build Coastguard Worker }
3136*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
3137*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kRGBA_8888_SRGB;
3138*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
3139*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = texImageExternalFormat;
3140*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RGBA;
3141*c8dee2aaSAndroid Build Coastguard Worker }
3142*c8dee2aaSAndroid Build Coastguard Worker }
3143*c8dee2aaSAndroid Build Coastguard Worker }
3144*c8dee2aaSAndroid Build Coastguard Worker }
3145*c8dee2aaSAndroid Build Coastguard Worker
3146*c8dee2aaSAndroid Build Coastguard Worker // Format: COMPRESSED_RGB8_BC1
3147*c8dee2aaSAndroid Build Coastguard Worker {
3148*c8dee2aaSAndroid Build Coastguard Worker FormatInfo& info = this->getFormatInfo(GrGLFormat::kCOMPRESSED_RGB8_BC1);
3149*c8dee2aaSAndroid Build Coastguard Worker info.fFormatType = FormatType::kNormalizedFixedPoint;
3150*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage = GR_GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
3151*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard) || GR_IS_GR_GL_ES(standard)) {
3152*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.hasExtension("GL_EXT_texture_compression_s3tc")) {
3153*c8dee2aaSAndroid Build Coastguard Worker info.fFlags = FormatInfo::kTexturable_Flag;
3154*c8dee2aaSAndroid Build Coastguard Worker }
3155*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(standard)) {
3156*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.hasExtension("WEBGL_compressed_texture_s3tc")) {
3157*c8dee2aaSAndroid Build Coastguard Worker info.fFlags = FormatInfo::kTexturable_Flag;
3158*c8dee2aaSAndroid Build Coastguard Worker }
3159*c8dee2aaSAndroid Build Coastguard Worker }
3160*c8dee2aaSAndroid Build Coastguard Worker
3161*c8dee2aaSAndroid Build Coastguard Worker // There are no support GrColorTypes for this format
3162*c8dee2aaSAndroid Build Coastguard Worker }
3163*c8dee2aaSAndroid Build Coastguard Worker
3164*c8dee2aaSAndroid Build Coastguard Worker // Format: COMPRESSED_RGBA8_BC1
3165*c8dee2aaSAndroid Build Coastguard Worker {
3166*c8dee2aaSAndroid Build Coastguard Worker FormatInfo& info = this->getFormatInfo(GrGLFormat::kCOMPRESSED_RGBA8_BC1);
3167*c8dee2aaSAndroid Build Coastguard Worker info.fFormatType = FormatType::kNormalizedFixedPoint;
3168*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage = GR_GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
3169*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard) || GR_IS_GR_GL_ES(standard)) {
3170*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.hasExtension("GL_EXT_texture_compression_s3tc")) {
3171*c8dee2aaSAndroid Build Coastguard Worker info.fFlags = FormatInfo::kTexturable_Flag;
3172*c8dee2aaSAndroid Build Coastguard Worker }
3173*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(standard)) {
3174*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.hasExtension("WEBGL_compressed_texture_s3tc")) {
3175*c8dee2aaSAndroid Build Coastguard Worker info.fFlags = FormatInfo::kTexturable_Flag;
3176*c8dee2aaSAndroid Build Coastguard Worker }
3177*c8dee2aaSAndroid Build Coastguard Worker }
3178*c8dee2aaSAndroid Build Coastguard Worker
3179*c8dee2aaSAndroid Build Coastguard Worker // There are no support GrColorTypes for this format
3180*c8dee2aaSAndroid Build Coastguard Worker }
3181*c8dee2aaSAndroid Build Coastguard Worker
3182*c8dee2aaSAndroid Build Coastguard Worker // Format: COMPRESSED_RGB8_ETC2
3183*c8dee2aaSAndroid Build Coastguard Worker {
3184*c8dee2aaSAndroid Build Coastguard Worker FormatInfo& info = this->getFormatInfo(GrGLFormat::kCOMPRESSED_RGB8_ETC2);
3185*c8dee2aaSAndroid Build Coastguard Worker info.fFormatType = FormatType::kNormalizedFixedPoint;
3186*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage = GR_GL_COMPRESSED_RGB8_ETC2;
3187*c8dee2aaSAndroid Build Coastguard Worker if (!formatWorkarounds.fDisallowETC2Compression) {
3188*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
3189*c8dee2aaSAndroid Build Coastguard Worker if (version >= GR_GL_VER(4, 3) ||
3190*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_ARB_ES3_compatibility")) {
3191*c8dee2aaSAndroid Build Coastguard Worker info.fFlags = FormatInfo::kTexturable_Flag;
3192*c8dee2aaSAndroid Build Coastguard Worker }
3193*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
3194*c8dee2aaSAndroid Build Coastguard Worker if (version >= GR_GL_VER(3, 0) ||
3195*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture")) {
3196*c8dee2aaSAndroid Build Coastguard Worker info.fFlags = FormatInfo::kTexturable_Flag;
3197*c8dee2aaSAndroid Build Coastguard Worker }
3198*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(standard)) {
3199*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.hasExtension("WEBGL_compressed_texture_etc")) {
3200*c8dee2aaSAndroid Build Coastguard Worker info.fFlags = FormatInfo::kTexturable_Flag;
3201*c8dee2aaSAndroid Build Coastguard Worker }
3202*c8dee2aaSAndroid Build Coastguard Worker }
3203*c8dee2aaSAndroid Build Coastguard Worker }
3204*c8dee2aaSAndroid Build Coastguard Worker
3205*c8dee2aaSAndroid Build Coastguard Worker // There are no support GrColorTypes for this format
3206*c8dee2aaSAndroid Build Coastguard Worker }
3207*c8dee2aaSAndroid Build Coastguard Worker
3208*c8dee2aaSAndroid Build Coastguard Worker // Format: COMPRESSED_ETC1_RGB8
3209*c8dee2aaSAndroid Build Coastguard Worker {
3210*c8dee2aaSAndroid Build Coastguard Worker FormatInfo& info = this->getFormatInfo(GrGLFormat::kCOMPRESSED_ETC1_RGB8);
3211*c8dee2aaSAndroid Build Coastguard Worker info.fFormatType = FormatType::kNormalizedFixedPoint;
3212*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage = GR_GL_COMPRESSED_ETC1_RGB8;
3213*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL_ES(standard)) {
3214*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture")) {
3215*c8dee2aaSAndroid Build Coastguard Worker info.fFlags = FormatInfo::kTexturable_Flag;
3216*c8dee2aaSAndroid Build Coastguard Worker }
3217*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(standard)) {
3218*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.hasExtension("WEBGL_compressed_texture_etc1")) {
3219*c8dee2aaSAndroid Build Coastguard Worker info.fFlags = FormatInfo::kTexturable_Flag;
3220*c8dee2aaSAndroid Build Coastguard Worker }
3221*c8dee2aaSAndroid Build Coastguard Worker }
3222*c8dee2aaSAndroid Build Coastguard Worker // No GL support
3223*c8dee2aaSAndroid Build Coastguard Worker
3224*c8dee2aaSAndroid Build Coastguard Worker // There are no support GrColorTypes for this format
3225*c8dee2aaSAndroid Build Coastguard Worker }
3226*c8dee2aaSAndroid Build Coastguard Worker
3227*c8dee2aaSAndroid Build Coastguard Worker // Format: R16
3228*c8dee2aaSAndroid Build Coastguard Worker {
3229*c8dee2aaSAndroid Build Coastguard Worker FormatInfo& info = this->getFormatInfo(GrGLFormat::kR16);
3230*c8dee2aaSAndroid Build Coastguard Worker info.fFormatType = FormatType::kNormalizedFixedPoint;
3231*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForRenderbuffer = GR_GL_R16;
3232*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultExternalFormat = GR_GL_RED;
3233*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultExternalType = GR_GL_UNSIGNED_SHORT;
3234*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultColorType = GrColorType::kR_16;
3235*c8dee2aaSAndroid Build Coastguard Worker bool r16Supported = false;
3236*c8dee2aaSAndroid Build Coastguard Worker if (!formatWorkarounds.fDisallowTextureUnorm16) {
3237*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
3238*c8dee2aaSAndroid Build Coastguard Worker r16Supported = version >= GR_GL_VER(3, 0) ||
3239*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_ARB_texture_rg");
3240*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
3241*c8dee2aaSAndroid Build Coastguard Worker r16Supported = ctxInfo.hasExtension("GL_EXT_texture_norm16");
3242*c8dee2aaSAndroid Build Coastguard Worker } // No WebGL support
3243*c8dee2aaSAndroid Build Coastguard Worker }
3244*c8dee2aaSAndroid Build Coastguard Worker
3245*c8dee2aaSAndroid Build Coastguard Worker if (r16Supported) {
3246*c8dee2aaSAndroid Build Coastguard Worker info.fFlags = FormatInfo::kTexturable_Flag | msaaRenderFlags;
3247*c8dee2aaSAndroid Build Coastguard Worker if (!formatWorkarounds.fDisallowUnorm16Transfers) {
3248*c8dee2aaSAndroid Build Coastguard Worker info.fFlags |= FormatInfo::kTransfers_Flag;
3249*c8dee2aaSAndroid Build Coastguard Worker }
3250*c8dee2aaSAndroid Build Coastguard Worker }
3251*c8dee2aaSAndroid Build Coastguard Worker
3252*c8dee2aaSAndroid Build Coastguard Worker if (texStorageSupported) {
3253*c8dee2aaSAndroid Build Coastguard Worker info.fFlags |= FormatInfo::kUseTexStorage_Flag;
3254*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage = GR_GL_R16;
3255*c8dee2aaSAndroid Build Coastguard Worker } else {
3256*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage =
3257*c8dee2aaSAndroid Build Coastguard Worker texImageSupportsSizedInternalFormat ? GR_GL_R16 : GR_GL_RED;
3258*c8dee2aaSAndroid Build Coastguard Worker }
3259*c8dee2aaSAndroid Build Coastguard Worker
3260*c8dee2aaSAndroid Build Coastguard Worker if (r16Supported) {
3261*c8dee2aaSAndroid Build Coastguard Worker info.fColorTypeInfoCount = 1;
3262*c8dee2aaSAndroid Build Coastguard Worker info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount);
3263*c8dee2aaSAndroid Build Coastguard Worker int ctIdx = 0;
3264*c8dee2aaSAndroid Build Coastguard Worker // Format: R16, Surface: kAlpha_16
3265*c8dee2aaSAndroid Build Coastguard Worker {
3266*c8dee2aaSAndroid Build Coastguard Worker auto& ctInfo = info.fColorTypeInfos[ctIdx++];
3267*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fColorType = GrColorType::kAlpha_16;
3268*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
3269*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fReadSwizzle = skgpu::Swizzle("000r");
3270*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fWriteSwizzle = skgpu::Swizzle("a000");
3271*c8dee2aaSAndroid Build Coastguard Worker this->setColorTypeFormat(GrColorType::kAlpha_16, GrGLFormat::kR16);
3272*c8dee2aaSAndroid Build Coastguard Worker
3273*c8dee2aaSAndroid Build Coastguard Worker // External IO ColorTypes:
3274*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount = 2;
3275*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
3276*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount);
3277*c8dee2aaSAndroid Build Coastguard Worker int ioIdx = 0;
3278*c8dee2aaSAndroid Build Coastguard Worker // Format: R16, Surface: kAlpha_16, Data: kAlpha_16
3279*c8dee2aaSAndroid Build Coastguard Worker {
3280*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
3281*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kAlpha_16;
3282*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_SHORT;
3283*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = GR_GL_RED;
3284*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RED;
3285*c8dee2aaSAndroid Build Coastguard Worker // Not guaranteed by ES/WebGL.
3286*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fRequiresImplementationReadQuery = !GR_IS_GR_GL(standard);
3287*c8dee2aaSAndroid Build Coastguard Worker }
3288*c8dee2aaSAndroid Build Coastguard Worker
3289*c8dee2aaSAndroid Build Coastguard Worker // Format: R16, Surface: kAlpha_16, Data: kAlpha_8xxx
3290*c8dee2aaSAndroid Build Coastguard Worker {
3291*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
3292*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kAlpha_8xxx;
3293*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
3294*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = 0;
3295*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RGBA;
3296*c8dee2aaSAndroid Build Coastguard Worker }
3297*c8dee2aaSAndroid Build Coastguard Worker }
3298*c8dee2aaSAndroid Build Coastguard Worker }
3299*c8dee2aaSAndroid Build Coastguard Worker }
3300*c8dee2aaSAndroid Build Coastguard Worker
3301*c8dee2aaSAndroid Build Coastguard Worker // Format: RG16
3302*c8dee2aaSAndroid Build Coastguard Worker {
3303*c8dee2aaSAndroid Build Coastguard Worker FormatInfo& info = this->getFormatInfo(GrGLFormat::kRG16);
3304*c8dee2aaSAndroid Build Coastguard Worker info.fFormatType = FormatType::kNormalizedFixedPoint;
3305*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage =
3306*c8dee2aaSAndroid Build Coastguard Worker texImageSupportsSizedInternalFormat ? GR_GL_RG16 : GR_GL_RG;
3307*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForRenderbuffer = GR_GL_RG16;
3308*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultExternalFormat = GR_GL_RG;
3309*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultExternalType = GR_GL_UNSIGNED_SHORT;
3310*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultColorType = GrColorType::kRG_1616;
3311*c8dee2aaSAndroid Build Coastguard Worker bool rg16Supported = false;
3312*c8dee2aaSAndroid Build Coastguard Worker if (!formatWorkarounds.fDisallowTextureUnorm16) {
3313*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
3314*c8dee2aaSAndroid Build Coastguard Worker rg16Supported = version >= GR_GL_VER(3, 0) ||
3315*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_ARB_texture_rg");
3316*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
3317*c8dee2aaSAndroid Build Coastguard Worker rg16Supported = ctxInfo.hasExtension("GL_EXT_texture_norm16");
3318*c8dee2aaSAndroid Build Coastguard Worker } // No WebGL support
3319*c8dee2aaSAndroid Build Coastguard Worker }
3320*c8dee2aaSAndroid Build Coastguard Worker
3321*c8dee2aaSAndroid Build Coastguard Worker if (rg16Supported) {
3322*c8dee2aaSAndroid Build Coastguard Worker info.fFlags = FormatInfo::kTexturable_Flag | msaaRenderFlags;
3323*c8dee2aaSAndroid Build Coastguard Worker if (!formatWorkarounds.fDisallowUnorm16Transfers) {
3324*c8dee2aaSAndroid Build Coastguard Worker info.fFlags |= FormatInfo::kTransfers_Flag;
3325*c8dee2aaSAndroid Build Coastguard Worker }
3326*c8dee2aaSAndroid Build Coastguard Worker }
3327*c8dee2aaSAndroid Build Coastguard Worker
3328*c8dee2aaSAndroid Build Coastguard Worker if (texStorageSupported) {
3329*c8dee2aaSAndroid Build Coastguard Worker info.fFlags |= FormatInfo::kUseTexStorage_Flag;
3330*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage = GR_GL_RG16;
3331*c8dee2aaSAndroid Build Coastguard Worker } else {
3332*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage =
3333*c8dee2aaSAndroid Build Coastguard Worker texImageSupportsSizedInternalFormat ? GR_GL_RG16 : GR_GL_RG;
3334*c8dee2aaSAndroid Build Coastguard Worker }
3335*c8dee2aaSAndroid Build Coastguard Worker
3336*c8dee2aaSAndroid Build Coastguard Worker if (rg16Supported) {
3337*c8dee2aaSAndroid Build Coastguard Worker info.fColorTypeInfoCount = 1;
3338*c8dee2aaSAndroid Build Coastguard Worker info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount);
3339*c8dee2aaSAndroid Build Coastguard Worker int ctIdx = 0;
3340*c8dee2aaSAndroid Build Coastguard Worker // Format: GR_GL_RG16, Surface: kRG_1616
3341*c8dee2aaSAndroid Build Coastguard Worker {
3342*c8dee2aaSAndroid Build Coastguard Worker auto& ctInfo = info.fColorTypeInfos[ctIdx++];
3343*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fColorType = GrColorType::kRG_1616;
3344*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
3345*c8dee2aaSAndroid Build Coastguard Worker this->setColorTypeFormat(GrColorType::kRG_1616, GrGLFormat::kRG16);
3346*c8dee2aaSAndroid Build Coastguard Worker
3347*c8dee2aaSAndroid Build Coastguard Worker // External IO ColorTypes:
3348*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount = 2;
3349*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
3350*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount);
3351*c8dee2aaSAndroid Build Coastguard Worker int ioIdx = 0;
3352*c8dee2aaSAndroid Build Coastguard Worker // Format: GR_GL_RG16, Surface: kRG_1616, Data: kRG_1616
3353*c8dee2aaSAndroid Build Coastguard Worker {
3354*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
3355*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kRG_1616;
3356*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_SHORT;
3357*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = GR_GL_RG;
3358*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RG;
3359*c8dee2aaSAndroid Build Coastguard Worker // Not guaranteed by ES/WebGL.
3360*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fRequiresImplementationReadQuery = !GR_IS_GR_GL(standard);
3361*c8dee2aaSAndroid Build Coastguard Worker }
3362*c8dee2aaSAndroid Build Coastguard Worker
3363*c8dee2aaSAndroid Build Coastguard Worker // Format: GR_GL_RG16, Surface: kRG_1616, Data: kRGBA_8888
3364*c8dee2aaSAndroid Build Coastguard Worker {
3365*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
3366*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kRGBA_8888;
3367*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
3368*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = 0;
3369*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RGBA;
3370*c8dee2aaSAndroid Build Coastguard Worker }
3371*c8dee2aaSAndroid Build Coastguard Worker }
3372*c8dee2aaSAndroid Build Coastguard Worker }
3373*c8dee2aaSAndroid Build Coastguard Worker }
3374*c8dee2aaSAndroid Build Coastguard Worker
3375*c8dee2aaSAndroid Build Coastguard Worker // Format: RGBA16
3376*c8dee2aaSAndroid Build Coastguard Worker {
3377*c8dee2aaSAndroid Build Coastguard Worker bool rgba16Support = false;
3378*c8dee2aaSAndroid Build Coastguard Worker if (!formatWorkarounds.fDisallowTextureUnorm16) {
3379*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
3380*c8dee2aaSAndroid Build Coastguard Worker rgba16Support = version >= GR_GL_VER(3, 0);
3381*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
3382*c8dee2aaSAndroid Build Coastguard Worker rgba16Support = ctxInfo.hasExtension("GL_EXT_texture_norm16");
3383*c8dee2aaSAndroid Build Coastguard Worker } // No WebGL support
3384*c8dee2aaSAndroid Build Coastguard Worker }
3385*c8dee2aaSAndroid Build Coastguard Worker
3386*c8dee2aaSAndroid Build Coastguard Worker FormatInfo& info = this->getFormatInfo(GrGLFormat::kRGBA16);
3387*c8dee2aaSAndroid Build Coastguard Worker info.fFormatType = FormatType::kNormalizedFixedPoint;
3388*c8dee2aaSAndroid Build Coastguard Worker
3389*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForRenderbuffer = GR_GL_RGBA16;
3390*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultExternalFormat = GR_GL_RGBA;
3391*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultExternalType = GR_GL_UNSIGNED_SHORT;
3392*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultColorType = GrColorType::kRGBA_16161616;
3393*c8dee2aaSAndroid Build Coastguard Worker if (rgba16Support) {
3394*c8dee2aaSAndroid Build Coastguard Worker info.fFlags = FormatInfo::kTexturable_Flag | msaaRenderFlags;
3395*c8dee2aaSAndroid Build Coastguard Worker if (!formatWorkarounds.fDisallowUnorm16Transfers) {
3396*c8dee2aaSAndroid Build Coastguard Worker info.fFlags |= FormatInfo::kTransfers_Flag;
3397*c8dee2aaSAndroid Build Coastguard Worker }
3398*c8dee2aaSAndroid Build Coastguard Worker }
3399*c8dee2aaSAndroid Build Coastguard Worker
3400*c8dee2aaSAndroid Build Coastguard Worker if (texStorageSupported) {
3401*c8dee2aaSAndroid Build Coastguard Worker info.fFlags |= FormatInfo::kUseTexStorage_Flag;
3402*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage = GR_GL_RGBA16;
3403*c8dee2aaSAndroid Build Coastguard Worker } else {
3404*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage =
3405*c8dee2aaSAndroid Build Coastguard Worker texImageSupportsSizedInternalFormat ? GR_GL_RGBA16 : GR_GL_RGBA;
3406*c8dee2aaSAndroid Build Coastguard Worker }
3407*c8dee2aaSAndroid Build Coastguard Worker
3408*c8dee2aaSAndroid Build Coastguard Worker if (rgba16Support) {
3409*c8dee2aaSAndroid Build Coastguard Worker // Format: GR_GL_RGBA16, Surface: kRGBA_16161616
3410*c8dee2aaSAndroid Build Coastguard Worker info.fColorTypeInfoCount = 1;
3411*c8dee2aaSAndroid Build Coastguard Worker info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount);
3412*c8dee2aaSAndroid Build Coastguard Worker int ctIdx = 0;
3413*c8dee2aaSAndroid Build Coastguard Worker {
3414*c8dee2aaSAndroid Build Coastguard Worker auto& ctInfo = info.fColorTypeInfos[ctIdx++];
3415*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fColorType = GrColorType::kRGBA_16161616;
3416*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
3417*c8dee2aaSAndroid Build Coastguard Worker this->setColorTypeFormat(GrColorType::kRGBA_16161616, GrGLFormat::kRGBA16);
3418*c8dee2aaSAndroid Build Coastguard Worker
3419*c8dee2aaSAndroid Build Coastguard Worker // External IO ColorTypes:
3420*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount = 2;
3421*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
3422*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount);
3423*c8dee2aaSAndroid Build Coastguard Worker int ioIdx = 0;
3424*c8dee2aaSAndroid Build Coastguard Worker // Format: GR_GL_RGBA16, Surface: kRGBA_16161616, Data: kRGBA_16161616
3425*c8dee2aaSAndroid Build Coastguard Worker {
3426*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
3427*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kRGBA_16161616;
3428*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_SHORT;
3429*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = GR_GL_RGBA;
3430*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RGBA;
3431*c8dee2aaSAndroid Build Coastguard Worker // Not guaranteed by ES/WebGL.
3432*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fRequiresImplementationReadQuery = !GR_IS_GR_GL(standard);
3433*c8dee2aaSAndroid Build Coastguard Worker }
3434*c8dee2aaSAndroid Build Coastguard Worker
3435*c8dee2aaSAndroid Build Coastguard Worker // Format: GR_GL_RGBA16, Surface: kRGBA_16161616, Data: kRGBA_8888
3436*c8dee2aaSAndroid Build Coastguard Worker {
3437*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
3438*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kRGBA_8888;
3439*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
3440*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = 0;
3441*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RGBA;
3442*c8dee2aaSAndroid Build Coastguard Worker }
3443*c8dee2aaSAndroid Build Coastguard Worker }
3444*c8dee2aaSAndroid Build Coastguard Worker }
3445*c8dee2aaSAndroid Build Coastguard Worker }
3446*c8dee2aaSAndroid Build Coastguard Worker
3447*c8dee2aaSAndroid Build Coastguard Worker // Format:RG16F
3448*c8dee2aaSAndroid Build Coastguard Worker {
3449*c8dee2aaSAndroid Build Coastguard Worker bool rg16FTextureSupport = false;
3450*c8dee2aaSAndroid Build Coastguard Worker bool rg16FRenderTargetSupport = false;
3451*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(standard)) {
3452*c8dee2aaSAndroid Build Coastguard Worker if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_float")) {
3453*c8dee2aaSAndroid Build Coastguard Worker rg16FTextureSupport = true;
3454*c8dee2aaSAndroid Build Coastguard Worker rg16FRenderTargetSupport = true;
3455*c8dee2aaSAndroid Build Coastguard Worker }
3456*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_GL_ES(standard)) {
3457*c8dee2aaSAndroid Build Coastguard Worker // It seems possible that a combination of GL_EXT_texture_rg and
3458*c8dee2aaSAndroid Build Coastguard Worker // GL_EXT_color_buffer_half_float might add this format to ES 2.0 but it is not entirely
3459*c8dee2aaSAndroid Build Coastguard Worker // clear. The latter mentions interaction but that may only be for renderbuffers as
3460*c8dee2aaSAndroid Build Coastguard Worker // neither adds the texture format explicitly.
3461*c8dee2aaSAndroid Build Coastguard Worker // GL_OES_texture_format_half_float makes no reference to RG formats.
3462*c8dee2aaSAndroid Build Coastguard Worker if (version >= GR_GL_VER(3, 0)) {
3463*c8dee2aaSAndroid Build Coastguard Worker rg16FTextureSupport = true;
3464*c8dee2aaSAndroid Build Coastguard Worker rg16FRenderTargetSupport = version >= GR_GL_VER(3, 2) ||
3465*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_EXT_color_buffer_float") ||
3466*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_EXT_color_buffer_half_float");
3467*c8dee2aaSAndroid Build Coastguard Worker }
3468*c8dee2aaSAndroid Build Coastguard Worker } else if (GR_IS_GR_WEBGL(standard)) {
3469*c8dee2aaSAndroid Build Coastguard Worker if (version >= GR_GL_VER(2, 0)) {
3470*c8dee2aaSAndroid Build Coastguard Worker rg16FTextureSupport = true;
3471*c8dee2aaSAndroid Build Coastguard Worker rg16FRenderTargetSupport = ctxInfo.hasExtension("GL_EXT_color_buffer_half_float") ||
3472*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("EXT_color_buffer_half_float") ||
3473*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_EXT_color_buffer_float") ||
3474*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("EXT_color_buffer_float");
3475*c8dee2aaSAndroid Build Coastguard Worker }
3476*c8dee2aaSAndroid Build Coastguard Worker }
3477*c8dee2aaSAndroid Build Coastguard Worker
3478*c8dee2aaSAndroid Build Coastguard Worker FormatInfo& info = this->getFormatInfo(GrGLFormat::kRG16F);
3479*c8dee2aaSAndroid Build Coastguard Worker info.fFormatType = FormatType::kFloat;
3480*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForRenderbuffer = GR_GL_RG16F;
3481*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultExternalFormat = GR_GL_RG;
3482*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultExternalType = halfFloatType;
3483*c8dee2aaSAndroid Build Coastguard Worker info.fDefaultColorType = GrColorType::kRG_F16;
3484*c8dee2aaSAndroid Build Coastguard Worker if (rg16FTextureSupport) {
3485*c8dee2aaSAndroid Build Coastguard Worker info.fFlags |= FormatInfo::kTexturable_Flag | FormatInfo::kTransfers_Flag;
3486*c8dee2aaSAndroid Build Coastguard Worker if (rg16FRenderTargetSupport) {
3487*c8dee2aaSAndroid Build Coastguard Worker info.fFlags |= fpRenderFlags;
3488*c8dee2aaSAndroid Build Coastguard Worker }
3489*c8dee2aaSAndroid Build Coastguard Worker }
3490*c8dee2aaSAndroid Build Coastguard Worker
3491*c8dee2aaSAndroid Build Coastguard Worker if (texStorageSupported) {
3492*c8dee2aaSAndroid Build Coastguard Worker info.fFlags |= FormatInfo::kUseTexStorage_Flag;
3493*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage = GR_GL_RG16F;
3494*c8dee2aaSAndroid Build Coastguard Worker } else {
3495*c8dee2aaSAndroid Build Coastguard Worker info.fInternalFormatForTexImageOrStorage =
3496*c8dee2aaSAndroid Build Coastguard Worker texImageSupportsSizedInternalFormat ? GR_GL_RG16F : GR_GL_RG;
3497*c8dee2aaSAndroid Build Coastguard Worker }
3498*c8dee2aaSAndroid Build Coastguard Worker
3499*c8dee2aaSAndroid Build Coastguard Worker if (rg16FTextureSupport) {
3500*c8dee2aaSAndroid Build Coastguard Worker info.fColorTypeInfoCount = 1;
3501*c8dee2aaSAndroid Build Coastguard Worker info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount);
3502*c8dee2aaSAndroid Build Coastguard Worker int ctIdx = 0;
3503*c8dee2aaSAndroid Build Coastguard Worker // Format: GR_GL_RG16F, Surface: kRG_F16
3504*c8dee2aaSAndroid Build Coastguard Worker {
3505*c8dee2aaSAndroid Build Coastguard Worker auto& ctInfo = info.fColorTypeInfos[ctIdx++];
3506*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fColorType = GrColorType::kRG_F16;
3507*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
3508*c8dee2aaSAndroid Build Coastguard Worker this->setColorTypeFormat(GrColorType::kRG_F16, GrGLFormat::kRG16F);
3509*c8dee2aaSAndroid Build Coastguard Worker
3510*c8dee2aaSAndroid Build Coastguard Worker // External IO ColorTypes:
3511*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount = 2;
3512*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
3513*c8dee2aaSAndroid Build Coastguard Worker ctInfo.fExternalIOFormatCount);
3514*c8dee2aaSAndroid Build Coastguard Worker int ioIdx = 0;
3515*c8dee2aaSAndroid Build Coastguard Worker // Format: GR_GL_RG16F, Surface: kRG_F16, Data: kRG_F16
3516*c8dee2aaSAndroid Build Coastguard Worker {
3517*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
3518*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kRG_F16;
3519*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = halfFloatType;
3520*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = GR_GL_RG;
3521*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RG;
3522*c8dee2aaSAndroid Build Coastguard Worker // Not guaranteed by ES/WebGL.
3523*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fRequiresImplementationReadQuery = !GR_IS_GR_GL(standard);
3524*c8dee2aaSAndroid Build Coastguard Worker }
3525*c8dee2aaSAndroid Build Coastguard Worker
3526*c8dee2aaSAndroid Build Coastguard Worker // Format: GR_GL_RG16F, Surface: kRG_F16, Data: kRGBA_F32
3527*c8dee2aaSAndroid Build Coastguard Worker {
3528*c8dee2aaSAndroid Build Coastguard Worker auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
3529*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fColorType = GrColorType::kRGBA_F32;
3530*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalType = GR_GL_FLOAT;
3531*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalTexImageFormat = 0;
3532*c8dee2aaSAndroid Build Coastguard Worker ioFormat.fExternalReadFormat = GR_GL_RGBA;
3533*c8dee2aaSAndroid Build Coastguard Worker }
3534*c8dee2aaSAndroid Build Coastguard Worker }
3535*c8dee2aaSAndroid Build Coastguard Worker }
3536*c8dee2aaSAndroid Build Coastguard Worker }
3537*c8dee2aaSAndroid Build Coastguard Worker
3538*c8dee2aaSAndroid Build Coastguard Worker this->setupSampleCounts(ctxInfo, gli);
3539*c8dee2aaSAndroid Build Coastguard Worker
3540*c8dee2aaSAndroid Build Coastguard Worker #ifdef SK_DEBUG
3541*c8dee2aaSAndroid Build Coastguard Worker for (int i = 0; i < kGrGLColorFormatCount; ++i) {
3542*c8dee2aaSAndroid Build Coastguard Worker if (GrGLFormat::kUnknown == static_cast<GrGLFormat>(i)) {
3543*c8dee2aaSAndroid Build Coastguard Worker continue;
3544*c8dee2aaSAndroid Build Coastguard Worker }
3545*c8dee2aaSAndroid Build Coastguard Worker const auto& formatInfo = fFormatTable[i];
3546*c8dee2aaSAndroid Build Coastguard Worker // Make sure we didn't set fbo attachable with msaa and not fbo attachable.
3547*c8dee2aaSAndroid Build Coastguard Worker SkASSERT(!((formatInfo.fFlags & FormatInfo::kFBOColorAttachmentWithMSAA_Flag) &&
3548*c8dee2aaSAndroid Build Coastguard Worker !(formatInfo.fFlags & FormatInfo::kFBOColorAttachment_Flag)));
3549*c8dee2aaSAndroid Build Coastguard Worker
3550*c8dee2aaSAndroid Build Coastguard Worker // Make sure we set all the formats' FormatType
3551*c8dee2aaSAndroid Build Coastguard Worker SkASSERT(formatInfo.fFormatType != FormatType::kUnknown);
3552*c8dee2aaSAndroid Build Coastguard Worker
3553*c8dee2aaSAndroid Build Coastguard Worker // Make sure if we added a ColorTypeInfo we filled it out
3554*c8dee2aaSAndroid Build Coastguard Worker for (int j = 0; j < formatInfo.fColorTypeInfoCount; ++j) {
3555*c8dee2aaSAndroid Build Coastguard Worker const auto& ctInfo = formatInfo.fColorTypeInfos[j];
3556*c8dee2aaSAndroid Build Coastguard Worker SkASSERT(ctInfo.fColorType != GrColorType::kUnknown);
3557*c8dee2aaSAndroid Build Coastguard Worker // Seems silly to add a color type if we don't support any flags on it.
3558*c8dee2aaSAndroid Build Coastguard Worker SkASSERT(ctInfo.fFlags);
3559*c8dee2aaSAndroid Build Coastguard Worker // Make sure if we added any ExternalIOFormats we filled it out
3560*c8dee2aaSAndroid Build Coastguard Worker for (int k = 0; k < ctInfo.fExternalIOFormatCount; ++k) {
3561*c8dee2aaSAndroid Build Coastguard Worker const auto& ioInfo = ctInfo.fExternalIOFormats[k];
3562*c8dee2aaSAndroid Build Coastguard Worker SkASSERT(ioInfo.fColorType != GrColorType::kUnknown);
3563*c8dee2aaSAndroid Build Coastguard Worker }
3564*c8dee2aaSAndroid Build Coastguard Worker }
3565*c8dee2aaSAndroid Build Coastguard Worker }
3566*c8dee2aaSAndroid Build Coastguard Worker #endif
3567*c8dee2aaSAndroid Build Coastguard Worker }
3568*c8dee2aaSAndroid Build Coastguard Worker
setupSampleCounts(const GrGLContextInfo & ctxInfo,const GrGLInterface * gli)3569*c8dee2aaSAndroid Build Coastguard Worker void GrGLCaps::setupSampleCounts(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
3570*c8dee2aaSAndroid Build Coastguard Worker GrGLStandard standard = ctxInfo.standard();
3571*c8dee2aaSAndroid Build Coastguard Worker // standard can be unused (optimized away) if SK_ASSUME_GL_ES is set
3572*c8dee2aaSAndroid Build Coastguard Worker sk_ignore_unused_variable(standard);
3573*c8dee2aaSAndroid Build Coastguard Worker GrGLVersion version = ctxInfo.version();
3574*c8dee2aaSAndroid Build Coastguard Worker
3575*c8dee2aaSAndroid Build Coastguard Worker int maxSampleCnt = 1;
3576*c8dee2aaSAndroid Build Coastguard Worker if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
3577*c8dee2aaSAndroid Build Coastguard Worker GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &maxSampleCnt);
3578*c8dee2aaSAndroid Build Coastguard Worker } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
3579*c8dee2aaSAndroid Build Coastguard Worker GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &maxSampleCnt);
3580*c8dee2aaSAndroid Build Coastguard Worker }
3581*c8dee2aaSAndroid Build Coastguard Worker // Chrome has a mock GL implementation that returns 0.
3582*c8dee2aaSAndroid Build Coastguard Worker maxSampleCnt = std::max(1, maxSampleCnt);
3583*c8dee2aaSAndroid Build Coastguard Worker
3584*c8dee2aaSAndroid Build Coastguard Worker for (int i = 0; i < kGrGLColorFormatCount; ++i) {
3585*c8dee2aaSAndroid Build Coastguard Worker if (FormatInfo::kFBOColorAttachmentWithMSAA_Flag & fFormatTable[i].fFlags) {
3586*c8dee2aaSAndroid Build Coastguard Worker // We assume that MSAA rendering is supported only if we support non-MSAA rendering.
3587*c8dee2aaSAndroid Build Coastguard Worker SkASSERT(FormatInfo::kFBOColorAttachment_Flag & fFormatTable[i].fFlags);
3588*c8dee2aaSAndroid Build Coastguard Worker SkASSERT(GrGLCaps::kNone_MSFBOType != fMSFBOType);
3589*c8dee2aaSAndroid Build Coastguard Worker if ((GR_IS_GR_GL(standard) &&
3590*c8dee2aaSAndroid Build Coastguard Worker (version >= GR_GL_VER(4,2) ||
3591*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.hasExtension("GL_ARB_internalformat_query"))) ||
3592*c8dee2aaSAndroid Build Coastguard Worker (GR_IS_GR_GL_ES(standard) && version >= GR_GL_VER(3,0))) {
3593*c8dee2aaSAndroid Build Coastguard Worker // Implicite resolve may have a lower max samples than the per format MSAA.
3594*c8dee2aaSAndroid Build Coastguard Worker const bool multisampleIsImplicit =
3595*c8dee2aaSAndroid Build Coastguard Worker GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType ||
3596*c8dee2aaSAndroid Build Coastguard Worker GrGLCaps::kES_EXT_MsToTexture_MSFBOType == fMSFBOType;
3597*c8dee2aaSAndroid Build Coastguard Worker int count;
3598*c8dee2aaSAndroid Build Coastguard Worker GrGLFormat grGLFormat = static_cast<GrGLFormat>(i);
3599*c8dee2aaSAndroid Build Coastguard Worker GrGLenum glFormat = this->getRenderbufferInternalFormat(grGLFormat);
3600*c8dee2aaSAndroid Build Coastguard Worker GR_GL_GetInternalformativ(gli, GR_GL_RENDERBUFFER, glFormat,
3601*c8dee2aaSAndroid Build Coastguard Worker GR_GL_NUM_SAMPLE_COUNTS, 1, &count);
3602*c8dee2aaSAndroid Build Coastguard Worker if (count) {
3603*c8dee2aaSAndroid Build Coastguard Worker std::unique_ptr<int[]> temp(new int[count]);
3604*c8dee2aaSAndroid Build Coastguard Worker GR_GL_GetInternalformativ(gli, GR_GL_RENDERBUFFER, glFormat, GR_GL_SAMPLES,
3605*c8dee2aaSAndroid Build Coastguard Worker count, temp.get());
3606*c8dee2aaSAndroid Build Coastguard Worker // GL has a concept of MSAA rasterization with a single sample but we do not.
3607*c8dee2aaSAndroid Build Coastguard Worker if (count && temp[count - 1] == 1) {
3608*c8dee2aaSAndroid Build Coastguard Worker --count;
3609*c8dee2aaSAndroid Build Coastguard Worker SkASSERT(!count || temp[count -1] > 1);
3610*c8dee2aaSAndroid Build Coastguard Worker }
3611*c8dee2aaSAndroid Build Coastguard Worker fFormatTable[i].fColorSampleCounts.reserve(count + 1);
3612*c8dee2aaSAndroid Build Coastguard Worker // We initialize our supported values with 1 (no msaa) and reverse the order
3613*c8dee2aaSAndroid Build Coastguard Worker // returned by GL so that the array is ascending.
3614*c8dee2aaSAndroid Build Coastguard Worker fFormatTable[i].fColorSampleCounts.push_back(1);
3615*c8dee2aaSAndroid Build Coastguard Worker for (int j = 0; j < count; ++j) {
3616*c8dee2aaSAndroid Build Coastguard Worker #if defined(SK_BUILD_FOR_IOS) && TARGET_OS_SIMULATOR
3617*c8dee2aaSAndroid Build Coastguard Worker // The iOS simulator is reporting incorrect values for sample counts,
3618*c8dee2aaSAndroid Build Coastguard Worker // so force them to be a power of 2.
3619*c8dee2aaSAndroid Build Coastguard Worker int sampleCnt = SkPrevPow2(temp[count - j - 1]);
3620*c8dee2aaSAndroid Build Coastguard Worker #else
3621*c8dee2aaSAndroid Build Coastguard Worker int sampleCnt = temp[count - j - 1];
3622*c8dee2aaSAndroid Build Coastguard Worker #endif
3623*c8dee2aaSAndroid Build Coastguard Worker if (multisampleIsImplicit && sampleCnt > maxSampleCnt) {
3624*c8dee2aaSAndroid Build Coastguard Worker break;
3625*c8dee2aaSAndroid Build Coastguard Worker }
3626*c8dee2aaSAndroid Build Coastguard Worker fFormatTable[i].fColorSampleCounts.push_back(sampleCnt);
3627*c8dee2aaSAndroid Build Coastguard Worker }
3628*c8dee2aaSAndroid Build Coastguard Worker }
3629*c8dee2aaSAndroid Build Coastguard Worker } else {
3630*c8dee2aaSAndroid Build Coastguard Worker // Fake out the table using some semi-standard counts up to the max allowed sample
3631*c8dee2aaSAndroid Build Coastguard Worker // count.
3632*c8dee2aaSAndroid Build Coastguard Worker static constexpr int kDefaultSamples[] = {1, 2, 4, 8};
3633*c8dee2aaSAndroid Build Coastguard Worker int count = std::size(kDefaultSamples);
3634*c8dee2aaSAndroid Build Coastguard Worker for (; count > 0; --count) {
3635*c8dee2aaSAndroid Build Coastguard Worker if (kDefaultSamples[count - 1] <= maxSampleCnt) {
3636*c8dee2aaSAndroid Build Coastguard Worker break;
3637*c8dee2aaSAndroid Build Coastguard Worker }
3638*c8dee2aaSAndroid Build Coastguard Worker }
3639*c8dee2aaSAndroid Build Coastguard Worker if (count > 0) {
3640*c8dee2aaSAndroid Build Coastguard Worker fFormatTable[i].fColorSampleCounts.append(count, kDefaultSamples);
3641*c8dee2aaSAndroid Build Coastguard Worker }
3642*c8dee2aaSAndroid Build Coastguard Worker }
3643*c8dee2aaSAndroid Build Coastguard Worker } else if (FormatInfo::kFBOColorAttachment_Flag & fFormatTable[i].fFlags) {
3644*c8dee2aaSAndroid Build Coastguard Worker fFormatTable[i].fColorSampleCounts.resize(1);
3645*c8dee2aaSAndroid Build Coastguard Worker fFormatTable[i].fColorSampleCounts[0] = 1;
3646*c8dee2aaSAndroid Build Coastguard Worker }
3647*c8dee2aaSAndroid Build Coastguard Worker }
3648*c8dee2aaSAndroid Build Coastguard Worker }
3649*c8dee2aaSAndroid Build Coastguard Worker
canCopyTexSubImage(GrGLFormat dstFormat,bool dstHasMSAARenderBuffer,const GrTextureType * dstTypeIfTexture,GrGLFormat srcFormat,bool srcHasMSAARenderBuffer,const GrTextureType * srcTypeIfTexture) const3650*c8dee2aaSAndroid Build Coastguard Worker bool GrGLCaps::canCopyTexSubImage(GrGLFormat dstFormat, bool dstHasMSAARenderBuffer,
3651*c8dee2aaSAndroid Build Coastguard Worker const GrTextureType* dstTypeIfTexture,
3652*c8dee2aaSAndroid Build Coastguard Worker GrGLFormat srcFormat, bool srcHasMSAARenderBuffer,
3653*c8dee2aaSAndroid Build Coastguard Worker const GrTextureType* srcTypeIfTexture) const {
3654*c8dee2aaSAndroid Build Coastguard Worker // When it comes to format types and component sizes the gl spec is fairly complex as
3655*c8dee2aaSAndroid Build Coastguard Worker // requirements differ depending on many properties (e.g. if the internalFormat was created with
3656*c8dee2aaSAndroid Build Coastguard Worker // a sized format or not). These affect the rules about which format types can be copied to
3657*c8dee2aaSAndroid Build Coastguard Worker // which other types. For now we are being more restrictive and requiring that the types must
3658*c8dee2aaSAndroid Build Coastguard Worker // match exactly.
3659*c8dee2aaSAndroid Build Coastguard Worker if (this->getFormatDefaultExternalType(dstFormat) !=
3660*c8dee2aaSAndroid Build Coastguard Worker this->getFormatDefaultExternalType(srcFormat)) {
3661*c8dee2aaSAndroid Build Coastguard Worker return false;
3662*c8dee2aaSAndroid Build Coastguard Worker }
3663*c8dee2aaSAndroid Build Coastguard Worker
3664*c8dee2aaSAndroid Build Coastguard Worker // Either both the src and dst formats need to be SRGB or both need to not be SRGB
3665*c8dee2aaSAndroid Build Coastguard Worker if (GrGLFormatIsSRGB(dstFormat) != GrGLFormatIsSRGB(srcFormat)) {
3666*c8dee2aaSAndroid Build Coastguard Worker return false;
3667*c8dee2aaSAndroid Build Coastguard Worker }
3668*c8dee2aaSAndroid Build Coastguard Worker
3669*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL_ES(fStandard)) {
3670*c8dee2aaSAndroid Build Coastguard Worker // Table 3.9 of the ES2 spec indicates the supported formats with CopyTexSubImage
3671*c8dee2aaSAndroid Build Coastguard Worker // and BGRA isn't in the spec. There doesn't appear to be any extension that adds it.
3672*c8dee2aaSAndroid Build Coastguard Worker // ANGLE, for one, does not allow it. However, we've found it works on some drivers and
3673*c8dee2aaSAndroid Build Coastguard Worker // avoids bugs with using glBlitFramebuffer.
3674*c8dee2aaSAndroid Build Coastguard Worker if ((dstFormat == GrGLFormat::kBGRA8 || srcFormat == GrGLFormat::kBGRA8) &&
3675*c8dee2aaSAndroid Build Coastguard Worker !fAllowBGRA8CopyTexSubImage) {
3676*c8dee2aaSAndroid Build Coastguard Worker return false;
3677*c8dee2aaSAndroid Build Coastguard Worker }
3678*c8dee2aaSAndroid Build Coastguard Worker
3679*c8dee2aaSAndroid Build Coastguard Worker // Table 3.9 of the ES2 spec indicates the supported formats with CopyTexSubImage
3680*c8dee2aaSAndroid Build Coastguard Worker // and SRGB isn't in the spec. There doesn't appear to be any extension that adds it.
3681*c8dee2aaSAndroid Build Coastguard Worker // ANGLE, for one, does not allow it. However, we've found it works on some drivers and
3682*c8dee2aaSAndroid Build Coastguard Worker // avoids bugs with using glBlitFramebuffer.
3683*c8dee2aaSAndroid Build Coastguard Worker if ((GrGLFormatIsSRGB(dstFormat) || GrGLFormatIsSRGB(srcFormat)) &&
3684*c8dee2aaSAndroid Build Coastguard Worker !fAllowSRGBCopyTexSubImage) {
3685*c8dee2aaSAndroid Build Coastguard Worker return false;
3686*c8dee2aaSAndroid Build Coastguard Worker }
3687*c8dee2aaSAndroid Build Coastguard Worker
3688*c8dee2aaSAndroid Build Coastguard Worker // Table 3.9 of the ES2 spec and 3.16 of ES3 spec indicates the supported internal base
3689*c8dee2aaSAndroid Build Coastguard Worker // formats with CopyTexSubImage. Each base format can be copied to itself or formats with
3690*c8dee2aaSAndroid Build Coastguard Worker // less channels.
3691*c8dee2aaSAndroid Build Coastguard Worker uint32_t dstChannels = GrGLFormatChannels(dstFormat);
3692*c8dee2aaSAndroid Build Coastguard Worker uint32_t srcChannels = GrGLFormatChannels(srcFormat);
3693*c8dee2aaSAndroid Build Coastguard Worker if (!dstChannels || !srcChannels) {
3694*c8dee2aaSAndroid Build Coastguard Worker // The formats don't represent color channels (i.e. may be depth stencil)
3695*c8dee2aaSAndroid Build Coastguard Worker return false;
3696*c8dee2aaSAndroid Build Coastguard Worker }
3697*c8dee2aaSAndroid Build Coastguard Worker // The dst channels have to be a subset of the srcChannels, except R, RG, or RGB, channels
3698*c8dee2aaSAndroid Build Coastguard Worker // can go to LUM. (See expansion of Table 3.9 in EXT_texture_rg).
3699*c8dee2aaSAndroid Build Coastguard Worker if ((dstChannels & srcChannels) != srcChannels) {
3700*c8dee2aaSAndroid Build Coastguard Worker if (dstChannels == kGray_SkColorChannelFlag ||
3701*c8dee2aaSAndroid Build Coastguard Worker dstChannels == kGrayAlpha_SkColorChannelFlags) {
3702*c8dee2aaSAndroid Build Coastguard Worker // The dst can't have gray if the src is alpha-only.
3703*c8dee2aaSAndroid Build Coastguard Worker if (srcChannels == kAlpha_SkColorChannelFlag) {
3704*c8dee2aaSAndroid Build Coastguard Worker return false;
3705*c8dee2aaSAndroid Build Coastguard Worker }
3706*c8dee2aaSAndroid Build Coastguard Worker } else {
3707*c8dee2aaSAndroid Build Coastguard Worker return false;
3708*c8dee2aaSAndroid Build Coastguard Worker }
3709*c8dee2aaSAndroid Build Coastguard Worker }
3710*c8dee2aaSAndroid Build Coastguard Worker }
3711*c8dee2aaSAndroid Build Coastguard Worker
3712*c8dee2aaSAndroid Build Coastguard Worker // CopyTexSubImage is invalid or doesn't copy what we want when we have msaa render buffers.
3713*c8dee2aaSAndroid Build Coastguard Worker if (dstHasMSAARenderBuffer || srcHasMSAARenderBuffer) {
3714*c8dee2aaSAndroid Build Coastguard Worker return false;
3715*c8dee2aaSAndroid Build Coastguard Worker }
3716*c8dee2aaSAndroid Build Coastguard Worker
3717*c8dee2aaSAndroid Build Coastguard Worker // CopyTex(Sub)Image writes to a texture and we have no way of dynamically wrapping a RT in a
3718*c8dee2aaSAndroid Build Coastguard Worker // texture.
3719*c8dee2aaSAndroid Build Coastguard Worker if (!dstTypeIfTexture) {
3720*c8dee2aaSAndroid Build Coastguard Worker return false;
3721*c8dee2aaSAndroid Build Coastguard Worker }
3722*c8dee2aaSAndroid Build Coastguard Worker
3723*c8dee2aaSAndroid Build Coastguard Worker // Check that we could wrap the source in an FBO, that the dst is not TEXTURE_EXTERNAL, that no
3724*c8dee2aaSAndroid Build Coastguard Worker // mirroring is required
3725*c8dee2aaSAndroid Build Coastguard Worker return this->canFormatBeFBOColorAttachment(srcFormat) &&
3726*c8dee2aaSAndroid Build Coastguard Worker (!srcTypeIfTexture || *srcTypeIfTexture != GrTextureType::kExternal) &&
3727*c8dee2aaSAndroid Build Coastguard Worker *dstTypeIfTexture != GrTextureType::kExternal;
3728*c8dee2aaSAndroid Build Coastguard Worker }
3729*c8dee2aaSAndroid Build Coastguard Worker
canCopyAsBlit(GrGLFormat dstFormat,int dstSampleCnt,const GrTextureType * dstTypeIfTexture,GrGLFormat srcFormat,int srcSampleCnt,const GrTextureType * srcTypeIfTexture,const SkRect & srcBounds,bool srcBoundsExact,const SkIRect & srcRect,const SkIRect & dstRect) const3730*c8dee2aaSAndroid Build Coastguard Worker bool GrGLCaps::canCopyAsBlit(GrGLFormat dstFormat, int dstSampleCnt,
3731*c8dee2aaSAndroid Build Coastguard Worker const GrTextureType* dstTypeIfTexture,
3732*c8dee2aaSAndroid Build Coastguard Worker GrGLFormat srcFormat, int srcSampleCnt,
3733*c8dee2aaSAndroid Build Coastguard Worker const GrTextureType* srcTypeIfTexture,
3734*c8dee2aaSAndroid Build Coastguard Worker const SkRect& srcBounds, bool srcBoundsExact,
3735*c8dee2aaSAndroid Build Coastguard Worker const SkIRect& srcRect, const SkIRect& dstRect) const {
3736*c8dee2aaSAndroid Build Coastguard Worker auto blitFramebufferFlags = fBlitFramebufferFlags;
3737*c8dee2aaSAndroid Build Coastguard Worker if (!this->canFormatBeFBOColorAttachment(dstFormat) ||
3738*c8dee2aaSAndroid Build Coastguard Worker !this->canFormatBeFBOColorAttachment(srcFormat)) {
3739*c8dee2aaSAndroid Build Coastguard Worker return false;
3740*c8dee2aaSAndroid Build Coastguard Worker }
3741*c8dee2aaSAndroid Build Coastguard Worker
3742*c8dee2aaSAndroid Build Coastguard Worker if (dstTypeIfTexture && *dstTypeIfTexture == GrTextureType::kExternal) {
3743*c8dee2aaSAndroid Build Coastguard Worker return false;
3744*c8dee2aaSAndroid Build Coastguard Worker }
3745*c8dee2aaSAndroid Build Coastguard Worker if (srcTypeIfTexture && *srcTypeIfTexture == GrTextureType::kExternal) {
3746*c8dee2aaSAndroid Build Coastguard Worker return false;
3747*c8dee2aaSAndroid Build Coastguard Worker }
3748*c8dee2aaSAndroid Build Coastguard Worker
3749*c8dee2aaSAndroid Build Coastguard Worker if (GrGLCaps::kNoSupport_BlitFramebufferFlag & blitFramebufferFlags) {
3750*c8dee2aaSAndroid Build Coastguard Worker return false;
3751*c8dee2aaSAndroid Build Coastguard Worker }
3752*c8dee2aaSAndroid Build Coastguard Worker
3753*c8dee2aaSAndroid Build Coastguard Worker if (dstSampleCnt > 1 && dstSampleCnt != srcSampleCnt) {
3754*c8dee2aaSAndroid Build Coastguard Worker // Regardless of support-level, all blits require src and dst sample counts to match if
3755*c8dee2aaSAndroid Build Coastguard Worker // the dst is MSAA.
3756*c8dee2aaSAndroid Build Coastguard Worker return false;
3757*c8dee2aaSAndroid Build Coastguard Worker }
3758*c8dee2aaSAndroid Build Coastguard Worker
3759*c8dee2aaSAndroid Build Coastguard Worker if (srcRect.width() != dstRect.width() || srcRect.height() != dstRect.height()) {
3760*c8dee2aaSAndroid Build Coastguard Worker // If the blit would scale contents, it's only valid for non-MSAA framebuffers that we
3761*c8dee2aaSAndroid Build Coastguard Worker // can write directly to.
3762*c8dee2aaSAndroid Build Coastguard Worker if ((GrGLCaps::kNoScalingOrMirroring_BlitFramebufferFlag & blitFramebufferFlags) ||
3763*c8dee2aaSAndroid Build Coastguard Worker this->useDrawInsteadOfAllRenderTargetWrites() || srcSampleCnt > 1) {
3764*c8dee2aaSAndroid Build Coastguard Worker return false;
3765*c8dee2aaSAndroid Build Coastguard Worker }
3766*c8dee2aaSAndroid Build Coastguard Worker }
3767*c8dee2aaSAndroid Build Coastguard Worker
3768*c8dee2aaSAndroid Build Coastguard Worker if (GrGLCaps::kResolveMustBeFull_BlitFrambufferFlag & blitFramebufferFlags) {
3769*c8dee2aaSAndroid Build Coastguard Worker if (srcSampleCnt > 1) {
3770*c8dee2aaSAndroid Build Coastguard Worker if (1 == dstSampleCnt) {
3771*c8dee2aaSAndroid Build Coastguard Worker return false;
3772*c8dee2aaSAndroid Build Coastguard Worker }
3773*c8dee2aaSAndroid Build Coastguard Worker if (SkRect::Make(srcRect) != srcBounds || !srcBoundsExact) {
3774*c8dee2aaSAndroid Build Coastguard Worker return false;
3775*c8dee2aaSAndroid Build Coastguard Worker }
3776*c8dee2aaSAndroid Build Coastguard Worker }
3777*c8dee2aaSAndroid Build Coastguard Worker }
3778*c8dee2aaSAndroid Build Coastguard Worker
3779*c8dee2aaSAndroid Build Coastguard Worker if (GrGLCaps::kNoMSAADst_BlitFramebufferFlag & blitFramebufferFlags) {
3780*c8dee2aaSAndroid Build Coastguard Worker if (dstSampleCnt > 1) {
3781*c8dee2aaSAndroid Build Coastguard Worker return false;
3782*c8dee2aaSAndroid Build Coastguard Worker }
3783*c8dee2aaSAndroid Build Coastguard Worker }
3784*c8dee2aaSAndroid Build Coastguard Worker
3785*c8dee2aaSAndroid Build Coastguard Worker if (GrGLCaps::kNoFormatConversion_BlitFramebufferFlag & blitFramebufferFlags) {
3786*c8dee2aaSAndroid Build Coastguard Worker if (srcFormat != dstFormat) {
3787*c8dee2aaSAndroid Build Coastguard Worker return false;
3788*c8dee2aaSAndroid Build Coastguard Worker }
3789*c8dee2aaSAndroid Build Coastguard Worker } else if (GrGLCaps::kNoFormatConversionForMSAASrc_BlitFramebufferFlag & blitFramebufferFlags) {
3790*c8dee2aaSAndroid Build Coastguard Worker if (srcSampleCnt > 1 && srcFormat != dstFormat) {
3791*c8dee2aaSAndroid Build Coastguard Worker return false;
3792*c8dee2aaSAndroid Build Coastguard Worker }
3793*c8dee2aaSAndroid Build Coastguard Worker }
3794*c8dee2aaSAndroid Build Coastguard Worker
3795*c8dee2aaSAndroid Build Coastguard Worker if (GrGLCaps::kRectsMustMatchForMSAASrc_BlitFramebufferFlag & blitFramebufferFlags) {
3796*c8dee2aaSAndroid Build Coastguard Worker if (srcSampleCnt > 1) {
3797*c8dee2aaSAndroid Build Coastguard Worker if (dstRect != srcRect) {
3798*c8dee2aaSAndroid Build Coastguard Worker return false;
3799*c8dee2aaSAndroid Build Coastguard Worker }
3800*c8dee2aaSAndroid Build Coastguard Worker }
3801*c8dee2aaSAndroid Build Coastguard Worker }
3802*c8dee2aaSAndroid Build Coastguard Worker return true;
3803*c8dee2aaSAndroid Build Coastguard Worker }
3804*c8dee2aaSAndroid Build Coastguard Worker
canCopyAsDraw(GrGLFormat dstFormat,bool srcIsTexturable,bool scalingCopy) const3805*c8dee2aaSAndroid Build Coastguard Worker bool GrGLCaps::canCopyAsDraw(GrGLFormat dstFormat, bool srcIsTexturable, bool scalingCopy) const {
3806*c8dee2aaSAndroid Build Coastguard Worker return this->isFormatRenderable(dstFormat, 1) &&
3807*c8dee2aaSAndroid Build Coastguard Worker srcIsTexturable &&
3808*c8dee2aaSAndroid Build Coastguard Worker !(fDisableScalingCopyAsDraws && scalingCopy);
3809*c8dee2aaSAndroid Build Coastguard Worker }
3810*c8dee2aaSAndroid Build Coastguard Worker
has_msaa_render_buffer(const GrSurfaceProxy * surf,const GrGLCaps & glCaps)3811*c8dee2aaSAndroid Build Coastguard Worker static bool has_msaa_render_buffer(const GrSurfaceProxy* surf, const GrGLCaps& glCaps) {
3812*c8dee2aaSAndroid Build Coastguard Worker const GrRenderTargetProxy* rt = surf->asRenderTargetProxy();
3813*c8dee2aaSAndroid Build Coastguard Worker if (!rt) {
3814*c8dee2aaSAndroid Build Coastguard Worker return false;
3815*c8dee2aaSAndroid Build Coastguard Worker }
3816*c8dee2aaSAndroid Build Coastguard Worker // A RT has a separate MSAA renderbuffer if:
3817*c8dee2aaSAndroid Build Coastguard Worker // 1) It's multisampled
3818*c8dee2aaSAndroid Build Coastguard Worker // 2) We're using an extension with separate MSAA renderbuffers
3819*c8dee2aaSAndroid Build Coastguard Worker // 3) It's not FBO 0, which is special and always auto-resolves
3820*c8dee2aaSAndroid Build Coastguard Worker return rt->numSamples() > 1 &&
3821*c8dee2aaSAndroid Build Coastguard Worker glCaps.usesMSAARenderBuffers() &&
3822*c8dee2aaSAndroid Build Coastguard Worker !rt->glRTFBOIDIs0();
3823*c8dee2aaSAndroid Build Coastguard Worker }
3824*c8dee2aaSAndroid Build Coastguard Worker
onCanCopySurface(const GrSurfaceProxy * dst,const SkIRect & dstRect,const GrSurfaceProxy * src,const SkIRect & srcRect) const3825*c8dee2aaSAndroid Build Coastguard Worker bool GrGLCaps::onCanCopySurface(const GrSurfaceProxy* dst, const SkIRect& dstRect,
3826*c8dee2aaSAndroid Build Coastguard Worker const GrSurfaceProxy* src, const SkIRect& srcRect) const {
3827*c8dee2aaSAndroid Build Coastguard Worker if (src->isProtected() == GrProtected::kYes && dst->isProtected() != GrProtected::kYes) {
3828*c8dee2aaSAndroid Build Coastguard Worker return false;
3829*c8dee2aaSAndroid Build Coastguard Worker }
3830*c8dee2aaSAndroid Build Coastguard Worker
3831*c8dee2aaSAndroid Build Coastguard Worker int dstSampleCnt = 0;
3832*c8dee2aaSAndroid Build Coastguard Worker int srcSampleCnt = 0;
3833*c8dee2aaSAndroid Build Coastguard Worker if (const GrRenderTargetProxy* rtProxy = dst->asRenderTargetProxy()) {
3834*c8dee2aaSAndroid Build Coastguard Worker dstSampleCnt = rtProxy->numSamples();
3835*c8dee2aaSAndroid Build Coastguard Worker }
3836*c8dee2aaSAndroid Build Coastguard Worker if (const GrRenderTargetProxy* rtProxy = src->asRenderTargetProxy()) {
3837*c8dee2aaSAndroid Build Coastguard Worker srcSampleCnt = rtProxy->numSamples();
3838*c8dee2aaSAndroid Build Coastguard Worker }
3839*c8dee2aaSAndroid Build Coastguard Worker SkASSERT((dstSampleCnt > 0) == SkToBool(dst->asRenderTargetProxy()));
3840*c8dee2aaSAndroid Build Coastguard Worker SkASSERT((srcSampleCnt > 0) == SkToBool(src->asRenderTargetProxy()));
3841*c8dee2aaSAndroid Build Coastguard Worker
3842*c8dee2aaSAndroid Build Coastguard Worker const GrTextureProxy* dstTex = dst->asTextureProxy();
3843*c8dee2aaSAndroid Build Coastguard Worker const GrTextureProxy* srcTex = src->asTextureProxy();
3844*c8dee2aaSAndroid Build Coastguard Worker
3845*c8dee2aaSAndroid Build Coastguard Worker GrTextureType dstTexType;
3846*c8dee2aaSAndroid Build Coastguard Worker GrTextureType* dstTexTypePtr = nullptr;
3847*c8dee2aaSAndroid Build Coastguard Worker GrTextureType srcTexType;
3848*c8dee2aaSAndroid Build Coastguard Worker GrTextureType* srcTexTypePtr = nullptr;
3849*c8dee2aaSAndroid Build Coastguard Worker if (dstTex) {
3850*c8dee2aaSAndroid Build Coastguard Worker dstTexType = dstTex->textureType();
3851*c8dee2aaSAndroid Build Coastguard Worker dstTexTypePtr = &dstTexType;
3852*c8dee2aaSAndroid Build Coastguard Worker }
3853*c8dee2aaSAndroid Build Coastguard Worker if (srcTex) {
3854*c8dee2aaSAndroid Build Coastguard Worker srcTexType = srcTex->textureType();
3855*c8dee2aaSAndroid Build Coastguard Worker srcTexTypePtr = &srcTexType;
3856*c8dee2aaSAndroid Build Coastguard Worker }
3857*c8dee2aaSAndroid Build Coastguard Worker
3858*c8dee2aaSAndroid Build Coastguard Worker auto dstFormat = GrBackendFormats::AsGLFormat(dst->backendFormat());
3859*c8dee2aaSAndroid Build Coastguard Worker auto srcFormat = GrBackendFormats::AsGLFormat(src->backendFormat());
3860*c8dee2aaSAndroid Build Coastguard Worker // Only copyAsBlit() and copyAsDraw() can handle scaling between src and dst.
3861*c8dee2aaSAndroid Build Coastguard Worker const bool scalingCopy = srcRect.size() != dstRect.size();
3862*c8dee2aaSAndroid Build Coastguard Worker if (!scalingCopy &&
3863*c8dee2aaSAndroid Build Coastguard Worker this->canCopyTexSubImage(dstFormat, has_msaa_render_buffer(dst, *this), dstTexTypePtr,
3864*c8dee2aaSAndroid Build Coastguard Worker srcFormat, has_msaa_render_buffer(src, *this), srcTexTypePtr)) {
3865*c8dee2aaSAndroid Build Coastguard Worker return true;
3866*c8dee2aaSAndroid Build Coastguard Worker }
3867*c8dee2aaSAndroid Build Coastguard Worker return this->canCopyAsBlit(dstFormat, dstSampleCnt, dstTexTypePtr, srcFormat, srcSampleCnt,
3868*c8dee2aaSAndroid Build Coastguard Worker srcTexTypePtr, src->getBoundsRect(), src->priv().isExact(), srcRect,
3869*c8dee2aaSAndroid Build Coastguard Worker dstRect) ||
3870*c8dee2aaSAndroid Build Coastguard Worker this->canCopyAsDraw(dstFormat, SkToBool(srcTex), scalingCopy);
3871*c8dee2aaSAndroid Build Coastguard Worker }
3872*c8dee2aaSAndroid Build Coastguard Worker
getDstCopyRestrictions(const GrRenderTargetProxy * src,GrColorType colorType) const3873*c8dee2aaSAndroid Build Coastguard Worker GrCaps::DstCopyRestrictions GrGLCaps::getDstCopyRestrictions(const GrRenderTargetProxy* src,
3874*c8dee2aaSAndroid Build Coastguard Worker GrColorType colorType) const {
3875*c8dee2aaSAndroid Build Coastguard Worker // If the src is a texture, we can implement the blit as a draw assuming the config is
3876*c8dee2aaSAndroid Build Coastguard Worker // renderable.
3877*c8dee2aaSAndroid Build Coastguard Worker if (src->asTextureProxy() && !this->isFormatAsColorTypeRenderable(colorType,
3878*c8dee2aaSAndroid Build Coastguard Worker src->backendFormat())) {
3879*c8dee2aaSAndroid Build Coastguard Worker return {};
3880*c8dee2aaSAndroid Build Coastguard Worker }
3881*c8dee2aaSAndroid Build Coastguard Worker
3882*c8dee2aaSAndroid Build Coastguard Worker if (const auto* texProxy = src->asTextureProxy()) {
3883*c8dee2aaSAndroid Build Coastguard Worker if (texProxy->textureType() == GrTextureType::kExternal) {
3884*c8dee2aaSAndroid Build Coastguard Worker // Not supported for FBO blit or CopyTexSubImage. Caller will have to fall back to a
3885*c8dee2aaSAndroid Build Coastguard Worker // draw (if the source is also a texture).
3886*c8dee2aaSAndroid Build Coastguard Worker return {};
3887*c8dee2aaSAndroid Build Coastguard Worker }
3888*c8dee2aaSAndroid Build Coastguard Worker }
3889*c8dee2aaSAndroid Build Coastguard Worker
3890*c8dee2aaSAndroid Build Coastguard Worker // We look for opportunities to use CopyTexSubImage, or fbo blit. If neither are
3891*c8dee2aaSAndroid Build Coastguard Worker // possible and we return false to fallback to creating a render target dst for render-to-
3892*c8dee2aaSAndroid Build Coastguard Worker // texture. This code prefers CopyTexSubImage to fbo blit and avoids triggering temporary fbo
3893*c8dee2aaSAndroid Build Coastguard Worker // creation. It isn't clear that avoiding temporary fbo creation is actually optimal.
3894*c8dee2aaSAndroid Build Coastguard Worker DstCopyRestrictions blitFramebufferRestrictions = {};
3895*c8dee2aaSAndroid Build Coastguard Worker if (src->numSamples() > 1 &&
3896*c8dee2aaSAndroid Build Coastguard Worker (fBlitFramebufferFlags & kResolveMustBeFull_BlitFrambufferFlag)) {
3897*c8dee2aaSAndroid Build Coastguard Worker blitFramebufferRestrictions.fRectsMustMatch = GrSurfaceProxy::RectsMustMatch::kYes;
3898*c8dee2aaSAndroid Build Coastguard Worker blitFramebufferRestrictions.fMustCopyWholeSrc = true;
3899*c8dee2aaSAndroid Build Coastguard Worker // Mirroring causes rects to mismatch later, don't allow it.
3900*c8dee2aaSAndroid Build Coastguard Worker } else if (src->numSamples() > 1 && (fBlitFramebufferFlags &
3901*c8dee2aaSAndroid Build Coastguard Worker kRectsMustMatchForMSAASrc_BlitFramebufferFlag)) {
3902*c8dee2aaSAndroid Build Coastguard Worker blitFramebufferRestrictions.fRectsMustMatch = GrSurfaceProxy::RectsMustMatch::kYes;
3903*c8dee2aaSAndroid Build Coastguard Worker }
3904*c8dee2aaSAndroid Build Coastguard Worker
3905*c8dee2aaSAndroid Build Coastguard Worker auto srcFormat = GrBackendFormats::AsGLFormat(src->backendFormat());
3906*c8dee2aaSAndroid Build Coastguard Worker // Check for format issues with glCopyTexSubImage2D
3907*c8dee2aaSAndroid Build Coastguard Worker if (srcFormat == GrGLFormat::kBGRA8) {
3908*c8dee2aaSAndroid Build Coastguard Worker // glCopyTexSubImage2D doesn't work with this config. If the bgra can be used with fbo blit
3909*c8dee2aaSAndroid Build Coastguard Worker // then we set up for that, otherwise fail.
3910*c8dee2aaSAndroid Build Coastguard Worker if (this->canFormatBeFBOColorAttachment(srcFormat)) {
3911*c8dee2aaSAndroid Build Coastguard Worker return blitFramebufferRestrictions;
3912*c8dee2aaSAndroid Build Coastguard Worker }
3913*c8dee2aaSAndroid Build Coastguard Worker // Caller will have to use a draw.
3914*c8dee2aaSAndroid Build Coastguard Worker return {};
3915*c8dee2aaSAndroid Build Coastguard Worker }
3916*c8dee2aaSAndroid Build Coastguard Worker
3917*c8dee2aaSAndroid Build Coastguard Worker {
3918*c8dee2aaSAndroid Build Coastguard Worker bool srcIsMSAARenderbuffer = src->numSamples() > 1 &&
3919*c8dee2aaSAndroid Build Coastguard Worker this->usesMSAARenderBuffers();
3920*c8dee2aaSAndroid Build Coastguard Worker if (srcIsMSAARenderbuffer) {
3921*c8dee2aaSAndroid Build Coastguard Worker // It's illegal to call CopyTexSubImage2D on a MSAA renderbuffer. Set up for FBO
3922*c8dee2aaSAndroid Build Coastguard Worker // blit or fail.
3923*c8dee2aaSAndroid Build Coastguard Worker if (this->canFormatBeFBOColorAttachment(srcFormat)) {
3924*c8dee2aaSAndroid Build Coastguard Worker return blitFramebufferRestrictions;
3925*c8dee2aaSAndroid Build Coastguard Worker }
3926*c8dee2aaSAndroid Build Coastguard Worker // Caller will have to use a draw.
3927*c8dee2aaSAndroid Build Coastguard Worker return {};
3928*c8dee2aaSAndroid Build Coastguard Worker }
3929*c8dee2aaSAndroid Build Coastguard Worker }
3930*c8dee2aaSAndroid Build Coastguard Worker
3931*c8dee2aaSAndroid Build Coastguard Worker // We'll do a CopyTexSubImage, no restrictions.
3932*c8dee2aaSAndroid Build Coastguard Worker return {};
3933*c8dee2aaSAndroid Build Coastguard Worker }
3934*c8dee2aaSAndroid Build Coastguard Worker
applyDriverCorrectnessWorkarounds(const GrGLContextInfo & ctxInfo,const GrContextOptions & contextOptions,const GrGLInterface * glInterface,GrShaderCaps * shaderCaps,FormatWorkarounds * formatWorkarounds)3935*c8dee2aaSAndroid Build Coastguard Worker void GrGLCaps::applyDriverCorrectnessWorkarounds(const GrGLContextInfo& ctxInfo,
3936*c8dee2aaSAndroid Build Coastguard Worker const GrContextOptions& contextOptions,
3937*c8dee2aaSAndroid Build Coastguard Worker const GrGLInterface* glInterface,
3938*c8dee2aaSAndroid Build Coastguard Worker GrShaderCaps* shaderCaps,
3939*c8dee2aaSAndroid Build Coastguard Worker FormatWorkarounds* formatWorkarounds) {
3940*c8dee2aaSAndroid Build Coastguard Worker // A driver bug on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
3941*c8dee2aaSAndroid Build Coastguard Worker // Thus we are disabling this extension for now on Adreno4xx devices.
3942*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.renderer() == GrGLRenderer::kAdreno430 ||
3943*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.renderer() == GrGLRenderer::kAdreno4xx_other ||
3944*c8dee2aaSAndroid Build Coastguard Worker fDriverBugWorkarounds.disable_discard_framebuffer) {
3945*c8dee2aaSAndroid Build Coastguard Worker fInvalidateFBType = kNone_InvalidateFBType;
3946*c8dee2aaSAndroid Build Coastguard Worker }
3947*c8dee2aaSAndroid Build Coastguard Worker
3948*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.renderer() == GrGLRenderer::kIntelCherryView) {
3949*c8dee2aaSAndroid Build Coastguard Worker // When running DMSAA_dst_read_with_existing_barrier with DMSAA disabled on linux Intel
3950*c8dee2aaSAndroid Build Coastguard Worker // HD405, the test fails when using texture barriers. Oddly the gpu doing the draw which
3951*c8dee2aaSAndroid Build Coastguard Worker // uses the barrier correctly. It is the next draw, which does not use or need a barrier,
3952*c8dee2aaSAndroid Build Coastguard Worker // that is blending with a dst as if the barrier draw didn't happen. Since this GPU is not
3953*c8dee2aaSAndroid Build Coastguard Worker // that important to us and this driver bug could probably manifest itself in the wild, we
3954*c8dee2aaSAndroid Build Coastguard Worker // are just disabling texture barrier support for the gpu.
3955*c8dee2aaSAndroid Build Coastguard Worker fTextureBarrierSupport = false;
3956*c8dee2aaSAndroid Build Coastguard Worker }
3957*c8dee2aaSAndroid Build Coastguard Worker
3958*c8dee2aaSAndroid Build Coastguard Worker // glClearTexImage seems to have a bug in NVIDIA drivers that was fixed sometime between
3959*c8dee2aaSAndroid Build Coastguard Worker // 340.96 and 367.57.
3960*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(ctxInfo.standard()) && ctxInfo.driver() == GrGLDriver::kNVIDIA &&
3961*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.driverVersion() < GR_GL_DRIVER_VER(367, 57, 0)) {
3962*c8dee2aaSAndroid Build Coastguard Worker fClearTextureSupport = false;
3963*c8dee2aaSAndroid Build Coastguard Worker }
3964*c8dee2aaSAndroid Build Coastguard Worker
3965*c8dee2aaSAndroid Build Coastguard Worker // glBlitFramebuffer seems to produce incorrect results on QC, Mali400, and Tegra3 but
3966*c8dee2aaSAndroid Build Coastguard Worker // glCopyTexSubImage2D works (even though there is no extension that specifically allows it).
3967*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.vendor() == GrGLVendor::kQualcomm ||
3968*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.renderer() == GrGLRenderer::kMali4xx ||
3969*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.renderer() == GrGLRenderer::kTegra_PreK1) {
3970*c8dee2aaSAndroid Build Coastguard Worker fAllowBGRA8CopyTexSubImage = true;
3971*c8dee2aaSAndroid Build Coastguard Worker }
3972*c8dee2aaSAndroid Build Coastguard Worker // glCopyTexSubImage2D works for sRGB with GLES 3.0 and on some GPUs with GLES 2.0
3973*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
3974*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.renderer() == GrGLRenderer::kMali4xx ||
3975*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.renderer() == GrGLRenderer::kTegra_PreK1) {
3976*c8dee2aaSAndroid Build Coastguard Worker fAllowSRGBCopyTexSubImage = true;
3977*c8dee2aaSAndroid Build Coastguard Worker }
3978*c8dee2aaSAndroid Build Coastguard Worker
3979*c8dee2aaSAndroid Build Coastguard Worker // http://anglebug.com/6030
3980*c8dee2aaSAndroid Build Coastguard Worker if (fMSFBOType == kES_EXT_MsToTexture_MSFBOType &&
3981*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.angleBackend() == GrGLANGLEBackend::kD3D11) {
3982*c8dee2aaSAndroid Build Coastguard Worker // As GL_EXT_multisampled_render_to_texture supporting issue,
3983*c8dee2aaSAndroid Build Coastguard Worker // fall back to default dmsaa path
3984*c8dee2aaSAndroid Build Coastguard Worker if ((ctxInfo.vendor() == GrGLVendor::kIntel ||
3985*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.angleVendor() == GrGLVendor::kIntel) &&
3986*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.renderer() >= GrGLRenderer::kIntelIceLake) {
3987*c8dee2aaSAndroid Build Coastguard Worker fMSFBOType = kStandard_MSFBOType;
3988*c8dee2aaSAndroid Build Coastguard Worker fMSAAResolvesAutomatically = false;
3989*c8dee2aaSAndroid Build Coastguard Worker }
3990*c8dee2aaSAndroid Build Coastguard Worker else {
3991*c8dee2aaSAndroid Build Coastguard Worker fDisallowDynamicMSAA = true;
3992*c8dee2aaSAndroid Build Coastguard Worker }
3993*c8dee2aaSAndroid Build Coastguard Worker }
3994*c8dee2aaSAndroid Build Coastguard Worker
3995*c8dee2aaSAndroid Build Coastguard Worker // http://skbug.com/12081
3996*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_WEBGL(ctxInfo.standard())) {
3997*c8dee2aaSAndroid Build Coastguard Worker fDisallowDynamicMSAA = true;
3998*c8dee2aaSAndroid Build Coastguard Worker }
3999*c8dee2aaSAndroid Build Coastguard Worker
4000*c8dee2aaSAndroid Build Coastguard Worker // Below we are aggressive about turning off all mapping/transfer functionality together. This
4001*c8dee2aaSAndroid Build Coastguard Worker // could be finer grained if code paths and tests were adjusted to check more specific caps.
4002*c8dee2aaSAndroid Build Coastguard Worker // For example it might be possible to support buffer to buffer transfers even if buffer mapping
4003*c8dee2aaSAndroid Build Coastguard Worker // or buffer to surface transfers don't work.
4004*c8dee2aaSAndroid Build Coastguard Worker #if defined(__has_feature)
4005*c8dee2aaSAndroid Build Coastguard Worker #if defined(SK_BUILD_FOR_MAC) && __has_feature(thread_sanitizer)
4006*c8dee2aaSAndroid Build Coastguard Worker // See skbug.com/7058
4007*c8dee2aaSAndroid Build Coastguard Worker fMapBufferType = kNone_MapBufferType;
4008*c8dee2aaSAndroid Build Coastguard Worker fMapBufferFlags = kNone_MapFlags;
4009*c8dee2aaSAndroid Build Coastguard Worker fTransferFromBufferToTextureSupport = false;
4010*c8dee2aaSAndroid Build Coastguard Worker fTransferFromSurfaceToBufferSupport = false;
4011*c8dee2aaSAndroid Build Coastguard Worker fTransferFromBufferToBufferSupport = false;
4012*c8dee2aaSAndroid Build Coastguard Worker fTransferBufferType = TransferBufferType::kNone;
4013*c8dee2aaSAndroid Build Coastguard Worker #endif
4014*c8dee2aaSAndroid Build Coastguard Worker #endif
4015*c8dee2aaSAndroid Build Coastguard Worker
4016*c8dee2aaSAndroid Build Coastguard Worker // We found that the Galaxy J5 with an Adreno 306 running 6.0.1 has a bug where
4017*c8dee2aaSAndroid Build Coastguard Worker // GL_INVALID_OPERATION thrown by glDrawArrays when using a buffer that was mapped. The same bug
4018*c8dee2aaSAndroid Build Coastguard Worker // did not reproduce on a Nexus7 2013 with a 320 running Android M with driver 127.0. It's
4019*c8dee2aaSAndroid Build Coastguard Worker // unclear whether this really affects a wide range of devices.
4020*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.renderer() == GrGLRenderer::kAdreno3xx &&
4021*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.driverVersion() > GR_GL_DRIVER_VER(127, 0, 0)) {
4022*c8dee2aaSAndroid Build Coastguard Worker fMapBufferType = kNone_MapBufferType;
4023*c8dee2aaSAndroid Build Coastguard Worker fMapBufferFlags = kNone_MapFlags;
4024*c8dee2aaSAndroid Build Coastguard Worker fTransferFromBufferToTextureSupport = false;
4025*c8dee2aaSAndroid Build Coastguard Worker fTransferFromSurfaceToBufferSupport = false;
4026*c8dee2aaSAndroid Build Coastguard Worker fTransferFromBufferToBufferSupport = false;
4027*c8dee2aaSAndroid Build Coastguard Worker fTransferBufferType = TransferBufferType::kNone;
4028*c8dee2aaSAndroid Build Coastguard Worker }
4029*c8dee2aaSAndroid Build Coastguard Worker
4030*c8dee2aaSAndroid Build Coastguard Worker // The TransferPixelsToTexture test fails on ANGLE D3D9 and D3D11 if this is enabled.
4031*c8dee2aaSAndroid Build Coastguard Worker // https://anglebug.com/5542
4032*c8dee2aaSAndroid Build Coastguard Worker if (angle_backend_is_d3d(ctxInfo.angleBackend())) {
4033*c8dee2aaSAndroid Build Coastguard Worker fTransferPixelsToRowBytesSupport = false;
4034*c8dee2aaSAndroid Build Coastguard Worker }
4035*c8dee2aaSAndroid Build Coastguard Worker
4036*c8dee2aaSAndroid Build Coastguard Worker // Using MIPs on this GPU seems to be a source of trouble.
4037*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.renderer() == GrGLRenderer::kPowerVR54x) {
4038*c8dee2aaSAndroid Build Coastguard Worker fMipmapSupport = false;
4039*c8dee2aaSAndroid Build Coastguard Worker }
4040*c8dee2aaSAndroid Build Coastguard Worker
4041*c8dee2aaSAndroid Build Coastguard Worker #ifdef SK_BUILD_FOR_ANDROID
4042*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.renderer() == GrGLRenderer::kPowerVR54x) {
4043*c8dee2aaSAndroid Build Coastguard Worker // Flutter found glTexSubImage2D for GL_RED is much slower than GL_ALPHA on the
4044*c8dee2aaSAndroid Build Coastguard Worker // "MC18 PERSONAL SHOPPER"
4045*c8dee2aaSAndroid Build Coastguard Worker formatWorkarounds->fDisallowR8ForPowerVRSGX54x = true;
4046*c8dee2aaSAndroid Build Coastguard Worker }
4047*c8dee2aaSAndroid Build Coastguard Worker #endif
4048*c8dee2aaSAndroid Build Coastguard Worker
4049*c8dee2aaSAndroid Build Coastguard Worker // Reported on skia-discuss as occurring with these GL strings:
4050*c8dee2aaSAndroid Build Coastguard Worker // GL_VERSION: 3.1.0 - Build 9.17.10.4459
4051*c8dee2aaSAndroid Build Coastguard Worker // GL_VENDOR: Intel
4052*c8dee2aaSAndroid Build Coastguard Worker // GL_RENDERER: Intel(R) HD Graphics 2000
4053*c8dee2aaSAndroid Build Coastguard Worker // https://groups.google.com/g/skia-discuss/c/dYV1blEAda0/m/-zuZLXQKAwAJ?utm_medium=email&utm_source=footer
4054*c8dee2aaSAndroid Build Coastguard Worker // See also http://skbug.com/9286
4055*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.renderer() == GrGLRenderer::kIntelSandyBridge &&
4056*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.driver() == GrGLDriver::kIntel) {
4057*c8dee2aaSAndroid Build Coastguard Worker fMapBufferType = kNone_MapBufferType;
4058*c8dee2aaSAndroid Build Coastguard Worker fMapBufferFlags = kNone_MapFlags;
4059*c8dee2aaSAndroid Build Coastguard Worker // On skia-discuss it was reported that after turning off mapping there was this
4060*c8dee2aaSAndroid Build Coastguard Worker // shader compilation error.
4061*c8dee2aaSAndroid Build Coastguard Worker // ERROR: 0:18: 'assign' : cannot convert from '3-component vector of float' to 'varying 2-component vector of float'
4062*c8dee2aaSAndroid Build Coastguard Worker // for this line:
4063*c8dee2aaSAndroid Build Coastguard Worker // vTransformedCoords_5_S0 = mat3x2(umatrix_S1_c0_c1) * vec3(_tmp_2_inPosition, 1.0);
4064*c8dee2aaSAndroid Build Coastguard Worker fShaderCaps->fNonsquareMatrixSupport = false;
4065*c8dee2aaSAndroid Build Coastguard Worker }
4066*c8dee2aaSAndroid Build Coastguard Worker
4067*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.isOverCommandBuffer() && ctxInfo.version() >= GR_GL_VER(3,0)) {
4068*c8dee2aaSAndroid Build Coastguard Worker formatWorkarounds->fDisallowTextureUnorm16 = true; // http://crbug.com/1224108
4069*c8dee2aaSAndroid Build Coastguard Worker formatWorkarounds->fDisallowETC2Compression = true; // http://crbug.com/1224111
4070*c8dee2aaSAndroid Build Coastguard Worker fTransferFromSurfaceToBufferSupport = false; // http://crbug.com/1224138
4071*c8dee2aaSAndroid Build Coastguard Worker
4072*c8dee2aaSAndroid Build Coastguard Worker // http://crbug.com/1224117
4073*c8dee2aaSAndroid Build Coastguard Worker fMapBufferFlags = kNone_MapFlags;
4074*c8dee2aaSAndroid Build Coastguard Worker fMapBufferType = kNone_MapBufferType;
4075*c8dee2aaSAndroid Build Coastguard Worker }
4076*c8dee2aaSAndroid Build Coastguard Worker
4077*c8dee2aaSAndroid Build Coastguard Worker // https://b.corp.google.com/issues/143074513
4078*c8dee2aaSAndroid Build Coastguard Worker // https://skbug.com/11152
4079*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.renderer() == GrGLRenderer::kAdreno615 ||
4080*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.renderer() == GrGLRenderer::kAdreno620) {
4081*c8dee2aaSAndroid Build Coastguard Worker fMSFBOType = kNone_MSFBOType;
4082*c8dee2aaSAndroid Build Coastguard Worker fMSAAResolvesAutomatically = false;
4083*c8dee2aaSAndroid Build Coastguard Worker }
4084*c8dee2aaSAndroid Build Coastguard Worker
4085*c8dee2aaSAndroid Build Coastguard Worker #ifndef SK_BUILD_FOR_IOS
4086*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.renderer() == GrGLRenderer::kPowerVR54x ||
4087*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.renderer() == GrGLRenderer::kPowerVRRogue ||
4088*c8dee2aaSAndroid Build Coastguard Worker (ctxInfo.renderer() == GrGLRenderer::kAdreno3xx && !ctxInfo.isOverCommandBuffer())) {
4089*c8dee2aaSAndroid Build Coastguard Worker fPerformColorClearsAsDraws = true;
4090*c8dee2aaSAndroid Build Coastguard Worker }
4091*c8dee2aaSAndroid Build Coastguard Worker #endif
4092*c8dee2aaSAndroid Build Coastguard Worker
4093*c8dee2aaSAndroid Build Coastguard Worker // A lot of GPUs have trouble with full screen clears (skbug.com/7195)
4094*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.renderer() == GrGLRenderer::kAMDRadeonHD7xxx ||
4095*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.renderer() == GrGLRenderer::kAMDRadeonR9M4xx) {
4096*c8dee2aaSAndroid Build Coastguard Worker fPerformColorClearsAsDraws = true;
4097*c8dee2aaSAndroid Build Coastguard Worker }
4098*c8dee2aaSAndroid Build Coastguard Worker
4099*c8dee2aaSAndroid Build Coastguard Worker #ifdef SK_BUILD_FOR_MAC
4100*c8dee2aaSAndroid Build Coastguard Worker // crbug.com/768134 - On MacBook Pros, the Intel Iris Pro doesn't always perform
4101*c8dee2aaSAndroid Build Coastguard Worker // full screen clears
4102*c8dee2aaSAndroid Build Coastguard Worker // crbug.com/773107 - On MacBook Pros, a wide range of Intel GPUs don't always
4103*c8dee2aaSAndroid Build Coastguard Worker // perform full screen clears.
4104*c8dee2aaSAndroid Build Coastguard Worker // Update on 4/4/2018 - This appears to be fixed on driver 10.30.12 on a macOS 10.13.2 on a
4105*c8dee2aaSAndroid Build Coastguard Worker // Retina MBP Early 2015 with Iris 6100. It is possibly fixed on earlier drivers as well.
4106*c8dee2aaSAndroid Build Coastguard Worker // crbug.com/1039912 - Crash rate in glClear spiked after OS update, affecting mostly
4107*c8dee2aaSAndroid Build Coastguard Worker // Broadwell on 10.13+
4108*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.vendor() == GrGLVendor::kIntel &&
4109*c8dee2aaSAndroid Build Coastguard Worker (ctxInfo.driverVersion() < GR_GL_DRIVER_VER(10, 30, 12) ||
4110*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.renderer() == GrGLRenderer::kIntelBroadwell)) {
4111*c8dee2aaSAndroid Build Coastguard Worker fPerformColorClearsAsDraws = true;
4112*c8dee2aaSAndroid Build Coastguard Worker }
4113*c8dee2aaSAndroid Build Coastguard Worker // crbug.com/969609 - NVIDIA on Mac sometimes segfaults during glClear in chrome. It seems
4114*c8dee2aaSAndroid Build Coastguard Worker // mostly concentrated in 10.13/14, GT 650Ms, driver 12+. But there are instances of older
4115*c8dee2aaSAndroid Build Coastguard Worker // drivers and GTX 775s, so we'll start with a broader workaround.
4116*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.vendor() == GrGLVendor::kNVIDIA) {
4117*c8dee2aaSAndroid Build Coastguard Worker fPerformColorClearsAsDraws = true;
4118*c8dee2aaSAndroid Build Coastguard Worker }
4119*c8dee2aaSAndroid Build Coastguard Worker #endif
4120*c8dee2aaSAndroid Build Coastguard Worker
4121*c8dee2aaSAndroid Build Coastguard Worker // See crbug.com/755871. This could probably be narrowed to just partial clears as the driver
4122*c8dee2aaSAndroid Build Coastguard Worker // bugs seems to involve clearing too much and not skipping the clear.
4123*c8dee2aaSAndroid Build Coastguard Worker // See crbug.com/768134. This is also needed for full clears and was seen on an nVidia K620
4124*c8dee2aaSAndroid Build Coastguard Worker // but only for D3D11 ANGLE.
4125*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.angleBackend() == GrGLANGLEBackend::kD3D11) {
4126*c8dee2aaSAndroid Build Coastguard Worker fPerformColorClearsAsDraws = true;
4127*c8dee2aaSAndroid Build Coastguard Worker }
4128*c8dee2aaSAndroid Build Coastguard Worker
4129*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.renderer() == GrGLRenderer::kAdreno430 ||
4130*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.renderer() == GrGLRenderer::kAdreno4xx_other) {
4131*c8dee2aaSAndroid Build Coastguard Worker // This is known to be fixed sometime between driver 145.0 and 219.0
4132*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.driverVersion() <= GR_GL_DRIVER_VER(219, 0, 0)) {
4133*c8dee2aaSAndroid Build Coastguard Worker fPerformStencilClearsAsDraws = true;
4134*c8dee2aaSAndroid Build Coastguard Worker }
4135*c8dee2aaSAndroid Build Coastguard Worker // This is known to be fixed sometime between driver 129.0 and 145.0 on Nexus 6P.
4136*c8dee2aaSAndroid Build Coastguard Worker // On driver 129 on Android M it fails the unit tests called WritePixelsPendingIO without
4137*c8dee2aaSAndroid Build Coastguard Worker // the workaround. It passes on Android N with driver 145 without the workaround.
4138*c8dee2aaSAndroid Build Coastguard Worker // skbug.com/11834
4139*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.driverVersion() < GR_GL_DRIVER_VER(145, 0, 0)) {
4140*c8dee2aaSAndroid Build Coastguard Worker fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = true;
4141*c8dee2aaSAndroid Build Coastguard Worker }
4142*c8dee2aaSAndroid Build Coastguard Worker }
4143*c8dee2aaSAndroid Build Coastguard Worker
4144*c8dee2aaSAndroid Build Coastguard Worker if (fDriverBugWorkarounds.gl_clear_broken) {
4145*c8dee2aaSAndroid Build Coastguard Worker fPerformColorClearsAsDraws = true;
4146*c8dee2aaSAndroid Build Coastguard Worker fPerformStencilClearsAsDraws = true;
4147*c8dee2aaSAndroid Build Coastguard Worker }
4148*c8dee2aaSAndroid Build Coastguard Worker
4149*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.vendor() == GrGLVendor::kQualcomm) {
4150*c8dee2aaSAndroid Build Coastguard Worker // It appears that all the Adreno GPUs have less than optimal performance when
4151*c8dee2aaSAndroid Build Coastguard Worker // drawing w/ large index buffers.
4152*c8dee2aaSAndroid Build Coastguard Worker fAvoidLargeIndexBufferDraws = true;
4153*c8dee2aaSAndroid Build Coastguard Worker }
4154*c8dee2aaSAndroid Build Coastguard Worker
4155*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.renderer() == GrGLRenderer::kMali4xx ||
4156*c8dee2aaSAndroid Build Coastguard Worker (ctxInfo.renderer() == GrGLRenderer::kWebGL &&
4157*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.webglRenderer() == GrGLRenderer::kMali4xx)) {
4158*c8dee2aaSAndroid Build Coastguard Worker // Perspective SDF text runs significantly slower on Mali-4xx hardware
4159*c8dee2aaSAndroid Build Coastguard Worker fDisablePerspectiveSDFText = true;
4160*c8dee2aaSAndroid Build Coastguard Worker }
4161*c8dee2aaSAndroid Build Coastguard Worker
4162*c8dee2aaSAndroid Build Coastguard Worker // This was reproduced on the following configurations:
4163*c8dee2aaSAndroid Build Coastguard Worker // - A Galaxy J5 (Adreno 306) running Android 6 with driver 140.0
4164*c8dee2aaSAndroid Build Coastguard Worker // - A Nexus 7 2013 (Adreno 320) running Android 5 with driver 104.0
4165*c8dee2aaSAndroid Build Coastguard Worker // - A Nexus 7 2013 (Adreno 320) running Android 6 with driver 127.0
4166*c8dee2aaSAndroid Build Coastguard Worker // - A Nexus 5 (Adreno 330) running Android 6 with driver 127.0
4167*c8dee2aaSAndroid Build Coastguard Worker // and not produced on:
4168*c8dee2aaSAndroid Build Coastguard Worker // - A Nexus 7 2013 (Adreno 320) running Android 4 with driver 53.0
4169*c8dee2aaSAndroid Build Coastguard Worker // The particular lines that get dropped from test images varies across different devices.
4170*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.renderer() == GrGLRenderer::kAdreno3xx &&
4171*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.driverVersion() > GR_GL_DRIVER_VER(53, 0, 0)) {
4172*c8dee2aaSAndroid Build Coastguard Worker fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines = true;
4173*c8dee2aaSAndroid Build Coastguard Worker }
4174*c8dee2aaSAndroid Build Coastguard Worker
4175*c8dee2aaSAndroid Build Coastguard Worker // TODO: Don't apply this on iOS?
4176*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.renderer() == GrGLRenderer::kPowerVRRogue) {
4177*c8dee2aaSAndroid Build Coastguard Worker // Our Chromebook with GrGLRenderer::kPowerVRRogue crashes on large instanced draws. The
4178*c8dee2aaSAndroid Build Coastguard Worker // current minimum number of instances observed to crash is somewhere between 2^14 and 2^15.
4179*c8dee2aaSAndroid Build Coastguard Worker // Keep the number of instances below 1000, just to be safe.
4180*c8dee2aaSAndroid Build Coastguard Worker fMaxInstancesPerDrawWithoutCrashing = 999;
4181*c8dee2aaSAndroid Build Coastguard Worker } else if (fDriverBugWorkarounds.disallow_large_instanced_draw) {
4182*c8dee2aaSAndroid Build Coastguard Worker fMaxInstancesPerDrawWithoutCrashing = 0x4000000;
4183*c8dee2aaSAndroid Build Coastguard Worker }
4184*c8dee2aaSAndroid Build Coastguard Worker
4185*c8dee2aaSAndroid Build Coastguard Worker #ifndef SK_BUILD_FOR_IOS
4186*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.renderer() == GrGLRenderer::kPowerVRRogue) {
4187*c8dee2aaSAndroid Build Coastguard Worker // We saw this bug on a TecnoSpark 3 Pro with a PowerVR GE8300.
4188*c8dee2aaSAndroid Build Coastguard Worker // GL_VERSION: "OpenGL ES 3.2 build 1.10@51309121"
4189*c8dee2aaSAndroid Build Coastguard Worker // Possibly this could be more limited by driver version or HW generation.
4190*c8dee2aaSAndroid Build Coastguard Worker // When using samplers, we are seeing a bug where the gpu is sometimes not sampling the
4191*c8dee2aaSAndroid Build Coastguard Worker // correct mip level data. A workaround to this issue is that when binding a texture we also
4192*c8dee2aaSAndroid Build Coastguard Worker // set some texture state, and it seems like any inividual state works (e.g. min/mag filter,
4193*c8dee2aaSAndroid Build Coastguard Worker // base level, max level, etc.). Currently we just set the min filter level every time we
4194*c8dee2aaSAndroid Build Coastguard Worker // bind a texture as the workaround.
4195*c8dee2aaSAndroid Build Coastguard Worker fMustSetAnyTexParameterToEnableMipmapping = true;
4196*c8dee2aaSAndroid Build Coastguard Worker // ColorTypeBackendAllocationTest failed for kAlpha_8 and kGray_8 when using
4197*c8dee2aaSAndroid Build Coastguard Worker // GL_UNPACK_ROW_LENGTH. Perhaps this could be a more limited workaround by applying
4198*c8dee2aaSAndroid Build Coastguard Worker // only to single channel 8 bit unorm formats but we only have a monolithic query for this
4199*c8dee2aaSAndroid Build Coastguard Worker // support at present.
4200*c8dee2aaSAndroid Build Coastguard Worker fWritePixelsRowBytesSupport = false;
4201*c8dee2aaSAndroid Build Coastguard Worker // TransferPixelsToTextureTest fails for all color types on
4202*c8dee2aaSAndroid Build Coastguard Worker // TecnoSpark 3 Pro with a PowerVR GE8300, GL_VERSION: "OpenGL ES 3.2 build 1.10@51309121"
4203*c8dee2aaSAndroid Build Coastguard Worker // if GL_UNPACK_ROW_LENGTH is used.
4204*c8dee2aaSAndroid Build Coastguard Worker fTransferPixelsToRowBytesSupport = false;
4205*c8dee2aaSAndroid Build Coastguard Worker }
4206*c8dee2aaSAndroid Build Coastguard Worker #endif
4207*c8dee2aaSAndroid Build Coastguard Worker
4208*c8dee2aaSAndroid Build Coastguard Worker // Texture uploads sometimes seem to be ignored to textures bound to FBOS on Tegra3.
4209*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.renderer() == GrGLRenderer::kTegra_PreK1) {
4210*c8dee2aaSAndroid Build Coastguard Worker fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = true;
4211*c8dee2aaSAndroid Build Coastguard Worker fUseDrawInsteadOfAllRenderTargetWrites = true;
4212*c8dee2aaSAndroid Build Coastguard Worker }
4213*c8dee2aaSAndroid Build Coastguard Worker
4214*c8dee2aaSAndroid Build Coastguard Worker #ifdef SK_BUILD_FOR_MAC
4215*c8dee2aaSAndroid Build Coastguard Worker static constexpr bool isMAC = true;
4216*c8dee2aaSAndroid Build Coastguard Worker #else
4217*c8dee2aaSAndroid Build Coastguard Worker static constexpr bool isMAC = false;
4218*c8dee2aaSAndroid Build Coastguard Worker #endif
4219*c8dee2aaSAndroid Build Coastguard Worker
4220*c8dee2aaSAndroid Build Coastguard Worker #ifdef SK_BUILD_FOR_ANDROID
4221*c8dee2aaSAndroid Build Coastguard Worker // Older versions of Android have problems with setting GL_TEXTURE_BASE_LEVEL or
4222*c8dee2aaSAndroid Build Coastguard Worker // GL_TEXTURE_MAX_LEVEL on GL_TEXTURE_EXTERTNAL_OES textures. We just leave them as is and hope
4223*c8dee2aaSAndroid Build Coastguard Worker // the client never changes them either.
4224*c8dee2aaSAndroid Build Coastguard Worker fDontSetBaseOrMaxLevelForExternalTextures = true;
4225*c8dee2aaSAndroid Build Coastguard Worker // PowerVR can crash setting the levels on Android up to Q for any texture?
4226*c8dee2aaSAndroid Build Coastguard Worker // https://crbug.com/1123874
4227*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.vendor() == GrGLVendor::kImagination) {
4228*c8dee2aaSAndroid Build Coastguard Worker fMipmapLevelControlSupport = false;
4229*c8dee2aaSAndroid Build Coastguard Worker }
4230*c8dee2aaSAndroid Build Coastguard Worker #endif
4231*c8dee2aaSAndroid Build Coastguard Worker
4232*c8dee2aaSAndroid Build Coastguard Worker // We support manual mip-map generation (via iterative downsampling draw calls). This fixes
4233*c8dee2aaSAndroid Build Coastguard Worker // bugs on some cards/drivers that produce incorrect mip-maps for sRGB textures when using
4234*c8dee2aaSAndroid Build Coastguard Worker // glGenerateMipmap. Our implementation requires mip-level sampling control. Additionally,
4235*c8dee2aaSAndroid Build Coastguard Worker // it can be much slower (especially on mobile GPUs), so we opt-in only when necessary:
4236*c8dee2aaSAndroid Build Coastguard Worker if (fMipmapLevelControlSupport &&
4237*c8dee2aaSAndroid Build Coastguard Worker !ctxInfo.isOverCommandBuffer() && // http://crbug.com/1224110
4238*c8dee2aaSAndroid Build Coastguard Worker (contextOptions.fDoManualMipmapping ||
4239*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.vendor() == GrGLVendor::kIntel ||
4240*c8dee2aaSAndroid Build Coastguard Worker (ctxInfo.driver() == GrGLDriver::kNVIDIA && isMAC) ||
4241*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.vendor() == GrGLVendor::kATI)) {
4242*c8dee2aaSAndroid Build Coastguard Worker fDoManualMipmapping = true;
4243*c8dee2aaSAndroid Build Coastguard Worker }
4244*c8dee2aaSAndroid Build Coastguard Worker
4245*c8dee2aaSAndroid Build Coastguard Worker // See http://crbug.com/710443
4246*c8dee2aaSAndroid Build Coastguard Worker #ifdef SK_BUILD_FOR_MAC
4247*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.renderer() == GrGLRenderer::kIntelBroadwell) {
4248*c8dee2aaSAndroid Build Coastguard Worker fClearToBoundaryValuesIsBroken = true;
4249*c8dee2aaSAndroid Build Coastguard Worker }
4250*c8dee2aaSAndroid Build Coastguard Worker #endif
4251*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.vendor() == GrGLVendor::kQualcomm) {
4252*c8dee2aaSAndroid Build Coastguard Worker fDrawArraysBaseVertexIsBroken = true;
4253*c8dee2aaSAndroid Build Coastguard Worker }
4254*c8dee2aaSAndroid Build Coastguard Worker
4255*c8dee2aaSAndroid Build Coastguard Worker // b/40043081, b/40045491: indirect draws in ANGLE + D3D are very slow
4256*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.angleBackend() == GrGLANGLEBackend::kD3D9 ||
4257*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.angleBackend() == GrGLANGLEBackend::kD3D11) {
4258*c8dee2aaSAndroid Build Coastguard Worker fBaseVertexBaseInstanceSupport = false;
4259*c8dee2aaSAndroid Build Coastguard Worker fNativeDrawIndirectSupport = false;
4260*c8dee2aaSAndroid Build Coastguard Worker fMultiDrawType = MultiDrawType::kNone;
4261*c8dee2aaSAndroid Build Coastguard Worker }
4262*c8dee2aaSAndroid Build Coastguard Worker
4263*c8dee2aaSAndroid Build Coastguard Worker // https://b.corp.google.com/issues/188410972
4264*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.isRunningOverVirgl()) {
4265*c8dee2aaSAndroid Build Coastguard Worker fDrawInstancedSupport = false;
4266*c8dee2aaSAndroid Build Coastguard Worker }
4267*c8dee2aaSAndroid Build Coastguard Worker
4268*c8dee2aaSAndroid Build Coastguard Worker // http://anglebug.com/4538
4269*c8dee2aaSAndroid Build Coastguard Worker if (fBaseVertexBaseInstanceSupport && !fDrawInstancedSupport) {
4270*c8dee2aaSAndroid Build Coastguard Worker fBaseVertexBaseInstanceSupport = false;
4271*c8dee2aaSAndroid Build Coastguard Worker fNativeDrawIndirectSupport = false;
4272*c8dee2aaSAndroid Build Coastguard Worker fMultiDrawType = MultiDrawType::kNone;
4273*c8dee2aaSAndroid Build Coastguard Worker }
4274*c8dee2aaSAndroid Build Coastguard Worker
4275*c8dee2aaSAndroid Build Coastguard Worker // Currently the extension is advertised but fb fetch is broken on 500 series Adrenos like the
4276*c8dee2aaSAndroid Build Coastguard Worker // Galaxy S7.
4277*c8dee2aaSAndroid Build Coastguard Worker // TODO: Once this is fixed we can update the check here to look at a driver version number too.
4278*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.renderer() == GrGLRenderer::kAdreno530 ||
4279*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.renderer() == GrGLRenderer::kAdreno5xx_other) {
4280*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fFBFetchSupport = false;
4281*c8dee2aaSAndroid Build Coastguard Worker }
4282*c8dee2aaSAndroid Build Coastguard Worker
4283*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.renderer() == GrGLRenderer::kTegra_PreK1) {
4284*c8dee2aaSAndroid Build Coastguard Worker // The Tegra3 compiler will sometimes never return if we have min(abs(x), 1.0),
4285*c8dee2aaSAndroid Build Coastguard Worker // so we must do the abs first in a separate expression.
4286*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fCanUseMinAndAbsTogether = false;
4287*c8dee2aaSAndroid Build Coastguard Worker
4288*c8dee2aaSAndroid Build Coastguard Worker // Tegra3 fract() seems to trigger undefined behavior for negative values, so we
4289*c8dee2aaSAndroid Build Coastguard Worker // must avoid this condition.
4290*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fCanUseFractForNegativeValues = false;
4291*c8dee2aaSAndroid Build Coastguard Worker }
4292*c8dee2aaSAndroid Build Coastguard Worker
4293*c8dee2aaSAndroid Build Coastguard Worker // On Intel GPU there is an issue where it reads the second argument to atan "- %s.x" as an int
4294*c8dee2aaSAndroid Build Coastguard Worker // thus must us -1.0 * %s.x to work correctly
4295*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.vendor() == GrGLVendor::kIntel) {
4296*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fMustForceNegatedAtanParamToFloat = true;
4297*c8dee2aaSAndroid Build Coastguard Worker }
4298*c8dee2aaSAndroid Build Coastguard Worker
4299*c8dee2aaSAndroid Build Coastguard Worker #if defined(SK_BUILD_FOR_MAC)
4300*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.vendor() == GrGLVendor::kATI) {
4301*c8dee2aaSAndroid Build Coastguard Worker // The Radeon GLSL compiler on Mac gets confused by ldexp(..., -x).
4302*c8dee2aaSAndroid Build Coastguard Worker // Convert to ldexp(..., x * -1).
4303*c8dee2aaSAndroid Build Coastguard Worker // http://skbug.com/12076
4304*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fMustForceNegatedLdexpParamToMultiply = true;
4305*c8dee2aaSAndroid Build Coastguard Worker }
4306*c8dee2aaSAndroid Build Coastguard Worker #endif
4307*c8dee2aaSAndroid Build Coastguard Worker
4308*c8dee2aaSAndroid Build Coastguard Worker // On some Intel GPUs there is an issue where the driver outputs bogus values in the shader
4309*c8dee2aaSAndroid Build Coastguard Worker // when floor and abs are called on the same line. Thus we must execute an Op between them to
4310*c8dee2aaSAndroid Build Coastguard Worker // make sure the compiler doesn't re-inline them even if we break the calls apart.
4311*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.vendor() == GrGLVendor::kIntel) {
4312*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fMustDoOpBetweenFloorAndAbs = true;
4313*c8dee2aaSAndroid Build Coastguard Worker }
4314*c8dee2aaSAndroid Build Coastguard Worker
4315*c8dee2aaSAndroid Build Coastguard Worker // On Adreno devices with framebuffer fetch support, there is a bug where they always return
4316*c8dee2aaSAndroid Build Coastguard Worker // the original dst color when reading the outColor even after being written to. By using a
4317*c8dee2aaSAndroid Build Coastguard Worker // local outColor we can work around this bug.
4318*c8dee2aaSAndroid Build Coastguard Worker if (shaderCaps->fFBFetchSupport && ctxInfo.vendor() == GrGLVendor::kQualcomm) {
4319*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fRequiresLocalOutputColorForFBFetch = true;
4320*c8dee2aaSAndroid Build Coastguard Worker }
4321*c8dee2aaSAndroid Build Coastguard Worker
4322*c8dee2aaSAndroid Build Coastguard Worker // Newer Mali GPUs do incorrect static analysis in specific situations: If there is uniform
4323*c8dee2aaSAndroid Build Coastguard Worker // color, and that uniform contains an opaque color, and the output of the shader is only based
4324*c8dee2aaSAndroid Build Coastguard Worker // on that uniform plus soemthing un-trackable (like a texture read), the compiler will deduce
4325*c8dee2aaSAndroid Build Coastguard Worker // that the shader always outputs opaque values. In that case, it appears to remove the shader
4326*c8dee2aaSAndroid Build Coastguard Worker // based blending code it normally injects, turning SrcOver into Src. To fix this, we always
4327*c8dee2aaSAndroid Build Coastguard Worker // insert an extra bit of math on the uniform that confuses the compiler just enough...
4328*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.renderer() == GrGLRenderer::kMaliT) {
4329*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fMustObfuscateUniformColor = true;
4330*c8dee2aaSAndroid Build Coastguard Worker }
4331*c8dee2aaSAndroid Build Coastguard Worker
4332*c8dee2aaSAndroid Build Coastguard Worker #if defined(SK_BUILD_FOR_ANDROID)
4333*c8dee2aaSAndroid Build Coastguard Worker // On the following GPUs, the Perlin noise code needs to aggressively snap to multiples
4334*c8dee2aaSAndroid Build Coastguard Worker // of 1/255 to avoid artifacts in the double table lookup:
4335*c8dee2aaSAndroid Build Coastguard Worker // Tegra3, PowerVRGE8320 (Wembley), MaliG76, and Adreno308
4336*c8dee2aaSAndroid Build Coastguard Worker // Given the range of vendors we're just blanket enabling it on Android for OpenGL.
4337*c8dee2aaSAndroid Build Coastguard Worker fShaderCaps->fPerlinNoiseRoundingFix = true;
4338*c8dee2aaSAndroid Build Coastguard Worker #endif
4339*c8dee2aaSAndroid Build Coastguard Worker
4340*c8dee2aaSAndroid Build Coastguard Worker // On Mali 400 there is a bug using dFd* in the x direction. So we avoid using it when possible.
4341*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.renderer() == GrGLRenderer::kMali4xx) {
4342*c8dee2aaSAndroid Build Coastguard Worker fShaderCaps->fAvoidDfDxForGradientsWhenPossible = true;
4343*c8dee2aaSAndroid Build Coastguard Worker }
4344*c8dee2aaSAndroid Build Coastguard Worker
4345*c8dee2aaSAndroid Build Coastguard Worker #ifdef SK_BUILD_FOR_WIN
4346*c8dee2aaSAndroid Build Coastguard Worker // Check for ANGLE on Windows, so we can workaround a bug in D3D itself (anglebug.com/2098).
4347*c8dee2aaSAndroid Build Coastguard Worker //
4348*c8dee2aaSAndroid Build Coastguard Worker // Basically, if a shader has a construct like:
4349*c8dee2aaSAndroid Build Coastguard Worker //
4350*c8dee2aaSAndroid Build Coastguard Worker // float x = someCondition ? someValue : 0;
4351*c8dee2aaSAndroid Build Coastguard Worker // float2 result = (0 == x) ? float2(x, x)
4352*c8dee2aaSAndroid Build Coastguard Worker // : float2(2 * x / x, 0);
4353*c8dee2aaSAndroid Build Coastguard Worker //
4354*c8dee2aaSAndroid Build Coastguard Worker // ... the compiler will produce an error 'NaN and infinity literals not allowed', even though
4355*c8dee2aaSAndroid Build Coastguard Worker // we've explicitly guarded the division with a check against zero. This manifests in much
4356*c8dee2aaSAndroid Build Coastguard Worker // more complex ways in some of our shaders, so we use this caps bit to add an epsilon value
4357*c8dee2aaSAndroid Build Coastguard Worker // to the denominator of divisions, even when we've added checks that the denominator isn't 0.
4358*c8dee2aaSAndroid Build Coastguard Worker if (angle_backend_is_d3d(ctxInfo.angleBackend()) || ctxInfo.isOverCommandBuffer()) {
4359*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fMustGuardDivisionEvenAfterExplicitZeroCheck = true;
4360*c8dee2aaSAndroid Build Coastguard Worker }
4361*c8dee2aaSAndroid Build Coastguard Worker #endif
4362*c8dee2aaSAndroid Build Coastguard Worker
4363*c8dee2aaSAndroid Build Coastguard Worker // The Adreno 5xx and 6xx produce incorrect results when comparing a pair of matrices.
4364*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.renderer() == GrGLRenderer::kAdreno530 ||
4365*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.renderer() == GrGLRenderer::kAdreno5xx_other ||
4366*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.renderer() == GrGLRenderer::kAdreno615 ||
4367*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.renderer() == GrGLRenderer::kAdreno620 ||
4368*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.renderer() == GrGLRenderer::kAdreno630 ||
4369*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.renderer() == GrGLRenderer::kAdreno640 ||
4370*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.renderer() == GrGLRenderer::kAdreno6xx_other) {
4371*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fRewriteMatrixComparisons = true;
4372*c8dee2aaSAndroid Build Coastguard Worker }
4373*c8dee2aaSAndroid Build Coastguard Worker
4374*c8dee2aaSAndroid Build Coastguard Worker // We've seen Adreno 3xx devices produce incorrect (flipped) values for gl_FragCoord, in some
4375*c8dee2aaSAndroid Build Coastguard Worker // (rare) situations. It's sporadic, and mostly on older drivers. Additionally, old Adreno
4376*c8dee2aaSAndroid Build Coastguard Worker // compilers (see crbug.com/skia/4078) crash when accessing .zw of gl_FragCoord, so just bypass
4377*c8dee2aaSAndroid Build Coastguard Worker // using gl_FragCoord at all to get around it.
4378*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.renderer() == GrGLRenderer::kAdreno3xx) {
4379*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fCanUseFragCoord = false;
4380*c8dee2aaSAndroid Build Coastguard Worker }
4381*c8dee2aaSAndroid Build Coastguard Worker
4382*c8dee2aaSAndroid Build Coastguard Worker // gl_FragCoord has an incorrect subpixel offset on legacy Tegra hardware.
4383*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.renderer() == GrGLRenderer::kTegra_PreK1) {
4384*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fCanUseFragCoord = false;
4385*c8dee2aaSAndroid Build Coastguard Worker }
4386*c8dee2aaSAndroid Build Coastguard Worker
4387*c8dee2aaSAndroid Build Coastguard Worker if (fDriverBugWorkarounds.add_and_true_to_loop_condition) {
4388*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fAddAndTrueToLoopCondition = true;
4389*c8dee2aaSAndroid Build Coastguard Worker }
4390*c8dee2aaSAndroid Build Coastguard Worker
4391*c8dee2aaSAndroid Build Coastguard Worker if (fDriverBugWorkarounds.unfold_short_circuit_as_ternary_operation) {
4392*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fUnfoldShortCircuitAsTernary = true;
4393*c8dee2aaSAndroid Build Coastguard Worker }
4394*c8dee2aaSAndroid Build Coastguard Worker
4395*c8dee2aaSAndroid Build Coastguard Worker if (fDriverBugWorkarounds.emulate_abs_int_function) {
4396*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fEmulateAbsIntFunction = true;
4397*c8dee2aaSAndroid Build Coastguard Worker }
4398*c8dee2aaSAndroid Build Coastguard Worker
4399*c8dee2aaSAndroid Build Coastguard Worker if (fDriverBugWorkarounds.rewrite_do_while_loops) {
4400*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fRewriteDoWhileLoops = true;
4401*c8dee2aaSAndroid Build Coastguard Worker }
4402*c8dee2aaSAndroid Build Coastguard Worker
4403*c8dee2aaSAndroid Build Coastguard Worker if (fDriverBugWorkarounds.remove_pow_with_constant_exponent) {
4404*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fRemovePowWithConstantExponent = true;
4405*c8dee2aaSAndroid Build Coastguard Worker }
4406*c8dee2aaSAndroid Build Coastguard Worker
4407*c8dee2aaSAndroid Build Coastguard Worker if (fDriverBugWorkarounds.disable_dual_source_blending_support) {
4408*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fDualSourceBlendingSupport = false;
4409*c8dee2aaSAndroid Build Coastguard Worker }
4410*c8dee2aaSAndroid Build Coastguard Worker
4411*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.renderer() == GrGLRenderer::kAdreno3xx ||
4412*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.renderer() == GrGLRenderer::kAdreno4xx_other) {
4413*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fMustWriteToFragColor = true;
4414*c8dee2aaSAndroid Build Coastguard Worker }
4415*c8dee2aaSAndroid Build Coastguard Worker
4416*c8dee2aaSAndroid Build Coastguard Worker // Disabling advanced blend on various platforms with major known issues. We also block Chrome
4417*c8dee2aaSAndroid Build Coastguard Worker // command buffer for now until its own denylists can be updated.
4418*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.renderer() == GrGLRenderer::kAdreno430 ||
4419*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.renderer() == GrGLRenderer::kAdreno4xx_other ||
4420*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.renderer() == GrGLRenderer::kAdreno530 ||
4421*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.renderer() == GrGLRenderer::kAdreno5xx_other ||
4422*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.driver() == GrGLDriver::kIntel ||
4423*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.angleVendor() == GrGLVendor::kIntel ||
4424*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.isOverCommandBuffer() ||
4425*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.vendor() == GrGLVendor::kARM /* http://skbug.com/11906 */) {
4426*c8dee2aaSAndroid Build Coastguard Worker fBlendEquationSupport = kBasic_BlendEquationSupport;
4427*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
4428*c8dee2aaSAndroid Build Coastguard Worker }
4429*c8dee2aaSAndroid Build Coastguard Worker
4430*c8dee2aaSAndroid Build Coastguard Worker // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
4431*c8dee2aaSAndroid Build Coastguard Worker if (((ctxInfo.driver() == GrGLDriver::kNVIDIA &&
4432*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337, 00, 0)) ||
4433*c8dee2aaSAndroid Build Coastguard Worker (ctxInfo.angleBackend() == GrGLANGLEBackend::kOpenGL &&
4434*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.angleDriver() == GrGLDriver::kNVIDIA &&
4435*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.angleDriverVersion() < GR_GL_DRIVER_VER(337, 00, 0))) &&
4436*c8dee2aaSAndroid Build Coastguard Worker kAdvanced_BlendEquationSupport == fBlendEquationSupport) {
4437*c8dee2aaSAndroid Build Coastguard Worker fBlendEquationSupport = kBasic_BlendEquationSupport;
4438*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
4439*c8dee2aaSAndroid Build Coastguard Worker }
4440*c8dee2aaSAndroid Build Coastguard Worker
4441*c8dee2aaSAndroid Build Coastguard Worker if (fDriverBugWorkarounds.disable_blend_equation_advanced) {
4442*c8dee2aaSAndroid Build Coastguard Worker fBlendEquationSupport = kBasic_BlendEquationSupport;
4443*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
4444*c8dee2aaSAndroid Build Coastguard Worker }
4445*c8dee2aaSAndroid Build Coastguard Worker
4446*c8dee2aaSAndroid Build Coastguard Worker if (this->advancedBlendEquationSupport()) {
4447*c8dee2aaSAndroid Build Coastguard Worker if ((ctxInfo.driver() == GrGLDriver::kNVIDIA &&
4448*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.driverVersion() < GR_GL_DRIVER_VER(355, 00, 0)) ||
4449*c8dee2aaSAndroid Build Coastguard Worker (ctxInfo.angleBackend() == GrGLANGLEBackend::kOpenGL &&
4450*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.angleDriver() == GrGLDriver::kNVIDIA &&
4451*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.angleDriverVersion() < GR_GL_DRIVER_VER(355, 00, 0))) {
4452*c8dee2aaSAndroid Build Coastguard Worker // Disable color-dodge and color-burn on pre-355.00 NVIDIA.
4453*c8dee2aaSAndroid Build Coastguard Worker fAdvBlendEqDisableFlags |= (1 << static_cast<int>(skgpu::BlendEquation::kColorDodge)) |
4454*c8dee2aaSAndroid Build Coastguard Worker (1 << static_cast<int>(skgpu::BlendEquation::kColorBurn));
4455*c8dee2aaSAndroid Build Coastguard Worker }
4456*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.vendor() == GrGLVendor::kARM) {
4457*c8dee2aaSAndroid Build Coastguard Worker // Disable color-burn on ARM until the fix is released.
4458*c8dee2aaSAndroid Build Coastguard Worker fAdvBlendEqDisableFlags |= (1 << static_cast<int>(skgpu::BlendEquation::kColorBurn));
4459*c8dee2aaSAndroid Build Coastguard Worker }
4460*c8dee2aaSAndroid Build Coastguard Worker }
4461*c8dee2aaSAndroid Build Coastguard Worker
4462*c8dee2aaSAndroid Build Coastguard Worker // On Adreno 5xx devices, there is a bug where we first draw using dual source blending. Thus
4463*c8dee2aaSAndroid Build Coastguard Worker // the dst blend func references the dst. Then the next draw we disable blending. However, on
4464*c8dee2aaSAndroid Build Coastguard Worker // the second draw the driver has a bug where it tries to access the second color output again.
4465*c8dee2aaSAndroid Build Coastguard Worker // This is fixed by reseting the blend function to anything that does not reference src2 when we
4466*c8dee2aaSAndroid Build Coastguard Worker // disable blending.
4467*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.renderer() == GrGLRenderer::kAdreno530 ||
4468*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.renderer() == GrGLRenderer::kAdreno5xx_other ||
4469*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.renderer() == GrGLRenderer::kAdreno620 ||
4470*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.renderer() == GrGLRenderer::kAdreno640) {
4471*c8dee2aaSAndroid Build Coastguard Worker fMustResetBlendFuncBetweenDualSourceAndDisable = true;
4472*c8dee2aaSAndroid Build Coastguard Worker }
4473*c8dee2aaSAndroid Build Coastguard Worker
4474*c8dee2aaSAndroid Build Coastguard Worker // Many ES3 drivers only advertise the ES2 image_external extension, but support the _essl3
4475*c8dee2aaSAndroid Build Coastguard Worker // extension, and require that it be enabled to work with ESSL3. Other devices require the ES2
4476*c8dee2aaSAndroid Build Coastguard Worker // extension to be enabled, even when using ESSL3. Enabling both extensions fixes both cases.
4477*c8dee2aaSAndroid Build Coastguard Worker // skbug.com/7713
4478*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.hasExtension("GL_OES_EGL_image_external") &&
4479*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.glslGeneration() >= SkSL::GLSLGeneration::k330 &&
4480*c8dee2aaSAndroid Build Coastguard Worker !shaderCaps->fExternalTextureSupport) { // i.e. Missing the _essl3 extension
4481*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fExternalTextureSupport = true;
4482*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
4483*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fSecondExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
4484*c8dee2aaSAndroid Build Coastguard Worker }
4485*c8dee2aaSAndroid Build Coastguard Worker
4486*c8dee2aaSAndroid Build Coastguard Worker #ifdef SK_BUILD_FOR_IOS
4487*c8dee2aaSAndroid Build Coastguard Worker // iOS drivers appear to implement TexSubImage by creating a staging buffer, and copying
4488*c8dee2aaSAndroid Build Coastguard Worker // UNPACK_ROW_LENGTH * height bytes. That's unsafe in several scenarios, and the simplest fix
4489*c8dee2aaSAndroid Build Coastguard Worker // is to just disable the feature.
4490*c8dee2aaSAndroid Build Coastguard Worker // https://github.com/flutter/flutter/issues/16718
4491*c8dee2aaSAndroid Build Coastguard Worker // https://bugreport.apple.com/web/?problemID=39948888
4492*c8dee2aaSAndroid Build Coastguard Worker fWritePixelsRowBytesSupport = false;
4493*c8dee2aaSAndroid Build Coastguard Worker // This affects all iOS devices for transfering from a PBO as well (presumably the issue is in
4494*c8dee2aaSAndroid Build Coastguard Worker // the GL->Metal layer).
4495*c8dee2aaSAndroid Build Coastguard Worker fTransferPixelsToRowBytesSupport = false;
4496*c8dee2aaSAndroid Build Coastguard Worker #endif
4497*c8dee2aaSAndroid Build Coastguard Worker
4498*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.vendor() == GrGLVendor::kIntel || // IntelIris640 drops draws completely.
4499*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.webglVendor() == GrGLVendor::kIntel || // Disable if the webgl vendor is Intel
4500*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.renderer() == GrGLRenderer::kMaliT || // Some curves appear flat on GalaxyS6.
4501*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.renderer() == GrGLRenderer::kAdreno3xx ||
4502*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.renderer() == GrGLRenderer::kAdreno430 ||
4503*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.renderer() == GrGLRenderer::kAdreno4xx_other || // We get garbage on Adreno405.
4504*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.angleBackend() == GrGLANGLEBackend::kD3D9) { // D3D9 conic strokes fail.
4505*c8dee2aaSAndroid Build Coastguard Worker fDisableTessellationPathRenderer = true;
4506*c8dee2aaSAndroid Build Coastguard Worker }
4507*c8dee2aaSAndroid Build Coastguard Worker // We found that on Wembley devices (PowerVR GE8320) that using tessellation path renderer would
4508*c8dee2aaSAndroid Build Coastguard Worker // cause lots of rendering errors where it seemed like vertices were in the wrong place. This
4509*c8dee2aaSAndroid Build Coastguard Worker // led to lots of GMs drawing nothing (e.g. dashing4) or lots of garbage. The Wembley devices
4510*c8dee2aaSAndroid Build Coastguard Worker // were running Android 12 with a driver version of 1.13. We previously had TecnoSpark devices
4511*c8dee2aaSAndroid Build Coastguard Worker // with the same GPU running on Android P (driver 1.10) which did not have this issue. We don't
4512*c8dee2aaSAndroid Build Coastguard Worker // know when the bug appeared in the driver so for now we disable tessellation path renderer for
4513*c8dee2aaSAndroid Build Coastguard Worker // all matching gpus regardless of driver version.
4514*c8dee2aaSAndroid Build Coastguard Worker //
4515*c8dee2aaSAndroid Build Coastguard Worker // 2022-10-28 Update: Testing via Flutter found this is not a problem on driver version 1.15.
4516*c8dee2aaSAndroid Build Coastguard Worker // See https://github.com/flutter/flutter/issues/113596
4517*c8dee2aaSAndroid Build Coastguard Worker // GL_VERSION : OpenGL ES 3.1 build 1.15@6133109
4518*c8dee2aaSAndroid Build Coastguard Worker // GL_RENDERER: PowerVR Rogue AXE-1-16M
4519*c8dee2aaSAndroid Build Coastguard Worker // GL_VENDOR : Imagination Technologies
4520*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.renderer() == GrGLRenderer::kPowerVRRogue &&
4521*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.driverVersion() < GR_GL_DRIVER_VER(1, 15, 0)) {
4522*c8dee2aaSAndroid Build Coastguard Worker fDisableTessellationPathRenderer = true;
4523*c8dee2aaSAndroid Build Coastguard Worker }
4524*c8dee2aaSAndroid Build Coastguard Worker
4525*c8dee2aaSAndroid Build Coastguard Worker // The Wembley device draws the mesh_update GM incorrectly when using transfer buffers. Buffer
4526*c8dee2aaSAndroid Build Coastguard Worker // to buffer transfers affect draws earlier in the GL command sequence.
4527*c8dee2aaSAndroid Build Coastguard Worker // Android API: 31
4528*c8dee2aaSAndroid Build Coastguard Worker // GL_VERSION : OpenGL ES 3.2 build 1.13@5720833
4529*c8dee2aaSAndroid Build Coastguard Worker // GL_RENDERER: PowerVR Rogue GE8300
4530*c8dee2aaSAndroid Build Coastguard Worker // GL_VENDOR : Imagination Technologies
4531*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.renderer() == GrGLRenderer::kPowerVRRogue) {
4532*c8dee2aaSAndroid Build Coastguard Worker fTransferFromBufferToBufferSupport = false;
4533*c8dee2aaSAndroid Build Coastguard Worker }
4534*c8dee2aaSAndroid Build Coastguard Worker
4535*c8dee2aaSAndroid Build Coastguard Worker // The Wembley device fails shader compilations with no error message when there is a const
4536*c8dee2aaSAndroid Build Coastguard Worker // parameter. Given that we've already passed through SkSL compilation and enforced that the
4537*c8dee2aaSAndroid Build Coastguard Worker // parameter is never written, it is harmless to strip the const off when writing GLSL.
4538*c8dee2aaSAndroid Build Coastguard Worker // Android API: 31
4539*c8dee2aaSAndroid Build Coastguard Worker // GL_VERSION : OpenGL ES 3.2 build 1.13@5720833
4540*c8dee2aaSAndroid Build Coastguard Worker // GL_RENDERER: PowerVR Rogue GE8300
4541*c8dee2aaSAndroid Build Coastguard Worker // GL_VENDOR : Imagination Technologies
4542*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.renderer() == GrGLRenderer::kPowerVRRogue) {
4543*c8dee2aaSAndroid Build Coastguard Worker fShaderCaps->fRemoveConstFromFunctionParameters = true;
4544*c8dee2aaSAndroid Build Coastguard Worker }
4545*c8dee2aaSAndroid Build Coastguard Worker #ifdef SK_BUILD_FOR_WIN
4546*c8dee2aaSAndroid Build Coastguard Worker // glDrawElementsIndirect fails GrMeshTest on every Win10 Intel bot.
4547*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.driver() == GrGLDriver::kIntel ||
4548*c8dee2aaSAndroid Build Coastguard Worker (ctxInfo.angleVendor() == GrGLVendor::kIntel &&
4549*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.angleBackend() == GrGLANGLEBackend::kOpenGL)) {
4550*c8dee2aaSAndroid Build Coastguard Worker fNativeDrawIndexedIndirectIsBroken = true;
4551*c8dee2aaSAndroid Build Coastguard Worker fUseClientSideIndirectBuffers = true;
4552*c8dee2aaSAndroid Build Coastguard Worker }
4553*c8dee2aaSAndroid Build Coastguard Worker #endif
4554*c8dee2aaSAndroid Build Coastguard Worker
4555*c8dee2aaSAndroid Build Coastguard Worker // PowerVRGX6250 drops every pixel if we modify the sample mask while color writes are disabled.
4556*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.renderer() == GrGLRenderer::kPowerVRRogue) {
4557*c8dee2aaSAndroid Build Coastguard Worker fNeverDisableColorWrites = true;
4558*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fMustWriteToFragColor = true;
4559*c8dee2aaSAndroid Build Coastguard Worker }
4560*c8dee2aaSAndroid Build Coastguard Worker
4561*c8dee2aaSAndroid Build Coastguard Worker // It appears that Qualcomm drivers don't actually support
4562*c8dee2aaSAndroid Build Coastguard Worker // GL_NV_shader_noperspective_interpolation in ES 3.00 or 3.10 shaders, only 3.20.
4563*c8dee2aaSAndroid Build Coastguard Worker // https://crbug.com/986581
4564*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.vendor() == GrGLVendor::kQualcomm &&
4565*c8dee2aaSAndroid Build Coastguard Worker SkSL::GLSLGeneration::k320es != ctxInfo.glslGeneration()) {
4566*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fNoPerspectiveInterpolationSupport = false;
4567*c8dee2aaSAndroid Build Coastguard Worker }
4568*c8dee2aaSAndroid Build Coastguard Worker
4569*c8dee2aaSAndroid Build Coastguard Worker // We disable srgb write control for Adreno4xx devices.
4570*c8dee2aaSAndroid Build Coastguard Worker // see: https://bug.skia.org/5329
4571*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.renderer() == GrGLRenderer::kAdreno430 ||
4572*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.renderer() == GrGLRenderer::kAdreno4xx_other) {
4573*c8dee2aaSAndroid Build Coastguard Worker fSRGBWriteControl = false;
4574*c8dee2aaSAndroid Build Coastguard Worker }
4575*c8dee2aaSAndroid Build Coastguard Worker
4576*c8dee2aaSAndroid Build Coastguard Worker // MacPro devices with AMD cards fail to create MSAA sRGB render buffers.
4577*c8dee2aaSAndroid Build Coastguard Worker #if defined(SK_BUILD_FOR_MAC)
4578*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.vendor() == GrGLVendor::kATI) {
4579*c8dee2aaSAndroid Build Coastguard Worker formatWorkarounds->fDisableSRGBRenderWithMSAAForMacAMD = true;
4580*c8dee2aaSAndroid Build Coastguard Worker }
4581*c8dee2aaSAndroid Build Coastguard Worker #endif
4582*c8dee2aaSAndroid Build Coastguard Worker
4583*c8dee2aaSAndroid Build Coastguard Worker // Command buffer fails glTexSubImage2D with type == GL_HALF_FLOAT_OES if a GL_RGBA16F texture
4584*c8dee2aaSAndroid Build Coastguard Worker // is created with glTexStorage2D. See crbug.com/1008003.
4585*c8dee2aaSAndroid Build Coastguard Worker formatWorkarounds->fDisableRGBA16FTexStorageForCrBug1008003 =
4586*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.isOverCommandBuffer() && ctxInfo.version() < GR_GL_VER(3, 0);
4587*c8dee2aaSAndroid Build Coastguard Worker
4588*c8dee2aaSAndroid Build Coastguard Worker #if defined(SK_BUILD_FOR_WIN)
4589*c8dee2aaSAndroid Build Coastguard Worker // On Intel Windows ES contexts it seems that using texture storage with BGRA causes
4590*c8dee2aaSAndroid Build Coastguard Worker // problems with cross-context SkImages.
4591*c8dee2aaSAndroid Build Coastguard Worker formatWorkarounds->fDisableBGRATextureStorageForIntelWindowsES =
4592*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.driver() == GrGLDriver::kIntel && GR_IS_GR_GL_ES(ctxInfo.standard());
4593*c8dee2aaSAndroid Build Coastguard Worker #endif
4594*c8dee2aaSAndroid Build Coastguard Worker
4595*c8dee2aaSAndroid Build Coastguard Worker // On the Intel Iris 6100, interacting with LUM16F seems to confuse the driver. After
4596*c8dee2aaSAndroid Build Coastguard Worker // writing to/reading from a LUM16F texture reads from/writes to other formats behave
4597*c8dee2aaSAndroid Build Coastguard Worker // erratically.
4598*c8dee2aaSAndroid Build Coastguard Worker // All Adrenos claim to support LUM16F but don't appear to actually do so.
4599*c8dee2aaSAndroid Build Coastguard Worker // The failing devices/gpus were: Nexus5/Adreno330, Nexus5x/Adreno418, Pixel/Adreno530,
4600*c8dee2aaSAndroid Build Coastguard Worker // Pixel2XL/Adreno540 and Pixel3/Adreno630
4601*c8dee2aaSAndroid Build Coastguard Worker formatWorkarounds->fDisableLuminance16F =
4602*c8dee2aaSAndroid Build Coastguard Worker (ctxInfo.renderer() == GrGLRenderer::kIntelBroadwell ||
4603*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.vendor() == GrGLVendor::kQualcomm) &&
4604*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.angleBackend() == GrGLANGLEBackend::kUnknown;
4605*c8dee2aaSAndroid Build Coastguard Worker
4606*c8dee2aaSAndroid Build Coastguard Worker #ifdef SK_BUILD_FOR_MAC
4607*c8dee2aaSAndroid Build Coastguard Worker // On a MacBookPro 11.5 running MacOS 10.13 with a Radeon M370X the TransferPixelsFrom test
4608*c8dee2aaSAndroid Build Coastguard Worker // fails when transferring out from a GL_RG8 texture using GL_RG/GL_UNSIGNED_BYTE.
4609*c8dee2aaSAndroid Build Coastguard Worker // The same error also occurs in MacOS 10.15 with a Radeon Pro 5300M.
4610*c8dee2aaSAndroid Build Coastguard Worker formatWorkarounds->fDisallowDirectRG8ReadPixels =
4611*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.renderer() == GrGLRenderer::kAMDRadeonR9M3xx ||
4612*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.renderer() == GrGLRenderer::kAMDRadeonPro5xxx ||
4613*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.renderer() == GrGLRenderer::kAMDRadeonProVegaxx;
4614*c8dee2aaSAndroid Build Coastguard Worker #endif
4615*c8dee2aaSAndroid Build Coastguard Worker
4616*c8dee2aaSAndroid Build Coastguard Worker #ifdef SK_BUILD_FOR_ANDROID
4617*c8dee2aaSAndroid Build Coastguard Worker // crbug.com/945506. Telemetry reported a memory usage regression for Android Go Chrome/WebView
4618*c8dee2aaSAndroid Build Coastguard Worker // when using glTexStorage2D. This appears to affect OOP-R (so not just over command buffer).
4619*c8dee2aaSAndroid Build Coastguard Worker // Update 10/2023, it looks like this may just effect chrome Android GO devices which are
4620*c8dee2aaSAndroid Build Coastguard Worker // running on Mali-T720. It does not seem to impact Qualcomm devices. We have no tests to verify
4621*c8dee2aaSAndroid Build Coastguard Worker // if newer ARM devices are impacted, so for now we keep this disabled on all ARM by default.
4622*c8dee2aaSAndroid Build Coastguard Worker //
4623*c8dee2aaSAndroid Build Coastguard Worker // We allow the client to pass in a GrContextOption flag to say they prefer having tex storage
4624*c8dee2aaSAndroid Build Coastguard Worker // support regadless of memory usage impacts. This is important for supporting Protected
4625*c8dee2aaSAndroid Build Coastguard Worker // textures as they require tex storage support.
4626*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.vendor() == GrGLVendor::kARM &&
4627*c8dee2aaSAndroid Build Coastguard Worker !contextOptions.fAlwaysUseTexStorageWhenAvailable &&
4628*c8dee2aaSAndroid Build Coastguard Worker !fSupportsProtectedContent) {
4629*c8dee2aaSAndroid Build Coastguard Worker formatWorkarounds->fDisableTexStorage = true;
4630*c8dee2aaSAndroid Build Coastguard Worker }
4631*c8dee2aaSAndroid Build Coastguard Worker #endif
4632*c8dee2aaSAndroid Build Coastguard Worker
4633*c8dee2aaSAndroid Build Coastguard Worker // https://github.com/flutter/flutter/issues/38700
4634*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.driver() == GrGLDriver::kAndroidEmulator) {
4635*c8dee2aaSAndroid Build Coastguard Worker shaderCaps->fNoDefaultPrecisionForExternalSamplers = true;
4636*c8dee2aaSAndroid Build Coastguard Worker }
4637*c8dee2aaSAndroid Build Coastguard Worker
4638*c8dee2aaSAndroid Build Coastguard Worker // http://skbug.com/9491: Nexus5 produces rendering artifacts when we use QCOM_tiled_rendering.
4639*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.renderer() == GrGLRenderer::kAdreno3xx) {
4640*c8dee2aaSAndroid Build Coastguard Worker fTiledRenderingSupport = false;
4641*c8dee2aaSAndroid Build Coastguard Worker }
4642*c8dee2aaSAndroid Build Coastguard Worker // https://github.com/flutter/flutter/issues/47164
4643*c8dee2aaSAndroid Build Coastguard Worker // https://github.com/flutter/flutter/issues/47804
4644*c8dee2aaSAndroid Build Coastguard Worker if (fTiledRenderingSupport && (!glInterface->fFunctions.fStartTiling ||
4645*c8dee2aaSAndroid Build Coastguard Worker !glInterface->fFunctions.fEndTiling)) {
4646*c8dee2aaSAndroid Build Coastguard Worker // Some devices expose the QCOM tiled memory extension string but don't actually provide the
4647*c8dee2aaSAndroid Build Coastguard Worker // start and end tiling functions (see above flutter bugs). To work around this, the funcs
4648*c8dee2aaSAndroid Build Coastguard Worker // are marked optional in the interface generator, but we turn off the tiled rendering cap
4649*c8dee2aaSAndroid Build Coastguard Worker // if they aren't provided. This disabling is in driver workarounds so that SKQP will still
4650*c8dee2aaSAndroid Build Coastguard Worker // fail on devices that advertise the extension w/o the functions.
4651*c8dee2aaSAndroid Build Coastguard Worker fTiledRenderingSupport = false;
4652*c8dee2aaSAndroid Build Coastguard Worker }
4653*c8dee2aaSAndroid Build Coastguard Worker
4654*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.angleBackend() == GrGLANGLEBackend::kD3D9) {
4655*c8dee2aaSAndroid Build Coastguard Worker formatWorkarounds->fDisallowBGRA8ReadPixels = true;
4656*c8dee2aaSAndroid Build Coastguard Worker }
4657*c8dee2aaSAndroid Build Coastguard Worker
4658*c8dee2aaSAndroid Build Coastguard Worker // We disable MSAA for older Intel GPUs. Before Gen9, performance was very bad. Even with Gen9,
4659*c8dee2aaSAndroid Build Coastguard Worker // we've seen driver crashes in the wild.
4660*c8dee2aaSAndroid Build Coastguard Worker // (crbug.com/527565, crbug.com/983926)
4661*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.vendor() == GrGLVendor::kIntel || ctxInfo.angleVendor() == GrGLVendor::kIntel) {
4662*c8dee2aaSAndroid Build Coastguard Worker // Gen11 seems mostly ok, except we avoid drawing lines with MSAA. (anglebug.com/7796)
4663*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.renderer() >= GrGLRenderer::kIntelIceLake &&
4664*c8dee2aaSAndroid Build Coastguard Worker contextOptions.fAllowMSAAOnNewIntel) {
4665*c8dee2aaSAndroid Build Coastguard Worker if (fMSFBOType != kNone_MSFBOType) {
4666*c8dee2aaSAndroid Build Coastguard Worker fAvoidLineDraws = true;
4667*c8dee2aaSAndroid Build Coastguard Worker }
4668*c8dee2aaSAndroid Build Coastguard Worker } else {
4669*c8dee2aaSAndroid Build Coastguard Worker fMSFBOType = kNone_MSFBOType;
4670*c8dee2aaSAndroid Build Coastguard Worker }
4671*c8dee2aaSAndroid Build Coastguard Worker }
4672*c8dee2aaSAndroid Build Coastguard Worker
4673*c8dee2aaSAndroid Build Coastguard Worker // ANGLE's D3D9 backend + AMD GPUs are flaky with program binary caching (skbug.com/10395)
4674*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.angleBackend() == GrGLANGLEBackend::kD3D9 &&
4675*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.angleVendor() == GrGLVendor::kATI) {
4676*c8dee2aaSAndroid Build Coastguard Worker fProgramBinarySupport = false;
4677*c8dee2aaSAndroid Build Coastguard Worker }
4678*c8dee2aaSAndroid Build Coastguard Worker
4679*c8dee2aaSAndroid Build Coastguard Worker // skbug.com/11204. Avoid recursion issue in SurfaceContext::writePixels.
4680*c8dee2aaSAndroid Build Coastguard Worker if (fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO) {
4681*c8dee2aaSAndroid Build Coastguard Worker fReuseScratchTextures = false;
4682*c8dee2aaSAndroid Build Coastguard Worker }
4683*c8dee2aaSAndroid Build Coastguard Worker
4684*c8dee2aaSAndroid Build Coastguard Worker // skbug.com/11935. Don't reorder on these GPUs in GL on old drivers.
4685*c8dee2aaSAndroid Build Coastguard Worker if ((ctxInfo.renderer() == GrGLRenderer::kAdreno620 ||
4686*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.renderer() == GrGLRenderer::kAdreno640) &&
4687*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.driverVersion() < GR_GL_DRIVER_VER(571, 0, 0)) {
4688*c8dee2aaSAndroid Build Coastguard Worker fAvoidReorderingRenderTasks = true;
4689*c8dee2aaSAndroid Build Coastguard Worker }
4690*c8dee2aaSAndroid Build Coastguard Worker
4691*c8dee2aaSAndroid Build Coastguard Worker // http://crbug.com/1197152
4692*c8dee2aaSAndroid Build Coastguard Worker // http://b/187364475
4693*c8dee2aaSAndroid Build Coastguard Worker // We could limit this < 1.13 on ChromeOS but we don't really have a good way to detect
4694*c8dee2aaSAndroid Build Coastguard Worker // ChromeOS from here.
4695*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.renderer() == GrGLRenderer::kPowerVRRogue &&
4696*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.driver() == GrGLDriver::kImagination &&
4697*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.driverVersion() < GR_GL_DRIVER_VER(1, 16, 0)) {
4698*c8dee2aaSAndroid Build Coastguard Worker fShaderCaps->fShaderDerivativeSupport = false;
4699*c8dee2aaSAndroid Build Coastguard Worker }
4700*c8dee2aaSAndroid Build Coastguard Worker
4701*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.driver() == GrGLDriver::kFreedreno) {
4702*c8dee2aaSAndroid Build Coastguard Worker formatWorkarounds->fDisallowUnorm16Transfers = true;
4703*c8dee2aaSAndroid Build Coastguard Worker }
4704*c8dee2aaSAndroid Build Coastguard Worker
4705*c8dee2aaSAndroid Build Coastguard Worker // If we keep rebind the same texture to an FBO's color attachment but changing between MSAA and
4706*c8dee2aaSAndroid Build Coastguard Worker // non-MSAA we get corruption in the texture contents. Binding texture 0 and then rebinding the
4707*c8dee2aaSAndroid Build Coastguard Worker // original texture avoids this.
4708*c8dee2aaSAndroid Build Coastguard Worker // This was found on Nexus 5, Android 6.0.1, build M4B30Z
4709*c8dee2aaSAndroid Build Coastguard Worker // GL_VENDOR : "Qualcomm"
4710*c8dee2aaSAndroid Build Coastguard Worker // GL_RENDERER: "Adreno (TM) 330"
4711*c8dee2aaSAndroid Build Coastguard Worker // GL_VERSION : "OpenGL ES 3.0 [email protected] AU@ (GIT@I96aee987eb)"
4712*c8dee2aaSAndroid Build Coastguard Worker //
4713*c8dee2aaSAndroid Build Coastguard Worker // We also so alpha blending issues on these GMs skbug_9819, p3_ovals, p3 on Mali-Gxx devices
4714*c8dee2aaSAndroid Build Coastguard Worker // The GM issues were observed on a Galaxy S9 running Android 10:
4715*c8dee2aaSAndroid Build Coastguard Worker // GL_VERSION : "OpenGL ES 3.2 v1.r19p0-01rel0.###other-sha0123456789ABCDEF0###"
4716*c8dee2aaSAndroid Build Coastguard Worker // GL_RENDERER: "Mali-G72"
4717*c8dee2aaSAndroid Build Coastguard Worker // GL_VENDOR : "ARM"
4718*c8dee2aaSAndroid Build Coastguard Worker // and a P30 running Android 9:
4719*c8dee2aaSAndroid Build Coastguard Worker // GL_VERSION : "OpenGL ES 3.2 v1.r16p0-01rel0.4aee637066427cbcd25297324dba15f5"
4720*c8dee2aaSAndroid Build Coastguard Worker // GL_RENDERER: "Mali-G76"
4721*c8dee2aaSAndroid Build Coastguard Worker // GL_VENDOR : "ARM"
4722*c8dee2aaSAndroid Build Coastguard Worker // but *not* a Galaxy S20 running Android 10:
4723*c8dee2aaSAndroid Build Coastguard Worker // GL_VERSION : "OpenGL ES 3.2 v1.r20p0-01rel0.###other-sha0123456789ABCDEF0###"
4724*c8dee2aaSAndroid Build Coastguard Worker // GL_RENDERER: "Mali-G77"
4725*c8dee2aaSAndroid Build Coastguard Worker // GL_VENDOR : "ARM"
4726*c8dee2aaSAndroid Build Coastguard Worker // It's unclear if the difference is driver version or Bifrost vs Valhall. The workaround is
4727*c8dee2aaSAndroid Build Coastguard Worker // fairly trivial so just applying to all Bifrost and Valhall.
4728*c8dee2aaSAndroid Build Coastguard Worker if ((ctxInfo.renderer() == GrGLRenderer::kAdreno3xx &&
4729*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.driver() == GrGLDriver::kQualcomm) ||
4730*c8dee2aaSAndroid Build Coastguard Worker (ctxInfo.renderer() == GrGLRenderer::kMaliG)) {
4731*c8dee2aaSAndroid Build Coastguard Worker fBindTexture0WhenChangingTextureFBOMultisampleCount = true;
4732*c8dee2aaSAndroid Build Coastguard Worker }
4733*c8dee2aaSAndroid Build Coastguard Worker
4734*c8dee2aaSAndroid Build Coastguard Worker // skbug.com/12640
4735*c8dee2aaSAndroid Build Coastguard Worker // We found that on the Galaxy S7 the TransferPixelsTo test would fail after adding
4736*c8dee2aaSAndroid Build Coastguard Worker // glCheckFramebufferStatus() checks when making new FBOs. Note that the returned status was
4737*c8dee2aaSAndroid Build Coastguard Worker // GL_FRAMEBUFFER_COMPLETE. Switching the color binding to ID 0 and back to the original
4738*c8dee2aaSAndroid Build Coastguard Worker // afterwards works around the issue.
4739*c8dee2aaSAndroid Build Coastguard Worker // GL_VENDOR : "ARM"
4740*c8dee2aaSAndroid Build Coastguard Worker // GL_RENDERER: "Mali-T880"
4741*c8dee2aaSAndroid Build Coastguard Worker // GL_VERSION : "OpenGL ES 3.2 v1.r22p0-01rel0.f294e54ceb2cb2d81039204fa4b0402e"
4742*c8dee2aaSAndroid Build Coastguard Worker //
4743*c8dee2aaSAndroid Build Coastguard Worker // This *didn't* reproduce on a Kevin ChromeOS device:
4744*c8dee2aaSAndroid Build Coastguard Worker // GL_VENDOR : "ARM"
4745*c8dee2aaSAndroid Build Coastguard Worker // GL_RENDERER: "Mali-T860"
4746*c8dee2aaSAndroid Build Coastguard Worker // GL_VERSION : "OpenGL ES 3.2 v1.r26p0-01rel0.217d2597f6bd19b169343737782e56e3"
4747*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.renderer() == GrGLRenderer::kMaliT &&
4748*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.driver() == GrGLDriver::kARM &&
4749*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.driverVersion() < GR_GL_DRIVER_VER(1, 26, 0)) {
4750*c8dee2aaSAndroid Build Coastguard Worker fRebindColorAttachmentAfterCheckFramebufferStatus = true;
4751*c8dee2aaSAndroid Build Coastguard Worker }
4752*c8dee2aaSAndroid Build Coastguard Worker
4753*c8dee2aaSAndroid Build Coastguard Worker // skbug.com/13286
4754*c8dee2aaSAndroid Build Coastguard Worker // We found that the P30 produces a GL error when setting GL_TEXTURE_MAX_ANISOTROPY as a sampler
4755*c8dee2aaSAndroid Build Coastguard Worker // parameter but not as a texture parameter. We are disabling anisotropy on drivers that may
4756*c8dee2aaSAndroid Build Coastguard Worker // be affected.
4757*c8dee2aaSAndroid Build Coastguard Worker //
4758*c8dee2aaSAndroid Build Coastguard Worker // FAIL on P30
4759*c8dee2aaSAndroid Build Coastguard Worker // GL_VENDOR : ARM
4760*c8dee2aaSAndroid Build Coastguard Worker // GL_RENDERER: Mali-G76
4761*c8dee2aaSAndroid Build Coastguard Worker // GL_VERSION : OpenGL ES 3.2 v1.r16p0-01rel0.4aee637066427cbcd25297324dba15f5
4762*c8dee2aaSAndroid Build Coastguard Worker //
4763*c8dee2aaSAndroid Build Coastguard Worker // PASS on Pixel6
4764*c8dee2aaSAndroid Build Coastguard Worker // GL_VENDOR : ARM
4765*c8dee2aaSAndroid Build Coastguard Worker // GL_RENDERER: Mali-G78
4766*c8dee2aaSAndroid Build Coastguard Worker // GL_VERSION : OpenGL ES 3.2 v1.r32p1-00pxl0.b7e5868a59a273f4a9f58d1657ef99de
4767*c8dee2aaSAndroid Build Coastguard Worker //
4768*c8dee2aaSAndroid Build Coastguard Worker // PASS on Galaxy S30:
4769*c8dee2aaSAndroid Build Coastguard Worker // GL_VENDOR : ARM
4770*c8dee2aaSAndroid Build Coastguard Worker // GL_RENDERER: Mali-G77
4771*c8dee2aaSAndroid Build Coastguard Worker // GL_VERSION : OpenGL ES 3.2 v1.r20p0-01rel0.###other-sha0123456789ABCDEF0###
4772*c8dee2aaSAndroid Build Coastguard Worker //
4773*c8dee2aaSAndroid Build Coastguard Worker // PASS on Galaxy S9:
4774*c8dee2aaSAndroid Build Coastguard Worker // GL_VENDOR : ARM
4775*c8dee2aaSAndroid Build Coastguard Worker // GL_RENDERER: Mali-G72
4776*c8dee2aaSAndroid Build Coastguard Worker // GL_VENDOR : OpenGL ES 3.2 v1.r19p0-01rel0.###other-sha0123456789ABCDEF0###
4777*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.renderer() == GrGLRenderer::kMaliG &&
4778*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.driver() == GrGLDriver::kARM &&
4779*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.driverVersion() < GR_GL_DRIVER_VER(1, 19, 0)) {
4780*c8dee2aaSAndroid Build Coastguard Worker fAnisoSupport = false;
4781*c8dee2aaSAndroid Build Coastguard Worker }
4782*c8dee2aaSAndroid Build Coastguard Worker
4783*c8dee2aaSAndroid Build Coastguard Worker // b/229626353
4784*c8dee2aaSAndroid Build Coastguard Worker // On certain classes of Adreno running WebGL, glTexSubImage2D() occasionally fails to upload
4785*c8dee2aaSAndroid Build Coastguard Worker // texels on time for sampling. The solution is to call glFlush() before glTexSubImage2D().
4786*c8dee2aaSAndroid Build Coastguard Worker // Seen on:
4787*c8dee2aaSAndroid Build Coastguard Worker // * Nexus 5x (Adreno 418)
4788*c8dee2aaSAndroid Build Coastguard Worker // * Nexus 6 (Adreno 420)
4789*c8dee2aaSAndroid Build Coastguard Worker // * Pixel 3 (Adreno 630)
4790*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.renderer() == GrGLRenderer::kWebGL &&
4791*c8dee2aaSAndroid Build Coastguard Worker (ctxInfo.webglRenderer() == GrGLRenderer::kAdreno4xx_other ||
4792*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.webglRenderer() == GrGLRenderer::kAdreno630)) {
4793*c8dee2aaSAndroid Build Coastguard Worker fFlushBeforeWritePixels = true;
4794*c8dee2aaSAndroid Build Coastguard Worker }
4795*c8dee2aaSAndroid Build Coastguard Worker // crbug.com/1395777
4796*c8dee2aaSAndroid Build Coastguard Worker // There appears to be a driver bug in GLSL program linking on Mali 400 and 450 devices with
4797*c8dee2aaSAndroid Build Coastguard Worker // driver version 2.1.199xx that causes the copy-as-draw programs in GrGLGpu to fail. The crash
4798*c8dee2aaSAndroid Build Coastguard Worker // rate increased when scaling copy support was added, so disallow scaling copy-as-draws on
4799*c8dee2aaSAndroid Build Coastguard Worker // these devices.
4800*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.renderer() == GrGLRenderer::kMali4xx &&
4801*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.driverVersion() >= GR_GL_DRIVER_VER(2, 1, 19900)) {
4802*c8dee2aaSAndroid Build Coastguard Worker fDisableScalingCopyAsDraws = true;
4803*c8dee2aaSAndroid Build Coastguard Worker }
4804*c8dee2aaSAndroid Build Coastguard Worker // skbug.com/14194
4805*c8dee2aaSAndroid Build Coastguard Worker // Setting the max level is technically unnecessary, but on Intel drivers it makes it
4806*c8dee2aaSAndroid Build Coastguard Worker // clear that a rendering feedback loop is not occurring, and avoids hitting a slow path.
4807*c8dee2aaSAndroid Build Coastguard Worker // When running on ANGLE, however, this triggers the validator because we can only use
4808*c8dee2aaSAndroid Build Coastguard Worker // levels between BASE_LEVEL and MAX_LEVEL for a framebuffer, and we're trying to use
4809*c8dee2aaSAndroid Build Coastguard Worker // MAX_LEVEL+1. So instead we set up sync points between each mipmap level render.
4810*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.vendor() == GrGLVendor::kIntel &&
4811*c8dee2aaSAndroid Build Coastguard Worker ctxInfo.angleBackend() == GrGLANGLEBackend::kUnknown) {
4812*c8dee2aaSAndroid Build Coastguard Worker fRegenerateMipmapType = RegenerateMipmapType::kBasePlusMaxLevel;
4813*c8dee2aaSAndroid Build Coastguard Worker } else if (ctxInfo.angleVendor() == GrGLVendor::kIntel) {
4814*c8dee2aaSAndroid Build Coastguard Worker fRegenerateMipmapType = RegenerateMipmapType::kBasePlusSync;
4815*c8dee2aaSAndroid Build Coastguard Worker }
4816*c8dee2aaSAndroid Build Coastguard Worker #ifdef SK_BUILD_FOR_MAC
4817*c8dee2aaSAndroid Build Coastguard Worker // On Apple Silicon, RG88 requires 2-byte alignment for transfer buffer readback
4818*c8dee2aaSAndroid Build Coastguard Worker if (ctxInfo.vendor() == GrGLVendor::kApple) {
4819*c8dee2aaSAndroid Build Coastguard Worker fPadRG88TransferAlignment = true;
4820*c8dee2aaSAndroid Build Coastguard Worker }
4821*c8dee2aaSAndroid Build Coastguard Worker #endif
4822*c8dee2aaSAndroid Build Coastguard Worker }
4823*c8dee2aaSAndroid Build Coastguard Worker
onApplyOptionsOverrides(const GrContextOptions & options)4824*c8dee2aaSAndroid Build Coastguard Worker void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {
4825*c8dee2aaSAndroid Build Coastguard Worker if (options.fDisableDriverCorrectnessWorkarounds) {
4826*c8dee2aaSAndroid Build Coastguard Worker SkASSERT(!fDoManualMipmapping);
4827*c8dee2aaSAndroid Build Coastguard Worker SkASSERT(!fClearToBoundaryValuesIsBroken);
4828*c8dee2aaSAndroid Build Coastguard Worker SkASSERT(0 == fMaxInstancesPerDrawWithoutCrashing);
4829*c8dee2aaSAndroid Build Coastguard Worker SkASSERT(!fDrawArraysBaseVertexIsBroken);
4830*c8dee2aaSAndroid Build Coastguard Worker SkASSERT(!fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO);
4831*c8dee2aaSAndroid Build Coastguard Worker SkASSERT(!fUseDrawInsteadOfAllRenderTargetWrites);
4832*c8dee2aaSAndroid Build Coastguard Worker SkASSERT(!fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines);
4833*c8dee2aaSAndroid Build Coastguard Worker SkASSERT(!fDontSetBaseOrMaxLevelForExternalTextures);
4834*c8dee2aaSAndroid Build Coastguard Worker SkASSERT(!fNeverDisableColorWrites);
4835*c8dee2aaSAndroid Build Coastguard Worker }
4836*c8dee2aaSAndroid Build Coastguard Worker if (options.fShaderCacheStrategy < GrContextOptions::ShaderCacheStrategy::kBackendBinary) {
4837*c8dee2aaSAndroid Build Coastguard Worker fProgramBinarySupport = false;
4838*c8dee2aaSAndroid Build Coastguard Worker }
4839*c8dee2aaSAndroid Build Coastguard Worker
4840*c8dee2aaSAndroid Build Coastguard Worker switch (options.fSkipGLErrorChecks) {
4841*c8dee2aaSAndroid Build Coastguard Worker case GrContextOptions::Enable::kNo:
4842*c8dee2aaSAndroid Build Coastguard Worker fSkipErrorChecks = false;
4843*c8dee2aaSAndroid Build Coastguard Worker break;
4844*c8dee2aaSAndroid Build Coastguard Worker case GrContextOptions::Enable::kYes:
4845*c8dee2aaSAndroid Build Coastguard Worker fSkipErrorChecks = true;
4846*c8dee2aaSAndroid Build Coastguard Worker break;
4847*c8dee2aaSAndroid Build Coastguard Worker case GrContextOptions::Enable::kDefault:
4848*c8dee2aaSAndroid Build Coastguard Worker break;
4849*c8dee2aaSAndroid Build Coastguard Worker }
4850*c8dee2aaSAndroid Build Coastguard Worker }
4851*c8dee2aaSAndroid Build Coastguard Worker
onSurfaceSupportsWritePixels(const GrSurface * surface) const4852*c8dee2aaSAndroid Build Coastguard Worker bool GrGLCaps::onSurfaceSupportsWritePixels(const GrSurface* surface) const {
4853*c8dee2aaSAndroid Build Coastguard Worker if (fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO) {
4854*c8dee2aaSAndroid Build Coastguard Worker if (auto tex = static_cast<const GrGLTexture*>(surface->asTexture())) {
4855*c8dee2aaSAndroid Build Coastguard Worker if (tex->hasBaseLevelBeenBoundToFBO()) {
4856*c8dee2aaSAndroid Build Coastguard Worker return false;
4857*c8dee2aaSAndroid Build Coastguard Worker }
4858*c8dee2aaSAndroid Build Coastguard Worker }
4859*c8dee2aaSAndroid Build Coastguard Worker }
4860*c8dee2aaSAndroid Build Coastguard Worker if (auto rt = surface->asRenderTarget()) {
4861*c8dee2aaSAndroid Build Coastguard Worker if (fUseDrawInsteadOfAllRenderTargetWrites) {
4862*c8dee2aaSAndroid Build Coastguard Worker return false;
4863*c8dee2aaSAndroid Build Coastguard Worker }
4864*c8dee2aaSAndroid Build Coastguard Worker if (rt->numSamples() > 1 && this->usesMSAARenderBuffers()) {
4865*c8dee2aaSAndroid Build Coastguard Worker return false;
4866*c8dee2aaSAndroid Build Coastguard Worker }
4867*c8dee2aaSAndroid Build Coastguard Worker return SkToBool(surface->asTexture());
4868*c8dee2aaSAndroid Build Coastguard Worker }
4869*c8dee2aaSAndroid Build Coastguard Worker return true;
4870*c8dee2aaSAndroid Build Coastguard Worker }
4871*c8dee2aaSAndroid Build Coastguard Worker
surfaceSupportsReadPixels(const GrSurface * surface) const4872*c8dee2aaSAndroid Build Coastguard Worker GrCaps::SurfaceReadPixelsSupport GrGLCaps::surfaceSupportsReadPixels(
4873*c8dee2aaSAndroid Build Coastguard Worker const GrSurface* surface) const {
4874*c8dee2aaSAndroid Build Coastguard Worker if (surface->isProtected()) {
4875*c8dee2aaSAndroid Build Coastguard Worker return SurfaceReadPixelsSupport::kUnsupported;
4876*c8dee2aaSAndroid Build Coastguard Worker }
4877*c8dee2aaSAndroid Build Coastguard Worker if (auto tex = static_cast<const GrGLTexture*>(surface->asTexture())) {
4878*c8dee2aaSAndroid Build Coastguard Worker // We don't support reading pixels directly from EXTERNAL textures as it would require
4879*c8dee2aaSAndroid Build Coastguard Worker // binding the texture to a FBO. For now we also disallow reading back directly
4880*c8dee2aaSAndroid Build Coastguard Worker // from compressed textures.
4881*c8dee2aaSAndroid Build Coastguard Worker if (tex->target() == GR_GL_TEXTURE_EXTERNAL || GrGLFormatIsCompressed(tex->format())) {
4882*c8dee2aaSAndroid Build Coastguard Worker return SurfaceReadPixelsSupport::kCopyToTexture2D;
4883*c8dee2aaSAndroid Build Coastguard Worker }
4884*c8dee2aaSAndroid Build Coastguard Worker } else if (auto rt = static_cast<const GrGLRenderTarget*>(surface->asRenderTarget())) {
4885*c8dee2aaSAndroid Build Coastguard Worker // glReadPixels does not allow reading back from a MSAA framebuffer. If the underlying
4886*c8dee2aaSAndroid Build Coastguard Worker // GrSurface doesn't have a second FBO to resolve to then we must make a copy.
4887*c8dee2aaSAndroid Build Coastguard Worker if (rt->numSamples() > 1 && !rt->asTexture()) {
4888*c8dee2aaSAndroid Build Coastguard Worker return SurfaceReadPixelsSupport::kCopyToTexture2D;
4889*c8dee2aaSAndroid Build Coastguard Worker }
4890*c8dee2aaSAndroid Build Coastguard Worker }
4891*c8dee2aaSAndroid Build Coastguard Worker return SurfaceReadPixelsSupport::kSupported;
4892*c8dee2aaSAndroid Build Coastguard Worker }
4893*c8dee2aaSAndroid Build Coastguard Worker
offset_alignment_for_transfer_buffer(GrGLenum externalType)4894*c8dee2aaSAndroid Build Coastguard Worker size_t offset_alignment_for_transfer_buffer(GrGLenum externalType) {
4895*c8dee2aaSAndroid Build Coastguard Worker // This switch is derived from a table titled "Pixel data type parameter values and the
4896*c8dee2aaSAndroid Build Coastguard Worker // corresponding GL data types" in the OpenGL spec (Table 8.2 in OpenGL 4.5).
4897*c8dee2aaSAndroid Build Coastguard Worker switch (externalType) {
4898*c8dee2aaSAndroid Build Coastguard Worker case GR_GL_UNSIGNED_BYTE: return sizeof(GrGLubyte);
4899*c8dee2aaSAndroid Build Coastguard Worker case GR_GL_BYTE: return sizeof(GrGLbyte);
4900*c8dee2aaSAndroid Build Coastguard Worker case GR_GL_UNSIGNED_SHORT: return sizeof(GrGLushort);
4901*c8dee2aaSAndroid Build Coastguard Worker case GR_GL_SHORT: return sizeof(GrGLshort);
4902*c8dee2aaSAndroid Build Coastguard Worker case GR_GL_UNSIGNED_INT: return sizeof(GrGLuint);
4903*c8dee2aaSAndroid Build Coastguard Worker case GR_GL_INT: return sizeof(GrGLint);
4904*c8dee2aaSAndroid Build Coastguard Worker case GR_GL_HALF_FLOAT: return sizeof(GrGLhalf);
4905*c8dee2aaSAndroid Build Coastguard Worker case GR_GL_HALF_FLOAT_OES: return sizeof(GrGLhalf);
4906*c8dee2aaSAndroid Build Coastguard Worker case GR_GL_FLOAT: return sizeof(GrGLfloat);
4907*c8dee2aaSAndroid Build Coastguard Worker case GR_GL_UNSIGNED_SHORT_5_6_5: return sizeof(GrGLushort);
4908*c8dee2aaSAndroid Build Coastguard Worker case GR_GL_UNSIGNED_SHORT_4_4_4_4: return sizeof(GrGLushort);
4909*c8dee2aaSAndroid Build Coastguard Worker case GR_GL_UNSIGNED_SHORT_5_5_5_1: return sizeof(GrGLushort);
4910*c8dee2aaSAndroid Build Coastguard Worker case GR_GL_UNSIGNED_INT_2_10_10_10_REV: return sizeof(GrGLuint);
4911*c8dee2aaSAndroid Build Coastguard Worker #if 0 // GL types we currently don't use. Here for future reference.
4912*c8dee2aaSAndroid Build Coastguard Worker case GR_GL_UNSIGNED_BYTE_3_3_2: return sizeof(GrGLubyte);
4913*c8dee2aaSAndroid Build Coastguard Worker case GR_GL_UNSIGNED_BYTE_2_3_3_REV: return sizeof(GrGLubyte);
4914*c8dee2aaSAndroid Build Coastguard Worker case GR_GL_UNSIGNED_SHORT_5_6_5_REV: return sizeof(GrGLushort);
4915*c8dee2aaSAndroid Build Coastguard Worker case GR_GL_UNSIGNED_SHORT_4_4_4_4_REV: return sizeof(GrGLushort);
4916*c8dee2aaSAndroid Build Coastguard Worker case GR_GL_UNSIGNED_SHORT_1_5_5_5_REV: return sizeof(GrGLushort);
4917*c8dee2aaSAndroid Build Coastguard Worker case GR_GL_UNSIGNED_INT_8_8_8_8: return sizeof(GrGLuint);
4918*c8dee2aaSAndroid Build Coastguard Worker case GR_GL_UNSIGNED_INT_8_8_8_8_REV: return sizeof(GrGLuint);
4919*c8dee2aaSAndroid Build Coastguard Worker case GR_GL_UNSIGNED_INT_10_10_10_2: return sizeof(GrGLuint);
4920*c8dee2aaSAndroid Build Coastguard Worker case GR_GL_UNSIGNED_INT_24_8: return sizeof(GrGLuint);
4921*c8dee2aaSAndroid Build Coastguard Worker case GR_GL_UNSIGNED_INT_10F_11F_11F_REV: return sizeof(GrGLuint);
4922*c8dee2aaSAndroid Build Coastguard Worker case GR_GL_UNSIGNED_INT_5_9_9_9_REV: return sizeof(GrGLuint);
4923*c8dee2aaSAndroid Build Coastguard Worker // This one is not corresponding to a GL data type and the spec just says it is 4.
4924*c8dee2aaSAndroid Build Coastguard Worker case GR_GL_FLOAT_32_UNSIGNED_INT_24_8_REV: return 4;
4925*c8dee2aaSAndroid Build Coastguard Worker #endif
4926*c8dee2aaSAndroid Build Coastguard Worker default: return 0;
4927*c8dee2aaSAndroid Build Coastguard Worker }
4928*c8dee2aaSAndroid Build Coastguard Worker }
4929*c8dee2aaSAndroid Build Coastguard Worker
onSupportedReadPixelsColorType(GrColorType srcColorType,const GrBackendFormat & srcBackendFormat,GrColorType dstColorType) const4930*c8dee2aaSAndroid Build Coastguard Worker GrCaps::SupportedRead GrGLCaps::onSupportedReadPixelsColorType(
4931*c8dee2aaSAndroid Build Coastguard Worker GrColorType srcColorType, const GrBackendFormat& srcBackendFormat,
4932*c8dee2aaSAndroid Build Coastguard Worker GrColorType dstColorType) const {
4933*c8dee2aaSAndroid Build Coastguard Worker
4934*c8dee2aaSAndroid Build Coastguard Worker SkTextureCompressionType compression = GrBackendFormatToCompressionType(srcBackendFormat);
4935*c8dee2aaSAndroid Build Coastguard Worker if (compression != SkTextureCompressionType::kNone) {
4936*c8dee2aaSAndroid Build Coastguard Worker return {SkTextureCompressionTypeIsOpaque(compression) ? GrColorType::kRGB_888x
4937*c8dee2aaSAndroid Build Coastguard Worker : GrColorType::kRGBA_8888,
4938*c8dee2aaSAndroid Build Coastguard Worker 0};
4939*c8dee2aaSAndroid Build Coastguard Worker }
4940*c8dee2aaSAndroid Build Coastguard Worker
4941*c8dee2aaSAndroid Build Coastguard Worker // We first try to find a supported read pixels GrColorType that matches the requested
4942*c8dee2aaSAndroid Build Coastguard Worker // dstColorType. If that doesn't exists we will use any valid read pixels GrColorType.
4943*c8dee2aaSAndroid Build Coastguard Worker GrCaps::SupportedRead fallbackRead = {GrColorType::kUnknown, 0};
4944*c8dee2aaSAndroid Build Coastguard Worker const auto& formatInfo = this->getFormatInfo(GrBackendFormats::AsGLFormat(srcBackendFormat));
4945*c8dee2aaSAndroid Build Coastguard Worker bool foundSrcCT = false;
4946*c8dee2aaSAndroid Build Coastguard Worker for (int i = 0; !foundSrcCT && i < formatInfo.fColorTypeInfoCount; ++i) {
4947*c8dee2aaSAndroid Build Coastguard Worker if (formatInfo.fColorTypeInfos[i].fColorType == srcColorType) {
4948*c8dee2aaSAndroid Build Coastguard Worker const ColorTypeInfo& ctInfo = formatInfo.fColorTypeInfos[i];
4949*c8dee2aaSAndroid Build Coastguard Worker foundSrcCT = true;
4950*c8dee2aaSAndroid Build Coastguard Worker for (int j = 0; j < ctInfo.fExternalIOFormatCount; ++j) {
4951*c8dee2aaSAndroid Build Coastguard Worker const auto& ioInfo = ctInfo.fExternalIOFormats[j];
4952*c8dee2aaSAndroid Build Coastguard Worker if (ioInfo.fExternalReadFormat != 0) {
4953*c8dee2aaSAndroid Build Coastguard Worker if (formatInfo.fHaveQueriedImplementationReadSupport ||
4954*c8dee2aaSAndroid Build Coastguard Worker !ioInfo.fRequiresImplementationReadQuery) {
4955*c8dee2aaSAndroid Build Coastguard Worker GrGLenum transferOffsetAlignment = 0;
4956*c8dee2aaSAndroid Build Coastguard Worker if (formatInfo.fFlags & FormatInfo::kTransfers_Flag) {
4957*c8dee2aaSAndroid Build Coastguard Worker transferOffsetAlignment =
4958*c8dee2aaSAndroid Build Coastguard Worker offset_alignment_for_transfer_buffer(ioInfo.fExternalType);
4959*c8dee2aaSAndroid Build Coastguard Worker if (dstColorType == GrColorType::kRG_88 && fPadRG88TransferAlignment) {
4960*c8dee2aaSAndroid Build Coastguard Worker transferOffsetAlignment = 2;
4961*c8dee2aaSAndroid Build Coastguard Worker }
4962*c8dee2aaSAndroid Build Coastguard Worker }
4963*c8dee2aaSAndroid Build Coastguard Worker if (ioInfo.fColorType == dstColorType) {
4964*c8dee2aaSAndroid Build Coastguard Worker return {dstColorType, transferOffsetAlignment};
4965*c8dee2aaSAndroid Build Coastguard Worker }
4966*c8dee2aaSAndroid Build Coastguard Worker // Currently we just pick the first supported format that we find as our
4967*c8dee2aaSAndroid Build Coastguard Worker // fallback.
4968*c8dee2aaSAndroid Build Coastguard Worker if (fallbackRead.fColorType == GrColorType::kUnknown) {
4969*c8dee2aaSAndroid Build Coastguard Worker fallbackRead = {ioInfo.fColorType, transferOffsetAlignment};
4970*c8dee2aaSAndroid Build Coastguard Worker }
4971*c8dee2aaSAndroid Build Coastguard Worker }
4972*c8dee2aaSAndroid Build Coastguard Worker }
4973*c8dee2aaSAndroid Build Coastguard Worker }
4974*c8dee2aaSAndroid Build Coastguard Worker }
4975*c8dee2aaSAndroid Build Coastguard Worker }
4976*c8dee2aaSAndroid Build Coastguard Worker return fallbackRead;
4977*c8dee2aaSAndroid Build Coastguard Worker }
4978*c8dee2aaSAndroid Build Coastguard Worker
supportedWritePixelsColorType(GrColorType surfaceColorType,const GrBackendFormat & surfaceFormat,GrColorType srcColorType) const4979*c8dee2aaSAndroid Build Coastguard Worker GrCaps::SupportedWrite GrGLCaps::supportedWritePixelsColorType(GrColorType surfaceColorType,
4980*c8dee2aaSAndroid Build Coastguard Worker const GrBackendFormat& surfaceFormat,
4981*c8dee2aaSAndroid Build Coastguard Worker GrColorType srcColorType) const {
4982*c8dee2aaSAndroid Build Coastguard Worker // We first try to find a supported write pixels GrColorType that matches the data's
4983*c8dee2aaSAndroid Build Coastguard Worker // srcColorType. If that doesn't exists we will use any supported GrColorType.
4984*c8dee2aaSAndroid Build Coastguard Worker GrColorType fallbackCT = GrColorType::kUnknown;
4985*c8dee2aaSAndroid Build Coastguard Worker const auto& formatInfo = this->getFormatInfo(GrBackendFormats::AsGLFormat(surfaceFormat));
4986*c8dee2aaSAndroid Build Coastguard Worker bool foundSurfaceCT = false;
4987*c8dee2aaSAndroid Build Coastguard Worker size_t transferOffsetAlignment = 0;
4988*c8dee2aaSAndroid Build Coastguard Worker if (formatInfo.fFlags & FormatInfo::kTransfers_Flag) {
4989*c8dee2aaSAndroid Build Coastguard Worker transferOffsetAlignment = 1;
4990*c8dee2aaSAndroid Build Coastguard Worker }
4991*c8dee2aaSAndroid Build Coastguard Worker for (int i = 0; !foundSurfaceCT && i < formatInfo.fColorTypeInfoCount; ++i) {
4992*c8dee2aaSAndroid Build Coastguard Worker if (formatInfo.fColorTypeInfos[i].fColorType == surfaceColorType) {
4993*c8dee2aaSAndroid Build Coastguard Worker const ColorTypeInfo& ctInfo = formatInfo.fColorTypeInfos[i];
4994*c8dee2aaSAndroid Build Coastguard Worker foundSurfaceCT = true;
4995*c8dee2aaSAndroid Build Coastguard Worker for (int j = 0; j < ctInfo.fExternalIOFormatCount; ++j) {
4996*c8dee2aaSAndroid Build Coastguard Worker const auto& ioInfo = ctInfo.fExternalIOFormats[j];
4997*c8dee2aaSAndroid Build Coastguard Worker if (ioInfo.fExternalTexImageFormat != 0) {
4998*c8dee2aaSAndroid Build Coastguard Worker if (ioInfo.fColorType == srcColorType) {
4999*c8dee2aaSAndroid Build Coastguard Worker return {srcColorType, transferOffsetAlignment};
5000*c8dee2aaSAndroid Build Coastguard Worker }
5001*c8dee2aaSAndroid Build Coastguard Worker // Currently we just pick the first supported format that we find as our
5002*c8dee2aaSAndroid Build Coastguard Worker // fallback.
5003*c8dee2aaSAndroid Build Coastguard Worker if (fallbackCT == GrColorType::kUnknown) {
5004*c8dee2aaSAndroid Build Coastguard Worker fallbackCT = ioInfo.fColorType;
5005*c8dee2aaSAndroid Build Coastguard Worker }
5006*c8dee2aaSAndroid Build Coastguard Worker }
5007*c8dee2aaSAndroid Build Coastguard Worker }
5008*c8dee2aaSAndroid Build Coastguard Worker }
5009*c8dee2aaSAndroid Build Coastguard Worker }
5010*c8dee2aaSAndroid Build Coastguard Worker return {fallbackCT, transferOffsetAlignment};
5011*c8dee2aaSAndroid Build Coastguard Worker }
5012*c8dee2aaSAndroid Build Coastguard Worker
programBinaryFormatIsValid(GrGLenum binaryFormat) const5013*c8dee2aaSAndroid Build Coastguard Worker bool GrGLCaps::programBinaryFormatIsValid(GrGLenum binaryFormat) const {
5014*c8dee2aaSAndroid Build Coastguard Worker return std::find(fProgramBinaryFormats.begin(), fProgramBinaryFormats.end(), binaryFormat) !=
5015*c8dee2aaSAndroid Build Coastguard Worker fProgramBinaryFormats.end();
5016*c8dee2aaSAndroid Build Coastguard Worker }
5017*c8dee2aaSAndroid Build Coastguard Worker
onIsWindowRectanglesSupportedForRT(const GrBackendRenderTarget & backendRT) const5018*c8dee2aaSAndroid Build Coastguard Worker bool GrGLCaps::onIsWindowRectanglesSupportedForRT(const GrBackendRenderTarget& backendRT) const {
5019*c8dee2aaSAndroid Build Coastguard Worker GrGLFramebufferInfo fbInfo;
5020*c8dee2aaSAndroid Build Coastguard Worker SkAssertResult(GrBackendRenderTargets::GetGLFramebufferInfo(backendRT, &fbInfo));
5021*c8dee2aaSAndroid Build Coastguard Worker // Window Rectangles are not supported for FBO 0;
5022*c8dee2aaSAndroid Build Coastguard Worker return fbInfo.fFBOID != 0;
5023*c8dee2aaSAndroid Build Coastguard Worker }
5024*c8dee2aaSAndroid Build Coastguard Worker
isFormatSRGB(const GrBackendFormat & format) const5025*c8dee2aaSAndroid Build Coastguard Worker bool GrGLCaps::isFormatSRGB(const GrBackendFormat& format) const {
5026*c8dee2aaSAndroid Build Coastguard Worker return GrBackendFormats::AsGLFormat(format) == GrGLFormat::kSRGB8_ALPHA8;
5027*c8dee2aaSAndroid Build Coastguard Worker }
5028*c8dee2aaSAndroid Build Coastguard Worker
isFormatTexturable(const GrBackendFormat & format,GrTextureType textureType) const5029*c8dee2aaSAndroid Build Coastguard Worker bool GrGLCaps::isFormatTexturable(const GrBackendFormat& format, GrTextureType textureType) const {
5030*c8dee2aaSAndroid Build Coastguard Worker if (textureType == GrTextureType::kRectangle && !this->rectangleTextureSupport()) {
5031*c8dee2aaSAndroid Build Coastguard Worker return false;
5032*c8dee2aaSAndroid Build Coastguard Worker }
5033*c8dee2aaSAndroid Build Coastguard Worker return this->isFormatTexturable(GrBackendFormats::AsGLFormat(format));
5034*c8dee2aaSAndroid Build Coastguard Worker }
5035*c8dee2aaSAndroid Build Coastguard Worker
isFormatTexturable(GrGLFormat format) const5036*c8dee2aaSAndroid Build Coastguard Worker bool GrGLCaps::isFormatTexturable(GrGLFormat format) const {
5037*c8dee2aaSAndroid Build Coastguard Worker const FormatInfo& info = this->getFormatInfo(format);
5038*c8dee2aaSAndroid Build Coastguard Worker return SkToBool(info.fFlags & FormatInfo::kTexturable_Flag);
5039*c8dee2aaSAndroid Build Coastguard Worker }
5040*c8dee2aaSAndroid Build Coastguard Worker
isFormatAsColorTypeRenderable(GrColorType ct,const GrBackendFormat & format,int sampleCount) const5041*c8dee2aaSAndroid Build Coastguard Worker bool GrGLCaps::isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat& format,
5042*c8dee2aaSAndroid Build Coastguard Worker int sampleCount) const {
5043*c8dee2aaSAndroid Build Coastguard Worker if (format.textureType() == GrTextureType::kRectangle && !this->rectangleTextureSupport()) {
5044*c8dee2aaSAndroid Build Coastguard Worker return false;
5045*c8dee2aaSAndroid Build Coastguard Worker }
5046*c8dee2aaSAndroid Build Coastguard Worker if (format.textureType() == GrTextureType::kExternal) {
5047*c8dee2aaSAndroid Build Coastguard Worker return false;
5048*c8dee2aaSAndroid Build Coastguard Worker }
5049*c8dee2aaSAndroid Build Coastguard Worker auto f = GrBackendFormats::AsGLFormat(format);
5050*c8dee2aaSAndroid Build Coastguard Worker const FormatInfo& info = this->getFormatInfo(f);
5051*c8dee2aaSAndroid Build Coastguard Worker if (!SkToBool(info.colorTypeFlags(ct) & ColorTypeInfo::kRenderable_Flag)) {
5052*c8dee2aaSAndroid Build Coastguard Worker return false;
5053*c8dee2aaSAndroid Build Coastguard Worker }
5054*c8dee2aaSAndroid Build Coastguard Worker
5055*c8dee2aaSAndroid Build Coastguard Worker return this->isFormatRenderable(f, sampleCount);
5056*c8dee2aaSAndroid Build Coastguard Worker }
5057*c8dee2aaSAndroid Build Coastguard Worker
isFormatRenderable(const GrBackendFormat & format,int sampleCount) const5058*c8dee2aaSAndroid Build Coastguard Worker bool GrGLCaps::isFormatRenderable(const GrBackendFormat& format, int sampleCount) const {
5059*c8dee2aaSAndroid Build Coastguard Worker if (format.textureType() == GrTextureType::kRectangle && !this->rectangleTextureSupport()) {
5060*c8dee2aaSAndroid Build Coastguard Worker return false;
5061*c8dee2aaSAndroid Build Coastguard Worker }
5062*c8dee2aaSAndroid Build Coastguard Worker if (format.textureType() == GrTextureType::kExternal) {
5063*c8dee2aaSAndroid Build Coastguard Worker return false;
5064*c8dee2aaSAndroid Build Coastguard Worker }
5065*c8dee2aaSAndroid Build Coastguard Worker return this->isFormatRenderable(GrBackendFormats::AsGLFormat(format), sampleCount);
5066*c8dee2aaSAndroid Build Coastguard Worker }
5067*c8dee2aaSAndroid Build Coastguard Worker
getRenderTargetSampleCount(int requestedCount,GrGLFormat format) const5068*c8dee2aaSAndroid Build Coastguard Worker int GrGLCaps::getRenderTargetSampleCount(int requestedCount, GrGLFormat format) const {
5069*c8dee2aaSAndroid Build Coastguard Worker const FormatInfo& info = this->getFormatInfo(format);
5070*c8dee2aaSAndroid Build Coastguard Worker
5071*c8dee2aaSAndroid Build Coastguard Worker int count = info.fColorSampleCounts.size();
5072*c8dee2aaSAndroid Build Coastguard Worker if (!count) {
5073*c8dee2aaSAndroid Build Coastguard Worker return 0;
5074*c8dee2aaSAndroid Build Coastguard Worker }
5075*c8dee2aaSAndroid Build Coastguard Worker
5076*c8dee2aaSAndroid Build Coastguard Worker requestedCount = std::max(1, requestedCount);
5077*c8dee2aaSAndroid Build Coastguard Worker if (1 == requestedCount) {
5078*c8dee2aaSAndroid Build Coastguard Worker return info.fColorSampleCounts[0] == 1 ? 1 : 0;
5079*c8dee2aaSAndroid Build Coastguard Worker }
5080*c8dee2aaSAndroid Build Coastguard Worker
5081*c8dee2aaSAndroid Build Coastguard Worker for (int sampleCount : info.fColorSampleCounts) {
5082*c8dee2aaSAndroid Build Coastguard Worker if (sampleCount >= requestedCount) {
5083*c8dee2aaSAndroid Build Coastguard Worker if (fDriverBugWorkarounds.max_msaa_sample_count_4) {
5084*c8dee2aaSAndroid Build Coastguard Worker sampleCount = std::min(sampleCount, 4);
5085*c8dee2aaSAndroid Build Coastguard Worker }
5086*c8dee2aaSAndroid Build Coastguard Worker return sampleCount;
5087*c8dee2aaSAndroid Build Coastguard Worker }
5088*c8dee2aaSAndroid Build Coastguard Worker }
5089*c8dee2aaSAndroid Build Coastguard Worker return 0;
5090*c8dee2aaSAndroid Build Coastguard Worker }
5091*c8dee2aaSAndroid Build Coastguard Worker
maxRenderTargetSampleCount(GrGLFormat format) const5092*c8dee2aaSAndroid Build Coastguard Worker int GrGLCaps::maxRenderTargetSampleCount(GrGLFormat format) const {
5093*c8dee2aaSAndroid Build Coastguard Worker const FormatInfo& info = this->getFormatInfo(format);
5094*c8dee2aaSAndroid Build Coastguard Worker const auto& table = info.fColorSampleCounts;
5095*c8dee2aaSAndroid Build Coastguard Worker if (table.empty()) {
5096*c8dee2aaSAndroid Build Coastguard Worker return 0;
5097*c8dee2aaSAndroid Build Coastguard Worker }
5098*c8dee2aaSAndroid Build Coastguard Worker int count = table[table.size() - 1];
5099*c8dee2aaSAndroid Build Coastguard Worker if (fDriverBugWorkarounds.max_msaa_sample_count_4) {
5100*c8dee2aaSAndroid Build Coastguard Worker count = std::min(count, 4);
5101*c8dee2aaSAndroid Build Coastguard Worker }
5102*c8dee2aaSAndroid Build Coastguard Worker return count;
5103*c8dee2aaSAndroid Build Coastguard Worker }
5104*c8dee2aaSAndroid Build Coastguard Worker
canFormatBeFBOColorAttachment(GrGLFormat format) const5105*c8dee2aaSAndroid Build Coastguard Worker bool GrGLCaps::canFormatBeFBOColorAttachment(GrGLFormat format) const {
5106*c8dee2aaSAndroid Build Coastguard Worker return SkToBool(this->getFormatInfo(format).fFlags & FormatInfo::kFBOColorAttachment_Flag);
5107*c8dee2aaSAndroid Build Coastguard Worker }
5108*c8dee2aaSAndroid Build Coastguard Worker
isFormatCopyable(const GrBackendFormat & format) const5109*c8dee2aaSAndroid Build Coastguard Worker bool GrGLCaps::isFormatCopyable(const GrBackendFormat& format) const {
5110*c8dee2aaSAndroid Build Coastguard Worker // In GL we have three ways to be able to copy. CopyTexImage, blit, and draw. CopyTexImage
5111*c8dee2aaSAndroid Build Coastguard Worker // requires the src to be an FBO attachment, blit requires both src and dst to be FBO
5112*c8dee2aaSAndroid Build Coastguard Worker // attachments, and draw requires the dst to be an FBO attachment. Thus to copy from and to
5113*c8dee2aaSAndroid Build Coastguard Worker // the same config, we need that config to be bindable to an FBO.
5114*c8dee2aaSAndroid Build Coastguard Worker return this->canFormatBeFBOColorAttachment(GrBackendFormats::AsGLFormat(format));
5115*c8dee2aaSAndroid Build Coastguard Worker }
5116*c8dee2aaSAndroid Build Coastguard Worker
formatSupportsTexStorage(GrGLFormat format) const5117*c8dee2aaSAndroid Build Coastguard Worker bool GrGLCaps::formatSupportsTexStorage(GrGLFormat format) const {
5118*c8dee2aaSAndroid Build Coastguard Worker return SkToBool(this->getFormatInfo(format).fFlags & FormatInfo::kUseTexStorage_Flag);
5119*c8dee2aaSAndroid Build Coastguard Worker }
5120*c8dee2aaSAndroid Build Coastguard Worker
shouldQueryImplementationReadSupport(GrGLFormat format) const5121*c8dee2aaSAndroid Build Coastguard Worker bool GrGLCaps::shouldQueryImplementationReadSupport(GrGLFormat format) const {
5122*c8dee2aaSAndroid Build Coastguard Worker const auto& formatInfo = const_cast<GrGLCaps*>(this)->getFormatInfo(format);
5123*c8dee2aaSAndroid Build Coastguard Worker if (!formatInfo.fHaveQueriedImplementationReadSupport) {
5124*c8dee2aaSAndroid Build Coastguard Worker // Check whether we will actually learn anything useful.
5125*c8dee2aaSAndroid Build Coastguard Worker bool needQuery = false;
5126*c8dee2aaSAndroid Build Coastguard Worker for (int i = 0; i < formatInfo.fColorTypeInfoCount && !needQuery; ++i) {
5127*c8dee2aaSAndroid Build Coastguard Worker const auto& surfCTInfo = formatInfo.fColorTypeInfos[i];
5128*c8dee2aaSAndroid Build Coastguard Worker for (int j = 0; j < surfCTInfo.fExternalIOFormatCount; ++j) {
5129*c8dee2aaSAndroid Build Coastguard Worker if (surfCTInfo.fExternalIOFormats[j].fRequiresImplementationReadQuery) {
5130*c8dee2aaSAndroid Build Coastguard Worker needQuery = true;
5131*c8dee2aaSAndroid Build Coastguard Worker break;
5132*c8dee2aaSAndroid Build Coastguard Worker }
5133*c8dee2aaSAndroid Build Coastguard Worker }
5134*c8dee2aaSAndroid Build Coastguard Worker }
5135*c8dee2aaSAndroid Build Coastguard Worker if (!needQuery) {
5136*c8dee2aaSAndroid Build Coastguard Worker // Pretend we already checked it.
5137*c8dee2aaSAndroid Build Coastguard Worker const_cast<FormatInfo&>(formatInfo).fHaveQueriedImplementationReadSupport = true;
5138*c8dee2aaSAndroid Build Coastguard Worker }
5139*c8dee2aaSAndroid Build Coastguard Worker }
5140*c8dee2aaSAndroid Build Coastguard Worker return !formatInfo.fHaveQueriedImplementationReadSupport;
5141*c8dee2aaSAndroid Build Coastguard Worker }
5142*c8dee2aaSAndroid Build Coastguard Worker
didQueryImplementationReadSupport(GrGLFormat format,GrGLenum readFormat,GrGLenum readType) const5143*c8dee2aaSAndroid Build Coastguard Worker void GrGLCaps::didQueryImplementationReadSupport(GrGLFormat format,
5144*c8dee2aaSAndroid Build Coastguard Worker GrGLenum readFormat,
5145*c8dee2aaSAndroid Build Coastguard Worker GrGLenum readType) const {
5146*c8dee2aaSAndroid Build Coastguard Worker auto& formatInfo = const_cast<GrGLCaps*>(this)->getFormatInfo(format);
5147*c8dee2aaSAndroid Build Coastguard Worker for (int i = 0; i < formatInfo.fColorTypeInfoCount; ++i) {
5148*c8dee2aaSAndroid Build Coastguard Worker auto& surfCTInfo = formatInfo.fColorTypeInfos[i];
5149*c8dee2aaSAndroid Build Coastguard Worker for (int j = 0; j < surfCTInfo.fExternalIOFormatCount; ++j) {
5150*c8dee2aaSAndroid Build Coastguard Worker auto& readCTInfo = surfCTInfo.fExternalIOFormats[j];
5151*c8dee2aaSAndroid Build Coastguard Worker if (readCTInfo.fRequiresImplementationReadQuery) {
5152*c8dee2aaSAndroid Build Coastguard Worker if (readCTInfo.fExternalReadFormat != readFormat ||
5153*c8dee2aaSAndroid Build Coastguard Worker readCTInfo.fExternalType != readType) {
5154*c8dee2aaSAndroid Build Coastguard Worker // Don't zero out fExternalType. It's also used for writing data to the texture!
5155*c8dee2aaSAndroid Build Coastguard Worker readCTInfo.fExternalReadFormat = 0;
5156*c8dee2aaSAndroid Build Coastguard Worker }
5157*c8dee2aaSAndroid Build Coastguard Worker }
5158*c8dee2aaSAndroid Build Coastguard Worker }
5159*c8dee2aaSAndroid Build Coastguard Worker }
5160*c8dee2aaSAndroid Build Coastguard Worker formatInfo.fHaveQueriedImplementationReadSupport = true;
5161*c8dee2aaSAndroid Build Coastguard Worker }
5162*c8dee2aaSAndroid Build Coastguard Worker
onAreColorTypeAndFormatCompatible(GrColorType ct,const GrBackendFormat & format) const5163*c8dee2aaSAndroid Build Coastguard Worker bool GrGLCaps::onAreColorTypeAndFormatCompatible(GrColorType ct,
5164*c8dee2aaSAndroid Build Coastguard Worker const GrBackendFormat& format) const {
5165*c8dee2aaSAndroid Build Coastguard Worker GrGLFormat glFormat = GrBackendFormats::AsGLFormat(format);
5166*c8dee2aaSAndroid Build Coastguard Worker const auto& info = this->getFormatInfo(glFormat);
5167*c8dee2aaSAndroid Build Coastguard Worker for (int i = 0; i < info.fColorTypeInfoCount; ++i) {
5168*c8dee2aaSAndroid Build Coastguard Worker if (info.fColorTypeInfos[i].fColorType == ct) {
5169*c8dee2aaSAndroid Build Coastguard Worker return true;
5170*c8dee2aaSAndroid Build Coastguard Worker }
5171*c8dee2aaSAndroid Build Coastguard Worker }
5172*c8dee2aaSAndroid Build Coastguard Worker return false;
5173*c8dee2aaSAndroid Build Coastguard Worker }
5174*c8dee2aaSAndroid Build Coastguard Worker
onGetDefaultBackendFormat(GrColorType ct) const5175*c8dee2aaSAndroid Build Coastguard Worker GrBackendFormat GrGLCaps::onGetDefaultBackendFormat(GrColorType ct) const {
5176*c8dee2aaSAndroid Build Coastguard Worker auto format = this->getFormatFromColorType(ct);
5177*c8dee2aaSAndroid Build Coastguard Worker if (format == GrGLFormat::kUnknown) {
5178*c8dee2aaSAndroid Build Coastguard Worker return {};
5179*c8dee2aaSAndroid Build Coastguard Worker }
5180*c8dee2aaSAndroid Build Coastguard Worker return GrBackendFormats::MakeGL(GrGLFormatToEnum(format), GR_GL_TEXTURE_2D);
5181*c8dee2aaSAndroid Build Coastguard Worker }
5182*c8dee2aaSAndroid Build Coastguard Worker
getBackendFormatFromCompressionType(SkTextureCompressionType compressionType) const5183*c8dee2aaSAndroid Build Coastguard Worker GrBackendFormat GrGLCaps::getBackendFormatFromCompressionType(
5184*c8dee2aaSAndroid Build Coastguard Worker SkTextureCompressionType compressionType) const {
5185*c8dee2aaSAndroid Build Coastguard Worker switch (compressionType) {
5186*c8dee2aaSAndroid Build Coastguard Worker case SkTextureCompressionType::kNone:
5187*c8dee2aaSAndroid Build Coastguard Worker return {};
5188*c8dee2aaSAndroid Build Coastguard Worker case SkTextureCompressionType::kETC2_RGB8_UNORM:
5189*c8dee2aaSAndroid Build Coastguard Worker // if ETC2 is available default to that format
5190*c8dee2aaSAndroid Build Coastguard Worker if (this->isFormatTexturable(GrGLFormat::kCOMPRESSED_RGB8_ETC2)) {
5191*c8dee2aaSAndroid Build Coastguard Worker return GrBackendFormats::MakeGL(GR_GL_COMPRESSED_RGB8_ETC2, GR_GL_TEXTURE_2D);
5192*c8dee2aaSAndroid Build Coastguard Worker }
5193*c8dee2aaSAndroid Build Coastguard Worker if (this->isFormatTexturable(GrGLFormat::kCOMPRESSED_ETC1_RGB8)) {
5194*c8dee2aaSAndroid Build Coastguard Worker return GrBackendFormats::MakeGL(GR_GL_COMPRESSED_ETC1_RGB8, GR_GL_TEXTURE_2D);
5195*c8dee2aaSAndroid Build Coastguard Worker }
5196*c8dee2aaSAndroid Build Coastguard Worker return {};
5197*c8dee2aaSAndroid Build Coastguard Worker case SkTextureCompressionType::kBC1_RGB8_UNORM:
5198*c8dee2aaSAndroid Build Coastguard Worker if (this->isFormatTexturable(GrGLFormat::kCOMPRESSED_RGB8_BC1)) {
5199*c8dee2aaSAndroid Build Coastguard Worker return GrBackendFormats::MakeGL(GR_GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
5200*c8dee2aaSAndroid Build Coastguard Worker GR_GL_TEXTURE_2D);
5201*c8dee2aaSAndroid Build Coastguard Worker }
5202*c8dee2aaSAndroid Build Coastguard Worker return {};
5203*c8dee2aaSAndroid Build Coastguard Worker case SkTextureCompressionType::kBC1_RGBA8_UNORM:
5204*c8dee2aaSAndroid Build Coastguard Worker if (this->isFormatTexturable(GrGLFormat::kCOMPRESSED_RGBA8_BC1)) {
5205*c8dee2aaSAndroid Build Coastguard Worker return GrBackendFormats::MakeGL(GR_GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
5206*c8dee2aaSAndroid Build Coastguard Worker GR_GL_TEXTURE_2D);
5207*c8dee2aaSAndroid Build Coastguard Worker }
5208*c8dee2aaSAndroid Build Coastguard Worker return {};
5209*c8dee2aaSAndroid Build Coastguard Worker }
5210*c8dee2aaSAndroid Build Coastguard Worker
5211*c8dee2aaSAndroid Build Coastguard Worker SkUNREACHABLE;
5212*c8dee2aaSAndroid Build Coastguard Worker }
5213*c8dee2aaSAndroid Build Coastguard Worker
onGetReadSwizzle(const GrBackendFormat & format,GrColorType colorType) const5214*c8dee2aaSAndroid Build Coastguard Worker skgpu::Swizzle GrGLCaps::onGetReadSwizzle(const GrBackendFormat& format,
5215*c8dee2aaSAndroid Build Coastguard Worker GrColorType colorType) const {
5216*c8dee2aaSAndroid Build Coastguard Worker GrGLFormat glFormat = GrBackendFormats::AsGLFormat(format);
5217*c8dee2aaSAndroid Build Coastguard Worker const auto& info = this->getFormatInfo(glFormat);
5218*c8dee2aaSAndroid Build Coastguard Worker for (int i = 0; i < info.fColorTypeInfoCount; ++i) {
5219*c8dee2aaSAndroid Build Coastguard Worker const auto& ctInfo = info.fColorTypeInfos[i];
5220*c8dee2aaSAndroid Build Coastguard Worker if (ctInfo.fColorType == colorType) {
5221*c8dee2aaSAndroid Build Coastguard Worker return ctInfo.fReadSwizzle;
5222*c8dee2aaSAndroid Build Coastguard Worker }
5223*c8dee2aaSAndroid Build Coastguard Worker }
5224*c8dee2aaSAndroid Build Coastguard Worker SkDEBUGFAILF("Illegal color type (%d) and format (%d) combination.",
5225*c8dee2aaSAndroid Build Coastguard Worker (int)colorType, (int)glFormat);
5226*c8dee2aaSAndroid Build Coastguard Worker return {};
5227*c8dee2aaSAndroid Build Coastguard Worker }
5228*c8dee2aaSAndroid Build Coastguard Worker
getWriteSwizzle(const GrBackendFormat & format,GrColorType colorType) const5229*c8dee2aaSAndroid Build Coastguard Worker skgpu::Swizzle GrGLCaps::getWriteSwizzle(const GrBackendFormat& format,
5230*c8dee2aaSAndroid Build Coastguard Worker GrColorType colorType) const {
5231*c8dee2aaSAndroid Build Coastguard Worker const auto& info = this->getFormatInfo(GrBackendFormats::AsGLFormat(format));
5232*c8dee2aaSAndroid Build Coastguard Worker for (int i = 0; i < info.fColorTypeInfoCount; ++i) {
5233*c8dee2aaSAndroid Build Coastguard Worker const auto& ctInfo = info.fColorTypeInfos[i];
5234*c8dee2aaSAndroid Build Coastguard Worker if (ctInfo.fColorType == colorType) {
5235*c8dee2aaSAndroid Build Coastguard Worker return ctInfo.fWriteSwizzle;
5236*c8dee2aaSAndroid Build Coastguard Worker }
5237*c8dee2aaSAndroid Build Coastguard Worker }
5238*c8dee2aaSAndroid Build Coastguard Worker SkDEBUGFAILF("Illegal color type (%d) and format (%d) combination.",
5239*c8dee2aaSAndroid Build Coastguard Worker (int)colorType,
5240*c8dee2aaSAndroid Build Coastguard Worker (int)GrBackendFormats::AsGLFormat(format));
5241*c8dee2aaSAndroid Build Coastguard Worker return {};
5242*c8dee2aaSAndroid Build Coastguard Worker }
5243*c8dee2aaSAndroid Build Coastguard Worker
onGetDstSampleFlagsForProxy(const GrRenderTargetProxy * rt) const5244*c8dee2aaSAndroid Build Coastguard Worker GrDstSampleFlags GrGLCaps::onGetDstSampleFlagsForProxy(const GrRenderTargetProxy* rt) const {
5245*c8dee2aaSAndroid Build Coastguard Worker if (rt->asTextureProxy()) {
5246*c8dee2aaSAndroid Build Coastguard Worker return GrDstSampleFlags::kRequiresTextureBarrier;
5247*c8dee2aaSAndroid Build Coastguard Worker }
5248*c8dee2aaSAndroid Build Coastguard Worker return GrDstSampleFlags::kNone;
5249*c8dee2aaSAndroid Build Coastguard Worker }
5250*c8dee2aaSAndroid Build Coastguard Worker
onSupportsDynamicMSAA(const GrRenderTargetProxy * rtProxy) const5251*c8dee2aaSAndroid Build Coastguard Worker bool GrGLCaps::onSupportsDynamicMSAA(const GrRenderTargetProxy* rtProxy) const {
5252*c8dee2aaSAndroid Build Coastguard Worker return !fDisallowDynamicMSAA;
5253*c8dee2aaSAndroid Build Coastguard Worker }
5254*c8dee2aaSAndroid Build Coastguard Worker
computeFormatKey(const GrBackendFormat & format) const5255*c8dee2aaSAndroid Build Coastguard Worker uint64_t GrGLCaps::computeFormatKey(const GrBackendFormat& format) const {
5256*c8dee2aaSAndroid Build Coastguard Worker auto glFormat = GrBackendFormats::AsGLFormat(format);
5257*c8dee2aaSAndroid Build Coastguard Worker return (uint64_t)(glFormat);
5258*c8dee2aaSAndroid Build Coastguard Worker }
5259*c8dee2aaSAndroid Build Coastguard Worker
makeDesc(GrRenderTarget *,const GrProgramInfo & programInfo,ProgramDescOverrideFlags overrideFlags) const5260*c8dee2aaSAndroid Build Coastguard Worker GrProgramDesc GrGLCaps::makeDesc(GrRenderTarget* /* rt */,
5261*c8dee2aaSAndroid Build Coastguard Worker const GrProgramInfo& programInfo,
5262*c8dee2aaSAndroid Build Coastguard Worker ProgramDescOverrideFlags overrideFlags) const {
5263*c8dee2aaSAndroid Build Coastguard Worker SkASSERT(overrideFlags == ProgramDescOverrideFlags::kNone);
5264*c8dee2aaSAndroid Build Coastguard Worker GrProgramDesc desc;
5265*c8dee2aaSAndroid Build Coastguard Worker GrProgramDesc::Build(&desc, programInfo, *this);
5266*c8dee2aaSAndroid Build Coastguard Worker return desc;
5267*c8dee2aaSAndroid Build Coastguard Worker }
5268*c8dee2aaSAndroid Build Coastguard Worker
5269*c8dee2aaSAndroid Build Coastguard Worker #if defined(GPU_TEST_UTILS)
getTestingCombinations() const5270*c8dee2aaSAndroid Build Coastguard Worker std::vector<GrTest::TestFormatColorTypeCombination> GrGLCaps::getTestingCombinations() const {
5271*c8dee2aaSAndroid Build Coastguard Worker std::vector<GrTest::TestFormatColorTypeCombination> combos = {
5272*c8dee2aaSAndroid Build Coastguard Worker { GrColorType::kAlpha_8,
5273*c8dee2aaSAndroid Build Coastguard Worker GrBackendFormats::MakeGL(GR_GL_ALPHA8, GR_GL_TEXTURE_2D) },
5274*c8dee2aaSAndroid Build Coastguard Worker { GrColorType::kAlpha_8,
5275*c8dee2aaSAndroid Build Coastguard Worker GrBackendFormats::MakeGL(GR_GL_R8, GR_GL_TEXTURE_2D) },
5276*c8dee2aaSAndroid Build Coastguard Worker { GrColorType::kBGR_565,
5277*c8dee2aaSAndroid Build Coastguard Worker GrBackendFormats::MakeGL(GR_GL_RGB565, GR_GL_TEXTURE_2D) },
5278*c8dee2aaSAndroid Build Coastguard Worker { GrColorType::kABGR_4444,
5279*c8dee2aaSAndroid Build Coastguard Worker GrBackendFormats::MakeGL(GR_GL_RGBA4, GR_GL_TEXTURE_2D) },
5280*c8dee2aaSAndroid Build Coastguard Worker { GrColorType::kRGBA_8888,
5281*c8dee2aaSAndroid Build Coastguard Worker GrBackendFormats::MakeGL(GR_GL_RGBA8, GR_GL_TEXTURE_2D) },
5282*c8dee2aaSAndroid Build Coastguard Worker { GrColorType::kRGBA_8888_SRGB,
5283*c8dee2aaSAndroid Build Coastguard Worker GrBackendFormats::MakeGL(GR_GL_SRGB8_ALPHA8, GR_GL_TEXTURE_2D) },
5284*c8dee2aaSAndroid Build Coastguard Worker { GrColorType::kRGB_888x,
5285*c8dee2aaSAndroid Build Coastguard Worker GrBackendFormats::MakeGL(GR_GL_RGBA8, GR_GL_TEXTURE_2D) },
5286*c8dee2aaSAndroid Build Coastguard Worker { GrColorType::kRGB_888x,
5287*c8dee2aaSAndroid Build Coastguard Worker GrBackendFormats::MakeGL(GR_GL_BGRA8, GR_GL_TEXTURE_2D) },
5288*c8dee2aaSAndroid Build Coastguard Worker { GrColorType::kRGB_888x,
5289*c8dee2aaSAndroid Build Coastguard Worker GrBackendFormats::MakeGL(GR_GL_RGB8, GR_GL_TEXTURE_2D) },
5290*c8dee2aaSAndroid Build Coastguard Worker { GrColorType::kRGB_888x,
5291*c8dee2aaSAndroid Build Coastguard Worker GrBackendFormats::MakeGL(GR_GL_COMPRESSED_RGB8_ETC2, GR_GL_TEXTURE_2D) },
5292*c8dee2aaSAndroid Build Coastguard Worker { GrColorType::kRGB_888x,
5293*c8dee2aaSAndroid Build Coastguard Worker GrBackendFormats::MakeGL(GR_GL_COMPRESSED_ETC1_RGB8, GR_GL_TEXTURE_2D) },
5294*c8dee2aaSAndroid Build Coastguard Worker { GrColorType::kRGB_888x,
5295*c8dee2aaSAndroid Build Coastguard Worker GrBackendFormats::MakeGL(GR_GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GR_GL_TEXTURE_2D) },
5296*c8dee2aaSAndroid Build Coastguard Worker { GrColorType::kRGBA_8888,
5297*c8dee2aaSAndroid Build Coastguard Worker GrBackendFormats::MakeGL(GR_GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GR_GL_TEXTURE_2D) },
5298*c8dee2aaSAndroid Build Coastguard Worker { GrColorType::kRG_88,
5299*c8dee2aaSAndroid Build Coastguard Worker GrBackendFormats::MakeGL(GR_GL_RG8, GR_GL_TEXTURE_2D) },
5300*c8dee2aaSAndroid Build Coastguard Worker { GrColorType::kRGBA_1010102,
5301*c8dee2aaSAndroid Build Coastguard Worker GrBackendFormats::MakeGL(GR_GL_RGB10_A2, GR_GL_TEXTURE_2D) },
5302*c8dee2aaSAndroid Build Coastguard Worker { GrColorType::kRGB_101010x,
5303*c8dee2aaSAndroid Build Coastguard Worker GrBackendFormats::MakeGL(GR_GL_RGB10_A2, GR_GL_TEXTURE_2D) },
5304*c8dee2aaSAndroid Build Coastguard Worker { GrColorType::kGray_8,
5305*c8dee2aaSAndroid Build Coastguard Worker GrBackendFormats::MakeGL(GR_GL_LUMINANCE8, GR_GL_TEXTURE_2D) },
5306*c8dee2aaSAndroid Build Coastguard Worker { GrColorType::kGray_8,
5307*c8dee2aaSAndroid Build Coastguard Worker GrBackendFormats::MakeGL(GR_GL_R8, GR_GL_TEXTURE_2D) },
5308*c8dee2aaSAndroid Build Coastguard Worker { GrColorType::kGrayAlpha_88,
5309*c8dee2aaSAndroid Build Coastguard Worker GrBackendFormats::MakeGL(GR_GL_LUMINANCE8_ALPHA8, GR_GL_TEXTURE_2D) },
5310*c8dee2aaSAndroid Build Coastguard Worker { GrColorType::kAlpha_F16,
5311*c8dee2aaSAndroid Build Coastguard Worker GrBackendFormats::MakeGL(GR_GL_R16F, GR_GL_TEXTURE_2D) },
5312*c8dee2aaSAndroid Build Coastguard Worker { GrColorType::kAlpha_F16,
5313*c8dee2aaSAndroid Build Coastguard Worker GrBackendFormats::MakeGL(GR_GL_LUMINANCE16F, GR_GL_TEXTURE_2D) },
5314*c8dee2aaSAndroid Build Coastguard Worker { GrColorType::kRGBA_F16,
5315*c8dee2aaSAndroid Build Coastguard Worker GrBackendFormats::MakeGL(GR_GL_RGBA16F, GR_GL_TEXTURE_2D) },
5316*c8dee2aaSAndroid Build Coastguard Worker { GrColorType::kRGBA_F16_Clamped,
5317*c8dee2aaSAndroid Build Coastguard Worker GrBackendFormats::MakeGL(GR_GL_RGBA16F, GR_GL_TEXTURE_2D) },
5318*c8dee2aaSAndroid Build Coastguard Worker { GrColorType::kRGB_F16F16F16x,
5319*c8dee2aaSAndroid Build Coastguard Worker GrBackendFormats::MakeGL(GR_GL_RGBA16F, GR_GL_TEXTURE_2D) },
5320*c8dee2aaSAndroid Build Coastguard Worker { GrColorType::kAlpha_16,
5321*c8dee2aaSAndroid Build Coastguard Worker GrBackendFormats::MakeGL(GR_GL_R16, GR_GL_TEXTURE_2D) },
5322*c8dee2aaSAndroid Build Coastguard Worker { GrColorType::kRG_1616,
5323*c8dee2aaSAndroid Build Coastguard Worker GrBackendFormats::MakeGL(GR_GL_RG16, GR_GL_TEXTURE_2D) },
5324*c8dee2aaSAndroid Build Coastguard Worker { GrColorType::kRGBA_16161616,
5325*c8dee2aaSAndroid Build Coastguard Worker GrBackendFormats::MakeGL(GR_GL_RGBA16, GR_GL_TEXTURE_2D) },
5326*c8dee2aaSAndroid Build Coastguard Worker { GrColorType::kRG_F16,
5327*c8dee2aaSAndroid Build Coastguard Worker GrBackendFormats::MakeGL(GR_GL_RG16F, GR_GL_TEXTURE_2D) },
5328*c8dee2aaSAndroid Build Coastguard Worker };
5329*c8dee2aaSAndroid Build Coastguard Worker
5330*c8dee2aaSAndroid Build Coastguard Worker if (GR_IS_GR_GL(fStandard)) {
5331*c8dee2aaSAndroid Build Coastguard Worker combos.push_back({ GrColorType::kBGRA_8888,
5332*c8dee2aaSAndroid Build Coastguard Worker GrBackendFormats::MakeGL(GR_GL_RGBA8, GR_GL_TEXTURE_2D) });
5333*c8dee2aaSAndroid Build Coastguard Worker combos.push_back({ GrColorType::kBGRA_1010102,
5334*c8dee2aaSAndroid Build Coastguard Worker GrBackendFormats::MakeGL(GR_GL_RGB10_A2, GR_GL_TEXTURE_2D) });
5335*c8dee2aaSAndroid Build Coastguard Worker } else {
5336*c8dee2aaSAndroid Build Coastguard Worker SkASSERT(GR_IS_GR_GL_ES(fStandard) || GR_IS_GR_WEBGL(fStandard));
5337*c8dee2aaSAndroid Build Coastguard Worker
5338*c8dee2aaSAndroid Build Coastguard Worker combos.push_back({ GrColorType::kBGRA_8888,
5339*c8dee2aaSAndroid Build Coastguard Worker GrBackendFormats::MakeGL(GR_GL_BGRA8, GR_GL_TEXTURE_2D) });
5340*c8dee2aaSAndroid Build Coastguard Worker }
5341*c8dee2aaSAndroid Build Coastguard Worker if (this->rectangleTextureSupport()) {
5342*c8dee2aaSAndroid Build Coastguard Worker size_t count2D = combos.size();
5343*c8dee2aaSAndroid Build Coastguard Worker for (size_t i = 0; i < count2D; ++i) {
5344*c8dee2aaSAndroid Build Coastguard Worker auto combo2D = combos[i];
5345*c8dee2aaSAndroid Build Coastguard Worker GrGLenum formatEnum = GrBackendFormats::AsGLFormatEnum(combo2D.fFormat);
5346*c8dee2aaSAndroid Build Coastguard Worker combos.push_back({combo2D.fColorType,
5347*c8dee2aaSAndroid Build Coastguard Worker GrBackendFormats::MakeGL(formatEnum, GR_GL_TEXTURE_RECTANGLE)});
5348*c8dee2aaSAndroid Build Coastguard Worker }
5349*c8dee2aaSAndroid Build Coastguard Worker }
5350*c8dee2aaSAndroid Build Coastguard Worker return combos;
5351*c8dee2aaSAndroid Build Coastguard Worker }
5352*c8dee2aaSAndroid Build Coastguard Worker #endif
5353