blob: c381562b7cd1860e9c2c5d41a312aa55b33e50fb [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)
brianosman64d094d2016-03-25 06:01:59 -070018 , fDisableOutputConversionToSRGB(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) {
22 fXPFactory.reset(GrCoverageSetOpXPFactory::Create(regionOp, invertCoverage));
23}
24
joshualittb0a8a372014-09-23 09:50:21 -070025void GrPaint::addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
bsalomon4a339522015-10-06 08:40:50 -070026 this->addColorFragmentProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref();
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) {
bsalomon4a339522015-10-06 08:40:50 -070030 this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref();
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) {
bsalomon4a339522015-10-06 08:40:50 -070036 this->addColorFragmentProcessor(GrSimpleTextureEffect::Create(texture,
joshualittaf2533a2015-09-09 10:00:12 -070037 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) {
bsalomon4a339522015-10-06 08:40:50 -070043 this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Create(texture,
joshualittaf2533a2015-09-09 10:00:12 -070044 matrix, params))->unref();
commit-bot@chromium.org42dacab2013-07-13 17:24:24 +000045}
commit-bot@chromium.org24ab3b02013-08-14 21:56:37 +000046
cdalton1fa45722015-06-02 10:43:39 -070047bool GrPaint::isConstantBlendedColor(GrColor* color) const {
egdaniel9e4ecdc2014-12-18 12:44:55 -080048 GrProcOptInfo colorProcInfo;
bsalomonac856c92015-08-27 06:30:17 -070049 colorProcInfo.calcWithInitialValues(fColorFragmentProcessors.begin(),
50 this->numColorFragmentProcessors(), fColor,
egdaniel9e4ecdc2014-12-18 12:44:55 -080051 kRGBA_GrColorComponentFlags, false);
52
cdalton1fa45722015-06-02 10:43:39 -070053 GrXPFactory::InvariantBlendedColor blendedColor;
egdanielc4b72722015-11-23 13:20:41 -080054 if (fXPFactory) {
55 fXPFactory->getInvariantBlendedColor(colorProcInfo, &blendedColor);
56 } else {
57 GrPorterDuffXPFactory::SrcOverInvariantBlendedColor(colorProcInfo.color(),
58 colorProcInfo.validFlags(),
59 colorProcInfo.isOpaque(),
60 &blendedColor);
61 }
egdaniel9e4ecdc2014-12-18 12:44:55 -080062
cdalton1fa45722015-06-02 10:43:39 -070063 if (kRGBA_GrColorComponentFlags == blendedColor.fKnownColorFlags) {
64 *color = blendedColor.fKnownColor;
egdaniel9e4ecdc2014-12-18 12:44:55 -080065 return true;
commit-bot@chromium.org24ab3b02013-08-14 21:56:37 +000066 }
67 return false;
68}