blob: d60fab13378bc031343c3a930d4fec4d20a7786e [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"
bungeman06ca8ec2016-06-09 08:01:03 -070012#include "SkRefCnt.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,
egdaniel990dbc82016-07-13 14:09:30 -070027 kTexture2DSampler_GrSLType,
28 kTextureExternalSampler_GrSLType,
29 kTexture2DRectSampler_GrSLType,
30 kTextureBufferSampler_GrSLType,
ethannicholas22793252016-01-30 09:59:10 -080031 kBool_GrSLType,
32 kInt_GrSLType,
cdalton793dc262016-02-08 10:11:47 -080033 kUint_GrSLType,
egdaniel990dbc82016-07-13 14:09:30 -070034 kTexture2D_GrSLType,
35 kSampler_GrSLType,
jvanverth@google.com054ae992013-04-01 20:06:51 +000036
egdaniel990dbc82016-07-13 14:09:30 -070037 kLast_GrSLType = kSampler_GrSLType
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +000038};
jvanverth@google.com054ae992013-04-01 20:06:51 +000039static const int kGrSLTypeCount = kLast_GrSLType + 1;
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +000040
bsalomon17168df2014-12-09 09:00:49 -080041enum GrShaderType {
42 kVertex_GrShaderType,
43 kGeometry_GrShaderType,
44 kFragment_GrShaderType,
45
46 kLastkFragment_GrShaderType = kFragment_GrShaderType
47};
48static const int kGrShaderTypeCount = kLastkFragment_GrShaderType + 1;
49
cdalton5e58cee2016-02-11 12:49:47 -080050enum GrShaderFlags {
51 kNone_GrShaderFlags = 0,
52 kVertex_GrShaderFlag = 1 << kVertex_GrShaderType,
53 kGeometry_GrShaderFlag = 1 << kGeometry_GrShaderType,
54 kFragment_GrShaderFlag = 1 << kFragment_GrShaderType
55};
56GR_MAKE_BITFIELD_OPS(GrShaderFlags);
57
robertphillips5fa7f302016-07-21 09:21:04 -070058enum class GrDrawFace {
59 kInvalid = -1,
60
61 kBoth,
62 kCCW,
63 kCW,
64};
65
bsalomon@google.com31ec7982013-03-27 18:14:57 +000066/**
bsalomonc0bd6482014-12-09 10:04:14 -080067 * Precisions of shader language variables. Not all shading languages support precisions or actually
bsalomon422f56f2014-12-09 10:18:12 -080068 * vary the internal precision based on the qualifiers. These currently only apply to float types (
69 * including float vectors and matrices).
bsalomonc0bd6482014-12-09 10:04:14 -080070 */
71enum GrSLPrecision {
72 kLow_GrSLPrecision,
73 kMedium_GrSLPrecision,
74 kHigh_GrSLPrecision,
75
76 // Default precision is medium. This is because on OpenGL ES 2 highp support is not
77 // guaranteed. On (non-ES) OpenGL the specifiers have no effect on precision.
78 kDefault_GrSLPrecision = kMedium_GrSLPrecision,
79
80 kLast_GrSLPrecision = kHigh_GrSLPrecision
81};
82
83static const int kGrSLPrecisionCount = kLast_GrSLPrecision + 1;
84
85/**
jvanverth@google.com054ae992013-04-01 20:06:51 +000086 * Gets the vector size of the SLType. Returns -1 for void, matrices, and samplers.
87 */
88static inline int GrSLTypeVectorCount(GrSLType type) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000089 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
egdaniel990dbc82016-07-13 14:09:30 -070090 static const int kCounts[] = { -1, 1, 2, 3, 4, -1, -1, -1, -1, -1, -1, -1, 1, 1, 1, -1, -1 };
jvanverth@google.com054ae992013-04-01 20:06:51 +000091 return kCounts[type];
92
93 GR_STATIC_ASSERT(0 == kVoid_GrSLType);
94 GR_STATIC_ASSERT(1 == kFloat_GrSLType);
95 GR_STATIC_ASSERT(2 == kVec2f_GrSLType);
96 GR_STATIC_ASSERT(3 == kVec3f_GrSLType);
97 GR_STATIC_ASSERT(4 == kVec4f_GrSLType);
cdalton8d988b32016-03-07 15:39:09 -080098 GR_STATIC_ASSERT(5 == kMat22f_GrSLType);
99 GR_STATIC_ASSERT(6 == kMat33f_GrSLType);
100 GR_STATIC_ASSERT(7 == kMat44f_GrSLType);
egdaniel990dbc82016-07-13 14:09:30 -0700101 GR_STATIC_ASSERT(8 == kTexture2DSampler_GrSLType);
102 GR_STATIC_ASSERT(9 == kTextureExternalSampler_GrSLType);
103 GR_STATIC_ASSERT(10 == kTexture2DRectSampler_GrSLType);
104 GR_STATIC_ASSERT(11 == kTextureBufferSampler_GrSLType);
cdalton74b8d322016-04-11 14:47:28 -0700105 GR_STATIC_ASSERT(12 == kBool_GrSLType);
106 GR_STATIC_ASSERT(13 == kInt_GrSLType);
107 GR_STATIC_ASSERT(14 == kUint_GrSLType);
egdaniel990dbc82016-07-13 14:09:30 -0700108 GR_STATIC_ASSERT(15 == kTexture2D_GrSLType);
109 GR_STATIC_ASSERT(16 == kSampler_GrSLType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000110 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCounts) == kGrSLTypeCount);
jvanverth@google.com054ae992013-04-01 20:06:51 +0000111}
112
bsalomon@google.com018f1792013-04-18 19:36:09 +0000113/** Return the type enum for a vector of floats of length n (1..4),
114 e.g. 1 -> kFloat_GrSLType, 2 -> kVec2_GrSLType, ... */
jvanverth@google.com054ae992013-04-01 20:06:51 +0000115static inline GrSLType GrSLFloatVectorType(int count) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000116 SkASSERT(count > 0 && count <= 4);
jvanverth@google.com054ae992013-04-01 20:06:51 +0000117 return (GrSLType)(count);
118
119 GR_STATIC_ASSERT(kFloat_GrSLType == 1);
120 GR_STATIC_ASSERT(kVec2f_GrSLType == 2);
121 GR_STATIC_ASSERT(kVec3f_GrSLType == 3);
122 GR_STATIC_ASSERT(kVec4f_GrSLType == 4);
123}
124
ethannicholas22793252016-01-30 09:59:10 -0800125/** Is the shading language type float (including vectors/matrices)? */
bsalomon422f56f2014-12-09 10:18:12 -0800126static inline bool GrSLTypeIsFloatType(GrSLType type) {
127 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
cdalton8d988b32016-03-07 15:39:09 -0800128 return type >= kFloat_GrSLType && type <= kMat44f_GrSLType;
bsalomon422f56f2014-12-09 10:18:12 -0800129
130 GR_STATIC_ASSERT(0 == kVoid_GrSLType);
131 GR_STATIC_ASSERT(1 == kFloat_GrSLType);
132 GR_STATIC_ASSERT(2 == kVec2f_GrSLType);
133 GR_STATIC_ASSERT(3 == kVec3f_GrSLType);
134 GR_STATIC_ASSERT(4 == kVec4f_GrSLType);
cdalton8d988b32016-03-07 15:39:09 -0800135 GR_STATIC_ASSERT(5 == kMat22f_GrSLType);
136 GR_STATIC_ASSERT(6 == kMat33f_GrSLType);
137 GR_STATIC_ASSERT(7 == kMat44f_GrSLType);
egdaniel990dbc82016-07-13 14:09:30 -0700138 GR_STATIC_ASSERT(8 == kTexture2DSampler_GrSLType);
139 GR_STATIC_ASSERT(9 == kTextureExternalSampler_GrSLType);
140 GR_STATIC_ASSERT(10 == kTexture2DRectSampler_GrSLType);
141 GR_STATIC_ASSERT(11 == kTextureBufferSampler_GrSLType);
cdalton74b8d322016-04-11 14:47:28 -0700142 GR_STATIC_ASSERT(12 == kBool_GrSLType);
143 GR_STATIC_ASSERT(13 == kInt_GrSLType);
144 GR_STATIC_ASSERT(14 == kUint_GrSLType);
egdaniel990dbc82016-07-13 14:09:30 -0700145 GR_STATIC_ASSERT(15 == kTexture2D_GrSLType);
146 GR_STATIC_ASSERT(16 == kSampler_GrSLType);
147 GR_STATIC_ASSERT(17 == kGrSLTypeCount);
ethannicholas22793252016-01-30 09:59:10 -0800148}
149
150/** Is the shading language type integral (including vectors/matrices)? */
151static inline bool GrSLTypeIsIntType(GrSLType type) {
152 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
egdaniel990dbc82016-07-13 14:09:30 -0700153 return type >= kInt_GrSLType && type <= kUint_GrSLType;
ethannicholas22793252016-01-30 09:59:10 -0800154
155 GR_STATIC_ASSERT(0 == kVoid_GrSLType);
156 GR_STATIC_ASSERT(1 == kFloat_GrSLType);
157 GR_STATIC_ASSERT(2 == kVec2f_GrSLType);
158 GR_STATIC_ASSERT(3 == kVec3f_GrSLType);
159 GR_STATIC_ASSERT(4 == kVec4f_GrSLType);
cdalton8d988b32016-03-07 15:39:09 -0800160 GR_STATIC_ASSERT(5 == kMat22f_GrSLType);
161 GR_STATIC_ASSERT(6 == kMat33f_GrSLType);
162 GR_STATIC_ASSERT(7 == kMat44f_GrSLType);
egdaniel990dbc82016-07-13 14:09:30 -0700163 GR_STATIC_ASSERT(8 == kTexture2DSampler_GrSLType);
164 GR_STATIC_ASSERT(9 == kTextureExternalSampler_GrSLType);
165 GR_STATIC_ASSERT(10 == kTexture2DRectSampler_GrSLType);
166 GR_STATIC_ASSERT(11 == kTextureBufferSampler_GrSLType);
cdalton74b8d322016-04-11 14:47:28 -0700167 GR_STATIC_ASSERT(12 == kBool_GrSLType);
168 GR_STATIC_ASSERT(13 == kInt_GrSLType);
169 GR_STATIC_ASSERT(14 == kUint_GrSLType);
egdaniel990dbc82016-07-13 14:09:30 -0700170 GR_STATIC_ASSERT(15 == kTexture2D_GrSLType);
171 GR_STATIC_ASSERT(16 == kSampler_GrSLType);
172 GR_STATIC_ASSERT(17 == kGrSLTypeCount);
ethannicholas22793252016-01-30 09:59:10 -0800173}
174
175/** Is the shading language type numeric (including vectors/matrices)? */
176static inline bool GrSLTypeIsNumeric(GrSLType type) {
177 return GrSLTypeIsFloatType(type) || GrSLTypeIsIntType(type);
bsalomon422f56f2014-12-09 10:18:12 -0800178}
egdanielfa896322016-01-13 12:19:30 -0800179
180/** Returns the size in bytes for floating point GrSLTypes. For non floating point type returns 0 */
181static inline size_t GrSLTypeSize(GrSLType type) {
182 SkASSERT(GrSLTypeIsFloatType(type));
183 static const size_t kSizes[] = {
184 0, // kVoid_GrSLType
185 sizeof(float), // kFloat_GrSLType
186 2 * sizeof(float), // kVec2f_GrSLType
187 3 * sizeof(float), // kVec3f_GrSLType
188 4 * sizeof(float), // kVec4f_GrSLType
cdalton8d988b32016-03-07 15:39:09 -0800189 2 * 2 * sizeof(float), // kMat22f_GrSLType
190 3 * 3 * sizeof(float), // kMat33f_GrSLType
191 4 * 4 * sizeof(float), // kMat44f_GrSLType
egdaniel990dbc82016-07-13 14:09:30 -0700192 0, // kTexture2DSampler_GrSLType
193 0, // kTextureExternalSampler_GrSLType
194 0, // kTexture2DRectSampler_GrSLType
195 0, // kTextureBufferSampler_GrSLType
ethannicholas22793252016-01-30 09:59:10 -0800196 0, // kBool_GrSLType
197 0, // kInt_GrSLType
cdalton793dc262016-02-08 10:11:47 -0800198 0, // kUint_GrSLType
egdaniel990dbc82016-07-13 14:09:30 -0700199 0, // kTexture2D_GrSLType
200 0, // kSampler_GrSLType
egdanielfa896322016-01-13 12:19:30 -0800201 };
202 return kSizes[type];
203
204 GR_STATIC_ASSERT(0 == kVoid_GrSLType);
205 GR_STATIC_ASSERT(1 == kFloat_GrSLType);
206 GR_STATIC_ASSERT(2 == kVec2f_GrSLType);
207 GR_STATIC_ASSERT(3 == kVec3f_GrSLType);
208 GR_STATIC_ASSERT(4 == kVec4f_GrSLType);
cdalton8d988b32016-03-07 15:39:09 -0800209 GR_STATIC_ASSERT(5 == kMat22f_GrSLType);
210 GR_STATIC_ASSERT(6 == kMat33f_GrSLType);
211 GR_STATIC_ASSERT(7 == kMat44f_GrSLType);
egdaniel990dbc82016-07-13 14:09:30 -0700212 GR_STATIC_ASSERT(8 == kTexture2DSampler_GrSLType);
213 GR_STATIC_ASSERT(9 == kTextureExternalSampler_GrSLType);
214 GR_STATIC_ASSERT(10 == kTexture2DRectSampler_GrSLType);
215 GR_STATIC_ASSERT(11 == kTextureBufferSampler_GrSLType);
cdalton74b8d322016-04-11 14:47:28 -0700216 GR_STATIC_ASSERT(12 == kBool_GrSLType);
217 GR_STATIC_ASSERT(13 == kInt_GrSLType);
218 GR_STATIC_ASSERT(14 == kUint_GrSLType);
egdaniel990dbc82016-07-13 14:09:30 -0700219 GR_STATIC_ASSERT(15 == kTexture2D_GrSLType);
220 GR_STATIC_ASSERT(16 == kSampler_GrSLType);
221 GR_STATIC_ASSERT(17 == kGrSLTypeCount);
bsalomone5286e02016-01-14 09:24:09 -0800222}
223
egdaniel990dbc82016-07-13 14:09:30 -0700224static inline bool GrSLTypeIs2DCombinedSamplerType(GrSLType type) {
bsalomone5286e02016-01-14 09:24:09 -0800225 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
egdaniel990dbc82016-07-13 14:09:30 -0700226 return type >= kTexture2DSampler_GrSLType && type <= kTexture2DRectSampler_GrSLType;
bsalomone5286e02016-01-14 09:24:09 -0800227
egdaniel990dbc82016-07-13 14:09:30 -0700228 GR_STATIC_ASSERT(8 == kTexture2DSampler_GrSLType);
229 GR_STATIC_ASSERT(9 == kTextureExternalSampler_GrSLType);
230 GR_STATIC_ASSERT(10 == kTexture2DRectSampler_GrSLType);
egdanielfa896322016-01-13 12:19:30 -0800231}
232
egdaniel990dbc82016-07-13 14:09:30 -0700233static inline bool GrSLTypeIsCombinedSamplerType(GrSLType type) {
cdalton74b8d322016-04-11 14:47:28 -0700234 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
egdaniel990dbc82016-07-13 14:09:30 -0700235 return type >= kTexture2DSampler_GrSLType && type <= kTextureBufferSampler_GrSLType;
cdalton74b8d322016-04-11 14:47:28 -0700236
egdaniel990dbc82016-07-13 14:09:30 -0700237 GR_STATIC_ASSERT(8 == kTexture2DSampler_GrSLType);
238 GR_STATIC_ASSERT(9 == kTextureExternalSampler_GrSLType);
239 GR_STATIC_ASSERT(10 == kTexture2DRectSampler_GrSLType);
240 GR_STATIC_ASSERT(11 == kTextureBufferSampler_GrSLType);
cdalton74b8d322016-04-11 14:47:28 -0700241}
242
cdalton5f2d8e22016-03-11 13:34:32 -0800243static inline bool GrSLTypeAcceptsPrecision(GrSLType type) {
egdaniel990dbc82016-07-13 14:09:30 -0700244 return type != kVoid_GrSLType && type != kBool_GrSLType;
cdalton5f2d8e22016-03-11 13:34:32 -0800245}
246
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000247//////////////////////////////////////////////////////////////////////////////
248
jvanverth@google.com054ae992013-04-01 20:06:51 +0000249/**
250 * Types used to describe format of vertices in arrays.
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000251 */
252enum GrVertexAttribType {
253 kFloat_GrVertexAttribType = 0,
254 kVec2f_GrVertexAttribType,
255 kVec3f_GrVertexAttribType,
256 kVec4f_GrVertexAttribType,
egdaniel37b4d862014-11-03 10:07:07 -0800257
258 kUByte_GrVertexAttribType, // unsigned byte, e.g. coverage
jvanverth5a105ff2015-02-18 11:36:35 -0800259 kVec4ub_GrVertexAttribType, // vector of 4 unsigned bytes, e.g. colors
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000260
jvanverth7023a002016-02-22 11:25:32 -0800261 kVec2us_GrVertexAttribType, // vector of 2 shorts, e.g. texture coordinates
ethannicholas22793252016-01-30 09:59:10 -0800262
263 kInt_GrVertexAttribType,
cdalton793dc262016-02-08 10:11:47 -0800264 kUint_GrVertexAttribType,
egdaniel990dbc82016-07-13 14:09:30 -0700265
cdalton793dc262016-02-08 10:11:47 -0800266 kLast_GrVertexAttribType = kUint_GrVertexAttribType
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000267};
268static const int kGrVertexAttribTypeCount = kLast_GrVertexAttribType + 1;
269
jvanverth@google.com054ae992013-04-01 20:06:51 +0000270/**
271 * Returns the vector size of the type.
272 */
273static inline int GrVertexAttribTypeVectorCount(GrVertexAttribType type) {
cdalton793dc262016-02-08 10:11:47 -0800274 SkASSERT(type >= 0 && type < kGrVertexAttribTypeCount);
275 static const int kCounts[] = { 1, 2, 3, 4, 1, 4, 2, 1, 1 };
jvanverth@google.com054ae992013-04-01 20:06:51 +0000276 return kCounts[type];
277
278 GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType);
279 GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType);
280 GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType);
281 GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType);
egdaniel37b4d862014-11-03 10:07:07 -0800282 GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType);
283 GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType);
jvanverth7023a002016-02-22 11:25:32 -0800284 GR_STATIC_ASSERT(6 == kVec2us_GrVertexAttribType);
ethannicholas22793252016-01-30 09:59:10 -0800285 GR_STATIC_ASSERT(7 == kInt_GrVertexAttribType);
cdalton793dc262016-02-08 10:11:47 -0800286 GR_STATIC_ASSERT(8 == kUint_GrVertexAttribType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000287 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCounts) == kGrVertexAttribTypeCount);
jvanverth@google.com054ae992013-04-01 20:06:51 +0000288}
289
290/**
291 * Returns the size of the attrib type in bytes.
292 */
293static inline size_t GrVertexAttribTypeSize(GrVertexAttribType type) {
jvanverth@google.com054ae992013-04-01 20:06:51 +0000294 static const size_t kSizes[] = {
295 sizeof(float), // kFloat_GrVertexAttribType
296 2*sizeof(float), // kVec2f_GrVertexAttribType
297 3*sizeof(float), // kVec3f_GrVertexAttribType
298 4*sizeof(float), // kVec4f_GrVertexAttribType
egdaniel37b4d862014-11-03 10:07:07 -0800299 1*sizeof(char), // kUByte_GrVertexAttribType
jvanverth5a105ff2015-02-18 11:36:35 -0800300 4*sizeof(char), // kVec4ub_GrVertexAttribType
jvanverth7023a002016-02-22 11:25:32 -0800301 2*sizeof(int16_t), // kVec2us_GrVertexAttribType
cdalton793dc262016-02-08 10:11:47 -0800302 sizeof(int32_t), // kInt_GrVertexAttribType
303 sizeof(uint32_t) // kUint_GrVertexAttribType
jvanverth@google.com054ae992013-04-01 20:06:51 +0000304 };
305 return kSizes[type];
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);
egdaniel37b4d862014-11-03 10:07:07 -0800311 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);
ethannicholas22793252016-01-30 09:59:10 -0800314 GR_STATIC_ASSERT(7 == kInt_GrVertexAttribType);
cdalton793dc262016-02-08 10:11:47 -0800315 GR_STATIC_ASSERT(8 == kUint_GrVertexAttribType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000316 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kSizes) == kGrVertexAttribTypeCount);
jvanverth@google.com054ae992013-04-01 20:06:51 +0000317}
318
319/**
cdalton793dc262016-02-08 10:11:47 -0800320 * Is the attrib type integral?
321 */
322static inline bool GrVertexAttribTypeIsIntType(GrVertexAttribType type) {
323 SkASSERT(type >= 0 && type < static_cast<GrVertexAttribType>(kGrVertexAttribTypeCount));
324 return type >= kInt_GrVertexAttribType;
325
326 GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType);
327 GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType);
328 GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType);
329 GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType);
330 GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType);
331 GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType);
jvanverth7023a002016-02-22 11:25:32 -0800332 GR_STATIC_ASSERT(6 == kVec2us_GrVertexAttribType);
cdalton793dc262016-02-08 10:11:47 -0800333 GR_STATIC_ASSERT(7 == kInt_GrVertexAttribType);
334 GR_STATIC_ASSERT(8 == kUint_GrVertexAttribType);
335 GR_STATIC_ASSERT(9 == kGrVertexAttribTypeCount);
336}
337
338/**
joshualitt2dd1ae02014-12-03 06:24:10 -0800339 * converts a GrVertexAttribType to a GrSLType
jvanverth@google.com054ae992013-04-01 20:06:51 +0000340 */
joshualitt2dd1ae02014-12-03 06:24:10 -0800341static inline GrSLType GrVertexAttribTypeToSLType(GrVertexAttribType type) {
342 switch (type) {
343 default:
344 SkFAIL("Unsupported type conversion");
tzikbc7d2352016-01-05 00:35:50 -0800345 return kVoid_GrSLType;
joshualitt2dd1ae02014-12-03 06:24:10 -0800346 case kUByte_GrVertexAttribType:
347 case kFloat_GrVertexAttribType:
348 return kFloat_GrSLType;
jvanverth7023a002016-02-22 11:25:32 -0800349 case kVec2us_GrVertexAttribType:
joshualitt2dd1ae02014-12-03 06:24:10 -0800350 case kVec2f_GrVertexAttribType:
351 return kVec2f_GrSLType;
352 case kVec3f_GrVertexAttribType:
353 return kVec3f_GrSLType;
354 case kVec4ub_GrVertexAttribType:
355 case kVec4f_GrVertexAttribType:
356 return kVec4f_GrSLType;
ethannicholas22793252016-01-30 09:59:10 -0800357 case kInt_GrVertexAttribType:
358 return kInt_GrSLType;
cdalton793dc262016-02-08 10:11:47 -0800359 case kUint_GrVertexAttribType:
360 return kUint_GrSLType;
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000361 }
joshualitt2dd1ae02014-12-03 06:24:10 -0800362}
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000363
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000364//////////////////////////////////////////////////////////////////////////////
365
366/**
367* We have coverage effects that clip rendering to the edge of some geometric primitive.
skia.committer@gmail.com06acb582014-03-06 03:02:32 +0000368* This enum specifies how that clipping is performed. Not all factories that take a
joshualittb0a8a372014-09-23 09:50:21 -0700369* 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 +0000370* a NULL return.
371*/
joshualittb0a8a372014-09-23 09:50:21 -0700372enum GrPrimitiveEdgeType {
373 kFillBW_GrProcessorEdgeType,
374 kFillAA_GrProcessorEdgeType,
375 kInverseFillBW_GrProcessorEdgeType,
376 kInverseFillAA_GrProcessorEdgeType,
377 kHairlineAA_GrProcessorEdgeType,
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000378
joshualittb0a8a372014-09-23 09:50:21 -0700379 kLast_GrProcessorEdgeType = kHairlineAA_GrProcessorEdgeType
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000380};
381
joshualittb0a8a372014-09-23 09:50:21 -0700382static const int kGrProcessorEdgeTypeCnt = kLast_GrProcessorEdgeType + 1;
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000383
joshualittb0a8a372014-09-23 09:50:21 -0700384static inline bool GrProcessorEdgeTypeIsFill(const GrPrimitiveEdgeType edgeType) {
385 return (kFillAA_GrProcessorEdgeType == edgeType || kFillBW_GrProcessorEdgeType == edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000386}
387
joshualittb0a8a372014-09-23 09:50:21 -0700388static inline bool GrProcessorEdgeTypeIsInverseFill(const GrPrimitiveEdgeType edgeType) {
389 return (kInverseFillAA_GrProcessorEdgeType == edgeType ||
390 kInverseFillBW_GrProcessorEdgeType == edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000391}
392
joshualittb0a8a372014-09-23 09:50:21 -0700393static inline bool GrProcessorEdgeTypeIsAA(const GrPrimitiveEdgeType edgeType) {
394 return (kFillBW_GrProcessorEdgeType != edgeType && kInverseFillBW_GrProcessorEdgeType != edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000395}
396
joshualittb0a8a372014-09-23 09:50:21 -0700397static inline GrPrimitiveEdgeType GrInvertProcessorEdgeType(const GrPrimitiveEdgeType edgeType) {
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000398 switch (edgeType) {
joshualittb0a8a372014-09-23 09:50:21 -0700399 case kFillBW_GrProcessorEdgeType:
400 return kInverseFillBW_GrProcessorEdgeType;
401 case kFillAA_GrProcessorEdgeType:
402 return kInverseFillAA_GrProcessorEdgeType;
403 case kInverseFillBW_GrProcessorEdgeType:
404 return kFillBW_GrProcessorEdgeType;
405 case kInverseFillAA_GrProcessorEdgeType:
406 return kFillAA_GrProcessorEdgeType;
407 case kHairlineAA_GrProcessorEdgeType:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000408 SkFAIL("Hairline fill isn't invertible.");
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000409 }
joshualittb0a8a372014-09-23 09:50:21 -0700410 return kFillAA_GrProcessorEdgeType; // suppress warning.
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000411}
412
bsalomonbcf0a522014-10-08 08:40:09 -0700413/**
414 * Indicates the type of pending IO operations that can be recorded for gpu resources.
415 */
416enum GrIOType {
417 kRead_GrIOType,
418 kWrite_GrIOType,
419 kRW_GrIOType
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