| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrTypesPriv_DEFINED | 8 #ifndef GrTypesPriv_DEFINED |
| 9 #define GrTypesPriv_DEFINED | 9 #define GrTypesPriv_DEFINED |
| 10 | 10 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 /** | 109 /** |
| 110 * Types used to describe format of vertices in arrays. | 110 * Types used to describe format of vertices in arrays. |
| 111 */ | 111 */ |
| 112 enum GrVertexAttribType { | 112 enum GrVertexAttribType { |
| 113 kFloat_GrVertexAttribType = 0, | 113 kFloat_GrVertexAttribType = 0, |
| 114 kVec2f_GrVertexAttribType, | 114 kVec2f_GrVertexAttribType, |
| 115 kVec3f_GrVertexAttribType, | 115 kVec3f_GrVertexAttribType, |
| 116 kVec4f_GrVertexAttribType, | 116 kVec4f_GrVertexAttribType, |
| 117 | 117 |
| 118 kUByte_GrVertexAttribType, // unsigned byte, e.g. coverage | 118 kUByte_GrVertexAttribType, // unsigned byte, e.g. coverage |
| 119 kVec4ub_GrVertexAttribType, // vector of 4 unsigned bytes, e.g. colors | 119 kVec4ub_GrVertexAttribType, // vector of 4 unsigned bytes, e.g. colors |
| 120 | 120 |
| 121 kVec2s_GrVertexAttribType, // vector of 2 shorts, e.g. texture coordinates | 121 kLast_GrVertexAttribType = kVec4ub_GrVertexAttribType |
| 122 | |
| 123 kLast_GrVertexAttribType = kVec2s_GrVertexAttribType | |
| 124 }; | 122 }; |
| 125 static const int kGrVertexAttribTypeCount = kLast_GrVertexAttribType + 1; | 123 static const int kGrVertexAttribTypeCount = kLast_GrVertexAttribType + 1; |
| 126 | 124 |
| 127 /** | 125 /** |
| 128 * Returns the vector size of the type. | 126 * Returns the vector size of the type. |
| 129 */ | 127 */ |
| 130 static inline int GrVertexAttribTypeVectorCount(GrVertexAttribType type) { | 128 static inline int GrVertexAttribTypeVectorCount(GrVertexAttribType type) { |
| 131 SkASSERT(type >= 0 && type < kGrVertexAttribTypeCount); | 129 SkASSERT(type >= 0 && type < kGrVertexAttribTypeCount); |
| 132 static const int kCounts[] = { 1, 2, 3, 4, 1, 4, 2 }; | 130 static const int kCounts[] = { 1, 2, 3, 4, 1, 4 }; |
| 133 return kCounts[type]; | 131 return kCounts[type]; |
| 134 | 132 |
| 135 GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType); | 133 GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType); |
| 136 GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType); | 134 GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType); |
| 137 GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType); | 135 GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType); |
| 138 GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType); | 136 GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType); |
| 139 GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType); | 137 GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType); |
| 140 GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType); | 138 GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType); |
| 141 GR_STATIC_ASSERT(6 == kVec2s_GrVertexAttribType); | |
| 142 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCounts) == kGrVertexAttribTypeCount); | 139 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCounts) == kGrVertexAttribTypeCount); |
| 143 } | 140 } |
| 144 | 141 |
| 145 /** | 142 /** |
| 146 * Returns the size of the attrib type in bytes. | 143 * Returns the size of the attrib type in bytes. |
| 147 */ | 144 */ |
| 148 static inline size_t GrVertexAttribTypeSize(GrVertexAttribType type) { | 145 static inline size_t GrVertexAttribTypeSize(GrVertexAttribType type) { |
| 149 SkASSERT(type >= 0 && type < kGrVertexAttribTypeCount); | 146 SkASSERT(type >= 0 && type < kGrVertexAttribTypeCount); |
| 150 static const size_t kSizes[] = { | 147 static const size_t kSizes[] = { |
| 151 sizeof(float), // kFloat_GrVertexAttribType | 148 sizeof(float), // kFloat_GrVertexAttribType |
| 152 2*sizeof(float), // kVec2f_GrVertexAttribType | 149 2*sizeof(float), // kVec2f_GrVertexAttribType |
| 153 3*sizeof(float), // kVec3f_GrVertexAttribType | 150 3*sizeof(float), // kVec3f_GrVertexAttribType |
| 154 4*sizeof(float), // kVec4f_GrVertexAttribType | 151 4*sizeof(float), // kVec4f_GrVertexAttribType |
| 155 1*sizeof(char), // kUByte_GrVertexAttribType | 152 1*sizeof(char), // kUByte_GrVertexAttribType |
| 156 4*sizeof(char), // kVec4ub_GrVertexAttribType | 153 4*sizeof(char) // kVec4ub_GrVertexAttribType |
| 157 2*sizeof(int16_t) // kVec2s_GrVertexAttribType | |
| 158 }; | 154 }; |
| 159 return kSizes[type]; | 155 return kSizes[type]; |
| 160 | 156 |
| 161 GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType); | 157 GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType); |
| 162 GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType); | 158 GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType); |
| 163 GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType); | 159 GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType); |
| 164 GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType); | 160 GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType); |
| 165 GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType); | 161 GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType); |
| 166 GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType); | 162 GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType); |
| 167 GR_STATIC_ASSERT(6 == kVec2s_GrVertexAttribType); | |
| 168 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kSizes) == kGrVertexAttribTypeCount); | 163 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kSizes) == kGrVertexAttribTypeCount); |
| 169 } | 164 } |
| 170 | 165 |
| 171 /** | 166 /** |
| 172 * converts a GrVertexAttribType to a GrSLType | 167 * converts a GrVertexAttribType to a GrSLType |
| 173 */ | 168 */ |
| 174 static inline GrSLType GrVertexAttribTypeToSLType(GrVertexAttribType type) { | 169 static inline GrSLType GrVertexAttribTypeToSLType(GrVertexAttribType type) { |
| 175 switch (type) { | 170 switch (type) { |
| 176 default: | 171 default: |
| 177 SkFAIL("Unsupported type conversion"); | 172 SkFAIL("Unsupported type conversion"); |
| 178 case kUByte_GrVertexAttribType: | 173 case kUByte_GrVertexAttribType: |
| 179 case kFloat_GrVertexAttribType: | 174 case kFloat_GrVertexAttribType: |
| 180 return kFloat_GrSLType; | 175 return kFloat_GrSLType; |
| 181 case kVec2s_GrVertexAttribType: | |
| 182 case kVec2f_GrVertexAttribType: | 176 case kVec2f_GrVertexAttribType: |
| 183 return kVec2f_GrSLType; | 177 return kVec2f_GrSLType; |
| 184 case kVec3f_GrVertexAttribType: | 178 case kVec3f_GrVertexAttribType: |
| 185 return kVec3f_GrSLType; | 179 return kVec3f_GrSLType; |
| 186 case kVec4ub_GrVertexAttribType: | 180 case kVec4ub_GrVertexAttribType: |
| 187 case kVec4f_GrVertexAttribType: | 181 case kVec4f_GrVertexAttribType: |
| 188 return kVec4f_GrSLType; | 182 return kVec4f_GrSLType; |
| 189 } | 183 } |
| 190 } | 184 } |
| 191 | 185 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 | 252 |
| 259 bool enabled() const { return fEnabled; } | 253 bool enabled() const { return fEnabled; } |
| 260 const SkIRect& rect() const { return fRect; } | 254 const SkIRect& rect() const { return fRect; } |
| 261 | 255 |
| 262 private: | 256 private: |
| 263 bool fEnabled; | 257 bool fEnabled; |
| 264 SkIRect fRect; | 258 SkIRect fRect; |
| 265 }; | 259 }; |
| 266 | 260 |
| 267 #endif | 261 #endif |
| OLD | NEW |