gfx/skia/trunk/src/gpu/gl/GrGLCaps.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 * Copyright 2012 Google Inc.
michael@0 3 *
michael@0 4 * Use of this source code is governed by a BSD-style license that can be
michael@0 5 * found in the LICENSE file.
michael@0 6 */
michael@0 7
michael@0 8
michael@0 9 #ifndef GrGLCaps_DEFINED
michael@0 10 #define GrGLCaps_DEFINED
michael@0 11
michael@0 12 #include "GrDrawTargetCaps.h"
michael@0 13 #include "GrGLStencilBuffer.h"
michael@0 14 #include "SkTArray.h"
michael@0 15 #include "SkTDArray.h"
michael@0 16
michael@0 17 class GrGLContextInfo;
michael@0 18
michael@0 19 /**
michael@0 20 * Stores some capabilities of a GL context. Most are determined by the GL
michael@0 21 * version and the extensions string. It also tracks formats that have passed
michael@0 22 * the FBO completeness test.
michael@0 23 */
michael@0 24 class GrGLCaps : public GrDrawTargetCaps {
michael@0 25 public:
michael@0 26 SK_DECLARE_INST_COUNT(GrGLCaps)
michael@0 27
michael@0 28 typedef GrGLStencilBuffer::Format StencilFormat;
michael@0 29
michael@0 30 /**
michael@0 31 * The type of MSAA for FBOs supported. Different extensions have different
michael@0 32 * semantics of how / when a resolve is performed.
michael@0 33 */
michael@0 34 enum MSFBOType {
michael@0 35 /**
michael@0 36 * no support for MSAA FBOs
michael@0 37 */
michael@0 38 kNone_MSFBOType = 0,
michael@0 39 /**
michael@0 40 * GL3.0-style MSAA FBO (GL_ARB_framebuffer_object).
michael@0 41 */
michael@0 42 kDesktop_ARB_MSFBOType,
michael@0 43 /**
michael@0 44 * earlier GL_EXT_framebuffer* extensions
michael@0 45 */
michael@0 46 kDesktop_EXT_MSFBOType,
michael@0 47 /**
michael@0 48 * Similar to kDesktop_ARB but with additional restrictions on glBlitFramebuffer.
michael@0 49 */
michael@0 50 kES_3_0_MSFBOType,
michael@0 51 /**
michael@0 52 * GL_APPLE_framebuffer_multisample ES extension
michael@0 53 */
michael@0 54 kES_Apple_MSFBOType,
michael@0 55 /**
michael@0 56 * GL_IMG_multisampled_render_to_texture. This variation does not have MSAA renderbuffers.
michael@0 57 * Instead the texture is multisampled when bound to the FBO and then resolved automatically
michael@0 58 * when read. It also defines an alternate value for GL_MAX_SAMPLES (which we call
michael@0 59 * GR_GL_MAX_SAMPLES_IMG).
michael@0 60 */
michael@0 61 kES_IMG_MsToTexture_MSFBOType,
michael@0 62 /**
michael@0 63 * GL_EXT_multisampled_render_to_texture. Same as the IMG one above but uses the standard
michael@0 64 * GL_MAX_SAMPLES value.
michael@0 65 */
michael@0 66 kES_EXT_MsToTexture_MSFBOType,
michael@0 67
michael@0 68 kLast_MSFBOType = kES_EXT_MsToTexture_MSFBOType
michael@0 69 };
michael@0 70
michael@0 71 enum FBFetchType {
michael@0 72 kNone_FBFetchType,
michael@0 73 /** GL_EXT_shader_framebuffer_fetch */
michael@0 74 kEXT_FBFetchType,
michael@0 75 /** GL_NV_shader_framebuffer_fetch */
michael@0 76 kNV_FBFetchType,
michael@0 77
michael@0 78 kLast_FBFetchType = kNV_FBFetchType,
michael@0 79 };
michael@0 80
michael@0 81 /**
michael@0 82 * Creates a GrGLCaps that advertises no support for any extensions,
michael@0 83 * formats, etc. Call init to initialize from a GrGLContextInfo.
michael@0 84 */
michael@0 85 GrGLCaps();
michael@0 86
michael@0 87 GrGLCaps(const GrGLCaps& caps);
michael@0 88
michael@0 89 GrGLCaps& operator = (const GrGLCaps& caps);
michael@0 90
michael@0 91 /**
michael@0 92 * Resets the caps such that nothing is supported.
michael@0 93 */
michael@0 94 virtual void reset() SK_OVERRIDE;
michael@0 95
michael@0 96 /**
michael@0 97 * Initializes the GrGLCaps to the set of features supported in the current
michael@0 98 * OpenGL context accessible via ctxInfo.
michael@0 99 */
michael@0 100 void init(const GrGLContextInfo& ctxInfo, const GrGLInterface* interface);
michael@0 101
michael@0 102 /**
michael@0 103 * Call to note that a color config has been verified as a valid color
michael@0 104 * attachment. This may save future calls to glCheckFramebufferStatus
michael@0 105 * using isConfigVerifiedColorAttachment().
michael@0 106 */
michael@0 107 void markConfigAsValidColorAttachment(GrPixelConfig config) {
michael@0 108 fVerifiedColorConfigs.markVerified(config);
michael@0 109 }
michael@0 110
michael@0 111 /**
michael@0 112 * Call to check whether a config has been verified as a valid color
michael@0 113 * attachment.
michael@0 114 */
michael@0 115 bool isConfigVerifiedColorAttachment(GrPixelConfig config) const {
michael@0 116 return fVerifiedColorConfigs.isVerified(config);
michael@0 117 }
michael@0 118
michael@0 119 /**
michael@0 120 * Call to note that a color config / stencil format pair passed
michael@0 121 * FBO status check. We may skip calling glCheckFramebufferStatus for
michael@0 122 * this combination in the future using
michael@0 123 * isColorConfigAndStencilFormatVerified().
michael@0 124 */
michael@0 125 void markColorConfigAndStencilFormatAsVerified(
michael@0 126 GrPixelConfig config,
michael@0 127 const GrGLStencilBuffer::Format& format);
michael@0 128
michael@0 129 /**
michael@0 130 * Call to check whether color config / stencil format pair has already
michael@0 131 * passed FBO status check.
michael@0 132 */
michael@0 133 bool isColorConfigAndStencilFormatVerified(
michael@0 134 GrPixelConfig config,
michael@0 135 const GrGLStencilBuffer::Format& format) const;
michael@0 136
michael@0 137 /**
michael@0 138 * Reports the type of MSAA FBO support.
michael@0 139 */
michael@0 140 MSFBOType msFBOType() const { return fMSFBOType; }
michael@0 141
michael@0 142 /**
michael@0 143 * Does the supported MSAA FBO extension have MSAA renderbuffers?
michael@0 144 */
michael@0 145 bool usesMSAARenderBuffers() const {
michael@0 146 return kNone_MSFBOType != fMSFBOType &&
michael@0 147 kES_IMG_MsToTexture_MSFBOType != fMSFBOType &&
michael@0 148 kES_EXT_MsToTexture_MSFBOType != fMSFBOType;
michael@0 149 }
michael@0 150
michael@0 151 /**
michael@0 152 * Is the MSAA FBO extension one where the texture is multisampled when bound to an FBO and
michael@0 153 * then implicitly resolved when read.
michael@0 154 */
michael@0 155 bool usesImplicitMSAAResolve() const {
michael@0 156 return kES_IMG_MsToTexture_MSFBOType == fMSFBOType ||
michael@0 157 kES_EXT_MsToTexture_MSFBOType == fMSFBOType;
michael@0 158 }
michael@0 159
michael@0 160 FBFetchType fbFetchType() const { return fFBFetchType; }
michael@0 161
michael@0 162 /**
michael@0 163 * Returs a string containeng the caps info.
michael@0 164 */
michael@0 165 virtual SkString dump() const SK_OVERRIDE;
michael@0 166
michael@0 167 /**
michael@0 168 * Gets an array of legal stencil formats. These formats are not guaranteed
michael@0 169 * to be supported by the driver but are legal GLenum names given the GL
michael@0 170 * version and extensions supported.
michael@0 171 */
michael@0 172 const SkTArray<StencilFormat, true>& stencilFormats() const {
michael@0 173 return fStencilFormats;
michael@0 174 }
michael@0 175
michael@0 176 /// The maximum number of fragment uniform vectors (GLES has min. 16).
michael@0 177 int maxFragmentUniformVectors() const { return fMaxFragmentUniformVectors; }
michael@0 178
michael@0 179 /// maximum number of attribute values per vertex
michael@0 180 int maxVertexAttributes() const { return fMaxVertexAttributes; }
michael@0 181
michael@0 182 /// maximum number of texture units accessible in the fragment shader.
michael@0 183 int maxFragmentTextureUnits() const { return fMaxFragmentTextureUnits; }
michael@0 184
michael@0 185 /// maximum number of fixed-function texture coords, or zero if no fixed-function.
michael@0 186 int maxFixedFunctionTextureCoords() const { return fMaxFixedFunctionTextureCoords; }
michael@0 187
michael@0 188 /// ES requires an extension to support RGBA8 in RenderBufferStorage
michael@0 189 bool rgba8RenderbufferSupport() const { return fRGBA8RenderbufferSupport; }
michael@0 190
michael@0 191 /// Is GL_BGRA supported
michael@0 192 bool bgraFormatSupport() const { return fBGRAFormatSupport; }
michael@0 193
michael@0 194 /**
michael@0 195 * Depending on the ES extensions present the BGRA external format may
michael@0 196 * correspond either a BGRA or RGBA internalFormat. On desktop GL it is
michael@0 197 * RGBA.
michael@0 198 */
michael@0 199 bool bgraIsInternalFormat() const { return fBGRAIsInternalFormat; }
michael@0 200
michael@0 201 /// GL_ARB_texture_swizzle support
michael@0 202 bool textureSwizzleSupport() const { return fTextureSwizzleSupport; }
michael@0 203
michael@0 204 /// Is there support for GL_UNPACK_ROW_LENGTH
michael@0 205 bool unpackRowLengthSupport() const { return fUnpackRowLengthSupport; }
michael@0 206
michael@0 207 /// Is there support for GL_UNPACK_FLIP_Y
michael@0 208 bool unpackFlipYSupport() const { return fUnpackFlipYSupport; }
michael@0 209
michael@0 210 /// Is there support for GL_PACK_ROW_LENGTH
michael@0 211 bool packRowLengthSupport() const { return fPackRowLengthSupport; }
michael@0 212
michael@0 213 /// Is there support for GL_PACK_REVERSE_ROW_ORDER
michael@0 214 bool packFlipYSupport() const { return fPackFlipYSupport; }
michael@0 215
michael@0 216 /// Is there support for texture parameter GL_TEXTURE_USAGE
michael@0 217 bool textureUsageSupport() const { return fTextureUsageSupport; }
michael@0 218
michael@0 219 /// Is there support for glTexStorage
michael@0 220 bool texStorageSupport() const { return fTexStorageSupport; }
michael@0 221
michael@0 222 /// Is there support for GL_RED and GL_R8
michael@0 223 bool textureRedSupport() const { return fTextureRedSupport; }
michael@0 224
michael@0 225 /// Is GL_ARB_IMAGING supported
michael@0 226 bool imagingSupport() const { return fImagingSupport; }
michael@0 227
michael@0 228 /// Is GL_ARB_fragment_coord_conventions supported?
michael@0 229 bool fragCoordConventionsSupport() const { return fFragCoordsConventionSupport; }
michael@0 230
michael@0 231 /// Is there support for Vertex Array Objects?
michael@0 232 bool vertexArrayObjectSupport() const { return fVertexArrayObjectSupport; }
michael@0 233
michael@0 234 /// Use indices or vertices in CPU arrays rather than VBOs for dynamic content.
michael@0 235 bool useNonVBOVertexAndIndexDynamicData() const {
michael@0 236 return fUseNonVBOVertexAndIndexDynamicData;
michael@0 237 }
michael@0 238
michael@0 239 /// Does ReadPixels support the provided format/type combo?
michael@0 240 bool readPixelsSupported(const GrGLInterface* intf,
michael@0 241 GrGLenum format,
michael@0 242 GrGLenum type) const;
michael@0 243
michael@0 244 bool isCoreProfile() const { return fIsCoreProfile; }
michael@0 245
michael@0 246 bool fixedFunctionSupport() const { return fFixedFunctionSupport; }
michael@0 247
michael@0 248 /// Is there support for discarding the frame buffer
michael@0 249 bool discardFBSupport() const { return fDiscardFBSupport; }
michael@0 250
michael@0 251 bool fullClearIsFree() const { return fFullClearIsFree; }
michael@0 252
michael@0 253 private:
michael@0 254 /**
michael@0 255 * Maintains a bit per GrPixelConfig. It is used to avoid redundantly
michael@0 256 * performing glCheckFrameBufferStatus for the same config.
michael@0 257 */
michael@0 258 struct VerifiedColorConfigs {
michael@0 259 VerifiedColorConfigs() {
michael@0 260 this->reset();
michael@0 261 }
michael@0 262
michael@0 263 void reset() {
michael@0 264 for (int i = 0; i < kNumUints; ++i) {
michael@0 265 fVerifiedColorConfigs[i] = 0;
michael@0 266 }
michael@0 267 }
michael@0 268
michael@0 269 static const int kNumUints = (kGrPixelConfigCnt + 31) / 32;
michael@0 270 uint32_t fVerifiedColorConfigs[kNumUints];
michael@0 271
michael@0 272 void markVerified(GrPixelConfig config) {
michael@0 273 #if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
michael@0 274 return;
michael@0 275 #endif
michael@0 276 int u32Idx = config / 32;
michael@0 277 int bitIdx = config % 32;
michael@0 278 fVerifiedColorConfigs[u32Idx] |= 1 << bitIdx;
michael@0 279 }
michael@0 280
michael@0 281 bool isVerified(GrPixelConfig config) const {
michael@0 282 #if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
michael@0 283 return false;
michael@0 284 #endif
michael@0 285 int u32Idx = config / 32;
michael@0 286 int bitIdx = config % 32;
michael@0 287 return SkToBool(fVerifiedColorConfigs[u32Idx] & (1 << bitIdx));
michael@0 288 }
michael@0 289 };
michael@0 290
michael@0 291 void initFSAASupport(const GrGLContextInfo&, const GrGLInterface*);
michael@0 292 void initStencilFormats(const GrGLContextInfo&);
michael@0 293 // This must be called after initFSAASupport().
michael@0 294 void initConfigRenderableTable(const GrGLContextInfo&);
michael@0 295
michael@0 296 // tracks configs that have been verified to pass the FBO completeness when
michael@0 297 // used as a color attachment
michael@0 298 VerifiedColorConfigs fVerifiedColorConfigs;
michael@0 299
michael@0 300 SkTArray<StencilFormat, true> fStencilFormats;
michael@0 301 // tracks configs that have been verified to pass the FBO completeness when
michael@0 302 // used as a color attachment when a particular stencil format is used
michael@0 303 // as a stencil attachment.
michael@0 304 SkTArray<VerifiedColorConfigs, true> fStencilVerifiedColorConfigs;
michael@0 305
michael@0 306 int fMaxFragmentUniformVectors;
michael@0 307 int fMaxVertexAttributes;
michael@0 308 int fMaxFragmentTextureUnits;
michael@0 309 int fMaxFixedFunctionTextureCoords;
michael@0 310
michael@0 311 MSFBOType fMSFBOType;
michael@0 312
michael@0 313 FBFetchType fFBFetchType;
michael@0 314
michael@0 315 bool fRGBA8RenderbufferSupport : 1;
michael@0 316 bool fBGRAFormatSupport : 1;
michael@0 317 bool fBGRAIsInternalFormat : 1;
michael@0 318 bool fTextureSwizzleSupport : 1;
michael@0 319 bool fUnpackRowLengthSupport : 1;
michael@0 320 bool fUnpackFlipYSupport : 1;
michael@0 321 bool fPackRowLengthSupport : 1;
michael@0 322 bool fPackFlipYSupport : 1;
michael@0 323 bool fTextureUsageSupport : 1;
michael@0 324 bool fTexStorageSupport : 1;
michael@0 325 bool fTextureRedSupport : 1;
michael@0 326 bool fImagingSupport : 1;
michael@0 327 bool fTwoFormatLimit : 1;
michael@0 328 bool fFragCoordsConventionSupport : 1;
michael@0 329 bool fVertexArrayObjectSupport : 1;
michael@0 330 bool fUseNonVBOVertexAndIndexDynamicData : 1;
michael@0 331 bool fIsCoreProfile : 1;
michael@0 332 bool fFixedFunctionSupport : 1;
michael@0 333 bool fDiscardFBSupport : 1;
michael@0 334 bool fFullClearIsFree : 1;
michael@0 335
michael@0 336 typedef GrDrawTargetCaps INHERITED;
michael@0 337 };
michael@0 338
michael@0 339 #endif

mercurial