OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 | |
8 #include "GrGLProgram.h" | 7 #include "GrGLProgram.h" |
9 | 8 |
10 #include "GrAllocator.h" | 9 #include "GrAllocator.h" |
11 #include "GrEffect.h" | 10 #include "GrEffect.h" |
12 #include "GrCoordTransform.h" | 11 #include "GrCoordTransform.h" |
13 #include "GrDrawEffect.h" | 12 #include "GrDrawEffect.h" |
14 #include "GrGLEffect.h" | 13 #include "GrGLEffect.h" |
15 #include "GrGpuGL.h" | 14 #include "GrGpuGL.h" |
16 #include "GrGLPathRendering.h" | 15 #include "GrGLPathRendering.h" |
17 #include "GrGLShaderVar.h" | 16 #include "GrGLShaderVar.h" |
18 #include "GrGLSL.h" | 17 #include "GrGLSL.h" |
| 18 #include "GrOptDrawState.h" |
19 #include "SkXfermode.h" | 19 #include "SkXfermode.h" |
20 | 20 |
21 #define GL_CALL(X) GR_GL_CALL(fGpu->glInterface(), X) | 21 #define GL_CALL(X) GR_GL_CALL(fGpu->glInterface(), X) |
22 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fGpu->glInterface(), R, X) | 22 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fGpu->glInterface(), R, X) |
23 | 23 |
24 GrGLProgram* GrGLProgram::Create(GrGpuGL* gpu, | 24 GrGLProgram* GrGLProgram::Create(GrGpuGL* gpu, |
25 const GrGLProgramDesc& desc, | 25 const GrGLProgramDesc& desc, |
26 const GrEffectStage* geometryProcessor, | 26 const GrEffectStage* geometryProcessor, |
27 const GrEffectStage* colorStages[], | 27 const GrEffectStage* colorStages[], |
28 const GrEffectStage* coverageStages[]) { | 28 const GrEffectStage* coverageStages[]) { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 } | 102 } |
103 if (fGeometryProcessor.get()) { | 103 if (fGeometryProcessor.get()) { |
104 fGeometryProcessor->initSamplers(fProgramDataManager, &texUnitIdx); | 104 fGeometryProcessor->initSamplers(fProgramDataManager, &texUnitIdx); |
105 } | 105 } |
106 fColorEffects->initSamplers(fProgramDataManager, &texUnitIdx); | 106 fColorEffects->initSamplers(fProgramDataManager, &texUnitIdx); |
107 fCoverageEffects->initSamplers(fProgramDataManager, &texUnitIdx); | 107 fCoverageEffects->initSamplers(fProgramDataManager, &texUnitIdx); |
108 } | 108 } |
109 | 109 |
110 /////////////////////////////////////////////////////////////////////////////// | 110 /////////////////////////////////////////////////////////////////////////////// |
111 | 111 |
112 void GrGLProgram::setData(GrGpu::DrawType drawType, | 112 void GrGLProgram::setData(const GrOptDrawState& optState, |
113 GrDrawState::BlendOptFlags blendOpts, | 113 GrGpu::DrawType drawType, |
114 const GrEffectStage* geometryProcessor, | 114 const GrEffectStage* geometryProcessor, |
115 const GrEffectStage* colorStages[], | 115 const GrEffectStage* colorStages[], |
116 const GrEffectStage* coverageStages[], | 116 const GrEffectStage* coverageStages[], |
117 const GrDeviceCoordTexture* dstCopy, | 117 const GrDeviceCoordTexture* dstCopy, |
118 SharedGLState* sharedState) { | 118 SharedGLState* sharedState) { |
119 const GrDrawState& drawState = fGpu->getDrawState(); | 119 GrColor color = optState.getColor(); |
| 120 GrColor coverage = optState.getCoverageColor(); |
120 | 121 |
121 GrColor color; | 122 this->setColor(optState, color, sharedState); |
122 GrColor coverage; | 123 this->setCoverage(optState, coverage, sharedState); |
123 if (blendOpts & GrDrawState::kEmitTransBlack_BlendOptFlag) { | 124 this->setMatrixAndRenderTargetHeight(drawType, optState); |
124 color = 0; | |
125 coverage = 0; | |
126 } else if (blendOpts & GrDrawState::kEmitCoverage_BlendOptFlag) { | |
127 color = 0xffffffff; | |
128 coverage = drawState.getCoverageColor(); | |
129 } else { | |
130 color = drawState.getColor(); | |
131 coverage = drawState.getCoverageColor(); | |
132 } | |
133 | |
134 this->setColor(drawState, color, sharedState); | |
135 this->setCoverage(drawState, coverage, sharedState); | |
136 this->setMatrixAndRenderTargetHeight(drawType, drawState); | |
137 | 125 |
138 if (dstCopy) { | 126 if (dstCopy) { |
139 if (fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()) { | 127 if (fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()) { |
140 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyTopLeftUni, | 128 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyTopLeftUni, |
141 static_cast<GrGLfloat>(dstCopy->offset().
fX), | 129 static_cast<GrGLfloat>(dstCopy->offset().
fX), |
142 static_cast<GrGLfloat>(dstCopy->offset().
fY)); | 130 static_cast<GrGLfloat>(dstCopy->offset().
fY)); |
143 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyScaleUni, | 131 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyScaleUni, |
144 1.f / dstCopy->texture()->width(), | 132 1.f / dstCopy->texture()->width(), |
145 1.f / dstCopy->texture()->height()); | 133 1.f / dstCopy->texture()->height()); |
146 GrGLTexture* texture = static_cast<GrGLTexture*>(dstCopy->texture())
; | 134 GrGLTexture* texture = static_cast<GrGLTexture*>(dstCopy->texture())
; |
(...skipping 17 matching lines...) Expand all Loading... |
164 fCoverageEffects->setData(fGpu, drawType,fProgramDataManager, coverageStages
); | 152 fCoverageEffects->setData(fGpu, drawType,fProgramDataManager, coverageStages
); |
165 | 153 |
166 // PathTexGen state applies to the the fixed function vertex shader. For | 154 // PathTexGen state applies to the the fixed function vertex shader. For |
167 // custom shaders, it's ignored, so we don't need to change the texgen | 155 // custom shaders, it's ignored, so we don't need to change the texgen |
168 // settings in that case. | 156 // settings in that case. |
169 if (!fHasVertexShader) { | 157 if (!fHasVertexShader) { |
170 fGpu->glPathRendering()->flushPathTexGenSettings(fTexCoordSetCnt); | 158 fGpu->glPathRendering()->flushPathTexGenSettings(fTexCoordSetCnt); |
171 } | 159 } |
172 } | 160 } |
173 | 161 |
174 void GrGLProgram::setColor(const GrDrawState& drawState, | 162 void GrGLProgram::setColor(const GrOptDrawState& optState, |
175 GrColor color, | 163 GrColor color, |
176 SharedGLState* sharedState) { | 164 SharedGLState* sharedState) { |
177 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); | 165 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); |
178 if (!drawState.hasColorVertexAttribute() || drawState.canIgnoreColorAttribut
e()) { | 166 if (!optState.hasColorVertexAttribute()) { |
179 switch (header.fColorInput) { | 167 switch (header.fColorInput) { |
180 case GrGLProgramDesc::kAttribute_ColorInput: | 168 case GrGLProgramDesc::kAttribute_ColorInput: |
181 SkASSERT(-1 != header.fColorAttributeIndex); | 169 SkASSERT(-1 != header.fColorAttributeIndex); |
182 if (sharedState->fConstAttribColor != color || | 170 if (sharedState->fConstAttribColor != color || |
183 sharedState->fConstAttribColorIndex != header.fColorAttribut
eIndex) { | 171 sharedState->fConstAttribColorIndex != header.fColorAttribut
eIndex) { |
184 // OpenGL ES only supports the float varieties of glVertexAt
trib | 172 // OpenGL ES only supports the float varieties of glVertexAt
trib |
185 GrGLfloat c[4]; | 173 GrGLfloat c[4]; |
186 GrColorToRGBAFloat(color, c); | 174 GrColorToRGBAFloat(color, c); |
187 GL_CALL(VertexAttrib4fv(header.fColorAttributeIndex, c)); | 175 GL_CALL(VertexAttrib4fv(header.fColorAttributeIndex, c)); |
188 sharedState->fConstAttribColor = color; | 176 sharedState->fConstAttribColor = color; |
(...skipping 14 matching lines...) Expand all Loading... |
203 sharedState->fConstAttribColorIndex = -1; | 191 sharedState->fConstAttribColorIndex = -1; |
204 break; | 192 break; |
205 default: | 193 default: |
206 SkFAIL("Unexpected color type."); | 194 SkFAIL("Unexpected color type."); |
207 } | 195 } |
208 } else { | 196 } else { |
209 sharedState->fConstAttribColorIndex = -1; | 197 sharedState->fConstAttribColorIndex = -1; |
210 } | 198 } |
211 } | 199 } |
212 | 200 |
213 void GrGLProgram::setCoverage(const GrDrawState& drawState, | 201 void GrGLProgram::setCoverage(const GrOptDrawState& optState, |
214 GrColor coverage, | 202 GrColor coverage, |
215 SharedGLState* sharedState) { | 203 SharedGLState* sharedState) { |
216 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); | 204 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); |
217 if (!drawState.hasCoverageVertexAttribute()) { | 205 if (!optState.hasCoverageVertexAttribute()) { |
218 switch (header.fCoverageInput) { | 206 switch (header.fCoverageInput) { |
219 case GrGLProgramDesc::kAttribute_ColorInput: | 207 case GrGLProgramDesc::kAttribute_ColorInput: |
220 if (sharedState->fConstAttribCoverage != coverage || | 208 if (sharedState->fConstAttribCoverage != coverage || |
221 sharedState->fConstAttribCoverageIndex != header.fCoverageAt
tributeIndex) { | 209 sharedState->fConstAttribCoverageIndex != header.fCoverageAt
tributeIndex) { |
222 // OpenGL ES only supports the float varieties of glVertexA
ttrib | 210 // OpenGL ES only supports the float varieties of glVertexA
ttrib |
223 GrGLfloat c[4]; | 211 GrGLfloat c[4]; |
224 GrColorToRGBAFloat(coverage, c); | 212 GrColorToRGBAFloat(coverage, c); |
225 GL_CALL(VertexAttrib4fv(header.fCoverageAttributeIndex, c)); | 213 GL_CALL(VertexAttrib4fv(header.fCoverageAttributeIndex, c)); |
226 sharedState->fConstAttribCoverage = coverage; | 214 sharedState->fConstAttribCoverage = coverage; |
227 sharedState->fConstAttribCoverageIndex = header.fCoverageAtt
ributeIndex; | 215 sharedState->fConstAttribCoverageIndex = header.fCoverageAtt
ributeIndex; |
(...skipping 14 matching lines...) Expand all Loading... |
242 break; | 230 break; |
243 default: | 231 default: |
244 SkFAIL("Unexpected coverage type."); | 232 SkFAIL("Unexpected coverage type."); |
245 } | 233 } |
246 } else { | 234 } else { |
247 sharedState->fConstAttribCoverageIndex = -1; | 235 sharedState->fConstAttribCoverageIndex = -1; |
248 } | 236 } |
249 } | 237 } |
250 | 238 |
251 void GrGLProgram::setMatrixAndRenderTargetHeight(GrGpu::DrawType drawType, | 239 void GrGLProgram::setMatrixAndRenderTargetHeight(GrGpu::DrawType drawType, |
252 const GrDrawState& drawState) { | 240 const GrOptDrawState& optState)
{ |
253 const GrRenderTarget* rt = drawState.getRenderTarget(); | 241 const GrRenderTarget* rt = optState.getRenderTarget(); |
254 SkISize size; | 242 SkISize size; |
255 size.set(rt->width(), rt->height()); | 243 size.set(rt->width(), rt->height()); |
256 | 244 |
257 // Load the RT height uniform if it is needed to y-flip gl_FragCoord. | 245 // Load the RT height uniform if it is needed to y-flip gl_FragCoord. |
258 if (fBuiltinUniformHandles.fRTHeightUni.isValid() && | 246 if (fBuiltinUniformHandles.fRTHeightUni.isValid() && |
259 fMatrixState.fRenderTargetSize.fHeight != size.fHeight) { | 247 fMatrixState.fRenderTargetSize.fHeight != size.fHeight) { |
260 fProgramDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni, | 248 fProgramDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni, |
261 SkIntToScalar(size.fHeight)); | 249 SkIntToScalar(size.fHeight)); |
262 } | 250 } |
263 | 251 |
264 if (GrGpu::IsPathRenderingDrawType(drawType)) { | 252 if (GrGpu::IsPathRenderingDrawType(drawType)) { |
265 fGpu->glPathRendering()->setProjectionMatrix(drawState.getViewMatrix(),
size, rt->origin()); | 253 fGpu->glPathRendering()->setProjectionMatrix(optState.getViewMatrix(), s
ize, rt->origin()); |
266 } else if (fMatrixState.fRenderTargetOrigin != rt->origin() || | 254 } else if (fMatrixState.fRenderTargetOrigin != rt->origin() || |
267 fMatrixState.fRenderTargetSize != size || | 255 fMatrixState.fRenderTargetSize != size || |
268 !fMatrixState.fViewMatrix.cheapEqualTo(drawState.getViewMatrix())
) { | 256 !fMatrixState.fViewMatrix.cheapEqualTo(optState.getViewMatrix()))
{ |
269 SkASSERT(fBuiltinUniformHandles.fViewMatrixUni.isValid()); | 257 SkASSERT(fBuiltinUniformHandles.fViewMatrixUni.isValid()); |
270 | 258 |
271 fMatrixState.fViewMatrix = drawState.getViewMatrix(); | 259 fMatrixState.fViewMatrix = optState.getViewMatrix(); |
272 fMatrixState.fRenderTargetSize = size; | 260 fMatrixState.fRenderTargetSize = size; |
273 fMatrixState.fRenderTargetOrigin = rt->origin(); | 261 fMatrixState.fRenderTargetOrigin = rt->origin(); |
274 | 262 |
275 GrGLfloat viewMatrix[3 * 3]; | 263 GrGLfloat viewMatrix[3 * 3]; |
276 fMatrixState.getGLMatrix<3>(viewMatrix); | 264 fMatrixState.getGLMatrix<3>(viewMatrix); |
277 fProgramDataManager.setMatrix3f(fBuiltinUniformHandles.fViewMatrixUni, v
iewMatrix); | 265 fProgramDataManager.setMatrix3f(fBuiltinUniformHandles.fViewMatrixUni, v
iewMatrix); |
278 | 266 |
279 GrGLfloat rtAdjustmentVec[4]; | 267 GrGLfloat rtAdjustmentVec[4]; |
280 fMatrixState.getRTAdjustmentVec(rtAdjustmentVec); | 268 fMatrixState.getRTAdjustmentVec(rtAdjustmentVec); |
281 fProgramDataManager.set4fv(fBuiltinUniformHandles.fRTAdjustmentUni, 1, r
tAdjustmentVec); | 269 fProgramDataManager.set4fv(fBuiltinUniformHandles.fRTAdjustmentUni, 1, r
tAdjustmentVec); |
282 } | 270 } |
283 } | 271 } |
OLD | NEW |