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. |
14 struct TwoPtRadial { | 16 struct TwoPtRadial { |
15 enum { | 17 enum { |
16 kDontDrawT = 0x80000000 | 18 kDontDrawT = 0x80000000 |
17 }; | 19 }; |
18 | 20 |
19 float fCenterX, fCenterY; | 21 float fCenterX, fCenterY; |
20 float fDCenterX, fDCenterY; | 22 float fDCenterX, fDCenterY; |
21 float fRadius; | 23 float fRadius; |
22 float fDRadius; | 24 float fDRadius; |
23 float fA; | 25 float fA; |
24 float fRadius2; | 26 float fRadius2; |
25 float fRDR; | 27 float fRDR; |
26 bool fFlipped; | 28 bool fFlipped; |
27 | 29 |
28 void init(const SkPoint& center0, SkScalar rad0, | 30 void init(const SkPoint& center0, SkScalar rad0, |
29 const SkPoint& center1, SkScalar rad1, | 31 const SkPoint& center1, SkScalar rad1, |
30 bool flipped); | 32 bool flipped); |
31 | 33 |
32 // used by setup and nextT | |
33 float fRelX, fRelY, fIncX, fIncY; | |
34 float fB, fDB; | |
35 | |
36 void setup(SkScalar fx, SkScalar fy, SkScalar dfx, SkScalar dfy); | |
37 SkFixed nextT(); | |
38 | |
39 static bool DontDrawT(SkFixed t) { | 34 static bool DontDrawT(SkFixed t) { |
40 return kDontDrawT == (uint32_t)t; | 35 return kDontDrawT == (uint32_t)t; |
41 } | 36 } |
42 }; | 37 }; |
43 | 38 |
44 | 39 |
45 class SkTwoPointConicalGradient : public SkGradientShaderBase { | 40 class SkTwoPointConicalGradient : public SkGradientShaderBase { |
46 TwoPtRadial fRec; | 41 TwoPtRadial fRec; |
47 void init(); | 42 void init(); |
48 | 43 |
49 public: | 44 public: |
50 SkTwoPointConicalGradient(const SkPoint& start, SkScalar startRadius, | 45 SkTwoPointConicalGradient(const SkPoint& start, SkScalar startRadius, |
51 const SkPoint& end, SkScalar endRadius, | 46 const SkPoint& end, SkScalar endRadius, |
52 bool flippedGrad, const Descriptor&); | 47 bool flippedGrad, const Descriptor&); |
53 | 48 |
54 virtual void shadeSpan(int x, int y, SkPMColor* dstCParam, | 49 |
55 int count) SK_OVERRIDE; | 50 virtual SkShader::Context* createContext(const SkBitmap&, const SkPaint&, co
nst SkMatrix&, |
56 virtual bool setContext(const SkBitmap& device, | 51 void* storage) const SK_OVERRIDE; |
57 const SkPaint& paint, | 52 virtual size_t contextSize() const SK_OVERRIDE; |
58 const SkMatrix& matrix) SK_OVERRIDE; | 53 |
| 54 class TwoPointConicalGradientContext : public SkGradientShaderBase::Gradient
ShaderBaseContext { |
| 55 public: |
| 56 TwoPointConicalGradientContext(const SkTwoPointConicalGradient& shader, |
| 57 const SkBitmap& device, |
| 58 const SkPaint& paint, |
| 59 const SkMatrix& matrix); |
| 60 ~TwoPointConicalGradientContext() {} |
| 61 |
| 62 virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count) SK_OVE
RRIDE; |
| 63 |
| 64 private: |
| 65 typedef SkGradientShaderBase::GradientShaderBaseContext INHERITED; |
| 66 }; |
59 | 67 |
60 virtual BitmapType asABitmap(SkBitmap* bitmap, | 68 virtual BitmapType asABitmap(SkBitmap* bitmap, |
61 SkMatrix* matrix, | 69 SkMatrix* matrix, |
62 TileMode* xy) const; | 70 TileMode* xy) const; |
63 virtual SkShader::GradientType asAGradient(GradientInfo* info) const SK_OVE
RRIDE; | 71 virtual SkShader::GradientType asAGradient(GradientInfo* info) const SK_OVE
RRIDE; |
64 virtual GrEffectRef* asNewEffect(GrContext* context, const SkPaint& paint) c
onst SK_OVERRIDE; | 72 virtual GrEffectRef* asNewEffect(GrContext* context, const SkPaint& paint) c
onst SK_OVERRIDE; |
65 virtual bool isOpaque() const SK_OVERRIDE; | 73 virtual bool isOpaque() const SK_OVERRIDE; |
66 | 74 |
67 SkScalar getCenterX1() const { return SkPoint::Distance(fCenter1, fCenter2);
} | 75 SkScalar getCenterX1() const { return SkPoint::Distance(fCenter1, fCenter2);
} |
68 SkScalar getStartRadius() const { return fRadius1; } | 76 SkScalar getStartRadius() const { return fRadius1; } |
(...skipping 14 matching lines...) Expand all Loading... |
83 SkPoint fCenter1; | 91 SkPoint fCenter1; |
84 SkPoint fCenter2; | 92 SkPoint fCenter2; |
85 SkScalar fRadius1; | 93 SkScalar fRadius1; |
86 SkScalar fRadius2; | 94 SkScalar fRadius2; |
87 bool fFlippedGrad; | 95 bool fFlippedGrad; |
88 | 96 |
89 typedef SkGradientShaderBase INHERITED; | 97 typedef SkGradientShaderBase INHERITED; |
90 }; | 98 }; |
91 | 99 |
92 #endif | 100 #endif |
OLD | NEW |