| 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 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 #include "ui/gfx/android/java_bitmap.h" | 88 #include "ui/gfx/android/java_bitmap.h" |
| 89 #include "ui/gfx/android/view_configuration.h" | 89 #include "ui/gfx/android/view_configuration.h" |
| 90 #include "ui/gfx/geometry/dip_util.h" | 90 #include "ui/gfx/geometry/dip_util.h" |
| 91 #include "ui/gfx/geometry/size_conversions.h" | 91 #include "ui/gfx/geometry/size_conversions.h" |
| 92 #include "ui/touch_selection/touch_selection_controller.h" | 92 #include "ui/touch_selection/touch_selection_controller.h" |
| 93 | 93 |
| 94 namespace content { | 94 namespace content { |
| 95 | 95 |
| 96 namespace { | 96 namespace { |
| 97 | 97 |
| 98 const int kUndefinedOutputSurfaceId = -1; | 98 const int kUndefinedCompositorFrameSinkId = -1; |
| 99 | 99 |
| 100 static const char kAsyncReadBackString[] = "Compositing.CopyFromSurfaceTime"; | 100 static const char kAsyncReadBackString[] = "Compositing.CopyFromSurfaceTime"; |
| 101 | 101 |
| 102 class GLHelperHolder { | 102 class GLHelperHolder { |
| 103 public: | 103 public: |
| 104 static GLHelperHolder* Create(); | 104 static GLHelperHolder* Create(); |
| 105 | 105 |
| 106 display_compositor::GLHelper* gl_helper() { return gl_helper_.get(); } | 106 display_compositor::GLHelper* gl_helper() { return gl_helper_.get(); } |
| 107 bool IsLost() { | 107 bool IsLost() { |
| 108 if (!gl_helper_) | 108 if (!gl_helper_) |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 rect.Union(controller.GetStartHandleRect()); | 265 rect.Union(controller.GetStartHandleRect()); |
| 266 rect.Union(controller.GetEndHandleRect()); | 266 rect.Union(controller.GetEndHandleRect()); |
| 267 return rect; | 267 return rect; |
| 268 } | 268 } |
| 269 | 269 |
| 270 } // anonymous namespace | 270 } // anonymous namespace |
| 271 | 271 |
| 272 RenderWidgetHostViewAndroid::LastFrameInfo::LastFrameInfo( | 272 RenderWidgetHostViewAndroid::LastFrameInfo::LastFrameInfo( |
| 273 uint32_t output_id, | 273 uint32_t output_id, |
| 274 cc::CompositorFrame output_frame) | 274 cc::CompositorFrame output_frame) |
| 275 : output_surface_id(output_id), frame(std::move(output_frame)) {} | 275 : compositor_frame_sink_id(output_id), frame(std::move(output_frame)) {} |
| 276 | 276 |
| 277 RenderWidgetHostViewAndroid::LastFrameInfo::~LastFrameInfo() {} | 277 RenderWidgetHostViewAndroid::LastFrameInfo::~LastFrameInfo() {} |
| 278 | 278 |
| 279 void RenderWidgetHostViewAndroid::OnContextLost() { | 279 void RenderWidgetHostViewAndroid::OnContextLost() { |
| 280 std::unique_ptr<RenderWidgetHostIterator> widgets( | 280 std::unique_ptr<RenderWidgetHostIterator> widgets( |
| 281 RenderWidgetHostImpl::GetAllRenderWidgetHosts()); | 281 RenderWidgetHostImpl::GetAllRenderWidgetHosts()); |
| 282 while (RenderWidgetHost* widget = widgets->GetNextHost()) { | 282 while (RenderWidgetHost* widget = widgets->GetNextHost()) { |
| 283 if (widget->GetView()) { | 283 if (widget->GetView()) { |
| 284 static_cast<RenderWidgetHostViewAndroid*>(widget->GetView()) | 284 static_cast<RenderWidgetHostViewAndroid*>(widget->GetView()) |
| 285 ->OnLostResources(); | 285 ->OnLostResources(); |
| 286 } | 286 } |
| 287 } | 287 } |
| 288 } | 288 } |
| 289 | 289 |
| 290 RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid( | 290 RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid( |
| 291 RenderWidgetHostImpl* widget_host, | 291 RenderWidgetHostImpl* widget_host, |
| 292 ContentViewCoreImpl* content_view_core) | 292 ContentViewCoreImpl* content_view_core) |
| 293 : host_(widget_host), | 293 : host_(widget_host), |
| 294 outstanding_vsync_requests_(0), | 294 outstanding_vsync_requests_(0), |
| 295 is_showing_(!widget_host->is_hidden()), | 295 is_showing_(!widget_host->is_hidden()), |
| 296 is_window_visible_(true), | 296 is_window_visible_(true), |
| 297 is_window_activity_started_(true), | 297 is_window_activity_started_(true), |
| 298 content_view_core_(nullptr), | 298 content_view_core_(nullptr), |
| 299 ime_adapter_android_(this), | 299 ime_adapter_android_(this), |
| 300 cached_background_color_(SK_ColorWHITE), | 300 cached_background_color_(SK_ColorWHITE), |
| 301 last_output_surface_id_(kUndefinedOutputSurfaceId), | 301 last_compositor_frame_sink_id_(kUndefinedCompositorFrameSinkId), |
| 302 gesture_provider_(ui::GetGestureProviderConfig( | 302 gesture_provider_(ui::GetGestureProviderConfig( |
| 303 ui::GestureProviderConfigType::CURRENT_PLATFORM), | 303 ui::GestureProviderConfigType::CURRENT_PLATFORM), |
| 304 this), | 304 this), |
| 305 stylus_text_selector_(this), | 305 stylus_text_selector_(this), |
| 306 using_browser_compositor_(CompositorImpl::IsInitialized()), | 306 using_browser_compositor_(CompositorImpl::IsInitialized()), |
| 307 frame_evictor_(new DelegatedFrameEvictor(this)), | 307 frame_evictor_(new DelegatedFrameEvictor(this)), |
| 308 locks_on_frame_count_(0), | 308 locks_on_frame_count_(0), |
| 309 observing_root_window_(false), | 309 observing_root_window_(false), |
| 310 weak_ptr_factory_(this) { | 310 weak_ptr_factory_(this) { |
| 311 // Set the layer which will hold the content layer for this view. The content | 311 // Set the layer which will hold the content layer for this view. The content |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 DCHECK_EQ(locks_on_frame_count_, 0u); | 509 DCHECK_EQ(locks_on_frame_count_, 0u); |
| 510 return; | 510 return; |
| 511 } | 511 } |
| 512 | 512 |
| 513 DCHECK_GT(locks_on_frame_count_, 0u); | 513 DCHECK_GT(locks_on_frame_count_, 0u); |
| 514 locks_on_frame_count_--; | 514 locks_on_frame_count_--; |
| 515 frame_evictor_->UnlockFrame(); | 515 frame_evictor_->UnlockFrame(); |
| 516 | 516 |
| 517 if (locks_on_frame_count_ == 0) { | 517 if (locks_on_frame_count_ == 0) { |
| 518 if (last_frame_info_) { | 518 if (last_frame_info_) { |
| 519 InternalSwapCompositorFrame(last_frame_info_->output_surface_id, | 519 InternalSwapCompositorFrame(last_frame_info_->compositor_frame_sink_id, |
| 520 std::move(last_frame_info_->frame)); | 520 std::move(last_frame_info_->frame)); |
| 521 last_frame_info_.reset(); | 521 last_frame_info_.reset(); |
| 522 } | 522 } |
| 523 | 523 |
| 524 view_.GetLayer()->SetHideLayerAndSubtree(!is_showing_); | 524 view_.GetLayer()->SetHideLayerAndSubtree(!is_showing_); |
| 525 } | 525 } |
| 526 } | 526 } |
| 527 | 527 |
| 528 void RenderWidgetHostViewAndroid::OnShowUnhandledTapUIIfNeeded(int x_dip, | 528 void RenderWidgetHostViewAndroid::OnShowUnhandledTapUIIfNeeded(int x_dip, |
| 529 int y_dip) { | 529 int y_dip) { |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 884 } | 884 } |
| 885 | 885 |
| 886 std::unique_ptr<SyntheticGestureTarget> | 886 std::unique_ptr<SyntheticGestureTarget> |
| 887 RenderWidgetHostViewAndroid::CreateSyntheticGestureTarget() { | 887 RenderWidgetHostViewAndroid::CreateSyntheticGestureTarget() { |
| 888 return std::unique_ptr<SyntheticGestureTarget>( | 888 return std::unique_ptr<SyntheticGestureTarget>( |
| 889 new SyntheticGestureTargetAndroid( | 889 new SyntheticGestureTargetAndroid( |
| 890 host_, content_view_core_->CreateMotionEventSynthesizer())); | 890 host_, content_view_core_->CreateMotionEventSynthesizer())); |
| 891 } | 891 } |
| 892 | 892 |
| 893 void RenderWidgetHostViewAndroid::SendReclaimCompositorResources( | 893 void RenderWidgetHostViewAndroid::SendReclaimCompositorResources( |
| 894 uint32_t output_surface_id, | 894 uint32_t compositor_frame_sink_id, |
| 895 bool is_swap_ack) { | 895 bool is_swap_ack) { |
| 896 DCHECK(host_); | 896 DCHECK(host_); |
| 897 host_->Send(new ViewMsg_ReclaimCompositorResources( | 897 host_->Send(new ViewMsg_ReclaimCompositorResources( |
| 898 host_->GetRoutingID(), output_surface_id, is_swap_ack, | 898 host_->GetRoutingID(), compositor_frame_sink_id, is_swap_ack, |
| 899 surface_returned_resources_)); | 899 surface_returned_resources_)); |
| 900 surface_returned_resources_.clear(); | 900 surface_returned_resources_.clear(); |
| 901 } | 901 } |
| 902 | 902 |
| 903 void RenderWidgetHostViewAndroid::ReturnResources( | 903 void RenderWidgetHostViewAndroid::ReturnResources( |
| 904 const cc::ReturnedResourceArray& resources) { | 904 const cc::ReturnedResourceArray& resources) { |
| 905 if (resources.empty()) | 905 if (resources.empty()) |
| 906 return; | 906 return; |
| 907 std::copy(resources.begin(), resources.end(), | 907 std::copy(resources.begin(), resources.end(), |
| 908 std::back_inserter(surface_returned_resources_)); | 908 std::back_inserter(surface_returned_resources_)); |
| 909 if (ack_callbacks_.empty()) | 909 if (ack_callbacks_.empty()) |
| 910 SendReclaimCompositorResources(last_output_surface_id_, | 910 SendReclaimCompositorResources(last_compositor_frame_sink_id_, |
| 911 false /* is_swap_ack */); | 911 false /* is_swap_ack */); |
| 912 } | 912 } |
| 913 | 913 |
| 914 void RenderWidgetHostViewAndroid::CheckOutputSurfaceChanged( | 914 void RenderWidgetHostViewAndroid::CheckCompositorFrameSinkChanged( |
| 915 uint32_t output_surface_id) { | 915 uint32_t compositor_frame_sink_id) { |
| 916 if (output_surface_id == last_output_surface_id_) | 916 if (compositor_frame_sink_id == last_compositor_frame_sink_id_) |
| 917 return; | 917 return; |
| 918 | 918 |
| 919 delegated_frame_host_->OutputSurfaceChanged(); | 919 delegated_frame_host_->CompositorFrameSinkChanged(); |
| 920 | 920 |
| 921 if (!surface_returned_resources_.empty()) | 921 if (!surface_returned_resources_.empty()) |
| 922 SendReclaimCompositorResources(last_output_surface_id_, | 922 SendReclaimCompositorResources(last_compositor_frame_sink_id_, |
| 923 false /* is_swap_ack */); | 923 false /* is_swap_ack */); |
| 924 | 924 |
| 925 last_output_surface_id_ = output_surface_id; | 925 last_compositor_frame_sink_id_ = compositor_frame_sink_id; |
| 926 } | 926 } |
| 927 | 927 |
| 928 void RenderWidgetHostViewAndroid::InternalSwapCompositorFrame( | 928 void RenderWidgetHostViewAndroid::InternalSwapCompositorFrame( |
| 929 uint32_t output_surface_id, | 929 uint32_t compositor_frame_sink_id, |
| 930 cc::CompositorFrame frame) { | 930 cc::CompositorFrame frame) { |
| 931 last_scroll_offset_ = frame.metadata.root_scroll_offset; | 931 last_scroll_offset_ = frame.metadata.root_scroll_offset; |
| 932 DCHECK(frame.delegated_frame_data); | 932 DCHECK(frame.delegated_frame_data); |
| 933 DCHECK(delegated_frame_host_); | 933 DCHECK(delegated_frame_host_); |
| 934 | 934 |
| 935 if (locks_on_frame_count_ > 0) { | 935 if (locks_on_frame_count_ > 0) { |
| 936 DCHECK(HasValidFrame()); | 936 DCHECK(HasValidFrame()); |
| 937 RetainFrame(output_surface_id, std::move(frame)); | 937 RetainFrame(compositor_frame_sink_id, std::move(frame)); |
| 938 return; | 938 return; |
| 939 } | 939 } |
| 940 | 940 |
| 941 DCHECK(!frame.delegated_frame_data->render_pass_list.empty()); | 941 DCHECK(!frame.delegated_frame_data->render_pass_list.empty()); |
| 942 | 942 |
| 943 cc::RenderPass* root_pass = | 943 cc::RenderPass* root_pass = |
| 944 frame.delegated_frame_data->render_pass_list.back().get(); | 944 frame.delegated_frame_data->render_pass_list.back().get(); |
| 945 current_surface_size_ = root_pass->output_rect.size(); | 945 current_surface_size_ = root_pass->output_rect.size(); |
| 946 bool is_transparent = root_pass->has_transparent_background; | 946 bool is_transparent = root_pass->has_transparent_background; |
| 947 | 947 |
| 948 cc::CompositorFrameMetadata metadata = frame.metadata.Clone(); | 948 cc::CompositorFrameMetadata metadata = frame.metadata.Clone(); |
| 949 | 949 |
| 950 CheckOutputSurfaceChanged(output_surface_id); | 950 CheckCompositorFrameSinkChanged(compositor_frame_sink_id); |
| 951 bool has_content = !current_surface_size_.IsEmpty(); | 951 bool has_content = !current_surface_size_.IsEmpty(); |
| 952 | 952 |
| 953 base::Closure ack_callback = | 953 base::Closure ack_callback = |
| 954 base::Bind(&RenderWidgetHostViewAndroid::SendReclaimCompositorResources, | 954 base::Bind(&RenderWidgetHostViewAndroid::SendReclaimCompositorResources, |
| 955 weak_ptr_factory_.GetWeakPtr(), output_surface_id, | 955 weak_ptr_factory_.GetWeakPtr(), compositor_frame_sink_id, |
| 956 true /* is_swap_ack */); | 956 true /* is_swap_ack */); |
| 957 | 957 |
| 958 ack_callbacks_.push(ack_callback); | 958 ack_callbacks_.push(ack_callback); |
| 959 | 959 |
| 960 if (!has_content) { | 960 if (!has_content) { |
| 961 DestroyDelegatedContent(); | 961 DestroyDelegatedContent(); |
| 962 } else { | 962 } else { |
| 963 cc::SurfaceFactory::DrawCallback ack_callback = | 963 cc::SurfaceFactory::DrawCallback ack_callback = |
| 964 base::Bind(&RenderWidgetHostViewAndroid::RunAckCallbacks, | 964 base::Bind(&RenderWidgetHostViewAndroid::RunAckCallbacks, |
| 965 weak_ptr_factory_.GetWeakPtr()); | 965 weak_ptr_factory_.GetWeakPtr()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 986 return; | 986 return; |
| 987 | 987 |
| 988 if (!delegated_frame_host_->HasDelegatedContent()) | 988 if (!delegated_frame_host_->HasDelegatedContent()) |
| 989 return; | 989 return; |
| 990 | 990 |
| 991 frame_evictor_->DiscardedFrame(); | 991 frame_evictor_->DiscardedFrame(); |
| 992 delegated_frame_host_->DestroyDelegatedContent(); | 992 delegated_frame_host_->DestroyDelegatedContent(); |
| 993 } | 993 } |
| 994 | 994 |
| 995 void RenderWidgetHostViewAndroid::OnSwapCompositorFrame( | 995 void RenderWidgetHostViewAndroid::OnSwapCompositorFrame( |
| 996 uint32_t output_surface_id, | 996 uint32_t compositor_frame_sink_id, |
| 997 cc::CompositorFrame frame) { | 997 cc::CompositorFrame frame) { |
| 998 InternalSwapCompositorFrame(output_surface_id, std::move(frame)); | 998 InternalSwapCompositorFrame(compositor_frame_sink_id, std::move(frame)); |
| 999 } | 999 } |
| 1000 | 1000 |
| 1001 void RenderWidgetHostViewAndroid::ClearCompositorFrame() { | 1001 void RenderWidgetHostViewAndroid::ClearCompositorFrame() { |
| 1002 DestroyDelegatedContent(); | 1002 DestroyDelegatedContent(); |
| 1003 } | 1003 } |
| 1004 | 1004 |
| 1005 void RenderWidgetHostViewAndroid::RetainFrame(uint32_t output_surface_id, | 1005 void RenderWidgetHostViewAndroid::RetainFrame(uint32_t compositor_frame_sink_id, |
| 1006 cc::CompositorFrame frame) { | 1006 cc::CompositorFrame frame) { |
| 1007 DCHECK(locks_on_frame_count_); | 1007 DCHECK(locks_on_frame_count_); |
| 1008 | 1008 |
| 1009 // Store the incoming frame so that it can be swapped when all the locks have | 1009 // Store the incoming frame so that it can be swapped when all the locks have |
| 1010 // been released. If there is already a stored frame, then replace and skip | 1010 // been released. If there is already a stored frame, then replace and skip |
| 1011 // the previous one but make sure we still eventually send the ACK. Holding | 1011 // the previous one but make sure we still eventually send the ACK. Holding |
| 1012 // the ACK also blocks the renderer when its max_frames_pending is reached. | 1012 // the ACK also blocks the renderer when its max_frames_pending is reached. |
| 1013 if (last_frame_info_) { | 1013 if (last_frame_info_) { |
| 1014 base::Closure ack_callback = | 1014 base::Closure ack_callback = base::Bind( |
| 1015 base::Bind(&RenderWidgetHostViewAndroid::SendReclaimCompositorResources, | 1015 &RenderWidgetHostViewAndroid::SendReclaimCompositorResources, |
| 1016 weak_ptr_factory_.GetWeakPtr(), | 1016 weak_ptr_factory_.GetWeakPtr(), |
| 1017 last_frame_info_->output_surface_id, true /* is_swap_ack */); | 1017 last_frame_info_->compositor_frame_sink_id, true /* is_swap_ack */); |
| 1018 | 1018 |
| 1019 ack_callbacks_.push(ack_callback); | 1019 ack_callbacks_.push(ack_callback); |
| 1020 } | 1020 } |
| 1021 | 1021 |
| 1022 last_frame_info_.reset( | 1022 last_frame_info_.reset( |
| 1023 new LastFrameInfo(output_surface_id, std::move(frame))); | 1023 new LastFrameInfo(compositor_frame_sink_id, std::move(frame))); |
| 1024 } | 1024 } |
| 1025 | 1025 |
| 1026 void RenderWidgetHostViewAndroid::SynchronousFrameMetadata( | 1026 void RenderWidgetHostViewAndroid::SynchronousFrameMetadata( |
| 1027 cc::CompositorFrameMetadata frame_metadata) { | 1027 cc::CompositorFrameMetadata frame_metadata) { |
| 1028 if (!content_view_core_) | 1028 if (!content_view_core_) |
| 1029 return; | 1029 return; |
| 1030 | 1030 |
| 1031 bool is_mobile_optimized = IsMobileOptimizedFrame(frame_metadata); | 1031 bool is_mobile_optimized = IsMobileOptimizedFrame(frame_metadata); |
| 1032 | 1032 |
| 1033 if (host_ && host_->input_router()) { | 1033 if (host_ && host_->input_router()) { |
| (...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1880 case ui::MotionEvent::ACTION_UP: | 1880 case ui::MotionEvent::ACTION_UP: |
| 1881 case ui::MotionEvent::ACTION_POINTER_UP: | 1881 case ui::MotionEvent::ACTION_POINTER_UP: |
| 1882 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED", | 1882 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED", |
| 1883 delta.InMicroseconds(), 1, 1000000, 50); | 1883 delta.InMicroseconds(), 1, 1000000, 50); |
| 1884 default: | 1884 default: |
| 1885 return; | 1885 return; |
| 1886 } | 1886 } |
| 1887 } | 1887 } |
| 1888 | 1888 |
| 1889 } // namespace content | 1889 } // namespace content |
| OLD | NEW |