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