blob: 28c33350eba6a241cca3f385c8c9111eb9422d61 [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. */
Brian Salomonaf9847e2017-03-01 11:28:27 -050015enum class GrAAType : unsigned {
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050016 /** 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
Brian Salomon0abc8b42016-12-13 10:22:54 -050029static inline bool GrAATypeIsHW(GrAAType type) {
30 switch (type) {
31 case GrAAType::kNone:
32 return false;
33 case GrAAType::kCoverage:
34 return false;
35 case GrAAType::kMSAA:
36 return true;
37 case GrAAType::kMixedSamples:
38 return true;
39 }
40 SkFAIL("Unknown AA Type");
41 return false;
42}
43
44/**
45 * Types of shader-language-specific boxed variables we can create. (Currently only GrGLShaderVars,
46 * but should be applicable to other shader languages.)
47 */
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +000048enum GrSLType {
49 kVoid_GrSLType,
Brian Salomonfa26e662016-11-14 11:27:00 -050050 kBool_GrSLType,
51 kInt_GrSLType,
52 kUint_GrSLType,
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +000053 kFloat_GrSLType,
54 kVec2f_GrSLType,
55 kVec3f_GrSLType,
56 kVec4f_GrSLType,
csmartdaltonb37cb232017-02-08 14:56:27 -050057 kVec2i_GrSLType,
58 kVec3i_GrSLType,
59 kVec4i_GrSLType,
cdalton8d988b32016-03-07 15:39:09 -080060 kMat22f_GrSLType,
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +000061 kMat33f_GrSLType,
62 kMat44f_GrSLType,
egdaniel990dbc82016-07-13 14:09:30 -070063 kTexture2DSampler_GrSLType,
Brian Salomona8f00022016-11-16 12:55:57 -050064 kITexture2DSampler_GrSLType,
egdaniel990dbc82016-07-13 14:09:30 -070065 kTextureExternalSampler_GrSLType,
66 kTexture2DRectSampler_GrSLType,
csmartdalton22458032016-11-16 11:28:16 -070067 kBufferSampler_GrSLType,
egdaniel990dbc82016-07-13 14:09:30 -070068 kTexture2D_GrSLType,
69 kSampler_GrSLType,
Brian Salomonf9f45122016-11-29 11:59:17 -050070 kImageStorage2D_GrSLType,
71 kIImageStorage2D_GrSLType,
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +000072};
73
bsalomon17168df2014-12-09 09:00:49 -080074enum GrShaderType {
75 kVertex_GrShaderType,
76 kGeometry_GrShaderType,
77 kFragment_GrShaderType,
78
79 kLastkFragment_GrShaderType = kFragment_GrShaderType
80};
81static const int kGrShaderTypeCount = kLastkFragment_GrShaderType + 1;
82
cdalton5e58cee2016-02-11 12:49:47 -080083enum GrShaderFlags {
84 kNone_GrShaderFlags = 0,
85 kVertex_GrShaderFlag = 1 << kVertex_GrShaderType,
86 kGeometry_GrShaderFlag = 1 << kGeometry_GrShaderType,
87 kFragment_GrShaderFlag = 1 << kFragment_GrShaderType
88};
89GR_MAKE_BITFIELD_OPS(GrShaderFlags);
90
robertphillips5fa7f302016-07-21 09:21:04 -070091enum class GrDrawFace {
92 kInvalid = -1,
93
94 kBoth,
95 kCCW,
96 kCW,
97};
98
bsalomon@google.com31ec7982013-03-27 18:14:57 +000099/**
bsalomonc0bd6482014-12-09 10:04:14 -0800100 * Precisions of shader language variables. Not all shading languages support precisions or actually
bsalomon422f56f2014-12-09 10:18:12 -0800101 * vary the internal precision based on the qualifiers. These currently only apply to float types (
102 * including float vectors and matrices).
bsalomonc0bd6482014-12-09 10:04:14 -0800103 */
104enum GrSLPrecision {
105 kLow_GrSLPrecision,
106 kMedium_GrSLPrecision,
107 kHigh_GrSLPrecision,
108
109 // Default precision is medium. This is because on OpenGL ES 2 highp support is not
110 // guaranteed. On (non-ES) OpenGL the specifiers have no effect on precision.
111 kDefault_GrSLPrecision = kMedium_GrSLPrecision,
112
113 kLast_GrSLPrecision = kHigh_GrSLPrecision
114};
115
116static const int kGrSLPrecisionCount = kLast_GrSLPrecision + 1;
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) {
Brian Salomonfa26e662016-11-14 11:27:00 -0500120 switch (type) {
121 case kFloat_GrSLType:
122 case kVec2f_GrSLType:
123 case kVec3f_GrSLType:
124 case kVec4f_GrSLType:
125 case kMat22f_GrSLType:
126 case kMat33f_GrSLType:
127 case kMat44f_GrSLType:
128 return true;
bsalomon422f56f2014-12-09 10:18:12 -0800129
Brian Salomonfa26e662016-11-14 11:27:00 -0500130 case kVoid_GrSLType:
131 case kTexture2DSampler_GrSLType:
Brian Salomona8f00022016-11-16 12:55:57 -0500132 case kITexture2DSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500133 case kTextureExternalSampler_GrSLType:
134 case kTexture2DRectSampler_GrSLType:
csmartdalton22458032016-11-16 11:28:16 -0700135 case kBufferSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500136 case kBool_GrSLType:
137 case kInt_GrSLType:
138 case kUint_GrSLType:
csmartdaltonb37cb232017-02-08 14:56:27 -0500139 case kVec2i_GrSLType:
140 case kVec3i_GrSLType:
141 case kVec4i_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500142 case kTexture2D_GrSLType:
143 case kSampler_GrSLType:
Brian Salomonf9f45122016-11-29 11:59:17 -0500144 case kImageStorage2D_GrSLType:
145 case kIImageStorage2D_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500146 return false;
147 }
148 SkFAIL("Unexpected type");
149 return false;
bsalomone5286e02016-01-14 09:24:09 -0800150}
151
egdaniel990dbc82016-07-13 14:09:30 -0700152static inline bool GrSLTypeIs2DCombinedSamplerType(GrSLType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -0500153 switch (type) {
154 case kTexture2DSampler_GrSLType:
Brian Salomona8f00022016-11-16 12:55:57 -0500155 case kITexture2DSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500156 case kTextureExternalSampler_GrSLType:
157 case kTexture2DRectSampler_GrSLType:
158 return true;
bsalomone5286e02016-01-14 09:24:09 -0800159
Brian Salomonfa26e662016-11-14 11:27:00 -0500160 case kVoid_GrSLType:
161 case kFloat_GrSLType:
162 case kVec2f_GrSLType:
163 case kVec3f_GrSLType:
164 case kVec4f_GrSLType:
csmartdaltonb37cb232017-02-08 14:56:27 -0500165 case kVec2i_GrSLType:
166 case kVec3i_GrSLType:
167 case kVec4i_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500168 case kMat22f_GrSLType:
169 case kMat33f_GrSLType:
170 case kMat44f_GrSLType:
csmartdalton22458032016-11-16 11:28:16 -0700171 case kBufferSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500172 case kInt_GrSLType:
173 case kUint_GrSLType:
174 case kBool_GrSLType:
175 case kTexture2D_GrSLType:
176 case kSampler_GrSLType:
Brian Salomonf9f45122016-11-29 11:59:17 -0500177 case kImageStorage2D_GrSLType:
178 case kIImageStorage2D_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500179 return false;
180 }
181 SkFAIL("Unexpected type");
182 return false;
egdanielfa896322016-01-13 12:19:30 -0800183}
184
egdaniel990dbc82016-07-13 14:09:30 -0700185static inline bool GrSLTypeIsCombinedSamplerType(GrSLType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -0500186 switch (type) {
187 case kTexture2DSampler_GrSLType:
Brian Salomona8f00022016-11-16 12:55:57 -0500188 case kITexture2DSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500189 case kTextureExternalSampler_GrSLType:
190 case kTexture2DRectSampler_GrSLType:
csmartdalton22458032016-11-16 11:28:16 -0700191 case kBufferSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500192 return true;
cdalton74b8d322016-04-11 14:47:28 -0700193
Brian Salomonfa26e662016-11-14 11:27:00 -0500194 case kVoid_GrSLType:
195 case kFloat_GrSLType:
196 case kVec2f_GrSLType:
197 case kVec3f_GrSLType:
198 case kVec4f_GrSLType:
csmartdaltonb37cb232017-02-08 14:56:27 -0500199 case kVec2i_GrSLType:
200 case kVec3i_GrSLType:
201 case kVec4i_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500202 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:
Brian Salomonf9f45122016-11-29 11:59:17 -0500210 case kImageStorage2D_GrSLType:
211 case kIImageStorage2D_GrSLType:
212 return false;
213 }
214 SkFAIL("Unexpected type");
215 return false;
216}
217
218static inline bool GrSLTypeIsImageStorage(GrSLType type) {
219 switch (type) {
220 case kImageStorage2D_GrSLType:
221 case kIImageStorage2D_GrSLType:
222 return true;
223
224 case kVoid_GrSLType:
225 case kFloat_GrSLType:
226 case kVec2f_GrSLType:
227 case kVec3f_GrSLType:
228 case kVec4f_GrSLType:
csmartdaltonb37cb232017-02-08 14:56:27 -0500229 case kVec2i_GrSLType:
230 case kVec3i_GrSLType:
231 case kVec4i_GrSLType:
Brian Salomonf9f45122016-11-29 11:59:17 -0500232 case kMat22f_GrSLType:
233 case kMat33f_GrSLType:
234 case kMat44f_GrSLType:
235 case kInt_GrSLType:
236 case kUint_GrSLType:
237 case kBool_GrSLType:
238 case kTexture2D_GrSLType:
239 case kSampler_GrSLType:
240 case kTexture2DSampler_GrSLType:
241 case kITexture2DSampler_GrSLType:
242 case kTextureExternalSampler_GrSLType:
243 case kTexture2DRectSampler_GrSLType:
244 case kBufferSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500245 return false;
246 }
247 SkFAIL("Unexpected type");
248 return false;
cdalton74b8d322016-04-11 14:47:28 -0700249}
250
cdalton5f2d8e22016-03-11 13:34:32 -0800251static inline bool GrSLTypeAcceptsPrecision(GrSLType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -0500252 switch (type) {
253 case kInt_GrSLType:
254 case kUint_GrSLType:
255 case kFloat_GrSLType:
256 case kVec2f_GrSLType:
257 case kVec3f_GrSLType:
258 case kVec4f_GrSLType:
csmartdaltonb37cb232017-02-08 14:56:27 -0500259 case kVec2i_GrSLType:
260 case kVec3i_GrSLType:
261 case kVec4i_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500262 case kMat22f_GrSLType:
263 case kMat33f_GrSLType:
264 case kMat44f_GrSLType:
265 case kTexture2DSampler_GrSLType:
Brian Salomona8f00022016-11-16 12:55:57 -0500266 case kITexture2DSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500267 case kTextureExternalSampler_GrSLType:
268 case kTexture2DRectSampler_GrSLType:
csmartdalton22458032016-11-16 11:28:16 -0700269 case kBufferSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500270 case kTexture2D_GrSLType:
271 case kSampler_GrSLType:
Brian Salomonf9f45122016-11-29 11:59:17 -0500272 case kImageStorage2D_GrSLType:
273 case kIImageStorage2D_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500274 return true;
275
276 case kVoid_GrSLType:
277 case kBool_GrSLType:
278 return false;
279 }
280 SkFAIL("Unexpected type");
281 return false;
cdalton5f2d8e22016-03-11 13:34:32 -0800282}
283
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000284//////////////////////////////////////////////////////////////////////////////
285
jvanverth@google.com054ae992013-04-01 20:06:51 +0000286/**
287 * Types used to describe format of vertices in arrays.
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000288 */
289enum GrVertexAttribType {
290 kFloat_GrVertexAttribType = 0,
291 kVec2f_GrVertexAttribType,
292 kVec3f_GrVertexAttribType,
293 kVec4f_GrVertexAttribType,
egdaniel37b4d862014-11-03 10:07:07 -0800294
csmartdaltonb37cb232017-02-08 14:56:27 -0500295 kVec2i_GrVertexAttribType, // vector of 2 32-bit ints
296 kVec3i_GrVertexAttribType, // vector of 3 32-bit ints
297 kVec4i_GrVertexAttribType, // vector of 4 32-bit ints
298
egdaniel37b4d862014-11-03 10:07:07 -0800299 kUByte_GrVertexAttribType, // unsigned byte, e.g. coverage
jvanverth5a105ff2015-02-18 11:36:35 -0800300 kVec4ub_GrVertexAttribType, // vector of 4 unsigned bytes, e.g. colors
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000301
jvanverth7023a002016-02-22 11:25:32 -0800302 kVec2us_GrVertexAttribType, // vector of 2 shorts, e.g. texture coordinates
ethannicholas22793252016-01-30 09:59:10 -0800303
304 kInt_GrVertexAttribType,
cdalton793dc262016-02-08 10:11:47 -0800305 kUint_GrVertexAttribType,
egdaniel990dbc82016-07-13 14:09:30 -0700306
cdalton793dc262016-02-08 10:11:47 -0800307 kLast_GrVertexAttribType = kUint_GrVertexAttribType
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000308};
309static const int kGrVertexAttribTypeCount = kLast_GrVertexAttribType + 1;
310
jvanverth@google.com054ae992013-04-01 20:06:51 +0000311
312/**
313 * Returns the size of the attrib type in bytes.
314 */
315static inline size_t GrVertexAttribTypeSize(GrVertexAttribType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -0500316 switch (type) {
317 case kFloat_GrVertexAttribType:
318 return sizeof(float);
319 case kVec2f_GrVertexAttribType:
320 return 2*sizeof(float);
321 case kVec3f_GrVertexAttribType:
322 return 3*sizeof(float);
323 case kVec4f_GrVertexAttribType:
324 return 4*sizeof(float);
csmartdaltonb37cb232017-02-08 14:56:27 -0500325 case kVec2i_GrVertexAttribType:
326 return 2*sizeof(int32_t);
327 case kVec3i_GrVertexAttribType:
328 return 3*sizeof(int32_t);
329 case kVec4i_GrVertexAttribType:
330 return 4*sizeof(int32_t);
Brian Salomonfa26e662016-11-14 11:27:00 -0500331 case kUByte_GrVertexAttribType:
332 return 1*sizeof(char);
333 case kVec4ub_GrVertexAttribType:
334 return 4*sizeof(char);
335 case kVec2us_GrVertexAttribType:
336 return 2*sizeof(int16_t);
337 case kInt_GrVertexAttribType:
338 return sizeof(int32_t);
339 case kUint_GrVertexAttribType:
340 return sizeof(uint32_t);
341 }
342 SkFAIL("Unexpected attribute type");
343 return 0;
jvanverth@google.com054ae992013-04-01 20:06:51 +0000344}
345
346/**
cdalton793dc262016-02-08 10:11:47 -0800347 * Is the attrib type integral?
348 */
349static inline bool GrVertexAttribTypeIsIntType(GrVertexAttribType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -0500350 switch (type) {
351 case kFloat_GrVertexAttribType:
352 return false;
353 case kVec2f_GrVertexAttribType:
354 return false;
355 case kVec3f_GrVertexAttribType:
356 return false;
357 case kVec4f_GrVertexAttribType:
358 return false;
csmartdaltonb37cb232017-02-08 14:56:27 -0500359 case kVec2i_GrVertexAttribType:
360 return true;
361 case kVec3i_GrVertexAttribType:
362 return true;
363 case kVec4i_GrVertexAttribType:
364 return true;
Brian Salomonfa26e662016-11-14 11:27:00 -0500365 case kUByte_GrVertexAttribType:
366 return false;
367 case kVec4ub_GrVertexAttribType:
368 return false;
369 case kVec2us_GrVertexAttribType:
370 return false;
371 case kInt_GrVertexAttribType:
372 return true;
373 case kUint_GrVertexAttribType:
374 return true;
375 }
376 SkFAIL("Unexpected attribute type");
377 return false;
cdalton793dc262016-02-08 10:11:47 -0800378}
379
380/**
joshualitt2dd1ae02014-12-03 06:24:10 -0800381 * converts a GrVertexAttribType to a GrSLType
jvanverth@google.com054ae992013-04-01 20:06:51 +0000382 */
joshualitt2dd1ae02014-12-03 06:24:10 -0800383static inline GrSLType GrVertexAttribTypeToSLType(GrVertexAttribType type) {
384 switch (type) {
joshualitt2dd1ae02014-12-03 06:24:10 -0800385 case kUByte_GrVertexAttribType:
386 case kFloat_GrVertexAttribType:
387 return kFloat_GrSLType;
jvanverth7023a002016-02-22 11:25:32 -0800388 case kVec2us_GrVertexAttribType:
joshualitt2dd1ae02014-12-03 06:24:10 -0800389 case kVec2f_GrVertexAttribType:
390 return kVec2f_GrSLType;
391 case kVec3f_GrVertexAttribType:
392 return kVec3f_GrSLType;
393 case kVec4ub_GrVertexAttribType:
394 case kVec4f_GrVertexAttribType:
395 return kVec4f_GrSLType;
csmartdaltonb37cb232017-02-08 14:56:27 -0500396 case kVec2i_GrVertexAttribType:
397 return kVec2i_GrSLType;
398 case kVec3i_GrVertexAttribType:
399 return kVec3i_GrSLType;
400 case kVec4i_GrVertexAttribType:
401 return kVec4i_GrSLType;
ethannicholas22793252016-01-30 09:59:10 -0800402 case kInt_GrVertexAttribType:
403 return kInt_GrSLType;
cdalton793dc262016-02-08 10:11:47 -0800404 case kUint_GrVertexAttribType:
405 return kUint_GrSLType;
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000406 }
Brian Salomonfa26e662016-11-14 11:27:00 -0500407 SkFAIL("Unsupported type conversion");
408 return kVoid_GrSLType;
joshualitt2dd1ae02014-12-03 06:24:10 -0800409}
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000410
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000411//////////////////////////////////////////////////////////////////////////////
412
Brian Salomonf9f45122016-11-29 11:59:17 -0500413enum class GrImageStorageFormat {
414 kRGBA8,
415 kRGBA8i,
416 kRGBA16f,
417 kRGBA32f,
418};
419
420/**
421 * Describes types of caching and compiler optimizations allowed for certain variable types
422 * (currently only image storages).
423 **/
424enum class GrSLMemoryModel {
425 /** No special restrctions on memory accesses or compiler optimizations */
426 kNone,
427 /** Cache coherent across shader invocations */
428 kCoherent,
429 /**
430 * Disallows compiler from eliding loads or stores that appear redundant in a single
431 * invocation. Implies coherent.
432 */
433 kVolatile
434};
435
436/**
437 * If kYes then the memory backing the varialble is only accessed via the variable. This is
438 * currently only used with image storages.
439 */
440enum class GrSLRestrict {
441 kYes,
442 kNo,
443};
444
445//////////////////////////////////////////////////////////////////////////////
446
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000447/**
448* We have coverage effects that clip rendering to the edge of some geometric primitive.
skia.committer@gmail.com06acb582014-03-06 03:02:32 +0000449* This enum specifies how that clipping is performed. Not all factories that take a
joshualittb0a8a372014-09-23 09:50:21 -0700450* 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 +0000451* a NULL return.
452*/
joshualittb0a8a372014-09-23 09:50:21 -0700453enum GrPrimitiveEdgeType {
454 kFillBW_GrProcessorEdgeType,
455 kFillAA_GrProcessorEdgeType,
456 kInverseFillBW_GrProcessorEdgeType,
457 kInverseFillAA_GrProcessorEdgeType,
458 kHairlineAA_GrProcessorEdgeType,
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000459
joshualittb0a8a372014-09-23 09:50:21 -0700460 kLast_GrProcessorEdgeType = kHairlineAA_GrProcessorEdgeType
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000461};
462
joshualittb0a8a372014-09-23 09:50:21 -0700463static const int kGrProcessorEdgeTypeCnt = kLast_GrProcessorEdgeType + 1;
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000464
joshualittb0a8a372014-09-23 09:50:21 -0700465static inline bool GrProcessorEdgeTypeIsFill(const GrPrimitiveEdgeType edgeType) {
466 return (kFillAA_GrProcessorEdgeType == edgeType || kFillBW_GrProcessorEdgeType == edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000467}
468
joshualittb0a8a372014-09-23 09:50:21 -0700469static inline bool GrProcessorEdgeTypeIsInverseFill(const GrPrimitiveEdgeType edgeType) {
470 return (kInverseFillAA_GrProcessorEdgeType == edgeType ||
471 kInverseFillBW_GrProcessorEdgeType == edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000472}
473
joshualittb0a8a372014-09-23 09:50:21 -0700474static inline bool GrProcessorEdgeTypeIsAA(const GrPrimitiveEdgeType edgeType) {
475 return (kFillBW_GrProcessorEdgeType != edgeType && kInverseFillBW_GrProcessorEdgeType != edgeType);
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000476}
477
joshualittb0a8a372014-09-23 09:50:21 -0700478static inline GrPrimitiveEdgeType GrInvertProcessorEdgeType(const GrPrimitiveEdgeType edgeType) {
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000479 switch (edgeType) {
joshualittb0a8a372014-09-23 09:50:21 -0700480 case kFillBW_GrProcessorEdgeType:
481 return kInverseFillBW_GrProcessorEdgeType;
482 case kFillAA_GrProcessorEdgeType:
483 return kInverseFillAA_GrProcessorEdgeType;
484 case kInverseFillBW_GrProcessorEdgeType:
485 return kFillBW_GrProcessorEdgeType;
486 case kInverseFillAA_GrProcessorEdgeType:
487 return kFillAA_GrProcessorEdgeType;
488 case kHairlineAA_GrProcessorEdgeType:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000489 SkFAIL("Hairline fill isn't invertible.");
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000490 }
joshualittb0a8a372014-09-23 09:50:21 -0700491 return kFillAA_GrProcessorEdgeType; // suppress warning.
commit-bot@chromium.orgcabf4b22014-03-05 18:27:43 +0000492}
493
bsalomonbcf0a522014-10-08 08:40:09 -0700494/**
495 * Indicates the type of pending IO operations that can be recorded for gpu resources.
496 */
497enum GrIOType {
498 kRead_GrIOType,
499 kWrite_GrIOType,
500 kRW_GrIOType
501};
502
jvanverth17aa0472016-01-05 10:41:27 -0800503/**
cdalton397536c2016-03-25 12:15:03 -0700504* Indicates the type of data that a GPU buffer will be used for.
505*/
506enum GrBufferType {
507 kVertex_GrBufferType,
508 kIndex_GrBufferType,
cdaltone2e71c22016-04-07 18:13:29 -0700509 kTexel_GrBufferType,
510 kDrawIndirect_GrBufferType,
cdalton397536c2016-03-25 12:15:03 -0700511 kXferCpuToGpu_GrBufferType,
512 kXferGpuToCpu_GrBufferType,
513
514 kLast_GrBufferType = kXferGpuToCpu_GrBufferType
515};
cdaltone2e71c22016-04-07 18:13:29 -0700516static const int kGrBufferTypeCount = kLast_GrBufferType + 1;
517
518static inline bool GrBufferTypeIsVertexOrIndex(GrBufferType type) {
519 SkASSERT(type >= 0 && type < kGrBufferTypeCount);
520 return type <= kIndex_GrBufferType;
521
522 GR_STATIC_ASSERT(0 == kVertex_GrBufferType);
523 GR_STATIC_ASSERT(1 == kIndex_GrBufferType);
524}
cdalton397536c2016-03-25 12:15:03 -0700525
526/**
527* Provides a performance hint regarding the frequency at which a data store will be accessed.
528*/
529enum GrAccessPattern {
530 /** Data store will be respecified repeatedly and used many times. */
531 kDynamic_GrAccessPattern,
532 /** Data store will be specified once and used many times. (Thus disqualified from caching.) */
533 kStatic_GrAccessPattern,
534 /** Data store will be specified once and used at most a few times. (Also can't be cached.) */
535 kStream_GrAccessPattern,
536
537 kLast_GrAccessPattern = kStream_GrAccessPattern
jvanverth17aa0472016-01-05 10:41:27 -0800538};
539
540
joshualitt7d022d62015-05-12 12:03:50 -0700541#ifdef SK_DEBUG
bsalomon682c2692015-05-22 14:01:46 -0700542// Takes a pointer to a GrCaps, and will suppress prints if required
543#define GrCapsDebugf(caps, ...) \
Brian Salomoneb628292017-02-15 14:12:26 -0500544 if (!(caps)->suppressPrints()) { \
bsalomon682c2692015-05-22 14:01:46 -0700545 SkDebugf(__VA_ARGS__); \
joshualitt7d022d62015-05-12 12:03:50 -0700546 }
547#else
bsalomon682c2692015-05-22 14:01:46 -0700548#define GrCapsDebugf(caps, ...)
joshualitt7d022d62015-05-12 12:03:50 -0700549#endif
550
kkinnunen2e6055b2016-04-22 01:48:29 -0700551/**
552 * Specifies if the holder owns the backend, OpenGL or Vulkan, object.
553 */
554enum class GrBackendObjectOwnership : bool {
555 /** Holder does not destroy the backend object. */
556 kBorrowed = false,
557 /** Holder destroys the backend object. */
558 kOwned = true
559};
560
bungeman06ca8ec2016-06-09 08:01:03 -0700561template <typename T> T * const * sk_sp_address_as_pointer_address(sk_sp<T> const * sp) {
562 static_assert(sizeof(T*) == sizeof(sk_sp<T>), "sk_sp not expected size.");
563 return reinterpret_cast<T * const *>(sp);
564}
565
jvanverth84741b32016-09-30 08:39:02 -0700566/*
567 * Object for CPU-GPU synchronization
568 */
Greg Daniel6be35232017-03-01 17:01:09 -0500569typedef uint64_t GrFence;
jvanverth84741b32016-09-30 08:39:02 -0700570
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +0000571#endif