Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
12#include "include/private/base/SkTo.h" // IWYU pragma: keep
13
14#include <cstddef>
15#include <cstdint>
17
18namespace skgpu {
19enum class Protected : bool;
20enum class Renderable : bool;
21}
22
23////////////////////////////////////////////////////////////////////////////////
24
25/**
26 * Wraps a C++11 enum that we use as a bitfield, and enables a limited amount of
27 * masking with type safety. Instantiated with the ~ operator.
28 */
29template<typename TFlags> class GrTFlagsMask {
30public:
31 constexpr explicit GrTFlagsMask(TFlags value) : GrTFlagsMask(static_cast<int>(value)) {}
32 constexpr explicit GrTFlagsMask(int value) : fValue(value) {}
33 constexpr int value() const { return fValue; }
34private:
35 const int fValue;
36};
37
38/**
39 * Defines bitwise operators that make it possible to use an enum class as a
40 * basic bitfield.
41 */
42#define GR_MAKE_BITFIELD_CLASS_OPS(X) \
43 [[maybe_unused]] constexpr GrTFlagsMask<X> operator~(X a) { \
44 return GrTFlagsMask<X>(~static_cast<int>(a)); \
45 } \
46 [[maybe_unused]] constexpr X operator|(X a, X b) { \
47 return static_cast<X>(static_cast<int>(a) | static_cast<int>(b)); \
48 } \
49 [[maybe_unused]] inline X& operator|=(X& a, X b) { \
50 return (a = a | b); \
51 } \
52 [[maybe_unused]] constexpr bool operator&(X a, X b) { \
53 return SkToBool(static_cast<int>(a) & static_cast<int>(b)); \
54 } \
55 [[maybe_unused]] constexpr GrTFlagsMask<X> operator|(GrTFlagsMask<X> a, GrTFlagsMask<X> b) { \
56 return GrTFlagsMask<X>(a.value() | b.value()); \
57 } \
58 [[maybe_unused]] constexpr GrTFlagsMask<X> operator|(GrTFlagsMask<X> a, X b) { \
59 return GrTFlagsMask<X>(a.value() | static_cast<int>(b)); \
60 } \
61 [[maybe_unused]] constexpr GrTFlagsMask<X> operator|(X a, GrTFlagsMask<X> b) { \
62 return GrTFlagsMask<X>(static_cast<int>(a) | b.value()); \
63 } \
64 [[maybe_unused]] constexpr X operator&(GrTFlagsMask<X> a, GrTFlagsMask<X> b) { \
65 return static_cast<X>(a.value() & b.value()); \
66 } \
67 [[maybe_unused]] constexpr X operator&(GrTFlagsMask<X> a, X b) { \
68 return static_cast<X>(a.value() & static_cast<int>(b)); \
69 } \
70 [[maybe_unused]] constexpr X operator&(X a, GrTFlagsMask<X> b) { \
71 return static_cast<X>(static_cast<int>(a) & b.value()); \
72 } \
73 [[maybe_unused]] inline X& operator&=(X& a, GrTFlagsMask<X> b) { \
74 return (a = a & b); \
75 } \
76
77#define GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(X) \
78 friend constexpr GrTFlagsMask<X> operator ~(X); \
79 friend constexpr X operator |(X, X); \
80 friend X& operator |=(X&, X); \
81 friend constexpr bool operator &(X, X); \
82 friend constexpr GrTFlagsMask<X> operator|(GrTFlagsMask<X>, GrTFlagsMask<X>); \
83 friend constexpr GrTFlagsMask<X> operator|(GrTFlagsMask<X>, X); \
84 friend constexpr GrTFlagsMask<X> operator|(X, GrTFlagsMask<X>); \
85 friend constexpr X operator&(GrTFlagsMask<X>, GrTFlagsMask<X>); \
86 friend constexpr X operator&(GrTFlagsMask<X>, X); \
87 friend constexpr X operator&(X, GrTFlagsMask<X>); \
88 friend X& operator &=(X&, GrTFlagsMask<X>)
89
90///////////////////////////////////////////////////////////////////////////////
91
92/**
93 * Possible 3D APIs that may be used by Ganesh.
94 */
95enum class GrBackendApi : unsigned {
96 kOpenGL,
97 kVulkan,
98 kMetal,
100
101 /**
102 * Mock is a backend that does not draw anything. It is used for unit tests
103 * and to measure CPU overhead.
104 */
105 kMock,
106
107 /**
108 * Ganesh doesn't support some context types (e.g. Dawn) and will return Unsupported.
109 */
111
112 /**
113 * Added here to support the legacy GrBackend enum value and clients who referenced it using
114 * GrBackend::kOpenGL_GrBackend.
115 */
117};
118
119/**
120 * Previously the above enum was not an enum class but a normal enum. To support the legacy use of
121 * the enum values we define them below so that no clients break.
122 */
124
128
129///////////////////////////////////////////////////////////////////////////////
130
131/*
132 * Can a GrBackendObject be rendered to?
133 */
135
136/*
137 * Used to say whether texture is backed by protected memory.
138 */
140
141///////////////////////////////////////////////////////////////////////////////
142
143/**
144 * GPU SkImage and SkSurfaces can be stored such that (0, 0) in texture space may correspond to
145 * either the top-left or bottom-left content pixel.
146 */
151
152/**
153 * A GrContext's cache of backend context state can be partially invalidated.
154 * These enums are specific to the GL backend and we'd add a new set for an alternative backend.
155 */
172
173/**
174 * This value translates to reseting all the context state for any backend.
175 */
176static const uint32_t kAll_GrBackendState = 0xffffffff;
177
179typedef void (*GrGpuFinishedProc)(GrGpuFinishedContext finishedContext);
180
182typedef void (*GrGpuSubmittedProc)(GrGpuSubmittedContext submittedContext, bool success);
183
186
187/**
188 * Struct to supply options to flush calls.
189 *
190 * After issuing all commands, fNumSemaphore semaphores will be signaled by the gpu. The client
191 * passes in an array of fNumSemaphores GrBackendSemaphores. In general these GrBackendSemaphore's
192 * can be either initialized or not. If they are initialized, the backend uses the passed in
193 * semaphore. If it is not initialized, a new semaphore is created and the GrBackendSemaphore
194 * object is initialized with that semaphore. The semaphores are not sent to the GPU until the next
195 * GrContext::submit call is made. See the GrContext::submit for more information.
196 *
197 * The client will own and be responsible for deleting the underlying semaphores that are stored
198 * and returned in initialized GrBackendSemaphore objects. The GrBackendSemaphore objects
199 * themselves can be deleted as soon as this function returns.
200 *
201 * If a finishedProc is provided, the finishedProc will be called when all work submitted to the gpu
202 * from this flush call and all previous flush calls has finished on the GPU. If the flush call
203 * fails due to an error and nothing ends up getting sent to the GPU, the finished proc is called
204 * immediately.
205 *
206 * If a submittedProc is provided, the submittedProc will be called when all work from this flush
207 * call is submitted to the GPU. If the flush call fails due to an error and nothing will get sent
208 * to the GPU, the submitted proc is called immediately. It is possibly that when work is finally
209 * submitted, that the submission actual fails. In this case we will not reattempt to do the
210 * submission. Skia notifies the client of these via the success bool passed into the submittedProc.
211 * The submittedProc is useful to the client to know when semaphores that were sent with the flush
212 * have actually been submitted to the GPU so that they can be waited on (or deleted if the submit
213 * fails).
214 * GrBackendSemaphores are not supported for the GL backend and will be ignored if set.
215 */
224
225/**
226 * Enum used as return value when flush with semaphores so the client knows whether the valid
227 * semaphores will be submitted on the next GrContext::submit call.
228 */
229enum class GrSemaphoresSubmitted : bool {
230 kNo = false,
231 kYes = true
232};
233
238
239enum class GrSyncCpu : bool {
240 kNo = false,
241 kYes = true,
242};
243
244#endif
GrPurgeResourceOptions
Definition GrTypes.h:234
GrSurfaceOrigin
Definition GrTypes.h:147
@ kBottomLeft_GrSurfaceOrigin
Definition GrTypes.h:149
@ kTopLeft_GrSurfaceOrigin
Definition GrTypes.h:148
static const uint32_t kAll_GrBackendState
Definition GrTypes.h:176
static constexpr GrBackendApi kVulkan_GrBackend
Definition GrTypes.h:126
GrBackendApi
Definition GrTypes.h:95
static constexpr GrBackendApi kMock_GrBackend
Definition GrTypes.h:127
void * GrDirectContextDestroyedContext
Definition GrTypes.h:184
GrSemaphoresSubmitted
Definition GrTypes.h:229
void * GrGpuSubmittedContext
Definition GrTypes.h:181
void * GrGpuFinishedContext
Definition GrTypes.h:178
void(* GrGpuSubmittedProc)(GrGpuSubmittedContext submittedContext, bool success)
Definition GrTypes.h:182
void(* GrDirectContextDestroyedProc)(GrDirectContextDestroyedContext destroyedContext)
Definition GrTypes.h:185
void(* GrGpuFinishedProc)(GrGpuFinishedContext finishedContext)
Definition GrTypes.h:179
GrSyncCpu
Definition GrTypes.h:239
GrGLBackendState
Definition GrTypes.h:156
@ kProgram_GrGLBackendState
Definition GrTypes.h:167
@ kView_GrGLBackendState
Definition GrTypes.h:161
@ kTextureBinding_GrGLBackendState
Definition GrTypes.h:159
@ kVertex_GrGLBackendState
Definition GrTypes.h:164
@ kBlend_GrGLBackendState
Definition GrTypes.h:162
@ kMisc_GrGLBackendState
Definition GrTypes.h:169
@ kMSAAEnable_GrGLBackendState
Definition GrTypes.h:163
@ kALL_GrGLBackendState
Definition GrTypes.h:170
@ kFixedFunction_GrGLBackendState
Definition GrTypes.h:168
@ kPixelStore_GrGLBackendState
Definition GrTypes.h:166
@ kStencil_GrGLBackendState
Definition GrTypes.h:165
@ kRenderTarget_GrGLBackendState
Definition GrTypes.h:157
GrBackendApi GrBackend
Definition GrTypes.h:123
static constexpr GrBackendApi kMetal_GrBackend
Definition GrTypes.h:125
Type::kYUV Type::kRGBA() int(0.7 *637)
constexpr GrTFlagsMask(TFlags value)
Definition GrTypes.h:31
constexpr GrTFlagsMask(int value)
Definition GrTypes.h:32
constexpr int value() const
Definition GrTypes.h:33
Renderable
Definition GpuTypes.h:69
Protected
Definition GpuTypes.h:61
GrGpuFinishedContext fFinishedContext
Definition GrTypes.h:220
GrBackendSemaphore * fSignalSemaphores
Definition GrTypes.h:218
GrGpuFinishedProc fFinishedProc
Definition GrTypes.h:219
GrGpuSubmittedContext fSubmittedContext
Definition GrTypes.h:222
GrGpuSubmittedProc fSubmittedProc
Definition GrTypes.h:221
size_t fNumSemaphores
Definition GrTypes.h:217