blob: b4ee4a640d6cada2215d66dd847c303ee451962e [file] [log] [blame]
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8
9#include "GrGLCaps.h"
joshualittb4384b92014-10-21 12:53:15 -070010
robertphillips@google.com6177e692013-02-28 20:16:25 +000011#include "GrGLContext.h"
bsalomon@google.comc9668ec2012-04-11 18:16:41 +000012#include "SkTSearch.h"
bsalomon@google.com20f7f172013-05-17 19:05:03 +000013#include "SkTSort.h"
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000014
15GrGLCaps::GrGLCaps() {
16 this->reset();
17}
18
19void GrGLCaps::reset() {
bsalomon@google.combcce8922013-03-25 15:38:39 +000020 INHERITED::reset();
21
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000022 fVerifiedColorConfigs.reset();
23 fStencilFormats.reset();
24 fStencilVerifiedColorConfigs.reset();
25 fMSFBOType = kNone_MSFBOType;
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;
joshualitt58162332014-08-01 06:44:53 -070051 fFBFetchSupport = false;
52 fFBFetchColorName = NULL;
53 fFBFetchExtensionString = NULL;
piotaixre4b23142014-10-02 10:57:53 -070054
55 fReadPixelsSupportedCache.reset();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000056}
57
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000058GrGLCaps::GrGLCaps(const GrGLCaps& caps) : GrDrawTargetCaps() {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000059 *this = caps;
60}
61
commit-bot@chromium.orgbeb8b3a2014-04-15 15:37:51 +000062GrGLCaps& GrGLCaps::operator= (const GrGLCaps& caps) {
bsalomon@google.combcce8922013-03-25 15:38:39 +000063 INHERITED::operator=(caps);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000064 fVerifiedColorConfigs = caps.fVerifiedColorConfigs;
65 fStencilFormats = caps.fStencilFormats;
66 fStencilVerifiedColorConfigs = caps.fStencilVerifiedColorConfigs;
krajcevski3217c4a2014-06-09 09:10:04 -070067 fLATCAlias = caps.fLATCAlias;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000068 fMaxFragmentUniformVectors = caps.fMaxFragmentUniformVectors;
bsalomon@google.com60da4172012-06-01 19:25:00 +000069 fMaxVertexAttributes = caps.fMaxVertexAttributes;
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +000070 fMaxFragmentTextureUnits = caps.fMaxFragmentTextureUnits;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +000071 fMaxFixedFunctionTextureCoords = caps.fMaxFixedFunctionTextureCoords;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000072 fMSFBOType = caps.fMSFBOType;
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +000073 fInvalidateFBType = caps.fInvalidateFBType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000074 fMapBufferType = caps.fMapBufferType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000075 fRGBA8RenderbufferSupport = caps.fRGBA8RenderbufferSupport;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000076 fBGRAIsInternalFormat = caps.fBGRAIsInternalFormat;
77 fTextureSwizzleSupport = caps.fTextureSwizzleSupport;
78 fUnpackRowLengthSupport = caps.fUnpackRowLengthSupport;
79 fUnpackFlipYSupport = caps.fUnpackFlipYSupport;
80 fPackRowLengthSupport = caps.fPackRowLengthSupport;
81 fPackFlipYSupport = caps.fPackFlipYSupport;
82 fTextureUsageSupport = caps.fTextureUsageSupport;
83 fTexStorageSupport = caps.fTexStorageSupport;
robertphillips@google.com443e5a52012-04-30 20:01:21 +000084 fTextureRedSupport = caps.fTextureRedSupport;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000085 fImagingSupport = caps.fImagingSupport;
robertphillips@google.com1d89c932012-06-27 19:31:41 +000086 fTwoFormatLimit = caps.fTwoFormatLimit;
bsalomon@google.com706f6682012-10-23 14:53:55 +000087 fFragCoordsConventionSupport = caps.fFragCoordsConventionSupport;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000088 fVertexArrayObjectSupport = caps.fVertexArrayObjectSupport;
bsalomon@google.com96966a52013-02-21 16:34:21 +000089 fUseNonVBOVertexAndIndexDynamicData = caps.fUseNonVBOVertexAndIndexDynamicData;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000090 fIsCoreProfile = caps.fIsCoreProfile;
robertphillips@google.com56ce48a2013-10-31 21:44:25 +000091 fFullClearIsFree = caps.fFullClearIsFree;
commit-bot@chromium.org4362a382014-03-26 19:49:03 +000092 fDropsTileOnZeroDivide = caps.fDropsTileOnZeroDivide;
joshualitt58162332014-08-01 06:44:53 -070093 fFBFetchSupport = caps.fFBFetchSupport;
94 fFBFetchColorName = caps.fFBFetchColorName;
95 fFBFetchExtensionString = caps.fFBFetchExtensionString;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000096
97 return *this;
98}
99
commit-bot@chromium.orgf4e67e32014-04-30 01:26:04 +0000100bool GrGLCaps::init(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000101
102 this->reset();
103 if (!ctxInfo.isInitialized()) {
commit-bot@chromium.orgf4e67e32014-04-30 01:26:04 +0000104 return false;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000105 }
106
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000107 GrGLStandard standard = ctxInfo.standard();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000108 GrGLVersion version = ctxInfo.version();
109
bsalomon@google.combcce8922013-03-25 15:38:39 +0000110 /**************************************************************************
111 * Caps specific to GrGLCaps
112 **************************************************************************/
113
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000114 if (kGLES_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000115 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
116 &fMaxFragmentUniformVectors);
117 } else {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000118 SkASSERT(kGL_GrGLStandard == standard);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000119 GrGLint max;
120 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
121 fMaxFragmentUniformVectors = max / 4;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +0000122 if (version >= GR_GL_VER(3, 2)) {
123 GrGLint profileMask;
124 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
125 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
126 }
127 if (!fIsCoreProfile) {
128 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_COORDS, &fMaxFixedFunctionTextureCoords);
129 // Sanity check
130 SkASSERT(fMaxFixedFunctionTextureCoords > 0 && fMaxFixedFunctionTextureCoords < 128);
131 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000132 }
bsalomon@google.com60da4172012-06-01 19:25:00 +0000133 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000134 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &fMaxFragmentTextureUnits);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000135
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000136 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000137 fRGBA8RenderbufferSupport = true;
138 } else {
commit-bot@chromium.orgc5dffe42013-08-20 15:25:21 +0000139 fRGBA8RenderbufferSupport = version >= GR_GL_VER(3,0) ||
140 ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000141 ctxInfo.hasExtension("GL_ARM_rgba8");
142 }
143
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000144 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000145 fTextureSwizzleSupport = version >= GR_GL_VER(3,3) ||
146 ctxInfo.hasExtension("GL_ARB_texture_swizzle");
147 } else {
commit-bot@chromium.org6364b5e2013-08-20 20:22:52 +0000148 fTextureSwizzleSupport = version >= GR_GL_VER(3,0);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000149 }
150
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000151 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000152 fUnpackRowLengthSupport = true;
153 fUnpackFlipYSupport = false;
154 fPackRowLengthSupport = true;
155 fPackFlipYSupport = false;
156 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000157 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
158 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000159 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000160 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
161 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000162 fPackFlipYSupport =
163 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
164 }
165
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000166 fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000167 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
168
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000169 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org7a434a22013-08-21 14:01:56 +0000170 // The EXT version can apply to either GL or GLES.
171 fTexStorageSupport = version >= GR_GL_VER(4,2) ||
172 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
173 ctxInfo.hasExtension("GL_EXT_texture_storage");
174 } else {
175 // Qualcomm Adreno drivers appear to have issues with texture storage.
176 fTexStorageSupport = (version >= GR_GL_VER(3,0) &&
177 kQualcomm_GrGLVendor != ctxInfo.vendor()) ||
178 ctxInfo.hasExtension("GL_EXT_texture_storage");
179 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000180
hendrikwa0d5ad72014-12-02 07:30:30 -0800181 // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support GL_RED
182 // and GL_RG on FBO textures.
183 if (!ctxInfo.isMesa()) {
184 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000185 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
186 ctxInfo.hasExtension("GL_ARB_texture_rg");
hendrikwa0d5ad72014-12-02 07:30:30 -0800187 } else {
188 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
189 ctxInfo.hasExtension("GL_EXT_texture_rg");
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000190 }
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000191 }
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
rmistry63a9f842014-10-17 06:07:08 -0700200 // Frag Coords Convention support is not part of ES
bsalomon@google.com706f6682012-10-23 14:53:55 +0000201 // Known issue on at least some Intel platforms:
202 // http://code.google.com/p/skia/issues/detail?id=946
rmistry63a9f842014-10-17 06:07:08 -0700203 if (kIntel_GrGLVendor != ctxInfo.vendor() && kGLES_GrGLStandard != standard) {
bsalomon@google.com706f6682012-10-23 14:53:55 +0000204 fFragCoordsConventionSupport = ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
205 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions");
206 }
207
bsalomon@google.com3012ded2013-02-22 16:44:04 +0000208 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
209 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
210 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
211 // limit this decision to specific GPU families rather than basing it on the vendor alone.
212 if (!GR_GL_MUST_USE_VBO &&
bsalomoned82c4e2014-09-02 07:54:47 -0700213 (kARM_GrGLVendor == ctxInfo.vendor() ||
214 kImagination_GrGLVendor == ctxInfo.vendor() ||
215 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
bsalomon@google.com96966a52013-02-21 16:34:21 +0000216 fUseNonVBOVertexAndIndexDynamicData = true;
217 }
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000218
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000219 if ((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
skia.committer@gmail.coma9157722014-04-03 03:04:26 +0000220 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000221 ctxInfo.hasExtension("GL_ARB_invalidate_subdata")) {
222 fDiscardRenderTargetSupport = true;
223 fInvalidateFBType = kInvalidate_InvalidateFBType;
224 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
225 fDiscardRenderTargetSupport = true;
226 fInvalidateFBType = kDiscard_InvalidateFBType;
227 }
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000228
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000229 if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) {
230 fFullClearIsFree = true;
231 }
232
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000233 if (kGL_GrGLStandard == standard) {
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000234 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
tomhudson612e9262014-11-24 11:22:36 -0800235 ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
236 ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000237 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000238 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
239 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000240 }
241
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000242 if (kGLES_GrGLStandard == standard) {
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000243 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
joshualitt58162332014-08-01 06:44:53 -0700244 fFBFetchSupport = true;
245 fFBFetchColorName = "gl_LastFragData[0]";
246 fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000247 } else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
joshualitt58162332014-08-01 06:44:53 -0700248 fFBFetchSupport = true;
249 fFBFetchColorName = "gl_LastFragData[0]";
250 fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
251 } else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
252 // The arm extension also requires an additional flag which we will set onResetContext
253 // This is all temporary.
254 fFBFetchSupport = true;
255 fFBFetchColorName = "gl_LastFragColorARM";
256 fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000257 }
258 }
259
commit-bot@chromium.org4362a382014-03-26 19:49:03 +0000260 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
261 fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
262
robertphillips@google.com6177e692013-02-28 20:16:25 +0000263 this->initFSAASupport(ctxInfo, gli);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000264 this->initStencilFormats(ctxInfo);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000265
266 /**************************************************************************
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000267 * GrDrawTargetCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000268 **************************************************************************/
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000269 if (kGL_GrGLStandard == standard) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000270 // we could also look for GL_ATI_separate_stencil extension or
271 // GL_EXT_stencil_two_side but they use different function signatures
272 // than GL2.0+ (and than each other).
273 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
274 // supported on GL 1.4 and higher or by extension
275 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
276 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
277 } else {
278 // ES 2 has two sided stencil and stencil wrap
279 fTwoSidedStencilSupport = true;
280 fStencilWrapOpsSupport = true;
281 }
282
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000283 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000284 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
285 // extension includes glMapBuffer.
286 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
287 fMapBufferFlags |= kSubset_MapFlag;
288 fMapBufferType = kMapBufferRange_MapBufferType;
289 } else {
290 fMapBufferType = kMapBuffer_MapBufferType;
291 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000292 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000293 // Unextended GLES2 doesn't have any buffer mapping.
294 fMapBufferFlags = kNone_MapBufferType;
295 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
296 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
297 fMapBufferType = kChromium_MapBufferType;
298 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
299 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
300 fMapBufferType = kMapBufferRange_MapBufferType;
301 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
302 fMapBufferFlags = kCanMap_MapFlag;
303 fMapBufferType = kMapBuffer_MapBufferType;
304 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000305 }
306
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000307 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000308 SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) ||
309 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two"));
310 fNPOTTextureTileSupport = true;
311 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000312 } else {
313 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000314 // ES3 has no limitations.
315 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
316 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000317 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
318 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
319 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
320 // to alllow arbitrary wrap modes, however.
321 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000322 }
323
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000324 fHWAALineSupport = (kGL_GrGLStandard == standard);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000325
326 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
327 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
328 // Our render targets are always created with textures as the color
329 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000330 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000331
kkinnunen32b9a3b2014-07-02 22:56:35 -0700332 fPathRenderingSupport = ctxInfo.hasExtension("GL_NV_path_rendering");
333
334 if (fPathRenderingSupport) {
335 if (kGL_GrGLStandard == standard) {
336 // We need one of the two possible texturing methods: using fixed function pipeline
337 // (PathTexGen, texcoords, ...) or using the newer NVPR API additions that support
338 // setting individual fragment inputs with ProgramPathFragmentInputGen. The API
339 // additions are detected by checking the existence of the function. Eventually we may
340 // choose to remove the fixed function codepath.
341 // Set fMaxFixedFunctionTextureCoords = 0 here if you want to force
342 // ProgramPathFragmentInputGen usage on desktop.
343 fPathRenderingSupport = ctxInfo.hasExtension("GL_EXT_direct_state_access") &&
344 (fMaxFixedFunctionTextureCoords > 0 ||
345 ((ctxInfo.version() >= GR_GL_VER(4,3) ||
346 ctxInfo.hasExtension("GL_ARB_program_interface_query")) &&
bsalomon49f085d2014-09-05 13:34:00 -0700347 gli->fFunctions.fProgramPathFragmentInputGen));
kkinnunen32b9a3b2014-07-02 22:56:35 -0700348 } else {
kkinnunenec56e452014-08-25 22:21:16 -0700349 fPathRenderingSupport = ctxInfo.version() >= GR_GL_VER(3,1);
kkinnunen32b9a3b2014-07-02 22:56:35 -0700350 }
351 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000352
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000353 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
354
joshualitt58162332014-08-01 06:44:53 -0700355 // For now these two are equivalent but we could have dst read in shader via some other method
356 fDstReadInShaderSupport = fFBFetchSupport;
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000357
358 // Disable scratch texture reuse on Mali and Adreno devices
359 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() &&
360 kQualcomm_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000361
bsalomon@google.combcce8922013-03-25 15:38:39 +0000362 // Enable supported shader-related caps
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000363 if (kGL_GrGLStandard == standard) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000364 fDualSourceBlendingSupport = ctxInfo.version() >= GR_GL_VER(3,3) ||
365 ctxInfo.hasExtension("GL_ARB_blend_func_extended");
366 fShaderDerivativeSupport = true;
367 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
368 fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3,2) &&
369 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
370 } else {
rmistry63a9f842014-10-17 06:07:08 -0700371 fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
372 ctxInfo.hasExtension("GL_OES_standard_derivatives");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000373 }
374
bsalomon@google.com347c3822013-05-01 20:10:01 +0000375 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000376 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount);
377 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
378 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount);
379 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000380
bsalomon63b21962014-11-05 07:05:34 -0800381 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
382 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
383 fUseDrawInsteadOfClear = true;
384 }
385
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000386 this->initConfigTexturableTable(ctxInfo, gli);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000387 this->initConfigRenderableTable(ctxInfo);
commit-bot@chromium.orgf4e67e32014-04-30 01:26:04 +0000388
389 return true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000390}
391
392void GrGLCaps::initConfigRenderableTable(const GrGLContextInfo& ctxInfo) {
393
394 // OpenGL < 3.0
395 // no support for render targets unless the GL_ARB_framebuffer_object
396 // extension is supported (in which case we get ALPHA, RED, RG, RGB,
397 // RGBA (ALPHA8, RGBA4, RGBA8) for OpenGL > 1.1). Note that we
398 // probably don't get R8 in this case.
399
400 // OpenGL 3.0
401 // base color renderable: ALPHA, RED, RG, RGB, and RGBA
402 // sized derivatives: ALPHA8, R8, RGBA4, RGBA8
403
404 // >= OpenGL 3.1
405 // base color renderable: RED, RG, RGB, and RGBA
406 // sized derivatives: R8, RGBA4, RGBA8
407 // if the GL_ARB_compatibility extension is supported then we get back
408 // support for GL_ALPHA and ALPHA8
409
410 // GL_EXT_bgra adds BGRA render targets to any version
411
412 // ES 2.0
413 // color renderable: RGBA4, RGB5_A1, RGB565
414 // GL_EXT_texture_rg adds support for R8 as a color render target
415 // GL_OES_rgb8_rgba8 and/or GL_ARM_rgba8 adds support for RGBA8
416 // GL_EXT_texture_format_BGRA8888 and/or GL_APPLE_texture_format_BGRA8888 added BGRA support
417
418 // ES 3.0
419 // Same as ES 2.0 except R8 and RGBA8 are supported without extensions (the functions called
420 // below already account for this).
421
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000422 GrGLStandard standard = ctxInfo.standard();
423
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000424 enum {
425 kNo_MSAA = 0,
426 kYes_MSAA = 1,
427 };
428
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000429 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000430 // Post 3.0 we will get R8
431 // Prior to 3.0 we will get ALPHA8 (with GL_ARB_framebuffer_object)
432 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
433 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000434 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = true;
435 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000436 }
437 } else {
438 // On ES we can only hope for R8
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000439 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = fTextureRedSupport;
440 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = fTextureRedSupport;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000441 }
442
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000443 if (kGL_GrGLStandard != standard) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000444 // only available in ES
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000445 fConfigRenderSupport[kRGB_565_GrPixelConfig][kNo_MSAA] = true;
446 fConfigRenderSupport[kRGB_565_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000447 }
448
449 // we no longer support 444 as a render target
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000450 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kNo_MSAA] = false;
451 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kYes_MSAA] = false;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000452
453 if (this->fRGBA8RenderbufferSupport) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000454 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
commit-bot@chromium.orgda3d69c2013-10-28 15:09:13 +0000455 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000456 }
457
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000458 if (this->isConfigTexturable(kBGRA_8888_GrPixelConfig)) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000459 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kNo_MSAA] = true;
460 // The GL_EXT_texture_format_BGRA8888 extension does not add BGRA to the list of
461 // configs that are color-renderable and can be passed to glRenderBufferStorageMultisample.
commit-bot@chromium.org4256d242013-10-17 16:29:41 +0000462 // Chromium may have an extension to allow BGRA renderbuffers to work on desktop platforms.
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +0000463 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888")) {
commit-bot@chromium.org4256d242013-10-17 16:29:41 +0000464 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] = true;
465 } else {
466 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] =
467 !fBGRAIsInternalFormat || !this->usesMSAARenderBuffers();
468 }
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000469 }
470
joshualittee5da552014-07-16 13:32:56 -0700471 if (this->isConfigTexturable(kRGBA_float_GrPixelConfig)) {
472 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true;
473 }
474
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000475 // If we don't support MSAA then undo any places above where we set a config as renderable with
476 // msaa.
477 if (kNone_MSFBOType == fMSFBOType) {
478 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
479 fConfigRenderSupport[i][kYes_MSAA] = false;
480 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000481 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000482}
483
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000484void GrGLCaps::initConfigTexturableTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000485 GrGLStandard standard = ctxInfo.standard();
486 GrGLVersion version = ctxInfo.version();
487
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000488 // Base texture support
489 fConfigTextureSupport[kAlpha_8_GrPixelConfig] = true;
490 fConfigTextureSupport[kRGB_565_GrPixelConfig] = true;
491 fConfigTextureSupport[kRGBA_4444_GrPixelConfig] = true;
492 fConfigTextureSupport[kRGBA_8888_GrPixelConfig] = true;
493
494 // Check for 8-bit palette..
495 GrGLint numFormats;
496 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
497 if (numFormats) {
498 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
499 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
500 for (int i = 0; i < numFormats; ++i) {
501 if (GR_GL_PALETTE8_RGBA8 == formats[i]) {
502 fConfigTextureSupport[kIndex_8_GrPixelConfig] = true;
503 break;
504 }
505 }
506 }
507
508 // Check for BGRA
509 if (kGL_GrGLStandard == standard) {
510 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] =
511 version >= GR_GL_VER(1,2) || ctxInfo.hasExtension("GL_EXT_bgra");
512 } else {
513 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
514 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
515 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
516 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
517 fBGRAIsInternalFormat = true;
518 }
519 SkASSERT(fConfigTextureSupport[kBGRA_8888_GrPixelConfig] ||
520 kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig);
521 }
522
523 // Compressed texture support
524
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000525 // glCompressedTexImage2D is available on all OpenGL ES devices...
526 // however, it is only available on standard OpenGL after version 1.3
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000527 bool hasCompressTex2D = (kGL_GrGLStandard != standard || version >= GR_GL_VER(1, 3));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000528
krajcevski786978162014-07-30 11:25:44 -0700529 fCompressedTexSubImageSupport =
bsalomon49f085d2014-09-05 13:34:00 -0700530 hasCompressTex2D && (gli->fFunctions.fCompressedTexSubImage2D);
krajcevski786978162014-07-30 11:25:44 -0700531
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000532 // Check for ETC1
533 bool hasETC1 = false;
534
535 // First check version for support
536 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000537 hasETC1 = hasCompressTex2D &&
joshualittee5da552014-07-16 13:32:56 -0700538 (version >= GR_GL_VER(4, 3) ||
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000539 ctxInfo.hasExtension("GL_ARB_ES3_compatibility"));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000540 } else {
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000541 hasETC1 = hasCompressTex2D &&
542 (version >= GR_GL_VER(3, 0) ||
543 ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") ||
544 // ETC2 is a superset of ETC1, so we can just check for that, too.
545 (ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") &&
546 ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture")));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000547 }
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000548 fConfigTextureSupport[kETC1_GrPixelConfig] = hasETC1;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000549
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000550 // Check for LATC under its various forms
551 LATCAlias alias = kLATC_LATCAlias;
552 bool hasLATC = hasCompressTex2D &&
553 (ctxInfo.hasExtension("GL_EXT_texture_compression_latc") ||
554 ctxInfo.hasExtension("GL_NV_texture_compression_latc"));
555
556 // Check for RGTC
557 if (!hasLATC) {
558 // If we're using OpenGL 3.0 or later, then we have RGTC, an identical compression format.
559 if (kGL_GrGLStandard == standard) {
560 hasLATC = version >= GR_GL_VER(3, 0);
561 }
562
563 if (!hasLATC) {
564 hasLATC =
565 ctxInfo.hasExtension("GL_EXT_texture_compression_rgtc") ||
566 ctxInfo.hasExtension("GL_ARB_texture_compression_rgtc");
567 }
568
569 if (hasLATC) {
570 alias = kRGTC_LATCAlias;
571 }
572 }
573
574 // Check for 3DC
575 if (!hasLATC) {
576 hasLATC = ctxInfo.hasExtension("GL_AMD_compressed_3DC_texture");
577 if (hasLATC) {
578 alias = k3DC_LATCAlias;
579 }
580 }
581
582 fConfigTextureSupport[kLATC_GrPixelConfig] = hasLATC;
583 fLATCAlias = alias;
krajcevski238b4562014-06-30 09:09:22 -0700584
krajcevskib3abe902014-07-30 13:08:11 -0700585 // Check for R11_EAC ... We don't support R11_EAC on desktop, as most
586 // cards default to decompressing the textures in the driver, and is
587 // generally slower.
588 if (kGL_GrGLStandard != standard) {
krajcevski238b4562014-06-30 09:09:22 -0700589 fConfigTextureSupport[kR11_EAC_GrPixelConfig] = version >= GR_GL_VER(3, 0);
590 }
joshualittee5da552014-07-16 13:32:56 -0700591
krajcevski7ef21622014-07-16 15:21:13 -0700592 // Check for ASTC
piotaixre4b23142014-10-02 10:57:53 -0700593 fConfigTextureSupport[kASTC_12x12_GrPixelConfig] =
krajcevski7ef21622014-07-16 15:21:13 -0700594 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_hdr") ||
595 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_ldr") ||
596 ctxInfo.hasExtension("GL_OES_texture_compression_astc");
597
joshualittee5da552014-07-16 13:32:56 -0700598 // Check for floating point texture support
599 // NOTE: We disallow floating point textures on ES devices if linear
600 // filtering modes are not supported. This is for simplicity, but a more
601 // granular approach is possible. Coincidentally, floating point textures became part of
602 // the standard in ES3.1 / OGL 3.1, hence the shorthand
603 bool hasFPTextures = version >= GR_GL_VER(3, 1);
604 if (!hasFPTextures) {
605 hasFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") ||
606 (ctxInfo.hasExtension("OES_texture_float_linear") &&
607 ctxInfo.hasExtension("GL_OES_texture_float"));
608 }
609 fConfigTextureSupport[kRGBA_float_GrPixelConfig] = hasFPTextures;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000610}
611
piotaixre4b23142014-10-02 10:57:53 -0700612bool GrGLCaps::doReadPixelsSupported(const GrGLInterface* intf,
613 GrGLenum format,
614 GrGLenum type) const {
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000615 if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) {
616 // ES 2 guarantees this format is supported
robertphillips@google.comeca2dfb2012-06-27 20:13:49 +0000617 return true;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000618 }
619
620 if (!fTwoFormatLimit) {
621 // not limited by ES 2's constraints
622 return true;
623 }
624
bsalomon@google.com548a4332012-07-11 19:45:22 +0000625 GrGLint otherFormat = GR_GL_RGBA;
626 GrGLint otherType = GR_GL_UNSIGNED_BYTE;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000627
628 // The other supported format/type combo supported for ReadPixels
629 // can change based on which render target is bound
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000630 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000631 GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT,
632 &otherFormat);
633
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000634 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000635 GR_GL_IMPLEMENTATION_COLOR_READ_TYPE,
636 &otherType);
637
bsalomon@google.com548a4332012-07-11 19:45:22 +0000638 return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000639}
640
piotaixre4b23142014-10-02 10:57:53 -0700641bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,
642 GrGLenum format,
643 GrGLenum type,
644 GrGLenum currFboFormat) const {
645
646 ReadPixelsSupportedFormats::Key key = {format, type, currFboFormat};
647
648 ReadPixelsSupportedFormats* cachedValue = fReadPixelsSupportedCache.find(key);
649
650 if (NULL == cachedValue) {
651 bool value = doReadPixelsSupported(intf, format, type);
652 ReadPixelsSupportedFormats newValue(key, value);
653 fReadPixelsSupportedCache.add(newValue);
654
655 return newValue.value();
656 }
657
658 return cachedValue->value();
659}
660
robertphillips@google.com6177e692013-02-28 20:16:25 +0000661void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000662
663 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000664 if (kGL_GrGLStandard != ctxInfo.standard()) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000665 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
666 // ES3 driver bugs on at least one device with a tiled GPU (N10).
667 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
668 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
669 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
670 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
commit-bot@chromium.org92b78842014-01-16 20:49:46 +0000671 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000672 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType;
673 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
674 // chrome's extension is equivalent to the EXT msaa
675 // and fbo_blit extensions.
676 fMSFBOType = kDesktop_EXT_MSFBOType;
677 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
678 fMSFBOType = kES_Apple_MSFBOType;
679 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000680 } else {
681 if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
682 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000683 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000684 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
685 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000686 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000687 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000688 }
689}
690
691namespace {
692const GrGLuint kUnknownBitCount = GrGLStencilBuffer::kUnknownBitCount;
693}
694
695void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
696
697 // Build up list of legal stencil formats (though perhaps not supported on
698 // the particular gpu/driver) from most preferred to least.
699
700 // these consts are in order of most preferred to least preferred
701 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
702
703 static const StencilFormat
704 // internal Format stencil bits total bits packed?
705 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
706 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
707 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
708 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000709 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000710 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
711
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000712 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000713 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000714 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000715 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
716 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
717
718 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
719 // require FBO support we can expect these are legal formats and don't
720 // check. These also all support the unsized GL_STENCIL_INDEX.
721 fStencilFormats.push_back() = gS8;
722 fStencilFormats.push_back() = gS16;
723 if (supportsPackedDS) {
724 fStencilFormats.push_back() = gD24S8;
725 }
726 fStencilFormats.push_back() = gS4;
727 if (supportsPackedDS) {
728 fStencilFormats.push_back() = gDS;
729 }
730 } else {
731 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
732 // for other formats.
733 // ES doesn't support using the unsized format.
734
735 fStencilFormats.push_back() = gS8;
736 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +0000737 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
738 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000739 fStencilFormats.push_back() = gD24S8;
740 }
741 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
742 fStencilFormats.push_back() = gS4;
743 }
744 }
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000745 SkASSERT(0 == fStencilVerifiedColorConfigs.count());
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000746 fStencilVerifiedColorConfigs.push_back_n(fStencilFormats.count());
747}
748
749void GrGLCaps::markColorConfigAndStencilFormatAsVerified(
750 GrPixelConfig config,
751 const GrGLStencilBuffer::Format& format) {
752#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
753 return;
754#endif
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000755 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
756 SkASSERT(fStencilFormats.count() == fStencilVerifiedColorConfigs.count());
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000757 int count = fStencilFormats.count();
758 // we expect a really small number of possible formats so linear search
759 // should be OK
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000760 SkASSERT(count < 16);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000761 for (int i = 0; i < count; ++i) {
762 if (format.fInternalFormat ==
763 fStencilFormats[i].fInternalFormat) {
764 fStencilVerifiedColorConfigs[i].markVerified(config);
765 return;
766 }
767 }
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000768 SkFAIL("Why are we seeing a stencil format that "
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000769 "GrGLCaps doesn't know about.");
770}
771
772bool GrGLCaps::isColorConfigAndStencilFormatVerified(
773 GrPixelConfig config,
774 const GrGLStencilBuffer::Format& format) const {
775#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
776 return false;
777#endif
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000778 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000779 int count = fStencilFormats.count();
780 // we expect a really small number of possible formats so linear search
781 // should be OK
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000782 SkASSERT(count < 16);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000783 for (int i = 0; i < count; ++i) {
784 if (format.fInternalFormat ==
785 fStencilFormats[i].fInternalFormat) {
786 return fStencilVerifiedColorConfigs[i].isVerified(config);
787 }
788 }
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000789 SkFAIL("Why are we seeing a stencil format that "
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000790 "GLCaps doesn't know about.");
791 return false;
792}
793
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000794SkString GrGLCaps::dump() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000795
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000796 SkString r = INHERITED::dump();
bsalomon@google.combcce8922013-03-25 15:38:39 +0000797
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000798 r.appendf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000799 for (int i = 0; i < fStencilFormats.count(); ++i) {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000800 r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000801 i,
802 fStencilFormats[i].fStencilBits,
803 fStencilFormats[i].fTotalBits);
804 }
805
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000806 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000807 "None",
808 "ARB",
809 "EXT",
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000810 "ES 3.0",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000811 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +0000812 "IMG MS To Texture",
813 "EXT MS To Texture",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000814 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000815 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
816 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
817 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000818 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType);
819 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType);
820 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType);
821 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000822 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000823
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000824 static const char* kInvalidateFBTypeStr[] = {
825 "None",
826 "Discard",
827 "Invalidate",
828 };
829 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
830 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
831 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
832 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000833
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000834 static const char* kMapBufferTypeStr[] = {
835 "None",
836 "MapBuffer",
837 "MapBufferRange",
838 "Chromium",
839 };
840 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
841 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
842 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
843 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
844 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
845
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000846 r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000847 r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
joshualitt58162332014-08-01 06:44:53 -0700848 r.appendf("FB Fetch Support: %s\n", (fFBFetchSupport ? "YES" : "NO"));
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000849 r.appendf("Invalidate FB Type: %s\n", kInvalidateFBTypeStr[fInvalidateFBType]);
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000850 r.appendf("Map Buffer Type: %s\n", kMapBufferTypeStr[fMapBufferType]);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000851 r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
852 r.appendf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits);
commit-bot@chromium.org0a6fe712014-04-23 19:26:26 +0000853 if (!fIsCoreProfile) {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000854 r.appendf("Max Fixed Function Texture Coords: %d\n", fMaxFixedFunctionTextureCoords);
commit-bot@chromium.org3628ad92013-08-30 19:43:47 +0000855 }
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000856 r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
857 r.appendf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000858 r.appendf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO"));
859 r.appendf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO"));
860 r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
861 r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
862 r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
863 r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +0000864
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000865 r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
866 r.appendf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
867 r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
868 r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
869 r.appendf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO"));
870 r.appendf("Fragment coord conventions support: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +0000871 (fFragCoordsConventionSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000872 r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
873 r.appendf("Use non-VBO for dynamic data: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +0000874 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000875 r.appendf("Full screen clear is free: %s\n", (fFullClearIsFree ? "YES" : "NO"));
commit-bot@chromium.org4362a382014-03-26 19:49:03 +0000876 r.appendf("Drops tile on zero divide: %s\n", (fDropsTileOnZeroDivide ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000877 return r;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000878}