blob: 3c40c96d1b3b829341cdf00e904a7248960dff7e [file] [log] [blame]
commit-bot@chromium.org42dacab2013-07-13 17:24:24 +00001
2/*
3 * Copyright 2013 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#include "GrPaint.h"
10
egdanielb6cbc382014-11-13 11:00:34 -080011#include "GrProcOptInfo.h"
egdanielb197b8f2015-02-17 07:34:43 -080012#include "effects/GrCoverageSetOpXP.h"
egdaniel378092f2014-12-03 10:40:13 -080013#include "effects/GrPorterDuffXferProcessor.h"
commit-bot@chromium.org42dacab2013-07-13 17:24:24 +000014#include "effects/GrSimpleTextureEffect.h"
15
joshualitt2fdeda02015-01-22 07:11:44 -080016GrPaint::GrPaint()
17 : fAntiAlias(false)
18 , fDither(false)
19 , fColor(GrColor_WHITE) {
20}
21
egdanielb197b8f2015-02-17 07:34:43 -080022void GrPaint::setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage) {
23 fXPFactory.reset(GrCoverageSetOpXPFactory::Create(regionOp, invertCoverage));
24}
25
joshualittb0a8a372014-09-23 09:50:21 -070026void GrPaint::addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
27 this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref();
commit-bot@chromium.org42dacab2013-07-13 17:24:24 +000028}
29
joshualittb0a8a372014-09-23 09:50:21 -070030void GrPaint::addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
31 this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref();
commit-bot@chromium.org42dacab2013-07-13 17:24:24 +000032}
33
joshualittb0a8a372014-09-23 09:50:21 -070034void GrPaint::addColorTextureProcessor(GrTexture* texture,
joshualitt40d4bd82014-12-29 09:04:40 -080035 const SkMatrix& matrix,
36 const GrTextureParams& params) {
joshualittb0a8a372014-09-23 09:50:21 -070037 this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix, params))->unref();
commit-bot@chromium.org42dacab2013-07-13 17:24:24 +000038}
39
joshualittb0a8a372014-09-23 09:50:21 -070040void GrPaint::addCoverageTextureProcessor(GrTexture* texture,
joshualitt40d4bd82014-12-29 09:04:40 -080041 const SkMatrix& matrix,
42 const GrTextureParams& params) {
joshualittb0a8a372014-09-23 09:50:21 -070043 this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix, params))->unref();
commit-bot@chromium.org42dacab2013-07-13 17:24:24 +000044}
commit-bot@chromium.org24ab3b02013-08-14 21:56:37 +000045
cdalton1fa45722015-06-02 10:43:39 -070046bool GrPaint::isConstantBlendedColor(GrColor* color) const {
egdaniel9e4ecdc2014-12-18 12:44:55 -080047 GrProcOptInfo colorProcInfo;
48 colorProcInfo.calcWithInitialValues(fColorStages.begin(), this->numColorStages(), fColor,
49 kRGBA_GrColorComponentFlags, false);
50
cdalton1fa45722015-06-02 10:43:39 -070051 GrXPFactory::InvariantBlendedColor blendedColor;
52 fXPFactory->getInvariantBlendedColor(colorProcInfo, &blendedColor);
egdaniel9e4ecdc2014-12-18 12:44:55 -080053
cdalton1fa45722015-06-02 10:43:39 -070054 if (kRGBA_GrColorComponentFlags == blendedColor.fKnownColorFlags) {
55 *color = blendedColor.fKnownColor;
egdaniel9e4ecdc2014-12-18 12:44:55 -080056 return true;
commit-bot@chromium.org24ab3b02013-08-14 21:56:37 +000057 }
58 return false;
59}