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