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

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

Issue 2502373003: stop using SkXfermode -- use SkBlendMode instead (Closed)
Patch Set: rebase Created 4 years, 1 month 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 | « cc/output/gl_renderer.h ('k') | cc/output/gl_renderer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 case GL_TEXTURE_RECTANGLE_ARB: 98 case GL_TEXTURE_RECTANGLE_ARB:
99 return SAMPLER_TYPE_2D_RECT; 99 return SAMPLER_TYPE_2D_RECT;
100 case GL_TEXTURE_EXTERNAL_OES: 100 case GL_TEXTURE_EXTERNAL_OES:
101 return SAMPLER_TYPE_EXTERNAL_OES; 101 return SAMPLER_TYPE_EXTERNAL_OES;
102 default: 102 default:
103 NOTREACHED(); 103 NOTREACHED();
104 return SAMPLER_TYPE_2D; 104 return SAMPLER_TYPE_2D;
105 } 105 }
106 } 106 }
107 107
108 BlendMode BlendModeFromSkXfermode(SkXfermode::Mode mode) { 108 BlendMode BlendModeFromSkXfermode(SkBlendMode mode) {
109 switch (mode) { 109 switch (mode) {
110 case SkXfermode::kSrcOver_Mode: 110 case SkBlendMode::kSrcOver:
111 return BLEND_MODE_NORMAL; 111 return BLEND_MODE_NORMAL;
112 case SkXfermode::kScreen_Mode: 112 case SkBlendMode::kScreen:
113 return BLEND_MODE_SCREEN; 113 return BLEND_MODE_SCREEN;
114 case SkXfermode::kOverlay_Mode: 114 case SkBlendMode::kOverlay:
115 return BLEND_MODE_OVERLAY; 115 return BLEND_MODE_OVERLAY;
116 case SkXfermode::kDarken_Mode: 116 case SkBlendMode::kDarken:
117 return BLEND_MODE_DARKEN; 117 return BLEND_MODE_DARKEN;
118 case SkXfermode::kLighten_Mode: 118 case SkBlendMode::kLighten:
119 return BLEND_MODE_LIGHTEN; 119 return BLEND_MODE_LIGHTEN;
120 case SkXfermode::kColorDodge_Mode: 120 case SkBlendMode::kColorDodge:
121 return BLEND_MODE_COLOR_DODGE; 121 return BLEND_MODE_COLOR_DODGE;
122 case SkXfermode::kColorBurn_Mode: 122 case SkBlendMode::kColorBurn:
123 return BLEND_MODE_COLOR_BURN; 123 return BLEND_MODE_COLOR_BURN;
124 case SkXfermode::kHardLight_Mode: 124 case SkBlendMode::kHardLight:
125 return BLEND_MODE_HARD_LIGHT; 125 return BLEND_MODE_HARD_LIGHT;
126 case SkXfermode::kSoftLight_Mode: 126 case SkBlendMode::kSoftLight:
127 return BLEND_MODE_SOFT_LIGHT; 127 return BLEND_MODE_SOFT_LIGHT;
128 case SkXfermode::kDifference_Mode: 128 case SkBlendMode::kDifference:
129 return BLEND_MODE_DIFFERENCE; 129 return BLEND_MODE_DIFFERENCE;
130 case SkXfermode::kExclusion_Mode: 130 case SkBlendMode::kExclusion:
131 return BLEND_MODE_EXCLUSION; 131 return BLEND_MODE_EXCLUSION;
132 case SkXfermode::kMultiply_Mode: 132 case SkBlendMode::kMultiply:
133 return BLEND_MODE_MULTIPLY; 133 return BLEND_MODE_MULTIPLY;
134 case SkXfermode::kHue_Mode: 134 case SkBlendMode::kHue:
135 return BLEND_MODE_HUE; 135 return BLEND_MODE_HUE;
136 case SkXfermode::kSaturation_Mode: 136 case SkBlendMode::kSaturation:
137 return BLEND_MODE_SATURATION; 137 return BLEND_MODE_SATURATION;
138 case SkXfermode::kColor_Mode: 138 case SkBlendMode::kColor:
139 return BLEND_MODE_COLOR; 139 return BLEND_MODE_COLOR;
140 case SkXfermode::kLuminosity_Mode: 140 case SkBlendMode::kLuminosity:
141 return BLEND_MODE_LUMINOSITY; 141 return BLEND_MODE_LUMINOSITY;
142 default: 142 default:
143 NOTREACHED(); 143 NOTREACHED();
144 return BLEND_MODE_NONE; 144 return BLEND_MODE_NONE;
145 } 145 }
146 } 146 }
147 147
148 // Smallest unit that impact anti-aliasing output. We use this to 148 // Smallest unit that impact anti-aliasing output. We use this to
149 // determine when anti-aliasing is unnecessary. 149 // determine when anti-aliasing is unnecessary.
150 const float kAntiAliasingEpsilon = 1.0f / 1024.0f; 150 const float kAntiAliasingEpsilon = 1.0f / 1024.0f;
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 return nullptr; 705 return nullptr;
706 } 706 }
707 707
708 // Force a flush of the Skia pipeline before we switch back to the compositor 708 // Force a flush of the Skia pipeline before we switch back to the compositor
709 // context. 709 // context.
710 image->getTextureHandle(true); 710 image->getTextureHandle(true);
711 CHECK(image->isTextureBacked()); 711 CHECK(image->isTextureBacked());
712 return image; 712 return image;
713 } 713 }
714 714
715 bool GLRenderer::CanApplyBlendModeUsingBlendFunc(SkXfermode::Mode blend_mode) { 715 bool GLRenderer::CanApplyBlendModeUsingBlendFunc(SkBlendMode blend_mode) {
716 return use_blend_equation_advanced_ || 716 return use_blend_equation_advanced_ || blend_mode == SkBlendMode::kScreen ||
717 blend_mode == SkXfermode::kScreen_Mode || 717 blend_mode == SkBlendMode::kSrcOver;
718 blend_mode == SkXfermode::kSrcOver_Mode;
719 } 718 }
720 719
721 void GLRenderer::ApplyBlendModeUsingBlendFunc(SkXfermode::Mode blend_mode) { 720 void GLRenderer::ApplyBlendModeUsingBlendFunc(SkBlendMode blend_mode) {
722 DCHECK(CanApplyBlendModeUsingBlendFunc(blend_mode)); 721 DCHECK(CanApplyBlendModeUsingBlendFunc(blend_mode));
723 722
724 // Any modes set here must be reset in RestoreBlendFuncToDefault 723 // Any modes set here must be reset in RestoreBlendFuncToDefault
725 if (use_blend_equation_advanced_) { 724 if (use_blend_equation_advanced_) {
726 GLenum equation = GL_FUNC_ADD; 725 GLenum equation = GL_FUNC_ADD;
727 726
728 switch (blend_mode) { 727 switch (blend_mode) {
729 case SkXfermode::kScreen_Mode: 728 case SkBlendMode::kScreen:
730 equation = GL_SCREEN_KHR; 729 equation = GL_SCREEN_KHR;
731 break; 730 break;
732 case SkXfermode::kOverlay_Mode: 731 case SkBlendMode::kOverlay:
733 equation = GL_OVERLAY_KHR; 732 equation = GL_OVERLAY_KHR;
734 break; 733 break;
735 case SkXfermode::kDarken_Mode: 734 case SkBlendMode::kDarken:
736 equation = GL_DARKEN_KHR; 735 equation = GL_DARKEN_KHR;
737 break; 736 break;
738 case SkXfermode::kLighten_Mode: 737 case SkBlendMode::kLighten:
739 equation = GL_LIGHTEN_KHR; 738 equation = GL_LIGHTEN_KHR;
740 break; 739 break;
741 case SkXfermode::kColorDodge_Mode: 740 case SkBlendMode::kColorDodge:
742 equation = GL_COLORDODGE_KHR; 741 equation = GL_COLORDODGE_KHR;
743 break; 742 break;
744 case SkXfermode::kColorBurn_Mode: 743 case SkBlendMode::kColorBurn:
745 equation = GL_COLORBURN_KHR; 744 equation = GL_COLORBURN_KHR;
746 break; 745 break;
747 case SkXfermode::kHardLight_Mode: 746 case SkBlendMode::kHardLight:
748 equation = GL_HARDLIGHT_KHR; 747 equation = GL_HARDLIGHT_KHR;
749 break; 748 break;
750 case SkXfermode::kSoftLight_Mode: 749 case SkBlendMode::kSoftLight:
751 equation = GL_SOFTLIGHT_KHR; 750 equation = GL_SOFTLIGHT_KHR;
752 break; 751 break;
753 case SkXfermode::kDifference_Mode: 752 case SkBlendMode::kDifference:
754 equation = GL_DIFFERENCE_KHR; 753 equation = GL_DIFFERENCE_KHR;
755 break; 754 break;
756 case SkXfermode::kExclusion_Mode: 755 case SkBlendMode::kExclusion:
757 equation = GL_EXCLUSION_KHR; 756 equation = GL_EXCLUSION_KHR;
758 break; 757 break;
759 case SkXfermode::kMultiply_Mode: 758 case SkBlendMode::kMultiply:
760 equation = GL_MULTIPLY_KHR; 759 equation = GL_MULTIPLY_KHR;
761 break; 760 break;
762 case SkXfermode::kHue_Mode: 761 case SkBlendMode::kHue:
763 equation = GL_HSL_HUE_KHR; 762 equation = GL_HSL_HUE_KHR;
764 break; 763 break;
765 case SkXfermode::kSaturation_Mode: 764 case SkBlendMode::kSaturation:
766 equation = GL_HSL_SATURATION_KHR; 765 equation = GL_HSL_SATURATION_KHR;
767 break; 766 break;
768 case SkXfermode::kColor_Mode: 767 case SkBlendMode::kColor:
769 equation = GL_HSL_COLOR_KHR; 768 equation = GL_HSL_COLOR_KHR;
770 break; 769 break;
771 case SkXfermode::kLuminosity_Mode: 770 case SkBlendMode::kLuminosity:
772 equation = GL_HSL_LUMINOSITY_KHR; 771 equation = GL_HSL_LUMINOSITY_KHR;
773 break; 772 break;
774 default: 773 default:
775 return; 774 return;
776 } 775 }
777 776
778 gl_->BlendEquation(equation); 777 gl_->BlendEquation(equation);
779 } else { 778 } else {
780 if (blend_mode == SkXfermode::kScreen_Mode) { 779 if (blend_mode == SkBlendMode::kScreen) {
781 gl_->BlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE); 780 gl_->BlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE);
782 } 781 }
783 } 782 }
784 } 783 }
785 784
786 void GLRenderer::RestoreBlendFuncToDefault(SkXfermode::Mode blend_mode) { 785 void GLRenderer::RestoreBlendFuncToDefault(SkBlendMode blend_mode) {
787 if (blend_mode == SkXfermode::kSrcOver_Mode) 786 if (blend_mode == SkBlendMode::kSrcOver)
788 return; 787 return;
789 788
790 if (use_blend_equation_advanced_) { 789 if (use_blend_equation_advanced_) {
791 gl_->BlendEquation(GL_FUNC_ADD); 790 gl_->BlendEquation(GL_FUNC_ADD);
792 } else { 791 } else {
793 gl_->BlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); 792 gl_->BlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
794 } 793 }
795 } 794 }
796 795
797 bool GLRenderer::ShouldApplyBackgroundFilters(const RenderPassDrawQuad* quad) { 796 bool GLRenderer::ShouldApplyBackgroundFilters(const RenderPassDrawQuad* quad) {
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
1121 SetupRenderPassQuadForClippingAndAntialiasing( 1120 SetupRenderPassQuadForClippingAndAntialiasing(
1122 params->contents_device_transform, quad, aa_quad, params->clip_region, 1121 params->contents_device_transform, quad, aa_quad, params->clip_region,
1123 &params->surface_quad, params->edge); 1122 &params->surface_quad, params->edge);
1124 1123
1125 return true; 1124 return true;
1126 } 1125 }
1127 1126
1128 void GLRenderer::UpdateRPDQShadersForBlending( 1127 void GLRenderer::UpdateRPDQShadersForBlending(
1129 DrawRenderPassDrawQuadParams* params) { 1128 DrawRenderPassDrawQuadParams* params) {
1130 const RenderPassDrawQuad* quad = params->quad; 1129 const RenderPassDrawQuad* quad = params->quad;
1131 SkXfermode::Mode blend_mode = quad->shared_quad_state->blend_mode; 1130 SkBlendMode blend_mode = quad->shared_quad_state->blend_mode;
1132 params->use_shaders_for_blending = 1131 params->use_shaders_for_blending =
1133 !CanApplyBlendModeUsingBlendFunc(blend_mode) || 1132 !CanApplyBlendModeUsingBlendFunc(blend_mode) ||
1134 ShouldApplyBackgroundFilters(quad) || 1133 ShouldApplyBackgroundFilters(quad) ||
1135 settings_->force_blending_with_shaders; 1134 settings_->force_blending_with_shaders;
1136 1135
1137 if (params->use_shaders_for_blending) { 1136 if (params->use_shaders_for_blending) {
1138 DCHECK(params->frame); 1137 DCHECK(params->frame);
1139 // Compute a bounding box around the pixels that will be visible through 1138 // Compute a bounding box around the pixels that will be visible through
1140 // the quad. 1139 // the quad.
1141 gfx::Rect unclipped_rect; 1140 gfx::Rect unclipped_rect;
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1273 params->contents_resource_lock = 1272 params->contents_resource_lock =
1274 base::MakeUnique<ResourceProvider::ScopedSamplerGL>( 1273 base::MakeUnique<ResourceProvider::ScopedSamplerGL>(
1275 resource_provider_, params->contents_texture->id(), GL_LINEAR); 1274 resource_provider_, params->contents_texture->id(), GL_LINEAR);
1276 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), 1275 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D),
1277 params->contents_resource_lock->target()); 1276 params->contents_resource_lock->target());
1278 params->source_needs_flip = params->flip_texture; 1277 params->source_needs_flip = params->flip_texture;
1279 } 1278 }
1280 } 1279 }
1281 1280
1282 void GLRenderer::UpdateRPDQBlendMode(DrawRenderPassDrawQuadParams* params) { 1281 void GLRenderer::UpdateRPDQBlendMode(DrawRenderPassDrawQuadParams* params) {
1283 SkXfermode::Mode blend_mode = params->quad->shared_quad_state->blend_mode; 1282 SkBlendMode blend_mode = params->quad->shared_quad_state->blend_mode;
1284 SetBlendEnabled(!params->use_shaders_for_blending && 1283 SetBlendEnabled(!params->use_shaders_for_blending &&
1285 (params->quad->ShouldDrawWithBlending() || 1284 (params->quad->ShouldDrawWithBlending() ||
1286 !IsDefaultBlendMode(blend_mode))); 1285 !IsDefaultBlendMode(blend_mode)));
1287 if (!params->use_shaders_for_blending) { 1286 if (!params->use_shaders_for_blending) {
1288 if (!use_blend_equation_advanced_coherent_ && use_blend_equation_advanced_) 1287 if (!use_blend_equation_advanced_coherent_ && use_blend_equation_advanced_)
1289 gl_->BlendBarrierKHR(); 1288 gl_->BlendBarrierKHR();
1290 1289
1291 ApplyBlendModeUsingBlendFunc(blend_mode); 1290 ApplyBlendModeUsingBlendFunc(blend_mode);
1292 } 1291 }
1293 } 1292 }
(...skipping 2751 matching lines...) Expand 10 before | Expand all | Expand 10 after
4045 // The alpha has already been applied when copying the RPDQ to an IOSurface. 4044 // The alpha has already been applied when copying the RPDQ to an IOSurface.
4046 GLfloat alpha = 1; 4045 GLfloat alpha = 1;
4047 gl_->ScheduleCALayerSharedStateCHROMIUM(alpha, is_clipped, clip_rect, 4046 gl_->ScheduleCALayerSharedStateCHROMIUM(alpha, is_clipped, clip_rect,
4048 sorting_context_id, gl_transform); 4047 sorting_context_id, gl_transform);
4049 gl_->ScheduleCALayerCHROMIUM( 4048 gl_->ScheduleCALayerCHROMIUM(
4050 texture_id, contents_rect, ca_layer_overlay->background_color, 4049 texture_id, contents_rect, ca_layer_overlay->background_color,
4051 ca_layer_overlay->edge_aa_mask, bounds_rect, filter); 4050 ca_layer_overlay->edge_aa_mask, bounds_rect, filter);
4052 } 4051 }
4053 4052
4054 } // namespace cc 4053 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/gl_renderer.h ('k') | cc/output/gl_renderer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698