blob: 6361eece0c745853a423f2885ef06a246ac2bc96 [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"
16#include "SkPM4f.h"
Florin Malita4aed1382017-05-25 10:38:07 -040017#include "SkShaderBase.h"
fmalitabc590c02016-02-22 09:12:33 -080018#include "SkTArray.h"
19
Florin Malitada4545b2017-03-23 17:04:54 -040020struct Sk4fGradientInterval {
Florin Malitacf20f782017-04-07 14:56:14 -040021 Sk4fGradientInterval(const Sk4f& c0, SkScalar t0,
22 const Sk4f& c1, SkScalar t1);
Florin Malitada4545b2017-03-23 17:04:54 -040023
24 bool contains(SkScalar t) const {
25 // True if t is in [p0,p1]. Note: this helper assumes a
26 // natural/increasing interval - so it's not usable in Sk4fLinearGradient.
Florin Malitacf20f782017-04-07 14:56:14 -040027 SkASSERT(fT0 < fT1);
28 return t >= fT0 && t <= fT1;
Florin Malitada4545b2017-03-23 17:04:54 -040029 }
30
Florin Malitacf20f782017-04-07 14:56:14 -040031 // Color bias and color gradient, such that for a t in this interval
32 //
33 // C = fCb + t * fCg;
34 SkPM4f fCb, fCg;
35 SkScalar fT0, fT1;
Florin Malitada4545b2017-03-23 17:04:54 -040036};
37
38class Sk4fGradientIntervalBuffer {
39public:
Florin Malita0e36b3f2017-06-05 23:33:45 -040040 void init(const SkGradientShaderBase&, SkColorSpace* dstCS, SkShader::TileMode tileMode,
41 bool premulColors, SkScalar alpha, bool reverse);
Florin Malitada4545b2017-03-23 17:04:54 -040042
43 const Sk4fGradientInterval* find(SkScalar t) const;
44 const Sk4fGradientInterval* findNext(SkScalar t, const Sk4fGradientInterval* prev,
45 bool increasing) const;
46
47 using BufferType = SkSTArray<8, Sk4fGradientInterval, true>;
48
49 const BufferType* operator->() const { return &fIntervals; }
50
51private:
52 BufferType fIntervals;
53};
54
fmalitabc590c02016-02-22 09:12:33 -080055class SkGradientShaderBase::
Florin Malita4aed1382017-05-25 10:38:07 -040056GradientShaderBase4fContext : public Context {
fmalitabc590c02016-02-22 09:12:33 -080057public:
58 GradientShaderBase4fContext(const SkGradientShaderBase&,
59 const ContextRec&);
60
61 uint32_t getFlags() const override { return fFlags; }
62
fmalita088e21b2016-10-05 09:28:42 -070063 bool isValid() const;
64
fmalitabc590c02016-02-22 09:12:33 -080065protected:
Florin Malitada4545b2017-03-23 17:04:54 -040066 Sk4fGradientIntervalBuffer fIntervals;
67 SkMatrix fDstToPos;
Cary Clark9480d822017-10-19 18:01:13 -040068 SkMatrixPriv::MapXYProc fDstToPosProc;
Florin Malitada4545b2017-03-23 17:04:54 -040069 uint8_t fFlags;
Florin Malitada4545b2017-03-23 17:04:54 -040070 bool fColorsArePremul;
Florin Malitaaa0ce822017-08-28 12:50:26 -040071 bool fDither;
fmalitabc590c02016-02-22 09:12:33 -080072
73private:
Florin Malita4aed1382017-05-25 10:38:07 -040074 using INHERITED = Context;
fmalita7e6fcf82016-03-10 11:18:43 -080075
76 void addMirrorIntervals(const SkGradientShaderBase&,
77 const Sk4f& componentScale, bool reverse);
fmalitabc590c02016-02-22 09:12:33 -080078};
79
80#endif // Sk4fGradientBase_DEFINED