blob: 424954349108d23abae76a7865510bc643d884b4 [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 , fTrivial(that.fTrivial)
17 , fColor(that.fColor) {
John Stiles6c452a52020-07-21 12:06:38 -040018 if (that.fColorFragmentProcessor) {
19 fColorFragmentProcessor = that.fColorFragmentProcessor->clone();
20 SkASSERT(fColorFragmentProcessor);
Brian Salomonb74ef032017-08-10 12:46:01 -040021 }
John Stiles41d91b62020-07-21 14:39:40 -040022 if (that.fCoverageFragmentProcessor) {
23 fCoverageFragmentProcessor = that.fCoverageFragmentProcessor->clone();
24 SkASSERT(fCoverageFragmentProcessor);
Brian Salomonb74ef032017-08-10 12:46:01 -040025 }
26}
27
Brian Salomon94cce4c2017-02-21 16:32:20 -050028void GrPaint::setPorterDuffXPFactory(SkBlendMode mode) {
Brian Salomon6d4b65e2017-05-03 17:06:09 -040029 this->setXPFactory(GrPorterDuffXPFactory::Get(mode));
Brian Salomon94cce4c2017-02-21 16:32:20 -050030}
31
egdanielb197b8f2015-02-17 07:34:43 -080032void GrPaint::setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage) {
Brian Salomon6d4b65e2017-05-03 17:06:09 -040033 this->setXPFactory(GrCoverageSetOpXPFactory::Get(regionOp, invertCoverage));
egdanielb197b8f2015-02-17 07:34:43 -080034}
35
Brian Osman9a9baae2018-11-05 15:06:26 -050036bool GrPaint::isConstantBlendedColor(SkPMColor4f* constantColor) const {
Brian Salomon94cce4c2017-02-21 16:32:20 -050037 // This used to do a more sophisticated analysis but now it just explicitly looks for common
38 // cases.
39 static const GrXPFactory* kSrc = GrPorterDuffXPFactory::Get(SkBlendMode::kSrc);
40 static const GrXPFactory* kClear = GrPorterDuffXPFactory::Get(SkBlendMode::kClear);
41 if (kClear == fXPFactory) {
Brian Osman9a9baae2018-11-05 15:06:26 -050042 *constantColor = SK_PMColor4fTRANSPARENT;
Brian Salomon94cce4c2017-02-21 16:32:20 -050043 return true;
44 }
John Stiles5933d7d2020-07-21 12:28:35 -040045 if (this->hasColorFragmentProcessor()) {
Brian Salomon94cce4c2017-02-21 16:32:20 -050046 return false;
47 }
48 if (kSrc == fXPFactory || (!fXPFactory && fColor.isOpaque())) {
Brian Osman9a9baae2018-11-05 15:06:26 -050049 *constantColor = fColor;
Brian Salomon94cce4c2017-02-21 16:32:20 -050050 return true;
51 }
52 return false;
53}