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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/gpu/gl/GrGLCaps.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,339 @@
     1.4 +/*
     1.5 + * Copyright 2012 Google Inc.
     1.6 + *
     1.7 + * Use of this source code is governed by a BSD-style license that can be
     1.8 + * found in the LICENSE file.
     1.9 + */
    1.10 +
    1.11 +
    1.12 +#ifndef GrGLCaps_DEFINED
    1.13 +#define GrGLCaps_DEFINED
    1.14 +
    1.15 +#include "GrDrawTargetCaps.h"
    1.16 +#include "GrGLStencilBuffer.h"
    1.17 +#include "SkTArray.h"
    1.18 +#include "SkTDArray.h"
    1.19 +
    1.20 +class GrGLContextInfo;
    1.21 +
    1.22 +/**
    1.23 + * Stores some capabilities of a GL context. Most are determined by the GL
    1.24 + * version and the extensions string. It also tracks formats that have passed
    1.25 + * the FBO completeness test.
    1.26 + */
    1.27 +class GrGLCaps : public GrDrawTargetCaps {
    1.28 +public:
    1.29 +    SK_DECLARE_INST_COUNT(GrGLCaps)
    1.30 +
    1.31 +    typedef GrGLStencilBuffer::Format StencilFormat;
    1.32 +
    1.33 +    /**
    1.34 +     * The type of MSAA for FBOs supported. Different extensions have different
    1.35 +     * semantics of how / when a resolve is performed.
    1.36 +     */
    1.37 +    enum MSFBOType {
    1.38 +        /**
    1.39 +         * no support for MSAA FBOs
    1.40 +         */
    1.41 +        kNone_MSFBOType = 0,
    1.42 +        /**
    1.43 +         * GL3.0-style MSAA FBO (GL_ARB_framebuffer_object).
    1.44 +         */
    1.45 +        kDesktop_ARB_MSFBOType,
    1.46 +        /**
    1.47 +         * earlier GL_EXT_framebuffer* extensions
    1.48 +         */
    1.49 +        kDesktop_EXT_MSFBOType,
    1.50 +        /**
    1.51 +         * Similar to kDesktop_ARB but with additional restrictions on glBlitFramebuffer.
    1.52 +         */
    1.53 +        kES_3_0_MSFBOType,
    1.54 +        /**
    1.55 +         * GL_APPLE_framebuffer_multisample ES extension
    1.56 +         */
    1.57 +        kES_Apple_MSFBOType,
    1.58 +        /**
    1.59 +         * GL_IMG_multisampled_render_to_texture. This variation does not have MSAA renderbuffers.
    1.60 +         * Instead the texture is multisampled when bound to the FBO and then resolved automatically
    1.61 +         * when read. It also defines an alternate value for GL_MAX_SAMPLES (which we call
    1.62 +         * GR_GL_MAX_SAMPLES_IMG).
    1.63 +         */
    1.64 +        kES_IMG_MsToTexture_MSFBOType,
    1.65 +        /**
    1.66 +         * GL_EXT_multisampled_render_to_texture. Same as the IMG one above but uses the standard
    1.67 +         * GL_MAX_SAMPLES value.
    1.68 +         */
    1.69 +        kES_EXT_MsToTexture_MSFBOType,
    1.70 +
    1.71 +        kLast_MSFBOType = kES_EXT_MsToTexture_MSFBOType
    1.72 +    };
    1.73 +
    1.74 +    enum FBFetchType {
    1.75 +        kNone_FBFetchType,
    1.76 +        /** GL_EXT_shader_framebuffer_fetch */
    1.77 +        kEXT_FBFetchType,
    1.78 +        /** GL_NV_shader_framebuffer_fetch */
    1.79 +        kNV_FBFetchType,
    1.80 +
    1.81 +        kLast_FBFetchType = kNV_FBFetchType,
    1.82 +    };
    1.83 +
    1.84 +    /**
    1.85 +     * Creates a GrGLCaps that advertises no support for any extensions,
    1.86 +     * formats, etc. Call init to initialize from a GrGLContextInfo.
    1.87 +     */
    1.88 +    GrGLCaps();
    1.89 +
    1.90 +    GrGLCaps(const GrGLCaps& caps);
    1.91 +
    1.92 +    GrGLCaps& operator = (const GrGLCaps& caps);
    1.93 +
    1.94 +    /**
    1.95 +     * Resets the caps such that nothing is supported.
    1.96 +     */
    1.97 +    virtual void reset() SK_OVERRIDE;
    1.98 +
    1.99 +    /**
   1.100 +     * Initializes the GrGLCaps to the set of features supported in the current
   1.101 +     * OpenGL context accessible via ctxInfo.
   1.102 +     */
   1.103 +    void init(const GrGLContextInfo& ctxInfo, const GrGLInterface* interface);
   1.104 +
   1.105 +    /**
   1.106 +     * Call to note that a color config has been verified as a valid color
   1.107 +     * attachment. This may save future calls to glCheckFramebufferStatus
   1.108 +     * using isConfigVerifiedColorAttachment().
   1.109 +     */
   1.110 +    void markConfigAsValidColorAttachment(GrPixelConfig config) {
   1.111 +        fVerifiedColorConfigs.markVerified(config);
   1.112 +    }
   1.113 +
   1.114 +    /**
   1.115 +     * Call to check whether a config has been verified as a valid color
   1.116 +     * attachment.
   1.117 +     */
   1.118 +    bool isConfigVerifiedColorAttachment(GrPixelConfig config) const {
   1.119 +        return fVerifiedColorConfigs.isVerified(config);
   1.120 +    }
   1.121 +
   1.122 +    /**
   1.123 +     * Call to note that a color config / stencil format pair passed
   1.124 +     * FBO status check. We may skip calling glCheckFramebufferStatus for
   1.125 +     * this combination in the future using
   1.126 +     * isColorConfigAndStencilFormatVerified().
   1.127 +     */
   1.128 +    void markColorConfigAndStencilFormatAsVerified(
   1.129 +                    GrPixelConfig config,
   1.130 +                    const GrGLStencilBuffer::Format& format);
   1.131 +
   1.132 +    /**
   1.133 +     * Call to check whether color config / stencil format pair has already
   1.134 +     * passed FBO status check.
   1.135 +     */
   1.136 +    bool isColorConfigAndStencilFormatVerified(
   1.137 +                    GrPixelConfig config,
   1.138 +                    const GrGLStencilBuffer::Format& format) const;
   1.139 +
   1.140 +    /**
   1.141 +     * Reports the type of MSAA FBO support.
   1.142 +     */
   1.143 +    MSFBOType msFBOType() const { return fMSFBOType; }
   1.144 +
   1.145 +    /**
   1.146 +     * Does the supported MSAA FBO extension have MSAA renderbuffers?
   1.147 +     */
   1.148 +    bool usesMSAARenderBuffers() const {
   1.149 +        return kNone_MSFBOType != fMSFBOType &&
   1.150 +               kES_IMG_MsToTexture_MSFBOType != fMSFBOType &&
   1.151 +               kES_EXT_MsToTexture_MSFBOType != fMSFBOType;
   1.152 +    }
   1.153 +
   1.154 +    /**
   1.155 +     * Is the MSAA FBO extension one where the texture is multisampled when bound to an FBO and
   1.156 +     * then implicitly resolved when read.
   1.157 +     */
   1.158 +    bool usesImplicitMSAAResolve() const {
   1.159 +        return kES_IMG_MsToTexture_MSFBOType == fMSFBOType ||
   1.160 +               kES_EXT_MsToTexture_MSFBOType == fMSFBOType;
   1.161 +    }
   1.162 +
   1.163 +    FBFetchType fbFetchType() const { return fFBFetchType; }
   1.164 +
   1.165 +    /**
   1.166 +     * Returs a string containeng the caps info.
   1.167 +     */
   1.168 +    virtual SkString dump() const SK_OVERRIDE;
   1.169 +
   1.170 +    /**
   1.171 +     * Gets an array of legal stencil formats. These formats are not guaranteed
   1.172 +     * to be supported by the driver but are legal GLenum names given the GL
   1.173 +     * version and extensions supported.
   1.174 +     */
   1.175 +    const SkTArray<StencilFormat, true>& stencilFormats() const {
   1.176 +        return fStencilFormats;
   1.177 +    }
   1.178 +
   1.179 +    /// The maximum number of fragment uniform vectors (GLES has min. 16).
   1.180 +    int maxFragmentUniformVectors() const { return fMaxFragmentUniformVectors; }
   1.181 +
   1.182 +    /// maximum number of attribute values per vertex
   1.183 +    int maxVertexAttributes() const { return fMaxVertexAttributes; }
   1.184 +
   1.185 +    /// maximum number of texture units accessible in the fragment shader.
   1.186 +    int maxFragmentTextureUnits() const { return fMaxFragmentTextureUnits; }
   1.187 +
   1.188 +    /// maximum number of fixed-function texture coords, or zero if no fixed-function.
   1.189 +    int maxFixedFunctionTextureCoords() const { return fMaxFixedFunctionTextureCoords; }
   1.190 +
   1.191 +    /// ES requires an extension to support RGBA8 in RenderBufferStorage
   1.192 +    bool rgba8RenderbufferSupport() const { return fRGBA8RenderbufferSupport; }
   1.193 +
   1.194 +    /// Is GL_BGRA supported
   1.195 +    bool bgraFormatSupport() const { return fBGRAFormatSupport; }
   1.196 +
   1.197 +    /**
   1.198 +     * Depending on the ES extensions present the BGRA external format may
   1.199 +     * correspond either a BGRA or RGBA internalFormat. On desktop GL it is
   1.200 +     * RGBA.
   1.201 +     */
   1.202 +    bool bgraIsInternalFormat() const { return fBGRAIsInternalFormat; }
   1.203 +
   1.204 +    /// GL_ARB_texture_swizzle support
   1.205 +    bool textureSwizzleSupport() const { return fTextureSwizzleSupport; }
   1.206 +
   1.207 +    /// Is there support for GL_UNPACK_ROW_LENGTH
   1.208 +    bool unpackRowLengthSupport() const { return fUnpackRowLengthSupport; }
   1.209 +
   1.210 +    /// Is there support for GL_UNPACK_FLIP_Y
   1.211 +    bool unpackFlipYSupport() const { return fUnpackFlipYSupport; }
   1.212 +
   1.213 +    /// Is there support for GL_PACK_ROW_LENGTH
   1.214 +    bool packRowLengthSupport() const { return fPackRowLengthSupport; }
   1.215 +
   1.216 +    /// Is there support for GL_PACK_REVERSE_ROW_ORDER
   1.217 +    bool packFlipYSupport() const { return fPackFlipYSupport; }
   1.218 +
   1.219 +    /// Is there support for texture parameter GL_TEXTURE_USAGE
   1.220 +    bool textureUsageSupport() const { return fTextureUsageSupport; }
   1.221 +
   1.222 +    /// Is there support for glTexStorage
   1.223 +    bool texStorageSupport() const { return fTexStorageSupport; }
   1.224 +
   1.225 +    /// Is there support for GL_RED and GL_R8
   1.226 +    bool textureRedSupport() const { return fTextureRedSupport; }
   1.227 +
   1.228 +    /// Is GL_ARB_IMAGING supported
   1.229 +    bool imagingSupport() const { return fImagingSupport; }
   1.230 +
   1.231 +    /// Is GL_ARB_fragment_coord_conventions supported?
   1.232 +    bool fragCoordConventionsSupport() const { return fFragCoordsConventionSupport; }
   1.233 +
   1.234 +    /// Is there support for Vertex Array Objects?
   1.235 +    bool vertexArrayObjectSupport() const { return fVertexArrayObjectSupport; }
   1.236 +
   1.237 +    /// Use indices or vertices in CPU arrays rather than VBOs for dynamic content.
   1.238 +    bool useNonVBOVertexAndIndexDynamicData() const {
   1.239 +        return fUseNonVBOVertexAndIndexDynamicData;
   1.240 +    }
   1.241 +
   1.242 +    /// Does ReadPixels support the provided format/type combo?
   1.243 +    bool readPixelsSupported(const GrGLInterface* intf,
   1.244 +                             GrGLenum format,
   1.245 +                             GrGLenum type) const;
   1.246 +
   1.247 +    bool isCoreProfile() const { return fIsCoreProfile; }
   1.248 +
   1.249 +    bool fixedFunctionSupport() const { return fFixedFunctionSupport; }
   1.250 +
   1.251 +    /// Is there support for discarding the frame buffer
   1.252 +    bool discardFBSupport() const { return fDiscardFBSupport; }
   1.253 +
   1.254 +    bool fullClearIsFree() const { return fFullClearIsFree; }
   1.255 +
   1.256 +private:
   1.257 +    /**
   1.258 +     * Maintains a bit per GrPixelConfig. It is used to avoid redundantly
   1.259 +     * performing glCheckFrameBufferStatus for the same config.
   1.260 +     */
   1.261 +    struct VerifiedColorConfigs {
   1.262 +        VerifiedColorConfigs() {
   1.263 +            this->reset();
   1.264 +        }
   1.265 +
   1.266 +        void reset() {
   1.267 +            for (int i = 0; i < kNumUints; ++i) {
   1.268 +                fVerifiedColorConfigs[i] = 0;
   1.269 +            }
   1.270 +        }
   1.271 +
   1.272 +        static const int kNumUints = (kGrPixelConfigCnt  + 31) / 32;
   1.273 +        uint32_t fVerifiedColorConfigs[kNumUints];
   1.274 +
   1.275 +        void markVerified(GrPixelConfig config) {
   1.276 +#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
   1.277 +                return;
   1.278 +#endif
   1.279 +            int u32Idx = config / 32;
   1.280 +            int bitIdx = config % 32;
   1.281 +            fVerifiedColorConfigs[u32Idx] |= 1 << bitIdx;
   1.282 +        }
   1.283 +
   1.284 +        bool isVerified(GrPixelConfig config) const {
   1.285 +#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
   1.286 +            return false;
   1.287 +#endif
   1.288 +            int u32Idx = config / 32;
   1.289 +            int bitIdx = config % 32;
   1.290 +            return SkToBool(fVerifiedColorConfigs[u32Idx] & (1 << bitIdx));
   1.291 +        }
   1.292 +    };
   1.293 +
   1.294 +    void initFSAASupport(const GrGLContextInfo&, const GrGLInterface*);
   1.295 +    void initStencilFormats(const GrGLContextInfo&);
   1.296 +    // This must be called after initFSAASupport().
   1.297 +    void initConfigRenderableTable(const GrGLContextInfo&);
   1.298 +
   1.299 +    // tracks configs that have been verified to pass the FBO completeness when
   1.300 +    // used as a color attachment
   1.301 +    VerifiedColorConfigs fVerifiedColorConfigs;
   1.302 +
   1.303 +    SkTArray<StencilFormat, true> fStencilFormats;
   1.304 +    // tracks configs that have been verified to pass the FBO completeness when
   1.305 +    // used as a color attachment when a particular stencil format is used
   1.306 +    // as a stencil attachment.
   1.307 +    SkTArray<VerifiedColorConfigs, true> fStencilVerifiedColorConfigs;
   1.308 +
   1.309 +    int fMaxFragmentUniformVectors;
   1.310 +    int fMaxVertexAttributes;
   1.311 +    int fMaxFragmentTextureUnits;
   1.312 +    int fMaxFixedFunctionTextureCoords;
   1.313 +
   1.314 +    MSFBOType fMSFBOType;
   1.315 +
   1.316 +    FBFetchType fFBFetchType;
   1.317 +
   1.318 +    bool fRGBA8RenderbufferSupport : 1;
   1.319 +    bool fBGRAFormatSupport : 1;
   1.320 +    bool fBGRAIsInternalFormat : 1;
   1.321 +    bool fTextureSwizzleSupport : 1;
   1.322 +    bool fUnpackRowLengthSupport : 1;
   1.323 +    bool fUnpackFlipYSupport : 1;
   1.324 +    bool fPackRowLengthSupport : 1;
   1.325 +    bool fPackFlipYSupport : 1;
   1.326 +    bool fTextureUsageSupport : 1;
   1.327 +    bool fTexStorageSupport : 1;
   1.328 +    bool fTextureRedSupport : 1;
   1.329 +    bool fImagingSupport  : 1;
   1.330 +    bool fTwoFormatLimit : 1;
   1.331 +    bool fFragCoordsConventionSupport : 1;
   1.332 +    bool fVertexArrayObjectSupport : 1;
   1.333 +    bool fUseNonVBOVertexAndIndexDynamicData : 1;
   1.334 +    bool fIsCoreProfile : 1;
   1.335 +    bool fFixedFunctionSupport : 1;
   1.336 +    bool fDiscardFBSupport : 1;
   1.337 +    bool fFullClearIsFree : 1;
   1.338 +
   1.339 +    typedef GrDrawTargetCaps INHERITED;
   1.340 +};
   1.341 +
   1.342 +#endif

mercurial