1 /*
2  * Copyright 2012 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include "GrGLCaps.h"
9 #include "GrContextOptions.h"
10 #include "GrGLContext.h"
11 #include "GrGLRenderTarget.h"
12 #include "GrGLTexture.h"
13 #include "GrShaderCaps.h"
14 #include "GrSurfaceProxyPriv.h"
15 #include "SkJSONWriter.h"
16 #include "SkTSearch.h"
17 #include "SkTSort.h"
18 
GrGLCaps(const GrContextOptions & contextOptions,const GrGLContextInfo & ctxInfo,const GrGLInterface * glInterface)19 GrGLCaps::GrGLCaps(const GrContextOptions& contextOptions,
20                    const GrGLContextInfo& ctxInfo,
21                    const GrGLInterface* glInterface) : INHERITED(contextOptions) {
22     fStandard = ctxInfo.standard();
23 
24     fStencilFormats.reset();
25     fMSFBOType = kNone_MSFBOType;
26     fInvalidateFBType = kNone_InvalidateFBType;
27     fMapBufferType = kNone_MapBufferType;
28     fTransferBufferType = kNone_TransferBufferType;
29     fMaxFragmentUniformVectors = 0;
30     fUnpackRowLengthSupport = false;
31     fUnpackFlipYSupport = false;
32     fPackRowLengthSupport = false;
33     fPackFlipYSupport = false;
34     fTextureUsageSupport = false;
35     fAlpha8IsRenderable = false;
36     fImagingSupport = false;
37     fVertexArrayObjectSupport = false;
38     fDebugSupport = false;
39     fES2CompatibilitySupport = false;
40     fDrawIndirectSupport = false;
41     fMultiDrawIndirectSupport = false;
42     fBaseInstanceSupport = false;
43     fIsCoreProfile = false;
44     fBindFragDataLocationSupport = false;
45     fRectangleTextureSupport = false;
46     fTextureSwizzleSupport = false;
47     fRGBA8888PixelsOpsAreSlow = false;
48     fPartialFBOReadIsSlow = false;
49     fMipMapLevelAndLodControlSupport = false;
50     fRGBAToBGRAReadbackConversionsAreSlow = false;
51     fDoManualMipmapping = false;
52     fSRGBDecodeDisableAffectsMipmaps = false;
53     fClearToBoundaryValuesIsBroken = false;
54     fClearTextureSupport = false;
55     fDrawArraysBaseVertexIsBroken = false;
56     fUseDrawToClearColor = false;
57     fUseDrawToClearStencilClip = false;
58     fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = false;
59     fUseDrawInsteadOfAllRenderTargetWrites = false;
60     fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines = false;
61     fProgramBinarySupport = false;
62 
63     fBlitFramebufferFlags = kNoSupport_BlitFramebufferFlag;
64     fMaxInstancesPerDrawArraysWithoutCrashing = 0;
65 
66     fShaderCaps.reset(new GrShaderCaps(contextOptions));
67 
68     this->init(contextOptions, ctxInfo, glInterface);
69 }
70 
init(const GrContextOptions & contextOptions,const GrGLContextInfo & ctxInfo,const GrGLInterface * gli)71 void GrGLCaps::init(const GrContextOptions& contextOptions,
72                     const GrGLContextInfo& ctxInfo,
73                     const GrGLInterface* gli) {
74     GrGLStandard standard = ctxInfo.standard();
75     GrGLVersion version = ctxInfo.version();
76 
77     if (kGLES_GrGLStandard == standard) {
78         GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
79                           &fMaxFragmentUniformVectors);
80     } else {
81         SkASSERT(kGL_GrGLStandard == standard);
82         GrGLint max;
83         GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
84         fMaxFragmentUniformVectors = max / 4;
85         if (version >= GR_GL_VER(3, 2)) {
86             GrGLint profileMask;
87             GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
88             fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
89         }
90     }
91     GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
92 
93     if (kGL_GrGLStandard == standard) {
94         fUnpackRowLengthSupport = true;
95         fUnpackFlipYSupport = false;
96         fPackRowLengthSupport = true;
97         fPackFlipYSupport = false;
98     } else {
99         fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
100                                   ctxInfo.hasExtension("GL_EXT_unpack_subimage");
101         fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
102         fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
103                                 ctxInfo.hasExtension("GL_NV_pack_subimage");
104         fPackFlipYSupport =
105             ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
106     }
107 
108     fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
109                             ctxInfo.hasExtension("GL_ANGLE_texture_usage");
110 
111     if (kGL_GrGLStandard == standard) {
112         fTextureBarrierSupport = version >= GR_GL_VER(4,5) ||
113                                  ctxInfo.hasExtension("GL_ARB_texture_barrier") ||
114                                  ctxInfo.hasExtension("GL_NV_texture_barrier");
115     } else {
116         fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier");
117     }
118 
119     if (kGL_GrGLStandard == standard) {
120         fSampleLocationsSupport = version >= GR_GL_VER(3,2) ||
121                                   ctxInfo.hasExtension("GL_ARB_texture_multisample");
122     } else {
123         fSampleLocationsSupport = version >= GR_GL_VER(3,1);
124     }
125 
126     fImagingSupport = kGL_GrGLStandard == standard &&
127                       ctxInfo.hasExtension("GL_ARB_imaging");
128 
129     if (((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
130          (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
131          ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) {
132         fDiscardRenderTargetSupport = true;
133         fInvalidateFBType = kInvalidate_InvalidateFBType;
134     } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
135         fDiscardRenderTargetSupport = true;
136         fInvalidateFBType = kDiscard_InvalidateFBType;
137     }
138 
139     // For future reference on Desktop GL, GL_PRIMITIVE_RESTART_FIXED_INDEX appears in 4.3, and
140     // GL_PRIMITIVE_RESTART (where the client must call glPrimitiveRestartIndex) appears in 3.1.
141     if (kGLES_GrGLStandard == standard) {
142         // Primitive restart can cause a 3x slowdown on Adreno. Enable conservatively.
143         // TODO: Evaluate on PowerVR.
144         // FIXME: Primitive restart would likely be a win on iOS if we had an enum value for it.
145         if (kARM_GrGLVendor == ctxInfo.vendor()) {
146             fUsePrimitiveRestart = version >= GR_GL_VER(3,0);
147         }
148     }
149 
150     if (kARM_GrGLVendor == ctxInfo.vendor() ||
151         kImagination_GrGLVendor == ctxInfo.vendor() ||
152         kQualcomm_GrGLVendor == ctxInfo.vendor() ) {
153         fPreferFullscreenClears = true;
154     }
155 
156     if (kGL_GrGLStandard == standard) {
157         fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
158                                     ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
159                                     ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
160     } else {
161         fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
162                                     ctxInfo.hasExtension("GL_OES_vertex_array_object");
163     }
164 
165     if (kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) {
166         fDebugSupport = true;
167     } else {
168         fDebugSupport = ctxInfo.hasExtension("GL_KHR_debug");
169     }
170 
171     if (kGL_GrGLStandard == standard) {
172         fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
173     }
174     else {
175         fES2CompatibilitySupport = true;
176     }
177 
178     if (kGL_GrGLStandard == standard) {
179         fMultisampleDisableSupport = true;
180     } else {
181         fMultisampleDisableSupport = ctxInfo.hasExtension("GL_EXT_multisample_compatibility");
182     }
183 
184     if (kGL_GrGLStandard == standard) {
185         // 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about
186         // instanced arrays, but we could make this more granular if we wanted
187         fInstanceAttribSupport =
188                 version >= GR_GL_VER(3, 2) ||
189                 (ctxInfo.hasExtension("GL_ARB_draw_instanced") &&
190                  ctxInfo.hasExtension("GL_ARB_instanced_arrays"));
191     } else {
192         fInstanceAttribSupport =
193                 version >= GR_GL_VER(3, 0) ||
194                 (ctxInfo.hasExtension("GL_EXT_draw_instanced") &&
195                  ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
196     }
197 
198     if (kGL_GrGLStandard == standard) {
199         if (version >= GR_GL_VER(3, 0)) {
200             fBindFragDataLocationSupport = true;
201         }
202     } else {
203         if (version >= GR_GL_VER(3, 0) && ctxInfo.hasExtension("GL_EXT_blend_func_extended")) {
204             fBindFragDataLocationSupport = true;
205         }
206     }
207 
208     fBindUniformLocationSupport = ctxInfo.hasExtension("GL_CHROMIUM_bind_uniform_location");
209 
210     if (kGL_GrGLStandard == standard) {
211         if (version >= GR_GL_VER(3, 1) || ctxInfo.hasExtension("GL_ARB_texture_rectangle")) {
212             // We also require textureSize() support for rectangle 2D samplers which was added in
213             // GLSL 1.40.
214             if (ctxInfo.glslGeneration() >= k140_GrGLSLGeneration) {
215                 fRectangleTextureSupport = true;
216             }
217         }
218     } else {
219         // Command buffer exposes this in GL ES context for Chromium reasons,
220         // but it should not be used. Also, at the time of writing command buffer
221         // lacks TexImage2D support and ANGLE lacks GL ES 3.0 support.
222     }
223 
224     if (kGL_GrGLStandard == standard) {
225         if (version >= GR_GL_VER(3,3) || ctxInfo.hasExtension("GL_ARB_texture_swizzle")) {
226             fTextureSwizzleSupport = true;
227         }
228     } else {
229         if (version >= GR_GL_VER(3,0)) {
230             fTextureSwizzleSupport = true;
231         }
232     }
233 
234     if (kGL_GrGLStandard == standard) {
235         fMipMapLevelAndLodControlSupport = true;
236     } else if (kGLES_GrGLStandard == standard) {
237         if (version >= GR_GL_VER(3,0)) {
238             fMipMapLevelAndLodControlSupport = true;
239         }
240     }
241 
242 #ifdef SK_BUILD_FOR_WIN
243     // We're assuming that on Windows Chromium we're using ANGLE.
244     bool isANGLE = kANGLE_GrGLDriver == ctxInfo.driver() ||
245                    kChromium_GrGLDriver == ctxInfo.driver();
246     // Angle has slow read/write pixel paths for 32bit RGBA (but fast for BGRA).
247     fRGBA8888PixelsOpsAreSlow = isANGLE;
248     // On DX9 ANGLE reading a partial FBO is slow. TODO: Check whether this is still true and
249     // check DX11 ANGLE.
250     fPartialFBOReadIsSlow = isANGLE;
251 #endif
252 
253     bool isMESA = kMesa_GrGLDriver == ctxInfo.driver();
254     bool isMAC = false;
255 #ifdef SK_BUILD_FOR_MAC
256     isMAC = true;
257 #endif
258 
259     // Both mesa and mac have reduced performance if reading back an RGBA framebuffer as BGRA or
260     // vis-versa.
261     fRGBAToBGRAReadbackConversionsAreSlow = isMESA || isMAC;
262 
263     if (kGL_GrGLStandard == standard) {
264         if (version >= GR_GL_VER(4,4) || ctxInfo.hasExtension("GL_ARB_clear_texture")) {
265             fClearTextureSupport = true;
266         }
267     } else if (ctxInfo.hasExtension("GL_EXT_clear_texture")) {
268         fClearTextureSupport = true;
269     }
270 
271     /**************************************************************************
272     * GrShaderCaps fields
273     **************************************************************************/
274 
275     // This must be called after fCoreProfile is set on the GrGLCaps
276     this->initGLSL(ctxInfo, gli);
277     GrShaderCaps* shaderCaps = fShaderCaps.get();
278 
279     shaderCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli);
280 #if GR_TEST_UTILS
281     if (contextOptions.fSuppressPathRendering) {
282         shaderCaps->fPathRenderingSupport = false;
283     }
284 #endif
285 
286     // Enable supported shader-related caps
287     if (kGL_GrGLStandard == standard) {
288         shaderCaps->fDualSourceBlendingSupport = (ctxInfo.version() >= GR_GL_VER(3, 3) ||
289             ctxInfo.hasExtension("GL_ARB_blend_func_extended")) &&
290             GrGLSLSupportsNamedFragmentShaderOutputs(ctxInfo.glslGeneration());
291 
292         shaderCaps->fShaderDerivativeSupport = true;
293 
294         // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
295         shaderCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) &&
296             ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
297         if (shaderCaps->fGeometryShaderSupport) {
298             if (ctxInfo.glslGeneration() >= k400_GrGLSLGeneration) {
299                 shaderCaps->fGSInvocationsSupport = true;
300             } else if (ctxInfo.hasExtension("GL_ARB_gpu_shader5")) {
301                 shaderCaps->fGSInvocationsSupport = true;
302                 shaderCaps->fGSInvocationsExtensionString = "GL_ARB_gpu_shader5";
303             }
304         }
305 
306         shaderCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
307             ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
308     } else {
309         shaderCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended");
310 
311         shaderCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
312             ctxInfo.hasExtension("GL_OES_standard_derivatives");
313 
314         // Mali has support for geometry shaders, but in practice with ccpr they are slower than the
315         // backup impl that only uses vertex shaders.
316         if (kARM_GrGLVendor != ctxInfo.vendor()) {
317             if (ctxInfo.version() >= GR_GL_VER(3,2)) {
318                 shaderCaps->fGeometryShaderSupport = true;
319             } else if (ctxInfo.hasExtension("GL_EXT_geometry_shader")) {
320                 shaderCaps->fGeometryShaderSupport = true;
321                 shaderCaps->fGeometryShaderExtensionString = "GL_EXT_geometry_shader";
322             }
323             shaderCaps->fGSInvocationsSupport = shaderCaps->fGeometryShaderSupport;
324         }
325 
326         shaderCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
327             ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // We use this value for GLSL ES 3.0.
328     }
329 
330     // Protect ourselves against tracking huge amounts of texture state.
331     static const uint8_t kMaxSaneSamplers = 32;
332     GrGLint maxSamplers;
333     GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &maxSamplers);
334     shaderCaps->fMaxVertexSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
335     if (shaderCaps->fGeometryShaderSupport) {
336         GR_GL_GetIntegerv(gli, GR_GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS, &maxSamplers);
337         shaderCaps->fMaxGeometrySamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
338     }
339     GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &maxSamplers);
340     shaderCaps->fMaxFragmentSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
341     GR_GL_GetIntegerv(gli, GR_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxSamplers);
342     shaderCaps->fMaxCombinedSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
343 
344     // This is all *very* approximate.
345     switch (ctxInfo.vendor()) {
346         case kNVIDIA_GrGLVendor:
347             // We've seen a range from 100 x 100 (TegraK1, GTX660) up to 300 x 300 (GTX 1070)
348             // but it doesn't clearly align with Pascal vs Maxwell vs Kepler.
349             fShaderCaps->fDisableImageMultitexturingDstRectAreaThreshold = 150 * 150;
350             break;
351         case kImagination_GrGLVendor:
352             // Two PowerVR Rogues, Nexus Player and Chromebook Cb5-312T (PowerVR GX6250), show that
353             // it is always a win to use multitexturing.
354             if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
355                 fShaderCaps->fDisableImageMultitexturingDstRectAreaThreshold =
356                         std::numeric_limits<size_t>::max();
357             }
358             break;
359         case kATI_GrGLVendor:
360             // So far no AMD GPU shows a performance difference. A tie goes to disabling
361             // multitexturing for simplicity's sake.
362             fShaderCaps->fDisableImageMultitexturingDstRectAreaThreshold = 0;
363             break;
364         default:
365             break;
366     }
367 
368     // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
369     // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
370     // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
371     // limit this decision to specific GPU families rather than basing it on the vendor alone.
372     if (!GR_GL_MUST_USE_VBO &&
373         !fIsCoreProfile &&
374         (kARM_GrGLVendor == ctxInfo.vendor() ||
375          kImagination_GrGLVendor == ctxInfo.vendor() ||
376          kQualcomm_GrGLVendor == ctxInfo.vendor())) {
377         fPreferClientSideDynamicBuffers = true;
378     }
379 
380     if (!contextOptions.fAvoidStencilBuffers) {
381         // To reduce surface area, if we avoid stencil buffers, we also disable MSAA.
382         this->initFSAASupport(contextOptions, ctxInfo, gli);
383         this->initStencilSupport(ctxInfo);
384     }
385 
386     // Setup blit framebuffer
387     if (kGL_GrGLStandard != ctxInfo.standard()) {
388         if (ctxInfo.version() >= GR_GL_VER(3, 0)) {
389             fBlitFramebufferFlags = kNoFormatConversionForMSAASrc_BlitFramebufferFlag |
390                                     kNoMSAADst_BlitFramebufferFlag |
391                                     kRectsMustMatchForMSAASrc_BlitFramebufferFlag;
392         } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample") ||
393                    ctxInfo.hasExtension("GL_ANGLE_framebuffer_blit")) {
394             // The CHROMIUM extension uses the ANGLE version of glBlitFramebuffer and includes its
395             // limitations.
396             fBlitFramebufferFlags = kNoScalingOrMirroring_BlitFramebufferFlag |
397                                     kResolveMustBeFull_BlitFrambufferFlag |
398                                     kNoMSAADst_BlitFramebufferFlag |
399                                     kNoFormatConversion_BlitFramebufferFlag |
400                                     kRectsMustMatchForMSAASrc_BlitFramebufferFlag;
401         }
402     } else {
403         if (fUsesMixedSamples ||
404             ctxInfo.version() >= GR_GL_VER(3,0) ||
405             ctxInfo.hasExtension("GL_ARB_framebuffer_object") ||
406             ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
407             fBlitFramebufferFlags = 0;
408         }
409     }
410 
411     this->initBlendEqationSupport(ctxInfo);
412 
413     if (kGL_GrGLStandard == standard) {
414         fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
415                                             // extension includes glMapBuffer.
416         if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
417             fMapBufferFlags |= kSubset_MapFlag;
418             fMapBufferType = kMapBufferRange_MapBufferType;
419         } else {
420             fMapBufferType = kMapBuffer_MapBufferType;
421         }
422     } else {
423         // Unextended GLES2 doesn't have any buffer mapping.
424         fMapBufferFlags = kNone_MapBufferType;
425         if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
426             fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
427             fMapBufferType = kChromium_MapBufferType;
428         } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
429             fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
430             fMapBufferType = kMapBufferRange_MapBufferType;
431         } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
432             fMapBufferFlags = kCanMap_MapFlag;
433             fMapBufferType = kMapBuffer_MapBufferType;
434         }
435     }
436 
437     if (kGL_GrGLStandard == standard) {
438         if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_pixel_buffer_object")) {
439             fTransferBufferType = kPBO_TransferBufferType;
440         }
441     } else {
442         if (version >= GR_GL_VER(3, 0) ||
443             (ctxInfo.hasExtension("GL_NV_pixel_buffer_object") &&
444              // GL_EXT_unpack_subimage needed to support subtexture rectangles
445              ctxInfo.hasExtension("GL_EXT_unpack_subimage"))) {
446             fTransferBufferType = kPBO_TransferBufferType;
447 // TODO: get transfer buffers working in Chrome
448 //        } else if (ctxInfo.hasExtension("GL_CHROMIUM_pixel_transfer_buffer_object")) {
449 //            fTransferBufferType = kChromium_TransferBufferType;
450         }
451     }
452 
453     // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
454     // threshold to the maximum unless the client gives us a hint that map memory is cheap.
455     if (fBufferMapThreshold < 0) {
456 #if 0
457         // We think mapping on Chromium will be cheaper once we know ahead of time how much space
458         // we will use for all GrMeshDrawOps. Right now we might wind up mapping a large buffer and
459         // using a small subset.
460         fBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
461 #else
462         fBufferMapThreshold = SK_MaxS32;
463 #endif
464     }
465 
466     if (kGL_GrGLStandard == standard) {
467         fNPOTTextureTileSupport = true;
468         fMipMapSupport = true;
469     } else {
470         // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
471         // ES3 has no limitations.
472         fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
473                                   ctxInfo.hasExtension("GL_OES_texture_npot");
474         // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
475         // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
476         // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
477         // to alllow arbitrary wrap modes, however.
478         fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
479     }
480 
481     GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
482     GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
483     // Our render targets are always created with textures as the color
484     // attachment, hence this min:
485     fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
486     fMaxPreferredRenderTargetSize = fMaxRenderTargetSize;
487 
488     if (kARM_GrGLVendor == ctxInfo.vendor()) {
489         // On Mali G71, RT's above 4k have been observed to incur a performance cost.
490         fMaxPreferredRenderTargetSize = SkTMin(4096, fMaxPreferredRenderTargetSize);
491     }
492 
493     fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
494 
495     // Disable scratch texture reuse on Mali and Adreno devices
496     fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor();
497 
498 #if 0
499     fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() &&
500                            kQualcomm_GrGLVendor != ctxInfo.vendor();
501 #endif
502 
503     if (ctxInfo.hasExtension("GL_EXT_window_rectangles")) {
504         GR_GL_GetIntegerv(gli, GR_GL_MAX_WINDOW_RECTANGLES, &fMaxWindowRectangles);
505     }
506 
507 #ifdef SK_BUILD_FOR_WIN
508     // On ANGLE deferring flushes can lead to GPU starvation
509     fPreferVRAMUseOverFlushes = !isANGLE;
510 #endif
511 
512     if (kChromium_GrGLDriver == ctxInfo.driver()) {
513         fMustClearUploadedBufferData = true;
514     }
515 
516     if (kGL_GrGLStandard == standard) {
517         // ARB allows mixed size FBO attachments, EXT does not.
518         if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
519             ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
520             fOversizedStencilSupport = true;
521         } else {
522             SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
523         }
524     } else {
525         // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
526         fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
527     }
528 
529     if (kGL_GrGLStandard == standard) {
530         fDrawIndirectSupport = version >= GR_GL_VER(4,0) ||
531                                ctxInfo.hasExtension("GL_ARB_draw_indirect");
532         fBaseInstanceSupport = version >= GR_GL_VER(4,2);
533         fMultiDrawIndirectSupport = version >= GR_GL_VER(4,3) ||
534                                     (fDrawIndirectSupport &&
535                                      !fBaseInstanceSupport && // The ARB extension has no base inst.
536                                      ctxInfo.hasExtension("GL_ARB_multi_draw_indirect"));
537         fDrawRangeElementsSupport = version >= GR_GL_VER(2,0);
538     } else {
539         fDrawIndirectSupport = version >= GR_GL_VER(3,1);
540         fMultiDrawIndirectSupport = fDrawIndirectSupport &&
541                                     ctxInfo.hasExtension("GL_EXT_multi_draw_indirect");
542         fBaseInstanceSupport = fDrawIndirectSupport &&
543                                ctxInfo.hasExtension("GL_EXT_base_instance");
544         fDrawRangeElementsSupport = version >= GR_GL_VER(3,0);
545     }
546 
547     if (kGL_GrGLStandard == standard) {
548         if ((version >= GR_GL_VER(4, 0) || ctxInfo.hasExtension("GL_ARB_sample_shading"))) {
549             fSampleShadingSupport = true;
550         }
551     } else if (ctxInfo.hasExtension("GL_OES_sample_shading")) {
552         fSampleShadingSupport = true;
553     }
554 
555     // TODO: support CHROMIUM_sync_point and maybe KHR_fence_sync
556     if (kGL_GrGLStandard == standard) {
557         if (version >= GR_GL_VER(3, 2) || ctxInfo.hasExtension("GL_ARB_sync")) {
558             fFenceSyncSupport = true;
559         }
560     } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_APPLE_sync")) {
561         fFenceSyncSupport = true;
562     }
563 
564     // Safely moving textures between contexts requires fences.
565     fCrossContextTextureSupport = fFenceSyncSupport;
566 
567     fSRGBDecodeDisableSupport = ctxInfo.hasExtension("GL_EXT_texture_sRGB_decode");
568 
569     fSRGBDecodeDisableAffectsMipmaps = fSRGBDecodeDisableSupport &&
570         kChromium_GrGLDriver != ctxInfo.driver();
571 
572     if (kGL_GrGLStandard == standard) {
573         if (version >= GR_GL_VER(4, 1)) {
574             fProgramBinarySupport = true;
575         }
576     } else if (version >= GR_GL_VER(3, 0)) {
577         fProgramBinarySupport = true;
578     }
579 
580     // Requires fTextureRedSupport, fTextureSwizzleSupport, msaa support, ES compatibility have
581     // already been detected.
582     this->initConfigTable(contextOptions, ctxInfo, gli, shaderCaps);
583 
584     if (!contextOptions.fDisableDriverCorrectnessWorkarounds) {
585         this->applyDriverCorrectnessWorkarounds(ctxInfo, contextOptions, shaderCaps);
586     }
587 
588     this->applyOptionsOverrides(contextOptions);
589     shaderCaps->applyOptionsOverrides(contextOptions);
590 
591     // For now these two are equivalent but we could have dst read in shader via some other method.
592     shaderCaps->fDstReadInShaderSupport = shaderCaps->fFBFetchSupport;
593 }
594 
get_glsl_version_decl_string(GrGLStandard standard,GrGLSLGeneration generation,bool isCoreProfile)595 const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration generation,
596                                          bool isCoreProfile) {
597     switch (generation) {
598         case k110_GrGLSLGeneration:
599             if (kGLES_GrGLStandard == standard) {
600                 // ES2s shader language is based on version 1.20 but is version
601                 // 1.00 of the ES language.
602                 return "#version 100\n";
603             } else {
604                 SkASSERT(kGL_GrGLStandard == standard);
605                 return "#version 110\n";
606             }
607         case k130_GrGLSLGeneration:
608             SkASSERT(kGL_GrGLStandard == standard);
609             return "#version 130\n";
610         case k140_GrGLSLGeneration:
611             SkASSERT(kGL_GrGLStandard == standard);
612             return "#version 140\n";
613         case k150_GrGLSLGeneration:
614             SkASSERT(kGL_GrGLStandard == standard);
615             if (isCoreProfile) {
616                 return "#version 150\n";
617             } else {
618                 return "#version 150 compatibility\n";
619             }
620         case k330_GrGLSLGeneration:
621             if (kGLES_GrGLStandard == standard) {
622                 return "#version 300 es\n";
623             } else {
624                 SkASSERT(kGL_GrGLStandard == standard);
625                 if (isCoreProfile) {
626                     return "#version 330\n";
627                 } else {
628                     return "#version 330 compatibility\n";
629                 }
630             }
631         case k400_GrGLSLGeneration:
632             SkASSERT(kGL_GrGLStandard == standard);
633             if (isCoreProfile) {
634                 return "#version 400\n";
635             } else {
636                 return "#version 400 compatibility\n";
637             }
638         case k420_GrGLSLGeneration:
639             SkASSERT(kGL_GrGLStandard == standard);
640             if (isCoreProfile) {
641                 return "#version 420\n";
642             }
643             else {
644                 return "#version 420 compatibility\n";
645             }
646         case k310es_GrGLSLGeneration:
647             SkASSERT(kGLES_GrGLStandard == standard);
648             return "#version 310 es\n";
649         case k320es_GrGLSLGeneration:
650             SkASSERT(kGLES_GrGLStandard == standard);
651             return "#version 320 es\n";
652     }
653     return "<no version>";
654 }
655 
is_float_fp32(const GrGLContextInfo & ctxInfo,const GrGLInterface * gli,GrGLenum precision)656 bool is_float_fp32(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli, GrGLenum precision) {
657     if (kGLES_GrGLStandard != ctxInfo.standard() &&
658         ctxInfo.version() < GR_GL_VER(4,1) &&
659         !ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
660         // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
661         return true;
662     }
663     // glGetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Hopefully the
664     // geometry shaders don't have lower precision than vertex and fragment.
665     for (GrGLenum shader : {GR_GL_FRAGMENT_SHADER, GR_GL_VERTEX_SHADER}) {
666         GrGLint range[2];
667         GrGLint bits;
668         GR_GL_GetShaderPrecisionFormat(gli, shader, precision, range, &bits);
669         if (range[0] < 127 || range[1] < 127 || bits < 23) {
670             return false;
671         }
672     }
673     return true;
674 }
675 
initGLSL(const GrGLContextInfo & ctxInfo,const GrGLInterface * gli)676 void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
677     GrGLStandard standard = ctxInfo.standard();
678     GrGLVersion version = ctxInfo.version();
679 
680     /**************************************************************************
681     * Caps specific to GrShaderCaps
682     **************************************************************************/
683 
684     GrShaderCaps* shaderCaps = fShaderCaps.get();
685     shaderCaps->fGLSLGeneration = ctxInfo.glslGeneration();
686     if (kGLES_GrGLStandard == standard) {
687         if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
688             shaderCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
689             shaderCaps->fFBFetchSupport = true;
690             shaderCaps->fFBFetchColorName = "gl_LastFragData[0]";
691             shaderCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
692         }
693         else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
694             // Actually, we haven't seen an ES3.0 device with this extension yet, so we don't know
695             shaderCaps->fFBFetchNeedsCustomOutput = false;
696             shaderCaps->fFBFetchSupport = true;
697             shaderCaps->fFBFetchColorName = "gl_LastFragData[0]";
698             shaderCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
699         }
700         else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
701             // The arm extension also requires an additional flag which we will set onResetContext
702             shaderCaps->fFBFetchNeedsCustomOutput = false;
703             shaderCaps->fFBFetchSupport = true;
704             shaderCaps->fFBFetchColorName = "gl_LastFragColorARM";
705             shaderCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
706         }
707         shaderCaps->fUsesPrecisionModifiers = true;
708     }
709 
710     if (kGL_GrGLStandard == standard) {
711         shaderCaps->fFlatInterpolationSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
712     } else {
713         shaderCaps->fFlatInterpolationSupport =
714             ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // This is the value for GLSL ES 3.0.
715     }
716     // Flat interpolation appears to be slow on Qualcomm GPUs (tested Adreno 405 and 530).
717     shaderCaps->fPreferFlatInterpolation = shaderCaps->fFlatInterpolationSupport &&
718                                            kQualcomm_GrGLVendor != ctxInfo.vendor();
719     if (kGL_GrGLStandard == standard) {
720         shaderCaps->fNoPerspectiveInterpolationSupport =
721             ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
722     } else {
723         if (ctxInfo.hasExtension("GL_NV_shader_noperspective_interpolation")) {
724             shaderCaps->fNoPerspectiveInterpolationSupport = true;
725             shaderCaps->fNoPerspectiveInterpolationExtensionString =
726                 "GL_NV_shader_noperspective_interpolation";
727         }
728     }
729 
730     shaderCaps->fVersionDeclString = get_glsl_version_decl_string(standard,
731                                                                   shaderCaps->fGLSLGeneration,
732                                                                   fIsCoreProfile);
733 
734     if (kGLES_GrGLStandard == standard && k110_GrGLSLGeneration == shaderCaps->fGLSLGeneration) {
735         shaderCaps->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
736     }
737 
738     // Frag Coords Convention support is not part of ES
739     if (kGLES_GrGLStandard != standard &&
740         (ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
741          ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"))) {
742         shaderCaps->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions";
743     }
744 
745     if (kGLES_GrGLStandard == standard) {
746         shaderCaps->fSecondaryOutputExtensionString = "GL_EXT_blend_func_extended";
747     }
748 
749     if (ctxInfo.hasExtension("GL_OES_EGL_image_external")) {
750         if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
751             shaderCaps->fExternalTextureSupport = true;
752         } else if (ctxInfo.hasExtension("GL_OES_EGL_image_external_essl3") ||
753                    ctxInfo.hasExtension("OES_EGL_image_external_essl3")) {
754             // At least one driver has been found that has this extension without the "GL_" prefix.
755             shaderCaps->fExternalTextureSupport = true;
756         }
757     }
758 
759     if (shaderCaps->fExternalTextureSupport) {
760         if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
761             shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
762         } else {
763             shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
764         }
765     }
766 
767     if (kGL_GrGLStandard == standard) {
768         shaderCaps->fTexelFetchSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
769     } else {
770         shaderCaps->fTexelFetchSupport =
771             ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // We use this value for GLSL ES 3.0.
772     }
773 
774     if (shaderCaps->fTexelFetchSupport) {
775         if (kGL_GrGLStandard == standard) {
776             shaderCaps->fTexelBufferSupport = ctxInfo.version() >= GR_GL_VER(3, 1) &&
777                                             ctxInfo.glslGeneration() >= k330_GrGLSLGeneration;
778         } else {
779             if (ctxInfo.version() >= GR_GL_VER(3, 2) &&
780                 ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration) {
781                 shaderCaps->fTexelBufferSupport = true;
782             } else if (ctxInfo.hasExtension("GL_OES_texture_buffer")) {
783                 shaderCaps->fTexelBufferSupport = true;
784                 shaderCaps->fTexelBufferExtensionString = "GL_OES_texture_buffer";
785             } else if (ctxInfo.hasExtension("GL_EXT_texture_buffer")) {
786                 shaderCaps->fTexelBufferSupport = true;
787                 shaderCaps->fTexelBufferExtensionString = "GL_EXT_texture_buffer";
788             }
789         }
790     }
791 
792     if (kGL_GrGLStandard == standard) {
793         shaderCaps->fVertexIDSupport = true;
794     } else {
795         // Desktop GLSL 3.30 == ES GLSL 3.00.
796         shaderCaps->fVertexIDSupport = ctxInfo.glslGeneration() >= k330_GrGLSLGeneration;
797     }
798 
799     shaderCaps->fFloatIs32Bits = is_float_fp32(ctxInfo, gli, GR_GL_HIGH_FLOAT);
800     shaderCaps->fHalfIs32Bits = is_float_fp32(ctxInfo, gli, GR_GL_MEDIUM_FLOAT);
801 }
802 
hasPathRenderingSupport(const GrGLContextInfo & ctxInfo,const GrGLInterface * gli)803 bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
804     bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering");
805 
806     if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) {
807         return false;
808     }
809 
810     if (kGL_GrGLStandard == ctxInfo.standard()) {
811         if (ctxInfo.version() < GR_GL_VER(4, 3) &&
812             !ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
813             return false;
814         }
815     } else {
816         if (!hasChromiumPathRendering &&
817             ctxInfo.version() < GR_GL_VER(3, 1)) {
818             return false;
819         }
820     }
821     // We only support v1.3+ of GL_NV_path_rendering which allows us to
822     // set individual fragment inputs with ProgramPathFragmentInputGen. The API
823     // additions are detected by checking the existence of the function.
824     // We also use *Then* functions that not all drivers might have. Check
825     // them for consistency.
826     if (!gli->fFunctions.fStencilThenCoverFillPath ||
827         !gli->fFunctions.fStencilThenCoverStrokePath ||
828         !gli->fFunctions.fStencilThenCoverFillPathInstanced ||
829         !gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
830         !gli->fFunctions.fProgramPathFragmentInputGen) {
831         return false;
832     }
833     return true;
834 }
835 
readPixelsSupported(GrPixelConfig surfaceConfig,GrPixelConfig readConfig,std::function<void (GrGLenum,GrGLint *)> getIntegerv,std::function<bool ()> bindRenderTarget,std::function<void ()> unbindRenderTarget) const836 bool GrGLCaps::readPixelsSupported(GrPixelConfig surfaceConfig,
837                                    GrPixelConfig readConfig,
838                                    std::function<void (GrGLenum, GrGLint*)> getIntegerv,
839                                    std::function<bool ()> bindRenderTarget,
840                                    std::function<void ()> unbindRenderTarget) const {
841     // If it's not possible to even have a color attachment of surfaceConfig then read pixels is
842     // not supported regardless of readConfig.
843     if (!this->canConfigBeFBOColorAttachment(surfaceConfig)) {
844         return false;
845     }
846 
847     GrGLenum readFormat;
848     GrGLenum readType;
849     if (!this->getReadPixelsFormat(surfaceConfig, readConfig, &readFormat, &readType)) {
850         return false;
851     }
852 
853     if (kGL_GrGLStandard == fStandard) {
854         // Some OpenGL implementations allow GL_ALPHA as a format to glReadPixels. However,
855         // the manual (https://www.opengl.org/sdk/docs/man/) says only these formats are allowed:
856         // GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL, GL_RED, GL_GREEN, GL_BLUE,
857         // GL_RGB, GL_BGR, GL_RGBA, and GL_BGRA. We check for the subset that we would use.
858         // The manual does not seem to fully match the spec as the spec allows integer formats
859         // when the bound color buffer is an integer buffer. It doesn't specify which integer
860         // formats are allowed, so perhaps all of them are. We only use GL_RGBA_INTEGER currently.
861         if (readFormat != GR_GL_RED && readFormat != GR_GL_RG && readFormat != GR_GL_RGB &&
862             readFormat != GR_GL_RGBA && readFormat != GR_GL_BGRA &&
863             readFormat != GR_GL_RGBA_INTEGER) {
864             return false;
865         }
866         // There is also a set of allowed types, but all the types we use are in the set:
867         // GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT,
868         // GL_HALF_FLOAT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV,
869         // GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4,
870         // GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV,
871         // GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV,GL_UNSIGNED_INT_10_10_10_2,
872         // GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV,
873         // GL_UNSIGNED_INT_5_9_9_9_REV, or GL_FLOAT_32_UNSIGNED_INT_24_8_REV.
874         return true;
875     }
876 
877     // See Section 16.1.2 in the ES 3.2 specification.
878     switch (fConfigTable[surfaceConfig].fFormatType) {
879         case kNormalizedFixedPoint_FormatType:
880             if (GR_GL_RGBA == readFormat && GR_GL_UNSIGNED_BYTE == readType) {
881                 return true;
882             }
883             break;
884         case kInteger_FormatType:
885             if (GR_GL_RGBA_INTEGER == readFormat && GR_GL_INT == readType) {
886                 return true;
887             }
888             break;
889         case kFloat_FormatType:
890             if (GR_GL_RGBA == readFormat && GR_GL_FLOAT == readType) {
891                 return true;
892             }
893             break;
894     }
895 
896     if (0 == fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fFormat) {
897         ReadPixelsFormat* rpFormat =
898             const_cast<ReadPixelsFormat*>(&fConfigTable[surfaceConfig].fSecondReadPixelsFormat);
899         GrGLint format = 0, type = 0;
900         if (!bindRenderTarget()) {
901             return false;
902         }
903         getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, &format);
904         getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, &type);
905         rpFormat->fFormat = format;
906         rpFormat->fType = type;
907         unbindRenderTarget();
908     }
909 
910     return fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fFormat == readFormat &&
911            fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fType == readType;
912 }
913 
initFSAASupport(const GrContextOptions & contextOptions,const GrGLContextInfo & ctxInfo,const GrGLInterface * gli)914 void GrGLCaps::initFSAASupport(const GrContextOptions& contextOptions, const GrGLContextInfo& ctxInfo,
915                                const GrGLInterface* gli) {
916     // We need dual source blending and the ability to disable multisample in order to support mixed
917     // samples in every corner case. We only use mixed samples if the stencil-and-cover path
918     // renderer is available and enabled; no other path renderers support this feature.
919     if (fMultisampleDisableSupport &&
920         this->shaderCaps()->dualSourceBlendingSupport() &&
921         this->shaderCaps()->pathRenderingSupport()
922 #if GR_TEST_UTILS
923         && (contextOptions.fGpuPathRenderers & GpuPathRenderers::kStencilAndCover)
924 #endif
925         ) {
926         fUsesMixedSamples = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") ||
927                             ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_mixed_samples");
928     }
929 
930     if (kGL_GrGLStandard != ctxInfo.standard()) {
931         if (ctxInfo.version() >= GR_GL_VER(3,0) &&
932             ctxInfo.renderer() != kGalliumLLVM_GrGLRenderer) {
933             // The gallium llvmpipe renderer for es3.0 does not have textureRed support even though
934             // it is part of the spec. Thus alpha8 will not be renderable for those devices.
935             fAlpha8IsRenderable = true;
936         }
937         // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
938         // ES3 driver bugs on at least one device with a tiled GPU (N10).
939         if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
940             fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
941         } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
942             fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
943         } else if (fUsesMixedSamples) {
944             fMSFBOType = kMixedSamples_MSFBOType;
945         } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
946             fMSFBOType = kStandard_MSFBOType;
947         } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
948             fMSFBOType = kStandard_MSFBOType;
949         } else if (ctxInfo.hasExtension("GL_ANGLE_framebuffer_multisample")) {
950             fMSFBOType = kStandard_MSFBOType;
951         } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
952             fMSFBOType = kES_Apple_MSFBOType;
953         }
954     } else {
955         if (fUsesMixedSamples) {
956             fMSFBOType = kMixedSamples_MSFBOType;
957         } else if (ctxInfo.version() >= GR_GL_VER(3,0) ||
958                    ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
959 
960             fMSFBOType = kStandard_MSFBOType;
961             if (!fIsCoreProfile && ctxInfo.renderer() != kOSMesa_GrGLRenderer) {
962                 // Core profile removes ALPHA8 support.
963                 // OpenGL 3.0+ (and GL_ARB_framebuffer_object) supports ALPHA8 as renderable.
964                 // However, osmesa fails if it is used even when GL_ARB_framebuffer_object is
965                 // present.
966                 fAlpha8IsRenderable = true;
967             }
968         } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
969                    ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
970             fMSFBOType = kStandard_MSFBOType;
971         }
972     }
973 
974     // We disable MSAA across the board for Intel GPUs for performance reasons.
975     if (kIntel_GrGLVendor == ctxInfo.vendor()) {
976         fMSFBOType = kNone_MSFBOType;
977     }
978 
979     // We only have a use for raster multisample if there is coverage modulation from mixed samples.
980     if (fUsesMixedSamples && ctxInfo.hasExtension("GL_EXT_raster_multisample")) {
981         GR_GL_GetIntegerv(gli, GR_GL_MAX_RASTER_SAMPLES, &fMaxRasterSamples);
982     }
983 }
984 
initBlendEqationSupport(const GrGLContextInfo & ctxInfo)985 void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
986     GrShaderCaps* shaderCaps = static_cast<GrShaderCaps*>(fShaderCaps.get());
987 
988     bool layoutQualifierSupport = false;
989     if ((kGL_GrGLStandard == fStandard && shaderCaps->generation() >= k140_GrGLSLGeneration)  ||
990         (kGLES_GrGLStandard == fStandard && shaderCaps->generation() >= k330_GrGLSLGeneration)) {
991         layoutQualifierSupport = true;
992     }
993 
994     if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
995         fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
996         shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction;
997     } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent") &&
998                layoutQualifierSupport) {
999         fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
1000         shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kGeneralEnable_AdvBlendEqInteraction;
1001     } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
1002         fBlendEquationSupport = kAdvanced_BlendEquationSupport;
1003         shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction;
1004     } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced") && layoutQualifierSupport) {
1005         fBlendEquationSupport = kAdvanced_BlendEquationSupport;
1006         shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kGeneralEnable_AdvBlendEqInteraction;
1007         // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
1008         // slow on a particular platform.
1009     }
1010 }
1011 
1012 namespace {
1013 const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
1014 }
1015 
initStencilSupport(const GrGLContextInfo & ctxInfo)1016 void GrGLCaps::initStencilSupport(const GrGLContextInfo& ctxInfo) {
1017 
1018     // Build up list of legal stencil formats (though perhaps not supported on
1019     // the particular gpu/driver) from most preferred to least.
1020 
1021     // these consts are in order of most preferred to least preferred
1022     // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
1023 
1024     static const StencilFormat
1025                   // internal Format      stencil bits      total bits        packed?
1026         gS8    = {GR_GL_STENCIL_INDEX8,   8,                8,                false},
1027         gS16   = {GR_GL_STENCIL_INDEX16,  16,               16,               false},
1028         gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8,                32,               true },
1029         gS4    = {GR_GL_STENCIL_INDEX4,   4,                4,                false},
1030     //  gS     = {GR_GL_STENCIL_INDEX,    kUnknownBitCount, kUnknownBitCount, false},
1031         gDS    = {GR_GL_DEPTH_STENCIL,    kUnknownBitCount, kUnknownBitCount, true };
1032 
1033     if (kGL_GrGLStandard == ctxInfo.standard()) {
1034         bool supportsPackedDS =
1035             ctxInfo.version() >= GR_GL_VER(3,0) ||
1036             ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
1037             ctxInfo.hasExtension("GL_ARB_framebuffer_object");
1038 
1039         // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
1040         // require FBO support we can expect these are legal formats and don't
1041         // check. These also all support the unsized GL_STENCIL_INDEX.
1042         fStencilFormats.push_back() = gS8;
1043         fStencilFormats.push_back() = gS16;
1044         if (supportsPackedDS) {
1045             fStencilFormats.push_back() = gD24S8;
1046         }
1047         fStencilFormats.push_back() = gS4;
1048         if (supportsPackedDS) {
1049             fStencilFormats.push_back() = gDS;
1050         }
1051     } else {
1052         // ES2 has STENCIL_INDEX8 without extensions but requires extensions
1053         // for other formats.
1054         // ES doesn't support using the unsized format.
1055 
1056         fStencilFormats.push_back() = gS8;
1057         //fStencilFormats.push_back() = gS16;
1058         if (ctxInfo.version() >= GR_GL_VER(3,0) ||
1059             ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
1060             fStencilFormats.push_back() = gD24S8;
1061         }
1062         if (ctxInfo.hasExtension("GL_OES_stencil4")) {
1063             fStencilFormats.push_back() = gS4;
1064         }
1065     }
1066 }
1067 
onDumpJSON(SkJSONWriter * writer) const1068 void GrGLCaps::onDumpJSON(SkJSONWriter* writer) const {
1069 
1070     // We are called by the base class, which has already called beginObject(). We choose to nest
1071     // all of our caps information in a named sub-object.
1072     writer->beginObject("GL caps");
1073 
1074     writer->beginArray("Stencil Formats");
1075 
1076     for (int i = 0; i < fStencilFormats.count(); ++i) {
1077         writer->beginObject(nullptr, false);
1078         writer->appendS32("stencil bits", fStencilFormats[i].fStencilBits);
1079         writer->appendS32("total bits", fStencilFormats[i].fTotalBits);
1080         writer->endObject();
1081     }
1082 
1083     writer->endArray();
1084 
1085     static const char* kMSFBOExtStr[] = {
1086         "None",
1087         "Standard",
1088         "Apple",
1089         "IMG MS To Texture",
1090         "EXT MS To Texture",
1091         "MixedSamples",
1092     };
1093     GR_STATIC_ASSERT(0 == kNone_MSFBOType);
1094     GR_STATIC_ASSERT(1 == kStandard_MSFBOType);
1095     GR_STATIC_ASSERT(2 == kES_Apple_MSFBOType);
1096     GR_STATIC_ASSERT(3 == kES_IMG_MsToTexture_MSFBOType);
1097     GR_STATIC_ASSERT(4 == kES_EXT_MsToTexture_MSFBOType);
1098     GR_STATIC_ASSERT(5 == kMixedSamples_MSFBOType);
1099     GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
1100 
1101     static const char* kInvalidateFBTypeStr[] = {
1102         "None",
1103         "Discard",
1104         "Invalidate",
1105     };
1106     GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
1107     GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
1108     GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
1109     GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
1110 
1111     static const char* kMapBufferTypeStr[] = {
1112         "None",
1113         "MapBuffer",
1114         "MapBufferRange",
1115         "Chromium",
1116     };
1117     GR_STATIC_ASSERT(0 == kNone_MapBufferType);
1118     GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
1119     GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
1120     GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
1121     GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
1122 
1123     writer->appendBool("Core Profile", fIsCoreProfile);
1124     writer->appendString("MSAA Type", kMSFBOExtStr[fMSFBOType]);
1125     writer->appendString("Invalidate FB Type", kInvalidateFBTypeStr[fInvalidateFBType]);
1126     writer->appendString("Map Buffer Type", kMapBufferTypeStr[fMapBufferType]);
1127     writer->appendS32("Max FS Uniform Vectors", fMaxFragmentUniformVectors);
1128     writer->appendBool("Unpack Row length support", fUnpackRowLengthSupport);
1129     writer->appendBool("Unpack Flip Y support", fUnpackFlipYSupport);
1130     writer->appendBool("Pack Row length support", fPackRowLengthSupport);
1131     writer->appendBool("Pack Flip Y support", fPackFlipYSupport);
1132 
1133     writer->appendBool("Texture Usage support", fTextureUsageSupport);
1134     writer->appendBool("Alpha8 is renderable", fAlpha8IsRenderable);
1135     writer->appendBool("GL_ARB_imaging support", fImagingSupport);
1136     writer->appendBool("Vertex array object support", fVertexArrayObjectSupport);
1137     writer->appendBool("Debug support", fDebugSupport);
1138     writer->appendBool("Draw indirect support", fDrawIndirectSupport);
1139     writer->appendBool("Multi draw indirect support", fMultiDrawIndirectSupport);
1140     writer->appendBool("Base instance support", fBaseInstanceSupport);
1141     writer->appendBool("RGBA 8888 pixel ops are slow", fRGBA8888PixelsOpsAreSlow);
1142     writer->appendBool("Partial FBO read is slow", fPartialFBOReadIsSlow);
1143     writer->appendBool("Bind uniform location support", fBindUniformLocationSupport);
1144     writer->appendBool("Rectangle texture support", fRectangleTextureSupport);
1145     writer->appendBool("Texture swizzle support", fTextureSwizzleSupport);
1146     writer->appendBool("BGRA to RGBA readback conversions are slow",
1147                        fRGBAToBGRAReadbackConversionsAreSlow);
1148     writer->appendBool("Draw To clear color", fUseDrawToClearColor);
1149     writer->appendBool("Draw To clear stencil clip", fUseDrawToClearStencilClip);
1150     writer->appendBool("Intermediate texture for partial updates of unorm textures ever bound to FBOs",
1151                        fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO);
1152     writer->appendBool("Intermediate texture for all updates of textures bound to FBOs",
1153                        fUseDrawInsteadOfAllRenderTargetWrites);
1154     writer->appendBool("Max instances per glDrawArraysInstanced without crashing (or zero)",
1155                        fMaxInstancesPerDrawArraysWithoutCrashing);
1156 
1157     writer->beginArray("configs");
1158 
1159     for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1160         writer->beginObject(nullptr, false);
1161         writer->appendHexU32("flags", fConfigTable[i].fFlags);
1162         writer->appendHexU32("b_internal", fConfigTable[i].fFormats.fBaseInternalFormat);
1163         writer->appendHexU32("s_internal", fConfigTable[i].fFormats.fSizedInternalFormat);
1164         writer->appendHexU32("e_format",
1165                              fConfigTable[i].fFormats.fExternalFormat[kOther_ExternalFormatUsage]);
1166         writer->appendHexU32(
1167                 "e_format_teximage",
1168                 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage]);
1169         writer->appendHexU32("e_type", fConfigTable[i].fFormats.fExternalType);
1170         writer->appendHexU32("i_for_teximage", fConfigTable[i].fFormats.fInternalFormatTexImage);
1171         writer->appendHexU32("i_for_renderbuffer",
1172                              fConfigTable[i].fFormats.fInternalFormatRenderbuffer);
1173         writer->endObject();
1174     }
1175 
1176     writer->endArray();
1177     writer->endObject();
1178 }
1179 
bgraIsInternalFormat() const1180 bool GrGLCaps::bgraIsInternalFormat() const {
1181     return fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_BGRA;
1182 }
1183 
getTexImageFormats(GrPixelConfig surfaceConfig,GrPixelConfig externalConfig,GrGLenum * internalFormat,GrGLenum * externalFormat,GrGLenum * externalType) const1184 bool GrGLCaps::getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1185                                   GrGLenum* internalFormat, GrGLenum* externalFormat,
1186                                   GrGLenum* externalType) const {
1187     if (!this->getExternalFormat(surfaceConfig, externalConfig, kTexImage_ExternalFormatUsage,
1188                                  externalFormat, externalType)) {
1189         return false;
1190     }
1191     *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1192     return true;
1193 }
1194 
getReadPixelsFormat(GrPixelConfig surfaceConfig,GrPixelConfig externalConfig,GrGLenum * externalFormat,GrGLenum * externalType) const1195 bool GrGLCaps::getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1196                                    GrGLenum* externalFormat, GrGLenum* externalType) const {
1197     if (!this->getExternalFormat(surfaceConfig, externalConfig, kOther_ExternalFormatUsage,
1198                                  externalFormat, externalType)) {
1199         return false;
1200     }
1201     return true;
1202 }
1203 
getRenderbufferFormat(GrPixelConfig config,GrGLenum * internalFormat) const1204 bool GrGLCaps::getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const {
1205     *internalFormat = fConfigTable[config].fFormats.fInternalFormatRenderbuffer;
1206     return true;
1207 }
1208 
getExternalFormat(GrPixelConfig surfaceConfig,GrPixelConfig memoryConfig,ExternalFormatUsage usage,GrGLenum * externalFormat,GrGLenum * externalType) const1209 bool GrGLCaps::getExternalFormat(GrPixelConfig surfaceConfig, GrPixelConfig memoryConfig,
1210                                  ExternalFormatUsage usage, GrGLenum* externalFormat,
1211                                  GrGLenum* externalType) const {
1212     SkASSERT(externalFormat && externalType);
1213 
1214     bool surfaceIsAlphaOnly = GrPixelConfigIsAlphaOnly(surfaceConfig);
1215     bool memoryIsAlphaOnly = GrPixelConfigIsAlphaOnly(memoryConfig);
1216 
1217     // We don't currently support moving RGBA data into and out of ALPHA surfaces. It could be
1218     // made to work in many cases using glPixelStore and what not but is not needed currently.
1219     if (surfaceIsAlphaOnly && !memoryIsAlphaOnly) {
1220         return false;
1221     }
1222 
1223     *externalFormat = fConfigTable[memoryConfig].fFormats.fExternalFormat[usage];
1224     *externalType = fConfigTable[memoryConfig].fFormats.fExternalType;
1225 
1226     // When GL_RED is supported as a texture format, our alpha-only textures are stored using
1227     // GL_RED and we swizzle in order to map all components to 'r'. However, in this case the
1228     // surface is not alpha-only and we want alpha to really mean the alpha component of the
1229     // texture, not the red component.
1230     if (memoryIsAlphaOnly && !surfaceIsAlphaOnly) {
1231         if (GR_GL_RED == *externalFormat) {
1232             *externalFormat = GR_GL_ALPHA;
1233         }
1234     }
1235 
1236     return true;
1237 }
1238 
initConfigTable(const GrContextOptions & contextOptions,const GrGLContextInfo & ctxInfo,const GrGLInterface * gli,GrShaderCaps * shaderCaps)1239 void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
1240                                const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
1241                                GrShaderCaps* shaderCaps) {
1242     /*
1243         Comments on renderability of configs on various GL versions.
1244           OpenGL < 3.0:
1245             no built in support for render targets.
1246             GL_EXT_framebuffer_object adds possible support for any sized format with base internal
1247               format RGB, RGBA and NV float formats we don't use.
1248               This is the following:
1249                 R3_G3_B2, RGB4, RGB5, RGB8, RGB10, RGB12, RGB16, RGBA2, RGBA4, RGB5_A1, RGBA8
1250                 RGB10_A2, RGBA12,RGBA16
1251               Though, it is hard to believe the more obscure formats such as RGBA12 would work
1252               since they aren't required by later standards and the driver can simply return
1253               FRAMEBUFFER_UNSUPPORTED for anything it doesn't allow.
1254             GL_ARB_framebuffer_object adds everything added by the EXT extension and additionally
1255               any sized internal format with a base internal format of ALPHA, LUMINANCE,
1256               LUMINANCE_ALPHA, INTENSITY, RED, and RG.
1257               This adds a lot of additional renderable sized formats, including ALPHA8.
1258               The GL_ARB_texture_rg brings in the RED and RG formats (8, 8I, 8UI, 16, 16I, 16UI,
1259               16F, 32I, 32UI, and 32F variants).
1260               Again, the driver has an escape hatch via FRAMEBUFFER_UNSUPPORTED.
1261 
1262             For both the above extensions we limit ourselves to those that are also required by
1263             OpenGL 3.0.
1264 
1265           OpenGL 3.0:
1266             Any format with base internal format ALPHA, RED, RG, RGB or RGBA is "color-renderable"
1267             but are not required to be supported as renderable textures/renderbuffer.
1268             Required renderable color formats:
1269                 - RGBA32F, RGBA32I, RGBA32UI, RGBA16, RGBA16F, RGBA16I,
1270                   RGBA16UI, RGBA8, RGBA8I, RGBA8UI, SRGB8_ALPHA8, and
1271                   RGB10_A2.
1272                 - R11F_G11F_B10F.
1273                 - RG32F, RG32I, RG32UI, RG16, RG16F, RG16I, RG16UI, RG8, RG8I,
1274                   and RG8UI.
1275                 - R32F, R32I, R32UI, R16F, R16I, R16UI, R16, R8, R8I, and R8UI.
1276                 - ALPHA8
1277 
1278           OpenGL 3.1, 3.2, 3.3
1279             Same as 3.0 except ALPHA8 requires GL_ARB_compatibility/compatibility profile.
1280           OpengGL 3.3, 4.0, 4.1
1281             Adds RGB10_A2UI.
1282           OpengGL 4.2
1283             Adds
1284                 - RGB5_A1, RGBA4
1285                 - RGB565
1286           OpenGL 4.4
1287             Does away with the separate list and adds a column to the sized internal color format
1288             table. However, no new formats become required color renderable.
1289 
1290           ES 2.0
1291             color renderable: RGBA4, RGB5_A1, RGB565
1292             GL_EXT_texture_rg adds support for R8, RG5 as a color render target
1293             GL_OES_rgb8_rgba8 adds support for RGB8 and RGBA8
1294             GL_ARM_rgba8 adds support for RGBA8 (but not RGB8)
1295             GL_EXT_texture_format_BGRA8888 does not add renderbuffer support
1296             GL_CHROMIUM_renderbuffer_format_BGRA8888 adds BGRA8 as color-renderable
1297             GL_APPLE_texture_format_BGRA8888 does not add renderbuffer support
1298 
1299           ES 3.0
1300                 - RGBA32I, RGBA32UI, RGBA16I, RGBA16UI, RGBA8, RGBA8I,
1301                   RGBA8UI, SRGB8_ALPHA8, RGB10_A2, RGB10_A2UI, RGBA4, and
1302                   RGB5_A1.
1303                 - RGB8 and RGB565.
1304                 - RG32I, RG32UI, RG16I, RG16UI, RG8, RG8I, and RG8UI.
1305                 - R32I, R32UI, R16I, R16UI, R8, R8I, and R8UI
1306           ES 3.1
1307             Adds RGB10_A2, RGB10_A2UI,
1308           ES 3.2
1309             Adds R16F, RG16F, RGBA16F, R32F, RG32F, RGBA32F, R11F_G11F_B10F.
1310     */
1311 
1312     // Correctness workarounds.
1313     bool disableTextureRedForMesa = false;
1314     bool disableSRGBForX86PowerVR = false;
1315     bool disableSRGBWriteControlForAdreno4xx = false;
1316     bool disableR8TexStorageForANGLEGL = false;
1317     bool disableSRGBRenderWithMSAAForMacAMD = false;
1318 
1319     if (!contextOptions.fDisableDriverCorrectnessWorkarounds) {
1320         // ARB_texture_rg is part of OpenGL 3.0, but osmesa doesn't support GL_RED
1321         // and GL_RG on FBO textures.
1322         disableTextureRedForMesa = kOSMesa_GrGLRenderer == ctxInfo.renderer();
1323 
1324         bool isX86PowerVR = false;
1325 #if defined(SK_CPU_X86)
1326         if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
1327             isX86PowerVR = true;
1328         }
1329 #endif
1330         // NexusPlayer has strange bugs with sRGB (skbug.com/4148). This is a targeted fix to
1331         // blacklist that device (and any others that might be sharing the same driver).
1332         disableSRGBForX86PowerVR = isX86PowerVR;
1333         disableSRGBWriteControlForAdreno4xx = kAdreno4xx_GrGLRenderer == ctxInfo.renderer();
1334 
1335         // Angle with es2->GL has a bug where it will hang trying to call TexSubImage on GL_R8
1336         // formats on miplevels > 0. We already disable texturing on gles > 2.0 so just need to
1337         // check that we are not going to OpenGL.
1338         disableR8TexStorageForANGLEGL = GrGLANGLEBackend::kOpenGL == ctxInfo.angleBackend();
1339 
1340         // MacPro devices with AMD cards fail to create MSAA sRGB render buffers.
1341 #if defined(SK_BUILD_FOR_MAC)
1342         disableSRGBRenderWithMSAAForMacAMD = kATI_GrGLVendor == ctxInfo.vendor();
1343 #endif
1344     }
1345 
1346     uint32_t nonMSAARenderFlags = ConfigInfo::kRenderable_Flag |
1347                                   ConfigInfo::kFBOColorAttachment_Flag;
1348     uint32_t allRenderFlags = nonMSAARenderFlags;
1349     if (kNone_MSFBOType != fMSFBOType) {
1350         allRenderFlags |= ConfigInfo::kRenderableWithMSAA_Flag;
1351     }
1352     GrGLStandard standard = ctxInfo.standard();
1353     GrGLVersion version = ctxInfo.version();
1354 
1355     bool texStorageSupported = false;
1356     if (kGL_GrGLStandard == standard) {
1357         // The EXT version can apply to either GL or GLES.
1358         texStorageSupported = version >= GR_GL_VER(4,2) ||
1359                               ctxInfo.hasExtension("GL_ARB_texture_storage") ||
1360                               ctxInfo.hasExtension("GL_EXT_texture_storage");
1361     } else {
1362         texStorageSupported = version >= GR_GL_VER(3,0) ||
1363                               ctxInfo.hasExtension("GL_EXT_texture_storage");
1364     }
1365 
1366     bool texelBufferSupport = this->shaderCaps()->texelBufferSupport();
1367 
1368     bool textureRedSupport = false;
1369 
1370     if (!disableTextureRedForMesa) {
1371         if (kGL_GrGLStandard == standard) {
1372             textureRedSupport =
1373                     version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_rg");
1374         } else {
1375             textureRedSupport =
1376                     version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_texture_rg");
1377         }
1378     }
1379 
1380     fConfigTable[kUnknown_GrPixelConfig].fFormats.fBaseInternalFormat = 0;
1381     fConfigTable[kUnknown_GrPixelConfig].fFormats.fSizedInternalFormat = 0;
1382     fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
1383     fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalType = 0;
1384     fConfigTable[kUnknown_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1385     fConfigTable[kUnknown_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1386 
1387     fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1388     fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1389     fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1390         GR_GL_RGBA;
1391     fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1392     fConfigTable[kRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1393     fConfigTable[kRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1394     if (kGL_GrGLStandard == standard) {
1395         // We require some form of FBO support and all GLs with FBO support can render to RGBA8
1396         fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
1397     } else {
1398         if (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
1399             ctxInfo.hasExtension("GL_ARM_rgba8")) {
1400             fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
1401         }
1402     }
1403     if (texStorageSupported) {
1404         fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1405     }
1406     if (texelBufferSupport) {
1407         fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1408     }
1409     fConfigTable[kRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1410 
1411     fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1412         GR_GL_BGRA;
1413     fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalType  = GR_GL_UNSIGNED_BYTE;
1414     fConfigTable[kBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1415 
1416    // TexStorage requires using a sized internal format and BGRA8 is only supported if we have the
1417    // GL_APPLE_texture_format_BGRA8888 extension or if we have GL_EXT_texutre_storage and
1418    // GL_EXT_texture_format_BGRA8888.
1419     bool supportsBGRATexStorage = false;
1420 
1421     if (kGL_GrGLStandard == standard) {
1422         fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1423         fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1424         if (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra")) {
1425             // Since the internal format is RGBA8, it is also renderable.
1426             fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1427                                                             allRenderFlags;
1428         }
1429         // Since we are using RGBA8 we can use tex storage.
1430         supportsBGRATexStorage = true;
1431     } else {
1432         fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_BGRA;
1433         fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_BGRA8;
1434         if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
1435             // This APPLE extension introduces complexity on ES2. It leaves the internal format
1436             // as RGBA, but allows BGRA as the external format. From testing, it appears that the
1437             // driver remembers the external format when the texture is created (with TexImage).
1438             // If you then try to upload data in the other swizzle (with TexSubImage), it fails.
1439             // We could work around this, but it adds even more state tracking to code that is
1440             // already too tricky. Instead, we opt not to support BGRA on ES2 with this extension.
1441             // This also side-steps some ambiguous interactions with the texture storage extension.
1442             if (version >= GR_GL_VER(3,0)) {
1443                 // The APPLE extension doesn't make this renderable.
1444                 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1445                 supportsBGRATexStorage = true;
1446             }
1447         } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
1448             fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1449                                                             nonMSAARenderFlags;
1450 
1451             if (ctxInfo.hasExtension("GL_EXT_texture_storage")) {
1452                 supportsBGRATexStorage = true;
1453             }
1454             if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888") &&
1455                 (this->usesMSAARenderBuffers() || this->fMSFBOType == kMixedSamples_MSFBOType)) {
1456                 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |=
1457                     ConfigInfo::kRenderableWithMSAA_Flag;
1458             }
1459         }
1460     }
1461 
1462     if (texStorageSupported && supportsBGRATexStorage) {
1463         fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1464     }
1465     fConfigTable[kBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1466 
1467     // We only enable srgb support if both textures and FBOs support srgb,
1468     // *and* we can disable sRGB decode-on-read, to support "legacy" mode.
1469     if (kGL_GrGLStandard == standard) {
1470         if (ctxInfo.version() >= GR_GL_VER(3,0)) {
1471             fSRGBSupport = true;
1472         } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
1473             if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
1474                 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
1475                 fSRGBSupport = true;
1476             }
1477         }
1478         // All the above srgb extensions support toggling srgb writes
1479         if (fSRGBSupport) {
1480             fSRGBWriteControl = true;
1481         }
1482     } else {
1483         fSRGBSupport = ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB");
1484         if (disableSRGBForX86PowerVR) {
1485             fSRGBSupport = false;
1486         }
1487         // ES through 3.1 requires EXT_srgb_write_control to support toggling
1488         // sRGB writing for destinations.
1489         // See https://bug.skia.org/5329 for Adreno4xx issue.
1490         fSRGBWriteControl = !disableSRGBWriteControlForAdreno4xx &&
1491             ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
1492     }
1493     if (contextOptions.fRequireDecodeDisableForSRGB && !fSRGBDecodeDisableSupport) {
1494         // To support "legacy" L32 mode, we require the ability to turn off sRGB decode. Clients
1495         // can opt-out of that requirement, if they intend to always do linear blending.
1496         fSRGBSupport = false;
1497     }
1498 
1499     // This is very conservative, if we're on a platform where N32 is BGRA, and using ES, disable
1500     // all sRGB support. Too much code relies on creating surfaces with N32 + sRGB colorspace,
1501     // and sBGRA is basically impossible to support on any version of ES (with our current code).
1502     // In particular, ES2 doesn't support sBGRA at all, and even in ES3, there is no valid pair
1503     // of formats that can be used for TexImage calls to upload BGRA data to sRGBA (which is what
1504     // we *have* to use as the internal format, because sBGRA doesn't exist). This primarily
1505     // affects Windows.
1506     if (kSkia8888_GrPixelConfig == kBGRA_8888_GrPixelConfig && kGLES_GrGLStandard == standard) {
1507         fSRGBSupport = false;
1508     }
1509 
1510     // ES2 Command Buffer has several TexStorage restrictions. It appears to fail for any format
1511     // not explicitly allowed by GL_EXT_texture_storage, particularly those from other extensions.
1512     bool isCommandBufferES2 = kChromium_GrGLDriver == ctxInfo.driver() && version < GR_GL_VER(3, 0);
1513 
1514     uint32_t srgbRenderFlags = allRenderFlags;
1515     if (disableSRGBRenderWithMSAAForMacAMD) {
1516         srgbRenderFlags &= ~ConfigInfo::kRenderableWithMSAA_Flag;
1517     }
1518 
1519     fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1520     fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1521     // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1522     // external format is GL_RGBA. See below for note about ES2.0 and glTex[Sub]Image.
1523     fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1524         GR_GL_RGBA;
1525     fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1526     fConfigTable[kSRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1527     if (fSRGBSupport) {
1528         fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1529                                                          srgbRenderFlags;
1530     }
1531     // ES2 Command Buffer does not allow TexStorage with SRGB8_ALPHA8_EXT
1532     if (texStorageSupported && !isCommandBufferES2) {
1533         fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1534     }
1535     fConfigTable[kSRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1536     // sBGRA is not a "real" thing in OpenGL, but GPUs support it, and on platforms where
1537     // kN32 == BGRA, we need some way to work with it. (The default framebuffer on Windows
1538     // is in this format, for example).
1539     fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1540     fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1541     // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1542     // external format is GL_BGRA.
1543     fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1544         GR_GL_BGRA;
1545     fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1546     fConfigTable[kSBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1547     if (fSRGBSupport && kGL_GrGLStandard == standard) {
1548         fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1549                                                          srgbRenderFlags;
1550     }
1551 
1552     if (texStorageSupported) {
1553         fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1554     }
1555     fConfigTable[kSBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1556 
1557     fConfigTable[kRGB_565_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1558     if (this->ES2CompatibilitySupport()) {
1559         fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB565;
1560     } else {
1561         fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB5;
1562     }
1563     fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1564         GR_GL_RGB;
1565     fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_5_6_5;
1566     fConfigTable[kRGB_565_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1567     fConfigTable[kRGB_565_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1568     if (kGL_GrGLStandard == standard) {
1569         if (version >= GR_GL_VER(4, 2) || ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
1570             fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1571         }
1572     } else {
1573         fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1574     }
1575     // 565 is not a sized internal format on desktop GL. So on desktop with
1576     // 565 we always use an unsized internal format to let the system pick
1577     // the best sized format to convert the 565 data to. Since TexStorage
1578     // only allows sized internal formats we disallow it.
1579     //
1580     // TODO: As of 4.2, regular GL supports 565. This logic is due for an
1581     // update.
1582     if (texStorageSupported && kGL_GrGLStandard != standard) {
1583         fConfigTable[kRGB_565_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1584     }
1585     fConfigTable[kRGB_565_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1586 
1587     fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1588     fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA4;
1589     fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1590         GR_GL_RGBA;
1591     fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
1592     fConfigTable[kRGBA_4444_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1593     fConfigTable[kRGBA_4444_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1594     if (kGL_GrGLStandard == standard) {
1595         if (version >= GR_GL_VER(4, 2)) {
1596             fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1597         }
1598     } else {
1599         fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1600     }
1601     if (texStorageSupported) {
1602         fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1603     }
1604     fConfigTable[kRGBA_4444_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1605 
1606     bool alpha8IsValidForGL = kGL_GrGLStandard == standard &&
1607             (!fIsCoreProfile || version <= GR_GL_VER(3, 0));
1608 
1609     ConfigInfo& alphaInfo = fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig];
1610     alphaInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1611     alphaInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1612     if (alpha8IsValidForGL || (kGL_GrGLStandard != standard && version < GR_GL_VER(3, 0))) {
1613         alphaInfo.fFlags = ConfigInfo::kTextureable_Flag;
1614     }
1615     alphaInfo.fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1616     alphaInfo.fFormats.fSizedInternalFormat = GR_GL_ALPHA8;
1617     alphaInfo.fFormats.fExternalFormat[kOther_ExternalFormatUsage] = GR_GL_ALPHA;
1618     alphaInfo.fSwizzle = GrSwizzle::AAAA();
1619     if (fAlpha8IsRenderable && alpha8IsValidForGL) {
1620         alphaInfo.fFlags |= allRenderFlags;
1621     }
1622 
1623     ConfigInfo& redInfo = fConfigTable[kAlpha_8_as_Red_GrPixelConfig];
1624     redInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1625     redInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1626     redInfo.fFormats.fBaseInternalFormat = GR_GL_RED;
1627     redInfo.fFormats.fSizedInternalFormat = GR_GL_R8;
1628     redInfo.fFormats.fExternalFormat[kOther_ExternalFormatUsage] = GR_GL_RED;
1629     redInfo.fSwizzle = GrSwizzle::RRRR();
1630 
1631     // ES2 Command Buffer does not allow TexStorage with R8_EXT (so Alpha_8 and Gray_8)
1632     if (texStorageSupported && !isCommandBufferES2) {
1633         if (!disableR8TexStorageForANGLEGL) {
1634             alphaInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1635         }
1636         redInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1637     }
1638 
1639     if (textureRedSupport) {
1640         redInfo.fFlags |= ConfigInfo::kTextureable_Flag | allRenderFlags;
1641         if (texelBufferSupport) {
1642             redInfo.fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1643         }
1644 
1645         fConfigTable[kAlpha_8_GrPixelConfig] = redInfo;
1646     } else {
1647         redInfo.fFlags = 0;
1648 
1649         fConfigTable[kAlpha_8_GrPixelConfig] = alphaInfo;
1650     }
1651 
1652     ConfigInfo& grayLumInfo = fConfigTable[kGray_8_as_Lum_GrPixelConfig];
1653     grayLumInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1654     grayLumInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1655     grayLumInfo.fFormats.fBaseInternalFormat = GR_GL_LUMINANCE;
1656     grayLumInfo.fFormats.fSizedInternalFormat = GR_GL_LUMINANCE8;
1657     grayLumInfo.fFormats.fExternalFormat[kOther_ExternalFormatUsage] = GR_GL_LUMINANCE;
1658     grayLumInfo.fSwizzle = GrSwizzle::RGBA();
1659     if ((standard == kGL_GrGLStandard && version <= GR_GL_VER(3, 0)) ||
1660         (standard == kGLES_GrGLStandard && version < GR_GL_VER(3, 0))) {
1661         grayLumInfo.fFlags = ConfigInfo::kTextureable_Flag;
1662     }
1663 
1664     ConfigInfo& grayRedInfo = fConfigTable[kGray_8_as_Red_GrPixelConfig];
1665     grayRedInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1666     grayRedInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1667     grayRedInfo.fFormats.fBaseInternalFormat = GR_GL_RED;
1668     grayRedInfo.fFormats.fSizedInternalFormat = GR_GL_R8;
1669     grayRedInfo.fFormats.fExternalFormat[kOther_ExternalFormatUsage] = GR_GL_RED;
1670     grayRedInfo.fSwizzle = GrSwizzle::RRRA();
1671     grayRedInfo.fFlags = ConfigInfo::kTextureable_Flag;
1672 
1673 #if 0 // Leaving Gray8 as non-renderable, to keep things simple and match raster. Needs to be
1674       // updated to support Gray8_as_Lum and Gray8_as_red if this is ever enabled.
1675     if (this->textureRedSupport() ||
1676         (kDesktop_ARB_MSFBOType == this->msFBOType() &&
1677          ctxInfo.renderer() != kOSMesa_GrGLRenderer)) {
1678         // desktop ARB extension/3.0+ supports LUMINANCE8 as renderable.
1679         // However, osmesa fails if it used even when GL_ARB_framebuffer_object is present.
1680         // Core profile removes LUMINANCE8 support, but we should have chosen R8 in that case.
1681         fConfigTable[kGray_8_GrPixelConfig].fFlags |= allRenderFlags;
1682     }
1683 #endif
1684     if (texStorageSupported && !isCommandBufferES2) {
1685         if (!disableR8TexStorageForANGLEGL) {
1686             grayLumInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1687         }
1688         grayRedInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1689     }
1690 
1691     if (textureRedSupport) {
1692         if (texelBufferSupport) {
1693             grayRedInfo.fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1694         }
1695         fConfigTable[kGray_8_GrPixelConfig] = grayRedInfo;
1696     } else {
1697         grayRedInfo.fFlags = 0;
1698         fConfigTable[kGray_8_GrPixelConfig] = grayLumInfo;
1699     }
1700 
1701     // Check for [half] floating point texture support
1702     // NOTE: We disallow floating point textures on ES devices if linear filtering modes are not
1703     // supported. This is for simplicity, but a more granular approach is possible. Coincidentally,
1704     // [half] floating point textures became part of the standard in ES3.1 / OGL 3.0.
1705     bool hasFPTextures = false;
1706     bool hasHalfFPTextures = false;
1707     bool rgIsTexturable = false;
1708     // for now we don't support floating point MSAA on ES
1709     uint32_t fpRenderFlags = (kGL_GrGLStandard == standard) ? allRenderFlags : nonMSAARenderFlags;
1710 
1711     if (kGL_GrGLStandard == standard) {
1712         if (version >= GR_GL_VER(3, 0)) {
1713             hasFPTextures = true;
1714             hasHalfFPTextures = true;
1715             rgIsTexturable = true;
1716         }
1717     } else {
1718         if (version >= GR_GL_VER(3, 0)) {
1719             hasFPTextures = true;
1720             hasHalfFPTextures = true;
1721             rgIsTexturable = true;
1722         } else {
1723             if (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
1724                 ctxInfo.hasExtension("GL_OES_texture_float")) {
1725                 hasFPTextures = true;
1726             }
1727             if (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
1728                 ctxInfo.hasExtension("GL_OES_texture_half_float")) {
1729                 hasHalfFPTextures = true;
1730             }
1731         }
1732     }
1733 
1734     for (auto fpconfig : {kRGBA_float_GrPixelConfig, kRG_float_GrPixelConfig}) {
1735         const GrGLenum format = kRGBA_float_GrPixelConfig == fpconfig ? GR_GL_RGBA : GR_GL_RG;
1736         fConfigTable[fpconfig].fFormats.fBaseInternalFormat = format;
1737         fConfigTable[fpconfig].fFormats.fSizedInternalFormat =
1738             kRGBA_float_GrPixelConfig == fpconfig ? GR_GL_RGBA32F : GR_GL_RG32F;
1739         fConfigTable[fpconfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = format;
1740         fConfigTable[fpconfig].fFormats.fExternalType = GR_GL_FLOAT;
1741         fConfigTable[fpconfig].fFormatType = kFloat_FormatType;
1742         if (hasFPTextures) {
1743             fConfigTable[fpconfig].fFlags = rgIsTexturable ? ConfigInfo::kTextureable_Flag : 0;
1744             // For now we only enable rendering to float on desktop, because on ES we'd have to
1745             // solve many precision issues and no clients actually want this yet.
1746             if (kGL_GrGLStandard == standard /* || version >= GR_GL_VER(3,2) ||
1747                 ctxInfo.hasExtension("GL_EXT_color_buffer_float")*/) {
1748                 fConfigTable[fpconfig].fFlags |= fpRenderFlags;
1749             }
1750         }
1751         if (texStorageSupported) {
1752             fConfigTable[fpconfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1753         }
1754         if (texelBufferSupport) {
1755             fConfigTable[fpconfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1756         }
1757         fConfigTable[fpconfig].fSwizzle = GrSwizzle::RGBA();
1758     }
1759 
1760     GrGLenum redHalfExternalType;
1761     if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
1762         redHalfExternalType = GR_GL_HALF_FLOAT;
1763     } else {
1764         redHalfExternalType = GR_GL_HALF_FLOAT_OES;
1765     }
1766     ConfigInfo& redHalf = fConfigTable[kAlpha_half_as_Red_GrPixelConfig];
1767     redHalf.fFormats.fExternalType = redHalfExternalType;
1768     redHalf.fFormatType = kFloat_FormatType;
1769     redHalf.fFormats.fBaseInternalFormat = GR_GL_RED;
1770     redHalf.fFormats.fSizedInternalFormat = GR_GL_R16F;
1771     redHalf.fFormats.fExternalFormat[kOther_ExternalFormatUsage] = GR_GL_RED;
1772     redHalf.fSwizzle = GrSwizzle::RRRR();
1773     if (textureRedSupport && hasHalfFPTextures) {
1774         redHalf.fFlags = ConfigInfo::kTextureable_Flag;
1775 
1776         if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3, 2) ||
1777             (textureRedSupport && ctxInfo.hasExtension("GL_EXT_color_buffer_half_float"))) {
1778             redHalf.fFlags |= fpRenderFlags;
1779         }
1780 
1781         if (texStorageSupported && !isCommandBufferES2) {
1782             redHalf.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1783         }
1784 
1785         if (texelBufferSupport) {
1786             redHalf.fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1787         }
1788     }
1789     fConfigTable[kAlpha_half_GrPixelConfig] = redHalf;
1790 
1791     fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1792     fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA16F;
1793     fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1794         GR_GL_RGBA;
1795     if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
1796         fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1797     } else {
1798         fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1799     }
1800     fConfigTable[kRGBA_half_GrPixelConfig].fFormatType = kFloat_FormatType;
1801     if (hasHalfFPTextures) {
1802         fConfigTable[kRGBA_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1803         // ES requires 3.2 or EXT_color_buffer_half_float.
1804         if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3,2) ||
1805              ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
1806             fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= fpRenderFlags;
1807         }
1808     }
1809     if (texStorageSupported) {
1810         fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1811     }
1812     if (texelBufferSupport) {
1813         fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1814     }
1815     fConfigTable[kRGBA_half_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1816 
1817     // Bulk populate the texture internal/external formats here and then deal with exceptions below.
1818 
1819     // ES 2.0 requires that the internal/external formats match.
1820     bool useSizedTexFormats = (kGL_GrGLStandard == ctxInfo.standard() ||
1821                                ctxInfo.version() >= GR_GL_VER(3,0));
1822     // All ES versions (thus far) require sized internal formats for render buffers.
1823     // TODO: Always use sized internal format?
1824     bool useSizedRbFormats = kGLES_GrGLStandard == ctxInfo.standard();
1825 
1826     for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1827         // Almost always we want to pass fExternalFormat[kOther_ExternalFormatUsage] as the <format>
1828         // param to glTex[Sub]Image.
1829         fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
1830             fConfigTable[i].fFormats.fExternalFormat[kOther_ExternalFormatUsage];
1831         fConfigTable[i].fFormats.fInternalFormatTexImage = useSizedTexFormats ?
1832             fConfigTable[i].fFormats.fSizedInternalFormat :
1833             fConfigTable[i].fFormats.fBaseInternalFormat;
1834         fConfigTable[i].fFormats.fInternalFormatRenderbuffer = useSizedRbFormats ?
1835             fConfigTable[i].fFormats.fSizedInternalFormat :
1836             fConfigTable[i].fFormats.fBaseInternalFormat;
1837     }
1838     // If we're on ES 3.0+ but because of a driver workaround selected GL_ALPHA to implement the
1839     // kAlpha_8_GrPixelConfig then we actually have to use a base internal format rather than a
1840     // sized internal format. This is because there is no valid 8 bit alpha sized internal format
1841     // in ES.
1842     if (useSizedTexFormats && kGLES_GrGLStandard == ctxInfo.standard() && !textureRedSupport) {
1843         SkASSERT(fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_ALPHA8);
1844         SkASSERT(fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fBaseInternalFormat ==
1845                      GR_GL_ALPHA8);
1846         fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fInternalFormatTexImage =
1847             fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat;
1848         fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fInternalFormatTexImage =
1849             fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fBaseInternalFormat;
1850     }
1851 
1852     // OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the <format>
1853     // param to Tex(Sub)Image. ES 2.0 requires the <internalFormat> and <format> params to match.
1854     // Thus, on ES 2.0 we will use GL_SRGB_ALPHA as the <format> param.
1855     // On OpenGL and ES 3.0+ GL_SRGB_ALPHA does not work for the <format> param to glTexImage.
1856     if (ctxInfo.standard() == kGLES_GrGLStandard && ctxInfo.version() == GR_GL_VER(2,0)) {
1857         fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
1858             GR_GL_SRGB_ALPHA;
1859 
1860         // Additionally, because we had to "invent" sBGRA, there is no way to make it work
1861         // in ES 2.0, because there is no <internalFormat> we can use. So just make that format
1862         // unsupported. (If we have no sRGB support at all, this will get overwritten below).
1863         fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = 0;
1864     }
1865 
1866     // If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image
1867     // as a base format.
1868     // GL_EXT_texture_format_BGRA8888:
1869     //      This extension GL_BGRA as an unsized internal format. However, it is written against ES
1870     //      2.0 and therefore doesn't define a value for GL_BGRA8 as ES 2.0 uses unsized internal
1871     //      formats.
1872     // GL_APPLE_texture_format_BGRA8888:
1873     //     ES 2.0: the extension makes BGRA an external format but not an internal format.
1874     //     ES 3.0: the extension explicitly states GL_BGRA8 is not a valid internal format for
1875     //             glTexImage (just for glTexStorage).
1876     if (useSizedTexFormats && this->bgraIsInternalFormat()) {
1877         fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fInternalFormatTexImage = GR_GL_BGRA;
1878     }
1879 
1880     // If we don't have texture swizzle support then the shader generator must insert the
1881     // swizzle into shader code.
1882     if (!this->textureSwizzleSupport()) {
1883         for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1884             shaderCaps->fConfigTextureSwizzle[i] = fConfigTable[i].fSwizzle;
1885         }
1886     }
1887 
1888     // Shader output swizzles will default to RGBA. When we've use GL_RED instead of GL_ALPHA to
1889     // implement kAlpha_8_GrPixelConfig we need to swizzle the shader outputs so the alpha channel
1890     // gets written to the single component.
1891     if (textureRedSupport) {
1892         for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1893             GrPixelConfig config = static_cast<GrPixelConfig>(i);
1894             if (GrPixelConfigIsAlphaOnly(config) &&
1895                 fConfigTable[i].fFormats.fBaseInternalFormat == GR_GL_RED) {
1896                 shaderCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA();
1897             }
1898         }
1899     }
1900 
1901     for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1902         if (ConfigInfo::kRenderableWithMSAA_Flag & fConfigTable[i].fFlags) {
1903             // We assume that MSAA rendering is supported only if we support non-MSAA rendering.
1904             SkASSERT(ConfigInfo::kRenderable_Flag & fConfigTable[i].fFlags);
1905             if ((kGL_GrGLStandard == ctxInfo.standard() &&
1906                  (ctxInfo.version() >= GR_GL_VER(4,2) ||
1907                   ctxInfo.hasExtension("GL_ARB_internalformat_query"))) ||
1908                 (kGLES_GrGLStandard == ctxInfo.standard() && ctxInfo.version() >= GR_GL_VER(3,0))) {
1909                 int count;
1910                 GrGLenum format = fConfigTable[i].fFormats.fInternalFormatRenderbuffer;
1911                 GR_GL_GetInternalformativ(gli, GR_GL_RENDERBUFFER, format, GR_GL_NUM_SAMPLE_COUNTS,
1912                                           1, &count);
1913                 if (count) {
1914                     int* temp = new int[count];
1915                     GR_GL_GetInternalformativ(gli, GR_GL_RENDERBUFFER, format, GR_GL_SAMPLES, count,
1916                                               temp);
1917                     // GL has a concept of MSAA rasterization with a single sample but we do not.
1918                     if (count && temp[count - 1] == 1) {
1919                         --count;
1920                         SkASSERT(!count || temp[count -1] > 1);
1921                     }
1922                     fConfigTable[i].fColorSampleCounts.setCount(count+1);
1923                     // We initialize our supported values with 1 (no msaa) and reverse the order
1924                     // returned by GL so that the array is ascending.
1925                     fConfigTable[i].fColorSampleCounts[0] = 1;
1926                     for (int j = 0; j < count; ++j) {
1927                         fConfigTable[i].fColorSampleCounts[j+1] = temp[count - j - 1];
1928                     }
1929                     delete[] temp;
1930                 }
1931             } else {
1932                 // Fake out the table using some semi-standard counts up to the max allowed sample
1933                 // count.
1934                 int maxSampleCnt = 1;
1935                 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
1936                     GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &maxSampleCnt);
1937                 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
1938                     GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &maxSampleCnt);
1939                 }
1940                 // Chrome has a mock GL implementation that returns 0.
1941                 maxSampleCnt = SkTMax(1, maxSampleCnt);
1942 
1943                 static constexpr int kDefaultSamples[] = {1, 2, 4, 8};
1944                 int count = SK_ARRAY_COUNT(kDefaultSamples);
1945                 for (; count > 0; --count) {
1946                     if (kDefaultSamples[count - 1] <= maxSampleCnt) {
1947                         break;
1948                     }
1949                 }
1950                 if (count > 0) {
1951                     fConfigTable[i].fColorSampleCounts.append(count, kDefaultSamples);
1952                 }
1953             }
1954         } else if (ConfigInfo::kRenderable_Flag & fConfigTable[i].fFlags) {
1955             fConfigTable[i].fColorSampleCounts.setCount(1);
1956             fConfigTable[i].fColorSampleCounts[0] = 1;
1957         }
1958     }
1959 
1960 #ifdef SK_DEBUG
1961     // Make sure we initialized everything.
1962     ConfigInfo defaultEntry;
1963     for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1964         // Make sure we didn't set renderable and not blittable or renderable with msaa and not
1965         // renderable.
1966         SkASSERT(!((ConfigInfo::kRenderable_Flag) && !(ConfigInfo::kFBOColorAttachment_Flag)));
1967         SkASSERT(!((ConfigInfo::kRenderableWithMSAA_Flag) && !(ConfigInfo::kRenderable_Flag)));
1968         SkASSERT(defaultEntry.fFormats.fBaseInternalFormat !=
1969                  fConfigTable[i].fFormats.fBaseInternalFormat);
1970         SkASSERT(defaultEntry.fFormats.fSizedInternalFormat !=
1971                  fConfigTable[i].fFormats.fSizedInternalFormat);
1972         for (int j = 0; j < kExternalFormatUsageCnt; ++j) {
1973             SkASSERT(defaultEntry.fFormats.fExternalFormat[j] !=
1974                      fConfigTable[i].fFormats.fExternalFormat[j]);
1975         }
1976         SkASSERT(defaultEntry.fFormats.fExternalType != fConfigTable[i].fFormats.fExternalType);
1977     }
1978 #endif
1979 }
1980 
initDescForDstCopy(const GrRenderTargetProxy * src,GrSurfaceDesc * desc,bool * rectsMustMatch,bool * disallowSubrect) const1981 bool GrGLCaps::initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
1982                                   bool* rectsMustMatch, bool* disallowSubrect) const {
1983     // By default, we don't require rects to match.
1984     *rectsMustMatch = false;
1985 
1986     // By default, we allow subrects.
1987     *disallowSubrect = false;
1988 
1989     // If the src is a texture, we can implement the blit as a draw assuming the config is
1990     // renderable.
1991     if (src->asTextureProxy() && !this->isConfigRenderable(src->config())) {
1992         desc->fOrigin = kBottomLeft_GrSurfaceOrigin;
1993         desc->fFlags = kRenderTarget_GrSurfaceFlag;
1994         desc->fConfig = src->config();
1995         return true;
1996     }
1997 
1998     {
1999         // The only way we could see a non-GR_GL_TEXTURE_2D texture would be if it were
2000         // wrapped. In that case the proxy would already be instantiated.
2001         const GrTexture* srcTexture = src->priv().peekTexture();
2002         const GrGLTexture* glSrcTexture = static_cast<const GrGLTexture*>(srcTexture);
2003         if (glSrcTexture && glSrcTexture->target() != GR_GL_TEXTURE_2D) {
2004             // Not supported for FBO blit or CopyTexSubImage
2005             return false;
2006         }
2007     }
2008 
2009     // We look for opportunities to use CopyTexSubImage, or fbo blit. If neither are
2010     // possible and we return false to fallback to creating a render target dst for render-to-
2011     // texture. This code prefers CopyTexSubImage to fbo blit and avoids triggering temporary fbo
2012     // creation. It isn't clear that avoiding temporary fbo creation is actually optimal.
2013     GrSurfaceOrigin originForBlitFramebuffer = kTopLeft_GrSurfaceOrigin;
2014     bool rectsMustMatchForBlitFramebuffer = false;
2015     bool disallowSubrectForBlitFramebuffer = false;
2016     if (src->numColorSamples() > 1 &&
2017         (this->blitFramebufferSupportFlags() & kResolveMustBeFull_BlitFrambufferFlag)) {
2018         rectsMustMatchForBlitFramebuffer = true;
2019         disallowSubrectForBlitFramebuffer = true;
2020         // Mirroring causes rects to mismatch later, don't allow it.
2021         originForBlitFramebuffer = src->origin();
2022     } else if (src->numColorSamples() > 1 && (this->blitFramebufferSupportFlags() &
2023                                               kRectsMustMatchForMSAASrc_BlitFramebufferFlag)) {
2024         rectsMustMatchForBlitFramebuffer = true;
2025         // Mirroring causes rects to mismatch later, don't allow it.
2026         originForBlitFramebuffer = src->origin();
2027     } else if (this->blitFramebufferSupportFlags() & kNoScalingOrMirroring_BlitFramebufferFlag) {
2028         originForBlitFramebuffer = src->origin();
2029     }
2030 
2031     // Check for format issues with glCopyTexSubImage2D
2032     if (this->bgraIsInternalFormat() && kBGRA_8888_GrPixelConfig == src->config()) {
2033         // glCopyTexSubImage2D doesn't work with this config. If the bgra can be used with fbo blit
2034         // then we set up for that, otherwise fail.
2035         if (this->canConfigBeFBOColorAttachment(kBGRA_8888_GrPixelConfig)) {
2036             desc->fOrigin = originForBlitFramebuffer;
2037             desc->fConfig = kBGRA_8888_GrPixelConfig;
2038             *rectsMustMatch = rectsMustMatchForBlitFramebuffer;
2039             *disallowSubrect = disallowSubrectForBlitFramebuffer;
2040             return true;
2041         }
2042         return false;
2043     }
2044 
2045     {
2046         bool srcIsMSAARenderbuffer = GrFSAAType::kUnifiedMSAA == src->fsaaType() &&
2047                                      this->usesMSAARenderBuffers();
2048         if (srcIsMSAARenderbuffer) {
2049             // It's illegal to call CopyTexSubImage2D on a MSAA renderbuffer. Set up for FBO
2050             // blit or fail.
2051             if (this->canConfigBeFBOColorAttachment(src->config())) {
2052                 desc->fOrigin = originForBlitFramebuffer;
2053                 desc->fConfig = src->config();
2054                 *rectsMustMatch = rectsMustMatchForBlitFramebuffer;
2055                 *disallowSubrect = disallowSubrectForBlitFramebuffer;
2056                 return true;
2057             }
2058             return false;
2059         }
2060     }
2061 
2062     // We'll do a CopyTexSubImage. Make the dst a plain old texture.
2063     desc->fConfig = src->config();
2064     desc->fOrigin = src->origin();
2065     desc->fFlags = kNone_GrSurfaceFlags;
2066     return true;
2067 }
2068 
applyDriverCorrectnessWorkarounds(const GrGLContextInfo & ctxInfo,const GrContextOptions & contextOptions,GrShaderCaps * shaderCaps)2069 void GrGLCaps::applyDriverCorrectnessWorkarounds(const GrGLContextInfo& ctxInfo,
2070                                                  const GrContextOptions& contextOptions,
2071                                                  GrShaderCaps* shaderCaps) {
2072     // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
2073     // Thus we are blacklisting this extension for now on Adreno4xx devices.
2074     if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer()) {
2075         fDiscardRenderTargetSupport = false;
2076         fInvalidateFBType = kNone_InvalidateFBType;
2077     }
2078 
2079     // glClearTexImage seems to have a bug in NVIDIA drivers that was fixed sometime between
2080     // 340.96 and 367.57.
2081     if (kGL_GrGLStandard == ctxInfo.standard() &&
2082         ctxInfo.driver() == kNVIDIA_GrGLDriver &&
2083         ctxInfo.driverVersion() < GR_GL_DRIVER_VER(367, 57)) {
2084         fClearTextureSupport = false;
2085     }
2086 
2087     // Calling glClearTexImage crashes on the NexusPlayer.
2088     if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2089         fClearTextureSupport = false;
2090     }
2091 
2092     // On at least some MacBooks, GLSL 4.0 geometry shaders break if we use invocations.
2093 #ifdef SK_BUILD_FOR_MAC
2094     if (shaderCaps->fGeometryShaderSupport) {
2095         shaderCaps->fGSInvocationsSupport = false;
2096     }
2097 #endif
2098 
2099     // Qualcomm driver @103.0 has been observed to crash compiling ccpr geometry
2100     // shaders. @127.0 is the earliest verified driver to not crash.
2101     if (kQualcomm_GrGLDriver == ctxInfo.driver() &&
2102         ctxInfo.driverVersion() < GR_GL_DRIVER_VER(127,0)) {
2103         shaderCaps->fGeometryShaderSupport = false;
2104     }
2105 
2106 #if defined(__has_feature)
2107 #if defined(SK_BUILD_FOR_MAC) && __has_feature(thread_sanitizer)
2108     // See skbug.com/7058
2109     fMapBufferType = kNone_MapBufferType;
2110     fMapBufferFlags = kNone_MapFlags;
2111 #endif
2112 #endif
2113 
2114     // We found that the Galaxy J5 with an Adreno 306 running 6.0.1 has a bug where
2115     // GL_INVALID_OPERATION thrown by glDrawArrays when using a buffer that was mapped. The same bug
2116     // did not reproduce on a Nexus7 2013 with a 320 running Android M with driver 127.0. It's
2117     // unclear whether this really affects a wide range of devices.
2118     if (ctxInfo.renderer() == kAdreno3xx_GrGLRenderer &&
2119         ctxInfo.driverVersion() > GR_GL_DRIVER_VER(127, 0)) {
2120         fMapBufferType = kNone_MapBufferType;
2121         fMapBufferFlags = kNone_MapFlags;
2122     }
2123 
2124     // TODO: re-enable for ANGLE
2125     if (kANGLE_GrGLDriver == ctxInfo.driver()) {
2126         fTransferBufferType = kNone_TransferBufferType;
2127     }
2128 
2129     // Using MIPs on this GPU seems to be a source of trouble.
2130     if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
2131         fMipMapSupport = false;
2132     }
2133 
2134     if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2135         // Temporarily disabling clip analytic fragments processors on Nexus player while we work
2136         // around a driver bug related to gl_FragCoord.
2137         // https://bugs.chromium.org/p/skia/issues/detail?id=7286
2138         fMaxClipAnalyticFPs = 0;
2139     }
2140 
2141 #ifndef SK_BUILD_FOR_IOS
2142     if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
2143         kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
2144         (kAdreno3xx_GrGLRenderer == ctxInfo.renderer() &&
2145          ctxInfo.driver() != kChromium_GrGLDriver)) {
2146         fUseDrawToClearColor = true;
2147     }
2148 #endif
2149 
2150     // A lot of GPUs have trouble with full screen clears (skbug.com/7195)
2151     if (kAMDRadeonHD7xxx_GrGLRenderer == ctxInfo.renderer() ||
2152         kAMDRadeonR9M4xx_GrGLRenderer == ctxInfo.renderer()) {
2153         fUseDrawToClearColor = true;
2154     }
2155 
2156 #ifdef SK_BUILD_FOR_MAC
2157     // crbug.com/768134 - On MacBook Pros, the Intel Iris Pro doesn't always perform
2158     // full screen clears
2159     // crbug.com/773107 - On MacBook Pros, a wide range of Intel GPUs don't always
2160     // perform full screen clears.
2161     if (kIntel_GrGLVendor == ctxInfo.vendor()) {
2162         fUseDrawToClearColor = true;
2163     }
2164 #endif
2165 
2166     // See crbug.com/755871. This could probably be narrowed to just partial clears as the driver
2167     // bugs seems to involve clearing too much and not skipping the clear.
2168     // See crbug.com/768134. This is also needed for full clears and was seen on an nVidia K620
2169     // but only for D3D11 ANGLE.
2170     if (GrGLANGLEBackend::kD3D11 == ctxInfo.angleBackend()) {
2171         fUseDrawToClearColor = true;
2172     }
2173 
2174     if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer()) {
2175         // This is known to be fixed sometime between driver 145.0 and 219.0
2176         if (ctxInfo.driverVersion() <= GR_GL_DRIVER_VER(219, 0)) {
2177             fUseDrawToClearStencilClip = true;
2178         }
2179         fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = true;
2180     }
2181 
2182     // This was reproduced on the following configurations:
2183     // - A Galaxy J5 (Adreno 306) running Android 6 with driver 140.0
2184     // - A Nexus 7 2013 (Adreno 320) running Android 5 with driver 104.0
2185     // - A Nexus 7 2013 (Adreno 320) running Android 6 with driver 127.0
2186     // - A Nexus 5 (Adreno 330) running Android 6 with driver 127.0
2187     // and not produced on:
2188     // - A Nexus 7 2013 (Adreno 320) running Android 4 with driver 53.0
2189     // The particular lines that get dropped from test images varies across different devices.
2190     if (kAdreno3xx_GrGLRenderer == ctxInfo.renderer() &&
2191         ctxInfo.driverVersion() > GR_GL_DRIVER_VER(53, 0)) {
2192         fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines = true;
2193     }
2194 
2195     // Our Chromebook with kPowerVRRogue_GrGLRenderer seems to crash when glDrawArraysInstanced is
2196     // given 1 << 15 or more instances.
2197     if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2198         fMaxInstancesPerDrawArraysWithoutCrashing = 0x7fff;
2199     }
2200 
2201     // Texture uploads sometimes seem to be ignored to textures bound to FBOS on Tegra3.
2202     if (kTegra3_GrGLRenderer == ctxInfo.renderer()) {
2203         fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = true;
2204         fUseDrawInsteadOfAllRenderTargetWrites = true;
2205     }
2206 
2207     if (kGL_GrGLStandard == ctxInfo.standard() && kIntel_GrGLVendor == ctxInfo.vendor() ) {
2208         fSampleShadingSupport = false;
2209     }
2210 
2211 #ifdef SK_BUILD_FOR_MAC
2212     static constexpr bool isMAC = true;
2213 #else
2214     static constexpr bool isMAC = false;
2215 #endif
2216 
2217     // We support manual mip-map generation (via iterative downsampling draw calls). This fixes
2218     // bugs on some cards/drivers that produce incorrect mip-maps for sRGB textures when using
2219     // glGenerateMipmap. Our implementation requires mip-level sampling control. Additionally,
2220     // it can be much slower (especially on mobile GPUs), so we opt-in only when necessary:
2221     if (fMipMapLevelAndLodControlSupport &&
2222         (contextOptions.fDoManualMipmapping ||
2223          (kIntel_GrGLVendor == ctxInfo.vendor()) ||
2224          (kNVIDIA_GrGLDriver == ctxInfo.driver() && isMAC) ||
2225          (kATI_GrGLVendor == ctxInfo.vendor()))) {
2226         fDoManualMipmapping = true;
2227     }
2228 
2229     // See http://crbug.com/710443
2230 #ifdef SK_BUILD_FOR_MAC
2231     if (kIntel6xxx_GrGLRenderer == ctxInfo.renderer()) {
2232         fClearToBoundaryValuesIsBroken = true;
2233     }
2234 #endif
2235     if (kQualcomm_GrGLVendor == ctxInfo.vendor()) {
2236         fDrawArraysBaseVertexIsBroken = true;
2237     }
2238 
2239     // The ccpr vertex-shader implementation does not work on this platform. Only allow CCPR with
2240     // GS.
2241 
2242     if (kANGLE_GrGLRenderer == ctxInfo.renderer() &&
2243         GrGLANGLERenderer::kSkylake == ctxInfo.angleRenderer()) {
2244         bool gsSupport = fShaderCaps->geometryShaderSupport();
2245 #if GR_TEST_UTILS
2246         gsSupport &= !contextOptions.fSuppressGeometryShaders;
2247 #endif
2248         fBlacklistCoverageCounting = !gsSupport;
2249     }
2250     // Currently the extension is advertised but fb fetch is broken on 500 series Adrenos like the
2251     // Galaxy S7.
2252     // TODO: Once this is fixed we can update the check here to look at a driver version number too.
2253     if (kAdreno5xx_GrGLRenderer == ctxInfo.renderer()) {
2254         shaderCaps->fFBFetchSupport = false;
2255     }
2256 
2257     // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
2258     shaderCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
2259 
2260     // On the NexusS and GalaxyNexus, the use of 'any' causes the compilation error "Calls to any
2261     // function that may require a gradient calculation inside a conditional block may return
2262     // undefined results". This appears to be an issue with the 'any' call since even the simple
2263     // "result=black; if (any()) result=white;" code fails to compile. This issue comes into play
2264     // from our GrTextureDomain processor.
2265     shaderCaps->fCanUseAnyFunctionInShader = kImagination_GrGLVendor != ctxInfo.vendor();
2266 
2267     // Known issue on at least some Intel platforms:
2268     // http://code.google.com/p/skia/issues/detail?id=946
2269     if (kIntel_GrGLVendor == ctxInfo.vendor()) {
2270         shaderCaps->fFragCoordConventionsExtensionString = nullptr;
2271     }
2272 
2273     if (kTegra3_GrGLRenderer == ctxInfo.renderer()) {
2274         // The Tegra3 compiler will sometimes never return if we have min(abs(x), 1.0),
2275         // so we must do the abs first in a separate expression.
2276         shaderCaps->fCanUseMinAndAbsTogether = false;
2277 
2278         // Tegra3 fract() seems to trigger undefined behavior for negative values, so we
2279         // must avoid this condition.
2280         shaderCaps->fCanUseFractForNegativeValues = false;
2281     }
2282 
2283     // On Intel GPU there is an issue where it reads the second argument to atan "- %s.x" as an int
2284     // thus must us -1.0 * %s.x to work correctly
2285     if (kIntel_GrGLVendor == ctxInfo.vendor()) {
2286         shaderCaps->fMustForceNegatedAtanParamToFloat = true;
2287     }
2288 
2289     // On some Intel GPUs there is an issue where the driver outputs bogus values in the shader
2290     // when floor and abs are called on the same line. Thus we must execute an Op between them to
2291     // make sure the compiler doesn't re-inline them even if we break the calls apart.
2292     if (kIntel_GrGLVendor == ctxInfo.vendor()) {
2293         shaderCaps->fMustDoOpBetweenFloorAndAbs = true;
2294     }
2295 
2296     // On Adreno devices with framebuffer fetch support, there is a bug where they always return
2297     // the original dst color when reading the outColor even after being written to. By using a
2298     // local outColor we can work around this bug.
2299     if (shaderCaps->fFBFetchSupport && kQualcomm_GrGLVendor == ctxInfo.vendor()) {
2300         shaderCaps->fRequiresLocalOutputColorForFBFetch = true;
2301     }
2302 
2303     // Newer Mali GPUs do incorrect static analysis in specific situations: If there is uniform
2304     // color, and that uniform contains an opaque color, and the output of the shader is only based
2305     // on that uniform plus soemthing un-trackable (like a texture read), the compiler will deduce
2306     // that the shader always outputs opaque values. In that case, it appears to remove the shader
2307     // based blending code it normally injects, turning SrcOver into Src. To fix this, we always
2308     // insert an extra bit of math on the uniform that confuses the compiler just enough...
2309     if (kMaliT_GrGLRenderer == ctxInfo.renderer()) {
2310         shaderCaps->fMustObfuscateUniformColor = true;
2311     }
2312 #ifdef SK_BUILD_FOR_WIN
2313     // Check for ANGLE on Windows, so we can workaround a bug in D3D itself (anglebug.com/2098).
2314     //
2315     // Basically, if a shader has a construct like:
2316     //
2317     // float x = someCondition ? someValue : 0;
2318     // float2 result = (0 == x) ? float2(x, x)
2319     //                          : float2(2 * x / x, 0);
2320     //
2321     // ... the compiler will produce an error 'NaN and infinity literals not allowed', even though
2322     // we've explicitly guarded the division with a check against zero. This manifests in much
2323     // more complex ways in some of our shaders, so we use this caps bit to add an epsilon value
2324     // to the denominator of divisions, even when we've added checks that the denominator isn't 0.
2325     if (kANGLE_GrGLDriver == ctxInfo.driver() || kChromium_GrGLDriver == ctxInfo.driver()) {
2326         shaderCaps->fMustGuardDivisionEvenAfterExplicitZeroCheck = true;
2327     }
2328 #endif
2329 
2330     // We've seen Adreno 3xx devices produce incorrect (flipped) values for gl_FragCoord, in some
2331     // (rare) situations. It's sporadic, and mostly on older drivers. It also seems to be the case
2332     // that the interpolation of vertex shader outputs is quite inaccurate.
2333     if (kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
2334         shaderCaps->fCanUseFragCoord = false;
2335         shaderCaps->fInterpolantsAreInaccurate = true;
2336     }
2337 
2338     // Disabling advanced blend on various platforms with major known issues. We also block Chrome
2339     // for now until its own blacklists can be updated.
2340     if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer() ||
2341         kAdreno5xx_GrGLRenderer == ctxInfo.renderer() ||
2342         kIntel_GrGLDriver == ctxInfo.driver() ||
2343         kChromium_GrGLDriver == ctxInfo.driver()) {
2344         fBlendEquationSupport = kBasic_BlendEquationSupport;
2345         shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
2346     }
2347 
2348     // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
2349     if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
2350         ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337,00) &&
2351         kAdvanced_BlendEquationSupport == fBlendEquationSupport) {
2352         fBlendEquationSupport = kBasic_BlendEquationSupport;
2353         shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
2354     }
2355 
2356     if (this->advancedBlendEquationSupport()) {
2357         if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
2358             ctxInfo.driverVersion() < GR_GL_DRIVER_VER(355,00)) {
2359             // Blacklist color-dodge and color-burn on pre-355.00 NVIDIA.
2360             fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
2361                                     (1 << kColorBurn_GrBlendEquation);
2362         }
2363         if (kARM_GrGLVendor == ctxInfo.vendor()) {
2364             // Blacklist color-burn on ARM until the fix is released.
2365             fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation);
2366         }
2367     }
2368 
2369     // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples.
2370     if (fMultisampleDisableSupport &&
2371         this->shaderCaps()->dualSourceBlendingSupport() &&
2372         this->shaderCaps()->pathRenderingSupport() &&
2373         fUsesMixedSamples &&
2374 #if GR_TEST_UTILS
2375         (contextOptions.fGpuPathRenderers & GpuPathRenderers::kStencilAndCover) &&
2376 #endif
2377         (kNVIDIA_GrGLDriver == ctxInfo.driver() ||
2378          kChromium_GrGLDriver == ctxInfo.driver())) {
2379             fDiscardRenderTargetSupport = false;
2380             fInvalidateFBType = kNone_InvalidateFBType;
2381     }
2382 }
2383 
onApplyOptionsOverrides(const GrContextOptions & options)2384 void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {
2385     if (options.fDisableDriverCorrectnessWorkarounds) {
2386         SkASSERT(!fDoManualMipmapping);
2387         SkASSERT(!fClearToBoundaryValuesIsBroken);
2388         SkASSERT(0 == fMaxInstancesPerDrawArraysWithoutCrashing);
2389         SkASSERT(!fDrawArraysBaseVertexIsBroken);
2390         SkASSERT(!fUseDrawToClearColor);
2391         SkASSERT(!fUseDrawToClearStencilClip);
2392         SkASSERT(!fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO);
2393         SkASSERT(!fUseDrawInsteadOfAllRenderTargetWrites);
2394         SkASSERT(!fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines);
2395     }
2396     if (GrContextOptions::Enable::kNo == options.fUseDrawInsteadOfGLClear) {
2397         fUseDrawToClearColor = false;
2398     } else if (GrContextOptions::Enable::kYes == options.fUseDrawInsteadOfGLClear) {
2399         fUseDrawToClearColor = true;
2400     }
2401     if (options.fDoManualMipmapping) {
2402         fDoManualMipmapping = true;
2403     }
2404 }
2405 
surfaceSupportsWritePixels(const GrSurface * surface) const2406 bool GrGLCaps::surfaceSupportsWritePixels(const GrSurface* surface) const {
2407     if (fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO) {
2408         if (auto tex = static_cast<const GrGLTexture*>(surface->asTexture())) {
2409             if (tex->hasBaseLevelBeenBoundToFBO()) {
2410                 return false;
2411             }
2412         }
2413     }
2414     if (auto rt = surface->asRenderTarget()) {
2415         if (fUseDrawInsteadOfAllRenderTargetWrites) {
2416             return false;
2417         }
2418         if (rt->numColorSamples() > 1 && this->usesMSAARenderBuffers()) {
2419             return false;
2420         }
2421         return SkToBool(surface->asTexture());
2422     }
2423     return true;
2424 }
2425 
onIsMixedSamplesSupportedForRT(const GrBackendRenderTarget & backendRT) const2426 bool GrGLCaps::onIsMixedSamplesSupportedForRT(const GrBackendRenderTarget& backendRT) const {
2427     const GrGLFramebufferInfo* fbInfo = backendRT.getGLFramebufferInfo();
2428     SkASSERT(fbInfo);
2429     // Mixed samples are not supported for FBO 0;
2430     return fbInfo->fFBOID != 0;
2431 }
2432 
onIsWindowRectanglesSupportedForRT(const GrBackendRenderTarget & backendRT) const2433 bool GrGLCaps::onIsWindowRectanglesSupportedForRT(const GrBackendRenderTarget& backendRT) const {
2434     const GrGLFramebufferInfo* fbInfo = backendRT.getGLFramebufferInfo();
2435     SkASSERT(fbInfo);
2436     // Window Rectangles are not supported for FBO 0;
2437     return fbInfo->fFBOID != 0;
2438 }
2439 
getRenderTargetSampleCount(int requestedCount,GrPixelConfig config) const2440 int GrGLCaps::getRenderTargetSampleCount(int requestedCount, GrPixelConfig config) const {
2441     requestedCount = SkTMax(1, requestedCount);
2442     int count = fConfigTable[config].fColorSampleCounts.count();
2443     if (!count) {
2444         return 0;
2445     }
2446 
2447     if (1 == requestedCount) {
2448         return fConfigTable[config].fColorSampleCounts[0] == 1 ? 1 : 0;
2449     }
2450 
2451     for (int i = 0; i < count; ++i) {
2452         if (fConfigTable[config].fColorSampleCounts[i] >= requestedCount) {
2453             return fConfigTable[config].fColorSampleCounts[i];
2454         }
2455     }
2456     return 0;
2457 }
2458 
maxRenderTargetSampleCount(GrPixelConfig config) const2459 int GrGLCaps::maxRenderTargetSampleCount(GrPixelConfig config) const {
2460     const auto& table = fConfigTable[config].fColorSampleCounts;
2461     if (!table.count()) {
2462         return 0;
2463     }
2464     return table[table.count() - 1];
2465 }
2466 
validate_sized_format(GrGLenum format,SkColorType ct,GrPixelConfig * config,GrGLStandard standard)2467 bool validate_sized_format(GrGLenum format, SkColorType ct, GrPixelConfig* config,
2468                            GrGLStandard standard) {
2469     *config = kUnknown_GrPixelConfig;
2470 
2471     switch (ct) {
2472         case kUnknown_SkColorType:
2473             return false;
2474         case kAlpha_8_SkColorType:
2475             if (GR_GL_ALPHA8 == format) {
2476                 *config = kAlpha_8_as_Alpha_GrPixelConfig;
2477             } else if (GR_GL_R8 == format) {
2478                 *config = kAlpha_8_as_Red_GrPixelConfig;
2479             }
2480             break;
2481         case kRGB_565_SkColorType:
2482             if (GR_GL_RGB565 == format) {
2483                 *config = kRGB_565_GrPixelConfig;
2484             }
2485             break;
2486         case kARGB_4444_SkColorType:
2487             if (GR_GL_RGBA4 == format) {
2488                 *config = kRGBA_4444_GrPixelConfig;
2489             }
2490             break;
2491         case kRGBA_8888_SkColorType:
2492             if (GR_GL_RGBA8 == format) {
2493                 *config = kRGBA_8888_GrPixelConfig;
2494             } else if (GR_GL_SRGB8_ALPHA8 == format) {
2495                 *config = kSRGBA_8888_GrPixelConfig;
2496             }
2497             break;
2498         case kRGB_888x_SkColorType:
2499             return false;
2500         case kBGRA_8888_SkColorType:
2501             if (GR_GL_RGBA8 == format) {
2502                 if (kGL_GrGLStandard == standard) {
2503                     *config = kBGRA_8888_GrPixelConfig;
2504                 }
2505             } else if (GR_GL_BGRA8 == format) {
2506                 if (kGLES_GrGLStandard == standard) {
2507                     *config = kBGRA_8888_GrPixelConfig;
2508                 }
2509             } else if (GR_GL_SRGB8_ALPHA8 == format) {
2510                 *config = kSBGRA_8888_GrPixelConfig;
2511             }
2512             break;
2513         case kRGBA_1010102_SkColorType:
2514             return false;
2515         case kRGB_101010x_SkColorType:
2516             return false;
2517         case kGray_8_SkColorType:
2518             if (GR_GL_LUMINANCE8 == format) {
2519                 *config = kGray_8_as_Lum_GrPixelConfig;
2520             } else if (GR_GL_R8 == format) {
2521                 *config = kGray_8_as_Red_GrPixelConfig;
2522             }
2523             break;
2524         case kRGBA_F16_SkColorType:
2525             if (GR_GL_RGBA16F == format) {
2526                 *config = kRGBA_half_GrPixelConfig;
2527             }
2528             break;
2529     }
2530 
2531     return kUnknown_GrPixelConfig != *config;
2532 }
2533 
validateBackendTexture(const GrBackendTexture & tex,SkColorType ct,GrPixelConfig * config) const2534 bool GrGLCaps::validateBackendTexture(const GrBackendTexture& tex, SkColorType ct,
2535                                       GrPixelConfig* config) const {
2536     const GrGLTextureInfo* texInfo = tex.getGLTextureInfo();
2537     if (!texInfo) {
2538         return false;
2539     }
2540     return validate_sized_format(texInfo->fFormat, ct, config, fStandard);
2541 }
2542 
validateBackendRenderTarget(const GrBackendRenderTarget & rt,SkColorType ct,GrPixelConfig * config) const2543 bool GrGLCaps::validateBackendRenderTarget(const GrBackendRenderTarget& rt, SkColorType ct,
2544                                            GrPixelConfig* config) const {
2545     const GrGLFramebufferInfo* fbInfo = rt.getGLFramebufferInfo();
2546     if (!fbInfo) {
2547         return false;
2548     }
2549     return validate_sized_format(fbInfo->fFormat, ct, config, fStandard);
2550 }
2551 
getConfigFromBackendFormat(const GrBackendFormat & format,SkColorType ct,GrPixelConfig * config) const2552 bool GrGLCaps::getConfigFromBackendFormat(const GrBackendFormat& format, SkColorType ct,
2553                                           GrPixelConfig* config) const {
2554     const GrGLenum* glFormat = format.getGLFormat();
2555     if (!glFormat) {
2556         return false;
2557     }
2558     return validate_sized_format(*glFormat, ct, config, fStandard);
2559 }
2560 
2561 
2562