| OLD | NEW |
| 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 888 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 927 content_view_core_->ShowDisambiguationPopup(rect_pixels, zoomed_bitmap); | 926 content_view_core_->ShowDisambiguationPopup(rect_pixels, zoomed_bitmap); |
| 928 } | 927 } |
| 929 | 928 |
| 930 std::unique_ptr<SyntheticGestureTarget> | 929 std::unique_ptr<SyntheticGestureTarget> |
| 931 RenderWidgetHostViewAndroid::CreateSyntheticGestureTarget() { | 930 RenderWidgetHostViewAndroid::CreateSyntheticGestureTarget() { |
| 932 return std::unique_ptr<SyntheticGestureTarget>( | 931 return std::unique_ptr<SyntheticGestureTarget>( |
| 933 new SyntheticGestureTargetAndroid( | 932 new SyntheticGestureTargetAndroid( |
| 934 host_, content_view_core_->CreateMotionEventSynthesizer())); | 933 host_, content_view_core_->CreateMotionEventSynthesizer())); |
| 935 } | 934 } |
| 936 | 935 |
| 937 void RenderWidgetHostViewAndroid::SendDelegatedFrameAck( | 936 void RenderWidgetHostViewAndroid::SendReclaimCompositorResources( |
| 938 uint32_t output_surface_id) { | 937 uint32_t output_surface_id, |
| 938 bool is_swap_ack) { |
| 939 DCHECK(host_); | 939 DCHECK(host_); |
| 940 cc::CompositorFrameAck ack; | 940 host_->Send(new ViewMsg_ReclaimCompositorResources( |
| 941 if (!surface_returned_resources_.empty()) | 941 host_->GetRoutingID(), output_surface_id, is_swap_ack, |
| 942 ack.resources.swap(surface_returned_resources_); | 942 surface_returned_resources_)); |
| 943 host_->Send(new ViewMsg_SwapCompositorFrameAck(host_->GetRoutingID(), | 943 surface_returned_resources_.clear(); |
| 944 output_surface_id, ack)); | |
| 945 } | |
| 946 | |
| 947 void RenderWidgetHostViewAndroid::SendReturnedDelegatedResources( | |
| 948 uint32_t output_surface_id) { | |
| 949 DCHECK(host_); | |
| 950 cc::CompositorFrameAck ack; | |
| 951 DCHECK(!surface_returned_resources_.empty()); | |
| 952 ack.resources.swap(surface_returned_resources_); | |
| 953 | |
| 954 host_->Send(new ViewMsg_ReclaimCompositorResources(host_->GetRoutingID(), | |
| 955 output_surface_id, ack)); | |
| 956 } | 944 } |
| 957 | 945 |
| 958 void RenderWidgetHostViewAndroid::ReturnResources( | 946 void RenderWidgetHostViewAndroid::ReturnResources( |
| 959 const cc::ReturnedResourceArray& resources) { | 947 const cc::ReturnedResourceArray& resources) { |
| 960 if (resources.empty()) | 948 if (resources.empty()) |
| 961 return; | 949 return; |
| 962 std::copy(resources.begin(), resources.end(), | 950 std::copy(resources.begin(), resources.end(), |
| 963 std::back_inserter(surface_returned_resources_)); | 951 std::back_inserter(surface_returned_resources_)); |
| 964 if (ack_callbacks_.empty()) | 952 if (ack_callbacks_.empty()) |
| 965 SendReturnedDelegatedResources(last_output_surface_id_); | 953 SendReclaimCompositorResources(last_output_surface_id_, |
| 954 false /* is_swap_ack */); |
| 966 } | 955 } |
| 967 | 956 |
| 968 void RenderWidgetHostViewAndroid::SetBeginFrameSource( | 957 void RenderWidgetHostViewAndroid::SetBeginFrameSource( |
| 969 cc::BeginFrameSource* begin_frame_source) { | 958 cc::BeginFrameSource* begin_frame_source) { |
| 970 // TODO(tansell): Hook this up. | 959 // TODO(tansell): Hook this up. |
| 971 } | 960 } |
| 972 | 961 |
| 973 void RenderWidgetHostViewAndroid::DestroyDelegatedContent() { | 962 void RenderWidgetHostViewAndroid::DestroyDelegatedContent() { |
| 974 RemoveLayers(); | 963 RemoveLayers(); |
| 975 if (!surface_id_.is_null()) { | 964 if (!surface_id_.is_null()) { |
| 976 DCHECK(surface_factory_.get()); | 965 DCHECK(surface_factory_.get()); |
| 977 surface_factory_->Destroy(surface_id_); | 966 surface_factory_->Destroy(surface_id_); |
| 978 surface_id_ = cc::SurfaceId(); | 967 surface_id_ = cc::SurfaceId(); |
| 979 } | 968 } |
| 980 view_.SetLayer(nullptr); | 969 view_.SetLayer(nullptr); |
| 981 } | 970 } |
| 982 | 971 |
| 983 void RenderWidgetHostViewAndroid::CheckOutputSurfaceChanged( | 972 void RenderWidgetHostViewAndroid::CheckOutputSurfaceChanged( |
| 984 uint32_t output_surface_id) { | 973 uint32_t output_surface_id) { |
| 985 if (output_surface_id == last_output_surface_id_) | 974 if (output_surface_id == last_output_surface_id_) |
| 986 return; | 975 return; |
| 987 DestroyDelegatedContent(); | 976 DestroyDelegatedContent(); |
| 988 surface_factory_.reset(); | 977 surface_factory_.reset(); |
| 989 if (!surface_returned_resources_.empty()) | 978 if (!surface_returned_resources_.empty()) |
| 990 SendReturnedDelegatedResources(last_output_surface_id_); | 979 SendReclaimCompositorResources(last_output_surface_id_, |
| 980 false /* is_swap_ack */); |
| 991 | 981 |
| 992 last_output_surface_id_ = output_surface_id; | 982 last_output_surface_id_ = output_surface_id; |
| 993 } | 983 } |
| 994 | 984 |
| 995 void RenderWidgetHostViewAndroid::SubmitCompositorFrame( | 985 void RenderWidgetHostViewAndroid::SubmitCompositorFrame( |
| 996 cc::CompositorFrame frame) { | 986 cc::CompositorFrame frame) { |
| 997 cc::SurfaceManager* manager = CompositorImpl::GetSurfaceManager(); | 987 cc::SurfaceManager* manager = CompositorImpl::GetSurfaceManager(); |
| 998 if (!surface_factory_) { | 988 if (!surface_factory_) { |
| 999 surface_factory_ = base::WrapUnique(new cc::SurfaceFactory(manager, this)); | 989 surface_factory_ = base::WrapUnique(new cc::SurfaceFactory(manager, this)); |
| 1000 } | 990 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1044 cc::RenderPass* root_pass = | 1034 cc::RenderPass* root_pass = |
| 1045 frame.delegated_frame_data->render_pass_list.back().get(); | 1035 frame.delegated_frame_data->render_pass_list.back().get(); |
| 1046 texture_size_in_layer_ = root_pass->output_rect.size(); | 1036 texture_size_in_layer_ = root_pass->output_rect.size(); |
| 1047 | 1037 |
| 1048 cc::CompositorFrameMetadata metadata = frame.metadata.Clone(); | 1038 cc::CompositorFrameMetadata metadata = frame.metadata.Clone(); |
| 1049 | 1039 |
| 1050 CheckOutputSurfaceChanged(output_surface_id); | 1040 CheckOutputSurfaceChanged(output_surface_id); |
| 1051 bool has_content = !texture_size_in_layer_.IsEmpty(); | 1041 bool has_content = !texture_size_in_layer_.IsEmpty(); |
| 1052 | 1042 |
| 1053 base::Closure ack_callback = | 1043 base::Closure ack_callback = |
| 1054 base::Bind(&RenderWidgetHostViewAndroid::SendDelegatedFrameAck, | 1044 base::Bind(&RenderWidgetHostViewAndroid::SendReclaimCompositorResources, |
| 1055 weak_ptr_factory_.GetWeakPtr(), | 1045 weak_ptr_factory_.GetWeakPtr(), output_surface_id, |
| 1056 output_surface_id); | 1046 true /* is_swap_ack */); |
| 1057 | 1047 |
| 1058 ack_callbacks_.push(ack_callback); | 1048 ack_callbacks_.push(ack_callback); |
| 1059 | 1049 |
| 1060 if (!has_content) { | 1050 if (!has_content) { |
| 1061 DestroyDelegatedContent(); | 1051 DestroyDelegatedContent(); |
| 1062 } else { | 1052 } else { |
| 1063 SubmitCompositorFrame(std::move(frame)); | 1053 SubmitCompositorFrame(std::move(frame)); |
| 1064 view_.GetLayer()->SetIsDrawable(true); | 1054 view_.GetLayer()->SetIsDrawable(true); |
| 1065 view_.GetLayer()->SetContentsOpaque(true); | 1055 view_.GetLayer()->SetContentsOpaque(true); |
| 1066 view_.GetLayer()->SetBounds(texture_size_in_layer_); | 1056 view_.GetLayer()->SetBounds(texture_size_in_layer_); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1088 void RenderWidgetHostViewAndroid::RetainFrame(uint32_t output_surface_id, | 1078 void RenderWidgetHostViewAndroid::RetainFrame(uint32_t output_surface_id, |
| 1089 cc::CompositorFrame frame) { | 1079 cc::CompositorFrame frame) { |
| 1090 DCHECK(locks_on_frame_count_); | 1080 DCHECK(locks_on_frame_count_); |
| 1091 | 1081 |
| 1092 // Store the incoming frame so that it can be swapped when all the locks have | 1082 // Store the incoming frame so that it can be swapped when all the locks have |
| 1093 // been released. If there is already a stored frame, then replace and skip | 1083 // been released. If there is already a stored frame, then replace and skip |
| 1094 // the previous one but make sure we still eventually send the ACK. Holding | 1084 // the previous one but make sure we still eventually send the ACK. Holding |
| 1095 // the ACK also blocks the renderer when its max_frames_pending is reached. | 1085 // the ACK also blocks the renderer when its max_frames_pending is reached. |
| 1096 if (last_frame_info_) { | 1086 if (last_frame_info_) { |
| 1097 base::Closure ack_callback = | 1087 base::Closure ack_callback = |
| 1098 base::Bind(&RenderWidgetHostViewAndroid::SendDelegatedFrameAck, | 1088 base::Bind(&RenderWidgetHostViewAndroid::SendReclaimCompositorResources, |
| 1099 weak_ptr_factory_.GetWeakPtr(), | 1089 weak_ptr_factory_.GetWeakPtr(), |
| 1100 last_frame_info_->output_surface_id); | 1090 last_frame_info_->output_surface_id, true /* is_swap_ack */); |
| 1101 | 1091 |
| 1102 ack_callbacks_.push(ack_callback); | 1092 ack_callbacks_.push(ack_callback); |
| 1103 } | 1093 } |
| 1104 | 1094 |
| 1105 last_frame_info_.reset( | 1095 last_frame_info_.reset( |
| 1106 new LastFrameInfo(output_surface_id, std::move(frame))); | 1096 new LastFrameInfo(output_surface_id, std::move(frame))); |
| 1107 } | 1097 } |
| 1108 | 1098 |
| 1109 void RenderWidgetHostViewAndroid::SynchronousFrameMetadata( | 1099 void RenderWidgetHostViewAndroid::SynchronousFrameMetadata( |
| 1110 cc::CompositorFrameMetadata frame_metadata) { | 1100 cc::CompositorFrameMetadata frame_metadata) { |
| (...skipping 882 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1993 case ui::MotionEvent::ACTION_UP: | 1983 case ui::MotionEvent::ACTION_UP: |
| 1994 case ui::MotionEvent::ACTION_POINTER_UP: | 1984 case ui::MotionEvent::ACTION_POINTER_UP: |
| 1995 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED", | 1985 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED", |
| 1996 delta.InMicroseconds(), 1, 1000000, 50); | 1986 delta.InMicroseconds(), 1, 1000000, 50); |
| 1997 default: | 1987 default: |
| 1998 return; | 1988 return; |
| 1999 } | 1989 } |
| 2000 } | 1990 } |
| 2001 | 1991 |
| 2002 } // namespace content | 1992 } // namespace content |
| OLD | NEW |