blob: dc4ef4c160459fbc655287446d50322bfd0c4e5a [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"
robertphillips@google.com6177e692013-02-28 20:16:25 +000010#include "GrGLContext.h"
bsalomon@google.comc9668ec2012-04-11 18:16:41 +000011#include "SkTSearch.h"
bsalomon@google.com20f7f172013-05-17 19:05:03 +000012#include "SkTSort.h"
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000013
14GrGLCaps::GrGLCaps() {
15 this->reset();
16}
17
18void GrGLCaps::reset() {
bsalomon@google.combcce8922013-03-25 15:38:39 +000019 INHERITED::reset();
20
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000021 fVerifiedColorConfigs.reset();
22 fStencilFormats.reset();
23 fStencilVerifiedColorConfigs.reset();
24 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +000025 fInvalidateFBType = kNone_InvalidateFBType;
krajcevski3217c4a2014-06-09 09:10:04 -070026 fLATCAlias = kLATC_LATCAlias;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000027 fMapBufferType = kNone_MapBufferType;
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;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +000031 fMaxFixedFunctionTextureCoords = 0;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000032 fRGBA8RenderbufferSupport = false;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000033 fBGRAIsInternalFormat = false;
34 fTextureSwizzleSupport = false;
35 fUnpackRowLengthSupport = false;
36 fUnpackFlipYSupport = false;
37 fPackRowLengthSupport = false;
38 fPackFlipYSupport = false;
39 fTextureUsageSupport = false;
40 fTexStorageSupport = false;
robertphillips@google.com443e5a52012-04-30 20:01:21 +000041 fTextureRedSupport = false;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000042 fImagingSupport = false;
robertphillips@google.com1d89c932012-06-27 19:31:41 +000043 fTwoFormatLimit = false;
bsalomon@google.com706f6682012-10-23 14:53:55 +000044 fFragCoordsConventionSupport = false;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000045 fVertexArrayObjectSupport = false;
bsalomon@google.com96966a52013-02-21 16:34:21 +000046 fUseNonVBOVertexAndIndexDynamicData = false;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000047 fIsCoreProfile = false;
robertphillips@google.com56ce48a2013-10-31 21:44:25 +000048 fFullClearIsFree = false;
commit-bot@chromium.org4362a382014-03-26 19:49:03 +000049 fDropsTileOnZeroDivide = false;
joshualitt58162332014-08-01 06:44:53 -070050 fFBFetchSupport = false;
51 fFBFetchColorName = NULL;
52 fFBFetchExtensionString = NULL;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000053}
54
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000055GrGLCaps::GrGLCaps(const GrGLCaps& caps) : GrDrawTargetCaps() {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000056 *this = caps;
57}
58
commit-bot@chromium.orgbeb8b3a2014-04-15 15:37:51 +000059GrGLCaps& GrGLCaps::operator= (const GrGLCaps& caps) {
bsalomon@google.combcce8922013-03-25 15:38:39 +000060 INHERITED::operator=(caps);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000061 fVerifiedColorConfigs = caps.fVerifiedColorConfigs;
62 fStencilFormats = caps.fStencilFormats;
63 fStencilVerifiedColorConfigs = caps.fStencilVerifiedColorConfigs;
krajcevski3217c4a2014-06-09 09:10:04 -070064 fLATCAlias = caps.fLATCAlias;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000065 fMaxFragmentUniformVectors = caps.fMaxFragmentUniformVectors;
bsalomon@google.com60da4172012-06-01 19:25:00 +000066 fMaxVertexAttributes = caps.fMaxVertexAttributes;
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +000067 fMaxFragmentTextureUnits = caps.fMaxFragmentTextureUnits;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +000068 fMaxFixedFunctionTextureCoords = caps.fMaxFixedFunctionTextureCoords;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000069 fMSFBOType = caps.fMSFBOType;
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +000070 fInvalidateFBType = caps.fInvalidateFBType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000071 fMapBufferType = caps.fMapBufferType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000072 fRGBA8RenderbufferSupport = caps.fRGBA8RenderbufferSupport;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000073 fBGRAIsInternalFormat = caps.fBGRAIsInternalFormat;
74 fTextureSwizzleSupport = caps.fTextureSwizzleSupport;
75 fUnpackRowLengthSupport = caps.fUnpackRowLengthSupport;
76 fUnpackFlipYSupport = caps.fUnpackFlipYSupport;
77 fPackRowLengthSupport = caps.fPackRowLengthSupport;
78 fPackFlipYSupport = caps.fPackFlipYSupport;
79 fTextureUsageSupport = caps.fTextureUsageSupport;
80 fTexStorageSupport = caps.fTexStorageSupport;
robertphillips@google.com443e5a52012-04-30 20:01:21 +000081 fTextureRedSupport = caps.fTextureRedSupport;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000082 fImagingSupport = caps.fImagingSupport;
robertphillips@google.com1d89c932012-06-27 19:31:41 +000083 fTwoFormatLimit = caps.fTwoFormatLimit;
bsalomon@google.com706f6682012-10-23 14:53:55 +000084 fFragCoordsConventionSupport = caps.fFragCoordsConventionSupport;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000085 fVertexArrayObjectSupport = caps.fVertexArrayObjectSupport;
bsalomon@google.com96966a52013-02-21 16:34:21 +000086 fUseNonVBOVertexAndIndexDynamicData = caps.fUseNonVBOVertexAndIndexDynamicData;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000087 fIsCoreProfile = caps.fIsCoreProfile;
robertphillips@google.com56ce48a2013-10-31 21:44:25 +000088 fFullClearIsFree = caps.fFullClearIsFree;
commit-bot@chromium.org4362a382014-03-26 19:49:03 +000089 fDropsTileOnZeroDivide = caps.fDropsTileOnZeroDivide;
joshualitt58162332014-08-01 06:44:53 -070090 fFBFetchSupport = caps.fFBFetchSupport;
91 fFBFetchColorName = caps.fFBFetchColorName;
92 fFBFetchExtensionString = caps.fFBFetchExtensionString;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000093
94 return *this;
95}
96
commit-bot@chromium.orgf4e67e32014-04-30 01:26:04 +000097bool GrGLCaps::init(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000098
99 this->reset();
100 if (!ctxInfo.isInitialized()) {
commit-bot@chromium.orgf4e67e32014-04-30 01:26:04 +0000101 return false;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000102 }
103
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000104 GrGLStandard standard = ctxInfo.standard();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000105 GrGLVersion version = ctxInfo.version();
106
bsalomon@google.combcce8922013-03-25 15:38:39 +0000107 /**************************************************************************
108 * Caps specific to GrGLCaps
109 **************************************************************************/
110
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000111 if (kGLES_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000112 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
113 &fMaxFragmentUniformVectors);
114 } else {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000115 SkASSERT(kGL_GrGLStandard == standard);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000116 GrGLint max;
117 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
118 fMaxFragmentUniformVectors = max / 4;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +0000119 if (version >= GR_GL_VER(3, 2)) {
120 GrGLint profileMask;
121 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
122 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
123 }
124 if (!fIsCoreProfile) {
125 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_COORDS, &fMaxFixedFunctionTextureCoords);
126 // Sanity check
127 SkASSERT(fMaxFixedFunctionTextureCoords > 0 && fMaxFixedFunctionTextureCoords < 128);
128 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000129 }
bsalomon@google.com60da4172012-06-01 19:25:00 +0000130 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000131 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &fMaxFragmentTextureUnits);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000132
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000133 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000134 fRGBA8RenderbufferSupport = true;
135 } else {
commit-bot@chromium.orgc5dffe42013-08-20 15:25:21 +0000136 fRGBA8RenderbufferSupport = version >= GR_GL_VER(3,0) ||
137 ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000138 ctxInfo.hasExtension("GL_ARM_rgba8");
139 }
140
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000141 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000142 fTextureSwizzleSupport = version >= GR_GL_VER(3,3) ||
143 ctxInfo.hasExtension("GL_ARB_texture_swizzle");
144 } else {
commit-bot@chromium.org6364b5e2013-08-20 20:22:52 +0000145 fTextureSwizzleSupport = version >= GR_GL_VER(3,0);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000146 }
147
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000148 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000149 fUnpackRowLengthSupport = true;
150 fUnpackFlipYSupport = false;
151 fPackRowLengthSupport = true;
152 fPackFlipYSupport = false;
153 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000154 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
155 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000156 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000157 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
158 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000159 fPackFlipYSupport =
160 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
161 }
162
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000163 fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000164 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
165
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000166 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org7a434a22013-08-21 14:01:56 +0000167 // The EXT version can apply to either GL or GLES.
168 fTexStorageSupport = version >= GR_GL_VER(4,2) ||
169 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
170 ctxInfo.hasExtension("GL_EXT_texture_storage");
171 } else {
172 // Qualcomm Adreno drivers appear to have issues with texture storage.
173 fTexStorageSupport = (version >= GR_GL_VER(3,0) &&
174 kQualcomm_GrGLVendor != ctxInfo.vendor()) ||
175 ctxInfo.hasExtension("GL_EXT_texture_storage");
176 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000177
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000178 // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support it if
179 // it doesn't have ARB_texture_rg extension.
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000180 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000181 if (ctxInfo.isMesa()) {
182 fTextureRedSupport = ctxInfo.hasExtension("GL_ARB_texture_rg");
183 } else {
184 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
185 ctxInfo.hasExtension("GL_ARB_texture_rg");
186 }
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000187 } else {
commit-bot@chromium.orgc5dffe42013-08-20 15:25:21 +0000188 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
189 ctxInfo.hasExtension("GL_EXT_texture_rg");
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000190 }
191
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000192 fImagingSupport = kGL_GrGLStandard == standard &&
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000193 ctxInfo.hasExtension("GL_ARB_imaging");
194
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000195 // ES 2 only guarantees RGBA/uchar + one other format/type combo for
196 // ReadPixels. The other format has to checked at run-time since it
197 // can change based on which render target is bound
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000198 fTwoFormatLimit = kGLES_GrGLStandard == standard;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000199
bsalomon@google.com706f6682012-10-23 14:53:55 +0000200 // Known issue on at least some Intel platforms:
201 // http://code.google.com/p/skia/issues/detail?id=946
202 if (kIntel_GrGLVendor != ctxInfo.vendor()) {
203 fFragCoordsConventionSupport = ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
204 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions");
205 }
206
bsalomon@google.com3012ded2013-02-22 16:44:04 +0000207 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
208 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
209 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
210 // limit this decision to specific GPU families rather than basing it on the vendor alone.
211 if (!GR_GL_MUST_USE_VBO &&
bsalomoned82c4e2014-09-02 07:54:47 -0700212 (kARM_GrGLVendor == ctxInfo.vendor() ||
213 kImagination_GrGLVendor == ctxInfo.vendor() ||
214 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
bsalomon@google.com96966a52013-02-21 16:34:21 +0000215 fUseNonVBOVertexAndIndexDynamicData = true;
216 }
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000217
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000218 if ((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
skia.committer@gmail.coma9157722014-04-03 03:04:26 +0000219 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000220 ctxInfo.hasExtension("GL_ARB_invalidate_subdata")) {
221 fDiscardRenderTargetSupport = true;
222 fInvalidateFBType = kInvalidate_InvalidateFBType;
223 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
224 fDiscardRenderTargetSupport = true;
225 fInvalidateFBType = kDiscard_InvalidateFBType;
226 }
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000227
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000228 if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) {
229 fFullClearIsFree = true;
230 }
231
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000232 if (kGL_GrGLStandard == standard) {
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000233 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
234 ctxInfo.hasExtension("GL_ARB_vertex_array_object");
235 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000236 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
237 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000238 }
239
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000240 if (kGLES_GrGLStandard == standard) {
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000241 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
joshualitt58162332014-08-01 06:44:53 -0700242 fFBFetchSupport = true;
243 fFBFetchColorName = "gl_LastFragData[0]";
244 fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000245 } else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
joshualitt58162332014-08-01 06:44:53 -0700246 fFBFetchSupport = true;
247 fFBFetchColorName = "gl_LastFragData[0]";
248 fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
249 } else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
250 // The arm extension also requires an additional flag which we will set onResetContext
251 // This is all temporary.
252 fFBFetchSupport = true;
253 fFBFetchColorName = "gl_LastFragColorARM";
254 fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000255 }
256 }
257
commit-bot@chromium.org4362a382014-03-26 19:49:03 +0000258 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
259 fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
260
robertphillips@google.com6177e692013-02-28 20:16:25 +0000261 this->initFSAASupport(ctxInfo, gli);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000262 this->initStencilFormats(ctxInfo);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000263
264 /**************************************************************************
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000265 * GrDrawTargetCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000266 **************************************************************************/
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000267 if (kGL_GrGLStandard == standard) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000268 // we could also look for GL_ATI_separate_stencil extension or
269 // GL_EXT_stencil_two_side but they use different function signatures
270 // than GL2.0+ (and than each other).
271 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
272 // supported on GL 1.4 and higher or by extension
273 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
274 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
275 } else {
276 // ES 2 has two sided stencil and stencil wrap
277 fTwoSidedStencilSupport = true;
278 fStencilWrapOpsSupport = true;
279 }
280
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000281 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000282 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
283 // extension includes glMapBuffer.
284 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
285 fMapBufferFlags |= kSubset_MapFlag;
286 fMapBufferType = kMapBufferRange_MapBufferType;
287 } else {
288 fMapBufferType = kMapBuffer_MapBufferType;
289 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000290 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000291 // Unextended GLES2 doesn't have any buffer mapping.
292 fMapBufferFlags = kNone_MapBufferType;
293 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
294 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
295 fMapBufferType = kChromium_MapBufferType;
296 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
297 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
298 fMapBufferType = kMapBufferRange_MapBufferType;
299 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
300 fMapBufferFlags = kCanMap_MapFlag;
301 fMapBufferType = kMapBuffer_MapBufferType;
302 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000303 }
304
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000305 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000306 SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) ||
307 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two"));
308 fNPOTTextureTileSupport = true;
309 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000310 } else {
311 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000312 // ES3 has no limitations.
313 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
314 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000315 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
316 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
317 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
318 // to alllow arbitrary wrap modes, however.
319 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000320 }
321
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000322 fHWAALineSupport = (kGL_GrGLStandard == standard);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000323
324 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
325 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
326 // Our render targets are always created with textures as the color
327 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000328 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000329
kkinnunen32b9a3b2014-07-02 22:56:35 -0700330 fPathRenderingSupport = ctxInfo.hasExtension("GL_NV_path_rendering");
331
332 if (fPathRenderingSupport) {
333 if (kGL_GrGLStandard == standard) {
334 // We need one of the two possible texturing methods: using fixed function pipeline
335 // (PathTexGen, texcoords, ...) or using the newer NVPR API additions that support
336 // setting individual fragment inputs with ProgramPathFragmentInputGen. The API
337 // additions are detected by checking the existence of the function. Eventually we may
338 // choose to remove the fixed function codepath.
339 // Set fMaxFixedFunctionTextureCoords = 0 here if you want to force
340 // ProgramPathFragmentInputGen usage on desktop.
341 fPathRenderingSupport = ctxInfo.hasExtension("GL_EXT_direct_state_access") &&
342 (fMaxFixedFunctionTextureCoords > 0 ||
343 ((ctxInfo.version() >= GR_GL_VER(4,3) ||
344 ctxInfo.hasExtension("GL_ARB_program_interface_query")) &&
bsalomon49f085d2014-09-05 13:34:00 -0700345 gli->fFunctions.fProgramPathFragmentInputGen));
kkinnunen32b9a3b2014-07-02 22:56:35 -0700346 } else {
kkinnunenec56e452014-08-25 22:21:16 -0700347 fPathRenderingSupport = ctxInfo.version() >= GR_GL_VER(3,1);
kkinnunen32b9a3b2014-07-02 22:56:35 -0700348 }
349 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000350
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000351 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
352
joshualitt58162332014-08-01 06:44:53 -0700353 // For now these two are equivalent but we could have dst read in shader via some other method
354 fDstReadInShaderSupport = fFBFetchSupport;
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000355
356 // Disable scratch texture reuse on Mali and Adreno devices
357 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() &&
358 kQualcomm_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000359
bsalomon@google.combcce8922013-03-25 15:38:39 +0000360 // Enable supported shader-related caps
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000361 if (kGL_GrGLStandard == standard) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000362 fDualSourceBlendingSupport = ctxInfo.version() >= GR_GL_VER(3,3) ||
363 ctxInfo.hasExtension("GL_ARB_blend_func_extended");
364 fShaderDerivativeSupport = true;
365 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
366 fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3,2) &&
367 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
368 } else {
369 fShaderDerivativeSupport = ctxInfo.hasExtension("GL_OES_standard_derivatives");
370 }
371
bsalomon@google.com347c3822013-05-01 20:10:01 +0000372 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000373 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount);
374 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
375 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount);
376 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000377
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000378 this->initConfigTexturableTable(ctxInfo, gli);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000379 this->initConfigRenderableTable(ctxInfo);
commit-bot@chromium.orgf4e67e32014-04-30 01:26:04 +0000380
381 return true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000382}
383
384void GrGLCaps::initConfigRenderableTable(const GrGLContextInfo& ctxInfo) {
385
386 // OpenGL < 3.0
387 // no support for render targets unless the GL_ARB_framebuffer_object
388 // extension is supported (in which case we get ALPHA, RED, RG, RGB,
389 // RGBA (ALPHA8, RGBA4, RGBA8) for OpenGL > 1.1). Note that we
390 // probably don't get R8 in this case.
391
392 // OpenGL 3.0
393 // base color renderable: ALPHA, RED, RG, RGB, and RGBA
394 // sized derivatives: ALPHA8, R8, RGBA4, RGBA8
395
396 // >= OpenGL 3.1
397 // base color renderable: RED, RG, RGB, and RGBA
398 // sized derivatives: R8, RGBA4, RGBA8
399 // if the GL_ARB_compatibility extension is supported then we get back
400 // support for GL_ALPHA and ALPHA8
401
402 // GL_EXT_bgra adds BGRA render targets to any version
403
404 // ES 2.0
405 // color renderable: RGBA4, RGB5_A1, RGB565
406 // GL_EXT_texture_rg adds support for R8 as a color render target
407 // GL_OES_rgb8_rgba8 and/or GL_ARM_rgba8 adds support for RGBA8
408 // GL_EXT_texture_format_BGRA8888 and/or GL_APPLE_texture_format_BGRA8888 added BGRA support
409
410 // ES 3.0
411 // Same as ES 2.0 except R8 and RGBA8 are supported without extensions (the functions called
412 // below already account for this).
413
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000414 GrGLStandard standard = ctxInfo.standard();
415
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000416 enum {
417 kNo_MSAA = 0,
418 kYes_MSAA = 1,
419 };
420
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000421 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000422 // Post 3.0 we will get R8
423 // Prior to 3.0 we will get ALPHA8 (with GL_ARB_framebuffer_object)
424 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
425 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000426 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = true;
427 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000428 }
429 } else {
430 // On ES we can only hope for R8
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000431 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = fTextureRedSupport;
432 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = fTextureRedSupport;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000433 }
434
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000435 if (kGL_GrGLStandard != standard) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000436 // only available in ES
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000437 fConfigRenderSupport[kRGB_565_GrPixelConfig][kNo_MSAA] = true;
438 fConfigRenderSupport[kRGB_565_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000439 }
440
441 // we no longer support 444 as a render target
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000442 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kNo_MSAA] = false;
443 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kYes_MSAA] = false;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000444
445 if (this->fRGBA8RenderbufferSupport) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000446 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
commit-bot@chromium.orgda3d69c2013-10-28 15:09:13 +0000447 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000448 }
449
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000450 if (this->isConfigTexturable(kBGRA_8888_GrPixelConfig)) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000451 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kNo_MSAA] = true;
452 // The GL_EXT_texture_format_BGRA8888 extension does not add BGRA to the list of
453 // configs that are color-renderable and can be passed to glRenderBufferStorageMultisample.
commit-bot@chromium.org4256d242013-10-17 16:29:41 +0000454 // Chromium may have an extension to allow BGRA renderbuffers to work on desktop platforms.
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +0000455 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888")) {
commit-bot@chromium.org4256d242013-10-17 16:29:41 +0000456 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] = true;
457 } else {
458 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] =
459 !fBGRAIsInternalFormat || !this->usesMSAARenderBuffers();
460 }
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000461 }
462
joshualittee5da552014-07-16 13:32:56 -0700463 if (this->isConfigTexturable(kRGBA_float_GrPixelConfig)) {
464 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true;
465 }
466
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000467 // If we don't support MSAA then undo any places above where we set a config as renderable with
468 // msaa.
469 if (kNone_MSFBOType == fMSFBOType) {
470 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
471 fConfigRenderSupport[i][kYes_MSAA] = false;
472 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000473 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000474}
475
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000476void GrGLCaps::initConfigTexturableTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000477 GrGLStandard standard = ctxInfo.standard();
478 GrGLVersion version = ctxInfo.version();
479
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000480 // Base texture support
481 fConfigTextureSupport[kAlpha_8_GrPixelConfig] = true;
482 fConfigTextureSupport[kRGB_565_GrPixelConfig] = true;
483 fConfigTextureSupport[kRGBA_4444_GrPixelConfig] = true;
484 fConfigTextureSupport[kRGBA_8888_GrPixelConfig] = true;
485
486 // Check for 8-bit palette..
487 GrGLint numFormats;
488 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
489 if (numFormats) {
490 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
491 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
492 for (int i = 0; i < numFormats; ++i) {
493 if (GR_GL_PALETTE8_RGBA8 == formats[i]) {
494 fConfigTextureSupport[kIndex_8_GrPixelConfig] = true;
495 break;
496 }
497 }
498 }
499
500 // Check for BGRA
501 if (kGL_GrGLStandard == standard) {
502 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] =
503 version >= GR_GL_VER(1,2) || ctxInfo.hasExtension("GL_EXT_bgra");
504 } else {
505 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
506 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
507 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
508 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
509 fBGRAIsInternalFormat = true;
510 }
511 SkASSERT(fConfigTextureSupport[kBGRA_8888_GrPixelConfig] ||
512 kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig);
513 }
514
515 // Compressed texture support
516
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000517 // glCompressedTexImage2D is available on all OpenGL ES devices...
518 // however, it is only available on standard OpenGL after version 1.3
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000519 bool hasCompressTex2D = (kGL_GrGLStandard != standard || version >= GR_GL_VER(1, 3));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000520
krajcevski786978162014-07-30 11:25:44 -0700521 fCompressedTexSubImageSupport =
bsalomon49f085d2014-09-05 13:34:00 -0700522 hasCompressTex2D && (gli->fFunctions.fCompressedTexSubImage2D);
krajcevski786978162014-07-30 11:25:44 -0700523
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000524 // Check for ETC1
525 bool hasETC1 = false;
526
527 // First check version for support
528 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000529 hasETC1 = hasCompressTex2D &&
joshualittee5da552014-07-16 13:32:56 -0700530 (version >= GR_GL_VER(4, 3) ||
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000531 ctxInfo.hasExtension("GL_ARB_ES3_compatibility"));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000532 } else {
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000533 hasETC1 = hasCompressTex2D &&
534 (version >= GR_GL_VER(3, 0) ||
535 ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") ||
536 // ETC2 is a superset of ETC1, so we can just check for that, too.
537 (ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") &&
538 ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture")));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000539 }
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000540 fConfigTextureSupport[kETC1_GrPixelConfig] = hasETC1;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000541
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000542 // Check for LATC under its various forms
543 LATCAlias alias = kLATC_LATCAlias;
544 bool hasLATC = hasCompressTex2D &&
545 (ctxInfo.hasExtension("GL_EXT_texture_compression_latc") ||
546 ctxInfo.hasExtension("GL_NV_texture_compression_latc"));
547
548 // Check for RGTC
549 if (!hasLATC) {
550 // If we're using OpenGL 3.0 or later, then we have RGTC, an identical compression format.
551 if (kGL_GrGLStandard == standard) {
552 hasLATC = version >= GR_GL_VER(3, 0);
553 }
554
555 if (!hasLATC) {
556 hasLATC =
557 ctxInfo.hasExtension("GL_EXT_texture_compression_rgtc") ||
558 ctxInfo.hasExtension("GL_ARB_texture_compression_rgtc");
559 }
560
561 if (hasLATC) {
562 alias = kRGTC_LATCAlias;
563 }
564 }
565
566 // Check for 3DC
567 if (!hasLATC) {
568 hasLATC = ctxInfo.hasExtension("GL_AMD_compressed_3DC_texture");
569 if (hasLATC) {
570 alias = k3DC_LATCAlias;
571 }
572 }
573
574 fConfigTextureSupport[kLATC_GrPixelConfig] = hasLATC;
575 fLATCAlias = alias;
krajcevski238b4562014-06-30 09:09:22 -0700576
krajcevskib3abe902014-07-30 13:08:11 -0700577 // Check for R11_EAC ... We don't support R11_EAC on desktop, as most
578 // cards default to decompressing the textures in the driver, and is
579 // generally slower.
580 if (kGL_GrGLStandard != standard) {
krajcevski238b4562014-06-30 09:09:22 -0700581 fConfigTextureSupport[kR11_EAC_GrPixelConfig] = version >= GR_GL_VER(3, 0);
582 }
joshualittee5da552014-07-16 13:32:56 -0700583
krajcevski7ef21622014-07-16 15:21:13 -0700584 // Check for ASTC
585 fConfigTextureSupport[kASTC_12x12_GrPixelConfig] =
586 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_hdr") ||
587 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_ldr") ||
588 ctxInfo.hasExtension("GL_OES_texture_compression_astc");
589
joshualittee5da552014-07-16 13:32:56 -0700590 // Check for floating point texture support
591 // NOTE: We disallow floating point textures on ES devices if linear
592 // filtering modes are not supported. This is for simplicity, but a more
593 // granular approach is possible. Coincidentally, floating point textures became part of
594 // the standard in ES3.1 / OGL 3.1, hence the shorthand
595 bool hasFPTextures = version >= GR_GL_VER(3, 1);
596 if (!hasFPTextures) {
597 hasFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") ||
598 (ctxInfo.hasExtension("OES_texture_float_linear") &&
599 ctxInfo.hasExtension("GL_OES_texture_float"));
600 }
601 fConfigTextureSupport[kRGBA_float_GrPixelConfig] = hasFPTextures;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000602}
603
bungemanc7af8122014-07-16 09:10:41 -0700604bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,
605 GrGLenum format,
606 GrGLenum type) const {
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000607 if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) {
608 // ES 2 guarantees this format is supported
robertphillips@google.comeca2dfb2012-06-27 20:13:49 +0000609 return true;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000610 }
611
612 if (!fTwoFormatLimit) {
613 // not limited by ES 2's constraints
614 return true;
615 }
616
bsalomon@google.com548a4332012-07-11 19:45:22 +0000617 GrGLint otherFormat = GR_GL_RGBA;
618 GrGLint otherType = GR_GL_UNSIGNED_BYTE;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000619
620 // The other supported format/type combo supported for ReadPixels
621 // can change based on which render target is bound
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000622 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000623 GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT,
624 &otherFormat);
625
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000626 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000627 GR_GL_IMPLEMENTATION_COLOR_READ_TYPE,
628 &otherType);
629
bsalomon@google.com548a4332012-07-11 19:45:22 +0000630 return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000631}
632
robertphillips@google.com6177e692013-02-28 20:16:25 +0000633void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000634
635 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000636 if (kGL_GrGLStandard != ctxInfo.standard()) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000637 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
638 // ES3 driver bugs on at least one device with a tiled GPU (N10).
639 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
640 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
641 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
642 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
commit-bot@chromium.org92b78842014-01-16 20:49:46 +0000643 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000644 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType;
645 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
646 // chrome's extension is equivalent to the EXT msaa
647 // and fbo_blit extensions.
648 fMSFBOType = kDesktop_EXT_MSFBOType;
649 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
650 fMSFBOType = kES_Apple_MSFBOType;
651 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000652 } else {
653 if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
654 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000655 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000656 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
657 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000658 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000659 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000660 }
661}
662
663namespace {
664const GrGLuint kUnknownBitCount = GrGLStencilBuffer::kUnknownBitCount;
665}
666
667void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
668
669 // Build up list of legal stencil formats (though perhaps not supported on
670 // the particular gpu/driver) from most preferred to least.
671
672 // these consts are in order of most preferred to least preferred
673 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
674
675 static const StencilFormat
676 // internal Format stencil bits total bits packed?
677 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
678 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
679 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
680 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000681 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000682 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
683
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000684 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000685 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000686 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000687 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
688 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
689
690 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
691 // require FBO support we can expect these are legal formats and don't
692 // check. These also all support the unsized GL_STENCIL_INDEX.
693 fStencilFormats.push_back() = gS8;
694 fStencilFormats.push_back() = gS16;
695 if (supportsPackedDS) {
696 fStencilFormats.push_back() = gD24S8;
697 }
698 fStencilFormats.push_back() = gS4;
699 if (supportsPackedDS) {
700 fStencilFormats.push_back() = gDS;
701 }
702 } else {
703 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
704 // for other formats.
705 // ES doesn't support using the unsized format.
706
707 fStencilFormats.push_back() = gS8;
708 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +0000709 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
710 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000711 fStencilFormats.push_back() = gD24S8;
712 }
713 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
714 fStencilFormats.push_back() = gS4;
715 }
716 }
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000717 SkASSERT(0 == fStencilVerifiedColorConfigs.count());
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000718 fStencilVerifiedColorConfigs.push_back_n(fStencilFormats.count());
719}
720
721void GrGLCaps::markColorConfigAndStencilFormatAsVerified(
722 GrPixelConfig config,
723 const GrGLStencilBuffer::Format& format) {
724#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
725 return;
726#endif
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000727 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
728 SkASSERT(fStencilFormats.count() == fStencilVerifiedColorConfigs.count());
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000729 int count = fStencilFormats.count();
730 // we expect a really small number of possible formats so linear search
731 // should be OK
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000732 SkASSERT(count < 16);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000733 for (int i = 0; i < count; ++i) {
734 if (format.fInternalFormat ==
735 fStencilFormats[i].fInternalFormat) {
736 fStencilVerifiedColorConfigs[i].markVerified(config);
737 return;
738 }
739 }
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000740 SkFAIL("Why are we seeing a stencil format that "
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000741 "GrGLCaps doesn't know about.");
742}
743
744bool GrGLCaps::isColorConfigAndStencilFormatVerified(
745 GrPixelConfig config,
746 const GrGLStencilBuffer::Format& format) const {
747#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
748 return false;
749#endif
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000750 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000751 int count = fStencilFormats.count();
752 // we expect a really small number of possible formats so linear search
753 // should be OK
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000754 SkASSERT(count < 16);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000755 for (int i = 0; i < count; ++i) {
756 if (format.fInternalFormat ==
757 fStencilFormats[i].fInternalFormat) {
758 return fStencilVerifiedColorConfigs[i].isVerified(config);
759 }
760 }
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000761 SkFAIL("Why are we seeing a stencil format that "
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000762 "GLCaps doesn't know about.");
763 return false;
764}
765
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000766SkString GrGLCaps::dump() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000767
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000768 SkString r = INHERITED::dump();
bsalomon@google.combcce8922013-03-25 15:38:39 +0000769
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000770 r.appendf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000771 for (int i = 0; i < fStencilFormats.count(); ++i) {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000772 r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000773 i,
774 fStencilFormats[i].fStencilBits,
775 fStencilFormats[i].fTotalBits);
776 }
777
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000778 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000779 "None",
780 "ARB",
781 "EXT",
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000782 "ES 3.0",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000783 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +0000784 "IMG MS To Texture",
785 "EXT MS To Texture",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000786 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000787 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
788 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
789 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000790 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType);
791 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType);
792 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType);
793 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000794 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000795
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000796 static const char* kInvalidateFBTypeStr[] = {
797 "None",
798 "Discard",
799 "Invalidate",
800 };
801 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
802 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
803 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
804 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000805
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000806 static const char* kMapBufferTypeStr[] = {
807 "None",
808 "MapBuffer",
809 "MapBufferRange",
810 "Chromium",
811 };
812 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
813 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
814 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
815 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
816 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
817
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000818 r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000819 r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
joshualitt58162332014-08-01 06:44:53 -0700820 r.appendf("FB Fetch Support: %s\n", (fFBFetchSupport ? "YES" : "NO"));
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000821 r.appendf("Invalidate FB Type: %s\n", kInvalidateFBTypeStr[fInvalidateFBType]);
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000822 r.appendf("Map Buffer Type: %s\n", kMapBufferTypeStr[fMapBufferType]);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000823 r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
824 r.appendf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits);
commit-bot@chromium.org0a6fe712014-04-23 19:26:26 +0000825 if (!fIsCoreProfile) {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000826 r.appendf("Max Fixed Function Texture Coords: %d\n", fMaxFixedFunctionTextureCoords);
commit-bot@chromium.org3628ad92013-08-30 19:43:47 +0000827 }
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000828 r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
829 r.appendf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000830 r.appendf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO"));
831 r.appendf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO"));
832 r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
833 r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
834 r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
835 r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +0000836
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000837 r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
838 r.appendf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
839 r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
840 r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
841 r.appendf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO"));
842 r.appendf("Fragment coord conventions support: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +0000843 (fFragCoordsConventionSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000844 r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
845 r.appendf("Use non-VBO for dynamic data: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +0000846 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000847 r.appendf("Full screen clear is free: %s\n", (fFullClearIsFree ? "YES" : "NO"));
commit-bot@chromium.org4362a382014-03-26 19:49:03 +0000848 r.appendf("Drops tile on zero divide: %s\n", (fDropsTileOnZeroDivide ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000849 return r;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000850}