blob: 834c185944ac6368e07c0e86881f84a9958d8888 [file] [log] [blame]
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +00001/*
2 * Copyright 2013 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 GrTypesPriv_DEFINED
9#define GrTypesPriv_DEFINED
10
jvanverth@google.com054ae992013-04-01 20:06:51 +000011#include "GrTypes.h"
bsalomon3e791242014-12-17 13:43:13 -080012#include "SkRect.h"
bsalomon@google.com31ec7982013-03-27 18:14:57 +000013
bsalomoncdee0092016-01-08 13:20:12 -080014 /**
15 * Types of shader-language-specific boxed variables we can create. (Currently only GrGLShaderVars,
16 * but should be applicable to other shader languages.)
17 */
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +000018enum GrSLType {
19 kVoid_GrSLType,
20 kFloat_GrSLType,
21 kVec2f_GrSLType,
22 kVec3f_GrSLType,
23 kVec4f_GrSLType,
24 kMat33f_GrSLType,
25 kMat44f_GrSLType,
jvanverth@google.com054ae992013-04-01 20:06:51 +000026 kSampler2D_GrSLType,
bsalomon7ea33f52015-11-22 14:51:00 -080027 kSamplerExternal_GrSLType,
bsalomone5286e02016-01-14 09:24:09 -080028 kSampler2DRect_GrSLType,
ethannicholas22793252016-01-30 09:59:10 -080029 kBool_GrSLType,
30 kInt_GrSLType,
cdalton793dc262016-02-08 10:11:47 -080031 kUint_GrSLType,
jvanverth@google.com054ae992013-04-01 20:06:51 +000032
cdalton793dc262016-02-08 10:11:47 -080033 kLast_GrSLType = kUint_GrSLType
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +000034};
jvanverth@google.com054ae992013-04-01 20:06:51 +000035static const int kGrSLTypeCount = kLast_GrSLType + 1;
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +000036
bsalomon17168df2014-12-09 09:00:49 -080037enum GrShaderType {
38 kVertex_GrShaderType,
39 kGeometry_GrShaderType,
40 kFragment_GrShaderType,
41
42 kLastkFragment_GrShaderType = kFragment_GrShaderType
43};
44static const int kGrShaderTypeCount = kLastkFragment_GrShaderType + 1;
45
cdalton5e58cee2016-02-11 12:49:47 -080046enum GrShaderFlags {
47 kNone_GrShaderFlags = 0,
48 kVertex_GrShaderFlag = 1 << kVertex_GrShaderType,
49 kGeometry_GrShaderFlag = 1 << kGeometry_GrShaderType,
50 kFragment_GrShaderFlag = 1 << kFragment_GrShaderType
51};
52GR_MAKE_BITFIELD_OPS(GrShaderFlags);
53
bsalomon@google.com31ec7982013-03-27 18:14:57 +000054/**
bsalomonc0bd6482014-12-09 10:04:14 -080055 * Precisions of shader language variables. Not all shading languages support precisions or actually
bsalomon422f56f2014-12-09 10:18:12 -080056 * vary the internal precision based on the qualifiers. These currently only apply to float types (
57 * including float vectors and matrices).
bsalomonc0bd6482014-12-09 10:04:14 -080058 */
59enum GrSLPrecision {
60 kLow_GrSLPrecision,
61 kMedium_GrSLPrecision,
62 kHigh_GrSLPrecision,
63
64 // Default precision is medium. This is because on OpenGL ES 2 highp support is not
65 // guaranteed. On (non-ES) OpenGL the specifiers have no effect on precision.
66 kDefault_GrSLPrecision = kMedium_GrSLPrecision,
67
68 kLast_GrSLPrecision = kHigh_GrSLPrecision
69};
70
71static const int kGrSLPrecisionCount = kLast_GrSLPrecision + 1;
72
73/**
jvanverth@google.com054ae992013-04-01 20:06:51 +000074 * Gets the vector size of the SLType. Returns -1 for void, matrices, and samplers.
75 */
76static inline int GrSLTypeVectorCount(GrSLType type) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000077 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
cdalton793dc262016-02-08 10:11:47 -080078 static const int kCounts[] = { -1, 1, 2, 3, 4, -1, -1, -1, -1, -1, 1, 1, 1 };
jvanverth@google.com054ae992013-04-01 20:06:51 +000079 return kCounts[type];
80
81 GR_STATIC_ASSERT(0 == kVoid_GrSLType);
82 GR_STATIC_ASSERT(1 == kFloat_GrSLType);
83 GR_STATIC_ASSERT(2 == kVec2f_GrSLType);
84 GR_STATIC_ASSERT(3 == kVec3f_GrSLType);
85 GR_STATIC_ASSERT(4 == kVec4f_GrSLType);
86 GR_STATIC_ASSERT(5 == kMat33f_GrSLType);
87 GR_STATIC_ASSERT(6 == kMat44f_GrSLType);
88 GR_STATIC_ASSERT(7 == kSampler2D_GrSLType);
bsalomon7ea33f52015-11-22 14:51:00 -080089 GR_STATIC_ASSERT(8 == kSamplerExternal_GrSLType);
bsalomone5286e02016-01-14 09:24:09 -080090 GR_STATIC_ASSERT(9 == kSampler2DRect_GrSLType);
ethannicholas22793252016-01-30 09:59:10 -080091 GR_STATIC_ASSERT(10 == kBool_GrSLType);
92 GR_STATIC_ASSERT(11 == kInt_GrSLType);
cdalton793dc262016-02-08 10:11:47 -080093 GR_STATIC_ASSERT(12 == kUint_GrSLType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +000094 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCounts) == kGrSLTypeCount);
jvanverth@google.com054ae992013-04-01 20:06:51 +000095}
96
bsalomon@google.com018f1792013-04-18 19:36:09 +000097/** Return the type enum for a vector of floats of length n (1..4),
98 e.g. 1 -> kFloat_GrSLType, 2 -> kVec2_GrSLType, ... */
jvanverth@google.com054ae992013-04-01 20:06:51 +000099static inline GrSLType GrSLFloatVectorType(int count) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000100 SkASSERT(count > 0 && count <= 4);
jvanverth@google.com054ae992013-04-01 20:06:51 +0000101 return (GrSLType)(count);
102
103 GR_STATIC_ASSERT(kFloat_GrSLType == 1);
104 GR_STATIC_ASSERT(kVec2f_GrSLType == 2);
105 GR_STATIC_ASSERT(kVec3f_GrSLType == 3);
106 GR_STATIC_ASSERT(kVec4f_GrSLType == 4);
107}
108
ethannicholas22793252016-01-30 09:59:10 -0800109/** Is the shading language type float (including vectors/matrices)? */
bsalomon422f56f2014-12-09 10:18:12 -0800110static inline bool GrSLTypeIsFloatType(GrSLType type) {
111 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
ethannicholas22793252016-01-30 09:59:10 -0800112 return (type >= 1 && type <= 6);
bsalomon422f56f2014-12-09 10:18:12 -0800113
114 GR_STATIC_ASSERT(0 == kVoid_GrSLType);
115 GR_STATIC_ASSERT(1 == kFloat_GrSLType);
116 GR_STATIC_ASSERT(2 == kVec2f_GrSLType);
117 GR_STATIC_ASSERT(3 == kVec3f_GrSLType);
118 GR_STATIC_ASSERT(4 == kVec4f_GrSLType);
119 GR_STATIC_ASSERT(5 == kMat33f_GrSLType);
120 GR_STATIC_ASSERT(6 == kMat44f_GrSLType);
121 GR_STATIC_ASSERT(7 == kSampler2D_GrSLType);
bsalomon7ea33f52015-11-22 14:51:00 -0800122 GR_STATIC_ASSERT(8 == kSamplerExternal_GrSLType);
bsalomone5286e02016-01-14 09:24:09 -0800123 GR_STATIC_ASSERT(9 == kSampler2DRect_GrSLType);
ethannicholas22793252016-01-30 09:59:10 -0800124 GR_STATIC_ASSERT(10 == kBool_GrSLType);
125 GR_STATIC_ASSERT(11 == kInt_GrSLType);
cdalton793dc262016-02-08 10:11:47 -0800126 GR_STATIC_ASSERT(12 == kUint_GrSLType);
127 GR_STATIC_ASSERT(13 == kGrSLTypeCount);
ethannicholas22793252016-01-30 09:59:10 -0800128}
129
130/** Is the shading language type integral (including vectors/matrices)? */
131static inline bool GrSLTypeIsIntType(GrSLType type) {
132 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
cdalton793dc262016-02-08 10:11:47 -0800133 return type >= kInt_GrSLType;
ethannicholas22793252016-01-30 09:59:10 -0800134
135 GR_STATIC_ASSERT(0 == kVoid_GrSLType);
136 GR_STATIC_ASSERT(1 == kFloat_GrSLType);
137 GR_STATIC_ASSERT(2 == kVec2f_GrSLType);
138 GR_STATIC_ASSERT(3 == kVec3f_GrSLType);
139 GR_STATIC_ASSERT(4 == kVec4f_GrSLType);
140 GR_STATIC_ASSERT(5 == kMat33f_GrSLType);
141 GR_STATIC_ASSERT(6 == kMat44f_GrSLType);
142 GR_STATIC_ASSERT(7 == kSampler2D_GrSLType);
143 GR_STATIC_ASSERT(8 == kSamplerExternal_GrSLType);
144 GR_STATIC_ASSERT(9 == kSampler2DRect_GrSLType);
145 GR_STATIC_ASSERT(10 == kBool_GrSLType);
146 GR_STATIC_ASSERT(11 == kInt_GrSLType);
cdalton793dc262016-02-08 10:11:47 -0800147 GR_STATIC_ASSERT(12 == kUint_GrSLType);
148 GR_STATIC_ASSERT(13 == kGrSLTypeCount);
ethannicholas22793252016-01-30 09:59:10 -0800149}
150
151/** Is the shading language type numeric (including vectors/matrices)? */
152static inline bool GrSLTypeIsNumeric(GrSLType type) {
153 return GrSLTypeIsFloatType(type) || GrSLTypeIsIntType(type);
bsalomon422f56f2014-12-09 10:18:12 -0800154}
egdanielfa896322016-01-13 12:19:30 -0800155
156/** Returns the size in bytes for floating point GrSLTypes. For non floating point type returns 0 */
157static inline size_t GrSLTypeSize(GrSLType type) {
158 SkASSERT(GrSLTypeIsFloatType(type));
159 static const size_t kSizes[] = {
160 0, // kVoid_GrSLType
161 sizeof(float), // kFloat_GrSLType
162 2 * sizeof(float), // kVec2f_GrSLType
163 3 * sizeof(float), // kVec3f_GrSLType
164 4 * sizeof(float), // kVec4f_GrSLType
165 9 * sizeof(float), // kMat33f_GrSLType
166 16 * sizeof(float), // kMat44f_GrSLType
167 0, // kSampler2D_GrSLType
ethannicholas22793252016-01-30 09:59:10 -0800168 0, // kSamplerExternal_GrSLType
169 0, // kSampler2DRect_GrSLType
170 0, // kBool_GrSLType
171 0, // kInt_GrSLType
cdalton793dc262016-02-08 10:11:47 -0800172 0, // kUint_GrSLType
egdanielfa896322016-01-13 12:19:30 -0800173 };
174 return kSizes[type];
175
176 GR_STATIC_ASSERT(0 == kVoid_GrSLType);
177 GR_STATIC_ASSERT(1 == kFloat_GrSLType);
178 GR_STATIC_ASSERT(2 == kVec2f_GrSLType);
179 GR_STATIC_ASSERT(3 == kVec3f_GrSLType);
180 GR_STATIC_ASSERT(4 == kVec4f_GrSLType);
181 GR_STATIC_ASSERT(5 == kMat33f_GrSLType);
182 GR_STATIC_ASSERT(6 == kMat44f_GrSLType);
183 GR_STATIC_ASSERT(7 == kSampler2D_GrSLType);
184 GR_STATIC_ASSERT(8 == kSamplerExternal_GrSLType);
bsalomone5286e02016-01-14 09:24:09 -0800185 GR_STATIC_ASSERT(9 == kSampler2DRect_GrSLType);
ethannicholas22793252016-01-30 09:59:10 -0800186 GR_STATIC_ASSERT(10 == kBool_GrSLType);
187 GR_STATIC_ASSERT(11 == kInt_GrSLType);
cdalton793dc262016-02-08 10:11:47 -0800188 GR_STATIC_ASSERT(12 == kUint_GrSLType);
189 GR_STATIC_ASSERT(13 == kGrSLTypeCount);
bsalomone5286e02016-01-14 09:24:09 -0800190}
191
192static inline bool GrSLTypeIsSamplerType(GrSLType type) {
193 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
194 return type >= 7 && type <= 9;
195
196 GR_STATIC_ASSERT(7 == kSampler2D_GrSLType);
197 GR_STATIC_ASSERT(8 == kSamplerExternal_GrSLType);
198 GR_STATIC_ASSERT(9 == kSampler2DRect_GrSLType);
egdanielfa896322016-01-13 12:19:30 -0800199}
200
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000201//////////////////////////////////////////////////////////////////////////////
202
jvanverth@google.com054ae992013-04-01 20:06:51 +0000203/**
204 * Types used to describe format of vertices in arrays.
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000205 */
206enum GrVertexAttribType {
207 kFloat_GrVertexAttribType = 0,
208 kVec2f_GrVertexAttribType,
209 kVec3f_GrVertexAttribType,
210 kVec4f_GrVertexAttribType,
egdaniel37b4d862014-11-03 10:07:07 -0800211
212 kUByte_GrVertexAttribType, // unsigned byte, e.g. coverage
jvanverth5a105ff2015-02-18 11:36:35 -0800213 kVec4ub_GrVertexAttribType, // vector of 4 unsigned bytes, e.g. colors
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000214
jvanverth7023a002016-02-22 11:25:32 -0800215 kVec2us_GrVertexAttribType, // vector of 2 shorts, e.g. texture coordinates
ethannicholas22793252016-01-30 09:59:10 -0800216
217 kInt_GrVertexAttribType,
cdalton793dc262016-02-08 10:11:47 -0800218 kUint_GrVertexAttribType,
jvanverth5a105ff2015-02-18 11:36:35 -0800219
cdalton793dc262016-02-08 10:11:47 -0800220 kLast_GrVertexAttribType = kUint_GrVertexAttribType
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000221};
222static const int kGrVertexAttribTypeCount = kLast_GrVertexAttribType + 1;
223
jvanverth@google.com054ae992013-04-01 20:06:51 +0000224/**
225 * Returns the vector size of the type.
226 */
227static inline int GrVertexAttribTypeVectorCount(GrVertexAttribType type) {
cdalton793dc262016-02-08 10:11:47 -0800228 SkASSERT(type >= 0 && type < kGrVertexAttribTypeCount);
229 static const int kCounts[] = { 1, 2, 3, 4, 1, 4, 2, 1, 1 };
jvanverth@google.com054ae992013-04-01 20:06:51 +0000230 return kCounts[type];
231
232 GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType);
233 GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType);
234 GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType);
235 GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType);
egdaniel37b4d862014-11-03 10:07:07 -0800236 GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType);
237 GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType);
jvanverth7023a002016-02-22 11:25:32 -0800238 GR_STATIC_ASSERT(6 == kVec2us_GrVertexAttribType);
ethannicholas22793252016-01-30 09:59:10 -0800239 GR_STATIC_ASSERT(7 == kInt_GrVertexAttribType);
cdalton793dc262016-02-08 10:11:47 -0800240 GR_STATIC_ASSERT(8 == kUint_GrVertexAttribType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000241 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCounts) == kGrVertexAttribTypeCount);
jvanverth@google.com054ae992013-04-01 20:06:51 +0000242}
243
244/**
245 * Returns the size of the attrib type in bytes.
246 */
247static inline size_t GrVertexAttribTypeSize(GrVertexAttribType type) {
jvanverth@google.com054ae992013-04-01 20:06:51 +0000248 static const size_t kSizes[] = {
249 sizeof(float), // kFloat_GrVertexAttribType
250 2*sizeof(float), // kVec2f_GrVertexAttribType
251 3*sizeof(float), // kVec3f_GrVertexAttribType
252 4*sizeof(float), // kVec4f_GrVertexAttribType
egdaniel37b4d862014-11-03 10:07:07 -0800253 1*sizeof(char), // kUByte_GrVertexAttribType
jvanverth5a105ff2015-02-18 11:36:35 -0800254 4*sizeof(char), // kVec4ub_GrVertexAttribType
jvanverth7023a002016-02-22 11:25:32 -0800255 2*sizeof(int16_t), // kVec2us_GrVertexAttribType
cdalton793dc262016-02-08 10:11:47 -0800256 sizeof(int32_t), // kInt_GrVertexAttribType
257 sizeof(uint32_t) // kUint_GrVertexAttribType
jvanverth@google.com054ae992013-04-01 20:06:51 +0000258 };
259 return kSizes[type];
260
261 GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType);
262 GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType);
263 GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType);
264 GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType);
egdaniel37b4d862014-11-03 10:07:07 -0800265 GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType);
266 GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType);
jvanverth7023a002016-02-22 11:25:32 -0800267 GR_STATIC_ASSERT(6 == kVec2us_GrVertexAttribType);
ethannicholas22793252016-01-30 09:59:10 -0800268 GR_STATIC_ASSERT(7 == kInt_GrVertexAttribType);
cdalton793dc262016-02-08 10:11:47 -0800269 GR_STATIC_ASSERT(8 == kUint_GrVertexAttribType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000270 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kSizes) == kGrVertexAttribTypeCount);
jvanverth@google.com054ae992013-04-01 20:06:51 +0000271}
272
273/**
cdalton793dc262016-02-08 10:11:47 -0800274 * Is the attrib type integral?
275 */
276static inline bool GrVertexAttribTypeIsIntType(GrVertexAttribType type) {
277 SkASSERT(type >= 0 && type < static_cast<GrVertexAttribType>(kGrVertexAttribTypeCount));
278 return type >= kInt_GrVertexAttribType;
279
280 GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType);
281 GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType);
282 GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType);
283 GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType);
284 GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType);
285 GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType);
jvanverth7023a002016-02-22 11:25:32 -0800286 GR_STATIC_ASSERT(6 == kVec2us_GrVertexAttribType);
cdalton793dc262016-02-08 10:11:47 -0800287 GR_STATIC_ASSERT(7 == kInt_GrVertexAttribType);
288 GR_STATIC_ASSERT(8 == kUint_GrVertexAttribType);
289 GR_STATIC_ASSERT(9 == kGrVertexAttribTypeCount);
290}
291
292/**
joshualitt2dd1ae02014-12-03 06:24:10 -0800293 * converts a GrVertexAttribType to a GrSLType
jvanverth@google.com054ae992013-04-01 20:06:51 +0000294 */
joshualitt2dd1ae02014-12-03 06:24:10 -0800295static inline GrSLType GrVertexAttribTypeToSLType(GrVertexAttribType type) {
296 switch (type) {
297 default:
298 SkFAIL("Unsupported type conversion");
tzikbc7d2352016-01-05 00:35:50 -0800299 return kVoid_GrSLType;
joshualitt2dd1ae02014-12-03 06:24:10 -0800300 case kUByte_GrVertexAttribType:
301 case kFloat_GrVertexAttribType:
302 return kFloat_GrSLType;
jvanverth7023a002016-02-22 11:25:32 -0800303 case kVec2us_GrVertexAttribType:
joshualitt2dd1ae02014-12-03 06:24:10 -0800304 case kVec2f_GrVertexAttribType:
305 return kVec2f_GrSLType;
306 case kVec3f_GrVertexAttribType:
307 return kVec3f_GrSLType;
308 case kVec4ub_GrVertexAttribType:
309 case kVec4f_GrVertexAttribType:
310 return kVec4f_GrSLType;
ethannicholas22793252016-01-30 09:59:10 -0800311 case kInt_GrVertexAttribType:
312 return kInt_GrSLType;
cdalton793dc262016-02-08 10:11:47 -0800313 case kUint_GrVertexAttribType:
314 return kUint_GrSLType;
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000315 }
joshualitt2dd1ae02014-12-03 06:24:10 -0800316}
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000317
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000318//////////////////////////////////////////////////////////////////////////////
319
320/**
321* We have coverage effects that clip rendering to the edge of some geometric primitive.
skia.committer@gmail.com06acb582014-03-06 03:02:32 +0000322* This enum specifies how that clipping is performed. Not all factories that take a
joshualittb0a8a372014-09-23 09:50:21 -0700323* GrProcessorEdgeType will succeed with all values and it is up to the caller to check for
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000324* a NULL return.
325*/
joshualittb0a8a372014-09-23 09:50:21 -0700326enum GrPrimitiveEdgeType {
327 kFillBW_GrProcessorEdgeType,
328 kFillAA_GrProcessorEdgeType,
329 kInverseFillBW_GrProcessorEdgeType,
330 kInverseFillAA_GrProcessorEdgeType,
331 kHairlineAA_GrProcessorEdgeType,
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000332
joshualittb0a8a372014-09-23 09:50:21 -0700333 kLast_GrProcessorEdgeType = kHairlineAA_GrProcessorEdgeType
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000334};
335
joshualittb0a8a372014-09-23 09:50:21 -0700336static const int kGrProcessorEdgeTypeCnt = kLast_GrProcessorEdgeType + 1;
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000337
joshualittb0a8a372014-09-23 09:50:21 -0700338static inline bool GrProcessorEdgeTypeIsFill(const GrPrimitiveEdgeType edgeType) {
339 return (kFillAA_GrProcessorEdgeType == edgeType || kFillBW_GrProcessorEdgeType == edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000340}
341
joshualittb0a8a372014-09-23 09:50:21 -0700342static inline bool GrProcessorEdgeTypeIsInverseFill(const GrPrimitiveEdgeType edgeType) {
343 return (kInverseFillAA_GrProcessorEdgeType == edgeType ||
344 kInverseFillBW_GrProcessorEdgeType == edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000345}
346
joshualittb0a8a372014-09-23 09:50:21 -0700347static inline bool GrProcessorEdgeTypeIsAA(const GrPrimitiveEdgeType edgeType) {
348 return (kFillBW_GrProcessorEdgeType != edgeType && kInverseFillBW_GrProcessorEdgeType != edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000349}
350
joshualittb0a8a372014-09-23 09:50:21 -0700351static inline GrPrimitiveEdgeType GrInvertProcessorEdgeType(const GrPrimitiveEdgeType edgeType) {
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000352 switch (edgeType) {
joshualittb0a8a372014-09-23 09:50:21 -0700353 case kFillBW_GrProcessorEdgeType:
354 return kInverseFillBW_GrProcessorEdgeType;
355 case kFillAA_GrProcessorEdgeType:
356 return kInverseFillAA_GrProcessorEdgeType;
357 case kInverseFillBW_GrProcessorEdgeType:
358 return kFillBW_GrProcessorEdgeType;
359 case kInverseFillAA_GrProcessorEdgeType:
360 return kFillAA_GrProcessorEdgeType;
361 case kHairlineAA_GrProcessorEdgeType:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000362 SkFAIL("Hairline fill isn't invertible.");
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000363 }
joshualittb0a8a372014-09-23 09:50:21 -0700364 return kFillAA_GrProcessorEdgeType; // suppress warning.
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000365}
366
bsalomonbcf0a522014-10-08 08:40:09 -0700367/**
368 * Indicates the type of pending IO operations that can be recorded for gpu resources.
369 */
370enum GrIOType {
371 kRead_GrIOType,
372 kWrite_GrIOType,
373 kRW_GrIOType
374};
375
bsalomon3e791242014-12-17 13:43:13 -0800376struct GrScissorState {
377 GrScissorState() : fEnabled(false) {}
378 void set(const SkIRect& rect) { fRect = rect; fEnabled = true; }
379 bool operator==(const GrScissorState& other) const {
380 return fEnabled == other.fEnabled &&
381 (false == fEnabled || fRect == other.fRect);
382 }
383 bool operator!=(const GrScissorState& other) const { return !(*this == other); }
robertphillipse85a32d2015-02-10 08:16:55 -0800384
385 bool enabled() const { return fEnabled; }
386 const SkIRect& rect() const { return fRect; }
387
388private:
bsalomon3e791242014-12-17 13:43:13 -0800389 bool fEnabled;
390 SkIRect fRect;
391};
392
jvanverth17aa0472016-01-05 10:41:27 -0800393/**
394 * Indicates the transfer direction for a transfer buffer
395 */
396enum TransferType {
397 /** Caller intends to use the buffer to transfer data to the GPU */
398 kCpuToGpu_TransferType,
399 /** Caller intends to use the buffer to transfer data from the GPU */
400 kGpuToCpu_TransferType
401};
402
403
joshualitt7d022d62015-05-12 12:03:50 -0700404#ifdef SK_DEBUG
bsalomon682c2692015-05-22 14:01:46 -0700405// Takes a pointer to a GrCaps, and will suppress prints if required
406#define GrCapsDebugf(caps, ...) \
407 if (!caps->suppressPrints()) { \
408 SkDebugf(__VA_ARGS__); \
joshualitt7d022d62015-05-12 12:03:50 -0700409 }
410#else
bsalomon682c2692015-05-22 14:01:46 -0700411#define GrCapsDebugf(caps, ...)
joshualitt7d022d62015-05-12 12:03:50 -0700412#endif
413
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +0000414#endif