blob: 382bfba68daf67831f9f120be0c358e5b2f0a54b [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
bsalomon@google.combcce8922013-03-25 15:38:39 +000014SK_DEFINE_INST_COUNT(GrGLCaps)
15
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000016GrGLCaps::GrGLCaps() {
17 this->reset();
18}
19
20void GrGLCaps::reset() {
bsalomon@google.combcce8922013-03-25 15:38:39 +000021 INHERITED::reset();
22
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000023 fVerifiedColorConfigs.reset();
24 fStencilFormats.reset();
25 fStencilVerifiedColorConfigs.reset();
26 fMSFBOType = kNone_MSFBOType;
bsalomon@google.comc9668ec2012-04-11 18:16:41 +000027 fCoverageAAType = kNone_CoverageAAType;
bsalomon@google.com6b0cf022013-05-03 13:35:14 +000028 fFBFetchType = kNone_FBFetchType;
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;
34 fBGRAFormatSupport = false;
35 fBGRAIsInternalFormat = false;
36 fTextureSwizzleSupport = false;
37 fUnpackRowLengthSupport = false;
38 fUnpackFlipYSupport = false;
39 fPackRowLengthSupport = false;
40 fPackFlipYSupport = false;
41 fTextureUsageSupport = false;
42 fTexStorageSupport = false;
robertphillips@google.com443e5a52012-04-30 20:01:21 +000043 fTextureRedSupport = false;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000044 fImagingSupport = false;
robertphillips@google.com1d89c932012-06-27 19:31:41 +000045 fTwoFormatLimit = false;
bsalomon@google.com706f6682012-10-23 14:53:55 +000046 fFragCoordsConventionSupport = false;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000047 fVertexArrayObjectSupport = false;
bsalomon@google.com96966a52013-02-21 16:34:21 +000048 fUseNonVBOVertexAndIndexDynamicData = false;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000049 fIsCoreProfile = false;
commit-bot@chromium.org3628ad92013-08-30 19:43:47 +000050 fFixedFunctionSupport = false;
robertphillips@google.coma6ffb582013-04-29 16:50:17 +000051 fDiscardFBSupport = false;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000052}
53
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000054GrGLCaps::GrGLCaps(const GrGLCaps& caps) : GrDrawTargetCaps() {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000055 *this = caps;
56}
57
58GrGLCaps& GrGLCaps::operator = (const GrGLCaps& caps) {
bsalomon@google.combcce8922013-03-25 15:38:39 +000059 INHERITED::operator=(caps);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000060 fVerifiedColorConfigs = caps.fVerifiedColorConfigs;
61 fStencilFormats = caps.fStencilFormats;
62 fStencilVerifiedColorConfigs = caps.fStencilVerifiedColorConfigs;
63 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.comc9668ec2012-04-11 18:16:41 +000068 fCoverageAAType = caps.fCoverageAAType;
69 fMSAACoverageModes = caps.fMSAACoverageModes;
bsalomon@google.com6b0cf022013-05-03 13:35:14 +000070 fFBFetchType = caps.fFBFetchType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000071 fRGBA8RenderbufferSupport = caps.fRGBA8RenderbufferSupport;
72 fBGRAFormatSupport = caps.fBGRAFormatSupport;
73 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;
commit-bot@chromium.org3628ad92013-08-30 19:43:47 +000088 fFixedFunctionSupport = caps.fFixedFunctionSupport;
robertphillips@google.coma6ffb582013-04-29 16:50:17 +000089 fDiscardFBSupport = caps.fDiscardFBSupport;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000090
91 return *this;
92}
93
robertphillips@google.com6177e692013-02-28 20:16:25 +000094void GrGLCaps::init(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000095
96 this->reset();
97 if (!ctxInfo.isInitialized()) {
98 return;
99 }
100
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000101 GrGLBinding binding = ctxInfo.binding();
102 GrGLVersion version = ctxInfo.version();
103
bsalomon@google.combcce8922013-03-25 15:38:39 +0000104 /**************************************************************************
105 * Caps specific to GrGLCaps
106 **************************************************************************/
107
bsalomon@google.com791816a2013-08-15 18:54:39 +0000108 if (kES_GrGLBinding == binding) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000109 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
110 &fMaxFragmentUniformVectors);
111 } else {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000112 SkASSERT(kDesktop_GrGLBinding == binding);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000113 GrGLint max;
114 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
115 fMaxFragmentUniformVectors = max / 4;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +0000116 if (version >= GR_GL_VER(3, 2)) {
117 GrGLint profileMask;
118 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
119 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
120 }
121 if (!fIsCoreProfile) {
commit-bot@chromium.org3628ad92013-08-30 19:43:47 +0000122 fFixedFunctionSupport = true;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +0000123 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_COORDS, &fMaxFixedFunctionTextureCoords);
124 // Sanity check
125 SkASSERT(fMaxFixedFunctionTextureCoords > 0 && fMaxFixedFunctionTextureCoords < 128);
126 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000127 }
bsalomon@google.com60da4172012-06-01 19:25:00 +0000128 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000129 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &fMaxFragmentTextureUnits);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000130
131 if (kDesktop_GrGLBinding == binding) {
132 fRGBA8RenderbufferSupport = true;
133 } else {
commit-bot@chromium.orgc5dffe42013-08-20 15:25:21 +0000134 fRGBA8RenderbufferSupport = version >= GR_GL_VER(3,0) ||
135 ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000136 ctxInfo.hasExtension("GL_ARM_rgba8");
137 }
138
139 if (kDesktop_GrGLBinding == binding) {
140 fBGRAFormatSupport = version >= GR_GL_VER(1,2) ||
141 ctxInfo.hasExtension("GL_EXT_bgra");
142 } else {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000143 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
144 fBGRAFormatSupport = true;
145 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
146 fBGRAFormatSupport = true;
147 fBGRAIsInternalFormat = true;
148 }
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000149 SkASSERT(fBGRAFormatSupport ||
bsalomon@google.com0342a852012-08-20 19:22:38 +0000150 kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000151 }
152
153 if (kDesktop_GrGLBinding == binding) {
154 fTextureSwizzleSupport = version >= GR_GL_VER(3,3) ||
155 ctxInfo.hasExtension("GL_ARB_texture_swizzle");
156 } else {
commit-bot@chromium.org6364b5e2013-08-20 20:22:52 +0000157 fTextureSwizzleSupport = version >= GR_GL_VER(3,0);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000158 }
159
160 if (kDesktop_GrGLBinding == binding) {
161 fUnpackRowLengthSupport = true;
162 fUnpackFlipYSupport = false;
163 fPackRowLengthSupport = true;
164 fPackFlipYSupport = false;
165 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000166 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
167 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000168 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000169 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
170 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000171 fPackFlipYSupport =
172 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
173 }
174
bsalomon@google.com791816a2013-08-15 18:54:39 +0000175 fTextureUsageSupport = (kES_GrGLBinding == binding) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000176 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
177
commit-bot@chromium.org7a434a22013-08-21 14:01:56 +0000178 if (kDesktop_GrGLBinding == binding) {
179 // The EXT version can apply to either GL or GLES.
180 fTexStorageSupport = version >= GR_GL_VER(4,2) ||
181 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
182 ctxInfo.hasExtension("GL_EXT_texture_storage");
183 } else {
184 // Qualcomm Adreno drivers appear to have issues with texture storage.
185 fTexStorageSupport = (version >= GR_GL_VER(3,0) &&
186 kQualcomm_GrGLVendor != ctxInfo.vendor()) ||
187 ctxInfo.hasExtension("GL_EXT_texture_storage");
188 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000189
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000190 // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support it if
191 // it doesn't have ARB_texture_rg extension.
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000192 if (kDesktop_GrGLBinding == binding) {
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000193 if (ctxInfo.isMesa()) {
194 fTextureRedSupport = ctxInfo.hasExtension("GL_ARB_texture_rg");
195 } else {
196 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
197 ctxInfo.hasExtension("GL_ARB_texture_rg");
198 }
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000199 } else {
commit-bot@chromium.orgc5dffe42013-08-20 15:25:21 +0000200 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
201 ctxInfo.hasExtension("GL_EXT_texture_rg");
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000202 }
203
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000204 fImagingSupport = kDesktop_GrGLBinding == binding &&
205 ctxInfo.hasExtension("GL_ARB_imaging");
206
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000207 // ES 2 only guarantees RGBA/uchar + one other format/type combo for
208 // ReadPixels. The other format has to checked at run-time since it
209 // can change based on which render target is bound
bsalomon@google.com791816a2013-08-15 18:54:39 +0000210 fTwoFormatLimit = kES_GrGLBinding == binding;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000211
bsalomon@google.com706f6682012-10-23 14:53:55 +0000212 // Known issue on at least some Intel platforms:
213 // http://code.google.com/p/skia/issues/detail?id=946
214 if (kIntel_GrGLVendor != ctxInfo.vendor()) {
215 fFragCoordsConventionSupport = ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
216 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions");
217 }
218
bsalomon@google.com3012ded2013-02-22 16:44:04 +0000219 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
220 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
221 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
222 // limit this decision to specific GPU families rather than basing it on the vendor alone.
223 if (!GR_GL_MUST_USE_VBO &&
224 (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor())) {
bsalomon@google.com96966a52013-02-21 16:34:21 +0000225 fUseNonVBOVertexAndIndexDynamicData = true;
226 }
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000227
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000228 fDiscardFBSupport = ctxInfo.hasExtension("GL_EXT_discard_framebuffer");
229
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000230 if (kDesktop_GrGLBinding == binding) {
231 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
232 ctxInfo.hasExtension("GL_ARB_vertex_array_object");
233 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000234 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
235 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000236 }
237
bsalomon@google.com791816a2013-08-15 18:54:39 +0000238 if (kES_GrGLBinding == binding) {
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000239 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
240 fFBFetchType = kEXT_FBFetchType;
241 } else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
242 fFBFetchType = kNV_FBFetchType;
243 }
244 }
245
robertphillips@google.com6177e692013-02-28 20:16:25 +0000246 this->initFSAASupport(ctxInfo, gli);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000247 this->initStencilFormats(ctxInfo);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000248
249 /**************************************************************************
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000250 * GrDrawTargetCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000251 **************************************************************************/
bsalomon@google.combcce8922013-03-25 15:38:39 +0000252 GrGLint numFormats;
253 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
bungeman@google.com71033442013-05-01 14:21:20 +0000254 if (numFormats) {
255 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
256 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
257 for (int i = 0; i < numFormats; ++i) {
258 if (formats[i] == GR_GL_PALETTE8_RGBA8) {
259 f8BitPaletteSupport = true;
260 break;
261 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000262 }
263 }
264
265 if (kDesktop_GrGLBinding == binding) {
266 // we could also look for GL_ATI_separate_stencil extension or
267 // GL_EXT_stencil_two_side but they use different function signatures
268 // than GL2.0+ (and than each other).
269 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
270 // supported on GL 1.4 and higher or by extension
271 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
272 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
273 } else {
274 // ES 2 has two sided stencil and stencil wrap
275 fTwoSidedStencilSupport = true;
276 fStencilWrapOpsSupport = true;
277 }
278
279 if (kDesktop_GrGLBinding == binding) {
280 fBufferLockSupport = true; // we require VBO support and the desktop VBO extension includes
281 // glMapBuffer.
282 } else {
283 fBufferLockSupport = ctxInfo.hasExtension("GL_OES_mapbuffer");
284 }
285
286 if (kDesktop_GrGLBinding == binding) {
287 if (ctxInfo.version() >= GR_GL_VER(2,0) ||
288 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two")) {
289 fNPOTTextureTileSupport = true;
290 } else {
291 fNPOTTextureTileSupport = false;
292 }
293 } else {
294 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000295 // ES3 has no limitations.
296 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
297 ctxInfo.hasExtension("GL_OES_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000298 }
299
300 fHWAALineSupport = (kDesktop_GrGLBinding == binding);
301
302 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
303 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
304 // Our render targets are always created with textures as the color
305 // attachment, hence this min:
306 fMaxRenderTargetSize = GrMin(fMaxTextureSize, fMaxRenderTargetSize);
307
308 fPathStencilingSupport = GR_GL_USE_NV_PATH_RENDERING &&
309 ctxInfo.hasExtension("GL_NV_path_rendering");
310
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000311 fDstReadInShaderSupport = kNone_FBFetchType != fFBFetchType;
312
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000313#if 0
314 // This has to be temporarily disabled. On Android it causes the texture
315 // usage to become front loaded and the OS kills the process. It can
316 // be re-enabled once the more dynamic (ref-driven) cache clearing
317 // system is in place.
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000318 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor();
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000319#else
320 fReuseScratchTextures = true;
321#endif
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000322
bsalomon@google.combcce8922013-03-25 15:38:39 +0000323 // Enable supported shader-related caps
324 if (kDesktop_GrGLBinding == binding) {
325 fDualSourceBlendingSupport = ctxInfo.version() >= GR_GL_VER(3,3) ||
326 ctxInfo.hasExtension("GL_ARB_blend_func_extended");
327 fShaderDerivativeSupport = true;
328 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
329 fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3,2) &&
330 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
331 } else {
332 fShaderDerivativeSupport = ctxInfo.hasExtension("GL_OES_standard_derivatives");
333 }
334
bsalomon@google.com347c3822013-05-01 20:10:01 +0000335 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000336 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount);
337 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
338 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount);
339 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000340}
341
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000342bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000343 GrGLenum format,
344 GrGLenum type) const {
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000345 if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) {
346 // ES 2 guarantees this format is supported
robertphillips@google.comeca2dfb2012-06-27 20:13:49 +0000347 return true;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000348 }
349
350 if (!fTwoFormatLimit) {
351 // not limited by ES 2's constraints
352 return true;
353 }
354
bsalomon@google.com548a4332012-07-11 19:45:22 +0000355 GrGLint otherFormat = GR_GL_RGBA;
356 GrGLint otherType = GR_GL_UNSIGNED_BYTE;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000357
358 // The other supported format/type combo supported for ReadPixels
359 // can change based on which render target is bound
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000360 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000361 GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT,
362 &otherFormat);
363
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000364 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000365 GR_GL_IMPLEMENTATION_COLOR_READ_TYPE,
366 &otherType);
367
bsalomon@google.com548a4332012-07-11 19:45:22 +0000368 return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000369}
370
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000371namespace {
bsalomon@google.com20f7f172013-05-17 19:05:03 +0000372bool cov_mode_less(const GrGLCaps::MSAACoverageMode& left,
373 const GrGLCaps::MSAACoverageMode& right) {
374 if (left.fCoverageSampleCnt < right.fCoverageSampleCnt) {
375 return true;
376 } else if (right.fCoverageSampleCnt < left.fCoverageSampleCnt) {
377 return false;
378 } else if (left.fColorSampleCnt < right.fColorSampleCnt) {
379 return true;
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000380 }
bsalomon@google.com20f7f172013-05-17 19:05:03 +0000381 return false;
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000382}
383}
384
robertphillips@google.com6177e692013-02-28 20:16:25 +0000385void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000386
387 fMSFBOType = kNone_MSFBOType;
388 if (kDesktop_GrGLBinding != ctxInfo.binding()) {
389 if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
390 // chrome's extension is equivalent to the EXT msaa
391 // and fbo_blit extensions.
bsalomon@google.com347c3822013-05-01 20:10:01 +0000392 fMSFBOType = kDesktop_EXT_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000393 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000394 fMSFBOType = kES_Apple_MSFBOType;
395 } else if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
396 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
bsalomon@google.comf3a60c02013-03-19 19:06:09 +0000397 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000398 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000399 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000400 } else {
401 if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
402 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000403 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000404 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
405 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000406 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000407 }
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000408 // TODO: We could populate fMSAACoverageModes using GetInternalformativ
409 // on GL 4.2+. It's format-specific, though. See also
410 // http://code.google.com/p/skia/issues/detail?id=470 about using actual
411 // rather than requested sample counts in cache key.
412 if (ctxInfo.hasExtension("GL_NV_framebuffer_multisample_coverage")) {
413 fCoverageAAType = kNVDesktop_CoverageAAType;
414 GrGLint count;
robertphillips@google.com6177e692013-02-28 20:16:25 +0000415 GR_GL_GetIntegerv(gli,
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000416 GR_GL_MAX_MULTISAMPLE_COVERAGE_MODES,
417 &count);
418 fMSAACoverageModes.setCount(count);
robertphillips@google.com6177e692013-02-28 20:16:25 +0000419 GR_GL_GetIntegerv(gli,
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000420 GR_GL_MULTISAMPLE_COVERAGE_MODES,
421 (int*)&fMSAACoverageModes[0]);
422 // The NV driver seems to return the modes already sorted but the
423 // spec doesn't require this. So we sort.
bsalomon@google.com20f7f172013-05-17 19:05:03 +0000424 typedef SkTLessFunctionToFunctorAdaptor<MSAACoverageMode, cov_mode_less> SortFunctor;
425 SortFunctor sortFunctor;
426 SkTQSort<MSAACoverageMode, SortFunctor>(fMSAACoverageModes.begin(),
427 fMSAACoverageModes.end() - 1,
428 sortFunctor);
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000429 }
430 }
431}
432
bsalomon@google.com8a70eef2013-03-19 13:58:55 +0000433const GrGLCaps::MSAACoverageMode& GrGLCaps::getMSAACoverageMode(int desiredSampleCount) const {
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000434 static const MSAACoverageMode kNoneMode = {0, 0};
435 if (0 == fMSAACoverageModes.count()) {
436 return kNoneMode;
437 } else {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000438 SkASSERT(kNone_CoverageAAType != fCoverageAAType);
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000439 int max = (fMSAACoverageModes.end() - 1)->fCoverageSampleCnt;
440 desiredSampleCount = GrMin(desiredSampleCount, max);
441 MSAACoverageMode desiredMode = {desiredSampleCount, 0};
bsalomon@google.com20f7f172013-05-17 19:05:03 +0000442 int idx = SkTSearch<const MSAACoverageMode, cov_mode_less>(&fMSAACoverageModes[0],
443 fMSAACoverageModes.count(),
444 desiredMode,
445 sizeof(MSAACoverageMode));
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000446 if (idx < 0) {
447 idx = ~idx;
448 }
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000449 SkASSERT(idx >= 0 && idx < fMSAACoverageModes.count());
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000450 return fMSAACoverageModes[idx];
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000451 }
452}
453
454namespace {
455const GrGLuint kUnknownBitCount = GrGLStencilBuffer::kUnknownBitCount;
456}
457
458void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
459
460 // Build up list of legal stencil formats (though perhaps not supported on
461 // the particular gpu/driver) from most preferred to least.
462
463 // these consts are in order of most preferred to least preferred
464 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
465
466 static const StencilFormat
467 // internal Format stencil bits total bits packed?
468 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
469 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
470 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
471 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000472 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000473 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
474
475 if (kDesktop_GrGLBinding == ctxInfo.binding()) {
476 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000477 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000478 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
479 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
480
481 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
482 // require FBO support we can expect these are legal formats and don't
483 // check. These also all support the unsized GL_STENCIL_INDEX.
484 fStencilFormats.push_back() = gS8;
485 fStencilFormats.push_back() = gS16;
486 if (supportsPackedDS) {
487 fStencilFormats.push_back() = gD24S8;
488 }
489 fStencilFormats.push_back() = gS4;
490 if (supportsPackedDS) {
491 fStencilFormats.push_back() = gDS;
492 }
493 } else {
494 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
495 // for other formats.
496 // ES doesn't support using the unsized format.
497
498 fStencilFormats.push_back() = gS8;
499 //fStencilFormats.push_back() = gS16;
500 if (ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
501 fStencilFormats.push_back() = gD24S8;
502 }
503 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
504 fStencilFormats.push_back() = gS4;
505 }
506 }
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000507 SkASSERT(0 == fStencilVerifiedColorConfigs.count());
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000508 fStencilVerifiedColorConfigs.push_back_n(fStencilFormats.count());
509}
510
511void GrGLCaps::markColorConfigAndStencilFormatAsVerified(
512 GrPixelConfig config,
513 const GrGLStencilBuffer::Format& format) {
514#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
515 return;
516#endif
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000517 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
518 SkASSERT(fStencilFormats.count() == fStencilVerifiedColorConfigs.count());
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000519 int count = fStencilFormats.count();
520 // we expect a really small number of possible formats so linear search
521 // should be OK
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000522 SkASSERT(count < 16);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000523 for (int i = 0; i < count; ++i) {
524 if (format.fInternalFormat ==
525 fStencilFormats[i].fInternalFormat) {
526 fStencilVerifiedColorConfigs[i].markVerified(config);
527 return;
528 }
529 }
530 GrCrash("Why are we seeing a stencil format that "
531 "GrGLCaps doesn't know about.");
532}
533
534bool GrGLCaps::isColorConfigAndStencilFormatVerified(
535 GrPixelConfig config,
536 const GrGLStencilBuffer::Format& format) const {
537#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
538 return false;
539#endif
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000540 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000541 int count = fStencilFormats.count();
542 // we expect a really small number of possible formats so linear search
543 // should be OK
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000544 SkASSERT(count < 16);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000545 for (int i = 0; i < count; ++i) {
546 if (format.fInternalFormat ==
547 fStencilFormats[i].fInternalFormat) {
548 return fStencilVerifiedColorConfigs[i].isVerified(config);
549 }
550 }
551 GrCrash("Why are we seeing a stencil format that "
552 "GLCaps doesn't know about.");
553 return false;
554}
555
556void GrGLCaps::print() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000557
558 INHERITED::print();
559
560 GrPrintf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000561 for (int i = 0; i < fStencilFormats.count(); ++i) {
562 GrPrintf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
563 i,
564 fStencilFormats[i].fStencilBits,
565 fStencilFormats[i].fTotalBits);
566 }
567
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000568 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000569 "None",
570 "ARB",
571 "EXT",
572 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +0000573 "IMG MS To Texture",
574 "EXT MS To Texture",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000575 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000576 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
577 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
578 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
579 GR_STATIC_ASSERT(3 == kES_Apple_MSFBOType);
580 GR_STATIC_ASSERT(4 == kES_IMG_MsToTexture_MSFBOType);
581 GR_STATIC_ASSERT(5 == kES_EXT_MsToTexture_MSFBOType);
582 GR_STATIC_ASSERT(GR_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
583
584 static const char* kFBFetchTypeStr[] = {
585 "None",
586 "EXT",
587 "NV",
588 };
589 GR_STATIC_ASSERT(0 == kNone_FBFetchType);
590 GR_STATIC_ASSERT(1 == kEXT_FBFetchType);
591 GR_STATIC_ASSERT(2 == kNV_FBFetchType);
592 GR_STATIC_ASSERT(GR_ARRAY_COUNT(kFBFetchTypeStr) == kLast_FBFetchType + 1);
593
594
commit-bot@chromium.org3628ad92013-08-30 19:43:47 +0000595 GrPrintf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
596 GrPrintf("Fixed Function Support: %s\n", (fFixedFunctionSupport ? "YES" : "NO"));
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000597 GrPrintf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
598 GrPrintf("FB Fetch Type: %s\n", kFBFetchTypeStr[fFBFetchType]);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000599 GrPrintf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
commit-bot@chromium.org3628ad92013-08-30 19:43:47 +0000600 GrPrintf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits);
601 if (fFixedFunctionSupport) {
602 GrPrintf("Max Fixed Function Texture Coords: %d\n", fMaxFixedFunctionTextureCoords);
603 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000604 GrPrintf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
605 GrPrintf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO"));
606 GrPrintf("BGRA support: %s\n", (fBGRAFormatSupport ? "YES": "NO"));
607 GrPrintf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO"));
608 GrPrintf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO"));
609 GrPrintf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
610 GrPrintf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
611 GrPrintf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
612 GrPrintf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
613
614 GrPrintf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
615 GrPrintf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
616 GrPrintf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
617 GrPrintf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000618 GrPrintf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +0000619 GrPrintf("Fragment coord conventions support: %s\n",
620 (fFragCoordsConventionSupport ? "YES": "NO"));
621 GrPrintf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
622 GrPrintf("Use non-VBO for dynamic data: %s\n",
623 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000624 GrPrintf("Discard FrameBuffer support: %s\n", (fDiscardFBSupport ? "YES" : "NO"));
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000625}