blob: 414f06d6aebc14e6bc044c4b3a4625d3710ea5e0 [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
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000181 // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support it if
182 // it doesn't have ARB_texture_rg extension.
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000183 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000184 if (ctxInfo.isMesa()) {
185 fTextureRedSupport = ctxInfo.hasExtension("GL_ARB_texture_rg");
186 } else {
187 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
188 ctxInfo.hasExtension("GL_ARB_texture_rg");
189 }
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000190 } else {
commit-bot@chromium.orgc5dffe42013-08-20 15:25:21 +0000191 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
192 ctxInfo.hasExtension("GL_EXT_texture_rg");
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000193 }
194
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000195 fImagingSupport = kGL_GrGLStandard == standard &&
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000196 ctxInfo.hasExtension("GL_ARB_imaging");
197
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000198 // ES 2 only guarantees RGBA/uchar + one other format/type combo for
199 // ReadPixels. The other format has to checked at run-time since it
200 // can change based on which render target is bound
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000201 fTwoFormatLimit = kGLES_GrGLStandard == standard;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000202
rmistry63a9f842014-10-17 06:07:08 -0700203 // Frag Coords Convention support is not part of ES
bsalomon@google.com706f6682012-10-23 14:53:55 +0000204 // Known issue on at least some Intel platforms:
205 // http://code.google.com/p/skia/issues/detail?id=946
rmistry63a9f842014-10-17 06:07:08 -0700206 if (kIntel_GrGLVendor != ctxInfo.vendor() && kGLES_GrGLStandard != standard) {
bsalomon@google.com706f6682012-10-23 14:53:55 +0000207 fFragCoordsConventionSupport = ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
208 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions");
209 }
210
bsalomon@google.com3012ded2013-02-22 16:44:04 +0000211 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
212 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
213 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
214 // limit this decision to specific GPU families rather than basing it on the vendor alone.
215 if (!GR_GL_MUST_USE_VBO &&
bsalomoned82c4e2014-09-02 07:54:47 -0700216 (kARM_GrGLVendor == ctxInfo.vendor() ||
217 kImagination_GrGLVendor == ctxInfo.vendor() ||
218 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
bsalomon@google.com96966a52013-02-21 16:34:21 +0000219 fUseNonVBOVertexAndIndexDynamicData = true;
220 }
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000221
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000222 if ((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
skia.committer@gmail.coma9157722014-04-03 03:04:26 +0000223 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000224 ctxInfo.hasExtension("GL_ARB_invalidate_subdata")) {
225 fDiscardRenderTargetSupport = true;
226 fInvalidateFBType = kInvalidate_InvalidateFBType;
227 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
228 fDiscardRenderTargetSupport = true;
229 fInvalidateFBType = kDiscard_InvalidateFBType;
230 }
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000231
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000232 if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) {
233 fFullClearIsFree = true;
234 }
235
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000236 if (kGL_GrGLStandard == standard) {
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000237 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
tomhudson612e9262014-11-24 11:22:36 -0800238 ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
239 ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000240 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000241 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
242 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000243 }
244
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000245 if (kGLES_GrGLStandard == standard) {
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000246 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
joshualitt58162332014-08-01 06:44:53 -0700247 fFBFetchSupport = true;
248 fFBFetchColorName = "gl_LastFragData[0]";
249 fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000250 } else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
joshualitt58162332014-08-01 06:44:53 -0700251 fFBFetchSupport = true;
252 fFBFetchColorName = "gl_LastFragData[0]";
253 fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
254 } else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
255 // The arm extension also requires an additional flag which we will set onResetContext
256 // This is all temporary.
257 fFBFetchSupport = true;
258 fFBFetchColorName = "gl_LastFragColorARM";
259 fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000260 }
261 }
262
commit-bot@chromium.org4362a382014-03-26 19:49:03 +0000263 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
264 fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
265
robertphillips@google.com6177e692013-02-28 20:16:25 +0000266 this->initFSAASupport(ctxInfo, gli);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000267 this->initStencilFormats(ctxInfo);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000268
269 /**************************************************************************
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000270 * GrDrawTargetCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000271 **************************************************************************/
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000272 if (kGL_GrGLStandard == standard) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000273 // we could also look for GL_ATI_separate_stencil extension or
274 // GL_EXT_stencil_two_side but they use different function signatures
275 // than GL2.0+ (and than each other).
276 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
277 // supported on GL 1.4 and higher or by extension
278 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
279 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
280 } else {
281 // ES 2 has two sided stencil and stencil wrap
282 fTwoSidedStencilSupport = true;
283 fStencilWrapOpsSupport = true;
284 }
285
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000286 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000287 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
288 // extension includes glMapBuffer.
289 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
290 fMapBufferFlags |= kSubset_MapFlag;
291 fMapBufferType = kMapBufferRange_MapBufferType;
292 } else {
293 fMapBufferType = kMapBuffer_MapBufferType;
294 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000295 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000296 // Unextended GLES2 doesn't have any buffer mapping.
297 fMapBufferFlags = kNone_MapBufferType;
298 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
299 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
300 fMapBufferType = kChromium_MapBufferType;
301 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
302 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
303 fMapBufferType = kMapBufferRange_MapBufferType;
304 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
305 fMapBufferFlags = kCanMap_MapFlag;
306 fMapBufferType = kMapBuffer_MapBufferType;
307 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000308 }
309
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000310 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000311 SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) ||
312 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two"));
313 fNPOTTextureTileSupport = true;
314 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000315 } else {
316 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000317 // ES3 has no limitations.
318 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
319 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000320 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
321 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
322 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
323 // to alllow arbitrary wrap modes, however.
324 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000325 }
326
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000327 fHWAALineSupport = (kGL_GrGLStandard == standard);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000328
329 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
330 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
331 // Our render targets are always created with textures as the color
332 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000333 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000334
kkinnunen32b9a3b2014-07-02 22:56:35 -0700335 fPathRenderingSupport = ctxInfo.hasExtension("GL_NV_path_rendering");
336
337 if (fPathRenderingSupport) {
338 if (kGL_GrGLStandard == standard) {
339 // We need one of the two possible texturing methods: using fixed function pipeline
340 // (PathTexGen, texcoords, ...) or using the newer NVPR API additions that support
341 // setting individual fragment inputs with ProgramPathFragmentInputGen. The API
342 // additions are detected by checking the existence of the function. Eventually we may
343 // choose to remove the fixed function codepath.
344 // Set fMaxFixedFunctionTextureCoords = 0 here if you want to force
345 // ProgramPathFragmentInputGen usage on desktop.
346 fPathRenderingSupport = ctxInfo.hasExtension("GL_EXT_direct_state_access") &&
347 (fMaxFixedFunctionTextureCoords > 0 ||
348 ((ctxInfo.version() >= GR_GL_VER(4,3) ||
349 ctxInfo.hasExtension("GL_ARB_program_interface_query")) &&
bsalomon49f085d2014-09-05 13:34:00 -0700350 gli->fFunctions.fProgramPathFragmentInputGen));
kkinnunen32b9a3b2014-07-02 22:56:35 -0700351 } else {
kkinnunenec56e452014-08-25 22:21:16 -0700352 fPathRenderingSupport = ctxInfo.version() >= GR_GL_VER(3,1);
kkinnunen32b9a3b2014-07-02 22:56:35 -0700353 }
354 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000355
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000356 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
357
joshualitt58162332014-08-01 06:44:53 -0700358 // For now these two are equivalent but we could have dst read in shader via some other method
359 fDstReadInShaderSupport = fFBFetchSupport;
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000360
361 // Disable scratch texture reuse on Mali and Adreno devices
362 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() &&
363 kQualcomm_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000364
bsalomon@google.combcce8922013-03-25 15:38:39 +0000365 // Enable supported shader-related caps
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000366 if (kGL_GrGLStandard == standard) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000367 fDualSourceBlendingSupport = ctxInfo.version() >= GR_GL_VER(3,3) ||
368 ctxInfo.hasExtension("GL_ARB_blend_func_extended");
369 fShaderDerivativeSupport = true;
370 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
371 fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3,2) &&
372 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
373 } else {
rmistry63a9f842014-10-17 06:07:08 -0700374 fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
375 ctxInfo.hasExtension("GL_OES_standard_derivatives");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000376 }
377
bsalomon@google.com347c3822013-05-01 20:10:01 +0000378 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000379 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount);
380 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
381 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount);
382 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000383
bsalomon63b21962014-11-05 07:05:34 -0800384 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
385 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
386 fUseDrawInsteadOfClear = true;
387 }
388
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000389 this->initConfigTexturableTable(ctxInfo, gli);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000390 this->initConfigRenderableTable(ctxInfo);
commit-bot@chromium.orgf4e67e32014-04-30 01:26:04 +0000391
392 return true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000393}
394
395void GrGLCaps::initConfigRenderableTable(const GrGLContextInfo& ctxInfo) {
396
397 // OpenGL < 3.0
398 // no support for render targets unless the GL_ARB_framebuffer_object
399 // extension is supported (in which case we get ALPHA, RED, RG, RGB,
400 // RGBA (ALPHA8, RGBA4, RGBA8) for OpenGL > 1.1). Note that we
401 // probably don't get R8 in this case.
402
403 // OpenGL 3.0
404 // base color renderable: ALPHA, RED, RG, RGB, and RGBA
405 // sized derivatives: ALPHA8, R8, RGBA4, RGBA8
406
407 // >= OpenGL 3.1
408 // base color renderable: RED, RG, RGB, and RGBA
409 // sized derivatives: R8, RGBA4, RGBA8
410 // if the GL_ARB_compatibility extension is supported then we get back
411 // support for GL_ALPHA and ALPHA8
412
413 // GL_EXT_bgra adds BGRA render targets to any version
414
415 // ES 2.0
416 // color renderable: RGBA4, RGB5_A1, RGB565
417 // GL_EXT_texture_rg adds support for R8 as a color render target
418 // GL_OES_rgb8_rgba8 and/or GL_ARM_rgba8 adds support for RGBA8
419 // GL_EXT_texture_format_BGRA8888 and/or GL_APPLE_texture_format_BGRA8888 added BGRA support
420
421 // ES 3.0
422 // Same as ES 2.0 except R8 and RGBA8 are supported without extensions (the functions called
423 // below already account for this).
424
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000425 GrGLStandard standard = ctxInfo.standard();
426
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000427 enum {
428 kNo_MSAA = 0,
429 kYes_MSAA = 1,
430 };
431
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000432 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000433 // Post 3.0 we will get R8
434 // Prior to 3.0 we will get ALPHA8 (with GL_ARB_framebuffer_object)
435 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
436 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000437 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = true;
438 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000439 }
440 } else {
441 // On ES we can only hope for R8
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000442 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = fTextureRedSupport;
443 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = fTextureRedSupport;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000444 }
445
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000446 if (kGL_GrGLStandard != standard) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000447 // only available in ES
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000448 fConfigRenderSupport[kRGB_565_GrPixelConfig][kNo_MSAA] = true;
449 fConfigRenderSupport[kRGB_565_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000450 }
451
452 // we no longer support 444 as a render target
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000453 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kNo_MSAA] = false;
454 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kYes_MSAA] = false;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000455
456 if (this->fRGBA8RenderbufferSupport) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000457 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
commit-bot@chromium.orgda3d69c2013-10-28 15:09:13 +0000458 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000459 }
460
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000461 if (this->isConfigTexturable(kBGRA_8888_GrPixelConfig)) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000462 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kNo_MSAA] = true;
463 // The GL_EXT_texture_format_BGRA8888 extension does not add BGRA to the list of
464 // configs that are color-renderable and can be passed to glRenderBufferStorageMultisample.
commit-bot@chromium.org4256d242013-10-17 16:29:41 +0000465 // Chromium may have an extension to allow BGRA renderbuffers to work on desktop platforms.
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +0000466 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888")) {
commit-bot@chromium.org4256d242013-10-17 16:29:41 +0000467 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] = true;
468 } else {
469 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] =
470 !fBGRAIsInternalFormat || !this->usesMSAARenderBuffers();
471 }
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000472 }
473
joshualittee5da552014-07-16 13:32:56 -0700474 if (this->isConfigTexturable(kRGBA_float_GrPixelConfig)) {
475 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true;
476 }
477
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000478 // If we don't support MSAA then undo any places above where we set a config as renderable with
479 // msaa.
480 if (kNone_MSFBOType == fMSFBOType) {
481 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
482 fConfigRenderSupport[i][kYes_MSAA] = false;
483 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000484 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000485}
486
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000487void GrGLCaps::initConfigTexturableTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000488 GrGLStandard standard = ctxInfo.standard();
489 GrGLVersion version = ctxInfo.version();
490
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000491 // Base texture support
492 fConfigTextureSupport[kAlpha_8_GrPixelConfig] = true;
493 fConfigTextureSupport[kRGB_565_GrPixelConfig] = true;
494 fConfigTextureSupport[kRGBA_4444_GrPixelConfig] = true;
495 fConfigTextureSupport[kRGBA_8888_GrPixelConfig] = true;
496
497 // Check for 8-bit palette..
498 GrGLint numFormats;
499 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
500 if (numFormats) {
501 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
502 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
503 for (int i = 0; i < numFormats; ++i) {
504 if (GR_GL_PALETTE8_RGBA8 == formats[i]) {
505 fConfigTextureSupport[kIndex_8_GrPixelConfig] = true;
506 break;
507 }
508 }
509 }
510
511 // Check for BGRA
512 if (kGL_GrGLStandard == standard) {
513 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] =
514 version >= GR_GL_VER(1,2) || ctxInfo.hasExtension("GL_EXT_bgra");
515 } else {
516 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
517 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
518 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
519 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
520 fBGRAIsInternalFormat = true;
521 }
522 SkASSERT(fConfigTextureSupport[kBGRA_8888_GrPixelConfig] ||
523 kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig);
524 }
525
526 // Compressed texture support
527
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000528 // glCompressedTexImage2D is available on all OpenGL ES devices...
529 // however, it is only available on standard OpenGL after version 1.3
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000530 bool hasCompressTex2D = (kGL_GrGLStandard != standard || version >= GR_GL_VER(1, 3));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000531
krajcevski786978162014-07-30 11:25:44 -0700532 fCompressedTexSubImageSupport =
bsalomon49f085d2014-09-05 13:34:00 -0700533 hasCompressTex2D && (gli->fFunctions.fCompressedTexSubImage2D);
krajcevski786978162014-07-30 11:25:44 -0700534
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000535 // Check for ETC1
536 bool hasETC1 = false;
537
538 // First check version for support
539 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000540 hasETC1 = hasCompressTex2D &&
joshualittee5da552014-07-16 13:32:56 -0700541 (version >= GR_GL_VER(4, 3) ||
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000542 ctxInfo.hasExtension("GL_ARB_ES3_compatibility"));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000543 } else {
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000544 hasETC1 = hasCompressTex2D &&
545 (version >= GR_GL_VER(3, 0) ||
546 ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") ||
547 // ETC2 is a superset of ETC1, so we can just check for that, too.
548 (ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") &&
549 ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture")));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000550 }
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000551 fConfigTextureSupport[kETC1_GrPixelConfig] = hasETC1;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000552
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000553 // Check for LATC under its various forms
554 LATCAlias alias = kLATC_LATCAlias;
555 bool hasLATC = hasCompressTex2D &&
556 (ctxInfo.hasExtension("GL_EXT_texture_compression_latc") ||
557 ctxInfo.hasExtension("GL_NV_texture_compression_latc"));
558
559 // Check for RGTC
560 if (!hasLATC) {
561 // If we're using OpenGL 3.0 or later, then we have RGTC, an identical compression format.
562 if (kGL_GrGLStandard == standard) {
563 hasLATC = version >= GR_GL_VER(3, 0);
564 }
565
566 if (!hasLATC) {
567 hasLATC =
568 ctxInfo.hasExtension("GL_EXT_texture_compression_rgtc") ||
569 ctxInfo.hasExtension("GL_ARB_texture_compression_rgtc");
570 }
571
572 if (hasLATC) {
573 alias = kRGTC_LATCAlias;
574 }
575 }
576
577 // Check for 3DC
578 if (!hasLATC) {
579 hasLATC = ctxInfo.hasExtension("GL_AMD_compressed_3DC_texture");
580 if (hasLATC) {
581 alias = k3DC_LATCAlias;
582 }
583 }
584
585 fConfigTextureSupport[kLATC_GrPixelConfig] = hasLATC;
586 fLATCAlias = alias;
krajcevski238b4562014-06-30 09:09:22 -0700587
krajcevskib3abe902014-07-30 13:08:11 -0700588 // Check for R11_EAC ... We don't support R11_EAC on desktop, as most
589 // cards default to decompressing the textures in the driver, and is
590 // generally slower.
591 if (kGL_GrGLStandard != standard) {
krajcevski238b4562014-06-30 09:09:22 -0700592 fConfigTextureSupport[kR11_EAC_GrPixelConfig] = version >= GR_GL_VER(3, 0);
593 }
joshualittee5da552014-07-16 13:32:56 -0700594
krajcevski7ef21622014-07-16 15:21:13 -0700595 // Check for ASTC
piotaixre4b23142014-10-02 10:57:53 -0700596 fConfigTextureSupport[kASTC_12x12_GrPixelConfig] =
krajcevski7ef21622014-07-16 15:21:13 -0700597 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_hdr") ||
598 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_ldr") ||
599 ctxInfo.hasExtension("GL_OES_texture_compression_astc");
600
joshualittee5da552014-07-16 13:32:56 -0700601 // Check for floating point texture support
602 // NOTE: We disallow floating point textures on ES devices if linear
603 // filtering modes are not supported. This is for simplicity, but a more
604 // granular approach is possible. Coincidentally, floating point textures became part of
605 // the standard in ES3.1 / OGL 3.1, hence the shorthand
606 bool hasFPTextures = version >= GR_GL_VER(3, 1);
607 if (!hasFPTextures) {
608 hasFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") ||
609 (ctxInfo.hasExtension("OES_texture_float_linear") &&
610 ctxInfo.hasExtension("GL_OES_texture_float"));
611 }
612 fConfigTextureSupport[kRGBA_float_GrPixelConfig] = hasFPTextures;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000613}
614
piotaixre4b23142014-10-02 10:57:53 -0700615bool GrGLCaps::doReadPixelsSupported(const GrGLInterface* intf,
616 GrGLenum format,
617 GrGLenum type) const {
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000618 if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) {
619 // ES 2 guarantees this format is supported
robertphillips@google.comeca2dfb2012-06-27 20:13:49 +0000620 return true;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000621 }
622
623 if (!fTwoFormatLimit) {
624 // not limited by ES 2's constraints
625 return true;
626 }
627
bsalomon@google.com548a4332012-07-11 19:45:22 +0000628 GrGLint otherFormat = GR_GL_RGBA;
629 GrGLint otherType = GR_GL_UNSIGNED_BYTE;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000630
631 // The other supported format/type combo supported for ReadPixels
632 // can change based on which render target is bound
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000633 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000634 GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT,
635 &otherFormat);
636
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000637 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000638 GR_GL_IMPLEMENTATION_COLOR_READ_TYPE,
639 &otherType);
640
bsalomon@google.com548a4332012-07-11 19:45:22 +0000641 return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000642}
643
piotaixre4b23142014-10-02 10:57:53 -0700644bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,
645 GrGLenum format,
646 GrGLenum type,
647 GrGLenum currFboFormat) const {
648
649 ReadPixelsSupportedFormats::Key key = {format, type, currFboFormat};
650
651 ReadPixelsSupportedFormats* cachedValue = fReadPixelsSupportedCache.find(key);
652
653 if (NULL == cachedValue) {
654 bool value = doReadPixelsSupported(intf, format, type);
655 ReadPixelsSupportedFormats newValue(key, value);
656 fReadPixelsSupportedCache.add(newValue);
657
658 return newValue.value();
659 }
660
661 return cachedValue->value();
662}
663
robertphillips@google.com6177e692013-02-28 20:16:25 +0000664void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000665
666 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000667 if (kGL_GrGLStandard != ctxInfo.standard()) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000668 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
669 // ES3 driver bugs on at least one device with a tiled GPU (N10).
670 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
671 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
672 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
673 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
commit-bot@chromium.org92b78842014-01-16 20:49:46 +0000674 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000675 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType;
676 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
677 // chrome's extension is equivalent to the EXT msaa
678 // and fbo_blit extensions.
679 fMSFBOType = kDesktop_EXT_MSFBOType;
680 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
681 fMSFBOType = kES_Apple_MSFBOType;
682 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000683 } else {
684 if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
685 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000686 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000687 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
688 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000689 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000690 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000691 }
692}
693
694namespace {
695const GrGLuint kUnknownBitCount = GrGLStencilBuffer::kUnknownBitCount;
696}
697
698void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
699
700 // Build up list of legal stencil formats (though perhaps not supported on
701 // the particular gpu/driver) from most preferred to least.
702
703 // these consts are in order of most preferred to least preferred
704 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
705
706 static const StencilFormat
707 // internal Format stencil bits total bits packed?
708 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
709 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
710 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
711 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000712 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000713 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
714
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000715 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000716 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000717 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000718 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
719 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
720
721 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
722 // require FBO support we can expect these are legal formats and don't
723 // check. These also all support the unsized GL_STENCIL_INDEX.
724 fStencilFormats.push_back() = gS8;
725 fStencilFormats.push_back() = gS16;
726 if (supportsPackedDS) {
727 fStencilFormats.push_back() = gD24S8;
728 }
729 fStencilFormats.push_back() = gS4;
730 if (supportsPackedDS) {
731 fStencilFormats.push_back() = gDS;
732 }
733 } else {
734 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
735 // for other formats.
736 // ES doesn't support using the unsized format.
737
738 fStencilFormats.push_back() = gS8;
739 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +0000740 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
741 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000742 fStencilFormats.push_back() = gD24S8;
743 }
744 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
745 fStencilFormats.push_back() = gS4;
746 }
747 }
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000748 SkASSERT(0 == fStencilVerifiedColorConfigs.count());
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000749 fStencilVerifiedColorConfigs.push_back_n(fStencilFormats.count());
750}
751
752void GrGLCaps::markColorConfigAndStencilFormatAsVerified(
753 GrPixelConfig config,
754 const GrGLStencilBuffer::Format& format) {
755#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
756 return;
757#endif
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000758 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
759 SkASSERT(fStencilFormats.count() == fStencilVerifiedColorConfigs.count());
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000760 int count = fStencilFormats.count();
761 // we expect a really small number of possible formats so linear search
762 // should be OK
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000763 SkASSERT(count < 16);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000764 for (int i = 0; i < count; ++i) {
765 if (format.fInternalFormat ==
766 fStencilFormats[i].fInternalFormat) {
767 fStencilVerifiedColorConfigs[i].markVerified(config);
768 return;
769 }
770 }
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000771 SkFAIL("Why are we seeing a stencil format that "
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000772 "GrGLCaps doesn't know about.");
773}
774
775bool GrGLCaps::isColorConfigAndStencilFormatVerified(
776 GrPixelConfig config,
777 const GrGLStencilBuffer::Format& format) const {
778#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
779 return false;
780#endif
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000781 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000782 int count = fStencilFormats.count();
783 // we expect a really small number of possible formats so linear search
784 // should be OK
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000785 SkASSERT(count < 16);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000786 for (int i = 0; i < count; ++i) {
787 if (format.fInternalFormat ==
788 fStencilFormats[i].fInternalFormat) {
789 return fStencilVerifiedColorConfigs[i].isVerified(config);
790 }
791 }
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000792 SkFAIL("Why are we seeing a stencil format that "
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000793 "GLCaps doesn't know about.");
794 return false;
795}
796
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000797SkString GrGLCaps::dump() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000798
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000799 SkString r = INHERITED::dump();
bsalomon@google.combcce8922013-03-25 15:38:39 +0000800
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000801 r.appendf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000802 for (int i = 0; i < fStencilFormats.count(); ++i) {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000803 r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000804 i,
805 fStencilFormats[i].fStencilBits,
806 fStencilFormats[i].fTotalBits);
807 }
808
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000809 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000810 "None",
811 "ARB",
812 "EXT",
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000813 "ES 3.0",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000814 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +0000815 "IMG MS To Texture",
816 "EXT MS To Texture",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000817 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000818 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
819 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
820 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000821 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType);
822 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType);
823 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType);
824 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000825 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000826
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000827 static const char* kInvalidateFBTypeStr[] = {
828 "None",
829 "Discard",
830 "Invalidate",
831 };
832 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
833 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
834 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
835 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000836
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000837 static const char* kMapBufferTypeStr[] = {
838 "None",
839 "MapBuffer",
840 "MapBufferRange",
841 "Chromium",
842 };
843 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
844 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
845 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
846 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
847 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
848
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000849 r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000850 r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
joshualitt58162332014-08-01 06:44:53 -0700851 r.appendf("FB Fetch Support: %s\n", (fFBFetchSupport ? "YES" : "NO"));
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000852 r.appendf("Invalidate FB Type: %s\n", kInvalidateFBTypeStr[fInvalidateFBType]);
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000853 r.appendf("Map Buffer Type: %s\n", kMapBufferTypeStr[fMapBufferType]);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000854 r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
855 r.appendf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits);
commit-bot@chromium.org0a6fe712014-04-23 19:26:26 +0000856 if (!fIsCoreProfile) {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000857 r.appendf("Max Fixed Function Texture Coords: %d\n", fMaxFixedFunctionTextureCoords);
commit-bot@chromium.org3628ad92013-08-30 19:43:47 +0000858 }
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000859 r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
860 r.appendf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000861 r.appendf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO"));
862 r.appendf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO"));
863 r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
864 r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
865 r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
866 r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +0000867
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000868 r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
869 r.appendf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
870 r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
871 r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
872 r.appendf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO"));
873 r.appendf("Fragment coord conventions support: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +0000874 (fFragCoordsConventionSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000875 r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
876 r.appendf("Use non-VBO for dynamic data: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +0000877 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000878 r.appendf("Full screen clear is free: %s\n", (fFullClearIsFree ? "YES" : "NO"));
commit-bot@chromium.org4362a382014-03-26 19:49:03 +0000879 r.appendf("Drops tile on zero divide: %s\n", (fDropsTileOnZeroDivide ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000880 return r;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000881}