OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 #include "GrDefaultGeoProcFactory.h" | 8 #include "GrDefaultGeoProcFactory.h" |
9 | 9 |
10 #include "GrInvariantOutput.h" | 10 #include "GrInvariantOutput.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 } | 33 } |
34 | 34 |
35 const char* name() const override { return "DefaultGeometryProcessor"; } | 35 const char* name() const override { return "DefaultGeometryProcessor"; } |
36 | 36 |
37 const Attribute* inPosition() const { return fInPosition; } | 37 const Attribute* inPosition() const { return fInPosition; } |
38 const Attribute* inColor() const { return fInColor; } | 38 const Attribute* inColor() const { return fInColor; } |
39 const Attribute* inLocalCoords() const { return fInLocalCoords; } | 39 const Attribute* inLocalCoords() const { return fInLocalCoords; } |
40 const Attribute* inCoverage() const { return fInCoverage; } | 40 const Attribute* inCoverage() const { return fInCoverage; } |
41 GrColor color() const { return fColor; } | 41 GrColor color() const { return fColor; } |
42 const SkMatrix& viewMatrix() const { return fViewMatrix; } | 42 const SkMatrix& viewMatrix() const { return fViewMatrix; } |
| 43 const SkMatrix& localMatrix() const { return fLocalMatrix; } |
43 uint8_t coverage() const { return fCoverage; } | 44 uint8_t coverage() const { return fCoverage; } |
44 | 45 |
45 void initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const
override { | 46 void initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const
override { |
46 BatchTracker* local = bt->cast<BatchTracker>(); | 47 BatchTracker* local = bt->cast<BatchTracker>(); |
47 local->fInputColorType = GetColorInputType(&local->fColor, this->color()
, init, | 48 local->fInputColorType = GetColorInputType(&local->fColor, this->color()
, init, |
48 SkToBool(fInColor)); | 49 SkToBool(fInColor)); |
49 | 50 |
50 bool hasVertexCoverage = SkToBool(fInCoverage) && !init.fCoverageIgnored
; | 51 bool hasVertexCoverage = SkToBool(fInCoverage) && !init.fCoverageIgnored
; |
51 bool covIsSolidWhite = !hasVertexCoverage && 0xff == this->coverage(); | 52 bool covIsSolidWhite = !hasVertexCoverage && 0xff == this->coverage(); |
52 if (init.fCoverageIgnored) { | 53 if (init.fCoverageIgnored) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 } | 115 } |
115 | 116 |
116 static inline void GenKey(const GrGeometryProcessor& gp, | 117 static inline void GenKey(const GrGeometryProcessor& gp, |
117 const GrBatchTracker& bt, | 118 const GrBatchTracker& bt, |
118 const GrGLSLCaps&, | 119 const GrGLSLCaps&, |
119 GrProcessorKeyBuilder* b) { | 120 GrProcessorKeyBuilder* b) { |
120 const DefaultGeoProc& def = gp.cast<DefaultGeoProc>(); | 121 const DefaultGeoProc& def = gp.cast<DefaultGeoProc>(); |
121 const BatchTracker& local = bt.cast<BatchTracker>(); | 122 const BatchTracker& local = bt.cast<BatchTracker>(); |
122 uint32_t key = def.fFlags; | 123 uint32_t key = def.fFlags; |
123 key |= local.fInputColorType << 8 | local.fInputCoverageType << 16; | 124 key |= local.fInputColorType << 8 | local.fInputCoverageType << 16; |
124 key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ?
0x1 << 24 : 0x0; | 125 key |= local.fUsesLocalCoords && def.localMatrix().hasPerspective()
? 0x1 << 24 : 0x0; |
125 key |= ComputePosKey(def.viewMatrix()) << 25; | 126 key |= ComputePosKey(def.viewMatrix()) << 25; |
126 b->add32(key); | 127 b->add32(key); |
127 } | 128 } |
128 | 129 |
129 virtual void setData(const GrGLProgramDataManager& pdman, | 130 virtual void setData(const GrGLProgramDataManager& pdman, |
130 const GrPrimitiveProcessor& gp, | 131 const GrPrimitiveProcessor& gp, |
131 const GrBatchTracker& bt) override { | 132 const GrBatchTracker& bt) override { |
132 const DefaultGeoProc& dgp = gp.cast<DefaultGeoProc>(); | 133 const DefaultGeoProc& dgp = gp.cast<DefaultGeoProc>(); |
133 this->setUniformViewMatrix(pdman, dgp.viewMatrix()); | 134 this->setUniformViewMatrix(pdman, dgp.viewMatrix()); |
134 | 135 |
135 const BatchTracker& local = bt.cast<BatchTracker>(); | 136 const BatchTracker& local = bt.cast<BatchTracker>(); |
136 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != f
Color) { | 137 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != f
Color) { |
137 GrGLfloat c[4]; | 138 GrGLfloat c[4]; |
138 GrColorToRGBAFloat(local.fColor, c); | 139 GrColorToRGBAFloat(local.fColor, c); |
139 pdman.set4fv(fColorUniform, 1, c); | 140 pdman.set4fv(fColorUniform, 1, c); |
140 fColor = local.fColor; | 141 fColor = local.fColor; |
141 } | 142 } |
142 if (kUniform_GrGPInput == local.fInputCoverageType && local.fCoverag
e != fCoverage) { | 143 if (kUniform_GrGPInput == local.fInputCoverageType && local.fCoverag
e != fCoverage) { |
143 pdman.set1f(fCoverageUniform, GrNormalizeByteToFloat(local.fCove
rage)); | 144 pdman.set1f(fCoverageUniform, GrNormalizeByteToFloat(local.fCove
rage)); |
144 fCoverage = local.fCoverage; | 145 fCoverage = local.fCoverage; |
145 } | 146 } |
146 } | 147 } |
147 | 148 |
| 149 void setTransformData(const GrPrimitiveProcessor& primProc, |
| 150 const GrGLProgramDataManager& pdman, |
| 151 int index, |
| 152 const SkTArray<const GrCoordTransform*, true>& tra
nsforms) override { |
| 153 this->setTransformDataHelper<DefaultGeoProc>(primProc, pdman, index,
transforms); |
| 154 } |
| 155 |
148 private: | 156 private: |
149 GrColor fColor; | 157 GrColor fColor; |
150 uint8_t fCoverage; | 158 uint8_t fCoverage; |
151 UniformHandle fColorUniform; | 159 UniformHandle fColorUniform; |
152 UniformHandle fCoverageUniform; | 160 UniformHandle fCoverageUniform; |
153 | 161 |
154 typedef GrGLGeometryProcessor INHERITED; | 162 typedef GrGLGeometryProcessor INHERITED; |
155 }; | 163 }; |
156 | 164 |
157 virtual void getGLProcessorKey(const GrBatchTracker& bt, | 165 virtual void getGLProcessorKey(const GrBatchTracker& bt, |
158 const GrGLSLCaps& caps, | 166 const GrGLSLCaps& caps, |
159 GrProcessorKeyBuilder* b) const override { | 167 GrProcessorKeyBuilder* b) const override { |
160 GLProcessor::GenKey(*this, bt, caps, b); | 168 GLProcessor::GenKey(*this, bt, caps, b); |
161 } | 169 } |
162 | 170 |
163 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, | 171 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, |
164 const GrGLSLCaps&) const ov
erride { | 172 const GrGLSLCaps&) const ov
erride { |
165 return SkNEW_ARGS(GLProcessor, (*this, bt)); | 173 return SkNEW_ARGS(GLProcessor, (*this, bt)); |
166 } | 174 } |
167 | 175 |
168 private: | 176 private: |
169 DefaultGeoProc(uint32_t gpTypeFlags, | 177 DefaultGeoProc(uint32_t gpTypeFlags, |
170 GrColor color, | 178 GrColor color, |
171 const SkMatrix& viewMatrix, | 179 const SkMatrix& viewMatrix, |
172 const SkMatrix& localMatrix, | 180 const SkMatrix& localMatrix, |
173 uint8_t coverage) | 181 uint8_t coverage) |
174 : INHERITED(localMatrix) | 182 : fInPosition(NULL) |
175 , fInPosition(NULL) | |
176 , fInColor(NULL) | 183 , fInColor(NULL) |
177 , fInLocalCoords(NULL) | 184 , fInLocalCoords(NULL) |
178 , fInCoverage(NULL) | 185 , fInCoverage(NULL) |
179 , fColor(color) | 186 , fColor(color) |
180 , fViewMatrix(viewMatrix) | 187 , fViewMatrix(viewMatrix) |
| 188 , fLocalMatrix(localMatrix) |
181 , fCoverage(coverage) | 189 , fCoverage(coverage) |
182 , fFlags(gpTypeFlags) { | 190 , fFlags(gpTypeFlags) { |
183 this->initClassID<DefaultGeoProc>(); | 191 this->initClassID<DefaultGeoProc>(); |
184 bool hasColor = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kColor_G
PType); | 192 bool hasColor = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kColor_G
PType); |
185 bool hasLocalCoord = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kLo
calCoord_GPType); | 193 bool hasLocalCoord = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kLo
calCoord_GPType); |
186 bool hasCoverage = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kCove
rage_GPType); | 194 bool hasCoverage = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kCove
rage_GPType); |
187 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVe
rtexAttribType)); | 195 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVe
rtexAttribType)); |
188 if (hasColor) { | 196 if (hasColor) { |
189 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVer
texAttribType)); | 197 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVer
texAttribType)); |
190 } | 198 } |
(...skipping 15 matching lines...) Expand all Loading... |
206 GrColor fCoverage; | 214 GrColor fCoverage; |
207 bool fUsesLocalCoords; | 215 bool fUsesLocalCoords; |
208 }; | 216 }; |
209 | 217 |
210 const Attribute* fInPosition; | 218 const Attribute* fInPosition; |
211 const Attribute* fInColor; | 219 const Attribute* fInColor; |
212 const Attribute* fInLocalCoords; | 220 const Attribute* fInLocalCoords; |
213 const Attribute* fInCoverage; | 221 const Attribute* fInCoverage; |
214 GrColor fColor; | 222 GrColor fColor; |
215 SkMatrix fViewMatrix; | 223 SkMatrix fViewMatrix; |
| 224 SkMatrix fLocalMatrix; |
216 uint8_t fCoverage; | 225 uint8_t fCoverage; |
217 uint32_t fFlags; | 226 uint32_t fFlags; |
218 | 227 |
219 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; | 228 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
220 | 229 |
221 typedef GrGeometryProcessor INHERITED; | 230 typedef GrGeometryProcessor INHERITED; |
222 }; | 231 }; |
223 | 232 |
224 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DefaultGeoProc); | 233 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DefaultGeoProc); |
225 | 234 |
(...skipping 23 matching lines...) Expand all Loading... |
249 GrColor color, | 258 GrColor color, |
250 const SkMatrix& viewM
atrix, | 259 const SkMatrix& viewM
atrix, |
251 const SkMatrix& local
Matrix, | 260 const SkMatrix& local
Matrix, |
252 uint8_t coverage) { | 261 uint8_t coverage) { |
253 return DefaultGeoProc::Create(gpTypeFlags, | 262 return DefaultGeoProc::Create(gpTypeFlags, |
254 color, | 263 color, |
255 viewMatrix, | 264 viewMatrix, |
256 localMatrix, | 265 localMatrix, |
257 coverage); | 266 coverage); |
258 } | 267 } |
OLD | NEW |