blob: 041f8b8be44cd74e9c75c3da046e44a419689e7a [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
commit-bot@chromium.orgaa64fbf2014-04-03 14:59:19 +00009#ifndef SkTwoPointConicalGradient_DEFINED
10#define SkTwoPointConicalGradient_DEFINED
rileya@google.com589708b2012-07-26 20:04:23 +000011
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,
commit-bot@chromium.org7518ff22014-04-17 13:57:31 +000028 const SkPoint& center1, SkScalar rad1);
rmistry@google.comfbfcd562012-08-23 18:09:54 +000029
commit-bot@chromium.org53783b02014-04-17 21:09:49 +000030 // 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
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,
commit-bot@chromium.org7518ff22014-04-17 13:57:31 +000050 const Descriptor&);
rmistry@google.comfbfcd562012-08-23 18:09:54 +000051
commit-bot@chromium.org53783b02014-04-17 21:09:49 +000052 virtual void shadeSpan(int x, int y, SkPMColor* dstCParam,
53 int count) SK_OVERRIDE;
54 virtual bool setContext(const SkBitmap& device,
55 const SkPaint& paint,
56 const SkMatrix& matrix) SK_OVERRIDE;
rileya@google.com589708b2012-07-26 20:04:23 +000057
58 virtual BitmapType asABitmap(SkBitmap* bitmap,
59 SkMatrix* matrix,
60 TileMode* xy) const;
61 virtual SkShader::GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
bsalomon@google.com0ac6af42013-01-16 15:16:18 +000062 virtual GrEffectRef* asNewEffect(GrContext* context, const SkPaint& paint) const SK_OVERRIDE;
commit-bot@chromium.org3fbab822013-03-20 00:49:57 +000063 virtual bool isOpaque() const SK_OVERRIDE;
rileya@google.com589708b2012-07-26 20:04:23 +000064
rileya@google.com1c6d64b2012-07-27 15:49:05 +000065 SkScalar getCenterX1() const { return SkPoint::Distance(fCenter1, fCenter2); }
66 SkScalar getStartRadius() const { return fRadius1; }
67 SkScalar getDiffRadius() const { return fRadius2 - fRadius1; }
commit-bot@chromium.org2af1a2d2014-04-04 13:50:50 +000068 const SkPoint& getStartCenter() const { return fCenter1; }
69 const SkPoint& getEndCenter() const { return fCenter2; }
70 SkScalar getEndRadius() const { return fRadius2; }
rileya@google.com1c6d64b2012-07-27 15:49:05 +000071
commit-bot@chromium.org0f10f7b2014-03-13 18:02:17 +000072 SK_TO_STRING_OVERRIDE()
rileya@google.com589708b2012-07-26 20:04:23 +000073 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTwoPointConicalGradient)
rmistry@google.comfbfcd562012-08-23 18:09:54 +000074
rileya@google.com589708b2012-07-26 20:04:23 +000075protected:
commit-bot@chromium.org8b0e8ac2014-01-30 18:58:24 +000076 SkTwoPointConicalGradient(SkReadBuffer& buffer);
77 virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE;
rmistry@google.comfbfcd562012-08-23 18:09:54 +000078
rileya@google.com589708b2012-07-26 20:04:23 +000079private:
commit-bot@chromium.org53783b02014-04-17 21:09:49 +000080 typedef SkGradientShaderBase INHERITED;
commit-bot@chromium.org7518ff22014-04-17 13:57:31 +000081 const SkPoint fCenter1;
82 const SkPoint fCenter2;
83 const SkScalar fRadius1;
84 const SkScalar fRadius2;
rileya@google.com589708b2012-07-26 20:04:23 +000085};
86
rileya@google.com589708b2012-07-26 20:04:23 +000087#endif