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/SkTypes.h"
12 #include "include/private/base/SkTo.h" // IWYU pragma: keep
13 
14 #include <cstddef>
15 #include <cstdint>
16 class GrBackendSemaphore;
17 
18 namespace skgpu {
19 enum class Mipmapped : bool;
20 enum class Protected : bool;
21 enum class Renderable : bool;
22 }
23 
25 
30 template<typename TFlags> class GrTFlagsMask {
31 public:
32  constexpr explicit GrTFlagsMask(TFlags value) : GrTFlagsMask(static_cast<int>(value)) {}
33  constexpr explicit GrTFlagsMask(int value) : fValue(value) {}
34  constexpr int value() const { return fValue; }
35 private:
36  const int fValue;
37 };
38 
43 #define GR_MAKE_BITFIELD_CLASS_OPS(X) \
44  [[maybe_unused]] constexpr GrTFlagsMask<X> operator~(X a) { \
45  return GrTFlagsMask<X>(~static_cast<int>(a)); \
46  } \
47  [[maybe_unused]] constexpr X operator|(X a, X b) { \
48  return static_cast<X>(static_cast<int>(a) | static_cast<int>(b)); \
49  } \
50  [[maybe_unused]] inline X& operator|=(X& a, X b) { \
51  return (a = a | b); \
52  } \
53  [[maybe_unused]] constexpr bool operator&(X a, X b) { \
54  return SkToBool(static_cast<int>(a) & static_cast<int>(b)); \
55  } \
56  [[maybe_unused]] constexpr GrTFlagsMask<X> operator|(GrTFlagsMask<X> a, GrTFlagsMask<X> b) { \
57  return GrTFlagsMask<X>(a.value() | b.value()); \
58  } \
59  [[maybe_unused]] constexpr GrTFlagsMask<X> operator|(GrTFlagsMask<X> a, X b) { \
60  return GrTFlagsMask<X>(a.value() | static_cast<int>(b)); \
61  } \
62  [[maybe_unused]] constexpr GrTFlagsMask<X> operator|(X a, GrTFlagsMask<X> b) { \
63  return GrTFlagsMask<X>(static_cast<int>(a) | b.value()); \
64  } \
65  [[maybe_unused]] constexpr X operator&(GrTFlagsMask<X> a, GrTFlagsMask<X> b) { \
66  return static_cast<X>(a.value() & b.value()); \
67  } \
68  [[maybe_unused]] constexpr X operator&(GrTFlagsMask<X> a, X b) { \
69  return static_cast<X>(a.value() & static_cast<int>(b)); \
70  } \
71  [[maybe_unused]] constexpr X operator&(X a, GrTFlagsMask<X> b) { \
72  return static_cast<X>(static_cast<int>(a) & b.value()); \
73  } \
74  [[maybe_unused]] inline X& operator&=(X& a, GrTFlagsMask<X> b) { \
75  return (a = a & b); \
76  } \
77 
78 #define GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(X) \
79  friend constexpr GrTFlagsMask<X> operator ~(X); \
80  friend constexpr X operator |(X, X); \
81  friend X& operator |=(X&, X); \
82  friend constexpr bool operator &(X, X); \
83  friend constexpr GrTFlagsMask<X> operator|(GrTFlagsMask<X>, GrTFlagsMask<X>); \
84  friend constexpr GrTFlagsMask<X> operator|(GrTFlagsMask<X>, X); \
85  friend constexpr GrTFlagsMask<X> operator|(X, GrTFlagsMask<X>); \
86  friend constexpr X operator&(GrTFlagsMask<X>, GrTFlagsMask<X>); \
87  friend constexpr X operator&(GrTFlagsMask<X>, X); \
88  friend constexpr X operator&(X, GrTFlagsMask<X>); \
89  friend X& operator &=(X&, GrTFlagsMask<X>)
90 
92 
96 enum class GrBackendApi : unsigned {
97  kOpenGL,
98  kVulkan,
99  kMetal,
100  kDirect3D,
101 
106  kMock,
107 
111  kUnsupported,
112 
118 };
119 
125 
129 
131 
139 
140 /*
141  * Can a GrBackendObject be rendered to?
142  */
144 
145 /*
146  * Used to say whether texture is backed by protected memory.
147  */
149 
151 
156 enum GrSurfaceOrigin : int {
159 };
160 
167  // Also includes samplers bound to texture units.
169  // View state stands for scissor and viewport
179  kALL_GrGLBackendState = 0xffff
180 };
181 
185 static const uint32_t kAll_GrBackendState = 0xffffffff;
186 
187 typedef void* GrGpuFinishedContext;
188 typedef void (*GrGpuFinishedProc)(GrGpuFinishedContext finishedContext);
189 
190 typedef void* GrGpuSubmittedContext;
191 typedef void (*GrGpuSubmittedProc)(GrGpuSubmittedContext submittedContext, bool success);
192 
195 
225 struct GrFlushInfo {
226  size_t fNumSemaphores = 0;
227  GrBackendSemaphore* fSignalSemaphores = nullptr;
228  GrGpuFinishedProc fFinishedProc = nullptr;
229  GrGpuFinishedContext fFinishedContext = nullptr;
230  GrGpuSubmittedProc fSubmittedProc = nullptr;
231  GrGpuSubmittedContext fSubmittedContext = nullptr;
232 };
233 
238 enum class GrSemaphoresSubmitted : bool {
239  kNo = false,
240  kYes = true
241 };
242 
246 };
247 
248 enum class GrSyncCpu : bool {
249  kNo = false,
250  kYes = true,
251 };
252 
253 #endif
GrPurgeResourceOptions
Definition: GrTypes.h:243
GrSurfaceOrigin
GPU SkImage and SkSurfaces can be stored such that (0, 0) in texture space may correspond to either t...
Definition: GrTypes.h:156
@ kBottomLeft_GrSurfaceOrigin
Definition: GrTypes.h:158
@ kTopLeft_GrSurfaceOrigin
Definition: GrTypes.h:157
static const uint32_t kAll_GrBackendState
This value translates to reseting all the context state for any backend.
Definition: GrTypes.h:185
static constexpr GrBackendApi kVulkan_GrBackend
Definition: GrTypes.h:127
GrBackendApi
Possible 3D APIs that may be used by Ganesh.
Definition: GrTypes.h:96
@ kMock
Mock is a backend that does not draw anything.
@ kOpenGL_GrBackend
Added here to support the legacy GrBackend enum value and clients who referenced it using GrBackend::...
static constexpr GrBackendApi kMock_GrBackend
Definition: GrTypes.h:128
void * GrDirectContextDestroyedContext
Definition: GrTypes.h:193
GrSemaphoresSubmitted
Enum used as return value when flush with semaphores so the client knows whether the valid semaphores...
Definition: GrTypes.h:238
void * GrGpuSubmittedContext
Definition: GrTypes.h:190
void * GrGpuFinishedContext
Definition: GrTypes.h:187
void(* GrGpuSubmittedProc)(GrGpuSubmittedContext submittedContext, bool success)
Definition: GrTypes.h:191
void(* GrDirectContextDestroyedProc)(GrDirectContextDestroyedContext destroyedContext)
Definition: GrTypes.h:194
void(* GrGpuFinishedProc)(GrGpuFinishedContext finishedContext)
Definition: GrTypes.h:188
GrSyncCpu
Definition: GrTypes.h:248
GrGLBackendState
A GrContext's cache of backend context state can be partially invalidated.
Definition: GrTypes.h:165
@ kProgram_GrGLBackendState
Definition: GrTypes.h:176
@ kView_GrGLBackendState
Definition: GrTypes.h:170
@ kTextureBinding_GrGLBackendState
Definition: GrTypes.h:168
@ kVertex_GrGLBackendState
Definition: GrTypes.h:173
@ kBlend_GrGLBackendState
Definition: GrTypes.h:171
@ kMisc_GrGLBackendState
Definition: GrTypes.h:178
@ kMSAAEnable_GrGLBackendState
Definition: GrTypes.h:172
@ kALL_GrGLBackendState
Definition: GrTypes.h:179
@ kFixedFunction_GrGLBackendState
Definition: GrTypes.h:177
@ kPixelStore_GrGLBackendState
Definition: GrTypes.h:175
@ kStencil_GrGLBackendState
Definition: GrTypes.h:174
@ kRenderTarget_GrGLBackendState
Definition: GrTypes.h:166
GrBackendApi GrBackend
Previously the above enum was not an enum class but a normal enum.
Definition: GrTypes.h:124
static constexpr GrBackendApi kMetal_GrBackend
Definition: GrTypes.h:126
@ kYes
Do pre-clip the geometry before applying the (perspective) matrix.
@ kNo
Don't pre-clip the geometry before applying the (perspective) matrix.
Wrapper class for passing into and receiving data from Ganesh about a backend semaphore object.
Definition: GrBackendSemaphore.h:34
Wraps a C++11 enum that we use as a bitfield, and enables a limited amount of masking with type safet...
Definition: GrTypes.h:30
constexpr GrTFlagsMask(TFlags value)
Definition: GrTypes.h:32
constexpr GrTFlagsMask(int value)
Definition: GrTypes.h:33
constexpr int value() const
Definition: GrTypes.h:34
This file includes numerous public types that are used by all of our gpu backends.
Definition: SkCanvas.h:73
Renderable
Is a texture renderable or not.
Definition: GpuTypes.h:69
Mipmapped
Is the texture mipmapped or not.
Definition: GpuTypes.h:53
Protected
Is the data protected on the GPU or not.
Definition: GpuTypes.h:61
Struct to supply options to flush calls.
Definition: GrTypes.h:225