| 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" |
| 11 #include "effects/GrConstColorProcessor.h" | 11 #include "effects/GrConstColorProcessor.h" |
| 12 #include "glsl/GrGLSLFragmentProcessor.h" | 12 #include "glsl/GrGLSLFragmentProcessor.h" |
| 13 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 13 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
| 14 #include "glsl/GrGLSLProgramDataManager.h" | 14 #include "glsl/GrGLSLProgramDataManager.h" |
| 15 #include "glsl/GrGLSLUniformHandler.h" | 15 #include "glsl/GrGLSLUniformHandler.h" |
| 16 | 16 |
| 17 ////////////////////////////////////////////////////////////////////////////// | 17 ////////////////////////////////////////////////////////////////////////////// |
| 18 class AARectEffect : public GrFragmentProcessor { | 18 class AARectEffect : public GrFragmentProcessor { |
| 19 public: | 19 public: |
| 20 const SkRect& getRect() const { return fRect; } | 20 const SkRect& getRect() const { return fRect; } |
| 21 | 21 |
| 22 static GrFragmentProcessor* Create(GrPrimitiveEdgeType edgeType, const SkRec
t& rect) { | 22 static sk_sp<GrFragmentProcessor> Make(GrPrimitiveEdgeType edgeType, const S
kRect& rect) { |
| 23 return new AARectEffect(edgeType, rect); | 23 return sk_sp<GrFragmentProcessor>(new AARectEffect(edgeType, rect)); |
| 24 } | 24 } |
| 25 | 25 |
| 26 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } | 26 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } |
| 27 | 27 |
| 28 const char* name() const override { return "AARect"; } | 28 const char* name() const override { return "AARect"; } |
| 29 | 29 |
| 30 void onGetGLSLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const
override; | 30 void onGetGLSLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const
override; |
| 31 | 31 |
| 32 private: | 32 private: |
| 33 AARectEffect(GrPrimitiveEdgeType edgeType, const SkRect& rect) | 33 AARectEffect(GrPrimitiveEdgeType edgeType, const SkRect& rect) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 56 GrPrimitiveEdgeType fEdgeType; | 56 GrPrimitiveEdgeType fEdgeType; |
| 57 | 57 |
| 58 typedef GrFragmentProcessor INHERITED; | 58 typedef GrFragmentProcessor INHERITED; |
| 59 | 59 |
| 60 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 60 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
| 61 | 61 |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(AARectEffect); | 64 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(AARectEffect); |
| 65 | 65 |
| 66 const GrFragmentProcessor* AARectEffect::TestCreate(GrProcessorTestData* d) { | 66 sk_sp<GrFragmentProcessor> AARectEffect::TestCreate(GrProcessorTestData* d) { |
| 67 SkRect rect = SkRect::MakeLTRB(d->fRandom->nextSScalar1(), | 67 SkRect rect = SkRect::MakeLTRB(d->fRandom->nextSScalar1(), |
| 68 d->fRandom->nextSScalar1(), | 68 d->fRandom->nextSScalar1(), |
| 69 d->fRandom->nextSScalar1(), | 69 d->fRandom->nextSScalar1(), |
| 70 d->fRandom->nextSScalar1()); | 70 d->fRandom->nextSScalar1()); |
| 71 GrFragmentProcessor* fp; | 71 sk_sp<GrFragmentProcessor> fp; |
| 72 do { | 72 do { |
| 73 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( | 73 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( |
| 74 d->fRandom->nextULessThan(kGrProcessorEdgeTypeCnt)); | 74 d->fRandom->nextULessThan(kGrProcessorEdgeTypeCnt)); |
| 75 | 75 |
| 76 fp = AARectEffect::Create(edgeType, rect); | 76 fp = AARectEffect::Make(edgeType, rect); |
| 77 } while (nullptr == fp); | 77 } while (nullptr == fp); |
| 78 return fp; | 78 return fp; |
| 79 } | 79 } |
| 80 | 80 |
| 81 ////////////////////////////////////////////////////////////////////////////// | 81 ////////////////////////////////////////////////////////////////////////////// |
| 82 | 82 |
| 83 class GLAARectEffect : public GrGLSLFragmentProcessor { | 83 class GLAARectEffect : public GrGLSLFragmentProcessor { |
| 84 public: | 84 public: |
| 85 GLAARectEffect() { | 85 GLAARectEffect() { |
| 86 fPrevRect.fLeft = SK_ScalarNaN; | 86 fPrevRect.fLeft = SK_ScalarNaN; |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 void GrGLConvexPolyEffect::GenKey(const GrProcessor& processor, const GrGLSLCaps
&, | 230 void GrGLConvexPolyEffect::GenKey(const GrProcessor& processor, const GrGLSLCaps
&, |
| 231 GrProcessorKeyBuilder* b) { | 231 GrProcessorKeyBuilder* b) { |
| 232 const GrConvexPolyEffect& cpe = processor.cast<GrConvexPolyEffect>(); | 232 const GrConvexPolyEffect& cpe = processor.cast<GrConvexPolyEffect>(); |
| 233 GR_STATIC_ASSERT(kGrProcessorEdgeTypeCnt <= 8); | 233 GR_STATIC_ASSERT(kGrProcessorEdgeTypeCnt <= 8); |
| 234 uint32_t key = (cpe.getEdgeCount() << 3) | cpe.getEdgeType(); | 234 uint32_t key = (cpe.getEdgeCount() << 3) | cpe.getEdgeType(); |
| 235 b->add32(key); | 235 b->add32(key); |
| 236 } | 236 } |
| 237 | 237 |
| 238 ////////////////////////////////////////////////////////////////////////////// | 238 ////////////////////////////////////////////////////////////////////////////// |
| 239 | 239 |
| 240 GrFragmentProcessor* GrConvexPolyEffect::Create(GrPrimitiveEdgeType type, const
SkPath& path, | 240 sk_sp<GrFragmentProcessor> GrConvexPolyEffect::Make(GrPrimitiveEdgeType type, co
nst SkPath& path, |
| 241 const SkVector* offset) { | 241 const SkVector* offset) { |
| 242 if (kHairlineAA_GrProcessorEdgeType == type) { | 242 if (kHairlineAA_GrProcessorEdgeType == type) { |
| 243 return nullptr; | 243 return nullptr; |
| 244 } | 244 } |
| 245 if (path.getSegmentMasks() != SkPath::kLine_SegmentMask || | 245 if (path.getSegmentMasks() != SkPath::kLine_SegmentMask || |
| 246 !path.isConvex()) { | 246 !path.isConvex()) { |
| 247 return nullptr; | 247 return nullptr; |
| 248 } | 248 } |
| 249 | 249 |
| 250 SkPathPriv::FirstDirection dir; | 250 SkPathPriv::FirstDirection dir; |
| 251 // The only way this should fail is if the clip is effectively a infinitely
thin line. In that | 251 // The only way this should fail is if the clip is effectively a infinitely
thin line. In that |
| 252 // case nothing is inside the clip. It'd be nice to detect this at a higher
level and either | 252 // case nothing is inside the clip. It'd be nice to detect this at a higher
level and either |
| 253 // skip the draw or omit the clip element. | 253 // skip the draw or omit the clip element. |
| 254 if (!SkPathPriv::CheapComputeFirstDirection(path, &dir)) { | 254 if (!SkPathPriv::CheapComputeFirstDirection(path, &dir)) { |
| 255 if (GrProcessorEdgeTypeIsInverseFill(type)) { | 255 if (GrProcessorEdgeTypeIsInverseFill(type)) { |
| 256 return GrConstColorProcessor::Create(0xFFFFFFFF, | 256 return GrConstColorProcessor::Make(0xFFFFFFFF, |
| 257 GrConstColorProcessor::kModulat
eRGBA_InputMode); | 257 GrConstColorProcessor::kModulateR
GBA_InputMode); |
| 258 } | 258 } |
| 259 return GrConstColorProcessor::Create(0, GrConstColorProcessor::kIgnore_I
nputMode); | 259 return GrConstColorProcessor::Make(0, GrConstColorProcessor::kIgnore_Inp
utMode); |
| 260 } | 260 } |
| 261 | 261 |
| 262 SkVector t; | 262 SkVector t; |
| 263 if (nullptr == offset) { | 263 if (nullptr == offset) { |
| 264 t.set(0, 0); | 264 t.set(0, 0); |
| 265 } else { | 265 } else { |
| 266 t = *offset; | 266 t = *offset; |
| 267 } | 267 } |
| 268 | 268 |
| 269 SkScalar edges[3 * kMaxEdges]; | 269 SkScalar edges[3 * kMaxEdges]; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 break; | 301 break; |
| 302 } | 302 } |
| 303 default: | 303 default: |
| 304 return nullptr; | 304 return nullptr; |
| 305 } | 305 } |
| 306 } | 306 } |
| 307 | 307 |
| 308 if (path.isInverseFillType()) { | 308 if (path.isInverseFillType()) { |
| 309 type = GrInvertProcessorEdgeType(type); | 309 type = GrInvertProcessorEdgeType(type); |
| 310 } | 310 } |
| 311 return Create(type, n, edges); | 311 return Make(type, n, edges); |
| 312 } | 312 } |
| 313 | 313 |
| 314 GrFragmentProcessor* GrConvexPolyEffect::Create(GrPrimitiveEdgeType edgeType, co
nst SkRect& rect) { | 314 sk_sp<GrFragmentProcessor> GrConvexPolyEffect::Make(GrPrimitiveEdgeType edgeType
, |
| 315 const SkRect& rect) { |
| 315 if (kHairlineAA_GrProcessorEdgeType == edgeType){ | 316 if (kHairlineAA_GrProcessorEdgeType == edgeType){ |
| 316 return nullptr; | 317 return nullptr; |
| 317 } | 318 } |
| 318 return AARectEffect::Create(edgeType, rect); | 319 return AARectEffect::Make(edgeType, rect); |
| 319 } | 320 } |
| 320 | 321 |
| 321 GrConvexPolyEffect::~GrConvexPolyEffect() {} | 322 GrConvexPolyEffect::~GrConvexPolyEffect() {} |
| 322 | 323 |
| 323 void GrConvexPolyEffect::onComputeInvariantOutput(GrInvariantOutput* inout) cons
t { | 324 void GrConvexPolyEffect::onComputeInvariantOutput(GrInvariantOutput* inout) cons
t { |
| 324 inout->mulByUnknownSingleComponent(); | 325 inout->mulByUnknownSingleComponent(); |
| 325 } | 326 } |
| 326 | 327 |
| 327 void GrConvexPolyEffect::onGetGLSLProcessorKey(const GrGLSLCaps& caps, | 328 void GrConvexPolyEffect::onGetGLSLProcessorKey(const GrGLSLCaps& caps, |
| 328 GrProcessorKeyBuilder* b) const { | 329 GrProcessorKeyBuilder* b) const { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 352 const GrConvexPolyEffect& cpe = other.cast<GrConvexPolyEffect>(); | 353 const GrConvexPolyEffect& cpe = other.cast<GrConvexPolyEffect>(); |
| 353 // ignore the fact that 0 == -0 and just use memcmp. | 354 // ignore the fact that 0 == -0 and just use memcmp. |
| 354 return (cpe.fEdgeType == fEdgeType && cpe.fEdgeCount == fEdgeCount && | 355 return (cpe.fEdgeType == fEdgeType && cpe.fEdgeCount == fEdgeCount && |
| 355 0 == memcmp(cpe.fEdges, fEdges, 3 * fEdgeCount * sizeof(SkScalar))); | 356 0 == memcmp(cpe.fEdges, fEdges, 3 * fEdgeCount * sizeof(SkScalar))); |
| 356 } | 357 } |
| 357 | 358 |
| 358 ////////////////////////////////////////////////////////////////////////////// | 359 ////////////////////////////////////////////////////////////////////////////// |
| 359 | 360 |
| 360 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrConvexPolyEffect); | 361 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrConvexPolyEffect); |
| 361 | 362 |
| 362 const GrFragmentProcessor* GrConvexPolyEffect::TestCreate(GrProcessorTestData* d
) { | 363 sk_sp<GrFragmentProcessor> GrConvexPolyEffect::TestCreate(GrProcessorTestData* d
) { |
| 363 int count = d->fRandom->nextULessThan(kMaxEdges) + 1; | 364 int count = d->fRandom->nextULessThan(kMaxEdges) + 1; |
| 364 SkScalar edges[kMaxEdges * 3]; | 365 SkScalar edges[kMaxEdges * 3]; |
| 365 for (int i = 0; i < 3 * count; ++i) { | 366 for (int i = 0; i < 3 * count; ++i) { |
| 366 edges[i] = d->fRandom->nextSScalar1(); | 367 edges[i] = d->fRandom->nextSScalar1(); |
| 367 } | 368 } |
| 368 | 369 |
| 369 GrFragmentProcessor* fp; | 370 sk_sp<GrFragmentProcessor> fp; |
| 370 do { | 371 do { |
| 371 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( | 372 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( |
| 372 d->fRandom->nextULessThan(kGrProcessorEdgeTypeCnt)); | 373 d->fRandom->nextULessThan(kGrProcessorEdgeTypeCnt)); |
| 373 fp = GrConvexPolyEffect::Create(edgeType, count, edges); | 374 fp = GrConvexPolyEffect::Make(edgeType, count, edges); |
| 374 } while (nullptr == fp); | 375 } while (nullptr == fp); |
| 375 return fp; | 376 return fp; |
| 376 } | 377 } |
| OLD | NEW |