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