• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2012 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SkTwoPointConicalGradient_DEFINED
9 #define SkTwoPointConicalGradient_DEFINED
10 
11 #include "SkGradientShaderPriv.h"
12 
13 // TODO(dominikg): Worth making it truly immutable (i.e. set values in constructor)?
14 // Should only be initialized once via init(). Immutable afterwards.
15 struct TwoPtRadial {
16     enum {
17         // This value is outside the range SK_FixedMin to SK_FixedMax.
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;
28     bool    fFlipped;
29 
30     void init(const SkPoint& center0, SkScalar rad0,
31               const SkPoint& center1, SkScalar rad1,
32               bool flipped);
33 
DontDrawTTwoPtRadial34     static bool DontDrawT(SkFixed t) {
35         return kDontDrawT == (uint32_t)t;
36     }
37 };
38 
39 
40 class SkTwoPointConicalGradient : public SkGradientShaderBase {
41     TwoPtRadial fRec;
42 public:
43     SkTwoPointConicalGradient(const SkPoint& start, SkScalar startRadius,
44                               const SkPoint& end, SkScalar endRadius,
45                               bool flippedGrad, const Descriptor&);
46 
47     class TwoPointConicalGradientContext : public SkGradientShaderBase::GradientShaderBaseContext {
48     public:
49         TwoPointConicalGradientContext(const SkTwoPointConicalGradient&, const ContextRec&);
~TwoPointConicalGradientContext()50         ~TwoPointConicalGradientContext() override {}
51 
52         void shadeSpan(int x, int y, SkPMColor dstC[], int count) override;
53 
54     private:
55         typedef SkGradientShaderBase::GradientShaderBaseContext INHERITED;
56     };
57 
58     SkShader::GradientType asAGradient(GradientInfo* info) const  override;
59 #if SK_SUPPORT_GPU
60     sk_sp<GrFragmentProcessor> asFragmentProcessor(const AsFPArgs&) const override;
61 #endif
62     bool isOpaque() const override;
63 
getCenterX1()64     SkScalar getCenterX1() const { return SkPoint::Distance(fCenter1, fCenter2); }
getStartRadius()65     SkScalar getStartRadius() const { return fRadius1; }
getDiffRadius()66     SkScalar getDiffRadius() const { return fRadius2 - fRadius1; }
getStartCenter()67     const SkPoint& getStartCenter() const { return fCenter1; }
getEndCenter()68     const SkPoint& getEndCenter() const { return fCenter2; }
getEndRadius()69     SkScalar getEndRadius() const { return fRadius2; }
isFlippedGrad()70     bool isFlippedGrad() const { return fFlippedGrad; }
71 
72     SK_TO_STRING_OVERRIDE()
73     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTwoPointConicalGradient)
74 
75 protected:
76     SkTwoPointConicalGradient(SkReadBuffer& buffer);
77     void flatten(SkWriteBuffer& buffer) const override;
78     Context* onMakeContext(const ContextRec&, SkArenaAlloc*) const override;
79 
80 private:
81     SkPoint fCenter1;
82     SkPoint fCenter2;
83     SkScalar fRadius1;
84     SkScalar fRadius2;
85     bool fFlippedGrad;
86 
87     friend class SkGradientShader;
88     typedef SkGradientShaderBase INHERITED;
89 };
90 
91 #endif
92