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

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

Issue 2337913003: Fork cc::OutputSurface into cc::CompositorFrameSink. (Closed)
Patch Set: cfsfork: android-vulkan Created 4 years, 3 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
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 return rect; 263 return rect;
264 264
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 compositor_frame_sink_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(compositor_frame_sink_id),
276 frame(std::move(output_frame)) {}
276 277
277 RenderWidgetHostViewAndroid::LastFrameInfo::~LastFrameInfo() {} 278 RenderWidgetHostViewAndroid::LastFrameInfo::~LastFrameInfo() {}
278 279
279 void RenderWidgetHostViewAndroid::OnContextLost() { 280 void RenderWidgetHostViewAndroid::OnContextLost() {
280 std::unique_ptr<RenderWidgetHostIterator> widgets( 281 std::unique_ptr<RenderWidgetHostIterator> widgets(
281 RenderWidgetHostImpl::GetAllRenderWidgetHosts()); 282 RenderWidgetHostImpl::GetAllRenderWidgetHosts());
282 while (RenderWidgetHost* widget = widgets->GetNextHost()) { 283 while (RenderWidgetHost* widget = widgets->GetNextHost()) {
283 if (widget->GetView()) { 284 if (widget->GetView()) {
284 static_cast<RenderWidgetHostViewAndroid*>(widget->GetView()) 285 static_cast<RenderWidgetHostViewAndroid*>(widget->GetView())
285 ->OnLostResources(); 286 ->OnLostResources();
286 } 287 }
287 } 288 }
288 } 289 }
289 290
290 RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid( 291 RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid(
291 RenderWidgetHostImpl* widget_host, 292 RenderWidgetHostImpl* widget_host,
292 ContentViewCoreImpl* content_view_core) 293 ContentViewCoreImpl* content_view_core)
293 : host_(widget_host), 294 : host_(widget_host),
294 outstanding_vsync_requests_(0), 295 outstanding_vsync_requests_(0),
295 is_showing_(!widget_host->is_hidden()), 296 is_showing_(!widget_host->is_hidden()),
296 is_window_visible_(true), 297 is_window_visible_(true),
297 is_window_activity_started_(true), 298 is_window_activity_started_(true),
298 content_view_core_(nullptr), 299 content_view_core_(nullptr),
299 ime_adapter_android_(this), 300 ime_adapter_android_(this),
300 cached_background_color_(SK_ColorWHITE), 301 cached_background_color_(SK_ColorWHITE),
301 last_output_surface_id_(kUndefinedOutputSurfaceId), 302 last_compositor_frame_sink_id_(kUndefinedCompositorFrameSinkId),
302 gesture_provider_(ui::GetGestureProviderConfig( 303 gesture_provider_(ui::GetGestureProviderConfig(
303 ui::GestureProviderConfigType::CURRENT_PLATFORM), 304 ui::GestureProviderConfigType::CURRENT_PLATFORM),
304 this), 305 this),
305 stylus_text_selector_(this), 306 stylus_text_selector_(this),
306 using_browser_compositor_(CompositorImpl::IsInitialized()), 307 using_browser_compositor_(CompositorImpl::IsInitialized()),
307 frame_evictor_(new DelegatedFrameEvictor(this)), 308 frame_evictor_(new DelegatedFrameEvictor(this)),
308 locks_on_frame_count_(0), 309 locks_on_frame_count_(0),
309 observing_root_window_(false), 310 observing_root_window_(false),
310 weak_ptr_factory_(this) { 311 weak_ptr_factory_(this) {
311 // Set the layer which will hold the content layer for this view. The content 312 // 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
509 DCHECK_EQ(locks_on_frame_count_, 0u); 510 DCHECK_EQ(locks_on_frame_count_, 0u);
510 return; 511 return;
511 } 512 }
512 513
513 DCHECK_GT(locks_on_frame_count_, 0u); 514 DCHECK_GT(locks_on_frame_count_, 0u);
514 locks_on_frame_count_--; 515 locks_on_frame_count_--;
515 frame_evictor_->UnlockFrame(); 516 frame_evictor_->UnlockFrame();
516 517
517 if (locks_on_frame_count_ == 0) { 518 if (locks_on_frame_count_ == 0) {
518 if (last_frame_info_) { 519 if (last_frame_info_) {
519 InternalSwapCompositorFrame(last_frame_info_->output_surface_id, 520 InternalSwapCompositorFrame(last_frame_info_->compositor_frame_sink_id,
520 std::move(last_frame_info_->frame)); 521 std::move(last_frame_info_->frame));
521 last_frame_info_.reset(); 522 last_frame_info_.reset();
522 } 523 }
523 524
524 view_.GetLayer()->SetHideLayerAndSubtree(!is_showing_); 525 view_.GetLayer()->SetHideLayerAndSubtree(!is_showing_);
525 } 526 }
526 } 527 }
527 528
528 void RenderWidgetHostViewAndroid::OnShowUnhandledTapUIIfNeeded(int x_dip, 529 void RenderWidgetHostViewAndroid::OnShowUnhandledTapUIIfNeeded(int x_dip,
529 int y_dip) { 530 int y_dip) {
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 } 885 }
885 886
886 std::unique_ptr<SyntheticGestureTarget> 887 std::unique_ptr<SyntheticGestureTarget>
887 RenderWidgetHostViewAndroid::CreateSyntheticGestureTarget() { 888 RenderWidgetHostViewAndroid::CreateSyntheticGestureTarget() {
888 return std::unique_ptr<SyntheticGestureTarget>( 889 return std::unique_ptr<SyntheticGestureTarget>(
889 new SyntheticGestureTargetAndroid( 890 new SyntheticGestureTargetAndroid(
890 host_, content_view_core_->CreateMotionEventSynthesizer())); 891 host_, content_view_core_->CreateMotionEventSynthesizer()));
891 } 892 }
892 893
893 void RenderWidgetHostViewAndroid::SendReclaimCompositorResources( 894 void RenderWidgetHostViewAndroid::SendReclaimCompositorResources(
894 uint32_t output_surface_id, 895 uint32_t compositor_frame_sink_id,
895 bool is_swap_ack) { 896 bool is_swap_ack) {
896 DCHECK(host_); 897 DCHECK(host_);
897 host_->Send(new ViewMsg_ReclaimCompositorResources( 898 host_->Send(new ViewMsg_ReclaimCompositorResources(
898 host_->GetRoutingID(), output_surface_id, is_swap_ack, 899 host_->GetRoutingID(), compositor_frame_sink_id, is_swap_ack,
899 surface_returned_resources_)); 900 surface_returned_resources_));
900 surface_returned_resources_.clear(); 901 surface_returned_resources_.clear();
901 } 902 }
902 903
903 void RenderWidgetHostViewAndroid::ReturnResources( 904 void RenderWidgetHostViewAndroid::ReturnResources(
904 const cc::ReturnedResourceArray& resources) { 905 const cc::ReturnedResourceArray& resources) {
905 if (resources.empty()) 906 if (resources.empty())
906 return; 907 return;
907 std::copy(resources.begin(), resources.end(), 908 std::copy(resources.begin(), resources.end(),
908 std::back_inserter(surface_returned_resources_)); 909 std::back_inserter(surface_returned_resources_));
909 if (ack_callbacks_.empty()) 910 if (ack_callbacks_.empty())
910 SendReclaimCompositorResources(last_output_surface_id_, 911 SendReclaimCompositorResources(last_compositor_frame_sink_id_,
911 false /* is_swap_ack */); 912 false /* is_swap_ack */);
912 } 913 }
913 914
914 void RenderWidgetHostViewAndroid::CheckOutputSurfaceChanged( 915 void RenderWidgetHostViewAndroid::CheckCompositorFrameSinkChanged(
915 uint32_t output_surface_id) { 916 uint32_t compositor_frame_sink_id) {
916 if (output_surface_id == last_output_surface_id_) 917 if (compositor_frame_sink_id == last_compositor_frame_sink_id_)
917 return; 918 return;
918 919
919 delegated_frame_host_->OutputSurfaceChanged(); 920 delegated_frame_host_->CompositorFrameSinkChanged();
920 921
921 if (!surface_returned_resources_.empty()) 922 if (!surface_returned_resources_.empty())
922 SendReclaimCompositorResources(last_output_surface_id_, 923 SendReclaimCompositorResources(last_compositor_frame_sink_id_,
923 false /* is_swap_ack */); 924 false /* is_swap_ack */);
924 925
925 last_output_surface_id_ = output_surface_id; 926 last_compositor_frame_sink_id_ = compositor_frame_sink_id;
926 } 927 }
927 928
928 void RenderWidgetHostViewAndroid::InternalSwapCompositorFrame( 929 void RenderWidgetHostViewAndroid::InternalSwapCompositorFrame(
929 uint32_t output_surface_id, 930 uint32_t compositor_frame_sink_id,
930 cc::CompositorFrame frame) { 931 cc::CompositorFrame frame) {
931 last_scroll_offset_ = frame.metadata.root_scroll_offset; 932 last_scroll_offset_ = frame.metadata.root_scroll_offset;
932 DCHECK(frame.delegated_frame_data); 933 DCHECK(frame.delegated_frame_data);
933 DCHECK(delegated_frame_host_); 934 DCHECK(delegated_frame_host_);
934 935
935 if (locks_on_frame_count_ > 0) { 936 if (locks_on_frame_count_ > 0) {
936 DCHECK(HasValidFrame()); 937 DCHECK(HasValidFrame());
937 RetainFrame(output_surface_id, std::move(frame)); 938 RetainFrame(compositor_frame_sink_id, std::move(frame));
938 return; 939 return;
939 } 940 }
940 941
941 DCHECK(!frame.delegated_frame_data->render_pass_list.empty()); 942 DCHECK(!frame.delegated_frame_data->render_pass_list.empty());
942 943
943 cc::RenderPass* root_pass = 944 cc::RenderPass* root_pass =
944 frame.delegated_frame_data->render_pass_list.back().get(); 945 frame.delegated_frame_data->render_pass_list.back().get();
945 current_surface_size_ = root_pass->output_rect.size(); 946 current_surface_size_ = root_pass->output_rect.size();
946 bool is_transparent = root_pass->has_transparent_background; 947 bool is_transparent = root_pass->has_transparent_background;
947 948
948 cc::CompositorFrameMetadata metadata = frame.metadata.Clone(); 949 cc::CompositorFrameMetadata metadata = frame.metadata.Clone();
949 950
950 CheckOutputSurfaceChanged(output_surface_id); 951 CheckCompositorFrameSinkChanged(compositor_frame_sink_id);
951 bool has_content = !current_surface_size_.IsEmpty(); 952 bool has_content = !current_surface_size_.IsEmpty();
952 953
953 base::Closure ack_callback = 954 base::Closure ack_callback =
954 base::Bind(&RenderWidgetHostViewAndroid::SendReclaimCompositorResources, 955 base::Bind(&RenderWidgetHostViewAndroid::SendReclaimCompositorResources,
955 weak_ptr_factory_.GetWeakPtr(), output_surface_id, 956 weak_ptr_factory_.GetWeakPtr(), compositor_frame_sink_id,
956 true /* is_swap_ack */); 957 true /* is_swap_ack */);
957 958
958 ack_callbacks_.push(ack_callback); 959 ack_callbacks_.push(ack_callback);
959 960
960 if (!has_content) { 961 if (!has_content) {
961 DestroyDelegatedContent(); 962 DestroyDelegatedContent();
962 } else { 963 } else {
963 cc::SurfaceFactory::DrawCallback ack_callback = 964 cc::SurfaceFactory::DrawCallback ack_callback =
964 base::Bind(&RenderWidgetHostViewAndroid::RunAckCallbacks, 965 base::Bind(&RenderWidgetHostViewAndroid::RunAckCallbacks,
965 weak_ptr_factory_.GetWeakPtr()); 966 weak_ptr_factory_.GetWeakPtr());
(...skipping 20 matching lines...) Expand all
986 return; 987 return;
987 988
988 if (!delegated_frame_host_->HasDelegatedContent()) 989 if (!delegated_frame_host_->HasDelegatedContent())
989 return; 990 return;
990 991
991 frame_evictor_->DiscardedFrame(); 992 frame_evictor_->DiscardedFrame();
992 delegated_frame_host_->DestroyDelegatedContent(); 993 delegated_frame_host_->DestroyDelegatedContent();
993 } 994 }
994 995
995 void RenderWidgetHostViewAndroid::OnSwapCompositorFrame( 996 void RenderWidgetHostViewAndroid::OnSwapCompositorFrame(
996 uint32_t output_surface_id, 997 uint32_t compositor_frame_sink_id,
997 cc::CompositorFrame frame) { 998 cc::CompositorFrame frame) {
998 InternalSwapCompositorFrame(output_surface_id, std::move(frame)); 999 InternalSwapCompositorFrame(compositor_frame_sink_id, std::move(frame));
999 } 1000 }
1000 1001
1001 void RenderWidgetHostViewAndroid::ClearCompositorFrame() { 1002 void RenderWidgetHostViewAndroid::ClearCompositorFrame() {
1002 DestroyDelegatedContent(); 1003 DestroyDelegatedContent();
1003 } 1004 }
1004 1005
1005 void RenderWidgetHostViewAndroid::RetainFrame(uint32_t output_surface_id, 1006 void RenderWidgetHostViewAndroid::RetainFrame(uint32_t compositor_frame_sink_id,
1006 cc::CompositorFrame frame) { 1007 cc::CompositorFrame frame) {
1007 DCHECK(locks_on_frame_count_); 1008 DCHECK(locks_on_frame_count_);
1008 1009
1009 // Store the incoming frame so that it can be swapped when all the locks have 1010 // 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 1011 // 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 1012 // 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. 1013 // the ACK also blocks the renderer when its max_frames_pending is reached.
1013 if (last_frame_info_) { 1014 if (last_frame_info_) {
1014 base::Closure ack_callback = 1015 base::Closure ack_callback = base::Bind(
1015 base::Bind(&RenderWidgetHostViewAndroid::SendReclaimCompositorResources, 1016 &RenderWidgetHostViewAndroid::SendReclaimCompositorResources,
1016 weak_ptr_factory_.GetWeakPtr(), 1017 weak_ptr_factory_.GetWeakPtr(),
1017 last_frame_info_->output_surface_id, true /* is_swap_ack */); 1018 last_frame_info_->compositor_frame_sink_id, true /* is_swap_ack */);
1018 1019
1019 ack_callbacks_.push(ack_callback); 1020 ack_callbacks_.push(ack_callback);
1020 } 1021 }
1021 1022
1022 last_frame_info_.reset( 1023 last_frame_info_.reset(
1023 new LastFrameInfo(output_surface_id, std::move(frame))); 1024 new LastFrameInfo(compositor_frame_sink_id, std::move(frame)));
1024 } 1025 }
1025 1026
1026 void RenderWidgetHostViewAndroid::SynchronousFrameMetadata( 1027 void RenderWidgetHostViewAndroid::SynchronousFrameMetadata(
1027 cc::CompositorFrameMetadata frame_metadata) { 1028 cc::CompositorFrameMetadata frame_metadata) {
1028 if (!content_view_core_) 1029 if (!content_view_core_)
1029 return; 1030 return;
1030 1031
1031 bool is_mobile_optimized = IsMobileOptimizedFrame(frame_metadata); 1032 bool is_mobile_optimized = IsMobileOptimizedFrame(frame_metadata);
1032 1033
1033 if (host_ && host_->input_router()) { 1034 if (host_ && host_->input_router()) {
(...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after
1880 case ui::MotionEvent::ACTION_UP: 1881 case ui::MotionEvent::ACTION_UP:
1881 case ui::MotionEvent::ACTION_POINTER_UP: 1882 case ui::MotionEvent::ACTION_POINTER_UP:
1882 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED", 1883 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED",
1883 delta.InMicroseconds(), 1, 1000000, 50); 1884 delta.InMicroseconds(), 1, 1000000, 50);
1884 default: 1885 default:
1885 return; 1886 return;
1886 } 1887 }
1887 } 1888 }
1888 1889
1889 } // namespace content 1890 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698