blob: 6efcc210593fe75c9126b6026c282ce9d1655a54 [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
Greg Daniel81e7bf82017-07-19 14:47:42 -0400115 int getSampleCount(int requestedCount, GrPixelConfig config) const override;
116
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 }
Greg Danielbb76ace2017-09-29 15:58:22 -0400128
129 bool isConfigCopyable(GrPixelConfig config) const override {
130 // In GL we have three ways to be able to copy. CopyTexImage, blit, and draw. CopyTexImage
131 // requires the src to be an FBO attachment, blit requires both src and dst to be FBO
132 // attachments, and draw requires the dst to be an FBO attachment. Thus to copy from and to
133 // the same config, we need that config to be renderable so we can attach it to an FBO.
134 return this->isConfigRenderable(config, false);
135 }
136
Brian Salomon71d9d842016-11-03 13:42:00 -0400137 bool canConfigBeFBOColorAttachment(GrPixelConfig config) const {
138 return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kFBOColorAttachment_Flag);
139 }
140
cblume790d5132016-02-29 11:13:29 -0800141 bool isConfigTexSupportEnabled(GrPixelConfig config) const {
cblume790d5132016-02-29 11:13:29 -0800142 return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kCanUseTexStorage_Flag);
143 }
144
cdalton74b8d322016-04-11 14:47:28 -0700145 bool canUseConfigWithTexelBuffer(GrPixelConfig config) const {
146 return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kCanUseWithTexelBuffer_Flag);
147 }
148
bsalomoncdee0092016-01-08 13:20:12 -0800149 /** Returns the mapping between GrPixelConfig components and GL internal format components. */
150 const GrSwizzle& configSwizzle(GrPixelConfig config) const {
151 return fConfigTable[config].fSwizzle;
152 }
153
cdalton74b8d322016-04-11 14:47:28 -0700154 GrGLenum configSizedInternalFormat(GrPixelConfig config) const {
155 return fConfigTable[config].fFormats.fSizedInternalFormat;
156 }
157
bsalomon76148af2016-01-12 11:13:47 -0800158 bool getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
159 GrGLenum* internalFormat, GrGLenum* externalFormat,
160 GrGLenum* externalType) const;
161
bsalomon76148af2016-01-12 11:13:47 -0800162 bool getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
163 GrGLenum* externalFormat, GrGLenum* externalType) const;
164
165 bool getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const;
166
Brian Salomonf9f45122016-11-29 11:59:17 -0500167 /** The format to use read/write a texture as an image in a shader */
168 GrGLenum getImageFormat(GrPixelConfig config) const {
169 return fConfigTable[config].fFormats.fSizedInternalFormat;
170 }
171
bsalomon30447372015-12-21 09:03:05 -0800172 /**
173 * Gets an array of legal stencil formats. These formats are not guaranteed
174 * to be supported by the driver but are legal GLenum names given the GL
175 * version and extensions supported.
176 */
177 const SkTArray<StencilFormat, true>& stencilFormats() const {
178 return fStencilFormats;
179 }
180
181 /**
182 * Has a stencil format index been found for the config (or we've found that no format works).
183 */
184 bool hasStencilFormatBeenDeterminedForConfig(GrPixelConfig config) const {
185 return fConfigTable[config].fStencilFormatIndex != ConfigInfo::kUnknown_StencilIndex;
186 }
187
188 /**
189 * Gets the stencil format index for the config. This assumes
190 * hasStencilFormatBeenDeterminedForConfig has already been checked. Returns a value < 0 if
191 * no stencil format is supported with the config. Otherwise, returned index refers to the array
192 * returned by stencilFormats().
193 */
194 int getStencilFormatIndexForConfig(GrPixelConfig config) const {
195 SkASSERT(this->hasStencilFormatBeenDeterminedForConfig(config));
196 return fConfigTable[config].fStencilFormatIndex;
197 }
198
199 /**
200 * If index is >= 0 this records an index into stencilFormats() as the best stencil format for
201 * the config. If < 0 it records that the config has no supported stencil format index.
202 */
203 void setStencilFormatIndexForConfig(GrPixelConfig config, int index) {
204 SkASSERT(!this->hasStencilFormatBeenDeterminedForConfig(config));
205 if (index < 0) {
206 fConfigTable[config].fStencilFormatIndex = ConfigInfo::kUnsupported_StencilFormatIndex;
207 } else {
208 fConfigTable[config].fStencilFormatIndex = index;
209 }
210 }
211
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000212 /**
213 * Call to note that a color config has been verified as a valid color
214 * attachment. This may save future calls to glCheckFramebufferStatus
215 * using isConfigVerifiedColorAttachment().
216 */
217 void markConfigAsValidColorAttachment(GrPixelConfig config) {
bsalomon480e8c02015-12-21 13:44:18 -0800218 fConfigTable[config].fFlags |= ConfigInfo::kVerifiedColorAttachment_Flag;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000219 }
220
221 /**
222 * Call to check whether a config has been verified as a valid color
223 * attachment.
224 */
225 bool isConfigVerifiedColorAttachment(GrPixelConfig config) const {
bsalomon480e8c02015-12-21 13:44:18 -0800226 return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kVerifiedColorAttachment_Flag);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000227 }
228
229 /**
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000230 * Reports the type of MSAA FBO support.
231 */
232 MSFBOType msFBOType() const { return fMSFBOType; }
233
234 /**
bsalomon083617b2016-02-12 12:10:14 -0800235 * Does the preferred MSAA FBO extension have MSAA renderbuffers?
bsalomon@google.com347c3822013-05-01 20:10:01 +0000236 */
237 bool usesMSAARenderBuffers() const {
238 return kNone_MSFBOType != fMSFBOType &&
239 kES_IMG_MsToTexture_MSFBOType != fMSFBOType &&
vbuzinovdded6962015-06-12 08:59:45 -0700240 kES_EXT_MsToTexture_MSFBOType != fMSFBOType &&
241 kMixedSamples_MSFBOType != fMSFBOType;
bsalomon@google.com347c3822013-05-01 20:10:01 +0000242 }
243
244 /**
bsalomon083617b2016-02-12 12:10:14 -0800245 * What functionality is supported by glBlitFramebuffer.
246 */
Brian Salomone5e7eb12016-10-14 16:18:33 -0400247 uint32_t blitFramebufferSupportFlags() const { return fBlitFramebufferFlags; }
bsalomon083617b2016-02-12 12:10:14 -0800248
249 /**
bsalomon@google.com347c3822013-05-01 20:10:01 +0000250 * Is the MSAA FBO extension one where the texture is multisampled when bound to an FBO and
251 * then implicitly resolved when read.
252 */
253 bool usesImplicitMSAAResolve() const {
254 return kES_IMG_MsToTexture_MSFBOType == fMSFBOType ||
255 kES_EXT_MsToTexture_MSFBOType == fMSFBOType;
256 }
257
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000258 InvalidateFBType invalidateFBType() const { return fInvalidateFBType; }
259
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000260 /// What type of buffer mapping is supported?
261 MapBufferType mapBufferType() const { return fMapBufferType; }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000262
jvanverthd7a2c1f2015-12-07 07:36:44 -0800263 /// What type of transfer buffer is supported?
264 TransferBufferType transferBufferType() const { return fTransferBufferType; }
265
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000266 /// The maximum number of fragment uniform vectors (GLES has min. 16).
267 int maxFragmentUniformVectors() const { return fMaxFragmentUniformVectors; }
268
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000269 /**
270 * Depending on the ES extensions present the BGRA external format may
bsalomon41e4384e2016-01-08 09:12:44 -0800271 * correspond to either a BGRA or RGBA internalFormat. On desktop GL it is
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000272 * RGBA.
273 */
bsalomon41e4384e2016-01-08 09:12:44 -0800274 bool bgraIsInternalFormat() const;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000275
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000276 /// Is there support for GL_UNPACK_ROW_LENGTH
277 bool unpackRowLengthSupport() const { return fUnpackRowLengthSupport; }
278
279 /// Is there support for GL_UNPACK_FLIP_Y
280 bool unpackFlipYSupport() const { return fUnpackFlipYSupport; }
281
282 /// Is there support for GL_PACK_ROW_LENGTH
283 bool packRowLengthSupport() const { return fPackRowLengthSupport; }
284
285 /// Is there support for GL_PACK_REVERSE_ROW_ORDER
286 bool packFlipYSupport() const { return fPackFlipYSupport; }
287
288 /// Is there support for texture parameter GL_TEXTURE_USAGE
289 bool textureUsageSupport() const { return fTextureUsageSupport; }
290
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000291 /// Is there support for GL_RED and GL_R8
292 bool textureRedSupport() const { return fTextureRedSupport; }
293
Robert Phillips5ab72762017-06-07 12:04:18 -0400294 /// Is GL_ALPHA8 renderable
295 bool alpha8IsRenderable() const { return fAlpha8IsRenderable; }
296
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000297 /// Is GL_ARB_IMAGING supported
298 bool imagingSupport() const { return fImagingSupport; }
299
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000300 /// Is there support for Vertex Array Objects?
301 bool vertexArrayObjectSupport() const { return fVertexArrayObjectSupport; }
302
cdalton626e1ff2015-06-12 13:56:46 -0700303 /// Is there support for GL_EXT_direct_state_access?
304 bool directStateAccessSupport() const { return fDirectStateAccessSupport; }
305
306 /// Is there support for GL_KHR_debug?
307 bool debugSupport() const { return fDebugSupport; }
308
jvanverth3f801cb2014-12-16 09:49:38 -0800309 /// Is there support for ES2 compatability?
310 bool ES2CompatibilitySupport() const { return fES2CompatibilitySupport; }
311
csmartdalton4c18b622016-07-29 12:19:28 -0700312 /// Is there support for glDraw*Instanced?
313 bool drawInstancedSupport() const { return fDrawInstancedSupport; }
314
cdalton06604b92016-02-05 10:09:51 -0800315 /// Is there support for glDraw*Indirect? Note that the baseInstance fields of indirect draw
316 /// commands cannot be used unless we have base instance support.
317 bool drawIndirectSupport() const { return fDrawIndirectSupport; }
318
319 /// Is there support for glMultiDraw*Indirect? Note that the baseInstance fields of indirect
320 /// draw commands cannot be used unless we have base instance support.
321 bool multiDrawIndirectSupport() const { return fMultiDrawIndirectSupport; }
322
bsalomonfc9527a2016-08-29 09:18:39 -0700323 /// Is there support for glDrawRangeElements?
324 bool drawRangeElementsSupport() const { return fDrawRangeElementsSupport; }
325
cdalton06604b92016-02-05 10:09:51 -0800326 /// Are the baseInstance fields supported in indirect draw commands?
327 bool baseInstanceSupport() const { return fBaseInstanceSupport; }
328
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000329 /// Use indices or vertices in CPU arrays rather than VBOs for dynamic content.
bsalomon76148af2016-01-12 11:13:47 -0800330 bool useNonVBOVertexAndIndexDynamicData() const { return fUseNonVBOVertexAndIndexDynamicData; }
bsalomon@google.com96966a52013-02-21 16:34:21 +0000331
Brian Salomon71d9d842016-11-03 13:42:00 -0400332 /// Does ReadPixels support reading readConfig pixels from a FBO that is surfaceConfig?
333 bool readPixelsSupported(GrPixelConfig surfaceConfig,
bsalomon7928ef62016-01-05 10:26:39 -0800334 GrPixelConfig readConfig,
bsalomon1aa20292016-01-22 08:16:09 -0800335 std::function<void (GrGLenum, GrGLint*)> getIntegerv,
bsalomon2c3db322016-11-08 13:26:24 -0800336 std::function<bool ()> bindRenderTarget,
337 std::function<void ()> unbindRenderTarget) const;
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000338
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +0000339 bool isCoreProfile() const { return fIsCoreProfile; }
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000340
joshualittc1f56b52015-06-22 12:31:31 -0700341 bool bindFragDataLocationSupport() const { return fBindFragDataLocationSupport; }
342
joshualitt7bdd70a2015-10-01 06:28:11 -0700343 bool bindUniformLocationSupport() const { return fBindUniformLocationSupport; }
344
bsalomone5286e02016-01-14 09:24:09 -0800345 /// Are textures with GL_TEXTURE_RECTANGLE type supported.
346 bool rectangleTextureSupport() const { return fRectangleTextureSupport; }
347
bsalomoncdee0092016-01-08 13:20:12 -0800348 /// GL_ARB_texture_swizzle
349 bool textureSwizzleSupport() const { return fTextureSwizzleSupport; }
350
cblume09bd2c02016-03-01 14:08:28 -0800351 bool mipMapLevelAndLodControlSupport() const { return fMipMapLevelAndLodControlSupport; }
352
brianosman09563ce2016-06-02 08:59:34 -0700353 bool doManualMipmapping() const { return fDoManualMipmapping; }
354
brianosman851c2382016-12-07 10:03:25 -0800355 bool srgbDecodeDisableAffectsMipmaps() const { return fSRGBDecodeDisableAffectsMipmaps; }
brianosman20471892016-12-02 06:43:32 -0800356
Brian Osman71a18892017-08-10 10:23:25 -0400357 void onDumpJSON(SkJSONWriter*) const override;
commit-bot@chromium.orgbeb8b3a2014-04-15 15:37:51 +0000358
bsalomon88c7b982015-07-31 11:20:16 -0700359 bool rgba8888PixelsOpsAreSlow() const { return fRGBA8888PixelsOpsAreSlow; }
360 bool partialFBOReadIsSlow() const { return fPartialFBOReadIsSlow; }
ericrkb4ecabd2016-03-11 15:18:20 -0800361 bool rgbaToBgraReadbackConversionsAreSlow() const {
362 return fRGBAToBGRAReadbackConversionsAreSlow;
363 }
bsalomon88c7b982015-07-31 11:20:16 -0700364
Eric Karlaeaf22b2017-05-18 15:08:09 -0700365 // Certain Intel GPUs on Mac fail to clear if the glClearColor is made up of only 1s and 0s.
366 bool clearToBoundaryValuesIsBroken() const { return fClearToBoundaryValuesIsBroken; }
Chris Dalton9926f4b2017-05-17 15:15:50 -0600367
Brian Salomond17b4a62017-05-23 16:53:47 -0400368 /// glClearTex(Sub)Image support
369 bool clearTextureSupport() const { return fClearTextureSupport; }
370
Chris Dalton9926f4b2017-05-17 15:15:50 -0600371 // Adreno/MSAA drops a draw on the imagefiltersbase GM if the base vertex param to
372 // glDrawArrays is nonzero.
373 // https://bugs.chromium.org/p/skia/issues/detail?id=6650
374 bool drawArraysBaseVertexIsBroken() const { return fDrawArraysBaseVertexIsBroken; }
375
Brian Salomon43f8bf02017-10-18 08:33:29 -0400376 // Many drivers have issues with color clears.
377 bool useDrawToClearColor() const { return fUseDrawToClearColor; }
378
Mike Klein31550db2017-06-06 23:29:53 +0000379 /// Adreno 4xx devices experience an issue when there are a large number of stencil clip bit
380 /// clears. The minimal repro steps are not precisely known but drawing a rect with a stencil
381 /// op instead of using glClear seems to resolve the issue.
382 bool useDrawToClearStencilClip() const { return fUseDrawToClearStencilClip; }
383
Brian Salomon9bada542017-06-12 12:09:30 -0400384 // If true then we must use an intermediate surface to perform partial updates to unorm textures
385 // that have ever been bound to a FBO.
386 bool disallowTexSubImageForUnormConfigTexturesEverBoundToFBO() const {
387 return fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO;
388 }
389
390 // Use an intermediate surface to write pixels (full or partial overwrite) to into a texture
391 // that is bound to an FBO.
392 bool useDrawInsteadOfAllRenderTargetWrites() const {
393 return fUseDrawInsteadOfAllRenderTargetWrites;
394 }
395
Brian Salomon6d9c88b2017-06-12 10:24:42 -0400396 // At least some Adreno 3xx drivers draw lines incorrectly after drawing non-lines. Toggling
397 // face culling on and off seems to resolve this.
398 bool requiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines() const {
399 return fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines;
Brian Salomonaf971de2017-06-08 16:11:33 -0400400 }
401
Chris Daltoncc604e52017-10-06 16:27:32 -0600402 // Returns the observed maximum number of instances the driver can handle in a single call to
403 // glDrawArraysInstanced without crashing, or 'pendingInstanceCount' if this
404 // workaround is not necessary.
405 // NOTE: the return value may be larger than pendingInstanceCount.
406 int maxInstancesPerDrawArraysWithoutCrashing(int pendingInstanceCount) const {
407 return fMaxInstancesPerDrawArraysWithoutCrashing ? fMaxInstancesPerDrawArraysWithoutCrashing
408 : pendingInstanceCount;
409 }
410
Robert Phillipsbf25d432017-04-07 10:08:53 -0400411 bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
412 bool* rectsMustMatch, bool* disallowSubrect) const override;
Brian Salomon467921e2017-03-06 16:17:12 -0500413
Ethan Nicholasd1b2eec2017-11-01 15:45:43 -0400414 bool programBinarySupport() const {
415 return fProgramBinarySupport;
416 }
417
Greg Danielfaa095e2017-12-19 13:15:02 -0500418 bool validateBackendTexture(const GrBackendTexture&, SkColorType,
419 GrPixelConfig*) const override;
420 bool validateBackendRenderTarget(const GrBackendRenderTarget&, SkColorType,
421 GrPixelConfig*) const override;
Greg Danielf5d87582017-12-18 14:48:15 -0500422
Greg Danielfaa095e2017-12-19 13:15:02 -0500423private:
bsalomon76148af2016-01-12 11:13:47 -0800424 enum ExternalFormatUsage {
425 kTexImage_ExternalFormatUsage,
426 kOther_ExternalFormatUsage,
427
428 kLast_ExternalFormatUsage = kOther_ExternalFormatUsage
429 };
430 static const int kExternalFormatUsageCnt = kLast_ExternalFormatUsage + 1;
431 bool getExternalFormat(GrPixelConfig surfaceConfig, GrPixelConfig memoryConfig,
432 ExternalFormatUsage usage, GrGLenum* externalFormat,
433 GrGLenum* externalType) const;
434
cdalton4cd67132015-06-10 19:23:46 -0700435 void init(const GrContextOptions&, const GrGLContextInfo&, const GrGLInterface*);
Chris Dalton47c8ed32017-11-15 18:27:09 -0700436 void initGLSL(const GrGLContextInfo&, const GrGLInterface*);
kkinnunencfe62e32015-07-01 02:58:50 -0700437 bool hasPathRenderingSupport(const GrGLContextInfo&, const GrGLInterface*);
bsalomon424cc262015-05-22 10:37:30 -0700438
egdanielb7e7d572015-11-04 04:23:53 -0800439 void onApplyOptionsOverrides(const GrContextOptions& options) override;
440
Eric Karl5c779752017-05-08 12:02:07 -0700441 void initFSAASupport(const GrContextOptions& contextOptions, const GrGLContextInfo&,
442 const GrGLInterface*);
cdalton1dd05422015-06-12 09:01:18 -0700443 void initBlendEqationSupport(const GrGLContextInfo&);
Eric Karl5c779752017-05-08 12:02:07 -0700444 void initStencilSupport(const GrGLContextInfo&);
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000445 // This must be called after initFSAASupport().
brianosman20471892016-12-02 06:43:32 -0800446 void initConfigTable(const GrContextOptions&, const GrGLContextInfo&, const GrGLInterface*,
447 GrShaderCaps*);
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000448
bsalomon1aa20292016-01-22 08:16:09 -0800449 GrGLStandard fStandard;
450
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000451 SkTArray<StencilFormat, true> fStencilFormats;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000452
453 int fMaxFragmentUniformVectors;
bsalomon@google.com60da4172012-06-01 19:25:00 +0000454
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000455 MSFBOType fMSFBOType;
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000456 InvalidateFBType fInvalidateFBType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000457 MapBufferType fMapBufferType;
jvanverthd7a2c1f2015-12-07 07:36:44 -0800458 TransferBufferType fTransferBufferType;
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000459
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000460 bool fUnpackRowLengthSupport : 1;
461 bool fUnpackFlipYSupport : 1;
462 bool fPackRowLengthSupport : 1;
463 bool fPackFlipYSupport : 1;
464 bool fTextureUsageSupport : 1;
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000465 bool fTextureRedSupport : 1;
Robert Phillips5ab72762017-06-07 12:04:18 -0400466 bool fAlpha8IsRenderable: 1;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000467 bool fImagingSupport : 1;
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000468 bool fVertexArrayObjectSupport : 1;
cdalton626e1ff2015-06-12 13:56:46 -0700469 bool fDirectStateAccessSupport : 1;
470 bool fDebugSupport : 1;
jvanverth3f801cb2014-12-16 09:49:38 -0800471 bool fES2CompatibilitySupport : 1;
csmartdalton4c18b622016-07-29 12:19:28 -0700472 bool fDrawInstancedSupport : 1;
cdalton06604b92016-02-05 10:09:51 -0800473 bool fDrawIndirectSupport : 1;
bsalomonfc9527a2016-08-29 09:18:39 -0700474 bool fDrawRangeElementsSupport : 1;
cdalton06604b92016-02-05 10:09:51 -0800475 bool fMultiDrawIndirectSupport : 1;
476 bool fBaseInstanceSupport : 1;
bsalomon@google.com96966a52013-02-21 16:34:21 +0000477 bool fUseNonVBOVertexAndIndexDynamicData : 1;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +0000478 bool fIsCoreProfile : 1;
joshualittc1f56b52015-06-22 12:31:31 -0700479 bool fBindFragDataLocationSupport : 1;
bsalomon88c7b982015-07-31 11:20:16 -0700480 bool fRGBA8888PixelsOpsAreSlow : 1;
481 bool fPartialFBOReadIsSlow : 1;
joshualitt7bdd70a2015-10-01 06:28:11 -0700482 bool fBindUniformLocationSupport : 1;
bsalomone5286e02016-01-14 09:24:09 -0800483 bool fRectangleTextureSupport : 1;
bsalomoncdee0092016-01-08 13:20:12 -0800484 bool fTextureSwizzleSupport : 1;
cblume09bd2c02016-03-01 14:08:28 -0800485 bool fMipMapLevelAndLodControlSupport : 1;
ericrkb4ecabd2016-03-11 15:18:20 -0800486 bool fRGBAToBGRAReadbackConversionsAreSlow : 1;
brianosman09563ce2016-06-02 08:59:34 -0700487 bool fDoManualMipmapping : 1;
brianosman851c2382016-12-07 10:03:25 -0800488 bool fSRGBDecodeDisableAffectsMipmaps : 1;
Eric Karlaeaf22b2017-05-18 15:08:09 -0700489 bool fClearToBoundaryValuesIsBroken : 1;
Brian Salomond17b4a62017-05-23 16:53:47 -0400490 bool fClearTextureSupport : 1;
Chris Dalton9926f4b2017-05-17 15:15:50 -0600491 bool fDrawArraysBaseVertexIsBroken : 1;
Brian Salomon43f8bf02017-10-18 08:33:29 -0400492 bool fUseDrawToClearColor : 1;
Mike Klein31550db2017-06-06 23:29:53 +0000493 bool fUseDrawToClearStencilClip : 1;
Brian Salomon9bada542017-06-12 12:09:30 -0400494 bool fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO : 1;
495 bool fUseDrawInsteadOfAllRenderTargetWrites : 1;
Brian Salomon6d9c88b2017-06-12 10:24:42 -0400496 bool fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines : 1;
Ethan Nicholasd1b2eec2017-11-01 15:45:43 -0400497 bool fProgramBinarySupport : 1;
joshualitt58162332014-08-01 06:44:53 -0700498
Brian Salomone5e7eb12016-10-14 16:18:33 -0400499 uint32_t fBlitFramebufferFlags;
Chris Daltoncc604e52017-10-06 16:27:32 -0600500 int fMaxInstancesPerDrawArraysWithoutCrashing;
bsalomon083617b2016-02-12 12:10:14 -0800501
bsalomon7928ef62016-01-05 10:26:39 -0800502 /** Number type of the components (with out considering number of bits.) */
503 enum FormatType {
504 kNormalizedFixedPoint_FormatType,
505 kFloat_FormatType,
Brian Salomonbf7b6202016-11-11 16:08:03 -0500506 kInteger_FormatType,
bsalomon7928ef62016-01-05 10:26:39 -0800507 };
508
509 struct ReadPixelsFormat {
510 ReadPixelsFormat() : fFormat(0), fType(0) {}
511 GrGLenum fFormat;
512 GrGLenum fType;
513 };
514
bsalomon76148af2016-01-12 11:13:47 -0800515 struct ConfigFormats {
516 ConfigFormats() {
517 // Inits to known bad GL enum values.
518 memset(this, 0xAB, sizeof(ConfigFormats));
519 }
520 GrGLenum fBaseInternalFormat;
521 GrGLenum fSizedInternalFormat;
522
523 /** The external format and type are to be used when uploading/downloading data using this
524 config where both the CPU data and GrSurface are the same config. To get the external
525 format and type when converting between configs while copying to/from memory use
halcanary9d524f22016-03-29 09:03:52 -0700526 getExternalFormat().
bsalomon76148af2016-01-12 11:13:47 -0800527 The kTexImage external format is usually the same as kOther except for kSRGBA on some
528 GL contexts. */
529 GrGLenum fExternalFormat[kExternalFormatUsageCnt];
530 GrGLenum fExternalType;
531
bsalomon76148af2016-01-12 11:13:47 -0800532 // Either the base or sized internal format depending on the GL and config.
533 GrGLenum fInternalFormatTexImage;
534 GrGLenum fInternalFormatRenderbuffer;
535 };
536
bsalomon30447372015-12-21 09:03:05 -0800537 struct ConfigInfo {
bsalomon7928ef62016-01-05 10:26:39 -0800538 ConfigInfo() : fStencilFormatIndex(kUnknown_StencilIndex), fFlags(0) {}
bsalomon30447372015-12-21 09:03:05 -0800539
540 ConfigFormats fFormats;
541
bsalomon7928ef62016-01-05 10:26:39 -0800542 FormatType fFormatType;
543
544 // On ES contexts there are restrictions on type type/format that may be used for
545 // ReadPixels. One is implicitly specified by the current FBO's format. The other is
546 // queryable. This stores the queried option (lazily).
547 ReadPixelsFormat fSecondReadPixelsFormat;
548
bsalomon30447372015-12-21 09:03:05 -0800549 enum {
550 // This indicates that a stencil format has not yet been determined for the config.
551 kUnknown_StencilIndex = -1,
552 // This indicates that there is no supported stencil format for the config.
553 kUnsupported_StencilFormatIndex = -2
554 };
bsalomon480e8c02015-12-21 13:44:18 -0800555
556 // Index fStencilFormats.
Greg Daniel81e7bf82017-07-19 14:47:42 -0400557 int fStencilFormatIndex;
558
559 SkTDArray<int> fColorSampleCounts;
bsalomon480e8c02015-12-21 13:44:18 -0800560
561 enum {
bsalomon41e4384e2016-01-08 09:12:44 -0800562 kVerifiedColorAttachment_Flag = 0x1,
563 kTextureable_Flag = 0x2,
564 kRenderable_Flag = 0x4,
565 kRenderableWithMSAA_Flag = 0x8,
Brian Salomon71d9d842016-11-03 13:42:00 -0400566 /** kFBOColorAttachment means that even if the config cannot be a GrRenderTarget, we can
567 still attach it to a FBO for blitting or reading pixels. */
568 kFBOColorAttachment_Flag = 0x10,
569 kCanUseTexStorage_Flag = 0x20,
570 kCanUseWithTexelBuffer_Flag = 0x40,
bsalomon480e8c02015-12-21 13:44:18 -0800571 };
572 uint32_t fFlags;
bsalomoncdee0092016-01-08 13:20:12 -0800573
574 GrSwizzle fSwizzle;
bsalomon30447372015-12-21 09:03:05 -0800575 };
576
577 ConfigInfo fConfigTable[kGrPixelConfigCnt];
578
bsalomon4b91f762015-05-19 09:29:46 -0700579 typedef GrCaps INHERITED;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000580};
581
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000582#endif