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