Chromium Code Reviews| 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::ShouldApplyBackgroundFilters(DrawingFrame* frame, | |
|
enne (OOO)
2014/09/26 18:20:36
How is this related to this change?
Erik Dahlström (inactive)
2014/09/29 08:33:41
You're right, it's not really related, I'll drop t
| |
| 704 const RenderPassDrawQuad* quad) { | |
| 705 if (quad->background_filters.IsEmpty()) | |
| 706 return false; | |
| 707 | |
| 708 // TODO(danakj): We only allow background filters on an opaque render surface | |
| 709 // because other surfaces may contain translucent pixels, and the contents | |
| 710 // behind those translucent pixels wouldn't have the filter applied. | |
| 711 if (frame->current_render_pass->has_transparent_background) | |
| 712 return false; | |
| 713 | |
| 714 // TODO(ajuma): Add support for reference filters once | |
| 715 // FilterOperations::GetOutsets supports reference filters. | |
| 716 if (quad->background_filters.HasReferenceFilter()) | |
| 717 return false; | |
| 718 return true; | |
| 719 } | |
| 720 | |
| 721 bool GLRenderer::ShouldApplyBlendModeUsingBlendFunc(const DrawQuad* quad) { | |
| 722 SkXfermode::Mode blend_mode = quad->shared_quad_state->blend_mode; | |
| 723 return blend_mode == SkXfermode::kScreen_Mode; | |
| 724 } | |
| 725 | |
| 726 void GLRenderer::ApplyBlendModeUsingBlendFunc(const DrawQuad* quad) { | |
| 727 DCHECK(ShouldApplyBlendModeUsingBlendFunc(quad)); | |
| 728 if (quad->shared_quad_state->blend_mode == SkXfermode::kScreen_Mode) { | |
| 729 GLC(gl_, gl_->BlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE)); | |
| 730 } | |
| 731 } | |
| 732 | |
| 733 void GLRenderer::RestoreBlendFuncToDefault(const DrawQuad* quad) { | |
| 734 DCHECK(ShouldApplyBlendModeUsingBlendFunc(quad)); | |
| 735 GLC(gl_, gl_->BlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); | |
| 736 } | |
| 737 | |
| 703 static skia::RefPtr<SkImage> ApplyBlendModeWithBackdrop( | 738 static skia::RefPtr<SkImage> ApplyBlendModeWithBackdrop( |
| 704 scoped_ptr<GLRenderer::ScopedUseGrContext> use_gr_context, | 739 scoped_ptr<GLRenderer::ScopedUseGrContext> use_gr_context, |
| 705 ResourceProvider* resource_provider, | 740 ResourceProvider* resource_provider, |
| 706 skia::RefPtr<SkImage> source_bitmap_with_filters, | 741 skia::RefPtr<SkImage> source_bitmap_with_filters, |
| 707 ScopedResource* source_texture_resource, | 742 ScopedResource* source_texture_resource, |
| 708 ScopedResource* background_texture_resource, | 743 ScopedResource* background_texture_resource, |
| 709 SkXfermode::Mode blend_mode) { | 744 SkXfermode::Mode blend_mode) { |
| 710 if (!use_gr_context) | 745 if (!use_gr_context) |
| 711 return source_bitmap_with_filters; | 746 return source_bitmap_with_filters; |
| 712 | 747 |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 966 | 1001 |
| 967 UseRenderPass(frame, target_render_pass); | 1002 UseRenderPass(frame, target_render_pass); |
| 968 | 1003 |
| 969 if (!using_background_texture) | 1004 if (!using_background_texture) |
| 970 return scoped_ptr<ScopedResource>(); | 1005 return scoped_ptr<ScopedResource>(); |
| 971 return background_texture.Pass(); | 1006 return background_texture.Pass(); |
| 972 } | 1007 } |
| 973 | 1008 |
| 974 void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame, | 1009 void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame, |
| 975 const RenderPassDrawQuad* quad) { | 1010 const RenderPassDrawQuad* quad) { |
| 976 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 1011 SetBlendEnabled(quad->ShouldDrawWithBlending() || |
| 1012 ShouldApplyBlendModeUsingBlendFunc(quad)); | |
| 977 | 1013 |
| 978 ScopedResource* contents_texture = | 1014 ScopedResource* contents_texture = |
| 979 render_pass_textures_.get(quad->render_pass_id); | 1015 render_pass_textures_.get(quad->render_pass_id); |
| 980 if (!contents_texture || !contents_texture->id()) | 1016 if (!contents_texture || !contents_texture->id()) |
| 981 return; | 1017 return; |
| 982 | 1018 |
| 983 gfx::Transform quad_rect_matrix; | 1019 gfx::Transform quad_rect_matrix; |
| 984 QuadRectTransform(&quad_rect_matrix, quad->quadTransform(), quad->rect); | 1020 QuadRectTransform(&quad_rect_matrix, quad->quadTransform(), quad->rect); |
| 985 gfx::Transform contents_device_transform = | 1021 gfx::Transform contents_device_transform = |
| 986 frame->window_matrix * frame->projection_matrix * quad_rect_matrix; | 1022 frame->window_matrix * frame->projection_matrix * quad_rect_matrix; |
| 987 contents_device_transform.FlattenTo2d(); | 1023 contents_device_transform.FlattenTo2d(); |
| 988 | 1024 |
| 989 // Can only draw surface if device matrix is invertible. | 1025 // Can only draw surface if device matrix is invertible. |
| 990 gfx::Transform contents_device_transform_inverse( | 1026 gfx::Transform contents_device_transform_inverse( |
| 991 gfx::Transform::kSkipInitialization); | 1027 gfx::Transform::kSkipInitialization); |
| 992 if (!contents_device_transform.GetInverse(&contents_device_transform_inverse)) | 1028 if (!contents_device_transform.GetInverse(&contents_device_transform_inverse)) |
| 993 return; | 1029 return; |
| 994 | 1030 |
| 995 bool need_background_texture = | 1031 bool need_background_texture = |
| 996 quad->shared_quad_state->blend_mode != SkXfermode::kSrcOver_Mode || | 1032 (quad->shared_quad_state->blend_mode != SkXfermode::kSrcOver_Mode && |
| 997 !quad->background_filters.IsEmpty(); | 1033 !ShouldApplyBlendModeUsingBlendFunc(quad)) || |
|
enne (OOO)
2014/09/26 18:20:36
Could you combine ShouldApplyBlendModeUsingBlendFu
Erik Dahlström (inactive)
2014/09/29 08:33:41
Done.
| |
| 1034 ShouldApplyBackgroundFilters(frame, quad); | |
| 998 bool background_changed = false; | 1035 bool background_changed = false; |
| 999 scoped_ptr<ScopedResource> background_texture; | 1036 scoped_ptr<ScopedResource> background_texture; |
| 1000 if (need_background_texture) { | 1037 if (need_background_texture) { |
| 1001 // The pixels from the filtered background should completely replace the | 1038 // The pixels from the filtered background should completely replace the |
| 1002 // current pixel values. | 1039 // current pixel values. |
| 1003 bool disable_blending = blend_enabled(); | 1040 bool disable_blending = blend_enabled(); |
| 1004 if (disable_blending) | 1041 if (disable_blending) |
| 1005 SetBlendEnabled(false); | 1042 SetBlendEnabled(false); |
| 1006 | 1043 |
| 1007 background_texture = | 1044 background_texture = |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1042 resource_provider_, | 1079 resource_provider_, |
| 1043 quad->rect.origin(), | 1080 quad->rect.origin(), |
| 1044 quad->filters_scale, | 1081 quad->filters_scale, |
| 1045 filter.get(), | 1082 filter.get(), |
| 1046 contents_texture); | 1083 contents_texture); |
| 1047 } | 1084 } |
| 1048 } | 1085 } |
| 1049 } | 1086 } |
| 1050 | 1087 |
| 1051 if (quad->shared_quad_state->blend_mode != SkXfermode::kSrcOver_Mode && | 1088 if (quad->shared_quad_state->blend_mode != SkXfermode::kSrcOver_Mode && |
| 1052 background_texture) { | 1089 background_texture && !ShouldApplyBlendModeUsingBlendFunc(quad)) { |
| 1053 filter_bitmap = | 1090 filter_bitmap = |
| 1054 ApplyBlendModeWithBackdrop(ScopedUseGrContext::Create(this, frame), | 1091 ApplyBlendModeWithBackdrop(ScopedUseGrContext::Create(this, frame), |
| 1055 resource_provider_, | 1092 resource_provider_, |
| 1056 filter_bitmap, | 1093 filter_bitmap, |
| 1057 contents_texture, | 1094 contents_texture, |
| 1058 background_texture.get(), | 1095 background_texture.get(), |
| 1059 quad->shared_quad_state->blend_mode); | 1096 quad->shared_quad_state->blend_mode); |
| 1060 } | 1097 } |
| 1061 | 1098 |
| 1062 // Draw the background texture if it has some filters applied. | 1099 // 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_)); | 1147 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); |
| 1111 gl_->BindTexture(GL_TEXTURE_2D, texture->getTextureHandle()); | 1148 gl_->BindTexture(GL_TEXTURE_2D, texture->getTextureHandle()); |
| 1112 } else { | 1149 } else { |
| 1113 contents_resource_lock = | 1150 contents_resource_lock = |
| 1114 make_scoped_ptr(new ResourceProvider::ScopedSamplerGL( | 1151 make_scoped_ptr(new ResourceProvider::ScopedSamplerGL( |
| 1115 resource_provider_, contents_texture->id(), GL_LINEAR)); | 1152 resource_provider_, contents_texture->id(), GL_LINEAR)); |
| 1116 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), | 1153 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), |
| 1117 contents_resource_lock->target()); | 1154 contents_resource_lock->target()); |
| 1118 } | 1155 } |
| 1119 | 1156 |
| 1157 if (ShouldApplyBlendModeUsingBlendFunc(quad)) | |
| 1158 ApplyBlendModeUsingBlendFunc(quad); | |
| 1159 | |
| 1120 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 1160 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
| 1121 gl_, | 1161 gl_, |
| 1122 &highp_threshold_cache_, | 1162 &highp_threshold_cache_, |
| 1123 highp_threshold_min_, | 1163 highp_threshold_min_, |
| 1124 quad->shared_quad_state->visible_content_rect.bottom_right()); | 1164 quad->shared_quad_state->visible_content_rect.bottom_right()); |
| 1125 | 1165 |
| 1126 int shader_quad_location = -1; | 1166 int shader_quad_location = -1; |
| 1127 int shader_edge_location = -1; | 1167 int shader_edge_location = -1; |
| 1128 int shader_viewport_location = -1; | 1168 int shader_viewport_location = -1; |
| 1129 int shader_mask_sampler_location = -1; | 1169 int shader_mask_sampler_location = -1; |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1356 | 1396 |
| 1357 SetShaderOpacity(quad->opacity(), shader_alpha_location); | 1397 SetShaderOpacity(quad->opacity(), shader_alpha_location); |
| 1358 SetShaderQuadF(surface_quad, shader_quad_location); | 1398 SetShaderQuadF(surface_quad, shader_quad_location); |
| 1359 DrawQuadGeometry( | 1399 DrawQuadGeometry( |
| 1360 frame, quad->quadTransform(), quad->rect, shader_matrix_location); | 1400 frame, quad->quadTransform(), quad->rect, shader_matrix_location); |
| 1361 | 1401 |
| 1362 // Flush the compositor context before the filter bitmap goes out of | 1402 // Flush the compositor context before the filter bitmap goes out of |
| 1363 // scope, so the draw gets processed before the filter texture gets deleted. | 1403 // scope, so the draw gets processed before the filter texture gets deleted. |
| 1364 if (filter_bitmap) | 1404 if (filter_bitmap) |
| 1365 GLC(gl_, gl_->Flush()); | 1405 GLC(gl_, gl_->Flush()); |
| 1406 | |
| 1407 if (ShouldApplyBlendModeUsingBlendFunc(quad)) | |
| 1408 RestoreBlendFuncToDefault(quad); | |
| 1366 } | 1409 } |
| 1367 | 1410 |
| 1368 struct SolidColorProgramUniforms { | 1411 struct SolidColorProgramUniforms { |
| 1369 unsigned program; | 1412 unsigned program; |
| 1370 unsigned matrix_location; | 1413 unsigned matrix_location; |
| 1371 unsigned viewport_location; | 1414 unsigned viewport_location; |
| 1372 unsigned quad_location; | 1415 unsigned quad_location; |
| 1373 unsigned edge_location; | 1416 unsigned edge_location; |
| 1374 unsigned color_location; | 1417 unsigned color_location; |
| 1375 }; | 1418 }; |
| (...skipping 1826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3202 context_support_->ScheduleOverlayPlane( | 3245 context_support_->ScheduleOverlayPlane( |
| 3203 overlay.plane_z_order, | 3246 overlay.plane_z_order, |
| 3204 overlay.transform, | 3247 overlay.transform, |
| 3205 pending_overlay_resources_.back()->texture_id(), | 3248 pending_overlay_resources_.back()->texture_id(), |
| 3206 overlay.display_rect, | 3249 overlay.display_rect, |
| 3207 overlay.uv_rect); | 3250 overlay.uv_rect); |
| 3208 } | 3251 } |
| 3209 } | 3252 } |
| 3210 | 3253 |
| 3211 } // namespace cc | 3254 } // namespace cc |
| OLD | NEW |