bsalomon@google.com | af84e74 | 2012-10-05 13:23:24 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 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 "GrDrawState.h" |
bsalomon@google.com | af84e74 | 2012-10-05 13:23:24 +0000 | [diff] [blame] | 9 | #include "GrPaint.h" |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 10 | #include "GrDrawTargetCaps.h" |
bsalomon@google.com | af84e74 | 2012-10-05 13:23:24 +0000 | [diff] [blame] | 11 | |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 12 | //////////////////////////////////////////////////////////////////////////////s |
| 13 | |
| 14 | GrDrawState::CombinedState GrDrawState::CombineIfPossible( |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 15 | const GrDrawState& a, const GrDrawState& b, const GrDrawTargetCaps& caps) { |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 16 | |
egdaniel | 21aed57 | 2014-08-26 12:24:06 -0700 | [diff] [blame] | 17 | if (!a.isEqual(b)) { |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 18 | return kIncompatible_CombinedState; |
| 19 | } |
| 20 | |
egdaniel | 21aed57 | 2014-08-26 12:24:06 -0700 | [diff] [blame] | 21 | // If the general draw states are equal (from check above) we know hasColorVertexAttribute() |
| 22 | // is equivalent for both a and b |
| 23 | if (a.hasColorVertexAttribute()) { |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 24 | // If one is opaque and the other is not then the combined state is not opaque. Moreover, |
| 25 | // if the opaqueness affects the ability to get color/coverage blending correct then we |
| 26 | // don't combine the draw states. |
| 27 | bool aIsOpaque = (kVertexColorsAreOpaque_Hint & a.fHints); |
| 28 | bool bIsOpaque = (kVertexColorsAreOpaque_Hint & b.fHints); |
| 29 | if (aIsOpaque != bIsOpaque) { |
| 30 | const GrDrawState* opaque; |
| 31 | const GrDrawState* nonOpaque; |
| 32 | if (aIsOpaque) { |
| 33 | opaque = &a; |
| 34 | nonOpaque = &b; |
| 35 | } else { |
| 36 | opaque = &b; |
| 37 | nonOpaque = &a; |
| 38 | } |
| 39 | if (!opaque->hasSolidCoverage() && opaque->couldApplyCoverage(caps)) { |
| 40 | SkASSERT(!nonOpaque->hasSolidCoverage()); |
| 41 | if (!nonOpaque->couldApplyCoverage(caps)) { |
| 42 | return kIncompatible_CombinedState; |
| 43 | } |
| 44 | } |
| 45 | return aIsOpaque ? kB_CombinedState : kA_CombinedState; |
| 46 | } |
| 47 | } |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 48 | return kAOrB_CombinedState; |
| 49 | } |
| 50 | |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 51 | //////////////////////////////////////////////////////////////////////////////s |
| 52 | |
| 53 | GrDrawState::GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatrix) { |
| 54 | SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
| 55 | *this = state; |
| 56 | if (!preConcatMatrix.isIdentity()) { |
egdaniel | 776bdbd | 2014-08-06 11:07:02 -0700 | [diff] [blame] | 57 | for (int i = 0; i < this->numColorStages(); ++i) { |
egdaniel | 8cbf3d5 | 2014-08-21 06:27:22 -0700 | [diff] [blame] | 58 | fColorStages[i].localCoordChange(preConcatMatrix); |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 59 | } |
egdaniel | 776bdbd | 2014-08-06 11:07:02 -0700 | [diff] [blame] | 60 | for (int i = 0; i < this->numCoverageStages(); ++i) { |
egdaniel | 8cbf3d5 | 2014-08-21 06:27:22 -0700 | [diff] [blame] | 61 | fCoverageStages[i].localCoordChange(preConcatMatrix); |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 62 | } |
| 63 | this->invalidateBlendOptFlags(); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | GrDrawState& GrDrawState::operator=(const GrDrawState& that) { |
| 68 | SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); |
| 69 | this->setRenderTarget(that.fRenderTarget.get()); |
| 70 | fColor = that.fColor; |
| 71 | fViewMatrix = that.fViewMatrix; |
egdaniel | 8cbf3d5 | 2014-08-21 06:27:22 -0700 | [diff] [blame] | 72 | fSrcBlend = that.fSrcBlend; |
| 73 | fDstBlend = that.fDstBlend; |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 74 | fBlendConstant = that.fBlendConstant; |
| 75 | fFlagBits = that.fFlagBits; |
| 76 | fVACount = that.fVACount; |
| 77 | fVAPtr = that.fVAPtr; |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame^] | 78 | fVAStride = that.fVAStride; |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 79 | fStencilSettings = that.fStencilSettings; |
| 80 | fCoverage = that.fCoverage; |
| 81 | fDrawFace = that.fDrawFace; |
egdaniel | 8cbf3d5 | 2014-08-21 06:27:22 -0700 | [diff] [blame] | 82 | fColorStages = that.fColorStages; |
| 83 | fCoverageStages = that.fCoverageStages; |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 84 | fOptSrcBlend = that.fOptSrcBlend; |
| 85 | fOptDstBlend = that.fOptDstBlend; |
| 86 | fBlendOptFlags = that.fBlendOptFlags; |
| 87 | |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 88 | fHints = that.fHints; |
egdaniel | 776bdbd | 2014-08-06 11:07:02 -0700 | [diff] [blame] | 89 | |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 90 | memcpy(fFixedFunctionVertexAttribIndices, |
| 91 | that.fFixedFunctionVertexAttribIndices, |
| 92 | sizeof(fFixedFunctionVertexAttribIndices)); |
| 93 | return *this; |
| 94 | } |
| 95 | |
| 96 | void GrDrawState::onReset(const SkMatrix* initialViewMatrix) { |
| 97 | SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); |
egdaniel | 8cbf3d5 | 2014-08-21 06:27:22 -0700 | [diff] [blame] | 98 | fColorStages.reset(); |
| 99 | fCoverageStages.reset(); |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 100 | |
| 101 | fRenderTarget.reset(NULL); |
| 102 | |
| 103 | this->setDefaultVertexAttribs(); |
| 104 | |
| 105 | fColor = 0xffffffff; |
| 106 | if (NULL == initialViewMatrix) { |
| 107 | fViewMatrix.reset(); |
| 108 | } else { |
| 109 | fViewMatrix = *initialViewMatrix; |
| 110 | } |
egdaniel | 8cbf3d5 | 2014-08-21 06:27:22 -0700 | [diff] [blame] | 111 | fSrcBlend = kOne_GrBlendCoeff; |
| 112 | fDstBlend = kZero_GrBlendCoeff; |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 113 | fBlendConstant = 0x0; |
| 114 | fFlagBits = 0x0; |
| 115 | fStencilSettings.setDisabled(); |
egdaniel | 8cbf3d5 | 2014-08-21 06:27:22 -0700 | [diff] [blame] | 116 | fCoverage = 0xff; |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 117 | fDrawFace = kBoth_DrawFace; |
| 118 | |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 119 | fHints = 0; |
| 120 | |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 121 | this->invalidateBlendOptFlags(); |
| 122 | } |
| 123 | |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 124 | bool GrDrawState::setIdentityViewMatrix() { |
egdaniel | 776bdbd | 2014-08-06 11:07:02 -0700 | [diff] [blame] | 125 | if (this->numTotalStages()) { |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 126 | SkMatrix invVM; |
bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 127 | if (!fViewMatrix.invert(&invVM)) { |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 128 | // sad trombone sound |
| 129 | return false; |
| 130 | } |
egdaniel | 776bdbd | 2014-08-06 11:07:02 -0700 | [diff] [blame] | 131 | for (int s = 0; s < this->numColorStages(); ++s) { |
egdaniel | 8cbf3d5 | 2014-08-21 06:27:22 -0700 | [diff] [blame] | 132 | fColorStages[s].localCoordChange(invVM); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 133 | } |
egdaniel | 776bdbd | 2014-08-06 11:07:02 -0700 | [diff] [blame] | 134 | for (int s = 0; s < this->numCoverageStages(); ++s) { |
egdaniel | 8cbf3d5 | 2014-08-21 06:27:22 -0700 | [diff] [blame] | 135 | fCoverageStages[s].localCoordChange(invVM); |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 136 | } |
| 137 | } |
bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 138 | fViewMatrix.reset(); |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 139 | return true; |
| 140 | } |
| 141 | |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 142 | void GrDrawState::setFromPaint(const GrPaint& paint, const SkMatrix& vm, GrRenderTarget* rt) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 143 | SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 144 | |
egdaniel | 8cbf3d5 | 2014-08-21 06:27:22 -0700 | [diff] [blame] | 145 | fColorStages.reset(); |
| 146 | fCoverageStages.reset(); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 147 | |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 148 | for (int i = 0; i < paint.numColorStages(); ++i) { |
egdaniel | 8cbf3d5 | 2014-08-21 06:27:22 -0700 | [diff] [blame] | 149 | fColorStages.push_back(paint.getColorStage(i)); |
bsalomon@google.com | af84e74 | 2012-10-05 13:23:24 +0000 | [diff] [blame] | 150 | } |
| 151 | |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 152 | for (int i = 0; i < paint.numCoverageStages(); ++i) { |
egdaniel | 8cbf3d5 | 2014-08-21 06:27:22 -0700 | [diff] [blame] | 153 | fCoverageStages.push_back(paint.getCoverageStage(i)); |
bsalomon@google.com | af84e74 | 2012-10-05 13:23:24 +0000 | [diff] [blame] | 154 | } |
| 155 | |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 156 | this->setRenderTarget(rt); |
bsalomon@google.com | af84e74 | 2012-10-05 13:23:24 +0000 | [diff] [blame] | 157 | |
bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 158 | fViewMatrix = vm; |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 159 | |
| 160 | // These have no equivalent in GrPaint, set them to defaults |
bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 161 | fBlendConstant = 0x0; |
| 162 | fDrawFace = kBoth_DrawFace; |
| 163 | fStencilSettings.setDisabled(); |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 164 | this->resetStateFlags(); |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 165 | fHints = 0; |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 166 | |
bsalomon@google.com | 21c10c5 | 2013-06-13 17:44:07 +0000 | [diff] [blame] | 167 | // Enable the clip bit |
| 168 | this->enableState(GrDrawState::kClip_StateBit); |
| 169 | |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 170 | this->setColor(paint.getColor()); |
bsalomon@google.com | c7448ce | 2012-10-05 19:04:13 +0000 | [diff] [blame] | 171 | this->setState(GrDrawState::kDither_StateBit, paint.isDither()); |
| 172 | this->setState(GrDrawState::kHWAntialias_StateBit, paint.isAntiAlias()); |
bsalomon@google.com | af84e74 | 2012-10-05 13:23:24 +0000 | [diff] [blame] | 173 | |
bsalomon@google.com | c7448ce | 2012-10-05 19:04:13 +0000 | [diff] [blame] | 174 | this->setBlendFunc(paint.getSrcBlendCoeff(), paint.getDstBlendCoeff()); |
bsalomon@google.com | c7448ce | 2012-10-05 19:04:13 +0000 | [diff] [blame] | 175 | this->setCoverage(paint.getCoverage()); |
egdaniel | 9514d24 | 2014-07-18 06:15:43 -0700 | [diff] [blame] | 176 | this->invalidateBlendOptFlags(); |
bsalomon@google.com | af84e74 | 2012-10-05 13:23:24 +0000 | [diff] [blame] | 177 | } |
bsalomon@google.com | 5b3e890 | 2012-10-05 20:13:28 +0000 | [diff] [blame] | 178 | |
| 179 | //////////////////////////////////////////////////////////////////////////////// |
| 180 | |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame^] | 181 | static void validate_vertex_attribs(const GrVertexAttrib* attribs, int count, size_t stride) { |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 182 | // this works as long as we're 4 byte-aligned |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 183 | #ifdef SK_DEBUG |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 184 | uint32_t overlapCheck = 0; |
egdaniel | 21aed57 | 2014-08-26 12:24:06 -0700 | [diff] [blame] | 185 | SkASSERT(count <= GrRODrawState::kMaxVertexAttribCnt); |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 186 | for (int index = 0; index < count; ++index) { |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 187 | size_t attribSize = GrVertexAttribTypeSize(attribs[index].fType); |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame^] | 188 | size_t attribOffset = attribs[index].fOffset; |
| 189 | SkASSERT(attribOffset + attribSize <= stride); |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 190 | size_t dwordCount = attribSize >> 2; |
| 191 | uint32_t mask = (1 << dwordCount)-1; |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame^] | 192 | size_t offsetShift = attribOffset >> 2; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 193 | SkASSERT(!(overlapCheck & (mask << offsetShift))); |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 194 | overlapCheck |= (mask << offsetShift); |
djsollen | ea81ced | 2014-08-27 13:07:34 -0700 | [diff] [blame] | 195 | } |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame^] | 196 | #endif |
jvanverth@google.com | cc78238 | 2013-01-28 20:39:48 +0000 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | //////////////////////////////////////////////////////////////////////////////// |
| 200 | |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame^] | 201 | void GrDrawState::internalSetVertexAttribs(const GrVertexAttrib* attribs, int count, |
| 202 | size_t stride) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 203 | SkASSERT(count <= kMaxVertexAttribCnt); |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 204 | |
bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 205 | fVAPtr = attribs; |
| 206 | fVACount = count; |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame^] | 207 | fVAStride = stride; |
| 208 | validate_vertex_attribs(fVAPtr, fVACount, fVAStride); |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 209 | |
| 210 | // Set all the indices to -1 |
bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 211 | memset(fFixedFunctionVertexAttribIndices, |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 212 | 0xff, |
bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 213 | sizeof(fFixedFunctionVertexAttribIndices)); |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 214 | #ifdef SK_DEBUG |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 215 | uint32_t overlapCheck = 0; |
| 216 | #endif |
| 217 | for (int i = 0; i < count; ++i) { |
| 218 | if (attribs[i].fBinding < kGrFixedFunctionVertexAttribBindingCnt) { |
| 219 | // The fixed function attribs can only be specified once |
bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 220 | SkASSERT(-1 == fFixedFunctionVertexAttribIndices[attribs[i].fBinding]); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 221 | SkASSERT(GrFixedFunctionVertexAttribVectorCount(attribs[i].fBinding) == |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 222 | GrVertexAttribTypeVectorCount(attribs[i].fType)); |
bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 223 | fFixedFunctionVertexAttribIndices[attribs[i].fBinding] = i; |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 224 | } |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 225 | #ifdef SK_DEBUG |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 226 | size_t dwordCount = GrVertexAttribTypeSize(attribs[i].fType) >> 2; |
| 227 | uint32_t mask = (1 << dwordCount)-1; |
| 228 | size_t offsetShift = attribs[i].fOffset >> 2; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 229 | SkASSERT(!(overlapCheck & (mask << offsetShift))); |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 230 | overlapCheck |= (mask << offsetShift); |
| 231 | #endif |
jvanverth@google.com | cc78238 | 2013-01-28 20:39:48 +0000 | [diff] [blame] | 232 | } |
egdaniel | 9514d24 | 2014-07-18 06:15:43 -0700 | [diff] [blame] | 233 | this->invalidateBlendOptFlags(); |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 234 | // Positions must be specified. |
bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 235 | SkASSERT(-1 != fFixedFunctionVertexAttribIndices[kPosition_GrVertexAttribBinding]); |
jvanverth@google.com | cc78238 | 2013-01-28 20:39:48 +0000 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | //////////////////////////////////////////////////////////////////////////////// |
| 239 | |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 240 | void GrDrawState::setDefaultVertexAttribs() { |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 241 | static const GrVertexAttrib kPositionAttrib = |
| 242 | {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}; |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 243 | |
bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 244 | fVAPtr = &kPositionAttrib; |
| 245 | fVACount = 1; |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame^] | 246 | fVAStride = GrVertexAttribTypeSize(kVec2f_GrVertexAttribType); |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 247 | |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 248 | // set all the fixed function indices to -1 except position. |
bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 249 | memset(fFixedFunctionVertexAttribIndices, |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 250 | 0xff, |
bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 251 | sizeof(fFixedFunctionVertexAttribIndices)); |
| 252 | fFixedFunctionVertexAttribIndices[kPosition_GrVertexAttribBinding] = 0; |
egdaniel | 9514d24 | 2014-07-18 06:15:43 -0700 | [diff] [blame] | 253 | this->invalidateBlendOptFlags(); |
jvanverth@google.com | cc78238 | 2013-01-28 20:39:48 +0000 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | //////////////////////////////////////////////////////////////////////////////// |
| 257 | |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 258 | bool GrDrawState::couldApplyCoverage(const GrDrawTargetCaps& caps) const { |
| 259 | if (caps.dualSourceBlendingSupport()) { |
| 260 | return true; |
| 261 | } |
| 262 | // we can correctly apply coverage if a) we have dual source blending |
| 263 | // or b) one of our blend optimizations applies |
| 264 | // or c) the src, dst blend coeffs are 1,0 and we will read Dst Color |
| 265 | GrBlendCoeff srcCoeff; |
| 266 | GrBlendCoeff dstCoeff; |
egdaniel | 21aed57 | 2014-08-26 12:24:06 -0700 | [diff] [blame] | 267 | GrRODrawState::BlendOptFlags flag = this->getBlendOpts(true, &srcCoeff, &dstCoeff); |
| 268 | return GrRODrawState::kNone_BlendOpt != flag || |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 269 | (this->willEffectReadDstColor() && |
| 270 | kOne_GrBlendCoeff == srcCoeff && kZero_GrBlendCoeff == dstCoeff); |
| 271 | } |
| 272 | |
egdaniel | 21aed57 | 2014-08-26 12:24:06 -0700 | [diff] [blame] | 273 | ////////////////////////////////////////////////////////////////////////////// |
jvanverth@google.com | cc78238 | 2013-01-28 20:39:48 +0000 | [diff] [blame] | 274 | |
egdaniel | 21aed57 | 2014-08-26 12:24:06 -0700 | [diff] [blame] | 275 | GrDrawState::AutoVertexAttribRestore::AutoVertexAttribRestore( |
| 276 | GrDrawState* drawState) { |
| 277 | SkASSERT(NULL != drawState); |
| 278 | fDrawState = drawState; |
| 279 | fVAPtr = drawState->fVAPtr; |
| 280 | fVACount = drawState->fVACount; |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame^] | 281 | fVAStride = drawState->fVAStride; |
egdaniel | 21aed57 | 2014-08-26 12:24:06 -0700 | [diff] [blame] | 282 | fDrawState->setDefaultVertexAttribs(); |
jvanverth@google.com | cc78238 | 2013-01-28 20:39:48 +0000 | [diff] [blame] | 283 | } |
| 284 | |
egdaniel | 21aed57 | 2014-08-26 12:24:06 -0700 | [diff] [blame] | 285 | //////////////////////////////////////////////////////////////////////////////s |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 286 | |
egdaniel | 21aed57 | 2014-08-26 12:24:06 -0700 | [diff] [blame] | 287 | void GrDrawState::AutoRestoreEffects::set(GrDrawState* ds) { |
| 288 | if (NULL != fDrawState) { |
| 289 | int m = fDrawState->numColorStages() - fColorEffectCnt; |
| 290 | SkASSERT(m >= 0); |
| 291 | fDrawState->fColorStages.pop_back_n(m); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 292 | |
egdaniel | 21aed57 | 2014-08-26 12:24:06 -0700 | [diff] [blame] | 293 | int n = fDrawState->numCoverageStages() - fCoverageEffectCnt; |
| 294 | SkASSERT(n >= 0); |
| 295 | fDrawState->fCoverageStages.pop_back_n(n); |
| 296 | if (m + n > 0) { |
| 297 | fDrawState->invalidateBlendOptFlags(); |
| 298 | } |
| 299 | SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;) |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 300 | } |
egdaniel | 21aed57 | 2014-08-26 12:24:06 -0700 | [diff] [blame] | 301 | fDrawState = ds; |
| 302 | if (NULL != ds) { |
| 303 | fColorEffectCnt = ds->numColorStages(); |
| 304 | fCoverageEffectCnt = ds->numCoverageStages(); |
| 305 | SkDEBUGCODE(++ds->fBlockEffectRemovalCnt;) |
| 306 | } |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 307 | } |
| 308 | |
jvanverth@google.com | cc78238 | 2013-01-28 20:39:48 +0000 | [diff] [blame] | 309 | //////////////////////////////////////////////////////////////////////////////// |
| 310 | |
egdaniel | 21aed57 | 2014-08-26 12:24:06 -0700 | [diff] [blame] | 311 | GrRODrawState::BlendOptFlags GrDrawState::getBlendOpts(bool forceCoverage, |
| 312 | GrBlendCoeff* srcCoeff, |
| 313 | GrBlendCoeff* dstCoeff) const { |
bsalomon@google.com | 2b44673 | 2013-02-12 16:47:41 +0000 | [diff] [blame] | 314 | GrBlendCoeff bogusSrcCoeff, bogusDstCoeff; |
| 315 | if (NULL == srcCoeff) { |
| 316 | srcCoeff = &bogusSrcCoeff; |
| 317 | } |
bsalomon@google.com | 2b44673 | 2013-02-12 16:47:41 +0000 | [diff] [blame] | 318 | if (NULL == dstCoeff) { |
| 319 | dstCoeff = &bogusDstCoeff; |
| 320 | } |
egdaniel | 9514d24 | 2014-07-18 06:15:43 -0700 | [diff] [blame] | 321 | |
| 322 | if (forceCoverage) { |
| 323 | return this->calcBlendOpts(true, srcCoeff, dstCoeff); |
| 324 | } |
| 325 | |
| 326 | if (0 == (fBlendOptFlags & kInvalid_BlendOptFlag)) { |
| 327 | *srcCoeff = fOptSrcBlend; |
| 328 | *dstCoeff = fOptDstBlend; |
| 329 | return fBlendOptFlags; |
| 330 | } |
| 331 | |
| 332 | fBlendOptFlags = this->calcBlendOpts(forceCoverage, srcCoeff, dstCoeff); |
| 333 | fOptSrcBlend = *srcCoeff; |
| 334 | fOptDstBlend = *dstCoeff; |
| 335 | |
| 336 | return fBlendOptFlags; |
| 337 | } |
| 338 | |
egdaniel | 21aed57 | 2014-08-26 12:24:06 -0700 | [diff] [blame] | 339 | GrRODrawState::BlendOptFlags GrDrawState::calcBlendOpts(bool forceCoverage, |
| 340 | GrBlendCoeff* srcCoeff, |
| 341 | GrBlendCoeff* dstCoeff) const { |
egdaniel | 9514d24 | 2014-07-18 06:15:43 -0700 | [diff] [blame] | 342 | *srcCoeff = this->getSrcBlendCoeff(); |
bsalomon@google.com | 2b44673 | 2013-02-12 16:47:41 +0000 | [diff] [blame] | 343 | *dstCoeff = this->getDstBlendCoeff(); |
| 344 | |
| 345 | if (this->isColorWriteDisabled()) { |
| 346 | *srcCoeff = kZero_GrBlendCoeff; |
| 347 | *dstCoeff = kOne_GrBlendCoeff; |
| 348 | } |
| 349 | |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 350 | bool srcAIsOne = this->srcAlphaWillBeOne(); |
bsalomon@google.com | 2b44673 | 2013-02-12 16:47:41 +0000 | [diff] [blame] | 351 | bool dstCoeffIsOne = kOne_GrBlendCoeff == *dstCoeff || |
| 352 | (kSA_GrBlendCoeff == *dstCoeff && srcAIsOne); |
| 353 | bool dstCoeffIsZero = kZero_GrBlendCoeff == *dstCoeff || |
| 354 | (kISA_GrBlendCoeff == *dstCoeff && srcAIsOne); |
| 355 | |
bsalomon@google.com | 2b44673 | 2013-02-12 16:47:41 +0000 | [diff] [blame] | 356 | // When coeffs are (0,1) there is no reason to draw at all, unless |
| 357 | // stenciling is enabled. Having color writes disabled is effectively |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 358 | // (0,1). |
| 359 | if ((kZero_GrBlendCoeff == *srcCoeff && dstCoeffIsOne)) { |
bsalomon@google.com | 2b44673 | 2013-02-12 16:47:41 +0000 | [diff] [blame] | 360 | if (this->getStencil().doesWrite()) { |
egdaniel | 0f1a7c4 | 2014-07-30 13:18:32 -0700 | [diff] [blame] | 361 | return kEmitCoverage_BlendOptFlag; |
bsalomon@google.com | 2b44673 | 2013-02-12 16:47:41 +0000 | [diff] [blame] | 362 | } else { |
| 363 | return kSkipDraw_BlendOptFlag; |
| 364 | } |
| 365 | } |
| 366 | |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 367 | bool hasCoverage = forceCoverage || !this->hasSolidCoverage(); |
bsalomon@google.com | 2b44673 | 2013-02-12 16:47:41 +0000 | [diff] [blame] | 368 | |
| 369 | // if we don't have coverage we can check whether the dst |
| 370 | // has to read at all. If not, we'll disable blending. |
| 371 | if (!hasCoverage) { |
| 372 | if (dstCoeffIsZero) { |
| 373 | if (kOne_GrBlendCoeff == *srcCoeff) { |
| 374 | // if there is no coverage and coeffs are (1,0) then we |
| 375 | // won't need to read the dst at all, it gets replaced by src |
egdaniel | 0f1a7c4 | 2014-07-30 13:18:32 -0700 | [diff] [blame] | 376 | *dstCoeff = kZero_GrBlendCoeff; |
| 377 | return kNone_BlendOpt; |
bsalomon@google.com | 2b44673 | 2013-02-12 16:47:41 +0000 | [diff] [blame] | 378 | } else if (kZero_GrBlendCoeff == *srcCoeff) { |
| 379 | // if the op is "clear" then we don't need to emit a color |
| 380 | // or blend, just write transparent black into the dst. |
| 381 | *srcCoeff = kOne_GrBlendCoeff; |
| 382 | *dstCoeff = kZero_GrBlendCoeff; |
egdaniel | 0f1a7c4 | 2014-07-30 13:18:32 -0700 | [diff] [blame] | 383 | return kEmitTransBlack_BlendOptFlag; |
bsalomon@google.com | 2b44673 | 2013-02-12 16:47:41 +0000 | [diff] [blame] | 384 | } |
| 385 | } |
| 386 | } else if (this->isCoverageDrawing()) { |
| 387 | // we have coverage but we aren't distinguishing it from alpha by request. |
| 388 | return kCoverageAsAlpha_BlendOptFlag; |
| 389 | } else { |
| 390 | // check whether coverage can be safely rolled into alpha |
| 391 | // of if we can skip color computation and just emit coverage |
| 392 | if (this->canTweakAlphaForCoverage()) { |
| 393 | return kCoverageAsAlpha_BlendOptFlag; |
| 394 | } |
| 395 | if (dstCoeffIsZero) { |
| 396 | if (kZero_GrBlendCoeff == *srcCoeff) { |
| 397 | // the source color is not included in the blend |
| 398 | // the dst coeff is effectively zero so blend works out to: |
| 399 | // (c)(0)D + (1-c)D = (1-c)D. |
| 400 | *dstCoeff = kISA_GrBlendCoeff; |
| 401 | return kEmitCoverage_BlendOptFlag; |
| 402 | } else if (srcAIsOne) { |
| 403 | // the dst coeff is effectively zero so blend works out to: |
| 404 | // cS + (c)(0)D + (1-c)D = cS + (1-c)D. |
| 405 | // If Sa is 1 then we can replace Sa with c |
| 406 | // and set dst coeff to 1-Sa. |
| 407 | *dstCoeff = kISA_GrBlendCoeff; |
| 408 | return kCoverageAsAlpha_BlendOptFlag; |
| 409 | } |
| 410 | } else if (dstCoeffIsOne) { |
| 411 | // the dst coeff is effectively one so blend works out to: |
| 412 | // cS + (c)(1)D + (1-c)D = cS + D. |
| 413 | *dstCoeff = kOne_GrBlendCoeff; |
| 414 | return kCoverageAsAlpha_BlendOptFlag; |
| 415 | } |
| 416 | } |
egdaniel | 0f1a7c4 | 2014-07-30 13:18:32 -0700 | [diff] [blame] | 417 | |
bsalomon@google.com | 2b44673 | 2013-02-12 16:47:41 +0000 | [diff] [blame] | 418 | return kNone_BlendOpt; |
| 419 | } |
| 420 | |
| 421 | //////////////////////////////////////////////////////////////////////////////// |
| 422 | |
bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 423 | void GrDrawState::AutoViewMatrixRestore::restore() { |
| 424 | if (NULL != fDrawState) { |
commit-bot@chromium.org | 1acc3d7 | 2013-09-06 23:13:05 +0000 | [diff] [blame] | 425 | SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;) |
bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 426 | fDrawState->fViewMatrix = fViewMatrix; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 427 | SkASSERT(fDrawState->numColorStages() >= fNumColorStages); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 428 | int numCoverageStages = fSavedCoordChanges.count() - fNumColorStages; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 429 | SkASSERT(fDrawState->numCoverageStages() >= numCoverageStages); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 430 | |
| 431 | int i = 0; |
| 432 | for (int s = 0; s < fNumColorStages; ++s, ++i) { |
egdaniel | 8cbf3d5 | 2014-08-21 06:27:22 -0700 | [diff] [blame] | 433 | fDrawState->fColorStages[s].restoreCoordChange(fSavedCoordChanges[i]); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 434 | } |
| 435 | for (int s = 0; s < numCoverageStages; ++s, ++i) { |
egdaniel | 8cbf3d5 | 2014-08-21 06:27:22 -0700 | [diff] [blame] | 436 | fDrawState->fCoverageStages[s].restoreCoordChange(fSavedCoordChanges[i]); |
bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 437 | } |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 438 | fDrawState = NULL; |
bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 439 | } |
bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | void GrDrawState::AutoViewMatrixRestore::set(GrDrawState* drawState, |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 443 | const SkMatrix& preconcatMatrix) { |
bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 444 | this->restore(); |
bsalomon@google.com | 5b3e890 | 2012-10-05 20:13:28 +0000 | [diff] [blame] | 445 | |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 446 | SkASSERT(NULL == fDrawState); |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 447 | if (NULL == drawState || preconcatMatrix.isIdentity()) { |
bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 448 | return; |
| 449 | } |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 450 | fDrawState = drawState; |
bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 451 | |
bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 452 | fViewMatrix = drawState->getViewMatrix(); |
bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 453 | drawState->fViewMatrix.preConcat(preconcatMatrix); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 454 | |
| 455 | this->doEffectCoordChanges(preconcatMatrix); |
commit-bot@chromium.org | 1acc3d7 | 2013-09-06 23:13:05 +0000 | [diff] [blame] | 456 | SkDEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;) |
bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 457 | } |
| 458 | |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 459 | bool GrDrawState::AutoViewMatrixRestore::setIdentity(GrDrawState* drawState) { |
bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 460 | this->restore(); |
| 461 | |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 462 | if (NULL == drawState) { |
bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 463 | return false; |
skia.committer@gmail.com | f467ce7 | 2012-10-09 02:01:37 +0000 | [diff] [blame] | 464 | } |
bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 465 | |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 466 | if (drawState->getViewMatrix().isIdentity()) { |
| 467 | return true; |
| 468 | } |
| 469 | |
bsalomon@google.com | 5b3e890 | 2012-10-05 20:13:28 +0000 | [diff] [blame] | 470 | fViewMatrix = drawState->getViewMatrix(); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 471 | if (0 == drawState->numTotalStages()) { |
bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 472 | drawState->fViewMatrix.reset(); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 473 | fDrawState = drawState; |
| 474 | fNumColorStages = 0; |
| 475 | fSavedCoordChanges.reset(0); |
commit-bot@chromium.org | 1acc3d7 | 2013-09-06 23:13:05 +0000 | [diff] [blame] | 476 | SkDEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;) |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 477 | return true; |
| 478 | } else { |
| 479 | SkMatrix inv; |
| 480 | if (!fViewMatrix.invert(&inv)) { |
| 481 | return false; |
bsalomon@google.com | 5b3e890 | 2012-10-05 20:13:28 +0000 | [diff] [blame] | 482 | } |
bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 483 | drawState->fViewMatrix.reset(); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 484 | fDrawState = drawState; |
| 485 | this->doEffectCoordChanges(inv); |
commit-bot@chromium.org | 1acc3d7 | 2013-09-06 23:13:05 +0000 | [diff] [blame] | 486 | SkDEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;) |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 487 | return true; |
bsalomon@google.com | 5b3e890 | 2012-10-05 20:13:28 +0000 | [diff] [blame] | 488 | } |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | void GrDrawState::AutoViewMatrixRestore::doEffectCoordChanges(const SkMatrix& coordChangeMatrix) { |
| 492 | fSavedCoordChanges.reset(fDrawState->numTotalStages()); |
| 493 | int i = 0; |
| 494 | |
| 495 | fNumColorStages = fDrawState->numColorStages(); |
| 496 | for (int s = 0; s < fNumColorStages; ++s, ++i) { |
egdaniel | 776bdbd | 2014-08-06 11:07:02 -0700 | [diff] [blame] | 497 | fDrawState->getColorStage(s).saveCoordChange(&fSavedCoordChanges[i]); |
egdaniel | 8cbf3d5 | 2014-08-21 06:27:22 -0700 | [diff] [blame] | 498 | fDrawState->fColorStages[s].localCoordChange(coordChangeMatrix); |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 499 | } |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 500 | |
| 501 | int numCoverageStages = fDrawState->numCoverageStages(); |
| 502 | for (int s = 0; s < numCoverageStages; ++s, ++i) { |
egdaniel | 776bdbd | 2014-08-06 11:07:02 -0700 | [diff] [blame] | 503 | fDrawState->getCoverageStage(s).saveCoordChange(&fSavedCoordChanges[i]); |
egdaniel | 8cbf3d5 | 2014-08-21 06:27:22 -0700 | [diff] [blame] | 504 | fDrawState->fCoverageStages[s].localCoordChange(coordChangeMatrix); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 505 | } |
bsalomon@google.com | 5b3e890 | 2012-10-05 20:13:28 +0000 | [diff] [blame] | 506 | } |
egdaniel | 21aed57 | 2014-08-26 12:24:06 -0700 | [diff] [blame] | 507 | |
| 508 | bool GrDrawState::srcAlphaWillBeOne() const { |
| 509 | uint32_t validComponentFlags; |
| 510 | GrColor color; |
| 511 | // Check if per-vertex or constant color may have partial alpha |
| 512 | if (this->hasColorVertexAttribute()) { |
| 513 | if (fHints & kVertexColorsAreOpaque_Hint) { |
| 514 | validComponentFlags = kA_GrColorComponentFlag; |
| 515 | color = 0xFF << GrColor_SHIFT_A; |
| 516 | } else { |
| 517 | validComponentFlags = 0; |
| 518 | color = 0; // not strictly necessary but we get false alarms from tools about uninit. |
| 519 | } |
| 520 | } else { |
| 521 | validComponentFlags = kRGBA_GrColorComponentFlags; |
| 522 | color = this->getColor(); |
| 523 | } |
| 524 | |
| 525 | // Run through the color stages |
| 526 | for (int s = 0; s < this->numColorStages(); ++s) { |
| 527 | const GrEffect* effect = this->getColorStage(s).getEffect(); |
| 528 | effect->getConstantColorComponents(&color, &validComponentFlags); |
| 529 | } |
| 530 | |
| 531 | // Check whether coverage is treated as color. If so we run through the coverage computation. |
| 532 | if (this->isCoverageDrawing()) { |
| 533 | // The shader generated for coverage drawing runs the full coverage computation and then |
| 534 | // makes the shader output be the multiplication of color and coverage. We mirror that here. |
| 535 | GrColor coverage; |
| 536 | uint32_t coverageComponentFlags; |
| 537 | if (this->hasCoverageVertexAttribute()) { |
| 538 | coverageComponentFlags = 0; |
| 539 | coverage = 0; // suppresses any warnings. |
| 540 | } else { |
| 541 | coverageComponentFlags = kRGBA_GrColorComponentFlags; |
| 542 | coverage = this->getCoverageColor(); |
| 543 | } |
| 544 | |
| 545 | // Run through the coverage stages |
| 546 | for (int s = 0; s < this->numCoverageStages(); ++s) { |
| 547 | const GrEffect* effect = this->getCoverageStage(s).getEffect(); |
| 548 | effect->getConstantColorComponents(&coverage, &coverageComponentFlags); |
| 549 | } |
| 550 | |
| 551 | // Since the shader will multiply coverage and color, the only way the final A==1 is if |
| 552 | // coverage and color both have A==1. |
| 553 | return (kA_GrColorComponentFlag & validComponentFlags & coverageComponentFlags) && |
| 554 | 0xFF == GrColorUnpackA(color) && 0xFF == GrColorUnpackA(coverage); |
| 555 | |
| 556 | } |
| 557 | |
| 558 | return (kA_GrColorComponentFlag & validComponentFlags) && 0xFF == GrColorUnpackA(color); |
| 559 | } |
| 560 | |
| 561 | //////////////////////////////////////////////////////////////////////////////// |
| 562 | |
| 563 | bool GrDrawState::canIgnoreColorAttribute() const { |
| 564 | if (fBlendOptFlags & kInvalid_BlendOptFlag) { |
| 565 | this->getBlendOpts(); |
| 566 | } |
| 567 | return SkToBool(fBlendOptFlags & (GrRODrawState::kEmitTransBlack_BlendOptFlag | |
| 568 | GrRODrawState::kEmitCoverage_BlendOptFlag)); |
| 569 | } |
| 570 | |