blob: 5168ac91a175c9bb6935b4b73bfafeae8cc061ea [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,
egdaniel990dbc82016-07-13 14:09:30 -070028 kTexture2DSampler_GrSLType,
29 kTextureExternalSampler_GrSLType,
30 kTexture2DRectSampler_GrSLType,
31 kTextureBufferSampler_GrSLType,
ethannicholas22793252016-01-30 09:59:10 -080032 kBool_GrSLType,
33 kInt_GrSLType,
cdalton793dc262016-02-08 10:11:47 -080034 kUint_GrSLType,
egdaniel990dbc82016-07-13 14:09:30 -070035 kTexture2D_GrSLType,
36 kSampler_GrSLType,
jvanverth@google.com054ae992013-04-01 20:06:51 +000037
egdaniel990dbc82016-07-13 14:09:30 -070038 kLast_GrSLType = kSampler_GrSLType
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +000039};
jvanverth@google.com054ae992013-04-01 20:06:51 +000040static const int kGrSLTypeCount = kLast_GrSLType + 1;
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +000041
bsalomon17168df2014-12-09 09:00:49 -080042enum GrShaderType {
43 kVertex_GrShaderType,
44 kGeometry_GrShaderType,
45 kFragment_GrShaderType,
46
47 kLastkFragment_GrShaderType = kFragment_GrShaderType
48};
49static const int kGrShaderTypeCount = kLastkFragment_GrShaderType + 1;
50
cdalton5e58cee2016-02-11 12:49:47 -080051enum GrShaderFlags {
52 kNone_GrShaderFlags = 0,
53 kVertex_GrShaderFlag = 1 << kVertex_GrShaderType,
54 kGeometry_GrShaderFlag = 1 << kGeometry_GrShaderType,
55 kFragment_GrShaderFlag = 1 << kFragment_GrShaderType
56};
57GR_MAKE_BITFIELD_OPS(GrShaderFlags);
58
bsalomon@google.com31ec7982013-03-27 18:14:57 +000059/**
bsalomonc0bd6482014-12-09 10:04:14 -080060 * Precisions of shader language variables. Not all shading languages support precisions or actually
bsalomon422f56f2014-12-09 10:18:12 -080061 * vary the internal precision based on the qualifiers. These currently only apply to float types (
62 * including float vectors and matrices).
bsalomonc0bd6482014-12-09 10:04:14 -080063 */
64enum GrSLPrecision {
65 kLow_GrSLPrecision,
66 kMedium_GrSLPrecision,
67 kHigh_GrSLPrecision,
68
69 // Default precision is medium. This is because on OpenGL ES 2 highp support is not
70 // guaranteed. On (non-ES) OpenGL the specifiers have no effect on precision.
71 kDefault_GrSLPrecision = kMedium_GrSLPrecision,
72
73 kLast_GrSLPrecision = kHigh_GrSLPrecision
74};
75
76static const int kGrSLPrecisionCount = kLast_GrSLPrecision + 1;
77
78/**
jvanverth@google.com054ae992013-04-01 20:06:51 +000079 * Gets the vector size of the SLType. Returns -1 for void, matrices, and samplers.
80 */
81static inline int GrSLTypeVectorCount(GrSLType type) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000082 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
egdaniel990dbc82016-07-13 14:09:30 -070083 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 +000084 return kCounts[type];
85
86 GR_STATIC_ASSERT(0 == kVoid_GrSLType);
87 GR_STATIC_ASSERT(1 == kFloat_GrSLType);
88 GR_STATIC_ASSERT(2 == kVec2f_GrSLType);
89 GR_STATIC_ASSERT(3 == kVec3f_GrSLType);
90 GR_STATIC_ASSERT(4 == kVec4f_GrSLType);
cdalton8d988b32016-03-07 15:39:09 -080091 GR_STATIC_ASSERT(5 == kMat22f_GrSLType);
92 GR_STATIC_ASSERT(6 == kMat33f_GrSLType);
93 GR_STATIC_ASSERT(7 == kMat44f_GrSLType);
egdaniel990dbc82016-07-13 14:09:30 -070094 GR_STATIC_ASSERT(8 == kTexture2DSampler_GrSLType);
95 GR_STATIC_ASSERT(9 == kTextureExternalSampler_GrSLType);
96 GR_STATIC_ASSERT(10 == kTexture2DRectSampler_GrSLType);
97 GR_STATIC_ASSERT(11 == kTextureBufferSampler_GrSLType);
cdalton74b8d322016-04-11 14:47:28 -070098 GR_STATIC_ASSERT(12 == kBool_GrSLType);
99 GR_STATIC_ASSERT(13 == kInt_GrSLType);
100 GR_STATIC_ASSERT(14 == kUint_GrSLType);
egdaniel990dbc82016-07-13 14:09:30 -0700101 GR_STATIC_ASSERT(15 == kTexture2D_GrSLType);
102 GR_STATIC_ASSERT(16 == kSampler_GrSLType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000103 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCounts) == kGrSLTypeCount);
jvanverth@google.com054ae992013-04-01 20:06:51 +0000104}
105
bsalomon@google.com018f1792013-04-18 19:36:09 +0000106/** Return the type enum for a vector of floats of length n (1..4),
107 e.g. 1 -> kFloat_GrSLType, 2 -> kVec2_GrSLType, ... */
jvanverth@google.com054ae992013-04-01 20:06:51 +0000108static inline GrSLType GrSLFloatVectorType(int count) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000109 SkASSERT(count > 0 && count <= 4);
jvanverth@google.com054ae992013-04-01 20:06:51 +0000110 return (GrSLType)(count);
111
112 GR_STATIC_ASSERT(kFloat_GrSLType == 1);
113 GR_STATIC_ASSERT(kVec2f_GrSLType == 2);
114 GR_STATIC_ASSERT(kVec3f_GrSLType == 3);
115 GR_STATIC_ASSERT(kVec4f_GrSLType == 4);
116}
117
ethannicholas22793252016-01-30 09:59:10 -0800118/** Is the shading language type float (including vectors/matrices)? */
bsalomon422f56f2014-12-09 10:18:12 -0800119static inline bool GrSLTypeIsFloatType(GrSLType type) {
120 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
cdalton8d988b32016-03-07 15:39:09 -0800121 return type >= kFloat_GrSLType && type <= kMat44f_GrSLType;
bsalomon422f56f2014-12-09 10:18:12 -0800122
123 GR_STATIC_ASSERT(0 == kVoid_GrSLType);
124 GR_STATIC_ASSERT(1 == kFloat_GrSLType);
125 GR_STATIC_ASSERT(2 == kVec2f_GrSLType);
126 GR_STATIC_ASSERT(3 == kVec3f_GrSLType);
127 GR_STATIC_ASSERT(4 == kVec4f_GrSLType);
cdalton8d988b32016-03-07 15:39:09 -0800128 GR_STATIC_ASSERT(5 == kMat22f_GrSLType);
129 GR_STATIC_ASSERT(6 == kMat33f_GrSLType);
130 GR_STATIC_ASSERT(7 == kMat44f_GrSLType);
egdaniel990dbc82016-07-13 14:09:30 -0700131 GR_STATIC_ASSERT(8 == kTexture2DSampler_GrSLType);
132 GR_STATIC_ASSERT(9 == kTextureExternalSampler_GrSLType);
133 GR_STATIC_ASSERT(10 == kTexture2DRectSampler_GrSLType);
134 GR_STATIC_ASSERT(11 == kTextureBufferSampler_GrSLType);
cdalton74b8d322016-04-11 14:47:28 -0700135 GR_STATIC_ASSERT(12 == kBool_GrSLType);
136 GR_STATIC_ASSERT(13 == kInt_GrSLType);
137 GR_STATIC_ASSERT(14 == kUint_GrSLType);
egdaniel990dbc82016-07-13 14:09:30 -0700138 GR_STATIC_ASSERT(15 == kTexture2D_GrSLType);
139 GR_STATIC_ASSERT(16 == kSampler_GrSLType);
140 GR_STATIC_ASSERT(17 == kGrSLTypeCount);
ethannicholas22793252016-01-30 09:59:10 -0800141}
142
143/** Is the shading language type integral (including vectors/matrices)? */
144static inline bool GrSLTypeIsIntType(GrSLType type) {
145 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
egdaniel990dbc82016-07-13 14:09:30 -0700146 return type >= kInt_GrSLType && type <= kUint_GrSLType;
ethannicholas22793252016-01-30 09:59:10 -0800147
148 GR_STATIC_ASSERT(0 == kVoid_GrSLType);
149 GR_STATIC_ASSERT(1 == kFloat_GrSLType);
150 GR_STATIC_ASSERT(2 == kVec2f_GrSLType);
151 GR_STATIC_ASSERT(3 == kVec3f_GrSLType);
152 GR_STATIC_ASSERT(4 == kVec4f_GrSLType);
cdalton8d988b32016-03-07 15:39:09 -0800153 GR_STATIC_ASSERT(5 == kMat22f_GrSLType);
154 GR_STATIC_ASSERT(6 == kMat33f_GrSLType);
155 GR_STATIC_ASSERT(7 == kMat44f_GrSLType);
egdaniel990dbc82016-07-13 14:09:30 -0700156 GR_STATIC_ASSERT(8 == kTexture2DSampler_GrSLType);
157 GR_STATIC_ASSERT(9 == kTextureExternalSampler_GrSLType);
158 GR_STATIC_ASSERT(10 == kTexture2DRectSampler_GrSLType);
159 GR_STATIC_ASSERT(11 == kTextureBufferSampler_GrSLType);
cdalton74b8d322016-04-11 14:47:28 -0700160 GR_STATIC_ASSERT(12 == kBool_GrSLType);
161 GR_STATIC_ASSERT(13 == kInt_GrSLType);
162 GR_STATIC_ASSERT(14 == kUint_GrSLType);
egdaniel990dbc82016-07-13 14:09:30 -0700163 GR_STATIC_ASSERT(15 == kTexture2D_GrSLType);
164 GR_STATIC_ASSERT(16 == kSampler_GrSLType);
165 GR_STATIC_ASSERT(17 == kGrSLTypeCount);
ethannicholas22793252016-01-30 09:59:10 -0800166}
167
168/** Is the shading language type numeric (including vectors/matrices)? */
169static inline bool GrSLTypeIsNumeric(GrSLType type) {
170 return GrSLTypeIsFloatType(type) || GrSLTypeIsIntType(type);
bsalomon422f56f2014-12-09 10:18:12 -0800171}
egdanielfa896322016-01-13 12:19:30 -0800172
173/** Returns the size in bytes for floating point GrSLTypes. For non floating point type returns 0 */
174static inline size_t GrSLTypeSize(GrSLType type) {
175 SkASSERT(GrSLTypeIsFloatType(type));
176 static const size_t kSizes[] = {
177 0, // kVoid_GrSLType
178 sizeof(float), // kFloat_GrSLType
179 2 * sizeof(float), // kVec2f_GrSLType
180 3 * sizeof(float), // kVec3f_GrSLType
181 4 * sizeof(float), // kVec4f_GrSLType
cdalton8d988b32016-03-07 15:39:09 -0800182 2 * 2 * sizeof(float), // kMat22f_GrSLType
183 3 * 3 * sizeof(float), // kMat33f_GrSLType
184 4 * 4 * sizeof(float), // kMat44f_GrSLType
egdaniel990dbc82016-07-13 14:09:30 -0700185 0, // kTexture2DSampler_GrSLType
186 0, // kTextureExternalSampler_GrSLType
187 0, // kTexture2DRectSampler_GrSLType
188 0, // kTextureBufferSampler_GrSLType
ethannicholas22793252016-01-30 09:59:10 -0800189 0, // kBool_GrSLType
190 0, // kInt_GrSLType
cdalton793dc262016-02-08 10:11:47 -0800191 0, // kUint_GrSLType
egdaniel990dbc82016-07-13 14:09:30 -0700192 0, // kTexture2D_GrSLType
193 0, // kSampler_GrSLType
egdanielfa896322016-01-13 12:19:30 -0800194 };
195 return kSizes[type];
196
197 GR_STATIC_ASSERT(0 == kVoid_GrSLType);
198 GR_STATIC_ASSERT(1 == kFloat_GrSLType);
199 GR_STATIC_ASSERT(2 == kVec2f_GrSLType);
200 GR_STATIC_ASSERT(3 == kVec3f_GrSLType);
201 GR_STATIC_ASSERT(4 == kVec4f_GrSLType);
cdalton8d988b32016-03-07 15:39:09 -0800202 GR_STATIC_ASSERT(5 == kMat22f_GrSLType);
203 GR_STATIC_ASSERT(6 == kMat33f_GrSLType);
204 GR_STATIC_ASSERT(7 == kMat44f_GrSLType);
egdaniel990dbc82016-07-13 14:09:30 -0700205 GR_STATIC_ASSERT(8 == kTexture2DSampler_GrSLType);
206 GR_STATIC_ASSERT(9 == kTextureExternalSampler_GrSLType);
207 GR_STATIC_ASSERT(10 == kTexture2DRectSampler_GrSLType);
208 GR_STATIC_ASSERT(11 == kTextureBufferSampler_GrSLType);
cdalton74b8d322016-04-11 14:47:28 -0700209 GR_STATIC_ASSERT(12 == kBool_GrSLType);
210 GR_STATIC_ASSERT(13 == kInt_GrSLType);
211 GR_STATIC_ASSERT(14 == kUint_GrSLType);
egdaniel990dbc82016-07-13 14:09:30 -0700212 GR_STATIC_ASSERT(15 == kTexture2D_GrSLType);
213 GR_STATIC_ASSERT(16 == kSampler_GrSLType);
214 GR_STATIC_ASSERT(17 == kGrSLTypeCount);
bsalomone5286e02016-01-14 09:24:09 -0800215}
216
egdaniel990dbc82016-07-13 14:09:30 -0700217static inline bool GrSLTypeIs2DCombinedSamplerType(GrSLType type) {
bsalomone5286e02016-01-14 09:24:09 -0800218 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
egdaniel990dbc82016-07-13 14:09:30 -0700219 return type >= kTexture2DSampler_GrSLType && type <= kTexture2DRectSampler_GrSLType;
bsalomone5286e02016-01-14 09:24:09 -0800220
egdaniel990dbc82016-07-13 14:09:30 -0700221 GR_STATIC_ASSERT(8 == kTexture2DSampler_GrSLType);
222 GR_STATIC_ASSERT(9 == kTextureExternalSampler_GrSLType);
223 GR_STATIC_ASSERT(10 == kTexture2DRectSampler_GrSLType);
egdanielfa896322016-01-13 12:19:30 -0800224}
225
egdaniel990dbc82016-07-13 14:09:30 -0700226static inline bool GrSLTypeIsCombinedSamplerType(GrSLType type) {
cdalton74b8d322016-04-11 14:47:28 -0700227 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
egdaniel990dbc82016-07-13 14:09:30 -0700228 return type >= kTexture2DSampler_GrSLType && type <= kTextureBufferSampler_GrSLType;
cdalton74b8d322016-04-11 14:47:28 -0700229
egdaniel990dbc82016-07-13 14:09:30 -0700230 GR_STATIC_ASSERT(8 == kTexture2DSampler_GrSLType);
231 GR_STATIC_ASSERT(9 == kTextureExternalSampler_GrSLType);
232 GR_STATIC_ASSERT(10 == kTexture2DRectSampler_GrSLType);
233 GR_STATIC_ASSERT(11 == kTextureBufferSampler_GrSLType);
cdalton74b8d322016-04-11 14:47:28 -0700234}
235
cdalton5f2d8e22016-03-11 13:34:32 -0800236static inline bool GrSLTypeAcceptsPrecision(GrSLType type) {
egdaniel990dbc82016-07-13 14:09:30 -0700237 return type != kVoid_GrSLType && type != kBool_GrSLType;
cdalton5f2d8e22016-03-11 13:34:32 -0800238}
239
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000240//////////////////////////////////////////////////////////////////////////////
241
jvanverth@google.com054ae992013-04-01 20:06:51 +0000242/**
243 * Types used to describe format of vertices in arrays.
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000244 */
245enum GrVertexAttribType {
246 kFloat_GrVertexAttribType = 0,
247 kVec2f_GrVertexAttribType,
248 kVec3f_GrVertexAttribType,
249 kVec4f_GrVertexAttribType,
egdaniel37b4d862014-11-03 10:07:07 -0800250
251 kUByte_GrVertexAttribType, // unsigned byte, e.g. coverage
jvanverth5a105ff2015-02-18 11:36:35 -0800252 kVec4ub_GrVertexAttribType, // vector of 4 unsigned bytes, e.g. colors
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000253
jvanverth7023a002016-02-22 11:25:32 -0800254 kVec2us_GrVertexAttribType, // vector of 2 shorts, e.g. texture coordinates
ethannicholas22793252016-01-30 09:59:10 -0800255
256 kInt_GrVertexAttribType,
cdalton793dc262016-02-08 10:11:47 -0800257 kUint_GrVertexAttribType,
egdaniel990dbc82016-07-13 14:09:30 -0700258
cdalton793dc262016-02-08 10:11:47 -0800259 kLast_GrVertexAttribType = kUint_GrVertexAttribType
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000260};
261static const int kGrVertexAttribTypeCount = kLast_GrVertexAttribType + 1;
262
jvanverth@google.com054ae992013-04-01 20:06:51 +0000263/**
264 * Returns the vector size of the type.
265 */
266static inline int GrVertexAttribTypeVectorCount(GrVertexAttribType type) {
cdalton793dc262016-02-08 10:11:47 -0800267 SkASSERT(type >= 0 && type < kGrVertexAttribTypeCount);
268 static const int kCounts[] = { 1, 2, 3, 4, 1, 4, 2, 1, 1 };
jvanverth@google.com054ae992013-04-01 20:06:51 +0000269 return kCounts[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(kCounts) == kGrVertexAttribTypeCount);
jvanverth@google.com054ae992013-04-01 20:06:51 +0000281}
282
283/**
284 * Returns the size of the attrib type in bytes.
285 */
286static inline size_t GrVertexAttribTypeSize(GrVertexAttribType type) {
jvanverth@google.com054ae992013-04-01 20:06:51 +0000287 static const size_t kSizes[] = {
288 sizeof(float), // kFloat_GrVertexAttribType
289 2*sizeof(float), // kVec2f_GrVertexAttribType
290 3*sizeof(float), // kVec3f_GrVertexAttribType
291 4*sizeof(float), // kVec4f_GrVertexAttribType
egdaniel37b4d862014-11-03 10:07:07 -0800292 1*sizeof(char), // kUByte_GrVertexAttribType
jvanverth5a105ff2015-02-18 11:36:35 -0800293 4*sizeof(char), // kVec4ub_GrVertexAttribType
jvanverth7023a002016-02-22 11:25:32 -0800294 2*sizeof(int16_t), // kVec2us_GrVertexAttribType
cdalton793dc262016-02-08 10:11:47 -0800295 sizeof(int32_t), // kInt_GrVertexAttribType
296 sizeof(uint32_t) // kUint_GrVertexAttribType
jvanverth@google.com054ae992013-04-01 20:06:51 +0000297 };
298 return kSizes[type];
299
300 GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType);
301 GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType);
302 GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType);
303 GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType);
egdaniel37b4d862014-11-03 10:07:07 -0800304 GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType);
305 GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType);
jvanverth7023a002016-02-22 11:25:32 -0800306 GR_STATIC_ASSERT(6 == kVec2us_GrVertexAttribType);
ethannicholas22793252016-01-30 09:59:10 -0800307 GR_STATIC_ASSERT(7 == kInt_GrVertexAttribType);
cdalton793dc262016-02-08 10:11:47 -0800308 GR_STATIC_ASSERT(8 == kUint_GrVertexAttribType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000309 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kSizes) == kGrVertexAttribTypeCount);
jvanverth@google.com054ae992013-04-01 20:06:51 +0000310}
311
312/**
cdalton793dc262016-02-08 10:11:47 -0800313 * Is the attrib type integral?
314 */
315static inline bool GrVertexAttribTypeIsIntType(GrVertexAttribType type) {
316 SkASSERT(type >= 0 && type < static_cast<GrVertexAttribType>(kGrVertexAttribTypeCount));
317 return type >= kInt_GrVertexAttribType;
318
319 GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType);
320 GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType);
321 GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType);
322 GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType);
323 GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType);
324 GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType);
jvanverth7023a002016-02-22 11:25:32 -0800325 GR_STATIC_ASSERT(6 == kVec2us_GrVertexAttribType);
cdalton793dc262016-02-08 10:11:47 -0800326 GR_STATIC_ASSERT(7 == kInt_GrVertexAttribType);
327 GR_STATIC_ASSERT(8 == kUint_GrVertexAttribType);
328 GR_STATIC_ASSERT(9 == kGrVertexAttribTypeCount);
329}
330
331/**
joshualitt2dd1ae02014-12-03 06:24:10 -0800332 * converts a GrVertexAttribType to a GrSLType
jvanverth@google.com054ae992013-04-01 20:06:51 +0000333 */
joshualitt2dd1ae02014-12-03 06:24:10 -0800334static inline GrSLType GrVertexAttribTypeToSLType(GrVertexAttribType type) {
335 switch (type) {
336 default:
337 SkFAIL("Unsupported type conversion");
tzikbc7d2352016-01-05 00:35:50 -0800338 return kVoid_GrSLType;
joshualitt2dd1ae02014-12-03 06:24:10 -0800339 case kUByte_GrVertexAttribType:
340 case kFloat_GrVertexAttribType:
341 return kFloat_GrSLType;
jvanverth7023a002016-02-22 11:25:32 -0800342 case kVec2us_GrVertexAttribType:
joshualitt2dd1ae02014-12-03 06:24:10 -0800343 case kVec2f_GrVertexAttribType:
344 return kVec2f_GrSLType;
345 case kVec3f_GrVertexAttribType:
346 return kVec3f_GrSLType;
347 case kVec4ub_GrVertexAttribType:
348 case kVec4f_GrVertexAttribType:
349 return kVec4f_GrSLType;
ethannicholas22793252016-01-30 09:59:10 -0800350 case kInt_GrVertexAttribType:
351 return kInt_GrSLType;
cdalton793dc262016-02-08 10:11:47 -0800352 case kUint_GrVertexAttribType:
353 return kUint_GrSLType;
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000354 }
joshualitt2dd1ae02014-12-03 06:24:10 -0800355}
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000356
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000357//////////////////////////////////////////////////////////////////////////////
358
359/**
360* We have coverage effects that clip rendering to the edge of some geometric primitive.
skia.committer@gmail.com06acb582014-03-06 03:02:32 +0000361* This enum specifies how that clipping is performed. Not all factories that take a
joshualittb0a8a372014-09-23 09:50:21 -0700362* 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 +0000363* a NULL return.
364*/
joshualittb0a8a372014-09-23 09:50:21 -0700365enum GrPrimitiveEdgeType {
366 kFillBW_GrProcessorEdgeType,
367 kFillAA_GrProcessorEdgeType,
368 kInverseFillBW_GrProcessorEdgeType,
369 kInverseFillAA_GrProcessorEdgeType,
370 kHairlineAA_GrProcessorEdgeType,
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000371
joshualittb0a8a372014-09-23 09:50:21 -0700372 kLast_GrProcessorEdgeType = kHairlineAA_GrProcessorEdgeType
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000373};
374
joshualittb0a8a372014-09-23 09:50:21 -0700375static const int kGrProcessorEdgeTypeCnt = kLast_GrProcessorEdgeType + 1;
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000376
joshualittb0a8a372014-09-23 09:50:21 -0700377static inline bool GrProcessorEdgeTypeIsFill(const GrPrimitiveEdgeType edgeType) {
378 return (kFillAA_GrProcessorEdgeType == edgeType || kFillBW_GrProcessorEdgeType == edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000379}
380
joshualittb0a8a372014-09-23 09:50:21 -0700381static inline bool GrProcessorEdgeTypeIsInverseFill(const GrPrimitiveEdgeType edgeType) {
382 return (kInverseFillAA_GrProcessorEdgeType == edgeType ||
383 kInverseFillBW_GrProcessorEdgeType == edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000384}
385
joshualittb0a8a372014-09-23 09:50:21 -0700386static inline bool GrProcessorEdgeTypeIsAA(const GrPrimitiveEdgeType edgeType) {
387 return (kFillBW_GrProcessorEdgeType != edgeType && kInverseFillBW_GrProcessorEdgeType != edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000388}
389
joshualittb0a8a372014-09-23 09:50:21 -0700390static inline GrPrimitiveEdgeType GrInvertProcessorEdgeType(const GrPrimitiveEdgeType edgeType) {
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000391 switch (edgeType) {
joshualittb0a8a372014-09-23 09:50:21 -0700392 case kFillBW_GrProcessorEdgeType:
393 return kInverseFillBW_GrProcessorEdgeType;
394 case kFillAA_GrProcessorEdgeType:
395 return kInverseFillAA_GrProcessorEdgeType;
396 case kInverseFillBW_GrProcessorEdgeType:
397 return kFillBW_GrProcessorEdgeType;
398 case kInverseFillAA_GrProcessorEdgeType:
399 return kFillAA_GrProcessorEdgeType;
400 case kHairlineAA_GrProcessorEdgeType:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000401 SkFAIL("Hairline fill isn't invertible.");
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000402 }
joshualittb0a8a372014-09-23 09:50:21 -0700403 return kFillAA_GrProcessorEdgeType; // suppress warning.
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000404}
405
bsalomonbcf0a522014-10-08 08:40:09 -0700406/**
407 * Indicates the type of pending IO operations that can be recorded for gpu resources.
408 */
409enum GrIOType {
410 kRead_GrIOType,
411 kWrite_GrIOType,
412 kRW_GrIOType
413};
414
bsalomon3e791242014-12-17 13:43:13 -0800415struct GrScissorState {
416 GrScissorState() : fEnabled(false) {}
cdalton846c0512016-05-13 10:25:00 -0700417 GrScissorState(const SkIRect& rect) : fEnabled(true), fRect(rect) {}
418 void setDisabled() { fEnabled = false; }
bsalomon3e791242014-12-17 13:43:13 -0800419 void set(const SkIRect& rect) { fRect = rect; fEnabled = true; }
420 bool operator==(const GrScissorState& other) const {
421 return fEnabled == other.fEnabled &&
422 (false == fEnabled || fRect == other.fRect);
423 }
424 bool operator!=(const GrScissorState& other) const { return !(*this == other); }
robertphillipse85a32d2015-02-10 08:16:55 -0800425
426 bool enabled() const { return fEnabled; }
427 const SkIRect& rect() const { return fRect; }
428
429private:
bsalomon3e791242014-12-17 13:43:13 -0800430 bool fEnabled;
431 SkIRect fRect;
432};
433
jvanverth17aa0472016-01-05 10:41:27 -0800434/**
cdalton397536c2016-03-25 12:15:03 -0700435* Indicates the type of data that a GPU buffer will be used for.
436*/
437enum GrBufferType {
438 kVertex_GrBufferType,
439 kIndex_GrBufferType,
cdaltone2e71c22016-04-07 18:13:29 -0700440 kTexel_GrBufferType,
441 kDrawIndirect_GrBufferType,
cdalton397536c2016-03-25 12:15:03 -0700442 kXferCpuToGpu_GrBufferType,
443 kXferGpuToCpu_GrBufferType,
444
445 kLast_GrBufferType = kXferGpuToCpu_GrBufferType
446};
cdaltone2e71c22016-04-07 18:13:29 -0700447static const int kGrBufferTypeCount = kLast_GrBufferType + 1;
448
449static inline bool GrBufferTypeIsVertexOrIndex(GrBufferType type) {
450 SkASSERT(type >= 0 && type < kGrBufferTypeCount);
451 return type <= kIndex_GrBufferType;
452
453 GR_STATIC_ASSERT(0 == kVertex_GrBufferType);
454 GR_STATIC_ASSERT(1 == kIndex_GrBufferType);
455}
cdalton397536c2016-03-25 12:15:03 -0700456
457/**
458* Provides a performance hint regarding the frequency at which a data store will be accessed.
459*/
460enum GrAccessPattern {
461 /** Data store will be respecified repeatedly and used many times. */
462 kDynamic_GrAccessPattern,
463 /** Data store will be specified once and used many times. (Thus disqualified from caching.) */
464 kStatic_GrAccessPattern,
465 /** Data store will be specified once and used at most a few times. (Also can't be cached.) */
466 kStream_GrAccessPattern,
467
468 kLast_GrAccessPattern = kStream_GrAccessPattern
jvanverth17aa0472016-01-05 10:41:27 -0800469};
470
471
joshualitt7d022d62015-05-12 12:03:50 -0700472#ifdef SK_DEBUG
bsalomon682c2692015-05-22 14:01:46 -0700473// Takes a pointer to a GrCaps, and will suppress prints if required
474#define GrCapsDebugf(caps, ...) \
475 if (!caps->suppressPrints()) { \
476 SkDebugf(__VA_ARGS__); \
joshualitt7d022d62015-05-12 12:03:50 -0700477 }
478#else
bsalomon682c2692015-05-22 14:01:46 -0700479#define GrCapsDebugf(caps, ...)
joshualitt7d022d62015-05-12 12:03:50 -0700480#endif
481
kkinnunen2e6055b2016-04-22 01:48:29 -0700482/**
483 * Specifies if the holder owns the backend, OpenGL or Vulkan, object.
484 */
485enum class GrBackendObjectOwnership : bool {
486 /** Holder does not destroy the backend object. */
487 kBorrowed = false,
488 /** Holder destroys the backend object. */
489 kOwned = true
490};
491
bungeman06ca8ec2016-06-09 08:01:03 -0700492template <typename T> T * const * sk_sp_address_as_pointer_address(sk_sp<T> const * sp) {
493 static_assert(sizeof(T*) == sizeof(sk_sp<T>), "sk_sp not expected size.");
494 return reinterpret_cast<T * const *>(sp);
495}
496
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +0000497#endif