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 #include "GrInvariantOutput.h" | 9 #include "GrInvariantOutput.h" |
10 #include "SkPathPriv.h" | 10 #include "SkPathPriv.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } | 25 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } |
26 | 26 |
27 const char* name() const override { return "AARect"; } | 27 const char* name() const override { return "AARect"; } |
28 | 28 |
29 void onGetGLSLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const
override; | 29 void onGetGLSLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const
override; |
30 | 30 |
31 private: | 31 private: |
32 AARectEffect(GrPrimitiveEdgeType edgeType, const SkRect& rect) | 32 AARectEffect(GrPrimitiveEdgeType edgeType, const SkRect& rect) |
33 : fRect(rect), fEdgeType(edgeType) { | 33 : fRect(rect), fEdgeType(edgeType) { |
34 this->initClassID<AARectEffect>(); | 34 this->initClassID<AARectEffect>(); |
35 this->setWillReadFragmentPosition(); | 35 this->enableBuiltInState(kFragmentPosition_BuiltInState); |
36 } | 36 } |
37 | 37 |
38 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; | 38 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
39 | 39 |
40 bool onIsEqual(const GrFragmentProcessor& other) const override { | 40 bool onIsEqual(const GrFragmentProcessor& other) const override { |
41 const AARectEffect& aare = other.cast<AARectEffect>(); | 41 const AARectEffect& aare = other.cast<AARectEffect>(); |
42 return fRect == aare.fRect; | 42 return fRect == aare.fRect; |
43 } | 43 } |
44 | 44 |
45 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { | 45 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 , fEdgeCount(n) { | 314 , fEdgeCount(n) { |
315 this->initClassID<GrConvexPolyEffect>(); | 315 this->initClassID<GrConvexPolyEffect>(); |
316 // Factory function should have already ensured this. | 316 // Factory function should have already ensured this. |
317 SkASSERT(n <= kMaxEdges); | 317 SkASSERT(n <= kMaxEdges); |
318 memcpy(fEdges, edges, 3 * n * sizeof(SkScalar)); | 318 memcpy(fEdges, edges, 3 * n * sizeof(SkScalar)); |
319 // Outset the edges by 0.5 so that a pixel with center on an edge is 50% cov
ered in the AA case | 319 // Outset the edges by 0.5 so that a pixel with center on an edge is 50% cov
ered in the AA case |
320 // and 100% covered in the non-AA case. | 320 // and 100% covered in the non-AA case. |
321 for (int i = 0; i < n; ++i) { | 321 for (int i = 0; i < n; ++i) { |
322 fEdges[3 * i + 2] += SK_ScalarHalf; | 322 fEdges[3 * i + 2] += SK_ScalarHalf; |
323 } | 323 } |
324 this->setWillReadFragmentPosition(); | 324 this->enableBuiltInState(kFragmentPosition_BuiltInState); |
325 } | 325 } |
326 | 326 |
327 bool GrConvexPolyEffect::onIsEqual(const GrFragmentProcessor& other) const { | 327 bool GrConvexPolyEffect::onIsEqual(const GrFragmentProcessor& other) const { |
328 const GrConvexPolyEffect& cpe = other.cast<GrConvexPolyEffect>(); | 328 const GrConvexPolyEffect& cpe = other.cast<GrConvexPolyEffect>(); |
329 // ignore the fact that 0 == -0 and just use memcmp. | 329 // ignore the fact that 0 == -0 and just use memcmp. |
330 return (cpe.fEdgeType == fEdgeType && cpe.fEdgeCount == fEdgeCount && | 330 return (cpe.fEdgeType == fEdgeType && cpe.fEdgeCount == fEdgeCount && |
331 0 == memcmp(cpe.fEdges, fEdges, 3 * fEdgeCount * sizeof(SkScalar))); | 331 0 == memcmp(cpe.fEdges, fEdges, 3 * fEdgeCount * sizeof(SkScalar))); |
332 } | 332 } |
333 | 333 |
334 ////////////////////////////////////////////////////////////////////////////// | 334 ////////////////////////////////////////////////////////////////////////////// |
335 | 335 |
336 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrConvexPolyEffect); | 336 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrConvexPolyEffect); |
337 | 337 |
338 const GrFragmentProcessor* GrConvexPolyEffect::TestCreate(GrProcessorTestData* d
) { | 338 const GrFragmentProcessor* GrConvexPolyEffect::TestCreate(GrProcessorTestData* d
) { |
339 int count = d->fRandom->nextULessThan(kMaxEdges) + 1; | 339 int count = d->fRandom->nextULessThan(kMaxEdges) + 1; |
340 SkScalar edges[kMaxEdges * 3]; | 340 SkScalar edges[kMaxEdges * 3]; |
341 for (int i = 0; i < 3 * count; ++i) { | 341 for (int i = 0; i < 3 * count; ++i) { |
342 edges[i] = d->fRandom->nextSScalar1(); | 342 edges[i] = d->fRandom->nextSScalar1(); |
343 } | 343 } |
344 | 344 |
345 GrFragmentProcessor* fp; | 345 GrFragmentProcessor* fp; |
346 do { | 346 do { |
347 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( | 347 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( |
348 d->fRandom->nextULessThan(kGrProcessorEdgeTypeCnt)); | 348 d->fRandom->nextULessThan(kGrProcessorEdgeTypeCnt)); |
349 fp = GrConvexPolyEffect::Create(edgeType, count, edges); | 349 fp = GrConvexPolyEffect::Create(edgeType, count, edges); |
350 } while (nullptr == fp); | 350 } while (nullptr == fp); |
351 return fp; | 351 return fp; |
352 } | 352 } |
OLD | NEW |