blob: 68cbc9bf165fd1b6dac61a58eaf3220128220114 [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 Salomonf9f45122016-11-29 11:59:17 -0500137 bool canConfigBeImageStorage(GrPixelConfig config) const override {
138 return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kCanUseAsImageStorage_Flag);
139 }
Brian Salomon71d9d842016-11-03 13:42:00 -0400140 bool canConfigBeFBOColorAttachment(GrPixelConfig config) const {
141 return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kFBOColorAttachment_Flag);
142 }
143
cblume790d5132016-02-29 11:13:29 -0800144 bool isConfigTexSupportEnabled(GrPixelConfig config) const {
cblume790d5132016-02-29 11:13:29 -0800145 return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kCanUseTexStorage_Flag);
146 }
147
cdalton74b8d322016-04-11 14:47:28 -0700148 bool canUseConfigWithTexelBuffer(GrPixelConfig config) const {
149 return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kCanUseWithTexelBuffer_Flag);
150 }
151
bsalomoncdee0092016-01-08 13:20:12 -0800152 /** Returns the mapping between GrPixelConfig components and GL internal format components. */
153 const GrSwizzle& configSwizzle(GrPixelConfig config) const {
154 return fConfigTable[config].fSwizzle;
155 }
156
cdalton74b8d322016-04-11 14:47:28 -0700157 GrGLenum configSizedInternalFormat(GrPixelConfig config) const {
158 return fConfigTable[config].fFormats.fSizedInternalFormat;
159 }
160
bsalomon76148af2016-01-12 11:13:47 -0800161 bool getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
162 GrGLenum* internalFormat, GrGLenum* externalFormat,
163 GrGLenum* externalType) const;
164
bsalomon76148af2016-01-12 11:13:47 -0800165 bool getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
166 GrGLenum* externalFormat, GrGLenum* externalType) const;
167
168 bool getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const;
169
Brian Salomonf9f45122016-11-29 11:59:17 -0500170 /** The format to use read/write a texture as an image in a shader */
171 GrGLenum getImageFormat(GrPixelConfig config) const {
172 return fConfigTable[config].fFormats.fSizedInternalFormat;
173 }
174
bsalomon30447372015-12-21 09:03:05 -0800175 /**
176 * Gets an array of legal stencil formats. These formats are not guaranteed
177 * to be supported by the driver but are legal GLenum names given the GL
178 * version and extensions supported.
179 */
180 const SkTArray<StencilFormat, true>& stencilFormats() const {
181 return fStencilFormats;
182 }
183
184 /**
185 * Has a stencil format index been found for the config (or we've found that no format works).
186 */
187 bool hasStencilFormatBeenDeterminedForConfig(GrPixelConfig config) const {
188 return fConfigTable[config].fStencilFormatIndex != ConfigInfo::kUnknown_StencilIndex;
189 }
190
191 /**
192 * Gets the stencil format index for the config. This assumes
193 * hasStencilFormatBeenDeterminedForConfig has already been checked. Returns a value < 0 if
194 * no stencil format is supported with the config. Otherwise, returned index refers to the array
195 * returned by stencilFormats().
196 */
197 int getStencilFormatIndexForConfig(GrPixelConfig config) const {
198 SkASSERT(this->hasStencilFormatBeenDeterminedForConfig(config));
199 return fConfigTable[config].fStencilFormatIndex;
200 }
201
202 /**
203 * If index is >= 0 this records an index into stencilFormats() as the best stencil format for
204 * the config. If < 0 it records that the config has no supported stencil format index.
205 */
206 void setStencilFormatIndexForConfig(GrPixelConfig config, int index) {
207 SkASSERT(!this->hasStencilFormatBeenDeterminedForConfig(config));
208 if (index < 0) {
209 fConfigTable[config].fStencilFormatIndex = ConfigInfo::kUnsupported_StencilFormatIndex;
210 } else {
211 fConfigTable[config].fStencilFormatIndex = index;
212 }
213 }
214
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000215 /**
216 * Call to note that a color config has been verified as a valid color
217 * attachment. This may save future calls to glCheckFramebufferStatus
218 * using isConfigVerifiedColorAttachment().
219 */
220 void markConfigAsValidColorAttachment(GrPixelConfig config) {
bsalomon480e8c02015-12-21 13:44:18 -0800221 fConfigTable[config].fFlags |= ConfigInfo::kVerifiedColorAttachment_Flag;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000222 }
223
224 /**
225 * Call to check whether a config has been verified as a valid color
226 * attachment.
227 */
228 bool isConfigVerifiedColorAttachment(GrPixelConfig config) const {
bsalomon480e8c02015-12-21 13:44:18 -0800229 return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kVerifiedColorAttachment_Flag);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000230 }
231
232 /**
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000233 * Reports the type of MSAA FBO support.
234 */
235 MSFBOType msFBOType() const { return fMSFBOType; }
236
237 /**
bsalomon083617b2016-02-12 12:10:14 -0800238 * Does the preferred MSAA FBO extension have MSAA renderbuffers?
bsalomon@google.com347c3822013-05-01 20:10:01 +0000239 */
240 bool usesMSAARenderBuffers() const {
241 return kNone_MSFBOType != fMSFBOType &&
242 kES_IMG_MsToTexture_MSFBOType != fMSFBOType &&
vbuzinovdded6962015-06-12 08:59:45 -0700243 kES_EXT_MsToTexture_MSFBOType != fMSFBOType &&
244 kMixedSamples_MSFBOType != fMSFBOType;
bsalomon@google.com347c3822013-05-01 20:10:01 +0000245 }
246
247 /**
bsalomon083617b2016-02-12 12:10:14 -0800248 * What functionality is supported by glBlitFramebuffer.
249 */
Brian Salomone5e7eb12016-10-14 16:18:33 -0400250 uint32_t blitFramebufferSupportFlags() const { return fBlitFramebufferFlags; }
bsalomon083617b2016-02-12 12:10:14 -0800251
252 /**
bsalomon@google.com347c3822013-05-01 20:10:01 +0000253 * Is the MSAA FBO extension one where the texture is multisampled when bound to an FBO and
254 * then implicitly resolved when read.
255 */
256 bool usesImplicitMSAAResolve() const {
257 return kES_IMG_MsToTexture_MSFBOType == fMSFBOType ||
258 kES_EXT_MsToTexture_MSFBOType == fMSFBOType;
259 }
260
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000261 InvalidateFBType invalidateFBType() const { return fInvalidateFBType; }
262
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000263 /// What type of buffer mapping is supported?
264 MapBufferType mapBufferType() const { return fMapBufferType; }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000265
jvanverthd7a2c1f2015-12-07 07:36:44 -0800266 /// What type of transfer buffer is supported?
267 TransferBufferType transferBufferType() const { return fTransferBufferType; }
268
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000269 /// The maximum number of fragment uniform vectors (GLES has min. 16).
270 int maxFragmentUniformVectors() const { return fMaxFragmentUniformVectors; }
271
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000272 /**
273 * Depending on the ES extensions present the BGRA external format may
bsalomon41e4384e2016-01-08 09:12:44 -0800274 * correspond to either a BGRA or RGBA internalFormat. On desktop GL it is
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000275 * RGBA.
276 */
bsalomon41e4384e2016-01-08 09:12:44 -0800277 bool bgraIsInternalFormat() const;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000278
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000279 /// Is there support for GL_UNPACK_ROW_LENGTH
280 bool unpackRowLengthSupport() const { return fUnpackRowLengthSupport; }
281
282 /// Is there support for GL_UNPACK_FLIP_Y
283 bool unpackFlipYSupport() const { return fUnpackFlipYSupport; }
284
285 /// Is there support for GL_PACK_ROW_LENGTH
286 bool packRowLengthSupport() const { return fPackRowLengthSupport; }
287
288 /// Is there support for GL_PACK_REVERSE_ROW_ORDER
289 bool packFlipYSupport() const { return fPackFlipYSupport; }
290
291 /// Is there support for texture parameter GL_TEXTURE_USAGE
292 bool textureUsageSupport() const { return fTextureUsageSupport; }
293
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000294 /// Is there support for GL_RED and GL_R8
295 bool textureRedSupport() const { return fTextureRedSupport; }
296
Robert Phillips5ab72762017-06-07 12:04:18 -0400297 /// Is GL_ALPHA8 renderable
298 bool alpha8IsRenderable() const { return fAlpha8IsRenderable; }
299
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000300 /// Is GL_ARB_IMAGING supported
301 bool imagingSupport() const { return fImagingSupport; }
302
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000303 /// Is there support for Vertex Array Objects?
304 bool vertexArrayObjectSupport() const { return fVertexArrayObjectSupport; }
305
cdalton626e1ff2015-06-12 13:56:46 -0700306 /// Is there support for GL_EXT_direct_state_access?
307 bool directStateAccessSupport() const { return fDirectStateAccessSupport; }
308
309 /// Is there support for GL_KHR_debug?
310 bool debugSupport() const { return fDebugSupport; }
311
jvanverth3f801cb2014-12-16 09:49:38 -0800312 /// Is there support for ES2 compatability?
313 bool ES2CompatibilitySupport() const { return fES2CompatibilitySupport; }
314
csmartdalton4c18b622016-07-29 12:19:28 -0700315 /// Is there support for glDraw*Instanced?
316 bool drawInstancedSupport() const { return fDrawInstancedSupport; }
317
cdalton06604b92016-02-05 10:09:51 -0800318 /// Is there support for glDraw*Indirect? Note that the baseInstance fields of indirect draw
319 /// commands cannot be used unless we have base instance support.
320 bool drawIndirectSupport() const { return fDrawIndirectSupport; }
321
322 /// Is there support for glMultiDraw*Indirect? Note that the baseInstance fields of indirect
323 /// draw commands cannot be used unless we have base instance support.
324 bool multiDrawIndirectSupport() const { return fMultiDrawIndirectSupport; }
325
bsalomonfc9527a2016-08-29 09:18:39 -0700326 /// Is there support for glDrawRangeElements?
327 bool drawRangeElementsSupport() const { return fDrawRangeElementsSupport; }
328
cdalton06604b92016-02-05 10:09:51 -0800329 /// Are the baseInstance fields supported in indirect draw commands?
330 bool baseInstanceSupport() const { return fBaseInstanceSupport; }
331
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000332 /// Use indices or vertices in CPU arrays rather than VBOs for dynamic content.
bsalomon76148af2016-01-12 11:13:47 -0800333 bool useNonVBOVertexAndIndexDynamicData() const { return fUseNonVBOVertexAndIndexDynamicData; }
bsalomon@google.com96966a52013-02-21 16:34:21 +0000334
Brian Salomon71d9d842016-11-03 13:42:00 -0400335 /// Does ReadPixels support reading readConfig pixels from a FBO that is surfaceConfig?
336 bool readPixelsSupported(GrPixelConfig surfaceConfig,
bsalomon7928ef62016-01-05 10:26:39 -0800337 GrPixelConfig readConfig,
bsalomon1aa20292016-01-22 08:16:09 -0800338 std::function<void (GrGLenum, GrGLint*)> getIntegerv,
bsalomon2c3db322016-11-08 13:26:24 -0800339 std::function<bool ()> bindRenderTarget,
340 std::function<void ()> unbindRenderTarget) const;
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000341
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +0000342 bool isCoreProfile() const { return fIsCoreProfile; }
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000343
joshualittc1f56b52015-06-22 12:31:31 -0700344 bool bindFragDataLocationSupport() const { return fBindFragDataLocationSupport; }
345
joshualitt7bdd70a2015-10-01 06:28:11 -0700346 bool bindUniformLocationSupport() const { return fBindUniformLocationSupport; }
347
bsalomone5286e02016-01-14 09:24:09 -0800348 /// Are textures with GL_TEXTURE_RECTANGLE type supported.
349 bool rectangleTextureSupport() const { return fRectangleTextureSupport; }
350
bsalomoncdee0092016-01-08 13:20:12 -0800351 /// GL_ARB_texture_swizzle
352 bool textureSwizzleSupport() const { return fTextureSwizzleSupport; }
353
cblume09bd2c02016-03-01 14:08:28 -0800354 bool mipMapLevelAndLodControlSupport() const { return fMipMapLevelAndLodControlSupport; }
355
brianosman09563ce2016-06-02 08:59:34 -0700356 bool doManualMipmapping() const { return fDoManualMipmapping; }
357
brianosman851c2382016-12-07 10:03:25 -0800358 bool srgbDecodeDisableAffectsMipmaps() const { return fSRGBDecodeDisableAffectsMipmaps; }
brianosman20471892016-12-02 06:43:32 -0800359
Brian Osman71a18892017-08-10 10:23:25 -0400360 void onDumpJSON(SkJSONWriter*) const override;
commit-bot@chromium.orgbeb8b3a2014-04-15 15:37:51 +0000361
bsalomon88c7b982015-07-31 11:20:16 -0700362 bool rgba8888PixelsOpsAreSlow() const { return fRGBA8888PixelsOpsAreSlow; }
363 bool partialFBOReadIsSlow() const { return fPartialFBOReadIsSlow; }
ericrkb4ecabd2016-03-11 15:18:20 -0800364 bool rgbaToBgraReadbackConversionsAreSlow() const {
365 return fRGBAToBGRAReadbackConversionsAreSlow;
366 }
bsalomon88c7b982015-07-31 11:20:16 -0700367
Eric Karlaeaf22b2017-05-18 15:08:09 -0700368 // Certain Intel GPUs on Mac fail to clear if the glClearColor is made up of only 1s and 0s.
369 bool clearToBoundaryValuesIsBroken() const { return fClearToBoundaryValuesIsBroken; }
Chris Dalton9926f4b2017-05-17 15:15:50 -0600370
Brian Salomond17b4a62017-05-23 16:53:47 -0400371 /// glClearTex(Sub)Image support
372 bool clearTextureSupport() const { return fClearTextureSupport; }
373
Chris Dalton9926f4b2017-05-17 15:15:50 -0600374 // Adreno/MSAA drops a draw on the imagefiltersbase GM if the base vertex param to
375 // glDrawArrays is nonzero.
376 // https://bugs.chromium.org/p/skia/issues/detail?id=6650
377 bool drawArraysBaseVertexIsBroken() const { return fDrawArraysBaseVertexIsBroken; }
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
Robert Phillipsbf25d432017-04-07 10:08:53 -0400402 bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
403 bool* rectsMustMatch, bool* disallowSubrect) const override;
Brian Salomon467921e2017-03-06 16:17:12 -0500404
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000405private:
bsalomon76148af2016-01-12 11:13:47 -0800406 enum ExternalFormatUsage {
407 kTexImage_ExternalFormatUsage,
408 kOther_ExternalFormatUsage,
409
410 kLast_ExternalFormatUsage = kOther_ExternalFormatUsage
411 };
412 static const int kExternalFormatUsageCnt = kLast_ExternalFormatUsage + 1;
413 bool getExternalFormat(GrPixelConfig surfaceConfig, GrPixelConfig memoryConfig,
414 ExternalFormatUsage usage, GrGLenum* externalFormat,
415 GrGLenum* externalType) const;
416
cdalton4cd67132015-06-10 19:23:46 -0700417 void init(const GrContextOptions&, const GrGLContextInfo&, const GrGLInterface*);
egdaniel05ded892015-10-26 07:38:05 -0700418 void initGLSL(const GrGLContextInfo&);
kkinnunencfe62e32015-07-01 02:58:50 -0700419 bool hasPathRenderingSupport(const GrGLContextInfo&, const GrGLInterface*);
bsalomon424cc262015-05-22 10:37:30 -0700420
egdanielb7e7d572015-11-04 04:23:53 -0800421 void onApplyOptionsOverrides(const GrContextOptions& options) override;
422
Eric Karl5c779752017-05-08 12:02:07 -0700423 void initFSAASupport(const GrContextOptions& contextOptions, const GrGLContextInfo&,
424 const GrGLInterface*);
cdalton1dd05422015-06-12 09:01:18 -0700425 void initBlendEqationSupport(const GrGLContextInfo&);
Eric Karl5c779752017-05-08 12:02:07 -0700426 void initStencilSupport(const GrGLContextInfo&);
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000427 // This must be called after initFSAASupport().
brianosman20471892016-12-02 06:43:32 -0800428 void initConfigTable(const GrContextOptions&, const GrGLContextInfo&, const GrGLInterface*,
429 GrShaderCaps*);
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000430
Brian Salomon1edc5b92016-11-29 13:43:46 -0500431 void initShaderPrecisionTable(const GrGLContextInfo&, const GrGLInterface*, GrShaderCaps*);
jvanverthcba99b82015-06-24 06:59:57 -0700432
bsalomon1aa20292016-01-22 08:16:09 -0800433 GrGLStandard fStandard;
434
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000435 SkTArray<StencilFormat, true> fStencilFormats;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000436
437 int fMaxFragmentUniformVectors;
bsalomon@google.com60da4172012-06-01 19:25:00 +0000438
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000439 MSFBOType fMSFBOType;
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000440 InvalidateFBType fInvalidateFBType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000441 MapBufferType fMapBufferType;
jvanverthd7a2c1f2015-12-07 07:36:44 -0800442 TransferBufferType fTransferBufferType;
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000443
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000444 bool fUnpackRowLengthSupport : 1;
445 bool fUnpackFlipYSupport : 1;
446 bool fPackRowLengthSupport : 1;
447 bool fPackFlipYSupport : 1;
448 bool fTextureUsageSupport : 1;
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000449 bool fTextureRedSupport : 1;
Robert Phillips5ab72762017-06-07 12:04:18 -0400450 bool fAlpha8IsRenderable: 1;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000451 bool fImagingSupport : 1;
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000452 bool fVertexArrayObjectSupport : 1;
cdalton626e1ff2015-06-12 13:56:46 -0700453 bool fDirectStateAccessSupport : 1;
454 bool fDebugSupport : 1;
jvanverth3f801cb2014-12-16 09:49:38 -0800455 bool fES2CompatibilitySupport : 1;
csmartdalton4c18b622016-07-29 12:19:28 -0700456 bool fDrawInstancedSupport : 1;
cdalton06604b92016-02-05 10:09:51 -0800457 bool fDrawIndirectSupport : 1;
bsalomonfc9527a2016-08-29 09:18:39 -0700458 bool fDrawRangeElementsSupport : 1;
cdalton06604b92016-02-05 10:09:51 -0800459 bool fMultiDrawIndirectSupport : 1;
460 bool fBaseInstanceSupport : 1;
bsalomon@google.com96966a52013-02-21 16:34:21 +0000461 bool fUseNonVBOVertexAndIndexDynamicData : 1;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +0000462 bool fIsCoreProfile : 1;
joshualittc1f56b52015-06-22 12:31:31 -0700463 bool fBindFragDataLocationSupport : 1;
bsalomon88c7b982015-07-31 11:20:16 -0700464 bool fRGBA8888PixelsOpsAreSlow : 1;
465 bool fPartialFBOReadIsSlow : 1;
joshualitt7bdd70a2015-10-01 06:28:11 -0700466 bool fBindUniformLocationSupport : 1;
bsalomone5286e02016-01-14 09:24:09 -0800467 bool fRectangleTextureSupport : 1;
bsalomoncdee0092016-01-08 13:20:12 -0800468 bool fTextureSwizzleSupport : 1;
cblume09bd2c02016-03-01 14:08:28 -0800469 bool fMipMapLevelAndLodControlSupport : 1;
ericrkb4ecabd2016-03-11 15:18:20 -0800470 bool fRGBAToBGRAReadbackConversionsAreSlow : 1;
brianosman09563ce2016-06-02 08:59:34 -0700471 bool fDoManualMipmapping : 1;
brianosman851c2382016-12-07 10:03:25 -0800472 bool fSRGBDecodeDisableAffectsMipmaps : 1;
Eric Karlaeaf22b2017-05-18 15:08:09 -0700473 bool fClearToBoundaryValuesIsBroken : 1;
Brian Salomond17b4a62017-05-23 16:53:47 -0400474 bool fClearTextureSupport : 1;
Chris Dalton9926f4b2017-05-17 15:15:50 -0600475 bool fDrawArraysBaseVertexIsBroken : 1;
Mike Klein31550db2017-06-06 23:29:53 +0000476 bool fUseDrawToClearStencilClip : 1;
Brian Salomon9bada542017-06-12 12:09:30 -0400477 bool fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO : 1;
478 bool fUseDrawInsteadOfAllRenderTargetWrites : 1;
Brian Salomon6d9c88b2017-06-12 10:24:42 -0400479 bool fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines : 1;
joshualitt58162332014-08-01 06:44:53 -0700480
Brian Salomone5e7eb12016-10-14 16:18:33 -0400481 uint32_t fBlitFramebufferFlags;
bsalomon083617b2016-02-12 12:10:14 -0800482
bsalomon7928ef62016-01-05 10:26:39 -0800483 /** Number type of the components (with out considering number of bits.) */
484 enum FormatType {
485 kNormalizedFixedPoint_FormatType,
486 kFloat_FormatType,
Brian Salomonbf7b6202016-11-11 16:08:03 -0500487 kInteger_FormatType,
bsalomon7928ef62016-01-05 10:26:39 -0800488 };
489
490 struct ReadPixelsFormat {
491 ReadPixelsFormat() : fFormat(0), fType(0) {}
492 GrGLenum fFormat;
493 GrGLenum fType;
494 };
495
bsalomon76148af2016-01-12 11:13:47 -0800496 struct ConfigFormats {
497 ConfigFormats() {
498 // Inits to known bad GL enum values.
499 memset(this, 0xAB, sizeof(ConfigFormats));
500 }
501 GrGLenum fBaseInternalFormat;
502 GrGLenum fSizedInternalFormat;
503
504 /** The external format and type are to be used when uploading/downloading data using this
505 config where both the CPU data and GrSurface are the same config. To get the external
506 format and type when converting between configs while copying to/from memory use
halcanary9d524f22016-03-29 09:03:52 -0700507 getExternalFormat().
bsalomon76148af2016-01-12 11:13:47 -0800508 The kTexImage external format is usually the same as kOther except for kSRGBA on some
509 GL contexts. */
510 GrGLenum fExternalFormat[kExternalFormatUsageCnt];
511 GrGLenum fExternalType;
512
bsalomon76148af2016-01-12 11:13:47 -0800513 // Either the base or sized internal format depending on the GL and config.
514 GrGLenum fInternalFormatTexImage;
515 GrGLenum fInternalFormatRenderbuffer;
516 };
517
bsalomon30447372015-12-21 09:03:05 -0800518 struct ConfigInfo {
bsalomon7928ef62016-01-05 10:26:39 -0800519 ConfigInfo() : fStencilFormatIndex(kUnknown_StencilIndex), fFlags(0) {}
bsalomon30447372015-12-21 09:03:05 -0800520
521 ConfigFormats fFormats;
522
bsalomon7928ef62016-01-05 10:26:39 -0800523 FormatType fFormatType;
524
525 // On ES contexts there are restrictions on type type/format that may be used for
526 // ReadPixels. One is implicitly specified by the current FBO's format. The other is
527 // queryable. This stores the queried option (lazily).
528 ReadPixelsFormat fSecondReadPixelsFormat;
529
bsalomon30447372015-12-21 09:03:05 -0800530 enum {
531 // This indicates that a stencil format has not yet been determined for the config.
532 kUnknown_StencilIndex = -1,
533 // This indicates that there is no supported stencil format for the config.
534 kUnsupported_StencilFormatIndex = -2
535 };
bsalomon480e8c02015-12-21 13:44:18 -0800536
537 // Index fStencilFormats.
Greg Daniel81e7bf82017-07-19 14:47:42 -0400538 int fStencilFormatIndex;
539
540 SkTDArray<int> fColorSampleCounts;
bsalomon480e8c02015-12-21 13:44:18 -0800541
542 enum {
bsalomon41e4384e2016-01-08 09:12:44 -0800543 kVerifiedColorAttachment_Flag = 0x1,
544 kTextureable_Flag = 0x2,
545 kRenderable_Flag = 0x4,
546 kRenderableWithMSAA_Flag = 0x8,
Brian Salomon71d9d842016-11-03 13:42:00 -0400547 /** kFBOColorAttachment means that even if the config cannot be a GrRenderTarget, we can
548 still attach it to a FBO for blitting or reading pixels. */
549 kFBOColorAttachment_Flag = 0x10,
550 kCanUseTexStorage_Flag = 0x20,
551 kCanUseWithTexelBuffer_Flag = 0x40,
Brian Salomonf9f45122016-11-29 11:59:17 -0500552 kCanUseAsImageStorage_Flag = 0x80,
bsalomon480e8c02015-12-21 13:44:18 -0800553 };
554 uint32_t fFlags;
bsalomoncdee0092016-01-08 13:20:12 -0800555
556 GrSwizzle fSwizzle;
bsalomon30447372015-12-21 09:03:05 -0800557 };
558
559 ConfigInfo fConfigTable[kGrPixelConfigCnt];
560
bsalomon4b91f762015-05-19 09:29:46 -0700561 typedef GrCaps INHERITED;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000562};
563
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000564#endif