blob: 7870bc3ccf3a550809ccc54c336bb673593e2274 [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
11#include "SkColor.h"
12#include "SkGradientShaderPriv.h"
13#include "SkMatrix.h"
14#include "SkNx.h"
15#include "SkPM4f.h"
16#include "SkShader.h"
17#include "SkTArray.h"
18
19class SkGradientShaderBase::
20GradientShaderBase4fContext : public SkShader::Context {
21public:
22 GradientShaderBase4fContext(const SkGradientShaderBase&,
23 const ContextRec&);
24
25 uint32_t getFlags() const override { return fFlags; }
26
27protected:
28 struct Interval {
29 Interval(SkPMColor c0, SkScalar p0,
30 SkPMColor c1, SkScalar p1,
31 const Sk4f& componentScale);
32 Interval(const Sk4f& c0, const Sk4f& dc,
33 SkScalar p0, SkScalar p1);
34
35 bool isZeroRamp() const { return fZeroRamp; }
36
37 // true when fx is in [p0,p1)
38 bool contains(SkScalar fx) const;
39
40 SkPM4f fC0, fDc;
41 SkScalar fP0, fP1;
42 bool fZeroRamp;
43 };
44
45 const Interval* findInterval(SkScalar fx) const;
46
47 SkSTArray<8, Interval, true> fIntervals;
48 SkMatrix fDstToPos;
49 SkMatrix::MapXYProc fDstToPosProc;
50 uint8_t fDstToPosClass;
51 uint8_t fFlags;
52 bool fDither;
53 bool fColorsArePremul;
54
55private:
56 using INHERITED = SkShader::Context;
57
58 mutable const Interval* fCachedInterval;
59};
60
61#endif // Sk4fGradientBase_DEFINED