blob: 7d89535a11c7be1d1b2ace710c0b650af2f9a555 [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
commit-bot@chromium.org24ab3b02013-08-14 21:56:37 +000011#include "GrBlend.h"
egdanielb6cbc382014-11-13 11:00:34 -080012#include "GrProcOptInfo.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
35bool GrPaint::isOpaque() const {
36 return this->getOpaqueAndKnownColor(NULL, NULL);
37}
38
39bool GrPaint::isOpaqueAndConstantColor(GrColor* color) const {
egdanielb6cbc382014-11-13 11:00:34 -080040 GrColor tempColor = 0;
41 uint32_t colorComps = 0;
commit-bot@chromium.org24ab3b02013-08-14 21:56:37 +000042 if (this->getOpaqueAndKnownColor(&tempColor, &colorComps)) {
43 if (kRGBA_GrColorComponentFlags == colorComps) {
44 *color = tempColor;
45 return true;
46 }
47 }
48 return false;
49}
50
51bool GrPaint::getOpaqueAndKnownColor(GrColor* solidColor,
52 uint32_t* solidColorKnownComponents) const {
53
54 // TODO: Share this implementation with GrDrawState
egdanielb6cbc382014-11-13 11:00:34 -080055
56 GrProcOptInfo coverageProcInfo;
57 coverageProcInfo.calcWithInitialValues(fCoverageStages.begin(), this->numCoverageStages(),
58 0xFFFFFFFF, kRGBA_GrColorComponentFlags, true);
commit-bot@chromium.org24ab3b02013-08-14 21:56:37 +000059
egdanielb6cbc382014-11-13 11:00:34 -080060 if (!coverageProcInfo.isSolidWhite()) {
commit-bot@chromium.org24ab3b02013-08-14 21:56:37 +000061 return false;
62 }
63
egdanielb6cbc382014-11-13 11:00:34 -080064 GrProcOptInfo colorProcInfo;
65 colorProcInfo.calcWithInitialValues(fColorStages.begin(), this->numColorStages(), fColor,
66 kRGBA_GrColorComponentFlags, false);
commit-bot@chromium.org24ab3b02013-08-14 21:56:37 +000067
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000068 SkASSERT((NULL == solidColor) == (NULL == solidColorKnownComponents));
commit-bot@chromium.org24ab3b02013-08-14 21:56:37 +000069
70 GrBlendCoeff srcCoeff = fSrcBlendCoeff;
71 GrBlendCoeff dstCoeff = fDstBlendCoeff;
egdanielb6cbc382014-11-13 11:00:34 -080072 GrSimplifyBlend(&srcCoeff, &dstCoeff, colorProcInfo.color(), colorProcInfo.validFlags(),
egdaniel1a8ecdf2014-10-03 06:24:12 -070073 0, 0, 0);
commit-bot@chromium.org24ab3b02013-08-14 21:56:37 +000074
75 bool opaque = kZero_GrBlendCoeff == dstCoeff && !GrBlendCoeffRefsDst(srcCoeff);
bsalomon49f085d2014-09-05 13:34:00 -070076 if (solidColor) {
commit-bot@chromium.org24ab3b02013-08-14 21:56:37 +000077 if (opaque) {
78 switch (srcCoeff) {
79 case kZero_GrBlendCoeff:
80 *solidColor = 0;
81 *solidColorKnownComponents = kRGBA_GrColorComponentFlags;
82 break;
83
84 case kOne_GrBlendCoeff:
egdanielb6cbc382014-11-13 11:00:34 -080085 *solidColor = colorProcInfo.color();
86 *solidColorKnownComponents = colorProcInfo.validFlags();
commit-bot@chromium.org24ab3b02013-08-14 21:56:37 +000087 break;
88
89 // The src coeff should never refer to the src and if it refers to dst then opaque
90 // should have been false.
91 case kSC_GrBlendCoeff:
92 case kISC_GrBlendCoeff:
93 case kDC_GrBlendCoeff:
94 case kIDC_GrBlendCoeff:
95 case kSA_GrBlendCoeff:
96 case kISA_GrBlendCoeff:
97 case kDA_GrBlendCoeff:
98 case kIDA_GrBlendCoeff:
99 default:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000100 SkFAIL("srcCoeff should not refer to src or dst.");
commit-bot@chromium.org24ab3b02013-08-14 21:56:37 +0000101 break;
102
103 // TODO: update this once GrPaint actually has a const color.
104 case kConstC_GrBlendCoeff:
105 case kIConstC_GrBlendCoeff:
106 case kConstA_GrBlendCoeff:
107 case kIConstA_GrBlendCoeff:
108 *solidColorKnownComponents = 0;
109 break;
110 }
111 } else {
112 solidColorKnownComponents = 0;
113 }
114 }
115 return opaque;
116}