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

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

Issue 614953002: Accelerate the lighten blendmode if GL_EXT_blend_minmax is enabled. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add IsDefaultBlendMode 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') | content/common/gpu/gpu_messages.h » ('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 <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 capabilities_.allow_partial_texture_updates = true; 331 capabilities_.allow_partial_texture_updates = true;
332 332
333 capabilities_.using_image = context_caps.gpu.image; 333 capabilities_.using_image = context_caps.gpu.image;
334 334
335 capabilities_.using_discard_framebuffer = 335 capabilities_.using_discard_framebuffer =
336 context_caps.gpu.discard_framebuffer; 336 context_caps.gpu.discard_framebuffer;
337 337
338 capabilities_.allow_rasterize_on_demand = true; 338 capabilities_.allow_rasterize_on_demand = true;
339 339
340 use_sync_query_ = context_caps.gpu.sync_query; 340 use_sync_query_ = context_caps.gpu.sync_query;
341 use_blend_minmax = context_caps.gpu.blend_minmax;
341 342
342 InitializeSharedObjects(); 343 InitializeSharedObjects();
343 } 344 }
344 345
345 GLRenderer::~GLRenderer() { 346 GLRenderer::~GLRenderer() {
346 while (!pending_async_read_pixels_.empty()) { 347 while (!pending_async_read_pixels_.empty()) {
347 PendingAsyncReadPixels* pending_read = pending_async_read_pixels_.back(); 348 PendingAsyncReadPixels* pending_read = pending_async_read_pixels_.back();
348 pending_read->finished_read_pixels_callback.Cancel(); 349 pending_read->finished_read_pixels_callback.Cancel();
349 pending_async_read_pixels_.pop_back(); 350 pending_async_read_pixels_.pop_back();
350 } 351 }
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 } 695 }
695 696
696 // Flush the GrContext to ensure all buffered GL calls are drawn to the 697 // Flush the GrContext to ensure all buffered GL calls are drawn to the
697 // backing store before we access and return it, and have cc begin using the 698 // backing store before we access and return it, and have cc begin using the
698 // GL context again. 699 // GL context again.
699 canvas->flush(); 700 canvas->flush();
700 701
701 return image; 702 return image;
702 } 703 }
703 704
704 bool GLRenderer::ShouldApplyBlendModeUsingBlendFunc(const DrawQuad* quad) { 705 bool GLRenderer::CanApplyBlendModeUsingBlendFunc(SkXfermode::Mode blend_mode) {
705 SkXfermode::Mode blend_mode = quad->shared_quad_state->blend_mode; 706 return (use_blend_minmax && blend_mode == SkXfermode::kLighten_Mode) ||
706 return blend_mode == SkXfermode::kScreen_Mode || 707 blend_mode == SkXfermode::kScreen_Mode ||
707 blend_mode == SkXfermode::kSrcOver_Mode; 708 blend_mode == SkXfermode::kSrcOver_Mode;
708 } 709 }
709 710
710 void GLRenderer::ApplyBlendModeUsingBlendFunc(const DrawQuad* quad) { 711 void GLRenderer::ApplyBlendModeUsingBlendFunc(SkXfermode::Mode blend_mode) {
711 DCHECK(ShouldApplyBlendModeUsingBlendFunc(quad)); 712 DCHECK(CanApplyBlendModeUsingBlendFunc(blend_mode));
712 if (quad->shared_quad_state->blend_mode == SkXfermode::kScreen_Mode) { 713
714 // Any modes set here must be reset in RestoreBlendFuncToDefault
715 if (blend_mode == SkXfermode::kScreen_Mode) {
713 GLC(gl_, gl_->BlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE)); 716 GLC(gl_, gl_->BlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE));
717 } else if (blend_mode == SkXfermode::kLighten_Mode) {
718 GLC(gl_, gl_->BlendFunc(GL_ONE, GL_ONE));
719 GLC(gl_, gl_->BlendEquation(GL_MAX_EXT));
714 } 720 }
715 } 721 }
716 722
717 void GLRenderer::RestoreBlendFuncToDefault() { 723 void GLRenderer::RestoreBlendFuncToDefault(SkXfermode::Mode blend_mode) {
724 if (blend_mode == SkXfermode::kSrcOver_Mode)
725 return;
726
718 GLC(gl_, gl_->BlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); 727 GLC(gl_, gl_->BlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA));
728
729 if (blend_mode == SkXfermode::kLighten_Mode)
730 GLC(gl_, gl_->BlendEquation(GL_FUNC_ADD));
719 } 731 }
720 732
721 static skia::RefPtr<SkImage> ApplyBlendModeWithBackdrop( 733 static skia::RefPtr<SkImage> ApplyBlendModeWithBackdrop(
722 scoped_ptr<GLRenderer::ScopedUseGrContext> use_gr_context, 734 scoped_ptr<GLRenderer::ScopedUseGrContext> use_gr_context,
723 ResourceProvider* resource_provider, 735 ResourceProvider* resource_provider,
724 skia::RefPtr<SkImage> source_bitmap_with_filters, 736 skia::RefPtr<SkImage> source_bitmap_with_filters,
725 ScopedResource* source_texture_resource, 737 ScopedResource* source_texture_resource,
726 ScopedResource* background_texture_resource, 738 ScopedResource* background_texture_resource,
727 SkXfermode::Mode blend_mode) { 739 SkXfermode::Mode blend_mode) {
728 if (!use_gr_context) 740 if (!use_gr_context)
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 996
985 UseRenderPass(frame, target_render_pass); 997 UseRenderPass(frame, target_render_pass);
986 998
987 if (!using_background_texture) 999 if (!using_background_texture)
988 return nullptr; 1000 return nullptr;
989 return background_texture.Pass(); 1001 return background_texture.Pass();
990 } 1002 }
991 1003
992 void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame, 1004 void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame,
993 const RenderPassDrawQuad* quad) { 1005 const RenderPassDrawQuad* quad) {
1006 SkXfermode::Mode blend_mode = quad->shared_quad_state->blend_mode;
994 SetBlendEnabled(quad->ShouldDrawWithBlending() || 1007 SetBlendEnabled(quad->ShouldDrawWithBlending() ||
995 ShouldApplyBlendModeUsingBlendFunc(quad)); 1008 (!IsDefaultBlendMode(blend_mode) &&
1009 CanApplyBlendModeUsingBlendFunc(blend_mode)));
996 1010
997 ScopedResource* contents_texture = 1011 ScopedResource* contents_texture =
998 render_pass_textures_.get(quad->render_pass_id); 1012 render_pass_textures_.get(quad->render_pass_id);
999 if (!contents_texture || !contents_texture->id()) 1013 if (!contents_texture || !contents_texture->id())
1000 return; 1014 return;
1001 1015
1002 gfx::Transform quad_rect_matrix; 1016 gfx::Transform quad_rect_matrix;
1003 QuadRectTransform(&quad_rect_matrix, quad->quadTransform(), quad->rect); 1017 QuadRectTransform(&quad_rect_matrix, quad->quadTransform(), quad->rect);
1004 gfx::Transform contents_device_transform = 1018 gfx::Transform contents_device_transform =
1005 frame->window_matrix * frame->projection_matrix * quad_rect_matrix; 1019 frame->window_matrix * frame->projection_matrix * quad_rect_matrix;
1006 contents_device_transform.FlattenTo2d(); 1020 contents_device_transform.FlattenTo2d();
1007 1021
1008 // Can only draw surface if device matrix is invertible. 1022 // Can only draw surface if device matrix is invertible.
1009 gfx::Transform contents_device_transform_inverse( 1023 gfx::Transform contents_device_transform_inverse(
1010 gfx::Transform::kSkipInitialization); 1024 gfx::Transform::kSkipInitialization);
1011 if (!contents_device_transform.GetInverse(&contents_device_transform_inverse)) 1025 if (!contents_device_transform.GetInverse(&contents_device_transform_inverse))
1012 return; 1026 return;
1013 1027
1014 bool need_background_texture = !ShouldApplyBlendModeUsingBlendFunc(quad) || 1028 bool need_background_texture = !CanApplyBlendModeUsingBlendFunc(blend_mode) ||
1015 !quad->background_filters.IsEmpty(); 1029 !quad->background_filters.IsEmpty();
1016 bool background_changed = false; 1030 bool background_changed = false;
1017 scoped_ptr<ScopedResource> background_texture; 1031 scoped_ptr<ScopedResource> background_texture;
1018 if (need_background_texture) { 1032 if (need_background_texture) {
1019 // The pixels from the filtered background should completely replace the 1033 // The pixels from the filtered background should completely replace the
1020 // current pixel values. 1034 // current pixel values.
1021 bool disable_blending = blend_enabled(); 1035 bool disable_blending = blend_enabled();
1022 if (disable_blending) 1036 if (disable_blending)
1023 SetBlendEnabled(false); 1037 SetBlendEnabled(false);
1024 1038
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1059 ApplyImageFilter(ScopedUseGrContext::Create(this, frame), 1073 ApplyImageFilter(ScopedUseGrContext::Create(this, frame),
1060 resource_provider_, 1074 resource_provider_,
1061 quad->rect.origin(), 1075 quad->rect.origin(),
1062 quad->filters_scale, 1076 quad->filters_scale,
1063 filter.get(), 1077 filter.get(),
1064 contents_texture); 1078 contents_texture);
1065 } 1079 }
1066 } 1080 }
1067 } 1081 }
1068 1082
1069 if (background_texture && !ShouldApplyBlendModeUsingBlendFunc(quad)) { 1083 if (background_texture && !CanApplyBlendModeUsingBlendFunc(blend_mode)) {
enne (OOO) 2014/10/07 17:51:17 I think this CanApplyBlendModeUsingBlendFunc check
Erik Dahlström (inactive) 2014/10/08 15:25:20 No, I don't think it's redundant, have a look at t
1070 filter_bitmap = 1084 filter_bitmap =
1071 ApplyBlendModeWithBackdrop(ScopedUseGrContext::Create(this, frame), 1085 ApplyBlendModeWithBackdrop(ScopedUseGrContext::Create(this, frame),
1072 resource_provider_, 1086 resource_provider_,
1073 filter_bitmap, 1087 filter_bitmap,
1074 contents_texture, 1088 contents_texture,
1075 background_texture.get(), 1089 background_texture.get(),
1076 quad->shared_quad_state->blend_mode); 1090 quad->shared_quad_state->blend_mode);
1077 } 1091 }
1078 1092
1079 // Draw the background texture if it has some filters applied. 1093 // Draw the background texture if it has some filters applied.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1127 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); 1141 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_));
1128 gl_->BindTexture(GL_TEXTURE_2D, texture->getTextureHandle()); 1142 gl_->BindTexture(GL_TEXTURE_2D, texture->getTextureHandle());
1129 } else { 1143 } else {
1130 contents_resource_lock = 1144 contents_resource_lock =
1131 make_scoped_ptr(new ResourceProvider::ScopedSamplerGL( 1145 make_scoped_ptr(new ResourceProvider::ScopedSamplerGL(
1132 resource_provider_, contents_texture->id(), GL_LINEAR)); 1146 resource_provider_, contents_texture->id(), GL_LINEAR));
1133 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), 1147 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D),
1134 contents_resource_lock->target()); 1148 contents_resource_lock->target());
1135 } 1149 }
1136 1150
1137 if (ShouldApplyBlendModeUsingBlendFunc(quad)) 1151 if (CanApplyBlendModeUsingBlendFunc(blend_mode))
1138 ApplyBlendModeUsingBlendFunc(quad); 1152 ApplyBlendModeUsingBlendFunc(blend_mode);
1139 1153
1140 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( 1154 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired(
1141 gl_, 1155 gl_,
1142 &highp_threshold_cache_, 1156 &highp_threshold_cache_,
1143 highp_threshold_min_, 1157 highp_threshold_min_,
1144 quad->shared_quad_state->visible_content_rect.bottom_right()); 1158 quad->shared_quad_state->visible_content_rect.bottom_right());
1145 1159
1146 int shader_quad_location = -1; 1160 int shader_quad_location = -1;
1147 int shader_edge_location = -1; 1161 int shader_edge_location = -1;
1148 int shader_viewport_location = -1; 1162 int shader_viewport_location = -1;
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
1377 SetShaderOpacity(quad->opacity(), shader_alpha_location); 1391 SetShaderOpacity(quad->opacity(), shader_alpha_location);
1378 SetShaderQuadF(surface_quad, shader_quad_location); 1392 SetShaderQuadF(surface_quad, shader_quad_location);
1379 DrawQuadGeometry( 1393 DrawQuadGeometry(
1380 frame, quad->quadTransform(), quad->rect, shader_matrix_location); 1394 frame, quad->quadTransform(), quad->rect, shader_matrix_location);
1381 1395
1382 // Flush the compositor context before the filter bitmap goes out of 1396 // Flush the compositor context before the filter bitmap goes out of
1383 // scope, so the draw gets processed before the filter texture gets deleted. 1397 // scope, so the draw gets processed before the filter texture gets deleted.
1384 if (filter_bitmap) 1398 if (filter_bitmap)
1385 GLC(gl_, gl_->Flush()); 1399 GLC(gl_, gl_->Flush());
1386 1400
1387 if (ShouldApplyBlendModeUsingBlendFunc(quad)) 1401 if (CanApplyBlendModeUsingBlendFunc(blend_mode))
1388 RestoreBlendFuncToDefault(); 1402 RestoreBlendFuncToDefault(blend_mode);
1389 } 1403 }
1390 1404
1391 struct SolidColorProgramUniforms { 1405 struct SolidColorProgramUniforms {
1392 unsigned program; 1406 unsigned program;
1393 unsigned matrix_location; 1407 unsigned matrix_location;
1394 unsigned viewport_location; 1408 unsigned viewport_location;
1395 unsigned quad_location; 1409 unsigned quad_location;
1396 unsigned edge_location; 1410 unsigned edge_location;
1397 unsigned color_location; 1411 unsigned color_location;
1398 }; 1412 };
(...skipping 1824 matching lines...) Expand 10 before | Expand all | Expand 10 after
3223 context_support_->ScheduleOverlayPlane( 3237 context_support_->ScheduleOverlayPlane(
3224 overlay.plane_z_order, 3238 overlay.plane_z_order,
3225 overlay.transform, 3239 overlay.transform,
3226 pending_overlay_resources_.back()->texture_id(), 3240 pending_overlay_resources_.back()->texture_id(),
3227 overlay.display_rect, 3241 overlay.display_rect,
3228 overlay.uv_rect); 3242 overlay.uv_rect);
3229 } 3243 }
3230 } 3244 }
3231 3245
3232 } // namespace cc 3246 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/gl_renderer.h ('k') | content/common/gpu/gpu_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698