blob: bc7f5384a8275d6a6cae1fe3394eddcf54a4b1ce [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"
12#include "src/gpu/effects/generated/GrSimpleTextureEffect.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)
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 Salomon078e8fa2019-11-22 04:10:18 +000038void GrPaint::addColorTextureProcessor(sk_sp<GrTextureProxy> proxy, GrColorType srcColorType,
39 const SkMatrix& matrix) {
40 this->addColorFragmentProcessor(GrSimpleTextureEffect::Make(std::move(proxy), srcColorType,
41 matrix));
42}
43
44void GrPaint::addColorTextureProcessor(sk_sp<GrTextureProxy> proxy, GrColorType srcColorType,
Greg Danielc594e622019-10-15 14:01:49 -040045 const SkMatrix& matrix, const GrSamplerState& samplerState) {
Brian Salomon078e8fa2019-11-22 04:10:18 +000046 this->addColorFragmentProcessor(GrSimpleTextureEffect::Make(std::move(proxy), srcColorType,
47 matrix, samplerState));
Robert Phillips901f29a2017-01-24 16:24:41 -050048}
Brian Salomon94cce4c2017-02-21 16:32:20 -050049
Brian Osman9a9baae2018-11-05 15:06:26 -050050bool GrPaint::isConstantBlendedColor(SkPMColor4f* constantColor) const {
Brian Salomon94cce4c2017-02-21 16:32:20 -050051 // This used to do a more sophisticated analysis but now it just explicitly looks for common
52 // cases.
53 static const GrXPFactory* kSrc = GrPorterDuffXPFactory::Get(SkBlendMode::kSrc);
54 static const GrXPFactory* kClear = GrPorterDuffXPFactory::Get(SkBlendMode::kClear);
55 if (kClear == fXPFactory) {
Brian Osman9a9baae2018-11-05 15:06:26 -050056 *constantColor = SK_PMColor4fTRANSPARENT;
Brian Salomon94cce4c2017-02-21 16:32:20 -050057 return true;
58 }
59 if (this->numColorFragmentProcessors()) {
60 return false;
61 }
62 if (kSrc == fXPFactory || (!fXPFactory && fColor.isOpaque())) {
Brian Osman9a9baae2018-11-05 15:06:26 -050063 *constantColor = fColor;
Brian Salomon94cce4c2017-02-21 16:32:20 -050064 return true;
65 }
66 return false;
67}