Skia
2DGraphicsLibrary
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GrPaint.h
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 
13 #include "GrColor.h"
14 #include "GrColorSpaceXform.h"
15 #include "GrXferProcessor.h"
16 #include "effects/GrPorterDuffXferProcessor.h"
17 #include "GrFragmentProcessor.h"
18 
19 #include "SkRefCnt.h"
20 #include "SkRegion.h"
21 #include "SkXfermode.h"
22 
41 class GrPaint {
42 public:
43  GrPaint();
44 
45  GrPaint(const GrPaint& paint) { *this = paint; }
46 
47  ~GrPaint() { }
48 
52  void setColor4f(const GrColor4f& color) { fColor = color; }
53  const GrColor4f& getColor4f() const { return fColor; }
54 
58  GrColor getColor() const { return fColor.toGrColor(); }
59 
63  void setAntiAlias(bool aa) { fAntiAlias = aa; }
64  bool isAntiAlias() const { return fAntiAlias; }
65 
70  void setDisableOutputConversionToSRGB(bool srgb) { fDisableOutputConversionToSRGB = srgb; }
71  bool getDisableOutputConversionToSRGB() const { return fDisableOutputConversionToSRGB; }
72 
77  void setAllowSRGBInputs(bool allowSRGBInputs) { fAllowSRGBInputs = allowSRGBInputs; }
78  bool getAllowSRGBInputs() const { return fAllowSRGBInputs; }
79 
83  bool usesDistanceVectorField() const { return fUsesDistanceVectorField; }
84 
89  void setGammaCorrect(bool gammaCorrect) {
90  setDisableOutputConversionToSRGB(!gammaCorrect);
91  setAllowSRGBInputs(gammaCorrect);
92  }
93 
94  void setXPFactory(sk_sp<GrXPFactory> xpFactory) {
95  fXPFactory = std::move(xpFactory);
96  }
97 
98  void setPorterDuffXPFactory(SkXfermode::Mode mode) {
99  fXPFactory = GrPorterDuffXPFactory::Make(mode);
100  }
101 
102  void setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage = false);
103 
108  SkASSERT(fp);
109  fUsesDistanceVectorField |= fp->usesDistanceVectorField();
110  fColorFragmentProcessors.push_back(std::move(fp));
111  }
112 
117  SkASSERT(fp);
118  fUsesDistanceVectorField |= fp->usesDistanceVectorField();
119  fCoverageFragmentProcessors.push_back(std::move(fp));
120  }
121 
127  void addCoverageTextureProcessor(GrTexture*, const SkMatrix&);
129  const GrTextureParams&);
130  void addCoverageTextureProcessor(GrTexture*, const SkMatrix&, const GrTextureParams&);
131 
132  int numColorFragmentProcessors() const { return fColorFragmentProcessors.count(); }
133  int numCoverageFragmentProcessors() const { return fCoverageFragmentProcessors.count(); }
134  int numTotalFragmentProcessors() const { return this->numColorFragmentProcessors() +
135  this->numCoverageFragmentProcessors(); }
136 
137  GrXPFactory* getXPFactory() const {
138  return fXPFactory.get();
139  }
140 
141  GrFragmentProcessor* getColorFragmentProcessor(int i) const {
142  return fColorFragmentProcessors[i].get();
143  }
144  GrFragmentProcessor* getCoverageFragmentProcessor(int i) const {
145  return fCoverageFragmentProcessors[i].get();
146  }
147 
148  GrPaint& operator=(const GrPaint& paint) {
149  fAntiAlias = paint.fAntiAlias;
150  fDisableOutputConversionToSRGB = paint.fDisableOutputConversionToSRGB;
151  fAllowSRGBInputs = paint.fAllowSRGBInputs;
152  fUsesDistanceVectorField = paint.fUsesDistanceVectorField;
153 
154  fColor = paint.fColor;
155  fColorFragmentProcessors = paint.fColorFragmentProcessors;
156  fCoverageFragmentProcessors = paint.fCoverageFragmentProcessors;
157 
158  fXPFactory = paint.fXPFactory;
159 
160  return *this;
161  }
162 
169  bool isConstantBlendedColor(GrColor* constantColor) const {
170  GrColor paintColor = this->getColor();
171  if (!fXPFactory && fColorFragmentProcessors.empty()) {
172  if (!GrColorIsOpaque(paintColor)) {
173  return false;
174  }
175  *constantColor = paintColor;
176  return true;
177  }
178  return this->internalIsConstantBlendedColor(paintColor, constantColor);
179  }
180 
181 private:
182  bool internalIsConstantBlendedColor(GrColor paintColor, GrColor* constantColor) const;
183 
184  mutable sk_sp<GrXPFactory> fXPFactory;
185  SkSTArray<4, sk_sp<GrFragmentProcessor>> fColorFragmentProcessors;
186  SkSTArray<2, sk_sp<GrFragmentProcessor>> fCoverageFragmentProcessors;
187 
188  bool fAntiAlias;
189  bool fDisableOutputConversionToSRGB;
190  bool fAllowSRGBInputs;
191  bool fUsesDistanceVectorField;
192 
193  GrColor4f fColor;
194 };
195 
196 #endif
void setAntiAlias(bool aa)
Should primitives be anti-aliased or not.
Definition: GrPaint.h:63
void setAllowSRGBInputs(bool allowSRGBInputs)
Should sRGB inputs be allowed to perform sRGB to linear conversion.
Definition: GrPaint.h:77
Provides custom fragment shader code.
Definition: GrFragmentProcessor.h:24
Mode
List of predefined xfermodes.
Definition: SkXfermode.h:71
Represents the filtering and tile modes used to access a texture.
Definition: GrTextureParams.h:17
The SkMatrix class holds a 3x3 matrix for transforming coordinates.
Definition: SkMatrix.h:26
bool usesDistanceVectorField() const
Does this FP need a vector to the nearest edge?
Definition: GrFragmentProcessor.h:115
void setGammaCorrect(bool gammaCorrect)
Should rendering be gamma-correct, end-to-end.
Definition: GrPaint.h:89
GrColor getColor() const
Legacy getter, until all code handles 4f directly.
Definition: GrPaint.h:58
bool usesDistanceVectorField() const
Does one of the fragment processors need a field of distance vectors to the nearest edge...
Definition: GrPaint.h:83
Similarly, GrColor4f is 4 floats for R, G, B, A, in that order.
Definition: GrColor.h:177
void setDisableOutputConversionToSRGB(bool srgb)
Should shader output conversion from linear to sRGB be disabled.
Definition: GrPaint.h:70
void addColorFragmentProcessor(sk_sp< GrFragmentProcessor > fp)
Appends an additional color processor to the color computation.
Definition: GrPaint.h:107
bool isConstantBlendedColor(GrColor *constantColor) const
Returns true if the paint's output color will be constant after blending.
Definition: GrPaint.h:169
The paint describes how color and coverage are computed at each pixel by GrContext draw functions and...
Definition: GrPaint.h:41
void addColorTextureProcessor(GrTexture *, sk_sp< GrColorSpaceXform >, const SkMatrix &)
Helpers for adding color or coverage effects that sample a texture.
void addCoverageFragmentProcessor(sk_sp< GrFragmentProcessor > fp)
Appends an additional coverage processor to the coverage computation.
Definition: GrPaint.h:116
void setColor4f(const GrColor4f &color)
The initial color of the drawn primitive.
Definition: GrPaint.h:52
Definition: GrTexture.h:19
Op
The logical operations that can be performed when combining two regions.
Definition: SkRegion.h:239
We install a GrXPFactory (XPF) early on in the pipeline before all the final draw information is know...
Definition: GrXferProcessor.h:301