8 #ifndef GrTypesPriv_DEFINED
9 #define GrTypesPriv_DEFINED
28 kTexture2DSampler_GrSLType,
29 kTextureExternalSampler_GrSLType,
30 kTexture2DRectSampler_GrSLType,
31 kTextureBufferSampler_GrSLType,
38 kLast_GrSLType = kSampler_GrSLType
40 static const int kGrSLTypeCount = kLast_GrSLType + 1;
44 kGeometry_GrShaderType,
45 kFragment_GrShaderType,
47 kLastkFragment_GrShaderType = kFragment_GrShaderType
49 static const int kGrShaderTypeCount = kLastkFragment_GrShaderType + 1;
52 kNone_GrShaderFlags = 0,
53 kVertex_GrShaderFlag = 1 << kVertex_GrShaderType,
54 kGeometry_GrShaderFlag = 1 << kGeometry_GrShaderType,
55 kFragment_GrShaderFlag = 1 << kFragment_GrShaderType
57 GR_MAKE_BITFIELD_OPS(GrShaderFlags);
59 enum class GrDrawFace {
74 kMedium_GrSLPrecision,
79 kDefault_GrSLPrecision = kMedium_GrSLPrecision,
81 kLast_GrSLPrecision = kHigh_GrSLPrecision
84 static const int kGrSLPrecisionCount = kLast_GrSLPrecision + 1;
89 static inline int GrSLTypeVectorCount(GrSLType type) {
90 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
91 static const int kCounts[] = { -1, 1, 2, 3, 4, -1, -1, -1, -1, -1, -1, -1, 1, 1, 1, -1, -1 };
94 GR_STATIC_ASSERT(0 == kVoid_GrSLType);
95 GR_STATIC_ASSERT(1 == kFloat_GrSLType);
96 GR_STATIC_ASSERT(2 == kVec2f_GrSLType);
97 GR_STATIC_ASSERT(3 == kVec3f_GrSLType);
98 GR_STATIC_ASSERT(4 == kVec4f_GrSLType);
99 GR_STATIC_ASSERT(5 == kMat22f_GrSLType);
100 GR_STATIC_ASSERT(6 == kMat33f_GrSLType);
101 GR_STATIC_ASSERT(7 == kMat44f_GrSLType);
102 GR_STATIC_ASSERT(8 == kTexture2DSampler_GrSLType);
103 GR_STATIC_ASSERT(9 == kTextureExternalSampler_GrSLType);
104 GR_STATIC_ASSERT(10 == kTexture2DRectSampler_GrSLType);
105 GR_STATIC_ASSERT(11 == kTextureBufferSampler_GrSLType);
106 GR_STATIC_ASSERT(12 == kBool_GrSLType);
107 GR_STATIC_ASSERT(13 == kInt_GrSLType);
108 GR_STATIC_ASSERT(14 == kUint_GrSLType);
109 GR_STATIC_ASSERT(15 == kTexture2D_GrSLType);
110 GR_STATIC_ASSERT(16 == kSampler_GrSLType);
111 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCounts) == kGrSLTypeCount);
116 static inline GrSLType GrSLFloatVectorType(
int count) {
117 SkASSERT(count > 0 && count <= 4);
118 return (GrSLType)(count);
120 GR_STATIC_ASSERT(kFloat_GrSLType == 1);
121 GR_STATIC_ASSERT(kVec2f_GrSLType == 2);
122 GR_STATIC_ASSERT(kVec3f_GrSLType == 3);
123 GR_STATIC_ASSERT(kVec4f_GrSLType == 4);
127 static inline bool GrSLTypeIsFloatType(GrSLType type) {
128 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
129 return type >= kFloat_GrSLType && type <= kMat44f_GrSLType;
131 GR_STATIC_ASSERT(0 == kVoid_GrSLType);
132 GR_STATIC_ASSERT(1 == kFloat_GrSLType);
133 GR_STATIC_ASSERT(2 == kVec2f_GrSLType);
134 GR_STATIC_ASSERT(3 == kVec3f_GrSLType);
135 GR_STATIC_ASSERT(4 == kVec4f_GrSLType);
136 GR_STATIC_ASSERT(5 == kMat22f_GrSLType);
137 GR_STATIC_ASSERT(6 == kMat33f_GrSLType);
138 GR_STATIC_ASSERT(7 == kMat44f_GrSLType);
139 GR_STATIC_ASSERT(8 == kTexture2DSampler_GrSLType);
140 GR_STATIC_ASSERT(9 == kTextureExternalSampler_GrSLType);
141 GR_STATIC_ASSERT(10 == kTexture2DRectSampler_GrSLType);
142 GR_STATIC_ASSERT(11 == kTextureBufferSampler_GrSLType);
143 GR_STATIC_ASSERT(12 == kBool_GrSLType);
144 GR_STATIC_ASSERT(13 == kInt_GrSLType);
145 GR_STATIC_ASSERT(14 == kUint_GrSLType);
146 GR_STATIC_ASSERT(15 == kTexture2D_GrSLType);
147 GR_STATIC_ASSERT(16 == kSampler_GrSLType);
148 GR_STATIC_ASSERT(17 == kGrSLTypeCount);
152 static inline bool GrSLTypeIsIntType(GrSLType type) {
153 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
154 return type >= kInt_GrSLType && type <= kUint_GrSLType;
156 GR_STATIC_ASSERT(0 == kVoid_GrSLType);
157 GR_STATIC_ASSERT(1 == kFloat_GrSLType);
158 GR_STATIC_ASSERT(2 == kVec2f_GrSLType);
159 GR_STATIC_ASSERT(3 == kVec3f_GrSLType);
160 GR_STATIC_ASSERT(4 == kVec4f_GrSLType);
161 GR_STATIC_ASSERT(5 == kMat22f_GrSLType);
162 GR_STATIC_ASSERT(6 == kMat33f_GrSLType);
163 GR_STATIC_ASSERT(7 == kMat44f_GrSLType);
164 GR_STATIC_ASSERT(8 == kTexture2DSampler_GrSLType);
165 GR_STATIC_ASSERT(9 == kTextureExternalSampler_GrSLType);
166 GR_STATIC_ASSERT(10 == kTexture2DRectSampler_GrSLType);
167 GR_STATIC_ASSERT(11 == kTextureBufferSampler_GrSLType);
168 GR_STATIC_ASSERT(12 == kBool_GrSLType);
169 GR_STATIC_ASSERT(13 == kInt_GrSLType);
170 GR_STATIC_ASSERT(14 == kUint_GrSLType);
171 GR_STATIC_ASSERT(15 == kTexture2D_GrSLType);
172 GR_STATIC_ASSERT(16 == kSampler_GrSLType);
173 GR_STATIC_ASSERT(17 == kGrSLTypeCount);
177 static inline bool GrSLTypeIsNumeric(GrSLType type) {
178 return GrSLTypeIsFloatType(type) || GrSLTypeIsIntType(type);
182 static inline size_t GrSLTypeSize(GrSLType type) {
183 SkASSERT(GrSLTypeIsFloatType(type));
184 static const size_t kSizes[] = {
190 2 * 2 *
sizeof(float),
191 3 * 3 *
sizeof(
float),
192 4 * 4 *
sizeof(float),
205 GR_STATIC_ASSERT(0 == kVoid_GrSLType);
206 GR_STATIC_ASSERT(1 == kFloat_GrSLType);
207 GR_STATIC_ASSERT(2 == kVec2f_GrSLType);
208 GR_STATIC_ASSERT(3 == kVec3f_GrSLType);
209 GR_STATIC_ASSERT(4 == kVec4f_GrSLType);
210 GR_STATIC_ASSERT(5 == kMat22f_GrSLType);
211 GR_STATIC_ASSERT(6 == kMat33f_GrSLType);
212 GR_STATIC_ASSERT(7 == kMat44f_GrSLType);
213 GR_STATIC_ASSERT(8 == kTexture2DSampler_GrSLType);
214 GR_STATIC_ASSERT(9 == kTextureExternalSampler_GrSLType);
215 GR_STATIC_ASSERT(10 == kTexture2DRectSampler_GrSLType);
216 GR_STATIC_ASSERT(11 == kTextureBufferSampler_GrSLType);
217 GR_STATIC_ASSERT(12 == kBool_GrSLType);
218 GR_STATIC_ASSERT(13 == kInt_GrSLType);
219 GR_STATIC_ASSERT(14 == kUint_GrSLType);
220 GR_STATIC_ASSERT(15 == kTexture2D_GrSLType);
221 GR_STATIC_ASSERT(16 == kSampler_GrSLType);
222 GR_STATIC_ASSERT(17 == kGrSLTypeCount);
225 static inline bool GrSLTypeIs2DCombinedSamplerType(GrSLType type) {
226 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
227 return type >= kTexture2DSampler_GrSLType && type <= kTexture2DRectSampler_GrSLType;
229 GR_STATIC_ASSERT(8 == kTexture2DSampler_GrSLType);
230 GR_STATIC_ASSERT(9 == kTextureExternalSampler_GrSLType);
231 GR_STATIC_ASSERT(10 == kTexture2DRectSampler_GrSLType);
234 static inline bool GrSLTypeIsCombinedSamplerType(GrSLType type) {
235 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
236 return type >= kTexture2DSampler_GrSLType && type <= kTextureBufferSampler_GrSLType;
238 GR_STATIC_ASSERT(8 == kTexture2DSampler_GrSLType);
239 GR_STATIC_ASSERT(9 == kTextureExternalSampler_GrSLType);
240 GR_STATIC_ASSERT(10 == kTexture2DRectSampler_GrSLType);
241 GR_STATIC_ASSERT(11 == kTextureBufferSampler_GrSLType);
244 static inline bool GrSLTypeAcceptsPrecision(GrSLType type) {
245 return type != kVoid_GrSLType && type != kBool_GrSLType;
253 enum GrVertexAttribType {
254 kFloat_GrVertexAttribType = 0,
255 kVec2f_GrVertexAttribType,
256 kVec3f_GrVertexAttribType,
257 kVec4f_GrVertexAttribType,
259 kUByte_GrVertexAttribType,
260 kVec4ub_GrVertexAttribType,
262 kVec2us_GrVertexAttribType,
264 kInt_GrVertexAttribType,
265 kUint_GrVertexAttribType,
267 kLast_GrVertexAttribType = kUint_GrVertexAttribType
269 static const int kGrVertexAttribTypeCount = kLast_GrVertexAttribType + 1;
274 static inline int GrVertexAttribTypeVectorCount(GrVertexAttribType type) {
275 SkASSERT(type >= 0 && type < kGrVertexAttribTypeCount);
276 static const int kCounts[] = { 1, 2, 3, 4, 1, 4, 2, 1, 1 };
277 return kCounts[type];
279 GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType);
280 GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType);
281 GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType);
282 GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType);
283 GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType);
284 GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType);
285 GR_STATIC_ASSERT(6 == kVec2us_GrVertexAttribType);
286 GR_STATIC_ASSERT(7 == kInt_GrVertexAttribType);
287 GR_STATIC_ASSERT(8 == kUint_GrVertexAttribType);
288 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCounts) == kGrVertexAttribTypeCount);
294 static inline size_t GrVertexAttribTypeSize(GrVertexAttribType type) {
295 static const size_t kSizes[] = {
308 GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType);
309 GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType);
310 GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType);
311 GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType);
312 GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType);
313 GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType);
314 GR_STATIC_ASSERT(6 == kVec2us_GrVertexAttribType);
315 GR_STATIC_ASSERT(7 == kInt_GrVertexAttribType);
316 GR_STATIC_ASSERT(8 == kUint_GrVertexAttribType);
317 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kSizes) == kGrVertexAttribTypeCount);
323 static inline bool GrVertexAttribTypeIsIntType(GrVertexAttribType type) {
324 SkASSERT(type >= 0 && type < static_cast<GrVertexAttribType>(kGrVertexAttribTypeCount));
325 return type >= kInt_GrVertexAttribType;
327 GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType);
328 GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType);
329 GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType);
330 GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType);
331 GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType);
332 GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType);
333 GR_STATIC_ASSERT(6 == kVec2us_GrVertexAttribType);
334 GR_STATIC_ASSERT(7 == kInt_GrVertexAttribType);
335 GR_STATIC_ASSERT(8 == kUint_GrVertexAttribType);
336 GR_STATIC_ASSERT(9 == kGrVertexAttribTypeCount);
342 static inline GrSLType GrVertexAttribTypeToSLType(GrVertexAttribType type) {
345 SkFAIL(
"Unsupported type conversion");
346 return kVoid_GrSLType;
347 case kUByte_GrVertexAttribType:
348 case kFloat_GrVertexAttribType:
349 return kFloat_GrSLType;
350 case kVec2us_GrVertexAttribType:
351 case kVec2f_GrVertexAttribType:
352 return kVec2f_GrSLType;
353 case kVec3f_GrVertexAttribType:
354 return kVec3f_GrSLType;
355 case kVec4ub_GrVertexAttribType:
356 case kVec4f_GrVertexAttribType:
357 return kVec4f_GrSLType;
358 case kInt_GrVertexAttribType:
359 return kInt_GrSLType;
360 case kUint_GrVertexAttribType:
361 return kUint_GrSLType;
373 enum GrPrimitiveEdgeType {
374 kFillBW_GrProcessorEdgeType,
375 kFillAA_GrProcessorEdgeType,
376 kInverseFillBW_GrProcessorEdgeType,
377 kInverseFillAA_GrProcessorEdgeType,
378 kHairlineAA_GrProcessorEdgeType,
380 kLast_GrProcessorEdgeType = kHairlineAA_GrProcessorEdgeType
383 static const int kGrProcessorEdgeTypeCnt = kLast_GrProcessorEdgeType + 1;
385 static inline bool GrProcessorEdgeTypeIsFill(
const GrPrimitiveEdgeType edgeType) {
386 return (kFillAA_GrProcessorEdgeType == edgeType || kFillBW_GrProcessorEdgeType == edgeType);
389 static inline bool GrProcessorEdgeTypeIsInverseFill(
const GrPrimitiveEdgeType edgeType) {
390 return (kInverseFillAA_GrProcessorEdgeType == edgeType ||
391 kInverseFillBW_GrProcessorEdgeType == edgeType);
394 static inline bool GrProcessorEdgeTypeIsAA(
const GrPrimitiveEdgeType edgeType) {
395 return (kFillBW_GrProcessorEdgeType != edgeType && kInverseFillBW_GrProcessorEdgeType != edgeType);
398 static inline GrPrimitiveEdgeType GrInvertProcessorEdgeType(
const GrPrimitiveEdgeType edgeType) {
400 case kFillBW_GrProcessorEdgeType:
401 return kInverseFillBW_GrProcessorEdgeType;
402 case kFillAA_GrProcessorEdgeType:
403 return kInverseFillAA_GrProcessorEdgeType;
404 case kInverseFillBW_GrProcessorEdgeType:
405 return kFillBW_GrProcessorEdgeType;
406 case kInverseFillAA_GrProcessorEdgeType:
407 return kFillAA_GrProcessorEdgeType;
408 case kHairlineAA_GrProcessorEdgeType:
409 SkFAIL(
"Hairline fill isn't invertible.");
411 return kFillAA_GrProcessorEdgeType;
426 void setDisabled() { fEnabled =
false; }
427 void set(
const SkIRect& rect) { fRect = rect; fEnabled =
true; }
428 bool SK_WARN_UNUSED_RESULT intersect(
const SkIRect& rect) {
436 return fEnabled == other.fEnabled &&
437 (
false == fEnabled || fRect == other.fRect);
439 bool operator!=(
const GrScissorState& other)
const {
return !(*
this == other); }
441 bool enabled()
const {
return fEnabled; }
442 const SkIRect& rect()
const {
return fRect; }
453 kVertex_GrBufferType,
456 kDrawIndirect_GrBufferType,
457 kXferCpuToGpu_GrBufferType,
458 kXferGpuToCpu_GrBufferType,
460 kLast_GrBufferType = kXferGpuToCpu_GrBufferType
462 static const int kGrBufferTypeCount = kLast_GrBufferType + 1;
464 static inline bool GrBufferTypeIsVertexOrIndex(GrBufferType type) {
465 SkASSERT(type >= 0 && type < kGrBufferTypeCount);
466 return type <= kIndex_GrBufferType;
468 GR_STATIC_ASSERT(0 == kVertex_GrBufferType);
469 GR_STATIC_ASSERT(1 == kIndex_GrBufferType);
475 enum GrAccessPattern {
477 kDynamic_GrAccessPattern,
479 kStatic_GrAccessPattern,
481 kStream_GrAccessPattern,
483 kLast_GrAccessPattern = kStream_GrAccessPattern
489 #define GrCapsDebugf(caps, ...) \
490 if (!caps->suppressPrints()) { \
491 SkDebugf(__VA_ARGS__); \
494 #define GrCapsDebugf(caps, ...)
500 enum class GrBackendObjectOwnership : bool {
507 template <
typename T> T *
const * sk_sp_address_as_pointer_address(
sk_sp<T> const * sp) {
508 static_assert(
sizeof(T*) ==
sizeof(
sk_sp<T>),
"sk_sp not expected size.");
509 return reinterpret_cast<T *
const *
>(sp);
Shared pointer class to wrap classes that support a ref()/unref() interface.
Definition: SkRefCnt.h:258
Definition: GrTypesPriv.h:423
bool SK_WARN_UNUSED_RESULT intersect(const SkIRect &r)
If r intersects this rectangle, return true and set this rectangle to that intersection, otherwise return false and do not change this rectangle.
Definition: SkRect.h:283
SkIRect holds four 32 bit integer coordinates for a rectangle.
Definition: SkRect.h:20