Flutter Engine
The Flutter Engine
GrPaint.h
Go to the documentation of this file.
1
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9
10#ifndef GrPaint_DEFINED
11#define GrPaint_DEFINED
12
16#include "src/base/SkTLazy.h"
19
20class GrTextureProxy;
21class GrXPFactory;
22
23/**
24 * The paint describes how color and coverage are computed at each pixel by GrContext draw
25 * functions and the how color is blended with the destination pixel.
26 *
27 * The paint allows installation of custom color and coverage stages. New types of stages are
28 * created by subclassing GrProcessor.
29 *
30 * The primitive color computation starts with the color specified by setColor(). This color is the
31 * input to the first color stage. Each color stage feeds its output to the next color stage.
32 *
33 * Fractional pixel coverage follows a similar flow. The GrGeometryProcessor (specified elsewhere)
34 * provides the initial coverage which is passed to the first coverage fragment processor, which
35 * feeds its output to next coverage fragment processor.
36 *
37 * setXPFactory is used to control blending between the output color and dest. It also implements
38 * the application of fractional coverage from the coverage pipeline.
39 */
40class GrPaint {
41public:
42 GrPaint() = default;
43 ~GrPaint() = default;
44
45 static GrPaint Clone(const GrPaint& src) { return GrPaint(src); }
46
47 /**
48 * The initial color of the drawn primitive. Defaults to solid white.
49 */
50 void setColor4f(const SkPMColor4f& color) { fColor = color; }
51 const SkPMColor4f& getColor4f() const { return fColor; }
52
53 void setXPFactory(const GrXPFactory* xpFactory) {
54 fXPFactory = xpFactory;
55 fTrivial &= !SkToBool(xpFactory);
56 }
57
59
60 void setCoverageSetOpXPFactory(SkRegion::Op, bool invertCoverage = false);
61
62 /**
63 * Sets a processor for color computation.
64 */
65 void setColorFragmentProcessor(std::unique_ptr<GrFragmentProcessor> fp) {
66 SkASSERT(fp);
67 SkASSERT(fColorFragmentProcessor == nullptr);
68 fColorFragmentProcessor = std::move(fp);
69 fTrivial = false;
70 }
71
72 /**
73 * Appends an additional coverage processor to the coverage computation.
74 */
75 void setCoverageFragmentProcessor(std::unique_ptr<GrFragmentProcessor> fp) {
76 SkASSERT(fp);
77 SkASSERT(fCoverageFragmentProcessor == nullptr);
78 fCoverageFragmentProcessor = std::move(fp);
79 fTrivial = false;
80 }
81
82 bool hasColorFragmentProcessor() const { return fColorFragmentProcessor ? true : false; }
83 int hasCoverageFragmentProcessor() const { return fCoverageFragmentProcessor ? true : false; }
85 return (this->hasColorFragmentProcessor() ? 1 : 0) +
86 (this->hasCoverageFragmentProcessor() ? 1 : 0);
87 }
88
89 const GrXPFactory* getXPFactory() const { return fXPFactory; }
90
92 return fColorFragmentProcessor.get();
93 }
95 return fCoverageFragmentProcessor.get();
96 }
97 bool usesLocalCoords() const {
98 // The sample coords for the top level FPs are implicitly the GP's local coords.
99 return (fColorFragmentProcessor && fColorFragmentProcessor->usesSampleCoords()) ||
100 (fCoverageFragmentProcessor && fCoverageFragmentProcessor->usesSampleCoords());
101 }
102
103 /**
104 * Returns true if the paint's output color will be constant after blending. If the result is
105 * true, constantColor will be updated to contain the constant color. Note that we can conflate
106 * coverage and color, so the actual values written to pixels with partial coverage may still
107 * not seem constant, even if this function returns true.
108 */
109 bool isConstantBlendedColor(SkPMColor4f* constantColor) const;
110
111 /**
112 * A trivial paint is one that uses src-over and has no fragment processors.
113 * It may have variable sRGB settings.
114 **/
115 bool isTrivial() const { return fTrivial; }
116
117 friend void assert_alive(GrPaint& p) {
118 SkASSERT(p.fAlive);
119 }
120
121private:
122 // Since paint copying is expensive if there are fragment processors, we require going through
123 // the Clone() method.
124 GrPaint(const GrPaint&);
125 GrPaint& operator=(const GrPaint&) = delete;
126
127 friend class GrProcessorSet;
128
129 const GrXPFactory* fXPFactory = nullptr;
130 std::unique_ptr<GrFragmentProcessor> fColorFragmentProcessor;
131 std::unique_ptr<GrFragmentProcessor> fCoverageFragmentProcessor;
132 bool fTrivial = true;
134 SkDEBUGCODE(bool fAlive = true;) // Set false after moved from.
135};
136
137#endif
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkBlendMode
Definition: SkBlendMode.h:38
constexpr SkPMColor4f SK_PMColor4fWHITE
Definition: SkColorData.h:380
SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID()
static constexpr bool SkToBool(const T &x)
Definition: SkTo.h:35
void setCoverageSetOpXPFactory(SkRegion::Op, bool invertCoverage=false)
Definition: GrPaint.cpp:32
void setXPFactory(const GrXPFactory *xpFactory)
Definition: GrPaint.h:53
const GrXPFactory * getXPFactory() const
Definition: GrPaint.h:89
bool isTrivial() const
Definition: GrPaint.h:115
friend void assert_alive(GrPaint &p)
Definition: GrPaint.h:117
GrPaint()=default
static GrPaint Clone(const GrPaint &src)
Definition: GrPaint.h:45
const SkPMColor4f & getColor4f() const
Definition: GrPaint.h:51
GrFragmentProcessor * getColorFragmentProcessor() const
Definition: GrPaint.h:91
void setColorFragmentProcessor(std::unique_ptr< GrFragmentProcessor > fp)
Definition: GrPaint.h:65
bool isConstantBlendedColor(SkPMColor4f *constantColor) const
Definition: GrPaint.cpp:36
GrFragmentProcessor * getCoverageFragmentProcessor() const
Definition: GrPaint.h:94
int hasCoverageFragmentProcessor() const
Definition: GrPaint.h:83
void setColor4f(const SkPMColor4f &color)
Definition: GrPaint.h:50
void setCoverageFragmentProcessor(std::unique_ptr< GrFragmentProcessor > fp)
Definition: GrPaint.h:75
bool hasColorFragmentProcessor() const
Definition: GrPaint.h:82
void setPorterDuffXPFactory(SkBlendMode mode)
Definition: GrPaint.cpp:28
bool usesLocalCoords() const
Definition: GrPaint.h:97
int numTotalFragmentProcessors() const
Definition: GrPaint.h:84
~GrPaint()=default
DlColor color
const uint32_t fp
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition: switches.h:228