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 "GrRRectEffect.h" | 8 #include "GrRRectEffect.h" |
9 | 9 |
10 #include "gl/GrGLEffect.h" | 10 #include "gl/GrGLEffect.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 GR_DECLARE_EFFECT_TEST; | 60 GR_DECLARE_EFFECT_TEST; |
61 | 61 |
62 typedef GrEffect INHERITED; | 62 typedef GrEffect INHERITED; |
63 }; | 63 }; |
64 | 64 |
65 const SkScalar RRectEffect::kRadiusMin = 0.5f; | 65 const SkScalar RRectEffect::kRadiusMin = 0.5f; |
66 | 66 |
67 GrEffectRef* RRectEffect::Create(GrEffectEdgeType edgeType, | 67 GrEffectRef* RRectEffect::Create(GrEffectEdgeType edgeType, |
68 RRectType rrType, | 68 RRectType rrType, |
69 const SkRRect& rrect) { | 69 const SkRRect& rrect) { |
70 SkASSERT(kFillAA_GrEffectEdgeType == edgeType || kInverseFillBW_GrEffectEdge
Type == edgeType); | 70 SkASSERT(kFillAA_GrEffectEdgeType == edgeType || kInverseFillAA_GrEffectEdge
Type == edgeType); |
71 return CreateEffectRef(AutoEffectUnref(SkNEW_ARGS(RRectEffect, (edgeType, rr
Type, rrect)))); | 71 return CreateEffectRef(AutoEffectUnref(SkNEW_ARGS(RRectEffect, (edgeType, rr
Type, rrect)))); |
72 } | 72 } |
73 | 73 |
74 void RRectEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlag
s) const { | 74 void RRectEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlag
s) const { |
75 *validFlags = 0; | 75 *validFlags = 0; |
76 } | 76 } |
77 | 77 |
78 const GrBackendEffectFactory& RRectEffect::getFactory() const { | 78 const GrBackendEffectFactory& RRectEffect::getFactory() const { |
79 return GrTBackendEffectFactory<RRectEffect>::getInstance(); | 79 return GrTBackendEffectFactory<RRectEffect>::getInstance(); |
80 } | 80 } |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 builder->fsCodeAppendf("\t\tfloat dx0 = %s.x - %s.x;\n", rectName, f
ragmentPos); | 221 builder->fsCodeAppendf("\t\tfloat dx0 = %s.x - %s.x;\n", rectName, f
ragmentPos); |
222 builder->fsCodeAppendf("\t\tvec2 dxy1 = %s.xy - %s.zw;\n", fragmentP
os, rectName); | 222 builder->fsCodeAppendf("\t\tvec2 dxy1 = %s.xy - %s.zw;\n", fragmentP
os, rectName); |
223 builder->fsCodeAppend("\t\tvec2 dxy = max(vec2(max(dx0, dxy1.x), dxy
1.y), 0.0);\n"); | 223 builder->fsCodeAppend("\t\tvec2 dxy = max(vec2(max(dx0, dxy1.x), dxy
1.y), 0.0);\n"); |
224 builder->fsCodeAppendf("\t\tfloat topAlpha = clamp(%s.y - %s.y, 0.0,
1.0);\n", | 224 builder->fsCodeAppendf("\t\tfloat topAlpha = clamp(%s.y - %s.y, 0.0,
1.0);\n", |
225 fragmentPos, rectName); | 225 fragmentPos, rectName); |
226 builder->fsCodeAppendf("\t\tfloat alpha = topAlpha * clamp(%s - leng
th(dxy), 0.0, 1.0);\n", | 226 builder->fsCodeAppendf("\t\tfloat alpha = topAlpha * clamp(%s - leng
th(dxy), 0.0, 1.0);\n", |
227 radiusPlusHalfName); | 227 radiusPlusHalfName); |
228 break; | 228 break; |
229 } | 229 } |
230 | 230 |
231 if (kInverseFillBW_GrEffectEdgeType == rre.getEdgeType()) { | 231 if (kInverseFillAA_GrEffectEdgeType == rre.getEdgeType()) { |
232 builder->fsCodeAppend("\t\talpha = 1.0 - alpha;\n"); | 232 builder->fsCodeAppend("\t\talpha = 1.0 - alpha;\n"); |
233 } | 233 } |
234 | 234 |
235 builder->fsCodeAppendf("\t\t%s = %s;\n", outputColor, | 235 builder->fsCodeAppendf("\t\t%s = %s;\n", outputColor, |
236 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("alpha")).c_st
r()); | 236 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("alpha")).c_st
r()); |
237 } | 237 } |
238 | 238 |
239 GrGLEffect::EffectKey GLRRectEffect::GenKey(const GrDrawEffect& drawEffect, cons
t GrGLCaps&) { | 239 GrGLEffect::EffectKey GLRRectEffect::GenKey(const GrDrawEffect& drawEffect, cons
t GrGLCaps&) { |
240 const RRectEffect& rre = drawEffect.castEffect<RRectEffect>(); | 240 const RRectEffect& rre = drawEffect.castEffect<RRectEffect>(); |
241 GR_STATIC_ASSERT(kGrEffectEdgeTypeCnt <= 8); | 241 GR_STATIC_ASSERT(kGrEffectEdgeTypeCnt <= 8); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 } | 286 } |
287 uman.set4f(fInnerRectUniform, rect.fLeft, rect.fTop, rect.fRight, rect.f
Bottom); | 287 uman.set4f(fInnerRectUniform, rect.fLeft, rect.fTop, rect.fRight, rect.f
Bottom); |
288 uman.set1f(fRadiusPlusHalfUniform, radius + 0.5f); | 288 uman.set1f(fRadiusPlusHalfUniform, radius + 0.5f); |
289 fPrevRRect = rrect; | 289 fPrevRRect = rrect; |
290 } | 290 } |
291 } | 291 } |
292 | 292 |
293 ////////////////////////////////////////////////////////////////////////////// | 293 ////////////////////////////////////////////////////////////////////////////// |
294 | 294 |
295 GrEffectRef* GrRRectEffect::Create(GrEffectEdgeType edgeType, const SkRRect& rre
ct) { | 295 GrEffectRef* GrRRectEffect::Create(GrEffectEdgeType edgeType, const SkRRect& rre
ct) { |
296 if (kFillAA_GrEffectEdgeType != edgeType && kInverseFillBW_GrEffectEdgeType
!= edgeType) { | 296 if (kFillAA_GrEffectEdgeType != edgeType && kInverseFillAA_GrEffectEdgeType
!= edgeType) { |
297 return NULL; | 297 return NULL; |
298 } | 298 } |
299 RRectEffect::RRectType rrtype; | 299 RRectEffect::RRectType rrtype; |
300 if (rrect.isSimpleCircular()) { | 300 if (rrect.isSimpleCircular()) { |
301 if (rrect.getSimpleRadii().fX < RRectEffect::kRadiusMin) { | 301 if (rrect.getSimpleRadii().fX < RRectEffect::kRadiusMin) { |
302 return NULL; | 302 return NULL; |
303 } | 303 } |
304 rrtype = RRectEffect::kCircleCorner_RRectType; | 304 rrtype = RRectEffect::kCircleCorner_RRectType; |
305 } else if (rrect.isComplex()) { | 305 } else if (rrect.isComplex()) { |
306 // Check for the "tab" cases - two adjacent circular corners and two squ
are corners. | 306 // Check for the "tab" cases - two adjacent circular corners and two squ
are corners. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 rrtype = RRectEffect::kBottomCircleTab_RRectType; | 347 rrtype = RRectEffect::kBottomCircleTab_RRectType; |
348 break; | 348 break; |
349 default: | 349 default: |
350 return NULL; | 350 return NULL; |
351 } | 351 } |
352 } else { | 352 } else { |
353 return NULL; | 353 return NULL; |
354 } | 354 } |
355 return RRectEffect::Create(edgeType, rrtype, rrect); | 355 return RRectEffect::Create(edgeType, rrtype, rrect); |
356 } | 356 } |
OLD | NEW |