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

Side by Side Diff: cc/output/shader.cc

Issue 2659023003: [cc] Add SkBlendMode::kDstIn support to cc::Layer (Closed)
Patch Set: Created 3 years, 10 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
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/output/shader.h" 5 #include "cc/output/shader.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <vector> 10 #include <vector>
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 case BLEND_MODE_COLOR: 717 case BLEND_MODE_COLOR:
718 case BLEND_MODE_LUMINOSITY: 718 case BLEND_MODE_LUMINOSITY:
719 return kFunctionLum; 719 return kFunctionLum;
720 default: 720 default:
721 return std::string(); 721 return std::string();
722 } 722 }
723 } 723 }
724 724
725 std::string FragmentShader::GetBlendFunction() const { 725 std::string FragmentShader::GetBlendFunction() const {
726 return "vec4 Blend(vec4 src, vec4 dst) {" 726 return "vec4 Blend(vec4 src, vec4 dst) {"
727 " vec4 result;" 727 " vec4 result;" +
728 " result.a = src.a + (1.0 - src.a) * dst.a;" + 728 GetBlendFunctionBodyForAlpha() + GetBlendFunctionBodyForRGB() +
729 GetBlendFunctionBodyForRGB() +
730 " return result;" 729 " return result;"
731 "}"; 730 "}";
732 } 731 }
733 732
733 std::string FragmentShader::GetBlendFunctionBodyForAlpha() const {
734 if (blend_mode_ == BLEND_MODE_DESTINATION_IN)
735 return "result.a = src.a * dst.a;";
736 else
737 return "result.a = src.a + (1.0 - src.a) * dst.a;";
738 }
739
734 std::string FragmentShader::GetBlendFunctionBodyForRGB() const { 740 std::string FragmentShader::GetBlendFunctionBodyForRGB() const {
735 switch (blend_mode_) { 741 switch (blend_mode_) {
736 case BLEND_MODE_NORMAL: 742 case BLEND_MODE_NORMAL:
737 return "result.rgb = src.rgb + dst.rgb * (1.0 - src.a);"; 743 return "result.rgb = src.rgb + dst.rgb * (1.0 - src.a);";
744 case BLEND_MODE_DESTINATION_IN:
745 return "result.rgb = dst.rgb * src.a;";
738 case BLEND_MODE_SCREEN: 746 case BLEND_MODE_SCREEN:
739 return "result.rgb = src.rgb + (1.0 - src.rgb) * dst.rgb;"; 747 return "result.rgb = src.rgb + (1.0 - src.rgb) * dst.rgb;";
740 case BLEND_MODE_LIGHTEN: 748 case BLEND_MODE_LIGHTEN:
741 return "result.rgb = max((1.0 - src.a) * dst.rgb + src.rgb," 749 return "result.rgb = max((1.0 - src.a) * dst.rgb + src.rgb,"
742 " (1.0 - dst.a) * src.rgb + dst.rgb);"; 750 " (1.0 - dst.a) * src.rgb + dst.rgb);";
743 case BLEND_MODE_OVERLAY: 751 case BLEND_MODE_OVERLAY:
744 return "result.rgb = hardLight(dst, src);"; 752 return "result.rgb = hardLight(dst, src);";
745 case BLEND_MODE_DARKEN: 753 case BLEND_MODE_DARKEN:
746 return "result.rgb = min((1.0 - src.a) * dst.rgb + src.rgb," 754 return "result.rgb = min((1.0 - src.a) * dst.rgb + src.rgb,"
747 " (1.0 - dst.a) * src.rgb + dst.rgb);"; 755 " (1.0 - dst.a) * src.rgb + dst.rgb);";
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 else 1002 else
995 SRC("gl_FragColor = ApplyBlendMode(texColor, 0.0);"); 1003 SRC("gl_FragColor = ApplyBlendMode(texColor, 0.0);");
996 break; 1004 break;
997 } 1005 }
998 source += "}\n"; 1006 source += "}\n";
999 1007
1000 return header + source; 1008 return header + source;
1001 } 1009 }
1002 1010
1003 } // namespace cc 1011 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698