bsalomon@google.com | 798c8c4 | 2013-03-27 19:50:27 +0000 | [diff] [blame] | 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 "GrGLProgramDesc.h" |
| 9 | #include "GrBackendEffectFactory.h" |
| 10 | #include "GrDrawEffect.h" |
| 11 | #include "GrEffect.h" |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 12 | #include "GrGLShaderBuilder.h" |
bsalomon@google.com | 798c8c4 | 2013-03-27 19:50:27 +0000 | [diff] [blame] | 13 | #include "GrGpuGL.h" |
| 14 | |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 15 | #include "SkChecksum.h" |
| 16 | |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 17 | namespace { |
| 18 | inline GrGLEffect::EffectKey get_key_and_update_stats(const GrEffectStage& stage, |
| 19 | const GrGLCaps& caps, |
| 20 | bool useExplicitLocalCoords, |
| 21 | bool* setTrueIfReadsDst, |
commit-bot@chromium.org | 234d4fb | 2013-09-30 19:55:49 +0000 | [diff] [blame] | 22 | bool* setTrueIfReadsPos, |
| 23 | bool* setTrueIfHasVertexCode) { |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 24 | const GrEffectRef& effect = *stage.getEffect(); |
| 25 | const GrBackendEffectFactory& factory = effect->getFactory(); |
| 26 | GrDrawEffect drawEffect(stage, useExplicitLocalCoords); |
| 27 | if (effect->willReadDstColor()) { |
| 28 | *setTrueIfReadsDst = true; |
| 29 | } |
| 30 | if (effect->willReadFragmentPosition()) { |
| 31 | *setTrueIfReadsPos = true; |
| 32 | } |
commit-bot@chromium.org | 234d4fb | 2013-09-30 19:55:49 +0000 | [diff] [blame] | 33 | if (effect->hasVertexCode()) { |
| 34 | *setTrueIfHasVertexCode = true; |
| 35 | } |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 36 | return factory.glEffectKey(drawEffect, caps); |
| 37 | } |
| 38 | } |
bsalomon@google.com | 798c8c4 | 2013-03-27 19:50:27 +0000 | [diff] [blame] | 39 | void GrGLProgramDesc::Build(const GrDrawState& drawState, |
| 40 | bool isPoints, |
| 41 | GrDrawState::BlendOptFlags blendOpts, |
| 42 | GrBlendCoeff srcCoeff, |
| 43 | GrBlendCoeff dstCoeff, |
| 44 | const GrGpuGL* gpu, |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 45 | const GrDeviceCoordTexture* dstCopy, |
bsalomon@google.com | 2c84aa3 | 2013-06-06 20:28:57 +0000 | [diff] [blame] | 46 | SkTArray<const GrEffectStage*, true>* colorStages, |
| 47 | SkTArray<const GrEffectStage*, true>* coverageStages, |
bsalomon@google.com | 798c8c4 | 2013-03-27 19:50:27 +0000 | [diff] [blame] | 48 | GrGLProgramDesc* desc) { |
bsalomon@google.com | 2c84aa3 | 2013-06-06 20:28:57 +0000 | [diff] [blame] | 49 | colorStages->reset(); |
| 50 | coverageStages->reset(); |
| 51 | |
bsalomon@google.com | 798c8c4 | 2013-03-27 19:50:27 +0000 | [diff] [blame] | 52 | // This should already have been caught |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 53 | SkASSERT(!(GrDrawState::kSkipDraw_BlendOptFlag & blendOpts)); |
bsalomon@google.com | 798c8c4 | 2013-03-27 19:50:27 +0000 | [diff] [blame] | 54 | |
| 55 | bool skipCoverage = SkToBool(blendOpts & GrDrawState::kEmitTransBlack_BlendOptFlag); |
| 56 | |
| 57 | bool skipColor = SkToBool(blendOpts & (GrDrawState::kEmitTransBlack_BlendOptFlag | |
| 58 | GrDrawState::kEmitCoverage_BlendOptFlag)); |
commit-bot@chromium.org | a34995e | 2013-10-23 05:42:03 +0000 | [diff] [blame] | 59 | int firstEffectiveColorStage = 0; |
| 60 | bool inputColorIsUsed = true; |
| 61 | if (!skipColor) { |
| 62 | firstEffectiveColorStage = drawState.numColorStages(); |
| 63 | while (firstEffectiveColorStage > 0 && inputColorIsUsed) { |
| 64 | --firstEffectiveColorStage; |
| 65 | const GrEffect* effect = drawState.getColorStage(firstEffectiveColorStage).getEffect()->get(); |
| 66 | inputColorIsUsed = effect->willUseInputColor(); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | int firstEffectiveCoverageStage = 0; |
| 71 | bool inputCoverageIsUsed = true; |
| 72 | if (!skipCoverage) { |
| 73 | firstEffectiveCoverageStage = drawState.numCoverageStages(); |
| 74 | while (firstEffectiveCoverageStage > 0 && inputCoverageIsUsed) { |
| 75 | --firstEffectiveCoverageStage; |
| 76 | const GrEffect* effect = drawState.getCoverageStage(firstEffectiveCoverageStage).getEffect()->get(); |
| 77 | inputCoverageIsUsed = effect->willUseInputColor(); |
| 78 | } |
| 79 | } |
bsalomon@google.com | 798c8c4 | 2013-03-27 19:50:27 +0000 | [diff] [blame] | 80 | |
| 81 | // The descriptor is used as a cache key. Thus when a field of the |
| 82 | // descriptor will not affect program generation (because of the attribute |
| 83 | // bindings in use or other descriptor field settings) it should be set |
| 84 | // to a canonical value to avoid duplicate programs with different keys. |
| 85 | |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 86 | bool requiresColorAttrib = !skipColor && drawState.hasColorVertexAttribute(); |
| 87 | bool requiresCoverageAttrib = !skipCoverage && drawState.hasCoverageVertexAttribute(); |
| 88 | // we only need the local coords if we're actually going to generate effect code |
| 89 | bool requiresLocalCoordAttrib = !(skipCoverage && skipColor) && |
| 90 | drawState.hasLocalCoordAttribute(); |
bsalomon@google.com | 798c8c4 | 2013-03-27 19:50:27 +0000 | [diff] [blame] | 91 | |
bsalomon@google.com | 798c8c4 | 2013-03-27 19:50:27 +0000 | [diff] [blame] | 92 | bool colorIsTransBlack = SkToBool(blendOpts & GrDrawState::kEmitTransBlack_BlendOptFlag); |
| 93 | bool colorIsSolidWhite = (blendOpts & GrDrawState::kEmitCoverage_BlendOptFlag) || |
commit-bot@chromium.org | a34995e | 2013-10-23 05:42:03 +0000 | [diff] [blame] | 94 | (!requiresColorAttrib && 0xffffffff == drawState.getColor()) || |
| 95 | (!inputColorIsUsed); |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 96 | |
commit-bot@chromium.org | a34995e | 2013-10-23 05:42:03 +0000 | [diff] [blame] | 97 | int numEffects = (skipColor ? 0 : (drawState.numColorStages() - firstEffectiveColorStage)) + |
| 98 | (skipCoverage ? 0 : (drawState.numCoverageStages() - firstEffectiveCoverageStage)); |
bsalomon@google.com | 798c8c4 | 2013-03-27 19:50:27 +0000 | [diff] [blame] | 99 | |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 100 | size_t newKeyLength = KeyLength(numEffects); |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 101 | bool allocChanged; |
| 102 | desc->fKey.reset(newKeyLength, SkAutoMalloc::kAlloc_OnShrink, &allocChanged); |
| 103 | if (allocChanged || !desc->fInitialized) { |
| 104 | // make sure any padding in the header is zero if we we haven't used this allocation before. |
| 105 | memset(desc->header(), 0, kHeaderSize); |
bsalomon@google.com | 798c8c4 | 2013-03-27 19:50:27 +0000 | [diff] [blame] | 106 | } |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 107 | // write the key length |
robertphillips@google.com | a466286 | 2013-11-21 14:24:16 +0000 | [diff] [blame^] | 108 | *desc->atOffset<uint32_t, kLengthOffset>() = SkToU32(newKeyLength); |
bsalomon@google.com | 798c8c4 | 2013-03-27 19:50:27 +0000 | [diff] [blame] | 109 | |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 110 | KeyHeader* header = desc->header(); |
| 111 | EffectKey* effectKeys = desc->effectKeys(); |
| 112 | |
| 113 | int currEffectKey = 0; |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 114 | bool readsDst = false; |
bsalomon@google.com | b515881 | 2013-05-13 18:50:25 +0000 | [diff] [blame] | 115 | bool readFragPosition = false; |
commit-bot@chromium.org | 234d4fb | 2013-09-30 19:55:49 +0000 | [diff] [blame] | 116 | bool hasVertexCode = false; |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 117 | if (!skipColor) { |
commit-bot@chromium.org | a34995e | 2013-10-23 05:42:03 +0000 | [diff] [blame] | 118 | for (int s = firstEffectiveColorStage; s < drawState.numColorStages(); ++s) { |
skia.committer@gmail.com | 5c493d5 | 2013-06-14 07:00:49 +0000 | [diff] [blame] | 119 | effectKeys[currEffectKey++] = |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 120 | get_key_and_update_stats(drawState.getColorStage(s), gpu->glCaps(), |
commit-bot@chromium.org | 234d4fb | 2013-09-30 19:55:49 +0000 | [diff] [blame] | 121 | requiresLocalCoordAttrib, &readsDst, &readFragPosition, |
| 122 | &hasVertexCode); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | if (!skipCoverage) { |
commit-bot@chromium.org | a34995e | 2013-10-23 05:42:03 +0000 | [diff] [blame] | 126 | for (int s = firstEffectiveCoverageStage; s < drawState.numCoverageStages(); ++s) { |
skia.committer@gmail.com | 5c493d5 | 2013-06-14 07:00:49 +0000 | [diff] [blame] | 127 | effectKeys[currEffectKey++] = |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 128 | get_key_and_update_stats(drawState.getCoverageStage(s), gpu->glCaps(), |
commit-bot@chromium.org | 234d4fb | 2013-09-30 19:55:49 +0000 | [diff] [blame] | 129 | requiresLocalCoordAttrib, &readsDst, &readFragPosition, |
| 130 | &hasVertexCode); |
bsalomon@google.com | 798c8c4 | 2013-03-27 19:50:27 +0000 | [diff] [blame] | 131 | } |
| 132 | } |
| 133 | |
commit-bot@chromium.org | 234d4fb | 2013-09-30 19:55:49 +0000 | [diff] [blame] | 134 | header->fHasVertexCode = hasVertexCode || requiresLocalCoordAttrib; |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 135 | header->fEmitsPointSize = isPoints; |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 136 | |
| 137 | // Currently the experimental GS will only work with triangle prims (and it doesn't do anything |
| 138 | // other than pass through values from the VS to the FS anyway). |
| 139 | #if GR_GL_EXPERIMENTAL_GS |
| 140 | #if 0 |
| 141 | header->fExperimentalGS = gpu->caps().geometryShaderSupport(); |
| 142 | #else |
| 143 | header->fExperimentalGS = false; |
| 144 | #endif |
| 145 | #endif |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 146 | bool defaultToUniformInputs = GR_GL_NO_CONSTANT_ATTRIBUTES || gpu->caps()->pathRenderingSupport(); |
| 147 | |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 148 | if (colorIsTransBlack) { |
| 149 | header->fColorInput = kTransBlack_ColorInput; |
| 150 | } else if (colorIsSolidWhite) { |
| 151 | header->fColorInput = kSolidWhite_ColorInput; |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 152 | } else if (defaultToUniformInputs && !requiresColorAttrib) { |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 153 | header->fColorInput = kUniform_ColorInput; |
| 154 | } else { |
| 155 | header->fColorInput = kAttribute_ColorInput; |
commit-bot@chromium.org | 234d4fb | 2013-09-30 19:55:49 +0000 | [diff] [blame] | 156 | header->fHasVertexCode = true; |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 157 | } |
| 158 | |
bsalomon@google.com | 1b20a10 | 2013-11-08 14:42:56 +0000 | [diff] [blame] | 159 | bool covIsSolidWhite = !requiresCoverageAttrib && 0xffffffff == drawState.getCoverage(); |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 160 | |
| 161 | if (skipCoverage) { |
| 162 | header->fCoverageInput = kTransBlack_ColorInput; |
commit-bot@chromium.org | a34995e | 2013-10-23 05:42:03 +0000 | [diff] [blame] | 163 | } else if (covIsSolidWhite || !inputCoverageIsUsed) { |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 164 | header->fCoverageInput = kSolidWhite_ColorInput; |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 165 | } else if (defaultToUniformInputs && !requiresCoverageAttrib) { |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 166 | header->fCoverageInput = kUniform_ColorInput; |
| 167 | } else { |
| 168 | header->fCoverageInput = kAttribute_ColorInput; |
commit-bot@chromium.org | 234d4fb | 2013-09-30 19:55:49 +0000 | [diff] [blame] | 169 | header->fHasVertexCode = true; |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 170 | } |
| 171 | |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 172 | if (readsDst) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 173 | SkASSERT(NULL != dstCopy || gpu->caps()->dstReadInShaderSupport()); |
bsalomon@google.com | 6b0cf02 | 2013-05-03 13:35:14 +0000 | [diff] [blame] | 174 | const GrTexture* dstCopyTexture = NULL; |
| 175 | if (NULL != dstCopy) { |
| 176 | dstCopyTexture = dstCopy->texture(); |
| 177 | } |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 178 | header->fDstReadKey = GrGLShaderBuilder::KeyForDstRead(dstCopyTexture, gpu->glCaps()); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 179 | SkASSERT(0 != header->fDstReadKey); |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 180 | } else { |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 181 | header->fDstReadKey = 0; |
bsalomon@google.com | b515881 | 2013-05-13 18:50:25 +0000 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | if (readFragPosition) { |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 185 | header->fFragPosKey = GrGLShaderBuilder::KeyForFragmentPosition(drawState.getRenderTarget(), |
bsalomon@google.com | b515881 | 2013-05-13 18:50:25 +0000 | [diff] [blame] | 186 | gpu->glCaps()); |
| 187 | } else { |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 188 | header->fFragPosKey = 0; |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 189 | } |
| 190 | |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 191 | // Record attribute indices |
| 192 | header->fPositionAttributeIndex = drawState.positionAttributeIndex(); |
| 193 | header->fLocalCoordAttributeIndex = drawState.localCoordAttributeIndex(); |
skia.committer@gmail.com | 2d816ad | 2013-05-23 07:01:22 +0000 | [diff] [blame] | 194 | |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 195 | // For constant color and coverage we need an attribute with an index beyond those already set |
| 196 | int availableAttributeIndex = drawState.getVertexAttribCount(); |
| 197 | if (requiresColorAttrib) { |
| 198 | header->fColorAttributeIndex = drawState.colorVertexAttributeIndex(); |
| 199 | } else if (GrGLProgramDesc::kAttribute_ColorInput == header->fColorInput) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 200 | SkASSERT(availableAttributeIndex < GrDrawState::kMaxVertexAttribCnt); |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 201 | header->fColorAttributeIndex = availableAttributeIndex; |
| 202 | availableAttributeIndex++; |
| 203 | } else { |
| 204 | header->fColorAttributeIndex = -1; |
| 205 | } |
skia.committer@gmail.com | 2d816ad | 2013-05-23 07:01:22 +0000 | [diff] [blame] | 206 | |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 207 | if (requiresCoverageAttrib) { |
| 208 | header->fCoverageAttributeIndex = drawState.coverageVertexAttributeIndex(); |
| 209 | } else if (GrGLProgramDesc::kAttribute_ColorInput == header->fCoverageInput) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 210 | SkASSERT(availableAttributeIndex < GrDrawState::kMaxVertexAttribCnt); |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 211 | header->fCoverageAttributeIndex = availableAttributeIndex; |
| 212 | } else { |
| 213 | header->fCoverageAttributeIndex = -1; |
bsalomon@google.com | 798c8c4 | 2013-03-27 19:50:27 +0000 | [diff] [blame] | 214 | } |
| 215 | |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 216 | // Here we deal with whether/how we handle color and coverage separately. |
skia.committer@gmail.com | 2d816ad | 2013-05-23 07:01:22 +0000 | [diff] [blame] | 217 | |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 218 | // Set these defaults and then possibly change our mind if there is coverage. |
| 219 | header->fDiscardIfZeroCoverage = false; |
| 220 | header->fCoverageOutput = kModulate_CoverageOutput; |
| 221 | |
| 222 | // If we do have coverage determine whether it matters. |
| 223 | bool separateCoverageFromColor = false; |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 224 | if (!drawState.isCoverageDrawing() && !skipCoverage && |
| 225 | (drawState.numCoverageStages() > 0 || requiresCoverageAttrib)) { |
bsalomon@google.com | 798c8c4 | 2013-03-27 19:50:27 +0000 | [diff] [blame] | 226 | |
| 227 | // If we're stenciling then we want to discard samples that have zero coverage |
| 228 | if (drawState.getStencil().doesWrite()) { |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 229 | header->fDiscardIfZeroCoverage = true; |
| 230 | separateCoverageFromColor = true; |
bsalomon@google.com | 798c8c4 | 2013-03-27 19:50:27 +0000 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | if (gpu->caps()->dualSourceBlendingSupport() && |
| 234 | !(blendOpts & (GrDrawState::kEmitCoverage_BlendOptFlag | |
| 235 | GrDrawState::kCoverageAsAlpha_BlendOptFlag))) { |
| 236 | if (kZero_GrBlendCoeff == dstCoeff) { |
| 237 | // write the coverage value to second color |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 238 | header->fCoverageOutput = kSecondaryCoverage_CoverageOutput; |
| 239 | separateCoverageFromColor = true; |
bsalomon@google.com | 798c8c4 | 2013-03-27 19:50:27 +0000 | [diff] [blame] | 240 | } else if (kSA_GrBlendCoeff == dstCoeff) { |
| 241 | // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered. |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 242 | header->fCoverageOutput = kSecondaryCoverageISA_CoverageOutput; |
| 243 | separateCoverageFromColor = true; |
bsalomon@google.com | 798c8c4 | 2013-03-27 19:50:27 +0000 | [diff] [blame] | 244 | } else if (kSC_GrBlendCoeff == dstCoeff) { |
| 245 | // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered. |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 246 | header->fCoverageOutput = kSecondaryCoverageISC_CoverageOutput; |
| 247 | separateCoverageFromColor = true; |
bsalomon@google.com | 798c8c4 | 2013-03-27 19:50:27 +0000 | [diff] [blame] | 248 | } |
bsalomon@google.com | 5920ac2 | 2013-04-19 13:14:45 +0000 | [diff] [blame] | 249 | } else if (readsDst && |
bsalomon@google.com | 0c89db2 | 2013-05-15 17:53:04 +0000 | [diff] [blame] | 250 | kOne_GrBlendCoeff == srcCoeff && |
| 251 | kZero_GrBlendCoeff == dstCoeff) { |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 252 | header->fCoverageOutput = kCombineWithDst_CoverageOutput; |
| 253 | separateCoverageFromColor = true; |
bsalomon@google.com | 798c8c4 | 2013-03-27 19:50:27 +0000 | [diff] [blame] | 254 | } |
| 255 | } |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 256 | if (!skipColor) { |
commit-bot@chromium.org | a34995e | 2013-10-23 05:42:03 +0000 | [diff] [blame] | 257 | for (int s = firstEffectiveColorStage; s < drawState.numColorStages(); ++s) { |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 258 | colorStages->push_back(&drawState.getColorStage(s)); |
| 259 | } |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 260 | } |
| 261 | if (!skipCoverage) { |
| 262 | SkTArray<const GrEffectStage*, true>* array; |
| 263 | if (separateCoverageFromColor) { |
| 264 | array = coverageStages; |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 265 | } else { |
| 266 | array = colorStages; |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 267 | } |
commit-bot@chromium.org | a34995e | 2013-10-23 05:42:03 +0000 | [diff] [blame] | 268 | for (int s = firstEffectiveCoverageStage; s < drawState.numCoverageStages(); ++s) { |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 269 | array->push_back(&drawState.getCoverageStage(s)); |
| 270 | } |
bsalomon@google.com | 798c8c4 | 2013-03-27 19:50:27 +0000 | [diff] [blame] | 271 | } |
commit-bot@chromium.org | a34995e | 2013-10-23 05:42:03 +0000 | [diff] [blame] | 272 | header->fColorEffectCnt = colorStages->count(); |
| 273 | header->fCoverageEffectCnt = coverageStages->count(); |
bsalomon@google.com | 798c8c4 | 2013-03-27 19:50:27 +0000 | [diff] [blame] | 274 | |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 275 | *desc->checksum() = 0; |
| 276 | *desc->checksum() = SkChecksum::Compute(reinterpret_cast<uint32_t*>(desc->fKey.get()), |
| 277 | newKeyLength); |
| 278 | desc->fInitialized = true; |
bsalomon@google.com | 798c8c4 | 2013-03-27 19:50:27 +0000 | [diff] [blame] | 279 | } |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 280 | |
| 281 | GrGLProgramDesc& GrGLProgramDesc::operator= (const GrGLProgramDesc& other) { |
| 282 | fInitialized = other.fInitialized; |
| 283 | if (fInitialized) { |
| 284 | size_t keyLength = other.keyLength(); |
| 285 | fKey.reset(keyLength); |
| 286 | memcpy(fKey.get(), other.fKey.get(), keyLength); |
| 287 | } |
| 288 | return *this; |
| 289 | } |