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.

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

mercurial