Skia
2DGraphicsLibrary
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GrCaps.h
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 "GrTypes.h"
12 #include "GrTypesPriv.h"
13 #include "GrBlend.h"
14 #include "GrShaderCaps.h"
15 #include "SkRefCnt.h"
16 #include "SkString.h"
17 
18 struct GrContextOptions;
19 class GrRenderTargetProxy;
20 
24 class GrCaps : public SkRefCnt {
25 public:
26  GrCaps(const GrContextOptions&);
27 
28  virtual SkString dump() const;
29  const GrShaderCaps* shaderCaps() const { return fShaderCaps.get(); }
30 
31  bool npotTextureTileSupport() const { return fNPOTTextureTileSupport; }
34  bool mipMapSupport() const { return fMipMapSupport; }
35 
41  bool srgbSupport() const { return fSRGBSupport; }
45  bool srgbWriteControl() const { return fSRGBWriteControl; }
46  bool discardRenderTargetSupport() const { return fDiscardRenderTargetSupport; }
47  bool gpuTracingSupport() const { return fGpuTracingSupport; }
48  bool oversizedStencilSupport() const { return fOversizedStencilSupport; }
49  bool textureBarrierSupport() const { return fTextureBarrierSupport; }
50  bool sampleLocationsSupport() const { return fSampleLocationsSupport; }
51  bool multisampleDisableSupport() const { return fMultisampleDisableSupport; }
52  bool instanceAttribSupport() const { return fInstanceAttribSupport; }
53  bool usesMixedSamples() const { return fUsesMixedSamples; }
54  bool preferClientSideDynamicBuffers() const { return fPreferClientSideDynamicBuffers; }
55 
56  bool useDrawInsteadOfClear() const { return fUseDrawInsteadOfClear; }
57 
58  bool preferVRAMUseOverFlushes() const { return fPreferVRAMUseOverFlushes; }
59 
64  enum class InstancedSupport {
65  kNone,
66  kBasic,
67  kMultisampled,
68  kMixedSampled
69  };
70 
71  InstancedSupport instancedSupport() const { return fInstancedSupport; }
72 
73  bool avoidInstancedDrawsToFPTargets() const { return fAvoidInstancedDrawsToFPTargets; }
74 
75  bool avoidStencilBuffers() const { return fAvoidStencilBuffers; }
76 
81  kBasic_BlendEquationSupport, //<! Support to select the operator that
82  // combines src and dst terms.
83  kAdvanced_BlendEquationSupport, //<! Additional fixed function support for specific
84  // SVG/PDF blend modes. Requires blend barriers.
85  kAdvancedCoherent_BlendEquationSupport, //<! Advanced blend equation support that does not
86  // require blend barriers, and permits overlap.
87 
88  kLast_BlendEquationSupport = kAdvancedCoherent_BlendEquationSupport
89  };
90 
91  BlendEquationSupport blendEquationSupport() const { return fBlendEquationSupport; }
92 
93  bool advancedBlendEquationSupport() const {
94  return fBlendEquationSupport >= kAdvanced_BlendEquationSupport;
95  }
96 
97  bool advancedCoherentBlendEquationSupport() const {
98  return kAdvancedCoherent_BlendEquationSupport == fBlendEquationSupport;
99  }
100 
101  bool canUseAdvancedBlendEquation(GrBlendEquation equation) const {
102  SkASSERT(GrBlendEquationIsAdvanced(equation));
103  return SkToBool(fAdvBlendEqBlacklist & (1 << equation));
104  }
105 
110  enum MapFlags {
111  kNone_MapFlags = 0x0, //<! Cannot map the resource.
112 
113  kCanMap_MapFlag = 0x1, //<! The resource can be mapped. Must be set for any of
114  // the other flags to have meaning.k
115  kSubset_MapFlag = 0x2, //<! The resource can be partially mapped.
116  };
117 
118  uint32_t mapBufferFlags() const { return fMapBufferFlags; }
119 
120  // Scratch textures not being reused means that those scratch textures
121  // that we upload to (i.e., don't have a render target) will not be
122  // recycled in the texture cache. This is to prevent ghosting by drivers
123  // (in particular for deferred architectures).
124  bool reuseScratchTextures() const { return fReuseScratchTextures; }
125  bool reuseScratchBuffers() const { return fReuseScratchBuffers; }
126 
128  int maxVertexAttributes() const { return fMaxVertexAttributes; }
129 
130  int maxRenderTargetSize() const { return fMaxRenderTargetSize; }
131  int maxTextureSize() const { return fMaxTextureSize; }
134  int maxTileSize() const { SkASSERT(fMaxTileSize <= fMaxTextureSize); return fMaxTileSize; }
135 
136  // Will be 0 if MSAA is not supported
137  int maxColorSampleCount() const { return fMaxColorSampleCount; }
138  // Will be 0 if MSAA is not supported
139  int maxStencilSampleCount() const { return fMaxStencilSampleCount; }
140  // Will be 0 if raster multisample is not supported. Raster multisample is a special HW mode
141  // where the rasterizer runs with more samples than are in the target framebuffer.
142  int maxRasterSamples() const { return fMaxRasterSamples; }
143  // We require the sample count to be less than maxColorSampleCount and maxStencilSampleCount.
144  // If we are using mixed samples, we only care about stencil.
145  int maxSampleCount() const {
146  if (this->usesMixedSamples()) {
147  return this->maxStencilSampleCount();
148  } else {
149  return SkTMin(this->maxColorSampleCount(), this->maxStencilSampleCount());
150  }
151  }
152 
153  int maxWindowRectangles() const { return fMaxWindowRectangles; }
154 
155  virtual bool isConfigTexturable(GrPixelConfig) const = 0;
156  virtual bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const = 0;
157  virtual bool canConfigBeImageStorage(GrPixelConfig config) const = 0;
158 
159  bool suppressPrints() const { return fSuppressPrints; }
160 
161  size_t bufferMapThreshold() const {
162  SkASSERT(fBufferMapThreshold >= 0);
163  return fBufferMapThreshold;
164  }
165 
166  bool fullClearIsFree() const { return fFullClearIsFree; }
167 
170  bool mustClearUploadedBufferData() const { return fMustClearUploadedBufferData; }
171 
172  bool wireframeMode() const { return fWireframeMode; }
173 
174  bool sampleShadingSupport() const { return fSampleShadingSupport; }
175 
176  bool fenceSyncSupport() const { return fFenceSyncSupport; }
177  bool crossContextTextureSupport() const { return fCrossContextTextureSupport; }
178 
187  virtual bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
188  bool* rectsMustMatch, bool* disallowSubrect) const = 0;
189 
190 protected:
194  void applyOptionsOverrides(const GrContextOptions& options);
195 
196  sk_sp<GrShaderCaps> fShaderCaps;
197 
198  bool fNPOTTextureTileSupport : 1;
199  bool fMipMapSupport : 1;
200  bool fSRGBSupport : 1;
201  bool fSRGBWriteControl : 1;
202  bool fDiscardRenderTargetSupport : 1;
203  bool fReuseScratchTextures : 1;
204  bool fReuseScratchBuffers : 1;
205  bool fGpuTracingSupport : 1;
206  bool fOversizedStencilSupport : 1;
207  bool fTextureBarrierSupport : 1;
208  bool fSampleLocationsSupport : 1;
209  bool fMultisampleDisableSupport : 1;
210  bool fInstanceAttribSupport : 1;
211  bool fUsesMixedSamples : 1;
212  bool fPreferClientSideDynamicBuffers : 1;
213  bool fFullClearIsFree : 1;
214  bool fMustClearUploadedBufferData : 1;
215 
216  // Driver workaround
217  bool fUseDrawInsteadOfClear : 1;
218  bool fAvoidInstancedDrawsToFPTargets : 1;
219  bool fAvoidStencilBuffers : 1;
220 
221  // ANGLE workaround
222  bool fPreferVRAMUseOverFlushes : 1;
223 
224  bool fSampleShadingSupport : 1;
225  // TODO: this may need to be an enum to support different fence types
226  bool fFenceSyncSupport : 1;
227 
228  // Vulkan doesn't support this (yet) and some drivers have issues, too
229  bool fCrossContextTextureSupport : 1;
230 
231  InstancedSupport fInstancedSupport;
232 
233  BlendEquationSupport fBlendEquationSupport;
234  uint32_t fAdvBlendEqBlacklist;
235  GR_STATIC_ASSERT(kLast_GrBlendEquation < 32);
236 
237  uint32_t fMapBufferFlags;
238  int fBufferMapThreshold;
239 
240  int fMaxRenderTargetSize;
241  int fMaxVertexAttributes;
242  int fMaxTextureSize;
243  int fMaxTileSize;
244  int fMaxColorSampleCount;
245  int fMaxStencilSampleCount;
246  int fMaxRasterSamples;
247  int fMaxWindowRectangles;
248 
249 private:
250  virtual void onApplyOptionsOverrides(const GrContextOptions&) {}
251 
252  bool fSuppressPrints : 1;
253  bool fWireframeMode : 1;
254 
255  typedef SkRefCnt INHERITED;
256 };
257 
258 #endif
Definition: GrContextOptions.h:14
Represents the capabilities of a GrContext.
Definition: GrCaps.h:24
bool srgbWriteControl() const
Is there support for enabling/disabling sRGB writes for sRGB-capable color buffers?
Definition: GrCaps.h:45
Describes a surface to be created.
Definition: GrTypes.h:589
MapFlags
Indicates whether GPU->CPU memory mapping for GPU resources such as vertex buffers and textures allow...
Definition: GrCaps.h:110
InstancedSupport
Indicates the level of support for gr_instanced::* functionality.
Definition: GrCaps.h:64
Definition: SkRefCnt.h:125
#define SkToBool(cond)
Returns 0 or 1 based on the condition.
Definition: SkTypes.h:227
int maxVertexAttributes() const
maximum number of attribute values per vertex
Definition: GrCaps.h:128
bool mipMapSupport() const
To avoid as-yet-unnecessary complexity we don't allow any partial support of MIP Maps (e...
Definition: GrCaps.h:34
BlendEquationSupport
Indicates the capabilities of the fixed function blend unit.
Definition: GrCaps.h:80
void applyOptionsOverrides(const GrContextOptions &options)
Subclasses must call this at the end of their constructors in order to apply caps overrides requested...
Definition: GrShaderCaps.h:20
bool srgbSupport() const
Skia convention is that a device only has sRGB support if it supports sRGB formats for both textures ...
Definition: GrCaps.h:41
bool mustClearUploadedBufferData() const
True in environments that will issue errors if memory uploaded to buffers is not initialized (even if...
Definition: GrCaps.h:170
virtual bool initDescForDstCopy(const GrRenderTargetProxy *src, GrSurfaceDesc *desc, bool *rectsMustMatch, bool *disallowSubrect) const =0
This is can be called before allocating a texture to be a dst for copySurface.
Light weight class for managing strings.
Definition: SkString.h:121
int maxTileSize() const
This is the maximum tile size to use by GPU devices for rendering sw-backed images/bitmaps.
Definition: GrCaps.h:134