• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 SkLinearGradient_DEFINED
9 #define SkLinearGradient_DEFINED
10 
11 #include "SkGradientShaderPriv.h"
12 #include "SkNx.h"
13 
14 struct Sk4fStorage {
15     float fArray[4];
16 
Sk4fSk4fStorage17     operator Sk4f() const {
18         return Sk4f::Load(fArray);
19     }
20 
21     Sk4fStorage& operator=(const Sk4f& src) {
22         src.store(fArray);
23         return *this;
24     }
25 };
26 
27 class SkLinearGradient : public SkGradientShaderBase {
28 public:
29     SkLinearGradient(const SkPoint pts[2], const Descriptor&);
30 
31     class LinearGradientContext : public SkGradientShaderBase::GradientShaderBaseContext {
32     public:
33         LinearGradientContext(const SkLinearGradient&, const ContextRec&);
34 
35         void shadeSpan(int x, int y, SkPMColor dstC[], int count) override;
36 
37         struct Rec {
38             Sk4fStorage fColor;
39             float       fPos;
40             float       fPosScale;
41         };
42     private:
43         SkTDArray<Rec>  fRecs;
44         bool            fApplyAlphaAfterInterp;
45 
46         void shade4_clamp(int x, int y, SkPMColor dstC[], int count);
47         template <bool, bool> void shade4_dx_clamp(SkPMColor dstC[], int count, float fx, float dx,
48                                                    float invDx, const float dither[2]);
49 
50         typedef SkGradientShaderBase::GradientShaderBaseContext INHERITED;
51     };
52 
53     GradientType asAGradient(GradientInfo* info) const override;
54 #if SK_SUPPORT_GPU
55     sk_sp<GrFragmentProcessor> asFragmentProcessor(const AsFPArgs&) const override;
56 #endif
57 
58     SK_TO_STRING_OVERRIDE()
59     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLinearGradient)
60 
61 protected:
62     SkLinearGradient(SkReadBuffer& buffer);
63     void flatten(SkWriteBuffer& buffer) const override;
64     Context* onMakeContext(const ContextRec&, SkArenaAlloc*) const override;
65     Context* onMakeBurstPipelineContext(const ContextRec&, SkArenaAlloc*) const override;
66 
67     bool adjustMatrixAndAppendStages(SkArenaAlloc* alloc,
68                                      SkMatrix* matrix,
69                                      SkRasterPipeline* tPipeline,
70                                      SkRasterPipeline* postPipeline) const final;
71 
72 
73     sk_sp<SkShader> onMakeColorSpace(SkColorSpaceXformer* xformer) const override;
74 
75 private:
76     class LinearGradient4fContext;
77 
78     friend class SkGradientShader;
79     typedef SkGradientShaderBase INHERITED;
80     const SkPoint fStart;
81     const SkPoint fEnd;
82 };
83 
84 #endif
85