blob: 4646abdd7d90dee6902acd331d8b55a63b7a4105 [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"
bsalomon@google.com31ec7982013-03-27 18:14:57 +000012#include "SkTArray.h"
bsalomon3e791242014-12-17 13:43:13 -080013#include "SkRect.h"
bsalomon@google.com31ec7982013-03-27 18:14:57 +000014
bsalomoncdee0092016-01-08 13:20:12 -080015 /**
16 * Types of shader-language-specific boxed variables we can create. (Currently only GrGLShaderVars,
17 * but should be applicable to other shader languages.)
18 */
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +000019enum GrSLType {
20 kVoid_GrSLType,
21 kFloat_GrSLType,
22 kVec2f_GrSLType,
23 kVec3f_GrSLType,
24 kVec4f_GrSLType,
25 kMat33f_GrSLType,
26 kMat44f_GrSLType,
jvanverth@google.com054ae992013-04-01 20:06:51 +000027 kSampler2D_GrSLType,
bsalomon7ea33f52015-11-22 14:51:00 -080028 kSamplerExternal_GrSLType,
bsalomone5286e02016-01-14 09:24:09 -080029 kSampler2DRect_GrSLType,
ethannicholas22793252016-01-30 09:59:10 -080030 kBool_GrSLType,
31 kInt_GrSLType,
cdalton793dc262016-02-08 10:11:47 -080032 kUint_GrSLType,
jvanverth@google.com054ae992013-04-01 20:06:51 +000033
cdalton793dc262016-02-08 10:11:47 -080034 kLast_GrSLType = kUint_GrSLType
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +000035};
jvanverth@google.com054ae992013-04-01 20:06:51 +000036static const int kGrSLTypeCount = kLast_GrSLType + 1;
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +000037
bsalomon17168df2014-12-09 09:00:49 -080038enum GrShaderType {
39 kVertex_GrShaderType,
40 kGeometry_GrShaderType,
41 kFragment_GrShaderType,
42
43 kLastkFragment_GrShaderType = kFragment_GrShaderType
44};
45static const int kGrShaderTypeCount = kLastkFragment_GrShaderType + 1;
46
cdalton5e58cee2016-02-11 12:49:47 -080047enum GrShaderFlags {
48 kNone_GrShaderFlags = 0,
49 kVertex_GrShaderFlag = 1 << kVertex_GrShaderType,
50 kGeometry_GrShaderFlag = 1 << kGeometry_GrShaderType,
51 kFragment_GrShaderFlag = 1 << kFragment_GrShaderType
52};
53GR_MAKE_BITFIELD_OPS(GrShaderFlags);
54
bsalomon@google.com31ec7982013-03-27 18:14:57 +000055/**
bsalomonc0bd6482014-12-09 10:04:14 -080056 * Precisions of shader language variables. Not all shading languages support precisions or actually
bsalomon422f56f2014-12-09 10:18:12 -080057 * vary the internal precision based on the qualifiers. These currently only apply to float types (
58 * including float vectors and matrices).
bsalomonc0bd6482014-12-09 10:04:14 -080059 */
60enum GrSLPrecision {
61 kLow_GrSLPrecision,
62 kMedium_GrSLPrecision,
63 kHigh_GrSLPrecision,
64
65 // Default precision is medium. This is because on OpenGL ES 2 highp support is not
66 // guaranteed. On (non-ES) OpenGL the specifiers have no effect on precision.
67 kDefault_GrSLPrecision = kMedium_GrSLPrecision,
68
69 kLast_GrSLPrecision = kHigh_GrSLPrecision
70};
71
72static const int kGrSLPrecisionCount = kLast_GrSLPrecision + 1;
73
74/**
jvanverth@google.com054ae992013-04-01 20:06:51 +000075 * Gets the vector size of the SLType. Returns -1 for void, matrices, and samplers.
76 */
77static inline int GrSLTypeVectorCount(GrSLType type) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000078 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
cdalton793dc262016-02-08 10:11:47 -080079 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 +000080 return kCounts[type];
81
82 GR_STATIC_ASSERT(0 == kVoid_GrSLType);
83 GR_STATIC_ASSERT(1 == kFloat_GrSLType);
84 GR_STATIC_ASSERT(2 == kVec2f_GrSLType);
85 GR_STATIC_ASSERT(3 == kVec3f_GrSLType);
86 GR_STATIC_ASSERT(4 == kVec4f_GrSLType);
87 GR_STATIC_ASSERT(5 == kMat33f_GrSLType);
88 GR_STATIC_ASSERT(6 == kMat44f_GrSLType);
89 GR_STATIC_ASSERT(7 == kSampler2D_GrSLType);
bsalomon7ea33f52015-11-22 14:51:00 -080090 GR_STATIC_ASSERT(8 == kSamplerExternal_GrSLType);
bsalomone5286e02016-01-14 09:24:09 -080091 GR_STATIC_ASSERT(9 == kSampler2DRect_GrSLType);
ethannicholas22793252016-01-30 09:59:10 -080092 GR_STATIC_ASSERT(10 == kBool_GrSLType);
93 GR_STATIC_ASSERT(11 == kInt_GrSLType);
cdalton793dc262016-02-08 10:11:47 -080094 GR_STATIC_ASSERT(12 == kUint_GrSLType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +000095 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCounts) == kGrSLTypeCount);
jvanverth@google.com054ae992013-04-01 20:06:51 +000096}
97
bsalomon@google.com018f1792013-04-18 19:36:09 +000098/** Return the type enum for a vector of floats of length n (1..4),
99 e.g. 1 -> kFloat_GrSLType, 2 -> kVec2_GrSLType, ... */
jvanverth@google.com054ae992013-04-01 20:06:51 +0000100static inline GrSLType GrSLFloatVectorType(int count) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000101 SkASSERT(count > 0 && count <= 4);
jvanverth@google.com054ae992013-04-01 20:06:51 +0000102 return (GrSLType)(count);
103
104 GR_STATIC_ASSERT(kFloat_GrSLType == 1);
105 GR_STATIC_ASSERT(kVec2f_GrSLType == 2);
106 GR_STATIC_ASSERT(kVec3f_GrSLType == 3);
107 GR_STATIC_ASSERT(kVec4f_GrSLType == 4);
108}
109
ethannicholas22793252016-01-30 09:59:10 -0800110/** Is the shading language type float (including vectors/matrices)? */
bsalomon422f56f2014-12-09 10:18:12 -0800111static inline bool GrSLTypeIsFloatType(GrSLType type) {
112 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
ethannicholas22793252016-01-30 09:59:10 -0800113 return (type >= 1 && type <= 6);
bsalomon422f56f2014-12-09 10:18:12 -0800114
115 GR_STATIC_ASSERT(0 == kVoid_GrSLType);
116 GR_STATIC_ASSERT(1 == kFloat_GrSLType);
117 GR_STATIC_ASSERT(2 == kVec2f_GrSLType);
118 GR_STATIC_ASSERT(3 == kVec3f_GrSLType);
119 GR_STATIC_ASSERT(4 == kVec4f_GrSLType);
120 GR_STATIC_ASSERT(5 == kMat33f_GrSLType);
121 GR_STATIC_ASSERT(6 == kMat44f_GrSLType);
122 GR_STATIC_ASSERT(7 == kSampler2D_GrSLType);
bsalomon7ea33f52015-11-22 14:51:00 -0800123 GR_STATIC_ASSERT(8 == kSamplerExternal_GrSLType);
bsalomone5286e02016-01-14 09:24:09 -0800124 GR_STATIC_ASSERT(9 == kSampler2DRect_GrSLType);
ethannicholas22793252016-01-30 09:59:10 -0800125 GR_STATIC_ASSERT(10 == kBool_GrSLType);
126 GR_STATIC_ASSERT(11 == kInt_GrSLType);
cdalton793dc262016-02-08 10:11:47 -0800127 GR_STATIC_ASSERT(12 == kUint_GrSLType);
128 GR_STATIC_ASSERT(13 == kGrSLTypeCount);
ethannicholas22793252016-01-30 09:59:10 -0800129}
130
131/** Is the shading language type integral (including vectors/matrices)? */
132static inline bool GrSLTypeIsIntType(GrSLType type) {
133 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
cdalton793dc262016-02-08 10:11:47 -0800134 return type >= kInt_GrSLType;
ethannicholas22793252016-01-30 09:59:10 -0800135
136 GR_STATIC_ASSERT(0 == kVoid_GrSLType);
137 GR_STATIC_ASSERT(1 == kFloat_GrSLType);
138 GR_STATIC_ASSERT(2 == kVec2f_GrSLType);
139 GR_STATIC_ASSERT(3 == kVec3f_GrSLType);
140 GR_STATIC_ASSERT(4 == kVec4f_GrSLType);
141 GR_STATIC_ASSERT(5 == kMat33f_GrSLType);
142 GR_STATIC_ASSERT(6 == kMat44f_GrSLType);
143 GR_STATIC_ASSERT(7 == kSampler2D_GrSLType);
144 GR_STATIC_ASSERT(8 == kSamplerExternal_GrSLType);
145 GR_STATIC_ASSERT(9 == kSampler2DRect_GrSLType);
146 GR_STATIC_ASSERT(10 == kBool_GrSLType);
147 GR_STATIC_ASSERT(11 == kInt_GrSLType);
cdalton793dc262016-02-08 10:11:47 -0800148 GR_STATIC_ASSERT(12 == kUint_GrSLType);
149 GR_STATIC_ASSERT(13 == kGrSLTypeCount);
ethannicholas22793252016-01-30 09:59:10 -0800150}
151
152/** Is the shading language type numeric (including vectors/matrices)? */
153static inline bool GrSLTypeIsNumeric(GrSLType type) {
154 return GrSLTypeIsFloatType(type) || GrSLTypeIsIntType(type);
bsalomon422f56f2014-12-09 10:18:12 -0800155}
egdanielfa896322016-01-13 12:19:30 -0800156
157/** Returns the size in bytes for floating point GrSLTypes. For non floating point type returns 0 */
158static inline size_t GrSLTypeSize(GrSLType type) {
159 SkASSERT(GrSLTypeIsFloatType(type));
160 static const size_t kSizes[] = {
161 0, // kVoid_GrSLType
162 sizeof(float), // kFloat_GrSLType
163 2 * sizeof(float), // kVec2f_GrSLType
164 3 * sizeof(float), // kVec3f_GrSLType
165 4 * sizeof(float), // kVec4f_GrSLType
166 9 * sizeof(float), // kMat33f_GrSLType
167 16 * sizeof(float), // kMat44f_GrSLType
168 0, // kSampler2D_GrSLType
ethannicholas22793252016-01-30 09:59:10 -0800169 0, // kSamplerExternal_GrSLType
170 0, // kSampler2DRect_GrSLType
171 0, // kBool_GrSLType
172 0, // kInt_GrSLType
cdalton793dc262016-02-08 10:11:47 -0800173 0, // kUint_GrSLType
egdanielfa896322016-01-13 12:19:30 -0800174 };
175 return kSizes[type];
176
177 GR_STATIC_ASSERT(0 == kVoid_GrSLType);
178 GR_STATIC_ASSERT(1 == kFloat_GrSLType);
179 GR_STATIC_ASSERT(2 == kVec2f_GrSLType);
180 GR_STATIC_ASSERT(3 == kVec3f_GrSLType);
181 GR_STATIC_ASSERT(4 == kVec4f_GrSLType);
182 GR_STATIC_ASSERT(5 == kMat33f_GrSLType);
183 GR_STATIC_ASSERT(6 == kMat44f_GrSLType);
184 GR_STATIC_ASSERT(7 == kSampler2D_GrSLType);
185 GR_STATIC_ASSERT(8 == kSamplerExternal_GrSLType);
bsalomone5286e02016-01-14 09:24:09 -0800186 GR_STATIC_ASSERT(9 == kSampler2DRect_GrSLType);
ethannicholas22793252016-01-30 09:59:10 -0800187 GR_STATIC_ASSERT(10 == kBool_GrSLType);
188 GR_STATIC_ASSERT(11 == kInt_GrSLType);
cdalton793dc262016-02-08 10:11:47 -0800189 GR_STATIC_ASSERT(12 == kUint_GrSLType);
190 GR_STATIC_ASSERT(13 == kGrSLTypeCount);
bsalomone5286e02016-01-14 09:24:09 -0800191}
192
193static inline bool GrSLTypeIsSamplerType(GrSLType type) {
194 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
195 return type >= 7 && type <= 9;
196
197 GR_STATIC_ASSERT(7 == kSampler2D_GrSLType);
198 GR_STATIC_ASSERT(8 == kSamplerExternal_GrSLType);
199 GR_STATIC_ASSERT(9 == kSampler2DRect_GrSLType);
egdanielfa896322016-01-13 12:19:30 -0800200}
201
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000202//////////////////////////////////////////////////////////////////////////////
203
jvanverth@google.com054ae992013-04-01 20:06:51 +0000204/**
205 * Types used to describe format of vertices in arrays.
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000206 */
207enum GrVertexAttribType {
208 kFloat_GrVertexAttribType = 0,
209 kVec2f_GrVertexAttribType,
210 kVec3f_GrVertexAttribType,
211 kVec4f_GrVertexAttribType,
egdaniel37b4d862014-11-03 10:07:07 -0800212
213 kUByte_GrVertexAttribType, // unsigned byte, e.g. coverage
jvanverth5a105ff2015-02-18 11:36:35 -0800214 kVec4ub_GrVertexAttribType, // vector of 4 unsigned bytes, e.g. colors
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000215
jvanverth5a105ff2015-02-18 11:36:35 -0800216 kVec2s_GrVertexAttribType, // vector of 2 shorts, e.g. texture coordinates
ethannicholas22793252016-01-30 09:59:10 -0800217
218 kInt_GrVertexAttribType,
cdalton793dc262016-02-08 10:11:47 -0800219 kUint_GrVertexAttribType,
jvanverth5a105ff2015-02-18 11:36:35 -0800220
cdalton793dc262016-02-08 10:11:47 -0800221 kLast_GrVertexAttribType = kUint_GrVertexAttribType
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000222};
223static const int kGrVertexAttribTypeCount = kLast_GrVertexAttribType + 1;
224
jvanverth@google.com054ae992013-04-01 20:06:51 +0000225/**
226 * Returns the vector size of the type.
227 */
228static inline int GrVertexAttribTypeVectorCount(GrVertexAttribType type) {
cdalton793dc262016-02-08 10:11:47 -0800229 SkASSERT(type >= 0 && type < kGrVertexAttribTypeCount);
230 static const int kCounts[] = { 1, 2, 3, 4, 1, 4, 2, 1, 1 };
jvanverth@google.com054ae992013-04-01 20:06:51 +0000231 return kCounts[type];
232
233 GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType);
234 GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType);
235 GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType);
236 GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType);
egdaniel37b4d862014-11-03 10:07:07 -0800237 GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType);
238 GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType);
jvanverth5a105ff2015-02-18 11:36:35 -0800239 GR_STATIC_ASSERT(6 == kVec2s_GrVertexAttribType);
ethannicholas22793252016-01-30 09:59:10 -0800240 GR_STATIC_ASSERT(7 == kInt_GrVertexAttribType);
cdalton793dc262016-02-08 10:11:47 -0800241 GR_STATIC_ASSERT(8 == kUint_GrVertexAttribType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000242 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCounts) == kGrVertexAttribTypeCount);
jvanverth@google.com054ae992013-04-01 20:06:51 +0000243}
244
245/**
246 * Returns the size of the attrib type in bytes.
247 */
248static inline size_t GrVertexAttribTypeSize(GrVertexAttribType type) {
jvanverth@google.com054ae992013-04-01 20:06:51 +0000249 static const size_t kSizes[] = {
250 sizeof(float), // kFloat_GrVertexAttribType
251 2*sizeof(float), // kVec2f_GrVertexAttribType
252 3*sizeof(float), // kVec3f_GrVertexAttribType
253 4*sizeof(float), // kVec4f_GrVertexAttribType
egdaniel37b4d862014-11-03 10:07:07 -0800254 1*sizeof(char), // kUByte_GrVertexAttribType
jvanverth5a105ff2015-02-18 11:36:35 -0800255 4*sizeof(char), // kVec4ub_GrVertexAttribType
ethannicholas22793252016-01-30 09:59:10 -0800256 2*sizeof(int16_t), // kVec2s_GrVertexAttribType
cdalton793dc262016-02-08 10:11:47 -0800257 sizeof(int32_t), // kInt_GrVertexAttribType
258 sizeof(uint32_t) // kUint_GrVertexAttribType
jvanverth@google.com054ae992013-04-01 20:06:51 +0000259 };
260 return kSizes[type];
261
262 GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType);
263 GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType);
264 GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType);
265 GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType);
egdaniel37b4d862014-11-03 10:07:07 -0800266 GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType);
267 GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType);
jvanverth5a105ff2015-02-18 11:36:35 -0800268 GR_STATIC_ASSERT(6 == kVec2s_GrVertexAttribType);
ethannicholas22793252016-01-30 09:59:10 -0800269 GR_STATIC_ASSERT(7 == kInt_GrVertexAttribType);
cdalton793dc262016-02-08 10:11:47 -0800270 GR_STATIC_ASSERT(8 == kUint_GrVertexAttribType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000271 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kSizes) == kGrVertexAttribTypeCount);
jvanverth@google.com054ae992013-04-01 20:06:51 +0000272}
273
274/**
cdalton793dc262016-02-08 10:11:47 -0800275 * Is the attrib type integral?
276 */
277static inline bool GrVertexAttribTypeIsIntType(GrVertexAttribType type) {
278 SkASSERT(type >= 0 && type < static_cast<GrVertexAttribType>(kGrVertexAttribTypeCount));
279 return type >= kInt_GrVertexAttribType;
280
281 GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType);
282 GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType);
283 GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType);
284 GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType);
285 GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType);
286 GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType);
287 GR_STATIC_ASSERT(6 == kVec2s_GrVertexAttribType);
288 GR_STATIC_ASSERT(7 == kInt_GrVertexAttribType);
289 GR_STATIC_ASSERT(8 == kUint_GrVertexAttribType);
290 GR_STATIC_ASSERT(9 == kGrVertexAttribTypeCount);
291}
292
293/**
joshualitt2dd1ae02014-12-03 06:24:10 -0800294 * converts a GrVertexAttribType to a GrSLType
jvanverth@google.com054ae992013-04-01 20:06:51 +0000295 */
joshualitt2dd1ae02014-12-03 06:24:10 -0800296static inline GrSLType GrVertexAttribTypeToSLType(GrVertexAttribType type) {
297 switch (type) {
298 default:
299 SkFAIL("Unsupported type conversion");
tzikbc7d2352016-01-05 00:35:50 -0800300 return kVoid_GrSLType;
joshualitt2dd1ae02014-12-03 06:24:10 -0800301 case kUByte_GrVertexAttribType:
302 case kFloat_GrVertexAttribType:
303 return kFloat_GrSLType;
jvanverth5a105ff2015-02-18 11:36:35 -0800304 case kVec2s_GrVertexAttribType:
joshualitt2dd1ae02014-12-03 06:24:10 -0800305 case kVec2f_GrVertexAttribType:
306 return kVec2f_GrSLType;
307 case kVec3f_GrVertexAttribType:
308 return kVec3f_GrSLType;
309 case kVec4ub_GrVertexAttribType:
310 case kVec4f_GrVertexAttribType:
311 return kVec4f_GrSLType;
ethannicholas22793252016-01-30 09:59:10 -0800312 case kInt_GrVertexAttribType:
313 return kInt_GrSLType;
cdalton793dc262016-02-08 10:11:47 -0800314 case kUint_GrVertexAttribType:
315 return kUint_GrSLType;
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000316 }
joshualitt2dd1ae02014-12-03 06:24:10 -0800317}
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000318
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000319//////////////////////////////////////////////////////////////////////////////
320
321/**
322* We have coverage effects that clip rendering to the edge of some geometric primitive.
skia.committer@gmail.com06acb582014-03-06 03:02:32 +0000323* This enum specifies how that clipping is performed. Not all factories that take a
joshualittb0a8a372014-09-23 09:50:21 -0700324* 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 +0000325* a NULL return.
326*/
joshualittb0a8a372014-09-23 09:50:21 -0700327enum GrPrimitiveEdgeType {
328 kFillBW_GrProcessorEdgeType,
329 kFillAA_GrProcessorEdgeType,
330 kInverseFillBW_GrProcessorEdgeType,
331 kInverseFillAA_GrProcessorEdgeType,
332 kHairlineAA_GrProcessorEdgeType,
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000333
joshualittb0a8a372014-09-23 09:50:21 -0700334 kLast_GrProcessorEdgeType = kHairlineAA_GrProcessorEdgeType
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000335};
336
joshualittb0a8a372014-09-23 09:50:21 -0700337static const int kGrProcessorEdgeTypeCnt = kLast_GrProcessorEdgeType + 1;
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000338
joshualittb0a8a372014-09-23 09:50:21 -0700339static inline bool GrProcessorEdgeTypeIsFill(const GrPrimitiveEdgeType edgeType) {
340 return (kFillAA_GrProcessorEdgeType == edgeType || kFillBW_GrProcessorEdgeType == edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000341}
342
joshualittb0a8a372014-09-23 09:50:21 -0700343static inline bool GrProcessorEdgeTypeIsInverseFill(const GrPrimitiveEdgeType edgeType) {
344 return (kInverseFillAA_GrProcessorEdgeType == edgeType ||
345 kInverseFillBW_GrProcessorEdgeType == edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000346}
347
joshualittb0a8a372014-09-23 09:50:21 -0700348static inline bool GrProcessorEdgeTypeIsAA(const GrPrimitiveEdgeType edgeType) {
349 return (kFillBW_GrProcessorEdgeType != edgeType && kInverseFillBW_GrProcessorEdgeType != edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000350}
351
joshualittb0a8a372014-09-23 09:50:21 -0700352static inline GrPrimitiveEdgeType GrInvertProcessorEdgeType(const GrPrimitiveEdgeType edgeType) {
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000353 switch (edgeType) {
joshualittb0a8a372014-09-23 09:50:21 -0700354 case kFillBW_GrProcessorEdgeType:
355 return kInverseFillBW_GrProcessorEdgeType;
356 case kFillAA_GrProcessorEdgeType:
357 return kInverseFillAA_GrProcessorEdgeType;
358 case kInverseFillBW_GrProcessorEdgeType:
359 return kFillBW_GrProcessorEdgeType;
360 case kInverseFillAA_GrProcessorEdgeType:
361 return kFillAA_GrProcessorEdgeType;
362 case kHairlineAA_GrProcessorEdgeType:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000363 SkFAIL("Hairline fill isn't invertible.");
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000364 }
joshualittb0a8a372014-09-23 09:50:21 -0700365 return kFillAA_GrProcessorEdgeType; // suppress warning.
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000366}
367
bsalomonbcf0a522014-10-08 08:40:09 -0700368/**
369 * Indicates the type of pending IO operations that can be recorded for gpu resources.
370 */
371enum GrIOType {
372 kRead_GrIOType,
373 kWrite_GrIOType,
374 kRW_GrIOType
375};
376
bsalomon3e791242014-12-17 13:43:13 -0800377struct GrScissorState {
378 GrScissorState() : fEnabled(false) {}
379 void set(const SkIRect& rect) { fRect = rect; fEnabled = true; }
380 bool operator==(const GrScissorState& other) const {
381 return fEnabled == other.fEnabled &&
382 (false == fEnabled || fRect == other.fRect);
383 }
384 bool operator!=(const GrScissorState& other) const { return !(*this == other); }
robertphillipse85a32d2015-02-10 08:16:55 -0800385
386 bool enabled() const { return fEnabled; }
387 const SkIRect& rect() const { return fRect; }
388
389private:
bsalomon3e791242014-12-17 13:43:13 -0800390 bool fEnabled;
391 SkIRect fRect;
392};
393
jvanverth17aa0472016-01-05 10:41:27 -0800394/**
395 * Indicates the transfer direction for a transfer buffer
396 */
397enum TransferType {
398 /** Caller intends to use the buffer to transfer data to the GPU */
399 kCpuToGpu_TransferType,
400 /** Caller intends to use the buffer to transfer data from the GPU */
401 kGpuToCpu_TransferType
402};
403
404
joshualitt7d022d62015-05-12 12:03:50 -0700405#ifdef SK_DEBUG
bsalomon682c2692015-05-22 14:01:46 -0700406// Takes a pointer to a GrCaps, and will suppress prints if required
407#define GrCapsDebugf(caps, ...) \
408 if (!caps->suppressPrints()) { \
409 SkDebugf(__VA_ARGS__); \
joshualitt7d022d62015-05-12 12:03:50 -0700410 }
411#else
bsalomon682c2692015-05-22 14:01:46 -0700412#define GrCapsDebugf(caps, ...)
joshualitt7d022d62015-05-12 12:03:50 -0700413#endif
414
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +0000415#endif