Home | History | Annotate | Download | only in gl
      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 
     12 #include <functional>
     13 
     14 #include "GrCaps.h"
     15 #include "GrGLStencilAttachment.h"
     16 #include "GrSwizzle.h"
     17 #include "SkChecksum.h"
     18 #include "SkTHash.h"
     19 #include "SkTArray.h"
     20 #include "../private/GrGLSL.h"
     21 
     22 class GrGLContextInfo;
     23 class GrGLRenderTarget;
     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  */
     30 class GrGLCaps : public GrCaps {
     31 public:
     32     typedef GrGLStencilAttachment::Format StencilFormat;
     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          */
     42         kNone_MSFBOType = 0,
     43         /**
     44          * 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
     47          */
     48         kStandard_MSFBOType,
     49         /**
     50          * GL_APPLE_framebuffer_multisample ES extension
     51          */
     52         kES_Apple_MSFBOType,
     53         /**
     54          * 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).
     58          */
     59         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,
     65         /**
     66          * GL_NV_framebuffer_mixed_samples.
     67          */
     68         kMixedSamples_MSFBOType,
     69 
     70         kLast_MSFBOType = kMixedSamples_MSFBOType
     71     };
     72 
     73     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,
     81     };
     82 
     83     enum InvalidateFBType {
     84         kNone_InvalidateFBType,
     85         kDiscard_InvalidateFBType,       //<! glDiscardFramebuffer()
     86         kInvalidate_InvalidateFBType,    //<! glInvalidateFramebuffer()
     87 
     88         kLast_InvalidateFBType = kInvalidate_InvalidateFBType
     89     };
     90 
     91     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 
    100     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 
    108     /**
    109      * Initializes the GrGLCaps to the set of features supported in the current
    110      * OpenGL context accessible via ctxInfo.
    111      */
    112     GrGLCaps(const GrContextOptions& contextOptions, const GrGLContextInfo& ctxInfo,
    113              const GrGLInterface* glInterface);
    114 
    115     bool isConfigTexturable(GrPixelConfig config) const override {
    116         return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kTextureable_Flag);
    117     }
    118 
    119     int getRenderTargetSampleCount(int requestedCount, GrPixelConfig config) const override;
    120     int maxRenderTargetSampleCount(GrPixelConfig config) const override;
    121 
    122     bool isConfigCopyable(GrPixelConfig config) const override {
    123         // In GL we have three ways to be able to copy. CopyTexImage, blit, and draw. CopyTexImage
    124         // requires the src to be an FBO attachment, blit requires both src and dst to be FBO
    125         // attachments, and draw requires the dst to be an FBO attachment. Thus to copy from and to
    126         // the same config, we need that config to be renderable so we can attach it to an FBO.
    127         return this->isConfigRenderable(config, false);
    128     }
    129 
    130     bool canConfigBeFBOColorAttachment(GrPixelConfig config) const {
    131         return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kFBOColorAttachment_Flag);
    132     }
    133 
    134     bool isConfigTexSupportEnabled(GrPixelConfig config) const {
    135         return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kCanUseTexStorage_Flag);
    136     }
    137 
    138     bool canUseConfigWithTexelBuffer(GrPixelConfig config) const {
    139         return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kCanUseWithTexelBuffer_Flag);
    140     }
    141 
    142     /** Returns the mapping between GrPixelConfig components and GL internal format components. */
    143     const GrSwizzle& configSwizzle(GrPixelConfig config) const {
    144         return fConfigTable[config].fSwizzle;
    145     }
    146 
    147     GrGLenum configSizedInternalFormat(GrPixelConfig config) const {
    148         return fConfigTable[config].fFormats.fSizedInternalFormat;
    149     }
    150 
    151     bool getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
    152                             GrGLenum* internalFormat, GrGLenum* externalFormat,
    153                             GrGLenum* externalType) const;
    154 
    155     bool getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
    156                              GrGLenum* externalFormat, GrGLenum* externalType) const;
    157 
    158     bool getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const;
    159 
    160     /** The format to use read/write a texture as an image in a shader */
    161     GrGLenum getImageFormat(GrPixelConfig config) const {
    162         return fConfigTable[config].fFormats.fSizedInternalFormat;
    163     }
    164 
    165     /**
    166     * Gets an array of legal stencil formats. These formats are not guaranteed
    167     * to be supported by the driver but are legal GLenum names given the GL
    168     * version and extensions supported.
    169     */
    170     const SkTArray<StencilFormat, true>& stencilFormats() const {
    171         return fStencilFormats;
    172     }
    173 
    174     /**
    175      * Has a stencil format index been found for the config (or we've found that no format works).
    176      */
    177     bool hasStencilFormatBeenDeterminedForConfig(GrPixelConfig config) const {
    178         return fConfigTable[config].fStencilFormatIndex != ConfigInfo::kUnknown_StencilIndex;
    179     }
    180 
    181     /**
    182      * Gets the stencil format index for the config. This assumes
    183      * hasStencilFormatBeenDeterminedForConfig has already been checked. Returns a value < 0 if
    184      * no stencil format is supported with the config. Otherwise, returned index refers to the array
    185      * returned by stencilFormats().
    186      */
    187     int getStencilFormatIndexForConfig(GrPixelConfig config) const {
    188         SkASSERT(this->hasStencilFormatBeenDeterminedForConfig(config));
    189         return fConfigTable[config].fStencilFormatIndex;
    190     }
    191 
    192     /**
    193      * If index is >= 0 this records an index into stencilFormats() as the best stencil format for
    194      * the config. If < 0 it records that the config has no supported stencil format index.
    195      */
    196     void setStencilFormatIndexForConfig(GrPixelConfig config, int index) {
    197         SkASSERT(!this->hasStencilFormatBeenDeterminedForConfig(config));
    198         if (index < 0) {
    199             fConfigTable[config].fStencilFormatIndex = ConfigInfo::kUnsupported_StencilFormatIndex;
    200         } else {
    201             fConfigTable[config].fStencilFormatIndex = index;
    202         }
    203     }
    204 
    205     /**
    206      * Call to note that a color config has been verified as a valid color
    207      * attachment. This may save future calls to glCheckFramebufferStatus
    208      * using isConfigVerifiedColorAttachment().
    209      */
    210     void markConfigAsValidColorAttachment(GrPixelConfig config) {
    211         fConfigTable[config].fFlags |= ConfigInfo::kVerifiedColorAttachment_Flag;
    212     }
    213 
    214     /**
    215      * Call to check whether a config has been verified as a valid color
    216      * attachment.
    217      */
    218     bool isConfigVerifiedColorAttachment(GrPixelConfig config) const {
    219         return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kVerifiedColorAttachment_Flag);
    220     }
    221 
    222     /**
    223      * Reports the type of MSAA FBO support.
    224      */
    225     MSFBOType msFBOType() const { return fMSFBOType; }
    226 
    227     /**
    228      * Does the preferred MSAA FBO extension have MSAA renderbuffers?
    229      */
    230     bool usesMSAARenderBuffers() const {
    231         return kNone_MSFBOType != fMSFBOType &&
    232                kES_IMG_MsToTexture_MSFBOType != fMSFBOType &&
    233                kES_EXT_MsToTexture_MSFBOType != fMSFBOType &&
    234                kMixedSamples_MSFBOType != fMSFBOType;
    235     }
    236 
    237     /**
    238      * What functionality is supported by glBlitFramebuffer.
    239      */
    240     uint32_t blitFramebufferSupportFlags() const { return fBlitFramebufferFlags; }
    241 
    242     /**
    243      * Is the MSAA FBO extension one where the texture is multisampled when bound to an FBO and
    244      * then implicitly resolved when read.
    245      */
    246     bool usesImplicitMSAAResolve() const {
    247         return kES_IMG_MsToTexture_MSFBOType == fMSFBOType ||
    248                kES_EXT_MsToTexture_MSFBOType == fMSFBOType;
    249     }
    250 
    251     InvalidateFBType invalidateFBType() const { return fInvalidateFBType; }
    252 
    253     /// What type of buffer mapping is supported?
    254     MapBufferType mapBufferType() const { return fMapBufferType; }
    255 
    256     /// What type of transfer buffer is supported?
    257     TransferBufferType transferBufferType() const { return fTransferBufferType; }
    258 
    259     /// The maximum number of fragment uniform vectors (GLES has min. 16).
    260     int maxFragmentUniformVectors() const { return fMaxFragmentUniformVectors; }
    261 
    262     /**
    263      * Depending on the ES extensions present the BGRA external format may
    264      * correspond to either a BGRA or RGBA internalFormat. On desktop GL it is
    265      * RGBA.
    266      */
    267     bool bgraIsInternalFormat() const;
    268 
    269     /// Is there support for GL_UNPACK_ROW_LENGTH
    270     bool unpackRowLengthSupport() const { return fUnpackRowLengthSupport; }
    271 
    272     /// Is there support for GL_UNPACK_FLIP_Y
    273     bool unpackFlipYSupport() const { return fUnpackFlipYSupport; }
    274 
    275     /// Is there support for GL_PACK_ROW_LENGTH
    276     bool packRowLengthSupport() const { return fPackRowLengthSupport; }
    277 
    278     /// Is there support for GL_PACK_REVERSE_ROW_ORDER
    279     bool packFlipYSupport() const { return fPackFlipYSupport; }
    280 
    281     /// Is there support for texture parameter GL_TEXTURE_USAGE
    282     bool textureUsageSupport() const { return fTextureUsageSupport; }
    283 
    284     /// Is GL_ALPHA8 renderable
    285     bool alpha8IsRenderable() const { return fAlpha8IsRenderable; }
    286 
    287     /// Is GL_ARB_IMAGING supported
    288     bool imagingSupport() const { return fImagingSupport; }
    289 
    290     /// Is there support for Vertex Array Objects?
    291     bool vertexArrayObjectSupport() const { return fVertexArrayObjectSupport; }
    292 
    293     /// Is there support for GL_KHR_debug?
    294     bool debugSupport() const { return fDebugSupport; }
    295 
    296     /// Is there support for ES2 compatability?
    297     bool ES2CompatibilitySupport() const { return fES2CompatibilitySupport; }
    298 
    299     /// Is there support for glDraw*Instanced?
    300     bool drawInstancedSupport() const { return fDrawInstancedSupport; }
    301 
    302     /// Is there support for glDraw*Indirect? Note that the baseInstance fields of indirect draw
    303     /// commands cannot be used unless we have base instance support.
    304     bool drawIndirectSupport() const { return fDrawIndirectSupport; }
    305 
    306     /// Is there support for glMultiDraw*Indirect? Note that the baseInstance fields of indirect
    307     /// draw commands cannot be used unless we have base instance support.
    308     bool multiDrawIndirectSupport() const { return fMultiDrawIndirectSupport; }
    309 
    310     /// Is there support for glDrawRangeElements?
    311     bool drawRangeElementsSupport() const { return fDrawRangeElementsSupport; }
    312 
    313     /// Are the baseInstance fields supported in indirect draw commands?
    314     bool baseInstanceSupport() const { return fBaseInstanceSupport; }
    315 
    316     /// Use indices or vertices in CPU arrays rather than VBOs for dynamic content.
    317     bool useNonVBOVertexAndIndexDynamicData() const { return fUseNonVBOVertexAndIndexDynamicData; }
    318 
    319     bool surfaceSupportsWritePixels(const GrSurface* surface) const override;
    320 
    321     /// Does ReadPixels support reading readConfig pixels from a FBO that is surfaceConfig?
    322     bool readPixelsSupported(GrPixelConfig surfaceConfig,
    323                              GrPixelConfig readConfig,
    324                              std::function<void (GrGLenum, GrGLint*)> getIntegerv,
    325                              std::function<bool ()> bindRenderTarget,
    326                              std::function<void ()> unbindRenderTarget) const;
    327 
    328     bool isCoreProfile() const { return fIsCoreProfile; }
    329 
    330     bool bindFragDataLocationSupport() const { return fBindFragDataLocationSupport; }
    331 
    332     bool bindUniformLocationSupport() const { return fBindUniformLocationSupport; }
    333 
    334     /// Are textures with GL_TEXTURE_RECTANGLE type supported.
    335     bool rectangleTextureSupport() const { return fRectangleTextureSupport; }
    336 
    337     /// GL_ARB_texture_swizzle
    338     bool textureSwizzleSupport() const { return fTextureSwizzleSupport; }
    339 
    340     bool mipMapLevelAndLodControlSupport() const { return fMipMapLevelAndLodControlSupport; }
    341 
    342     bool doManualMipmapping() const { return fDoManualMipmapping; }
    343 
    344     bool srgbDecodeDisableAffectsMipmaps() const { return fSRGBDecodeDisableAffectsMipmaps; }
    345 
    346     void onDumpJSON(SkJSONWriter*) const override;
    347 
    348     bool rgba8888PixelsOpsAreSlow() const { return fRGBA8888PixelsOpsAreSlow; }
    349     bool partialFBOReadIsSlow() const { return fPartialFBOReadIsSlow; }
    350     bool rgbaToBgraReadbackConversionsAreSlow() const {
    351         return fRGBAToBGRAReadbackConversionsAreSlow;
    352     }
    353 
    354     bool useBufferDataNullHint() const { return fUseBufferDataNullHint; }
    355 
    356     // Certain Intel GPUs on Mac fail to clear if the glClearColor is made up of only 1s and 0s.
    357     bool clearToBoundaryValuesIsBroken() const { return fClearToBoundaryValuesIsBroken; }
    358 
    359     /// glClearTex(Sub)Image support
    360     bool clearTextureSupport() const { return fClearTextureSupport; }
    361 
    362     // Adreno/MSAA drops a draw on the imagefiltersbase GM if the base vertex param to
    363     // glDrawArrays is nonzero.
    364     // https://bugs.chromium.org/p/skia/issues/detail?id=6650
    365     bool drawArraysBaseVertexIsBroken() const { return fDrawArraysBaseVertexIsBroken; }
    366 
    367     // Many drivers have issues with color clears.
    368     bool useDrawToClearColor() const { return fUseDrawToClearColor; }
    369 
    370     /// Adreno 4xx devices experience an issue when there are a large number of stencil clip bit
    371     /// clears. The minimal repro steps are not precisely known but drawing a rect with a stencil
    372     /// op instead of using glClear seems to resolve the issue.
    373     bool useDrawToClearStencilClip() const { return fUseDrawToClearStencilClip; }
    374 
    375     // If true then we must use an intermediate surface to perform partial updates to unorm textures
    376     // that have ever been bound to a FBO.
    377     bool disallowTexSubImageForUnormConfigTexturesEverBoundToFBO() const {
    378         return fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO;
    379     }
    380 
    381     // Use an intermediate surface to write pixels (full or partial overwrite) to into a texture
    382     // that is bound to an FBO.
    383     bool useDrawInsteadOfAllRenderTargetWrites() const {
    384         return fUseDrawInsteadOfAllRenderTargetWrites;
    385     }
    386 
    387     // At least some Adreno 3xx drivers draw lines incorrectly after drawing non-lines. Toggling
    388     // face culling on and off seems to resolve this.
    389     bool requiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines() const {
    390         return fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines;
    391     }
    392 
    393     // Returns the observed maximum number of instances the driver can handle in a single call to
    394     // glDrawArraysInstanced without crashing, or 'pendingInstanceCount' if this
    395     // workaround is not necessary.
    396     // NOTE: the return value may be larger than pendingInstanceCount.
    397     int maxInstancesPerDrawArraysWithoutCrashing(int pendingInstanceCount) const {
    398         return fMaxInstancesPerDrawArraysWithoutCrashing ? fMaxInstancesPerDrawArraysWithoutCrashing
    399                                                          : pendingInstanceCount;
    400     }
    401 
    402     bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
    403                             bool* rectsMustMatch, bool* disallowSubrect) const override;
    404 
    405     bool programBinarySupport() const {
    406         return fProgramBinarySupport;
    407     }
    408 
    409     bool validateBackendTexture(const GrBackendTexture&, SkColorType,
    410                                 GrPixelConfig*) const override;
    411     bool validateBackendRenderTarget(const GrBackendRenderTarget&, SkColorType,
    412                                      GrPixelConfig*) const override;
    413 
    414     bool getConfigFromBackendFormat(const GrBackendFormat&, SkColorType,
    415                                     GrPixelConfig*) const override;
    416 
    417 private:
    418     enum ExternalFormatUsage {
    419         kTexImage_ExternalFormatUsage,
    420         kOther_ExternalFormatUsage,
    421 
    422         kLast_ExternalFormatUsage = kOther_ExternalFormatUsage
    423     };
    424     static const int kExternalFormatUsageCnt = kLast_ExternalFormatUsage + 1;
    425     bool getExternalFormat(GrPixelConfig surfaceConfig, GrPixelConfig memoryConfig,
    426                            ExternalFormatUsage usage, GrGLenum* externalFormat,
    427                            GrGLenum* externalType) const;
    428 
    429     void init(const GrContextOptions&, const GrGLContextInfo&, const GrGLInterface*);
    430     void initGLSL(const GrGLContextInfo&, const GrGLInterface*);
    431     bool hasPathRenderingSupport(const GrGLContextInfo&, const GrGLInterface*);
    432 
    433     void applyDriverCorrectnessWorkarounds(const GrGLContextInfo&, const GrContextOptions&,
    434                                            GrShaderCaps*);
    435 
    436     void onApplyOptionsOverrides(const GrContextOptions& options) override;
    437 
    438     bool onIsMixedSamplesSupportedForRT(const GrBackendRenderTarget&) const override;
    439     bool onIsWindowRectanglesSupportedForRT(const GrBackendRenderTarget&) const override;
    440 
    441     void initFSAASupport(const GrContextOptions& contextOptions, const GrGLContextInfo&,
    442                          const GrGLInterface*);
    443     void initBlendEqationSupport(const GrGLContextInfo&);
    444     void initStencilSupport(const GrGLContextInfo&);
    445     // This must be called after initFSAASupport().
    446     void initConfigTable(const GrContextOptions&, const GrGLContextInfo&, const GrGLInterface*,
    447                          GrShaderCaps*);
    448 
    449     GrGLStandard fStandard;
    450 
    451     SkTArray<StencilFormat, true> fStencilFormats;
    452 
    453     int fMaxFragmentUniformVectors;
    454 
    455     MSFBOType           fMSFBOType;
    456     InvalidateFBType    fInvalidateFBType;
    457     MapBufferType       fMapBufferType;
    458     TransferBufferType  fTransferBufferType;
    459 
    460     bool fUnpackRowLengthSupport : 1;
    461     bool fUnpackFlipYSupport : 1;
    462     bool fPackRowLengthSupport : 1;
    463     bool fPackFlipYSupport : 1;
    464     bool fTextureUsageSupport : 1;
    465     bool fAlpha8IsRenderable: 1;
    466     bool fImagingSupport  : 1;
    467     bool fVertexArrayObjectSupport : 1;
    468     bool fDebugSupport : 1;
    469     bool fES2CompatibilitySupport : 1;
    470     bool fDrawInstancedSupport : 1;
    471     bool fDrawIndirectSupport : 1;
    472     bool fDrawRangeElementsSupport : 1;
    473     bool fMultiDrawIndirectSupport : 1;
    474     bool fBaseInstanceSupport : 1;
    475     bool fUseNonVBOVertexAndIndexDynamicData : 1;
    476     bool fIsCoreProfile : 1;
    477     bool fBindFragDataLocationSupport : 1;
    478     bool fRGBA8888PixelsOpsAreSlow : 1;
    479     bool fPartialFBOReadIsSlow : 1;
    480     bool fBindUniformLocationSupport : 1;
    481     bool fRectangleTextureSupport : 1;
    482     bool fTextureSwizzleSupport : 1;
    483     bool fMipMapLevelAndLodControlSupport : 1;
    484     bool fRGBAToBGRAReadbackConversionsAreSlow : 1;
    485     bool fUseBufferDataNullHint                : 1;
    486     bool fClearTextureSupport : 1;
    487     bool fProgramBinarySupport : 1;
    488 
    489     // Driver workarounds
    490     bool fDoManualMipmapping : 1;
    491     bool fSRGBDecodeDisableAffectsMipmaps : 1;
    492     bool fClearToBoundaryValuesIsBroken : 1;
    493     bool fDrawArraysBaseVertexIsBroken : 1;
    494     bool fUseDrawToClearColor : 1;
    495     bool fUseDrawToClearStencilClip : 1;
    496     bool fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO : 1;
    497     bool fUseDrawInsteadOfAllRenderTargetWrites : 1;
    498     bool fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines : 1;
    499     int fMaxInstancesPerDrawArraysWithoutCrashing;
    500 
    501     uint32_t fBlitFramebufferFlags;
    502 
    503     /** Number type of the components (with out considering number of bits.) */
    504     enum FormatType {
    505         kNormalizedFixedPoint_FormatType,
    506         kFloat_FormatType,
    507         kInteger_FormatType,
    508     };
    509 
    510     struct ReadPixelsFormat {
    511         ReadPixelsFormat() : fFormat(0), fType(0) {}
    512         GrGLenum fFormat;
    513         GrGLenum fType;
    514     };
    515 
    516     struct ConfigFormats {
    517         ConfigFormats() {
    518             // Inits to known bad GL enum values.
    519             memset(this, 0xAB, sizeof(ConfigFormats));
    520         }
    521         GrGLenum fBaseInternalFormat;
    522         GrGLenum fSizedInternalFormat;
    523 
    524         /** The external format and type are to be used when uploading/downloading data using this
    525             config where both the CPU data and GrSurface are the same config. To get the external
    526             format and type when converting between configs while copying to/from memory use
    527             getExternalFormat().
    528             The kTexImage external format is usually the same as kOther except for kSRGBA on some
    529             GL contexts. */
    530         GrGLenum fExternalFormat[kExternalFormatUsageCnt];
    531         GrGLenum fExternalType;
    532 
    533         // Either the base or sized internal format depending on the GL and config.
    534         GrGLenum fInternalFormatTexImage;
    535         GrGLenum fInternalFormatRenderbuffer;
    536     };
    537 
    538     struct ConfigInfo {
    539         ConfigInfo() : fStencilFormatIndex(kUnknown_StencilIndex), fFlags(0) {}
    540 
    541         ConfigFormats fFormats;
    542 
    543         FormatType fFormatType;
    544 
    545         // On ES contexts there are restrictions on type type/format that may be used for
    546         // ReadPixels. One is implicitly specified by the current FBO's format. The other is
    547         // queryable. This stores the queried option (lazily).
    548         ReadPixelsFormat fSecondReadPixelsFormat;
    549 
    550         enum {
    551             // This indicates that a stencil format has not yet been determined for the config.
    552             kUnknown_StencilIndex = -1,
    553             // This indicates that there is no supported stencil format for the config.
    554             kUnsupported_StencilFormatIndex = -2
    555         };
    556 
    557         // Index fStencilFormats.
    558         int fStencilFormatIndex;
    559 
    560         SkTDArray<int> fColorSampleCounts;
    561 
    562         enum {
    563             kVerifiedColorAttachment_Flag = 0x1,
    564             kTextureable_Flag             = 0x2,
    565             kRenderable_Flag              = 0x4,
    566             kRenderableWithMSAA_Flag      = 0x8,
    567             /** kFBOColorAttachment means that even if the config cannot be a GrRenderTarget, we can
    568                 still attach it to a FBO for blitting or reading pixels. */
    569             kFBOColorAttachment_Flag      = 0x10,
    570             kCanUseTexStorage_Flag        = 0x20,
    571             kCanUseWithTexelBuffer_Flag   = 0x40,
    572         };
    573         uint32_t fFlags;
    574 
    575         GrSwizzle fSwizzle;
    576     };
    577 
    578     ConfigInfo fConfigTable[kGrPixelConfigCnt];
    579 
    580     typedef GrCaps INHERITED;
    581 };
    582 
    583 #endif
    584