2011-02-22 20:59:41 +00:00
|
|
|
|
2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2011-02-22 20:59:41 +00:00
|
|
|
*/
|
|
|
|
|
2011-07-28 14:26:00 +00:00
|
|
|
|
2011-02-22 20:59:41 +00:00
|
|
|
#ifndef GrPaint_DEFINED
|
|
|
|
#define GrPaint_DEFINED
|
|
|
|
|
|
|
|
#include "GrColor.h"
|
2014-12-03 18:40:13 +00:00
|
|
|
#include "GrXferProcessor.h"
|
2014-12-09 19:15:43 +00:00
|
|
|
#include "effects/GrPorterDuffXferProcessor.h"
|
2015-08-12 16:40:47 +00:00
|
|
|
#include "GrFragmentProcessor.h"
|
2011-02-22 20:59:41 +00:00
|
|
|
|
2015-02-17 15:34:43 +00:00
|
|
|
#include "SkRegion.h"
|
2011-05-11 14:05:25 +00:00
|
|
|
#include "SkXfermode.h"
|
|
|
|
|
2011-02-22 20:59:41 +00:00
|
|
|
/**
|
2012-10-05 19:04:13 +00:00
|
|
|
* The paint describes how color and coverage are computed at each pixel by GrContext draw
|
|
|
|
* functions and the how color is blended with the destination pixel.
|
|
|
|
*
|
|
|
|
* The paint allows installation of custom color and coverage stages. New types of stages are
|
2014-09-23 16:50:21 +00:00
|
|
|
* created by subclassing GrProcessor.
|
2012-10-05 19:04:13 +00:00
|
|
|
*
|
|
|
|
* The primitive color computation starts with the color specified by setColor(). This color is the
|
2015-02-02 21:00:10 +00:00
|
|
|
* input to the first color stage. Each color stage feeds its output to the next color stage.
|
2012-10-05 19:04:13 +00:00
|
|
|
*
|
|
|
|
* Fractional pixel coverage follows a similar flow. The coverage is initially the value specified
|
|
|
|
* by setCoverage(). This is input to the first coverage stage. Coverage stages are chained
|
|
|
|
* together in the same manner as color stages. The output of the last stage is modulated by any
|
|
|
|
* fractional coverage produced by anti-aliasing. This last step produces the final coverage, C.
|
|
|
|
*
|
2015-02-02 21:00:10 +00:00
|
|
|
* setXPFactory is used to control blending between the output color and dest. It also implements
|
|
|
|
* the application of fractional coverage from the coverage pipeline.
|
2011-02-22 20:59:41 +00:00
|
|
|
*/
|
|
|
|
class GrPaint {
|
|
|
|
public:
|
2015-01-22 15:11:44 +00:00
|
|
|
GrPaint();
|
2011-02-22 20:59:41 +00:00
|
|
|
|
2012-10-05 19:04:13 +00:00
|
|
|
GrPaint(const GrPaint& paint) { *this = paint; }
|
2011-02-22 20:59:41 +00:00
|
|
|
|
2015-08-27 13:30:17 +00:00
|
|
|
~GrPaint() { this->resetFragmentProcessors(); }
|
2012-10-05 19:04:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The initial color of the drawn primitive. Defaults to solid white.
|
|
|
|
*/
|
|
|
|
void setColor(GrColor color) { fColor = color; }
|
|
|
|
GrColor getColor() const { return fColor; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Should primitives be anti-aliased or not. Defaults to false.
|
|
|
|
*/
|
|
|
|
void setAntiAlias(bool aa) { fAntiAlias = aa; }
|
|
|
|
bool isAntiAlias() const { return fAntiAlias; }
|
|
|
|
|
2016-03-25 13:01:59 +00:00
|
|
|
/**
|
|
|
|
* Should shader output conversion from linear to sRGB be disabled.
|
|
|
|
* Only relevant if the destination is sRGB. Defaults to false.
|
|
|
|
*/
|
|
|
|
void setDisableOutputConversionToSRGB(bool srgb) { fDisableOutputConversionToSRGB = srgb; }
|
|
|
|
bool getDisableOutputConversionToSRGB() const { return fDisableOutputConversionToSRGB; }
|
|
|
|
|
2016-04-06 14:38:23 +00:00
|
|
|
/**
|
|
|
|
* Should sRGB inputs be allowed to perform sRGB to linear conversion. With this flag
|
|
|
|
* set to false, sRGB textures will be treated as linear (including filtering).
|
|
|
|
*/
|
|
|
|
void setAllowSRGBInputs(bool allowSRGBInputs) { fAllowSRGBInputs = allowSRGBInputs; }
|
|
|
|
bool getAllowSRGBInputs() const { return fAllowSRGBInputs; }
|
|
|
|
|
2016-04-13 20:10:14 +00:00
|
|
|
/**
|
2016-04-13 20:56:21 +00:00
|
|
|
* Should rendering be gamma-correct, end-to-end. Causes sRGB render targets to behave
|
|
|
|
* as such (with linear blending), and sRGB inputs to be filtered and decoded correctly.
|
2016-04-13 20:10:14 +00:00
|
|
|
*/
|
|
|
|
void setGammaCorrect(bool gammaCorrect) {
|
|
|
|
setDisableOutputConversionToSRGB(!gammaCorrect);
|
|
|
|
setAllowSRGBInputs(gammaCorrect);
|
|
|
|
}
|
|
|
|
|
2014-12-03 18:40:13 +00:00
|
|
|
const GrXPFactory* setXPFactory(const GrXPFactory* xpFactory) {
|
2015-11-23 21:20:41 +00:00
|
|
|
fXPFactory.reset(SkSafeRef(xpFactory));
|
2014-12-03 18:40:13 +00:00
|
|
|
return xpFactory;
|
|
|
|
}
|
|
|
|
|
2014-12-09 19:15:43 +00:00
|
|
|
void setPorterDuffXPFactory(SkXfermode::Mode mode) {
|
|
|
|
fXPFactory.reset(GrPorterDuffXPFactory::Create(mode));
|
|
|
|
}
|
|
|
|
|
2015-02-17 15:34:43 +00:00
|
|
|
void setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage = false);
|
2014-12-09 19:15:43 +00:00
|
|
|
|
2012-10-05 19:04:13 +00:00
|
|
|
/**
|
2014-09-23 16:50:21 +00:00
|
|
|
* Appends an additional color processor to the color computation.
|
2012-10-05 19:04:13 +00:00
|
|
|
*/
|
2015-08-27 13:30:17 +00:00
|
|
|
const GrFragmentProcessor* addColorFragmentProcessor(const GrFragmentProcessor* fp) {
|
2014-09-23 16:50:21 +00:00
|
|
|
SkASSERT(fp);
|
2015-08-27 13:30:17 +00:00
|
|
|
fColorFragmentProcessors.push_back(SkRef(fp));
|
2014-09-23 16:50:21 +00:00
|
|
|
return fp;
|
2011-05-17 20:15:30 +00:00
|
|
|
}
|
|
|
|
|
2012-10-05 19:04:13 +00:00
|
|
|
/**
|
2014-09-23 16:50:21 +00:00
|
|
|
* Appends an additional coverage processor to the coverage computation.
|
2012-10-05 19:04:13 +00:00
|
|
|
*/
|
2015-08-27 13:30:17 +00:00
|
|
|
const GrFragmentProcessor* addCoverageFragmentProcessor(const GrFragmentProcessor* fp) {
|
2014-09-23 16:50:21 +00:00
|
|
|
SkASSERT(fp);
|
2015-08-27 13:30:17 +00:00
|
|
|
fCoverageFragmentProcessors.push_back(SkRef(fp));
|
2014-09-23 16:50:21 +00:00
|
|
|
return fp;
|
2011-02-22 20:59:41 +00:00
|
|
|
}
|
|
|
|
|
2013-07-13 17:24:24 +00:00
|
|
|
/**
|
|
|
|
* Helpers for adding color or coverage effects that sample a texture. The matrix is applied
|
|
|
|
* to the src space position to compute texture coordinates.
|
|
|
|
*/
|
2014-09-23 16:50:21 +00:00
|
|
|
void addColorTextureProcessor(GrTexture*, const SkMatrix&);
|
|
|
|
void addCoverageTextureProcessor(GrTexture*, const SkMatrix&);
|
|
|
|
void addColorTextureProcessor(GrTexture*, const SkMatrix&, const GrTextureParams&);
|
|
|
|
void addCoverageTextureProcessor(GrTexture*, const SkMatrix&, const GrTextureParams&);
|
2012-07-20 13:37:06 +00:00
|
|
|
|
2015-08-27 13:30:17 +00:00
|
|
|
int numColorFragmentProcessors() const { return fColorFragmentProcessors.count(); }
|
|
|
|
int numCoverageFragmentProcessors() const { return fCoverageFragmentProcessors.count(); }
|
|
|
|
int numTotalFragmentProcessors() const { return this->numColorFragmentProcessors() +
|
|
|
|
this->numCoverageFragmentProcessors(); }
|
2012-07-20 13:37:06 +00:00
|
|
|
|
2015-01-22 15:11:44 +00:00
|
|
|
const GrXPFactory* getXPFactory() const {
|
2015-11-23 21:20:41 +00:00
|
|
|
return fXPFactory;
|
2015-01-22 15:11:44 +00:00
|
|
|
}
|
2014-12-03 18:40:13 +00:00
|
|
|
|
2015-08-27 13:30:17 +00:00
|
|
|
const GrFragmentProcessor* getColorFragmentProcessor(int i) const {
|
|
|
|
return fColorFragmentProcessors[i];
|
|
|
|
}
|
|
|
|
const GrFragmentProcessor* getCoverageFragmentProcessor(int i) const {
|
|
|
|
return fCoverageFragmentProcessors[i];
|
|
|
|
}
|
2012-07-20 13:37:06 +00:00
|
|
|
|
2011-09-12 14:30:27 +00:00
|
|
|
GrPaint& operator=(const GrPaint& paint) {
|
2011-02-22 20:59:41 +00:00
|
|
|
fAntiAlias = paint.fAntiAlias;
|
2016-03-25 13:01:59 +00:00
|
|
|
fDisableOutputConversionToSRGB = paint.fDisableOutputConversionToSRGB;
|
2016-04-06 14:38:23 +00:00
|
|
|
fAllowSRGBInputs = paint.fAllowSRGBInputs;
|
2011-02-22 20:59:41 +00:00
|
|
|
|
|
|
|
fColor = paint.fColor;
|
2015-08-27 13:30:17 +00:00
|
|
|
this->resetFragmentProcessors();
|
|
|
|
fColorFragmentProcessors = paint.fColorFragmentProcessors;
|
|
|
|
fCoverageFragmentProcessors = paint.fCoverageFragmentProcessors;
|
|
|
|
for (int i = 0; i < fColorFragmentProcessors.count(); ++i) {
|
|
|
|
fColorFragmentProcessors[i]->ref();
|
|
|
|
}
|
|
|
|
for (int i = 0; i < fCoverageFragmentProcessors.count(); ++i) {
|
|
|
|
fCoverageFragmentProcessors[i]->ref();
|
|
|
|
}
|
2013-07-13 17:24:24 +00:00
|
|
|
|
2015-11-23 21:20:41 +00:00
|
|
|
fXPFactory.reset(SkSafeRef(paint.getXPFactory()));
|
2014-12-03 18:40:13 +00:00
|
|
|
|
2011-09-12 14:30:27 +00:00
|
|
|
return *this;
|
2011-02-22 20:59:41 +00:00
|
|
|
}
|
|
|
|
|
2013-08-14 21:56:37 +00:00
|
|
|
/**
|
2015-06-02 17:43:39 +00:00
|
|
|
* Returns true if the paint's output color will be constant after blending. If the result is
|
|
|
|
* true, constantColor will be updated to contain the constant color. Note that we can conflate
|
|
|
|
* coverage and color, so the actual values written to pixels with partial coverage may still
|
|
|
|
* not seem constant, even if this function returns true.
|
2013-08-14 21:56:37 +00:00
|
|
|
*/
|
2015-06-02 17:43:39 +00:00
|
|
|
bool isConstantBlendedColor(GrColor* constantColor) const;
|
2013-08-14 21:56:37 +00:00
|
|
|
|
2014-12-17 23:50:11 +00:00
|
|
|
private:
|
2015-08-27 13:30:17 +00:00
|
|
|
void resetFragmentProcessors() {
|
|
|
|
for (int i = 0; i < fColorFragmentProcessors.count(); ++i) {
|
|
|
|
fColorFragmentProcessors[i]->unref();
|
|
|
|
}
|
|
|
|
for (int i = 0; i < fCoverageFragmentProcessors.count(); ++i) {
|
|
|
|
fCoverageFragmentProcessors[i]->unref();
|
|
|
|
}
|
|
|
|
fColorFragmentProcessors.reset();
|
|
|
|
fCoverageFragmentProcessors.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
mutable SkAutoTUnref<const GrXPFactory> fXPFactory;
|
|
|
|
SkSTArray<4, const GrFragmentProcessor*, true> fColorFragmentProcessors;
|
|
|
|
SkSTArray<2, const GrFragmentProcessor*, true> fCoverageFragmentProcessors;
|
2011-05-17 20:15:30 +00:00
|
|
|
|
2015-08-27 13:30:17 +00:00
|
|
|
bool fAntiAlias;
|
2016-03-25 13:01:59 +00:00
|
|
|
bool fDisableOutputConversionToSRGB;
|
2016-04-06 14:38:23 +00:00
|
|
|
bool fAllowSRGBInputs;
|
2012-10-05 19:04:13 +00:00
|
|
|
|
2015-08-27 13:30:17 +00:00
|
|
|
GrColor fColor;
|
2011-02-22 20:59:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|