blob: ddd0b2bc466dc2bce365a54f335f2ec1fb22dea8 [file] [log] [blame]
fmalitabc590c02016-02-22 09:12:33 -08001/*
2 * Copyright 2016 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 Sk4fGradientBase_DEFINED
9#define Sk4fGradientBase_DEFINED
10
fmalitaa928b282016-03-18 10:28:23 -070011#include "Sk4fGradientPriv.h"
fmalitabc590c02016-02-22 09:12:33 -080012#include "SkColor.h"
13#include "SkGradientShaderPriv.h"
14#include "SkMatrix.h"
15#include "SkNx.h"
16#include "SkPM4f.h"
17#include "SkShader.h"
18#include "SkTArray.h"
19
20class SkGradientShaderBase::
21GradientShaderBase4fContext : public SkShader::Context {
22public:
23 GradientShaderBase4fContext(const SkGradientShaderBase&,
24 const ContextRec&);
25
26 uint32_t getFlags() const override { return fFlags; }
27
fmalita7e6fcf82016-03-10 11:18:43 -080028 void shadeSpan(int x, int y, SkPMColor dst[], int count) override;
29 void shadeSpan4f(int x, int y, SkPM4f dst[], int count) override;
30
fmalitabc590c02016-02-22 09:12:33 -080031protected:
32 struct Interval {
33 Interval(SkPMColor c0, SkScalar p0,
34 SkPMColor c1, SkScalar p1,
35 const Sk4f& componentScale);
fmalitabc590c02016-02-22 09:12:33 -080036
37 bool isZeroRamp() const { return fZeroRamp; }
38
fmalitabc590c02016-02-22 09:12:33 -080039 SkPM4f fC0, fDc;
40 SkScalar fP0, fP1;
41 bool fZeroRamp;
42 };
43
fmalita7e6fcf82016-03-10 11:18:43 -080044 virtual void mapTs(int x, int y, SkScalar ts[], int count) const = 0;
45
46 void buildIntervals(const SkGradientShaderBase&, const ContextRec&, bool reverse);
47
fmalitabc590c02016-02-22 09:12:33 -080048 SkSTArray<8, Interval, true> fIntervals;
49 SkMatrix fDstToPos;
50 SkMatrix::MapXYProc fDstToPosProc;
51 uint8_t fDstToPosClass;
52 uint8_t fFlags;
53 bool fDither;
54 bool fColorsArePremul;
55
56private:
57 using INHERITED = SkShader::Context;
fmalita7e6fcf82016-03-10 11:18:43 -080058
59 void addMirrorIntervals(const SkGradientShaderBase&,
60 const Sk4f& componentScale, bool reverse);
61
fmalitadc6c9bf2016-03-21 13:16:51 -070062 template<DstType, SkShader::TileMode tileMode>
fmalita7e6fcf82016-03-10 11:18:43 -080063 class TSampler;
64
fmalitadc6c9bf2016-03-21 13:16:51 -070065 template <DstType dstType, ApplyPremul premul>
66 void shadePremulSpan(int x, int y, typename DstTraits<dstType, premul>::Type[],
67 int count) const;
fmalita7e6fcf82016-03-10 11:18:43 -080068
fmalitadc6c9bf2016-03-21 13:16:51 -070069 template <DstType dstType, ApplyPremul premul, SkShader::TileMode tileMode>
70 void shadeSpanInternal(int x, int y, typename DstTraits<dstType, premul>::Type[],
71 int count) const;
fmalitabc590c02016-02-22 09:12:33 -080072};
73
74#endif // Sk4fGradientBase_DEFINED