OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #ifndef SkTwoPointConicalGradient_DEFINED | 9 #ifndef SkTwoPointConicalGradient_DEFINED |
10 #define SkTwoPointConicalGradient_DEFINED | 10 #define SkTwoPointConicalGradient_DEFINED |
11 | 11 |
12 #include "SkGradientShaderPriv.h" | 12 #include "SkGradientShaderPriv.h" |
13 | 13 |
14 // TODO(dominikg): Worth making it truly immutable (i.e. set values in construct
or)? | |
15 // Should only be initialized once via init(). Immutable afterwards. | |
16 struct TwoPtRadial { | 14 struct TwoPtRadial { |
17 enum { | 15 enum { |
18 kDontDrawT = 0x80000000 | 16 kDontDrawT = 0x80000000 |
19 }; | 17 }; |
20 | 18 |
21 float fCenterX, fCenterY; | 19 float fCenterX, fCenterY; |
22 float fDCenterX, fDCenterY; | 20 float fDCenterX, fDCenterY; |
23 float fRadius; | 21 float fRadius; |
24 float fDRadius; | 22 float fDRadius; |
25 float fA; | 23 float fA; |
26 float fRadius2; | 24 float fRadius2; |
27 float fRDR; | 25 float fRDR; |
28 | 26 |
29 void init(const SkPoint& center0, SkScalar rad0, | 27 void init(const SkPoint& center0, SkScalar rad0, |
30 const SkPoint& center1, SkScalar rad1); | 28 const SkPoint& center1, SkScalar rad1); |
31 | 29 |
| 30 // used by setup and nextT |
| 31 float fRelX, fRelY, fIncX, fIncY; |
| 32 float fB, fDB; |
| 33 |
| 34 void setup(SkScalar fx, SkScalar fy, SkScalar dfx, SkScalar dfy); |
| 35 SkFixed nextT(); |
| 36 |
32 static bool DontDrawT(SkFixed t) { | 37 static bool DontDrawT(SkFixed t) { |
33 return kDontDrawT == (uint32_t)t; | 38 return kDontDrawT == (uint32_t)t; |
34 } | 39 } |
35 }; | 40 }; |
36 | 41 |
37 | 42 |
38 class SkTwoPointConicalGradient : public SkGradientShaderBase { | 43 class SkTwoPointConicalGradient : public SkGradientShaderBase { |
39 TwoPtRadial fRec; | 44 TwoPtRadial fRec; |
40 void init(); | 45 void init(); |
41 | 46 |
42 public: | 47 public: |
43 SkTwoPointConicalGradient(const SkPoint& start, SkScalar startRadius, | 48 SkTwoPointConicalGradient(const SkPoint& start, SkScalar startRadius, |
44 const SkPoint& end, SkScalar endRadius, | 49 const SkPoint& end, SkScalar endRadius, |
45 const Descriptor&); | 50 const Descriptor&); |
46 | 51 |
47 | 52 virtual void shadeSpan(int x, int y, SkPMColor* dstCParam, |
48 virtual SkShader::Context* createContext(const SkBitmap&, const SkPaint&, co
nst SkMatrix&, | 53 int count) SK_OVERRIDE; |
49 void* storage) const SK_OVERRIDE; | 54 virtual bool setContext(const SkBitmap& device, |
50 virtual size_t contextSize() const SK_OVERRIDE; | 55 const SkPaint& paint, |
51 | 56 const SkMatrix& matrix) SK_OVERRIDE; |
52 class TwoPointConicalGradientContext : public SkGradientShaderBase::Gradient
ShaderBaseContext { | |
53 public: | |
54 TwoPointConicalGradientContext(const SkTwoPointConicalGradient& shader, | |
55 const SkBitmap& device, | |
56 const SkPaint& paint, | |
57 const SkMatrix& matrix); | |
58 ~TwoPointConicalGradientContext() {} | |
59 | |
60 virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count) SK_OVE
RRIDE; | |
61 | |
62 private: | |
63 typedef SkGradientShaderBase::GradientShaderBaseContext INHERITED; | |
64 }; | |
65 | 57 |
66 virtual BitmapType asABitmap(SkBitmap* bitmap, | 58 virtual BitmapType asABitmap(SkBitmap* bitmap, |
67 SkMatrix* matrix, | 59 SkMatrix* matrix, |
68 TileMode* xy) const; | 60 TileMode* xy) const; |
69 virtual SkShader::GradientType asAGradient(GradientInfo* info) const SK_OVE
RRIDE; | 61 virtual SkShader::GradientType asAGradient(GradientInfo* info) const SK_OVE
RRIDE; |
70 virtual GrEffectRef* asNewEffect(GrContext* context, const SkPaint& paint) c
onst SK_OVERRIDE; | 62 virtual GrEffectRef* asNewEffect(GrContext* context, const SkPaint& paint) c
onst SK_OVERRIDE; |
71 virtual bool isOpaque() const SK_OVERRIDE; | 63 virtual bool isOpaque() const SK_OVERRIDE; |
72 | 64 |
73 SkScalar getCenterX1() const { return SkPoint::Distance(fCenter1, fCenter2);
} | 65 SkScalar getCenterX1() const { return SkPoint::Distance(fCenter1, fCenter2);
} |
74 SkScalar getStartRadius() const { return fRadius1; } | 66 SkScalar getStartRadius() const { return fRadius1; } |
75 SkScalar getDiffRadius() const { return fRadius2 - fRadius1; } | 67 SkScalar getDiffRadius() const { return fRadius2 - fRadius1; } |
76 const SkPoint& getStartCenter() const { return fCenter1; } | 68 const SkPoint& getStartCenter() const { return fCenter1; } |
77 const SkPoint& getEndCenter() const { return fCenter2; } | 69 const SkPoint& getEndCenter() const { return fCenter2; } |
78 SkScalar getEndRadius() const { return fRadius2; } | 70 SkScalar getEndRadius() const { return fRadius2; } |
79 | 71 |
80 SK_TO_STRING_OVERRIDE() | 72 SK_TO_STRING_OVERRIDE() |
81 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTwoPointConicalGradien
t) | 73 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTwoPointConicalGradien
t) |
82 | 74 |
83 protected: | 75 protected: |
84 SkTwoPointConicalGradient(SkReadBuffer& buffer); | 76 SkTwoPointConicalGradient(SkReadBuffer& buffer); |
85 virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE; | 77 virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE; |
86 | 78 |
87 private: | 79 private: |
| 80 typedef SkGradientShaderBase INHERITED; |
88 const SkPoint fCenter1; | 81 const SkPoint fCenter1; |
89 const SkPoint fCenter2; | 82 const SkPoint fCenter2; |
90 const SkScalar fRadius1; | 83 const SkScalar fRadius1; |
91 const SkScalar fRadius2; | 84 const SkScalar fRadius2; |
92 | |
93 typedef SkGradientShaderBase INHERITED; | |
94 }; | 85 }; |
95 | 86 |
96 #endif | 87 #endif |
OLD | NEW |