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

Side by Side Diff: cc/output/gl_renderer.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 2010 The Chromium Authors. All rights reserved. 1 // Copyright 2010 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/gl_renderer.h" 5 #include "cc/output/gl_renderer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 default: 103 default:
104 NOTREACHED(); 104 NOTREACHED();
105 return SAMPLER_TYPE_2D; 105 return SAMPLER_TYPE_2D;
106 } 106 }
107 } 107 }
108 108
109 BlendMode BlendModeFromSkXfermode(SkBlendMode mode) { 109 BlendMode BlendModeFromSkXfermode(SkBlendMode mode) {
110 switch (mode) { 110 switch (mode) {
111 case SkBlendMode::kSrcOver: 111 case SkBlendMode::kSrcOver:
112 return BLEND_MODE_NORMAL; 112 return BLEND_MODE_NORMAL;
113 case SkBlendMode::kDstIn:
114 return BLEND_MODE_DESTINATION_IN;
113 case SkBlendMode::kScreen: 115 case SkBlendMode::kScreen:
114 return BLEND_MODE_SCREEN; 116 return BLEND_MODE_SCREEN;
115 case SkBlendMode::kOverlay: 117 case SkBlendMode::kOverlay:
116 return BLEND_MODE_OVERLAY; 118 return BLEND_MODE_OVERLAY;
117 case SkBlendMode::kDarken: 119 case SkBlendMode::kDarken:
118 return BLEND_MODE_DARKEN; 120 return BLEND_MODE_DARKEN;
119 case SkBlendMode::kLighten: 121 case SkBlendMode::kLighten:
120 return BLEND_MODE_LIGHTEN; 122 return BLEND_MODE_LIGHTEN;
121 case SkBlendMode::kColorDodge: 123 case SkBlendMode::kColorDodge:
122 return BLEND_MODE_COLOR_DODGE; 124 return BLEND_MODE_COLOR_DODGE;
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 } 709 }
708 710
709 // Force a flush of the Skia pipeline before we switch back to the compositor 711 // Force a flush of the Skia pipeline before we switch back to the compositor
710 // context. 712 // context.
711 image->getTextureHandle(true); 713 image->getTextureHandle(true);
712 CHECK(image->isTextureBacked()); 714 CHECK(image->isTextureBacked());
713 return image; 715 return image;
714 } 716 }
715 717
716 bool GLRenderer::CanApplyBlendModeUsingBlendFunc(SkBlendMode blend_mode) { 718 bool GLRenderer::CanApplyBlendModeUsingBlendFunc(SkBlendMode blend_mode) {
717 return use_blend_equation_advanced_ || blend_mode == SkBlendMode::kScreen || 719 return use_blend_equation_advanced_ || blend_mode == SkBlendMode::kSrcOver ||
718 blend_mode == SkBlendMode::kSrcOver; 720 blend_mode == SkBlendMode::kDstIn ||
721 blend_mode == SkBlendMode::kScreen;
719 } 722 }
720 723
721 void GLRenderer::ApplyBlendModeUsingBlendFunc(SkBlendMode blend_mode) { 724 void GLRenderer::ApplyBlendModeUsingBlendFunc(SkBlendMode blend_mode) {
722 DCHECK(CanApplyBlendModeUsingBlendFunc(blend_mode));
723
724 // Any modes set here must be reset in RestoreBlendFuncToDefault 725 // Any modes set here must be reset in RestoreBlendFuncToDefault
725 if (use_blend_equation_advanced_) { 726 if (blend_mode == SkBlendMode::kSrcOver) {
727 // Left no-op intentionally.
728 } else if (blend_mode == SkBlendMode::kDstIn) {
729 gl_->BlendFunc(GL_ZERO, GL_SRC_ALPHA);
730 } else if (blend_mode == SkBlendMode::kScreen) {
731 gl_->BlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE);
732 } else {
733 DCHECK(use_blend_equation_advanced_);
726 GLenum equation = GL_FUNC_ADD; 734 GLenum equation = GL_FUNC_ADD;
727
728 switch (blend_mode) { 735 switch (blend_mode) {
729 case SkBlendMode::kScreen: 736 case SkBlendMode::kScreen:
730 equation = GL_SCREEN_KHR; 737 equation = GL_SCREEN_KHR;
731 break; 738 break;
732 case SkBlendMode::kOverlay: 739 case SkBlendMode::kOverlay:
733 equation = GL_OVERLAY_KHR; 740 equation = GL_OVERLAY_KHR;
734 break; 741 break;
735 case SkBlendMode::kDarken: 742 case SkBlendMode::kDarken:
736 equation = GL_DARKEN_KHR; 743 equation = GL_DARKEN_KHR;
737 break; 744 break;
(...skipping 27 matching lines...) Expand all
765 case SkBlendMode::kSaturation: 772 case SkBlendMode::kSaturation:
766 equation = GL_HSL_SATURATION_KHR; 773 equation = GL_HSL_SATURATION_KHR;
767 break; 774 break;
768 case SkBlendMode::kColor: 775 case SkBlendMode::kColor:
769 equation = GL_HSL_COLOR_KHR; 776 equation = GL_HSL_COLOR_KHR;
770 break; 777 break;
771 case SkBlendMode::kLuminosity: 778 case SkBlendMode::kLuminosity:
772 equation = GL_HSL_LUMINOSITY_KHR; 779 equation = GL_HSL_LUMINOSITY_KHR;
773 break; 780 break;
774 default: 781 default:
782 NOTREACHED() << "Unexpected blend mode: SkBlendMode::k"
783 << SkBlendMode_Name(blend_mode);
775 return; 784 return;
776 } 785 }
777
778 gl_->BlendEquation(equation); 786 gl_->BlendEquation(equation);
779 } else {
780 if (blend_mode == SkBlendMode::kScreen) {
781 gl_->BlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE);
782 }
783 } 787 }
784 } 788 }
785 789
786 void GLRenderer::RestoreBlendFuncToDefault(SkBlendMode blend_mode) { 790 void GLRenderer::RestoreBlendFuncToDefault(SkBlendMode blend_mode) {
787 if (blend_mode == SkBlendMode::kSrcOver) 791 switch (blend_mode) {
788 return; 792 case SkBlendMode::kSrcOver:
789 793 break;
790 if (use_blend_equation_advanced_) { 794 case SkBlendMode::kDstIn:
791 gl_->BlendEquation(GL_FUNC_ADD); 795 case SkBlendMode::kScreen:
792 } else { 796 gl_->BlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
793 gl_->BlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); 797 break;
798 default:
799 DCHECK(use_blend_equation_advanced_);
800 gl_->BlendEquation(GL_FUNC_ADD);
794 } 801 }
795 } 802 }
796 803
797 bool GLRenderer::ShouldApplyBackgroundFilters( 804 bool GLRenderer::ShouldApplyBackgroundFilters(
798 const RenderPassDrawQuad* quad, 805 const RenderPassDrawQuad* quad,
799 const FilterOperations* background_filters) { 806 const FilterOperations* background_filters) {
800 if (!background_filters) 807 if (!background_filters)
801 return false; 808 return false;
802 DCHECK(!background_filters->IsEmpty()); 809 DCHECK(!background_filters->IsEmpty());
803 810
(...skipping 2786 matching lines...) Expand 10 before | Expand all | Expand 10 after
3590 return; 3597 return;
3591 3598
3592 // Report GPU overdraw as a percentage of |max_result|. 3599 // Report GPU overdraw as a percentage of |max_result|.
3593 TRACE_COUNTER1( 3600 TRACE_COUNTER1(
3594 TRACE_DISABLED_BY_DEFAULT("cc.debug.overdraw"), "GPU Overdraw", 3601 TRACE_DISABLED_BY_DEFAULT("cc.debug.overdraw"), "GPU Overdraw",
3595 (std::accumulate(overdraw->begin(), overdraw->end(), 0) * 100) / 3602 (std::accumulate(overdraw->begin(), overdraw->end(), 0) * 100) /
3596 max_result); 3603 max_result);
3597 } 3604 }
3598 3605
3599 } // namespace cc 3606 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698