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 "GrConvexPolyEffect.h" | 8 #include "GrConvexPolyEffect.h" |
9 | 9 |
10 #include "gl/GrGLEffect.h" | 10 #include "gl/GrGLEffect.h" |
11 #include "gl/GrGLSL.h" | 11 #include "gl/GrGLSL.h" |
12 #include "GrTBackendEffectFactory.h" | 12 #include "GrTBackendEffectFactory.h" |
13 | 13 |
14 #include "SkPath.h" | 14 #include "SkPath.h" |
15 | 15 |
16 ////////////////////////////////////////////////////////////////////////////// | 16 ////////////////////////////////////////////////////////////////////////////// |
17 class GLAARectEffect; | 17 class GLAARectEffect; |
18 | 18 |
19 class AARectEffect : public GrEffect { | 19 class AARectEffect : public GrEffect { |
20 public: | 20 public: |
21 typedef GLAARectEffect GLEffect; | 21 typedef GLAARectEffect GLEffect; |
22 typedef GrConvexPolyEffect::EdgeType EdgeType; | |
23 | 22 |
24 const SkRect& getRect() const { return fRect; } | 23 const SkRect& getRect() const { return fRect; } |
25 | 24 |
26 static const char* Name() { return "AARect"; } | 25 static const char* Name() { return "AARect"; } |
27 | 26 |
28 static GrEffectRef* Create(EdgeType edgeType, const SkRect& rect) { | 27 static GrEffectRef* Create(GrEffectEdgeType edgeType, const SkRect& rect) { |
29 return CreateEffectRef(AutoEffectUnref(SkNEW_ARGS(AARectEffect, (edgeTyp
e, rect)))); | 28 return CreateEffectRef(AutoEffectUnref(SkNEW_ARGS(AARectEffect, (edgeTyp
e, rect)))); |
30 } | 29 } |
31 | 30 |
32 virtual void getConstantColorComponents(GrColor* color, | 31 virtual void getConstantColorComponents(GrColor* color, |
33 uint32_t* validFlags) const SK_OVERR
IDE { | 32 uint32_t* validFlags) const SK_OVERR
IDE { |
34 if (fRect.isEmpty()) { | 33 if (fRect.isEmpty()) { |
35 // An empty rect will have no coverage anywhere. | 34 // An empty rect will have no coverage anywhere. |
36 *color = 0x00000000; | 35 *color = 0x00000000; |
37 *validFlags = kRGBA_GrColorComponentFlags; | 36 *validFlags = kRGBA_GrColorComponentFlags; |
38 } else { | 37 } else { |
39 *validFlags = 0; | 38 *validFlags = 0; |
40 } | 39 } |
41 } | 40 } |
42 | 41 |
43 GrConvexPolyEffect::EdgeType getEdgeType() const { return fEdgeType; } | 42 GrEffectEdgeType getEdgeType() const { return fEdgeType; } |
44 | 43 |
45 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; | 44 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
46 | 45 |
47 private: | 46 private: |
48 AARectEffect(EdgeType edgeType, const SkRect& rect) : fRect(rect), fEdgeType
(edgeType) { | 47 AARectEffect(GrEffectEdgeType edgeType, const SkRect& rect) : fRect(rect), f
EdgeType(edgeType) { |
49 this->setWillReadFragmentPosition(); | 48 this->setWillReadFragmentPosition(); |
50 } | 49 } |
51 | 50 |
52 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE { | 51 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE { |
53 const AARectEffect& aare = CastEffect<AARectEffect>(other); | 52 const AARectEffect& aare = CastEffect<AARectEffect>(other); |
54 return fRect == aare.fRect; | 53 return fRect == aare.fRect; |
55 } | 54 } |
56 | 55 |
57 SkRect fRect; | 56 SkRect fRect; |
58 EdgeType fEdgeType; | 57 GrEffectEdgeType fEdgeType; |
59 | 58 |
60 typedef GrEffect INHERITED; | 59 typedef GrEffect INHERITED; |
61 | 60 |
62 GR_DECLARE_EFFECT_TEST; | 61 GR_DECLARE_EFFECT_TEST; |
63 | 62 |
64 }; | 63 }; |
65 | 64 |
66 GR_DEFINE_EFFECT_TEST(AARectEffect); | 65 GR_DEFINE_EFFECT_TEST(AARectEffect); |
67 | 66 |
68 GrEffectRef* AARectEffect::TestCreate(SkRandom* random, | 67 GrEffectRef* AARectEffect::TestCreate(SkRandom* random, |
69 GrContext*, | 68 GrContext*, |
70 const GrDrawTargetCaps& caps, | 69 const GrDrawTargetCaps& caps, |
71 GrTexture*[]) { | 70 GrTexture*[]) { |
72 EdgeType edgeType = static_cast<EdgeType>( | |
73 random->nextULessThan(GrConvexPolyEffect::kE
dgeTypeCnt)); | |
74 | |
75 SkRect rect = SkRect::MakeLTRB(random->nextSScalar1(), | 71 SkRect rect = SkRect::MakeLTRB(random->nextSScalar1(), |
76 random->nextSScalar1(), | 72 random->nextSScalar1(), |
77 random->nextSScalar1(), | 73 random->nextSScalar1(), |
78 random->nextSScalar1()); | 74 random->nextSScalar1()); |
79 return AARectEffect::Create(edgeType, rect); | 75 GrEffectRef* effect; |
| 76 do { |
| 77 GrEffectEdgeType edgeType = static_cast<GrEffectEdgeType>(random->nextUL
essThan( |
| 78 kGrEffectEdg
eTypeCnt)); |
| 79 |
| 80 effect = AARectEffect::Create(edgeType, rect); |
| 81 } while (NULL == effect); |
| 82 return effect; |
80 } | 83 } |
81 | 84 |
82 ////////////////////////////////////////////////////////////////////////////// | 85 ////////////////////////////////////////////////////////////////////////////// |
83 | 86 |
84 class GLAARectEffect : public GrGLEffect { | 87 class GLAARectEffect : public GrGLEffect { |
85 public: | 88 public: |
86 GLAARectEffect(const GrBackendEffectFactory&, const GrDrawEffect&); | 89 GLAARectEffect(const GrBackendEffectFactory&, const GrDrawEffect&); |
87 | 90 |
88 virtual void emitCode(GrGLShaderBuilder* builder, | 91 virtual void emitCode(GrGLShaderBuilder* builder, |
89 const GrDrawEffect& drawEffect, | 92 const GrDrawEffect& drawEffect, |
(...skipping 28 matching lines...) Expand all Loading... |
118 const TextureSamplerArray& samplers) { | 121 const TextureSamplerArray& samplers) { |
119 const AARectEffect& aare = drawEffect.castEffect<AARectEffect>(); | 122 const AARectEffect& aare = drawEffect.castEffect<AARectEffect>(); |
120 const char *rectName; | 123 const char *rectName; |
121 // The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bot
tom - 0.5), | 124 // The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bot
tom - 0.5), |
122 // respectively. | 125 // respectively. |
123 fRectUniform = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, | 126 fRectUniform = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, |
124 kVec4f_GrSLType, | 127 kVec4f_GrSLType, |
125 "rect", | 128 "rect", |
126 &rectName); | 129 &rectName); |
127 const char* fragmentPos = builder->fragmentPosition(); | 130 const char* fragmentPos = builder->fragmentPosition(); |
128 if (GrConvexPolyEffect::kFillAA_EdgeType == aare.getEdgeType() || | 131 if (GrEffectEdgeTypeIsAA(aare.getEdgeType())) { |
129 GrConvexPolyEffect::kInverseFillAA_EdgeType == aare.getEdgeType()) { | |
130 // The amount of coverage removed in x and y by the edges is computed as
a pair of negative | 132 // The amount of coverage removed in x and y by the edges is computed as
a pair of negative |
131 // numbers, xSub and ySub. | 133 // numbers, xSub and ySub. |
132 builder->fsCodeAppend("\t\tfloat xSub, ySub;\n"); | 134 builder->fsCodeAppend("\t\tfloat xSub, ySub;\n"); |
133 builder->fsCodeAppendf("\t\txSub = min(%s.x - %s.x, 0.0);\n", fragmentPo
s, rectName); | 135 builder->fsCodeAppendf("\t\txSub = min(%s.x - %s.x, 0.0);\n", fragmentPo
s, rectName); |
134 builder->fsCodeAppendf("\t\txSub += min(%s.z - %s.x, 0.0);\n", rectName,
fragmentPos); | 136 builder->fsCodeAppendf("\t\txSub += min(%s.z - %s.x, 0.0);\n", rectName,
fragmentPos); |
135 builder->fsCodeAppendf("\t\tySub = min(%s.y - %s.y, 0.0);\n", fragmentPo
s, rectName); | 137 builder->fsCodeAppendf("\t\tySub = min(%s.y - %s.y, 0.0);\n", fragmentPo
s, rectName); |
136 builder->fsCodeAppendf("\t\tySub += min(%s.w - %s.y, 0.0);\n", rectName,
fragmentPos); | 138 builder->fsCodeAppendf("\t\tySub += min(%s.w - %s.y, 0.0);\n", rectName,
fragmentPos); |
137 // Now compute coverage in x and y and multiply them to get the fraction
of the pixel | 139 // Now compute coverage in x and y and multiply them to get the fraction
of the pixel |
138 // covered. | 140 // covered. |
139 builder->fsCodeAppendf("\t\tfloat alpha = (1.0 + max(xSub, -1.0)) * (1.0
+ max(ySub, -1.0));\n"); | 141 builder->fsCodeAppendf("\t\tfloat alpha = (1.0 + max(xSub, -1.0)) * (1.0
+ max(ySub, -1.0));\n"); |
140 } else { | 142 } else { |
141 builder->fsCodeAppendf("\t\tfloat alpha = 1.0;\n"); | 143 builder->fsCodeAppendf("\t\tfloat alpha = 1.0;\n"); |
142 builder->fsCodeAppendf("\t\talpha *= (%s.x - %s.x) > -0.5 ? 1.0 : 0.0;\n
", fragmentPos, rectName); | 144 builder->fsCodeAppendf("\t\talpha *= (%s.x - %s.x) > -0.5 ? 1.0 : 0.0;\n
", fragmentPos, rectName); |
143 builder->fsCodeAppendf("\t\talpha *= (%s.z - %s.x) > -0.5 ? 1.0 : 0.0;\n
", rectName, fragmentPos); | 145 builder->fsCodeAppendf("\t\talpha *= (%s.z - %s.x) > -0.5 ? 1.0 : 0.0;\n
", rectName, fragmentPos); |
144 builder->fsCodeAppendf("\t\talpha *= (%s.y - %s.y) > 0.5 ? 1.0 : 0.0;\n"
, fragmentPos, rectName); | 146 builder->fsCodeAppendf("\t\talpha *= (%s.y - %s.y) > 0.5 ? 1.0 : 0.0;\n"
, fragmentPos, rectName); |
145 builder->fsCodeAppendf("\t\talpha *= (%s.w - %s.y) > 0.5 ? 1.0 : 0.0;\n"
, rectName, fragmentPos); | 147 builder->fsCodeAppendf("\t\talpha *= (%s.w - %s.y) > 0.5 ? 1.0 : 0.0;\n"
, rectName, fragmentPos); |
146 } | 148 } |
147 | 149 |
148 if (GrConvexPolyEffect::kInverseFillAA_EdgeType == aare.getEdgeType() || | 150 if (GrEffectEdgeTypeIsInverseFill(aare.getEdgeType())) { |
149 GrConvexPolyEffect::kInverseFillNoAA_EdgeType == aare.getEdgeType()) { | |
150 builder->fsCodeAppend("\t\talpha = 1.0 - alpha;\n"); | 151 builder->fsCodeAppend("\t\talpha = 1.0 - alpha;\n"); |
151 } | 152 } |
152 builder->fsCodeAppendf("\t\t%s = %s;\n", outputColor, | 153 builder->fsCodeAppendf("\t\t%s = %s;\n", outputColor, |
153 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("alpha")).c_st
r()); | 154 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("alpha")).c_st
r()); |
154 } | 155 } |
155 | 156 |
156 void GLAARectEffect::setData(const GrGLUniformManager& uman, const GrDrawEffect&
drawEffect) { | 157 void GLAARectEffect::setData(const GrGLUniformManager& uman, const GrDrawEffect&
drawEffect) { |
157 const AARectEffect& aare = drawEffect.castEffect<AARectEffect>(); | 158 const AARectEffect& aare = drawEffect.castEffect<AARectEffect>(); |
158 const SkRect& rect = aare.getRect(); | 159 const SkRect& rect = aare.getRect(); |
159 if (rect != fPrevRect) { | 160 if (rect != fPrevRect) { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 kVec3f_GrSLType, | 217 kVec3f_GrSLType, |
217 "edges", | 218 "edges", |
218 cpe.getEdgeCount(), | 219 cpe.getEdgeCount(), |
219 &edgeArrayName); | 220 &edgeArrayName); |
220 builder->fsCodeAppend("\t\tfloat alpha = 1.0;\n"); | 221 builder->fsCodeAppend("\t\tfloat alpha = 1.0;\n"); |
221 builder->fsCodeAppend("\t\tfloat edge;\n"); | 222 builder->fsCodeAppend("\t\tfloat edge;\n"); |
222 const char* fragmentPos = builder->fragmentPosition(); | 223 const char* fragmentPos = builder->fragmentPosition(); |
223 for (int i = 0; i < cpe.getEdgeCount(); ++i) { | 224 for (int i = 0; i < cpe.getEdgeCount(); ++i) { |
224 builder->fsCodeAppendf("\t\tedge = dot(%s[%d], vec3(%s.x, %s.y, 1));\n", | 225 builder->fsCodeAppendf("\t\tedge = dot(%s[%d], vec3(%s.x, %s.y, 1));\n", |
225 edgeArrayName, i, fragmentPos, fragmentPos); | 226 edgeArrayName, i, fragmentPos, fragmentPos); |
226 switch (cpe.getEdgeType()) { | 227 if (GrEffectEdgeTypeIsAA(cpe.getEdgeType())) { |
227 case GrConvexPolyEffect::kFillAA_EdgeType: | 228 builder->fsCodeAppend("\t\tedge = clamp(edge, 0.0, 1.0);\n"); |
228 case GrConvexPolyEffect::kInverseFillAA_EdgeType: // inverse handled
at the end | 229 } else { |
229 builder->fsCodeAppend("\t\tedge = clamp(edge, 0.0, 1.0);\n"); | 230 builder->fsCodeAppend("\t\tedge = edge >= 0.5 ? 1.0 : 0.0;\n"); |
230 break; | |
231 case GrConvexPolyEffect::kFillNoAA_EdgeType: | |
232 case GrConvexPolyEffect::kInverseFillNoAA_EdgeType: // inverse handl
ed at the end | |
233 builder->fsCodeAppend("\t\tedge = edge >= 0.5 ? 1.0 : 0.0;\n"); | |
234 break; | |
235 } | 231 } |
236 builder->fsCodeAppend("\t\talpha *= edge;\n"); | 232 builder->fsCodeAppend("\t\talpha *= edge;\n"); |
237 } | 233 } |
238 | 234 |
239 // Woe is me. See skbug.com/2149. | 235 // Woe is me. See skbug.com/2149. |
240 if (kTegra2_GrGLRenderer == builder->ctxInfo().renderer()) { | 236 if (kTegra2_GrGLRenderer == builder->ctxInfo().renderer()) { |
241 builder->fsCodeAppend("\t\tif (-1.0 == alpha) {\n\t\t\tdiscard;\n\t\t}\n
"); | 237 builder->fsCodeAppend("\t\tif (-1.0 == alpha) {\n\t\t\tdiscard;\n\t\t}\n
"); |
242 } | 238 } |
243 | 239 |
244 if (GrConvexPolyEffect::kInverseFillAA_EdgeType == cpe.getEdgeType() || | 240 if (GrEffectEdgeTypeIsInverseFill(cpe.getEdgeType())) { |
245 GrConvexPolyEffect::kInverseFillNoAA_EdgeType == cpe.getEdgeType() ) { | |
246 builder->fsCodeAppend("\talpha = 1.0 - alpha;\n"); | 241 builder->fsCodeAppend("\talpha = 1.0 - alpha;\n"); |
247 } | 242 } |
248 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, | 243 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, |
249 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("alpha")).c_st
r()); | 244 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("alpha")).c_st
r()); |
250 } | 245 } |
251 | 246 |
252 void GrGLConvexPolyEffect::setData(const GrGLUniformManager& uman, const GrDrawE
ffect& drawEffect) { | 247 void GrGLConvexPolyEffect::setData(const GrGLUniformManager& uman, const GrDrawE
ffect& drawEffect) { |
253 const GrConvexPolyEffect& cpe = drawEffect.castEffect<GrConvexPolyEffect>(); | 248 const GrConvexPolyEffect& cpe = drawEffect.castEffect<GrConvexPolyEffect>(); |
254 size_t byteSize = 3 * cpe.getEdgeCount() * sizeof(SkScalar); | 249 size_t byteSize = 3 * cpe.getEdgeCount() * sizeof(SkScalar); |
255 if (0 != memcmp(fPrevEdges, cpe.getEdges(), byteSize)) { | 250 if (0 != memcmp(fPrevEdges, cpe.getEdges(), byteSize)) { |
256 uman.set3fv(fEdgeUniform, cpe.getEdgeCount(), cpe.getEdges()); | 251 uman.set3fv(fEdgeUniform, cpe.getEdgeCount(), cpe.getEdges()); |
257 memcpy(fPrevEdges, cpe.getEdges(), byteSize); | 252 memcpy(fPrevEdges, cpe.getEdges(), byteSize); |
258 } | 253 } |
259 } | 254 } |
260 | 255 |
261 GrGLEffect::EffectKey GrGLConvexPolyEffect::GenKey(const GrDrawEffect& drawEffec
t, | 256 GrGLEffect::EffectKey GrGLConvexPolyEffect::GenKey(const GrDrawEffect& drawEffec
t, |
262 const GrGLCaps&) { | 257 const GrGLCaps&) { |
263 const GrConvexPolyEffect& cpe = drawEffect.castEffect<GrConvexPolyEffect>(); | 258 const GrConvexPolyEffect& cpe = drawEffect.castEffect<GrConvexPolyEffect>(); |
264 GR_STATIC_ASSERT(GrConvexPolyEffect::kEdgeTypeCnt <= 4); | 259 GR_STATIC_ASSERT(kGrEffectEdgeTypeCnt <= 8); |
265 return (cpe.getEdgeCount() << 2) | cpe.getEdgeType(); | 260 return (cpe.getEdgeCount() << 3) | cpe.getEdgeType(); |
266 } | 261 } |
267 | 262 |
268 ////////////////////////////////////////////////////////////////////////////// | 263 ////////////////////////////////////////////////////////////////////////////// |
269 | 264 |
270 GrEffectRef* GrConvexPolyEffect::Create(EdgeType type, const SkPath& path, const
SkVector* offset) { | 265 GrEffectRef* GrConvexPolyEffect::Create(GrEffectEdgeType type, const SkPath& pat
h, const SkVector* offset) { |
| 266 if (kHairlineAA_GrEffectEdgeType == type) { |
| 267 return NULL; |
| 268 } |
271 if (path.getSegmentMasks() != SkPath::kLine_SegmentMask || | 269 if (path.getSegmentMasks() != SkPath::kLine_SegmentMask || |
272 !path.isConvex() || | 270 !path.isConvex()) { |
273 path.isInverseFillType()) { | |
274 return NULL; | 271 return NULL; |
275 } | 272 } |
276 | 273 |
277 if (path.countPoints() > kMaxEdges) { | 274 if (path.countPoints() > kMaxEdges) { |
278 return NULL; | 275 return NULL; |
279 } | 276 } |
280 | 277 |
281 SkPoint pts[kMaxEdges]; | 278 SkPoint pts[kMaxEdges]; |
282 SkScalar edges[3 * kMaxEdges]; | 279 SkScalar edges[3 * kMaxEdges]; |
283 | 280 |
(...skipping 18 matching lines...) Expand all Loading... |
302 edges[3 * n + 1] = -v.fX; | 299 edges[3 * n + 1] = -v.fX; |
303 } else { | 300 } else { |
304 edges[3 * n] = -v.fY; | 301 edges[3 * n] = -v.fY; |
305 edges[3 * n + 1] = v.fX; | 302 edges[3 * n + 1] = v.fX; |
306 } | 303 } |
307 SkPoint p = pts[i] + t; | 304 SkPoint p = pts[i] + t; |
308 edges[3 * n + 2] = -(edges[3 * n] * p.fX + edges[3 * n + 1] * p.fY); | 305 edges[3 * n + 2] = -(edges[3 * n] * p.fX + edges[3 * n + 1] * p.fY); |
309 ++n; | 306 ++n; |
310 } | 307 } |
311 } | 308 } |
| 309 if (path.isInverseFillType()) { |
| 310 type = GrInvertEffectEdgeType(type); |
| 311 } |
312 return Create(type, n, edges); | 312 return Create(type, n, edges); |
313 } | 313 } |
314 | 314 |
315 GrEffectRef* GrConvexPolyEffect::Create(EdgeType edgeType, const SkRect& rect) { | 315 GrEffectRef* GrConvexPolyEffect::Create(GrEffectEdgeType edgeType, const SkRect&
rect) { |
| 316 if (kHairlineAA_GrEffectEdgeType == edgeType){ |
| 317 return NULL; |
| 318 } |
316 return AARectEffect::Create(edgeType, rect); | 319 return AARectEffect::Create(edgeType, rect); |
317 } | 320 } |
318 | 321 |
319 GrConvexPolyEffect::~GrConvexPolyEffect() {} | 322 GrConvexPolyEffect::~GrConvexPolyEffect() {} |
320 | 323 |
321 void GrConvexPolyEffect::getConstantColorComponents(GrColor* color, uint32_t* va
lidFlags) const { | 324 void GrConvexPolyEffect::getConstantColorComponents(GrColor* color, uint32_t* va
lidFlags) const { |
322 *validFlags = 0; | 325 *validFlags = 0; |
323 } | 326 } |
324 | 327 |
325 const GrBackendEffectFactory& GrConvexPolyEffect::getFactory() const { | 328 const GrBackendEffectFactory& GrConvexPolyEffect::getFactory() const { |
326 return GrTBackendEffectFactory<GrConvexPolyEffect>::getInstance(); | 329 return GrTBackendEffectFactory<GrConvexPolyEffect>::getInstance(); |
327 } | 330 } |
328 | 331 |
329 GrConvexPolyEffect::GrConvexPolyEffect(EdgeType edgeType, int n, const SkScalar
edges[]) | 332 GrConvexPolyEffect::GrConvexPolyEffect(GrEffectEdgeType edgeType, int n, const S
kScalar edges[]) |
330 : fEdgeType(edgeType) | 333 : fEdgeType(edgeType) |
331 , fEdgeCount(n) { | 334 , fEdgeCount(n) { |
332 // Factory function should have already ensured this. | 335 // Factory function should have already ensured this. |
333 SkASSERT(n <= kMaxEdges); | 336 SkASSERT(n <= kMaxEdges); |
334 memcpy(fEdges, edges, 3 * n * sizeof(SkScalar)); | 337 memcpy(fEdges, edges, 3 * n * sizeof(SkScalar)); |
335 // Outset the edges by 0.5 so that a pixel with center on an edge is 50% cov
ered in the AA case | 338 // Outset the edges by 0.5 so that a pixel with center on an edge is 50% cov
ered in the AA case |
336 // and 100% covered in the non-AA case. | 339 // and 100% covered in the non-AA case. |
337 for (int i = 0; i < n; ++i) { | 340 for (int i = 0; i < n; ++i) { |
338 fEdges[3 * i + 2] += SK_ScalarHalf; | 341 fEdges[3 * i + 2] += SK_ScalarHalf; |
339 } | 342 } |
340 this->setWillReadFragmentPosition(); | 343 this->setWillReadFragmentPosition(); |
341 } | 344 } |
342 | 345 |
343 bool GrConvexPolyEffect::onIsEqual(const GrEffect& other) const { | 346 bool GrConvexPolyEffect::onIsEqual(const GrEffect& other) const { |
344 const GrConvexPolyEffect& cpe = CastEffect<GrConvexPolyEffect>(other); | 347 const GrConvexPolyEffect& cpe = CastEffect<GrConvexPolyEffect>(other); |
345 // ignore the fact that 0 == -0 and just use memcmp. | 348 // ignore the fact that 0 == -0 and just use memcmp. |
346 return (cpe.fEdgeType == fEdgeType && cpe.fEdgeCount == fEdgeCount && | 349 return (cpe.fEdgeType == fEdgeType && cpe.fEdgeCount == fEdgeCount && |
347 0 == memcmp(cpe.fEdges, fEdges, 3 * fEdgeCount * sizeof(SkScalar))); | 350 0 == memcmp(cpe.fEdges, fEdges, 3 * fEdgeCount * sizeof(SkScalar))); |
348 } | 351 } |
349 | 352 |
350 ////////////////////////////////////////////////////////////////////////////// | 353 ////////////////////////////////////////////////////////////////////////////// |
351 | 354 |
352 GR_DEFINE_EFFECT_TEST(GrConvexPolyEffect); | 355 GR_DEFINE_EFFECT_TEST(GrConvexPolyEffect); |
353 | 356 |
354 GrEffectRef* GrConvexPolyEffect::TestCreate(SkRandom* random, | 357 GrEffectRef* GrConvexPolyEffect::TestCreate(SkRandom* random, |
355 GrContext*, | 358 GrContext*, |
356 const GrDrawTargetCaps& caps, | 359 const GrDrawTargetCaps& caps, |
357 GrTexture*[]) { | 360 GrTexture*[]) { |
358 EdgeType edgeType = static_cast<EdgeType>(random->nextULessThan(kEdgeTypeCnt
)); | |
359 int count = random->nextULessThan(kMaxEdges) + 1; | 361 int count = random->nextULessThan(kMaxEdges) + 1; |
360 SkScalar edges[kMaxEdges * 3]; | 362 SkScalar edges[kMaxEdges * 3]; |
361 for (int i = 0; i < 3 * count; ++i) { | 363 for (int i = 0; i < 3 * count; ++i) { |
362 edges[i] = random->nextSScalar1(); | 364 edges[i] = random->nextSScalar1(); |
363 } | 365 } |
364 | 366 |
365 return GrConvexPolyEffect::Create(edgeType, count, edges); | 367 GrEffectRef* effect; |
| 368 do { |
| 369 GrEffectEdgeType edgeType = static_cast<GrEffectEdgeType>( |
| 370 random->nextULessThan(kGrEffectEdgeTypeC
nt)); |
| 371 effect = GrConvexPolyEffect::Create(edgeType, count, edges); |
| 372 } while (NULL == effect); |
| 373 return effect; |
366 } | 374 } |
OLD | NEW |