blob: 19977963309b94fa8c666a8b7c1b550882ef147b [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"
egdaniel378092f2014-12-03 10:40:13 -080012#include "effects/GrPorterDuffXferProcessor.h"
commit-bot@chromium.org42dacab2013-07-13 17:24:24 +000013#include "effects/GrSimpleTextureEffect.h"
14
joshualittb0a8a372014-09-23 09:50:21 -070015void GrPaint::addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
16 this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref();
commit-bot@chromium.org42dacab2013-07-13 17:24:24 +000017}
18
joshualittb0a8a372014-09-23 09:50:21 -070019void GrPaint::addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
20 this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref();
commit-bot@chromium.org42dacab2013-07-13 17:24:24 +000021}
22
joshualittb0a8a372014-09-23 09:50:21 -070023void GrPaint::addColorTextureProcessor(GrTexture* texture,
commit-bot@chromium.org42dacab2013-07-13 17:24:24 +000024 const SkMatrix& matrix,
25 const GrTextureParams& params) {
joshualittb0a8a372014-09-23 09:50:21 -070026 this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix, params))->unref();
commit-bot@chromium.org42dacab2013-07-13 17:24:24 +000027}
28
joshualittb0a8a372014-09-23 09:50:21 -070029void GrPaint::addCoverageTextureProcessor(GrTexture* texture,
commit-bot@chromium.org42dacab2013-07-13 17:24:24 +000030 const SkMatrix& matrix,
31 const GrTextureParams& params) {
joshualittb0a8a372014-09-23 09:50:21 -070032 this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix, params))->unref();
commit-bot@chromium.org42dacab2013-07-13 17:24:24 +000033}
commit-bot@chromium.org24ab3b02013-08-14 21:56:37 +000034
commit-bot@chromium.org24ab3b02013-08-14 21:56:37 +000035bool GrPaint::isOpaqueAndConstantColor(GrColor* color) const {
egdaniel9e4ecdc2014-12-18 12:44:55 -080036 GrProcOptInfo coverageProcInfo;
37 coverageProcInfo.calcWithInitialValues(fCoverageStages.begin(), this->numCoverageStages(),
38 0xFFFFFFFF, kRGBA_GrColorComponentFlags, true);
39 GrProcOptInfo colorProcInfo;
40 colorProcInfo.calcWithInitialValues(fColorStages.begin(), this->numColorStages(), fColor,
41 kRGBA_GrColorComponentFlags, false);
42
43 GrXPFactory::InvariantOutput output;
44 fXPFactory->getInvariantOutput(colorProcInfo, coverageProcInfo, true, &output);
45
46 if (kRGBA_GrColorComponentFlags == output.fBlendedColorFlags &&
47 0xFF == GrColorUnpackA(output.fBlendedColor)) {
48 *color = output.fBlendedColor;
49 return true;
commit-bot@chromium.org24ab3b02013-08-14 21:56:37 +000050 }
51 return false;
52}
53
egdaniel378092f2014-12-03 10:40:13 -080054void GrPaint::resetStages() {
55 fColorStages.reset();
56 fCoverageStages.reset();
egdaniel95131432014-12-09 11:15:43 -080057 fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode));
egdaniel378092f2014-12-03 10:40:13 -080058}
59