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

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

Issue 608523003: Implement mix-blend-mode=screen using glBlendFunc. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: really remove quad argument this time... Created 6 years, 2 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
« no previous file with comments | « cc/output/gl_renderer.h ('k') | no next file » | 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 <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
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() {
717 GLC(gl_, gl_->BlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA));
718 }
719
703 static skia::RefPtr<SkImage> ApplyBlendModeWithBackdrop( 720 static skia::RefPtr<SkImage> ApplyBlendModeWithBackdrop(
704 scoped_ptr<GLRenderer::ScopedUseGrContext> use_gr_context, 721 scoped_ptr<GLRenderer::ScopedUseGrContext> use_gr_context,
705 ResourceProvider* resource_provider, 722 ResourceProvider* resource_provider,
706 skia::RefPtr<SkImage> source_bitmap_with_filters, 723 skia::RefPtr<SkImage> source_bitmap_with_filters,
707 ScopedResource* source_texture_resource, 724 ScopedResource* source_texture_resource,
708 ScopedResource* background_texture_resource, 725 ScopedResource* background_texture_resource,
709 SkXfermode::Mode blend_mode) { 726 SkXfermode::Mode blend_mode) {
710 if (!use_gr_context) 727 if (!use_gr_context)
711 return source_bitmap_with_filters; 728 return source_bitmap_with_filters;
712 729
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
966 983
967 UseRenderPass(frame, target_render_pass); 984 UseRenderPass(frame, target_render_pass);
968 985
969 if (!using_background_texture) 986 if (!using_background_texture)
970 return scoped_ptr<ScopedResource>(); 987 return scoped_ptr<ScopedResource>();
971 return background_texture.Pass(); 988 return background_texture.Pass();
972 } 989 }
973 990
974 void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame, 991 void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame,
975 const RenderPassDrawQuad* quad) { 992 const RenderPassDrawQuad* quad) {
976 SetBlendEnabled(quad->ShouldDrawWithBlending()); 993 SetBlendEnabled(quad->ShouldDrawWithBlending() ||
994 ShouldApplyBlendModeUsingBlendFunc(quad));
977 995
978 ScopedResource* contents_texture = 996 ScopedResource* contents_texture =
979 render_pass_textures_.get(quad->render_pass_id); 997 render_pass_textures_.get(quad->render_pass_id);
980 if (!contents_texture || !contents_texture->id()) 998 if (!contents_texture || !contents_texture->id())
981 return; 999 return;
982 1000
983 gfx::Transform quad_rect_matrix; 1001 gfx::Transform quad_rect_matrix;
984 QuadRectTransform(&quad_rect_matrix, quad->quadTransform(), quad->rect); 1002 QuadRectTransform(&quad_rect_matrix, quad->quadTransform(), quad->rect);
985 gfx::Transform contents_device_transform = 1003 gfx::Transform contents_device_transform =
986 frame->window_matrix * frame->projection_matrix * quad_rect_matrix; 1004 frame->window_matrix * frame->projection_matrix * quad_rect_matrix;
987 contents_device_transform.FlattenTo2d(); 1005 contents_device_transform.FlattenTo2d();
988 1006
989 // Can only draw surface if device matrix is invertible. 1007 // Can only draw surface if device matrix is invertible.
990 gfx::Transform contents_device_transform_inverse( 1008 gfx::Transform contents_device_transform_inverse(
991 gfx::Transform::kSkipInitialization); 1009 gfx::Transform::kSkipInitialization);
992 if (!contents_device_transform.GetInverse(&contents_device_transform_inverse)) 1010 if (!contents_device_transform.GetInverse(&contents_device_transform_inverse))
993 return; 1011 return;
994 1012
995 bool need_background_texture = 1013 bool need_background_texture = !ShouldApplyBlendModeUsingBlendFunc(quad) ||
996 quad->shared_quad_state->blend_mode != SkXfermode::kSrcOver_Mode || 1014 !quad->background_filters.IsEmpty();
997 !quad->background_filters.IsEmpty();
998 bool background_changed = false; 1015 bool background_changed = false;
999 scoped_ptr<ScopedResource> background_texture; 1016 scoped_ptr<ScopedResource> background_texture;
1000 if (need_background_texture) { 1017 if (need_background_texture) {
1001 // The pixels from the filtered background should completely replace the 1018 // The pixels from the filtered background should completely replace the
1002 // current pixel values. 1019 // current pixel values.
1003 bool disable_blending = blend_enabled(); 1020 bool disable_blending = blend_enabled();
1004 if (disable_blending) 1021 if (disable_blending)
1005 SetBlendEnabled(false); 1022 SetBlendEnabled(false);
1006 1023
1007 background_texture = 1024 background_texture =
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1041 ApplyImageFilter(ScopedUseGrContext::Create(this, frame), 1058 ApplyImageFilter(ScopedUseGrContext::Create(this, frame),
1042 resource_provider_, 1059 resource_provider_,
1043 quad->rect.origin(), 1060 quad->rect.origin(),
1044 quad->filters_scale, 1061 quad->filters_scale,
1045 filter.get(), 1062 filter.get(),
1046 contents_texture); 1063 contents_texture);
1047 } 1064 }
1048 } 1065 }
1049 } 1066 }
1050 1067
1051 if (quad->shared_quad_state->blend_mode != SkXfermode::kSrcOver_Mode && 1068 if (background_texture && !ShouldApplyBlendModeUsingBlendFunc(quad)) {
1052 background_texture) {
1053 filter_bitmap = 1069 filter_bitmap =
1054 ApplyBlendModeWithBackdrop(ScopedUseGrContext::Create(this, frame), 1070 ApplyBlendModeWithBackdrop(ScopedUseGrContext::Create(this, frame),
1055 resource_provider_, 1071 resource_provider_,
1056 filter_bitmap, 1072 filter_bitmap,
1057 contents_texture, 1073 contents_texture,
1058 background_texture.get(), 1074 background_texture.get(),
1059 quad->shared_quad_state->blend_mode); 1075 quad->shared_quad_state->blend_mode);
1060 } 1076 }
1061 1077
1062 // Draw the background texture if it has some filters applied. 1078 // Draw the background texture if it has some filters applied.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1110 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); 1126 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_));
1111 gl_->BindTexture(GL_TEXTURE_2D, texture->getTextureHandle()); 1127 gl_->BindTexture(GL_TEXTURE_2D, texture->getTextureHandle());
1112 } else { 1128 } else {
1113 contents_resource_lock = 1129 contents_resource_lock =
1114 make_scoped_ptr(new ResourceProvider::ScopedSamplerGL( 1130 make_scoped_ptr(new ResourceProvider::ScopedSamplerGL(
1115 resource_provider_, contents_texture->id(), GL_LINEAR)); 1131 resource_provider_, contents_texture->id(), GL_LINEAR));
1116 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), 1132 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D),
1117 contents_resource_lock->target()); 1133 contents_resource_lock->target());
1118 } 1134 }
1119 1135
1136 if (ShouldApplyBlendModeUsingBlendFunc(quad))
1137 ApplyBlendModeUsingBlendFunc(quad);
1138
1120 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( 1139 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired(
1121 gl_, 1140 gl_,
1122 &highp_threshold_cache_, 1141 &highp_threshold_cache_,
1123 highp_threshold_min_, 1142 highp_threshold_min_,
1124 quad->shared_quad_state->visible_content_rect.bottom_right()); 1143 quad->shared_quad_state->visible_content_rect.bottom_right());
1125 1144
1126 int shader_quad_location = -1; 1145 int shader_quad_location = -1;
1127 int shader_edge_location = -1; 1146 int shader_edge_location = -1;
1128 int shader_viewport_location = -1; 1147 int shader_viewport_location = -1;
1129 int shader_mask_sampler_location = -1; 1148 int shader_mask_sampler_location = -1;
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
1356 1375
1357 SetShaderOpacity(quad->opacity(), shader_alpha_location); 1376 SetShaderOpacity(quad->opacity(), shader_alpha_location);
1358 SetShaderQuadF(surface_quad, shader_quad_location); 1377 SetShaderQuadF(surface_quad, shader_quad_location);
1359 DrawQuadGeometry( 1378 DrawQuadGeometry(
1360 frame, quad->quadTransform(), quad->rect, shader_matrix_location); 1379 frame, quad->quadTransform(), quad->rect, shader_matrix_location);
1361 1380
1362 // Flush the compositor context before the filter bitmap goes out of 1381 // Flush the compositor context before the filter bitmap goes out of
1363 // scope, so the draw gets processed before the filter texture gets deleted. 1382 // scope, so the draw gets processed before the filter texture gets deleted.
1364 if (filter_bitmap) 1383 if (filter_bitmap)
1365 GLC(gl_, gl_->Flush()); 1384 GLC(gl_, gl_->Flush());
1385
1386 if (ShouldApplyBlendModeUsingBlendFunc(quad))
1387 RestoreBlendFuncToDefault();
1366 } 1388 }
1367 1389
1368 struct SolidColorProgramUniforms { 1390 struct SolidColorProgramUniforms {
1369 unsigned program; 1391 unsigned program;
1370 unsigned matrix_location; 1392 unsigned matrix_location;
1371 unsigned viewport_location; 1393 unsigned viewport_location;
1372 unsigned quad_location; 1394 unsigned quad_location;
1373 unsigned edge_location; 1395 unsigned edge_location;
1374 unsigned color_location; 1396 unsigned color_location;
1375 }; 1397 };
(...skipping 1826 matching lines...) Expand 10 before | Expand all | Expand 10 after
3202 context_support_->ScheduleOverlayPlane( 3224 context_support_->ScheduleOverlayPlane(
3203 overlay.plane_z_order, 3225 overlay.plane_z_order,
3204 overlay.transform, 3226 overlay.transform,
3205 pending_overlay_resources_.back()->texture_id(), 3227 pending_overlay_resources_.back()->texture_id(),
3206 overlay.display_rect, 3228 overlay.display_rect,
3207 overlay.uv_rect); 3229 overlay.uv_rect);
3208 } 3230 }
3209 } 3231 }
3210 3232
3211 } // namespace cc 3233 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/gl_renderer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698