blob: 237412a7fcb7cdf8a5568d120121a74e9dbe0287 [file] [log] [blame]
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001/*
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"
joshualittb4384b92014-10-21 12:53:15 -070010
egdanielb7e7d572015-11-04 04:23:53 -080011#include "GrContextOptions.h"
robertphillips@google.com6177e692013-02-28 20:16:25 +000012#include "GrGLContext.h"
bsalomon1aa20292016-01-22 08:16:09 -080013#include "GrGLRenderTarget.h"
jvanverthcba99b82015-06-24 06:59:57 -070014#include "glsl/GrGLSLCaps.h"
bsalomon@google.comc9668ec2012-04-11 18:16:41 +000015#include "SkTSearch.h"
bsalomon@google.com20f7f172013-05-17 19:05:03 +000016#include "SkTSort.h"
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000017
bsalomon682c2692015-05-22 14:01:46 -070018GrGLCaps::GrGLCaps(const GrContextOptions& contextOptions,
19 const GrGLContextInfo& ctxInfo,
20 const GrGLInterface* glInterface) : INHERITED(contextOptions) {
bsalomon1aa20292016-01-22 08:16:09 -080021 fStandard = ctxInfo.standard();
22
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000023 fStencilFormats.reset();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000024 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +000025 fInvalidateFBType = kNone_InvalidateFBType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000026 fMapBufferType = kNone_MapBufferType;
jvanverthd7a2c1f2015-12-07 07:36:44 -080027 fTransferBufferType = kNone_TransferBufferType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000028 fMaxFragmentUniformVectors = 0;
bsalomon@google.com60da4172012-06-01 19:25:00 +000029 fMaxVertexAttributes = 0;
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +000030 fMaxFragmentTextureUnits = 0;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000031 fUnpackRowLengthSupport = false;
32 fUnpackFlipYSupport = false;
33 fPackRowLengthSupport = false;
34 fPackFlipYSupport = false;
35 fTextureUsageSupport = false;
36 fTexStorageSupport = false;
robertphillips@google.com443e5a52012-04-30 20:01:21 +000037 fTextureRedSupport = false;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000038 fImagingSupport = false;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000039 fVertexArrayObjectSupport = false;
cdalton626e1ff2015-06-12 13:56:46 -070040 fDirectStateAccessSupport = false;
41 fDebugSupport = false;
jvanverth3f801cb2014-12-16 09:49:38 -080042 fES2CompatibilitySupport = false;
cdaltond4727922015-11-10 12:49:06 -080043 fMultisampleDisableSupport = false;
bsalomon@google.com96966a52013-02-21 16:34:21 +000044 fUseNonVBOVertexAndIndexDynamicData = false;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000045 fIsCoreProfile = false;
joshualittc1f56b52015-06-22 12:31:31 -070046 fBindFragDataLocationSupport = false;
bsalomon7ea33f52015-11-22 14:51:00 -080047 fExternalTextureSupport = false;
bsalomone5286e02016-01-14 09:24:09 -080048 fRectangleTextureSupport = false;
bsalomoncdee0092016-01-08 13:20:12 -080049 fTextureSwizzleSupport = false;
bsalomon16921ec2015-07-30 15:34:56 -070050 fSRGBWriteControl = false;
bsalomon88c7b982015-07-31 11:20:16 -070051 fRGBA8888PixelsOpsAreSlow = false;
52 fPartialFBOReadIsSlow = false;
piotaixre4b23142014-10-02 10:57:53 -070053
halcanary385fe4d2015-08-26 13:07:48 -070054 fShaderCaps.reset(new GrGLSLCaps(contextOptions));
bsalomon4ee6bd82015-05-27 13:23:23 -070055
cdalton4cd67132015-06-10 19:23:46 -070056 this->init(contextOptions, ctxInfo, glInterface);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000057}
58
cdalton4cd67132015-06-10 19:23:46 -070059void GrGLCaps::init(const GrContextOptions& contextOptions,
60 const GrGLContextInfo& ctxInfo,
61 const GrGLInterface* gli) {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000062 GrGLStandard standard = ctxInfo.standard();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000063 GrGLVersion version = ctxInfo.version();
64
bsalomon@google.combcce8922013-03-25 15:38:39 +000065 /**************************************************************************
66 * Caps specific to GrGLCaps
67 **************************************************************************/
68
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000069 if (kGLES_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000070 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
71 &fMaxFragmentUniformVectors);
72 } else {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000073 SkASSERT(kGL_GrGLStandard == standard);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000074 GrGLint max;
75 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
76 fMaxFragmentUniformVectors = max / 4;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +000077 if (version >= GR_GL_VER(3, 2)) {
78 GrGLint profileMask;
79 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
80 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
81 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000082 }
bsalomon@google.com60da4172012-06-01 19:25:00 +000083 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +000084 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &fMaxFragmentTextureUnits);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000085
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000086 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000087 fUnpackRowLengthSupport = true;
88 fUnpackFlipYSupport = false;
89 fPackRowLengthSupport = true;
90 fPackFlipYSupport = false;
91 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +000092 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
93 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000094 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +000095 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
96 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000097 fPackFlipYSupport =
98 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
99 }
100
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000101 fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000102 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
103
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000104 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org7a434a22013-08-21 14:01:56 +0000105 // The EXT version can apply to either GL or GLES.
106 fTexStorageSupport = version >= GR_GL_VER(4,2) ||
107 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
108 ctxInfo.hasExtension("GL_EXT_texture_storage");
109 } else {
110 // Qualcomm Adreno drivers appear to have issues with texture storage.
111 fTexStorageSupport = (version >= GR_GL_VER(3,0) &&
112 kQualcomm_GrGLVendor != ctxInfo.vendor()) ||
113 ctxInfo.hasExtension("GL_EXT_texture_storage");
114 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000115
cdaltonfd4167d2015-04-21 11:45:56 -0700116 if (kGL_GrGLStandard == standard) {
117 fTextureBarrierSupport = version >= GR_GL_VER(4,5) ||
118 ctxInfo.hasExtension("GL_ARB_texture_barrier") ||
119 ctxInfo.hasExtension("GL_NV_texture_barrier");
120 } else {
121 fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier");
122 }
123
hendrikwa0d5ad72014-12-02 07:30:30 -0800124 // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support GL_RED
125 // and GL_RG on FBO textures.
cdalton1acea862015-06-02 13:05:52 -0700126 if (kMesa_GrGLDriver != ctxInfo.driver()) {
hendrikwa0d5ad72014-12-02 07:30:30 -0800127 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000128 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
129 ctxInfo.hasExtension("GL_ARB_texture_rg");
hendrikwa0d5ad72014-12-02 07:30:30 -0800130 } else {
131 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
132 ctxInfo.hasExtension("GL_EXT_texture_rg");
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000133 }
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000134 }
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000135 fImagingSupport = kGL_GrGLStandard == standard &&
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000136 ctxInfo.hasExtension("GL_ARB_imaging");
137
bsalomon@google.com3012ded2013-02-22 16:44:04 +0000138 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
139 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
140 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
141 // limit this decision to specific GPU families rather than basing it on the vendor alone.
142 if (!GR_GL_MUST_USE_VBO &&
bsalomoned82c4e2014-09-02 07:54:47 -0700143 (kARM_GrGLVendor == ctxInfo.vendor() ||
144 kImagination_GrGLVendor == ctxInfo.vendor() ||
145 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
bsalomon@google.com96966a52013-02-21 16:34:21 +0000146 fUseNonVBOVertexAndIndexDynamicData = true;
147 }
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000148
egdaniel9250d242015-05-18 13:04:26 -0700149 // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
150 // Thus we are blacklisting this extension for now on Adreno4xx devices.
151 if (kAdreno4xx_GrGLRenderer != ctxInfo.renderer() &&
152 ((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
153 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
154 ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) {
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000155 fDiscardRenderTargetSupport = true;
156 fInvalidateFBType = kInvalidate_InvalidateFBType;
157 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
158 fDiscardRenderTargetSupport = true;
159 fInvalidateFBType = kDiscard_InvalidateFBType;
160 }
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000161
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000162 if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) {
163 fFullClearIsFree = true;
164 }
165
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000166 if (kGL_GrGLStandard == standard) {
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000167 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
tomhudson612e9262014-11-24 11:22:36 -0800168 ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
169 ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000170 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000171 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
172 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000173 }
174
cdalton626e1ff2015-06-12 13:56:46 -0700175 if (kGL_GrGLStandard == standard) {
176 fDirectStateAccessSupport = ctxInfo.hasExtension("GL_EXT_direct_state_access");
177 } else {
178 fDirectStateAccessSupport = false;
179 }
180
181 if (kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) {
182 fDebugSupport = true;
183 } else {
184 fDebugSupport = ctxInfo.hasExtension("GL_KHR_debug");
185 }
186
jvanverth3f801cb2014-12-16 09:49:38 -0800187 if (kGL_GrGLStandard == standard) {
188 fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
189 }
190 else {
191 fES2CompatibilitySupport = true;
192 }
193
cdalton0edea2c2015-05-21 08:27:44 -0700194 if (kGL_GrGLStandard == standard) {
195 fMultisampleDisableSupport = true;
196 } else {
kkinnunenbf49e462015-07-30 22:43:52 -0700197 fMultisampleDisableSupport = ctxInfo.hasExtension("GL_EXT_multisample_compatibility");
cdalton0edea2c2015-05-21 08:27:44 -0700198 }
199
kkinnunend94708e2015-07-30 22:47:04 -0700200 if (kGL_GrGLStandard == standard) {
201 if (version >= GR_GL_VER(3, 0)) {
202 fBindFragDataLocationSupport = true;
203 }
204 } else {
205 if (version >= GR_GL_VER(3, 0) && ctxInfo.hasExtension("GL_EXT_blend_func_extended")) {
206 fBindFragDataLocationSupport = true;
207 }
joshualittc1f56b52015-06-22 12:31:31 -0700208 }
209
joshualitt7bdd70a2015-10-01 06:28:11 -0700210 fBindUniformLocationSupport = ctxInfo.hasExtension("GL_CHROMIUM_bind_uniform_location");
211
bsalomon7ea33f52015-11-22 14:51:00 -0800212 if (ctxInfo.hasExtension("GL_OES_EGL_image_external")) {
213 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
214 fExternalTextureSupport = true;
215 } else if (ctxInfo.hasExtension("GL_OES_EGL_image_external_essl3") ||
216 ctxInfo.hasExtension("OES_EGL_image_external_essl3")) {
217 // At least one driver has been found that has this extension without the "GL_" prefix.
218 fExternalTextureSupport = true;
219 }
220 }
221
bsalomone179a912016-01-20 06:18:10 -0800222 if ((kGL_GrGLStandard == standard && version >= GR_GL_VER(3, 1)) ||
bsalomone5286e02016-01-14 09:24:09 -0800223 ctxInfo.hasExtension("GL_ARB_texture_rectangle")) {
bsalomone179a912016-01-20 06:18:10 -0800224 // We also require textureSize() support for rectangle 2D samplers which was added in GLSL
225 // 1.40.
226 if (ctxInfo.glslGeneration() >= k140_GrGLSLGeneration) {
227 fRectangleTextureSupport = true;
228 }
bsalomone5286e02016-01-14 09:24:09 -0800229 }
230
bsalomoncdee0092016-01-08 13:20:12 -0800231 if (kGL_GrGLStandard == standard) {
232 if (version >= GR_GL_VER(3,3) || ctxInfo.hasExtension("GL_ARB_texture_swizzle")) {
233 fTextureSwizzleSupport = true;
234 }
235 } else {
236 if (version >= GR_GL_VER(3,0)) {
237 fTextureSwizzleSupport = true;
238 }
239 }
240
bsalomon88c7b982015-07-31 11:20:16 -0700241#ifdef SK_BUILD_FOR_WIN
242 // We're assuming that on Windows Chromium we're using ANGLE.
243 bool isANGLE = kANGLE_GrGLDriver == ctxInfo.driver() ||
244 kChromium_GrGLDriver == ctxInfo.driver();
245 // Angle has slow read/write pixel paths for 32bit RGBA (but fast for BGRA).
246 fRGBA8888PixelsOpsAreSlow = isANGLE;
247 // On DX9 ANGLE reading a partial FBO is slow. TODO: Check whether this is still true and
248 // check DX11 ANGLE.
249 fPartialFBOReadIsSlow = isANGLE;
250#endif
251
cdalton4cd67132015-06-10 19:23:46 -0700252 /**************************************************************************
egdaniel05ded892015-10-26 07:38:05 -0700253 * GrShaderCaps fields
254 **************************************************************************/
255
egdaniel0a482332015-10-26 08:59:10 -0700256 // This must be called after fCoreProfile is set on the GrGLCaps
257 this->initGLSL(ctxInfo);
258 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
259
egdaniel05ded892015-10-26 07:38:05 -0700260 glslCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli);
261
262 // For now these two are equivalent but we could have dst read in shader via some other method.
263 // Before setting this, initGLSL() must have been called.
264 glslCaps->fDstReadInShaderSupport = glslCaps->fFBFetchSupport;
265
266 // Enable supported shader-related caps
267 if (kGL_GrGLStandard == standard) {
268 glslCaps->fDualSourceBlendingSupport = (ctxInfo.version() >= GR_GL_VER(3, 3) ||
269 ctxInfo.hasExtension("GL_ARB_blend_func_extended")) &&
270 GrGLSLSupportsNamedFragmentShaderOutputs(ctxInfo.glslGeneration());
271 glslCaps->fShaderDerivativeSupport = true;
272 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
273 glslCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) &&
274 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
275 }
276 else {
277 glslCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended");
278
279 glslCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
280 ctxInfo.hasExtension("GL_OES_standard_derivatives");
281 }
282
egdaniel05ded892015-10-26 07:38:05 -0700283 /**************************************************************************
bsalomon4b91f762015-05-19 09:29:46 -0700284 * GrCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000285 **************************************************************************/
cdalton4cd67132015-06-10 19:23:46 -0700286
cdalton63f6c1f2015-11-06 07:09:43 -0800287 // We need dual source blending and the ability to disable multisample in order to support mixed
288 // samples in every corner case.
egdanieleed519e2016-01-15 11:36:18 -0800289 if (fMultisampleDisableSupport &&
290 glslCaps->dualSourceBlendingSupport() &&
291 fShaderCaps->pathRenderingSupport()) {
292 fUsesMixedSamples = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") ||
kkinnunenea409432015-12-10 01:21:59 -0800293 ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_mixed_samples");
cdalton63f6c1f2015-11-06 07:09:43 -0800294 // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples.
kkinnunen9f63b442016-01-25 00:31:49 -0800295 if (fUsesMixedSamples && (kNVIDIA_GrGLDriver == ctxInfo.driver() ||
296 kChromium_GrGLDriver == ctxInfo.driver())) {
cdalton63f6c1f2015-11-06 07:09:43 -0800297 fDiscardRenderTargetSupport = false;
298 fInvalidateFBType = kNone_InvalidateFBType;
299 }
300 }
301
egdanieleed519e2016-01-15 11:36:18 -0800302 // fUsesMixedSamples must be set before calling initFSAASupport.
cdalton4cd67132015-06-10 19:23:46 -0700303 this->initFSAASupport(ctxInfo, gli);
cdalton1dd05422015-06-12 09:01:18 -0700304 this->initBlendEqationSupport(ctxInfo);
cdalton4cd67132015-06-10 19:23:46 -0700305 this->initStencilFormats(ctxInfo);
306
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000307 if (kGL_GrGLStandard == standard) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000308 // we could also look for GL_ATI_separate_stencil extension or
309 // GL_EXT_stencil_two_side but they use different function signatures
310 // than GL2.0+ (and than each other).
311 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
312 // supported on GL 1.4 and higher or by extension
313 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
314 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
315 } else {
316 // ES 2 has two sided stencil and stencil wrap
317 fTwoSidedStencilSupport = true;
318 fStencilWrapOpsSupport = true;
319 }
320
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000321 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000322 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
323 // extension includes glMapBuffer.
324 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
325 fMapBufferFlags |= kSubset_MapFlag;
326 fMapBufferType = kMapBufferRange_MapBufferType;
327 } else {
328 fMapBufferType = kMapBuffer_MapBufferType;
329 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000330 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000331 // Unextended GLES2 doesn't have any buffer mapping.
332 fMapBufferFlags = kNone_MapBufferType;
333 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
334 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
335 fMapBufferType = kChromium_MapBufferType;
336 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
337 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
338 fMapBufferType = kMapBufferRange_MapBufferType;
339 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
340 fMapBufferFlags = kCanMap_MapFlag;
341 fMapBufferType = kMapBuffer_MapBufferType;
342 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000343 }
344
jvanverthd7a2c1f2015-12-07 07:36:44 -0800345 if (kGL_GrGLStandard == standard) {
346 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_pixel_buffer_object")) {
347 fTransferBufferType = kPBO_TransferBufferType;
348 }
349 } else {
350 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_NV_pixel_buffer_object")) {
351 fTransferBufferType = kPBO_TransferBufferType;
352 } else if (ctxInfo.hasExtension("GL_CHROMIUM_pixel_transfer_buffer_object")) {
353 fTransferBufferType = kChromium_TransferBufferType;
354 }
355 }
356
joshualitte5b74c62015-06-01 14:17:47 -0700357 // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
358 // threshold to the maximum unless the client gives us a hint that map memory is cheap.
359 if (fGeometryBufferMapThreshold < 0) {
bsalomonbc233752015-06-26 11:38:25 -0700360 // We think mapping on Chromium will be cheaper once we know ahead of time how much space
361 // we will use for all GrBatchs. Right now we might wind up mapping a large buffer and using
362 // a small subset.
363#if 0
cdalton1acea862015-06-02 13:05:52 -0700364 fGeometryBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700365#else
366 fGeometryBufferMapThreshold = SK_MaxS32;
367#endif
joshualitte5b74c62015-06-01 14:17:47 -0700368 }
369
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000370 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000371 SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) ||
372 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two"));
373 fNPOTTextureTileSupport = true;
374 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000375 } else {
376 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000377 // ES3 has no limitations.
378 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
379 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000380 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
381 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
382 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
383 // to alllow arbitrary wrap modes, however.
384 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000385 }
386
bsalomone72bd022015-10-26 07:33:03 -0700387 // Using MIPs on this GPU seems to be a source of trouble.
388 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
389 fMipMapSupport = false;
390 }
391
bsalomon@google.combcce8922013-03-25 15:38:39 +0000392 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
393 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
394 // Our render targets are always created with textures as the color
395 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000396 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000397
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000398 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
399
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000400 // Disable scratch texture reuse on Mali and Adreno devices
401 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() &&
402 kQualcomm_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000403
robertphillips1b8e1b52015-06-24 06:54:10 -0700404#if 0
405 fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() &&
406 kQualcomm_GrGLVendor != ctxInfo.vendor();
407#endif
408
egdaniel05ded892015-10-26 07:38:05 -0700409 // initFSAASupport() must have been called before this point
bsalomon@google.com347c3822013-05-01 20:10:01 +0000410 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
egdanieleed519e2016-01-15 11:36:18 -0800411 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxColorSampleCount);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000412 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
egdanieleed519e2016-01-15 11:36:18 -0800413 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxColorSampleCount);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000414 }
egdanieleed519e2016-01-15 11:36:18 -0800415 fMaxStencilSampleCount = fMaxColorSampleCount;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000416
bsalomon63b21962014-11-05 07:05:34 -0800417 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
bsalomone702d972015-01-29 10:07:32 -0800418 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
bsalomona8fcea02015-02-13 09:00:39 -0800419 kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
bsalomon63b21962014-11-05 07:05:34 -0800420 fUseDrawInsteadOfClear = true;
421 }
422
joshualitt83bc2292015-06-18 14:18:02 -0700423 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer()) {
424 fUseDrawInsteadOfPartialRenderTargetWrite = true;
425 }
426
robertphillips63926682015-08-20 09:39:02 -0700427#ifdef SK_BUILD_FOR_WIN
428 // On ANGLE deferring flushes can lead to GPU starvation
429 fPreferVRAMUseOverFlushes = !isANGLE;
430#endif
431
bsalomon7dea7b72015-08-19 08:26:51 -0700432 if (kChromium_GrGLDriver == ctxInfo.driver()) {
433 fMustClearUploadedBufferData = true;
434 }
435
bsalomond08ea5f2015-02-20 06:58:13 -0800436 if (kGL_GrGLStandard == standard) {
437 // ARB allows mixed size FBO attachments, EXT does not.
438 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
439 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
440 fOversizedStencilSupport = true;
441 } else {
442 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
443 }
444 } else {
445 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
446 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
447 }
448
joshualitt58001552015-06-26 12:46:36 -0700449 if (kGL_GrGLStandard == standard) {
450 // 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about
451 // instanced arrays, but we could make this more granular if we wanted
452 fSupportsInstancedDraws =
453 version >= GR_GL_VER(3, 2) ||
454 (ctxInfo.hasExtension("GL_ARB_draw_instanced") &&
455 ctxInfo.hasExtension("GL_ARB_instanced_arrays"));
456 } else {
457 fSupportsInstancedDraws =
458 version >= GR_GL_VER(3, 0) ||
459 (ctxInfo.hasExtension("GL_EXT_draw_instanced") &&
460 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
461 }
462
jvanverthcba99b82015-06-24 06:59:57 -0700463 this->initShaderPrecisionTable(ctxInfo, gli, glslCaps);
bsalomoncdee0092016-01-08 13:20:12 -0800464
465 if (contextOptions.fUseShaderSwizzling) {
466 fTextureSwizzleSupport = false;
467 }
468
469 // Requires fTextureRedSupport, fTextureSwizzleSupport, msaa support, ES compatibility have
470 // already been detected.
471 this->initConfigTable(ctxInfo, gli, glslCaps);
cdalton4cd67132015-06-10 19:23:46 -0700472
473 this->applyOptionsOverrides(contextOptions);
474 glslCaps->applyOptionsOverrides(contextOptions);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000475}
476
egdaniel472d44e2015-10-22 08:20:00 -0700477const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration generation,
478 bool isCoreProfile) {
479 switch (generation) {
480 case k110_GrGLSLGeneration:
481 if (kGLES_GrGLStandard == standard) {
482 // ES2s shader language is based on version 1.20 but is version
483 // 1.00 of the ES language.
484 return "#version 100\n";
485 } else {
486 SkASSERT(kGL_GrGLStandard == standard);
487 return "#version 110\n";
488 }
489 case k130_GrGLSLGeneration:
490 SkASSERT(kGL_GrGLStandard == standard);
491 return "#version 130\n";
492 case k140_GrGLSLGeneration:
493 SkASSERT(kGL_GrGLStandard == standard);
494 return "#version 140\n";
495 case k150_GrGLSLGeneration:
496 SkASSERT(kGL_GrGLStandard == standard);
497 if (isCoreProfile) {
498 return "#version 150\n";
499 } else {
500 return "#version 150 compatibility\n";
501 }
502 case k330_GrGLSLGeneration:
503 if (kGLES_GrGLStandard == standard) {
504 return "#version 300 es\n";
505 } else {
506 SkASSERT(kGL_GrGLStandard == standard);
507 if (isCoreProfile) {
508 return "#version 330\n";
509 } else {
510 return "#version 330 compatibility\n";
511 }
512 }
513 case k310es_GrGLSLGeneration:
514 SkASSERT(kGLES_GrGLStandard == standard);
515 return "#version 310 es\n";
516 }
517 return "<no version>";
518}
519
egdaniel05ded892015-10-26 07:38:05 -0700520void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo) {
egdaniel472d44e2015-10-22 08:20:00 -0700521 GrGLStandard standard = ctxInfo.standard();
522 GrGLVersion version = ctxInfo.version();
523
524 /**************************************************************************
525 * Caps specific to GrGLSLCaps
526 **************************************************************************/
527
528 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
529 glslCaps->fGLSLGeneration = ctxInfo.glslGeneration();
ethannicholas5366a092016-01-22 09:45:47 -0800530
egdaniel472d44e2015-10-22 08:20:00 -0700531 if (kGLES_GrGLStandard == standard) {
532 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
533 glslCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
534 glslCaps->fFBFetchSupport = true;
535 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
536 glslCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
537 }
538 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
539 // Actually, we haven't seen an ES3.0 device with this extension yet, so we don't know
540 glslCaps->fFBFetchNeedsCustomOutput = false;
541 glslCaps->fFBFetchSupport = true;
542 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
543 glslCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
544 }
545 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
546 // The arm extension also requires an additional flag which we will set onResetContext
547 glslCaps->fFBFetchNeedsCustomOutput = false;
548 glslCaps->fFBFetchSupport = true;
549 glslCaps->fFBFetchColorName = "gl_LastFragColorARM";
550 glslCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
551 }
552 glslCaps->fUsesPrecisionModifiers = true;
553 }
554
555 glslCaps->fBindlessTextureSupport = ctxInfo.hasExtension("GL_NV_bindless_texture");
556
557 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
558 glslCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
559
560 // On the NexusS and GalaxyNexus, the use of 'any' causes the compilation error "Calls to any
561 // function that may require a gradient calculation inside a conditional block may return
562 // undefined results". This appears to be an issue with the 'any' call since even the simple
563 // "result=black; if (any()) result=white;" code fails to compile. This issue comes into play
564 // from our GrTextureDomain processor.
565 glslCaps->fCanUseAnyFunctionInShader = kImagination_GrGLVendor != ctxInfo.vendor();
566
egdaniel472d44e2015-10-22 08:20:00 -0700567 glslCaps->fVersionDeclString = get_glsl_version_decl_string(standard, glslCaps->fGLSLGeneration,
568 fIsCoreProfile);
egdaniel574a4c12015-11-02 06:22:44 -0800569
570 if (kGLES_GrGLStandard == standard && k110_GrGLSLGeneration == glslCaps->fGLSLGeneration) {
571 glslCaps->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
572 }
egdaniel8dcdedc2015-11-11 06:27:20 -0800573
574 // Frag Coords Convention support is not part of ES
575 // Known issue on at least some Intel platforms:
576 // http://code.google.com/p/skia/issues/detail?id=946
577 if (kIntel_GrGLVendor != ctxInfo.vendor() &&
578 kGLES_GrGLStandard != standard &&
579 (ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
580 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"))) {
581 glslCaps->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions";
582 }
583
584 if (kGLES_GrGLStandard == standard) {
585 glslCaps->fSecondaryOutputExtensionString = "GL_EXT_blend_func_extended";
586 }
587
bsalomon7ea33f52015-11-22 14:51:00 -0800588 if (fExternalTextureSupport) {
589 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
590 glslCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
591 } else {
592 glslCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
593 }
594 }
595
egdaniel8dcdedc2015-11-11 06:27:20 -0800596 // The Tegra3 compiler will sometimes never return if we have min(abs(x), 1.0), so we must do
597 // the abs first in a separate expression.
598 if (kTegra3_GrGLRenderer == ctxInfo.renderer()) {
599 glslCaps->fCanUseMinAndAbsTogether = false;
600 }
601
bsalomon7ea33f52015-11-22 14:51:00 -0800602 // On Intel GPU there is an issue where it reads the second argument to atan "- %s.x" as an int
egdaniel8dcdedc2015-11-11 06:27:20 -0800603 // thus must us -1.0 * %s.x to work correctly
604 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
605 glslCaps->fMustForceNegatedAtanParamToFloat = true;
606 }
egdaniel472d44e2015-10-22 08:20:00 -0700607}
608
kkinnunencfe62e32015-07-01 02:58:50 -0700609bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
kkinnunen6bb6d402015-07-14 10:59:23 -0700610 bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering");
611
612 if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700613 return false;
614 }
kkinnunen6bb6d402015-07-14 10:59:23 -0700615
kkinnunencfe62e32015-07-01 02:58:50 -0700616 if (kGL_GrGLStandard == ctxInfo.standard()) {
617 if (ctxInfo.version() < GR_GL_VER(4, 3) &&
618 !ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
619 return false;
620 }
621 } else {
kkinnunen6bb6d402015-07-14 10:59:23 -0700622 if (!hasChromiumPathRendering &&
623 ctxInfo.version() < GR_GL_VER(3, 1)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700624 return false;
625 }
626 }
627 // We only support v1.3+ of GL_NV_path_rendering which allows us to
628 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
629 // additions are detected by checking the existence of the function.
630 // We also use *Then* functions that not all drivers might have. Check
631 // them for consistency.
halcanary96fcdcc2015-08-27 07:41:13 -0700632 if (nullptr == gli->fFunctions.fStencilThenCoverFillPath ||
633 nullptr == gli->fFunctions.fStencilThenCoverStrokePath ||
634 nullptr == gli->fFunctions.fStencilThenCoverFillPathInstanced ||
635 nullptr == gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
636 nullptr == gli->fFunctions.fProgramPathFragmentInputGen) {
kkinnunencfe62e32015-07-01 02:58:50 -0700637 return false;
638 }
639 return true;
640}
bsalomon1aa20292016-01-22 08:16:09 -0800641
642bool GrGLCaps::readPixelsSupported(GrPixelConfig rtConfig,
bsalomon7928ef62016-01-05 10:26:39 -0800643 GrPixelConfig readConfig,
bsalomon1aa20292016-01-22 08:16:09 -0800644 std::function<void (GrGLenum, GrGLint*)> getIntegerv,
645 std::function<bool ()> bindRenderTarget) const {
bsalomone9573312016-01-25 14:33:25 -0800646 // If it's not possible to even have a render target of rtConfig then read pixels is
647 // not supported regardless of readConfig.
648 if (!this->isConfigRenderable(rtConfig, false)) {
649 return false;
650 }
bsalomon7928ef62016-01-05 10:26:39 -0800651
bsalomon76148af2016-01-12 11:13:47 -0800652 GrGLenum readFormat;
653 GrGLenum readType;
bsalomon1aa20292016-01-22 08:16:09 -0800654 if (!this->getReadPixelsFormat(rtConfig, readConfig, &readFormat, &readType)) {
bsalomon76148af2016-01-12 11:13:47 -0800655 return false;
656 }
657
bsalomon1aa20292016-01-22 08:16:09 -0800658 if (kGL_GrGLStandard == fStandard) {
bsalomone9573312016-01-25 14:33:25 -0800659 // Some OpenGL implementations allow GL_ALPHA as a format to glReadPixels. However,
660 // the manual (https://www.opengl.org/sdk/docs/man/) says only these formats are allowed:
661 // GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL, GL_RED, GL_GREEN, GL_BLUE,
662 // GL_RGB, GL_BGR, GL_RGBA, and GL_BGRA. We check for the subset that we would use.
663 if (readFormat != GR_GL_RED && readFormat != GR_GL_RGB && readFormat != GR_GL_RGBA &&
664 readFormat != GR_GL_BGRA) {
665 return false;
666 }
667 // There is also a set of allowed types, but all the types we use are in the set:
668 // GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT,
669 // GL_HALF_FLOAT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV,
670 // GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4,
671 // GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV,
672 // GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV,GL_UNSIGNED_INT_10_10_10_2,
673 // GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV,
674 // GL_UNSIGNED_INT_5_9_9_9_REV, or GL_FLOAT_32_UNSIGNED_INT_24_8_REV.
bsalomon7928ef62016-01-05 10:26:39 -0800675 return true;
piotaixre4b23142014-10-02 10:57:53 -0700676 }
bsalomon7928ef62016-01-05 10:26:39 -0800677
bsalomon76148af2016-01-12 11:13:47 -0800678 // See Section 16.1.2 in the ES 3.2 specification.
bsalomon7928ef62016-01-05 10:26:39 -0800679
bsalomon1aa20292016-01-22 08:16:09 -0800680 if (kNormalizedFixedPoint_FormatType == fConfigTable[rtConfig].fFormatType) {
bsalomon7928ef62016-01-05 10:26:39 -0800681 if (GR_GL_RGBA == readFormat && GR_GL_UNSIGNED_BYTE == readType) {
682 return true;
683 }
684 } else {
bsalomon1aa20292016-01-22 08:16:09 -0800685 SkASSERT(kFloat_FormatType == fConfigTable[rtConfig].fFormatType);
bsalomon7928ef62016-01-05 10:26:39 -0800686 if (GR_GL_RGBA == readFormat && GR_GL_FLOAT == readType) {
687 return true;
688 }
689 }
690
bsalomon1aa20292016-01-22 08:16:09 -0800691 if (0 == fConfigTable[rtConfig].fSecondReadPixelsFormat.fFormat) {
bsalomon7928ef62016-01-05 10:26:39 -0800692 ReadPixelsFormat* rpFormat =
bsalomon1aa20292016-01-22 08:16:09 -0800693 const_cast<ReadPixelsFormat*>(&fConfigTable[rtConfig].fSecondReadPixelsFormat);
bsalomon7928ef62016-01-05 10:26:39 -0800694 GrGLint format = 0, type = 0;
bsalomon1aa20292016-01-22 08:16:09 -0800695 if (!bindRenderTarget()) {
696 return false;
697 }
698 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, &format);
699 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, &type);
bsalomon7928ef62016-01-05 10:26:39 -0800700 rpFormat->fFormat = format;
701 rpFormat->fType = type;
702 }
703
bsalomon1aa20292016-01-22 08:16:09 -0800704 return fConfigTable[rtConfig].fSecondReadPixelsFormat.fFormat == readFormat &&
705 fConfigTable[rtConfig].fSecondReadPixelsFormat.fType == readType;
piotaixre4b23142014-10-02 10:57:53 -0700706}
707
robertphillips@google.com6177e692013-02-28 20:16:25 +0000708void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000709
710 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000711 if (kGL_GrGLStandard != ctxInfo.standard()) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000712 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
713 // ES3 driver bugs on at least one device with a tiled GPU (N10).
714 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
715 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
716 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
717 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
egdanieleed519e2016-01-15 11:36:18 -0800718 } else if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -0700719 fMSFBOType = kMixedSamples_MSFBOType;
commit-bot@chromium.org92b78842014-01-16 20:49:46 +0000720 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000721 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType;
722 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
723 // chrome's extension is equivalent to the EXT msaa
724 // and fbo_blit extensions.
725 fMSFBOType = kDesktop_EXT_MSFBOType;
726 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
727 fMSFBOType = kES_Apple_MSFBOType;
728 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000729 } else {
egdanieleed519e2016-01-15 11:36:18 -0800730 if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -0700731 fMSFBOType = kMixedSamples_MSFBOType;
732 } else if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000733 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000734 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000735 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
736 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000737 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000738 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000739 }
740}
741
cdalton1dd05422015-06-12 09:01:18 -0700742void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
743 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
744
745 // Disabling advanced blend on various platforms with major known issues. We also block Chrome
746 // for now until its own blacklists can be updated.
747 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer() ||
748 kIntel_GrGLDriver == ctxInfo.driver() ||
joel.liang9764c402015-07-09 19:46:18 -0700749 kChromium_GrGLDriver == ctxInfo.driver()) {
cdalton1dd05422015-06-12 09:01:18 -0700750 return;
751 }
752
753 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
754 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
755 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
756 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent")) {
757 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
758 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
759 } else if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
760 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337,00)) {
761 // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
762 return;
763 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
764 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
765 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
766 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced")) {
767 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
768 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
769 // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
770 // slow on a particular platform.
771 } else {
772 return; // No advanced blend support.
773 }
774
775 SkASSERT(this->advancedBlendEquationSupport());
776
777 if (kNVIDIA_GrGLDriver == ctxInfo.driver()) {
778 // Blacklist color-dodge and color-burn on NVIDIA until the fix is released.
779 fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
780 (1 << kColorBurn_GrBlendEquation);
781 }
joel.liang9764c402015-07-09 19:46:18 -0700782 if (kARM_GrGLVendor == ctxInfo.vendor()) {
783 // Blacklist color-burn on ARM until the fix is released.
784 fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation);
785 }
cdalton1dd05422015-06-12 09:01:18 -0700786}
787
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000788namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -0700789const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000790}
791
792void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
793
794 // Build up list of legal stencil formats (though perhaps not supported on
795 // the particular gpu/driver) from most preferred to least.
796
797 // these consts are in order of most preferred to least preferred
798 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
799
800 static const StencilFormat
801 // internal Format stencil bits total bits packed?
802 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
803 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
804 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
805 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000806 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000807 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
808
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000809 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000810 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000811 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000812 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
813 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
814
815 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
816 // require FBO support we can expect these are legal formats and don't
817 // check. These also all support the unsized GL_STENCIL_INDEX.
818 fStencilFormats.push_back() = gS8;
819 fStencilFormats.push_back() = gS16;
820 if (supportsPackedDS) {
821 fStencilFormats.push_back() = gD24S8;
822 }
823 fStencilFormats.push_back() = gS4;
824 if (supportsPackedDS) {
825 fStencilFormats.push_back() = gDS;
826 }
827 } else {
828 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
829 // for other formats.
830 // ES doesn't support using the unsized format.
831
832 fStencilFormats.push_back() = gS8;
833 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +0000834 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
835 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000836 fStencilFormats.push_back() = gD24S8;
837 }
838 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
839 fStencilFormats.push_back() = gS4;
840 }
841 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000842}
843
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000844SkString GrGLCaps::dump() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000845
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000846 SkString r = INHERITED::dump();
bsalomon@google.combcce8922013-03-25 15:38:39 +0000847
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000848 r.appendf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000849 for (int i = 0; i < fStencilFormats.count(); ++i) {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000850 r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000851 i,
852 fStencilFormats[i].fStencilBits,
853 fStencilFormats[i].fTotalBits);
854 }
855
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000856 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000857 "None",
858 "ARB",
859 "EXT",
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000860 "ES 3.0",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000861 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +0000862 "IMG MS To Texture",
863 "EXT MS To Texture",
vbuzinovdded6962015-06-12 08:59:45 -0700864 "MixedSamples",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000865 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000866 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
867 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
868 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000869 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType);
870 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType);
871 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType);
872 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType);
vbuzinovdded6962015-06-12 08:59:45 -0700873 GR_STATIC_ASSERT(7 == kMixedSamples_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000874 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000875
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000876 static const char* kInvalidateFBTypeStr[] = {
877 "None",
878 "Discard",
879 "Invalidate",
880 };
881 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
882 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
883 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
884 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000885
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000886 static const char* kMapBufferTypeStr[] = {
887 "None",
888 "MapBuffer",
889 "MapBufferRange",
890 "Chromium",
891 };
892 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
893 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
894 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
895 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
896 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
897
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000898 r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000899 r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000900 r.appendf("Invalidate FB Type: %s\n", kInvalidateFBTypeStr[fInvalidateFBType]);
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000901 r.appendf("Map Buffer Type: %s\n", kMapBufferTypeStr[fMapBufferType]);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000902 r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
903 r.appendf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000904 r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000905 r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
906 r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
907 r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
908 r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +0000909
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000910 r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
911 r.appendf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
912 r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
913 r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000914 r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
cdalton626e1ff2015-06-12 13:56:46 -0700915 r.appendf("Direct state access support: %s\n", (fDirectStateAccessSupport ? "YES": "NO"));
916 r.appendf("Debug support: %s\n", (fDebugSupport ? "YES": "NO"));
cdaltond4727922015-11-10 12:49:06 -0800917 r.appendf("Multisample disable support: %s\n", (fMultisampleDisableSupport ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000918 r.appendf("Use non-VBO for dynamic data: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +0000919 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
bsalomon16921ec2015-07-30 15:34:56 -0700920 r.appendf("SRGB write contol: %s\n", (fSRGBWriteControl ? "YES" : "NO"));
robertphillips63926682015-08-20 09:39:02 -0700921 r.appendf("RGBA 8888 pixel ops are slow: %s\n", (fRGBA8888PixelsOpsAreSlow ? "YES" : "NO"));
922 r.appendf("Partial FBO read is slow: %s\n", (fPartialFBOReadIsSlow ? "YES" : "NO"));
joshualitt7bdd70a2015-10-01 06:28:11 -0700923 r.appendf("Bind uniform location support: %s\n", (fBindUniformLocationSupport ? "YES" : "NO"));
bsalomoncdee0092016-01-08 13:20:12 -0800924 r.appendf("External texture support: %s\n", (fExternalTextureSupport ? "YES" : "NO"));
bsalomone5286e02016-01-14 09:24:09 -0800925 r.appendf("Rectangle texture support: %s\n", (fRectangleTextureSupport? "YES" : "NO"));
bsalomoncdee0092016-01-08 13:20:12 -0800926 r.appendf("Texture swizzle support: %s\n", (fTextureSwizzleSupport ? "YES" : "NO"));
bsalomon41e4384e2016-01-08 09:12:44 -0800927
928 r.append("Configs\n-------\n");
929 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
930 r.appendf(" cfg: %d flags: 0x%04x, b_internal: 0x%08x s_internal: 0x%08x, e_format: "
bsalomon76148af2016-01-12 11:13:47 -0800931 "0x%08x, e_format_teximage: 0x%08x, e_type: 0x%08x, i_for_teximage: 0x%08x, "
932 "i_for_renderbuffer: 0x%08x\n",
bsalomon41e4384e2016-01-08 09:12:44 -0800933 i,
934 fConfigTable[i].fFlags,
935 fConfigTable[i].fFormats.fBaseInternalFormat,
936 fConfigTable[i].fFormats.fSizedInternalFormat,
bsalomon76148af2016-01-12 11:13:47 -0800937 fConfigTable[i].fFormats.fExternalFormat[kOther_ExternalFormatUsage],
938 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage],
bsalomon41e4384e2016-01-08 09:12:44 -0800939 fConfigTable[i].fFormats.fExternalType,
940 fConfigTable[i].fFormats.fInternalFormatTexImage,
bsalomon76148af2016-01-12 11:13:47 -0800941 fConfigTable[i].fFormats.fInternalFormatRenderbuffer);
bsalomon41e4384e2016-01-08 09:12:44 -0800942 }
943
jvanverthe9c0fc62015-04-29 11:18:05 -0700944 return r;
945}
946
jvanverthe9c0fc62015-04-29 11:18:05 -0700947static GrGLenum precision_to_gl_float_type(GrSLPrecision p) {
948 switch (p) {
949 case kLow_GrSLPrecision:
950 return GR_GL_LOW_FLOAT;
951 case kMedium_GrSLPrecision:
952 return GR_GL_MEDIUM_FLOAT;
953 case kHigh_GrSLPrecision:
954 return GR_GL_HIGH_FLOAT;
955 }
956 SkFAIL("Unknown precision.");
957 return -1;
958}
959
960static GrGLenum shader_type_to_gl_shader(GrShaderType type) {
961 switch (type) {
962 case kVertex_GrShaderType:
963 return GR_GL_VERTEX_SHADER;
964 case kGeometry_GrShaderType:
965 return GR_GL_GEOMETRY_SHADER;
966 case kFragment_GrShaderType:
967 return GR_GL_FRAGMENT_SHADER;
968 }
969 SkFAIL("Unknown shader type.");
970 return -1;
971}
972
jvanverthcba99b82015-06-24 06:59:57 -0700973void GrGLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
974 const GrGLInterface* intf,
975 GrGLSLCaps* glslCaps) {
jvanverthe9c0fc62015-04-29 11:18:05 -0700976 if (kGLES_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(4, 1) ||
977 ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
978 for (int s = 0; s < kGrShaderTypeCount; ++s) {
979 if (kGeometry_GrShaderType != s) {
980 GrShaderType shaderType = static_cast<GrShaderType>(s);
981 GrGLenum glShader = shader_type_to_gl_shader(shaderType);
halcanary96fcdcc2015-08-27 07:41:13 -0700982 GrShaderCaps::PrecisionInfo* first = nullptr;
jvanverthcba99b82015-06-24 06:59:57 -0700983 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -0700984 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
985 GrSLPrecision precision = static_cast<GrSLPrecision>(p);
986 GrGLenum glPrecision = precision_to_gl_float_type(precision);
987 GrGLint range[2];
988 GrGLint bits;
989 GR_GL_GetShaderPrecisionFormat(intf, glShader, glPrecision, range, &bits);
990 if (bits) {
jvanverthcba99b82015-06-24 06:59:57 -0700991 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = range[0];
992 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = range[1];
993 glslCaps->fFloatPrecisions[s][p].fBits = bits;
jvanverthe9c0fc62015-04-29 11:18:05 -0700994 if (!first) {
jvanverthcba99b82015-06-24 06:59:57 -0700995 first = &glslCaps->fFloatPrecisions[s][p];
jvanverthe9c0fc62015-04-29 11:18:05 -0700996 }
jvanverthcba99b82015-06-24 06:59:57 -0700997 else if (!glslCaps->fShaderPrecisionVaries) {
998 glslCaps->fShaderPrecisionVaries =
999 (*first != glslCaps->fFloatPrecisions[s][p]);
jvanverthe9c0fc62015-04-29 11:18:05 -07001000 }
1001 }
1002 }
1003 }
1004 }
1005 }
1006 else {
1007 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
jvanverthcba99b82015-06-24 06:59:57 -07001008 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001009 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1010 if (kGeometry_GrShaderType != s) {
1011 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001012 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = 127;
1013 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = 127;
1014 glslCaps->fFloatPrecisions[s][p].fBits = 23;
jvanverthe9c0fc62015-04-29 11:18:05 -07001015 }
1016 }
1017 }
1018 }
1019 // GetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Assume they're
1020 // the same as the vertex shader. Only fragment shaders were ever allowed to omit support for
1021 // highp. GS was added after GetShaderPrecisionFormat was added to the list of features that
1022 // are recommended against.
jvanverthcba99b82015-06-24 06:59:57 -07001023 if (glslCaps->fGeometryShaderSupport) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001024 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001025 glslCaps->fFloatPrecisions[kGeometry_GrShaderType][p] =
1026 glslCaps->fFloatPrecisions[kVertex_GrShaderType][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001027 }
1028 }
1029}
1030
bsalomon41e4384e2016-01-08 09:12:44 -08001031bool GrGLCaps::bgraIsInternalFormat() const {
1032 return fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_BGRA;
1033}
1034
bsalomon76148af2016-01-12 11:13:47 -08001035bool GrGLCaps::getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1036 GrGLenum* internalFormat, GrGLenum* externalFormat,
1037 GrGLenum* externalType) const {
1038 if (!this->getExternalFormat(surfaceConfig, externalConfig, kTexImage_ExternalFormatUsage,
1039 externalFormat, externalType)) {
1040 return false;
1041 }
1042 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1043 return true;
1044}
1045
1046bool GrGLCaps::getCompressedTexImageFormats(GrPixelConfig surfaceConfig,
1047 GrGLenum* internalFormat) const {
1048 if (!GrPixelConfigIsCompressed(surfaceConfig)) {
1049 return false;
1050 }
1051 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1052 return true;
1053}
1054
1055bool GrGLCaps::getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1056 GrGLenum* externalFormat, GrGLenum* externalType) const {
1057 if (!this->getExternalFormat(surfaceConfig, externalConfig, kOther_ExternalFormatUsage,
1058 externalFormat, externalType)) {
1059 return false;
1060 }
1061 return true;
1062}
1063
1064bool GrGLCaps::getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const {
1065 if (GrPixelConfigIsCompressed(config)) {
1066 return false;
1067 }
1068 *internalFormat = fConfigTable[config].fFormats.fInternalFormatRenderbuffer;
1069 return true;
1070}
1071
1072bool GrGLCaps::getExternalFormat(GrPixelConfig surfaceConfig, GrPixelConfig memoryConfig,
1073 ExternalFormatUsage usage, GrGLenum* externalFormat,
1074 GrGLenum* externalType) const {
1075 SkASSERT(externalFormat && externalType);
1076 if (GrPixelConfigIsCompressed(memoryConfig) || GrPixelConfigIsCompressed(memoryConfig)) {
1077 return false;
1078 }
1079
1080 bool surfaceIsAlphaOnly = GrPixelConfigIsAlphaOnly(surfaceConfig);
1081 bool memoryIsAlphaOnly = GrPixelConfigIsAlphaOnly(memoryConfig);
1082
1083 // We don't currently support moving RGBA data into and out of ALPHA surfaces. It could be
1084 // made to work in many cases using glPixelStore and what not but is not needed currently.
1085 if (surfaceIsAlphaOnly && !memoryIsAlphaOnly) {
1086 return false;
1087 }
1088
1089 *externalFormat = fConfigTable[memoryConfig].fFormats.fExternalFormat[usage];
1090 *externalType = fConfigTable[memoryConfig].fFormats.fExternalType;
1091
bsalomone9573312016-01-25 14:33:25 -08001092 // When GL_RED is supported as a texture format, our alpha-only textures are stored using
1093 // GL_RED and we swizzle in order to map all components to 'r'. However, in this case the
1094 // surface is not alpha-only and we want alpha to really mean the alpha component of the
1095 // texture, not the red component.
1096 if (memoryIsAlphaOnly && !surfaceIsAlphaOnly) {
1097 if (this->textureRedSupport()) {
1098 SkASSERT(GR_GL_RED == *externalFormat);
1099 *externalFormat = GR_GL_ALPHA;
1100 }
1101 }
1102
bsalomon76148af2016-01-12 11:13:47 -08001103 return true;
1104}
1105
bsalomoncdee0092016-01-08 13:20:12 -08001106void GrGLCaps::initConfigTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
1107 GrGLSLCaps* glslCaps) {
bsalomon41e4384e2016-01-08 09:12:44 -08001108 /*
1109 Comments on renderability of configs on various GL versions.
1110 OpenGL < 3.0:
1111 no built in support for render targets.
1112 GL_EXT_framebuffer_object adds possible support for any sized format with base internal
1113 format RGB, RGBA and NV float formats we don't use.
1114 This is the following:
1115 R3_G3_B2, RGB4, RGB5, RGB8, RGB10, RGB12, RGB16, RGBA2, RGBA4, RGB5_A1, RGBA8
1116 RGB10_A2, RGBA12,RGBA16
1117 Though, it is hard to believe the more obscure formats such as RGBA12 would work
1118 since they aren't required by later standards and the driver can simply return
1119 FRAMEBUFFER_UNSUPPORTED for anything it doesn't allow.
1120 GL_ARB_framebuffer_object adds everything added by the EXT extension and additionally
1121 any sized internal format with a base internal format of ALPHA, LUMINANCE,
1122 LUMINANCE_ALPHA, INTENSITY, RED, and RG.
1123 This adds a lot of additional renderable sized formats, including ALPHA8.
1124 The GL_ARB_texture_rg brings in the RED and RG formats (8, 8I, 8UI, 16, 16I, 16UI,
1125 16F, 32I, 32UI, and 32F variants).
1126 Again, the driver has an escape hatch via FRAMEBUFFER_UNSUPPORTED.
1127
1128 For both the above extensions we limit ourselves to those that are also required by
1129 OpenGL 3.0.
1130
1131 OpenGL 3.0:
1132 Any format with base internal format ALPHA, RED, RG, RGB or RGBA is "color-renderable"
1133 but are not required to be supported as renderable textures/renderbuffer.
1134 Required renderable color formats:
1135 - RGBA32F, RGBA32I, RGBA32UI, RGBA16, RGBA16F, RGBA16I,
1136 RGBA16UI, RGBA8, RGBA8I, RGBA8UI, SRGB8_ALPHA8, and
1137 RGB10_A2.
1138 - R11F_G11F_B10F.
1139 - RG32F, RG32I, RG32UI, RG16, RG16F, RG16I, RG16UI, RG8, RG8I,
1140 and RG8UI.
1141 - R32F, R32I, R32UI, R16F, R16I, R16UI, R16, R8, R8I, and R8UI.
1142 - ALPHA8
1143
1144 OpenGL 3.1, 3.2, 3.3
1145 Same as 3.0 except ALPHA8 requires GL_ARB_compatibility/compatibility profile.
1146 OpengGL 3.3, 4.0, 4.1
1147 Adds RGB10_A2UI.
1148 OpengGL 4.2
1149 Adds
1150 - RGB5_A1, RGBA4
1151 - RGB565
1152 OpenGL 4.4
1153 Does away with the separate list and adds a column to the sized internal color format
1154 table. However, no new formats become required color renderable.
1155
1156 ES 2.0
1157 color renderable: RGBA4, RGB5_A1, RGB565
1158 GL_EXT_texture_rg adds support for R8, RG5 as a color render target
1159 GL_OES_rgb8_rgba8 adds support for RGB8 and RGBA8
1160 GL_ARM_rgba8 adds support for RGBA8 (but not RGB8)
1161 GL_EXT_texture_format_BGRA8888 does not add renderbuffer support
1162 GL_CHROMIUM_renderbuffer_format_BGRA8888 adds BGRA8 as color-renderable
1163 GL_APPLE_texture_format_BGRA8888 does not add renderbuffer support
1164
1165 ES 3.0
1166 - RGBA32I, RGBA32UI, RGBA16I, RGBA16UI, RGBA8, RGBA8I,
1167 RGBA8UI, SRGB8_ALPHA8, RGB10_A2, RGB10_A2UI, RGBA4, and
1168 RGB5_A1.
1169 - RGB8 and RGB565.
1170 - RG32I, RG32UI, RG16I, RG16UI, RG8, RG8I, and RG8UI.
1171 - R32I, R32UI, R16I, R16UI, R8, R8I, and R8UI
1172 ES 3.1
1173 Adds RGB10_A2, RGB10_A2UI,
1174 ES 3.2
1175 Adds R16F, RG16F, RGBA16F, R32F, RG32F, RGBA32F, R11F_G11F_B10F.
1176 */
1177 uint32_t allRenderFlags = ConfigInfo::kRenderable_Flag;
1178 if (kNone_MSFBOType != fMSFBOType) {
1179 allRenderFlags |= ConfigInfo::kRenderableWithMSAA_Flag;
1180 }
1181
1182 GrGLStandard standard = ctxInfo.standard();
1183 GrGLVersion version = ctxInfo.version();
1184
bsalomon30447372015-12-21 09:03:05 -08001185 fConfigTable[kUnknown_GrPixelConfig].fFormats.fBaseInternalFormat = 0;
1186 fConfigTable[kUnknown_GrPixelConfig].fFormats.fSizedInternalFormat = 0;
bsalomon76148af2016-01-12 11:13:47 -08001187 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001188 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001189 fConfigTable[kUnknown_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001190 fConfigTable[kUnknown_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001191
1192 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1193 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
bsalomon76148af2016-01-12 11:13:47 -08001194 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1195 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001196 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001197 fConfigTable[kRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001198 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1199 if (kGL_GrGLStandard == standard) {
1200 // We require some form of FBO support and all GLs with FBO support can render to RGBA8
1201 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
egdaniel4999df82016-01-07 17:06:04 -08001202 } else {
bsalomon41e4384e2016-01-08 09:12:44 -08001203 if (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
1204 ctxInfo.hasExtension("GL_ARM_rgba8")) {
1205 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
1206 }
egdaniel4999df82016-01-07 17:06:04 -08001207 }
bsalomoncdee0092016-01-08 13:20:12 -08001208 fConfigTable[kRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001209
bsalomon76148af2016-01-12 11:13:47 -08001210 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1211 GR_GL_BGRA;
bsalomon30447372015-12-21 09:03:05 -08001212 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001213 fConfigTable[kBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001214 if (kGL_GrGLStandard == standard) {
1215 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1216 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1217 if (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra")) {
1218 // Since the internal format is RGBA8, it is also renderable.
1219 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1220 allRenderFlags;
1221 }
1222 } else {
1223 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_BGRA;
1224 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_BGRA8;
1225 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
1226 // The APPLE extension doesn't make this renderable.
1227 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1228 if (version < GR_GL_VER(3,0) && !ctxInfo.hasExtension("GL_EXT_texture_storage")) {
1229 // On ES2 the internal format of a BGRA texture is RGBA with the APPLE extension.
1230 // Though, that seems to not be the case if the texture storage extension is
1231 // present. The specs don't exactly make that clear.
1232 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1233 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1234 }
1235 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
1236 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1237 ConfigInfo::kRenderable_Flag;
1238 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888") &&
kkinnunen9f63b442016-01-25 00:31:49 -08001239 (this->usesMSAARenderBuffers() || this->fMSFBOType == kMixedSamples_MSFBOType)) {
bsalomon41e4384e2016-01-08 09:12:44 -08001240 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |=
1241 ConfigInfo::kRenderableWithMSAA_Flag;
1242 }
1243 }
1244 }
bsalomoncdee0092016-01-08 13:20:12 -08001245 fConfigTable[kBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001246
bsalomon41e4384e2016-01-08 09:12:44 -08001247 // We only enable srgb support if both textures and FBOs support srgb.
1248 bool srgbSupport = false;
1249 if (kGL_GrGLStandard == standard) {
1250 if (ctxInfo.version() >= GR_GL_VER(3,0)) {
1251 srgbSupport = true;
1252 } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
1253 if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
1254 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
1255 srgbSupport = true;
1256 }
1257 }
1258 // All the above srgb extensions support toggling srgb writes
1259 fSRGBWriteControl = srgbSupport;
1260 } else {
1261 // See https://bug.skia.org/4148 for PowerVR issue.
1262 srgbSupport = kPowerVRRogue_GrGLRenderer != ctxInfo.renderer() &&
1263 (ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB"));
1264 // ES through 3.1 requires EXT_srgb_write_control to support toggling
1265 // sRGB writing for destinations.
1266 fSRGBWriteControl = ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
1267 }
bsalomon30447372015-12-21 09:03:05 -08001268 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1269 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1270 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1271 // external format is GL_RGBA. See below for note about ES2.0 and glTex[Sub]Image.
bsalomon76148af2016-01-12 11:13:47 -08001272 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1273 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001274 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001275 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001276 if (srgbSupport) {
1277 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1278 allRenderFlags;
1279 }
bsalomoncdee0092016-01-08 13:20:12 -08001280 fConfigTable[kSRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001281
1282 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1283 if (this->ES2CompatibilitySupport()) {
1284 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB565;
1285 } else {
1286 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB5;
1287 }
bsalomon76148af2016-01-12 11:13:47 -08001288 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1289 GR_GL_RGB;
bsalomon30447372015-12-21 09:03:05 -08001290 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_5_6_5;
bsalomon7928ef62016-01-05 10:26:39 -08001291 fConfigTable[kRGB_565_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001292 fConfigTable[kRGB_565_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1293 if (kGL_GrGLStandard == standard) {
1294 if (version >= GR_GL_VER(4, 2) || ctxInfo.hasExtension("GL_ES2_compatibility")) {
1295 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1296 }
1297 } else {
1298 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1299 }
bsalomoncdee0092016-01-08 13:20:12 -08001300 fConfigTable[kRGB_565_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001301
1302 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1303 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA4;
bsalomon76148af2016-01-12 11:13:47 -08001304 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1305 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001306 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
bsalomon7928ef62016-01-05 10:26:39 -08001307 fConfigTable[kRGBA_4444_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001308 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1309 if (kGL_GrGLStandard == standard) {
1310 if (version >= GR_GL_VER(4, 2)) {
1311 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1312 }
1313 } else {
1314 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1315 }
bsalomoncdee0092016-01-08 13:20:12 -08001316 fConfigTable[kRGBA_4444_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001317
1318 if (this->textureRedSupport()) {
1319 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
1320 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R8;
bsalomon76148af2016-01-12 11:13:47 -08001321 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1322 GR_GL_RED;
bsalomoncdee0092016-01-08 13:20:12 -08001323 fConfigTable[kAlpha_8_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001324 } else {
1325 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1326 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA8;
bsalomon76148af2016-01-12 11:13:47 -08001327 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1328 GR_GL_ALPHA;
bsalomoncdee0092016-01-08 13:20:12 -08001329 fConfigTable[kAlpha_8_GrPixelConfig].fSwizzle = GrSwizzle::AAAA();
bsalomon30447372015-12-21 09:03:05 -08001330 }
1331 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001332 fConfigTable[kAlpha_8_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001333 fConfigTable[kAlpha_8_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1334 if (this->textureRedSupport() || kDesktop_ARB_MSFBOType == this->msFBOType()) {
1335 // desktop ARB extension/3.0+ supports ALPHA8 as renderable.
1336 // Core profile removes ALPHA8 support, but we should have chosen R8 in that case.
1337 fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= allRenderFlags;
1338 }
1339
1340 // Check for [half] floating point texture support
1341 // NOTE: We disallow floating point textures on ES devices if linear filtering modes are not
1342 // supported. This is for simplicity, but a more granular approach is possible. Coincidentally,
1343 // [half] floating point textures became part of the standard in ES3.1 / OGL 3.0.
1344 bool hasFPTextures = false;
1345 bool hasHalfFPTextures = false;
1346 // for now we don't support floating point MSAA on ES
1347 uint32_t fpRenderFlags = (kGL_GrGLStandard == standard) ?
1348 allRenderFlags : (uint32_t)ConfigInfo::kRenderable_Flag;
1349
1350 if (kGL_GrGLStandard == standard) {
1351 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_float")) {
1352 hasFPTextures = true;
1353 hasHalfFPTextures = true;
1354 }
1355 } else {
1356 if (version >= GR_GL_VER(3, 1)) {
1357 hasFPTextures = true;
1358 hasHalfFPTextures = true;
1359 } else {
1360 if (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
1361 ctxInfo.hasExtension("GL_OES_texture_float")) {
1362 hasFPTextures = true;
1363 }
1364 if (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
1365 ctxInfo.hasExtension("GL_OES_texture_half_float")) {
1366 hasHalfFPTextures = true;
1367 }
1368 }
1369 }
bsalomon30447372015-12-21 09:03:05 -08001370
1371 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1372 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA32F;
bsalomon76148af2016-01-12 11:13:47 -08001373 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1374 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001375 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fExternalType = GR_GL_FLOAT;
bsalomon7928ef62016-01-05 10:26:39 -08001376 fConfigTable[kRGBA_float_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001377 if (hasFPTextures) {
1378 fConfigTable[kRGBA_float_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1379 // For now we only enable rendering to float on desktop, because on ES we'd have to solve
1380 // many precision issues and no clients actually want this yet.
1381 if (kGL_GrGLStandard == standard /* || version >= GR_GL_VER(3,2) ||
1382 ctxInfo.hasExtension("GL_EXT_color_buffer_float")*/) {
1383 fConfigTable[kRGBA_float_GrPixelConfig].fFlags |= fpRenderFlags;
1384 }
1385 }
bsalomoncdee0092016-01-08 13:20:12 -08001386 fConfigTable[kRGBA_float_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001387
1388 if (this->textureRedSupport()) {
1389 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
1390 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R16F;
bsalomon76148af2016-01-12 11:13:47 -08001391 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage]
1392 = GR_GL_RED;
bsalomoncdee0092016-01-08 13:20:12 -08001393 fConfigTable[kAlpha_half_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001394 } else {
1395 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1396 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA16F;
bsalomon76148af2016-01-12 11:13:47 -08001397 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage]
1398 = GR_GL_ALPHA;
bsalomoncdee0092016-01-08 13:20:12 -08001399 fConfigTable[kAlpha_half_GrPixelConfig].fSwizzle = GrSwizzle::AAAA();
bsalomon30447372015-12-21 09:03:05 -08001400 }
1401 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
1402 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1403 } else {
1404 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1405 }
bsalomon7928ef62016-01-05 10:26:39 -08001406 fConfigTable[kAlpha_half_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001407 if (hasHalfFPTextures) {
1408 fConfigTable[kAlpha_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1409 // ES requires either 3.2 or the combination of EXT_color_buffer_half_float and support for
1410 // GL_RED internal format.
1411 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3,2) ||
1412 (this->textureRedSupport() &&
1413 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float"))) {
1414 fConfigTable[kAlpha_half_GrPixelConfig].fFlags |= fpRenderFlags;
1415 }
1416 }
bsalomon30447372015-12-21 09:03:05 -08001417
1418 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1419 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA16F;
bsalomon76148af2016-01-12 11:13:47 -08001420 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1421 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001422 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
1423 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1424 } else {
1425 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1426 }
bsalomon7928ef62016-01-05 10:26:39 -08001427 fConfigTable[kRGBA_half_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001428 if (hasHalfFPTextures) {
1429 fConfigTable[kRGBA_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1430 // ES requires 3.2 or EXT_color_buffer_half_float.
1431 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3,2) ||
1432 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
1433 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= fpRenderFlags;
1434 }
1435 }
bsalomoncdee0092016-01-08 13:20:12 -08001436 fConfigTable[kRGBA_half_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001437
1438 // Compressed texture support
1439
1440 // glCompressedTexImage2D is available on all OpenGL ES devices. It is available on standard
1441 // OpenGL after version 1.3. We'll assume at least that level of OpenGL support.
1442
1443 // TODO: Fix command buffer bindings and remove this.
1444 fCompressedTexSubImageSupport = SkToBool(gli->fFunctions.fCompressedTexSubImage2D);
bsalomon30447372015-12-21 09:03:05 -08001445
1446 // No sized/unsized internal format distinction for compressed formats, no external format.
bsalomon41e4384e2016-01-08 09:12:44 -08001447 // Below we set the external formats and types to 0.
bsalomon30447372015-12-21 09:03:05 -08001448
1449 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_PALETTE8_RGBA8;
1450 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_PALETTE8_RGBA8;
bsalomon76148af2016-01-12 11:13:47 -08001451 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001452 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001453 fConfigTable[kIndex_8_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001454 // Disable this for now, while we investigate https://bug.skia.org/4333
1455 if (false) {
1456 // Check for 8-bit palette..
1457 GrGLint numFormats;
1458 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
1459 if (numFormats) {
1460 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
1461 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
1462 for (int i = 0; i < numFormats; ++i) {
1463 if (GR_GL_PALETTE8_RGBA8 == formats[i]) {
1464 fConfigTable[kIndex_8_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1465 break;
1466 }
1467 }
1468 }
1469 }
bsalomoncdee0092016-01-08 13:20:12 -08001470 fConfigTable[kIndex_8_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001471
bsalomon41e4384e2016-01-08 09:12:44 -08001472 // May change the internal format based on extensions.
1473 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat =
1474 GR_GL_COMPRESSED_LUMINANCE_LATC1;
1475 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1476 GR_GL_COMPRESSED_LUMINANCE_LATC1;
1477 if (ctxInfo.hasExtension("GL_EXT_texture_compression_latc") ||
1478 ctxInfo.hasExtension("GL_NV_texture_compression_latc")) {
1479 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1480 } else if ((kGL_GrGLStandard == standard && version >= GR_GL_VER(3, 0)) ||
1481 ctxInfo.hasExtension("GL_EXT_texture_compression_rgtc") ||
1482 ctxInfo.hasExtension("GL_ARB_texture_compression_rgtc")) {
1483 // RGTC is identical and available on OpenGL 3.0+ as well as with extensions
1484 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1485 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat =
1486 GR_GL_COMPRESSED_RED_RGTC1;
1487 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1488 GR_GL_COMPRESSED_RED_RGTC1;
1489 } else if (ctxInfo.hasExtension("GL_AMD_compressed_3DC_texture")) {
1490 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1491 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_3DC_X;
1492 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1493 GR_GL_COMPRESSED_3DC_X;
1494
bsalomon30447372015-12-21 09:03:05 -08001495 }
bsalomon76148af2016-01-12 11:13:47 -08001496 fConfigTable[kLATC_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001497 fConfigTable[kLATC_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001498 fConfigTable[kLATC_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001499 fConfigTable[kLATC_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001500
1501 fConfigTable[kETC1_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_ETC1_RGB8;
1502 fConfigTable[kETC1_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_COMPRESSED_ETC1_RGB8;
bsalomon76148af2016-01-12 11:13:47 -08001503 fConfigTable[kETC1_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001504 fConfigTable[kETC1_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001505 fConfigTable[kETC1_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001506 if (kGL_GrGLStandard == standard) {
1507 if (version >= GR_GL_VER(4, 3) || ctxInfo.hasExtension("GL_ARB_ES3_compatibility")) {
1508 fConfigTable[kETC1_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1509 }
1510 } else {
1511 if (version >= GR_GL_VER(3, 0) ||
1512 ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") ||
1513 // ETC2 is a superset of ETC1, so we can just check for that, too.
1514 (ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") &&
1515 ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture"))) {
1516 fConfigTable[kETC1_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1517 }
1518 }
bsalomoncdee0092016-01-08 13:20:12 -08001519 fConfigTable[kETC1_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001520
1521 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_R11_EAC;
1522 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_COMPRESSED_R11_EAC;
bsalomon76148af2016-01-12 11:13:47 -08001523 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001524 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001525 fConfigTable[kR11_EAC_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001526 // Check for R11_EAC. We don't support R11_EAC on desktop, as most cards default to
1527 // decompressing the textures in the driver, and is generally slower.
1528 if (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) {
1529 fConfigTable[kR11_EAC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1530 }
bsalomoncdee0092016-01-08 13:20:12 -08001531 fConfigTable[kR11_EAC_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001532
1533 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fBaseInternalFormat =
1534 GR_GL_COMPRESSED_RGBA_ASTC_12x12;
1535 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fSizedInternalFormat =
1536 GR_GL_COMPRESSED_RGBA_ASTC_12x12;
bsalomon76148af2016-01-12 11:13:47 -08001537 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1538 0;
bsalomon30447372015-12-21 09:03:05 -08001539 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001540 fConfigTable[kASTC_12x12_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001541 if (ctxInfo.hasExtension("GL_KHR_texture_compression_astc_hdr") ||
1542 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_ldr") ||
1543 ctxInfo.hasExtension("GL_OES_texture_compression_astc")) {
1544 fConfigTable[kASTC_12x12_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1545 }
bsalomoncdee0092016-01-08 13:20:12 -08001546 fConfigTable[kASTC_12x12_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001547
1548 // Bulk populate the texture internal/external formats here and then deal with exceptions below.
1549
1550 // ES 2.0 requires that the internal/external formats match.
bsalomon76148af2016-01-12 11:13:47 -08001551 bool useSizedTexFormats = (kGL_GrGLStandard == ctxInfo.standard() ||
1552 ctxInfo.version() >= GR_GL_VER(3,0));
1553 // All ES versions (thus far) require sized internal formats for render buffers.
1554 // TODO: Always use sized internal format?
1555 bool useSizedRbFormats = kGLES_GrGLStandard == ctxInfo.standard();
1556
bsalomon30447372015-12-21 09:03:05 -08001557 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
bsalomon76148af2016-01-12 11:13:47 -08001558 // Almost always we want to pass fExternalFormat[kOther_ExternalFormatUsage] as the <format>
1559 // param to glTex[Sub]Image.
1560 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
1561 fConfigTable[i].fFormats.fExternalFormat[kOther_ExternalFormatUsage];
1562 fConfigTable[i].fFormats.fInternalFormatTexImage = useSizedTexFormats ?
1563 fConfigTable[i].fFormats.fSizedInternalFormat :
1564 fConfigTable[i].fFormats.fBaseInternalFormat;
1565 fConfigTable[i].fFormats.fInternalFormatRenderbuffer = useSizedRbFormats ?
bsalomon30447372015-12-21 09:03:05 -08001566 fConfigTable[i].fFormats.fSizedInternalFormat :
1567 fConfigTable[i].fFormats.fBaseInternalFormat;
1568 }
1569 // OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the <format>
1570 // param to Tex(Sub)Image. ES 2.0 requires the <internalFormat> and <format> params to match.
1571 // Thus, on ES 2.0 we will use GL_SRGB_ALPHA as the <format> param.
1572 // On OpenGL and ES 3.0+ GL_SRGB_ALPHA does not work for the <format> param to glTexImage.
1573 if (ctxInfo.standard() == kGLES_GrGLStandard && ctxInfo.version() == GR_GL_VER(2,0)) {
bsalomon76148af2016-01-12 11:13:47 -08001574 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
bsalomon30447372015-12-21 09:03:05 -08001575 GR_GL_SRGB_ALPHA;
1576 }
1577
1578 // If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image
1579 // as a base format.
1580 // GL_EXT_texture_format_BGRA8888:
1581 // This extension GL_BGRA as an unsized internal format. However, it is written against ES
1582 // 2.0 and therefore doesn't define a value for GL_BGRA8 as ES 2.0 uses unsized internal
1583 // formats.
1584 // GL_APPLE_texture_format_BGRA8888:
1585 // ES 2.0: the extension makes BGRA an external format but not an internal format.
1586 // ES 3.0: the extension explicitly states GL_BGRA8 is not a valid internal format for
1587 // glTexImage (just for glTexStorage).
bsalomon76148af2016-01-12 11:13:47 -08001588 if (useSizedTexFormats && this->bgraIsInternalFormat()) {
bsalomon30447372015-12-21 09:03:05 -08001589 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fInternalFormatTexImage = GR_GL_BGRA;
1590 }
1591
bsalomoncdee0092016-01-08 13:20:12 -08001592 // If we don't have texture swizzle support then the shader generator must insert the
1593 // swizzle into shader code.
1594 if (!this->textureSwizzleSupport()) {
1595 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1596 glslCaps->fConfigTextureSwizzle[i] = fConfigTable[i].fSwizzle;
1597 }
1598 }
1599
bsalomon7f9b2e42016-01-12 13:29:26 -08001600 // Shader output swizzles will default to RGBA. When we've use GL_RED instead of GL_ALPHA to
1601 // implement kAlpha_8_GrPixelConfig we need to swizzle the shader outputs so the alpha channel
1602 // gets written to the single component.
1603 if (this->textureRedSupport()) {
1604 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1605 GrPixelConfig config = static_cast<GrPixelConfig>(i);
1606 if (GrPixelConfigIsAlphaOnly(config) &&
1607 fConfigTable[i].fFormats.fBaseInternalFormat == GR_GL_RED) {
1608 glslCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA();
1609 }
1610 }
1611 }
1612
bsalomon30447372015-12-21 09:03:05 -08001613#ifdef SK_DEBUG
1614 // Make sure we initialized everything.
bsalomon76148af2016-01-12 11:13:47 -08001615 ConfigInfo defaultEntry;
bsalomon30447372015-12-21 09:03:05 -08001616 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
bsalomon76148af2016-01-12 11:13:47 -08001617 SkASSERT(defaultEntry.fFormats.fBaseInternalFormat !=
1618 fConfigTable[i].fFormats.fBaseInternalFormat);
1619 SkASSERT(defaultEntry.fFormats.fSizedInternalFormat !=
bsalomon30447372015-12-21 09:03:05 -08001620 fConfigTable[i].fFormats.fSizedInternalFormat);
bsalomon76148af2016-01-12 11:13:47 -08001621 for (int j = 0; j < kExternalFormatUsageCnt; ++j) {
1622 SkASSERT(defaultEntry.fFormats.fExternalFormat[j] !=
1623 fConfigTable[i].fFormats.fExternalFormat[j]);
1624 }
1625 SkASSERT(defaultEntry.fFormats.fExternalType != fConfigTable[i].fFormats.fExternalType);
bsalomon30447372015-12-21 09:03:05 -08001626 }
1627#endif
1628}
1629
egdanielb7e7d572015-11-04 04:23:53 -08001630void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {}