blob: 895cce870e645aa77536c6aaa1bac21909b604eb [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;
joshualittabb52a12015-01-13 15:02:10 -080028 fNvprSupport = kNone_NvprSupport;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000029 fMapBufferType = kNone_MapBufferType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000030 fMaxFragmentUniformVectors = 0;
bsalomon@google.com60da4172012-06-01 19:25:00 +000031 fMaxVertexAttributes = 0;
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +000032 fMaxFragmentTextureUnits = 0;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +000033 fMaxFixedFunctionTextureCoords = 0;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000034 fRGBA8RenderbufferSupport = false;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000035 fBGRAIsInternalFormat = false;
36 fTextureSwizzleSupport = false;
37 fUnpackRowLengthSupport = false;
38 fUnpackFlipYSupport = false;
39 fPackRowLengthSupport = false;
40 fPackFlipYSupport = false;
41 fTextureUsageSupport = false;
42 fTexStorageSupport = false;
robertphillips@google.com443e5a52012-04-30 20:01:21 +000043 fTextureRedSupport = false;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000044 fImagingSupport = false;
robertphillips@google.com1d89c932012-06-27 19:31:41 +000045 fTwoFormatLimit = false;
bsalomon@google.com706f6682012-10-23 14:53:55 +000046 fFragCoordsConventionSupport = false;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000047 fVertexArrayObjectSupport = false;
jvanverth3f801cb2014-12-16 09:49:38 -080048 fES2CompatibilitySupport = false;
bsalomon@google.com96966a52013-02-21 16:34:21 +000049 fUseNonVBOVertexAndIndexDynamicData = false;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000050 fIsCoreProfile = false;
robertphillips@google.com56ce48a2013-10-31 21:44:25 +000051 fFullClearIsFree = false;
commit-bot@chromium.org4362a382014-03-26 19:49:03 +000052 fDropsTileOnZeroDivide = false;
joshualitt58162332014-08-01 06:44:53 -070053 fFBFetchSupport = false;
joshualitt3c1096f2015-01-13 13:13:59 -080054 fFBFetchNeedsCustomOutput = false;
joshualitt58162332014-08-01 06:44:53 -070055 fFBFetchColorName = NULL;
56 fFBFetchExtensionString = NULL;
vbuzinov08b4d292015-04-01 06:29:49 -070057 fFBMixedSamplesSupport = false;
piotaixre4b23142014-10-02 10:57:53 -070058
59 fReadPixelsSupportedCache.reset();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000060}
61
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000062GrGLCaps::GrGLCaps(const GrGLCaps& caps) : GrDrawTargetCaps() {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000063 *this = caps;
64}
65
commit-bot@chromium.orgbeb8b3a2014-04-15 15:37:51 +000066GrGLCaps& GrGLCaps::operator= (const GrGLCaps& caps) {
bsalomon@google.combcce8922013-03-25 15:38:39 +000067 INHERITED::operator=(caps);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000068 fVerifiedColorConfigs = caps.fVerifiedColorConfigs;
69 fStencilFormats = caps.fStencilFormats;
70 fStencilVerifiedColorConfigs = caps.fStencilVerifiedColorConfigs;
krajcevski3217c4a2014-06-09 09:10:04 -070071 fLATCAlias = caps.fLATCAlias;
joshualittabb52a12015-01-13 15:02:10 -080072 fNvprSupport = caps.fNvprSupport;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000073 fMaxFragmentUniformVectors = caps.fMaxFragmentUniformVectors;
bsalomon@google.com60da4172012-06-01 19:25:00 +000074 fMaxVertexAttributes = caps.fMaxVertexAttributes;
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +000075 fMaxFragmentTextureUnits = caps.fMaxFragmentTextureUnits;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +000076 fMaxFixedFunctionTextureCoords = caps.fMaxFixedFunctionTextureCoords;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000077 fMSFBOType = caps.fMSFBOType;
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +000078 fInvalidateFBType = caps.fInvalidateFBType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000079 fMapBufferType = caps.fMapBufferType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000080 fRGBA8RenderbufferSupport = caps.fRGBA8RenderbufferSupport;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000081 fBGRAIsInternalFormat = caps.fBGRAIsInternalFormat;
82 fTextureSwizzleSupport = caps.fTextureSwizzleSupport;
83 fUnpackRowLengthSupport = caps.fUnpackRowLengthSupport;
84 fUnpackFlipYSupport = caps.fUnpackFlipYSupport;
85 fPackRowLengthSupport = caps.fPackRowLengthSupport;
86 fPackFlipYSupport = caps.fPackFlipYSupport;
87 fTextureUsageSupport = caps.fTextureUsageSupport;
88 fTexStorageSupport = caps.fTexStorageSupport;
robertphillips@google.com443e5a52012-04-30 20:01:21 +000089 fTextureRedSupport = caps.fTextureRedSupport;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000090 fImagingSupport = caps.fImagingSupport;
robertphillips@google.com1d89c932012-06-27 19:31:41 +000091 fTwoFormatLimit = caps.fTwoFormatLimit;
bsalomon@google.com706f6682012-10-23 14:53:55 +000092 fFragCoordsConventionSupport = caps.fFragCoordsConventionSupport;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000093 fVertexArrayObjectSupport = caps.fVertexArrayObjectSupport;
jvanverth3f801cb2014-12-16 09:49:38 -080094 fES2CompatibilitySupport = caps.fES2CompatibilitySupport;
bsalomon@google.com96966a52013-02-21 16:34:21 +000095 fUseNonVBOVertexAndIndexDynamicData = caps.fUseNonVBOVertexAndIndexDynamicData;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000096 fIsCoreProfile = caps.fIsCoreProfile;
robertphillips@google.com56ce48a2013-10-31 21:44:25 +000097 fFullClearIsFree = caps.fFullClearIsFree;
commit-bot@chromium.org4362a382014-03-26 19:49:03 +000098 fDropsTileOnZeroDivide = caps.fDropsTileOnZeroDivide;
joshualitt58162332014-08-01 06:44:53 -070099 fFBFetchSupport = caps.fFBFetchSupport;
joshualitt3c1096f2015-01-13 13:13:59 -0800100 fFBFetchNeedsCustomOutput = caps.fFBFetchNeedsCustomOutput;
joshualitt58162332014-08-01 06:44:53 -0700101 fFBFetchColorName = caps.fFBFetchColorName;
102 fFBFetchExtensionString = caps.fFBFetchExtensionString;
vbuzinov08b4d292015-04-01 06:29:49 -0700103 fFBMixedSamplesSupport = caps.fFBMixedSamplesSupport;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000104
105 return *this;
106}
107
commit-bot@chromium.orgf4e67e32014-04-30 01:26:04 +0000108bool GrGLCaps::init(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000109
110 this->reset();
111 if (!ctxInfo.isInitialized()) {
commit-bot@chromium.orgf4e67e32014-04-30 01:26:04 +0000112 return false;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000113 }
114
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000115 GrGLStandard standard = ctxInfo.standard();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000116 GrGLVersion version = ctxInfo.version();
117
bsalomon@google.combcce8922013-03-25 15:38:39 +0000118 /**************************************************************************
119 * Caps specific to GrGLCaps
120 **************************************************************************/
121
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000122 if (kGLES_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000123 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
124 &fMaxFragmentUniformVectors);
125 } else {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000126 SkASSERT(kGL_GrGLStandard == standard);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000127 GrGLint max;
128 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
129 fMaxFragmentUniformVectors = max / 4;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +0000130 if (version >= GR_GL_VER(3, 2)) {
131 GrGLint profileMask;
132 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
133 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
134 }
135 if (!fIsCoreProfile) {
136 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_COORDS, &fMaxFixedFunctionTextureCoords);
137 // Sanity check
138 SkASSERT(fMaxFixedFunctionTextureCoords > 0 && fMaxFixedFunctionTextureCoords < 128);
139 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000140 }
bsalomon@google.com60da4172012-06-01 19:25:00 +0000141 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000142 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &fMaxFragmentTextureUnits);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000143
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000144 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000145 fRGBA8RenderbufferSupport = true;
146 } else {
commit-bot@chromium.orgc5dffe42013-08-20 15:25:21 +0000147 fRGBA8RenderbufferSupport = version >= GR_GL_VER(3,0) ||
148 ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000149 ctxInfo.hasExtension("GL_ARM_rgba8");
150 }
151
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000152 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000153 fTextureSwizzleSupport = version >= GR_GL_VER(3,3) ||
154 ctxInfo.hasExtension("GL_ARB_texture_swizzle");
155 } else {
commit-bot@chromium.org6364b5e2013-08-20 20:22:52 +0000156 fTextureSwizzleSupport = version >= GR_GL_VER(3,0);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000157 }
158
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000159 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000160 fUnpackRowLengthSupport = true;
161 fUnpackFlipYSupport = false;
162 fPackRowLengthSupport = true;
163 fPackFlipYSupport = false;
164 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000165 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
166 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000167 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000168 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
169 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000170 fPackFlipYSupport =
171 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
172 }
173
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000174 fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000175 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
176
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000177 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org7a434a22013-08-21 14:01:56 +0000178 // The EXT version can apply to either GL or GLES.
179 fTexStorageSupport = version >= GR_GL_VER(4,2) ||
180 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
181 ctxInfo.hasExtension("GL_EXT_texture_storage");
182 } else {
183 // Qualcomm Adreno drivers appear to have issues with texture storage.
184 fTexStorageSupport = (version >= GR_GL_VER(3,0) &&
185 kQualcomm_GrGLVendor != ctxInfo.vendor()) ||
186 ctxInfo.hasExtension("GL_EXT_texture_storage");
187 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000188
hendrikwa0d5ad72014-12-02 07:30:30 -0800189 // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support GL_RED
190 // and GL_RG on FBO textures.
191 if (!ctxInfo.isMesa()) {
192 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000193 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
194 ctxInfo.hasExtension("GL_ARB_texture_rg");
hendrikwa0d5ad72014-12-02 07:30:30 -0800195 } else {
196 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
197 ctxInfo.hasExtension("GL_EXT_texture_rg");
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000198 }
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000199 }
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000200 fImagingSupport = kGL_GrGLStandard == standard &&
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000201 ctxInfo.hasExtension("GL_ARB_imaging");
202
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000203 // ES 2 only guarantees RGBA/uchar + one other format/type combo for
204 // ReadPixels. The other format has to checked at run-time since it
205 // can change based on which render target is bound
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000206 fTwoFormatLimit = kGLES_GrGLStandard == standard;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000207
rmistry63a9f842014-10-17 06:07:08 -0700208 // Frag Coords Convention support is not part of ES
bsalomon@google.com706f6682012-10-23 14:53:55 +0000209 // Known issue on at least some Intel platforms:
210 // http://code.google.com/p/skia/issues/detail?id=946
rmistry63a9f842014-10-17 06:07:08 -0700211 if (kIntel_GrGLVendor != ctxInfo.vendor() && kGLES_GrGLStandard != standard) {
bsalomon@google.com706f6682012-10-23 14:53:55 +0000212 fFragCoordsConventionSupport = ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
213 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions");
214 }
215
bsalomon@google.com3012ded2013-02-22 16:44:04 +0000216 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
217 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
218 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
219 // limit this decision to specific GPU families rather than basing it on the vendor alone.
220 if (!GR_GL_MUST_USE_VBO &&
bsalomoned82c4e2014-09-02 07:54:47 -0700221 (kARM_GrGLVendor == ctxInfo.vendor() ||
222 kImagination_GrGLVendor == ctxInfo.vendor() ||
223 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
bsalomon@google.com96966a52013-02-21 16:34:21 +0000224 fUseNonVBOVertexAndIndexDynamicData = true;
225 }
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000226
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000227 if ((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
skia.committer@gmail.coma9157722014-04-03 03:04:26 +0000228 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000229 ctxInfo.hasExtension("GL_ARB_invalidate_subdata")) {
230 fDiscardRenderTargetSupport = true;
231 fInvalidateFBType = kInvalidate_InvalidateFBType;
232 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
233 fDiscardRenderTargetSupport = true;
234 fInvalidateFBType = kDiscard_InvalidateFBType;
235 }
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000236
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000237 if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) {
238 fFullClearIsFree = true;
239 }
240
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000241 if (kGL_GrGLStandard == standard) {
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000242 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
tomhudson612e9262014-11-24 11:22:36 -0800243 ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
244 ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000245 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000246 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
247 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000248 }
249
jvanverth3f801cb2014-12-16 09:49:38 -0800250 if (kGL_GrGLStandard == standard) {
251 fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
252 }
253 else {
254 fES2CompatibilitySupport = true;
255 }
256
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000257 if (kGLES_GrGLStandard == standard) {
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000258 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
joshualitt3c1096f2015-01-13 13:13:59 -0800259 fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
joshualitt58162332014-08-01 06:44:53 -0700260 fFBFetchSupport = true;
261 fFBFetchColorName = "gl_LastFragData[0]";
262 fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000263 } else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
joshualitt3c1096f2015-01-13 13:13:59 -0800264 // Actually, we haven't seen an ES3.0 device with this extension yet, so we don't know
265 fFBFetchNeedsCustomOutput = false;
joshualitt58162332014-08-01 06:44:53 -0700266 fFBFetchSupport = true;
267 fFBFetchColorName = "gl_LastFragData[0]";
268 fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
269 } else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
270 // The arm extension also requires an additional flag which we will set onResetContext
joshualitt3c1096f2015-01-13 13:13:59 -0800271 fFBFetchNeedsCustomOutput = false;
joshualitt58162332014-08-01 06:44:53 -0700272 fFBFetchSupport = true;
273 fFBFetchColorName = "gl_LastFragColorARM";
274 fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000275 }
276 }
277
commit-bot@chromium.org4362a382014-03-26 19:49:03 +0000278 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
279 fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
280
robertphillips@google.com6177e692013-02-28 20:16:25 +0000281 this->initFSAASupport(ctxInfo, gli);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000282 this->initStencilFormats(ctxInfo);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000283
284 /**************************************************************************
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000285 * GrDrawTargetCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000286 **************************************************************************/
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000287 if (kGL_GrGLStandard == standard) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000288 // we could also look for GL_ATI_separate_stencil extension or
289 // GL_EXT_stencil_two_side but they use different function signatures
290 // than GL2.0+ (and than each other).
291 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
292 // supported on GL 1.4 and higher or by extension
293 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
294 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
295 } else {
296 // ES 2 has two sided stencil and stencil wrap
297 fTwoSidedStencilSupport = true;
298 fStencilWrapOpsSupport = true;
299 }
300
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000301 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000302 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
303 // extension includes glMapBuffer.
304 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
305 fMapBufferFlags |= kSubset_MapFlag;
306 fMapBufferType = kMapBufferRange_MapBufferType;
307 } else {
308 fMapBufferType = kMapBuffer_MapBufferType;
309 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000310 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000311 // Unextended GLES2 doesn't have any buffer mapping.
312 fMapBufferFlags = kNone_MapBufferType;
313 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
314 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
315 fMapBufferType = kChromium_MapBufferType;
316 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
317 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
318 fMapBufferType = kMapBufferRange_MapBufferType;
319 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
320 fMapBufferFlags = kCanMap_MapFlag;
321 fMapBufferType = kMapBuffer_MapBufferType;
322 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000323 }
324
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000325 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000326 SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) ||
327 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two"));
328 fNPOTTextureTileSupport = true;
329 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000330 } else {
331 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000332 // ES3 has no limitations.
333 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
334 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000335 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
336 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
337 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
338 // to alllow arbitrary wrap modes, however.
339 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000340 }
341
bsalomon@google.combcce8922013-03-25 15:38:39 +0000342 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
343 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
344 // Our render targets are always created with textures as the color
345 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000346 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000347
kkinnunen32b9a3b2014-07-02 22:56:35 -0700348 fPathRenderingSupport = ctxInfo.hasExtension("GL_NV_path_rendering");
349
350 if (fPathRenderingSupport) {
351 if (kGL_GrGLStandard == standard) {
352 // We need one of the two possible texturing methods: using fixed function pipeline
353 // (PathTexGen, texcoords, ...) or using the newer NVPR API additions that support
354 // setting individual fragment inputs with ProgramPathFragmentInputGen. The API
355 // additions are detected by checking the existence of the function. Eventually we may
356 // choose to remove the fixed function codepath.
357 // Set fMaxFixedFunctionTextureCoords = 0 here if you want to force
358 // ProgramPathFragmentInputGen usage on desktop.
359 fPathRenderingSupport = ctxInfo.hasExtension("GL_EXT_direct_state_access") &&
360 (fMaxFixedFunctionTextureCoords > 0 ||
361 ((ctxInfo.version() >= GR_GL_VER(4,3) ||
362 ctxInfo.hasExtension("GL_ARB_program_interface_query")) &&
bsalomon49f085d2014-09-05 13:34:00 -0700363 gli->fFunctions.fProgramPathFragmentInputGen));
joshualittabb52a12015-01-13 15:02:10 -0800364 if (fPathRenderingSupport) {
365 fNvprSupport = gli->fFunctions.fProgramPathFragmentInputGen ? kNormal_NvprSupport :
366 kLegacy_NvprSupport;
367 }
kkinnunen32b9a3b2014-07-02 22:56:35 -0700368 } else {
kkinnunenec56e452014-08-25 22:21:16 -0700369 fPathRenderingSupport = ctxInfo.version() >= GR_GL_VER(3,1);
joshualittabb52a12015-01-13 15:02:10 -0800370 fNvprSupport = fPathRenderingSupport ? kNormal_NvprSupport : kNone_NvprSupport;
kkinnunen32b9a3b2014-07-02 22:56:35 -0700371 }
joshualittabb52a12015-01-13 15:02:10 -0800372 } else {
373 fNvprSupport = kNone_NvprSupport;
kkinnunen32b9a3b2014-07-02 22:56:35 -0700374 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000375
vbuzinov08b4d292015-04-01 06:29:49 -0700376 fFBMixedSamplesSupport = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples");
377
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000378 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
379
joshualitt58162332014-08-01 06:44:53 -0700380 // For now these two are equivalent but we could have dst read in shader via some other method
381 fDstReadInShaderSupport = fFBFetchSupport;
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000382
383 // Disable scratch texture reuse on Mali and Adreno devices
384 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() &&
385 kQualcomm_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000386
bsalomon@google.combcce8922013-03-25 15:38:39 +0000387 // Enable supported shader-related caps
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000388 if (kGL_GrGLStandard == standard) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000389 fDualSourceBlendingSupport = ctxInfo.version() >= GR_GL_VER(3,3) ||
390 ctxInfo.hasExtension("GL_ARB_blend_func_extended");
391 fShaderDerivativeSupport = true;
392 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
393 fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3,2) &&
394 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
395 } else {
rmistry63a9f842014-10-17 06:07:08 -0700396 fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
397 ctxInfo.hasExtension("GL_OES_standard_derivatives");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000398 }
399
bsalomon@google.com347c3822013-05-01 20:10:01 +0000400 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000401 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount);
402 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
403 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount);
404 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000405
bsalomon63b21962014-11-05 07:05:34 -0800406 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
bsalomone702d972015-01-29 10:07:32 -0800407 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
bsalomona8fcea02015-02-13 09:00:39 -0800408 kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
bsalomon63b21962014-11-05 07:05:34 -0800409 fUseDrawInsteadOfClear = true;
410 }
411
bsalomond08ea5f2015-02-20 06:58:13 -0800412 if (kGL_GrGLStandard == standard) {
413 // ARB allows mixed size FBO attachments, EXT does not.
414 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
415 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
416 fOversizedStencilSupport = true;
417 } else {
418 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
419 }
420 } else {
421 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
422 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
423 }
424
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000425 this->initConfigTexturableTable(ctxInfo, gli);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000426 this->initConfigRenderableTable(ctxInfo);
commit-bot@chromium.orgf4e67e32014-04-30 01:26:04 +0000427
bsalomon17168df2014-12-09 09:00:49 -0800428 this->initShaderPrecisionTable(ctxInfo, gli);
429
commit-bot@chromium.orgf4e67e32014-04-30 01:26:04 +0000430 return true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000431}
432
433void GrGLCaps::initConfigRenderableTable(const GrGLContextInfo& ctxInfo) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000434 // OpenGL < 3.0
435 // no support for render targets unless the GL_ARB_framebuffer_object
436 // extension is supported (in which case we get ALPHA, RED, RG, RGB,
437 // RGBA (ALPHA8, RGBA4, RGBA8) for OpenGL > 1.1). Note that we
438 // probably don't get R8 in this case.
439
440 // OpenGL 3.0
441 // base color renderable: ALPHA, RED, RG, RGB, and RGBA
442 // sized derivatives: ALPHA8, R8, RGBA4, RGBA8
443
444 // >= OpenGL 3.1
445 // base color renderable: RED, RG, RGB, and RGBA
446 // sized derivatives: R8, RGBA4, RGBA8
447 // if the GL_ARB_compatibility extension is supported then we get back
448 // support for GL_ALPHA and ALPHA8
449
450 // GL_EXT_bgra adds BGRA render targets to any version
451
452 // ES 2.0
453 // color renderable: RGBA4, RGB5_A1, RGB565
454 // GL_EXT_texture_rg adds support for R8 as a color render target
455 // GL_OES_rgb8_rgba8 and/or GL_ARM_rgba8 adds support for RGBA8
456 // GL_EXT_texture_format_BGRA8888 and/or GL_APPLE_texture_format_BGRA8888 added BGRA support
457
458 // ES 3.0
459 // Same as ES 2.0 except R8 and RGBA8 are supported without extensions (the functions called
460 // below already account for this).
461
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000462 GrGLStandard standard = ctxInfo.standard();
463
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000464 enum {
465 kNo_MSAA = 0,
466 kYes_MSAA = 1,
467 };
468
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000469 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000470 // Post 3.0 we will get R8
471 // Prior to 3.0 we will get ALPHA8 (with GL_ARB_framebuffer_object)
472 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
473 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000474 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = true;
475 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000476 }
477 } else {
478 // On ES we can only hope for R8
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000479 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = fTextureRedSupport;
480 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = fTextureRedSupport;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000481 }
482
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000483 if (kGL_GrGLStandard != standard) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000484 // only available in ES
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000485 fConfigRenderSupport[kRGB_565_GrPixelConfig][kNo_MSAA] = true;
486 fConfigRenderSupport[kRGB_565_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000487 }
488
489 // we no longer support 444 as a render target
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000490 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kNo_MSAA] = false;
491 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kYes_MSAA] = false;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000492
493 if (this->fRGBA8RenderbufferSupport) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000494 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
commit-bot@chromium.orgda3d69c2013-10-28 15:09:13 +0000495 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000496 }
497
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000498 if (this->isConfigTexturable(kBGRA_8888_GrPixelConfig)) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000499 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kNo_MSAA] = true;
500 // The GL_EXT_texture_format_BGRA8888 extension does not add BGRA to the list of
501 // configs that are color-renderable and can be passed to glRenderBufferStorageMultisample.
commit-bot@chromium.org4256d242013-10-17 16:29:41 +0000502 // Chromium may have an extension to allow BGRA renderbuffers to work on desktop platforms.
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +0000503 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888")) {
commit-bot@chromium.org4256d242013-10-17 16:29:41 +0000504 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] = true;
505 } else {
506 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] =
507 !fBGRAIsInternalFormat || !this->usesMSAARenderBuffers();
508 }
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000509 }
510
jvanverthfa1e8a72014-12-22 08:31:49 -0800511 if (this->fRGBA8RenderbufferSupport && this->isConfigTexturable(kSRGBA_8888_GrPixelConfig)) {
512 if (kGL_GrGLStandard == standard) {
513 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
514 ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
515 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
516 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
517 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
518 }
519 } else {
520 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
521 ctxInfo.hasExtension("GL_EXT_sRGB")) {
522 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
523 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
524 }
525 }
526 }
527
joshualittee5da552014-07-16 13:32:56 -0700528 if (this->isConfigTexturable(kRGBA_float_GrPixelConfig)) {
jvanverth28f9c602014-12-05 13:06:35 -0800529 if (kGL_GrGLStandard == standard) {
jvanvertha60b2ea2014-12-12 05:58:06 -0800530 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true;
jvanverth28f9c602014-12-05 13:06:35 -0800531 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = true;
532 } else {
jvanvertha60b2ea2014-12-12 05:58:06 -0800533 if (ctxInfo.hasExtension("GL_EXT_color_buffer_float")) {
534 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true;
535 } else {
536 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = false;
537 }
538 // for now we don't support floating point MSAA on ES
jvanverth28f9c602014-12-05 13:06:35 -0800539 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = false;
540 }
joshualittee5da552014-07-16 13:32:56 -0700541 }
542
jvanverth28f9c602014-12-05 13:06:35 -0800543 if (this->isConfigTexturable(kAlpha_half_GrPixelConfig)) {
jvanverth28f9c602014-12-05 13:06:35 -0800544 if (kGL_GrGLStandard == standard) {
jvanvertha60b2ea2014-12-12 05:58:06 -0800545 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
jvanverth28f9c602014-12-05 13:06:35 -0800546 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = true;
jvanverth1334c212014-12-18 05:44:55 -0800547 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
548 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
549 // for now we don't support floating point MSAA on ES
550 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = false;
jvanverth28f9c602014-12-05 13:06:35 -0800551 } else {
jvanverth1334c212014-12-18 05:44:55 -0800552 if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float") && fTextureRedSupport) {
553 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
554 } else {
555 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = false;
556 }
557 // for now we don't support floating point MSAA on ES
jvanverth28f9c602014-12-05 13:06:35 -0800558 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = false;
559 }
560 }
561
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000562 // If we don't support MSAA then undo any places above where we set a config as renderable with
563 // msaa.
564 if (kNone_MSFBOType == fMSFBOType) {
565 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
566 fConfigRenderSupport[i][kYes_MSAA] = false;
567 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000568 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000569}
570
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000571void GrGLCaps::initConfigTexturableTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000572 GrGLStandard standard = ctxInfo.standard();
573 GrGLVersion version = ctxInfo.version();
574
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000575 // Base texture support
576 fConfigTextureSupport[kAlpha_8_GrPixelConfig] = true;
577 fConfigTextureSupport[kRGB_565_GrPixelConfig] = true;
578 fConfigTextureSupport[kRGBA_4444_GrPixelConfig] = true;
579 fConfigTextureSupport[kRGBA_8888_GrPixelConfig] = true;
580
581 // Check for 8-bit palette..
582 GrGLint numFormats;
583 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
584 if (numFormats) {
585 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
586 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
587 for (int i = 0; i < numFormats; ++i) {
588 if (GR_GL_PALETTE8_RGBA8 == formats[i]) {
589 fConfigTextureSupport[kIndex_8_GrPixelConfig] = true;
590 break;
591 }
592 }
593 }
594
595 // Check for BGRA
596 if (kGL_GrGLStandard == standard) {
597 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] =
598 version >= GR_GL_VER(1,2) || ctxInfo.hasExtension("GL_EXT_bgra");
599 } else {
600 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
601 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
602 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
603 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
604 fBGRAIsInternalFormat = true;
605 }
606 SkASSERT(fConfigTextureSupport[kBGRA_8888_GrPixelConfig] ||
607 kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig);
608 }
609
jvanverthfa1e8a72014-12-22 08:31:49 -0800610 // Check for sRGBA
611 if (kGL_GrGLStandard == standard) {
612 fConfigTextureSupport[kSRGBA_8888_GrPixelConfig] =
613 (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_texture_sRGB"));
614 } else {
615 fConfigTextureSupport[kSRGBA_8888_GrPixelConfig] =
616 (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB"));
617 }
618
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000619 // Compressed texture support
620
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000621 // glCompressedTexImage2D is available on all OpenGL ES devices...
622 // however, it is only available on standard OpenGL after version 1.3
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000623 bool hasCompressTex2D = (kGL_GrGLStandard != standard || version >= GR_GL_VER(1, 3));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000624
krajcevski786978162014-07-30 11:25:44 -0700625 fCompressedTexSubImageSupport =
bsalomon49f085d2014-09-05 13:34:00 -0700626 hasCompressTex2D && (gli->fFunctions.fCompressedTexSubImage2D);
krajcevski786978162014-07-30 11:25:44 -0700627
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000628 // Check for ETC1
629 bool hasETC1 = false;
630
631 // First check version for support
632 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000633 hasETC1 = hasCompressTex2D &&
joshualittee5da552014-07-16 13:32:56 -0700634 (version >= GR_GL_VER(4, 3) ||
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000635 ctxInfo.hasExtension("GL_ARB_ES3_compatibility"));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000636 } else {
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000637 hasETC1 = hasCompressTex2D &&
638 (version >= GR_GL_VER(3, 0) ||
639 ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") ||
640 // ETC2 is a superset of ETC1, so we can just check for that, too.
641 (ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") &&
642 ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture")));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000643 }
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000644 fConfigTextureSupport[kETC1_GrPixelConfig] = hasETC1;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000645
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000646 // Check for LATC under its various forms
647 LATCAlias alias = kLATC_LATCAlias;
648 bool hasLATC = hasCompressTex2D &&
649 (ctxInfo.hasExtension("GL_EXT_texture_compression_latc") ||
650 ctxInfo.hasExtension("GL_NV_texture_compression_latc"));
651
652 // Check for RGTC
653 if (!hasLATC) {
654 // If we're using OpenGL 3.0 or later, then we have RGTC, an identical compression format.
655 if (kGL_GrGLStandard == standard) {
656 hasLATC = version >= GR_GL_VER(3, 0);
657 }
658
659 if (!hasLATC) {
660 hasLATC =
661 ctxInfo.hasExtension("GL_EXT_texture_compression_rgtc") ||
662 ctxInfo.hasExtension("GL_ARB_texture_compression_rgtc");
663 }
664
665 if (hasLATC) {
666 alias = kRGTC_LATCAlias;
667 }
668 }
669
670 // Check for 3DC
671 if (!hasLATC) {
672 hasLATC = ctxInfo.hasExtension("GL_AMD_compressed_3DC_texture");
673 if (hasLATC) {
674 alias = k3DC_LATCAlias;
675 }
676 }
677
678 fConfigTextureSupport[kLATC_GrPixelConfig] = hasLATC;
679 fLATCAlias = alias;
krajcevski238b4562014-06-30 09:09:22 -0700680
krajcevskib3abe902014-07-30 13:08:11 -0700681 // Check for R11_EAC ... We don't support R11_EAC on desktop, as most
682 // cards default to decompressing the textures in the driver, and is
683 // generally slower.
684 if (kGL_GrGLStandard != standard) {
krajcevski238b4562014-06-30 09:09:22 -0700685 fConfigTextureSupport[kR11_EAC_GrPixelConfig] = version >= GR_GL_VER(3, 0);
686 }
joshualittee5da552014-07-16 13:32:56 -0700687
krajcevski7ef21622014-07-16 15:21:13 -0700688 // Check for ASTC
piotaixre4b23142014-10-02 10:57:53 -0700689 fConfigTextureSupport[kASTC_12x12_GrPixelConfig] =
krajcevski7ef21622014-07-16 15:21:13 -0700690 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_hdr") ||
691 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_ldr") ||
692 ctxInfo.hasExtension("GL_OES_texture_compression_astc");
693
joshualittee5da552014-07-16 13:32:56 -0700694 // Check for floating point texture support
695 // NOTE: We disallow floating point textures on ES devices if linear
696 // filtering modes are not supported. This is for simplicity, but a more
697 // granular approach is possible. Coincidentally, floating point textures became part of
698 // the standard in ES3.1 / OGL 3.1, hence the shorthand
699 bool hasFPTextures = version >= GR_GL_VER(3, 1);
700 if (!hasFPTextures) {
701 hasFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") ||
jvanvertha60b2ea2014-12-12 05:58:06 -0800702 (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
joshualittee5da552014-07-16 13:32:56 -0700703 ctxInfo.hasExtension("GL_OES_texture_float"));
704 }
705 fConfigTextureSupport[kRGBA_float_GrPixelConfig] = hasFPTextures;
jvanverth28f9c602014-12-05 13:06:35 -0800706
707 // Check for fp16 texture support
708 // NOTE: We disallow floating point textures on ES devices if linear
709 // filtering modes are not supported. This is for simplicity, but a more
710 // granular approach is possible. Coincidentally, 16-bit floating point textures became part of
711 // the standard in ES3.1 / OGL 3.1, hence the shorthand
712 bool hasHalfFPTextures = version >= GR_GL_VER(3, 1);
713 if (!hasHalfFPTextures) {
714 hasHalfFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") ||
jvanverth1334c212014-12-18 05:44:55 -0800715 (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
716 ctxInfo.hasExtension("GL_OES_texture_half_float"));
jvanverth28f9c602014-12-05 13:06:35 -0800717 }
jvanverth1334c212014-12-18 05:44:55 -0800718 fConfigTextureSupport[kAlpha_half_GrPixelConfig] = hasHalfFPTextures;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000719}
720
piotaixre4b23142014-10-02 10:57:53 -0700721bool GrGLCaps::doReadPixelsSupported(const GrGLInterface* intf,
722 GrGLenum format,
723 GrGLenum type) const {
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000724 if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) {
725 // ES 2 guarantees this format is supported
robertphillips@google.comeca2dfb2012-06-27 20:13:49 +0000726 return true;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000727 }
728
729 if (!fTwoFormatLimit) {
730 // not limited by ES 2's constraints
731 return true;
732 }
733
bsalomon@google.com548a4332012-07-11 19:45:22 +0000734 GrGLint otherFormat = GR_GL_RGBA;
735 GrGLint otherType = GR_GL_UNSIGNED_BYTE;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000736
737 // The other supported format/type combo supported for ReadPixels
738 // can change based on which render target is bound
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000739 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000740 GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT,
741 &otherFormat);
742
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000743 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000744 GR_GL_IMPLEMENTATION_COLOR_READ_TYPE,
745 &otherType);
746
bsalomon@google.com548a4332012-07-11 19:45:22 +0000747 return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000748}
749
piotaixre4b23142014-10-02 10:57:53 -0700750bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,
751 GrGLenum format,
752 GrGLenum type,
753 GrGLenum currFboFormat) const {
mtklein2aa1f7e2015-02-20 12:35:32 -0800754 ReadPixelsSupportedFormat key = {format, type, currFboFormat};
755 if (const bool* supported = fReadPixelsSupportedCache.find(key)) {
756 return *supported;
piotaixre4b23142014-10-02 10:57:53 -0700757 }
mtklein2aa1f7e2015-02-20 12:35:32 -0800758 bool supported = this->doReadPixelsSupported(intf, format, type);
759 fReadPixelsSupportedCache.set(key, supported);
760 return supported;
piotaixre4b23142014-10-02 10:57:53 -0700761}
762
robertphillips@google.com6177e692013-02-28 20:16:25 +0000763void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000764
765 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000766 if (kGL_GrGLStandard != ctxInfo.standard()) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000767 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
768 // ES3 driver bugs on at least one device with a tiled GPU (N10).
769 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
770 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
771 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
772 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
commit-bot@chromium.org92b78842014-01-16 20:49:46 +0000773 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000774 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType;
775 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
776 // chrome's extension is equivalent to the EXT msaa
777 // and fbo_blit extensions.
778 fMSFBOType = kDesktop_EXT_MSFBOType;
779 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
780 fMSFBOType = kES_Apple_MSFBOType;
781 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000782 } else {
783 if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
784 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000785 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000786 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
787 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000788 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000789 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000790 }
791}
792
793namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -0700794const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000795}
796
797void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
798
799 // Build up list of legal stencil formats (though perhaps not supported on
800 // the particular gpu/driver) from most preferred to least.
801
802 // these consts are in order of most preferred to least preferred
803 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
804
805 static const StencilFormat
806 // internal Format stencil bits total bits packed?
807 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
808 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
809 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
810 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000811 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000812 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
813
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000814 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000815 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000816 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000817 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
818 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
819
820 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
821 // require FBO support we can expect these are legal formats and don't
822 // check. These also all support the unsized GL_STENCIL_INDEX.
823 fStencilFormats.push_back() = gS8;
824 fStencilFormats.push_back() = gS16;
825 if (supportsPackedDS) {
826 fStencilFormats.push_back() = gD24S8;
827 }
828 fStencilFormats.push_back() = gS4;
829 if (supportsPackedDS) {
830 fStencilFormats.push_back() = gDS;
831 }
832 } else {
833 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
834 // for other formats.
835 // ES doesn't support using the unsized format.
836
837 fStencilFormats.push_back() = gS8;
838 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +0000839 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
840 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000841 fStencilFormats.push_back() = gD24S8;
842 }
843 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
844 fStencilFormats.push_back() = gS4;
845 }
846 }
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000847 SkASSERT(0 == fStencilVerifiedColorConfigs.count());
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000848 fStencilVerifiedColorConfigs.push_back_n(fStencilFormats.count());
849}
850
bsalomonc0bd6482014-12-09 10:04:14 -0800851static GrGLenum precision_to_gl_float_type(GrSLPrecision p) {
bsalomon17168df2014-12-09 09:00:49 -0800852 switch (p) {
bsalomonc0bd6482014-12-09 10:04:14 -0800853 case kLow_GrSLPrecision:
bsalomon17168df2014-12-09 09:00:49 -0800854 return GR_GL_LOW_FLOAT;
bsalomonc0bd6482014-12-09 10:04:14 -0800855 case kMedium_GrSLPrecision:
bsalomon17168df2014-12-09 09:00:49 -0800856 return GR_GL_MEDIUM_FLOAT;
bsalomonc0bd6482014-12-09 10:04:14 -0800857 case kHigh_GrSLPrecision:
bsalomon17168df2014-12-09 09:00:49 -0800858 return GR_GL_HIGH_FLOAT;
859 }
860 SkFAIL("Unknown precision.");
861 return -1;
862}
863
864static GrGLenum shader_type_to_gl_shader(GrShaderType type) {
865 switch (type) {
866 case kVertex_GrShaderType:
867 return GR_GL_VERTEX_SHADER;
868 case kGeometry_GrShaderType:
869 return GR_GL_GEOMETRY_SHADER;
870 case kFragment_GrShaderType:
871 return GR_GL_FRAGMENT_SHADER;
872 }
873 SkFAIL("Unknown shader type.");
874 return -1;
875}
876
877void GrGLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* intf) {
878 if (kGLES_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(4,1) ||
879 ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
880 for (int s = 0; s < kGrShaderTypeCount; ++s) {
bsalomon06194c52014-12-09 11:16:12 -0800881 if (kGeometry_GrShaderType != s) {
bsalomon17168df2014-12-09 09:00:49 -0800882 GrShaderType shaderType = static_cast<GrShaderType>(s);
883 GrGLenum glShader = shader_type_to_gl_shader(shaderType);
884 PrecisionInfo* first = NULL;
885 fShaderPrecisionVaries = false;
bsalomonc0bd6482014-12-09 10:04:14 -0800886 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
887 GrSLPrecision precision = static_cast<GrSLPrecision>(p);
bsalomon17168df2014-12-09 09:00:49 -0800888 GrGLenum glPrecision = precision_to_gl_float_type(precision);
889 GrGLint range[2];
890 GrGLint bits;
891 GR_GL_GetShaderPrecisionFormat(intf, glShader, glPrecision, range, &bits);
892 if (bits) {
893 fFloatPrecisions[s][p].fLogRangeLow = range[0];
894 fFloatPrecisions[s][p].fLogRangeHigh = range[1];
895 fFloatPrecisions[s][p].fBits = bits;
896 if (!first) {
897 first = &fFloatPrecisions[s][p];
898 } else if (!fShaderPrecisionVaries) {
899 fShaderPrecisionVaries = (*first != fFloatPrecisions[s][p]);
900 }
901 }
902 }
903 }
904 }
905 } else {
906 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
907 fShaderPrecisionVaries = false;
908 for (int s = 0; s < kGrShaderTypeCount; ++s) {
bsalomon06194c52014-12-09 11:16:12 -0800909 if (kGeometry_GrShaderType != s) {
bsalomonc0bd6482014-12-09 10:04:14 -0800910 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
bsalomon17168df2014-12-09 09:00:49 -0800911 fFloatPrecisions[s][p].fLogRangeLow = 127;
912 fFloatPrecisions[s][p].fLogRangeHigh = 127;
913 fFloatPrecisions[s][p].fBits = 23;
914 }
915 }
916 }
917 }
bsalomon06194c52014-12-09 11:16:12 -0800918 // GetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Assume they're
919 // the same as the vertex shader. Only fragment shaders were ever allowed to omit support for
920 // highp. GS was added after GetShaderPrecisionFormat was added to the list of features that
921 // are recommended against.
922 if (fGeometryShaderSupport) {
923 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
924 fFloatPrecisions[kGeometry_GrShaderType][p] = fFloatPrecisions[kVertex_GrShaderType][p];
925 }
926 }
bsalomon17168df2014-12-09 09:00:49 -0800927}
928
929
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000930void GrGLCaps::markColorConfigAndStencilFormatAsVerified(
931 GrPixelConfig config,
egdaniel8dc7c3a2015-04-16 11:22:42 -0700932 const GrGLStencilAttachment::Format& format) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000933#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
934 return;
935#endif
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000936 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
937 SkASSERT(fStencilFormats.count() == fStencilVerifiedColorConfigs.count());
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000938 int count = fStencilFormats.count();
939 // we expect a really small number of possible formats so linear search
940 // should be OK
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000941 SkASSERT(count < 16);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000942 for (int i = 0; i < count; ++i) {
943 if (format.fInternalFormat ==
944 fStencilFormats[i].fInternalFormat) {
945 fStencilVerifiedColorConfigs[i].markVerified(config);
946 return;
947 }
948 }
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000949 SkFAIL("Why are we seeing a stencil format that "
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000950 "GrGLCaps doesn't know about.");
951}
952
953bool GrGLCaps::isColorConfigAndStencilFormatVerified(
954 GrPixelConfig config,
egdaniel8dc7c3a2015-04-16 11:22:42 -0700955 const GrGLStencilAttachment::Format& format) const {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000956#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
957 return false;
958#endif
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000959 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000960 int count = fStencilFormats.count();
961 // we expect a really small number of possible formats so linear search
962 // should be OK
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000963 SkASSERT(count < 16);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000964 for (int i = 0; i < count; ++i) {
965 if (format.fInternalFormat ==
966 fStencilFormats[i].fInternalFormat) {
967 return fStencilVerifiedColorConfigs[i].isVerified(config);
968 }
969 }
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000970 SkFAIL("Why are we seeing a stencil format that "
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000971 "GLCaps doesn't know about.");
972 return false;
973}
974
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000975SkString GrGLCaps::dump() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000976
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000977 SkString r = INHERITED::dump();
bsalomon@google.combcce8922013-03-25 15:38:39 +0000978
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000979 r.appendf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000980 for (int i = 0; i < fStencilFormats.count(); ++i) {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000981 r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000982 i,
983 fStencilFormats[i].fStencilBits,
984 fStencilFormats[i].fTotalBits);
985 }
986
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000987 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000988 "None",
989 "ARB",
990 "EXT",
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000991 "ES 3.0",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000992 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +0000993 "IMG MS To Texture",
994 "EXT MS To Texture",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000995 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000996 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
997 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
998 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000999 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType);
1000 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType);
1001 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType);
1002 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +00001003 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001004
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001005 static const char* kInvalidateFBTypeStr[] = {
1006 "None",
1007 "Discard",
1008 "Invalidate",
1009 };
1010 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
1011 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
1012 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
1013 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001014
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001015 static const char* kMapBufferTypeStr[] = {
1016 "None",
1017 "MapBuffer",
1018 "MapBufferRange",
1019 "Chromium",
1020 };
1021 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
1022 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
1023 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
1024 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
1025 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
1026
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001027 r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001028 r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
joshualitt58162332014-08-01 06:44:53 -07001029 r.appendf("FB Fetch Support: %s\n", (fFBFetchSupport ? "YES" : "NO"));
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001030 r.appendf("Invalidate FB Type: %s\n", kInvalidateFBTypeStr[fInvalidateFBType]);
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001031 r.appendf("Map Buffer Type: %s\n", kMapBufferTypeStr[fMapBufferType]);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001032 r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
1033 r.appendf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits);
commit-bot@chromium.org0a6fe712014-04-23 19:26:26 +00001034 if (!fIsCoreProfile) {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001035 r.appendf("Max Fixed Function Texture Coords: %d\n", fMaxFixedFunctionTextureCoords);
commit-bot@chromium.org3628ad92013-08-30 19:43:47 +00001036 }
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001037 r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
1038 r.appendf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001039 r.appendf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO"));
1040 r.appendf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO"));
1041 r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
1042 r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
1043 r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
1044 r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +00001045
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001046 r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
1047 r.appendf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
1048 r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
1049 r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
1050 r.appendf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO"));
1051 r.appendf("Fragment coord conventions support: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +00001052 (fFragCoordsConventionSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001053 r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
1054 r.appendf("Use non-VBO for dynamic data: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +00001055 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001056 r.appendf("Full screen clear is free: %s\n", (fFullClearIsFree ? "YES" : "NO"));
commit-bot@chromium.org4362a382014-03-26 19:49:03 +00001057 r.appendf("Drops tile on zero divide: %s\n", (fDropsTileOnZeroDivide ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001058 return r;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001059}