bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
bsalomon | 1aa2029 | 2016-01-22 08:16:09 -0800 | [diff] [blame] | 12 | #include <functional> |
| 13 | |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 14 | #include "GrCaps.h" |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 15 | #include "GrGLStencilAttachment.h" |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 16 | #include "GrSwizzle.h" |
piotaixr | e4b2314 | 2014-10-02 10:57:53 -0700 | [diff] [blame] | 17 | #include "SkChecksum.h" |
mtklein | 2aa1f7e | 2015-02-20 12:35:32 -0800 | [diff] [blame] | 18 | #include "SkTHash.h" |
robertphillips@google.com | a2d7148 | 2012-08-01 20:08:47 +0000 | [diff] [blame] | 19 | #include "SkTArray.h" |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 20 | #include "../private/GrGLSL.h" |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 21 | |
| 22 | class GrGLContextInfo; |
bsalomon | 1aa2029 | 2016-01-22 08:16:09 -0800 | [diff] [blame] | 23 | class GrGLRenderTarget; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 24 | |
| 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 | */ |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 30 | class GrGLCaps : public GrCaps { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 31 | public: |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 32 | typedef GrGLStencilAttachment::Format StencilFormat; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 33 | |
| 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.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 42 | kNone_MSFBOType = 0, |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 43 | /** |
Brian Salomon | 00731b4 | 2016-10-14 11:30:51 -0400 | [diff] [blame] | 44 | * OpenGL < 3.0 with GL_EXT_framebuffer_object. Doesn't allow rendering to ALPHA. |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 45 | */ |
Brian Salomon | 00731b4 | 2016-10-14 11:30:51 -0400 | [diff] [blame] | 46 | kEXT_MSFBOType, |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 47 | /** |
Brian Salomon | 00731b4 | 2016-10-14 11:30:51 -0400 | [diff] [blame] | 48 | * OpenGL 3.0+, OpenGL ES 3.0+, and GL_ARB_framebuffer_object. |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 49 | */ |
Brian Salomon | 00731b4 | 2016-10-14 11:30:51 -0400 | [diff] [blame] | 50 | kStandard_MSFBOType, |
commit-bot@chromium.org | a8e5a06 | 2013-09-05 23:44:09 +0000 | [diff] [blame] | 51 | /** |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 52 | * GL_APPLE_framebuffer_multisample ES extension |
| 53 | */ |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 54 | kES_Apple_MSFBOType, |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 55 | /** |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 56 | * 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.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 60 | */ |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 61 | 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, |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 67 | /** |
| 68 | * GL_NV_framebuffer_mixed_samples. |
| 69 | */ |
| 70 | kMixedSamples_MSFBOType, |
bsalomon@google.com | 6b0cf02 | 2013-05-03 13:35:14 +0000 | [diff] [blame] | 71 | |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 72 | kLast_MSFBOType = kMixedSamples_MSFBOType |
bsalomon@google.com | 6b0cf02 | 2013-05-03 13:35:14 +0000 | [diff] [blame] | 73 | }; |
| 74 | |
Brian Salomon | e5e7eb1 | 2016-10-14 16:18:33 -0400 | [diff] [blame] | 75 | 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, |
bsalomon | 083617b | 2016-02-12 12:10:14 -0800 | [diff] [blame] | 83 | }; |
| 84 | |
commit-bot@chromium.org | 52ffbf6 | 2014-04-02 16:19:33 +0000 | [diff] [blame] | 85 | enum InvalidateFBType { |
| 86 | kNone_InvalidateFBType, |
| 87 | kDiscard_InvalidateFBType, //<! glDiscardFramebuffer() |
bsalomon | 083617b | 2016-02-12 12:10:14 -0800 | [diff] [blame] | 88 | kInvalidate_InvalidateFBType, //<! glInvalidateFramebuffer() |
commit-bot@chromium.org | 52ffbf6 | 2014-04-02 16:19:33 +0000 | [diff] [blame] | 89 | |
| 90 | kLast_InvalidateFBType = kInvalidate_InvalidateFBType |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 91 | }; |
| 92 | |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 93 | 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 | |
jvanverth | d7a2c1f | 2015-12-07 07:36:44 -0800 | [diff] [blame] | 102 | 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.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 110 | /** |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 111 | * Initializes the GrGLCaps to the set of features supported in the current |
| 112 | * OpenGL context accessible via ctxInfo. |
| 113 | */ |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 114 | GrGLCaps(const GrContextOptions& contextOptions, const GrGLContextInfo& ctxInfo, |
| 115 | const GrGLInterface* glInterface); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 116 | |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 117 | bool isConfigTexturable(GrPixelConfig config) const override { |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 118 | return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kTextureable_Flag); |
| 119 | } |
| 120 | |
| 121 | bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const override { |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 122 | 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 Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 128 | bool canConfigBeImageStorage(GrPixelConfig config) const override { |
| 129 | return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kCanUseAsImageStorage_Flag); |
| 130 | } |
Brian Salomon | 71d9d84 | 2016-11-03 13:42:00 -0400 | [diff] [blame] | 131 | bool canConfigBeFBOColorAttachment(GrPixelConfig config) const { |
| 132 | return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kFBOColorAttachment_Flag); |
| 133 | } |
| 134 | |
cblume | 790d513 | 2016-02-29 11:13:29 -0800 | [diff] [blame] | 135 | bool isConfigTexSupportEnabled(GrPixelConfig config) const { |
cblume | 790d513 | 2016-02-29 11:13:29 -0800 | [diff] [blame] | 136 | return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kCanUseTexStorage_Flag); |
| 137 | } |
| 138 | |
cdalton | 74b8d32 | 2016-04-11 14:47:28 -0700 | [diff] [blame] | 139 | bool canUseConfigWithTexelBuffer(GrPixelConfig config) const { |
| 140 | return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kCanUseWithTexelBuffer_Flag); |
| 141 | } |
| 142 | |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 143 | /** 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 | |
cdalton | 74b8d32 | 2016-04-11 14:47:28 -0700 | [diff] [blame] | 148 | GrGLenum configSizedInternalFormat(GrPixelConfig config) const { |
| 149 | return fConfigTable[config].fFormats.fSizedInternalFormat; |
| 150 | } |
| 151 | |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 152 | bool getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig, |
| 153 | GrGLenum* internalFormat, GrGLenum* externalFormat, |
| 154 | GrGLenum* externalType) const; |
| 155 | |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 156 | bool getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig, |
| 157 | GrGLenum* externalFormat, GrGLenum* externalType) const; |
| 158 | |
| 159 | bool getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const; |
| 160 | |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 161 | /** 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 | |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 166 | /** |
| 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.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 206 | /** |
| 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) { |
bsalomon | 480e8c0 | 2015-12-21 13:44:18 -0800 | [diff] [blame] | 212 | fConfigTable[config].fFlags |= ConfigInfo::kVerifiedColorAttachment_Flag; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 213 | } |
| 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 { |
bsalomon | 480e8c0 | 2015-12-21 13:44:18 -0800 | [diff] [blame] | 220 | return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kVerifiedColorAttachment_Flag); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | /** |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 224 | * Reports the type of MSAA FBO support. |
| 225 | */ |
| 226 | MSFBOType msFBOType() const { return fMSFBOType; } |
| 227 | |
| 228 | /** |
bsalomon | 083617b | 2016-02-12 12:10:14 -0800 | [diff] [blame] | 229 | * Does the preferred MSAA FBO extension have MSAA renderbuffers? |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 230 | */ |
| 231 | bool usesMSAARenderBuffers() const { |
| 232 | return kNone_MSFBOType != fMSFBOType && |
| 233 | kES_IMG_MsToTexture_MSFBOType != fMSFBOType && |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 234 | kES_EXT_MsToTexture_MSFBOType != fMSFBOType && |
| 235 | kMixedSamples_MSFBOType != fMSFBOType; |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | /** |
bsalomon | 083617b | 2016-02-12 12:10:14 -0800 | [diff] [blame] | 239 | * What functionality is supported by glBlitFramebuffer. |
| 240 | */ |
Brian Salomon | e5e7eb1 | 2016-10-14 16:18:33 -0400 | [diff] [blame] | 241 | uint32_t blitFramebufferSupportFlags() const { return fBlitFramebufferFlags; } |
bsalomon | 083617b | 2016-02-12 12:10:14 -0800 | [diff] [blame] | 242 | |
| 243 | /** |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 244 | * 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.org | 52ffbf6 | 2014-04-02 16:19:33 +0000 | [diff] [blame] | 252 | InvalidateFBType invalidateFBType() const { return fInvalidateFBType; } |
| 253 | |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 254 | /// What type of buffer mapping is supported? |
| 255 | MapBufferType mapBufferType() const { return fMapBufferType; } |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 256 | |
jvanverth | d7a2c1f | 2015-12-07 07:36:44 -0800 | [diff] [blame] | 257 | /// What type of transfer buffer is supported? |
| 258 | TransferBufferType transferBufferType() const { return fTransferBufferType; } |
| 259 | |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 260 | /// The maximum number of fragment uniform vectors (GLES has min. 16). |
| 261 | int maxFragmentUniformVectors() const { return fMaxFragmentUniformVectors; } |
| 262 | |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 263 | /** |
| 264 | * Depending on the ES extensions present the BGRA external format may |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 265 | * correspond to either a BGRA or RGBA internalFormat. On desktop GL it is |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 266 | * RGBA. |
| 267 | */ |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 268 | bool bgraIsInternalFormat() const; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 269 | |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 270 | /// 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.com | 443e5a5 | 2012-04-30 20:01:21 +0000 | [diff] [blame] | 285 | /// Is there support for GL_RED and GL_R8 |
| 286 | bool textureRedSupport() const { return fTextureRedSupport; } |
| 287 | |
bsalomon@google.com | e76b7cc | 2012-06-18 12:47:06 +0000 | [diff] [blame] | 288 | /// Is GL_ARB_IMAGING supported |
| 289 | bool imagingSupport() const { return fImagingSupport; } |
| 290 | |
bsalomon@google.com | 07631cf | 2013-03-05 14:14:58 +0000 | [diff] [blame] | 291 | /// Is there support for Vertex Array Objects? |
| 292 | bool vertexArrayObjectSupport() const { return fVertexArrayObjectSupport; } |
| 293 | |
cdalton | 626e1ff | 2015-06-12 13:56:46 -0700 | [diff] [blame] | 294 | /// 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 | |
jvanverth | 3f801cb | 2014-12-16 09:49:38 -0800 | [diff] [blame] | 300 | /// Is there support for ES2 compatability? |
| 301 | bool ES2CompatibilitySupport() const { return fES2CompatibilitySupport; } |
| 302 | |
csmartdalton | 4c18b62 | 2016-07-29 12:19:28 -0700 | [diff] [blame] | 303 | /// Is there support for glDraw*Instanced? |
| 304 | bool drawInstancedSupport() const { return fDrawInstancedSupport; } |
| 305 | |
cdalton | 06604b9 | 2016-02-05 10:09:51 -0800 | [diff] [blame] | 306 | /// 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 | |
bsalomon | fc9527a | 2016-08-29 09:18:39 -0700 | [diff] [blame] | 314 | /// Is there support for glDrawRangeElements? |
| 315 | bool drawRangeElementsSupport() const { return fDrawRangeElementsSupport; } |
| 316 | |
cdalton | 06604b9 | 2016-02-05 10:09:51 -0800 | [diff] [blame] | 317 | /// Are the baseInstance fields supported in indirect draw commands? |
| 318 | bool baseInstanceSupport() const { return fBaseInstanceSupport; } |
| 319 | |
bsalomon@google.com | 07631cf | 2013-03-05 14:14:58 +0000 | [diff] [blame] | 320 | /// Use indices or vertices in CPU arrays rather than VBOs for dynamic content. |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 321 | bool useNonVBOVertexAndIndexDynamicData() const { return fUseNonVBOVertexAndIndexDynamicData; } |
bsalomon@google.com | 96966a5 | 2013-02-21 16:34:21 +0000 | [diff] [blame] | 322 | |
Brian Salomon | 71d9d84 | 2016-11-03 13:42:00 -0400 | [diff] [blame] | 323 | /// Does ReadPixels support reading readConfig pixels from a FBO that is surfaceConfig? |
| 324 | bool readPixelsSupported(GrPixelConfig surfaceConfig, |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 325 | GrPixelConfig readConfig, |
bsalomon | 1aa2029 | 2016-01-22 08:16:09 -0800 | [diff] [blame] | 326 | std::function<void (GrGLenum, GrGLint*)> getIntegerv, |
bsalomon | 2c3db32 | 2016-11-08 13:26:24 -0800 | [diff] [blame] | 327 | std::function<bool ()> bindRenderTarget, |
| 328 | std::function<void ()> unbindRenderTarget) const; |
skia.committer@gmail.com | 631cdcb | 2013-03-01 12:12:55 +0000 | [diff] [blame] | 329 | |
bsalomon@google.com | 2b1b8c0 | 2013-02-28 22:06:02 +0000 | [diff] [blame] | 330 | bool isCoreProfile() const { return fIsCoreProfile; } |
robertphillips@google.com | 1d89c93 | 2012-06-27 19:31:41 +0000 | [diff] [blame] | 331 | |
joshualitt | c1f56b5 | 2015-06-22 12:31:31 -0700 | [diff] [blame] | 332 | bool bindFragDataLocationSupport() const { return fBindFragDataLocationSupport; } |
| 333 | |
joshualitt | 7bdd70a | 2015-10-01 06:28:11 -0700 | [diff] [blame] | 334 | bool bindUniformLocationSupport() const { return fBindUniformLocationSupport; } |
| 335 | |
bsalomon | e5286e0 | 2016-01-14 09:24:09 -0800 | [diff] [blame] | 336 | /// Are textures with GL_TEXTURE_RECTANGLE type supported. |
| 337 | bool rectangleTextureSupport() const { return fRectangleTextureSupport; } |
| 338 | |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 339 | /// GL_ARB_texture_swizzle |
| 340 | bool textureSwizzleSupport() const { return fTextureSwizzleSupport; } |
| 341 | |
cblume | 09bd2c0 | 2016-03-01 14:08:28 -0800 | [diff] [blame] | 342 | bool mipMapLevelAndLodControlSupport() const { return fMipMapLevelAndLodControlSupport; } |
| 343 | |
brianosman | 09563ce | 2016-06-02 08:59:34 -0700 | [diff] [blame] | 344 | bool doManualMipmapping() const { return fDoManualMipmapping; } |
| 345 | |
brianosman | 2047189 | 2016-12-02 06:43:32 -0800 | [diff] [blame] | 346 | bool srgbDecodeDisableSupport() const { return fSRGBDecodeDisableSupport; } |
brianosman | 851c238 | 2016-12-07 10:03:25 -0800 | [diff] [blame] | 347 | bool srgbDecodeDisableAffectsMipmaps() const { return fSRGBDecodeDisableAffectsMipmaps; } |
brianosman | 2047189 | 2016-12-02 06:43:32 -0800 | [diff] [blame] | 348 | |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 349 | /** |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 350 | * Returns a string containing the caps info. |
| 351 | */ |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 352 | SkString dump() const override; |
commit-bot@chromium.org | beb8b3a | 2014-04-15 15:37:51 +0000 | [diff] [blame] | 353 | |
bsalomon | 88c7b98 | 2015-07-31 11:20:16 -0700 | [diff] [blame] | 354 | bool rgba8888PixelsOpsAreSlow() const { return fRGBA8888PixelsOpsAreSlow; } |
| 355 | bool partialFBOReadIsSlow() const { return fPartialFBOReadIsSlow; } |
ericrk | b4ecabd | 2016-03-11 15:18:20 -0800 | [diff] [blame] | 356 | bool rgbaToBgraReadbackConversionsAreSlow() const { |
| 357 | return fRGBAToBGRAReadbackConversionsAreSlow; |
| 358 | } |
bsalomon | 88c7b98 | 2015-07-31 11:20:16 -0700 | [diff] [blame] | 359 | |
Eric Karl | aeaf22b | 2017-05-18 15:08:09 -0700 | [diff] [blame] | 360 | // 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 Dalton | 9926f4b | 2017-05-17 15:15:50 -0600 | [diff] [blame] | 362 | |
Brian Salomon | d17b4a6 | 2017-05-23 16:53:47 -0400 | [diff] [blame^] | 363 | /// glClearTex(Sub)Image support |
| 364 | bool clearTextureSupport() const { return fClearTextureSupport; } |
| 365 | |
Chris Dalton | 9926f4b | 2017-05-17 15:15:50 -0600 | [diff] [blame] | 366 | // 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 Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 371 | bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc, |
| 372 | bool* rectsMustMatch, bool* disallowSubrect) const override; |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 373 | |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 374 | private: |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 375 | 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 | |
cdalton | 4cd6713 | 2015-06-10 19:23:46 -0700 | [diff] [blame] | 386 | void init(const GrContextOptions&, const GrGLContextInfo&, const GrGLInterface*); |
egdaniel | 05ded89 | 2015-10-26 07:38:05 -0700 | [diff] [blame] | 387 | void initGLSL(const GrGLContextInfo&); |
kkinnunen | cfe62e3 | 2015-07-01 02:58:50 -0700 | [diff] [blame] | 388 | bool hasPathRenderingSupport(const GrGLContextInfo&, const GrGLInterface*); |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 389 | |
egdaniel | b7e7d57 | 2015-11-04 04:23:53 -0800 | [diff] [blame] | 390 | void onApplyOptionsOverrides(const GrContextOptions& options) override; |
| 391 | |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 392 | void initFSAASupport(const GrContextOptions& contextOptions, const GrGLContextInfo&, |
| 393 | const GrGLInterface*); |
cdalton | 1dd0542 | 2015-06-12 09:01:18 -0700 | [diff] [blame] | 394 | void initBlendEqationSupport(const GrGLContextInfo&); |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 395 | void initStencilSupport(const GrGLContextInfo&); |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 396 | // This must be called after initFSAASupport(). |
brianosman | 2047189 | 2016-12-02 06:43:32 -0800 | [diff] [blame] | 397 | void initConfigTable(const GrContextOptions&, const GrGLContextInfo&, const GrGLInterface*, |
| 398 | GrShaderCaps*); |
commit-bot@chromium.org | 42dc813 | 2014-05-27 19:26:59 +0000 | [diff] [blame] | 399 | |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 400 | void initShaderPrecisionTable(const GrGLContextInfo&, const GrGLInterface*, GrShaderCaps*); |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 401 | |
bsalomon | 1aa2029 | 2016-01-22 08:16:09 -0800 | [diff] [blame] | 402 | GrGLStandard fStandard; |
| 403 | |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 404 | SkTArray<StencilFormat, true> fStencilFormats; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 405 | |
| 406 | int fMaxFragmentUniformVectors; |
bsalomon@google.com | 60da417 | 2012-06-01 19:25:00 +0000 | [diff] [blame] | 407 | |
commit-bot@chromium.org | 52ffbf6 | 2014-04-02 16:19:33 +0000 | [diff] [blame] | 408 | MSFBOType fMSFBOType; |
commit-bot@chromium.org | 52ffbf6 | 2014-04-02 16:19:33 +0000 | [diff] [blame] | 409 | InvalidateFBType fInvalidateFBType; |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 410 | MapBufferType fMapBufferType; |
jvanverth | d7a2c1f | 2015-12-07 07:36:44 -0800 | [diff] [blame] | 411 | TransferBufferType fTransferBufferType; |
bsalomon@google.com | 6b0cf02 | 2013-05-03 13:35:14 +0000 | [diff] [blame] | 412 | |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 413 | bool fUnpackRowLengthSupport : 1; |
| 414 | bool fUnpackFlipYSupport : 1; |
| 415 | bool fPackRowLengthSupport : 1; |
| 416 | bool fPackFlipYSupport : 1; |
| 417 | bool fTextureUsageSupport : 1; |
robertphillips@google.com | 443e5a5 | 2012-04-30 20:01:21 +0000 | [diff] [blame] | 418 | bool fTextureRedSupport : 1; |
bsalomon@google.com | e76b7cc | 2012-06-18 12:47:06 +0000 | [diff] [blame] | 419 | bool fImagingSupport : 1; |
bsalomon@google.com | 07631cf | 2013-03-05 14:14:58 +0000 | [diff] [blame] | 420 | bool fVertexArrayObjectSupport : 1; |
cdalton | 626e1ff | 2015-06-12 13:56:46 -0700 | [diff] [blame] | 421 | bool fDirectStateAccessSupport : 1; |
| 422 | bool fDebugSupport : 1; |
jvanverth | 3f801cb | 2014-12-16 09:49:38 -0800 | [diff] [blame] | 423 | bool fES2CompatibilitySupport : 1; |
csmartdalton | 4c18b62 | 2016-07-29 12:19:28 -0700 | [diff] [blame] | 424 | bool fDrawInstancedSupport : 1; |
cdalton | 06604b9 | 2016-02-05 10:09:51 -0800 | [diff] [blame] | 425 | bool fDrawIndirectSupport : 1; |
bsalomon | fc9527a | 2016-08-29 09:18:39 -0700 | [diff] [blame] | 426 | bool fDrawRangeElementsSupport : 1; |
cdalton | 06604b9 | 2016-02-05 10:09:51 -0800 | [diff] [blame] | 427 | bool fMultiDrawIndirectSupport : 1; |
| 428 | bool fBaseInstanceSupport : 1; |
bsalomon@google.com | 96966a5 | 2013-02-21 16:34:21 +0000 | [diff] [blame] | 429 | bool fUseNonVBOVertexAndIndexDynamicData : 1; |
bsalomon@google.com | 2b1b8c0 | 2013-02-28 22:06:02 +0000 | [diff] [blame] | 430 | bool fIsCoreProfile : 1; |
joshualitt | c1f56b5 | 2015-06-22 12:31:31 -0700 | [diff] [blame] | 431 | bool fBindFragDataLocationSupport : 1; |
bsalomon | 88c7b98 | 2015-07-31 11:20:16 -0700 | [diff] [blame] | 432 | bool fRGBA8888PixelsOpsAreSlow : 1; |
| 433 | bool fPartialFBOReadIsSlow : 1; |
joshualitt | 7bdd70a | 2015-10-01 06:28:11 -0700 | [diff] [blame] | 434 | bool fBindUniformLocationSupport : 1; |
bsalomon | e5286e0 | 2016-01-14 09:24:09 -0800 | [diff] [blame] | 435 | bool fRectangleTextureSupport : 1; |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 436 | bool fTextureSwizzleSupport : 1; |
cblume | 09bd2c0 | 2016-03-01 14:08:28 -0800 | [diff] [blame] | 437 | bool fMipMapLevelAndLodControlSupport : 1; |
ericrk | b4ecabd | 2016-03-11 15:18:20 -0800 | [diff] [blame] | 438 | bool fRGBAToBGRAReadbackConversionsAreSlow : 1; |
brianosman | 09563ce | 2016-06-02 08:59:34 -0700 | [diff] [blame] | 439 | bool fDoManualMipmapping : 1; |
brianosman | 2047189 | 2016-12-02 06:43:32 -0800 | [diff] [blame] | 440 | bool fSRGBDecodeDisableSupport : 1; |
brianosman | 851c238 | 2016-12-07 10:03:25 -0800 | [diff] [blame] | 441 | bool fSRGBDecodeDisableAffectsMipmaps : 1; |
Eric Karl | aeaf22b | 2017-05-18 15:08:09 -0700 | [diff] [blame] | 442 | bool fClearToBoundaryValuesIsBroken : 1; |
Brian Salomon | d17b4a6 | 2017-05-23 16:53:47 -0400 | [diff] [blame^] | 443 | bool fClearTextureSupport : 1; |
Chris Dalton | 9926f4b | 2017-05-17 15:15:50 -0600 | [diff] [blame] | 444 | bool fDrawArraysBaseVertexIsBroken : 1; |
joshualitt | 5816233 | 2014-08-01 06:44:53 -0700 | [diff] [blame] | 445 | |
Brian Salomon | e5e7eb1 | 2016-10-14 16:18:33 -0400 | [diff] [blame] | 446 | uint32_t fBlitFramebufferFlags; |
bsalomon | 083617b | 2016-02-12 12:10:14 -0800 | [diff] [blame] | 447 | |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 448 | /** Number type of the components (with out considering number of bits.) */ |
| 449 | enum FormatType { |
| 450 | kNormalizedFixedPoint_FormatType, |
| 451 | kFloat_FormatType, |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 452 | kInteger_FormatType, |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 453 | }; |
| 454 | |
| 455 | struct ReadPixelsFormat { |
| 456 | ReadPixelsFormat() : fFormat(0), fType(0) {} |
| 457 | GrGLenum fFormat; |
| 458 | GrGLenum fType; |
| 459 | }; |
| 460 | |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 461 | 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 |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 472 | getExternalFormat(). |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 473 | 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 | |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 478 | // Either the base or sized internal format depending on the GL and config. |
| 479 | GrGLenum fInternalFormatTexImage; |
| 480 | GrGLenum fInternalFormatRenderbuffer; |
| 481 | }; |
| 482 | |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 483 | struct ConfigInfo { |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 484 | ConfigInfo() : fStencilFormatIndex(kUnknown_StencilIndex), fFlags(0) {} |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 485 | |
| 486 | ConfigFormats fFormats; |
| 487 | |
bsalomon | 7928ef6 | 2016-01-05 10:26:39 -0800 | [diff] [blame] | 488 | 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 | |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 495 | 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 | }; |
bsalomon | 480e8c0 | 2015-12-21 13:44:18 -0800 | [diff] [blame] | 501 | |
| 502 | // Index fStencilFormats. |
| 503 | int fStencilFormatIndex; |
| 504 | |
| 505 | enum { |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 506 | kVerifiedColorAttachment_Flag = 0x1, |
| 507 | kTextureable_Flag = 0x2, |
| 508 | kRenderable_Flag = 0x4, |
| 509 | kRenderableWithMSAA_Flag = 0x8, |
Brian Salomon | 71d9d84 | 2016-11-03 13:42:00 -0400 | [diff] [blame] | 510 | /** 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 Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 515 | kCanUseAsImageStorage_Flag = 0x80, |
bsalomon | 480e8c0 | 2015-12-21 13:44:18 -0800 | [diff] [blame] | 516 | }; |
| 517 | uint32_t fFlags; |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 518 | |
| 519 | GrSwizzle fSwizzle; |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 520 | }; |
| 521 | |
| 522 | ConfigInfo fConfigTable[kGrPixelConfigCnt]; |
| 523 | |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 524 | typedef GrCaps INHERITED; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 525 | }; |
| 526 | |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 527 | #endif |