rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2012 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
commit-bot@chromium.org | aa64fbf | 2014-04-03 14:59:19 +0000 | [diff] [blame] | 9 | #ifndef SkTwoPointConicalGradient_DEFINED |
| 10 | #define SkTwoPointConicalGradient_DEFINED |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 11 | |
| 12 | #include "SkGradientShaderPriv.h" |
| 13 | |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 14 | // TODO(dominikg): Worth making it truly immutable (i.e. set values in constructor)? |
| 15 | // Should only be initialized once via init(). Immutable afterwards. |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 16 | struct TwoPtRadial { |
| 17 | enum { |
| 18 | kDontDrawT = 0x80000000 |
| 19 | }; |
| 20 | |
| 21 | float fCenterX, fCenterY; |
| 22 | float fDCenterX, fDCenterY; |
| 23 | float fRadius; |
| 24 | float fDRadius; |
| 25 | float fA; |
| 26 | float fRadius2; |
| 27 | float fRDR; |
commit-bot@chromium.org | 44d83c1 | 2014-04-21 13:10:25 +0000 | [diff] [blame] | 28 | bool fFlipped; |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 29 | |
| 30 | void init(const SkPoint& center0, SkScalar rad0, |
commit-bot@chromium.org | 44d83c1 | 2014-04-21 13:10:25 +0000 | [diff] [blame] | 31 | const SkPoint& center1, SkScalar rad1, |
| 32 | bool flipped); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 33 | |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 34 | static bool DontDrawT(SkFixed t) { |
| 35 | return kDontDrawT == (uint32_t)t; |
| 36 | } |
| 37 | }; |
| 38 | |
| 39 | |
| 40 | class SkTwoPointConicalGradient : public SkGradientShaderBase { |
| 41 | TwoPtRadial fRec; |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 42 | public: |
| 43 | SkTwoPointConicalGradient(const SkPoint& start, SkScalar startRadius, |
| 44 | const SkPoint& end, SkScalar endRadius, |
reed | addf2ed | 2014-08-11 08:28:24 -0700 | [diff] [blame] | 45 | bool flippedGrad, const Descriptor&); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 46 | |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 47 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 48 | size_t contextSize() const override; |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 49 | |
| 50 | class TwoPointConicalGradientContext : public SkGradientShaderBase::GradientShaderBaseContext { |
| 51 | public: |
commit-bot@chromium.org | e901b6d | 2014-05-01 19:31:31 +0000 | [diff] [blame] | 52 | TwoPointConicalGradientContext(const SkTwoPointConicalGradient&, const ContextRec&); |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 53 | ~TwoPointConicalGradientContext() {} |
| 54 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 55 | void shadeSpan(int x, int y, SkPMColor dstC[], int count) override; |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 56 | |
| 57 | private: |
| 58 | typedef SkGradientShaderBase::GradientShaderBaseContext INHERITED; |
| 59 | }; |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 60 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 61 | SkShader::GradientType asAGradient(GradientInfo* info) const override; |
rmistry | a511e6a | 2015-08-28 17:16:50 -0700 | [diff] [blame^] | 62 | bool asFragmentProcessor(GrContext*, const SkPaint&, const SkMatrix&, const SkMatrix*, |
| 63 | GrColor*, GrProcessorDataManager*, |
| 64 | GrFragmentProcessor**) const override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 65 | bool isOpaque() const override; |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 66 | |
rileya@google.com | 1c6d64b | 2012-07-27 15:49:05 +0000 | [diff] [blame] | 67 | SkScalar getCenterX1() const { return SkPoint::Distance(fCenter1, fCenter2); } |
| 68 | SkScalar getStartRadius() const { return fRadius1; } |
| 69 | SkScalar getDiffRadius() const { return fRadius2 - fRadius1; } |
commit-bot@chromium.org | 2af1a2d | 2014-04-04 13:50:50 +0000 | [diff] [blame] | 70 | const SkPoint& getStartCenter() const { return fCenter1; } |
| 71 | const SkPoint& getEndCenter() const { return fCenter2; } |
| 72 | SkScalar getEndRadius() const { return fRadius2; } |
commit-bot@chromium.org | 44d83c1 | 2014-04-21 13:10:25 +0000 | [diff] [blame] | 73 | bool isFlippedGrad() const { return fFlippedGrad; } |
rileya@google.com | 1c6d64b | 2012-07-27 15:49:05 +0000 | [diff] [blame] | 74 | |
commit-bot@chromium.org | 0f10f7b | 2014-03-13 18:02:17 +0000 | [diff] [blame] | 75 | SK_TO_STRING_OVERRIDE() |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 76 | SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTwoPointConicalGradient) |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 77 | |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 78 | protected: |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 79 | SkTwoPointConicalGradient(SkReadBuffer& buffer); |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 80 | void flatten(SkWriteBuffer& buffer) const override; |
| 81 | Context* onCreateContext(const ContextRec&, void* storage) const override; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 82 | |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 83 | private: |
commit-bot@chromium.org | 44d83c1 | 2014-04-21 13:10:25 +0000 | [diff] [blame] | 84 | SkPoint fCenter1; |
| 85 | SkPoint fCenter2; |
| 86 | SkScalar fRadius1; |
| 87 | SkScalar fRadius2; |
| 88 | bool fFlippedGrad; |
skia.committer@gmail.com | d3b28e8 | 2014-04-22 03:05:17 +0000 | [diff] [blame] | 89 | |
reed | 9fa60da | 2014-08-21 07:59:51 -0700 | [diff] [blame] | 90 | friend class SkGradientShader; |
commit-bot@chromium.org | 53783b0 | 2014-04-17 21:09:49 +0000 | [diff] [blame] | 91 | typedef SkGradientShaderBase INHERITED; |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 92 | }; |
| 93 | |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 94 | #endif |