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

Side by Side Diff: src/gpu/effects/GrPorterDuffXferProcessor.cpp

Issue 1132883002: Remove coverage multiplies when it is known to be fully opaque. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 7 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
« no previous file with comments | « src/gpu/GrDefaultGeoProcFactory.cpp ('k') | no next file » | 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 2014 Google Inc. 2 * Copyright 2014 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 "effects/GrPorterDuffXferProcessor.h" 8 #include "effects/GrPorterDuffXferProcessor.h"
9 9
10 #include "GrBlend.h" 10 #include "GrBlend.h"
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 } 399 }
400 400
401 // if we don't have coverage we can check whether the dst 401 // if we don't have coverage we can check whether the dst
402 // has to read at all. If not, we'll disable blending. 402 // has to read at all. If not, we'll disable blending.
403 if (!hasCoverage) { 403 if (!hasCoverage) {
404 if (dstCoeffIsZero) { 404 if (dstCoeffIsZero) {
405 if (kOne_GrBlendCoeff == fSrcBlend) { 405 if (kOne_GrBlendCoeff == fSrcBlend) {
406 // if there is no coverage and coeffs are (1,0) then we 406 // if there is no coverage and coeffs are (1,0) then we
407 // won't need to read the dst at all, it gets replaced by src 407 // won't need to read the dst at all, it gets replaced by src
408 fDstBlend = kZero_GrBlendCoeff; 408 fDstBlend = kZero_GrBlendCoeff;
409 return GrXferProcessor::kNone_Opt; 409 return GrXferProcessor::kNone_Opt |
410 GrXferProcessor::kIgnoreCoverage_OptFlag;
410 } else if (kZero_GrBlendCoeff == fSrcBlend) { 411 } else if (kZero_GrBlendCoeff == fSrcBlend) {
411 // if the op is "clear" then we don't need to emit a color 412 // if the op is "clear" then we don't need to emit a color
412 // or blend, just write transparent black into the dst. 413 // or blend, just write transparent black into the dst.
413 fSrcBlend = kOne_GrBlendCoeff; 414 fSrcBlend = kOne_GrBlendCoeff;
414 fDstBlend = kZero_GrBlendCoeff; 415 fDstBlend = kZero_GrBlendCoeff;
415 return GrXferProcessor::kIgnoreColor_OptFlag | 416 return GrXferProcessor::kIgnoreColor_OptFlag |
416 GrXferProcessor::kIgnoreCoverage_OptFlag; 417 GrXferProcessor::kIgnoreCoverage_OptFlag;
417 } 418 }
418 } 419 }
419 } else { 420 return GrXferProcessor::kIgnoreCoverage_OptFlag;
420 // check whether coverage can be safely rolled into alpha 421 }
421 // of if we can skip color computation and just emit coverage 422
422 if (can_tweak_alpha_for_coverage(fDstBlend)) { 423 // check whether coverage can be safely rolled into alpha
424 // of if we can skip color computation and just emit coverage
425 if (can_tweak_alpha_for_coverage(fDstBlend)) {
426 if (colorPOI.allStagesMultiplyInput()) {
427 return GrXferProcessor::kSetCoverageDrawing_OptFlag |
428 GrXferProcessor::kCanTweakAlphaForCoverage_OptFlag;
429 } else {
430 return GrXferProcessor::kSetCoverageDrawing_OptFlag;
431
432 }
433 }
434 if (dstCoeffIsZero) {
435 if (kZero_GrBlendCoeff == fSrcBlend) {
436 // the source color is not included in the blend
437 // the dst coeff is effectively zero so blend works out to:
438 // (c)(0)D + (1-c)D = (1-c)D.
439 fDstBlend = kISA_GrBlendCoeff;
440 return GrXferProcessor::kIgnoreColor_OptFlag |
441 GrXferProcessor::kSetCoverageDrawing_OptFlag;
442 } else if (srcAIsOne) {
443 // the dst coeff is effectively zero so blend works out to:
444 // cS + (c)(0)D + (1-c)D = cS + (1-c)D.
445 // If Sa is 1 then we can replace Sa with c
446 // and set dst coeff to 1-Sa.
447 fDstBlend = kISA_GrBlendCoeff;
423 if (colorPOI.allStagesMultiplyInput()) { 448 if (colorPOI.allStagesMultiplyInput()) {
424 return GrXferProcessor::kSetCoverageDrawing_OptFlag | 449 return GrXferProcessor::kSetCoverageDrawing_OptFlag |
425 GrXferProcessor::kCanTweakAlphaForCoverage_OptFlag; 450 GrXferProcessor::kCanTweakAlphaForCoverage_OptFlag;
426 } else { 451 } else {
427 return GrXferProcessor::kSetCoverageDrawing_OptFlag; 452 return GrXferProcessor::kSetCoverageDrawing_OptFlag;
428 453
429 } 454 }
430 } 455 }
431 if (dstCoeffIsZero) { 456 } else if (dstCoeffIsOne) {
432 if (kZero_GrBlendCoeff == fSrcBlend) { 457 // the dst coeff is effectively one so blend works out to:
433 // the source color is not included in the blend 458 // cS + (c)(1)D + (1-c)D = cS + D.
434 // the dst coeff is effectively zero so blend works out to: 459 fDstBlend = kOne_GrBlendCoeff;
435 // (c)(0)D + (1-c)D = (1-c)D. 460 if (colorPOI.allStagesMultiplyInput()) {
436 fDstBlend = kISA_GrBlendCoeff; 461 return GrXferProcessor::kSetCoverageDrawing_OptFlag |
437 return GrXferProcessor::kIgnoreColor_OptFlag | 462 GrXferProcessor::kCanTweakAlphaForCoverage_OptFlag;
438 GrXferProcessor::kSetCoverageDrawing_OptFlag; 463 } else {
439 } else if (srcAIsOne) { 464 return GrXferProcessor::kSetCoverageDrawing_OptFlag;
440 // the dst coeff is effectively zero so blend works out to:
441 // cS + (c)(0)D + (1-c)D = cS + (1-c)D.
442 // If Sa is 1 then we can replace Sa with c
443 // and set dst coeff to 1-Sa.
444 fDstBlend = kISA_GrBlendCoeff;
445 if (colorPOI.allStagesMultiplyInput()) {
446 return GrXferProcessor::kSetCoverageDrawing_OptFlag |
447 GrXferProcessor::kCanTweakAlphaForCoverage_OptFlag;
448 } else {
449 return GrXferProcessor::kSetCoverageDrawing_OptFlag;
450 465
451 }
452 }
453 } else if (dstCoeffIsOne) {
454 // the dst coeff is effectively one so blend works out to:
455 // cS + (c)(1)D + (1-c)D = cS + D.
456 fDstBlend = kOne_GrBlendCoeff;
457 if (colorPOI.allStagesMultiplyInput()) {
458 return GrXferProcessor::kSetCoverageDrawing_OptFlag |
459 GrXferProcessor::kCanTweakAlphaForCoverage_OptFlag;
460 } else {
461 return GrXferProcessor::kSetCoverageDrawing_OptFlag;
462
463 }
464 return GrXferProcessor::kSetCoverageDrawing_OptFlag;
465 } 466 }
467 return GrXferProcessor::kSetCoverageDrawing_OptFlag;
466 } 468 }
467 469
468 return GrXferProcessor::kNone_Opt; 470 return GrXferProcessor::kNone_Opt;
469 } 471 }
470 472
471 bool PorterDuffXferProcessor::hasSecondaryOutput() const { 473 bool PorterDuffXferProcessor::hasSecondaryOutput() const {
472 return kNone_SecondaryOutputType != fSecondaryOutputType; 474 return kNone_SecondaryOutputType != fSecondaryOutputType;
473 } 475 }
474 476
475 /////////////////////////////////////////////////////////////////////////////// 477 ///////////////////////////////////////////////////////////////////////////////
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 GR_DEFINE_XP_FACTORY_TEST(GrPorterDuffXPFactory); 698 GR_DEFINE_XP_FACTORY_TEST(GrPorterDuffXPFactory);
697 699
698 GrXPFactory* GrPorterDuffXPFactory::TestCreate(SkRandom* random, 700 GrXPFactory* GrPorterDuffXPFactory::TestCreate(SkRandom* random,
699 GrContext*, 701 GrContext*,
700 const GrDrawTargetCaps&, 702 const GrDrawTargetCaps&,
701 GrTexture*[]) { 703 GrTexture*[]) {
702 SkXfermode::Mode mode = SkXfermode::Mode(random->nextULessThan(SkXfermode::k LastCoeffMode)); 704 SkXfermode::Mode mode = SkXfermode::Mode(random->nextULessThan(SkXfermode::k LastCoeffMode));
703 return GrPorterDuffXPFactory::Create(mode); 705 return GrPorterDuffXPFactory::Create(mode);
704 } 706 }
705 707
OLDNEW
« no previous file with comments | « src/gpu/GrDefaultGeoProcFactory.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698