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-11-19 16:23:49 +00:00
|
|
|
#include "GrFragmentStage.h"
|
2014-12-03 18:40:13 +00:00
|
|
|
#include "GrXferProcessor.h"
|
2014-12-09 19:15:43 +00:00
|
|
|
#include "effects/GrPorterDuffXferProcessor.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
|
|
|
|
2012-10-05 19:04:13 +00:00
|
|
|
~GrPaint() {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Should dithering be applied. Defaults to false.
|
|
|
|
*/
|
|
|
|
void setDither(bool dither) { fDither = dither; }
|
|
|
|
bool isDither() const { return fDither; }
|
|
|
|
|
2014-12-03 18:40:13 +00:00
|
|
|
const GrXPFactory* setXPFactory(const GrXPFactory* xpFactory) {
|
|
|
|
fXPFactory.reset(SkRef(xpFactory));
|
|
|
|
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
|
|
|
*/
|
2014-09-23 16:50:21 +00:00
|
|
|
const GrFragmentProcessor* addColorProcessor(const GrFragmentProcessor* fp) {
|
|
|
|
SkASSERT(fp);
|
2014-10-07 23:43:25 +00:00
|
|
|
SkNEW_APPEND_TO_TARRAY(&fColorStages, GrFragmentStage, (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
|
|
|
*/
|
2014-09-23 16:50:21 +00:00
|
|
|
const GrFragmentProcessor* addCoverageProcessor(const GrFragmentProcessor* fp) {
|
|
|
|
SkASSERT(fp);
|
2014-10-07 23:43:25 +00:00
|
|
|
SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrFragmentStage, (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
|
|
|
|
2013-07-13 17:24:24 +00:00
|
|
|
int numColorStages() const { return fColorStages.count(); }
|
|
|
|
int numCoverageStages() const { return fCoverageStages.count(); }
|
|
|
|
int numTotalStages() const { return this->numColorStages() + this->numCoverageStages(); }
|
2012-07-20 13:37:06 +00:00
|
|
|
|
2015-01-22 15:11:44 +00:00
|
|
|
const GrXPFactory* getXPFactory() const {
|
|
|
|
if (!fXPFactory) {
|
|
|
|
fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode));
|
|
|
|
}
|
|
|
|
return fXPFactory.get();
|
|
|
|
}
|
2014-12-03 18:40:13 +00:00
|
|
|
|
2014-09-23 16:50:21 +00:00
|
|
|
const GrFragmentStage& getColorStage(int s) const { return fColorStages[s]; }
|
|
|
|
const GrFragmentStage& getCoverageStage(int s) const { return fCoverageStages[s]; }
|
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;
|
|
|
|
fDither = paint.fDither;
|
|
|
|
|
|
|
|
fColor = paint.fColor;
|
|
|
|
|
2013-07-13 17:24:24 +00:00
|
|
|
fColorStages = paint.fColorStages;
|
|
|
|
fCoverageStages = paint.fCoverageStages;
|
|
|
|
|
2014-12-03 18:40:13 +00:00
|
|
|
fXPFactory.reset(SkRef(paint.getXPFactory()));
|
|
|
|
|
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-01-22 15:11:44 +00:00
|
|
|
mutable SkAutoTUnref<const GrXPFactory> fXPFactory;
|
2014-12-03 18:40:13 +00:00
|
|
|
SkSTArray<4, GrFragmentStage> fColorStages;
|
|
|
|
SkSTArray<2, GrFragmentStage> fCoverageStages;
|
2011-05-17 20:15:30 +00:00
|
|
|
|
2014-12-03 18:40:13 +00:00
|
|
|
bool fAntiAlias;
|
|
|
|
bool fDither;
|
2012-10-05 19:04:13 +00:00
|
|
|
|
2014-12-03 18:40:13 +00:00
|
|
|
GrColor fColor;
|
2011-02-22 20:59:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|