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

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_android.cc

Issue 2147873003: cc: Dedup IPCs to return resources to client (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 5 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/renderer_host/render_widget_host_view_android.h" 5 #include "content/browser/renderer_host/render_widget_host_view_android.h"
6 6
7 #include <android/bitmap.h> 7 #include <android/bitmap.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/android/build_info.h" 11 #include "base/android/build_info.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/callback_helpers.h" 13 #include "base/callback_helpers.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/location.h" 15 #include "base/location.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/memory/ptr_util.h" 18 #include "base/memory/ptr_util.h"
19 #include "base/metrics/histogram.h" 19 #include "base/metrics/histogram.h"
20 #include "base/single_thread_task_runner.h" 20 #include "base/single_thread_task_runner.h"
21 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
22 #include "base/sys_info.h" 22 #include "base/sys_info.h"
23 #include "base/threading/thread_task_runner_handle.h" 23 #include "base/threading/thread_task_runner_handle.h"
24 #include "base/threading/worker_pool.h" 24 #include "base/threading/worker_pool.h"
25 #include "cc/layers/layer.h" 25 #include "cc/layers/layer.h"
26 #include "cc/layers/surface_layer.h" 26 #include "cc/layers/surface_layer.h"
27 #include "cc/output/compositor_frame.h" 27 #include "cc/output/compositor_frame.h"
28 #include "cc/output/compositor_frame_ack.h"
29 #include "cc/output/copy_output_request.h" 28 #include "cc/output/copy_output_request.h"
30 #include "cc/output/copy_output_result.h" 29 #include "cc/output/copy_output_result.h"
31 #include "cc/output/latency_info_swap_promise.h" 30 #include "cc/output/latency_info_swap_promise.h"
32 #include "cc/resources/single_release_callback.h" 31 #include "cc/resources/single_release_callback.h"
33 #include "cc/surfaces/surface.h" 32 #include "cc/surfaces/surface.h"
34 #include "cc/surfaces/surface_factory.h" 33 #include "cc/surfaces/surface_factory.h"
35 #include "cc/surfaces/surface_id_allocator.h" 34 #include "cc/surfaces/surface_id_allocator.h"
36 #include "cc/surfaces/surface_manager.h" 35 #include "cc/surfaces/surface_manager.h"
37 #include "cc/trees/layer_tree_host.h" 36 #include "cc/trees/layer_tree_host.h"
38 #include "components/display_compositor/gl_helper.h" 37 #include "components/display_compositor/gl_helper.h"
(...skipping 891 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 content_view_core_->ShowDisambiguationPopup(rect_pixels, zoomed_bitmap); 929 content_view_core_->ShowDisambiguationPopup(rect_pixels, zoomed_bitmap);
931 } 930 }
932 931
933 std::unique_ptr<SyntheticGestureTarget> 932 std::unique_ptr<SyntheticGestureTarget>
934 RenderWidgetHostViewAndroid::CreateSyntheticGestureTarget() { 933 RenderWidgetHostViewAndroid::CreateSyntheticGestureTarget() {
935 return std::unique_ptr<SyntheticGestureTarget>( 934 return std::unique_ptr<SyntheticGestureTarget>(
936 new SyntheticGestureTargetAndroid( 935 new SyntheticGestureTargetAndroid(
937 host_, content_view_core_->CreateMotionEventSynthesizer())); 936 host_, content_view_core_->CreateMotionEventSynthesizer()));
938 } 937 }
939 938
940 void RenderWidgetHostViewAndroid::SendDelegatedFrameAck( 939 void RenderWidgetHostViewAndroid::SendReclaimCompositorResources(
941 uint32_t output_surface_id) { 940 uint32_t output_surface_id,
941 bool is_swap_ack) {
942 DCHECK(host_); 942 DCHECK(host_);
943 cc::CompositorFrameAck ack; 943 host_->Send(new ViewMsg_ReclaimCompositorResources(
944 if (!surface_returned_resources_.empty()) 944 host_->GetRoutingID(), output_surface_id, is_swap_ack,
945 ack.resources.swap(surface_returned_resources_); 945 surface_returned_resources_));
946 host_->Send(new ViewMsg_SwapCompositorFrameAck(host_->GetRoutingID(), 946 surface_returned_resources_.clear();
947 output_surface_id, ack));
948 }
949
950 void RenderWidgetHostViewAndroid::SendReturnedDelegatedResources(
951 uint32_t output_surface_id) {
952 DCHECK(host_);
953 cc::CompositorFrameAck ack;
954 DCHECK(!surface_returned_resources_.empty());
955 ack.resources.swap(surface_returned_resources_);
956
957 host_->Send(new ViewMsg_ReclaimCompositorResources(host_->GetRoutingID(),
958 output_surface_id, ack));
959 } 947 }
960 948
961 void RenderWidgetHostViewAndroid::ReturnResources( 949 void RenderWidgetHostViewAndroid::ReturnResources(
962 const cc::ReturnedResourceArray& resources) { 950 const cc::ReturnedResourceArray& resources) {
963 if (resources.empty()) 951 if (resources.empty())
964 return; 952 return;
965 std::copy(resources.begin(), resources.end(), 953 std::copy(resources.begin(), resources.end(),
966 std::back_inserter(surface_returned_resources_)); 954 std::back_inserter(surface_returned_resources_));
967 if (ack_callbacks_.empty()) 955 if (ack_callbacks_.empty())
968 SendReturnedDelegatedResources(last_output_surface_id_); 956 SendReclaimCompositorResources(last_output_surface_id_,
957 false /* is_swap_ack */);
969 } 958 }
970 959
971 void RenderWidgetHostViewAndroid::SetBeginFrameSource( 960 void RenderWidgetHostViewAndroid::SetBeginFrameSource(
972 cc::BeginFrameSource* begin_frame_source) { 961 cc::BeginFrameSource* begin_frame_source) {
973 // TODO(tansell): Hook this up. 962 // TODO(tansell): Hook this up.
974 } 963 }
975 964
976 void RenderWidgetHostViewAndroid::DestroyDelegatedContent() { 965 void RenderWidgetHostViewAndroid::DestroyDelegatedContent() {
977 RemoveLayers(); 966 RemoveLayers();
978 if (!surface_id_.is_null()) { 967 if (!surface_id_.is_null()) {
979 DCHECK(surface_factory_.get()); 968 DCHECK(surface_factory_.get());
980 surface_factory_->Destroy(surface_id_); 969 surface_factory_->Destroy(surface_id_);
981 surface_id_ = cc::SurfaceId(); 970 surface_id_ = cc::SurfaceId();
982 } 971 }
983 view_.SetLayer(nullptr); 972 view_.SetLayer(nullptr);
984 } 973 }
985 974
986 void RenderWidgetHostViewAndroid::CheckOutputSurfaceChanged( 975 void RenderWidgetHostViewAndroid::CheckOutputSurfaceChanged(
987 uint32_t output_surface_id) { 976 uint32_t output_surface_id) {
988 if (output_surface_id == last_output_surface_id_) 977 if (output_surface_id == last_output_surface_id_)
989 return; 978 return;
990 DestroyDelegatedContent(); 979 DestroyDelegatedContent();
991 surface_factory_.reset(); 980 surface_factory_.reset();
992 if (!surface_returned_resources_.empty()) 981 if (!surface_returned_resources_.empty())
993 SendReturnedDelegatedResources(last_output_surface_id_); 982 SendReclaimCompositorResources(last_output_surface_id_,
983 false /* is_swap_ack */);
994 984
995 last_output_surface_id_ = output_surface_id; 985 last_output_surface_id_ = output_surface_id;
996 } 986 }
997 987
998 void RenderWidgetHostViewAndroid::SubmitCompositorFrame( 988 void RenderWidgetHostViewAndroid::SubmitCompositorFrame(
999 cc::CompositorFrame frame) { 989 cc::CompositorFrame frame) {
1000 cc::SurfaceManager* manager = CompositorImpl::GetSurfaceManager(); 990 cc::SurfaceManager* manager = CompositorImpl::GetSurfaceManager();
1001 if (!surface_factory_) { 991 if (!surface_factory_) {
1002 surface_factory_ = base::WrapUnique(new cc::SurfaceFactory(manager, this)); 992 surface_factory_ = base::WrapUnique(new cc::SurfaceFactory(manager, this));
1003 } 993 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1047 cc::RenderPass* root_pass = 1037 cc::RenderPass* root_pass =
1048 frame.delegated_frame_data->render_pass_list.back().get(); 1038 frame.delegated_frame_data->render_pass_list.back().get();
1049 texture_size_in_layer_ = root_pass->output_rect.size(); 1039 texture_size_in_layer_ = root_pass->output_rect.size();
1050 1040
1051 cc::CompositorFrameMetadata metadata = frame.metadata.Clone(); 1041 cc::CompositorFrameMetadata metadata = frame.metadata.Clone();
1052 1042
1053 CheckOutputSurfaceChanged(output_surface_id); 1043 CheckOutputSurfaceChanged(output_surface_id);
1054 bool has_content = !texture_size_in_layer_.IsEmpty(); 1044 bool has_content = !texture_size_in_layer_.IsEmpty();
1055 1045
1056 base::Closure ack_callback = 1046 base::Closure ack_callback =
1057 base::Bind(&RenderWidgetHostViewAndroid::SendDelegatedFrameAck, 1047 base::Bind(&RenderWidgetHostViewAndroid::SendReclaimCompositorResources,
1058 weak_ptr_factory_.GetWeakPtr(), 1048 weak_ptr_factory_.GetWeakPtr(), output_surface_id,
1059 output_surface_id); 1049 true /* is_swap_ack */);
1060 1050
1061 ack_callbacks_.push(ack_callback); 1051 ack_callbacks_.push(ack_callback);
1062 1052
1063 if (!has_content) { 1053 if (!has_content) {
1064 DestroyDelegatedContent(); 1054 DestroyDelegatedContent();
1065 } else { 1055 } else {
1066 SubmitCompositorFrame(std::move(frame)); 1056 SubmitCompositorFrame(std::move(frame));
1067 view_.GetLayer()->SetIsDrawable(true); 1057 view_.GetLayer()->SetIsDrawable(true);
1068 view_.GetLayer()->SetContentsOpaque(true); 1058 view_.GetLayer()->SetContentsOpaque(true);
1069 view_.GetLayer()->SetBounds(texture_size_in_layer_); 1059 view_.GetLayer()->SetBounds(texture_size_in_layer_);
(...skipping 21 matching lines...) Expand all
1091 void RenderWidgetHostViewAndroid::RetainFrame(uint32_t output_surface_id, 1081 void RenderWidgetHostViewAndroid::RetainFrame(uint32_t output_surface_id,
1092 cc::CompositorFrame frame) { 1082 cc::CompositorFrame frame) {
1093 DCHECK(locks_on_frame_count_); 1083 DCHECK(locks_on_frame_count_);
1094 1084
1095 // Store the incoming frame so that it can be swapped when all the locks have 1085 // Store the incoming frame so that it can be swapped when all the locks have
1096 // been released. If there is already a stored frame, then replace and skip 1086 // been released. If there is already a stored frame, then replace and skip
1097 // the previous one but make sure we still eventually send the ACK. Holding 1087 // the previous one but make sure we still eventually send the ACK. Holding
1098 // the ACK also blocks the renderer when its max_frames_pending is reached. 1088 // the ACK also blocks the renderer when its max_frames_pending is reached.
1099 if (last_frame_info_) { 1089 if (last_frame_info_) {
1100 base::Closure ack_callback = 1090 base::Closure ack_callback =
1101 base::Bind(&RenderWidgetHostViewAndroid::SendDelegatedFrameAck, 1091 base::Bind(&RenderWidgetHostViewAndroid::SendReclaimCompositorResources,
1102 weak_ptr_factory_.GetWeakPtr(), 1092 weak_ptr_factory_.GetWeakPtr(),
1103 last_frame_info_->output_surface_id); 1093 last_frame_info_->output_surface_id, true /* is_swap_ack */);
1104 1094
1105 ack_callbacks_.push(ack_callback); 1095 ack_callbacks_.push(ack_callback);
1106 } 1096 }
1107 1097
1108 last_frame_info_.reset( 1098 last_frame_info_.reset(
1109 new LastFrameInfo(output_surface_id, std::move(frame))); 1099 new LastFrameInfo(output_surface_id, std::move(frame)));
1110 } 1100 }
1111 1101
1112 void RenderWidgetHostViewAndroid::SynchronousFrameMetadata( 1102 void RenderWidgetHostViewAndroid::SynchronousFrameMetadata(
1113 cc::CompositorFrameMetadata frame_metadata) { 1103 cc::CompositorFrameMetadata frame_metadata) {
(...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after
2006 case ui::MotionEvent::ACTION_UP: 1996 case ui::MotionEvent::ACTION_UP:
2007 case ui::MotionEvent::ACTION_POINTER_UP: 1997 case ui::MotionEvent::ACTION_POINTER_UP:
2008 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED", 1998 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED",
2009 delta.InMicroseconds(), 1, 1000000, 50); 1999 delta.InMicroseconds(), 1, 1000000, 50);
2010 default: 2000 default:
2011 return; 2001 return;
2012 } 2002 }
2013 } 2003 }
2014 2004
2015 } // namespace content 2005 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698