1/*
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 "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/GrTextureEffect.h"
13
14GrPaint::GrPaint(const GrPaint& that)
15 : fXPFactory(that.fXPFactory)
16 , fColorFragmentProcessors(that.fColorFragmentProcessors.count())
17 , fCoverageFragmentProcessors(that.fCoverageFragmentProcessors.count())
18 , 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
30void GrPaint::setPorterDuffXPFactory(SkBlendMode mode) {
31 this->setXPFactory(GrPorterDuffXPFactory::Get(mode));
32}
33
34void GrPaint::setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage) {
35 this->setXPFactory(GrCoverageSetOpXPFactory::Get(regionOp, invertCoverage));
36}
37
38bool GrPaint::isConstantBlendedColor(SkPMColor4f* constantColor) const {
39 // This used to do a more sophisticated analysis but now it just explicitly looks for common
40 // cases.
41 static const GrXPFactory* kSrc = GrPorterDuffXPFactory::Get(SkBlendMode::kSrc);
42 static const GrXPFactory* kClear = GrPorterDuffXPFactory::Get(SkBlendMode::kClear);
43 if (kClear == fXPFactory) {
44 *constantColor = SK_PMColor4fTRANSPARENT;
45 return true;
46 }
47 if (this->numColorFragmentProcessors()) {
48 return false;
49 }
50 if (kSrc == fXPFactory || (!fXPFactory && fColor.isOpaque())) {
51 *constantColor = fColor;
52 return true;
53 }
54 return false;
55}
56