blob: 7a85b88cb79de1bf8cbbcd22c84effbe92e1a273 [file] [log] [blame]
rileya@google.com589708b2012-07-26 20:04:23 +00001/*
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"
reedf3182eb2015-11-17 08:12:19 -080012#include "SkNx.h"
13
14struct Sk4fStorage {
15 float fArray[4];
16
17 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};
rileya@google.com589708b2012-07-26 20:04:23 +000026
27class SkLinearGradient : public SkGradientShaderBase {
28public:
fmalitabc590c02016-02-22 09:12:33 -080029 enum {
30 // Temp flag for testing the 4f impl.
31 kForce4fContext_PrivateFlag = 1 << 7,
32 };
33
reedaddf2ed2014-08-11 08:28:24 -070034 SkLinearGradient(const SkPoint pts[2], const Descriptor&);
rileya@google.com589708b2012-07-26 20:04:23 +000035
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +000036 class LinearGradientContext : public SkGradientShaderBase::GradientShaderBaseContext {
37 public:
commit-bot@chromium.orge901b6d2014-05-01 19:31:31 +000038 LinearGradientContext(const SkLinearGradient&, const ContextRec&);
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +000039
mtklein36352bf2015-03-25 18:17:31 -070040 void shadeSpan(int x, int y, SkPMColor dstC[], int count) override;
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +000041
reedf3182eb2015-11-17 08:12:19 -080042 struct Rec {
43 Sk4fStorage fColor;
44 float fPos;
45 float fPosScale;
46 };
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +000047 private:
reedf3182eb2015-11-17 08:12:19 -080048 SkTDArray<Rec> fRecs;
49 bool fApplyAlphaAfterInterp;
50
51 void shade4_clamp(int x, int y, SkPMColor dstC[], int count);
52 template <bool, bool> void shade4_dx_clamp(SkPMColor dstC[], int count, float fx, float dx,
53 float invDx, const float dither[2]);
54
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +000055 typedef SkGradientShaderBase::GradientShaderBaseContext INHERITED;
56 };
57
mtklein36352bf2015-03-25 18:17:31 -070058 GradientType asAGradient(GradientInfo* info) const override;
bsalomonc21b09e2015-08-28 18:46:56 -070059#if SK_SUPPORT_GPU
brianosman839345d2016-07-22 11:04:53 -070060 sk_sp<GrFragmentProcessor> asFragmentProcessor(const AsFPArgs&) const override;
bsalomonc21b09e2015-08-28 18:46:56 -070061#endif
rileya@google.com589708b2012-07-26 20:04:23 +000062
commit-bot@chromium.org0f10f7b2014-03-13 18:02:17 +000063 SK_TO_STRING_OVERRIDE()
rileya@google.com589708b2012-07-26 20:04:23 +000064 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLinearGradient)
65
66protected:
commit-bot@chromium.org8b0e8ac2014-01-30 18:58:24 +000067 SkLinearGradient(SkReadBuffer& buffer);
mtklein36352bf2015-03-25 18:17:31 -070068 void flatten(SkWriteBuffer& buffer) const override;
reed773ceda2016-03-03 18:18:25 -080069 size_t onContextSize(const ContextRec&) const override;
mtklein36352bf2015-03-25 18:17:31 -070070 Context* onCreateContext(const ContextRec&, void* storage) const override;
rileya@google.com589708b2012-07-26 20:04:23 +000071
72private:
fmalitabc590c02016-02-22 09:12:33 -080073 class LinearGradient4fContext;
74
reed9fa60da2014-08-21 07:59:51 -070075 friend class SkGradientShader;
rileya@google.com589708b2012-07-26 20:04:23 +000076 typedef SkGradientShaderBase INHERITED;
77 const SkPoint fStart;
78 const SkPoint fEnd;
79};
80
rileya@google.com589708b2012-07-26 20:04:23 +000081#endif