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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 } | 95 } |
96 | 96 |
97 ////////////////////////////////////////////////////////////////////////////// | 97 ////////////////////////////////////////////////////////////////////////////// |
98 | 98 |
99 class GLCircleEffect : public GrGLEffect { | 99 class GLCircleEffect : public GrGLEffect { |
100 public: | 100 public: |
101 GLCircleEffect(const GrBackendEffectFactory&, const GrDrawEffect&); | 101 GLCircleEffect(const GrBackendEffectFactory&, const GrDrawEffect&); |
102 | 102 |
103 virtual void emitCode(GrGLShaderBuilder* builder, | 103 virtual void emitCode(GrGLShaderBuilder* builder, |
104 const GrDrawEffect& drawEffect, | 104 const GrDrawEffect& drawEffect, |
105 EffectKey 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 EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&); | 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 GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE; |
114 | 114 |
115 private: | 115 private: |
116 GrGLUniformManager::UniformHandle fCircleUniform; | 116 GrGLUniformManager::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; |
127 } | 127 } |
128 | 128 |
129 void GLCircleEffect::emitCode(GrGLShaderBuilder* builder, | 129 void GLCircleEffect::emitCode(GrGLShaderBuilder* builder, |
130 const GrDrawEffect& drawEffect, | 130 const GrDrawEffect& drawEffect, |
131 EffectKey key, | 131 const GrEffectKey& key, |
132 const char* outputColor, | 132 const char* outputColor, |
133 const char* inputColor, | 133 const char* inputColor, |
134 const TransformedCoordsArray&, | 134 const TransformedCoordsArray&, |
135 const TextureSamplerArray& samplers) { | 135 const TextureSamplerArray& samplers) { |
136 const CircleEffect& ce = drawEffect.castEffect<CircleEffect>(); | 136 const CircleEffect& ce = drawEffect.castEffect<CircleEffect>(); |
137 const char *circleName; | 137 const char *circleName; |
138 // The circle uniform is (center.x, center.y, radius + 0.5) for regular fill
s and | 138 // The circle uniform is (center.x, center.y, radius + 0.5) for regular fill
s and |
139 // (... ,radius - 0.5) for inverse fills. | 139 // (... ,radius - 0.5) for inverse fills. |
140 fCircleUniform = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility
, | 140 fCircleUniform = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility
, |
141 kVec3f_GrSLType, | 141 kVec3f_GrSLType, |
(...skipping 12 matching lines...) Expand all Loading... |
154 if (GrEffectEdgeTypeIsAA(ce.getEdgeType())) { | 154 if (GrEffectEdgeTypeIsAA(ce.getEdgeType())) { |
155 builder->fsCodeAppend("\t\td = clamp(d, 0.0, 1.0);\n"); | 155 builder->fsCodeAppend("\t\td = clamp(d, 0.0, 1.0);\n"); |
156 } else { | 156 } else { |
157 builder->fsCodeAppend("\t\td = d > 0.5 ? 1.0 : 0.0;\n"); | 157 builder->fsCodeAppend("\t\td = d > 0.5 ? 1.0 : 0.0;\n"); |
158 } | 158 } |
159 | 159 |
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 GrGLEffect::EffectKey GLCircleEffect::GenKey(const GrDrawEffect& drawEffect, | 164 void GLCircleEffect::GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&, |
165 const GrGLCaps&) { | 165 GrEffectKeyBuilder* b) { |
166 const CircleEffect& ce = drawEffect.castEffect<CircleEffect>(); | 166 const CircleEffect& ce = drawEffect.castEffect<CircleEffect>(); |
167 return 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 GrGLUniformManager& uman, const GrDrawEffect&
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; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 } | 267 } |
268 | 268 |
269 ////////////////////////////////////////////////////////////////////////////// | 269 ////////////////////////////////////////////////////////////////////////////// |
270 | 270 |
271 class GLEllipseEffect : public GrGLEffect { | 271 class GLEllipseEffect : public GrGLEffect { |
272 public: | 272 public: |
273 GLEllipseEffect(const GrBackendEffectFactory&, const GrDrawEffect&); | 273 GLEllipseEffect(const GrBackendEffectFactory&, const GrDrawEffect&); |
274 | 274 |
275 virtual void emitCode(GrGLShaderBuilder* builder, | 275 virtual void emitCode(GrGLShaderBuilder* builder, |
276 const GrDrawEffect& drawEffect, | 276 const GrDrawEffect& drawEffect, |
277 EffectKey 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 EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&); | 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 GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE; |
286 | 286 |
287 private: | 287 private: |
288 GrGLUniformManager::UniformHandle fEllipseUniform; | 288 GrGLUniformManager::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; |
299 } | 299 } |
300 | 300 |
301 void GLEllipseEffect::emitCode(GrGLShaderBuilder* builder, | 301 void GLEllipseEffect::emitCode(GrGLShaderBuilder* builder, |
302 const GrDrawEffect& drawEffect, | 302 const GrDrawEffect& drawEffect, |
303 EffectKey key, | 303 const GrEffectKey& key, |
304 const char* outputColor, | 304 const char* outputColor, |
305 const char* inputColor, | 305 const char* inputColor, |
306 const TransformedCoordsArray&, | 306 const TransformedCoordsArray&, |
307 const TextureSamplerArray& samplers) { | 307 const TextureSamplerArray& samplers) { |
308 const EllipseEffect& ee = drawEffect.castEffect<EllipseEffect>(); | 308 const EllipseEffect& ee = drawEffect.castEffect<EllipseEffect>(); |
309 const char *ellipseName; | 309 const char *ellipseName; |
310 // The ellipse uniform is (center.x, center.y, 1 / rx^2, 1 / ry^2) | 310 // The ellipse uniform is (center.x, center.y, 1 / rx^2, 1 / ry^2) |
311 fEllipseUniform = builder->addUniform(GrGLShaderBuilder::kFragment_Visibilit
y, | 311 fEllipseUniform = builder->addUniform(GrGLShaderBuilder::kFragment_Visibilit
y, |
312 kVec4f_GrSLType, | 312 kVec4f_GrSLType, |
313 "ellipse", | 313 "ellipse", |
(...skipping 25 matching lines...) Expand all Loading... |
339 builder->fsCodeAppend("\t\tfloat alpha = approx_dist > 0.0 ? 1.0 : 0
.0;\n"); | 339 builder->fsCodeAppend("\t\tfloat alpha = approx_dist > 0.0 ? 1.0 : 0
.0;\n"); |
340 break; | 340 break; |
341 case kHairlineAA_GrEffectEdgeType: | 341 case kHairlineAA_GrEffectEdgeType: |
342 SkFAIL("Hairline not expected here."); | 342 SkFAIL("Hairline not expected here."); |
343 } | 343 } |
344 | 344 |
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 GrGLEffect::EffectKey GLEllipseEffect::GenKey(const GrDrawEffect& drawEffect, | 349 void GLEllipseEffect::GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&, |
350 const GrGLCaps&) { | 350 GrEffectKeyBuilder* b) { |
351 const EllipseEffect& ee = drawEffect.castEffect<EllipseEffect>(); | 351 const EllipseEffect& ee = drawEffect.castEffect<EllipseEffect>(); |
352 return 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 GrGLUniformManager& uman, const GrDrawEffect
& 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 uman.set4f(fEllipseUniform, ee.getCenter().fX, ee.getCenter().fY, invRXS
qd, invRYSqd); |
361 fPrevCenter = ee.getCenter(); | 361 fPrevCenter = ee.getCenter(); |
362 fPrevRadii = ee.getRadii(); | 362 fPrevRadii = ee.getRadii(); |
(...skipping 12 matching lines...) Expand all Loading... |
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 |