blob: 8c7d6bda65150b6cd055a235f136077f4897c008 [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"
bungeman06ca8ec2016-06-09 08:01:03 -070013#include "SkRefCnt.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,
cdalton8d988b32016-03-07 15:39:09 -080025 kMat22f_GrSLType,
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +000026 kMat33f_GrSLType,
27 kMat44f_GrSLType,
jvanverth@google.com054ae992013-04-01 20:06:51 +000028 kSampler2D_GrSLType,
bsalomon7ea33f52015-11-22 14:51:00 -080029 kSamplerExternal_GrSLType,
bsalomone5286e02016-01-14 09:24:09 -080030 kSampler2DRect_GrSLType,
cdalton74b8d322016-04-11 14:47:28 -070031 kSamplerBuffer_GrSLType,
ethannicholas22793252016-01-30 09:59:10 -080032 kBool_GrSLType,
33 kInt_GrSLType,
cdalton793dc262016-02-08 10:11:47 -080034 kUint_GrSLType,
jvanverth@google.com054ae992013-04-01 20:06:51 +000035
cdalton793dc262016-02-08 10:11:47 -080036 kLast_GrSLType = kUint_GrSLType
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +000037};
jvanverth@google.com054ae992013-04-01 20:06:51 +000038static const int kGrSLTypeCount = kLast_GrSLType + 1;
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +000039
bsalomon17168df2014-12-09 09:00:49 -080040enum GrShaderType {
41 kVertex_GrShaderType,
42 kGeometry_GrShaderType,
43 kFragment_GrShaderType,
44
45 kLastkFragment_GrShaderType = kFragment_GrShaderType
46};
47static const int kGrShaderTypeCount = kLastkFragment_GrShaderType + 1;
48
cdalton5e58cee2016-02-11 12:49:47 -080049enum GrShaderFlags {
50 kNone_GrShaderFlags = 0,
51 kVertex_GrShaderFlag = 1 << kVertex_GrShaderType,
52 kGeometry_GrShaderFlag = 1 << kGeometry_GrShaderType,
53 kFragment_GrShaderFlag = 1 << kFragment_GrShaderType
54};
55GR_MAKE_BITFIELD_OPS(GrShaderFlags);
56
bsalomon@google.com31ec7982013-03-27 18:14:57 +000057/**
bsalomonc0bd6482014-12-09 10:04:14 -080058 * Precisions of shader language variables. Not all shading languages support precisions or actually
bsalomon422f56f2014-12-09 10:18:12 -080059 * vary the internal precision based on the qualifiers. These currently only apply to float types (
60 * including float vectors and matrices).
bsalomonc0bd6482014-12-09 10:04:14 -080061 */
62enum GrSLPrecision {
63 kLow_GrSLPrecision,
64 kMedium_GrSLPrecision,
65 kHigh_GrSLPrecision,
66
67 // Default precision is medium. This is because on OpenGL ES 2 highp support is not
68 // guaranteed. On (non-ES) OpenGL the specifiers have no effect on precision.
69 kDefault_GrSLPrecision = kMedium_GrSLPrecision,
70
71 kLast_GrSLPrecision = kHigh_GrSLPrecision
72};
73
74static const int kGrSLPrecisionCount = kLast_GrSLPrecision + 1;
75
76/**
jvanverth@google.com054ae992013-04-01 20:06:51 +000077 * Gets the vector size of the SLType. Returns -1 for void, matrices, and samplers.
78 */
79static inline int GrSLTypeVectorCount(GrSLType type) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000080 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
cdalton74b8d322016-04-11 14:47:28 -070081 static const int kCounts[] = { -1, 1, 2, 3, 4, -1, -1, -1, -1, -1, -1, -1, 1, 1, 1 };
jvanverth@google.com054ae992013-04-01 20:06:51 +000082 return kCounts[type];
83
84 GR_STATIC_ASSERT(0 == kVoid_GrSLType);
85 GR_STATIC_ASSERT(1 == kFloat_GrSLType);
86 GR_STATIC_ASSERT(2 == kVec2f_GrSLType);
87 GR_STATIC_ASSERT(3 == kVec3f_GrSLType);
88 GR_STATIC_ASSERT(4 == kVec4f_GrSLType);
cdalton8d988b32016-03-07 15:39:09 -080089 GR_STATIC_ASSERT(5 == kMat22f_GrSLType);
90 GR_STATIC_ASSERT(6 == kMat33f_GrSLType);
91 GR_STATIC_ASSERT(7 == kMat44f_GrSLType);
92 GR_STATIC_ASSERT(8 == kSampler2D_GrSLType);
93 GR_STATIC_ASSERT(9 == kSamplerExternal_GrSLType);
94 GR_STATIC_ASSERT(10 == kSampler2DRect_GrSLType);
cdalton74b8d322016-04-11 14:47:28 -070095 GR_STATIC_ASSERT(11 == kSamplerBuffer_GrSLType);
96 GR_STATIC_ASSERT(12 == kBool_GrSLType);
97 GR_STATIC_ASSERT(13 == kInt_GrSLType);
98 GR_STATIC_ASSERT(14 == kUint_GrSLType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +000099 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCounts) == kGrSLTypeCount);
jvanverth@google.com054ae992013-04-01 20:06:51 +0000100}
101
bsalomon@google.com018f1792013-04-18 19:36:09 +0000102/** Return the type enum for a vector of floats of length n (1..4),
103 e.g. 1 -> kFloat_GrSLType, 2 -> kVec2_GrSLType, ... */
jvanverth@google.com054ae992013-04-01 20:06:51 +0000104static inline GrSLType GrSLFloatVectorType(int count) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000105 SkASSERT(count > 0 && count <= 4);
jvanverth@google.com054ae992013-04-01 20:06:51 +0000106 return (GrSLType)(count);
107
108 GR_STATIC_ASSERT(kFloat_GrSLType == 1);
109 GR_STATIC_ASSERT(kVec2f_GrSLType == 2);
110 GR_STATIC_ASSERT(kVec3f_GrSLType == 3);
111 GR_STATIC_ASSERT(kVec4f_GrSLType == 4);
112}
113
ethannicholas22793252016-01-30 09:59:10 -0800114/** Is the shading language type float (including vectors/matrices)? */
bsalomon422f56f2014-12-09 10:18:12 -0800115static inline bool GrSLTypeIsFloatType(GrSLType type) {
116 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
cdalton8d988b32016-03-07 15:39:09 -0800117 return type >= kFloat_GrSLType && type <= kMat44f_GrSLType;
bsalomon422f56f2014-12-09 10:18:12 -0800118
119 GR_STATIC_ASSERT(0 == kVoid_GrSLType);
120 GR_STATIC_ASSERT(1 == kFloat_GrSLType);
121 GR_STATIC_ASSERT(2 == kVec2f_GrSLType);
122 GR_STATIC_ASSERT(3 == kVec3f_GrSLType);
123 GR_STATIC_ASSERT(4 == kVec4f_GrSLType);
cdalton8d988b32016-03-07 15:39:09 -0800124 GR_STATIC_ASSERT(5 == kMat22f_GrSLType);
125 GR_STATIC_ASSERT(6 == kMat33f_GrSLType);
126 GR_STATIC_ASSERT(7 == kMat44f_GrSLType);
127 GR_STATIC_ASSERT(8 == kSampler2D_GrSLType);
128 GR_STATIC_ASSERT(9 == kSamplerExternal_GrSLType);
129 GR_STATIC_ASSERT(10 == kSampler2DRect_GrSLType);
cdalton74b8d322016-04-11 14:47:28 -0700130 GR_STATIC_ASSERT(11 == kSamplerBuffer_GrSLType);
131 GR_STATIC_ASSERT(12 == kBool_GrSLType);
132 GR_STATIC_ASSERT(13 == kInt_GrSLType);
133 GR_STATIC_ASSERT(14 == kUint_GrSLType);
134 GR_STATIC_ASSERT(15 == kGrSLTypeCount);
ethannicholas22793252016-01-30 09:59:10 -0800135}
136
137/** Is the shading language type integral (including vectors/matrices)? */
138static inline bool GrSLTypeIsIntType(GrSLType type) {
139 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
cdalton793dc262016-02-08 10:11:47 -0800140 return type >= kInt_GrSLType;
ethannicholas22793252016-01-30 09:59:10 -0800141
142 GR_STATIC_ASSERT(0 == kVoid_GrSLType);
143 GR_STATIC_ASSERT(1 == kFloat_GrSLType);
144 GR_STATIC_ASSERT(2 == kVec2f_GrSLType);
145 GR_STATIC_ASSERT(3 == kVec3f_GrSLType);
146 GR_STATIC_ASSERT(4 == kVec4f_GrSLType);
cdalton8d988b32016-03-07 15:39:09 -0800147 GR_STATIC_ASSERT(5 == kMat22f_GrSLType);
148 GR_STATIC_ASSERT(6 == kMat33f_GrSLType);
149 GR_STATIC_ASSERT(7 == kMat44f_GrSLType);
150 GR_STATIC_ASSERT(8 == kSampler2D_GrSLType);
151 GR_STATIC_ASSERT(9 == kSamplerExternal_GrSLType);
152 GR_STATIC_ASSERT(10 == kSampler2DRect_GrSLType);
cdalton74b8d322016-04-11 14:47:28 -0700153 GR_STATIC_ASSERT(11 == kSamplerBuffer_GrSLType);
154 GR_STATIC_ASSERT(12 == kBool_GrSLType);
155 GR_STATIC_ASSERT(13 == kInt_GrSLType);
156 GR_STATIC_ASSERT(14 == kUint_GrSLType);
157 GR_STATIC_ASSERT(15 == kGrSLTypeCount);
ethannicholas22793252016-01-30 09:59:10 -0800158}
159
160/** Is the shading language type numeric (including vectors/matrices)? */
161static inline bool GrSLTypeIsNumeric(GrSLType type) {
162 return GrSLTypeIsFloatType(type) || GrSLTypeIsIntType(type);
bsalomon422f56f2014-12-09 10:18:12 -0800163}
egdanielfa896322016-01-13 12:19:30 -0800164
165/** Returns the size in bytes for floating point GrSLTypes. For non floating point type returns 0 */
166static inline size_t GrSLTypeSize(GrSLType type) {
167 SkASSERT(GrSLTypeIsFloatType(type));
168 static const size_t kSizes[] = {
169 0, // kVoid_GrSLType
170 sizeof(float), // kFloat_GrSLType
171 2 * sizeof(float), // kVec2f_GrSLType
172 3 * sizeof(float), // kVec3f_GrSLType
173 4 * sizeof(float), // kVec4f_GrSLType
cdalton8d988b32016-03-07 15:39:09 -0800174 2 * 2 * sizeof(float), // kMat22f_GrSLType
175 3 * 3 * sizeof(float), // kMat33f_GrSLType
176 4 * 4 * sizeof(float), // kMat44f_GrSLType
egdanielfa896322016-01-13 12:19:30 -0800177 0, // kSampler2D_GrSLType
ethannicholas22793252016-01-30 09:59:10 -0800178 0, // kSamplerExternal_GrSLType
179 0, // kSampler2DRect_GrSLType
cdalton74b8d322016-04-11 14:47:28 -0700180 0, // kSamplerBuffer_GrSLType
ethannicholas22793252016-01-30 09:59:10 -0800181 0, // kBool_GrSLType
182 0, // kInt_GrSLType
cdalton793dc262016-02-08 10:11:47 -0800183 0, // kUint_GrSLType
egdanielfa896322016-01-13 12:19:30 -0800184 };
185 return kSizes[type];
186
187 GR_STATIC_ASSERT(0 == kVoid_GrSLType);
188 GR_STATIC_ASSERT(1 == kFloat_GrSLType);
189 GR_STATIC_ASSERT(2 == kVec2f_GrSLType);
190 GR_STATIC_ASSERT(3 == kVec3f_GrSLType);
191 GR_STATIC_ASSERT(4 == kVec4f_GrSLType);
cdalton8d988b32016-03-07 15:39:09 -0800192 GR_STATIC_ASSERT(5 == kMat22f_GrSLType);
193 GR_STATIC_ASSERT(6 == kMat33f_GrSLType);
194 GR_STATIC_ASSERT(7 == kMat44f_GrSLType);
195 GR_STATIC_ASSERT(8 == kSampler2D_GrSLType);
196 GR_STATIC_ASSERT(9 == kSamplerExternal_GrSLType);
197 GR_STATIC_ASSERT(10 == kSampler2DRect_GrSLType);
cdalton74b8d322016-04-11 14:47:28 -0700198 GR_STATIC_ASSERT(11 == kSamplerBuffer_GrSLType);
199 GR_STATIC_ASSERT(12 == kBool_GrSLType);
200 GR_STATIC_ASSERT(13 == kInt_GrSLType);
201 GR_STATIC_ASSERT(14 == kUint_GrSLType);
202 GR_STATIC_ASSERT(15 == kGrSLTypeCount);
bsalomone5286e02016-01-14 09:24:09 -0800203}
204
cdalton74b8d322016-04-11 14:47:28 -0700205static inline bool GrSLTypeIs2DTextureType(GrSLType type) {
bsalomone5286e02016-01-14 09:24:09 -0800206 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
cdalton8d988b32016-03-07 15:39:09 -0800207 return type >= kSampler2D_GrSLType && type <= kSampler2DRect_GrSLType;
bsalomone5286e02016-01-14 09:24:09 -0800208
cdalton8d988b32016-03-07 15:39:09 -0800209 GR_STATIC_ASSERT(8 == kSampler2D_GrSLType);
210 GR_STATIC_ASSERT(9 == kSamplerExternal_GrSLType);
211 GR_STATIC_ASSERT(10 == kSampler2DRect_GrSLType);
egdanielfa896322016-01-13 12:19:30 -0800212}
213
cdalton74b8d322016-04-11 14:47:28 -0700214static inline bool GrSLTypeIsSamplerType(GrSLType type) {
215 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
216 return type >= kSampler2D_GrSLType && type <= kSamplerBuffer_GrSLType;
217
218 GR_STATIC_ASSERT(8 == kSampler2D_GrSLType);
219 GR_STATIC_ASSERT(9 == kSamplerExternal_GrSLType);
220 GR_STATIC_ASSERT(10 == kSampler2DRect_GrSLType);
221 GR_STATIC_ASSERT(11 == kSamplerBuffer_GrSLType);
222}
223
cdalton5f2d8e22016-03-11 13:34:32 -0800224static inline bool GrSLTypeAcceptsPrecision(GrSLType type) {
225 return GrSLTypeIsNumeric(type) || GrSLTypeIsSamplerType(type);
226}
227
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000228//////////////////////////////////////////////////////////////////////////////
229
jvanverth@google.com054ae992013-04-01 20:06:51 +0000230/**
231 * Types used to describe format of vertices in arrays.
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000232 */
233enum GrVertexAttribType {
234 kFloat_GrVertexAttribType = 0,
235 kVec2f_GrVertexAttribType,
236 kVec3f_GrVertexAttribType,
237 kVec4f_GrVertexAttribType,
egdaniel37b4d862014-11-03 10:07:07 -0800238
239 kUByte_GrVertexAttribType, // unsigned byte, e.g. coverage
jvanverth5a105ff2015-02-18 11:36:35 -0800240 kVec4ub_GrVertexAttribType, // vector of 4 unsigned bytes, e.g. colors
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000241
jvanverth7023a002016-02-22 11:25:32 -0800242 kVec2us_GrVertexAttribType, // vector of 2 shorts, e.g. texture coordinates
ethannicholas22793252016-01-30 09:59:10 -0800243
244 kInt_GrVertexAttribType,
cdalton793dc262016-02-08 10:11:47 -0800245 kUint_GrVertexAttribType,
jvanverth5a105ff2015-02-18 11:36:35 -0800246
cdalton793dc262016-02-08 10:11:47 -0800247 kLast_GrVertexAttribType = kUint_GrVertexAttribType
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000248};
249static const int kGrVertexAttribTypeCount = kLast_GrVertexAttribType + 1;
250
jvanverth@google.com054ae992013-04-01 20:06:51 +0000251/**
252 * Returns the vector size of the type.
253 */
254static inline int GrVertexAttribTypeVectorCount(GrVertexAttribType type) {
cdalton793dc262016-02-08 10:11:47 -0800255 SkASSERT(type >= 0 && type < kGrVertexAttribTypeCount);
256 static const int kCounts[] = { 1, 2, 3, 4, 1, 4, 2, 1, 1 };
jvanverth@google.com054ae992013-04-01 20:06:51 +0000257 return kCounts[type];
258
259 GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType);
260 GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType);
261 GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType);
262 GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType);
egdaniel37b4d862014-11-03 10:07:07 -0800263 GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType);
264 GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType);
jvanverth7023a002016-02-22 11:25:32 -0800265 GR_STATIC_ASSERT(6 == kVec2us_GrVertexAttribType);
ethannicholas22793252016-01-30 09:59:10 -0800266 GR_STATIC_ASSERT(7 == kInt_GrVertexAttribType);
cdalton793dc262016-02-08 10:11:47 -0800267 GR_STATIC_ASSERT(8 == kUint_GrVertexAttribType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000268 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCounts) == kGrVertexAttribTypeCount);
jvanverth@google.com054ae992013-04-01 20:06:51 +0000269}
270
271/**
272 * Returns the size of the attrib type in bytes.
273 */
274static inline size_t GrVertexAttribTypeSize(GrVertexAttribType type) {
jvanverth@google.com054ae992013-04-01 20:06:51 +0000275 static const size_t kSizes[] = {
276 sizeof(float), // kFloat_GrVertexAttribType
277 2*sizeof(float), // kVec2f_GrVertexAttribType
278 3*sizeof(float), // kVec3f_GrVertexAttribType
279 4*sizeof(float), // kVec4f_GrVertexAttribType
egdaniel37b4d862014-11-03 10:07:07 -0800280 1*sizeof(char), // kUByte_GrVertexAttribType
jvanverth5a105ff2015-02-18 11:36:35 -0800281 4*sizeof(char), // kVec4ub_GrVertexAttribType
jvanverth7023a002016-02-22 11:25:32 -0800282 2*sizeof(int16_t), // kVec2us_GrVertexAttribType
cdalton793dc262016-02-08 10:11:47 -0800283 sizeof(int32_t), // kInt_GrVertexAttribType
284 sizeof(uint32_t) // kUint_GrVertexAttribType
jvanverth@google.com054ae992013-04-01 20:06:51 +0000285 };
286 return kSizes[type];
287
288 GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType);
289 GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType);
290 GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType);
291 GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType);
egdaniel37b4d862014-11-03 10:07:07 -0800292 GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType);
293 GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType);
jvanverth7023a002016-02-22 11:25:32 -0800294 GR_STATIC_ASSERT(6 == kVec2us_GrVertexAttribType);
ethannicholas22793252016-01-30 09:59:10 -0800295 GR_STATIC_ASSERT(7 == kInt_GrVertexAttribType);
cdalton793dc262016-02-08 10:11:47 -0800296 GR_STATIC_ASSERT(8 == kUint_GrVertexAttribType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000297 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kSizes) == kGrVertexAttribTypeCount);
jvanverth@google.com054ae992013-04-01 20:06:51 +0000298}
299
300/**
cdalton793dc262016-02-08 10:11:47 -0800301 * Is the attrib type integral?
302 */
303static inline bool GrVertexAttribTypeIsIntType(GrVertexAttribType type) {
304 SkASSERT(type >= 0 && type < static_cast<GrVertexAttribType>(kGrVertexAttribTypeCount));
305 return type >= kInt_GrVertexAttribType;
306
307 GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType);
308 GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType);
309 GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType);
310 GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType);
311 GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType);
312 GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType);
jvanverth7023a002016-02-22 11:25:32 -0800313 GR_STATIC_ASSERT(6 == kVec2us_GrVertexAttribType);
cdalton793dc262016-02-08 10:11:47 -0800314 GR_STATIC_ASSERT(7 == kInt_GrVertexAttribType);
315 GR_STATIC_ASSERT(8 == kUint_GrVertexAttribType);
316 GR_STATIC_ASSERT(9 == kGrVertexAttribTypeCount);
317}
318
319/**
joshualitt2dd1ae02014-12-03 06:24:10 -0800320 * converts a GrVertexAttribType to a GrSLType
jvanverth@google.com054ae992013-04-01 20:06:51 +0000321 */
joshualitt2dd1ae02014-12-03 06:24:10 -0800322static inline GrSLType GrVertexAttribTypeToSLType(GrVertexAttribType type) {
323 switch (type) {
324 default:
325 SkFAIL("Unsupported type conversion");
tzikbc7d2352016-01-05 00:35:50 -0800326 return kVoid_GrSLType;
joshualitt2dd1ae02014-12-03 06:24:10 -0800327 case kUByte_GrVertexAttribType:
328 case kFloat_GrVertexAttribType:
329 return kFloat_GrSLType;
jvanverth7023a002016-02-22 11:25:32 -0800330 case kVec2us_GrVertexAttribType:
joshualitt2dd1ae02014-12-03 06:24:10 -0800331 case kVec2f_GrVertexAttribType:
332 return kVec2f_GrSLType;
333 case kVec3f_GrVertexAttribType:
334 return kVec3f_GrSLType;
335 case kVec4ub_GrVertexAttribType:
336 case kVec4f_GrVertexAttribType:
337 return kVec4f_GrSLType;
ethannicholas22793252016-01-30 09:59:10 -0800338 case kInt_GrVertexAttribType:
339 return kInt_GrSLType;
cdalton793dc262016-02-08 10:11:47 -0800340 case kUint_GrVertexAttribType:
341 return kUint_GrSLType;
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000342 }
joshualitt2dd1ae02014-12-03 06:24:10 -0800343}
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000344
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000345//////////////////////////////////////////////////////////////////////////////
346
347/**
348* We have coverage effects that clip rendering to the edge of some geometric primitive.
skia.committer@gmail.com06acb582014-03-06 03:02:32 +0000349* This enum specifies how that clipping is performed. Not all factories that take a
joshualittb0a8a372014-09-23 09:50:21 -0700350* 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 +0000351* a NULL return.
352*/
joshualittb0a8a372014-09-23 09:50:21 -0700353enum GrPrimitiveEdgeType {
354 kFillBW_GrProcessorEdgeType,
355 kFillAA_GrProcessorEdgeType,
356 kInverseFillBW_GrProcessorEdgeType,
357 kInverseFillAA_GrProcessorEdgeType,
358 kHairlineAA_GrProcessorEdgeType,
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000359
joshualittb0a8a372014-09-23 09:50:21 -0700360 kLast_GrProcessorEdgeType = kHairlineAA_GrProcessorEdgeType
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000361};
362
joshualittb0a8a372014-09-23 09:50:21 -0700363static const int kGrProcessorEdgeTypeCnt = kLast_GrProcessorEdgeType + 1;
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000364
joshualittb0a8a372014-09-23 09:50:21 -0700365static inline bool GrProcessorEdgeTypeIsFill(const GrPrimitiveEdgeType edgeType) {
366 return (kFillAA_GrProcessorEdgeType == edgeType || kFillBW_GrProcessorEdgeType == edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000367}
368
joshualittb0a8a372014-09-23 09:50:21 -0700369static inline bool GrProcessorEdgeTypeIsInverseFill(const GrPrimitiveEdgeType edgeType) {
370 return (kInverseFillAA_GrProcessorEdgeType == edgeType ||
371 kInverseFillBW_GrProcessorEdgeType == edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000372}
373
joshualittb0a8a372014-09-23 09:50:21 -0700374static inline bool GrProcessorEdgeTypeIsAA(const GrPrimitiveEdgeType edgeType) {
375 return (kFillBW_GrProcessorEdgeType != edgeType && kInverseFillBW_GrProcessorEdgeType != edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000376}
377
joshualittb0a8a372014-09-23 09:50:21 -0700378static inline GrPrimitiveEdgeType GrInvertProcessorEdgeType(const GrPrimitiveEdgeType edgeType) {
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000379 switch (edgeType) {
joshualittb0a8a372014-09-23 09:50:21 -0700380 case kFillBW_GrProcessorEdgeType:
381 return kInverseFillBW_GrProcessorEdgeType;
382 case kFillAA_GrProcessorEdgeType:
383 return kInverseFillAA_GrProcessorEdgeType;
384 case kInverseFillBW_GrProcessorEdgeType:
385 return kFillBW_GrProcessorEdgeType;
386 case kInverseFillAA_GrProcessorEdgeType:
387 return kFillAA_GrProcessorEdgeType;
388 case kHairlineAA_GrProcessorEdgeType:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000389 SkFAIL("Hairline fill isn't invertible.");
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000390 }
joshualittb0a8a372014-09-23 09:50:21 -0700391 return kFillAA_GrProcessorEdgeType; // suppress warning.
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000392}
393
bsalomonbcf0a522014-10-08 08:40:09 -0700394/**
395 * Indicates the type of pending IO operations that can be recorded for gpu resources.
396 */
397enum GrIOType {
398 kRead_GrIOType,
399 kWrite_GrIOType,
400 kRW_GrIOType
401};
402
bsalomon3e791242014-12-17 13:43:13 -0800403struct GrScissorState {
404 GrScissorState() : fEnabled(false) {}
cdalton846c0512016-05-13 10:25:00 -0700405 GrScissorState(const SkIRect& rect) : fEnabled(true), fRect(rect) {}
406 void setDisabled() { fEnabled = false; }
bsalomon3e791242014-12-17 13:43:13 -0800407 void set(const SkIRect& rect) { fRect = rect; fEnabled = true; }
408 bool operator==(const GrScissorState& other) const {
409 return fEnabled == other.fEnabled &&
410 (false == fEnabled || fRect == other.fRect);
411 }
412 bool operator!=(const GrScissorState& other) const { return !(*this == other); }
robertphillipse85a32d2015-02-10 08:16:55 -0800413
414 bool enabled() const { return fEnabled; }
415 const SkIRect& rect() const { return fRect; }
416
417private:
bsalomon3e791242014-12-17 13:43:13 -0800418 bool fEnabled;
419 SkIRect fRect;
420};
421
jvanverth17aa0472016-01-05 10:41:27 -0800422/**
cdalton397536c2016-03-25 12:15:03 -0700423* Indicates the type of data that a GPU buffer will be used for.
424*/
425enum GrBufferType {
426 kVertex_GrBufferType,
427 kIndex_GrBufferType,
cdaltone2e71c22016-04-07 18:13:29 -0700428 kTexel_GrBufferType,
429 kDrawIndirect_GrBufferType,
cdalton397536c2016-03-25 12:15:03 -0700430 kXferCpuToGpu_GrBufferType,
431 kXferGpuToCpu_GrBufferType,
432
433 kLast_GrBufferType = kXferGpuToCpu_GrBufferType
434};
cdaltone2e71c22016-04-07 18:13:29 -0700435static const int kGrBufferTypeCount = kLast_GrBufferType + 1;
436
437static inline bool GrBufferTypeIsVertexOrIndex(GrBufferType type) {
438 SkASSERT(type >= 0 && type < kGrBufferTypeCount);
439 return type <= kIndex_GrBufferType;
440
441 GR_STATIC_ASSERT(0 == kVertex_GrBufferType);
442 GR_STATIC_ASSERT(1 == kIndex_GrBufferType);
443}
cdalton397536c2016-03-25 12:15:03 -0700444
445/**
446* Provides a performance hint regarding the frequency at which a data store will be accessed.
447*/
448enum GrAccessPattern {
449 /** Data store will be respecified repeatedly and used many times. */
450 kDynamic_GrAccessPattern,
451 /** Data store will be specified once and used many times. (Thus disqualified from caching.) */
452 kStatic_GrAccessPattern,
453 /** Data store will be specified once and used at most a few times. (Also can't be cached.) */
454 kStream_GrAccessPattern,
455
456 kLast_GrAccessPattern = kStream_GrAccessPattern
jvanverth17aa0472016-01-05 10:41:27 -0800457};
458
459
joshualitt7d022d62015-05-12 12:03:50 -0700460#ifdef SK_DEBUG
bsalomon682c2692015-05-22 14:01:46 -0700461// Takes a pointer to a GrCaps, and will suppress prints if required
462#define GrCapsDebugf(caps, ...) \
463 if (!caps->suppressPrints()) { \
464 SkDebugf(__VA_ARGS__); \
joshualitt7d022d62015-05-12 12:03:50 -0700465 }
466#else
bsalomon682c2692015-05-22 14:01:46 -0700467#define GrCapsDebugf(caps, ...)
joshualitt7d022d62015-05-12 12:03:50 -0700468#endif
469
kkinnunen2e6055b2016-04-22 01:48:29 -0700470/**
471 * Specifies if the holder owns the backend, OpenGL or Vulkan, object.
472 */
473enum class GrBackendObjectOwnership : bool {
474 /** Holder does not destroy the backend object. */
475 kBorrowed = false,
476 /** Holder destroys the backend object. */
477 kOwned = true
478};
479
bungeman06ca8ec2016-06-09 08:01:03 -0700480template <typename T> T * const * sk_sp_address_as_pointer_address(sk_sp<T> const * sp) {
481 static_assert(sizeof(T*) == sizeof(sk_sp<T>), "sk_sp not expected size.");
482 return reinterpret_cast<T * const *>(sp);
483}
484
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +0000485#endif