OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/android/synchronous_compositor_host.h" | 5 #include "content/browser/android/synchronous_compositor_host.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 std::unique_ptr<SynchronousCompositorHost> SynchronousCompositorHost::Create( | 46 std::unique_ptr<SynchronousCompositorHost> SynchronousCompositorHost::Create( |
47 RenderWidgetHostViewAndroid* rwhva, | 47 RenderWidgetHostViewAndroid* rwhva, |
48 WebContents* web_contents) { | 48 WebContents* web_contents) { |
49 DCHECK(web_contents); | 49 DCHECK(web_contents); |
50 WebContentsAndroid* web_contents_android = | 50 WebContentsAndroid* web_contents_android = |
51 static_cast<WebContentsImpl*>(web_contents)->GetWebContentsAndroid(); | 51 static_cast<WebContentsImpl*>(web_contents)->GetWebContentsAndroid(); |
52 if (!web_contents_android->synchronous_compositor_client()) | 52 if (!web_contents_android->synchronous_compositor_client()) |
53 return nullptr; // Not using sync compositing. | 53 return nullptr; // Not using sync compositing. |
54 | 54 |
55 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 55 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
56 bool async_input = | |
57 !command_line->HasSwitch(switches::kSyncInputForSyncCompositor); | |
58 bool use_in_proc_software_draw = | 56 bool use_in_proc_software_draw = |
59 command_line->HasSwitch(switches::kSingleProcess); | 57 command_line->HasSwitch(switches::kSingleProcess); |
60 return base::WrapUnique(new SynchronousCompositorHost( | 58 return base::WrapUnique(new SynchronousCompositorHost( |
61 rwhva, web_contents_android->synchronous_compositor_client(), async_input, | 59 rwhva, web_contents_android->synchronous_compositor_client(), |
62 use_in_proc_software_draw)); | 60 use_in_proc_software_draw)); |
63 } | 61 } |
64 | 62 |
65 SynchronousCompositorHost::SynchronousCompositorHost( | 63 SynchronousCompositorHost::SynchronousCompositorHost( |
66 RenderWidgetHostViewAndroid* rwhva, | 64 RenderWidgetHostViewAndroid* rwhva, |
67 SynchronousCompositorClient* client, | 65 SynchronousCompositorClient* client, |
68 bool async_input, | |
69 bool use_in_proc_software_draw) | 66 bool use_in_proc_software_draw) |
70 : rwhva_(rwhva), | 67 : rwhva_(rwhva), |
71 client_(client), | 68 client_(client), |
72 ui_task_runner_( | 69 ui_task_runner_( |
73 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI)), | 70 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI)), |
74 routing_id_(rwhva_->GetRenderWidgetHost()->GetRoutingID()), | 71 routing_id_(rwhva_->GetRenderWidgetHost()->GetRoutingID()), |
75 sender_(rwhva_->GetRenderWidgetHost()), | 72 sender_(rwhva_->GetRenderWidgetHost()), |
76 async_input_(async_input), | |
77 use_in_process_zero_copy_software_draw_(use_in_proc_software_draw), | 73 use_in_process_zero_copy_software_draw_(use_in_proc_software_draw), |
78 is_active_(false), | 74 is_active_(false), |
79 bytes_limit_(0u), | 75 bytes_limit_(0u), |
80 renderer_param_version_(0u), | 76 renderer_param_version_(0u), |
81 need_animate_scroll_(false), | 77 need_animate_scroll_(false), |
82 need_invalidate_count_(0u), | 78 need_invalidate_count_(0u), |
83 need_begin_frame_(false), | 79 need_begin_frame_(false), |
84 did_activate_pending_tree_count_(0u), | 80 did_activate_pending_tree_count_(0u), |
85 weak_ptr_factory_(this) { | 81 weak_ptr_factory_(this) { |
86 client_->DidInitializeCompositor(this); | 82 client_->DidInitializeCompositor(this); |
87 } | 83 } |
88 | 84 |
89 SynchronousCompositorHost::~SynchronousCompositorHost() { | 85 SynchronousCompositorHost::~SynchronousCompositorHost() { |
90 client_->DidDestroyCompositor(this); | 86 client_->DidDestroyCompositor(this); |
91 if (weak_ptr_factory_.HasWeakPtrs()) | 87 if (weak_ptr_factory_.HasWeakPtrs()) |
92 UpdateStateTask(); | 88 UpdateStateTask(); |
93 } | 89 } |
94 | 90 |
95 bool SynchronousCompositorHost::OnMessageReceived(const IPC::Message& message) { | 91 bool SynchronousCompositorHost::OnMessageReceived(const IPC::Message& message) { |
96 bool handled = true; | 92 bool handled = true; |
97 IPC_BEGIN_MESSAGE_MAP(SynchronousCompositorHost, message) | 93 IPC_BEGIN_MESSAGE_MAP(SynchronousCompositorHost, message) |
98 IPC_MESSAGE_HANDLER(SyncCompositorHostMsg_OutputSurfaceCreated, | 94 IPC_MESSAGE_HANDLER(SyncCompositorHostMsg_OutputSurfaceCreated, |
99 OutputSurfaceCreated) | 95 OutputSurfaceCreated) |
100 IPC_MESSAGE_HANDLER(SyncCompositorHostMsg_UpdateState, ProcessCommonParams) | 96 IPC_MESSAGE_HANDLER(SyncCompositorHostMsg_UpdateState, ProcessCommonParams) |
101 IPC_MESSAGE_HANDLER(SyncCompositorHostMsg_OverScroll, OnOverScroll) | |
102 IPC_MESSAGE_UNHANDLED(handled = false) | 97 IPC_MESSAGE_UNHANDLED(handled = false) |
103 IPC_END_MESSAGE_MAP() | 98 IPC_END_MESSAGE_MAP() |
104 return handled; | 99 return handled; |
105 } | 100 } |
106 | 101 |
107 void SynchronousCompositorHost::DidBecomeCurrent() { | 102 void SynchronousCompositorHost::DidBecomeCurrent() { |
108 client_->DidBecomeCurrent(this); | 103 client_->DidBecomeCurrent(this); |
109 } | 104 } |
110 | 105 |
111 SynchronousCompositor::Frame SynchronousCompositorHost::DemandDrawHw( | 106 SynchronousCompositor::Frame SynchronousCompositorHost::DemandDrawHw( |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 return; | 372 return; |
378 need_animate_scroll_ = false; | 373 need_animate_scroll_ = false; |
379 | 374 |
380 SyncCompositorCommonBrowserParams common_browser_params; | 375 SyncCompositorCommonBrowserParams common_browser_params; |
381 PopulateCommonParams(&common_browser_params); | 376 PopulateCommonParams(&common_browser_params); |
382 SyncCompositorCommonRendererParams common_renderer_params; | 377 SyncCompositorCommonRendererParams common_renderer_params; |
383 sender_->Send(new SyncCompositorMsg_ComputeScroll( | 378 sender_->Send(new SyncCompositorMsg_ComputeScroll( |
384 routing_id_, common_browser_params, animation_time)); | 379 routing_id_, common_browser_params, animation_time)); |
385 } | 380 } |
386 | 381 |
387 InputEventAckState SynchronousCompositorHost::HandleInputEvent( | |
388 const blink::WebInputEvent& input_event) { | |
389 if (async_input_) | |
390 return INPUT_EVENT_ACK_STATE_NOT_CONSUMED; | |
391 SyncCompositorCommonBrowserParams common_browser_params; | |
392 PopulateCommonParams(&common_browser_params); | |
393 SyncCompositorCommonRendererParams common_renderer_params; | |
394 InputEventAckState ack = INPUT_EVENT_ACK_STATE_NOT_CONSUMED; | |
395 if (!sender_->Send(new SyncCompositorMsg_HandleInputEvent( | |
396 routing_id_, common_browser_params, &input_event, | |
397 &common_renderer_params, &ack))) { | |
398 return INPUT_EVENT_ACK_STATE_NOT_CONSUMED; | |
399 } | |
400 ProcessCommonParams(common_renderer_params); | |
401 return ack; | |
402 } | |
403 | |
404 void SynchronousCompositorHost::DidOverscroll( | 382 void SynchronousCompositorHost::DidOverscroll( |
405 const DidOverscrollParams& over_scroll_params) { | 383 const DidOverscrollParams& over_scroll_params) { |
406 client_->DidOverscroll(over_scroll_params.accumulated_overscroll, | 384 client_->DidOverscroll(over_scroll_params.accumulated_overscroll, |
407 over_scroll_params.latest_overscroll_delta, | 385 over_scroll_params.latest_overscroll_delta, |
408 over_scroll_params.current_fling_velocity); | 386 over_scroll_params.current_fling_velocity); |
409 } | 387 } |
410 | 388 |
411 void SynchronousCompositorHost::BeginFrame(const cc::BeginFrameArgs& args) { | 389 void SynchronousCompositorHost::BeginFrame(const cc::BeginFrameArgs& args) { |
412 if (!is_active_) | 390 if (!is_active_) |
413 return; | 391 return; |
414 | 392 |
415 SyncCompositorCommonBrowserParams common_browser_params; | 393 SyncCompositorCommonBrowserParams common_browser_params; |
416 PopulateCommonParams(&common_browser_params); | 394 PopulateCommonParams(&common_browser_params); |
417 SyncCompositorCommonRendererParams common_renderer_params; | 395 SyncCompositorCommonRendererParams common_renderer_params; |
418 if (!sender_->Send( | 396 if (!sender_->Send( |
419 new SyncCompositorMsg_BeginFrame(routing_id_, common_browser_params, | 397 new SyncCompositorMsg_BeginFrame(routing_id_, common_browser_params, |
420 args, &common_renderer_params))) { | 398 args, &common_renderer_params))) { |
421 return; | 399 return; |
422 } | 400 } |
423 ProcessCommonParams(common_renderer_params); | 401 ProcessCommonParams(common_renderer_params); |
424 } | 402 } |
425 | 403 |
426 void SynchronousCompositorHost::OutputSurfaceCreated() { | 404 void SynchronousCompositorHost::OutputSurfaceCreated() { |
427 // New output surface is not aware of state from Browser side. So need to | 405 // New output surface is not aware of state from Browser side. So need to |
428 // re-send all browser side state here. | 406 // re-send all browser side state here. |
429 sender_->Send( | 407 sender_->Send( |
430 new SyncCompositorMsg_SetMemoryPolicy(routing_id_, bytes_limit_)); | 408 new SyncCompositorMsg_SetMemoryPolicy(routing_id_, bytes_limit_)); |
431 } | 409 } |
432 | 410 |
433 void SynchronousCompositorHost::OnOverScroll( | |
434 const SyncCompositorCommonRendererParams& params, | |
435 const DidOverscrollParams& over_scroll_params) { | |
436 ProcessCommonParams(params); | |
437 DidOverscroll(over_scroll_params); | |
438 } | |
439 | |
440 void SynchronousCompositorHost::PopulateCommonParams( | 411 void SynchronousCompositorHost::PopulateCommonParams( |
441 SyncCompositorCommonBrowserParams* params) { | 412 SyncCompositorCommonBrowserParams* params) { |
442 DCHECK(params); | 413 DCHECK(params); |
443 params->begin_frame_source_paused = !is_active_; | 414 params->begin_frame_source_paused = !is_active_; |
444 | 415 |
445 weak_ptr_factory_.InvalidateWeakPtrs(); | 416 weak_ptr_factory_.InvalidateWeakPtrs(); |
446 } | 417 } |
447 | 418 |
448 void SynchronousCompositorHost::ProcessCommonParams( | 419 void SynchronousCompositorHost::ProcessCommonParams( |
449 const SyncCompositorCommonRendererParams& params) { | 420 const SyncCompositorCommonRendererParams& params) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 params.scrollable_size, params.page_scale_factor, | 452 params.scrollable_size, params.page_scale_factor, |
482 params.min_page_scale_factor, params.max_page_scale_factor); | 453 params.min_page_scale_factor, params.max_page_scale_factor); |
483 } | 454 } |
484 } | 455 } |
485 | 456 |
486 void SynchronousCompositorHost::UpdateNeedsBeginFrames() { | 457 void SynchronousCompositorHost::UpdateNeedsBeginFrames() { |
487 rwhva_->OnSetNeedsBeginFrames(is_active_ && need_begin_frame_); | 458 rwhva_->OnSetNeedsBeginFrames(is_active_ && need_begin_frame_); |
488 } | 459 } |
489 | 460 |
490 } // namespace content | 461 } // namespace content |
OLD | NEW |