blob: bf8ea4906352ed9c98c2ed8e3cb37594337e47a6 [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,
cdalton8d988b32016-03-07 15:39:09 -080024 kMat22f_GrSLType,
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +000025 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));
cdalton8d988b32016-03-07 15:39:09 -080079 static const int kCounts[] = { -1, 1, 2, 3, 4, -1, -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);
cdalton8d988b32016-03-07 15:39:09 -080087 GR_STATIC_ASSERT(5 == kMat22f_GrSLType);
88 GR_STATIC_ASSERT(6 == kMat33f_GrSLType);
89 GR_STATIC_ASSERT(7 == kMat44f_GrSLType);
90 GR_STATIC_ASSERT(8 == kSampler2D_GrSLType);
91 GR_STATIC_ASSERT(9 == kSamplerExternal_GrSLType);
92 GR_STATIC_ASSERT(10 == kSampler2DRect_GrSLType);
93 GR_STATIC_ASSERT(11 == kBool_GrSLType);
94 GR_STATIC_ASSERT(12 == kInt_GrSLType);
95 GR_STATIC_ASSERT(13 == kUint_GrSLType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +000096 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCounts) == kGrSLTypeCount);
jvanverth@google.com054ae992013-04-01 20:06:51 +000097}
98
bsalomon@google.com018f1792013-04-18 19:36:09 +000099/** Return the type enum for a vector of floats of length n (1..4),
100 e.g. 1 -> kFloat_GrSLType, 2 -> kVec2_GrSLType, ... */
jvanverth@google.com054ae992013-04-01 20:06:51 +0000101static inline GrSLType GrSLFloatVectorType(int count) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000102 SkASSERT(count > 0 && count <= 4);
jvanverth@google.com054ae992013-04-01 20:06:51 +0000103 return (GrSLType)(count);
104
105 GR_STATIC_ASSERT(kFloat_GrSLType == 1);
106 GR_STATIC_ASSERT(kVec2f_GrSLType == 2);
107 GR_STATIC_ASSERT(kVec3f_GrSLType == 3);
108 GR_STATIC_ASSERT(kVec4f_GrSLType == 4);
109}
110
ethannicholas22793252016-01-30 09:59:10 -0800111/** Is the shading language type float (including vectors/matrices)? */
bsalomon422f56f2014-12-09 10:18:12 -0800112static inline bool GrSLTypeIsFloatType(GrSLType type) {
113 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
cdalton8d988b32016-03-07 15:39:09 -0800114 return type >= kFloat_GrSLType && type <= kMat44f_GrSLType;
bsalomon422f56f2014-12-09 10:18:12 -0800115
116 GR_STATIC_ASSERT(0 == kVoid_GrSLType);
117 GR_STATIC_ASSERT(1 == kFloat_GrSLType);
118 GR_STATIC_ASSERT(2 == kVec2f_GrSLType);
119 GR_STATIC_ASSERT(3 == kVec3f_GrSLType);
120 GR_STATIC_ASSERT(4 == kVec4f_GrSLType);
cdalton8d988b32016-03-07 15:39:09 -0800121 GR_STATIC_ASSERT(5 == kMat22f_GrSLType);
122 GR_STATIC_ASSERT(6 == kMat33f_GrSLType);
123 GR_STATIC_ASSERT(7 == kMat44f_GrSLType);
124 GR_STATIC_ASSERT(8 == kSampler2D_GrSLType);
125 GR_STATIC_ASSERT(9 == kSamplerExternal_GrSLType);
126 GR_STATIC_ASSERT(10 == kSampler2DRect_GrSLType);
127 GR_STATIC_ASSERT(11 == kBool_GrSLType);
128 GR_STATIC_ASSERT(12 == kInt_GrSLType);
129 GR_STATIC_ASSERT(13 == kUint_GrSLType);
130 GR_STATIC_ASSERT(14 == kGrSLTypeCount);
ethannicholas22793252016-01-30 09:59:10 -0800131}
132
133/** Is the shading language type integral (including vectors/matrices)? */
134static inline bool GrSLTypeIsIntType(GrSLType type) {
135 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
cdalton793dc262016-02-08 10:11:47 -0800136 return type >= kInt_GrSLType;
ethannicholas22793252016-01-30 09:59:10 -0800137
138 GR_STATIC_ASSERT(0 == kVoid_GrSLType);
139 GR_STATIC_ASSERT(1 == kFloat_GrSLType);
140 GR_STATIC_ASSERT(2 == kVec2f_GrSLType);
141 GR_STATIC_ASSERT(3 == kVec3f_GrSLType);
142 GR_STATIC_ASSERT(4 == kVec4f_GrSLType);
cdalton8d988b32016-03-07 15:39:09 -0800143 GR_STATIC_ASSERT(5 == kMat22f_GrSLType);
144 GR_STATIC_ASSERT(6 == kMat33f_GrSLType);
145 GR_STATIC_ASSERT(7 == kMat44f_GrSLType);
146 GR_STATIC_ASSERT(8 == kSampler2D_GrSLType);
147 GR_STATIC_ASSERT(9 == kSamplerExternal_GrSLType);
148 GR_STATIC_ASSERT(10 == kSampler2DRect_GrSLType);
149 GR_STATIC_ASSERT(11 == kBool_GrSLType);
150 GR_STATIC_ASSERT(12 == kInt_GrSLType);
151 GR_STATIC_ASSERT(13 == kUint_GrSLType);
152 GR_STATIC_ASSERT(14 == kGrSLTypeCount);
ethannicholas22793252016-01-30 09:59:10 -0800153}
154
155/** Is the shading language type numeric (including vectors/matrices)? */
156static inline bool GrSLTypeIsNumeric(GrSLType type) {
157 return GrSLTypeIsFloatType(type) || GrSLTypeIsIntType(type);
bsalomon422f56f2014-12-09 10:18:12 -0800158}
egdanielfa896322016-01-13 12:19:30 -0800159
160/** Returns the size in bytes for floating point GrSLTypes. For non floating point type returns 0 */
161static inline size_t GrSLTypeSize(GrSLType type) {
162 SkASSERT(GrSLTypeIsFloatType(type));
163 static const size_t kSizes[] = {
164 0, // kVoid_GrSLType
165 sizeof(float), // kFloat_GrSLType
166 2 * sizeof(float), // kVec2f_GrSLType
167 3 * sizeof(float), // kVec3f_GrSLType
168 4 * sizeof(float), // kVec4f_GrSLType
cdalton8d988b32016-03-07 15:39:09 -0800169 2 * 2 * sizeof(float), // kMat22f_GrSLType
170 3 * 3 * sizeof(float), // kMat33f_GrSLType
171 4 * 4 * sizeof(float), // kMat44f_GrSLType
egdanielfa896322016-01-13 12:19:30 -0800172 0, // kSampler2D_GrSLType
ethannicholas22793252016-01-30 09:59:10 -0800173 0, // kSamplerExternal_GrSLType
174 0, // kSampler2DRect_GrSLType
175 0, // kBool_GrSLType
176 0, // kInt_GrSLType
cdalton793dc262016-02-08 10:11:47 -0800177 0, // kUint_GrSLType
egdanielfa896322016-01-13 12:19:30 -0800178 };
179 return kSizes[type];
180
181 GR_STATIC_ASSERT(0 == kVoid_GrSLType);
182 GR_STATIC_ASSERT(1 == kFloat_GrSLType);
183 GR_STATIC_ASSERT(2 == kVec2f_GrSLType);
184 GR_STATIC_ASSERT(3 == kVec3f_GrSLType);
185 GR_STATIC_ASSERT(4 == kVec4f_GrSLType);
cdalton8d988b32016-03-07 15:39:09 -0800186 GR_STATIC_ASSERT(5 == kMat22f_GrSLType);
187 GR_STATIC_ASSERT(6 == kMat33f_GrSLType);
188 GR_STATIC_ASSERT(7 == kMat44f_GrSLType);
189 GR_STATIC_ASSERT(8 == kSampler2D_GrSLType);
190 GR_STATIC_ASSERT(9 == kSamplerExternal_GrSLType);
191 GR_STATIC_ASSERT(10 == kSampler2DRect_GrSLType);
192 GR_STATIC_ASSERT(11 == kBool_GrSLType);
193 GR_STATIC_ASSERT(12 == kInt_GrSLType);
194 GR_STATIC_ASSERT(13 == kUint_GrSLType);
195 GR_STATIC_ASSERT(14 == kGrSLTypeCount);
bsalomone5286e02016-01-14 09:24:09 -0800196}
197
198static inline bool GrSLTypeIsSamplerType(GrSLType type) {
199 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
cdalton8d988b32016-03-07 15:39:09 -0800200 return type >= kSampler2D_GrSLType && type <= kSampler2DRect_GrSLType;
bsalomone5286e02016-01-14 09:24:09 -0800201
cdalton8d988b32016-03-07 15:39:09 -0800202 GR_STATIC_ASSERT(8 == kSampler2D_GrSLType);
203 GR_STATIC_ASSERT(9 == kSamplerExternal_GrSLType);
204 GR_STATIC_ASSERT(10 == kSampler2DRect_GrSLType);
egdanielfa896322016-01-13 12:19:30 -0800205}
206
cdalton5f2d8e22016-03-11 13:34:32 -0800207static inline bool GrSLTypeAcceptsPrecision(GrSLType type) {
208 return GrSLTypeIsNumeric(type) || GrSLTypeIsSamplerType(type);
209}
210
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000211//////////////////////////////////////////////////////////////////////////////
212
jvanverth@google.com054ae992013-04-01 20:06:51 +0000213/**
214 * Types used to describe format of vertices in arrays.
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000215 */
216enum GrVertexAttribType {
217 kFloat_GrVertexAttribType = 0,
218 kVec2f_GrVertexAttribType,
219 kVec3f_GrVertexAttribType,
220 kVec4f_GrVertexAttribType,
egdaniel37b4d862014-11-03 10:07:07 -0800221
222 kUByte_GrVertexAttribType, // unsigned byte, e.g. coverage
jvanverth5a105ff2015-02-18 11:36:35 -0800223 kVec4ub_GrVertexAttribType, // vector of 4 unsigned bytes, e.g. colors
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000224
jvanverth7023a002016-02-22 11:25:32 -0800225 kVec2us_GrVertexAttribType, // vector of 2 shorts, e.g. texture coordinates
ethannicholas22793252016-01-30 09:59:10 -0800226
227 kInt_GrVertexAttribType,
cdalton793dc262016-02-08 10:11:47 -0800228 kUint_GrVertexAttribType,
jvanverth5a105ff2015-02-18 11:36:35 -0800229
cdalton793dc262016-02-08 10:11:47 -0800230 kLast_GrVertexAttribType = kUint_GrVertexAttribType
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000231};
232static const int kGrVertexAttribTypeCount = kLast_GrVertexAttribType + 1;
233
jvanverth@google.com054ae992013-04-01 20:06:51 +0000234/**
235 * Returns the vector size of the type.
236 */
237static inline int GrVertexAttribTypeVectorCount(GrVertexAttribType type) {
cdalton793dc262016-02-08 10:11:47 -0800238 SkASSERT(type >= 0 && type < kGrVertexAttribTypeCount);
239 static const int kCounts[] = { 1, 2, 3, 4, 1, 4, 2, 1, 1 };
jvanverth@google.com054ae992013-04-01 20:06:51 +0000240 return kCounts[type];
241
242 GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType);
243 GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType);
244 GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType);
245 GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType);
egdaniel37b4d862014-11-03 10:07:07 -0800246 GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType);
247 GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType);
jvanverth7023a002016-02-22 11:25:32 -0800248 GR_STATIC_ASSERT(6 == kVec2us_GrVertexAttribType);
ethannicholas22793252016-01-30 09:59:10 -0800249 GR_STATIC_ASSERT(7 == kInt_GrVertexAttribType);
cdalton793dc262016-02-08 10:11:47 -0800250 GR_STATIC_ASSERT(8 == kUint_GrVertexAttribType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000251 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCounts) == kGrVertexAttribTypeCount);
jvanverth@google.com054ae992013-04-01 20:06:51 +0000252}
253
254/**
255 * Returns the size of the attrib type in bytes.
256 */
257static inline size_t GrVertexAttribTypeSize(GrVertexAttribType type) {
jvanverth@google.com054ae992013-04-01 20:06:51 +0000258 static const size_t kSizes[] = {
259 sizeof(float), // kFloat_GrVertexAttribType
260 2*sizeof(float), // kVec2f_GrVertexAttribType
261 3*sizeof(float), // kVec3f_GrVertexAttribType
262 4*sizeof(float), // kVec4f_GrVertexAttribType
egdaniel37b4d862014-11-03 10:07:07 -0800263 1*sizeof(char), // kUByte_GrVertexAttribType
jvanverth5a105ff2015-02-18 11:36:35 -0800264 4*sizeof(char), // kVec4ub_GrVertexAttribType
jvanverth7023a002016-02-22 11:25:32 -0800265 2*sizeof(int16_t), // kVec2us_GrVertexAttribType
cdalton793dc262016-02-08 10:11:47 -0800266 sizeof(int32_t), // kInt_GrVertexAttribType
267 sizeof(uint32_t) // kUint_GrVertexAttribType
jvanverth@google.com054ae992013-04-01 20:06:51 +0000268 };
269 return kSizes[type];
270
271 GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType);
272 GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType);
273 GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType);
274 GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType);
egdaniel37b4d862014-11-03 10:07:07 -0800275 GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType);
276 GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType);
jvanverth7023a002016-02-22 11:25:32 -0800277 GR_STATIC_ASSERT(6 == kVec2us_GrVertexAttribType);
ethannicholas22793252016-01-30 09:59:10 -0800278 GR_STATIC_ASSERT(7 == kInt_GrVertexAttribType);
cdalton793dc262016-02-08 10:11:47 -0800279 GR_STATIC_ASSERT(8 == kUint_GrVertexAttribType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000280 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kSizes) == kGrVertexAttribTypeCount);
jvanverth@google.com054ae992013-04-01 20:06:51 +0000281}
282
283/**
cdalton793dc262016-02-08 10:11:47 -0800284 * Is the attrib type integral?
285 */
286static inline bool GrVertexAttribTypeIsIntType(GrVertexAttribType type) {
287 SkASSERT(type >= 0 && type < static_cast<GrVertexAttribType>(kGrVertexAttribTypeCount));
288 return type >= kInt_GrVertexAttribType;
289
290 GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType);
291 GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType);
292 GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType);
293 GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType);
294 GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType);
295 GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType);
jvanverth7023a002016-02-22 11:25:32 -0800296 GR_STATIC_ASSERT(6 == kVec2us_GrVertexAttribType);
cdalton793dc262016-02-08 10:11:47 -0800297 GR_STATIC_ASSERT(7 == kInt_GrVertexAttribType);
298 GR_STATIC_ASSERT(8 == kUint_GrVertexAttribType);
299 GR_STATIC_ASSERT(9 == kGrVertexAttribTypeCount);
300}
301
302/**
joshualitt2dd1ae02014-12-03 06:24:10 -0800303 * converts a GrVertexAttribType to a GrSLType
jvanverth@google.com054ae992013-04-01 20:06:51 +0000304 */
joshualitt2dd1ae02014-12-03 06:24:10 -0800305static inline GrSLType GrVertexAttribTypeToSLType(GrVertexAttribType type) {
306 switch (type) {
307 default:
308 SkFAIL("Unsupported type conversion");
tzikbc7d2352016-01-05 00:35:50 -0800309 return kVoid_GrSLType;
joshualitt2dd1ae02014-12-03 06:24:10 -0800310 case kUByte_GrVertexAttribType:
311 case kFloat_GrVertexAttribType:
312 return kFloat_GrSLType;
jvanverth7023a002016-02-22 11:25:32 -0800313 case kVec2us_GrVertexAttribType:
joshualitt2dd1ae02014-12-03 06:24:10 -0800314 case kVec2f_GrVertexAttribType:
315 return kVec2f_GrSLType;
316 case kVec3f_GrVertexAttribType:
317 return kVec3f_GrSLType;
318 case kVec4ub_GrVertexAttribType:
319 case kVec4f_GrVertexAttribType:
320 return kVec4f_GrSLType;
ethannicholas22793252016-01-30 09:59:10 -0800321 case kInt_GrVertexAttribType:
322 return kInt_GrSLType;
cdalton793dc262016-02-08 10:11:47 -0800323 case kUint_GrVertexAttribType:
324 return kUint_GrSLType;
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000325 }
joshualitt2dd1ae02014-12-03 06:24:10 -0800326}
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000327
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000328//////////////////////////////////////////////////////////////////////////////
329
330/**
331* We have coverage effects that clip rendering to the edge of some geometric primitive.
skia.committer@gmail.com06acb582014-03-06 03:02:32 +0000332* This enum specifies how that clipping is performed. Not all factories that take a
joshualittb0a8a372014-09-23 09:50:21 -0700333* 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 +0000334* a NULL return.
335*/
joshualittb0a8a372014-09-23 09:50:21 -0700336enum GrPrimitiveEdgeType {
337 kFillBW_GrProcessorEdgeType,
338 kFillAA_GrProcessorEdgeType,
339 kInverseFillBW_GrProcessorEdgeType,
340 kInverseFillAA_GrProcessorEdgeType,
341 kHairlineAA_GrProcessorEdgeType,
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000342
joshualittb0a8a372014-09-23 09:50:21 -0700343 kLast_GrProcessorEdgeType = kHairlineAA_GrProcessorEdgeType
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000344};
345
joshualittb0a8a372014-09-23 09:50:21 -0700346static const int kGrProcessorEdgeTypeCnt = kLast_GrProcessorEdgeType + 1;
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000347
joshualittb0a8a372014-09-23 09:50:21 -0700348static inline bool GrProcessorEdgeTypeIsFill(const GrPrimitiveEdgeType edgeType) {
349 return (kFillAA_GrProcessorEdgeType == edgeType || kFillBW_GrProcessorEdgeType == edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000350}
351
joshualittb0a8a372014-09-23 09:50:21 -0700352static inline bool GrProcessorEdgeTypeIsInverseFill(const GrPrimitiveEdgeType edgeType) {
353 return (kInverseFillAA_GrProcessorEdgeType == edgeType ||
354 kInverseFillBW_GrProcessorEdgeType == edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000355}
356
joshualittb0a8a372014-09-23 09:50:21 -0700357static inline bool GrProcessorEdgeTypeIsAA(const GrPrimitiveEdgeType edgeType) {
358 return (kFillBW_GrProcessorEdgeType != edgeType && kInverseFillBW_GrProcessorEdgeType != edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000359}
360
joshualittb0a8a372014-09-23 09:50:21 -0700361static inline GrPrimitiveEdgeType GrInvertProcessorEdgeType(const GrPrimitiveEdgeType edgeType) {
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000362 switch (edgeType) {
joshualittb0a8a372014-09-23 09:50:21 -0700363 case kFillBW_GrProcessorEdgeType:
364 return kInverseFillBW_GrProcessorEdgeType;
365 case kFillAA_GrProcessorEdgeType:
366 return kInverseFillAA_GrProcessorEdgeType;
367 case kInverseFillBW_GrProcessorEdgeType:
368 return kFillBW_GrProcessorEdgeType;
369 case kInverseFillAA_GrProcessorEdgeType:
370 return kFillAA_GrProcessorEdgeType;
371 case kHairlineAA_GrProcessorEdgeType:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000372 SkFAIL("Hairline fill isn't invertible.");
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000373 }
joshualittb0a8a372014-09-23 09:50:21 -0700374 return kFillAA_GrProcessorEdgeType; // suppress warning.
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000375}
376
bsalomonbcf0a522014-10-08 08:40:09 -0700377/**
378 * Indicates the type of pending IO operations that can be recorded for gpu resources.
379 */
380enum GrIOType {
381 kRead_GrIOType,
382 kWrite_GrIOType,
383 kRW_GrIOType
384};
385
bsalomon3e791242014-12-17 13:43:13 -0800386struct GrScissorState {
387 GrScissorState() : fEnabled(false) {}
388 void set(const SkIRect& rect) { fRect = rect; fEnabled = true; }
389 bool operator==(const GrScissorState& other) const {
390 return fEnabled == other.fEnabled &&
391 (false == fEnabled || fRect == other.fRect);
392 }
393 bool operator!=(const GrScissorState& other) const { return !(*this == other); }
robertphillipse85a32d2015-02-10 08:16:55 -0800394
395 bool enabled() const { return fEnabled; }
396 const SkIRect& rect() const { return fRect; }
397
398private:
bsalomon3e791242014-12-17 13:43:13 -0800399 bool fEnabled;
400 SkIRect fRect;
401};
402
jvanverth17aa0472016-01-05 10:41:27 -0800403/**
cdalton397536c2016-03-25 12:15:03 -0700404* Indicates the type of data that a GPU buffer will be used for.
405*/
406enum GrBufferType {
407 kVertex_GrBufferType,
408 kIndex_GrBufferType,
409 kXferCpuToGpu_GrBufferType,
410 kXferGpuToCpu_GrBufferType,
411
412 kLast_GrBufferType = kXferGpuToCpu_GrBufferType
413};
414
415/**
416* Provides a performance hint regarding the frequency at which a data store will be accessed.
417*/
418enum GrAccessPattern {
419 /** Data store will be respecified repeatedly and used many times. */
420 kDynamic_GrAccessPattern,
421 /** Data store will be specified once and used many times. (Thus disqualified from caching.) */
422 kStatic_GrAccessPattern,
423 /** Data store will be specified once and used at most a few times. (Also can't be cached.) */
424 kStream_GrAccessPattern,
425
426 kLast_GrAccessPattern = kStream_GrAccessPattern
jvanverth17aa0472016-01-05 10:41:27 -0800427};
428
429
joshualitt7d022d62015-05-12 12:03:50 -0700430#ifdef SK_DEBUG
bsalomon682c2692015-05-22 14:01:46 -0700431// Takes a pointer to a GrCaps, and will suppress prints if required
432#define GrCapsDebugf(caps, ...) \
433 if (!caps->suppressPrints()) { \
434 SkDebugf(__VA_ARGS__); \
joshualitt7d022d62015-05-12 12:03:50 -0700435 }
436#else
bsalomon682c2692015-05-22 14:01:46 -0700437#define GrCapsDebugf(caps, ...)
joshualitt7d022d62015-05-12 12:03:50 -0700438#endif
439
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +0000440#endif