blob: 53e71e74abe7dd0c4e7d525c7c0deee42a805274 [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
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050014/** This enum indicates the type of antialiasing to be performed. */
15enum class GrAAType {
16 /** No antialiasing */
17 kNone,
18 /** Use fragment shader code to compute a fractional pixel coverage. */
19 kCoverage,
20 /** Use normal MSAA. */
21 kMSAA,
22 /**
23 * Use "mixed samples" MSAA such that the stencil buffer is multisampled but the color buffer is
24 * not.
25 */
26 kMixedSamples
27};
28
bsalomoncdee0092016-01-08 13:20:12 -080029 /**
30 * Types of shader-language-specific boxed variables we can create. (Currently only GrGLShaderVars,
31 * but should be applicable to other shader languages.)
32 */
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +000033enum GrSLType {
34 kVoid_GrSLType,
Brian Salomonfa26e662016-11-14 11:27:00 -050035 kBool_GrSLType,
36 kInt_GrSLType,
37 kUint_GrSLType,
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +000038 kFloat_GrSLType,
39 kVec2f_GrSLType,
40 kVec3f_GrSLType,
41 kVec4f_GrSLType,
cdalton8d988b32016-03-07 15:39:09 -080042 kMat22f_GrSLType,
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +000043 kMat33f_GrSLType,
44 kMat44f_GrSLType,
egdaniel990dbc82016-07-13 14:09:30 -070045 kTexture2DSampler_GrSLType,
Brian Salomona8f00022016-11-16 12:55:57 -050046 kITexture2DSampler_GrSLType,
egdaniel990dbc82016-07-13 14:09:30 -070047 kTextureExternalSampler_GrSLType,
48 kTexture2DRectSampler_GrSLType,
csmartdalton22458032016-11-16 11:28:16 -070049 kBufferSampler_GrSLType,
egdaniel990dbc82016-07-13 14:09:30 -070050 kTexture2D_GrSLType,
51 kSampler_GrSLType,
Brian Salomonf9f45122016-11-29 11:59:17 -050052 kImageStorage2D_GrSLType,
53 kIImageStorage2D_GrSLType,
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +000054};
55
bsalomon17168df2014-12-09 09:00:49 -080056enum GrShaderType {
57 kVertex_GrShaderType,
58 kGeometry_GrShaderType,
59 kFragment_GrShaderType,
60
61 kLastkFragment_GrShaderType = kFragment_GrShaderType
62};
63static const int kGrShaderTypeCount = kLastkFragment_GrShaderType + 1;
64
cdalton5e58cee2016-02-11 12:49:47 -080065enum GrShaderFlags {
66 kNone_GrShaderFlags = 0,
67 kVertex_GrShaderFlag = 1 << kVertex_GrShaderType,
68 kGeometry_GrShaderFlag = 1 << kGeometry_GrShaderType,
69 kFragment_GrShaderFlag = 1 << kFragment_GrShaderType
70};
71GR_MAKE_BITFIELD_OPS(GrShaderFlags);
72
robertphillips5fa7f302016-07-21 09:21:04 -070073enum class GrDrawFace {
74 kInvalid = -1,
75
76 kBoth,
77 kCCW,
78 kCW,
79};
80
bsalomon@google.com31ec7982013-03-27 18:14:57 +000081/**
bsalomonc0bd6482014-12-09 10:04:14 -080082 * Precisions of shader language variables. Not all shading languages support precisions or actually
bsalomon422f56f2014-12-09 10:18:12 -080083 * vary the internal precision based on the qualifiers. These currently only apply to float types (
84 * including float vectors and matrices).
bsalomonc0bd6482014-12-09 10:04:14 -080085 */
86enum GrSLPrecision {
87 kLow_GrSLPrecision,
88 kMedium_GrSLPrecision,
89 kHigh_GrSLPrecision,
90
91 // Default precision is medium. This is because on OpenGL ES 2 highp support is not
92 // guaranteed. On (non-ES) OpenGL the specifiers have no effect on precision.
93 kDefault_GrSLPrecision = kMedium_GrSLPrecision,
94
95 kLast_GrSLPrecision = kHigh_GrSLPrecision
96};
97
98static const int kGrSLPrecisionCount = kLast_GrSLPrecision + 1;
99
ethannicholas22793252016-01-30 09:59:10 -0800100/** Is the shading language type float (including vectors/matrices)? */
bsalomon422f56f2014-12-09 10:18:12 -0800101static inline bool GrSLTypeIsFloatType(GrSLType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -0500102 switch (type) {
103 case kFloat_GrSLType:
104 case kVec2f_GrSLType:
105 case kVec3f_GrSLType:
106 case kVec4f_GrSLType:
107 case kMat22f_GrSLType:
108 case kMat33f_GrSLType:
109 case kMat44f_GrSLType:
110 return true;
bsalomon422f56f2014-12-09 10:18:12 -0800111
Brian Salomonfa26e662016-11-14 11:27:00 -0500112 case kVoid_GrSLType:
113 case kTexture2DSampler_GrSLType:
Brian Salomona8f00022016-11-16 12:55:57 -0500114 case kITexture2DSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500115 case kTextureExternalSampler_GrSLType:
116 case kTexture2DRectSampler_GrSLType:
csmartdalton22458032016-11-16 11:28:16 -0700117 case kBufferSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500118 case kBool_GrSLType:
119 case kInt_GrSLType:
120 case kUint_GrSLType:
121 case kTexture2D_GrSLType:
122 case kSampler_GrSLType:
Brian Salomonf9f45122016-11-29 11:59:17 -0500123 case kImageStorage2D_GrSLType:
124 case kIImageStorage2D_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500125 return false;
126 }
127 SkFAIL("Unexpected type");
128 return false;
bsalomone5286e02016-01-14 09:24:09 -0800129}
130
egdaniel990dbc82016-07-13 14:09:30 -0700131static inline bool GrSLTypeIs2DCombinedSamplerType(GrSLType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -0500132 switch (type) {
133 case kTexture2DSampler_GrSLType:
Brian Salomona8f00022016-11-16 12:55:57 -0500134 case kITexture2DSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500135 case kTextureExternalSampler_GrSLType:
136 case kTexture2DRectSampler_GrSLType:
137 return true;
bsalomone5286e02016-01-14 09:24:09 -0800138
Brian Salomonfa26e662016-11-14 11:27:00 -0500139 case kVoid_GrSLType:
140 case kFloat_GrSLType:
141 case kVec2f_GrSLType:
142 case kVec3f_GrSLType:
143 case kVec4f_GrSLType:
144 case kMat22f_GrSLType:
145 case kMat33f_GrSLType:
146 case kMat44f_GrSLType:
csmartdalton22458032016-11-16 11:28:16 -0700147 case kBufferSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500148 case kInt_GrSLType:
149 case kUint_GrSLType:
150 case kBool_GrSLType:
151 case kTexture2D_GrSLType:
152 case kSampler_GrSLType:
Brian Salomonf9f45122016-11-29 11:59:17 -0500153 case kImageStorage2D_GrSLType:
154 case kIImageStorage2D_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500155 return false;
156 }
157 SkFAIL("Unexpected type");
158 return false;
egdanielfa896322016-01-13 12:19:30 -0800159}
160
egdaniel990dbc82016-07-13 14:09:30 -0700161static inline bool GrSLTypeIsCombinedSamplerType(GrSLType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -0500162 switch (type) {
163 case kTexture2DSampler_GrSLType:
Brian Salomona8f00022016-11-16 12:55:57 -0500164 case kITexture2DSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500165 case kTextureExternalSampler_GrSLType:
166 case kTexture2DRectSampler_GrSLType:
csmartdalton22458032016-11-16 11:28:16 -0700167 case kBufferSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500168 return true;
cdalton74b8d322016-04-11 14:47:28 -0700169
Brian Salomonfa26e662016-11-14 11:27:00 -0500170 case kVoid_GrSLType:
171 case kFloat_GrSLType:
172 case kVec2f_GrSLType:
173 case kVec3f_GrSLType:
174 case kVec4f_GrSLType:
175 case kMat22f_GrSLType:
176 case kMat33f_GrSLType:
177 case kMat44f_GrSLType:
178 case kInt_GrSLType:
179 case kUint_GrSLType:
180 case kBool_GrSLType:
181 case kTexture2D_GrSLType:
182 case kSampler_GrSLType:
Brian Salomonf9f45122016-11-29 11:59:17 -0500183 case kImageStorage2D_GrSLType:
184 case kIImageStorage2D_GrSLType:
185 return false;
186 }
187 SkFAIL("Unexpected type");
188 return false;
189}
190
191static inline bool GrSLTypeIsImageStorage(GrSLType type) {
192 switch (type) {
193 case kImageStorage2D_GrSLType:
194 case kIImageStorage2D_GrSLType:
195 return true;
196
197 case kVoid_GrSLType:
198 case kFloat_GrSLType:
199 case kVec2f_GrSLType:
200 case kVec3f_GrSLType:
201 case kVec4f_GrSLType:
202 case kMat22f_GrSLType:
203 case kMat33f_GrSLType:
204 case kMat44f_GrSLType:
205 case kInt_GrSLType:
206 case kUint_GrSLType:
207 case kBool_GrSLType:
208 case kTexture2D_GrSLType:
209 case kSampler_GrSLType:
210 case kTexture2DSampler_GrSLType:
211 case kITexture2DSampler_GrSLType:
212 case kTextureExternalSampler_GrSLType:
213 case kTexture2DRectSampler_GrSLType:
214 case kBufferSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500215 return false;
216 }
217 SkFAIL("Unexpected type");
218 return false;
cdalton74b8d322016-04-11 14:47:28 -0700219}
220
cdalton5f2d8e22016-03-11 13:34:32 -0800221static inline bool GrSLTypeAcceptsPrecision(GrSLType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -0500222 switch (type) {
223 case kInt_GrSLType:
224 case kUint_GrSLType:
225 case kFloat_GrSLType:
226 case kVec2f_GrSLType:
227 case kVec3f_GrSLType:
228 case kVec4f_GrSLType:
229 case kMat22f_GrSLType:
230 case kMat33f_GrSLType:
231 case kMat44f_GrSLType:
232 case kTexture2DSampler_GrSLType:
Brian Salomona8f00022016-11-16 12:55:57 -0500233 case kITexture2DSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500234 case kTextureExternalSampler_GrSLType:
235 case kTexture2DRectSampler_GrSLType:
csmartdalton22458032016-11-16 11:28:16 -0700236 case kBufferSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500237 case kTexture2D_GrSLType:
238 case kSampler_GrSLType:
Brian Salomonf9f45122016-11-29 11:59:17 -0500239 case kImageStorage2D_GrSLType:
240 case kIImageStorage2D_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500241 return true;
242
243 case kVoid_GrSLType:
244 case kBool_GrSLType:
245 return false;
246 }
247 SkFAIL("Unexpected type");
248 return false;
cdalton5f2d8e22016-03-11 13:34:32 -0800249}
250
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000251//////////////////////////////////////////////////////////////////////////////
252
jvanverth@google.com054ae992013-04-01 20:06:51 +0000253/**
254 * Types used to describe format of vertices in arrays.
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000255 */
256enum GrVertexAttribType {
257 kFloat_GrVertexAttribType = 0,
258 kVec2f_GrVertexAttribType,
259 kVec3f_GrVertexAttribType,
260 kVec4f_GrVertexAttribType,
egdaniel37b4d862014-11-03 10:07:07 -0800261
262 kUByte_GrVertexAttribType, // unsigned byte, e.g. coverage
jvanverth5a105ff2015-02-18 11:36:35 -0800263 kVec4ub_GrVertexAttribType, // vector of 4 unsigned bytes, e.g. colors
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000264
jvanverth7023a002016-02-22 11:25:32 -0800265 kVec2us_GrVertexAttribType, // vector of 2 shorts, e.g. texture coordinates
ethannicholas22793252016-01-30 09:59:10 -0800266
267 kInt_GrVertexAttribType,
cdalton793dc262016-02-08 10:11:47 -0800268 kUint_GrVertexAttribType,
egdaniel990dbc82016-07-13 14:09:30 -0700269
cdalton793dc262016-02-08 10:11:47 -0800270 kLast_GrVertexAttribType = kUint_GrVertexAttribType
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000271};
272static const int kGrVertexAttribTypeCount = kLast_GrVertexAttribType + 1;
273
jvanverth@google.com054ae992013-04-01 20:06:51 +0000274
275/**
276 * Returns the size of the attrib type in bytes.
277 */
278static inline size_t GrVertexAttribTypeSize(GrVertexAttribType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -0500279 switch (type) {
280 case kFloat_GrVertexAttribType:
281 return sizeof(float);
282 case kVec2f_GrVertexAttribType:
283 return 2*sizeof(float);
284 case kVec3f_GrVertexAttribType:
285 return 3*sizeof(float);
286 case kVec4f_GrVertexAttribType:
287 return 4*sizeof(float);
288 case kUByte_GrVertexAttribType:
289 return 1*sizeof(char);
290 case kVec4ub_GrVertexAttribType:
291 return 4*sizeof(char);
292 case kVec2us_GrVertexAttribType:
293 return 2*sizeof(int16_t);
294 case kInt_GrVertexAttribType:
295 return sizeof(int32_t);
296 case kUint_GrVertexAttribType:
297 return sizeof(uint32_t);
298 }
299 SkFAIL("Unexpected attribute type");
300 return 0;
jvanverth@google.com054ae992013-04-01 20:06:51 +0000301}
302
303/**
cdalton793dc262016-02-08 10:11:47 -0800304 * Is the attrib type integral?
305 */
306static inline bool GrVertexAttribTypeIsIntType(GrVertexAttribType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -0500307 switch (type) {
308 case kFloat_GrVertexAttribType:
309 return false;
310 case kVec2f_GrVertexAttribType:
311 return false;
312 case kVec3f_GrVertexAttribType:
313 return false;
314 case kVec4f_GrVertexAttribType:
315 return false;
316 case kUByte_GrVertexAttribType:
317 return false;
318 case kVec4ub_GrVertexAttribType:
319 return false;
320 case kVec2us_GrVertexAttribType:
321 return false;
322 case kInt_GrVertexAttribType:
323 return true;
324 case kUint_GrVertexAttribType:
325 return true;
326 }
327 SkFAIL("Unexpected attribute type");
328 return false;
cdalton793dc262016-02-08 10:11:47 -0800329}
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) {
joshualitt2dd1ae02014-12-03 06:24:10 -0800336 case kUByte_GrVertexAttribType:
337 case kFloat_GrVertexAttribType:
338 return kFloat_GrSLType;
jvanverth7023a002016-02-22 11:25:32 -0800339 case kVec2us_GrVertexAttribType:
joshualitt2dd1ae02014-12-03 06:24:10 -0800340 case kVec2f_GrVertexAttribType:
341 return kVec2f_GrSLType;
342 case kVec3f_GrVertexAttribType:
343 return kVec3f_GrSLType;
344 case kVec4ub_GrVertexAttribType:
345 case kVec4f_GrVertexAttribType:
346 return kVec4f_GrSLType;
ethannicholas22793252016-01-30 09:59:10 -0800347 case kInt_GrVertexAttribType:
348 return kInt_GrSLType;
cdalton793dc262016-02-08 10:11:47 -0800349 case kUint_GrVertexAttribType:
350 return kUint_GrSLType;
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000351 }
Brian Salomonfa26e662016-11-14 11:27:00 -0500352 SkFAIL("Unsupported type conversion");
353 return kVoid_GrSLType;
joshualitt2dd1ae02014-12-03 06:24:10 -0800354}
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000355
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000356//////////////////////////////////////////////////////////////////////////////
357
Brian Salomonf9f45122016-11-29 11:59:17 -0500358enum class GrImageStorageFormat {
359 kRGBA8,
360 kRGBA8i,
361 kRGBA16f,
362 kRGBA32f,
363};
364
365/**
366 * Describes types of caching and compiler optimizations allowed for certain variable types
367 * (currently only image storages).
368 **/
369enum class GrSLMemoryModel {
370 /** No special restrctions on memory accesses or compiler optimizations */
371 kNone,
372 /** Cache coherent across shader invocations */
373 kCoherent,
374 /**
375 * Disallows compiler from eliding loads or stores that appear redundant in a single
376 * invocation. Implies coherent.
377 */
378 kVolatile
379};
380
381/**
382 * If kYes then the memory backing the varialble is only accessed via the variable. This is
383 * currently only used with image storages.
384 */
385enum class GrSLRestrict {
386 kYes,
387 kNo,
388};
389
390//////////////////////////////////////////////////////////////////////////////
391
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000392/**
393* We have coverage effects that clip rendering to the edge of some geometric primitive.
skia.committer@gmail.com06acb582014-03-06 03:02:32 +0000394* This enum specifies how that clipping is performed. Not all factories that take a
joshualittb0a8a372014-09-23 09:50:21 -0700395* 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 +0000396* a NULL return.
397*/
joshualittb0a8a372014-09-23 09:50:21 -0700398enum GrPrimitiveEdgeType {
399 kFillBW_GrProcessorEdgeType,
400 kFillAA_GrProcessorEdgeType,
401 kInverseFillBW_GrProcessorEdgeType,
402 kInverseFillAA_GrProcessorEdgeType,
403 kHairlineAA_GrProcessorEdgeType,
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000404
joshualittb0a8a372014-09-23 09:50:21 -0700405 kLast_GrProcessorEdgeType = kHairlineAA_GrProcessorEdgeType
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000406};
407
joshualittb0a8a372014-09-23 09:50:21 -0700408static const int kGrProcessorEdgeTypeCnt = kLast_GrProcessorEdgeType + 1;
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000409
joshualittb0a8a372014-09-23 09:50:21 -0700410static inline bool GrProcessorEdgeTypeIsFill(const GrPrimitiveEdgeType edgeType) {
411 return (kFillAA_GrProcessorEdgeType == edgeType || kFillBW_GrProcessorEdgeType == edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000412}
413
joshualittb0a8a372014-09-23 09:50:21 -0700414static inline bool GrProcessorEdgeTypeIsInverseFill(const GrPrimitiveEdgeType edgeType) {
415 return (kInverseFillAA_GrProcessorEdgeType == edgeType ||
416 kInverseFillBW_GrProcessorEdgeType == edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000417}
418
joshualittb0a8a372014-09-23 09:50:21 -0700419static inline bool GrProcessorEdgeTypeIsAA(const GrPrimitiveEdgeType edgeType) {
420 return (kFillBW_GrProcessorEdgeType != edgeType && kInverseFillBW_GrProcessorEdgeType != edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000421}
422
joshualittb0a8a372014-09-23 09:50:21 -0700423static inline GrPrimitiveEdgeType GrInvertProcessorEdgeType(const GrPrimitiveEdgeType edgeType) {
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000424 switch (edgeType) {
joshualittb0a8a372014-09-23 09:50:21 -0700425 case kFillBW_GrProcessorEdgeType:
426 return kInverseFillBW_GrProcessorEdgeType;
427 case kFillAA_GrProcessorEdgeType:
428 return kInverseFillAA_GrProcessorEdgeType;
429 case kInverseFillBW_GrProcessorEdgeType:
430 return kFillBW_GrProcessorEdgeType;
431 case kInverseFillAA_GrProcessorEdgeType:
432 return kFillAA_GrProcessorEdgeType;
433 case kHairlineAA_GrProcessorEdgeType:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000434 SkFAIL("Hairline fill isn't invertible.");
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000435 }
joshualittb0a8a372014-09-23 09:50:21 -0700436 return kFillAA_GrProcessorEdgeType; // suppress warning.
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000437}
438
bsalomonbcf0a522014-10-08 08:40:09 -0700439/**
440 * Indicates the type of pending IO operations that can be recorded for gpu resources.
441 */
442enum GrIOType {
443 kRead_GrIOType,
444 kWrite_GrIOType,
445 kRW_GrIOType
446};
447
jvanverth17aa0472016-01-05 10:41:27 -0800448/**
cdalton397536c2016-03-25 12:15:03 -0700449* Indicates the type of data that a GPU buffer will be used for.
450*/
451enum GrBufferType {
452 kVertex_GrBufferType,
453 kIndex_GrBufferType,
cdaltone2e71c22016-04-07 18:13:29 -0700454 kTexel_GrBufferType,
455 kDrawIndirect_GrBufferType,
cdalton397536c2016-03-25 12:15:03 -0700456 kXferCpuToGpu_GrBufferType,
457 kXferGpuToCpu_GrBufferType,
458
459 kLast_GrBufferType = kXferGpuToCpu_GrBufferType
460};
cdaltone2e71c22016-04-07 18:13:29 -0700461static const int kGrBufferTypeCount = kLast_GrBufferType + 1;
462
463static inline bool GrBufferTypeIsVertexOrIndex(GrBufferType type) {
464 SkASSERT(type >= 0 && type < kGrBufferTypeCount);
465 return type <= kIndex_GrBufferType;
466
467 GR_STATIC_ASSERT(0 == kVertex_GrBufferType);
468 GR_STATIC_ASSERT(1 == kIndex_GrBufferType);
469}
cdalton397536c2016-03-25 12:15:03 -0700470
471/**
472* Provides a performance hint regarding the frequency at which a data store will be accessed.
473*/
474enum GrAccessPattern {
475 /** Data store will be respecified repeatedly and used many times. */
476 kDynamic_GrAccessPattern,
477 /** Data store will be specified once and used many times. (Thus disqualified from caching.) */
478 kStatic_GrAccessPattern,
479 /** Data store will be specified once and used at most a few times. (Also can't be cached.) */
480 kStream_GrAccessPattern,
481
482 kLast_GrAccessPattern = kStream_GrAccessPattern
jvanverth17aa0472016-01-05 10:41:27 -0800483};
484
485
joshualitt7d022d62015-05-12 12:03:50 -0700486#ifdef SK_DEBUG
bsalomon682c2692015-05-22 14:01:46 -0700487// Takes a pointer to a GrCaps, and will suppress prints if required
488#define GrCapsDebugf(caps, ...) \
489 if (!caps->suppressPrints()) { \
490 SkDebugf(__VA_ARGS__); \
joshualitt7d022d62015-05-12 12:03:50 -0700491 }
492#else
bsalomon682c2692015-05-22 14:01:46 -0700493#define GrCapsDebugf(caps, ...)
joshualitt7d022d62015-05-12 12:03:50 -0700494#endif
495
kkinnunen2e6055b2016-04-22 01:48:29 -0700496/**
497 * Specifies if the holder owns the backend, OpenGL or Vulkan, object.
498 */
499enum class GrBackendObjectOwnership : bool {
500 /** Holder does not destroy the backend object. */
501 kBorrowed = false,
502 /** Holder destroys the backend object. */
503 kOwned = true
504};
505
bungeman06ca8ec2016-06-09 08:01:03 -0700506template <typename T> T * const * sk_sp_address_as_pointer_address(sk_sp<T> const * sp) {
507 static_assert(sizeof(T*) == sizeof(sk_sp<T>), "sk_sp not expected size.");
508 return reinterpret_cast<T * const *>(sp);
509}
510
jvanverth84741b32016-09-30 08:39:02 -0700511/*
512 * Object for CPU-GPU synchronization
513 */
514typedef intptr_t GrFence;
515
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +0000516#endif