OLD | NEW |
---|---|
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 <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
693 } | 693 } |
694 | 694 |
695 // Flush the GrContext to ensure all buffered GL calls are drawn to the | 695 // Flush the GrContext to ensure all buffered GL calls are drawn to the |
696 // backing store before we access and return it, and have cc begin using the | 696 // backing store before we access and return it, and have cc begin using the |
697 // GL context again. | 697 // GL context again. |
698 canvas->flush(); | 698 canvas->flush(); |
699 | 699 |
700 return image; | 700 return image; |
701 } | 701 } |
702 | 702 |
703 bool GLRenderer::ShouldApplyBlendModeUsingBlendFunc(const DrawQuad* quad) { | |
704 SkXfermode::Mode blend_mode = quad->shared_quad_state->blend_mode; | |
705 return blend_mode == SkXfermode::kScreen_Mode || | |
706 blend_mode == SkXfermode::kSrcOver_Mode; | |
707 } | |
708 | |
709 void GLRenderer::ApplyBlendModeUsingBlendFunc(const DrawQuad* quad) { | |
710 DCHECK(ShouldApplyBlendModeUsingBlendFunc(quad)); | |
711 if (quad->shared_quad_state->blend_mode == SkXfermode::kScreen_Mode) { | |
712 GLC(gl_, gl_->BlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE)); | |
713 } | |
714 } | |
715 | |
716 void GLRenderer::RestoreBlendFuncToDefault(const DrawQuad* quad) { | |
717 DCHECK(ShouldApplyBlendModeUsingBlendFunc(quad)); | |
enne (OOO)
2014/09/29 18:25:13
I don't think this DCHECK adds much. Can you remo
Erik Dahlström (inactive)
2014/09/30 07:06:07
Done.
| |
718 GLC(gl_, gl_->BlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); | |
719 } | |
720 | |
703 static skia::RefPtr<SkImage> ApplyBlendModeWithBackdrop( | 721 static skia::RefPtr<SkImage> ApplyBlendModeWithBackdrop( |
704 scoped_ptr<GLRenderer::ScopedUseGrContext> use_gr_context, | 722 scoped_ptr<GLRenderer::ScopedUseGrContext> use_gr_context, |
705 ResourceProvider* resource_provider, | 723 ResourceProvider* resource_provider, |
706 skia::RefPtr<SkImage> source_bitmap_with_filters, | 724 skia::RefPtr<SkImage> source_bitmap_with_filters, |
707 ScopedResource* source_texture_resource, | 725 ScopedResource* source_texture_resource, |
708 ScopedResource* background_texture_resource, | 726 ScopedResource* background_texture_resource, |
709 SkXfermode::Mode blend_mode) { | 727 SkXfermode::Mode blend_mode) { |
710 if (!use_gr_context) | 728 if (!use_gr_context) |
711 return source_bitmap_with_filters; | 729 return source_bitmap_with_filters; |
712 | 730 |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
966 | 984 |
967 UseRenderPass(frame, target_render_pass); | 985 UseRenderPass(frame, target_render_pass); |
968 | 986 |
969 if (!using_background_texture) | 987 if (!using_background_texture) |
970 return scoped_ptr<ScopedResource>(); | 988 return scoped_ptr<ScopedResource>(); |
971 return background_texture.Pass(); | 989 return background_texture.Pass(); |
972 } | 990 } |
973 | 991 |
974 void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame, | 992 void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame, |
975 const RenderPassDrawQuad* quad) { | 993 const RenderPassDrawQuad* quad) { |
976 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 994 SetBlendEnabled(quad->ShouldDrawWithBlending() || |
995 ShouldApplyBlendModeUsingBlendFunc(quad)); | |
977 | 996 |
978 ScopedResource* contents_texture = | 997 ScopedResource* contents_texture = |
979 render_pass_textures_.get(quad->render_pass_id); | 998 render_pass_textures_.get(quad->render_pass_id); |
980 if (!contents_texture || !contents_texture->id()) | 999 if (!contents_texture || !contents_texture->id()) |
981 return; | 1000 return; |
982 | 1001 |
983 gfx::Transform quad_rect_matrix; | 1002 gfx::Transform quad_rect_matrix; |
984 QuadRectTransform(&quad_rect_matrix, quad->quadTransform(), quad->rect); | 1003 QuadRectTransform(&quad_rect_matrix, quad->quadTransform(), quad->rect); |
985 gfx::Transform contents_device_transform = | 1004 gfx::Transform contents_device_transform = |
986 frame->window_matrix * frame->projection_matrix * quad_rect_matrix; | 1005 frame->window_matrix * frame->projection_matrix * quad_rect_matrix; |
987 contents_device_transform.FlattenTo2d(); | 1006 contents_device_transform.FlattenTo2d(); |
988 | 1007 |
989 // Can only draw surface if device matrix is invertible. | 1008 // Can only draw surface if device matrix is invertible. |
990 gfx::Transform contents_device_transform_inverse( | 1009 gfx::Transform contents_device_transform_inverse( |
991 gfx::Transform::kSkipInitialization); | 1010 gfx::Transform::kSkipInitialization); |
992 if (!contents_device_transform.GetInverse(&contents_device_transform_inverse)) | 1011 if (!contents_device_transform.GetInverse(&contents_device_transform_inverse)) |
993 return; | 1012 return; |
994 | 1013 |
995 bool need_background_texture = | 1014 bool need_background_texture = !ShouldApplyBlendModeUsingBlendFunc(quad) || |
996 quad->shared_quad_state->blend_mode != SkXfermode::kSrcOver_Mode || | 1015 !quad->background_filters.IsEmpty(); |
997 !quad->background_filters.IsEmpty(); | |
998 bool background_changed = false; | 1016 bool background_changed = false; |
999 scoped_ptr<ScopedResource> background_texture; | 1017 scoped_ptr<ScopedResource> background_texture; |
1000 if (need_background_texture) { | 1018 if (need_background_texture) { |
1001 // The pixels from the filtered background should completely replace the | 1019 // The pixels from the filtered background should completely replace the |
1002 // current pixel values. | 1020 // current pixel values. |
1003 bool disable_blending = blend_enabled(); | 1021 bool disable_blending = blend_enabled(); |
1004 if (disable_blending) | 1022 if (disable_blending) |
1005 SetBlendEnabled(false); | 1023 SetBlendEnabled(false); |
1006 | 1024 |
1007 background_texture = | 1025 background_texture = |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1041 ApplyImageFilter(ScopedUseGrContext::Create(this, frame), | 1059 ApplyImageFilter(ScopedUseGrContext::Create(this, frame), |
1042 resource_provider_, | 1060 resource_provider_, |
1043 quad->rect.origin(), | 1061 quad->rect.origin(), |
1044 quad->filters_scale, | 1062 quad->filters_scale, |
1045 filter.get(), | 1063 filter.get(), |
1046 contents_texture); | 1064 contents_texture); |
1047 } | 1065 } |
1048 } | 1066 } |
1049 } | 1067 } |
1050 | 1068 |
1051 if (quad->shared_quad_state->blend_mode != SkXfermode::kSrcOver_Mode && | 1069 if (background_texture && !ShouldApplyBlendModeUsingBlendFunc(quad)) { |
1052 background_texture) { | |
1053 filter_bitmap = | 1070 filter_bitmap = |
1054 ApplyBlendModeWithBackdrop(ScopedUseGrContext::Create(this, frame), | 1071 ApplyBlendModeWithBackdrop(ScopedUseGrContext::Create(this, frame), |
1055 resource_provider_, | 1072 resource_provider_, |
1056 filter_bitmap, | 1073 filter_bitmap, |
1057 contents_texture, | 1074 contents_texture, |
1058 background_texture.get(), | 1075 background_texture.get(), |
1059 quad->shared_quad_state->blend_mode); | 1076 quad->shared_quad_state->blend_mode); |
1060 } | 1077 } |
1061 | 1078 |
1062 // Draw the background texture if it has some filters applied. | 1079 // Draw the background texture if it has some filters applied. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1110 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); | 1127 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); |
1111 gl_->BindTexture(GL_TEXTURE_2D, texture->getTextureHandle()); | 1128 gl_->BindTexture(GL_TEXTURE_2D, texture->getTextureHandle()); |
1112 } else { | 1129 } else { |
1113 contents_resource_lock = | 1130 contents_resource_lock = |
1114 make_scoped_ptr(new ResourceProvider::ScopedSamplerGL( | 1131 make_scoped_ptr(new ResourceProvider::ScopedSamplerGL( |
1115 resource_provider_, contents_texture->id(), GL_LINEAR)); | 1132 resource_provider_, contents_texture->id(), GL_LINEAR)); |
1116 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), | 1133 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), |
1117 contents_resource_lock->target()); | 1134 contents_resource_lock->target()); |
1118 } | 1135 } |
1119 | 1136 |
1137 if (ShouldApplyBlendModeUsingBlendFunc(quad)) | |
1138 ApplyBlendModeUsingBlendFunc(quad); | |
1139 | |
1120 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 1140 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
1121 gl_, | 1141 gl_, |
1122 &highp_threshold_cache_, | 1142 &highp_threshold_cache_, |
1123 highp_threshold_min_, | 1143 highp_threshold_min_, |
1124 quad->shared_quad_state->visible_content_rect.bottom_right()); | 1144 quad->shared_quad_state->visible_content_rect.bottom_right()); |
1125 | 1145 |
1126 int shader_quad_location = -1; | 1146 int shader_quad_location = -1; |
1127 int shader_edge_location = -1; | 1147 int shader_edge_location = -1; |
1128 int shader_viewport_location = -1; | 1148 int shader_viewport_location = -1; |
1129 int shader_mask_sampler_location = -1; | 1149 int shader_mask_sampler_location = -1; |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1356 | 1376 |
1357 SetShaderOpacity(quad->opacity(), shader_alpha_location); | 1377 SetShaderOpacity(quad->opacity(), shader_alpha_location); |
1358 SetShaderQuadF(surface_quad, shader_quad_location); | 1378 SetShaderQuadF(surface_quad, shader_quad_location); |
1359 DrawQuadGeometry( | 1379 DrawQuadGeometry( |
1360 frame, quad->quadTransform(), quad->rect, shader_matrix_location); | 1380 frame, quad->quadTransform(), quad->rect, shader_matrix_location); |
1361 | 1381 |
1362 // Flush the compositor context before the filter bitmap goes out of | 1382 // Flush the compositor context before the filter bitmap goes out of |
1363 // scope, so the draw gets processed before the filter texture gets deleted. | 1383 // scope, so the draw gets processed before the filter texture gets deleted. |
1364 if (filter_bitmap) | 1384 if (filter_bitmap) |
1365 GLC(gl_, gl_->Flush()); | 1385 GLC(gl_, gl_->Flush()); |
1386 | |
1387 if (ShouldApplyBlendModeUsingBlendFunc(quad)) | |
1388 RestoreBlendFuncToDefault(quad); | |
1366 } | 1389 } |
1367 | 1390 |
1368 struct SolidColorProgramUniforms { | 1391 struct SolidColorProgramUniforms { |
1369 unsigned program; | 1392 unsigned program; |
1370 unsigned matrix_location; | 1393 unsigned matrix_location; |
1371 unsigned viewport_location; | 1394 unsigned viewport_location; |
1372 unsigned quad_location; | 1395 unsigned quad_location; |
1373 unsigned edge_location; | 1396 unsigned edge_location; |
1374 unsigned color_location; | 1397 unsigned color_location; |
1375 }; | 1398 }; |
(...skipping 1826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3202 context_support_->ScheduleOverlayPlane( | 3225 context_support_->ScheduleOverlayPlane( |
3203 overlay.plane_z_order, | 3226 overlay.plane_z_order, |
3204 overlay.transform, | 3227 overlay.transform, |
3205 pending_overlay_resources_.back()->texture_id(), | 3228 pending_overlay_resources_.back()->texture_id(), |
3206 overlay.display_rect, | 3229 overlay.display_rect, |
3207 overlay.uv_rect); | 3230 overlay.uv_rect); |
3208 } | 3231 } |
3209 } | 3232 } |
3210 | 3233 |
3211 } // namespace cc | 3234 } // namespace cc |
OLD | NEW |