1cb93a386Sopenharmony_ci/*
2cb93a386Sopenharmony_ci * Copyright 2013 Google Inc.
3cb93a386Sopenharmony_ci *
4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be
5cb93a386Sopenharmony_ci * found in the LICENSE file.
6cb93a386Sopenharmony_ci */
7cb93a386Sopenharmony_ci
8cb93a386Sopenharmony_ci#include "src/gpu/GrPaint.h"
9cb93a386Sopenharmony_ci#include "src/gpu/GrXferProcessor.h"
10cb93a386Sopenharmony_ci#include "src/gpu/effects/GrCoverageSetOpXP.h"
11cb93a386Sopenharmony_ci#include "src/gpu/effects/GrPorterDuffXferProcessor.h"
12cb93a386Sopenharmony_ci#include "src/gpu/effects/GrTextureEffect.h"
13cb93a386Sopenharmony_ci
14cb93a386Sopenharmony_ciGrPaint::GrPaint(const GrPaint& that)
15cb93a386Sopenharmony_ci        : fXPFactory(that.fXPFactory)
16cb93a386Sopenharmony_ci        , fTrivial(that.fTrivial)
17cb93a386Sopenharmony_ci        , fColor(that.fColor) {
18cb93a386Sopenharmony_ci    if (that.fColorFragmentProcessor) {
19cb93a386Sopenharmony_ci        fColorFragmentProcessor = that.fColorFragmentProcessor->clone();
20cb93a386Sopenharmony_ci        SkASSERT(fColorFragmentProcessor);
21cb93a386Sopenharmony_ci    }
22cb93a386Sopenharmony_ci    if (that.fCoverageFragmentProcessor) {
23cb93a386Sopenharmony_ci        fCoverageFragmentProcessor = that.fCoverageFragmentProcessor->clone();
24cb93a386Sopenharmony_ci        SkASSERT(fCoverageFragmentProcessor);
25cb93a386Sopenharmony_ci    }
26cb93a386Sopenharmony_ci}
27cb93a386Sopenharmony_ci
28cb93a386Sopenharmony_civoid GrPaint::setPorterDuffXPFactory(SkBlendMode mode) {
29cb93a386Sopenharmony_ci    this->setXPFactory(GrPorterDuffXPFactory::Get(mode));
30cb93a386Sopenharmony_ci}
31cb93a386Sopenharmony_ci
32cb93a386Sopenharmony_civoid GrPaint::setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage) {
33cb93a386Sopenharmony_ci    this->setXPFactory(GrCoverageSetOpXPFactory::Get(regionOp, invertCoverage));
34cb93a386Sopenharmony_ci}
35cb93a386Sopenharmony_ci
36cb93a386Sopenharmony_cibool GrPaint::isConstantBlendedColor(SkPMColor4f* constantColor) const {
37cb93a386Sopenharmony_ci    // This used to do a more sophisticated analysis but now it just explicitly looks for common
38cb93a386Sopenharmony_ci    // cases.
39cb93a386Sopenharmony_ci    static const GrXPFactory* kSrc = GrPorterDuffXPFactory::Get(SkBlendMode::kSrc);
40cb93a386Sopenharmony_ci    static const GrXPFactory* kClear = GrPorterDuffXPFactory::Get(SkBlendMode::kClear);
41cb93a386Sopenharmony_ci    if (kClear == fXPFactory) {
42cb93a386Sopenharmony_ci        *constantColor = SK_PMColor4fTRANSPARENT;
43cb93a386Sopenharmony_ci        return true;
44cb93a386Sopenharmony_ci    }
45cb93a386Sopenharmony_ci    if (this->hasColorFragmentProcessor()) {
46cb93a386Sopenharmony_ci        return false;
47cb93a386Sopenharmony_ci    }
48cb93a386Sopenharmony_ci    if (kSrc == fXPFactory || (!fXPFactory && fColor.isOpaque())) {
49cb93a386Sopenharmony_ci        *constantColor = fColor;
50cb93a386Sopenharmony_ci        return true;
51cb93a386Sopenharmony_ci    }
52cb93a386Sopenharmony_ci    return false;
53cb93a386Sopenharmony_ci}
54