blob: 8c28d601cdf5eec0afb88d516dafd65cb6786a87 [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"
Cary Clark9480d822017-10-19 18:01:13 -040014#include "SkMatrixPriv.h"
fmalitabc590c02016-02-22 09:12:33 -080015#include "SkNx.h"
Florin Malita4aed1382017-05-25 10:38:07 -040016#include "SkShaderBase.h"
fmalitabc590c02016-02-22 09:12:33 -080017#include "SkTArray.h"
18
Florin Malitada4545b2017-03-23 17:04:54 -040019struct Sk4fGradientInterval {
Florin Malitacf20f782017-04-07 14:56:14 -040020 Sk4fGradientInterval(const Sk4f& c0, SkScalar t0,
21 const Sk4f& c1, SkScalar t1);
Florin Malitada4545b2017-03-23 17:04:54 -040022
23 bool contains(SkScalar t) const {
24 // True if t is in [p0,p1]. Note: this helper assumes a
25 // natural/increasing interval - so it's not usable in Sk4fLinearGradient.
Florin Malitacf20f782017-04-07 14:56:14 -040026 SkASSERT(fT0 < fT1);
27 return t >= fT0 && t <= fT1;
Florin Malitada4545b2017-03-23 17:04:54 -040028 }
29
Florin Malitacf20f782017-04-07 14:56:14 -040030 // Color bias and color gradient, such that for a t in this interval
31 //
32 // C = fCb + t * fCg;
Brian Osman781e3502018-10-03 15:42:47 -040033 SkPMColor4f fCb, fCg;
34 SkScalar fT0, fT1;
Florin Malitada4545b2017-03-23 17:04:54 -040035};
36
37class Sk4fGradientIntervalBuffer {
38public:
Florin Malita0e36b3f2017-06-05 23:33:45 -040039 void init(const SkGradientShaderBase&, SkColorSpace* dstCS, SkShader::TileMode tileMode,
40 bool premulColors, SkScalar alpha, bool reverse);
Florin Malitada4545b2017-03-23 17:04:54 -040041
42 const Sk4fGradientInterval* find(SkScalar t) const;
43 const Sk4fGradientInterval* findNext(SkScalar t, const Sk4fGradientInterval* prev,
44 bool increasing) const;
45
46 using BufferType = SkSTArray<8, Sk4fGradientInterval, true>;
47
48 const BufferType* operator->() const { return &fIntervals; }
49
50private:
51 BufferType fIntervals;
52};
53
fmalitabc590c02016-02-22 09:12:33 -080054class SkGradientShaderBase::
Florin Malita4aed1382017-05-25 10:38:07 -040055GradientShaderBase4fContext : public Context {
fmalitabc590c02016-02-22 09:12:33 -080056public:
57 GradientShaderBase4fContext(const SkGradientShaderBase&,
58 const ContextRec&);
59
60 uint32_t getFlags() const override { return fFlags; }
61
fmalita088e21b2016-10-05 09:28:42 -070062 bool isValid() const;
63
fmalitabc590c02016-02-22 09:12:33 -080064protected:
Florin Malitada4545b2017-03-23 17:04:54 -040065 Sk4fGradientIntervalBuffer fIntervals;
66 SkMatrix fDstToPos;
Cary Clark9480d822017-10-19 18:01:13 -040067 SkMatrixPriv::MapXYProc fDstToPosProc;
Florin Malitada4545b2017-03-23 17:04:54 -040068 uint8_t fFlags;
Florin Malitada4545b2017-03-23 17:04:54 -040069 bool fColorsArePremul;
Florin Malitaaa0ce822017-08-28 12:50:26 -040070 bool fDither;
fmalitabc590c02016-02-22 09:12:33 -080071
72private:
Florin Malita4aed1382017-05-25 10:38:07 -040073 using INHERITED = Context;
fmalita7e6fcf82016-03-10 11:18:43 -080074
75 void addMirrorIntervals(const SkGradientShaderBase&,
76 const Sk4f& componentScale, bool reverse);
fmalitabc590c02016-02-22 09:12:33 -080077};
78
79#endif // Sk4fGradientBase_DEFINED