blob: 7801945d0c0d1f0e147062540f8ae075c7487e50 [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
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +000014// TODO(dominikg): Worth making it truly immutable (i.e. set values in constructor)?
15// Should only be initialized once via init(). Immutable afterwards.
rileya@google.com589708b2012-07-26 20:04:23 +000016struct TwoPtRadial {
17 enum {
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;
commit-bot@chromium.org44d83c12014-04-21 13:10:25 +000028 bool fFlipped;
rileya@google.com589708b2012-07-26 20:04:23 +000029
30 void init(const SkPoint& center0, SkScalar rad0,
commit-bot@chromium.org44d83c12014-04-21 13:10:25 +000031 const SkPoint& center1, SkScalar rad1,
32 bool flipped);
rmistry@google.comfbfcd562012-08-23 18:09:54 +000033
rileya@google.com589708b2012-07-26 20:04:23 +000034 static bool DontDrawT(SkFixed t) {
35 return kDontDrawT == (uint32_t)t;
36 }
37};
38
39
40class SkTwoPointConicalGradient : public SkGradientShaderBase {
41 TwoPtRadial fRec;
rileya@google.com589708b2012-07-26 20:04:23 +000042public:
43 SkTwoPointConicalGradient(const SkPoint& start, SkScalar startRadius,
44 const SkPoint& end, SkScalar endRadius,
reedaddf2ed2014-08-11 08:28:24 -070045 bool flippedGrad, const Descriptor&);
rmistry@google.comfbfcd562012-08-23 18:09:54 +000046
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +000047
mtklein36352bf2015-03-25 18:17:31 -070048 size_t contextSize() const override;
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +000049
50 class TwoPointConicalGradientContext : public SkGradientShaderBase::GradientShaderBaseContext {
51 public:
commit-bot@chromium.orge901b6d2014-05-01 19:31:31 +000052 TwoPointConicalGradientContext(const SkTwoPointConicalGradient&, const ContextRec&);
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +000053 ~TwoPointConicalGradientContext() {}
54
mtklein36352bf2015-03-25 18:17:31 -070055 void shadeSpan(int x, int y, SkPMColor dstC[], int count) override;
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +000056
57 private:
58 typedef SkGradientShaderBase::GradientShaderBaseContext INHERITED;
59 };
rileya@google.com589708b2012-07-26 20:04:23 +000060
mtklein36352bf2015-03-25 18:17:31 -070061 SkShader::GradientType asAGradient(GradientInfo* info) const override;
bsalomonc21b09e2015-08-28 18:46:56 -070062#if SK_SUPPORT_GPU
63 const GrFragmentProcessor* asFragmentProcessor(GrContext*,
64 const SkMatrix&,
65 const SkMatrix*,
66 SkFilterQuality,
67 GrProcessorDataManager*) const override;
68#endif
mtklein36352bf2015-03-25 18:17:31 -070069 bool isOpaque() const override;
rileya@google.com589708b2012-07-26 20:04:23 +000070
rileya@google.com1c6d64b2012-07-27 15:49:05 +000071 SkScalar getCenterX1() const { return SkPoint::Distance(fCenter1, fCenter2); }
72 SkScalar getStartRadius() const { return fRadius1; }
73 SkScalar getDiffRadius() const { return fRadius2 - fRadius1; }
commit-bot@chromium.org2af1a2d2014-04-04 13:50:50 +000074 const SkPoint& getStartCenter() const { return fCenter1; }
75 const SkPoint& getEndCenter() const { return fCenter2; }
76 SkScalar getEndRadius() const { return fRadius2; }
commit-bot@chromium.org44d83c12014-04-21 13:10:25 +000077 bool isFlippedGrad() const { return fFlippedGrad; }
rileya@google.com1c6d64b2012-07-27 15:49:05 +000078
commit-bot@chromium.org0f10f7b2014-03-13 18:02:17 +000079 SK_TO_STRING_OVERRIDE()
rileya@google.com589708b2012-07-26 20:04:23 +000080 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTwoPointConicalGradient)
rmistry@google.comfbfcd562012-08-23 18:09:54 +000081
rileya@google.com589708b2012-07-26 20:04:23 +000082protected:
commit-bot@chromium.org8b0e8ac2014-01-30 18:58:24 +000083 SkTwoPointConicalGradient(SkReadBuffer& buffer);
mtklein36352bf2015-03-25 18:17:31 -070084 void flatten(SkWriteBuffer& buffer) const override;
85 Context* onCreateContext(const ContextRec&, void* storage) const override;
rmistry@google.comfbfcd562012-08-23 18:09:54 +000086
rileya@google.com589708b2012-07-26 20:04:23 +000087private:
commit-bot@chromium.org44d83c12014-04-21 13:10:25 +000088 SkPoint fCenter1;
89 SkPoint fCenter2;
90 SkScalar fRadius1;
91 SkScalar fRadius2;
92 bool fFlippedGrad;
skia.committer@gmail.comd3b28e82014-04-22 03:05:17 +000093
reed9fa60da2014-08-21 07:59:51 -070094 friend class SkGradientShader;
commit-bot@chromium.org53783b02014-04-17 21:09:49 +000095 typedef SkGradientShaderBase INHERITED;
rileya@google.com589708b2012-07-26 20:04:23 +000096};
97
rileya@google.com589708b2012-07-26 20:04:23 +000098#endif