blob: fd78f9f8191cbab73aa7963034a2ad7ef879d496 [file] [log] [blame]
commit-bot@chromium.org42dacab2013-07-13 17:24:24 +00001/*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "GrPaint.h"
9
egdanielb6cbc382014-11-13 11:00:34 -080010#include "GrProcOptInfo.h"
egdanielb197b8f2015-02-17 07:34:43 -080011#include "effects/GrCoverageSetOpXP.h"
egdaniel378092f2014-12-03 10:40:13 -080012#include "effects/GrPorterDuffXferProcessor.h"
commit-bot@chromium.org42dacab2013-07-13 17:24:24 +000013#include "effects/GrSimpleTextureEffect.h"
14
joshualitt2fdeda02015-01-22 07:11:44 -080015GrPaint::GrPaint()
16 : fAntiAlias(false)
brianosman64d094d2016-03-25 06:01:59 -070017 , fDisableOutputConversionToSRGB(false)
brianosman898235c2016-04-06 07:38:23 -070018 , fAllowSRGBInputs(false)
joshualittaf2533a2015-09-09 10:00:12 -070019 , fColor(GrColor_WHITE) {}
joshualitt2fdeda02015-01-22 07:11:44 -080020
egdanielb197b8f2015-02-17 07:34:43 -080021void GrPaint::setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage) {
bungeman06ca8ec2016-06-09 08:01:03 -070022 fXPFactory = GrCoverageSetOpXPFactory::Make(regionOp, invertCoverage);
egdanielb197b8f2015-02-17 07:34:43 -080023}
24
joshualittb0a8a372014-09-23 09:50:21 -070025void GrPaint::addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
bungeman06ca8ec2016-06-09 08:01:03 -070026 this->addColorFragmentProcessor(GrSimpleTextureEffect::Make(texture, matrix));
commit-bot@chromium.org42dacab2013-07-13 17:24:24 +000027}
28
joshualittb0a8a372014-09-23 09:50:21 -070029void GrPaint::addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
bungeman06ca8ec2016-06-09 08:01:03 -070030 this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Make(texture, matrix));
commit-bot@chromium.org42dacab2013-07-13 17:24:24 +000031}
32
joshualittb0a8a372014-09-23 09:50:21 -070033void GrPaint::addColorTextureProcessor(GrTexture* texture,
joshualitt40d4bd82014-12-29 09:04:40 -080034 const SkMatrix& matrix,
35 const GrTextureParams& params) {
bungeman06ca8ec2016-06-09 08:01:03 -070036 this->addColorFragmentProcessor(GrSimpleTextureEffect::Make(texture, matrix, params));
commit-bot@chromium.org42dacab2013-07-13 17:24:24 +000037}
38
joshualittb0a8a372014-09-23 09:50:21 -070039void GrPaint::addCoverageTextureProcessor(GrTexture* texture,
joshualitt40d4bd82014-12-29 09:04:40 -080040 const SkMatrix& matrix,
41 const GrTextureParams& params) {
bungeman06ca8ec2016-06-09 08:01:03 -070042 this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Make(texture, matrix, params));
commit-bot@chromium.org42dacab2013-07-13 17:24:24 +000043}
commit-bot@chromium.org24ab3b02013-08-14 21:56:37 +000044
cdalton1fa45722015-06-02 10:43:39 -070045bool GrPaint::isConstantBlendedColor(GrColor* color) const {
egdaniel9e4ecdc2014-12-18 12:44:55 -080046 GrProcOptInfo colorProcInfo;
bungeman06ca8ec2016-06-09 08:01:03 -070047 colorProcInfo.calcWithInitialValues(
48 sk_sp_address_as_pointer_address(fColorFragmentProcessors.begin()),
49 this->numColorFragmentProcessors(), fColor, kRGBA_GrColorComponentFlags, false);
egdaniel9e4ecdc2014-12-18 12:44:55 -080050
cdalton1fa45722015-06-02 10:43:39 -070051 GrXPFactory::InvariantBlendedColor blendedColor;
egdanielc4b72722015-11-23 13:20:41 -080052 if (fXPFactory) {
53 fXPFactory->getInvariantBlendedColor(colorProcInfo, &blendedColor);
54 } else {
55 GrPorterDuffXPFactory::SrcOverInvariantBlendedColor(colorProcInfo.color(),
56 colorProcInfo.validFlags(),
57 colorProcInfo.isOpaque(),
halcanary9d524f22016-03-29 09:03:52 -070058 &blendedColor);
egdanielc4b72722015-11-23 13:20:41 -080059 }
egdaniel9e4ecdc2014-12-18 12:44:55 -080060
cdalton1fa45722015-06-02 10:43:39 -070061 if (kRGBA_GrColorComponentFlags == blendedColor.fKnownColorFlags) {
62 *color = blendedColor.fKnownColor;
egdaniel9e4ecdc2014-12-18 12:44:55 -080063 return true;
commit-bot@chromium.org24ab3b02013-08-14 21:56:37 +000064 }
65 return false;
66}