3 * Copyright 2012 Google Inc.
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
9 #ifndef SkTwoPointRadialGradient_DEFINED
10 #define SkTwoPointRadialGradient_DEFINED
12 #include "SkGradientShaderPriv.h"
14 class SkTwoPointRadialGradient : public SkGradientShaderBase {
16 SkTwoPointRadialGradient(const SkPoint& start, SkScalar startRadius,
17 const SkPoint& end, SkScalar endRadius,
20 virtual BitmapType asABitmap(SkBitmap* bitmap,
22 TileMode* xy) const SK_OVERRIDE;
23 GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
24 virtual bool asFragmentProcessor(GrContext* context, const SkPaint&, const SkMatrix& viewM,
25 const SkMatrix*, GrColor*,
26 GrFragmentProcessor**) const SK_OVERRIDE;
28 size_t contextSize() const SK_OVERRIDE;
30 class TwoPointRadialGradientContext : public SkGradientShaderBase::GradientShaderBaseContext {
32 TwoPointRadialGradientContext(const SkTwoPointRadialGradient&, const ContextRec&);
34 void shadeSpan(int x, int y, SkPMColor dstC[], int count) SK_OVERRIDE;
37 typedef SkGradientShaderBase::GradientShaderBaseContext INHERITED;
40 SkScalar getCenterX1() const { return fDiff.length(); }
41 SkScalar getStartRadius() const { return fStartRadius; }
42 SkScalar getDiffRadius() const { return fDiffRadius; }
44 SK_TO_STRING_OVERRIDE()
45 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTwoPointRadialGradient)
48 SkTwoPointRadialGradient(SkReadBuffer& buffer);
49 void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE;
50 Context* onCreateContext(const ContextRec&, void* storage) const SK_OVERRIDE;
53 const SkPoint fCenter1;
54 const SkPoint fCenter2;
55 const SkScalar fRadius1;
56 const SkScalar fRadius2;
58 SkScalar fStartRadius, fDiffRadius, fSr2D2, fA, fOneOverTwoA;
60 friend class SkGradientShader;
61 typedef SkGradientShaderBase INHERITED;