blob: 724c1be574f8e85c8509c5cbb96ac6d86155967e [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "src/gpu/GrPaint.h"
9#include "src/gpu/GrXferProcessor.h"
10#include "src/gpu/effects/GrCoverageSetOpXP.h"
11#include "src/gpu/effects/GrPorterDuffXferProcessor.h"
Brian Salomonb8f098d2020-01-07 11:15:44 -050012#include "src/gpu/effects/GrTextureEffect.h"
commit-bot@chromium.org42dacab2013-07-13 17:24:24 +000013
Brian Salomonb74ef032017-08-10 12:46:01 -040014GrPaint::GrPaint(const GrPaint& that)
15 : fXPFactory(that.fXPFactory)
Brian Salomonb74ef032017-08-10 12:46:01 -040016 , fCoverageFragmentProcessors(that.fCoverageFragmentProcessors.count())
Brian Salomonb74ef032017-08-10 12:46:01 -040017 , fTrivial(that.fTrivial)
18 , fColor(that.fColor) {
John Stiles6c452a52020-07-21 12:06:38 -040019 if (that.fColorFragmentProcessor) {
20 fColorFragmentProcessor = that.fColorFragmentProcessor->clone();
21 SkASSERT(fColorFragmentProcessor);
Brian Salomonb74ef032017-08-10 12:46:01 -040022 }
23 for (int i = 0; i < that.fCoverageFragmentProcessors.count(); ++i) {
24 fCoverageFragmentProcessors.push_back(that.fCoverageFragmentProcessors[i]->clone());
25 SkASSERT(fCoverageFragmentProcessors[i]);
26 }
27}
28
Brian Salomon94cce4c2017-02-21 16:32:20 -050029void GrPaint::setPorterDuffXPFactory(SkBlendMode mode) {
Brian Salomon6d4b65e2017-05-03 17:06:09 -040030 this->setXPFactory(GrPorterDuffXPFactory::Get(mode));
Brian Salomon94cce4c2017-02-21 16:32:20 -050031}
32
egdanielb197b8f2015-02-17 07:34:43 -080033void GrPaint::setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage) {
Brian Salomon6d4b65e2017-05-03 17:06:09 -040034 this->setXPFactory(GrCoverageSetOpXPFactory::Get(regionOp, invertCoverage));
egdanielb197b8f2015-02-17 07:34:43 -080035}
36
Brian Osman9a9baae2018-11-05 15:06:26 -050037bool GrPaint::isConstantBlendedColor(SkPMColor4f* constantColor) const {
Brian Salomon94cce4c2017-02-21 16:32:20 -050038 // This used to do a more sophisticated analysis but now it just explicitly looks for common
39 // cases.
40 static const GrXPFactory* kSrc = GrPorterDuffXPFactory::Get(SkBlendMode::kSrc);
41 static const GrXPFactory* kClear = GrPorterDuffXPFactory::Get(SkBlendMode::kClear);
42 if (kClear == fXPFactory) {
Brian Osman9a9baae2018-11-05 15:06:26 -050043 *constantColor = SK_PMColor4fTRANSPARENT;
Brian Salomon94cce4c2017-02-21 16:32:20 -050044 return true;
45 }
John Stiles5933d7d2020-07-21 12:28:35 -040046 if (this->hasColorFragmentProcessor()) {
Brian Salomon94cce4c2017-02-21 16:32:20 -050047 return false;
48 }
49 if (kSrc == fXPFactory || (!fXPFactory && fColor.isOpaque())) {
Brian Osman9a9baae2018-11-05 15:06:26 -050050 *constantColor = fColor;
Brian Salomon94cce4c2017-02-21 16:32:20 -050051 return true;
52 }
53 return false;
54}