blob: ee09a26c446326b47e4b670a5cec7037c170e3da [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())
Brian Salomonb74ef032017-08-10 12:46:01 -040018 , fTrivial(that.fTrivial)
19 , fColor(that.fColor) {
20 for (int i = 0; i < that.fColorFragmentProcessors.count(); ++i) {
21 fColorFragmentProcessors.push_back(that.fColorFragmentProcessors[i]->clone());
22 SkASSERT(fColorFragmentProcessors[i]);
23 }
24 for (int i = 0; i < that.fCoverageFragmentProcessors.count(); ++i) {
25 fCoverageFragmentProcessors.push_back(that.fCoverageFragmentProcessors[i]->clone());
26 SkASSERT(fCoverageFragmentProcessors[i]);
27 }
28}
29
Brian Salomon94cce4c2017-02-21 16:32:20 -050030void GrPaint::setPorterDuffXPFactory(SkBlendMode mode) {
Brian Salomon6d4b65e2017-05-03 17:06:09 -040031 this->setXPFactory(GrPorterDuffXPFactory::Get(mode));
Brian Salomon94cce4c2017-02-21 16:32:20 -050032}
33
egdanielb197b8f2015-02-17 07:34:43 -080034void GrPaint::setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage) {
Brian Salomon6d4b65e2017-05-03 17:06:09 -040035 this->setXPFactory(GrCoverageSetOpXPFactory::Get(regionOp, invertCoverage));
egdanielb197b8f2015-02-17 07:34:43 -080036}
37
Brian Osman2240be92017-10-18 13:15:13 -040038void GrPaint::addColorTextureProcessor(sk_sp<GrTextureProxy> proxy, const SkMatrix& matrix) {
39 this->addColorFragmentProcessor(GrSimpleTextureEffect::Make(std::move(proxy), matrix));
Robert Phillips901f29a2017-01-24 16:24:41 -050040}
41
Brian Osman2240be92017-10-18 13:15:13 -040042void GrPaint::addColorTextureProcessor(sk_sp<GrTextureProxy> proxy, const SkMatrix& matrix,
Brian Salomon2bbdcc42017-09-07 12:36:34 -040043 const GrSamplerState& samplerState) {
Brian Osman2240be92017-10-18 13:15:13 -040044 this->addColorFragmentProcessor(GrSimpleTextureEffect::Make(std::move(proxy), matrix,
45 samplerState));
Robert Phillips901f29a2017-01-24 16:24:41 -050046}
47
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040048void GrPaint::addCoverageTextureProcessor(sk_sp<GrTextureProxy> proxy,
Robert Phillips901f29a2017-01-24 16:24:41 -050049 const SkMatrix& matrix) {
Brian Osman2240be92017-10-18 13:15:13 -040050 this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Make(std::move(proxy), matrix));
Robert Phillips901f29a2017-01-24 16:24:41 -050051}
52
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040053void GrPaint::addCoverageTextureProcessor(sk_sp<GrTextureProxy> proxy,
Robert Phillips901f29a2017-01-24 16:24:41 -050054 const SkMatrix& matrix,
Brian Salomon2bbdcc42017-09-07 12:36:34 -040055 const GrSamplerState& params) {
Brian Osman2240be92017-10-18 13:15:13 -040056 this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Make(std::move(proxy), matrix,
57 params));
Robert Phillips901f29a2017-01-24 16:24:41 -050058}
Brian Salomon94cce4c2017-02-21 16:32:20 -050059
Brian Osman9a9baae2018-11-05 15:06:26 -050060bool GrPaint::isConstantBlendedColor(SkPMColor4f* constantColor) const {
Brian Salomon94cce4c2017-02-21 16:32:20 -050061 // This used to do a more sophisticated analysis but now it just explicitly looks for common
62 // cases.
63 static const GrXPFactory* kSrc = GrPorterDuffXPFactory::Get(SkBlendMode::kSrc);
64 static const GrXPFactory* kClear = GrPorterDuffXPFactory::Get(SkBlendMode::kClear);
65 if (kClear == fXPFactory) {
Brian Osman9a9baae2018-11-05 15:06:26 -050066 *constantColor = SK_PMColor4fTRANSPARENT;
Brian Salomon94cce4c2017-02-21 16:32:20 -050067 return true;
68 }
69 if (this->numColorFragmentProcessors()) {
70 return false;
71 }
72 if (kSrc == fXPFactory || (!fXPFactory && fColor.isOpaque())) {
Brian Osman9a9baae2018-11-05 15:06:26 -050073 *constantColor = fColor;
Brian Salomon94cce4c2017-02-21 16:32:20 -050074 return true;
75 }
76 return false;
77}