OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2016 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 GrInstancedRenderingTypes_DEFINED |
| 9 #define GrInstancedRenderingTypes_DEFINED |
| 10 |
| 11 #include "GrTypes.h" |
| 12 #include "SkRRect.h" |
| 13 |
| 14 /** |
| 15 * Internal structs and enums for classes involved in instanced rendering. This
class is intended |
| 16 * to be inherited non-publicly. |
| 17 */ |
| 18 class GrInstancedRenderingTypes { |
| 19 public: |
| 20 /** |
| 21 * Per-vertex data. These values get fed into normal vertex attribs. |
| 22 */ |
| 23 struct ShapeVertex { |
| 24 float fX, fY; //!< Shape coordinates. |
| 25 int32_t fAttrs; //!< Shape-specific vertex attributes, if needed. |
| 26 }; |
| 27 |
| 28 /** |
| 29 * Per-instance data. These values get fed into instanced vertex attribs. |
| 30 */ |
| 31 struct Instance { |
| 32 uint32_t fInfo; //!< Packed info about the instance. See
InfoBits. |
| 33 float fShapeMatrix2x3[6]; //!< Maps canonical shape coords -> devi
ce space coords. |
| 34 uint32_t fColor; //!< Color to be written out by the prim
itive processor. |
| 35 float fLocalRect[4]; //!< Local coords rect that spans [-1, 1
] in shape coords. |
| 36 }; |
| 37 |
| 38 /** |
| 39 * Additional parameters required by some instances (e.g. round rect radii,
perspective column, |
| 40 * local matrix). These are accessed via texel buffer. |
| 41 */ |
| 42 struct ParamsTexel { |
| 43 union { |
| 44 struct { float fX, fY, fZ, fW; }; |
| 45 float fValues[4]; |
| 46 }; |
| 47 }; |
| 48 |
| 49 GR_STATIC_ASSERT(0 == offsetof(ParamsTexel, fX)); |
| 50 GR_STATIC_ASSERT(4 * 4 == sizeof(ParamsTexel)); |
| 51 |
| 52 enum AttribIdx { |
| 53 kShapeCoords_AttribIdx, |
| 54 kVertexAttrs_AttribIdx, |
| 55 kInstanceInfo_AttribIdx, |
| 56 kShapeMatrixX_AttribIdx, |
| 57 kShapeMatrixY_AttribIdx, |
| 58 kColor_AttribIdx, |
| 59 kLocalRect_AttribIdx, |
| 60 |
| 61 kNumVertexAttribs |
| 62 }; |
| 63 |
| 64 enum ShapeType { |
| 65 kRect_ShapeType, |
| 66 kOval_ShapeType, |
| 67 kSimpleRRect_ShapeType, |
| 68 kNinePatch_ShapeType, |
| 69 kComplexRRect_ShapeType, |
| 70 |
| 71 kLast_ShapeType = kComplexRRect_ShapeType |
| 72 }; |
| 73 |
| 74 static ShapeType RRectShapeType(const SkRRect& rrect) { |
| 75 SkASSERT(rrect.getType() >= SkRRect::kRect_Type && |
| 76 rrect.getType() <= SkRRect::kComplex_Type); |
| 77 return static_cast<ShapeType>(rrect.getType() - 1); |
| 78 |
| 79 GR_STATIC_ASSERT(kRect_ShapeType == SkRRect::kRect_Type - 1); |
| 80 GR_STATIC_ASSERT(kOval_ShapeType == SkRRect::kOval_Type - 1); |
| 81 GR_STATIC_ASSERT(kSimpleRRect_ShapeType == SkRRect::kSimple_Type - 1); |
| 82 GR_STATIC_ASSERT(kNinePatch_ShapeType == SkRRect::kNinePatch_Type - 1); |
| 83 GR_STATIC_ASSERT(kComplexRRect_ShapeType == SkRRect::kComplex_Type - 1); |
| 84 GR_STATIC_ASSERT(kLast_ShapeType == SkRRect::kComplex_Type - 1); |
| 85 } |
| 86 |
| 87 enum ShapeFlag { |
| 88 kRect_ShapeFlag = (1 << kRect_ShapeType), |
| 89 kOval_ShapeFlag = (1 << kOval_ShapeType), |
| 90 kSimpleRRect_ShapeFlag = (1 << kSimpleRRect_ShapeType), |
| 91 kNinePatch_ShapeFlag = (1 << kNinePatch_ShapeType), |
| 92 kComplexRRect_ShapeFlag = (1 << kComplexRRect_ShapeType), |
| 93 |
| 94 kRRect_ShapesMask = kSimpleRRect_ShapeFlag | kNinePatch_ShapeFlag | kCom
plexRRect_ShapeFlag |
| 95 }; |
| 96 |
| 97 /** |
| 98 * Defines what data is stored at which bits in the fInfo field of the insta
nced data. |
| 99 */ |
| 100 enum InfoBits { |
| 101 kShapeType_InfoBit = 29, |
| 102 kInnerShapeType_InfoBit = 27, |
| 103 kPerspective_InfoBit = 26, |
| 104 kLocalMatrix_InfoBit = 25, |
| 105 kParamsIdx_InfoBit = 0 |
| 106 }; |
| 107 |
| 108 enum InfoMasks { |
| 109 kShapeType_InfoMask = 0u - (1 << kShapeType_InfoBit), |
| 110 kInnerShapeType_InfoMask = (1 << kShapeType_InfoBit) - (1 << kInnerShap
eType_InfoBit), |
| 111 kPerspective_InfoFlag = (1 << kPerspective_InfoBit), |
| 112 kLocalMatrix_InfoFlag = (1 << kLocalMatrix_InfoBit), |
| 113 kParamsIdx_InfoMask = (1 << kLocalMatrix_InfoBit) - 1 |
| 114 }; |
| 115 |
| 116 GR_STATIC_ASSERT(kLast_ShapeType <= kShapeType_InfoMask >> kShapeType_InfoBi
t); |
| 117 GR_STATIC_ASSERT(kSimpleRRect_ShapeType <= kInnerShapeType_InfoMask >> kInne
rShapeType_InfoBit); |
| 118 |
| 119 struct BatchTracker { |
| 120 BatchTracker() : fData(0) {} |
| 121 |
| 122 bool isSimpleRects() const { |
| 123 return !((fShapeTypes & ~kRect_ShapeFlag) | fInnerShapeTypes); |
| 124 } |
| 125 |
| 126 void join(BatchTracker other) { fData |= other.fData; } |
| 127 |
| 128 union { |
| 129 struct { |
| 130 uint8_t fShapeTypes; |
| 131 uint8_t fInnerShapeTypes; |
| 132 bool fHasPerspective : 1; |
| 133 bool fHasLocalMatrix : 1; |
| 134 bool fHasParams : 1; |
| 135 bool fNonSquare : 1; |
| 136 bool fUsesColor : 1; |
| 137 bool fUsesCoverage : 1; |
| 138 bool fUsesLocalCoords : 1; |
| 139 bool fCannotTweakAlphaForCoverage : 1; |
| 140 }; |
| 141 uint32_t fData; |
| 142 }; |
| 143 }; |
| 144 |
| 145 // This is required since all the data must fit into 32 bits of a shader key
. |
| 146 GR_STATIC_ASSERT(sizeof(uint32_t) == sizeof(BatchTracker)); |
| 147 GR_STATIC_ASSERT(kLast_ShapeType <= 8); |
| 148 |
| 149 enum AntialiasMode { |
| 150 kNone_AntialiasMode, |
| 151 kCoverage_AntialiasMode, |
| 152 kMSAA_AntialiasMode, |
| 153 kMixedSamples_AntialiasMode, |
| 154 |
| 155 kLast_AntialiasMode = kMixedSamples_AntialiasMode |
| 156 }; |
| 157 |
| 158 enum AntialiasFlags { |
| 159 kNone_AntialiasFlag = (1 << kNone_AntialiasMode), |
| 160 kCoverage_AntialiasFlag = (1 << kCoverage_AntialiasMode), |
| 161 kMSAA_AntialiasFlag = (1 << kMSAA_AntialiasMode), |
| 162 kMixedSamples_AntialiasFlag = (1 << kMixedSamples_AntialiasMode) |
| 163 }; |
| 164 }; |
| 165 |
| 166 #endif |
OLD | NEW |