Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Side by Side Diff: src/gpu/gl/GrGLProgram.cpp

Issue 25605008: Repurpose GrGLCoordTransform as GrGLEffectArray (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/gpu/gl/GrGLProgram.h ('k') | src/gpu/gl/GrGLProgramEffects.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 7
8 #include "GrGLProgram.h" 8 #include "GrGLProgram.h"
9 9
10 #include "GrAllocator.h" 10 #include "GrAllocator.h"
(...skipping 30 matching lines...) Expand all
41 : fGpu(gpu) 41 : fGpu(gpu)
42 , fUniformManager(gpu) { 42 , fUniformManager(gpu) {
43 fDesc = desc; 43 fDesc = desc;
44 fProgramID = 0; 44 fProgramID = 0;
45 45
46 fDstCopyTexUnit = -1; 46 fDstCopyTexUnit = -1;
47 47
48 fColor = GrColor_ILLEGAL; 48 fColor = GrColor_ILLEGAL;
49 fColorFilterColor = GrColor_ILLEGAL; 49 fColorFilterColor = GrColor_ILLEGAL;
50 50
51 fColorEffects.reset(desc.numColorEffects());
52 fCoverageEffects.reset(desc.numCoverageEffects());
53
54 this->genProgram(colorStages, coverageStages); 51 this->genProgram(colorStages, coverageStages);
55 } 52 }
56 53
57 GrGLProgram::~GrGLProgram() { 54 GrGLProgram::~GrGLProgram() {
58 if (fProgramID) { 55 if (fProgramID) {
59 GL_CALL(DeleteProgram(fProgramID)); 56 GL_CALL(DeleteProgram(fProgramID));
60 } 57 }
61 } 58 }
62 59
63 void GrGLProgram::abandon() { 60 void GrGLProgram::abandon() {
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 // Get the coeffs for the Mode-based color filter, determine if color is nee ded. 225 // Get the coeffs for the Mode-based color filter, determine if color is nee ded.
229 SkXfermode::Coeff colorCoeff; 226 SkXfermode::Coeff colorCoeff;
230 SkXfermode::Coeff filterColorCoeff; 227 SkXfermode::Coeff filterColorCoeff;
231 SkAssertResult( 228 SkAssertResult(
232 SkXfermode::ModeAsCoeff(header.fColorFilterXfermode, 229 SkXfermode::ModeAsCoeff(header.fColorFilterXfermode,
233 &filterColorCoeff, 230 &filterColorCoeff,
234 &colorCoeff)); 231 &colorCoeff));
235 bool needColor, needFilterColor; 232 bool needColor, needFilterColor;
236 need_blend_inputs(filterColorCoeff, colorCoeff, &needFilterColor, &needColor ); 233 need_blend_inputs(filterColorCoeff, colorCoeff, &needFilterColor, &needColor );
237 234
238 // used in order for builder to return the per-stage uniform handles. 235 fColorEffects.reset(
239 typedef SkTArray<GrGLCoordTransform, false>* CoordTransformArrayPtr; 236 builder.createAndEmitEffects(colorStages,
240 typedef SkTArray<GrGLUniformManager::UniformHandle, true>* UniHandleArrayPtr ; 237 fDesc.effectKeys(),
241 int maxColorOrCovEffectCnt = GrMax(fDesc.numColorEffects(), fDesc.numCoverag eEffects()); 238 needColor ? fDesc.numColorEffects() : 0,
242 SkAutoTArray<CoordTransformArrayPtr> effectCoordTransformArrays(maxColorOrCo vEffectCnt); 239 &inColor,
243 SkAutoTArray<UniHandleArrayPtr> effectUniformArrays(maxColorOrCovEffectCnt); 240 &knownColorValue));
244 SkAutoTArray<GrGLEffect*> glEffects(maxColorOrCovEffectCnt);
245
246 if (needColor) {
247 for (int e = 0; e < fDesc.numColorEffects(); ++e) {
248 effectCoordTransformArrays[e] = &fColorEffects[e].fCoordTransforms;
249 effectUniformArrays[e] = &fColorEffects[e].fSamplerUnis;
250 }
251
252 builder.emitEffects(colorStages,
253 fDesc.effectKeys(),
254 fDesc.numColorEffects(),
255 &inColor,
256 &knownColorValue,
257 effectCoordTransformArrays.get(),
258 effectUniformArrays.get(),
259 glEffects.get());
260
261 for (int e = 0; e < fDesc.numColorEffects(); ++e) {
262 fColorEffects[e].fGLEffect = glEffects[e];
263 }
264 }
265 241
266 // Insert the color filter. This will soon be replaced by a color effect. 242 // Insert the color filter. This will soon be replaced by a color effect.
267 if (SkXfermode::kDst_Mode != header.fColorFilterXfermode) { 243 if (SkXfermode::kDst_Mode != header.fColorFilterXfermode) {
268 const char* colorFilterColorUniName = NULL; 244 const char* colorFilterColorUniName = NULL;
269 fUniformHandles.fColorFilterUni = builder.addUniform(GrGLShaderBuilder:: kFragment_Visibility, 245 fUniformHandles.fColorFilterUni = builder.addUniform(GrGLShaderBuilder:: kFragment_Visibility,
270 kVec4f_GrSLType, "F ilterColor", 246 kVec4f_GrSLType, "F ilterColor",
271 &colorFilterColorUn iName); 247 &colorFilterColorUn iName);
272 248
273 builder.fsCodeAppend("\tvec4 filteredColor;\n"); 249 builder.fsCodeAppend("\tvec4 filteredColor;\n");
274 const char* color; 250 const char* color;
275 // add_color_filter requires a real input string. 251 // add_color_filter requires a real input string.
276 if (knownColorValue == kOnes_GrSLConstantVec) { 252 if (knownColorValue == kOnes_GrSLConstantVec) {
277 color = GrGLSLOnesVecf(4); 253 color = GrGLSLOnesVecf(4);
278 } else if (knownColorValue == kZeros_GrSLConstantVec) { 254 } else if (knownColorValue == kZeros_GrSLConstantVec) {
279 color = GrGLSLZerosVecf(4); 255 color = GrGLSLZerosVecf(4);
280 } else { 256 } else {
281 color = inColor.c_str(); 257 color = inColor.c_str();
282 } 258 }
283 add_color_filter(&builder, "filteredColor", filterColorCoeff, 259 add_color_filter(&builder, "filteredColor", filterColorCoeff,
284 colorCoeff, colorFilterColorUniName, color); 260 colorCoeff, colorFilterColorUniName, color);
285 inColor = "filteredColor"; 261 inColor = "filteredColor";
286 } 262 }
287 263
288 /////////////////////////////////////////////////////////////////////////// 264 ///////////////////////////////////////////////////////////////////////////
289 // compute the partial coverage 265 // compute the partial coverage
290 SkString inCoverage = builder.getInputCoverage(); 266 SkString inCoverage = builder.getInputCoverage();
291 GrSLConstantVec knownCoverageValue = builder.getKnownCoverageValue(); 267 GrSLConstantVec knownCoverageValue = builder.getKnownCoverageValue();
292 268
293 for (int e = 0; e < fDesc.numCoverageEffects(); ++e) { 269 fCoverageEffects.reset(
294 effectCoordTransformArrays[e] = &fCoverageEffects[e].fCoordTransforms; 270 builder.createAndEmitEffects(coverageStages,
295 effectUniformArrays[e] = &fCoverageEffects[e].fSamplerUnis; 271 fDesc.getEffectKeys() + fDesc.numColorEffec ts(),
296 } 272 fDesc.numCoverageEffects(),
297 273 &inCoverage,
298 builder.emitEffects(coverageStages, 274 &knownCoverageValue));
299 fDesc.getEffectKeys() + fDesc.numColorEffects(),
300 fDesc.numCoverageEffects(),
301 &inCoverage,
302 &knownCoverageValue,
303 effectCoordTransformArrays.get(),
304 effectUniformArrays.get(),
305 glEffects.get());
306 for (int e = 0; e < fDesc.numCoverageEffects(); ++e) {
307 fCoverageEffects[e].fGLEffect = glEffects[e];
308 }
309 275
310 // discard if coverage is zero 276 // discard if coverage is zero
311 if (header.fDiscardIfZeroCoverage && kOnes_GrSLConstantVec != knownCoverageV alue) { 277 if (header.fDiscardIfZeroCoverage && kOnes_GrSLConstantVec != knownCoverageV alue) {
312 if (kZeros_GrSLConstantVec == knownCoverageValue) { 278 if (kZeros_GrSLConstantVec == knownCoverageValue) {
313 // This is unfortunate. 279 // This is unfortunate.
314 builder.fsCodeAppend("\tdiscard;\n"); 280 builder.fsCodeAppend("\tdiscard;\n");
315 } else { 281 } else {
316 builder.fsCodeAppendf("\tif (all(lessThanEqual(%s, vec4(0.0)))) {\n\ t\tdiscard;\n\t}\n", 282 builder.fsCodeAppendf("\tif (all(lessThanEqual(%s, vec4(0.0)))) {\n\ t\tdiscard;\n\t}\n",
317 inCoverage.c_str()); 283 inCoverage.c_str());
318 } 284 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 return true; 380 return true;
415 } 381 }
416 382
417 void GrGLProgram::initSamplerUniforms() { 383 void GrGLProgram::initSamplerUniforms() {
418 GL_CALL(UseProgram(fProgramID)); 384 GL_CALL(UseProgram(fProgramID));
419 GrGLint texUnitIdx = 0; 385 GrGLint texUnitIdx = 0;
420 if (fUniformHandles.fDstCopySamplerUni.isValid()) { 386 if (fUniformHandles.fDstCopySamplerUni.isValid()) {
421 fUniformManager.setSampler(fUniformHandles.fDstCopySamplerUni, texUnitId x); 387 fUniformManager.setSampler(fUniformHandles.fDstCopySamplerUni, texUnitId x);
422 fDstCopyTexUnit = texUnitIdx++; 388 fDstCopyTexUnit = texUnitIdx++;
423 } 389 }
424 390 fColorEffects->initSamplers(fUniformManager, &texUnitIdx);
425 for (int e = 0; e < fColorEffects.count(); ++e) { 391 fCoverageEffects->initSamplers(fUniformManager, &texUnitIdx);
426 this->initEffectSamplerUniforms(&fColorEffects[e], &texUnitIdx);
427 }
428
429 for (int e = 0; e < fCoverageEffects.count(); ++e) {
430 this->initEffectSamplerUniforms(&fCoverageEffects[e], &texUnitIdx);
431 }
432 }
433
434 void GrGLProgram::initEffectSamplerUniforms(EffectAndSamplers* effect, int* texU nitIdx) {
435 int numSamplers = effect->fSamplerUnis.count();
436 effect->fTextureUnits.reset(numSamplers);
437 for (int s = 0; s < numSamplers; ++s) {
438 UniformHandle handle = effect->fSamplerUnis[s];
439 if (handle.isValid()) {
440 fUniformManager.setSampler(handle, *texUnitIdx);
441 effect->fTextureUnits[s] = (*texUnitIdx)++;
442 }
443 }
444 } 392 }
445 393
446 /////////////////////////////////////////////////////////////////////////////// 394 ///////////////////////////////////////////////////////////////////////////////
447 395
448 void GrGLProgram::setEffectData(const GrEffectStage& stage,
449 EffectAndSamplers& effect) {
450
451 // Let the GrGLEffect set its data.
452 bool explicitLocalCoords = -1 != fDesc.getHeader().fLocalCoordAttributeIndex ;
453 GrDrawEffect drawEffect(stage, explicitLocalCoords);
454 effect.fGLEffect->setData(fUniformManager, drawEffect);
455
456 // Set the effect's coord transform matrices.
457 int numTransforms = effect.fCoordTransforms.count();
458 SkASSERT((*stage.getEffect())->numTransforms() == numTransforms);
459 for (int c = 0; c < numTransforms; ++c) {
460 effect.fCoordTransforms[c].setData(fUniformManager, drawEffect, c);
461 }
462
463 // Bind the texures for the effect.
464 int numSamplers = effect.fSamplerUnis.count();
465 SkASSERT((*stage.getEffect())->numTextures() == numSamplers);
466 for (int s = 0; s < numSamplers; ++s) {
467 UniformHandle handle = effect.fSamplerUnis[s];
468 if (handle.isValid()) {
469 const GrTextureAccess& access = (*stage.getEffect())->textureAccess( s);
470 GrGLTexture* texture = static_cast<GrGLTexture*>(access.getTexture() );
471 int unit = effect.fTextureUnits[s];
472 fGpu->bindTexture(unit, access.getParams(), texture);
473 }
474 }
475 }
476
477 void GrGLProgram::setData(GrDrawState::BlendOptFlags blendOpts, 396 void GrGLProgram::setData(GrDrawState::BlendOptFlags blendOpts,
478 const GrEffectStage* colorStages[], 397 const GrEffectStage* colorStages[],
479 const GrEffectStage* coverageStages[], 398 const GrEffectStage* coverageStages[],
480 const GrDeviceCoordTexture* dstCopy, 399 const GrDeviceCoordTexture* dstCopy,
481 SharedGLState* sharedState) { 400 SharedGLState* sharedState) {
482 const GrDrawState& drawState = fGpu->getDrawState(); 401 const GrDrawState& drawState = fGpu->getDrawState();
483 402
484 GrColor color; 403 GrColor color;
485 GrColor coverage; 404 GrColor coverage;
486 if (blendOpts & GrDrawState::kEmitTransBlack_BlendOptFlag) { 405 if (blendOpts & GrDrawState::kEmitTransBlack_BlendOptFlag) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 } else { 440 } else {
522 SkASSERT(!fUniformHandles.fDstCopyScaleUni.isValid()); 441 SkASSERT(!fUniformHandles.fDstCopyScaleUni.isValid());
523 SkASSERT(!fUniformHandles.fDstCopySamplerUni.isValid()); 442 SkASSERT(!fUniformHandles.fDstCopySamplerUni.isValid());
524 } 443 }
525 } else { 444 } else {
526 SkASSERT(!fUniformHandles.fDstCopyTopLeftUni.isValid()); 445 SkASSERT(!fUniformHandles.fDstCopyTopLeftUni.isValid());
527 SkASSERT(!fUniformHandles.fDstCopyScaleUni.isValid()); 446 SkASSERT(!fUniformHandles.fDstCopyScaleUni.isValid());
528 SkASSERT(!fUniformHandles.fDstCopySamplerUni.isValid()); 447 SkASSERT(!fUniformHandles.fDstCopySamplerUni.isValid());
529 } 448 }
530 449
531 for (int e = 0; e < fColorEffects.count(); ++e) { 450 fColorEffects->setData(fGpu, fUniformManager, colorStages);
532 // We may have omitted the GrGLEffect because of the color filter logic in genProgram. 451 fCoverageEffects->setData(fGpu, fUniformManager, coverageStages);
533 // This can be removed when the color filter is an effect.
534 if (NULL != fColorEffects[e].fGLEffect) {
535 this->setEffectData(*colorStages[e], fColorEffects[e]);
536 }
537 }
538
539 for (int e = 0; e < fCoverageEffects.count(); ++e) {
540 if (NULL != fCoverageEffects[e].fGLEffect) {
541 this->setEffectData(*coverageStages[e], fCoverageEffects[e]);
542 }
543 }
544 } 452 }
545 453
546 void GrGLProgram::setColor(const GrDrawState& drawState, 454 void GrGLProgram::setColor(const GrDrawState& drawState,
547 GrColor color, 455 GrColor color,
548 SharedGLState* sharedState) { 456 SharedGLState* sharedState) {
549 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); 457 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader();
550 if (!drawState.hasColorVertexAttribute()) { 458 if (!drawState.hasColorVertexAttribute()) {
551 switch (header.fColorInput) { 459 switch (header.fColorInput) {
552 case GrGLProgramDesc::kAttribute_ColorInput: 460 case GrGLProgramDesc::kAttribute_ColorInput:
553 SkASSERT(-1 != header.fColorAttributeIndex); 461 SkASSERT(-1 != header.fColorAttributeIndex);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 547
640 fMatrixState.fViewMatrix = drawState.getViewMatrix(); 548 fMatrixState.fViewMatrix = drawState.getViewMatrix();
641 fMatrixState.fRenderTargetSize = size; 549 fMatrixState.fRenderTargetSize = size;
642 fMatrixState.fRenderTargetOrigin = rt->origin(); 550 fMatrixState.fRenderTargetOrigin = rt->origin();
643 551
644 GrGLfloat viewMatrix[3 * 3]; 552 GrGLfloat viewMatrix[3 * 3];
645 fMatrixState.getGLMatrix<3>(viewMatrix); 553 fMatrixState.getGLMatrix<3>(viewMatrix);
646 fUniformManager.setMatrix3f(fUniformHandles.fViewMatrixUni, viewMatrix); 554 fUniformManager.setMatrix3f(fUniformHandles.fViewMatrixUni, viewMatrix);
647 } 555 }
648 } 556 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLProgram.h ('k') | src/gpu/gl/GrGLProgramEffects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698