blob: fdf6cacc08bb41dccab4cb467aabc857a08823fd [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;
bsalomon@google.com6b0cf022013-05-03 13:35:14 +000025 fFBFetchType = kNone_FBFetchType;
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +000026 fInvalidateFBType = kNone_InvalidateFBType;
krajcevski3217c4a2014-06-09 09:10:04 -070027 fLATCAlias = kLATC_LATCAlias;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000028 fMapBufferType = kNone_MapBufferType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000029 fMaxFragmentUniformVectors = 0;
bsalomon@google.com60da4172012-06-01 19:25:00 +000030 fMaxVertexAttributes = 0;
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +000031 fMaxFragmentTextureUnits = 0;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +000032 fMaxFixedFunctionTextureCoords = 0;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000033 fRGBA8RenderbufferSupport = false;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000034 fBGRAIsInternalFormat = false;
35 fTextureSwizzleSupport = false;
36 fUnpackRowLengthSupport = false;
37 fUnpackFlipYSupport = false;
38 fPackRowLengthSupport = false;
39 fPackFlipYSupport = false;
40 fTextureUsageSupport = false;
41 fTexStorageSupport = false;
robertphillips@google.com443e5a52012-04-30 20:01:21 +000042 fTextureRedSupport = false;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000043 fImagingSupport = false;
robertphillips@google.com1d89c932012-06-27 19:31:41 +000044 fTwoFormatLimit = false;
bsalomon@google.com706f6682012-10-23 14:53:55 +000045 fFragCoordsConventionSupport = false;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000046 fVertexArrayObjectSupport = false;
bsalomon@google.com96966a52013-02-21 16:34:21 +000047 fUseNonVBOVertexAndIndexDynamicData = false;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000048 fIsCoreProfile = false;
robertphillips@google.com56ce48a2013-10-31 21:44:25 +000049 fFullClearIsFree = false;
commit-bot@chromium.org4362a382014-03-26 19:49:03 +000050 fDropsTileOnZeroDivide = false;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000051}
52
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000053GrGLCaps::GrGLCaps(const GrGLCaps& caps) : GrDrawTargetCaps() {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000054 *this = caps;
55}
56
commit-bot@chromium.orgbeb8b3a2014-04-15 15:37:51 +000057GrGLCaps& GrGLCaps::operator= (const GrGLCaps& caps) {
bsalomon@google.combcce8922013-03-25 15:38:39 +000058 INHERITED::operator=(caps);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000059 fVerifiedColorConfigs = caps.fVerifiedColorConfigs;
60 fStencilFormats = caps.fStencilFormats;
61 fStencilVerifiedColorConfigs = caps.fStencilVerifiedColorConfigs;
krajcevski3217c4a2014-06-09 09:10:04 -070062 fLATCAlias = caps.fLATCAlias;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000063 fMaxFragmentUniformVectors = caps.fMaxFragmentUniformVectors;
bsalomon@google.com60da4172012-06-01 19:25:00 +000064 fMaxVertexAttributes = caps.fMaxVertexAttributes;
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +000065 fMaxFragmentTextureUnits = caps.fMaxFragmentTextureUnits;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +000066 fMaxFixedFunctionTextureCoords = caps.fMaxFixedFunctionTextureCoords;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000067 fMSFBOType = caps.fMSFBOType;
bsalomon@google.com6b0cf022013-05-03 13:35:14 +000068 fFBFetchType = caps.fFBFetchType;
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +000069 fInvalidateFBType = caps.fInvalidateFBType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000070 fMapBufferType = caps.fMapBufferType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000071 fRGBA8RenderbufferSupport = caps.fRGBA8RenderbufferSupport;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000072 fBGRAIsInternalFormat = caps.fBGRAIsInternalFormat;
73 fTextureSwizzleSupport = caps.fTextureSwizzleSupport;
74 fUnpackRowLengthSupport = caps.fUnpackRowLengthSupport;
75 fUnpackFlipYSupport = caps.fUnpackFlipYSupport;
76 fPackRowLengthSupport = caps.fPackRowLengthSupport;
77 fPackFlipYSupport = caps.fPackFlipYSupport;
78 fTextureUsageSupport = caps.fTextureUsageSupport;
79 fTexStorageSupport = caps.fTexStorageSupport;
robertphillips@google.com443e5a52012-04-30 20:01:21 +000080 fTextureRedSupport = caps.fTextureRedSupport;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000081 fImagingSupport = caps.fImagingSupport;
robertphillips@google.com1d89c932012-06-27 19:31:41 +000082 fTwoFormatLimit = caps.fTwoFormatLimit;
bsalomon@google.com706f6682012-10-23 14:53:55 +000083 fFragCoordsConventionSupport = caps.fFragCoordsConventionSupport;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000084 fVertexArrayObjectSupport = caps.fVertexArrayObjectSupport;
bsalomon@google.com96966a52013-02-21 16:34:21 +000085 fUseNonVBOVertexAndIndexDynamicData = caps.fUseNonVBOVertexAndIndexDynamicData;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000086 fIsCoreProfile = caps.fIsCoreProfile;
robertphillips@google.com56ce48a2013-10-31 21:44:25 +000087 fFullClearIsFree = caps.fFullClearIsFree;
commit-bot@chromium.org4362a382014-03-26 19:49:03 +000088 fDropsTileOnZeroDivide = caps.fDropsTileOnZeroDivide;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000089
90 return *this;
91}
92
commit-bot@chromium.orgf4e67e32014-04-30 01:26:04 +000093bool GrGLCaps::init(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000094
95 this->reset();
96 if (!ctxInfo.isInitialized()) {
commit-bot@chromium.orgf4e67e32014-04-30 01:26:04 +000097 return false;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000098 }
99
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000100 GrGLStandard standard = ctxInfo.standard();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000101 GrGLVersion version = ctxInfo.version();
102
bsalomon@google.combcce8922013-03-25 15:38:39 +0000103 /**************************************************************************
104 * Caps specific to GrGLCaps
105 **************************************************************************/
106
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000107 if (kGLES_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000108 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
109 &fMaxFragmentUniformVectors);
110 } else {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000111 SkASSERT(kGL_GrGLStandard == standard);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000112 GrGLint max;
113 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
114 fMaxFragmentUniformVectors = max / 4;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +0000115 if (version >= GR_GL_VER(3, 2)) {
116 GrGLint profileMask;
117 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
118 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
119 }
120 if (!fIsCoreProfile) {
121 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_COORDS, &fMaxFixedFunctionTextureCoords);
122 // Sanity check
123 SkASSERT(fMaxFixedFunctionTextureCoords > 0 && fMaxFixedFunctionTextureCoords < 128);
124 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000125 }
bsalomon@google.com60da4172012-06-01 19:25:00 +0000126 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000127 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &fMaxFragmentTextureUnits);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000128
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000129 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000130 fRGBA8RenderbufferSupport = true;
131 } else {
commit-bot@chromium.orgc5dffe42013-08-20 15:25:21 +0000132 fRGBA8RenderbufferSupport = version >= GR_GL_VER(3,0) ||
133 ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000134 ctxInfo.hasExtension("GL_ARM_rgba8");
135 }
136
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000137 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000138 fTextureSwizzleSupport = version >= GR_GL_VER(3,3) ||
139 ctxInfo.hasExtension("GL_ARB_texture_swizzle");
140 } else {
commit-bot@chromium.org6364b5e2013-08-20 20:22:52 +0000141 fTextureSwizzleSupport = version >= GR_GL_VER(3,0);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000142 }
143
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000144 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000145 fUnpackRowLengthSupport = true;
146 fUnpackFlipYSupport = false;
147 fPackRowLengthSupport = true;
148 fPackFlipYSupport = false;
149 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000150 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
151 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000152 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000153 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
154 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000155 fPackFlipYSupport =
156 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
157 }
158
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000159 fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000160 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
161
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000162 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org7a434a22013-08-21 14:01:56 +0000163 // The EXT version can apply to either GL or GLES.
164 fTexStorageSupport = version >= GR_GL_VER(4,2) ||
165 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
166 ctxInfo.hasExtension("GL_EXT_texture_storage");
167 } else {
168 // Qualcomm Adreno drivers appear to have issues with texture storage.
169 fTexStorageSupport = (version >= GR_GL_VER(3,0) &&
170 kQualcomm_GrGLVendor != ctxInfo.vendor()) ||
171 ctxInfo.hasExtension("GL_EXT_texture_storage");
172 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000173
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000174 // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support it if
175 // it doesn't have ARB_texture_rg extension.
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000176 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000177 if (ctxInfo.isMesa()) {
178 fTextureRedSupport = ctxInfo.hasExtension("GL_ARB_texture_rg");
179 } else {
180 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
181 ctxInfo.hasExtension("GL_ARB_texture_rg");
182 }
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000183 } else {
commit-bot@chromium.orgc5dffe42013-08-20 15:25:21 +0000184 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
185 ctxInfo.hasExtension("GL_EXT_texture_rg");
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000186 }
187
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000188 fImagingSupport = kGL_GrGLStandard == standard &&
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000189 ctxInfo.hasExtension("GL_ARB_imaging");
190
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000191 // ES 2 only guarantees RGBA/uchar + one other format/type combo for
192 // ReadPixels. The other format has to checked at run-time since it
193 // can change based on which render target is bound
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000194 fTwoFormatLimit = kGLES_GrGLStandard == standard;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000195
bsalomon@google.com706f6682012-10-23 14:53:55 +0000196 // Known issue on at least some Intel platforms:
197 // http://code.google.com/p/skia/issues/detail?id=946
198 if (kIntel_GrGLVendor != ctxInfo.vendor()) {
199 fFragCoordsConventionSupport = ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
200 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions");
201 }
202
bsalomon@google.com3012ded2013-02-22 16:44:04 +0000203 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
204 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
205 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
206 // limit this decision to specific GPU families rather than basing it on the vendor alone.
207 if (!GR_GL_MUST_USE_VBO &&
208 (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor())) {
bsalomon@google.com96966a52013-02-21 16:34:21 +0000209 fUseNonVBOVertexAndIndexDynamicData = true;
210 }
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000211
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000212 if ((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
skia.committer@gmail.coma9157722014-04-03 03:04:26 +0000213 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000214 ctxInfo.hasExtension("GL_ARB_invalidate_subdata")) {
215 fDiscardRenderTargetSupport = true;
216 fInvalidateFBType = kInvalidate_InvalidateFBType;
217 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
218 fDiscardRenderTargetSupport = true;
219 fInvalidateFBType = kDiscard_InvalidateFBType;
220 }
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000221
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000222 if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) {
223 fFullClearIsFree = true;
224 }
225
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000226 if (kGL_GrGLStandard == standard) {
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000227 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
228 ctxInfo.hasExtension("GL_ARB_vertex_array_object");
229 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000230 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
231 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000232 }
233
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000234 if (kGLES_GrGLStandard == standard) {
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000235 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
236 fFBFetchType = kEXT_FBFetchType;
237 } else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
238 fFBFetchType = kNV_FBFetchType;
239 }
240 }
241
commit-bot@chromium.org4362a382014-03-26 19:49:03 +0000242 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
243 fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
244
robertphillips@google.com6177e692013-02-28 20:16:25 +0000245 this->initFSAASupport(ctxInfo, gli);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000246 this->initStencilFormats(ctxInfo);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000247
248 /**************************************************************************
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000249 * GrDrawTargetCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000250 **************************************************************************/
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000251 if (kGL_GrGLStandard == standard) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000252 // we could also look for GL_ATI_separate_stencil extension or
253 // GL_EXT_stencil_two_side but they use different function signatures
254 // than GL2.0+ (and than each other).
255 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
256 // supported on GL 1.4 and higher or by extension
257 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
258 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
259 } else {
260 // ES 2 has two sided stencil and stencil wrap
261 fTwoSidedStencilSupport = true;
262 fStencilWrapOpsSupport = true;
263 }
264
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000265 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000266 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
267 // extension includes glMapBuffer.
268 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
269 fMapBufferFlags |= kSubset_MapFlag;
270 fMapBufferType = kMapBufferRange_MapBufferType;
271 } else {
272 fMapBufferType = kMapBuffer_MapBufferType;
273 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000274 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000275 // Unextended GLES2 doesn't have any buffer mapping.
276 fMapBufferFlags = kNone_MapBufferType;
277 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
278 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
279 fMapBufferType = kChromium_MapBufferType;
280 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
281 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
282 fMapBufferType = kMapBufferRange_MapBufferType;
283 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
284 fMapBufferFlags = kCanMap_MapFlag;
285 fMapBufferType = kMapBuffer_MapBufferType;
286 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000287 }
288
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000289 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000290 SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) ||
291 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two"));
292 fNPOTTextureTileSupport = true;
293 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000294 } else {
295 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000296 // ES3 has no limitations.
297 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
298 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000299 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
300 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
301 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
302 // to alllow arbitrary wrap modes, however.
303 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000304 }
305
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000306 fHWAALineSupport = (kGL_GrGLStandard == standard);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000307
308 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
309 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
310 // Our render targets are always created with textures as the color
311 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000312 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000313
commit-bot@chromium.orgf6696722014-04-25 06:21:30 +0000314 fPathRenderingSupport = ctxInfo.hasExtension("GL_NV_path_rendering") &&
315 ctxInfo.hasExtension("GL_EXT_direct_state_access");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000316
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000317 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
318
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000319 fDstReadInShaderSupport = kNone_FBFetchType != fFBFetchType;
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000320
321 // Disable scratch texture reuse on Mali and Adreno devices
322 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() &&
323 kQualcomm_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000324
bsalomon@google.combcce8922013-03-25 15:38:39 +0000325 // Enable supported shader-related caps
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000326 if (kGL_GrGLStandard == standard) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000327 fDualSourceBlendingSupport = ctxInfo.version() >= GR_GL_VER(3,3) ||
328 ctxInfo.hasExtension("GL_ARB_blend_func_extended");
329 fShaderDerivativeSupport = true;
330 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
331 fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3,2) &&
332 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
333 } else {
334 fShaderDerivativeSupport = ctxInfo.hasExtension("GL_OES_standard_derivatives");
335 }
336
bsalomon@google.com347c3822013-05-01 20:10:01 +0000337 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000338 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount);
339 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
340 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount);
341 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000342
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000343 this->initConfigTexturableTable(ctxInfo, gli);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000344 this->initConfigRenderableTable(ctxInfo);
commit-bot@chromium.orgf4e67e32014-04-30 01:26:04 +0000345
346 return true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000347}
348
349void GrGLCaps::initConfigRenderableTable(const GrGLContextInfo& ctxInfo) {
350
351 // OpenGL < 3.0
352 // no support for render targets unless the GL_ARB_framebuffer_object
353 // extension is supported (in which case we get ALPHA, RED, RG, RGB,
354 // RGBA (ALPHA8, RGBA4, RGBA8) for OpenGL > 1.1). Note that we
355 // probably don't get R8 in this case.
356
357 // OpenGL 3.0
358 // base color renderable: ALPHA, RED, RG, RGB, and RGBA
359 // sized derivatives: ALPHA8, R8, RGBA4, RGBA8
360
361 // >= OpenGL 3.1
362 // base color renderable: RED, RG, RGB, and RGBA
363 // sized derivatives: R8, RGBA4, RGBA8
364 // if the GL_ARB_compatibility extension is supported then we get back
365 // support for GL_ALPHA and ALPHA8
366
367 // GL_EXT_bgra adds BGRA render targets to any version
368
369 // ES 2.0
370 // color renderable: RGBA4, RGB5_A1, RGB565
371 // GL_EXT_texture_rg adds support for R8 as a color render target
372 // GL_OES_rgb8_rgba8 and/or GL_ARM_rgba8 adds support for RGBA8
373 // GL_EXT_texture_format_BGRA8888 and/or GL_APPLE_texture_format_BGRA8888 added BGRA support
374
375 // ES 3.0
376 // Same as ES 2.0 except R8 and RGBA8 are supported without extensions (the functions called
377 // below already account for this).
378
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000379 GrGLStandard standard = ctxInfo.standard();
380
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000381 enum {
382 kNo_MSAA = 0,
383 kYes_MSAA = 1,
384 };
385
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000386 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000387 // Post 3.0 we will get R8
388 // Prior to 3.0 we will get ALPHA8 (with GL_ARB_framebuffer_object)
389 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
390 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000391 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = true;
392 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000393 }
394 } else {
395 // On ES we can only hope for R8
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000396 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = fTextureRedSupport;
397 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = fTextureRedSupport;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000398 }
399
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000400 if (kGL_GrGLStandard != standard) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000401 // only available in ES
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000402 fConfigRenderSupport[kRGB_565_GrPixelConfig][kNo_MSAA] = true;
403 fConfigRenderSupport[kRGB_565_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000404 }
405
406 // we no longer support 444 as a render target
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000407 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kNo_MSAA] = false;
408 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kYes_MSAA] = false;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000409
410 if (this->fRGBA8RenderbufferSupport) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000411 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
commit-bot@chromium.orgda3d69c2013-10-28 15:09:13 +0000412 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000413 }
414
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000415 if (this->isConfigTexturable(kBGRA_8888_GrPixelConfig)) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000416 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kNo_MSAA] = true;
417 // The GL_EXT_texture_format_BGRA8888 extension does not add BGRA to the list of
418 // configs that are color-renderable and can be passed to glRenderBufferStorageMultisample.
commit-bot@chromium.org4256d242013-10-17 16:29:41 +0000419 // Chromium may have an extension to allow BGRA renderbuffers to work on desktop platforms.
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +0000420 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888")) {
commit-bot@chromium.org4256d242013-10-17 16:29:41 +0000421 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] = true;
422 } else {
423 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] =
424 !fBGRAIsInternalFormat || !this->usesMSAARenderBuffers();
425 }
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000426 }
427
428 // If we don't support MSAA then undo any places above where we set a config as renderable with
429 // msaa.
430 if (kNone_MSFBOType == fMSFBOType) {
431 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
432 fConfigRenderSupport[i][kYes_MSAA] = false;
433 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000434 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000435}
436
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000437void GrGLCaps::initConfigTexturableTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000438 GrGLStandard standard = ctxInfo.standard();
439 GrGLVersion version = ctxInfo.version();
440
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000441 // Base texture support
442 fConfigTextureSupport[kAlpha_8_GrPixelConfig] = true;
443 fConfigTextureSupport[kRGB_565_GrPixelConfig] = true;
444 fConfigTextureSupport[kRGBA_4444_GrPixelConfig] = true;
445 fConfigTextureSupport[kRGBA_8888_GrPixelConfig] = true;
446
447 // Check for 8-bit palette..
448 GrGLint numFormats;
449 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
450 if (numFormats) {
451 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
452 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
453 for (int i = 0; i < numFormats; ++i) {
454 if (GR_GL_PALETTE8_RGBA8 == formats[i]) {
455 fConfigTextureSupport[kIndex_8_GrPixelConfig] = true;
456 break;
457 }
458 }
459 }
460
461 // Check for BGRA
462 if (kGL_GrGLStandard == standard) {
463 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] =
464 version >= GR_GL_VER(1,2) || ctxInfo.hasExtension("GL_EXT_bgra");
465 } else {
466 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
467 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
468 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
469 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
470 fBGRAIsInternalFormat = true;
471 }
472 SkASSERT(fConfigTextureSupport[kBGRA_8888_GrPixelConfig] ||
473 kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig);
474 }
475
476 // Compressed texture support
477
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000478 // glCompressedTexImage2D is available on all OpenGL ES devices...
479 // however, it is only available on standard OpenGL after version 1.3
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000480 bool hasCompressTex2D = (kGL_GrGLStandard != standard || version >= GR_GL_VER(1, 3));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000481
482 // Check for ETC1
483 bool hasETC1 = false;
484
485 // First check version for support
486 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000487 hasETC1 = hasCompressTex2D &&
488 (version >= GR_GL_VER(4, 3) ||
489 ctxInfo.hasExtension("GL_ARB_ES3_compatibility"));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000490 } else {
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000491 hasETC1 = hasCompressTex2D &&
492 (version >= GR_GL_VER(3, 0) ||
493 ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") ||
494 // ETC2 is a superset of ETC1, so we can just check for that, too.
495 (ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") &&
496 ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture")));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000497 }
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000498 fConfigTextureSupport[kETC1_GrPixelConfig] = hasETC1;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000499
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000500 // Check for LATC under its various forms
501 LATCAlias alias = kLATC_LATCAlias;
502 bool hasLATC = hasCompressTex2D &&
503 (ctxInfo.hasExtension("GL_EXT_texture_compression_latc") ||
504 ctxInfo.hasExtension("GL_NV_texture_compression_latc"));
505
506 // Check for RGTC
507 if (!hasLATC) {
508 // If we're using OpenGL 3.0 or later, then we have RGTC, an identical compression format.
509 if (kGL_GrGLStandard == standard) {
510 hasLATC = version >= GR_GL_VER(3, 0);
511 }
512
513 if (!hasLATC) {
514 hasLATC =
515 ctxInfo.hasExtension("GL_EXT_texture_compression_rgtc") ||
516 ctxInfo.hasExtension("GL_ARB_texture_compression_rgtc");
517 }
518
519 if (hasLATC) {
520 alias = kRGTC_LATCAlias;
521 }
522 }
523
524 // Check for 3DC
525 if (!hasLATC) {
526 hasLATC = ctxInfo.hasExtension("GL_AMD_compressed_3DC_texture");
527 if (hasLATC) {
528 alias = k3DC_LATCAlias;
529 }
530 }
531
532 fConfigTextureSupport[kLATC_GrPixelConfig] = hasLATC;
533 fLATCAlias = alias;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000534}
535
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000536bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000537 GrGLenum format,
538 GrGLenum type) const {
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000539 if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) {
540 // ES 2 guarantees this format is supported
robertphillips@google.comeca2dfb2012-06-27 20:13:49 +0000541 return true;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000542 }
543
544 if (!fTwoFormatLimit) {
545 // not limited by ES 2's constraints
546 return true;
547 }
548
bsalomon@google.com548a4332012-07-11 19:45:22 +0000549 GrGLint otherFormat = GR_GL_RGBA;
550 GrGLint otherType = GR_GL_UNSIGNED_BYTE;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000551
552 // The other supported format/type combo supported for ReadPixels
553 // can change based on which render target is bound
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000554 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000555 GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT,
556 &otherFormat);
557
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000558 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000559 GR_GL_IMPLEMENTATION_COLOR_READ_TYPE,
560 &otherType);
561
bsalomon@google.com548a4332012-07-11 19:45:22 +0000562 return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000563}
564
robertphillips@google.com6177e692013-02-28 20:16:25 +0000565void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000566
567 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000568 if (kGL_GrGLStandard != ctxInfo.standard()) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000569 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
570 // ES3 driver bugs on at least one device with a tiled GPU (N10).
571 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
572 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
573 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
574 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
commit-bot@chromium.org92b78842014-01-16 20:49:46 +0000575 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000576 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType;
577 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
578 // chrome's extension is equivalent to the EXT msaa
579 // and fbo_blit extensions.
580 fMSFBOType = kDesktop_EXT_MSFBOType;
581 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
582 fMSFBOType = kES_Apple_MSFBOType;
583 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000584 } else {
585 if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
586 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000587 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000588 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
589 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000590 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000591 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000592 }
593}
594
595namespace {
596const GrGLuint kUnknownBitCount = GrGLStencilBuffer::kUnknownBitCount;
597}
598
599void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
600
601 // Build up list of legal stencil formats (though perhaps not supported on
602 // the particular gpu/driver) from most preferred to least.
603
604 // these consts are in order of most preferred to least preferred
605 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
606
607 static const StencilFormat
608 // internal Format stencil bits total bits packed?
609 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
610 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
611 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
612 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000613 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000614 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
615
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000616 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000617 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000618 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000619 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
620 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
621
622 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
623 // require FBO support we can expect these are legal formats and don't
624 // check. These also all support the unsized GL_STENCIL_INDEX.
625 fStencilFormats.push_back() = gS8;
626 fStencilFormats.push_back() = gS16;
627 if (supportsPackedDS) {
628 fStencilFormats.push_back() = gD24S8;
629 }
630 fStencilFormats.push_back() = gS4;
631 if (supportsPackedDS) {
632 fStencilFormats.push_back() = gDS;
633 }
634 } else {
635 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
636 // for other formats.
637 // ES doesn't support using the unsized format.
638
639 fStencilFormats.push_back() = gS8;
640 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +0000641 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
642 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000643 fStencilFormats.push_back() = gD24S8;
644 }
645 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
646 fStencilFormats.push_back() = gS4;
647 }
648 }
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000649 SkASSERT(0 == fStencilVerifiedColorConfigs.count());
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000650 fStencilVerifiedColorConfigs.push_back_n(fStencilFormats.count());
651}
652
653void GrGLCaps::markColorConfigAndStencilFormatAsVerified(
654 GrPixelConfig config,
655 const GrGLStencilBuffer::Format& format) {
656#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
657 return;
658#endif
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000659 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
660 SkASSERT(fStencilFormats.count() == fStencilVerifiedColorConfigs.count());
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000661 int count = fStencilFormats.count();
662 // we expect a really small number of possible formats so linear search
663 // should be OK
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000664 SkASSERT(count < 16);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000665 for (int i = 0; i < count; ++i) {
666 if (format.fInternalFormat ==
667 fStencilFormats[i].fInternalFormat) {
668 fStencilVerifiedColorConfigs[i].markVerified(config);
669 return;
670 }
671 }
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000672 SkFAIL("Why are we seeing a stencil format that "
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000673 "GrGLCaps doesn't know about.");
674}
675
676bool GrGLCaps::isColorConfigAndStencilFormatVerified(
677 GrPixelConfig config,
678 const GrGLStencilBuffer::Format& format) const {
679#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
680 return false;
681#endif
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000682 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000683 int count = fStencilFormats.count();
684 // we expect a really small number of possible formats so linear search
685 // should be OK
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000686 SkASSERT(count < 16);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000687 for (int i = 0; i < count; ++i) {
688 if (format.fInternalFormat ==
689 fStencilFormats[i].fInternalFormat) {
690 return fStencilVerifiedColorConfigs[i].isVerified(config);
691 }
692 }
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000693 SkFAIL("Why are we seeing a stencil format that "
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000694 "GLCaps doesn't know about.");
695 return false;
696}
697
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000698SkString GrGLCaps::dump() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000699
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000700 SkString r = INHERITED::dump();
bsalomon@google.combcce8922013-03-25 15:38:39 +0000701
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000702 r.appendf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000703 for (int i = 0; i < fStencilFormats.count(); ++i) {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000704 r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000705 i,
706 fStencilFormats[i].fStencilBits,
707 fStencilFormats[i].fTotalBits);
708 }
709
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000710 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000711 "None",
712 "ARB",
713 "EXT",
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000714 "ES 3.0",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000715 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +0000716 "IMG MS To Texture",
717 "EXT MS To Texture",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000718 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000719 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
720 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
721 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000722 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType);
723 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType);
724 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType);
725 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000726 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000727
728 static const char* kFBFetchTypeStr[] = {
729 "None",
730 "EXT",
731 "NV",
732 };
733 GR_STATIC_ASSERT(0 == kNone_FBFetchType);
734 GR_STATIC_ASSERT(1 == kEXT_FBFetchType);
735 GR_STATIC_ASSERT(2 == kNV_FBFetchType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000736 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kFBFetchTypeStr) == kLast_FBFetchType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000737
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000738 static const char* kInvalidateFBTypeStr[] = {
739 "None",
740 "Discard",
741 "Invalidate",
742 };
743 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
744 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
745 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
746 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000747
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000748 static const char* kMapBufferTypeStr[] = {
749 "None",
750 "MapBuffer",
751 "MapBufferRange",
752 "Chromium",
753 };
754 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
755 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
756 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
757 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
758 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
759
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000760 r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000761 r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
762 r.appendf("FB Fetch Type: %s\n", kFBFetchTypeStr[fFBFetchType]);
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000763 r.appendf("Invalidate FB Type: %s\n", kInvalidateFBTypeStr[fInvalidateFBType]);
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000764 r.appendf("Map Buffer Type: %s\n", kMapBufferTypeStr[fMapBufferType]);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000765 r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
766 r.appendf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits);
commit-bot@chromium.org0a6fe712014-04-23 19:26:26 +0000767 if (!fIsCoreProfile) {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000768 r.appendf("Max Fixed Function Texture Coords: %d\n", fMaxFixedFunctionTextureCoords);
commit-bot@chromium.org3628ad92013-08-30 19:43:47 +0000769 }
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000770 r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
771 r.appendf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000772 r.appendf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO"));
773 r.appendf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO"));
774 r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
775 r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
776 r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
777 r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +0000778
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000779 r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
780 r.appendf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
781 r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
782 r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
783 r.appendf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO"));
784 r.appendf("Fragment coord conventions support: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +0000785 (fFragCoordsConventionSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000786 r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
787 r.appendf("Use non-VBO for dynamic data: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +0000788 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000789 r.appendf("Full screen clear is free: %s\n", (fFullClearIsFree ? "YES" : "NO"));
commit-bot@chromium.org4362a382014-03-26 19:49:03 +0000790 r.appendf("Drops tile on zero divide: %s\n", (fDropsTileOnZeroDivide ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000791 return r;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000792}