blob: 32a7b80ed8095de42108da31b455cf7d8da7ab15 [file] [log] [blame]
rileya@google.com589708b2012-07-26 20:04:23 +00001
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
9 #ifndef SkTwoPointConicalGradient_DEFINED
10 #define SkTwoPointConicalGradient_DEFINED
11
12#include "SkGradientShaderPriv.h"
13
14struct TwoPtRadial {
15 enum {
16 kDontDrawT = 0x80000000
17 };
18
19 float fCenterX, fCenterY;
20 float fDCenterX, fDCenterY;
21 float fRadius;
22 float fDRadius;
23 float fA;
24 float fRadius2;
25 float fRDR;
26
27 void init(const SkPoint& center0, SkScalar rad0,
28 const SkPoint& center1, SkScalar rad1);
rmistry@google.comfbfcd562012-08-23 18:09:54 +000029
rileya@google.com589708b2012-07-26 20:04:23 +000030 // used by setup and nextT
31 float fRelX, fRelY, fIncX, fIncY;
32 float fB, fDB;
rmistry@google.comfbfcd562012-08-23 18:09:54 +000033
rileya@google.com589708b2012-07-26 20:04:23 +000034 void setup(SkScalar fx, SkScalar fy, SkScalar dfx, SkScalar dfy);
35 SkFixed nextT();
rmistry@google.comfbfcd562012-08-23 18:09:54 +000036
rileya@google.com589708b2012-07-26 20:04:23 +000037 static bool DontDrawT(SkFixed t) {
38 return kDontDrawT == (uint32_t)t;
39 }
40};
41
42
43class SkTwoPointConicalGradient : public SkGradientShaderBase {
44 TwoPtRadial fRec;
45 void init();
46
47public:
48 SkTwoPointConicalGradient(const SkPoint& start, SkScalar startRadius,
49 const SkPoint& end, SkScalar endRadius,
50 const SkColor colors[], const SkScalar pos[],
51 int colorCount, SkShader::TileMode mode,
52 SkUnitMapper* mapper);
rmistry@google.comfbfcd562012-08-23 18:09:54 +000053
rileya@google.com589708b2012-07-26 20:04:23 +000054 virtual void shadeSpan(int x, int y, SkPMColor* dstCParam,
55 int count) SK_OVERRIDE;
56 virtual bool setContext(const SkBitmap& device,
57 const SkPaint& paint,
58 const SkMatrix& matrix) SK_OVERRIDE;
59
60 virtual BitmapType asABitmap(SkBitmap* bitmap,
61 SkMatrix* matrix,
62 TileMode* xy) const;
63 virtual SkShader::GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
bsalomon@google.com0ac6af42013-01-16 15:16:18 +000064 virtual GrEffectRef* asNewEffect(GrContext* context, const SkPaint& paint) const SK_OVERRIDE;
rileya@google.com589708b2012-07-26 20:04:23 +000065
rileya@google.com1c6d64b2012-07-27 15:49:05 +000066 SkScalar getCenterX1() const { return SkPoint::Distance(fCenter1, fCenter2); }
67 SkScalar getStartRadius() const { return fRadius1; }
68 SkScalar getDiffRadius() const { return fRadius2 - fRadius1; }
69
robertphillips@google.com76f9e932013-01-15 20:17:47 +000070 SK_DEVELOPER_TO_STRING()
rileya@google.com589708b2012-07-26 20:04:23 +000071 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTwoPointConicalGradient)
rmistry@google.comfbfcd562012-08-23 18:09:54 +000072
rileya@google.com589708b2012-07-26 20:04:23 +000073protected:
74 SkTwoPointConicalGradient(SkFlattenableReadBuffer& buffer);
75 virtual void flatten(SkFlattenableWriteBuffer& buffer) const SK_OVERRIDE;
rmistry@google.comfbfcd562012-08-23 18:09:54 +000076
rileya@google.com589708b2012-07-26 20:04:23 +000077private:
78 typedef SkGradientShaderBase INHERITED;
79 const SkPoint fCenter1;
80 const SkPoint fCenter2;
81 const SkScalar fRadius1;
82 const SkScalar fRadius2;
83};
84
rileya@google.com589708b2012-07-26 20:04:23 +000085#endif
86