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 | 22 |
23 const SkRect& getRect() const { return fRect; } | 23 const SkRect& getRect() const { return fRect; } |
24 | 24 |
25 static const char* Name() { return "AARect"; } | 25 static const char* Name() { return "AARect"; } |
26 | 26 |
27 static GrEffectRef* Create(GrEffectEdgeType edgeType, const SkRect& rect) { | 27 static GrEffect* Create(GrEffectEdgeType edgeType, const SkRect& rect) { |
28 return SkNEW_ARGS(AARectEffect, (edgeType, rect)); | 28 return SkNEW_ARGS(AARectEffect, (edgeType, rect)); |
29 } | 29 } |
30 | 30 |
31 virtual void getConstantColorComponents(GrColor* color, | 31 virtual void getConstantColorComponents(GrColor* color, |
32 uint32_t* validFlags) const SK_OVERR
IDE { | 32 uint32_t* validFlags) const SK_OVERR
IDE { |
33 if (fRect.isEmpty()) { | 33 if (fRect.isEmpty()) { |
34 // An empty rect will have no coverage anywhere. | 34 // An empty rect will have no coverage anywhere. |
35 *color = 0x00000000; | 35 *color = 0x00000000; |
36 *validFlags = kRGBA_GrColorComponentFlags; | 36 *validFlags = kRGBA_GrColorComponentFlags; |
37 } else { | 37 } else { |
(...skipping 19 matching lines...) Expand all Loading... |
57 GrEffectEdgeType fEdgeType; | 57 GrEffectEdgeType fEdgeType; |
58 | 58 |
59 typedef GrEffect INHERITED; | 59 typedef GrEffect INHERITED; |
60 | 60 |
61 GR_DECLARE_EFFECT_TEST; | 61 GR_DECLARE_EFFECT_TEST; |
62 | 62 |
63 }; | 63 }; |
64 | 64 |
65 GR_DEFINE_EFFECT_TEST(AARectEffect); | 65 GR_DEFINE_EFFECT_TEST(AARectEffect); |
66 | 66 |
67 GrEffectRef* AARectEffect::TestCreate(SkRandom* random, | 67 GrEffect* AARectEffect::TestCreate(SkRandom* random, |
68 GrContext*, | 68 GrContext*, |
69 const GrDrawTargetCaps& caps, | 69 const GrDrawTargetCaps& caps, |
70 GrTexture*[]) { | 70 GrTexture*[]) { |
71 SkRect rect = SkRect::MakeLTRB(random->nextSScalar1(), | 71 SkRect rect = SkRect::MakeLTRB(random->nextSScalar1(), |
72 random->nextSScalar1(), | 72 random->nextSScalar1(), |
73 random->nextSScalar1(), | 73 random->nextSScalar1(), |
74 random->nextSScalar1()); | 74 random->nextSScalar1()); |
75 GrEffectRef* effect; | 75 GrEffect* effect; |
76 do { | 76 do { |
77 GrEffectEdgeType edgeType = static_cast<GrEffectEdgeType>(random->nextUL
essThan( | 77 GrEffectEdgeType edgeType = static_cast<GrEffectEdgeType>(random->nextUL
essThan( |
78 kGrEffectEdg
eTypeCnt)); | 78 kGrEffectEdg
eTypeCnt)); |
79 | 79 |
80 effect = AARectEffect::Create(edgeType, rect); | 80 effect = AARectEffect::Create(edgeType, rect); |
81 } while (NULL == effect); | 81 } while (NULL == effect); |
82 return effect; | 82 return effect; |
83 } | 83 } |
84 | 84 |
85 ////////////////////////////////////////////////////////////////////////////// | 85 ////////////////////////////////////////////////////////////////////////////// |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 | 255 |
256 GrGLEffect::EffectKey GrGLConvexPolyEffect::GenKey(const GrDrawEffect& drawEffec
t, | 256 GrGLEffect::EffectKey GrGLConvexPolyEffect::GenKey(const GrDrawEffect& drawEffec
t, |
257 const GrGLCaps&) { | 257 const GrGLCaps&) { |
258 const GrConvexPolyEffect& cpe = drawEffect.castEffect<GrConvexPolyEffect>(); | 258 const GrConvexPolyEffect& cpe = drawEffect.castEffect<GrConvexPolyEffect>(); |
259 GR_STATIC_ASSERT(kGrEffectEdgeTypeCnt <= 8); | 259 GR_STATIC_ASSERT(kGrEffectEdgeTypeCnt <= 8); |
260 return (cpe.getEdgeCount() << 3) | cpe.getEdgeType(); | 260 return (cpe.getEdgeCount() << 3) | cpe.getEdgeType(); |
261 } | 261 } |
262 | 262 |
263 ////////////////////////////////////////////////////////////////////////////// | 263 ////////////////////////////////////////////////////////////////////////////// |
264 | 264 |
265 GrEffectRef* GrConvexPolyEffect::Create(GrEffectEdgeType type, const SkPath& pat
h, const SkVector* offset) { | 265 GrEffect* GrConvexPolyEffect::Create(GrEffectEdgeType type, const SkPath& path, |
| 266 const SkVector* offset) { |
266 if (kHairlineAA_GrEffectEdgeType == type) { | 267 if (kHairlineAA_GrEffectEdgeType == type) { |
267 return NULL; | 268 return NULL; |
268 } | 269 } |
269 if (path.getSegmentMasks() != SkPath::kLine_SegmentMask || | 270 if (path.getSegmentMasks() != SkPath::kLine_SegmentMask || |
270 !path.isConvex()) { | 271 !path.isConvex()) { |
271 return NULL; | 272 return NULL; |
272 } | 273 } |
273 | 274 |
274 if (path.countPoints() > kMaxEdges) { | 275 if (path.countPoints() > kMaxEdges) { |
275 return NULL; | 276 return NULL; |
(...skipping 29 matching lines...) Expand all Loading... |
305 edges[3 * n + 2] = -(edges[3 * n] * p.fX + edges[3 * n + 1] * p.fY); | 306 edges[3 * n + 2] = -(edges[3 * n] * p.fX + edges[3 * n + 1] * p.fY); |
306 ++n; | 307 ++n; |
307 } | 308 } |
308 } | 309 } |
309 if (path.isInverseFillType()) { | 310 if (path.isInverseFillType()) { |
310 type = GrInvertEffectEdgeType(type); | 311 type = GrInvertEffectEdgeType(type); |
311 } | 312 } |
312 return Create(type, n, edges); | 313 return Create(type, n, edges); |
313 } | 314 } |
314 | 315 |
315 GrEffectRef* GrConvexPolyEffect::Create(GrEffectEdgeType edgeType, const SkRect&
rect) { | 316 GrEffect* GrConvexPolyEffect::Create(GrEffectEdgeType edgeType, const SkRect& re
ct) { |
316 if (kHairlineAA_GrEffectEdgeType == edgeType){ | 317 if (kHairlineAA_GrEffectEdgeType == edgeType){ |
317 return NULL; | 318 return NULL; |
318 } | 319 } |
319 return AARectEffect::Create(edgeType, rect); | 320 return AARectEffect::Create(edgeType, rect); |
320 } | 321 } |
321 | 322 |
322 GrConvexPolyEffect::~GrConvexPolyEffect() {} | 323 GrConvexPolyEffect::~GrConvexPolyEffect() {} |
323 | 324 |
324 void GrConvexPolyEffect::getConstantColorComponents(GrColor* color, uint32_t* va
lidFlags) const { | 325 void GrConvexPolyEffect::getConstantColorComponents(GrColor* color, uint32_t* va
lidFlags) const { |
325 *validFlags = 0; | 326 *validFlags = 0; |
(...skipping 21 matching lines...) Expand all Loading... |
347 const GrConvexPolyEffect& cpe = CastEffect<GrConvexPolyEffect>(other); | 348 const GrConvexPolyEffect& cpe = CastEffect<GrConvexPolyEffect>(other); |
348 // ignore the fact that 0 == -0 and just use memcmp. | 349 // ignore the fact that 0 == -0 and just use memcmp. |
349 return (cpe.fEdgeType == fEdgeType && cpe.fEdgeCount == fEdgeCount && | 350 return (cpe.fEdgeType == fEdgeType && cpe.fEdgeCount == fEdgeCount && |
350 0 == memcmp(cpe.fEdges, fEdges, 3 * fEdgeCount * sizeof(SkScalar))); | 351 0 == memcmp(cpe.fEdges, fEdges, 3 * fEdgeCount * sizeof(SkScalar))); |
351 } | 352 } |
352 | 353 |
353 ////////////////////////////////////////////////////////////////////////////// | 354 ////////////////////////////////////////////////////////////////////////////// |
354 | 355 |
355 GR_DEFINE_EFFECT_TEST(GrConvexPolyEffect); | 356 GR_DEFINE_EFFECT_TEST(GrConvexPolyEffect); |
356 | 357 |
357 GrEffectRef* GrConvexPolyEffect::TestCreate(SkRandom* random, | 358 GrEffect* GrConvexPolyEffect::TestCreate(SkRandom* random, |
358 GrContext*, | 359 GrContext*, |
359 const GrDrawTargetCaps& caps, | 360 const GrDrawTargetCaps& caps, |
360 GrTexture*[]) { | 361 GrTexture*[]) { |
361 int count = random->nextULessThan(kMaxEdges) + 1; | 362 int count = random->nextULessThan(kMaxEdges) + 1; |
362 SkScalar edges[kMaxEdges * 3]; | 363 SkScalar edges[kMaxEdges * 3]; |
363 for (int i = 0; i < 3 * count; ++i) { | 364 for (int i = 0; i < 3 * count; ++i) { |
364 edges[i] = random->nextSScalar1(); | 365 edges[i] = random->nextSScalar1(); |
365 } | 366 } |
366 | 367 |
367 GrEffectRef* effect; | 368 GrEffect* effect; |
368 do { | 369 do { |
369 GrEffectEdgeType edgeType = static_cast<GrEffectEdgeType>( | 370 GrEffectEdgeType edgeType = static_cast<GrEffectEdgeType>( |
370 random->nextULessThan(kGrEffectEdgeTypeC
nt)); | 371 random->nextULessThan(kGrEffectEdgeTypeC
nt)); |
371 effect = GrConvexPolyEffect::Create(edgeType, count, edges); | 372 effect = GrConvexPolyEffect::Create(edgeType, count, edges); |
372 } while (NULL == effect); | 373 } while (NULL == effect); |
373 return effect; | 374 return effect; |
374 } | 375 } |
OLD | NEW |