Skia
2D Graphics Library
GrTypes.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010 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 #ifndef GrTypes_DEFINED
9 #define GrTypes_DEFINED
10 
11 #include "include/core/SkMath.h"
12 #include "include/core/SkTypes.h"
13 #include "include/gpu/GrConfig.h"
14 
15 class GrBackendSemaphore;
16 class SkImage;
17 class SkSurface;
18 
20 
25 #define GR_MAKE_BITFIELD_OPS(X) \
26  inline X operator |(X a, X b) { \
27  return (X) (+a | +b); \
28  } \
29  inline X& operator |=(X& a, X b) { \
30  return (a = a | b); \
31  } \
32  inline X operator &(X a, X b) { \
33  return (X) (+a & +b); \
34  } \
35  inline X& operator &=(X& a, X b) { \
36  return (a = a & b); \
37  } \
38  template <typename T> \
39  inline X operator &(T a, X b) { \
40  return (X) (+a & +b); \
41  } \
42  template <typename T> \
43  inline X operator &(X a, T b) { \
44  return (X) (+a & +b); \
45  } \
46 
47 #define GR_DECL_BITFIELD_OPS_FRIENDS(X) \
48  friend X operator |(X a, X b); \
49  friend X& operator |=(X& a, X b); \
50  \
51  friend X operator &(X a, X b); \
52  friend X& operator &=(X& a, X b); \
53  \
54  template <typename T> \
55  friend X operator &(T a, X b); \
56  \
57  template <typename T> \
58  friend X operator &(X a, T b); \
59 
60 
64 template<typename TFlags> class GrTFlagsMask {
65 public:
66  constexpr explicit GrTFlagsMask(TFlags value) : GrTFlagsMask(static_cast<int>(value)) {}
67  constexpr explicit GrTFlagsMask(int value) : fValue(value) {}
68  constexpr int value() const { return fValue; }
69 private:
70  const int fValue;
71 };
72 
73 // Or-ing a mask always returns another mask.
74 template<typename TFlags> constexpr GrTFlagsMask<TFlags> operator|(GrTFlagsMask<TFlags> a,
76  return GrTFlagsMask<TFlags>(a.value() | b.value());
77 }
78 template<typename TFlags> constexpr GrTFlagsMask<TFlags> operator|(GrTFlagsMask<TFlags> a,
79  TFlags b) {
80  return GrTFlagsMask<TFlags>(a.value() | static_cast<int>(b));
81 }
82 template<typename TFlags> constexpr GrTFlagsMask<TFlags> operator|(TFlags a,
84  return GrTFlagsMask<TFlags>(static_cast<int>(a) | b.value());
85 }
86 template<typename TFlags> inline GrTFlagsMask<TFlags>& operator|=(GrTFlagsMask<TFlags>& a,
88  return (a = a | b);
89 }
90 
91 // And-ing two masks returns another mask; and-ing one with regular flags returns flags.
92 template<typename TFlags> constexpr GrTFlagsMask<TFlags> operator&(GrTFlagsMask<TFlags> a,
94  return GrTFlagsMask<TFlags>(a.value() & b.value());
95 }
96 template<typename TFlags> constexpr TFlags operator&(GrTFlagsMask<TFlags> a, TFlags b) {
97  return static_cast<TFlags>(a.value() & static_cast<int>(b));
98 }
99 template<typename TFlags> constexpr TFlags operator&(TFlags a, GrTFlagsMask<TFlags> b) {
100  return static_cast<TFlags>(static_cast<int>(a) & b.value());
101 }
102 template<typename TFlags> inline TFlags& operator&=(TFlags& a, GrTFlagsMask<TFlags> b) {
103  return (a = a & b);
104 }
105 
110 #define GR_MAKE_BITFIELD_CLASS_OPS(X) \
111  constexpr GrTFlagsMask<X> operator~(X a) { \
112  return GrTFlagsMask<X>(~static_cast<int>(a)); \
113  } \
114  constexpr X operator|(X a, X b) { \
115  return static_cast<X>(static_cast<int>(a) | static_cast<int>(b)); \
116  } \
117  inline X& operator|=(X& a, X b) { \
118  return (a = a | b); \
119  } \
120  constexpr bool operator&(X a, X b) { \
121  return SkToBool(static_cast<int>(a) & static_cast<int>(b)); \
122  } \
123 
124 #define GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(X) \
125  friend constexpr GrTFlagsMask<X> operator ~(X); \
126  friend constexpr X operator |(X, X); \
127  friend X& operator |=(X&, X); \
128  friend constexpr bool operator &(X, X)
129 
131 
135 enum class GrBackendApi : unsigned {
136  kOpenGL,
137  kVulkan,
138  kMetal,
139  kDirect3D,
140  kDawn,
145  kMock,
146 
152 };
153 
159 
163 
165 
169 enum class GrMipmapped : bool {
170  kNo = false,
171  kYes = true
172 };
175 
176 /*
177  * Can a GrBackendObject be rendered to?
178  */
179 enum class GrRenderable : bool {
180  kNo = false,
181  kYes = true
182 };
183 
184 /*
185  * Used to say whether texture is backed by protected memory.
186  */
187 enum class GrProtected : bool {
188  kNo = false,
189  kYes = true
190 };
191 
193 
198 enum GrSurfaceOrigin : int {
201 };
202 
209  // Also includes samplers bound to texture units.
211  // View state stands for scissor and viewport
222  kALL_GrGLBackendState = 0xffff
223 };
224 
228 static const uint32_t kAll_GrBackendState = 0xffffffff;
229 
230 typedef void* GrGpuFinishedContext;
231 typedef void (*GrGpuFinishedProc)(GrGpuFinishedContext finishedContext);
232 
233 typedef void* GrGpuSubmittedContext;
234 typedef void (*GrGpuSubmittedProc)(GrGpuSubmittedContext submittedContext, bool success);
235 
271 struct GrFlushInfo {
272  int fNumSemaphores = 0;
278 };
279 
284 enum class GrSemaphoresSubmitted : bool {
285  kNo = false,
286  kYes = true
287 };
288 
289 #endif
kPathRendering_GrGLBackendState
@ kPathRendering_GrGLBackendState
Definition: GrTypes.h:221
GrProtected::kYes
@ kYes
GrSemaphoresSubmitted
GrSemaphoresSubmitted
Enum used as return value when flush with semaphores so the client knows whether the valid semaphores...
Definition: GrTypes.h:284
SkImage
Definition: SkImage.h:61
kStencil_GrGLBackendState
@ kStencil_GrGLBackendState
Definition: GrTypes.h:216
SkSurface
Definition: SkSurface.h:46
SkTypes.h
kTopLeft_GrSurfaceOrigin
@ kTopLeft_GrSurfaceOrigin
Definition: GrTypes.h:199
GrFlushInfo::fFinishedProc
GrGpuFinishedProc fFinishedProc
Definition: GrTypes.h:274
GrSurfaceOrigin
GrSurfaceOrigin
GPU SkImage and SkSurfaces can be stored such that (0, 0) in texture space may correspond to either t...
Definition: GrTypes.h:198
GrBackend
GrBackendApi GrBackend
Previously the above enum was not an enum class but a normal enum.
Definition: GrTypes.h:158
GrProtected
GrProtected
Definition: GrTypes.h:187
operator&=
TFlags & operator&=(TFlags &a, GrTFlagsMask< TFlags > b)
Definition: GrTypes.h:102
GrFlushInfo::fSubmittedProc
GrGpuSubmittedProc fSubmittedProc
Definition: GrTypes.h:276
kVulkan_GrBackend
static constexpr GrBackendApi kVulkan_GrBackend
Definition: GrTypes.h:161
GrGLBackendState
GrGLBackendState
A GrContext's cache of backend context state can be partially invalidated.
Definition: GrTypes.h:207
GrRenderable::kNo
@ kNo
kVertex_GrGLBackendState
@ kVertex_GrGLBackendState
Definition: GrTypes.h:215
kFixedFunction_GrGLBackendState
@ kFixedFunction_GrGLBackendState
Definition: GrTypes.h:219
kProgram_GrGLBackendState
@ kProgram_GrGLBackendState
Definition: GrTypes.h:218
GrConfig.h
operator|
constexpr GrTFlagsMask< TFlags > operator|(GrTFlagsMask< TFlags > a, GrTFlagsMask< TFlags > b)
Definition: GrTypes.h:74
GrMipmapped
GrMipmapped
Used to say whether a texture has mip levels allocated or not.
Definition: GrTypes.h:169
GrFlushInfo
Struct to supply options to flush calls.
Definition: GrTypes.h:271
GrBackendApi::kDirect3D
@ kDirect3D
GrFlushInfo::fSubmittedContext
GrGpuSubmittedContext fSubmittedContext
Definition: GrTypes.h:277
kALL_GrGLBackendState
@ kALL_GrGLBackendState
Definition: GrTypes.h:222
kMock_GrBackend
static constexpr GrBackendApi kMock_GrBackend
Definition: GrTypes.h:162
GrMipmapped::kYes
@ kYes
GrTFlagsMask
Wraps a C++11 enum that we use as a bitfield, and enables a limited amount of masking with type safet...
Definition: GrTypes.h:64
kPixelStore_GrGLBackendState
@ kPixelStore_GrGLBackendState
Definition: GrTypes.h:217
GrBackendSemaphore
Wrapper class for passing into and receiving data from Ganesh about a backend semaphore object.
Definition: GrBackendSemaphore.h:23
GrBackendApi::kVulkan
@ kVulkan
GrRenderable
GrRenderable
Definition: GrTypes.h:179
GrGpuSubmittedProc
void(* GrGpuSubmittedProc)(GrGpuSubmittedContext submittedContext, bool success)
Definition: GrTypes.h:234
GrSemaphoresSubmitted::kNo
@ kNo
kRenderTarget_GrGLBackendState
@ kRenderTarget_GrGLBackendState
Definition: GrTypes.h:208
kView_GrGLBackendState
@ kView_GrGLBackendState
Definition: GrTypes.h:212
kTextureBinding_GrGLBackendState
@ kTextureBinding_GrGLBackendState
Definition: GrTypes.h:210
GrFlushInfo::fFinishedContext
GrGpuFinishedContext fFinishedContext
Definition: GrTypes.h:275
GrBackendApi::kOpenGL
@ kOpenGL
kMetal_GrBackend
static constexpr GrBackendApi kMetal_GrBackend
Definition: GrTypes.h:160
GrFlushInfo::fNumSemaphores
int fNumSemaphores
Definition: GrTypes.h:272
kAll_GrBackendState
static const uint32_t kAll_GrBackendState
This value translates to reseting all the context state for any backend.
Definition: GrTypes.h:228
GrBackendApi::kDawn
@ kDawn
GrBackendApi
GrBackendApi
Possible 3D APIs that may be used by Ganesh.
Definition: GrTypes.h:135
GrTFlagsMask::GrTFlagsMask
constexpr GrTFlagsMask(TFlags value)
Definition: GrTypes.h:66
GrTFlagsMask::GrTFlagsMask
constexpr GrTFlagsMask(int value)
Definition: GrTypes.h:67
operator|=
GrTFlagsMask< TFlags > & operator|=(GrTFlagsMask< TFlags > &a, GrTFlagsMask< TFlags > b)
Definition: GrTypes.h:86
GrGpuFinishedContext
void * GrGpuFinishedContext
Definition: GrTypes.h:230
GrSemaphoresSubmitted::kYes
@ kYes
GrFlushInfo::fSignalSemaphores
GrBackendSemaphore * fSignalSemaphores
Definition: GrTypes.h:273
GrGpuSubmittedContext
void * GrGpuSubmittedContext
Definition: GrTypes.h:233
GrProtected::kNo
@ kNo
GrBackendApi::kOpenGL_GrBackend
@ kOpenGL_GrBackend
Added here to support the legacy GrBackend enum value and clients who referenced it using GrBackend::...
kBlend_GrGLBackendState
@ kBlend_GrGLBackendState
Definition: GrTypes.h:213
GrBackendApi::kMetal
@ kMetal
GrGpuFinishedProc
void(* GrGpuFinishedProc)(GrGpuFinishedContext finishedContext)
Definition: GrTypes.h:231
kMSAAEnable_GrGLBackendState
@ kMSAAEnable_GrGLBackendState
Definition: GrTypes.h:214
GrMipmapped::kNo
@ kNo
GrRenderable::kYes
@ kYes
GrTFlagsMask::value
constexpr int value() const
Definition: GrTypes.h:68
kBottomLeft_GrSurfaceOrigin
@ kBottomLeft_GrSurfaceOrigin
Definition: GrTypes.h:200
GrBackendApi::kMock
@ kMock
Mock is a backend that does not draw anything.
kMisc_GrGLBackendState
@ kMisc_GrGLBackendState
Definition: GrTypes.h:220
operator&
constexpr GrTFlagsMask< TFlags > operator&(GrTFlagsMask< TFlags > a, GrTFlagsMask< TFlags > b)
Definition: GrTypes.h:92
SkMath.h