1 
2 /*
3  * Copyright 2013 Google Inc.
4  *
5  * Use of this source code is governed by a BSD-style license that can be
6  * found in the LICENSE file.
7  */
8 #ifndef GrCaps_DEFINED
9 #define GrCaps_DEFINED
10 
11 #include "include/core/SkImageInfo.h"
12 #include "include/core/SkRefCnt.h"
13 #include "include/core/SkString.h"
14 #include "include/gpu/GrDriverBugWorkarounds.h"
15 #include "include/private/GrTypesPriv.h"
16 #include "src/gpu/GrBlend.h"
17 #include "src/gpu/GrShaderCaps.h"
18 #include "src/gpu/GrSurfaceProxy.h"
19 
20 class GrBackendFormat;
21 class GrBackendRenderTarget;
22 class GrBackendTexture;
23 struct GrContextOptions;
24 class GrRenderTargetProxy;
25 class GrSurface;
26 class SkJSONWriter;
27 
28 /**
29  * Represents the capabilities of a GrContext.
30  */
31 class GrCaps : public SkRefCnt {
32 public:
33     GrCaps(const GrContextOptions&);
34 
35     void dumpJSON(SkJSONWriter*) const;
36 
shaderCaps()37     const GrShaderCaps* shaderCaps() const { return fShaderCaps.get(); }
38 
npotTextureTileSupport()39     bool npotTextureTileSupport() const { return fNPOTTextureTileSupport; }
40     /** To avoid as-yet-unnecessary complexity we don't allow any partial support of MIP Maps (e.g.
41         only for POT textures) */
mipMapSupport()42     bool mipMapSupport() const { return fMipMapSupport; }
43 
gpuTracingSupport()44     bool gpuTracingSupport() const { return fGpuTracingSupport; }
oversizedStencilSupport()45     bool oversizedStencilSupport() const { return fOversizedStencilSupport; }
textureBarrierSupport()46     bool textureBarrierSupport() const { return fTextureBarrierSupport; }
sampleLocationsSupport()47     bool sampleLocationsSupport() const { return fSampleLocationsSupport; }
multisampleDisableSupport()48     bool multisampleDisableSupport() const { return fMultisampleDisableSupport; }
instanceAttribSupport()49     bool instanceAttribSupport() const { return fInstanceAttribSupport; }
mixedSamplesSupport()50     bool mixedSamplesSupport() const { return fMixedSamplesSupport; }
51     // This flag indicates that we never have to resolve MSAA. In practice, it means that we have
52     // an MSAA-render-to-texture extension: Any render target we create internally will use the
53     // extension, and any wrapped render target is the client's responsibility.
msaaResolvesAutomatically()54     bool msaaResolvesAutomatically() const { return fMSAAResolvesAutomatically; }
halfFloatVertexAttributeSupport()55     bool halfFloatVertexAttributeSupport() const { return fHalfFloatVertexAttributeSupport; }
56 
57     // Primitive restart functionality is core in ES 3.0, but using it will cause slowdowns on some
58     // systems. This cap is only set if primitive restart will improve performance.
usePrimitiveRestart()59     bool usePrimitiveRestart() const { return fUsePrimitiveRestart; }
60 
preferClientSideDynamicBuffers()61     bool preferClientSideDynamicBuffers() const { return fPreferClientSideDynamicBuffers; }
62 
63     // On tilers, an initial fullscreen clear is an OPTIMIZATION. It allows the hardware to
64     // initialize each tile with a constant value rather than loading each pixel from memory.
preferFullscreenClears()65     bool preferFullscreenClears() const { return fPreferFullscreenClears; }
66 
67     // Should we discard stencil values after a render pass? (Tilers get better performance if we
68     // always load stencil buffers with a "clear" op, and then discard the content when finished.)
discardStencilValuesAfterRenderPass()69     bool discardStencilValuesAfterRenderPass() const {
70         // This method is actually just a duplicate of preferFullscreenClears(), with a descriptive
71         // name for the sake of readability.
72         return this->preferFullscreenClears();
73     }
74 
preferVRAMUseOverFlushes()75     bool preferVRAMUseOverFlushes() const { return fPreferVRAMUseOverFlushes; }
76 
preferTrianglesOverSampleMask()77     bool preferTrianglesOverSampleMask() const { return fPreferTrianglesOverSampleMask; }
78 
avoidStencilBuffers()79     bool avoidStencilBuffers() const { return fAvoidStencilBuffers; }
80 
avoidWritePixelsFastPath()81     bool avoidWritePixelsFastPath() const { return fAvoidWritePixelsFastPath; }
82 
83     /**
84      * Indicates the capabilities of the fixed function blend unit.
85      */
86     enum BlendEquationSupport {
87         kBasic_BlendEquationSupport,             //<! Support to select the operator that
88                                                  //   combines src and dst terms.
89         kAdvanced_BlendEquationSupport,          //<! Additional fixed function support for specific
90                                                  //   SVG/PDF blend modes. Requires blend barriers.
91         kAdvancedCoherent_BlendEquationSupport,  //<! Advanced blend equation support that does not
92                                                  //   require blend barriers, and permits overlap.
93 
94         kLast_BlendEquationSupport = kAdvancedCoherent_BlendEquationSupport
95     };
96 
blendEquationSupport()97     BlendEquationSupport blendEquationSupport() const { return fBlendEquationSupport; }
98 
advancedBlendEquationSupport()99     bool advancedBlendEquationSupport() const {
100         return fBlendEquationSupport >= kAdvanced_BlendEquationSupport;
101     }
102 
advancedCoherentBlendEquationSupport()103     bool advancedCoherentBlendEquationSupport() const {
104         return kAdvancedCoherent_BlendEquationSupport == fBlendEquationSupport;
105     }
106 
isAdvancedBlendEquationBlacklisted(GrBlendEquation equation)107     bool isAdvancedBlendEquationBlacklisted(GrBlendEquation equation) const {
108         SkASSERT(GrBlendEquationIsAdvanced(equation));
109         SkASSERT(this->advancedBlendEquationSupport());
110         return SkToBool(fAdvBlendEqBlacklist & (1 << equation));
111     }
112 
113     /**
114      * Indicates whether GPU->CPU memory mapping for GPU resources such as vertex buffers and
115      * textures allows partial mappings or full mappings.
116      */
117     enum MapFlags {
118         kNone_MapFlags      = 0x0,   //<! Cannot map the resource.
119 
120         kCanMap_MapFlag     = 0x1,   //<! The resource can be mapped. Must be set for any of
121                                      //   the other flags to have meaning.
122         kSubset_MapFlag     = 0x2,   //<! The resource can be partially mapped.
123         kAsyncRead_MapFlag  = 0x4,   //<! Are maps for reading asynchronous WRT GrOpsRenderPass
124                                      //   submitted to GrGpu.
125     };
126 
mapBufferFlags()127     uint32_t mapBufferFlags() const { return fMapBufferFlags; }
128 
129     // Scratch textures not being reused means that those scratch textures
130     // that we upload to (i.e., don't have a render target) will not be
131     // recycled in the texture cache. This is to prevent ghosting by drivers
132     // (in particular for deferred architectures).
reuseScratchTextures()133     bool reuseScratchTextures() const { return fReuseScratchTextures; }
reuseScratchBuffers()134     bool reuseScratchBuffers() const { return fReuseScratchBuffers; }
135 
136     /// maximum number of attribute values per vertex
maxVertexAttributes()137     int maxVertexAttributes() const { return fMaxVertexAttributes; }
138 
maxRenderTargetSize()139     int maxRenderTargetSize() const { return fMaxRenderTargetSize; }
140 
141     /** This is the largest render target size that can be used without incurring extra perfomance
142         cost. It is usually the max RT size, unless larger render targets are known to be slower. */
maxPreferredRenderTargetSize()143     int maxPreferredRenderTargetSize() const { return fMaxPreferredRenderTargetSize; }
144 
maxTextureSize()145     int maxTextureSize() const { return fMaxTextureSize; }
146 
147     /** This is the maximum tile size to use by GPU devices for rendering sw-backed images/bitmaps.
148         It is usually the max texture size, unless we're overriding it for testing. */
maxTileSize()149     int maxTileSize() const {
150         SkASSERT(fMaxTileSize <= fMaxTextureSize);
151         return fMaxTileSize;
152     }
153 
maxWindowRectangles()154     int maxWindowRectangles() const { return fMaxWindowRectangles; }
155 
156     // Returns whether mixed samples is supported for the given backend render target.
isWindowRectanglesSupportedForRT(const GrBackendRenderTarget & rt)157     bool isWindowRectanglesSupportedForRT(const GrBackendRenderTarget& rt) const {
158         return this->maxWindowRectangles() > 0 && this->onIsWindowRectanglesSupportedForRT(rt);
159     }
160 
161     virtual bool isFormatSRGB(const GrBackendFormat&) const = 0;
162 
163     // Callers can optionally pass in an SkImage::CompressionType which will be filled in with the
164     // correct type if the GrBackendFormat is compressed.
165     virtual bool isFormatCompressed(const GrBackendFormat&,
166                                     SkImage::CompressionType* compressionType = nullptr) const = 0;
167 
168     // TODO: Once we use the supportWritePixels call for uploads, we can remove this function and
169     // instead only have the version that takes a GrBackendFormat.
170     virtual bool isFormatTexturableAndUploadable(GrColorType, const GrBackendFormat&) const = 0;
171     // Can a texture be made with the GrBackendFormat, and then be bound and sampled in a shader.
172     virtual bool isFormatTexturable(const GrBackendFormat&) const = 0;
173 
174     // Returns whether a texture of the given format can be copied to a texture of the same format.
175     virtual bool isFormatCopyable(const GrBackendFormat&) const = 0;
176 
177     // Returns the maximum supported sample count for a format. 0 means the format is not renderable
178     // 1 means the format is renderable but doesn't support MSAA. This call only refers to the
179     // format itself. A caller should also confirm if the format is renderable with a given
180     // GrColorType by calling isFormatRenderable.
181     virtual int maxRenderTargetSampleCount(const GrBackendFormat&) const = 0;
182 
183     // Returns the number of samples to use when performing internal draws to the given config with
184     // MSAA or mixed samples. If 0, Ganesh should not attempt to use internal multisampling.
internalMultisampleCount(const GrBackendFormat & format)185     int internalMultisampleCount(const GrBackendFormat& format) const {
186         return SkTMin(fInternalMultisampleCount, this->maxRenderTargetSampleCount(format));
187     }
188 
189     virtual bool isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat& format,
190                                                int sampleCount = 1) const = 0;
191 
192     virtual bool isFormatRenderable(const GrBackendFormat& format, int sampleCount) const = 0;
193 
194     // Find a sample count greater than or equal to the requested count which is supported for a
195     // render target of the given format or 0 if no such sample count is supported. If the requested
196     // sample count is 1 then 1 will be returned if non-MSAA rendering is supported, otherwise 0.
197     // For historical reasons requestedCount==0 is handled identically to requestedCount==1.
198     virtual int getRenderTargetSampleCount(int requestedCount, const GrBackendFormat&) const = 0;
199 
200     // Returns the number of bytes per pixel for the given GrBackendFormat. This is only supported
201     // for "normal" formats. For compressed formats this will return 0.
202     virtual size_t bytesPerPixel(const GrBackendFormat&) const = 0;
203 
204     /**
205      * Backends may have restrictions on what types of surfaces support GrGpu::writePixels().
206      * If this returns false then the caller should implement a fallback where a temporary texture
207      * is created, pixels are written to it, and then that is copied or drawn into the the surface.
208      */
209     bool surfaceSupportsWritePixels(const GrSurface*) const;
210 
211     /**
212      * Indicates whether surface supports GrGpu::readPixels, must be copied, or cannot be read.
213      */
214     enum class SurfaceReadPixelsSupport {
215         /** GrGpu::readPixels is supported by the surface. */
216         kSupported,
217         /**
218          * GrGpu::readPixels is not supported by this surface but this surface can be drawn
219          * or copied to a Ganesh-created GrTextureType::kTexture2D and then that surface will be
220          * readable.
221          */
222         kCopyToTexture2D,
223         /**
224          * Not supported
225          */
226         kUnsupported,
227     };
228     /**
229      * Backends may have restrictions on what types of surfaces support GrGpu::readPixels(). We may
230      * either be able to read directly from the surface, read from a copy of the surface, or not
231      * read at all.
232      */
233     virtual SurfaceReadPixelsSupport surfaceSupportsReadPixels(const GrSurface*) const = 0;
234 
235     struct SupportedWrite {
236         GrColorType fColorType;
237         // If the write is occurring using GrGpu::transferPixelsTo then this provides the
238         // minimum alignment of the offset into the transfer buffer.
239         size_t fOffsetAlignmentForTransferBuffer;
240     };
241 
242     /**
243      * Given a dst pixel config and a src color type what color type must the caller coax the
244      * the data into in order to use GrGpu::writePixels().
245      */
246     virtual SupportedWrite supportedWritePixelsColorType(GrColorType surfaceColorType,
247                                                          const GrBackendFormat& surfaceFormat,
248                                                          GrColorType srcColorType) const = 0;
249 
250     struct SupportedRead {
251         GrColorType fColorType;
252         // If the read is occurring using GrGpu::transferPixelsFrom then this provides the
253         // minimum alignment of the offset into the transfer buffer.
254         size_t fOffsetAlignmentForTransferBuffer;
255     };
256 
257     /**
258      * Given a src surface's color type and its backend format as well as a color type the caller
259      * would like read into, this provides a legal color type that the caller may pass to
260      * GrGpu::readPixels(). The returned color type may differ from the passed dstColorType, in
261      * which case the caller must convert the read pixel data (see GrConvertPixels). When converting
262      * to dstColorType the swizzle in the returned struct should be applied. The caller must check
263      * the returned color type for kUnknown.
264      */
265     SupportedRead supportedReadPixelsColorType(GrColorType srcColorType,
266                                                const GrBackendFormat& srcFormat,
267                                                GrColorType dstColorType) const;
268 
269     /**
270      * Do GrGpu::writePixels() and GrGpu::transferPixelsTo() support a src buffer where the row
271      * bytes is not equal to bpp * w?
272      */
writePixelsRowBytesSupport()273     bool writePixelsRowBytesSupport() const { return fWritePixelsRowBytesSupport; }
274     /**
275      * Does GrGpu::readPixels() support a dst buffer where the row bytes is not equal to bpp * w?
276      */
readPixelsRowBytesSupport()277     bool readPixelsRowBytesSupport() const { return fReadPixelsRowBytesSupport; }
278 
279     /** Are transfer buffers (to textures and from surfaces) supported? */
transferBufferSupport()280     bool transferBufferSupport() const { return fTransferBufferSupport; }
281 
suppressPrints()282     bool suppressPrints() const { return fSuppressPrints; }
283 
bufferMapThreshold()284     size_t bufferMapThreshold() const {
285         SkASSERT(fBufferMapThreshold >= 0);
286         return fBufferMapThreshold;
287     }
288 
289     /** True in environments that will issue errors if memory uploaded to buffers
290         is not initialized (even if not read by draw calls). */
mustClearUploadedBufferData()291     bool mustClearUploadedBufferData() const { return fMustClearUploadedBufferData; }
292 
293     /** For some environments, there is a performance or safety concern to not
294         initializing textures. For example, with WebGL and Firefox, there is a large
295         performance hit to not doing it.
296      */
shouldInitializeTextures()297     bool shouldInitializeTextures() const { return fShouldInitializeTextures; }
298 
299     /** Returns true if the given backend supports importing AHardwareBuffers via the
300      * GrAHardwarebufferImageGenerator. This will only ever be supported on Android devices with API
301      * level >= 26.
302      * */
supportsAHardwareBufferImages()303     bool supportsAHardwareBufferImages() const { return fSupportsAHardwareBufferImages; }
304 
wireframeMode()305     bool wireframeMode() const { return fWireframeMode; }
306 
307     /** Supports using GrFence. */
fenceSyncSupport()308     bool fenceSyncSupport() const { return fFenceSyncSupport; }
309 
310     /** Supports using GrSemaphore. */
semaphoreSupport()311     bool semaphoreSupport() const { return fSemaphoreSupport; }
312 
crossContextTextureSupport()313     bool crossContextTextureSupport() const { return fCrossContextTextureSupport; }
314     /**
315      * Returns whether or not we will be able to do a copy given the passed in params
316      */
317     bool canCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src,
318                         const SkIRect& srcRect, const SkIPoint& dstPoint) const;
319 
dynamicStateArrayGeometryProcessorTextureSupport()320     bool dynamicStateArrayGeometryProcessorTextureSupport() const {
321         return fDynamicStateArrayGeometryProcessorTextureSupport;
322     }
323 
324     // Not all backends support clearing with a scissor test (e.g. Metal), this will always
325     // return true if performColorClearsAsDraws() returns true.
performPartialClearsAsDraws()326     bool performPartialClearsAsDraws() const {
327         return fPerformColorClearsAsDraws || fPerformPartialClearsAsDraws;
328     }
329 
330     // Many drivers have issues with color clears.
performColorClearsAsDraws()331     bool performColorClearsAsDraws() const { return fPerformColorClearsAsDraws; }
332 
333     /// Adreno 4xx devices experience an issue when there are a large number of stencil clip bit
334     /// clears. The minimal repro steps are not precisely known but drawing a rect with a stencil
335     /// op instead of using glClear seems to resolve the issue.
performStencilClearsAsDraws()336     bool performStencilClearsAsDraws() const { return fPerformStencilClearsAsDraws; }
337 
338     // Can we use coverage counting shortcuts to render paths? Coverage counting can cause artifacts
339     // along shared edges if care isn't taken to ensure both contours wind in the same direction.
allowCoverageCounting()340     bool allowCoverageCounting() const { return fAllowCoverageCounting; }
341 
342     // Should we disable the CCPR code due to a faulty driver?
driverBlacklistCCPR()343     bool driverBlacklistCCPR() const { return fDriverBlacklistCCPR; }
driverBlacklistMSAACCPR()344     bool driverBlacklistMSAACCPR() const { return fDriverBlacklistMSAACCPR; }
345 
346     /**
347      * This is used to try to ensure a successful copy a dst in order to perform shader-based
348      * blending.
349      *
350      * fRectsMustMatch will be set to true if the copy operation must ensure that the src and dest
351      * rects are identical.
352      *
353      * fMustCopyWholeSrc will be set to true if copy rect must equal src's bounds.
354      *
355      * Caller will detect cases when copy cannot succeed and try copy-as-draw as a fallback.
356      */
357     struct DstCopyRestrictions {
358         GrSurfaceProxy::RectsMustMatch fRectsMustMatch = GrSurfaceProxy::RectsMustMatch::kNo;
359         bool fMustCopyWholeSrc = false;
360     };
getDstCopyRestrictions(const GrRenderTargetProxy * src,GrColorType ct)361     virtual DstCopyRestrictions getDstCopyRestrictions(const GrRenderTargetProxy* src,
362                                                        GrColorType ct) const {
363         return {};
364     }
365 
366     bool validateSurfaceParams(const SkISize&, const GrBackendFormat&, GrPixelConfig,
367                                GrRenderable renderable, int renderTargetSampleCnt,
368                                GrMipMapped) const;
369 
areColorTypeAndFormatCompatible(GrColorType grCT,const GrBackendFormat & format)370     bool areColorTypeAndFormatCompatible(GrColorType grCT,
371                                          const GrBackendFormat& format) const {
372         if (GrColorType::kUnknown == grCT) {
373             return false;
374         }
375 
376         return this->onAreColorTypeAndFormatCompatible(grCT, format);
377     }
378 
379     // TODO: it seems like we could pass the full SkImageInfo and validate its colorSpace too
380     // Returns kUnknown if a valid config could not be determined.
getConfigFromBackendFormat(const GrBackendFormat & format,GrColorType grCT)381     GrPixelConfig getConfigFromBackendFormat(const GrBackendFormat& format,
382                                              GrColorType grCT) const {
383         if (GrColorType::kUnknown == grCT) {
384             return kUnknown_GrPixelConfig;
385         }
386 
387         return this->onGetConfigFromBackendFormat(format, grCT);
388     }
389 
390     /**
391      * Special method only for YUVA images. Returns a colortype that matches the backend format or
392      * kUnknown if a colortype could not be determined.
393      */
394     virtual GrColorType getYUVAColorTypeFromBackendFormat(const GrBackendFormat&,
395                                                           bool isAlphaChannel) const = 0;
396 
397     /** These are used when creating a new texture internally. */
398     GrBackendFormat getDefaultBackendFormat(GrColorType, GrRenderable) const;
399 
400     virtual GrBackendFormat getBackendFormatFromCompressionType(SkImage::CompressionType) const = 0;
401 
402     /**
403      * The CLAMP_TO_BORDER wrap mode for texture coordinates was added to desktop GL in 1.3, and
404      * GLES 3.2, but is also available in extensions. Vulkan and Metal always have support.
405      */
clampToBorderSupport()406     bool clampToBorderSupport() const { return fClampToBorderSupport; }
407 
408     /**
409      * Returns the GrSwizzle to use when sampling from a texture with the passed in GrBackendFormat
410      * and GrColorType.
411      */
412     virtual GrSwizzle getTextureSwizzle(const GrBackendFormat&, GrColorType) const = 0;
413 
414     /**
415      * Returns the GrSwizzle to use when outputting to a render target with the passed in
416      * GrBackendFormat and GrColorType.
417      */
418     virtual GrSwizzle getOutputSwizzle(const GrBackendFormat&, GrColorType) const = 0;
419 
workarounds()420     const GrDriverBugWorkarounds& workarounds() const { return fDriverBugWorkarounds; }
421 
422     /**
423      * Given a possibly generic GrPixelConfig and a backend format return a specific
424      * GrPixelConfig.
425      */
makeConfigSpecific(GrPixelConfig config,const GrBackendFormat & format)426     GrPixelConfig makeConfigSpecific(GrPixelConfig config, const GrBackendFormat& format) const {
427         auto ct = GrPixelConfigToColorType(config);
428         auto result = this->getConfigFromBackendFormat(format, ct);
429         SkASSERT(config == result || AreConfigsCompatible(config, result));
430         return result;
431     }
432 
433 #ifdef SK_DEBUG
434     // This is just a debugging entry point until we're weaned off of GrPixelConfig. It
435     // should be used to verify that the pixel config from user-level code (the genericConfig)
436     // is compatible with a pixel config we've computed from scratch (the specificConfig).
437     static bool AreConfigsCompatible(GrPixelConfig genericConfig, GrPixelConfig specificConfig);
438 #endif
439 
440 #if GR_TEST_UTILS
441     struct TestFormatColorTypeCombination {
442         GrColorType fColorType;
443         GrBackendFormat fFormat;
444     };
445 
446     virtual std::vector<TestFormatColorTypeCombination> getTestingCombinations() const = 0;
447 #endif
448 
449 protected:
450     /** Subclasses must call this at the end of their constructors in order to apply caps
451         overrides requested by the client. Note that overrides will only reduce the caps never
452         expand them. */
453     void applyOptionsOverrides(const GrContextOptions& options);
454 
455     sk_sp<GrShaderCaps> fShaderCaps;
456 
457     bool fNPOTTextureTileSupport                     : 1;
458     bool fMipMapSupport                              : 1;
459     bool fReuseScratchTextures                       : 1;
460     bool fReuseScratchBuffers                        : 1;
461     bool fGpuTracingSupport                          : 1;
462     bool fOversizedStencilSupport                    : 1;
463     bool fTextureBarrierSupport                      : 1;
464     bool fSampleLocationsSupport                     : 1;
465     bool fMultisampleDisableSupport                  : 1;
466     bool fInstanceAttribSupport                      : 1;
467     bool fMixedSamplesSupport                        : 1;
468     bool fMSAAResolvesAutomatically                  : 1;
469     bool fUsePrimitiveRestart                        : 1;
470     bool fPreferClientSideDynamicBuffers             : 1;
471     bool fPreferFullscreenClears                     : 1;
472     bool fMustClearUploadedBufferData                : 1;
473     bool fShouldInitializeTextures                   : 1;
474     bool fSupportsAHardwareBufferImages              : 1;
475     bool fHalfFloatVertexAttributeSupport            : 1;
476     bool fClampToBorderSupport                       : 1;
477     bool fPerformPartialClearsAsDraws                : 1;
478     bool fPerformColorClearsAsDraws                  : 1;
479     bool fPerformStencilClearsAsDraws                : 1;
480     bool fAllowCoverageCounting                      : 1;
481     bool fTransferBufferSupport                      : 1;
482     bool fWritePixelsRowBytesSupport                 : 1;
483     bool fReadPixelsRowBytesSupport                  : 1;
484 
485     // Driver workaround
486     bool fDriverBlacklistCCPR                        : 1;
487     bool fDriverBlacklistMSAACCPR                    : 1;
488     bool fAvoidStencilBuffers                        : 1;
489     bool fAvoidWritePixelsFastPath                   : 1;
490 
491     // ANGLE performance workaround
492     bool fPreferVRAMUseOverFlushes                   : 1;
493 
494     // On some platforms it's better to make more triangles than to use the sample mask (MSAA only).
495     bool fPreferTrianglesOverSampleMask              : 1;
496 
497     bool fFenceSyncSupport                           : 1;
498     bool fSemaphoreSupport                           : 1;
499 
500     // Requires fence sync support in GL.
501     bool fCrossContextTextureSupport                 : 1;
502 
503     // Not (yet) implemented in VK backend.
504     bool fDynamicStateArrayGeometryProcessorTextureSupport : 1;
505 
506     BlendEquationSupport fBlendEquationSupport;
507     uint32_t fAdvBlendEqBlacklist;
508     GR_STATIC_ASSERT(kLast_GrBlendEquation < 32);
509 
510     uint32_t fMapBufferFlags;
511     int fBufferMapThreshold;
512 
513     int fMaxRenderTargetSize;
514     int fMaxPreferredRenderTargetSize;
515     int fMaxVertexAttributes;
516     int fMaxTextureSize;
517     int fMaxTileSize;
518     int fMaxWindowRectangles;
519     int fInternalMultisampleCount;
520 
521     GrDriverBugWorkarounds fDriverBugWorkarounds;
522 
523 private:
onApplyOptionsOverrides(const GrContextOptions &)524     virtual void onApplyOptionsOverrides(const GrContextOptions&) {}
onDumpJSON(SkJSONWriter *)525     virtual void onDumpJSON(SkJSONWriter*) const {}
526     virtual bool onSurfaceSupportsWritePixels(const GrSurface*) const = 0;
527     virtual bool onCanCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src,
528                                   const SkIRect& srcRect, const SkIPoint& dstPoint) const = 0;
529     virtual GrBackendFormat onGetDefaultBackendFormat(GrColorType, GrRenderable) const = 0;
530 
531     // Backends should implement this if they have any extra requirements for use of window
532     // rectangles for a specific GrBackendRenderTarget outside of basic support.
onIsWindowRectanglesSupportedForRT(const GrBackendRenderTarget &)533     virtual bool onIsWindowRectanglesSupportedForRT(const GrBackendRenderTarget&) const {
534         return true;
535     }
536 
537     virtual GrPixelConfig onGetConfigFromBackendFormat(const GrBackendFormat& format,
538                                                        GrColorType ct) const = 0;
539 
540     virtual bool onAreColorTypeAndFormatCompatible(GrColorType, const GrBackendFormat&) const = 0;
541 
542     virtual SupportedRead onSupportedReadPixelsColorType(GrColorType srcColorType,
543                                                          const GrBackendFormat& srcFormat,
544                                                          GrColorType dstColorType) const = 0;
545 
546 
547     bool fSuppressPrints : 1;
548     bool fWireframeMode  : 1;
549 
550     typedef SkRefCnt INHERITED;
551 };
552 
553 #endif
554