| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "GrGLPathProcessor.h" | 8 #include "GrGLPathProcessor.h" |
| 9 | 9 |
| 10 #include "GrPathProcessor.h" | 10 #include "GrPathProcessor.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 const GrBatchTracker& bt) { | 52 const GrBatchTracker& bt) { |
| 53 const PathBatchTracker& local = bt.cast<PathBatchTracker>(); | 53 const PathBatchTracker& local = bt.cast<PathBatchTracker>(); |
| 54 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColor) { | 54 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColor) { |
| 55 GrGLfloat c[4]; | 55 GrGLfloat c[4]; |
| 56 GrColorToRGBAFloat(local.fColor, c); | 56 GrColorToRGBAFloat(local.fColor, c); |
| 57 pdman.set4fv(fColorUniform, 1, c); | 57 pdman.set4fv(fColorUniform, 1, c); |
| 58 fColor = local.fColor; | 58 fColor = local.fColor; |
| 59 } | 59 } |
| 60 } | 60 } |
| 61 | 61 |
| 62 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 62 void GrGLPathProcessor::emitTransforms(GrGLGPBuilder* pb, const TransformsIn& ti
n, |
| 63 | 63 TransformsOut* tout) { |
| 64 void GrGLLegacyPathProcessor::emitTransforms(GrGLGPBuilder*, const TransformsIn&
tin, | |
| 65 TransformsOut* tout) { | |
| 66 tout->push_back_n(tin.count()); | 64 tout->push_back_n(tin.count()); |
| 67 fInstalledTransforms.push_back_n(tin.count()); | 65 fInstalledTransforms.push_back_n(tin.count()); |
| 68 for (int i = 0; i < tin.count(); i++) { | 66 for (int i = 0; i < tin.count(); i++) { |
| 69 const ProcCoords& coordTransforms = tin[i]; | |
| 70 int texCoordIndex = this->addTexCoordSets(coordTransforms.count()); | |
| 71 | |
| 72 // Use the first uniform location as the texcoord index. | |
| 73 fInstalledTransforms[i].push_back_n(1); | |
| 74 fInstalledTransforms[i][0].fHandle = ShaderVarHandle(texCoordIndex); | |
| 75 | |
| 76 SkString name; | |
| 77 for (int t = 0; t < coordTransforms.count(); ++t) { | |
| 78 GrSLType type = coordTransforms[t]->getMatrix().hasPerspective() ? k
Vec3f_GrSLType : | |
| 79 k
Vec2f_GrSLType; | |
| 80 | |
| 81 name.printf("%s(gl_TexCoord[%i])", GrGLSLTypeString(type), texCoordI
ndex++); | |
| 82 SkNEW_APPEND_TO_TARRAY(&(*tout)[i], GrGLProcessor::TransformedCoords
, (name, type)); | |
| 83 } | |
| 84 } | |
| 85 } | |
| 86 | |
| 87 void GrGLLegacyPathProcessor::setTransformData( | |
| 88 const GrPrimitiveProcessor& primProc, | |
| 89 int index, | |
| 90 const SkTArray<const GrCoordTransform*, true>& transforms, | |
| 91 GrGLPathRendering* glpr, | |
| 92 GrGLuint) { | |
| 93 // We've hidden the texcoord index in the first entry of the transforms arra
y for each | |
| 94 // effect | |
| 95 int texCoordIndex = fInstalledTransforms[index][0].fHandle.handle(); | |
| 96 for (int t = 0; t < transforms.count(); ++t) { | |
| 97 const SkMatrix& transform = GetTransformMatrix(primProc.localMatrix(), *
transforms[t]); | |
| 98 GrGLPathRendering::PathTexGenComponents components = | |
| 99 GrGLPathRendering::kST_PathTexGenComponents; | |
| 100 if (transform.hasPerspective()) { | |
| 101 components = GrGLPathRendering::kSTR_PathTexGenComponents; | |
| 102 } | |
| 103 glpr->enablePathTexGen(texCoordIndex++, components, transform); | |
| 104 } | |
| 105 } | |
| 106 | |
| 107 void GrGLLegacyPathProcessor::didSetData(GrGLPathRendering* glpr) { | |
| 108 glpr->flushPathTexGenSettings(fTexCoordSetCnt); | |
| 109 } | |
| 110 | |
| 111 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | |
| 112 | |
| 113 void GrGLNormalPathProcessor::emitTransforms(GrGLGPBuilder* pb, const Transforms
In& tin, | |
| 114 TransformsOut* tout) { | |
| 115 tout->push_back_n(tin.count()); | |
| 116 fInstalledTransforms.push_back_n(tin.count()); | |
| 117 for (int i = 0; i < tin.count(); i++) { | |
| 118 const ProcCoords& coordTransforms = tin[i]; | 67 const ProcCoords& coordTransforms = tin[i]; |
| 119 fInstalledTransforms[i].push_back_n(coordTransforms.count()); | 68 fInstalledTransforms[i].push_back_n(coordTransforms.count()); |
| 120 for (int t = 0; t < coordTransforms.count(); t++) { | 69 for (int t = 0; t < coordTransforms.count(); t++) { |
| 121 GrSLType varyingType = | 70 GrSLType varyingType = |
| 122 coordTransforms[t]->getMatrix().hasPerspective() ? kVec3f_Gr
SLType : | 71 coordTransforms[t]->getMatrix().hasPerspective() ? kVec3f_Gr
SLType : |
| 123 kVec2f_Gr
SLType; | 72 kVec2f_Gr
SLType; |
| 124 | 73 |
| 125 | 74 |
| 126 SkString strVaryingName("MatrixCoord"); | 75 SkString strVaryingName("MatrixCoord"); |
| 127 strVaryingName.appendf("_%i_%i", i, t); | 76 strVaryingName.appendf("_%i_%i", i, t); |
| 128 GrGLVertToFrag v(varyingType); | 77 GrGLVertToFrag v(varyingType); |
| 129 pb->addVarying(strVaryingName.c_str(), &v); | 78 pb->addVarying(strVaryingName.c_str(), &v); |
| 130 SeparableVaryingInfo& varyingInfo = fSeparableVaryingInfos.push_back
(); | 79 SeparableVaryingInfo& varyingInfo = fSeparableVaryingInfos.push_back
(); |
| 131 varyingInfo.fVariable = pb->getFragmentShaderBuilder()->fInputs.back
(); | 80 varyingInfo.fVariable = pb->getFragmentShaderBuilder()->fInputs.back
(); |
| 132 varyingInfo.fLocation = fSeparableVaryingInfos.count() - 1; | 81 varyingInfo.fLocation = fSeparableVaryingInfos.count() - 1; |
| 133 varyingInfo.fType = varyingType; | 82 varyingInfo.fType = varyingType; |
| 134 fInstalledTransforms[i][t].fHandle = ShaderVarHandle(varyingInfo.fLo
cation); | 83 fInstalledTransforms[i][t].fHandle = ShaderVarHandle(varyingInfo.fLo
cation); |
| 135 fInstalledTransforms[i][t].fType = varyingType; | 84 fInstalledTransforms[i][t].fType = varyingType; |
| 136 | 85 |
| 137 SkNEW_APPEND_TO_TARRAY(&(*tout)[i], GrGLProcessor::TransformedCoords
, | 86 SkNEW_APPEND_TO_TARRAY(&(*tout)[i], GrGLProcessor::TransformedCoords
, |
| 138 (SkString(v.fsIn()), varyingType)); | 87 (SkString(v.fsIn()), varyingType)); |
| 139 } | 88 } |
| 140 } | 89 } |
| 141 } | 90 } |
| 142 | 91 |
| 143 void GrGLNormalPathProcessor::resolveSeparableVaryings(GrGLGpu* gpu, GrGLuint pr
ogramId) { | 92 void GrGLPathProcessor::resolveSeparableVaryings(GrGLGpu* gpu, GrGLuint programI
d) { |
| 144 int count = fSeparableVaryingInfos.count(); | 93 int count = fSeparableVaryingInfos.count(); |
| 145 for (int i = 0; i < count; ++i) { | 94 for (int i = 0; i < count; ++i) { |
| 146 GrGLint location; | 95 GrGLint location; |
| 147 GR_GL_CALL_RET(gpu->glInterface(), | 96 GR_GL_CALL_RET(gpu->glInterface(), |
| 148 location, | 97 location, |
| 149 GetProgramResourceLocation(programId, | 98 GetProgramResourceLocation(programId, |
| 150 GR_GL_FRAGMENT_INPUT, | 99 GR_GL_FRAGMENT_INPUT, |
| 151 fSeparableVaryingInfos[i].fVar
iable.c_str())); | 100 fSeparableVaryingInfos[i].fVar
iable.c_str())); |
| 152 fSeparableVaryingInfos[i].fLocation = location; | 101 fSeparableVaryingInfos[i].fLocation = location; |
| 153 } | 102 } |
| 154 } | 103 } |
| 155 | 104 |
| 156 void GrGLNormalPathProcessor::setTransformData( | 105 void GrGLPathProcessor::setTransformData( |
| 157 const GrPrimitiveProcessor& primProc, | 106 const GrPrimitiveProcessor& primProc, |
| 158 int index, | 107 int index, |
| 159 const SkTArray<const GrCoordTransform*, true>& coordTransforms, | 108 const SkTArray<const GrCoordTransform*, true>& coordTransforms, |
| 160 GrGLPathRendering* glpr, | 109 GrGLPathRendering* glpr, |
| 161 GrGLuint programID) { | 110 GrGLuint programID) { |
| 162 SkSTArray<2, Transform, true>& transforms = fInstalledTransforms[index]; | 111 SkSTArray<2, Transform, true>& transforms = fInstalledTransforms[index]; |
| 163 int numTransforms = transforms.count(); | 112 int numTransforms = transforms.count(); |
| 164 for (int t = 0; t < numTransforms; ++t) { | 113 for (int t = 0; t < numTransforms; ++t) { |
| 165 SkASSERT(transforms[t].fHandle.isValid()); | 114 SkASSERT(transforms[t].fHandle.isValid()); |
| 166 const SkMatrix& transform = GetTransformMatrix(primProc.localMatrix(), | 115 const SkMatrix& transform = GetTransformMatrix(primProc.localMatrix(), |
| 167 *coordTransforms[t]); | 116 *coordTransforms[t]); |
| 168 if (transforms[t].fCurrentValue.cheapEqualTo(transform)) { | 117 if (transforms[t].fCurrentValue.cheapEqualTo(transform)) { |
| 169 continue; | 118 continue; |
| 170 } | 119 } |
| 171 transforms[t].fCurrentValue = transform; | 120 transforms[t].fCurrentValue = transform; |
| 172 const SeparableVaryingInfo& fragmentInput = | 121 const SeparableVaryingInfo& fragmentInput = |
| 173 fSeparableVaryingInfos[transforms[t].fHandle.handle()]; | 122 fSeparableVaryingInfos[transforms[t].fHandle.handle()]; |
| 174 SkASSERT(transforms[t].fType == kVec2f_GrSLType || | 123 SkASSERT(transforms[t].fType == kVec2f_GrSLType || |
| 175 transforms[t].fType == kVec3f_GrSLType); | 124 transforms[t].fType == kVec3f_GrSLType); |
| 176 unsigned components = transforms[t].fType == kVec2f_GrSLType ? 2 : 3; | 125 unsigned components = transforms[t].fType == kVec2f_GrSLType ? 2 : 3; |
| 177 glpr->setProgramPathFragmentInputTransform(programID, | 126 glpr->setProgramPathFragmentInputTransform(programID, |
| 178 fragmentInput.fLocation, | 127 fragmentInput.fLocation, |
| 179 GR_GL_OBJECT_LINEAR, | 128 GR_GL_OBJECT_LINEAR, |
| 180 components, | 129 components, |
| 181 transform); | 130 transform); |
| 182 } | 131 } |
| 183 } | 132 } |
| OLD | NEW |