blob: b7273a08b12aec313e8f4ec06aeb6cbabdceeeab [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#ifndef GrGLCaps_DEFINED
10#define GrGLCaps_DEFINED
11
bsalomon1aa20292016-01-22 08:16:09 -080012#include <functional>
13
bsalomoncdee0092016-01-08 13:20:12 -080014#include "GrCaps.h"
egdaniel8dc7c3a2015-04-16 11:22:42 -070015#include "GrGLStencilAttachment.h"
bsalomoncdee0092016-01-08 13:20:12 -080016#include "GrSwizzle.h"
piotaixre4b23142014-10-02 10:57:53 -070017#include "SkChecksum.h"
mtklein2aa1f7e2015-02-20 12:35:32 -080018#include "SkTHash.h"
robertphillips@google.coma2d71482012-08-01 20:08:47 +000019#include "SkTArray.h"
Brian Salomon94efbf52016-11-29 13:43:05 -050020#include "../private/GrGLSL.h"
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000021
22class GrGLContextInfo;
bsalomon1aa20292016-01-22 08:16:09 -080023class GrGLRenderTarget;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000024
25/**
26 * Stores some capabilities of a GL context. Most are determined by the GL
27 * version and the extensions string. It also tracks formats that have passed
28 * the FBO completeness test.
29 */
bsalomon4b91f762015-05-19 09:29:46 -070030class GrGLCaps : public GrCaps {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000031public:
egdaniel8dc7c3a2015-04-16 11:22:42 -070032 typedef GrGLStencilAttachment::Format StencilFormat;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000033
34 /**
35 * The type of MSAA for FBOs supported. Different extensions have different
36 * semantics of how / when a resolve is performed.
37 */
38 enum MSFBOType {
39 /**
40 * no support for MSAA FBOs
41 */
rmistry@google.comfbfcd562012-08-23 18:09:54 +000042 kNone_MSFBOType = 0,
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000043 /**
Brian Salomon00731b42016-10-14 11:30:51 -040044 * OpenGL < 3.0 with GL_EXT_framebuffer_object. Doesn't allow rendering to ALPHA.
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000045 */
Brian Salomon00731b42016-10-14 11:30:51 -040046 kEXT_MSFBOType,
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000047 /**
Brian Salomon00731b42016-10-14 11:30:51 -040048 * OpenGL 3.0+, OpenGL ES 3.0+, and GL_ARB_framebuffer_object.
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000049 */
Brian Salomon00731b42016-10-14 11:30:51 -040050 kStandard_MSFBOType,
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +000051 /**
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000052 * GL_APPLE_framebuffer_multisample ES extension
53 */
bsalomon@google.com347c3822013-05-01 20:10:01 +000054 kES_Apple_MSFBOType,
bsalomon@google.comf3a60c02013-03-19 19:06:09 +000055 /**
bsalomon@google.com347c3822013-05-01 20:10:01 +000056 * GL_IMG_multisampled_render_to_texture. This variation does not have MSAA renderbuffers.
57 * Instead the texture is multisampled when bound to the FBO and then resolved automatically
58 * when read. It also defines an alternate value for GL_MAX_SAMPLES (which we call
59 * GR_GL_MAX_SAMPLES_IMG).
bsalomon@google.comf3a60c02013-03-19 19:06:09 +000060 */
bsalomon@google.com347c3822013-05-01 20:10:01 +000061 kES_IMG_MsToTexture_MSFBOType,
62 /**
63 * GL_EXT_multisampled_render_to_texture. Same as the IMG one above but uses the standard
64 * GL_MAX_SAMPLES value.
65 */
66 kES_EXT_MsToTexture_MSFBOType,
vbuzinovdded6962015-06-12 08:59:45 -070067 /**
68 * GL_NV_framebuffer_mixed_samples.
69 */
70 kMixedSamples_MSFBOType,
bsalomon@google.com6b0cf022013-05-03 13:35:14 +000071
vbuzinovdded6962015-06-12 08:59:45 -070072 kLast_MSFBOType = kMixedSamples_MSFBOType
bsalomon@google.com6b0cf022013-05-03 13:35:14 +000073 };
74
Brian Salomone5e7eb12016-10-14 16:18:33 -040075 enum BlitFramebufferFlags {
76 kNoSupport_BlitFramebufferFlag = 1 << 0,
77 kNoScalingOrMirroring_BlitFramebufferFlag = 1 << 1,
78 kResolveMustBeFull_BlitFrambufferFlag = 1 << 2,
79 kNoMSAADst_BlitFramebufferFlag = 1 << 3,
80 kNoFormatConversion_BlitFramebufferFlag = 1 << 4,
81 kNoFormatConversionForMSAASrc_BlitFramebufferFlag = 1 << 5,
82 kRectsMustMatchForMSAASrc_BlitFramebufferFlag = 1 << 6,
bsalomon083617b2016-02-12 12:10:14 -080083 };
84
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +000085 enum InvalidateFBType {
86 kNone_InvalidateFBType,
87 kDiscard_InvalidateFBType, //<! glDiscardFramebuffer()
bsalomon083617b2016-02-12 12:10:14 -080088 kInvalidate_InvalidateFBType, //<! glInvalidateFramebuffer()
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +000089
90 kLast_InvalidateFBType = kInvalidate_InvalidateFBType
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000091 };
92
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000093 enum MapBufferType {
94 kNone_MapBufferType,
95 kMapBuffer_MapBufferType, // glMapBuffer()
96 kMapBufferRange_MapBufferType, // glMapBufferRange()
97 kChromium_MapBufferType, // GL_CHROMIUM_map_sub
98
99 kLast_MapBufferType = kChromium_MapBufferType,
100 };
101
jvanverthd7a2c1f2015-12-07 07:36:44 -0800102 enum TransferBufferType {
103 kNone_TransferBufferType,
104 kPBO_TransferBufferType, // ARB_pixel_buffer_object
105 kChromium_TransferBufferType, // CHROMIUM_pixel_transfer_buffer_object
106
107 kLast_TransferBufferType = kChromium_TransferBufferType,
108 };
109
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000110 /**
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000111 * Initializes the GrGLCaps to the set of features supported in the current
112 * OpenGL context accessible via ctxInfo.
113 */
bsalomon682c2692015-05-22 14:01:46 -0700114 GrGLCaps(const GrContextOptions& contextOptions, const GrGLContextInfo& ctxInfo,
115 const GrGLInterface* glInterface);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000116
bsalomon41e4384e2016-01-08 09:12:44 -0800117 bool isConfigTexturable(GrPixelConfig config) const override {
bsalomon41e4384e2016-01-08 09:12:44 -0800118 return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kTextureable_Flag);
119 }
120
121 bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const override {
bsalomon41e4384e2016-01-08 09:12:44 -0800122 if (withMSAA) {
123 return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kRenderableWithMSAA_Flag);
124 } else {
125 return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kRenderable_Flag);
126 }
127 }
Brian Salomonf9f45122016-11-29 11:59:17 -0500128 bool canConfigBeImageStorage(GrPixelConfig config) const override {
129 return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kCanUseAsImageStorage_Flag);
130 }
Brian Salomon71d9d842016-11-03 13:42:00 -0400131 bool canConfigBeFBOColorAttachment(GrPixelConfig config) const {
132 return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kFBOColorAttachment_Flag);
133 }
134
cblume790d5132016-02-29 11:13:29 -0800135 bool isConfigTexSupportEnabled(GrPixelConfig config) const {
cblume790d5132016-02-29 11:13:29 -0800136 return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kCanUseTexStorage_Flag);
137 }
138
cdalton74b8d322016-04-11 14:47:28 -0700139 bool canUseConfigWithTexelBuffer(GrPixelConfig config) const {
140 return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kCanUseWithTexelBuffer_Flag);
141 }
142
bsalomoncdee0092016-01-08 13:20:12 -0800143 /** Returns the mapping between GrPixelConfig components and GL internal format components. */
144 const GrSwizzle& configSwizzle(GrPixelConfig config) const {
145 return fConfigTable[config].fSwizzle;
146 }
147
cdalton74b8d322016-04-11 14:47:28 -0700148 GrGLenum configSizedInternalFormat(GrPixelConfig config) const {
149 return fConfigTable[config].fFormats.fSizedInternalFormat;
150 }
151
bsalomon76148af2016-01-12 11:13:47 -0800152 bool getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
153 GrGLenum* internalFormat, GrGLenum* externalFormat,
154 GrGLenum* externalType) const;
155
bsalomon76148af2016-01-12 11:13:47 -0800156 bool getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
157 GrGLenum* externalFormat, GrGLenum* externalType) const;
158
159 bool getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const;
160
Brian Salomonf9f45122016-11-29 11:59:17 -0500161 /** The format to use read/write a texture as an image in a shader */
162 GrGLenum getImageFormat(GrPixelConfig config) const {
163 return fConfigTable[config].fFormats.fSizedInternalFormat;
164 }
165
bsalomon30447372015-12-21 09:03:05 -0800166 /**
167 * Gets an array of legal stencil formats. These formats are not guaranteed
168 * to be supported by the driver but are legal GLenum names given the GL
169 * version and extensions supported.
170 */
171 const SkTArray<StencilFormat, true>& stencilFormats() const {
172 return fStencilFormats;
173 }
174
175 /**
176 * Has a stencil format index been found for the config (or we've found that no format works).
177 */
178 bool hasStencilFormatBeenDeterminedForConfig(GrPixelConfig config) const {
179 return fConfigTable[config].fStencilFormatIndex != ConfigInfo::kUnknown_StencilIndex;
180 }
181
182 /**
183 * Gets the stencil format index for the config. This assumes
184 * hasStencilFormatBeenDeterminedForConfig has already been checked. Returns a value < 0 if
185 * no stencil format is supported with the config. Otherwise, returned index refers to the array
186 * returned by stencilFormats().
187 */
188 int getStencilFormatIndexForConfig(GrPixelConfig config) const {
189 SkASSERT(this->hasStencilFormatBeenDeterminedForConfig(config));
190 return fConfigTable[config].fStencilFormatIndex;
191 }
192
193 /**
194 * If index is >= 0 this records an index into stencilFormats() as the best stencil format for
195 * the config. If < 0 it records that the config has no supported stencil format index.
196 */
197 void setStencilFormatIndexForConfig(GrPixelConfig config, int index) {
198 SkASSERT(!this->hasStencilFormatBeenDeterminedForConfig(config));
199 if (index < 0) {
200 fConfigTable[config].fStencilFormatIndex = ConfigInfo::kUnsupported_StencilFormatIndex;
201 } else {
202 fConfigTable[config].fStencilFormatIndex = index;
203 }
204 }
205
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000206 /**
207 * Call to note that a color config has been verified as a valid color
208 * attachment. This may save future calls to glCheckFramebufferStatus
209 * using isConfigVerifiedColorAttachment().
210 */
211 void markConfigAsValidColorAttachment(GrPixelConfig config) {
bsalomon480e8c02015-12-21 13:44:18 -0800212 fConfigTable[config].fFlags |= ConfigInfo::kVerifiedColorAttachment_Flag;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000213 }
214
215 /**
216 * Call to check whether a config has been verified as a valid color
217 * attachment.
218 */
219 bool isConfigVerifiedColorAttachment(GrPixelConfig config) const {
bsalomon480e8c02015-12-21 13:44:18 -0800220 return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kVerifiedColorAttachment_Flag);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000221 }
222
223 /**
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000224 * Reports the type of MSAA FBO support.
225 */
226 MSFBOType msFBOType() const { return fMSFBOType; }
227
228 /**
bsalomon083617b2016-02-12 12:10:14 -0800229 * Does the preferred MSAA FBO extension have MSAA renderbuffers?
bsalomon@google.com347c3822013-05-01 20:10:01 +0000230 */
231 bool usesMSAARenderBuffers() const {
232 return kNone_MSFBOType != fMSFBOType &&
233 kES_IMG_MsToTexture_MSFBOType != fMSFBOType &&
vbuzinovdded6962015-06-12 08:59:45 -0700234 kES_EXT_MsToTexture_MSFBOType != fMSFBOType &&
235 kMixedSamples_MSFBOType != fMSFBOType;
bsalomon@google.com347c3822013-05-01 20:10:01 +0000236 }
237
238 /**
bsalomon083617b2016-02-12 12:10:14 -0800239 * What functionality is supported by glBlitFramebuffer.
240 */
Brian Salomone5e7eb12016-10-14 16:18:33 -0400241 uint32_t blitFramebufferSupportFlags() const { return fBlitFramebufferFlags; }
bsalomon083617b2016-02-12 12:10:14 -0800242
243 /**
bsalomon@google.com347c3822013-05-01 20:10:01 +0000244 * Is the MSAA FBO extension one where the texture is multisampled when bound to an FBO and
245 * then implicitly resolved when read.
246 */
247 bool usesImplicitMSAAResolve() const {
248 return kES_IMG_MsToTexture_MSFBOType == fMSFBOType ||
249 kES_EXT_MsToTexture_MSFBOType == fMSFBOType;
250 }
251
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000252 InvalidateFBType invalidateFBType() const { return fInvalidateFBType; }
253
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000254 /// What type of buffer mapping is supported?
255 MapBufferType mapBufferType() const { return fMapBufferType; }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000256
jvanverthd7a2c1f2015-12-07 07:36:44 -0800257 /// What type of transfer buffer is supported?
258 TransferBufferType transferBufferType() const { return fTransferBufferType; }
259
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000260 /// The maximum number of fragment uniform vectors (GLES has min. 16).
261 int maxFragmentUniformVectors() const { return fMaxFragmentUniformVectors; }
262
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000263 /**
264 * Depending on the ES extensions present the BGRA external format may
bsalomon41e4384e2016-01-08 09:12:44 -0800265 * correspond to either a BGRA or RGBA internalFormat. On desktop GL it is
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000266 * RGBA.
267 */
bsalomon41e4384e2016-01-08 09:12:44 -0800268 bool bgraIsInternalFormat() const;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000269
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000270 /// Is there support for GL_UNPACK_ROW_LENGTH
271 bool unpackRowLengthSupport() const { return fUnpackRowLengthSupport; }
272
273 /// Is there support for GL_UNPACK_FLIP_Y
274 bool unpackFlipYSupport() const { return fUnpackFlipYSupport; }
275
276 /// Is there support for GL_PACK_ROW_LENGTH
277 bool packRowLengthSupport() const { return fPackRowLengthSupport; }
278
279 /// Is there support for GL_PACK_REVERSE_ROW_ORDER
280 bool packFlipYSupport() const { return fPackFlipYSupport; }
281
282 /// Is there support for texture parameter GL_TEXTURE_USAGE
283 bool textureUsageSupport() const { return fTextureUsageSupport; }
284
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000285 /// Is there support for GL_RED and GL_R8
286 bool textureRedSupport() const { return fTextureRedSupport; }
287
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000288 /// Is GL_ARB_IMAGING supported
289 bool imagingSupport() const { return fImagingSupport; }
290
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000291 /// Is there support for Vertex Array Objects?
292 bool vertexArrayObjectSupport() const { return fVertexArrayObjectSupport; }
293
cdalton626e1ff2015-06-12 13:56:46 -0700294 /// Is there support for GL_EXT_direct_state_access?
295 bool directStateAccessSupport() const { return fDirectStateAccessSupport; }
296
297 /// Is there support for GL_KHR_debug?
298 bool debugSupport() const { return fDebugSupport; }
299
jvanverth3f801cb2014-12-16 09:49:38 -0800300 /// Is there support for ES2 compatability?
301 bool ES2CompatibilitySupport() const { return fES2CompatibilitySupport; }
302
csmartdalton4c18b622016-07-29 12:19:28 -0700303 /// Is there support for glDraw*Instanced?
304 bool drawInstancedSupport() const { return fDrawInstancedSupport; }
305
cdalton06604b92016-02-05 10:09:51 -0800306 /// Is there support for glDraw*Indirect? Note that the baseInstance fields of indirect draw
307 /// commands cannot be used unless we have base instance support.
308 bool drawIndirectSupport() const { return fDrawIndirectSupport; }
309
310 /// Is there support for glMultiDraw*Indirect? Note that the baseInstance fields of indirect
311 /// draw commands cannot be used unless we have base instance support.
312 bool multiDrawIndirectSupport() const { return fMultiDrawIndirectSupport; }
313
bsalomonfc9527a2016-08-29 09:18:39 -0700314 /// Is there support for glDrawRangeElements?
315 bool drawRangeElementsSupport() const { return fDrawRangeElementsSupport; }
316
cdalton06604b92016-02-05 10:09:51 -0800317 /// Are the baseInstance fields supported in indirect draw commands?
318 bool baseInstanceSupport() const { return fBaseInstanceSupport; }
319
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000320 /// Use indices or vertices in CPU arrays rather than VBOs for dynamic content.
bsalomon76148af2016-01-12 11:13:47 -0800321 bool useNonVBOVertexAndIndexDynamicData() const { return fUseNonVBOVertexAndIndexDynamicData; }
bsalomon@google.com96966a52013-02-21 16:34:21 +0000322
Brian Salomon71d9d842016-11-03 13:42:00 -0400323 /// Does ReadPixels support reading readConfig pixels from a FBO that is surfaceConfig?
324 bool readPixelsSupported(GrPixelConfig surfaceConfig,
bsalomon7928ef62016-01-05 10:26:39 -0800325 GrPixelConfig readConfig,
bsalomon1aa20292016-01-22 08:16:09 -0800326 std::function<void (GrGLenum, GrGLint*)> getIntegerv,
bsalomon2c3db322016-11-08 13:26:24 -0800327 std::function<bool ()> bindRenderTarget,
328 std::function<void ()> unbindRenderTarget) const;
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000329
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +0000330 bool isCoreProfile() const { return fIsCoreProfile; }
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000331
joshualittc1f56b52015-06-22 12:31:31 -0700332 bool bindFragDataLocationSupport() const { return fBindFragDataLocationSupport; }
333
joshualitt7bdd70a2015-10-01 06:28:11 -0700334 bool bindUniformLocationSupport() const { return fBindUniformLocationSupport; }
335
bsalomone5286e02016-01-14 09:24:09 -0800336 /// Are textures with GL_TEXTURE_RECTANGLE type supported.
337 bool rectangleTextureSupport() const { return fRectangleTextureSupport; }
338
bsalomoncdee0092016-01-08 13:20:12 -0800339 /// GL_ARB_texture_swizzle
340 bool textureSwizzleSupport() const { return fTextureSwizzleSupport; }
341
cblume09bd2c02016-03-01 14:08:28 -0800342 bool mipMapLevelAndLodControlSupport() const { return fMipMapLevelAndLodControlSupport; }
343
brianosman09563ce2016-06-02 08:59:34 -0700344 bool doManualMipmapping() const { return fDoManualMipmapping; }
345
brianosman20471892016-12-02 06:43:32 -0800346 bool srgbDecodeDisableSupport() const { return fSRGBDecodeDisableSupport; }
brianosman851c2382016-12-07 10:03:25 -0800347 bool srgbDecodeDisableAffectsMipmaps() const { return fSRGBDecodeDisableAffectsMipmaps; }
brianosman20471892016-12-02 06:43:32 -0800348
bsalomon16921ec2015-07-30 15:34:56 -0700349 /**
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000350 * Returns a string containing the caps info.
351 */
mtklein36352bf2015-03-25 18:17:31 -0700352 SkString dump() const override;
commit-bot@chromium.orgbeb8b3a2014-04-15 15:37:51 +0000353
bsalomon88c7b982015-07-31 11:20:16 -0700354 bool rgba8888PixelsOpsAreSlow() const { return fRGBA8888PixelsOpsAreSlow; }
355 bool partialFBOReadIsSlow() const { return fPartialFBOReadIsSlow; }
ericrkb4ecabd2016-03-11 15:18:20 -0800356 bool rgbaToBgraReadbackConversionsAreSlow() const {
357 return fRGBAToBGRAReadbackConversionsAreSlow;
358 }
bsalomon88c7b982015-07-31 11:20:16 -0700359
Eric Karlaeaf22b2017-05-18 15:08:09 -0700360 // Certain Intel GPUs on Mac fail to clear if the glClearColor is made up of only 1s and 0s.
361 bool clearToBoundaryValuesIsBroken() const { return fClearToBoundaryValuesIsBroken; }
Chris Dalton9926f4b2017-05-17 15:15:50 -0600362
Brian Salomond17b4a62017-05-23 16:53:47 -0400363 /// glClearTex(Sub)Image support
364 bool clearTextureSupport() const { return fClearTextureSupport; }
365
Chris Dalton9926f4b2017-05-17 15:15:50 -0600366 // Adreno/MSAA drops a draw on the imagefiltersbase GM if the base vertex param to
367 // glDrawArrays is nonzero.
368 // https://bugs.chromium.org/p/skia/issues/detail?id=6650
369 bool drawArraysBaseVertexIsBroken() const { return fDrawArraysBaseVertexIsBroken; }
370
Robert Phillipsbf25d432017-04-07 10:08:53 -0400371 bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
372 bool* rectsMustMatch, bool* disallowSubrect) const override;
Brian Salomon467921e2017-03-06 16:17:12 -0500373
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000374private:
bsalomon76148af2016-01-12 11:13:47 -0800375 enum ExternalFormatUsage {
376 kTexImage_ExternalFormatUsage,
377 kOther_ExternalFormatUsage,
378
379 kLast_ExternalFormatUsage = kOther_ExternalFormatUsage
380 };
381 static const int kExternalFormatUsageCnt = kLast_ExternalFormatUsage + 1;
382 bool getExternalFormat(GrPixelConfig surfaceConfig, GrPixelConfig memoryConfig,
383 ExternalFormatUsage usage, GrGLenum* externalFormat,
384 GrGLenum* externalType) const;
385
cdalton4cd67132015-06-10 19:23:46 -0700386 void init(const GrContextOptions&, const GrGLContextInfo&, const GrGLInterface*);
egdaniel05ded892015-10-26 07:38:05 -0700387 void initGLSL(const GrGLContextInfo&);
kkinnunencfe62e32015-07-01 02:58:50 -0700388 bool hasPathRenderingSupport(const GrGLContextInfo&, const GrGLInterface*);
bsalomon424cc262015-05-22 10:37:30 -0700389
egdanielb7e7d572015-11-04 04:23:53 -0800390 void onApplyOptionsOverrides(const GrContextOptions& options) override;
391
Eric Karl5c779752017-05-08 12:02:07 -0700392 void initFSAASupport(const GrContextOptions& contextOptions, const GrGLContextInfo&,
393 const GrGLInterface*);
cdalton1dd05422015-06-12 09:01:18 -0700394 void initBlendEqationSupport(const GrGLContextInfo&);
Eric Karl5c779752017-05-08 12:02:07 -0700395 void initStencilSupport(const GrGLContextInfo&);
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000396 // This must be called after initFSAASupport().
brianosman20471892016-12-02 06:43:32 -0800397 void initConfigTable(const GrContextOptions&, const GrGLContextInfo&, const GrGLInterface*,
398 GrShaderCaps*);
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000399
Brian Salomon1edc5b92016-11-29 13:43:46 -0500400 void initShaderPrecisionTable(const GrGLContextInfo&, const GrGLInterface*, GrShaderCaps*);
jvanverthcba99b82015-06-24 06:59:57 -0700401
bsalomon1aa20292016-01-22 08:16:09 -0800402 GrGLStandard fStandard;
403
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000404 SkTArray<StencilFormat, true> fStencilFormats;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000405
406 int fMaxFragmentUniformVectors;
bsalomon@google.com60da4172012-06-01 19:25:00 +0000407
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000408 MSFBOType fMSFBOType;
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000409 InvalidateFBType fInvalidateFBType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000410 MapBufferType fMapBufferType;
jvanverthd7a2c1f2015-12-07 07:36:44 -0800411 TransferBufferType fTransferBufferType;
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000412
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000413 bool fUnpackRowLengthSupport : 1;
414 bool fUnpackFlipYSupport : 1;
415 bool fPackRowLengthSupport : 1;
416 bool fPackFlipYSupport : 1;
417 bool fTextureUsageSupport : 1;
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000418 bool fTextureRedSupport : 1;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000419 bool fImagingSupport : 1;
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000420 bool fVertexArrayObjectSupport : 1;
cdalton626e1ff2015-06-12 13:56:46 -0700421 bool fDirectStateAccessSupport : 1;
422 bool fDebugSupport : 1;
jvanverth3f801cb2014-12-16 09:49:38 -0800423 bool fES2CompatibilitySupport : 1;
csmartdalton4c18b622016-07-29 12:19:28 -0700424 bool fDrawInstancedSupport : 1;
cdalton06604b92016-02-05 10:09:51 -0800425 bool fDrawIndirectSupport : 1;
bsalomonfc9527a2016-08-29 09:18:39 -0700426 bool fDrawRangeElementsSupport : 1;
cdalton06604b92016-02-05 10:09:51 -0800427 bool fMultiDrawIndirectSupport : 1;
428 bool fBaseInstanceSupport : 1;
bsalomon@google.com96966a52013-02-21 16:34:21 +0000429 bool fUseNonVBOVertexAndIndexDynamicData : 1;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +0000430 bool fIsCoreProfile : 1;
joshualittc1f56b52015-06-22 12:31:31 -0700431 bool fBindFragDataLocationSupport : 1;
bsalomon88c7b982015-07-31 11:20:16 -0700432 bool fRGBA8888PixelsOpsAreSlow : 1;
433 bool fPartialFBOReadIsSlow : 1;
joshualitt7bdd70a2015-10-01 06:28:11 -0700434 bool fBindUniformLocationSupport : 1;
bsalomone5286e02016-01-14 09:24:09 -0800435 bool fRectangleTextureSupport : 1;
bsalomoncdee0092016-01-08 13:20:12 -0800436 bool fTextureSwizzleSupport : 1;
cblume09bd2c02016-03-01 14:08:28 -0800437 bool fMipMapLevelAndLodControlSupport : 1;
ericrkb4ecabd2016-03-11 15:18:20 -0800438 bool fRGBAToBGRAReadbackConversionsAreSlow : 1;
brianosman09563ce2016-06-02 08:59:34 -0700439 bool fDoManualMipmapping : 1;
brianosman20471892016-12-02 06:43:32 -0800440 bool fSRGBDecodeDisableSupport : 1;
brianosman851c2382016-12-07 10:03:25 -0800441 bool fSRGBDecodeDisableAffectsMipmaps : 1;
Eric Karlaeaf22b2017-05-18 15:08:09 -0700442 bool fClearToBoundaryValuesIsBroken : 1;
Brian Salomond17b4a62017-05-23 16:53:47 -0400443 bool fClearTextureSupport : 1;
Chris Dalton9926f4b2017-05-17 15:15:50 -0600444 bool fDrawArraysBaseVertexIsBroken : 1;
joshualitt58162332014-08-01 06:44:53 -0700445
Brian Salomone5e7eb12016-10-14 16:18:33 -0400446 uint32_t fBlitFramebufferFlags;
bsalomon083617b2016-02-12 12:10:14 -0800447
bsalomon7928ef62016-01-05 10:26:39 -0800448 /** Number type of the components (with out considering number of bits.) */
449 enum FormatType {
450 kNormalizedFixedPoint_FormatType,
451 kFloat_FormatType,
Brian Salomonbf7b6202016-11-11 16:08:03 -0500452 kInteger_FormatType,
bsalomon7928ef62016-01-05 10:26:39 -0800453 };
454
455 struct ReadPixelsFormat {
456 ReadPixelsFormat() : fFormat(0), fType(0) {}
457 GrGLenum fFormat;
458 GrGLenum fType;
459 };
460
bsalomon76148af2016-01-12 11:13:47 -0800461 struct ConfigFormats {
462 ConfigFormats() {
463 // Inits to known bad GL enum values.
464 memset(this, 0xAB, sizeof(ConfigFormats));
465 }
466 GrGLenum fBaseInternalFormat;
467 GrGLenum fSizedInternalFormat;
468
469 /** The external format and type are to be used when uploading/downloading data using this
470 config where both the CPU data and GrSurface are the same config. To get the external
471 format and type when converting between configs while copying to/from memory use
halcanary9d524f22016-03-29 09:03:52 -0700472 getExternalFormat().
bsalomon76148af2016-01-12 11:13:47 -0800473 The kTexImage external format is usually the same as kOther except for kSRGBA on some
474 GL contexts. */
475 GrGLenum fExternalFormat[kExternalFormatUsageCnt];
476 GrGLenum fExternalType;
477
bsalomon76148af2016-01-12 11:13:47 -0800478 // Either the base or sized internal format depending on the GL and config.
479 GrGLenum fInternalFormatTexImage;
480 GrGLenum fInternalFormatRenderbuffer;
481 };
482
bsalomon30447372015-12-21 09:03:05 -0800483 struct ConfigInfo {
bsalomon7928ef62016-01-05 10:26:39 -0800484 ConfigInfo() : fStencilFormatIndex(kUnknown_StencilIndex), fFlags(0) {}
bsalomon30447372015-12-21 09:03:05 -0800485
486 ConfigFormats fFormats;
487
bsalomon7928ef62016-01-05 10:26:39 -0800488 FormatType fFormatType;
489
490 // On ES contexts there are restrictions on type type/format that may be used for
491 // ReadPixels. One is implicitly specified by the current FBO's format. The other is
492 // queryable. This stores the queried option (lazily).
493 ReadPixelsFormat fSecondReadPixelsFormat;
494
bsalomon30447372015-12-21 09:03:05 -0800495 enum {
496 // This indicates that a stencil format has not yet been determined for the config.
497 kUnknown_StencilIndex = -1,
498 // This indicates that there is no supported stencil format for the config.
499 kUnsupported_StencilFormatIndex = -2
500 };
bsalomon480e8c02015-12-21 13:44:18 -0800501
502 // Index fStencilFormats.
503 int fStencilFormatIndex;
504
505 enum {
bsalomon41e4384e2016-01-08 09:12:44 -0800506 kVerifiedColorAttachment_Flag = 0x1,
507 kTextureable_Flag = 0x2,
508 kRenderable_Flag = 0x4,
509 kRenderableWithMSAA_Flag = 0x8,
Brian Salomon71d9d842016-11-03 13:42:00 -0400510 /** kFBOColorAttachment means that even if the config cannot be a GrRenderTarget, we can
511 still attach it to a FBO for blitting or reading pixels. */
512 kFBOColorAttachment_Flag = 0x10,
513 kCanUseTexStorage_Flag = 0x20,
514 kCanUseWithTexelBuffer_Flag = 0x40,
Brian Salomonf9f45122016-11-29 11:59:17 -0500515 kCanUseAsImageStorage_Flag = 0x80,
bsalomon480e8c02015-12-21 13:44:18 -0800516 };
517 uint32_t fFlags;
bsalomoncdee0092016-01-08 13:20:12 -0800518
519 GrSwizzle fSwizzle;
bsalomon30447372015-12-21 09:03:05 -0800520 };
521
522 ConfigInfo fConfigTable[kGrPixelConfigCnt];
523
bsalomon4b91f762015-05-19 09:29:46 -0700524 typedef GrCaps INHERITED;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000525};
526
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000527#endif