1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
/*
* Copyright 2012 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkLinearGradient_DEFINED
#define SkLinearGradient_DEFINED
#include "SkGradientShaderPriv.h"
#include "SkNx.h"
struct Sk4fStorage {
float fArray[4];
operator Sk4f() const {
return Sk4f::Load(fArray);
}
Sk4fStorage& operator=(const Sk4f& src) {
src.store(fArray);
return *this;
}
};
class SkLinearGradient : public SkGradientShaderBase {
public:
enum {
// Temp flag for testing the 4f impl.
kForce4fContext_PrivateFlag = 1 << 7,
};
SkLinearGradient(const SkPoint pts[2], const Descriptor&);
size_t contextSize(const ContextRec&) const override;
class LinearGradientContext : public SkGradientShaderBase::GradientShaderBaseContext {
public:
LinearGradientContext(const SkLinearGradient&, const ContextRec&);
void shadeSpan(int x, int y, SkPMColor dstC[], int count) override;
struct Rec {
Sk4fStorage fColor;
float fPos;
float fPosScale;
};
private:
SkTDArray<Rec> fRecs;
bool fApplyAlphaAfterInterp;
void shade4_clamp(int x, int y, SkPMColor dstC[], int count);
template <bool, bool> void shade4_dx_clamp(SkPMColor dstC[], int count, float fx, float dx,
float invDx, const float dither[2]);
typedef SkGradientShaderBase::GradientShaderBaseContext INHERITED;
};
GradientType asAGradient(GradientInfo* info) const override;
#if SK_SUPPORT_GPU
const GrFragmentProcessor* asFragmentProcessor(GrContext*,
const SkMatrix& viewM,
const SkMatrix*,
SkFilterQuality) const override;
#endif
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLinearGradient)
protected:
SkLinearGradient(SkReadBuffer& buffer);
void flatten(SkWriteBuffer& buffer) const override;
Context* onCreateContext(const ContextRec&, void* storage) const override;
private:
class LinearGradient4fContext;
friend class SkGradientShader;
typedef SkGradientShaderBase INHERITED;
const SkPoint fStart;
const SkPoint fEnd;
};
#endif
|