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 "GrOvalEffect.h" | 8 #include "GrOvalEffect.h" |
9 | 9 |
10 #include "gl/GrGLEffect.h" | 10 #include "gl/GrGLEffect.h" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 virtual void emitCode(GrGLShaderBuilder* builder, | 103 virtual void emitCode(GrGLShaderBuilder* builder, |
104 const GrDrawEffect& drawEffect, | 104 const GrDrawEffect& drawEffect, |
105 const GrEffectKey& key, | 105 const GrEffectKey& key, |
106 const char* outputColor, | 106 const char* outputColor, |
107 const char* inputColor, | 107 const char* inputColor, |
108 const TransformedCoordsArray&, | 108 const TransformedCoordsArray&, |
109 const TextureSamplerArray&) SK_OVERRIDE; | 109 const TextureSamplerArray&) SK_OVERRIDE; |
110 | 110 |
111 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyB
uilder*); | 111 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyB
uilder*); |
112 | 112 |
113 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE; | 113 virtual void setData(const GrGLProgramResourceManager&, const GrDrawEffect&)
SK_OVERRIDE; |
114 | 114 |
115 private: | 115 private: |
116 GrGLUniformManager::UniformHandle fCircleUniform; | 116 GrGLProgramResourceManager::UniformHandle fCircleUniform; |
117 SkPoint fPrevCenter; | 117 SkPoint fPrevCenter; |
118 SkScalar fPrevRadius; | 118 SkScalar fPrevRadius; |
119 | 119 |
120 typedef GrGLEffect INHERITED; | 120 typedef GrGLEffect INHERITED; |
121 }; | 121 }; |
122 | 122 |
123 GLCircleEffect::GLCircleEffect(const GrBackendEffectFactory& factory, | 123 GLCircleEffect::GLCircleEffect(const GrBackendEffectFactory& factory, |
124 const GrDrawEffect& drawEffect) | 124 const GrDrawEffect& drawEffect) |
125 : INHERITED (factory) { | 125 : INHERITED (factory) { |
126 fPrevRadius = -1.f; | 126 fPrevRadius = -1.f; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 builder->fsCodeAppendf("\t\t%s = %s;\n", outputColor, | 160 builder->fsCodeAppendf("\t\t%s = %s;\n", outputColor, |
161 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("d")).c_str())
; | 161 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("d")).c_str())
; |
162 } | 162 } |
163 | 163 |
164 void GLCircleEffect::GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&, | 164 void GLCircleEffect::GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&, |
165 GrEffectKeyBuilder* b) { | 165 GrEffectKeyBuilder* b) { |
166 const CircleEffect& ce = drawEffect.castEffect<CircleEffect>(); | 166 const CircleEffect& ce = drawEffect.castEffect<CircleEffect>(); |
167 b->add32(ce.getEdgeType()); | 167 b->add32(ce.getEdgeType()); |
168 } | 168 } |
169 | 169 |
170 void GLCircleEffect::setData(const GrGLUniformManager& uman, const GrDrawEffect&
drawEffect) { | 170 void GLCircleEffect::setData(const GrGLProgramResourceManager& prman, const GrDr
awEffect& drawEffect) { |
171 const CircleEffect& ce = drawEffect.castEffect<CircleEffect>(); | 171 const CircleEffect& ce = drawEffect.castEffect<CircleEffect>(); |
172 if (ce.getRadius() != fPrevRadius || ce.getCenter() != fPrevCenter) { | 172 if (ce.getRadius() != fPrevRadius || ce.getCenter() != fPrevCenter) { |
173 SkScalar radius = ce.getRadius(); | 173 SkScalar radius = ce.getRadius(); |
174 if (GrEffectEdgeTypeIsInverseFill(ce.getEdgeType())) { | 174 if (GrEffectEdgeTypeIsInverseFill(ce.getEdgeType())) { |
175 radius -= 0.5f; | 175 radius -= 0.5f; |
176 } else { | 176 } else { |
177 radius += 0.5f; | 177 radius += 0.5f; |
178 } | 178 } |
179 uman.set3f(fCircleUniform, ce.getCenter().fX, ce.getCenter().fY, radius)
; | 179 prman.set3f(fCircleUniform, ce.getCenter().fX, ce.getCenter().fY, radius
); |
180 fPrevCenter = ce.getCenter(); | 180 fPrevCenter = ce.getCenter(); |
181 fPrevRadius = ce.getRadius(); | 181 fPrevRadius = ce.getRadius(); |
182 } | 182 } |
183 } | 183 } |
184 | 184 |
185 ////////////////////////////////////////////////////////////////////////////// | 185 ////////////////////////////////////////////////////////////////////////////// |
186 | 186 |
187 class GLEllipseEffect; | 187 class GLEllipseEffect; |
188 | 188 |
189 class EllipseEffect : public GrEffect { | 189 class EllipseEffect : public GrEffect { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 virtual void emitCode(GrGLShaderBuilder* builder, | 275 virtual void emitCode(GrGLShaderBuilder* builder, |
276 const GrDrawEffect& drawEffect, | 276 const GrDrawEffect& drawEffect, |
277 const GrEffectKey& key, | 277 const GrEffectKey& key, |
278 const char* outputColor, | 278 const char* outputColor, |
279 const char* inputColor, | 279 const char* inputColor, |
280 const TransformedCoordsArray&, | 280 const TransformedCoordsArray&, |
281 const TextureSamplerArray&) SK_OVERRIDE; | 281 const TextureSamplerArray&) SK_OVERRIDE; |
282 | 282 |
283 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyB
uilder*); | 283 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyB
uilder*); |
284 | 284 |
285 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE; | 285 virtual void setData(const GrGLProgramResourceManager&, const GrDrawEffect&)
SK_OVERRIDE; |
286 | 286 |
287 private: | 287 private: |
288 GrGLUniformManager::UniformHandle fEllipseUniform; | 288 GrGLProgramResourceManager::UniformHandle fEllipseUniform; |
289 SkPoint fPrevCenter; | 289 SkPoint fPrevCenter; |
290 SkVector fPrevRadii; | 290 SkVector fPrevRadii; |
291 | 291 |
292 typedef GrGLEffect INHERITED; | 292 typedef GrGLEffect INHERITED; |
293 }; | 293 }; |
294 | 294 |
295 GLEllipseEffect::GLEllipseEffect(const GrBackendEffectFactory& factory, | 295 GLEllipseEffect::GLEllipseEffect(const GrBackendEffectFactory& factory, |
296 const GrDrawEffect& drawEffect) | 296 const GrDrawEffect& drawEffect) |
297 : INHERITED (factory) { | 297 : INHERITED (factory) { |
298 fPrevRadii.fX = -1.f; | 298 fPrevRadii.fX = -1.f; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 builder->fsCodeAppendf("\t\t%s = %s;\n", outputColor, | 345 builder->fsCodeAppendf("\t\t%s = %s;\n", outputColor, |
346 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("alpha")).c_st
r()); | 346 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("alpha")).c_st
r()); |
347 } | 347 } |
348 | 348 |
349 void GLEllipseEffect::GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&, | 349 void GLEllipseEffect::GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&, |
350 GrEffectKeyBuilder* b) { | 350 GrEffectKeyBuilder* b) { |
351 const EllipseEffect& ee = drawEffect.castEffect<EllipseEffect>(); | 351 const EllipseEffect& ee = drawEffect.castEffect<EllipseEffect>(); |
352 b->add32(ee.getEdgeType()); | 352 b->add32(ee.getEdgeType()); |
353 } | 353 } |
354 | 354 |
355 void GLEllipseEffect::setData(const GrGLUniformManager& uman, const GrDrawEffect
& drawEffect) { | 355 void GLEllipseEffect::setData(const GrGLProgramResourceManager& prman, const GrD
rawEffect& drawEffect) { |
356 const EllipseEffect& ee = drawEffect.castEffect<EllipseEffect>(); | 356 const EllipseEffect& ee = drawEffect.castEffect<EllipseEffect>(); |
357 if (ee.getRadii() != fPrevRadii || ee.getCenter() != fPrevCenter) { | 357 if (ee.getRadii() != fPrevRadii || ee.getCenter() != fPrevCenter) { |
358 SkScalar invRXSqd = 1.f / (ee.getRadii().fX * ee.getRadii().fX); | 358 SkScalar invRXSqd = 1.f / (ee.getRadii().fX * ee.getRadii().fX); |
359 SkScalar invRYSqd = 1.f / (ee.getRadii().fY * ee.getRadii().fY); | 359 SkScalar invRYSqd = 1.f / (ee.getRadii().fY * ee.getRadii().fY); |
360 uman.set4f(fEllipseUniform, ee.getCenter().fX, ee.getCenter().fY, invRXS
qd, invRYSqd); | 360 prman.set4f(fEllipseUniform, ee.getCenter().fX, ee.getCenter().fY, invRX
Sqd, invRYSqd); |
361 fPrevCenter = ee.getCenter(); | 361 fPrevCenter = ee.getCenter(); |
362 fPrevRadii = ee.getRadii(); | 362 fPrevRadii = ee.getRadii(); |
363 } | 363 } |
364 } | 364 } |
365 | 365 |
366 ////////////////////////////////////////////////////////////////////////////// | 366 ////////////////////////////////////////////////////////////////////////////// |
367 | 367 |
368 GrEffect* GrOvalEffect::Create(GrEffectEdgeType edgeType, const SkRect& oval) { | 368 GrEffect* GrOvalEffect::Create(GrEffectEdgeType edgeType, const SkRect& oval) { |
369 if (kHairlineAA_GrEffectEdgeType == edgeType) { | 369 if (kHairlineAA_GrEffectEdgeType == edgeType) { |
370 return NULL; | 370 return NULL; |
371 } | 371 } |
372 SkScalar w = oval.width(); | 372 SkScalar w = oval.width(); |
373 SkScalar h = oval.height(); | 373 SkScalar h = oval.height(); |
374 if (SkScalarNearlyEqual(w, h)) { | 374 if (SkScalarNearlyEqual(w, h)) { |
375 w /= 2; | 375 w /= 2; |
376 return CircleEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, oval
.fTop + w), w); | 376 return CircleEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, oval
.fTop + w), w); |
377 } else { | 377 } else { |
378 w /= 2; | 378 w /= 2; |
379 h /= 2; | 379 h /= 2; |
380 return EllipseEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, ova
l.fTop + h), w, h); | 380 return EllipseEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, ova
l.fTop + h), w, h); |
381 } | 381 } |
382 | 382 |
383 return NULL; | 383 return NULL; |
384 } | 384 } |
OLD | NEW |