• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "../private/GrTypesPriv.h"
12 #include "GrBlend.h"
13 #include "GrShaderCaps.h"
14 #include "SkRefCnt.h"
15 #include "SkString.h"
16 
17 struct GrContextOptions;
18 class GrRenderTargetProxy;
19 
20 /**
21  * Represents the capabilities of a GrContext.
22  */
23 class GrCaps : public SkRefCnt {
24 public:
25     GrCaps(const GrContextOptions&);
26 
27     virtual SkString dump() const;
shaderCaps()28     const GrShaderCaps* shaderCaps() const { return fShaderCaps.get(); }
29 
npotTextureTileSupport()30     bool npotTextureTileSupport() const { return fNPOTTextureTileSupport; }
31     /** To avoid as-yet-unnecessary complexity we don't allow any partial support of MIP Maps (e.g.
32         only for POT textures) */
mipMapSupport()33     bool mipMapSupport() const { return fMipMapSupport; }
34 
35     /**
36      * Skia convention is that a device only has sRGB support if it supports sRGB formats for both
37      * textures and framebuffers. In addition:
38      *   Decoding to linear of an sRGB texture can be disabled.
39      */
srgbSupport()40     bool srgbSupport() const { return fSRGBSupport; }
41     /**
42      * Is there support for enabling/disabling sRGB writes for sRGB-capable color buffers?
43      */
srgbWriteControl()44     bool srgbWriteControl() const { return fSRGBWriteControl; }
discardRenderTargetSupport()45     bool discardRenderTargetSupport() const { return fDiscardRenderTargetSupport; }
gpuTracingSupport()46     bool gpuTracingSupport() const { return fGpuTracingSupport; }
oversizedStencilSupport()47     bool oversizedStencilSupport() const { return fOversizedStencilSupport; }
textureBarrierSupport()48     bool textureBarrierSupport() const { return fTextureBarrierSupport; }
sampleLocationsSupport()49     bool sampleLocationsSupport() const { return fSampleLocationsSupport; }
multisampleDisableSupport()50     bool multisampleDisableSupport() const { return fMultisampleDisableSupport; }
instanceAttribSupport()51     bool instanceAttribSupport() const { return fInstanceAttribSupport; }
usesMixedSamples()52     bool usesMixedSamples() const { return fUsesMixedSamples; }
preferClientSideDynamicBuffers()53     bool preferClientSideDynamicBuffers() const { return fPreferClientSideDynamicBuffers; }
54 
useDrawInsteadOfClear()55     bool useDrawInsteadOfClear() const { return fUseDrawInsteadOfClear; }
56 
preferVRAMUseOverFlushes()57     bool preferVRAMUseOverFlushes() const { return fPreferVRAMUseOverFlushes; }
58 
59     /**
60      * Indicates the level of support for gr_instanced::* functionality. A higher level includes
61      * all functionality from the levels below it.
62      */
63     enum class InstancedSupport {
64         kNone,
65         kBasic,
66         kMultisampled,
67         kMixedSampled
68     };
69 
instancedSupport()70     InstancedSupport instancedSupport() const { return fInstancedSupport; }
71 
avoidInstancedDrawsToFPTargets()72     bool avoidInstancedDrawsToFPTargets() const { return fAvoidInstancedDrawsToFPTargets; }
73 
avoidStencilBuffers()74     bool avoidStencilBuffers() const { return fAvoidStencilBuffers; }
75 
76     /**
77      * Indicates the capabilities of the fixed function blend unit.
78      */
79     enum BlendEquationSupport {
80         kBasic_BlendEquationSupport,             //<! Support to select the operator that
81                                                  //   combines src and dst terms.
82         kAdvanced_BlendEquationSupport,          //<! Additional fixed function support for specific
83                                                  //   SVG/PDF blend modes. Requires blend barriers.
84         kAdvancedCoherent_BlendEquationSupport,  //<! Advanced blend equation support that does not
85                                                  //   require blend barriers, and permits overlap.
86 
87         kLast_BlendEquationSupport = kAdvancedCoherent_BlendEquationSupport
88     };
89 
blendEquationSupport()90     BlendEquationSupport blendEquationSupport() const { return fBlendEquationSupport; }
91 
advancedBlendEquationSupport()92     bool advancedBlendEquationSupport() const {
93         return fBlendEquationSupport >= kAdvanced_BlendEquationSupport;
94     }
95 
advancedCoherentBlendEquationSupport()96     bool advancedCoherentBlendEquationSupport() const {
97         return kAdvancedCoherent_BlendEquationSupport == fBlendEquationSupport;
98     }
99 
canUseAdvancedBlendEquation(GrBlendEquation equation)100     bool canUseAdvancedBlendEquation(GrBlendEquation equation) const {
101         SkASSERT(GrBlendEquationIsAdvanced(equation));
102         return SkToBool(fAdvBlendEqBlacklist & (1 << equation));
103     }
104 
105     /**
106      * Indicates whether GPU->CPU memory mapping for GPU resources such as vertex buffers and
107      * textures allows partial mappings or full mappings.
108      */
109     enum MapFlags {
110         kNone_MapFlags   = 0x0,       //<! Cannot map the resource.
111 
112         kCanMap_MapFlag  = 0x1,       //<! The resource can be mapped. Must be set for any of
113                                       //   the other flags to have meaning.k
114         kSubset_MapFlag  = 0x2,       //<! The resource can be partially mapped.
115     };
116 
mapBufferFlags()117     uint32_t mapBufferFlags() const { return fMapBufferFlags; }
118 
119     // Scratch textures not being reused means that those scratch textures
120     // that we upload to (i.e., don't have a render target) will not be
121     // recycled in the texture cache. This is to prevent ghosting by drivers
122     // (in particular for deferred architectures).
reuseScratchTextures()123     bool reuseScratchTextures() const { return fReuseScratchTextures; }
reuseScratchBuffers()124     bool reuseScratchBuffers() const { return fReuseScratchBuffers; }
125 
126     /// maximum number of attribute values per vertex
maxVertexAttributes()127     int maxVertexAttributes() const { return fMaxVertexAttributes; }
128 
maxRenderTargetSize()129     int maxRenderTargetSize() const { return fMaxRenderTargetSize; }
maxTextureSize()130     int maxTextureSize() const { return fMaxTextureSize; }
131     /** This is the maximum tile size to use by GPU devices for rendering sw-backed images/bitmaps.
132         It is usually the max texture size, unless we're overriding it for testing. */
maxTileSize()133     int maxTileSize() const { SkASSERT(fMaxTileSize <= fMaxTextureSize); return fMaxTileSize; }
134 
maxRasterSamples()135     int maxRasterSamples() const { return fMaxRasterSamples; }
136 
137     // Find a sample count greater than or equal to the requested count which is supported for a
138     // color buffer of the given config. If MSAA is not support for the config we will return 0.
139     virtual int getSampleCount(int requestedCount, GrPixelConfig config) const = 0;
140 
maxWindowRectangles()141     int maxWindowRectangles() const { return fMaxWindowRectangles; }
142 
143     virtual bool isConfigTexturable(GrPixelConfig) const = 0;
144     virtual bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const = 0;
145     virtual bool canConfigBeImageStorage(GrPixelConfig config) const = 0;
146 
suppressPrints()147     bool suppressPrints() const { return fSuppressPrints; }
148 
bufferMapThreshold()149     size_t bufferMapThreshold() const {
150         SkASSERT(fBufferMapThreshold >= 0);
151         return fBufferMapThreshold;
152     }
153 
fullClearIsFree()154     bool fullClearIsFree() const { return fFullClearIsFree; }
155 
156     /** True in environments that will issue errors if memory uploaded to buffers
157         is not initialized (even if not read by draw calls). */
mustClearUploadedBufferData()158     bool mustClearUploadedBufferData() const { return fMustClearUploadedBufferData; }
159 
wireframeMode()160     bool wireframeMode() const { return fWireframeMode; }
161 
sampleShadingSupport()162     bool sampleShadingSupport() const { return fSampleShadingSupport; }
163 
fenceSyncSupport()164     bool fenceSyncSupport() const { return fFenceSyncSupport; }
crossContextTextureSupport()165     bool crossContextTextureSupport() const { return fCrossContextTextureSupport; }
166 
167     /**
168      * This is can be called before allocating a texture to be a dst for copySurface. This is only
169      * used for doing dst copies needed in blends, thus the src is always a GrRenderTargetProxy. It
170      * will populate the origin, config, and flags fields of the desc such that copySurface can
171      * efficiently succeed. rectsMustMatch will be set to true if the copy operation must ensure
172      * that the src and dest rects are identical. disallowSubrect will be set to true if copy rect
173      * must equal src's bounds.
174      */
175     virtual bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
176                                     bool* rectsMustMatch, bool* disallowSubrect) const = 0;
177 
178 protected:
179     /** Subclasses must call this at the end of their constructors in order to apply caps
180         overrides requested by the client. Note that overrides will only reduce the caps never
181         expand them. */
182     void applyOptionsOverrides(const GrContextOptions& options);
183 
184     sk_sp<GrShaderCaps> fShaderCaps;
185 
186     bool fNPOTTextureTileSupport                     : 1;
187     bool fMipMapSupport                              : 1;
188     bool fSRGBSupport                                : 1;
189     bool fSRGBWriteControl                           : 1;
190     bool fDiscardRenderTargetSupport                 : 1;
191     bool fReuseScratchTextures                       : 1;
192     bool fReuseScratchBuffers                        : 1;
193     bool fGpuTracingSupport                          : 1;
194     bool fOversizedStencilSupport                    : 1;
195     bool fTextureBarrierSupport                      : 1;
196     bool fSampleLocationsSupport                     : 1;
197     bool fMultisampleDisableSupport                  : 1;
198     bool fInstanceAttribSupport                      : 1;
199     bool fUsesMixedSamples                           : 1;
200     bool fPreferClientSideDynamicBuffers             : 1;
201     bool fFullClearIsFree                            : 1;
202     bool fMustClearUploadedBufferData                : 1;
203 
204     // Driver workaround
205     bool fUseDrawInsteadOfClear                      : 1;
206     bool fAvoidInstancedDrawsToFPTargets             : 1;
207     bool fAvoidStencilBuffers                        : 1;
208 
209     // ANGLE workaround
210     bool fPreferVRAMUseOverFlushes                   : 1;
211 
212     bool fSampleShadingSupport                       : 1;
213     // TODO: this may need to be an enum to support different fence types
214     bool fFenceSyncSupport                           : 1;
215 
216     // Vulkan doesn't support this (yet) and some drivers have issues, too
217     bool fCrossContextTextureSupport                 : 1;
218 
219     InstancedSupport fInstancedSupport;
220 
221     BlendEquationSupport fBlendEquationSupport;
222     uint32_t fAdvBlendEqBlacklist;
223     GR_STATIC_ASSERT(kLast_GrBlendEquation < 32);
224 
225     uint32_t fMapBufferFlags;
226     int fBufferMapThreshold;
227 
228     int fMaxRenderTargetSize;
229     int fMaxVertexAttributes;
230     int fMaxTextureSize;
231     int fMaxTileSize;
232     int fMaxColorSampleCount;
233     int fMaxStencilSampleCount;
234     int fMaxRasterSamples;
235     int fMaxWindowRectangles;
236 
237 private:
onApplyOptionsOverrides(const GrContextOptions &)238     virtual void onApplyOptionsOverrides(const GrContextOptions&) {}
239 
240     bool fSuppressPrints : 1;
241     bool fWireframeMode  : 1;
242 
243     typedef SkRefCnt INHERITED;
244 };
245 
246 #endif
247