1 /* 2 * Copyright 2012 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef SkTwoPointConicalGradient_DEFINED 9 #define SkTwoPointConicalGradient_DEFINED 10 11 #include "SkColorSpaceXformer.h" 12 #include "SkGradientShaderPriv.h" 13 14 class SkTwoPointConicalGradient final : public SkGradientShaderBase { 15 public: 16 SkTwoPointConicalGradient(const SkPoint& start, SkScalar startRadius, 17 const SkPoint& end, SkScalar endRadius, 18 bool flippedGrad, const Descriptor&); 19 20 SkShader::GradientType asAGradient(GradientInfo* info) const override; 21 #if SK_SUPPORT_GPU 22 sk_sp<GrFragmentProcessor> asFragmentProcessor(const AsFPArgs&) const override; 23 #endif 24 bool isOpaque() const override; 25 getCenterX1()26 SkScalar getCenterX1() const { return SkPoint::Distance(fCenter1, fCenter2); } getStartRadius()27 SkScalar getStartRadius() const { return fRadius1; } getDiffRadius()28 SkScalar getDiffRadius() const { return fRadius2 - fRadius1; } getStartCenter()29 const SkPoint& getStartCenter() const { return fCenter1; } getEndCenter()30 const SkPoint& getEndCenter() const { return fCenter2; } getEndRadius()31 SkScalar getEndRadius() const { return fRadius2; } isFlippedGrad()32 bool isFlippedGrad() const { return fFlippedGrad; } 33 34 SK_TO_STRING_OVERRIDE() 35 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTwoPointConicalGradient) 36 37 protected: 38 SkTwoPointConicalGradient(SkReadBuffer& buffer); 39 void flatten(SkWriteBuffer& buffer) const override; 40 sk_sp<SkShader> onMakeColorSpace(SkColorSpaceXformer* xformer) const override; 41 42 bool adjustMatrixAndAppendStages(SkArenaAlloc* alloc, 43 SkMatrix* matrix, 44 SkRasterPipeline* tPipeline, 45 SkRasterPipeline* postPipeline) const override; 46 onIsRasterPipelineOnly()47 bool onIsRasterPipelineOnly() const override { return true; } 48 49 private: 50 SkPoint fCenter1; 51 SkPoint fCenter2; 52 SkScalar fRadius1; 53 SkScalar fRadius2; 54 bool fFlippedGrad; 55 56 friend class SkGradientShader; 57 typedef SkGradientShaderBase INHERITED; 58 }; 59 60 #endif 61