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 #include "GrOvalRenderer.h" | 8 #include "GrOvalRenderer.h" |
9 | 9 |
10 #include "GrBatch.h" | 10 #include "GrBatch.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 * with origin at the circle center. Two vertex attributes are used: | 64 * with origin at the circle center. Two vertex attributes are used: |
65 * vec2f : position in device space of the bounding geometry vertices | 65 * vec2f : position in device space of the bounding geometry vertices |
66 * vec4f : (p.xy, outerRad, innerRad) | 66 * vec4f : (p.xy, outerRad, innerRad) |
67 * p is the position in the normalized space. | 67 * p is the position in the normalized space. |
68 * outerRad is the outerRadius in device space. | 68 * outerRad is the outerRadius in device space. |
69 * innerRad is the innerRadius in normalized space (ignored if not s
troking). | 69 * innerRad is the innerRadius in normalized space (ignored if not s
troking). |
70 */ | 70 */ |
71 | 71 |
72 class CircleEdgeEffect : public GrGeometryProcessor { | 72 class CircleEdgeEffect : public GrGeometryProcessor { |
73 public: | 73 public: |
74 static GrGeometryProcessor* Create(GrColor color, bool stroke, const SkMatri
x& localMatrix) { | 74 static GrGeometryProcessor* Create(GrColor color, bool stroke, const SkMatri
x& localMatrix, |
75 return SkNEW_ARGS(CircleEdgeEffect, (color, stroke, localMatrix)); | 75 bool usesLocalCoords) { |
| 76 return SkNEW_ARGS(CircleEdgeEffect, (color, stroke, localMatrix, usesLoc
alCoords)); |
76 } | 77 } |
77 | 78 |
78 const Attribute* inPosition() const { return fInPosition; } | 79 const Attribute* inPosition() const { return fInPosition; } |
79 const Attribute* inCircleEdge() const { return fInCircleEdge; } | 80 const Attribute* inCircleEdge() const { return fInCircleEdge; } |
80 GrColor color() const { return fColor; } | 81 GrColor color() const { return fColor; } |
| 82 bool colorIgnored() const { return GrColor_ILLEGAL == fColor; } |
81 const SkMatrix& localMatrix() const { return fLocalMatrix; } | 83 const SkMatrix& localMatrix() const { return fLocalMatrix; } |
| 84 bool usesLocalCoords() const { return fUsesLocalCoords; } |
82 virtual ~CircleEdgeEffect() {} | 85 virtual ~CircleEdgeEffect() {} |
83 | 86 |
84 const char* name() const override { return "CircleEdge"; } | 87 const char* name() const override { return "CircleEdge"; } |
85 | 88 |
86 inline bool isStroked() const { return fStroke; } | 89 inline bool isStroked() const { return fStroke; } |
87 | 90 |
88 class GLProcessor : public GrGLGeometryProcessor { | 91 class GLProcessor : public GrGLGeometryProcessor { |
89 public: | 92 public: |
90 GLProcessor(const GrGeometryProcessor&, | 93 GLProcessor(const GrGeometryProcessor&, |
91 const GrBatchTracker&) | 94 const GrBatchTracker&) |
92 : fColor(GrColor_ILLEGAL) {} | 95 : fColor(GrColor_ILLEGAL) {} |
93 | 96 |
94 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ | 97 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ |
95 const CircleEdgeEffect& ce = args.fGP.cast<CircleEdgeEffect>(); | 98 const CircleEdgeEffect& ce = args.fGP.cast<CircleEdgeEffect>(); |
96 GrGLGPBuilder* pb = args.fPB; | 99 GrGLGPBuilder* pb = args.fPB; |
97 const BatchTracker& local = args.fBT.cast<BatchTracker>(); | |
98 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 100 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
99 | 101 |
100 // emit attributes | 102 // emit attributes |
101 vsBuilder->emitAttributes(ce); | 103 vsBuilder->emitAttributes(ce); |
102 | 104 |
103 GrGLVertToFrag v(kVec4f_GrSLType); | 105 GrGLVertToFrag v(kVec4f_GrSLType); |
104 args.fPB->addVarying("CircleEdge", &v); | 106 args.fPB->addVarying("CircleEdge", &v); |
105 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), ce.inCircleEdge()->fNa
me); | 107 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), ce.inCircleEdge()->fNa
me); |
106 | 108 |
107 // Setup pass through color | 109 // setup pass through color |
108 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputC
olor, NULL, | 110 if (!ce.colorIgnored()) { |
109 &fColorUniform); | 111 this->setupUniformColor(pb, args.fOutputColor, &fColorUniform); |
| 112 } |
110 | 113 |
111 // Setup position | 114 // Setup position |
112 this->setupPosition(pb, gpArgs, ce.inPosition()->fName); | 115 this->setupPosition(pb, gpArgs, ce.inPosition()->fName); |
113 | 116 |
114 // emit transforms | 117 // emit transforms |
115 this->emitTransforms(args.fPB, gpArgs->fPositionVar, ce.inPosition()
->fName, | 118 this->emitTransforms(args.fPB, gpArgs->fPositionVar, ce.inPosition()
->fName, |
116 ce.localMatrix(), args.fTransformsIn, args.fTra
nsformsOut); | 119 ce.localMatrix(), args.fTransformsIn, args.fTra
nsformsOut); |
117 | 120 |
118 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(
); | 121 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(
); |
119 fsBuilder->codeAppendf("float d = length(%s.xy);", v.fsIn()); | 122 fsBuilder->codeAppendf("float d = length(%s.xy);", v.fsIn()); |
120 fsBuilder->codeAppendf("float edgeAlpha = clamp(%s.z * (1.0 - d), 0.
0, 1.0);", v.fsIn()); | 123 fsBuilder->codeAppendf("float edgeAlpha = clamp(%s.z * (1.0 - d), 0.
0, 1.0);", v.fsIn()); |
121 if (ce.isStroked()) { | 124 if (ce.isStroked()) { |
122 fsBuilder->codeAppendf("float innerAlpha = clamp(%s.z * (d - %s.
w), 0.0, 1.0);", | 125 fsBuilder->codeAppendf("float innerAlpha = clamp(%s.z * (d - %s.
w), 0.0, 1.0);", |
123 v.fsIn(), v.fsIn()); | 126 v.fsIn(), v.fsIn()); |
124 fsBuilder->codeAppend("edgeAlpha *= innerAlpha;"); | 127 fsBuilder->codeAppend("edgeAlpha *= innerAlpha;"); |
125 } | 128 } |
126 | 129 |
127 fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage
); | 130 fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage
); |
128 } | 131 } |
129 | 132 |
130 static void GenKey(const GrGeometryProcessor& gp, | 133 static void GenKey(const GrGeometryProcessor& gp, |
131 const GrBatchTracker& bt, | 134 const GrBatchTracker& bt, |
132 const GrGLSLCaps&, | 135 const GrGLSLCaps&, |
133 GrProcessorKeyBuilder* b) { | 136 GrProcessorKeyBuilder* b) { |
134 const BatchTracker& local = bt.cast<BatchTracker>(); | |
135 const CircleEdgeEffect& ce = gp.cast<CircleEdgeEffect>(); | 137 const CircleEdgeEffect& ce = gp.cast<CircleEdgeEffect>(); |
136 uint16_t key = ce.isStroked() ? 0x1 : 0x0; | 138 uint16_t key = ce.isStroked() ? 0x1 : 0x0; |
137 key |= local.fUsesLocalCoords && ce.localMatrix().hasPerspective() ?
0x2 : 0x0; | 139 key |= ce.usesLocalCoords() && ce.localMatrix().hasPerspective() ? 0
x2 : 0x0; |
138 b->add32(key << 16 | local.fInputColorType); | 140 key |= ce.colorIgnored() ? 0x4 : 0x0; |
| 141 b->add32(key); |
139 } | 142 } |
140 | 143 |
141 virtual void setData(const GrGLProgramDataManager& pdman, | 144 virtual void setData(const GrGLProgramDataManager& pdman, |
142 const GrPrimitiveProcessor& gp, | 145 const GrPrimitiveProcessor& gp, |
143 const GrBatchTracker& bt) override { | 146 const GrBatchTracker& bt) override { |
144 const BatchTracker& local = bt.cast<BatchTracker>(); | 147 const CircleEdgeEffect& ce = gp.cast<CircleEdgeEffect>(); |
145 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != f
Color) { | 148 if (ce.color() != fColor) { |
146 GrGLfloat c[4]; | 149 GrGLfloat c[4]; |
147 GrColorToRGBAFloat(local.fColor, c); | 150 GrColorToRGBAFloat(ce.color(), c); |
148 pdman.set4fv(fColorUniform, 1, c); | 151 pdman.set4fv(fColorUniform, 1, c); |
149 fColor = local.fColor; | 152 fColor = ce.color(); |
150 } | 153 } |
151 } | 154 } |
152 | 155 |
153 void setTransformData(const GrPrimitiveProcessor& primProc, | 156 void setTransformData(const GrPrimitiveProcessor& primProc, |
154 const GrGLProgramDataManager& pdman, | 157 const GrGLProgramDataManager& pdman, |
155 int index, | 158 int index, |
156 const SkTArray<const GrCoordTransform*, true>& tra
nsforms) override { | 159 const SkTArray<const GrCoordTransform*, true>& tra
nsforms) override { |
157 this->setTransformDataHelper<CircleEdgeEffect>(primProc, pdman, inde
x, transforms); | 160 this->setTransformDataHelper<CircleEdgeEffect>(primProc, pdman, inde
x, transforms); |
158 } | 161 } |
159 | 162 |
160 private: | 163 private: |
161 GrColor fColor; | 164 GrColor fColor; |
162 UniformHandle fColorUniform; | 165 UniformHandle fColorUniform; |
163 typedef GrGLGeometryProcessor INHERITED; | 166 typedef GrGLGeometryProcessor INHERITED; |
164 }; | 167 }; |
165 | 168 |
166 virtual void getGLProcessorKey(const GrBatchTracker& bt, | 169 virtual void getGLProcessorKey(const GrBatchTracker& bt, |
167 const GrGLSLCaps& caps, | 170 const GrGLSLCaps& caps, |
168 GrProcessorKeyBuilder* b) const override { | 171 GrProcessorKeyBuilder* b) const override { |
169 GLProcessor::GenKey(*this, bt, caps, b); | 172 GLProcessor::GenKey(*this, bt, caps, b); |
170 } | 173 } |
171 | 174 |
172 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, | 175 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, |
173 const GrGLSLCaps&) const ov
erride { | 176 const GrGLSLCaps&) const ov
erride { |
174 return SkNEW_ARGS(GLProcessor, (*this, bt)); | 177 return SkNEW_ARGS(GLProcessor, (*this, bt)); |
175 } | 178 } |
176 | 179 |
177 void initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const
override { | |
178 BatchTracker* local = bt->cast<BatchTracker>(); | |
179 local->fInputColorType = GetColorInputType(&local->fColor, this->color()
, init, false); | |
180 local->fUsesLocalCoords = init.fUsesLocalCoords; | |
181 } | |
182 | |
183 private: | 180 private: |
184 CircleEdgeEffect(GrColor color, bool stroke, const SkMatrix& localMatrix) | 181 CircleEdgeEffect(GrColor color, bool stroke, const SkMatrix& localMatrix, bo
ol usesLocalCoords) |
185 : fColor(color) | 182 : fColor(color) |
186 , fLocalMatrix(localMatrix) { | 183 , fLocalMatrix(localMatrix) |
| 184 , fUsesLocalCoords(usesLocalCoords) { |
187 this->initClassID<CircleEdgeEffect>(); | 185 this->initClassID<CircleEdgeEffect>(); |
188 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVe
rtexAttribType)); | 186 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVe
rtexAttribType)); |
189 fInCircleEdge = &this->addVertexAttrib(Attribute("inCircleEdge", | 187 fInCircleEdge = &this->addVertexAttrib(Attribute("inCircleEdge", |
190 kVec4f_GrVertexAttrib
Type)); | 188 kVec4f_GrVertexAttrib
Type)); |
191 fStroke = stroke; | 189 fStroke = stroke; |
192 } | 190 } |
193 | 191 |
194 struct BatchTracker { | |
195 GrGPInput fInputColorType; | |
196 GrColor fColor; | |
197 bool fUsesLocalCoords; | |
198 }; | |
199 | |
200 GrColor fColor; | 192 GrColor fColor; |
201 SkMatrix fLocalMatrix; | 193 SkMatrix fLocalMatrix; |
202 const Attribute* fInPosition; | 194 const Attribute* fInPosition; |
203 const Attribute* fInCircleEdge; | 195 const Attribute* fInCircleEdge; |
204 bool fStroke; | 196 bool fStroke; |
| 197 bool fUsesLocalCoords; |
205 | 198 |
206 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; | 199 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
207 | 200 |
208 typedef GrGeometryProcessor INHERITED; | 201 typedef GrGeometryProcessor INHERITED; |
209 }; | 202 }; |
210 | 203 |
211 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(CircleEdgeEffect); | 204 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(CircleEdgeEffect); |
212 | 205 |
213 GrGeometryProcessor* CircleEdgeEffect::TestCreate(SkRandom* random, | 206 GrGeometryProcessor* CircleEdgeEffect::TestCreate(SkRandom* random, |
214 GrContext* context, | 207 GrContext* context, |
215 const GrDrawTargetCaps&, | 208 const GrDrawTargetCaps&, |
216 GrTexture* textures[]) { | 209 GrTexture* textures[]) { |
217 return CircleEdgeEffect::Create(GrRandomColor(random), | 210 return CircleEdgeEffect::Create(GrRandomColor(random), |
218 random->nextBool(), | 211 random->nextBool(), |
219 GrTest::TestMatrix(random)); | 212 GrTest::TestMatrix(random), |
| 213 random->nextBool()); |
220 } | 214 } |
221 | 215 |
222 /////////////////////////////////////////////////////////////////////////////// | 216 /////////////////////////////////////////////////////////////////////////////// |
223 | 217 |
224 /** | 218 /** |
225 * The output of this effect is a modulation of the input color and coverage for
an axis-aligned | 219 * The output of this effect is a modulation of the input color and coverage for
an axis-aligned |
226 * ellipse, specified as a 2D offset from center, and the reciprocals of the out
er and inner radii, | 220 * ellipse, specified as a 2D offset from center, and the reciprocals of the out
er and inner radii, |
227 * in both x and y directions. | 221 * in both x and y directions. |
228 * | 222 * |
229 * We are using an implicit function of x^2/a^2 + y^2/b^2 - 1 = 0. | 223 * We are using an implicit function of x^2/a^2 + y^2/b^2 - 1 = 0. |
230 */ | 224 */ |
231 | 225 |
232 class EllipseEdgeEffect : public GrGeometryProcessor { | 226 class EllipseEdgeEffect : public GrGeometryProcessor { |
233 public: | 227 public: |
234 static GrGeometryProcessor* Create(GrColor color, bool stroke, const SkMatri
x& localMatrix) { | 228 static GrGeometryProcessor* Create(GrColor color, bool stroke, const SkMatri
x& localMatrix, |
235 return SkNEW_ARGS(EllipseEdgeEffect, (color, stroke, localMatrix)); | 229 bool usesLocalCoords) { |
| 230 return SkNEW_ARGS(EllipseEdgeEffect, (color, stroke, localMatrix, usesLo
calCoords)); |
236 } | 231 } |
237 | 232 |
238 virtual ~EllipseEdgeEffect() {} | 233 virtual ~EllipseEdgeEffect() {} |
239 | 234 |
240 const char* name() const override { return "EllipseEdge"; } | 235 const char* name() const override { return "EllipseEdge"; } |
241 | 236 |
242 const Attribute* inPosition() const { return fInPosition; } | 237 const Attribute* inPosition() const { return fInPosition; } |
243 const Attribute* inEllipseOffset() const { return fInEllipseOffset; } | 238 const Attribute* inEllipseOffset() const { return fInEllipseOffset; } |
244 const Attribute* inEllipseRadii() const { return fInEllipseRadii; } | 239 const Attribute* inEllipseRadii() const { return fInEllipseRadii; } |
245 GrColor color() const { return fColor; } | 240 GrColor color() const { return fColor; } |
| 241 bool colorIgnored() const { return GrColor_ILLEGAL == fColor; } |
246 const SkMatrix& localMatrix() const { return fLocalMatrix; } | 242 const SkMatrix& localMatrix() const { return fLocalMatrix; } |
| 243 bool usesLocalCoords() const { return fUsesLocalCoords; } |
247 | 244 |
248 inline bool isStroked() const { return fStroke; } | 245 inline bool isStroked() const { return fStroke; } |
249 | 246 |
250 class GLProcessor : public GrGLGeometryProcessor { | 247 class GLProcessor : public GrGLGeometryProcessor { |
251 public: | 248 public: |
252 GLProcessor(const GrGeometryProcessor&, | 249 GLProcessor(const GrGeometryProcessor&, |
253 const GrBatchTracker&) | 250 const GrBatchTracker&) |
254 : fColor(GrColor_ILLEGAL) {} | 251 : fColor(GrColor_ILLEGAL) {} |
255 | 252 |
256 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ | 253 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ |
257 const EllipseEdgeEffect& ee = args.fGP.cast<EllipseEdgeEffect>(); | 254 const EllipseEdgeEffect& ee = args.fGP.cast<EllipseEdgeEffect>(); |
258 GrGLGPBuilder* pb = args.fPB; | 255 GrGLGPBuilder* pb = args.fPB; |
259 const BatchTracker& local = args.fBT.cast<BatchTracker>(); | |
260 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 256 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
261 | 257 |
262 // emit attributes | 258 // emit attributes |
263 vsBuilder->emitAttributes(ee); | 259 vsBuilder->emitAttributes(ee); |
264 | 260 |
265 GrGLVertToFrag ellipseOffsets(kVec2f_GrSLType); | 261 GrGLVertToFrag ellipseOffsets(kVec2f_GrSLType); |
266 args.fPB->addVarying("EllipseOffsets", &ellipseOffsets); | 262 args.fPB->addVarying("EllipseOffsets", &ellipseOffsets); |
267 vsBuilder->codeAppendf("%s = %s;", ellipseOffsets.vsOut(), | 263 vsBuilder->codeAppendf("%s = %s;", ellipseOffsets.vsOut(), |
268 ee.inEllipseOffset()->fName); | 264 ee.inEllipseOffset()->fName); |
269 | 265 |
270 GrGLVertToFrag ellipseRadii(kVec4f_GrSLType); | 266 GrGLVertToFrag ellipseRadii(kVec4f_GrSLType); |
271 args.fPB->addVarying("EllipseRadii", &ellipseRadii); | 267 args.fPB->addVarying("EllipseRadii", &ellipseRadii); |
272 vsBuilder->codeAppendf("%s = %s;", ellipseRadii.vsOut(), | 268 vsBuilder->codeAppendf("%s = %s;", ellipseRadii.vsOut(), |
273 ee.inEllipseRadii()->fName); | 269 ee.inEllipseRadii()->fName); |
274 | 270 |
275 // Setup pass through color | 271 // setup pass through color |
276 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputC
olor, NULL, | 272 if (!ee.colorIgnored()) { |
277 &fColorUniform); | 273 this->setupUniformColor(pb, args.fOutputColor, &fColorUniform); |
| 274 } |
278 | 275 |
279 // Setup position | 276 // Setup position |
280 this->setupPosition(pb, gpArgs, ee.inPosition()->fName); | 277 this->setupPosition(pb, gpArgs, ee.inPosition()->fName); |
281 | 278 |
282 // emit transforms | 279 // emit transforms |
283 this->emitTransforms(args.fPB, gpArgs->fPositionVar, ee.inPosition()
->fName, | 280 this->emitTransforms(args.fPB, gpArgs->fPositionVar, ee.inPosition()
->fName, |
284 ee.localMatrix(), args.fTransformsIn, args.fTra
nsformsOut); | 281 ee.localMatrix(), args.fTransformsIn, args.fTra
nsformsOut); |
285 | 282 |
286 // for outer curve | 283 // for outer curve |
287 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(
); | 284 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(
); |
(...skipping 19 matching lines...) Expand all Loading... |
307 fsBuilder->codeAppend("edgeAlpha *= clamp(0.5+test*invlen, 0.0,
1.0);"); | 304 fsBuilder->codeAppend("edgeAlpha *= clamp(0.5+test*invlen, 0.0,
1.0);"); |
308 } | 305 } |
309 | 306 |
310 fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage
); | 307 fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage
); |
311 } | 308 } |
312 | 309 |
313 static void GenKey(const GrGeometryProcessor& gp, | 310 static void GenKey(const GrGeometryProcessor& gp, |
314 const GrBatchTracker& bt, | 311 const GrBatchTracker& bt, |
315 const GrGLSLCaps&, | 312 const GrGLSLCaps&, |
316 GrProcessorKeyBuilder* b) { | 313 GrProcessorKeyBuilder* b) { |
317 const BatchTracker& local = bt.cast<BatchTracker>(); | |
318 const EllipseEdgeEffect& ee = gp.cast<EllipseEdgeEffect>(); | 314 const EllipseEdgeEffect& ee = gp.cast<EllipseEdgeEffect>(); |
319 uint16_t key = ee.isStroked() ? 0x1 : 0x0; | 315 uint16_t key = ee.isStroked() ? 0x1 : 0x0; |
320 key |= local.fUsesLocalCoords && ee.localMatrix().hasPerspective() ?
0x2 : 0x0; | 316 key |= ee.usesLocalCoords() && ee.localMatrix().hasPerspective() ? 0
x2 : 0x0; |
321 b->add32(key << 16 | local.fInputColorType); | 317 key |= ee.colorIgnored() ? 0x4 : 0x0; |
| 318 b->add32(key); |
322 } | 319 } |
323 | 320 |
324 virtual void setData(const GrGLProgramDataManager& pdman, | 321 virtual void setData(const GrGLProgramDataManager& pdman, |
325 const GrPrimitiveProcessor& gp, | 322 const GrPrimitiveProcessor& gp, |
326 const GrBatchTracker& bt) override { | 323 const GrBatchTracker& bt) override { |
327 | 324 const EllipseEdgeEffect& ee = gp.cast<EllipseEdgeEffect>(); |
328 const BatchTracker& local = bt.cast<BatchTracker>(); | 325 if (ee.color() != fColor) { |
329 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != f
Color) { | |
330 GrGLfloat c[4]; | 326 GrGLfloat c[4]; |
331 GrColorToRGBAFloat(local.fColor, c); | 327 GrColorToRGBAFloat(ee.color(), c); |
332 pdman.set4fv(fColorUniform, 1, c); | 328 pdman.set4fv(fColorUniform, 1, c); |
333 fColor = local.fColor; | 329 fColor = ee.color(); |
334 } | 330 } |
335 } | 331 } |
336 | 332 |
337 void setTransformData(const GrPrimitiveProcessor& primProc, | 333 void setTransformData(const GrPrimitiveProcessor& primProc, |
338 const GrGLProgramDataManager& pdman, | 334 const GrGLProgramDataManager& pdman, |
339 int index, | 335 int index, |
340 const SkTArray<const GrCoordTransform*, true>& tra
nsforms) override { | 336 const SkTArray<const GrCoordTransform*, true>& tra
nsforms) override { |
341 this->setTransformDataHelper<EllipseEdgeEffect>(primProc, pdman, ind
ex, transforms); | 337 this->setTransformDataHelper<EllipseEdgeEffect>(primProc, pdman, ind
ex, transforms); |
342 } | 338 } |
343 | 339 |
344 private: | 340 private: |
345 GrColor fColor; | 341 GrColor fColor; |
346 UniformHandle fColorUniform; | 342 UniformHandle fColorUniform; |
347 | 343 |
348 typedef GrGLGeometryProcessor INHERITED; | 344 typedef GrGLGeometryProcessor INHERITED; |
349 }; | 345 }; |
350 | 346 |
351 virtual void getGLProcessorKey(const GrBatchTracker& bt, | 347 virtual void getGLProcessorKey(const GrBatchTracker& bt, |
352 const GrGLSLCaps& caps, | 348 const GrGLSLCaps& caps, |
353 GrProcessorKeyBuilder* b) const override { | 349 GrProcessorKeyBuilder* b) const override { |
354 GLProcessor::GenKey(*this, bt, caps, b); | 350 GLProcessor::GenKey(*this, bt, caps, b); |
355 } | 351 } |
356 | 352 |
357 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, | 353 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, |
358 const GrGLSLCaps&) const ov
erride { | 354 const GrGLSLCaps&) const ov
erride { |
359 return SkNEW_ARGS(GLProcessor, (*this, bt)); | 355 return SkNEW_ARGS(GLProcessor, (*this, bt)); |
360 } | 356 } |
361 | 357 |
362 void initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const
override { | |
363 BatchTracker* local = bt->cast<BatchTracker>(); | |
364 local->fInputColorType = GetColorInputType(&local->fColor, this->color()
, init, false); | |
365 local->fUsesLocalCoords = init.fUsesLocalCoords; | |
366 } | |
367 | |
368 private: | 358 private: |
369 EllipseEdgeEffect(GrColor color, bool stroke, const SkMatrix& localMatrix) | 359 EllipseEdgeEffect(GrColor color, bool stroke, const SkMatrix& localMatrix, |
| 360 bool usesLocalCoords) |
370 : fColor(color) | 361 : fColor(color) |
371 , fLocalMatrix(localMatrix) { | 362 , fLocalMatrix(localMatrix) |
| 363 , fUsesLocalCoords(usesLocalCoords) { |
372 this->initClassID<EllipseEdgeEffect>(); | 364 this->initClassID<EllipseEdgeEffect>(); |
373 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVe
rtexAttribType)); | 365 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVe
rtexAttribType)); |
374 fInEllipseOffset = &this->addVertexAttrib(Attribute("inEllipseOffset", | 366 fInEllipseOffset = &this->addVertexAttrib(Attribute("inEllipseOffset", |
375 kVec2f_GrVertexAtt
ribType)); | 367 kVec2f_GrVertexAtt
ribType)); |
376 fInEllipseRadii = &this->addVertexAttrib(Attribute("inEllipseRadii", | 368 fInEllipseRadii = &this->addVertexAttrib(Attribute("inEllipseRadii", |
377 kVec4f_GrVertexAttr
ibType)); | 369 kVec4f_GrVertexAttr
ibType)); |
378 fStroke = stroke; | 370 fStroke = stroke; |
379 } | 371 } |
380 | 372 |
381 struct BatchTracker { | |
382 GrGPInput fInputColorType; | |
383 GrColor fColor; | |
384 bool fUsesLocalCoords; | |
385 }; | |
386 | |
387 const Attribute* fInPosition; | 373 const Attribute* fInPosition; |
388 const Attribute* fInEllipseOffset; | 374 const Attribute* fInEllipseOffset; |
389 const Attribute* fInEllipseRadii; | 375 const Attribute* fInEllipseRadii; |
390 GrColor fColor; | 376 GrColor fColor; |
391 SkMatrix fLocalMatrix; | 377 SkMatrix fLocalMatrix; |
392 bool fStroke; | 378 bool fStroke; |
| 379 bool fUsesLocalCoords; |
393 | 380 |
394 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; | 381 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
395 | 382 |
396 typedef GrGeometryProcessor INHERITED; | 383 typedef GrGeometryProcessor INHERITED; |
397 }; | 384 }; |
398 | 385 |
399 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(EllipseEdgeEffect); | 386 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(EllipseEdgeEffect); |
400 | 387 |
401 GrGeometryProcessor* EllipseEdgeEffect::TestCreate(SkRandom* random, | 388 GrGeometryProcessor* EllipseEdgeEffect::TestCreate(SkRandom* random, |
402 GrContext* context, | 389 GrContext* context, |
403 const GrDrawTargetCaps&, | 390 const GrDrawTargetCaps&, |
404 GrTexture* textures[]) { | 391 GrTexture* textures[]) { |
405 return EllipseEdgeEffect::Create(GrRandomColor(random), | 392 return EllipseEdgeEffect::Create(GrRandomColor(random), |
406 random->nextBool(), | 393 random->nextBool(), |
407 GrTest::TestMatrix(random)); | 394 GrTest::TestMatrix(random), |
| 395 random->nextBool()); |
408 } | 396 } |
409 | 397 |
410 /////////////////////////////////////////////////////////////////////////////// | 398 /////////////////////////////////////////////////////////////////////////////// |
411 | 399 |
412 /** | 400 /** |
413 * The output of this effect is a modulation of the input color and coverage for
an ellipse, | 401 * The output of this effect is a modulation of the input color and coverage for
an ellipse, |
414 * specified as a 2D offset from center for both the outer and inner paths (if s
troked). The | 402 * specified as a 2D offset from center for both the outer and inner paths (if s
troked). The |
415 * implict equation used is for a unit circle (x^2 + y^2 - 1 = 0) and the edge c
orrected by | 403 * implict equation used is for a unit circle (x^2 + y^2 - 1 = 0) and the edge c
orrected by |
416 * using differentials. | 404 * using differentials. |
417 * | 405 * |
418 * The result is device-independent and can be used with any affine matrix. | 406 * The result is device-independent and can be used with any affine matrix. |
419 */ | 407 */ |
420 | 408 |
421 class DIEllipseEdgeEffect : public GrGeometryProcessor { | 409 class DIEllipseEdgeEffect : public GrGeometryProcessor { |
422 public: | 410 public: |
423 enum Mode { kStroke = 0, kHairline, kFill }; | 411 enum Mode { kStroke = 0, kHairline, kFill }; |
424 | 412 |
425 static GrGeometryProcessor* Create(GrColor color, const SkMatrix& viewMatrix
, Mode mode) { | 413 static GrGeometryProcessor* Create(GrColor color, const SkMatrix& viewMatrix
, Mode mode, |
426 return SkNEW_ARGS(DIEllipseEdgeEffect, (color, viewMatrix, mode)); | 414 bool usesLocalCoords) { |
| 415 return SkNEW_ARGS(DIEllipseEdgeEffect, (color, viewMatrix, mode, usesLoc
alCoords)); |
427 } | 416 } |
428 | 417 |
429 virtual ~DIEllipseEdgeEffect() {} | 418 virtual ~DIEllipseEdgeEffect() {} |
430 | 419 |
431 const char* name() const override { return "DIEllipseEdge"; } | 420 const char* name() const override { return "DIEllipseEdge"; } |
432 | 421 |
433 const Attribute* inPosition() const { return fInPosition; } | 422 const Attribute* inPosition() const { return fInPosition; } |
434 const Attribute* inEllipseOffsets0() const { return fInEllipseOffsets0; } | 423 const Attribute* inEllipseOffsets0() const { return fInEllipseOffsets0; } |
435 const Attribute* inEllipseOffsets1() const { return fInEllipseOffsets1; } | 424 const Attribute* inEllipseOffsets1() const { return fInEllipseOffsets1; } |
436 GrColor color() const { return fColor; } | 425 GrColor color() const { return fColor; } |
| 426 bool colorIgnored() const { return GrColor_ILLEGAL == fColor; } |
437 const SkMatrix& viewMatrix() const { return fViewMatrix; } | 427 const SkMatrix& viewMatrix() const { return fViewMatrix; } |
| 428 bool usesLocalCoords() const { return fUsesLocalCoords; } |
438 | 429 |
439 inline Mode getMode() const { return fMode; } | 430 inline Mode getMode() const { return fMode; } |
440 | 431 |
441 class GLProcessor : public GrGLGeometryProcessor { | 432 class GLProcessor : public GrGLGeometryProcessor { |
442 public: | 433 public: |
443 GLProcessor(const GrGeometryProcessor&, | 434 GLProcessor(const GrGeometryProcessor&, |
444 const GrBatchTracker&) | 435 const GrBatchTracker&) |
445 : fColor(GrColor_ILLEGAL) {} | 436 : fColor(GrColor_ILLEGAL) {} |
446 | 437 |
447 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ | 438 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ |
448 const DIEllipseEdgeEffect& ee = args.fGP.cast<DIEllipseEdgeEffect>()
; | 439 const DIEllipseEdgeEffect& ee = args.fGP.cast<DIEllipseEdgeEffect>()
; |
449 GrGLGPBuilder* pb = args.fPB; | 440 GrGLGPBuilder* pb = args.fPB; |
450 const BatchTracker& local = args.fBT.cast<BatchTracker>(); | |
451 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 441 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
452 | 442 |
453 // emit attributes | 443 // emit attributes |
454 vsBuilder->emitAttributes(ee); | 444 vsBuilder->emitAttributes(ee); |
455 | 445 |
456 GrGLVertToFrag offsets0(kVec2f_GrSLType); | 446 GrGLVertToFrag offsets0(kVec2f_GrSLType); |
457 args.fPB->addVarying("EllipseOffsets0", &offsets0); | 447 args.fPB->addVarying("EllipseOffsets0", &offsets0); |
458 vsBuilder->codeAppendf("%s = %s;", offsets0.vsOut(), | 448 vsBuilder->codeAppendf("%s = %s;", offsets0.vsOut(), |
459 ee.inEllipseOffsets0()->fName); | 449 ee.inEllipseOffsets0()->fName); |
460 | 450 |
461 GrGLVertToFrag offsets1(kVec2f_GrSLType); | 451 GrGLVertToFrag offsets1(kVec2f_GrSLType); |
462 args.fPB->addVarying("EllipseOffsets1", &offsets1); | 452 args.fPB->addVarying("EllipseOffsets1", &offsets1); |
463 vsBuilder->codeAppendf("%s = %s;", offsets1.vsOut(), | 453 vsBuilder->codeAppendf("%s = %s;", offsets1.vsOut(), |
464 ee.inEllipseOffsets1()->fName); | 454 ee.inEllipseOffsets1()->fName); |
465 | 455 |
466 // Setup pass through color | 456 // setup pass through color |
467 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputC
olor, NULL, | 457 if (!ee.colorIgnored()) { |
468 &fColorUniform); | 458 this->setupUniformColor(pb, args.fOutputColor, &fColorUniform); |
| 459 } |
469 | 460 |
470 // Setup position | 461 // Setup position |
471 this->setupPosition(pb, gpArgs, ee.inPosition()->fName, ee.viewMatri
x()); | 462 this->setupPosition(pb, gpArgs, ee.inPosition()->fName, ee.viewMatri
x()); |
472 | 463 |
473 // emit transforms | 464 // emit transforms |
474 this->emitTransforms(args.fPB, gpArgs->fPositionVar, ee.inPosition()
->fName, | 465 this->emitTransforms(args.fPB, gpArgs->fPositionVar, ee.inPosition()
->fName, |
475 args.fTransformsIn, args.fTransformsOut); | 466 args.fTransformsIn, args.fTransformsOut); |
476 | 467 |
477 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(
); | 468 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(
); |
478 SkAssertResult(fsBuilder->enableFeature( | 469 SkAssertResult(fsBuilder->enableFeature( |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 fsBuilder->codeAppend("edgeAlpha *= clamp(0.5+test*invlen, 0.0,
1.0);"); | 503 fsBuilder->codeAppend("edgeAlpha *= clamp(0.5+test*invlen, 0.0,
1.0);"); |
513 } | 504 } |
514 | 505 |
515 fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage
); | 506 fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage
); |
516 } | 507 } |
517 | 508 |
518 static void GenKey(const GrGeometryProcessor& gp, | 509 static void GenKey(const GrGeometryProcessor& gp, |
519 const GrBatchTracker& bt, | 510 const GrBatchTracker& bt, |
520 const GrGLSLCaps&, | 511 const GrGLSLCaps&, |
521 GrProcessorKeyBuilder* b) { | 512 GrProcessorKeyBuilder* b) { |
522 const BatchTracker& local = bt.cast<BatchTracker>(); | |
523 const DIEllipseEdgeEffect& ellipseEffect = gp.cast<DIEllipseEdgeEffe
ct>(); | 513 const DIEllipseEdgeEffect& ellipseEffect = gp.cast<DIEllipseEdgeEffe
ct>(); |
524 uint16_t key = ellipseEffect.getMode(); | 514 uint16_t key = ellipseEffect.getMode(); |
525 key |= ComputePosKey(ellipseEffect.viewMatrix()) << 9; | 515 key |= ellipseEffect.colorIgnored() << 9; |
526 b->add32(key << 16 | local.fInputColorType); | 516 key |= ComputePosKey(ellipseEffect.viewMatrix()) << 10; |
| 517 b->add32(key); |
527 } | 518 } |
528 | 519 |
529 virtual void setData(const GrGLProgramDataManager& pdman, | 520 virtual void setData(const GrGLProgramDataManager& pdman, |
530 const GrPrimitiveProcessor& gp, | 521 const GrPrimitiveProcessor& gp, |
531 const GrBatchTracker& bt) override { | 522 const GrBatchTracker& bt) override { |
532 const DIEllipseEdgeEffect& dee = gp.cast<DIEllipseEdgeEffect>(); | 523 const DIEllipseEdgeEffect& dee = gp.cast<DIEllipseEdgeEffect>(); |
533 this->setUniformViewMatrix(pdman, dee.viewMatrix()); | 524 this->setUniformViewMatrix(pdman, dee.viewMatrix()); |
534 | 525 |
535 const BatchTracker& local = bt.cast<BatchTracker>(); | 526 if (dee.color() != fColor) { |
536 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != f
Color) { | |
537 GrGLfloat c[4]; | 527 GrGLfloat c[4]; |
538 GrColorToRGBAFloat(local.fColor, c); | 528 GrColorToRGBAFloat(dee.color(), c); |
539 pdman.set4fv(fColorUniform, 1, c); | 529 pdman.set4fv(fColorUniform, 1, c); |
540 fColor = local.fColor; | 530 fColor = dee.color(); |
541 } | 531 } |
542 } | 532 } |
543 | 533 |
544 private: | 534 private: |
545 GrColor fColor; | 535 GrColor fColor; |
546 UniformHandle fColorUniform; | 536 UniformHandle fColorUniform; |
547 | 537 |
548 typedef GrGLGeometryProcessor INHERITED; | 538 typedef GrGLGeometryProcessor INHERITED; |
549 }; | 539 }; |
550 | 540 |
551 virtual void getGLProcessorKey(const GrBatchTracker& bt, | 541 virtual void getGLProcessorKey(const GrBatchTracker& bt, |
552 const GrGLSLCaps& caps, | 542 const GrGLSLCaps& caps, |
553 GrProcessorKeyBuilder* b) const override { | 543 GrProcessorKeyBuilder* b) const override { |
554 GLProcessor::GenKey(*this, bt, caps, b); | 544 GLProcessor::GenKey(*this, bt, caps, b); |
555 } | 545 } |
556 | 546 |
557 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, | 547 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, |
558 const GrGLSLCaps&) const ov
erride { | 548 const GrGLSLCaps&) const ov
erride { |
559 return SkNEW_ARGS(GLProcessor, (*this, bt)); | 549 return SkNEW_ARGS(GLProcessor, (*this, bt)); |
560 } | 550 } |
561 | 551 |
562 void initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const
override { | |
563 BatchTracker* local = bt->cast<BatchTracker>(); | |
564 local->fInputColorType = GetColorInputType(&local->fColor, this->color()
, init, false); | |
565 local->fUsesLocalCoords = init.fUsesLocalCoords; | |
566 } | |
567 | |
568 private: | 552 private: |
569 DIEllipseEdgeEffect(GrColor color, const SkMatrix& viewMatrix, Mode mode) | 553 DIEllipseEdgeEffect(GrColor color, const SkMatrix& viewMatrix, Mode mode, |
| 554 bool usesLocalCoords) |
570 : fColor(color) | 555 : fColor(color) |
571 , fViewMatrix(viewMatrix) { | 556 , fViewMatrix(viewMatrix) |
| 557 , fUsesLocalCoords(usesLocalCoords) { |
572 this->initClassID<DIEllipseEdgeEffect>(); | 558 this->initClassID<DIEllipseEdgeEffect>(); |
573 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVe
rtexAttribType)); | 559 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVe
rtexAttribType)); |
574 fInEllipseOffsets0 = &this->addVertexAttrib(Attribute("inEllipseOffsets0
", | 560 fInEllipseOffsets0 = &this->addVertexAttrib(Attribute("inEllipseOffsets0
", |
575 kVec2f_GrVertexA
ttribType)); | 561 kVec2f_GrVertexAtt
ribType)); |
576 fInEllipseOffsets1 = &this->addVertexAttrib(Attribute("inEllipseOffsets1
", | 562 fInEllipseOffsets1 = &this->addVertexAttrib(Attribute("inEllipseOffsets1
", |
577 kVec2f_GrVertexA
ttribType)); | 563 kVec2f_GrVertexAtt
ribType)); |
578 fMode = mode; | 564 fMode = mode; |
579 } | 565 } |
580 | 566 |
581 struct BatchTracker { | |
582 GrGPInput fInputColorType; | |
583 GrColor fColor; | |
584 bool fUsesLocalCoords; | |
585 }; | |
586 | |
587 const Attribute* fInPosition; | 567 const Attribute* fInPosition; |
588 const Attribute* fInEllipseOffsets0; | 568 const Attribute* fInEllipseOffsets0; |
589 const Attribute* fInEllipseOffsets1; | 569 const Attribute* fInEllipseOffsets1; |
590 GrColor fColor; | 570 GrColor fColor; |
591 SkMatrix fViewMatrix; | 571 SkMatrix fViewMatrix; |
592 Mode fMode; | 572 Mode fMode; |
| 573 bool fUsesLocalCoords; |
593 | 574 |
594 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; | 575 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
595 | 576 |
596 typedef GrGeometryProcessor INHERITED; | 577 typedef GrGeometryProcessor INHERITED; |
597 }; | 578 }; |
598 | 579 |
599 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DIEllipseEdgeEffect); | 580 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DIEllipseEdgeEffect); |
600 | 581 |
601 GrGeometryProcessor* DIEllipseEdgeEffect::TestCreate(SkRandom* random, | 582 GrGeometryProcessor* DIEllipseEdgeEffect::TestCreate(SkRandom* random, |
602 GrContext* context, | 583 GrContext* context, |
603 const GrDrawTargetCaps&, | 584 const GrDrawTargetCaps&, |
604 GrTexture* textures[]) { | 585 GrTexture* textures[]) { |
605 return DIEllipseEdgeEffect::Create(GrRandomColor(random), | 586 return DIEllipseEdgeEffect::Create(GrRandomColor(random), |
606 GrTest::TestMatrix(random), | 587 GrTest::TestMatrix(random), |
607 (Mode)(random->nextRangeU(0,2))); | 588 (Mode)(random->nextRangeU(0,2)), |
| 589 random->nextBool()); |
608 } | 590 } |
609 | 591 |
610 /////////////////////////////////////////////////////////////////////////////// | 592 /////////////////////////////////////////////////////////////////////////////// |
611 | 593 |
612 bool GrOvalRenderer::drawOval(GrDrawTarget* target, | 594 bool GrOvalRenderer::drawOval(GrDrawTarget* target, |
613 GrPipelineBuilder* pipelineBuilder, | 595 GrPipelineBuilder* pipelineBuilder, |
614 GrColor color, | 596 GrColor color, |
615 const SkMatrix& viewMatrix, | 597 const SkMatrix& viewMatrix, |
616 bool useAA, | 598 bool useAA, |
617 const SkRect& oval, | 599 const SkRect& oval, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 | 667 |
686 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline
) override { | 668 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline
) override { |
687 SkMatrix invert; | 669 SkMatrix invert; |
688 if (!this->viewMatrix().invert(&invert)) { | 670 if (!this->viewMatrix().invert(&invert)) { |
689 return; | 671 return; |
690 } | 672 } |
691 | 673 |
692 // Setup geometry processor | 674 // Setup geometry processor |
693 SkAutoTUnref<GrGeometryProcessor> gp(CircleEdgeEffect::Create(this->colo
r(), | 675 SkAutoTUnref<GrGeometryProcessor> gp(CircleEdgeEffect::Create(this->colo
r(), |
694 this->stro
ke(), | 676 this->stro
ke(), |
695 invert)); | 677 invert, |
| 678 this->uses
LocalCoords())); |
696 | 679 |
697 batchTarget->initDraw(gp, pipeline); | 680 batchTarget->initDraw(gp, pipeline); |
698 | 681 |
699 // TODO this is hacky, but the only way we have to initialize the GP is
to use the | |
700 // GrPipelineInfo struct so we can generate the correct shader. Once we
have GrBatch | |
701 // everywhere we can remove this nastiness | |
702 GrPipelineInfo init; | |
703 init.fColorIgnored = fBatch.fColorIgnored; | |
704 init.fOverrideColor = GrColor_ILLEGAL; | |
705 init.fCoverageIgnored = fBatch.fCoverageIgnored; | |
706 init.fUsesLocalCoords = this->usesLocalCoords(); | |
707 gp->initBatchTracker(batchTarget->currentBatchTracker(), init); | |
708 | |
709 int instanceCount = fGeoData.count(); | 682 int instanceCount = fGeoData.count(); |
710 size_t vertexStride = gp->getVertexStride(); | 683 size_t vertexStride = gp->getVertexStride(); |
711 SkASSERT(vertexStride == sizeof(CircleVertex)); | 684 SkASSERT(vertexStride == sizeof(CircleVertex)); |
712 QuadHelper helper; | 685 QuadHelper helper; |
713 CircleVertex* verts = reinterpret_cast<CircleVertex*>(helper.init(batchT
arget, vertexStride, | 686 CircleVertex* verts = reinterpret_cast<CircleVertex*>(helper.init(batchT
arget, vertexStride, |
714 instan
ceCount)); | 687 instan
ceCount)); |
715 if (!verts) { | 688 if (!verts) { |
716 return; | 689 return; |
717 } | 690 } |
718 | 691 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
909 | 882 |
910 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline
) override { | 883 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline
) override { |
911 SkMatrix invert; | 884 SkMatrix invert; |
912 if (!this->viewMatrix().invert(&invert)) { | 885 if (!this->viewMatrix().invert(&invert)) { |
913 return; | 886 return; |
914 } | 887 } |
915 | 888 |
916 // Setup geometry processor | 889 // Setup geometry processor |
917 SkAutoTUnref<GrGeometryProcessor> gp(EllipseEdgeEffect::Create(this->col
or(), | 890 SkAutoTUnref<GrGeometryProcessor> gp(EllipseEdgeEffect::Create(this->col
or(), |
918 this->str
oke(), | 891 this->str
oke(), |
919 invert)); | 892 invert, |
| 893 this->use
sLocalCoords())); |
920 | 894 |
921 batchTarget->initDraw(gp, pipeline); | 895 batchTarget->initDraw(gp, pipeline); |
922 | 896 |
923 // TODO this is hacky, but the only way we have to initialize the GP is
to use the | |
924 // GrPipelineInfo struct so we can generate the correct shader. Once we
have GrBatch | |
925 // everywhere we can remove this nastiness | |
926 GrPipelineInfo init; | |
927 init.fColorIgnored = fBatch.fColorIgnored; | |
928 init.fOverrideColor = GrColor_ILLEGAL; | |
929 init.fCoverageIgnored = fBatch.fCoverageIgnored; | |
930 init.fUsesLocalCoords = this->usesLocalCoords(); | |
931 gp->initBatchTracker(batchTarget->currentBatchTracker(), init); | |
932 | |
933 int instanceCount = fGeoData.count(); | 897 int instanceCount = fGeoData.count(); |
934 QuadHelper helper; | 898 QuadHelper helper; |
935 size_t vertexStride = gp->getVertexStride(); | 899 size_t vertexStride = gp->getVertexStride(); |
936 SkASSERT(vertexStride == sizeof(EllipseVertex)); | 900 SkASSERT(vertexStride == sizeof(EllipseVertex)); |
937 EllipseVertex* verts = reinterpret_cast<EllipseVertex*>( | 901 EllipseVertex* verts = reinterpret_cast<EllipseVertex*>( |
938 helper.init(batchTarget, vertexStride, instanceCount)); | 902 helper.init(batchTarget, vertexStride, instanceCount)); |
939 if (!verts) { | 903 if (!verts) { |
940 return; | 904 return; |
941 } | 905 } |
942 | 906 |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1177 fBatch.fColor = fGeoData[0].fColor; | 1141 fBatch.fColor = fGeoData[0].fColor; |
1178 fBatch.fMode = fGeoData[0].fMode; | 1142 fBatch.fMode = fGeoData[0].fMode; |
1179 fBatch.fUsesLocalCoords = init.fUsesLocalCoords; | 1143 fBatch.fUsesLocalCoords = init.fUsesLocalCoords; |
1180 fBatch.fCoverageIgnored = init.fCoverageIgnored; | 1144 fBatch.fCoverageIgnored = init.fCoverageIgnored; |
1181 } | 1145 } |
1182 | 1146 |
1183 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline
) override { | 1147 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline
) override { |
1184 // Setup geometry processor | 1148 // Setup geometry processor |
1185 SkAutoTUnref<GrGeometryProcessor> gp(DIEllipseEdgeEffect::Create(this->c
olor(), | 1149 SkAutoTUnref<GrGeometryProcessor> gp(DIEllipseEdgeEffect::Create(this->c
olor(), |
1186 this->v
iewMatrix(), | 1150 this->v
iewMatrix(), |
1187 this->m
ode())); | 1151 this->m
ode(), |
| 1152 this->u
sesLocalCoords())); |
1188 | 1153 |
1189 batchTarget->initDraw(gp, pipeline); | 1154 batchTarget->initDraw(gp, pipeline); |
1190 | 1155 |
1191 // TODO this is hacky, but the only way we have to initialize the GP is
to use the | |
1192 // GrPipelineInfo struct so we can generate the correct shader. Once we
have GrBatch | |
1193 // everywhere we can remove this nastiness | |
1194 GrPipelineInfo init; | |
1195 init.fColorIgnored = fBatch.fColorIgnored; | |
1196 init.fOverrideColor = GrColor_ILLEGAL; | |
1197 init.fCoverageIgnored = fBatch.fCoverageIgnored; | |
1198 init.fUsesLocalCoords = this->usesLocalCoords(); | |
1199 gp->initBatchTracker(batchTarget->currentBatchTracker(), init); | |
1200 | |
1201 int instanceCount = fGeoData.count(); | 1156 int instanceCount = fGeoData.count(); |
1202 size_t vertexStride = gp->getVertexStride(); | 1157 size_t vertexStride = gp->getVertexStride(); |
1203 SkASSERT(vertexStride == sizeof(DIEllipseVertex)); | 1158 SkASSERT(vertexStride == sizeof(DIEllipseVertex)); |
1204 QuadHelper helper; | 1159 QuadHelper helper; |
1205 DIEllipseVertex* verts = reinterpret_cast<DIEllipseVertex*>( | 1160 DIEllipseVertex* verts = reinterpret_cast<DIEllipseVertex*>( |
1206 helper.init(batchTarget, vertexStride, instanceCount)); | 1161 helper.init(batchTarget, vertexStride, instanceCount)); |
1207 if (!verts) { | 1162 if (!verts) { |
1208 return; | 1163 return; |
1209 } | 1164 } |
1210 | 1165 |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1542 // reset to device coordinates | 1497 // reset to device coordinates |
1543 SkMatrix invert; | 1498 SkMatrix invert; |
1544 if (!this->viewMatrix().invert(&invert)) { | 1499 if (!this->viewMatrix().invert(&invert)) { |
1545 SkDebugf("Failed to invert\n"); | 1500 SkDebugf("Failed to invert\n"); |
1546 return; | 1501 return; |
1547 } | 1502 } |
1548 | 1503 |
1549 // Setup geometry processor | 1504 // Setup geometry processor |
1550 SkAutoTUnref<GrGeometryProcessor> gp(CircleEdgeEffect::Create(this->colo
r(), | 1505 SkAutoTUnref<GrGeometryProcessor> gp(CircleEdgeEffect::Create(this->colo
r(), |
1551 this->stro
ke(), | 1506 this->stro
ke(), |
1552 invert)); | 1507 invert, |
| 1508 this->uses
LocalCoords())); |
1553 | 1509 |
1554 batchTarget->initDraw(gp, pipeline); | 1510 batchTarget->initDraw(gp, pipeline); |
1555 | 1511 |
1556 // TODO this is hacky, but the only way we have to initialize the GP is
to use the | |
1557 // GrPipelineInfo struct so we can generate the correct shader. Once we
have GrBatch | |
1558 // everywhere we can remove this nastiness | |
1559 GrPipelineInfo init; | |
1560 init.fColorIgnored = fBatch.fColorIgnored; | |
1561 init.fOverrideColor = GrColor_ILLEGAL; | |
1562 init.fCoverageIgnored = fBatch.fCoverageIgnored; | |
1563 init.fUsesLocalCoords = this->usesLocalCoords(); | |
1564 gp->initBatchTracker(batchTarget->currentBatchTracker(), init); | |
1565 | |
1566 int instanceCount = fGeoData.count(); | 1512 int instanceCount = fGeoData.count(); |
1567 size_t vertexStride = gp->getVertexStride(); | 1513 size_t vertexStride = gp->getVertexStride(); |
1568 SkASSERT(vertexStride == sizeof(CircleVertex)); | 1514 SkASSERT(vertexStride == sizeof(CircleVertex)); |
1569 | 1515 |
1570 // drop out the middle quad if we're stroked | 1516 // drop out the middle quad if we're stroked |
1571 int indicesPerInstance = this->stroke() ? kIndicesPerStrokeRRect : kIndi
cesPerRRect; | 1517 int indicesPerInstance = this->stroke() ? kIndicesPerStrokeRRect : kIndi
cesPerRRect; |
1572 SkAutoTUnref<const GrIndexBuffer> indexBuffer( | 1518 SkAutoTUnref<const GrIndexBuffer> indexBuffer( |
1573 ref_rrect_index_buffer(this->stroke(), batchTarget->resourceProvider
())); | 1519 ref_rrect_index_buffer(this->stroke(), batchTarget->resourceProvider
())); |
1574 | 1520 |
1575 InstancedHelper helper; | 1521 InstancedHelper helper; |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1724 // reset to device coordinates | 1670 // reset to device coordinates |
1725 SkMatrix invert; | 1671 SkMatrix invert; |
1726 if (!this->viewMatrix().invert(&invert)) { | 1672 if (!this->viewMatrix().invert(&invert)) { |
1727 SkDebugf("Failed to invert\n"); | 1673 SkDebugf("Failed to invert\n"); |
1728 return; | 1674 return; |
1729 } | 1675 } |
1730 | 1676 |
1731 // Setup geometry processor | 1677 // Setup geometry processor |
1732 SkAutoTUnref<GrGeometryProcessor> gp(EllipseEdgeEffect::Create(this->col
or(), | 1678 SkAutoTUnref<GrGeometryProcessor> gp(EllipseEdgeEffect::Create(this->col
or(), |
1733 this->str
oke(), | 1679 this->str
oke(), |
1734 invert)); | 1680 invert, |
| 1681 this->use
sLocalCoords())); |
1735 | 1682 |
1736 batchTarget->initDraw(gp, pipeline); | 1683 batchTarget->initDraw(gp, pipeline); |
1737 | 1684 |
1738 // TODO this is hacky, but the only way we have to initialize the GP is
to use the | |
1739 // GrPipelineInfo struct so we can generate the correct shader. Once we
have GrBatch | |
1740 // everywhere we can remove this nastiness | |
1741 GrPipelineInfo init; | |
1742 init.fColorIgnored = fBatch.fColorIgnored; | |
1743 init.fOverrideColor = GrColor_ILLEGAL; | |
1744 init.fCoverageIgnored = fBatch.fCoverageIgnored; | |
1745 init.fUsesLocalCoords = this->usesLocalCoords(); | |
1746 gp->initBatchTracker(batchTarget->currentBatchTracker(), init); | |
1747 | |
1748 int instanceCount = fGeoData.count(); | 1685 int instanceCount = fGeoData.count(); |
1749 size_t vertexStride = gp->getVertexStride(); | 1686 size_t vertexStride = gp->getVertexStride(); |
1750 SkASSERT(vertexStride == sizeof(EllipseVertex)); | 1687 SkASSERT(vertexStride == sizeof(EllipseVertex)); |
1751 | 1688 |
1752 // drop out the middle quad if we're stroked | 1689 // drop out the middle quad if we're stroked |
1753 int indicesPerInstance = this->stroke() ? kIndicesPerStrokeRRect : kIndi
cesPerRRect; | 1690 int indicesPerInstance = this->stroke() ? kIndicesPerStrokeRRect : kIndi
cesPerRRect; |
1754 SkAutoTUnref<const GrIndexBuffer> indexBuffer( | 1691 SkAutoTUnref<const GrIndexBuffer> indexBuffer( |
1755 ref_rrect_index_buffer(this->stroke(), batchTarget->resourceProvider
())); | 1692 ref_rrect_index_buffer(this->stroke(), batchTarget->resourceProvider
())); |
1756 | 1693 |
1757 InstancedHelper helper; | 1694 InstancedHelper helper; |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2081 } | 2018 } |
2082 | 2019 |
2083 BATCH_TEST_DEFINE(RRectBatch) { | 2020 BATCH_TEST_DEFINE(RRectBatch) { |
2084 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); | 2021 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); |
2085 GrColor color = GrRandomColor(random); | 2022 GrColor color = GrRandomColor(random); |
2086 const SkRRect& rrect = GrTest::TestRRectSimple(random); | 2023 const SkRRect& rrect = GrTest::TestRRectSimple(random); |
2087 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra
ndom)); | 2024 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra
ndom)); |
2088 } | 2025 } |
2089 | 2026 |
2090 #endif | 2027 #endif |
OLD | NEW |