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
9 #include "GrGLCaps.h"
10
11 #include "GrContextOptions.h"
12 #include "GrGLContext.h"
13 #include "GrGLRenderTarget.h"
14 #include "glsl/GrGLSLCaps.h"
15 #include "SkTSearch.h"
16 #include "SkTSort.h"
17
GrGLCaps(const GrContextOptions & contextOptions,const GrGLContextInfo & ctxInfo,const GrGLInterface * glInterface)18 GrGLCaps::GrGLCaps(const GrContextOptions& contextOptions,
19 const GrGLContextInfo& ctxInfo,
20 const GrGLInterface* glInterface) : INHERITED(contextOptions) {
21 fStandard = ctxInfo.standard();
22
23 fStencilFormats.reset();
24 fMSFBOType = kNone_MSFBOType;
25 fInvalidateFBType = kNone_InvalidateFBType;
26 fMapBufferType = kNone_MapBufferType;
27 fTransferBufferType = kNone_TransferBufferType;
28 fMaxFragmentUniformVectors = 0;
29 fMaxVertexAttributes = 0;
30 fMaxFragmentTextureUnits = 0;
31 fUnpackRowLengthSupport = false;
32 fUnpackFlipYSupport = false;
33 fPackRowLengthSupport = false;
34 fPackFlipYSupport = false;
35 fTextureUsageSupport = false;
36 fTexStorageSupport = false;
37 fTextureRedSupport = false;
38 fImagingSupport = false;
39 fVertexArrayObjectSupport = false;
40 fDirectStateAccessSupport = false;
41 fDebugSupport = false;
42 fES2CompatibilitySupport = false;
43 fMultisampleDisableSupport = false;
44 fDrawIndirectSupport = false;
45 fMultiDrawIndirectSupport = false;
46 fBaseInstanceSupport = false;
47 fUseNonVBOVertexAndIndexDynamicData = false;
48 fIsCoreProfile = false;
49 fBindFragDataLocationSupport = false;
50 fExternalTextureSupport = false;
51 fRectangleTextureSupport = false;
52 fTextureSwizzleSupport = false;
53 fSRGBWriteControl = false;
54 fRGBA8888PixelsOpsAreSlow = false;
55 fPartialFBOReadIsSlow = false;
56
57 fBlitFramebufferSupport = kNone_BlitFramebufferSupport;
58
59 fShaderCaps.reset(new GrGLSLCaps(contextOptions));
60
61 this->init(contextOptions, ctxInfo, glInterface);
62 }
63
init(const GrContextOptions & contextOptions,const GrGLContextInfo & ctxInfo,const GrGLInterface * gli)64 void GrGLCaps::init(const GrContextOptions& contextOptions,
65 const GrGLContextInfo& ctxInfo,
66 const GrGLInterface* gli) {
67 GrGLStandard standard = ctxInfo.standard();
68 GrGLVersion version = ctxInfo.version();
69
70 /**************************************************************************
71 * Caps specific to GrGLCaps
72 **************************************************************************/
73
74 if (kGLES_GrGLStandard == standard) {
75 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
76 &fMaxFragmentUniformVectors);
77 } else {
78 SkASSERT(kGL_GrGLStandard == standard);
79 GrGLint max;
80 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
81 fMaxFragmentUniformVectors = max / 4;
82 if (version >= GR_GL_VER(3, 2)) {
83 GrGLint profileMask;
84 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
85 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
86 }
87 }
88 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
89 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &fMaxFragmentTextureUnits);
90
91 if (kGL_GrGLStandard == standard) {
92 fUnpackRowLengthSupport = true;
93 fUnpackFlipYSupport = false;
94 fPackRowLengthSupport = true;
95 fPackFlipYSupport = false;
96 } else {
97 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
98 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
99 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
100 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
101 ctxInfo.hasExtension("GL_NV_pack_subimage");
102 fPackFlipYSupport =
103 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
104 }
105
106 fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
107 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
108
109 if (kGL_GrGLStandard == standard) {
110 // The EXT version can apply to either GL or GLES.
111 fTexStorageSupport = version >= GR_GL_VER(4,2) ||
112 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
113 ctxInfo.hasExtension("GL_EXT_texture_storage");
114 } else {
115 // Qualcomm Adreno drivers appear to have issues with texture storage.
116 fTexStorageSupport = (version >= GR_GL_VER(3,0) &&
117 kQualcomm_GrGLVendor != ctxInfo.vendor()) &&
118 ctxInfo.hasExtension("GL_EXT_texture_storage");
119 }
120
121 if (kGL_GrGLStandard == standard) {
122 fTextureBarrierSupport = version >= GR_GL_VER(4,5) ||
123 ctxInfo.hasExtension("GL_ARB_texture_barrier") ||
124 ctxInfo.hasExtension("GL_NV_texture_barrier");
125 } else {
126 fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier");
127 }
128
129 // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support GL_RED
130 // and GL_RG on FBO textures.
131 if (kMesa_GrGLDriver != ctxInfo.driver()) {
132 if (kGL_GrGLStandard == standard) {
133 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
134 ctxInfo.hasExtension("GL_ARB_texture_rg");
135 } else {
136 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
137 ctxInfo.hasExtension("GL_EXT_texture_rg");
138 }
139 }
140 fImagingSupport = kGL_GrGLStandard == standard &&
141 ctxInfo.hasExtension("GL_ARB_imaging");
142
143 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
144 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
145 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
146 // limit this decision to specific GPU families rather than basing it on the vendor alone.
147 if (!GR_GL_MUST_USE_VBO &&
148 (kARM_GrGLVendor == ctxInfo.vendor() ||
149 kImagination_GrGLVendor == ctxInfo.vendor() ||
150 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
151 fUseNonVBOVertexAndIndexDynamicData = true;
152 }
153
154 // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
155 // Thus we are blacklisting this extension for now on Adreno4xx devices.
156 if (kAdreno4xx_GrGLRenderer != ctxInfo.renderer() &&
157 ((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
158 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
159 ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) {
160 fDiscardRenderTargetSupport = true;
161 fInvalidateFBType = kInvalidate_InvalidateFBType;
162 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
163 fDiscardRenderTargetSupport = true;
164 fInvalidateFBType = kDiscard_InvalidateFBType;
165 }
166
167 if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) {
168 fFullClearIsFree = true;
169 }
170
171 if (kGL_GrGLStandard == standard) {
172 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
173 ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
174 ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
175 } else {
176 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
177 ctxInfo.hasExtension("GL_OES_vertex_array_object");
178 }
179
180 if (kGL_GrGLStandard == standard) {
181 fDirectStateAccessSupport = ctxInfo.hasExtension("GL_EXT_direct_state_access");
182 } else {
183 fDirectStateAccessSupport = false;
184 }
185
186 if (kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) {
187 fDebugSupport = true;
188 } else {
189 fDebugSupport = ctxInfo.hasExtension("GL_KHR_debug");
190 }
191
192 if (kGL_GrGLStandard == standard) {
193 fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
194 }
195 else {
196 fES2CompatibilitySupport = true;
197 }
198
199 if (kGL_GrGLStandard == standard) {
200 fMultisampleDisableSupport = true;
201 } else {
202 fMultisampleDisableSupport = ctxInfo.hasExtension("GL_EXT_multisample_compatibility");
203 }
204
205 if (kGL_GrGLStandard == standard) {
206 if (version >= GR_GL_VER(3, 0)) {
207 fBindFragDataLocationSupport = true;
208 }
209 } else {
210 if (version >= GR_GL_VER(3, 0) && ctxInfo.hasExtension("GL_EXT_blend_func_extended")) {
211 fBindFragDataLocationSupport = true;
212 }
213 }
214
215 #if 0 // Disabled due to https://bug.skia.org/4454
216 fBindUniformLocationSupport = ctxInfo.hasExtension("GL_CHROMIUM_bind_uniform_location");
217 #else
218 fBindUniformLocationSupport = false;
219 #endif
220
221 if (ctxInfo.hasExtension("GL_OES_EGL_image_external")) {
222 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
223 fExternalTextureSupport = true;
224 } else if (ctxInfo.hasExtension("GL_OES_EGL_image_external_essl3") ||
225 ctxInfo.hasExtension("OES_EGL_image_external_essl3")) {
226 // At least one driver has been found that has this extension without the "GL_" prefix.
227 fExternalTextureSupport = true;
228 }
229 }
230
231 if (kGL_GrGLStandard == standard) {
232 if (version >= GR_GL_VER(3, 1) || ctxInfo.hasExtension("GL_ARB_texture_rectangle")) {
233 // We also require textureSize() support for rectangle 2D samplers which was added in
234 // GLSL 1.40.
235 if (ctxInfo.glslGeneration() >= k140_GrGLSLGeneration) {
236 fRectangleTextureSupport = true;
237 }
238 }
239 } else {
240 // Command buffer exposes this in GL ES context for Chromium reasons,
241 // but it should not be used. Also, at the time of writing command buffer
242 // lacks TexImage2D support and ANGLE lacks GL ES 3.0 support.
243 }
244
245 if (kGL_GrGLStandard == standard) {
246 if (version >= GR_GL_VER(3,3) || ctxInfo.hasExtension("GL_ARB_texture_swizzle")) {
247 fTextureSwizzleSupport = true;
248 }
249 } else {
250 if (version >= GR_GL_VER(3,0)) {
251 fTextureSwizzleSupport = true;
252 }
253 }
254
255 #ifdef SK_BUILD_FOR_WIN
256 // We're assuming that on Windows Chromium we're using ANGLE.
257 bool isANGLE = kANGLE_GrGLDriver == ctxInfo.driver() ||
258 kChromium_GrGLDriver == ctxInfo.driver();
259 // Angle has slow read/write pixel paths for 32bit RGBA (but fast for BGRA).
260 fRGBA8888PixelsOpsAreSlow = isANGLE;
261 // On DX9 ANGLE reading a partial FBO is slow. TODO: Check whether this is still true and
262 // check DX11 ANGLE.
263 fPartialFBOReadIsSlow = isANGLE;
264 #endif
265
266 /**************************************************************************
267 * GrShaderCaps fields
268 **************************************************************************/
269
270 // This must be called after fCoreProfile is set on the GrGLCaps
271 this->initGLSL(ctxInfo);
272 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
273
274 glslCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli);
275
276 // For now these two are equivalent but we could have dst read in shader via some other method.
277 // Before setting this, initGLSL() must have been called.
278 glslCaps->fDstReadInShaderSupport = glslCaps->fFBFetchSupport;
279
280 // Enable supported shader-related caps
281 if (kGL_GrGLStandard == standard) {
282 glslCaps->fDualSourceBlendingSupport = (ctxInfo.version() >= GR_GL_VER(3, 3) ||
283 ctxInfo.hasExtension("GL_ARB_blend_func_extended")) &&
284 GrGLSLSupportsNamedFragmentShaderOutputs(ctxInfo.glslGeneration());
285 glslCaps->fShaderDerivativeSupport = true;
286 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
287 glslCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) &&
288 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
289 glslCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
290 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
291 }
292 else {
293 glslCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended");
294
295 glslCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
296 ctxInfo.hasExtension("GL_OES_standard_derivatives");
297
298 glslCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
299 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // We use this value for GLSL ES 3.0.
300 }
301
302 if (ctxInfo.hasExtension("GL_EXT_shader_pixel_local_storage")) {
303 #define GL_MAX_SHADER_PIXEL_LOCAL_STORAGE_FAST_SIZE_EXT 0x8F63
304 GR_GL_GetIntegerv(gli, GL_MAX_SHADER_PIXEL_LOCAL_STORAGE_FAST_SIZE_EXT,
305 &glslCaps->fPixelLocalStorageSize);
306 glslCaps->fPLSPathRenderingSupport = glslCaps->fFBFetchSupport;
307 }
308 else {
309 glslCaps->fPixelLocalStorageSize = 0;
310 glslCaps->fPLSPathRenderingSupport = false;
311 }
312
313 /**************************************************************************
314 * GrCaps fields
315 **************************************************************************/
316
317 // We need dual source blending and the ability to disable multisample in order to support mixed
318 // samples in every corner case.
319 if (fMultisampleDisableSupport &&
320 glslCaps->dualSourceBlendingSupport() &&
321 fShaderCaps->pathRenderingSupport()) {
322 fUsesMixedSamples = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") ||
323 ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_mixed_samples");
324 // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples.
325 if (fUsesMixedSamples && (kNVIDIA_GrGLDriver == ctxInfo.driver() ||
326 kChromium_GrGLDriver == ctxInfo.driver())) {
327 fDiscardRenderTargetSupport = false;
328 fInvalidateFBType = kNone_InvalidateFBType;
329 }
330 }
331
332 // fUsesMixedSamples must be set before calling initFSAASupport.
333 this->initFSAASupport(ctxInfo, gli);
334 this->initBlendEqationSupport(ctxInfo);
335 this->initStencilFormats(ctxInfo);
336
337 if (kGL_GrGLStandard == standard) {
338 // we could also look for GL_ATI_separate_stencil extension or
339 // GL_EXT_stencil_two_side but they use different function signatures
340 // than GL2.0+ (and than each other).
341 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
342 // supported on GL 1.4 and higher or by extension
343 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
344 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
345 } else {
346 // ES 2 has two sided stencil and stencil wrap
347 fTwoSidedStencilSupport = true;
348 fStencilWrapOpsSupport = true;
349 }
350
351 if (kGL_GrGLStandard == standard) {
352 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
353 // extension includes glMapBuffer.
354 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
355 fMapBufferFlags |= kSubset_MapFlag;
356 fMapBufferType = kMapBufferRange_MapBufferType;
357 } else {
358 fMapBufferType = kMapBuffer_MapBufferType;
359 }
360 } else {
361 // Unextended GLES2 doesn't have any buffer mapping.
362 fMapBufferFlags = kNone_MapBufferType;
363 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
364 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
365 fMapBufferType = kMapBufferRange_MapBufferType;
366 } else if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
367 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
368 fMapBufferType = kChromium_MapBufferType;
369 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
370 fMapBufferFlags = kCanMap_MapFlag;
371 fMapBufferType = kMapBuffer_MapBufferType;
372 }
373 }
374
375 if (kGL_GrGLStandard == standard) {
376 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_pixel_buffer_object")) {
377 fTransferBufferType = kPBO_TransferBufferType;
378 }
379 } else {
380 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_NV_pixel_buffer_object")) {
381 fTransferBufferType = kPBO_TransferBufferType;
382 } else if (ctxInfo.hasExtension("GL_CHROMIUM_pixel_transfer_buffer_object")) {
383 fTransferBufferType = kChromium_TransferBufferType;
384 }
385 }
386
387 // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
388 // threshold to the maximum unless the client gives us a hint that map memory is cheap.
389 if (fGeometryBufferMapThreshold < 0) {
390 // We think mapping on Chromium will be cheaper once we know ahead of time how much space
391 // we will use for all GrBatchs. Right now we might wind up mapping a large buffer and using
392 // a small subset.
393 #if 0
394 fGeometryBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
395 #else
396 fGeometryBufferMapThreshold = SK_MaxS32;
397 #endif
398 }
399
400 if (kGL_GrGLStandard == standard) {
401 SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) ||
402 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two"));
403 fNPOTTextureTileSupport = true;
404 fMipMapSupport = true;
405 } else {
406 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
407 // ES3 has no limitations.
408 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
409 ctxInfo.hasExtension("GL_OES_texture_npot");
410 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
411 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
412 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
413 // to alllow arbitrary wrap modes, however.
414 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
415 }
416
417 // Using MIPs on this GPU seems to be a source of trouble.
418 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
419 fMipMapSupport = false;
420 }
421
422 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
423 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
424 // Our render targets are always created with textures as the color
425 // attachment, hence this min:
426 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
427
428 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
429
430 // Disable scratch texture reuse on Mali and Adreno devices
431 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() &&
432 kQualcomm_GrGLVendor != ctxInfo.vendor();
433
434 #if 0
435 fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() &&
436 kQualcomm_GrGLVendor != ctxInfo.vendor();
437 #endif
438
439 // initFSAASupport() must have been called before this point
440 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
441 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxStencilSampleCount);
442 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
443 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxStencilSampleCount);
444 }
445 // We only have a use for raster multisample if there is coverage modulation from mixed samples.
446 if (fUsesMixedSamples && ctxInfo.hasExtension("GL_EXT_raster_multisample")) {
447 GR_GL_GetIntegerv(gli, GR_GL_MAX_RASTER_SAMPLES, &fMaxRasterSamples);
448 // This is to guard against platforms that may not support as many samples for
449 // glRasterSamples as they do for framebuffers.
450 fMaxStencilSampleCount = SkTMin(fMaxStencilSampleCount, fMaxRasterSamples);
451 }
452 fMaxColorSampleCount = fMaxStencilSampleCount;
453
454 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
455 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
456 kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
457 fUseDrawInsteadOfClear = true;
458 }
459
460 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer()) {
461 fUseDrawInsteadOfPartialRenderTargetWrite = true;
462 }
463
464 // Texture uploads sometimes seem to be ignored to textures bound to FBOS on Tegra3.
465 if (kTegra3_GrGLRenderer == ctxInfo.renderer()) {
466 fUseDrawInsteadOfPartialRenderTargetWrite = true;
467 fUseDrawInsteadOfAllRenderTargetWrites = true;
468 }
469
470 #ifdef SK_BUILD_FOR_WIN
471 // On ANGLE deferring flushes can lead to GPU starvation
472 fPreferVRAMUseOverFlushes = !isANGLE;
473 #endif
474
475 if (kChromium_GrGLDriver == ctxInfo.driver()) {
476 fMustClearUploadedBufferData = true;
477 }
478
479 if (kGL_GrGLStandard == standard) {
480 // ARB allows mixed size FBO attachments, EXT does not.
481 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
482 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
483 fOversizedStencilSupport = true;
484 } else {
485 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
486 }
487 } else {
488 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
489 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
490 }
491
492 if (kGL_GrGLStandard == standard) {
493 // 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about
494 // instanced arrays, but we could make this more granular if we wanted
495 fSupportsInstancedDraws =
496 version >= GR_GL_VER(3, 2) ||
497 (ctxInfo.hasExtension("GL_ARB_draw_instanced") &&
498 ctxInfo.hasExtension("GL_ARB_instanced_arrays"));
499 } else {
500 fSupportsInstancedDraws =
501 version >= GR_GL_VER(3, 0) ||
502 (ctxInfo.hasExtension("GL_EXT_draw_instanced") &&
503 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
504 }
505
506 if (kGL_GrGLStandard == standard) {
507 // We don't use ARB_draw_indirect because it does not support a base instance.
508 // We don't use ARB_multi_draw_indirect because it does not support GL_DRAW_INDIRECT_BUFFER.
509 fDrawIndirectSupport =
510 fMultiDrawIndirectSupport = fBaseInstanceSupport = version >= GR_GL_VER(4,3);
511 } else {
512 fDrawIndirectSupport = version >= GR_GL_VER(3,1);
513 fMultiDrawIndirectSupport = ctxInfo.hasExtension("GL_EXT_multi_draw_indirect");
514 fBaseInstanceSupport = ctxInfo.hasExtension("GL_EXT_base_instance");
515 }
516
517 this->initShaderPrecisionTable(ctxInfo, gli, glslCaps);
518
519 if (contextOptions.fUseShaderSwizzling) {
520 fTextureSwizzleSupport = false;
521 }
522
523 // TODO: remove after command buffer supports full ES 3.0.
524 if (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3, 0) &&
525 kChromium_GrGLDriver == ctxInfo.driver()) {
526 fTexStorageSupport = false;
527 fSupportsInstancedDraws = false;
528 fTextureSwizzleSupport = false;
529 SkASSERT(ctxInfo.hasExtension("GL_CHROMIUM_map_sub"));
530 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
531 fMapBufferType = kChromium_MapBufferType;
532 }
533
534 // Requires fTextureRedSupport, fTextureSwizzleSupport, msaa support, ES compatibility have
535 // already been detected.
536 this->initConfigTable(ctxInfo, gli, glslCaps);
537
538 this->applyOptionsOverrides(contextOptions);
539 glslCaps->applyOptionsOverrides(contextOptions);
540 }
541
get_glsl_version_decl_string(GrGLStandard standard,GrGLSLGeneration generation,bool isCoreProfile)542 const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration generation,
543 bool isCoreProfile) {
544 switch (generation) {
545 case k110_GrGLSLGeneration:
546 if (kGLES_GrGLStandard == standard) {
547 // ES2s shader language is based on version 1.20 but is version
548 // 1.00 of the ES language.
549 return "#version 100\n";
550 } else {
551 SkASSERT(kGL_GrGLStandard == standard);
552 return "#version 110\n";
553 }
554 case k130_GrGLSLGeneration:
555 SkASSERT(kGL_GrGLStandard == standard);
556 return "#version 130\n";
557 case k140_GrGLSLGeneration:
558 SkASSERT(kGL_GrGLStandard == standard);
559 return "#version 140\n";
560 case k150_GrGLSLGeneration:
561 SkASSERT(kGL_GrGLStandard == standard);
562 if (isCoreProfile) {
563 return "#version 150\n";
564 } else {
565 return "#version 150 compatibility\n";
566 }
567 case k330_GrGLSLGeneration:
568 if (kGLES_GrGLStandard == standard) {
569 return "#version 300 es\n";
570 } else {
571 SkASSERT(kGL_GrGLStandard == standard);
572 if (isCoreProfile) {
573 return "#version 330\n";
574 } else {
575 return "#version 330 compatibility\n";
576 }
577 }
578 case k400_GrGLSLGeneration:
579 SkASSERT(kGL_GrGLStandard == standard);
580 if (isCoreProfile) {
581 return "#version 400\n";
582 } else {
583 return "#version 400 compatibility\n";
584 }
585 case k310es_GrGLSLGeneration:
586 SkASSERT(kGLES_GrGLStandard == standard);
587 return "#version 310 es\n";
588 case k320es_GrGLSLGeneration:
589 SkASSERT(kGLES_GrGLStandard == standard);
590 return "#version 320 es\n";
591 }
592 return "<no version>";
593 }
594
initGLSL(const GrGLContextInfo & ctxInfo)595 void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo) {
596 GrGLStandard standard = ctxInfo.standard();
597 GrGLVersion version = ctxInfo.version();
598
599 /**************************************************************************
600 * Caps specific to GrGLSLCaps
601 **************************************************************************/
602
603 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
604 glslCaps->fGLSLGeneration = ctxInfo.glslGeneration();
605 if (kGLES_GrGLStandard == standard) {
606 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
607 glslCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
608 glslCaps->fFBFetchSupport = true;
609 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
610 glslCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
611 }
612 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
613 // Actually, we haven't seen an ES3.0 device with this extension yet, so we don't know
614 glslCaps->fFBFetchNeedsCustomOutput = false;
615 glslCaps->fFBFetchSupport = true;
616 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
617 glslCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
618 }
619 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
620 // The arm extension also requires an additional flag which we will set onResetContext
621 glslCaps->fFBFetchNeedsCustomOutput = false;
622 glslCaps->fFBFetchSupport = true;
623 glslCaps->fFBFetchColorName = "gl_LastFragColorARM";
624 glslCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
625 }
626 glslCaps->fUsesPrecisionModifiers = true;
627 }
628
629 glslCaps->fBindlessTextureSupport = ctxInfo.hasExtension("GL_NV_bindless_texture");
630
631 if (kGL_GrGLStandard == standard) {
632 glslCaps->fFlatInterpolationSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
633 } else {
634 glslCaps->fFlatInterpolationSupport =
635 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // This is the value for GLSL ES 3.0.
636 }
637
638 if (kGL_GrGLStandard == standard) {
639 glslCaps->fNoPerspectiveInterpolationSupport =
640 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
641 } else {
642 if (ctxInfo.hasExtension("GL_NV_shader_noperspective_interpolation")) {
643 glslCaps->fNoPerspectiveInterpolationSupport = true;
644 glslCaps->fNoPerspectiveInterpolationExtensionString =
645 "GL_NV_shader_noperspective_interpolation";
646 }
647 }
648
649 if (kGL_GrGLStandard == standard) {
650 glslCaps->fSampleVariablesSupport = ctxInfo.glslGeneration() >= k400_GrGLSLGeneration;
651 } else {
652 if (ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration) {
653 glslCaps->fSampleVariablesSupport = true;
654 } else if (ctxInfo.hasExtension("GL_OES_sample_variables")) {
655 glslCaps->fSampleVariablesSupport = true;
656 glslCaps->fSampleVariablesExtensionString = "GL_OES_sample_variables";
657 }
658 }
659
660 if (glslCaps->fSampleVariablesSupport) {
661 glslCaps->fSampleMaskOverrideCoverageSupport =
662 ctxInfo.hasExtension("GL_NV_sample_mask_override_coverage");
663 }
664
665 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
666 glslCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
667
668 // On the NexusS and GalaxyNexus, the use of 'any' causes the compilation error "Calls to any
669 // function that may require a gradient calculation inside a conditional block may return
670 // undefined results". This appears to be an issue with the 'any' call since even the simple
671 // "result=black; if (any()) result=white;" code fails to compile. This issue comes into play
672 // from our GrTextureDomain processor.
673 glslCaps->fCanUseAnyFunctionInShader = kImagination_GrGLVendor != ctxInfo.vendor();
674
675 glslCaps->fVersionDeclString = get_glsl_version_decl_string(standard, glslCaps->fGLSLGeneration,
676 fIsCoreProfile);
677
678 if (kGLES_GrGLStandard == standard && k110_GrGLSLGeneration == glslCaps->fGLSLGeneration) {
679 glslCaps->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
680 }
681
682 // Frag Coords Convention support is not part of ES
683 // Known issue on at least some Intel platforms:
684 // http://code.google.com/p/skia/issues/detail?id=946
685 if (kIntel_GrGLVendor != ctxInfo.vendor() &&
686 kGLES_GrGLStandard != standard &&
687 (ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
688 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"))) {
689 glslCaps->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions";
690 }
691
692 if (kGLES_GrGLStandard == standard) {
693 glslCaps->fSecondaryOutputExtensionString = "GL_EXT_blend_func_extended";
694 }
695
696 if (fExternalTextureSupport) {
697 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
698 glslCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
699 } else {
700 glslCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
701 }
702 }
703
704 // The Tegra3 compiler will sometimes never return if we have min(abs(x), 1.0), so we must do
705 // the abs first in a separate expression.
706 if (kTegra3_GrGLRenderer == ctxInfo.renderer()) {
707 glslCaps->fCanUseMinAndAbsTogether = false;
708 }
709
710 // On Intel GPU there is an issue where it reads the second argument to atan "- %s.x" as an int
711 // thus must us -1.0 * %s.x to work correctly
712 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
713 glslCaps->fMustForceNegatedAtanParamToFloat = true;
714 }
715 }
716
hasPathRenderingSupport(const GrGLContextInfo & ctxInfo,const GrGLInterface * gli)717 bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
718 bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering");
719
720 if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) {
721 return false;
722 }
723
724 if (kGL_GrGLStandard == ctxInfo.standard()) {
725 if (ctxInfo.version() < GR_GL_VER(4, 3) &&
726 !ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
727 return false;
728 }
729 } else {
730 if (!hasChromiumPathRendering &&
731 ctxInfo.version() < GR_GL_VER(3, 1)) {
732 return false;
733 }
734 }
735 // We only support v1.3+ of GL_NV_path_rendering which allows us to
736 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
737 // additions are detected by checking the existence of the function.
738 // We also use *Then* functions that not all drivers might have. Check
739 // them for consistency.
740 if (!gli->fFunctions.fStencilThenCoverFillPath ||
741 !gli->fFunctions.fStencilThenCoverStrokePath ||
742 !gli->fFunctions.fStencilThenCoverFillPathInstanced ||
743 !gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
744 !gli->fFunctions.fProgramPathFragmentInputGen) {
745 return false;
746 }
747 return true;
748 }
749
readPixelsSupported(GrPixelConfig rtConfig,GrPixelConfig readConfig,std::function<void (GrGLenum,GrGLint *)> getIntegerv,std::function<bool ()> bindRenderTarget) const750 bool GrGLCaps::readPixelsSupported(GrPixelConfig rtConfig,
751 GrPixelConfig readConfig,
752 std::function<void (GrGLenum, GrGLint*)> getIntegerv,
753 std::function<bool ()> bindRenderTarget) const {
754 // If it's not possible to even have a render target of rtConfig then read pixels is
755 // not supported regardless of readConfig.
756 if (!this->isConfigRenderable(rtConfig, false)) {
757 return false;
758 }
759
760 GrGLenum readFormat;
761 GrGLenum readType;
762 if (!this->getReadPixelsFormat(rtConfig, readConfig, &readFormat, &readType)) {
763 return false;
764 }
765
766 if (kGL_GrGLStandard == fStandard) {
767 // Some OpenGL implementations allow GL_ALPHA as a format to glReadPixels. However,
768 // the manual (https://www.opengl.org/sdk/docs/man/) says only these formats are allowed:
769 // GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL, GL_RED, GL_GREEN, GL_BLUE,
770 // GL_RGB, GL_BGR, GL_RGBA, and GL_BGRA. We check for the subset that we would use.
771 if (readFormat != GR_GL_RED && readFormat != GR_GL_RGB && readFormat != GR_GL_RGBA &&
772 readFormat != GR_GL_BGRA) {
773 return false;
774 }
775 // There is also a set of allowed types, but all the types we use are in the set:
776 // GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT,
777 // GL_HALF_FLOAT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV,
778 // GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4,
779 // GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV,
780 // GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV,GL_UNSIGNED_INT_10_10_10_2,
781 // GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV,
782 // GL_UNSIGNED_INT_5_9_9_9_REV, or GL_FLOAT_32_UNSIGNED_INT_24_8_REV.
783 return true;
784 }
785
786 // See Section 16.1.2 in the ES 3.2 specification.
787
788 if (kNormalizedFixedPoint_FormatType == fConfigTable[rtConfig].fFormatType) {
789 if (GR_GL_RGBA == readFormat && GR_GL_UNSIGNED_BYTE == readType) {
790 return true;
791 }
792 } else {
793 SkASSERT(kFloat_FormatType == fConfigTable[rtConfig].fFormatType);
794 if (GR_GL_RGBA == readFormat && GR_GL_FLOAT == readType) {
795 return true;
796 }
797 }
798
799 if (0 == fConfigTable[rtConfig].fSecondReadPixelsFormat.fFormat) {
800 ReadPixelsFormat* rpFormat =
801 const_cast<ReadPixelsFormat*>(&fConfigTable[rtConfig].fSecondReadPixelsFormat);
802 GrGLint format = 0, type = 0;
803 if (!bindRenderTarget()) {
804 return false;
805 }
806 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, &format);
807 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, &type);
808 rpFormat->fFormat = format;
809 rpFormat->fType = type;
810 }
811
812 return fConfigTable[rtConfig].fSecondReadPixelsFormat.fFormat == readFormat &&
813 fConfigTable[rtConfig].fSecondReadPixelsFormat.fType == readType;
814 }
815
initFSAASupport(const GrGLContextInfo & ctxInfo,const GrGLInterface * gli)816 void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
817
818 fMSFBOType = kNone_MSFBOType;
819 if (kGL_GrGLStandard != ctxInfo.standard()) {
820 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
821 // ES3 driver bugs on at least one device with a tiled GPU (N10).
822 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
823 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
824 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
825 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
826 } else if (fUsesMixedSamples) {
827 fMSFBOType = kMixedSamples_MSFBOType;
828 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
829 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType;
830 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
831 // chrome's extension is equivalent to the EXT msaa
832 // and fbo_blit extensions.
833 fMSFBOType = kDesktop_EXT_MSFBOType;
834 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
835 fMSFBOType = kES_Apple_MSFBOType;
836 }
837
838 // Above determined the preferred MSAA approach, now decide whether glBlitFramebuffer
839 // is available.
840 if (ctxInfo.version() >= GR_GL_VER(3, 0)) {
841 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
842 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
843 // The CHROMIUM extension uses the ANGLE version of glBlitFramebuffer and includes its
844 // limitations.
845 fBlitFramebufferSupport = kNoScalingNoMirroring_BlitFramebufferSupport;
846 }
847 } else {
848 if (fUsesMixedSamples) {
849 fMSFBOType = kMixedSamples_MSFBOType;
850 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
851 } else if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
852 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
853 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
854 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
855 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
856 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
857 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
858 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
859 }
860 }
861 }
862
initBlendEqationSupport(const GrGLContextInfo & ctxInfo)863 void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
864 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
865
866 // Disabling advanced blend on various platforms with major known issues. We also block Chrome
867 // for now until its own blacklists can be updated.
868 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer() ||
869 kIntel_GrGLDriver == ctxInfo.driver() ||
870 kChromium_GrGLDriver == ctxInfo.driver()) {
871 return;
872 }
873
874 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
875 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
876 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
877 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent")) {
878 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
879 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
880 } else if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
881 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337,00)) {
882 // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
883 return;
884 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
885 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
886 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
887 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced")) {
888 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
889 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
890 // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
891 // slow on a particular platform.
892 } else {
893 return; // No advanced blend support.
894 }
895
896 SkASSERT(this->advancedBlendEquationSupport());
897
898 if (kNVIDIA_GrGLDriver == ctxInfo.driver()) {
899 // Blacklist color-dodge and color-burn on NVIDIA until the fix is released.
900 fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
901 (1 << kColorBurn_GrBlendEquation);
902 }
903 if (kARM_GrGLVendor == ctxInfo.vendor()) {
904 // Blacklist color-burn on ARM until the fix is released.
905 fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation);
906 }
907 }
908
909 namespace {
910 const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
911 }
912
initStencilFormats(const GrGLContextInfo & ctxInfo)913 void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
914
915 // Build up list of legal stencil formats (though perhaps not supported on
916 // the particular gpu/driver) from most preferred to least.
917
918 // these consts are in order of most preferred to least preferred
919 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
920
921 static const StencilFormat
922 // internal Format stencil bits total bits packed?
923 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
924 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
925 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
926 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
927 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
928 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
929
930 if (kGL_GrGLStandard == ctxInfo.standard()) {
931 bool supportsPackedDS =
932 ctxInfo.version() >= GR_GL_VER(3,0) ||
933 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
934 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
935
936 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
937 // require FBO support we can expect these are legal formats and don't
938 // check. These also all support the unsized GL_STENCIL_INDEX.
939 fStencilFormats.push_back() = gS8;
940 fStencilFormats.push_back() = gS16;
941 if (supportsPackedDS) {
942 fStencilFormats.push_back() = gD24S8;
943 }
944 fStencilFormats.push_back() = gS4;
945 if (supportsPackedDS) {
946 fStencilFormats.push_back() = gDS;
947 }
948 } else {
949 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
950 // for other formats.
951 // ES doesn't support using the unsized format.
952
953 fStencilFormats.push_back() = gS8;
954 //fStencilFormats.push_back() = gS16;
955 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
956 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
957 fStencilFormats.push_back() = gD24S8;
958 }
959 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
960 fStencilFormats.push_back() = gS4;
961 }
962 }
963 }
964
dump() const965 SkString GrGLCaps::dump() const {
966
967 SkString r = INHERITED::dump();
968
969 r.appendf("--- GL-Specific ---\n");
970 for (int i = 0; i < fStencilFormats.count(); ++i) {
971 r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
972 i,
973 fStencilFormats[i].fStencilBits,
974 fStencilFormats[i].fTotalBits);
975 }
976
977 static const char* kMSFBOExtStr[] = {
978 "None",
979 "ARB",
980 "EXT",
981 "ES 3.0",
982 "Apple",
983 "IMG MS To Texture",
984 "EXT MS To Texture",
985 "MixedSamples",
986 };
987 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
988 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
989 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
990 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType);
991 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType);
992 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType);
993 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType);
994 GR_STATIC_ASSERT(7 == kMixedSamples_MSFBOType);
995 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
996
997 static const char* kInvalidateFBTypeStr[] = {
998 "None",
999 "Discard",
1000 "Invalidate",
1001 };
1002 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
1003 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
1004 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
1005 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
1006
1007 static const char* kMapBufferTypeStr[] = {
1008 "None",
1009 "MapBuffer",
1010 "MapBufferRange",
1011 "Chromium",
1012 };
1013 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
1014 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
1015 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
1016 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
1017 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
1018
1019 r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
1020 r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
1021 r.appendf("Invalidate FB Type: %s\n", kInvalidateFBTypeStr[fInvalidateFBType]);
1022 r.appendf("Map Buffer Type: %s\n", kMapBufferTypeStr[fMapBufferType]);
1023 r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
1024 r.appendf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits);
1025 r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
1026 r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
1027 r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
1028 r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
1029 r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
1030
1031 r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
1032 r.appendf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
1033 r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
1034 r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
1035 r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
1036 r.appendf("Direct state access support: %s\n", (fDirectStateAccessSupport ? "YES": "NO"));
1037 r.appendf("Debug support: %s\n", (fDebugSupport ? "YES": "NO"));
1038 r.appendf("Multisample disable support: %s\n", (fMultisampleDisableSupport ? "YES" : "NO"));
1039 r.appendf("Draw indirect support: %s\n", (fDrawIndirectSupport ? "YES" : "NO"));
1040 r.appendf("Multi draw indirect support: %s\n", (fMultiDrawIndirectSupport ? "YES" : "NO"));
1041 r.appendf("Base instance support: %s\n", (fBaseInstanceSupport ? "YES" : "NO"));
1042 r.appendf("Use non-VBO for dynamic data: %s\n",
1043 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
1044 r.appendf("SRGB write contol: %s\n", (fSRGBWriteControl ? "YES" : "NO"));
1045 r.appendf("RGBA 8888 pixel ops are slow: %s\n", (fRGBA8888PixelsOpsAreSlow ? "YES" : "NO"));
1046 r.appendf("Partial FBO read is slow: %s\n", (fPartialFBOReadIsSlow ? "YES" : "NO"));
1047 r.appendf("Bind uniform location support: %s\n", (fBindUniformLocationSupport ? "YES" : "NO"));
1048 r.appendf("External texture support: %s\n", (fExternalTextureSupport ? "YES" : "NO"));
1049 r.appendf("Rectangle texture support: %s\n", (fRectangleTextureSupport? "YES" : "NO"));
1050 r.appendf("Texture swizzle support: %s\n", (fTextureSwizzleSupport ? "YES" : "NO"));
1051
1052 r.append("Configs\n-------\n");
1053 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1054 r.appendf(" cfg: %d flags: 0x%04x, b_internal: 0x%08x s_internal: 0x%08x, e_format: "
1055 "0x%08x, e_format_teximage: 0x%08x, e_type: 0x%08x, i_for_teximage: 0x%08x, "
1056 "i_for_renderbuffer: 0x%08x\n",
1057 i,
1058 fConfigTable[i].fFlags,
1059 fConfigTable[i].fFormats.fBaseInternalFormat,
1060 fConfigTable[i].fFormats.fSizedInternalFormat,
1061 fConfigTable[i].fFormats.fExternalFormat[kOther_ExternalFormatUsage],
1062 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage],
1063 fConfigTable[i].fFormats.fExternalType,
1064 fConfigTable[i].fFormats.fInternalFormatTexImage,
1065 fConfigTable[i].fFormats.fInternalFormatRenderbuffer);
1066 }
1067
1068 return r;
1069 }
1070
precision_to_gl_float_type(GrSLPrecision p)1071 static GrGLenum precision_to_gl_float_type(GrSLPrecision p) {
1072 switch (p) {
1073 case kLow_GrSLPrecision:
1074 return GR_GL_LOW_FLOAT;
1075 case kMedium_GrSLPrecision:
1076 return GR_GL_MEDIUM_FLOAT;
1077 case kHigh_GrSLPrecision:
1078 return GR_GL_HIGH_FLOAT;
1079 }
1080 SkFAIL("Unknown precision.");
1081 return -1;
1082 }
1083
shader_type_to_gl_shader(GrShaderType type)1084 static GrGLenum shader_type_to_gl_shader(GrShaderType type) {
1085 switch (type) {
1086 case kVertex_GrShaderType:
1087 return GR_GL_VERTEX_SHADER;
1088 case kGeometry_GrShaderType:
1089 return GR_GL_GEOMETRY_SHADER;
1090 case kFragment_GrShaderType:
1091 return GR_GL_FRAGMENT_SHADER;
1092 }
1093 SkFAIL("Unknown shader type.");
1094 return -1;
1095 }
1096
initShaderPrecisionTable(const GrGLContextInfo & ctxInfo,const GrGLInterface * intf,GrGLSLCaps * glslCaps)1097 void GrGLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
1098 const GrGLInterface* intf,
1099 GrGLSLCaps* glslCaps) {
1100 if (kGLES_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(4, 1) ||
1101 ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
1102 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1103 if (kGeometry_GrShaderType != s) {
1104 GrShaderType shaderType = static_cast<GrShaderType>(s);
1105 GrGLenum glShader = shader_type_to_gl_shader(shaderType);
1106 GrShaderCaps::PrecisionInfo* first = nullptr;
1107 glslCaps->fShaderPrecisionVaries = false;
1108 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1109 GrSLPrecision precision = static_cast<GrSLPrecision>(p);
1110 GrGLenum glPrecision = precision_to_gl_float_type(precision);
1111 GrGLint range[2];
1112 GrGLint bits;
1113 GR_GL_GetShaderPrecisionFormat(intf, glShader, glPrecision, range, &bits);
1114 if (bits) {
1115 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = range[0];
1116 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = range[1];
1117 glslCaps->fFloatPrecisions[s][p].fBits = bits;
1118 if (!first) {
1119 first = &glslCaps->fFloatPrecisions[s][p];
1120 }
1121 else if (!glslCaps->fShaderPrecisionVaries) {
1122 glslCaps->fShaderPrecisionVaries =
1123 (*first != glslCaps->fFloatPrecisions[s][p]);
1124 }
1125 }
1126 }
1127 }
1128 }
1129 }
1130 else {
1131 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
1132 glslCaps->fShaderPrecisionVaries = false;
1133 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1134 if (kGeometry_GrShaderType != s) {
1135 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1136 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = 127;
1137 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = 127;
1138 glslCaps->fFloatPrecisions[s][p].fBits = 23;
1139 }
1140 }
1141 }
1142 }
1143 // GetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Assume they're
1144 // the same as the vertex shader. Only fragment shaders were ever allowed to omit support for
1145 // highp. GS was added after GetShaderPrecisionFormat was added to the list of features that
1146 // are recommended against.
1147 if (glslCaps->fGeometryShaderSupport) {
1148 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1149 glslCaps->fFloatPrecisions[kGeometry_GrShaderType][p] =
1150 glslCaps->fFloatPrecisions[kVertex_GrShaderType][p];
1151 }
1152 }
1153 }
1154
bgraIsInternalFormat() const1155 bool GrGLCaps::bgraIsInternalFormat() const {
1156 return fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_BGRA;
1157 }
1158
getTexImageFormats(GrPixelConfig surfaceConfig,GrPixelConfig externalConfig,GrGLenum * internalFormat,GrGLenum * externalFormat,GrGLenum * externalType) const1159 bool GrGLCaps::getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1160 GrGLenum* internalFormat, GrGLenum* externalFormat,
1161 GrGLenum* externalType) const {
1162 if (!this->getExternalFormat(surfaceConfig, externalConfig, kTexImage_ExternalFormatUsage,
1163 externalFormat, externalType)) {
1164 return false;
1165 }
1166 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1167 return true;
1168 }
1169
getCompressedTexImageFormats(GrPixelConfig surfaceConfig,GrGLenum * internalFormat) const1170 bool GrGLCaps::getCompressedTexImageFormats(GrPixelConfig surfaceConfig,
1171 GrGLenum* internalFormat) const {
1172 if (!GrPixelConfigIsCompressed(surfaceConfig)) {
1173 return false;
1174 }
1175 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1176 return true;
1177 }
1178
getReadPixelsFormat(GrPixelConfig surfaceConfig,GrPixelConfig externalConfig,GrGLenum * externalFormat,GrGLenum * externalType) const1179 bool GrGLCaps::getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1180 GrGLenum* externalFormat, GrGLenum* externalType) const {
1181 if (!this->getExternalFormat(surfaceConfig, externalConfig, kOther_ExternalFormatUsage,
1182 externalFormat, externalType)) {
1183 return false;
1184 }
1185 return true;
1186 }
1187
getRenderbufferFormat(GrPixelConfig config,GrGLenum * internalFormat) const1188 bool GrGLCaps::getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const {
1189 if (GrPixelConfigIsCompressed(config)) {
1190 return false;
1191 }
1192 *internalFormat = fConfigTable[config].fFormats.fInternalFormatRenderbuffer;
1193 return true;
1194 }
1195
getExternalFormat(GrPixelConfig surfaceConfig,GrPixelConfig memoryConfig,ExternalFormatUsage usage,GrGLenum * externalFormat,GrGLenum * externalType) const1196 bool GrGLCaps::getExternalFormat(GrPixelConfig surfaceConfig, GrPixelConfig memoryConfig,
1197 ExternalFormatUsage usage, GrGLenum* externalFormat,
1198 GrGLenum* externalType) const {
1199 SkASSERT(externalFormat && externalType);
1200 if (GrPixelConfigIsCompressed(memoryConfig) || GrPixelConfigIsCompressed(memoryConfig)) {
1201 return false;
1202 }
1203
1204 bool surfaceIsAlphaOnly = GrPixelConfigIsAlphaOnly(surfaceConfig);
1205 bool memoryIsAlphaOnly = GrPixelConfigIsAlphaOnly(memoryConfig);
1206
1207 // We don't currently support moving RGBA data into and out of ALPHA surfaces. It could be
1208 // made to work in many cases using glPixelStore and what not but is not needed currently.
1209 if (surfaceIsAlphaOnly && !memoryIsAlphaOnly) {
1210 return false;
1211 }
1212
1213 *externalFormat = fConfigTable[memoryConfig].fFormats.fExternalFormat[usage];
1214 *externalType = fConfigTable[memoryConfig].fFormats.fExternalType;
1215
1216 // When GL_RED is supported as a texture format, our alpha-only textures are stored using
1217 // GL_RED and we swizzle in order to map all components to 'r'. However, in this case the
1218 // surface is not alpha-only and we want alpha to really mean the alpha component of the
1219 // texture, not the red component.
1220 if (memoryIsAlphaOnly && !surfaceIsAlphaOnly) {
1221 if (this->textureRedSupport()) {
1222 SkASSERT(GR_GL_RED == *externalFormat);
1223 *externalFormat = GR_GL_ALPHA;
1224 }
1225 }
1226
1227 return true;
1228 }
1229
initConfigTable(const GrGLContextInfo & ctxInfo,const GrGLInterface * gli,GrGLSLCaps * glslCaps)1230 void GrGLCaps::initConfigTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
1231 GrGLSLCaps* glslCaps) {
1232 /*
1233 Comments on renderability of configs on various GL versions.
1234 OpenGL < 3.0:
1235 no built in support for render targets.
1236 GL_EXT_framebuffer_object adds possible support for any sized format with base internal
1237 format RGB, RGBA and NV float formats we don't use.
1238 This is the following:
1239 R3_G3_B2, RGB4, RGB5, RGB8, RGB10, RGB12, RGB16, RGBA2, RGBA4, RGB5_A1, RGBA8
1240 RGB10_A2, RGBA12,RGBA16
1241 Though, it is hard to believe the more obscure formats such as RGBA12 would work
1242 since they aren't required by later standards and the driver can simply return
1243 FRAMEBUFFER_UNSUPPORTED for anything it doesn't allow.
1244 GL_ARB_framebuffer_object adds everything added by the EXT extension and additionally
1245 any sized internal format with a base internal format of ALPHA, LUMINANCE,
1246 LUMINANCE_ALPHA, INTENSITY, RED, and RG.
1247 This adds a lot of additional renderable sized formats, including ALPHA8.
1248 The GL_ARB_texture_rg brings in the RED and RG formats (8, 8I, 8UI, 16, 16I, 16UI,
1249 16F, 32I, 32UI, and 32F variants).
1250 Again, the driver has an escape hatch via FRAMEBUFFER_UNSUPPORTED.
1251
1252 For both the above extensions we limit ourselves to those that are also required by
1253 OpenGL 3.0.
1254
1255 OpenGL 3.0:
1256 Any format with base internal format ALPHA, RED, RG, RGB or RGBA is "color-renderable"
1257 but are not required to be supported as renderable textures/renderbuffer.
1258 Required renderable color formats:
1259 - RGBA32F, RGBA32I, RGBA32UI, RGBA16, RGBA16F, RGBA16I,
1260 RGBA16UI, RGBA8, RGBA8I, RGBA8UI, SRGB8_ALPHA8, and
1261 RGB10_A2.
1262 - R11F_G11F_B10F.
1263 - RG32F, RG32I, RG32UI, RG16, RG16F, RG16I, RG16UI, RG8, RG8I,
1264 and RG8UI.
1265 - R32F, R32I, R32UI, R16F, R16I, R16UI, R16, R8, R8I, and R8UI.
1266 - ALPHA8
1267
1268 OpenGL 3.1, 3.2, 3.3
1269 Same as 3.0 except ALPHA8 requires GL_ARB_compatibility/compatibility profile.
1270 OpengGL 3.3, 4.0, 4.1
1271 Adds RGB10_A2UI.
1272 OpengGL 4.2
1273 Adds
1274 - RGB5_A1, RGBA4
1275 - RGB565
1276 OpenGL 4.4
1277 Does away with the separate list and adds a column to the sized internal color format
1278 table. However, no new formats become required color renderable.
1279
1280 ES 2.0
1281 color renderable: RGBA4, RGB5_A1, RGB565
1282 GL_EXT_texture_rg adds support for R8, RG5 as a color render target
1283 GL_OES_rgb8_rgba8 adds support for RGB8 and RGBA8
1284 GL_ARM_rgba8 adds support for RGBA8 (but not RGB8)
1285 GL_EXT_texture_format_BGRA8888 does not add renderbuffer support
1286 GL_CHROMIUM_renderbuffer_format_BGRA8888 adds BGRA8 as color-renderable
1287 GL_APPLE_texture_format_BGRA8888 does not add renderbuffer support
1288
1289 ES 3.0
1290 - RGBA32I, RGBA32UI, RGBA16I, RGBA16UI, RGBA8, RGBA8I,
1291 RGBA8UI, SRGB8_ALPHA8, RGB10_A2, RGB10_A2UI, RGBA4, and
1292 RGB5_A1.
1293 - RGB8 and RGB565.
1294 - RG32I, RG32UI, RG16I, RG16UI, RG8, RG8I, and RG8UI.
1295 - R32I, R32UI, R16I, R16UI, R8, R8I, and R8UI
1296 ES 3.1
1297 Adds RGB10_A2, RGB10_A2UI,
1298 ES 3.2
1299 Adds R16F, RG16F, RGBA16F, R32F, RG32F, RGBA32F, R11F_G11F_B10F.
1300 */
1301 uint32_t allRenderFlags = ConfigInfo::kRenderable_Flag;
1302 if (kNone_MSFBOType != fMSFBOType) {
1303 allRenderFlags |= ConfigInfo::kRenderableWithMSAA_Flag;
1304 }
1305
1306 GrGLStandard standard = ctxInfo.standard();
1307 GrGLVersion version = ctxInfo.version();
1308
1309 fConfigTable[kUnknown_GrPixelConfig].fFormats.fBaseInternalFormat = 0;
1310 fConfigTable[kUnknown_GrPixelConfig].fFormats.fSizedInternalFormat = 0;
1311 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
1312 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalType = 0;
1313 fConfigTable[kUnknown_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1314 fConfigTable[kUnknown_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1315
1316 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1317 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1318 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1319 GR_GL_RGBA;
1320 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1321 fConfigTable[kRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1322 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1323 if (kGL_GrGLStandard == standard) {
1324 // We require some form of FBO support and all GLs with FBO support can render to RGBA8
1325 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
1326 } else {
1327 if (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
1328 ctxInfo.hasExtension("GL_ARM_rgba8")) {
1329 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
1330 }
1331 }
1332 fConfigTable[kRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1333
1334 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1335 GR_GL_BGRA;
1336 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1337 fConfigTable[kBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1338 if (kGL_GrGLStandard == standard) {
1339 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1340 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1341 if (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra")) {
1342 // Since the internal format is RGBA8, it is also renderable.
1343 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1344 allRenderFlags;
1345 }
1346 } else {
1347 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_BGRA;
1348 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_BGRA8;
1349 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
1350 // The APPLE extension doesn't make this renderable.
1351 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1352 if (version < GR_GL_VER(3,0) && !ctxInfo.hasExtension("GL_EXT_texture_storage")) {
1353 // On ES2 the internal format of a BGRA texture is RGBA with the APPLE extension.
1354 // Though, that seems to not be the case if the texture storage extension is
1355 // present. The specs don't exactly make that clear.
1356 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1357 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1358 }
1359 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
1360 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1361 ConfigInfo::kRenderable_Flag;
1362 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888") &&
1363 (this->usesMSAARenderBuffers() || this->fMSFBOType == kMixedSamples_MSFBOType)) {
1364 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |=
1365 ConfigInfo::kRenderableWithMSAA_Flag;
1366 }
1367 }
1368 }
1369 fConfigTable[kBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1370
1371 // We only enable srgb support if both textures and FBOs support srgb.
1372 bool srgbSupport = false;
1373 if (kGL_GrGLStandard == standard) {
1374 if (ctxInfo.version() >= GR_GL_VER(3,0)) {
1375 srgbSupport = true;
1376 } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
1377 if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
1378 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
1379 srgbSupport = true;
1380 }
1381 }
1382 // All the above srgb extensions support toggling srgb writes
1383 fSRGBWriteControl = srgbSupport;
1384 } else {
1385 // See https://bug.skia.org/4148 for PowerVR issue.
1386 srgbSupport = kPowerVRRogue_GrGLRenderer != ctxInfo.renderer() &&
1387 (ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB"));
1388 // ES through 3.1 requires EXT_srgb_write_control to support toggling
1389 // sRGB writing for destinations.
1390 fSRGBWriteControl = ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
1391 }
1392 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1393 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1394 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1395 // external format is GL_RGBA. See below for note about ES2.0 and glTex[Sub]Image.
1396 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1397 GR_GL_RGBA;
1398 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1399 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1400 if (srgbSupport) {
1401 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1402 allRenderFlags;
1403 }
1404 fConfigTable[kSRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1405
1406 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1407 if (this->ES2CompatibilitySupport()) {
1408 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB565;
1409 } else {
1410 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB5;
1411 }
1412 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1413 GR_GL_RGB;
1414 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_5_6_5;
1415 fConfigTable[kRGB_565_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1416 fConfigTable[kRGB_565_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1417 if (kGL_GrGLStandard == standard) {
1418 if (version >= GR_GL_VER(4, 2) || ctxInfo.hasExtension("GL_ES2_compatibility")) {
1419 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1420 }
1421 } else {
1422 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1423 }
1424 fConfigTable[kRGB_565_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1425
1426 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1427 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA4;
1428 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1429 GR_GL_RGBA;
1430 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
1431 fConfigTable[kRGBA_4444_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1432 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1433 if (kGL_GrGLStandard == standard) {
1434 if (version >= GR_GL_VER(4, 2)) {
1435 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1436 }
1437 } else {
1438 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1439 }
1440 fConfigTable[kRGBA_4444_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1441
1442 if (this->textureRedSupport()) {
1443 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
1444 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R8;
1445 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1446 GR_GL_RED;
1447 fConfigTable[kAlpha_8_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
1448 } else {
1449 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1450 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA8;
1451 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1452 GR_GL_ALPHA;
1453 fConfigTable[kAlpha_8_GrPixelConfig].fSwizzle = GrSwizzle::AAAA();
1454 }
1455 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1456 fConfigTable[kAlpha_8_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1457 fConfigTable[kAlpha_8_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1458 if (this->textureRedSupport() || kDesktop_ARB_MSFBOType == this->msFBOType()) {
1459 // desktop ARB extension/3.0+ supports ALPHA8 as renderable.
1460 // Core profile removes ALPHA8 support, but we should have chosen R8 in that case.
1461 fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= allRenderFlags;
1462 }
1463
1464 // Check for [half] floating point texture support
1465 // NOTE: We disallow floating point textures on ES devices if linear filtering modes are not
1466 // supported. This is for simplicity, but a more granular approach is possible. Coincidentally,
1467 // [half] floating point textures became part of the standard in ES3.1 / OGL 3.0.
1468 bool hasFPTextures = false;
1469 bool hasHalfFPTextures = false;
1470 // for now we don't support floating point MSAA on ES
1471 uint32_t fpRenderFlags = (kGL_GrGLStandard == standard) ?
1472 allRenderFlags : (uint32_t)ConfigInfo::kRenderable_Flag;
1473
1474 if (kGL_GrGLStandard == standard) {
1475 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_float")) {
1476 hasFPTextures = true;
1477 hasHalfFPTextures = true;
1478 }
1479 } else {
1480 if (version >= GR_GL_VER(3, 1)) {
1481 hasFPTextures = true;
1482 hasHalfFPTextures = true;
1483 } else {
1484 if (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
1485 ctxInfo.hasExtension("GL_OES_texture_float")) {
1486 hasFPTextures = true;
1487 }
1488 if (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
1489 ctxInfo.hasExtension("GL_OES_texture_half_float")) {
1490 hasHalfFPTextures = true;
1491 }
1492 }
1493 }
1494
1495 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1496 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA32F;
1497 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1498 GR_GL_RGBA;
1499 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fExternalType = GR_GL_FLOAT;
1500 fConfigTable[kRGBA_float_GrPixelConfig].fFormatType = kFloat_FormatType;
1501 if (hasFPTextures) {
1502 fConfigTable[kRGBA_float_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1503 // For now we only enable rendering to float on desktop, because on ES we'd have to solve
1504 // many precision issues and no clients actually want this yet.
1505 if (kGL_GrGLStandard == standard /* || version >= GR_GL_VER(3,2) ||
1506 ctxInfo.hasExtension("GL_EXT_color_buffer_float")*/) {
1507 fConfigTable[kRGBA_float_GrPixelConfig].fFlags |= fpRenderFlags;
1508 }
1509 }
1510 fConfigTable[kRGBA_float_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1511
1512 if (this->textureRedSupport()) {
1513 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
1514 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R16F;
1515 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage]
1516 = GR_GL_RED;
1517 fConfigTable[kAlpha_half_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
1518 } else {
1519 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1520 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA16F;
1521 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage]
1522 = GR_GL_ALPHA;
1523 fConfigTable[kAlpha_half_GrPixelConfig].fSwizzle = GrSwizzle::AAAA();
1524 }
1525 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
1526 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1527 } else {
1528 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1529 }
1530 fConfigTable[kAlpha_half_GrPixelConfig].fFormatType = kFloat_FormatType;
1531 if (hasHalfFPTextures) {
1532 fConfigTable[kAlpha_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1533 // ES requires either 3.2 or the combination of EXT_color_buffer_half_float and support for
1534 // GL_RED internal format.
1535 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3,2) ||
1536 (this->textureRedSupport() &&
1537 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float"))) {
1538 fConfigTable[kAlpha_half_GrPixelConfig].fFlags |= fpRenderFlags;
1539 }
1540 }
1541
1542 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1543 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA16F;
1544 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1545 GR_GL_RGBA;
1546 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
1547 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1548 } else {
1549 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1550 }
1551 fConfigTable[kRGBA_half_GrPixelConfig].fFormatType = kFloat_FormatType;
1552 if (hasHalfFPTextures) {
1553 fConfigTable[kRGBA_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1554 // ES requires 3.2 or EXT_color_buffer_half_float.
1555 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3,2) ||
1556 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
1557 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= fpRenderFlags;
1558 }
1559 }
1560 fConfigTable[kRGBA_half_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1561
1562 // Compressed texture support
1563
1564 // glCompressedTexImage2D is available on all OpenGL ES devices. It is available on standard
1565 // OpenGL after version 1.3. We'll assume at least that level of OpenGL support.
1566
1567 // TODO: Fix command buffer bindings and remove this.
1568 fCompressedTexSubImageSupport = SkToBool(gli->fFunctions.fCompressedTexSubImage2D);
1569
1570 // No sized/unsized internal format distinction for compressed formats, no external format.
1571 // Below we set the external formats and types to 0.
1572
1573 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_PALETTE8_RGBA8;
1574 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_PALETTE8_RGBA8;
1575 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
1576 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fExternalType = 0;
1577 fConfigTable[kIndex_8_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1578 // Disable this for now, while we investigate https://bug.skia.org/4333
1579 if (false) {
1580 // Check for 8-bit palette..
1581 GrGLint numFormats;
1582 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
1583 if (numFormats) {
1584 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
1585 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
1586 for (int i = 0; i < numFormats; ++i) {
1587 if (GR_GL_PALETTE8_RGBA8 == formats[i]) {
1588 fConfigTable[kIndex_8_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1589 break;
1590 }
1591 }
1592 }
1593 }
1594 fConfigTable[kIndex_8_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1595
1596 // May change the internal format based on extensions.
1597 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat =
1598 GR_GL_COMPRESSED_LUMINANCE_LATC1;
1599 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1600 GR_GL_COMPRESSED_LUMINANCE_LATC1;
1601 if (ctxInfo.hasExtension("GL_EXT_texture_compression_latc") ||
1602 ctxInfo.hasExtension("GL_NV_texture_compression_latc")) {
1603 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1604 } else if ((kGL_GrGLStandard == standard && version >= GR_GL_VER(3, 0)) ||
1605 ctxInfo.hasExtension("GL_EXT_texture_compression_rgtc") ||
1606 ctxInfo.hasExtension("GL_ARB_texture_compression_rgtc")) {
1607 // RGTC is identical and available on OpenGL 3.0+ as well as with extensions
1608 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1609 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat =
1610 GR_GL_COMPRESSED_RED_RGTC1;
1611 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1612 GR_GL_COMPRESSED_RED_RGTC1;
1613 } else if (ctxInfo.hasExtension("GL_AMD_compressed_3DC_texture")) {
1614 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1615 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_3DC_X;
1616 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1617 GR_GL_COMPRESSED_3DC_X;
1618
1619 }
1620 fConfigTable[kLATC_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
1621 fConfigTable[kLATC_GrPixelConfig].fFormats.fExternalType = 0;
1622 fConfigTable[kLATC_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1623 fConfigTable[kLATC_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
1624
1625 fConfigTable[kETC1_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_ETC1_RGB8;
1626 fConfigTable[kETC1_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_COMPRESSED_ETC1_RGB8;
1627 fConfigTable[kETC1_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
1628 fConfigTable[kETC1_GrPixelConfig].fFormats.fExternalType = 0;
1629 fConfigTable[kETC1_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1630 if (kGL_GrGLStandard == standard) {
1631 if (version >= GR_GL_VER(4, 3) || ctxInfo.hasExtension("GL_ARB_ES3_compatibility")) {
1632 fConfigTable[kETC1_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1633 }
1634 } else {
1635 if (version >= GR_GL_VER(3, 0) ||
1636 ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") ||
1637 // ETC2 is a superset of ETC1, so we can just check for that, too.
1638 (ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") &&
1639 ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture"))) {
1640 fConfigTable[kETC1_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1641 }
1642 }
1643 fConfigTable[kETC1_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1644
1645 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_R11_EAC;
1646 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_COMPRESSED_R11_EAC;
1647 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
1648 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fExternalType = 0;
1649 fConfigTable[kR11_EAC_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1650 // Check for R11_EAC. We don't support R11_EAC on desktop, as most cards default to
1651 // decompressing the textures in the driver, and is generally slower.
1652 if (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) {
1653 fConfigTable[kR11_EAC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1654 }
1655 fConfigTable[kR11_EAC_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
1656
1657 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fBaseInternalFormat =
1658 GR_GL_COMPRESSED_RGBA_ASTC_12x12;
1659 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fSizedInternalFormat =
1660 GR_GL_COMPRESSED_RGBA_ASTC_12x12;
1661 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1662 0;
1663 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fExternalType = 0;
1664 fConfigTable[kASTC_12x12_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1665 if (ctxInfo.hasExtension("GL_KHR_texture_compression_astc_hdr") ||
1666 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_ldr") ||
1667 ctxInfo.hasExtension("GL_OES_texture_compression_astc")) {
1668 fConfigTable[kASTC_12x12_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1669 }
1670 fConfigTable[kASTC_12x12_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1671
1672 // Bulk populate the texture internal/external formats here and then deal with exceptions below.
1673
1674 // ES 2.0 requires that the internal/external formats match.
1675 bool useSizedTexFormats = (kGL_GrGLStandard == ctxInfo.standard() ||
1676 ctxInfo.version() >= GR_GL_VER(3,0));
1677 // All ES versions (thus far) require sized internal formats for render buffers.
1678 // TODO: Always use sized internal format?
1679 bool useSizedRbFormats = kGLES_GrGLStandard == ctxInfo.standard();
1680
1681 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1682 // Almost always we want to pass fExternalFormat[kOther_ExternalFormatUsage] as the <format>
1683 // param to glTex[Sub]Image.
1684 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
1685 fConfigTable[i].fFormats.fExternalFormat[kOther_ExternalFormatUsage];
1686 fConfigTable[i].fFormats.fInternalFormatTexImage = useSizedTexFormats ?
1687 fConfigTable[i].fFormats.fSizedInternalFormat :
1688 fConfigTable[i].fFormats.fBaseInternalFormat;
1689 fConfigTable[i].fFormats.fInternalFormatRenderbuffer = useSizedRbFormats ?
1690 fConfigTable[i].fFormats.fSizedInternalFormat :
1691 fConfigTable[i].fFormats.fBaseInternalFormat;
1692 }
1693 // OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the <format>
1694 // param to Tex(Sub)Image. ES 2.0 requires the <internalFormat> and <format> params to match.
1695 // Thus, on ES 2.0 we will use GL_SRGB_ALPHA as the <format> param.
1696 // On OpenGL and ES 3.0+ GL_SRGB_ALPHA does not work for the <format> param to glTexImage.
1697 if (ctxInfo.standard() == kGLES_GrGLStandard && ctxInfo.version() == GR_GL_VER(2,0)) {
1698 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
1699 GR_GL_SRGB_ALPHA;
1700 }
1701
1702 // If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image
1703 // as a base format.
1704 // GL_EXT_texture_format_BGRA8888:
1705 // This extension GL_BGRA as an unsized internal format. However, it is written against ES
1706 // 2.0 and therefore doesn't define a value for GL_BGRA8 as ES 2.0 uses unsized internal
1707 // formats.
1708 // GL_APPLE_texture_format_BGRA8888:
1709 // ES 2.0: the extension makes BGRA an external format but not an internal format.
1710 // ES 3.0: the extension explicitly states GL_BGRA8 is not a valid internal format for
1711 // glTexImage (just for glTexStorage).
1712 if (useSizedTexFormats && this->bgraIsInternalFormat()) {
1713 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fInternalFormatTexImage = GR_GL_BGRA;
1714 }
1715
1716 // If we don't have texture swizzle support then the shader generator must insert the
1717 // swizzle into shader code.
1718 if (!this->textureSwizzleSupport()) {
1719 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1720 glslCaps->fConfigTextureSwizzle[i] = fConfigTable[i].fSwizzle;
1721 }
1722 }
1723
1724 // Shader output swizzles will default to RGBA. When we've use GL_RED instead of GL_ALPHA to
1725 // implement kAlpha_8_GrPixelConfig we need to swizzle the shader outputs so the alpha channel
1726 // gets written to the single component.
1727 if (this->textureRedSupport()) {
1728 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1729 GrPixelConfig config = static_cast<GrPixelConfig>(i);
1730 if (GrPixelConfigIsAlphaOnly(config) &&
1731 fConfigTable[i].fFormats.fBaseInternalFormat == GR_GL_RED) {
1732 glslCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA();
1733 }
1734 }
1735 }
1736
1737 #ifdef SK_DEBUG
1738 // Make sure we initialized everything.
1739 ConfigInfo defaultEntry;
1740 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1741 SkASSERT(defaultEntry.fFormats.fBaseInternalFormat !=
1742 fConfigTable[i].fFormats.fBaseInternalFormat);
1743 SkASSERT(defaultEntry.fFormats.fSizedInternalFormat !=
1744 fConfigTable[i].fFormats.fSizedInternalFormat);
1745 for (int j = 0; j < kExternalFormatUsageCnt; ++j) {
1746 SkASSERT(defaultEntry.fFormats.fExternalFormat[j] !=
1747 fConfigTable[i].fFormats.fExternalFormat[j]);
1748 }
1749 SkASSERT(defaultEntry.fFormats.fExternalType != fConfigTable[i].fFormats.fExternalType);
1750 }
1751 #endif
1752 }
1753
onApplyOptionsOverrides(const GrContextOptions & options)1754 void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {}
1755