blob: 4a81c7eab417441d3b4323596d9b359755e513a9 [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 /**
Robert Phillips5ab72762017-06-07 12:04:18 -040044 * OpenGL 3.0+, OpenGL ES 3.0+, GL_ARB_framebuffer_object,
45 * GL_CHROMIUM_framebuffer_multisample, GL_ANGLE_framebuffer_multisample,
46 * or GL_EXT_framebuffer_multisample
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000047 */
Brian Salomon00731b42016-10-14 11:30:51 -040048 kStandard_MSFBOType,
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +000049 /**
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000050 * GL_APPLE_framebuffer_multisample ES extension
51 */
bsalomon@google.com347c3822013-05-01 20:10:01 +000052 kES_Apple_MSFBOType,
bsalomon@google.comf3a60c02013-03-19 19:06:09 +000053 /**
bsalomon@google.com347c3822013-05-01 20:10:01 +000054 * GL_IMG_multisampled_render_to_texture. This variation does not have MSAA renderbuffers.
55 * Instead the texture is multisampled when bound to the FBO and then resolved automatically
56 * when read. It also defines an alternate value for GL_MAX_SAMPLES (which we call
57 * GR_GL_MAX_SAMPLES_IMG).
bsalomon@google.comf3a60c02013-03-19 19:06:09 +000058 */
bsalomon@google.com347c3822013-05-01 20:10:01 +000059 kES_IMG_MsToTexture_MSFBOType,
60 /**
61 * GL_EXT_multisampled_render_to_texture. Same as the IMG one above but uses the standard
62 * GL_MAX_SAMPLES value.
63 */
64 kES_EXT_MsToTexture_MSFBOType,
vbuzinovdded6962015-06-12 08:59:45 -070065 /**
66 * GL_NV_framebuffer_mixed_samples.
67 */
68 kMixedSamples_MSFBOType,
bsalomon@google.com6b0cf022013-05-03 13:35:14 +000069
vbuzinovdded6962015-06-12 08:59:45 -070070 kLast_MSFBOType = kMixedSamples_MSFBOType
bsalomon@google.com6b0cf022013-05-03 13:35:14 +000071 };
72
Brian Salomone5e7eb12016-10-14 16:18:33 -040073 enum BlitFramebufferFlags {
74 kNoSupport_BlitFramebufferFlag = 1 << 0,
75 kNoScalingOrMirroring_BlitFramebufferFlag = 1 << 1,
76 kResolveMustBeFull_BlitFrambufferFlag = 1 << 2,
77 kNoMSAADst_BlitFramebufferFlag = 1 << 3,
78 kNoFormatConversion_BlitFramebufferFlag = 1 << 4,
79 kNoFormatConversionForMSAASrc_BlitFramebufferFlag = 1 << 5,
80 kRectsMustMatchForMSAASrc_BlitFramebufferFlag = 1 << 6,
bsalomon083617b2016-02-12 12:10:14 -080081 };
82
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +000083 enum InvalidateFBType {
84 kNone_InvalidateFBType,
85 kDiscard_InvalidateFBType, //<! glDiscardFramebuffer()
bsalomon083617b2016-02-12 12:10:14 -080086 kInvalidate_InvalidateFBType, //<! glInvalidateFramebuffer()
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +000087
88 kLast_InvalidateFBType = kInvalidate_InvalidateFBType
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000089 };
90
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000091 enum MapBufferType {
92 kNone_MapBufferType,
93 kMapBuffer_MapBufferType, // glMapBuffer()
94 kMapBufferRange_MapBufferType, // glMapBufferRange()
95 kChromium_MapBufferType, // GL_CHROMIUM_map_sub
96
97 kLast_MapBufferType = kChromium_MapBufferType,
98 };
99
jvanverthd7a2c1f2015-12-07 07:36:44 -0800100 enum TransferBufferType {
101 kNone_TransferBufferType,
102 kPBO_TransferBufferType, // ARB_pixel_buffer_object
103 kChromium_TransferBufferType, // CHROMIUM_pixel_transfer_buffer_object
104
105 kLast_TransferBufferType = kChromium_TransferBufferType,
106 };
107
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000108 /**
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000109 * Initializes the GrGLCaps to the set of features supported in the current
110 * OpenGL context accessible via ctxInfo.
111 */
bsalomon682c2692015-05-22 14:01:46 -0700112 GrGLCaps(const GrContextOptions& contextOptions, const GrGLContextInfo& ctxInfo,
113 const GrGLInterface* glInterface);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000114
bsalomon41e4384e2016-01-08 09:12:44 -0800115 bool isConfigTexturable(GrPixelConfig config) const override {
bsalomon41e4384e2016-01-08 09:12:44 -0800116 return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kTextureable_Flag);
117 }
118
119 bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const override {
bsalomon41e4384e2016-01-08 09:12:44 -0800120 if (withMSAA) {
121 return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kRenderableWithMSAA_Flag);
122 } else {
123 return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kRenderable_Flag);
124 }
125 }
Brian Salomonf9f45122016-11-29 11:59:17 -0500126 bool canConfigBeImageStorage(GrPixelConfig config) const override {
127 return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kCanUseAsImageStorage_Flag);
128 }
Brian Salomon71d9d842016-11-03 13:42:00 -0400129 bool canConfigBeFBOColorAttachment(GrPixelConfig config) const {
130 return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kFBOColorAttachment_Flag);
131 }
132
cblume790d5132016-02-29 11:13:29 -0800133 bool isConfigTexSupportEnabled(GrPixelConfig config) const {
cblume790d5132016-02-29 11:13:29 -0800134 return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kCanUseTexStorage_Flag);
135 }
136
cdalton74b8d322016-04-11 14:47:28 -0700137 bool canUseConfigWithTexelBuffer(GrPixelConfig config) const {
138 return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kCanUseWithTexelBuffer_Flag);
139 }
140
bsalomoncdee0092016-01-08 13:20:12 -0800141 /** Returns the mapping between GrPixelConfig components and GL internal format components. */
142 const GrSwizzle& configSwizzle(GrPixelConfig config) const {
143 return fConfigTable[config].fSwizzle;
144 }
145
cdalton74b8d322016-04-11 14:47:28 -0700146 GrGLenum configSizedInternalFormat(GrPixelConfig config) const {
147 return fConfigTable[config].fFormats.fSizedInternalFormat;
148 }
149
bsalomon76148af2016-01-12 11:13:47 -0800150 bool getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
151 GrGLenum* internalFormat, GrGLenum* externalFormat,
152 GrGLenum* externalType) const;
153
bsalomon76148af2016-01-12 11:13:47 -0800154 bool getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
155 GrGLenum* externalFormat, GrGLenum* externalType) const;
156
157 bool getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const;
158
Brian Salomonf9f45122016-11-29 11:59:17 -0500159 /** The format to use read/write a texture as an image in a shader */
160 GrGLenum getImageFormat(GrPixelConfig config) const {
161 return fConfigTable[config].fFormats.fSizedInternalFormat;
162 }
163
bsalomon30447372015-12-21 09:03:05 -0800164 /**
165 * Gets an array of legal stencil formats. These formats are not guaranteed
166 * to be supported by the driver but are legal GLenum names given the GL
167 * version and extensions supported.
168 */
169 const SkTArray<StencilFormat, true>& stencilFormats() const {
170 return fStencilFormats;
171 }
172
173 /**
174 * Has a stencil format index been found for the config (or we've found that no format works).
175 */
176 bool hasStencilFormatBeenDeterminedForConfig(GrPixelConfig config) const {
177 return fConfigTable[config].fStencilFormatIndex != ConfigInfo::kUnknown_StencilIndex;
178 }
179
180 /**
181 * Gets the stencil format index for the config. This assumes
182 * hasStencilFormatBeenDeterminedForConfig has already been checked. Returns a value < 0 if
183 * no stencil format is supported with the config. Otherwise, returned index refers to the array
184 * returned by stencilFormats().
185 */
186 int getStencilFormatIndexForConfig(GrPixelConfig config) const {
187 SkASSERT(this->hasStencilFormatBeenDeterminedForConfig(config));
188 return fConfigTable[config].fStencilFormatIndex;
189 }
190
191 /**
192 * If index is >= 0 this records an index into stencilFormats() as the best stencil format for
193 * the config. If < 0 it records that the config has no supported stencil format index.
194 */
195 void setStencilFormatIndexForConfig(GrPixelConfig config, int index) {
196 SkASSERT(!this->hasStencilFormatBeenDeterminedForConfig(config));
197 if (index < 0) {
198 fConfigTable[config].fStencilFormatIndex = ConfigInfo::kUnsupported_StencilFormatIndex;
199 } else {
200 fConfigTable[config].fStencilFormatIndex = index;
201 }
202 }
203
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000204 /**
205 * Call to note that a color config has been verified as a valid color
206 * attachment. This may save future calls to glCheckFramebufferStatus
207 * using isConfigVerifiedColorAttachment().
208 */
209 void markConfigAsValidColorAttachment(GrPixelConfig config) {
bsalomon480e8c02015-12-21 13:44:18 -0800210 fConfigTable[config].fFlags |= ConfigInfo::kVerifiedColorAttachment_Flag;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000211 }
212
213 /**
214 * Call to check whether a config has been verified as a valid color
215 * attachment.
216 */
217 bool isConfigVerifiedColorAttachment(GrPixelConfig config) const {
bsalomon480e8c02015-12-21 13:44:18 -0800218 return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kVerifiedColorAttachment_Flag);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000219 }
220
221 /**
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000222 * Reports the type of MSAA FBO support.
223 */
224 MSFBOType msFBOType() const { return fMSFBOType; }
225
226 /**
bsalomon083617b2016-02-12 12:10:14 -0800227 * Does the preferred MSAA FBO extension have MSAA renderbuffers?
bsalomon@google.com347c3822013-05-01 20:10:01 +0000228 */
229 bool usesMSAARenderBuffers() const {
230 return kNone_MSFBOType != fMSFBOType &&
231 kES_IMG_MsToTexture_MSFBOType != fMSFBOType &&
vbuzinovdded6962015-06-12 08:59:45 -0700232 kES_EXT_MsToTexture_MSFBOType != fMSFBOType &&
233 kMixedSamples_MSFBOType != fMSFBOType;
bsalomon@google.com347c3822013-05-01 20:10:01 +0000234 }
235
236 /**
bsalomon083617b2016-02-12 12:10:14 -0800237 * What functionality is supported by glBlitFramebuffer.
238 */
Brian Salomone5e7eb12016-10-14 16:18:33 -0400239 uint32_t blitFramebufferSupportFlags() const { return fBlitFramebufferFlags; }
bsalomon083617b2016-02-12 12:10:14 -0800240
241 /**
bsalomon@google.com347c3822013-05-01 20:10:01 +0000242 * Is the MSAA FBO extension one where the texture is multisampled when bound to an FBO and
243 * then implicitly resolved when read.
244 */
245 bool usesImplicitMSAAResolve() const {
246 return kES_IMG_MsToTexture_MSFBOType == fMSFBOType ||
247 kES_EXT_MsToTexture_MSFBOType == fMSFBOType;
248 }
249
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000250 InvalidateFBType invalidateFBType() const { return fInvalidateFBType; }
251
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000252 /// What type of buffer mapping is supported?
253 MapBufferType mapBufferType() const { return fMapBufferType; }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000254
jvanverthd7a2c1f2015-12-07 07:36:44 -0800255 /// What type of transfer buffer is supported?
256 TransferBufferType transferBufferType() const { return fTransferBufferType; }
257
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000258 /// The maximum number of fragment uniform vectors (GLES has min. 16).
259 int maxFragmentUniformVectors() const { return fMaxFragmentUniformVectors; }
260
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000261 /**
262 * Depending on the ES extensions present the BGRA external format may
bsalomon41e4384e2016-01-08 09:12:44 -0800263 * correspond to either a BGRA or RGBA internalFormat. On desktop GL it is
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000264 * RGBA.
265 */
bsalomon41e4384e2016-01-08 09:12:44 -0800266 bool bgraIsInternalFormat() const;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000267
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000268 /// Is there support for GL_UNPACK_ROW_LENGTH
269 bool unpackRowLengthSupport() const { return fUnpackRowLengthSupport; }
270
271 /// Is there support for GL_UNPACK_FLIP_Y
272 bool unpackFlipYSupport() const { return fUnpackFlipYSupport; }
273
274 /// Is there support for GL_PACK_ROW_LENGTH
275 bool packRowLengthSupport() const { return fPackRowLengthSupport; }
276
277 /// Is there support for GL_PACK_REVERSE_ROW_ORDER
278 bool packFlipYSupport() const { return fPackFlipYSupport; }
279
280 /// Is there support for texture parameter GL_TEXTURE_USAGE
281 bool textureUsageSupport() const { return fTextureUsageSupport; }
282
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000283 /// Is there support for GL_RED and GL_R8
284 bool textureRedSupport() const { return fTextureRedSupport; }
285
Robert Phillips5ab72762017-06-07 12:04:18 -0400286 /// Is GL_ALPHA8 renderable
287 bool alpha8IsRenderable() const { return fAlpha8IsRenderable; }
288
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000289 /// Is GL_ARB_IMAGING supported
290 bool imagingSupport() const { return fImagingSupport; }
291
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000292 /// Is there support for Vertex Array Objects?
293 bool vertexArrayObjectSupport() const { return fVertexArrayObjectSupport; }
294
cdalton626e1ff2015-06-12 13:56:46 -0700295 /// Is there support for GL_EXT_direct_state_access?
296 bool directStateAccessSupport() const { return fDirectStateAccessSupport; }
297
298 /// Is there support for GL_KHR_debug?
299 bool debugSupport() const { return fDebugSupport; }
300
jvanverth3f801cb2014-12-16 09:49:38 -0800301 /// Is there support for ES2 compatability?
302 bool ES2CompatibilitySupport() const { return fES2CompatibilitySupport; }
303
csmartdalton4c18b622016-07-29 12:19:28 -0700304 /// Is there support for glDraw*Instanced?
305 bool drawInstancedSupport() const { return fDrawInstancedSupport; }
306
cdalton06604b92016-02-05 10:09:51 -0800307 /// Is there support for glDraw*Indirect? Note that the baseInstance fields of indirect draw
308 /// commands cannot be used unless we have base instance support.
309 bool drawIndirectSupport() const { return fDrawIndirectSupport; }
310
311 /// Is there support for glMultiDraw*Indirect? Note that the baseInstance fields of indirect
312 /// draw commands cannot be used unless we have base instance support.
313 bool multiDrawIndirectSupport() const { return fMultiDrawIndirectSupport; }
314
bsalomonfc9527a2016-08-29 09:18:39 -0700315 /// Is there support for glDrawRangeElements?
316 bool drawRangeElementsSupport() const { return fDrawRangeElementsSupport; }
317
cdalton06604b92016-02-05 10:09:51 -0800318 /// Are the baseInstance fields supported in indirect draw commands?
319 bool baseInstanceSupport() const { return fBaseInstanceSupport; }
320
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000321 /// Use indices or vertices in CPU arrays rather than VBOs for dynamic content.
bsalomon76148af2016-01-12 11:13:47 -0800322 bool useNonVBOVertexAndIndexDynamicData() const { return fUseNonVBOVertexAndIndexDynamicData; }
bsalomon@google.com96966a52013-02-21 16:34:21 +0000323
Brian Salomon71d9d842016-11-03 13:42:00 -0400324 /// Does ReadPixels support reading readConfig pixels from a FBO that is surfaceConfig?
325 bool readPixelsSupported(GrPixelConfig surfaceConfig,
bsalomon7928ef62016-01-05 10:26:39 -0800326 GrPixelConfig readConfig,
bsalomon1aa20292016-01-22 08:16:09 -0800327 std::function<void (GrGLenum, GrGLint*)> getIntegerv,
bsalomon2c3db322016-11-08 13:26:24 -0800328 std::function<bool ()> bindRenderTarget,
329 std::function<void ()> unbindRenderTarget) const;
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000330
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +0000331 bool isCoreProfile() const { return fIsCoreProfile; }
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000332
joshualittc1f56b52015-06-22 12:31:31 -0700333 bool bindFragDataLocationSupport() const { return fBindFragDataLocationSupport; }
334
joshualitt7bdd70a2015-10-01 06:28:11 -0700335 bool bindUniformLocationSupport() const { return fBindUniformLocationSupport; }
336
bsalomone5286e02016-01-14 09:24:09 -0800337 /// Are textures with GL_TEXTURE_RECTANGLE type supported.
338 bool rectangleTextureSupport() const { return fRectangleTextureSupport; }
339
bsalomoncdee0092016-01-08 13:20:12 -0800340 /// GL_ARB_texture_swizzle
341 bool textureSwizzleSupport() const { return fTextureSwizzleSupport; }
342
cblume09bd2c02016-03-01 14:08:28 -0800343 bool mipMapLevelAndLodControlSupport() const { return fMipMapLevelAndLodControlSupport; }
344
brianosman09563ce2016-06-02 08:59:34 -0700345 bool doManualMipmapping() const { return fDoManualMipmapping; }
346
brianosman20471892016-12-02 06:43:32 -0800347 bool srgbDecodeDisableSupport() const { return fSRGBDecodeDisableSupport; }
brianosman851c2382016-12-07 10:03:25 -0800348 bool srgbDecodeDisableAffectsMipmaps() const { return fSRGBDecodeDisableAffectsMipmaps; }
brianosman20471892016-12-02 06:43:32 -0800349
bsalomon16921ec2015-07-30 15:34:56 -0700350 /**
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000351 * Returns a string containing the caps info.
352 */
mtklein36352bf2015-03-25 18:17:31 -0700353 SkString dump() const override;
commit-bot@chromium.orgbeb8b3a2014-04-15 15:37:51 +0000354
bsalomon88c7b982015-07-31 11:20:16 -0700355 bool rgba8888PixelsOpsAreSlow() const { return fRGBA8888PixelsOpsAreSlow; }
356 bool partialFBOReadIsSlow() const { return fPartialFBOReadIsSlow; }
ericrkb4ecabd2016-03-11 15:18:20 -0800357 bool rgbaToBgraReadbackConversionsAreSlow() const {
358 return fRGBAToBGRAReadbackConversionsAreSlow;
359 }
bsalomon88c7b982015-07-31 11:20:16 -0700360
Eric Karlaeaf22b2017-05-18 15:08:09 -0700361 // Certain Intel GPUs on Mac fail to clear if the glClearColor is made up of only 1s and 0s.
362 bool clearToBoundaryValuesIsBroken() const { return fClearToBoundaryValuesIsBroken; }
Chris Dalton9926f4b2017-05-17 15:15:50 -0600363
Brian Salomond17b4a62017-05-23 16:53:47 -0400364 /// glClearTex(Sub)Image support
365 bool clearTextureSupport() const { return fClearTextureSupport; }
366
Chris Dalton9926f4b2017-05-17 15:15:50 -0600367 // Adreno/MSAA drops a draw on the imagefiltersbase GM if the base vertex param to
368 // glDrawArrays is nonzero.
369 // https://bugs.chromium.org/p/skia/issues/detail?id=6650
370 bool drawArraysBaseVertexIsBroken() const { return fDrawArraysBaseVertexIsBroken; }
371
Mike Klein31550db2017-06-06 23:29:53 +0000372 /// Adreno 4xx devices experience an issue when there are a large number of stencil clip bit
373 /// clears. The minimal repro steps are not precisely known but drawing a rect with a stencil
374 /// op instead of using glClear seems to resolve the issue.
375 bool useDrawToClearStencilClip() const { return fUseDrawToClearStencilClip; }
376
Robert Phillipsbf25d432017-04-07 10:08:53 -0400377 bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
378 bool* rectsMustMatch, bool* disallowSubrect) const override;
Brian Salomon467921e2017-03-06 16:17:12 -0500379
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000380private:
bsalomon76148af2016-01-12 11:13:47 -0800381 enum ExternalFormatUsage {
382 kTexImage_ExternalFormatUsage,
383 kOther_ExternalFormatUsage,
384
385 kLast_ExternalFormatUsage = kOther_ExternalFormatUsage
386 };
387 static const int kExternalFormatUsageCnt = kLast_ExternalFormatUsage + 1;
388 bool getExternalFormat(GrPixelConfig surfaceConfig, GrPixelConfig memoryConfig,
389 ExternalFormatUsage usage, GrGLenum* externalFormat,
390 GrGLenum* externalType) const;
391
cdalton4cd67132015-06-10 19:23:46 -0700392 void init(const GrContextOptions&, const GrGLContextInfo&, const GrGLInterface*);
egdaniel05ded892015-10-26 07:38:05 -0700393 void initGLSL(const GrGLContextInfo&);
kkinnunencfe62e32015-07-01 02:58:50 -0700394 bool hasPathRenderingSupport(const GrGLContextInfo&, const GrGLInterface*);
bsalomon424cc262015-05-22 10:37:30 -0700395
egdanielb7e7d572015-11-04 04:23:53 -0800396 void onApplyOptionsOverrides(const GrContextOptions& options) override;
397
Eric Karl5c779752017-05-08 12:02:07 -0700398 void initFSAASupport(const GrContextOptions& contextOptions, const GrGLContextInfo&,
399 const GrGLInterface*);
cdalton1dd05422015-06-12 09:01:18 -0700400 void initBlendEqationSupport(const GrGLContextInfo&);
Eric Karl5c779752017-05-08 12:02:07 -0700401 void initStencilSupport(const GrGLContextInfo&);
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000402 // This must be called after initFSAASupport().
brianosman20471892016-12-02 06:43:32 -0800403 void initConfigTable(const GrContextOptions&, const GrGLContextInfo&, const GrGLInterface*,
404 GrShaderCaps*);
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000405
Brian Salomon1edc5b92016-11-29 13:43:46 -0500406 void initShaderPrecisionTable(const GrGLContextInfo&, const GrGLInterface*, GrShaderCaps*);
jvanverthcba99b82015-06-24 06:59:57 -0700407
bsalomon1aa20292016-01-22 08:16:09 -0800408 GrGLStandard fStandard;
409
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000410 SkTArray<StencilFormat, true> fStencilFormats;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000411
412 int fMaxFragmentUniformVectors;
bsalomon@google.com60da4172012-06-01 19:25:00 +0000413
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000414 MSFBOType fMSFBOType;
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000415 InvalidateFBType fInvalidateFBType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000416 MapBufferType fMapBufferType;
jvanverthd7a2c1f2015-12-07 07:36:44 -0800417 TransferBufferType fTransferBufferType;
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000418
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000419 bool fUnpackRowLengthSupport : 1;
420 bool fUnpackFlipYSupport : 1;
421 bool fPackRowLengthSupport : 1;
422 bool fPackFlipYSupport : 1;
423 bool fTextureUsageSupport : 1;
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000424 bool fTextureRedSupport : 1;
Robert Phillips5ab72762017-06-07 12:04:18 -0400425 bool fAlpha8IsRenderable: 1;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000426 bool fImagingSupport : 1;
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000427 bool fVertexArrayObjectSupport : 1;
cdalton626e1ff2015-06-12 13:56:46 -0700428 bool fDirectStateAccessSupport : 1;
429 bool fDebugSupport : 1;
jvanverth3f801cb2014-12-16 09:49:38 -0800430 bool fES2CompatibilitySupport : 1;
csmartdalton4c18b622016-07-29 12:19:28 -0700431 bool fDrawInstancedSupport : 1;
cdalton06604b92016-02-05 10:09:51 -0800432 bool fDrawIndirectSupport : 1;
bsalomonfc9527a2016-08-29 09:18:39 -0700433 bool fDrawRangeElementsSupport : 1;
cdalton06604b92016-02-05 10:09:51 -0800434 bool fMultiDrawIndirectSupport : 1;
435 bool fBaseInstanceSupport : 1;
bsalomon@google.com96966a52013-02-21 16:34:21 +0000436 bool fUseNonVBOVertexAndIndexDynamicData : 1;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +0000437 bool fIsCoreProfile : 1;
joshualittc1f56b52015-06-22 12:31:31 -0700438 bool fBindFragDataLocationSupport : 1;
bsalomon88c7b982015-07-31 11:20:16 -0700439 bool fRGBA8888PixelsOpsAreSlow : 1;
440 bool fPartialFBOReadIsSlow : 1;
joshualitt7bdd70a2015-10-01 06:28:11 -0700441 bool fBindUniformLocationSupport : 1;
bsalomone5286e02016-01-14 09:24:09 -0800442 bool fRectangleTextureSupport : 1;
bsalomoncdee0092016-01-08 13:20:12 -0800443 bool fTextureSwizzleSupport : 1;
cblume09bd2c02016-03-01 14:08:28 -0800444 bool fMipMapLevelAndLodControlSupport : 1;
ericrkb4ecabd2016-03-11 15:18:20 -0800445 bool fRGBAToBGRAReadbackConversionsAreSlow : 1;
brianosman09563ce2016-06-02 08:59:34 -0700446 bool fDoManualMipmapping : 1;
brianosman20471892016-12-02 06:43:32 -0800447 bool fSRGBDecodeDisableSupport : 1;
brianosman851c2382016-12-07 10:03:25 -0800448 bool fSRGBDecodeDisableAffectsMipmaps : 1;
Eric Karlaeaf22b2017-05-18 15:08:09 -0700449 bool fClearToBoundaryValuesIsBroken : 1;
Brian Salomond17b4a62017-05-23 16:53:47 -0400450 bool fClearTextureSupport : 1;
Chris Dalton9926f4b2017-05-17 15:15:50 -0600451 bool fDrawArraysBaseVertexIsBroken : 1;
Mike Klein31550db2017-06-06 23:29:53 +0000452 bool fUseDrawToClearStencilClip : 1;
joshualitt58162332014-08-01 06:44:53 -0700453
Brian Salomone5e7eb12016-10-14 16:18:33 -0400454 uint32_t fBlitFramebufferFlags;
bsalomon083617b2016-02-12 12:10:14 -0800455
bsalomon7928ef62016-01-05 10:26:39 -0800456 /** Number type of the components (with out considering number of bits.) */
457 enum FormatType {
458 kNormalizedFixedPoint_FormatType,
459 kFloat_FormatType,
Brian Salomonbf7b6202016-11-11 16:08:03 -0500460 kInteger_FormatType,
bsalomon7928ef62016-01-05 10:26:39 -0800461 };
462
463 struct ReadPixelsFormat {
464 ReadPixelsFormat() : fFormat(0), fType(0) {}
465 GrGLenum fFormat;
466 GrGLenum fType;
467 };
468
bsalomon76148af2016-01-12 11:13:47 -0800469 struct ConfigFormats {
470 ConfigFormats() {
471 // Inits to known bad GL enum values.
472 memset(this, 0xAB, sizeof(ConfigFormats));
473 }
474 GrGLenum fBaseInternalFormat;
475 GrGLenum fSizedInternalFormat;
476
477 /** The external format and type are to be used when uploading/downloading data using this
478 config where both the CPU data and GrSurface are the same config. To get the external
479 format and type when converting between configs while copying to/from memory use
halcanary9d524f22016-03-29 09:03:52 -0700480 getExternalFormat().
bsalomon76148af2016-01-12 11:13:47 -0800481 The kTexImage external format is usually the same as kOther except for kSRGBA on some
482 GL contexts. */
483 GrGLenum fExternalFormat[kExternalFormatUsageCnt];
484 GrGLenum fExternalType;
485
bsalomon76148af2016-01-12 11:13:47 -0800486 // Either the base or sized internal format depending on the GL and config.
487 GrGLenum fInternalFormatTexImage;
488 GrGLenum fInternalFormatRenderbuffer;
489 };
490
bsalomon30447372015-12-21 09:03:05 -0800491 struct ConfigInfo {
bsalomon7928ef62016-01-05 10:26:39 -0800492 ConfigInfo() : fStencilFormatIndex(kUnknown_StencilIndex), fFlags(0) {}
bsalomon30447372015-12-21 09:03:05 -0800493
494 ConfigFormats fFormats;
495
bsalomon7928ef62016-01-05 10:26:39 -0800496 FormatType fFormatType;
497
498 // On ES contexts there are restrictions on type type/format that may be used for
499 // ReadPixels. One is implicitly specified by the current FBO's format. The other is
500 // queryable. This stores the queried option (lazily).
501 ReadPixelsFormat fSecondReadPixelsFormat;
502
bsalomon30447372015-12-21 09:03:05 -0800503 enum {
504 // This indicates that a stencil format has not yet been determined for the config.
505 kUnknown_StencilIndex = -1,
506 // This indicates that there is no supported stencil format for the config.
507 kUnsupported_StencilFormatIndex = -2
508 };
bsalomon480e8c02015-12-21 13:44:18 -0800509
510 // Index fStencilFormats.
511 int fStencilFormatIndex;
512
513 enum {
bsalomon41e4384e2016-01-08 09:12:44 -0800514 kVerifiedColorAttachment_Flag = 0x1,
515 kTextureable_Flag = 0x2,
516 kRenderable_Flag = 0x4,
517 kRenderableWithMSAA_Flag = 0x8,
Brian Salomon71d9d842016-11-03 13:42:00 -0400518 /** kFBOColorAttachment means that even if the config cannot be a GrRenderTarget, we can
519 still attach it to a FBO for blitting or reading pixels. */
520 kFBOColorAttachment_Flag = 0x10,
521 kCanUseTexStorage_Flag = 0x20,
522 kCanUseWithTexelBuffer_Flag = 0x40,
Brian Salomonf9f45122016-11-29 11:59:17 -0500523 kCanUseAsImageStorage_Flag = 0x80,
bsalomon480e8c02015-12-21 13:44:18 -0800524 };
525 uint32_t fFlags;
bsalomoncdee0092016-01-08 13:20:12 -0800526
527 GrSwizzle fSwizzle;
bsalomon30447372015-12-21 09:03:05 -0800528 };
529
530 ConfigInfo fConfigTable[kGrPixelConfigCnt];
531
bsalomon4b91f762015-05-19 09:29:46 -0700532 typedef GrCaps INHERITED;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000533};
534
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000535#endif