blob: e29c464bc08bd85f9cd475c9248ab12aedd03a89 [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"
Brian Salomon94cce4c2017-02-21 16:32:20 -05009#include "GrXferProcessor.h"
egdanielb197b8f2015-02-17 07:34:43 -080010#include "effects/GrCoverageSetOpXP.h"
egdaniel378092f2014-12-03 10:40:13 -080011#include "effects/GrPorterDuffXferProcessor.h"
commit-bot@chromium.org42dacab2013-07-13 17:24:24 +000012#include "effects/GrSimpleTextureEffect.h"
13
Brian Salomonb74ef032017-08-10 12:46:01 -040014GrPaint::GrPaint(const GrPaint& that)
15 : fXPFactory(that.fXPFactory)
16 , fColorFragmentProcessors(that.fColorFragmentProcessors.count())
17 , fCoverageFragmentProcessors(that.fCoverageFragmentProcessors.count())
18 , fDisableOutputConversionToSRGB(that.fDisableOutputConversionToSRGB)
19 , fAllowSRGBInputs(that.fAllowSRGBInputs)
20 , fTrivial(that.fTrivial)
21 , fColor(that.fColor) {
22 for (int i = 0; i < that.fColorFragmentProcessors.count(); ++i) {
23 fColorFragmentProcessors.push_back(that.fColorFragmentProcessors[i]->clone());
24 SkASSERT(fColorFragmentProcessors[i]);
25 }
26 for (int i = 0; i < that.fCoverageFragmentProcessors.count(); ++i) {
27 fCoverageFragmentProcessors.push_back(that.fCoverageFragmentProcessors[i]->clone());
28 SkASSERT(fCoverageFragmentProcessors[i]);
29 }
30}
31
Brian Salomon94cce4c2017-02-21 16:32:20 -050032void GrPaint::setPorterDuffXPFactory(SkBlendMode mode) {
Brian Salomon6d4b65e2017-05-03 17:06:09 -040033 this->setXPFactory(GrPorterDuffXPFactory::Get(mode));
Brian Salomon94cce4c2017-02-21 16:32:20 -050034}
35
egdanielb197b8f2015-02-17 07:34:43 -080036void GrPaint::setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage) {
Brian Salomon6d4b65e2017-05-03 17:06:09 -040037 this->setXPFactory(GrCoverageSetOpXPFactory::Get(regionOp, invertCoverage));
egdanielb197b8f2015-02-17 07:34:43 -080038}
39
Brian Osman2240be92017-10-18 13:15:13 -040040void GrPaint::addColorTextureProcessor(sk_sp<GrTextureProxy> proxy, const SkMatrix& matrix) {
41 this->addColorFragmentProcessor(GrSimpleTextureEffect::Make(std::move(proxy), matrix));
Robert Phillips901f29a2017-01-24 16:24:41 -050042}
43
Brian Osman2240be92017-10-18 13:15:13 -040044void GrPaint::addColorTextureProcessor(sk_sp<GrTextureProxy> proxy, const SkMatrix& matrix,
Brian Salomon2bbdcc42017-09-07 12:36:34 -040045 const GrSamplerState& samplerState) {
Brian Osman2240be92017-10-18 13:15:13 -040046 this->addColorFragmentProcessor(GrSimpleTextureEffect::Make(std::move(proxy), matrix,
47 samplerState));
Robert Phillips901f29a2017-01-24 16:24:41 -050048}
49
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040050void GrPaint::addCoverageTextureProcessor(sk_sp<GrTextureProxy> proxy,
Robert Phillips901f29a2017-01-24 16:24:41 -050051 const SkMatrix& matrix) {
Brian Osman2240be92017-10-18 13:15:13 -040052 this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Make(std::move(proxy), matrix));
Robert Phillips901f29a2017-01-24 16:24:41 -050053}
54
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040055void GrPaint::addCoverageTextureProcessor(sk_sp<GrTextureProxy> proxy,
Robert Phillips901f29a2017-01-24 16:24:41 -050056 const SkMatrix& matrix,
Brian Salomon2bbdcc42017-09-07 12:36:34 -040057 const GrSamplerState& params) {
Brian Osman2240be92017-10-18 13:15:13 -040058 this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Make(std::move(proxy), matrix,
59 params));
Robert Phillips901f29a2017-01-24 16:24:41 -050060}
Brian Salomon94cce4c2017-02-21 16:32:20 -050061
62bool GrPaint::isConstantBlendedColor(GrColor* constantColor) const {
63 // This used to do a more sophisticated analysis but now it just explicitly looks for common
64 // cases.
65 static const GrXPFactory* kSrc = GrPorterDuffXPFactory::Get(SkBlendMode::kSrc);
66 static const GrXPFactory* kClear = GrPorterDuffXPFactory::Get(SkBlendMode::kClear);
67 if (kClear == fXPFactory) {
68 *constantColor = GrColor_TRANSPARENT_BLACK;
69 return true;
70 }
71 if (this->numColorFragmentProcessors()) {
72 return false;
73 }
74 if (kSrc == fXPFactory || (!fXPFactory && fColor.isOpaque())) {
75 *constantColor = fColor.toGrColor();
76 return true;
77 }
78 return false;
79}