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 "gl/builders/GrGLProgramBuilder.h" | 8 #include "gl/builders/GrGLProgramBuilder.h" |
9 #include "GrOvalEffect.h" | 9 #include "GrOvalEffect.h" |
10 | 10 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 } while (kHairlineAA_GrProcessorEdgeType == et); | 95 } while (kHairlineAA_GrProcessorEdgeType == et); |
96 return CircleEffect::Create(et, center, radius); | 96 return CircleEffect::Create(et, center, radius); |
97 } | 97 } |
98 | 98 |
99 ////////////////////////////////////////////////////////////////////////////// | 99 ////////////////////////////////////////////////////////////////////////////// |
100 | 100 |
101 class GLCircleEffect : public GrGLFragmentProcessor { | 101 class GLCircleEffect : public GrGLFragmentProcessor { |
102 public: | 102 public: |
103 GLCircleEffect(const GrBackendProcessorFactory&, const GrProcessor&); | 103 GLCircleEffect(const GrBackendProcessorFactory&, const GrProcessor&); |
104 | 104 |
105 virtual void emitCode(GrGLProgramBuilder* builder, | 105 virtual void emitCode(GrGLFPBuilder* builder, |
106 const GrFragmentProcessor& fp, | 106 const GrFragmentProcessor& fp, |
107 const GrProcessorKey& key, | 107 const GrProcessorKey& key, |
108 const char* outputColor, | 108 const char* outputColor, |
109 const char* inputColor, | 109 const char* inputColor, |
110 const TransformedCoordsArray&, | 110 const TransformedCoordsArray&, |
111 const TextureSamplerArray&) SK_OVERRIDE; | 111 const TextureSamplerArray&) SK_OVERRIDE; |
112 | 112 |
113 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder*); | 113 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder*); |
114 | 114 |
115 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; | 115 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; |
116 | 116 |
117 private: | 117 private: |
118 GrGLProgramDataManager::UniformHandle fCircleUniform; | 118 GrGLProgramDataManager::UniformHandle fCircleUniform; |
119 SkPoint fPrevCenter; | 119 SkPoint fPrevCenter; |
120 SkScalar fPrevRadius; | 120 SkScalar fPrevRadius; |
121 | 121 |
122 typedef GrGLFragmentProcessor INHERITED; | 122 typedef GrGLFragmentProcessor INHERITED; |
123 }; | 123 }; |
124 | 124 |
125 GLCircleEffect::GLCircleEffect(const GrBackendProcessorFactory& factory, | 125 GLCircleEffect::GLCircleEffect(const GrBackendProcessorFactory& factory, |
126 const GrProcessor&) | 126 const GrProcessor&) |
127 : INHERITED (factory) { | 127 : INHERITED (factory) { |
128 fPrevRadius = -1.f; | 128 fPrevRadius = -1.f; |
129 } | 129 } |
130 | 130 |
131 void GLCircleEffect::emitCode(GrGLProgramBuilder* builder, | 131 void GLCircleEffect::emitCode(GrGLFPBuilder* builder, |
132 const GrFragmentProcessor& fp, | 132 const GrFragmentProcessor& fp, |
133 const GrProcessorKey& key, | 133 const GrProcessorKey& key, |
134 const char* outputColor, | 134 const char* outputColor, |
135 const char* inputColor, | 135 const char* inputColor, |
136 const TransformedCoordsArray&, | 136 const TransformedCoordsArray&, |
137 const TextureSamplerArray& samplers) { | 137 const TextureSamplerArray& samplers) { |
138 const CircleEffect& ce = fp.cast<CircleEffect>(); | 138 const CircleEffect& ce = fp.cast<CircleEffect>(); |
139 const char *circleName; | 139 const char *circleName; |
140 // The circle uniform is (center.x, center.y, radius + 0.5) for regular fill
s and | 140 // The circle uniform is (center.x, center.y, radius + 0.5) for regular fill
s and |
141 // (... ,radius - 0.5) for inverse fills. | 141 // (... ,radius - 0.5) for inverse fills. |
142 fCircleUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibilit
y, | 142 fCircleUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibilit
y, |
143 kVec3f_GrSLType, | 143 kVec3f_GrSLType, |
144 "circle", | 144 "circle", |
145 &circleName); | 145 &circleName); |
146 | 146 |
147 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 147 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
148 const char* fragmentPos = fsBuilder->fragmentPosition(); | 148 const char* fragmentPos = fsBuilder->fragmentPosition(); |
149 | 149 |
150 SkASSERT(kHairlineAA_GrProcessorEdgeType != ce.getEdgeType()); | 150 SkASSERT(kHairlineAA_GrProcessorEdgeType != ce.getEdgeType()); |
151 if (GrProcessorEdgeTypeIsInverseFill(ce.getEdgeType())) { | 151 if (GrProcessorEdgeTypeIsInverseFill(ce.getEdgeType())) { |
152 fsBuilder->codeAppendf("\t\tfloat d = length(%s.xy - %s.xy) - %s.z;\n", | 152 fsBuilder->codeAppendf("\t\tfloat d = length(%s.xy - %s.xy) - %s.z;\n", |
153 circleName, fragmentPos, circleName); | 153 circleName, fragmentPos, circleName); |
154 } else { | 154 } else { |
155 fsBuilder->codeAppendf("\t\tfloat d = %s.z - length(%s.xy - %s.xy);\n", | 155 fsBuilder->codeAppendf("\t\tfloat d = %s.z - length(%s.xy - %s.xy);\n", |
156 circleName, fragmentPos, circleName); | 156 circleName, fragmentPos, circleName); |
157 } | 157 } |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 } while (kHairlineAA_GrProcessorEdgeType == et); | 271 } while (kHairlineAA_GrProcessorEdgeType == et); |
272 return EllipseEffect::Create(et, center, rx, ry); | 272 return EllipseEffect::Create(et, center, rx, ry); |
273 } | 273 } |
274 | 274 |
275 ////////////////////////////////////////////////////////////////////////////// | 275 ////////////////////////////////////////////////////////////////////////////// |
276 | 276 |
277 class GLEllipseEffect : public GrGLFragmentProcessor { | 277 class GLEllipseEffect : public GrGLFragmentProcessor { |
278 public: | 278 public: |
279 GLEllipseEffect(const GrBackendProcessorFactory&, const GrProcessor&); | 279 GLEllipseEffect(const GrBackendProcessorFactory&, const GrProcessor&); |
280 | 280 |
281 virtual void emitCode(GrGLProgramBuilder* builder, | 281 virtual void emitCode(GrGLFPBuilder* builder, |
282 const GrFragmentProcessor& fp, | 282 const GrFragmentProcessor& fp, |
283 const GrProcessorKey& key, | 283 const GrProcessorKey& key, |
284 const char* outputColor, | 284 const char* outputColor, |
285 const char* inputColor, | 285 const char* inputColor, |
286 const TransformedCoordsArray&, | 286 const TransformedCoordsArray&, |
287 const TextureSamplerArray&) SK_OVERRIDE; | 287 const TextureSamplerArray&) SK_OVERRIDE; |
288 | 288 |
289 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder*); | 289 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder*); |
290 | 290 |
291 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; | 291 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; |
292 | 292 |
293 private: | 293 private: |
294 GrGLProgramDataManager::UniformHandle fEllipseUniform; | 294 GrGLProgramDataManager::UniformHandle fEllipseUniform; |
295 SkPoint fPrevCenter; | 295 SkPoint fPrevCenter; |
296 SkVector fPrevRadii; | 296 SkVector fPrevRadii; |
297 | 297 |
298 typedef GrGLFragmentProcessor INHERITED; | 298 typedef GrGLFragmentProcessor INHERITED; |
299 }; | 299 }; |
300 | 300 |
301 GLEllipseEffect::GLEllipseEffect(const GrBackendProcessorFactory& factory, | 301 GLEllipseEffect::GLEllipseEffect(const GrBackendProcessorFactory& factory, |
302 const GrProcessor& effect) | 302 const GrProcessor& effect) |
303 : INHERITED (factory) { | 303 : INHERITED (factory) { |
304 fPrevRadii.fX = -1.f; | 304 fPrevRadii.fX = -1.f; |
305 } | 305 } |
306 | 306 |
307 void GLEllipseEffect::emitCode(GrGLProgramBuilder* builder, | 307 void GLEllipseEffect::emitCode(GrGLFPBuilder* builder, |
308 const GrFragmentProcessor& fp, | 308 const GrFragmentProcessor& fp, |
309 const GrProcessorKey& key, | 309 const GrProcessorKey& key, |
310 const char* outputColor, | 310 const char* outputColor, |
311 const char* inputColor, | 311 const char* inputColor, |
312 const TransformedCoordsArray&, | 312 const TransformedCoordsArray&, |
313 const TextureSamplerArray& samplers) { | 313 const TextureSamplerArray& samplers) { |
314 const EllipseEffect& ee = fp.cast<EllipseEffect>(); | 314 const EllipseEffect& ee = fp.cast<EllipseEffect>(); |
315 const char *ellipseName; | 315 const char *ellipseName; |
316 // The ellipse uniform is (center.x, center.y, 1 / rx^2, 1 / ry^2) | 316 // The ellipse uniform is (center.x, center.y, 1 / rx^2, 1 / ry^2) |
317 fEllipseUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibili
ty, | 317 fEllipseUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibili
ty, |
318 kVec4f_GrSLType, | 318 kVec4f_GrSLType, |
319 "ellipse", | 319 "ellipse", |
320 &ellipseName); | 320 &ellipseName); |
321 | 321 |
322 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 322 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
323 const char* fragmentPos = fsBuilder->fragmentPosition(); | 323 const char* fragmentPos = fsBuilder->fragmentPosition(); |
324 | 324 |
325 // d is the offset to the ellipse center | 325 // d is the offset to the ellipse center |
326 fsBuilder->codeAppendf("\t\tvec2 d = %s.xy - %s.xy;\n", fragmentPos, ellipse
Name); | 326 fsBuilder->codeAppendf("\t\tvec2 d = %s.xy - %s.xy;\n", fragmentPos, ellipse
Name); |
327 fsBuilder->codeAppendf("\t\tvec2 Z = d * %s.zw;\n", ellipseName); | 327 fsBuilder->codeAppendf("\t\tvec2 Z = d * %s.zw;\n", ellipseName); |
328 // implicit is the evaluation of (x/rx)^2 + (y/ry)^2 - 1. | 328 // implicit is the evaluation of (x/rx)^2 + (y/ry)^2 - 1. |
329 fsBuilder->codeAppend("\t\tfloat implicit = dot(Z, d) - 1.0;\n"); | 329 fsBuilder->codeAppend("\t\tfloat implicit = dot(Z, d) - 1.0;\n"); |
330 // grad_dot is the squared length of the gradient of the implicit. | 330 // grad_dot is the squared length of the gradient of the implicit. |
331 fsBuilder->codeAppendf("\t\tfloat grad_dot = 4.0 * dot(Z, Z);\n"); | 331 fsBuilder->codeAppendf("\t\tfloat grad_dot = 4.0 * dot(Z, Z);\n"); |
332 // avoid calling inversesqrt on zero. | 332 // avoid calling inversesqrt on zero. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 w /= 2; | 383 w /= 2; |
384 return CircleEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, oval
.fTop + w), w); | 384 return CircleEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, oval
.fTop + w), w); |
385 } else { | 385 } else { |
386 w /= 2; | 386 w /= 2; |
387 h /= 2; | 387 h /= 2; |
388 return EllipseEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, ova
l.fTop + h), w, h); | 388 return EllipseEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, ova
l.fTop + h), w, h); |
389 } | 389 } |
390 | 390 |
391 return NULL; | 391 return NULL; |
392 } | 392 } |
OLD | NEW |