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

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

Issue 1254833003: Added GrGLBlend.h|cpp with helper function AppendPorterDuffBlend() in preparation for SkComposeShad… (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: More nits by Greg Created 5 years, 5 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 | « gyp/gpu.gypi ('k') | src/gpu/gl/GrGLBlend.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 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"
11 #include "GrCaps.h" 11 #include "GrCaps.h"
12 #include "GrProcessor.h" 12 #include "GrProcessor.h"
13 #include "GrProcOptInfo.h" 13 #include "GrProcOptInfo.h"
14 #include "GrTypes.h" 14 #include "GrTypes.h"
15 #include "GrXferProcessor.h" 15 #include "GrXferProcessor.h"
16 #include "gl/GrGLBlend.h"
16 #include "gl/GrGLXferProcessor.h" 17 #include "gl/GrGLXferProcessor.h"
17 #include "gl/builders/GrGLFragmentShaderBuilder.h" 18 #include "gl/builders/GrGLFragmentShaderBuilder.h"
18 #include "gl/builders/GrGLProgramBuilder.h" 19 #include "gl/builders/GrGLProgramBuilder.h"
19 20
20 /** 21 /**
21 * Wraps the shader outputs and HW blend state that comprise a Porter Duff blend mode with coverage. 22 * Wraps the shader outputs and HW blend state that comprise a Porter Duff blend mode with coverage.
22 */ 23 */
23 struct BlendFormula { 24 struct BlendFormula {
24 public: 25 public:
25 /** 26 /**
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 return fXfermode == xp.fXfermode; 482 return fXfermode == xp.fXfermode;
482 } 483 }
483 484
484 const SkXfermode::Mode fXfermode; 485 const SkXfermode::Mode fXfermode;
485 486
486 typedef GrXferProcessor INHERITED; 487 typedef GrXferProcessor INHERITED;
487 }; 488 };
488 489
489 /////////////////////////////////////////////////////////////////////////////// 490 ///////////////////////////////////////////////////////////////////////////////
490 491
491 static bool append_porterduff_term(GrGLXPFragmentBuilder* fsBuilder, SkXfermode: :Coeff coeff,
492 const char* colorName, const char* srcColorNa me,
493 const char* dstColorName, bool hasPrevious) {
494 if (SkXfermode::kZero_Coeff == coeff) {
495 return hasPrevious;
496 } else {
497 if (hasPrevious) {
498 fsBuilder->codeAppend(" + ");
499 }
500 fsBuilder->codeAppendf("%s", colorName);
501 switch (coeff) {
502 case SkXfermode::kOne_Coeff:
503 break;
504 case SkXfermode::kSC_Coeff:
505 fsBuilder->codeAppendf(" * %s", srcColorName);
506 break;
507 case SkXfermode::kISC_Coeff:
508 fsBuilder->codeAppendf(" * (vec4(1.0) - %s)", srcColorName);
509 break;
510 case SkXfermode::kDC_Coeff:
511 fsBuilder->codeAppendf(" * %s", dstColorName);
512 break;
513 case SkXfermode::kIDC_Coeff:
514 fsBuilder->codeAppendf(" * (vec4(1.0) - %s)", dstColorName);
515 break;
516 case SkXfermode::kSA_Coeff:
517 fsBuilder->codeAppendf(" * %s.a", srcColorName);
518 break;
519 case SkXfermode::kISA_Coeff:
520 fsBuilder->codeAppendf(" * (1.0 - %s.a)", srcColorName);
521 break;
522 case SkXfermode::kDA_Coeff:
523 fsBuilder->codeAppendf(" * %s.a", dstColorName);
524 break;
525 case SkXfermode::kIDA_Coeff:
526 fsBuilder->codeAppendf(" * (1.0 - %s.a)", dstColorName);
527 break;
528 default:
529 SkFAIL("Unsupported Blend Coeff");
530 }
531 return true;
532 }
533 }
534
535 class GLShaderPDXferProcessor : public GrGLXferProcessor { 492 class GLShaderPDXferProcessor : public GrGLXferProcessor {
536 public: 493 public:
537 static void GenKey(const GrProcessor& processor, GrProcessorKeyBuilder* b) { 494 static void GenKey(const GrProcessor& processor, GrProcessorKeyBuilder* b) {
538 const ShaderPDXferProcessor& xp = processor.cast<ShaderPDXferProcessor>( ); 495 const ShaderPDXferProcessor& xp = processor.cast<ShaderPDXferProcessor>( );
539 b->add32(xp.getXfermode()); 496 b->add32(xp.getXfermode());
540 } 497 }
541 498
542 private: 499 private:
543 void emitBlendCodeForDstRead(GrGLXPBuilder* pb, const char* srcColor, const char* dstColor, 500 void emitBlendCodeForDstRead(GrGLXPBuilder* pb, const char* srcColor, const char* dstColor,
544 const char* outColor, const GrXferProcessor& pr oc) override { 501 const char* outColor, const GrXferProcessor& pr oc) override {
545 const ShaderPDXferProcessor& xp = proc.cast<ShaderPDXferProcessor>(); 502 const ShaderPDXferProcessor& xp = proc.cast<ShaderPDXferProcessor>();
546 GrGLXPFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder(); 503 GrGLXPFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder();
547 504
548 SkXfermode::Coeff srcCoeff, dstCoeff; 505 GrGLBlend::AppendPorterDuffBlend(fsBuilder, srcColor, dstColor, outColor , xp.getXfermode());
549 SkXfermode::ModeAsCoeff(xp.getXfermode(), &srcCoeff, &dstCoeff);
550
551 fsBuilder->codeAppendf("%s =", outColor);
552 // append src blend
553 bool didAppend = append_porterduff_term(fsBuilder, srcCoeff, srcColor, s rcColor, dstColor,
554 false);
555 // append dst blend
556 SkAssertResult(append_porterduff_term(fsBuilder, dstCoeff, dstColor, src Color, dstColor,
557 didAppend));
558 fsBuilder->codeAppend(";");
559 } 506 }
560 507
561 void onSetData(const GrGLProgramDataManager&, const GrXferProcessor&) overri de {} 508 void onSetData(const GrGLProgramDataManager&, const GrXferProcessor&) overri de {}
562 509
563 typedef GrGLXferProcessor INHERITED; 510 typedef GrGLXferProcessor INHERITED;
564 }; 511 };
565 512
566 /////////////////////////////////////////////////////////////////////////////// 513 ///////////////////////////////////////////////////////////////////////////////
567 514
568 void ShaderPDXferProcessor::onGetGLProcessorKey(const GrGLSLCaps&, 515 void ShaderPDXferProcessor::onGetGLProcessorKey(const GrGLSLCaps&,
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 int* outPrimary, 764 int* outPrimary,
818 int* outSecondary) { 765 int* outSecondary) {
819 if (!!strcmp(xp->name(), "Porter Duff")) { 766 if (!!strcmp(xp->name(), "Porter Duff")) {
820 *outPrimary = *outSecondary = -1; 767 *outPrimary = *outSecondary = -1;
821 return; 768 return;
822 } 769 }
823 BlendFormula blendFormula = static_cast<const PorterDuffXferProcessor*>(xp)- >getBlendFormula(); 770 BlendFormula blendFormula = static_cast<const PorterDuffXferProcessor*>(xp)- >getBlendFormula();
824 *outPrimary = blendFormula.fPrimaryOutputType; 771 *outPrimary = blendFormula.fPrimaryOutputType;
825 *outSecondary = blendFormula.fSecondaryOutputType; 772 *outSecondary = blendFormula.fSecondaryOutputType;
826 } 773 }
827
OLDNEW
« no previous file with comments | « gyp/gpu.gypi ('k') | src/gpu/gl/GrGLBlend.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698