blob: dc1644b014d76edd01ae2fd9acc444a5dfbe79e8 [file] [log] [blame]
commit-bot@chromium.org42dacab2013-07-13 17:24:24 +00001
2/*
3 * Copyright 2013 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9#include "GrPaint.h"
10
egdanielb6cbc382014-11-13 11:00:34 -080011#include "GrProcOptInfo.h"
egdanielb197b8f2015-02-17 07:34:43 -080012#include "effects/GrCoverageSetOpXP.h"
egdaniel378092f2014-12-03 10:40:13 -080013#include "effects/GrPorterDuffXferProcessor.h"
commit-bot@chromium.org42dacab2013-07-13 17:24:24 +000014#include "effects/GrSimpleTextureEffect.h"
15
joshualitt2fdeda02015-01-22 07:11:44 -080016GrPaint::GrPaint()
17 : fAntiAlias(false)
18 , fDither(false)
joshualitt5b4f05f2015-07-10 07:26:21 -070019 , fColor(GrColor_WHITE)
halcanary385fe4d2015-08-26 13:07:48 -070020 , fProcDataManager(new GrProcessorDataManager) {}
joshualitt2fdeda02015-01-22 07:11:44 -080021
egdanielb197b8f2015-02-17 07:34:43 -080022void GrPaint::setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage) {
23 fXPFactory.reset(GrCoverageSetOpXPFactory::Create(regionOp, invertCoverage));
24}
25
joshualittb0a8a372014-09-23 09:50:21 -070026void GrPaint::addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
bsalomonac856c92015-08-27 06:30:17 -070027 this->addColorFragmentProcessor(GrSimpleTextureEffect::Create(fProcDataManager, texture,
joshualitt5f10b5c2015-07-09 10:24:35 -070028 matrix))->unref();
commit-bot@chromium.org42dacab2013-07-13 17:24:24 +000029}
30
joshualittb0a8a372014-09-23 09:50:21 -070031void GrPaint::addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
bsalomonac856c92015-08-27 06:30:17 -070032 this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Create(fProcDataManager, texture,
joshualitt5f10b5c2015-07-09 10:24:35 -070033 matrix))->unref();
commit-bot@chromium.org42dacab2013-07-13 17:24:24 +000034}
35
joshualittb0a8a372014-09-23 09:50:21 -070036void GrPaint::addColorTextureProcessor(GrTexture* texture,
joshualitt40d4bd82014-12-29 09:04:40 -080037 const SkMatrix& matrix,
38 const GrTextureParams& params) {
bsalomonac856c92015-08-27 06:30:17 -070039 this->addColorFragmentProcessor(GrSimpleTextureEffect::Create(fProcDataManager, texture, matrix,
joshualitt5f10b5c2015-07-09 10:24:35 -070040 params))->unref();
commit-bot@chromium.org42dacab2013-07-13 17:24:24 +000041}
42
joshualittb0a8a372014-09-23 09:50:21 -070043void GrPaint::addCoverageTextureProcessor(GrTexture* texture,
joshualitt40d4bd82014-12-29 09:04:40 -080044 const SkMatrix& matrix,
45 const GrTextureParams& params) {
bsalomonac856c92015-08-27 06:30:17 -070046 this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Create(fProcDataManager, texture, matrix,
joshualitt5f10b5c2015-07-09 10:24:35 -070047 params))->unref();
commit-bot@chromium.org42dacab2013-07-13 17:24:24 +000048}
commit-bot@chromium.org24ab3b02013-08-14 21:56:37 +000049
cdalton1fa45722015-06-02 10:43:39 -070050bool GrPaint::isConstantBlendedColor(GrColor* color) const {
egdaniel9e4ecdc2014-12-18 12:44:55 -080051 GrProcOptInfo colorProcInfo;
bsalomonac856c92015-08-27 06:30:17 -070052 colorProcInfo.calcWithInitialValues(fColorFragmentProcessors.begin(),
53 this->numColorFragmentProcessors(), fColor,
egdaniel9e4ecdc2014-12-18 12:44:55 -080054 kRGBA_GrColorComponentFlags, false);
55
cdalton1fa45722015-06-02 10:43:39 -070056 GrXPFactory::InvariantBlendedColor blendedColor;
57 fXPFactory->getInvariantBlendedColor(colorProcInfo, &blendedColor);
egdaniel9e4ecdc2014-12-18 12:44:55 -080058
cdalton1fa45722015-06-02 10:43:39 -070059 if (kRGBA_GrColorComponentFlags == blendedColor.fKnownColorFlags) {
60 *color = blendedColor.fKnownColor;
egdaniel9e4ecdc2014-12-18 12:44:55 -080061 return true;
commit-bot@chromium.org24ab3b02013-08-14 21:56:37 +000062 }
63 return false;
64}