| 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/renderer/android/synchronous_compositor_proxy.h" | 5 #include "content/renderer/android/synchronous_compositor_proxy.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/memory/shared_memory.h" | 9 #include "base/memory/shared_memory.h" |
| 10 #include "cc/ipc/cc_param_traits.h" | 10 #include "cc/ipc/cc_param_traits.h" |
| 11 #include "content/common/android/sync_compositor_messages.h" | 11 #include "content/common/android/sync_compositor_messages.h" |
| 12 #include "content/common/android/sync_compositor_statics.h" | 12 #include "content/common/android/sync_compositor_statics.h" |
| 13 #include "content/public/common/content_switches.h" | 13 #include "content/public/common/content_switches.h" |
| 14 #include "ipc/ipc_message.h" | 14 #include "ipc/ipc_message.h" |
| 15 #include "ipc/ipc_sender.h" | 15 #include "ipc/ipc_sender.h" |
| 16 #include "third_party/skia/include/core/SkBitmap.h" | 16 #include "third_party/skia/include/core/SkBitmap.h" |
| 17 #include "third_party/skia/include/core/SkCanvas.h" | 17 #include "third_party/skia/include/core/SkCanvas.h" |
| 18 #include "third_party/skia/include/core/SkImageInfo.h" | 18 #include "third_party/skia/include/core/SkImageInfo.h" |
| 19 #include "third_party/skia/include/core/SkRegion.h" | 19 #include "third_party/skia/include/core/SkRegion.h" |
| 20 #include "ui/events/latency_info.h" | |
| 21 #include "ui/gfx/skia_util.h" | 20 #include "ui/gfx/skia_util.h" |
| 22 | 21 |
| 23 namespace content { | 22 namespace content { |
| 24 | 23 |
| 25 SynchronousCompositorProxy::SynchronousCompositorProxy( | 24 SynchronousCompositorProxy::SynchronousCompositorProxy( |
| 26 int routing_id, | 25 int routing_id, |
| 27 IPC::Sender* sender, | 26 IPC::Sender* sender, |
| 28 SynchronousCompositorExternalBeginFrameSource* begin_frame_source, | 27 SynchronousCompositorExternalBeginFrameSource* begin_frame_source, |
| 29 ui::SynchronousInputHandlerProxy* input_handler_proxy, | 28 ui::SynchronousInputHandlerProxy* input_handler_proxy) |
| 30 InputHandlerManagerClient::Handler* handler) | |
| 31 : routing_id_(routing_id), | 29 : routing_id_(routing_id), |
| 32 sender_(sender), | 30 sender_(sender), |
| 33 begin_frame_source_(begin_frame_source), | 31 begin_frame_source_(begin_frame_source), |
| 34 input_handler_proxy_(input_handler_proxy), | 32 input_handler_proxy_(input_handler_proxy), |
| 35 input_handler_(handler), | |
| 36 use_in_process_zero_copy_software_draw_( | 33 use_in_process_zero_copy_software_draw_( |
| 37 base::CommandLine::ForCurrentProcess()->HasSwitch( | 34 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 38 switches::kSingleProcess)), | 35 switches::kSingleProcess)), |
| 39 output_surface_(nullptr), | 36 output_surface_(nullptr), |
| 40 inside_receive_(false), | 37 inside_receive_(false), |
| 41 hardware_draw_reply_(nullptr), | 38 hardware_draw_reply_(nullptr), |
| 42 software_draw_reply_(nullptr), | 39 software_draw_reply_(nullptr), |
| 43 version_(0u), | 40 version_(0u), |
| 44 page_scale_factor_(0.f), | 41 page_scale_factor_(0.f), |
| 45 min_page_scale_factor_(0.f), | 42 min_page_scale_factor_(0.f), |
| 46 max_page_scale_factor_(0.f), | 43 max_page_scale_factor_(0.f), |
| 47 need_animate_scroll_(false), | 44 need_animate_scroll_(false), |
| 48 need_invalidate_count_(0u), | 45 need_invalidate_count_(0u), |
| 49 need_begin_frame_(false), | 46 need_begin_frame_(false), |
| 50 did_activate_pending_tree_count_(0u) { | 47 did_activate_pending_tree_count_(0u) { |
| 51 DCHECK(begin_frame_source_); | 48 DCHECK(begin_frame_source_); |
| 52 DCHECK(input_handler_proxy_); | 49 DCHECK(input_handler_proxy_); |
| 53 DCHECK(input_handler_); | |
| 54 begin_frame_source_->SetClient(this); | 50 begin_frame_source_->SetClient(this); |
| 55 input_handler_proxy_->SetOnlySynchronouslyAnimateRootFlings(this); | 51 input_handler_proxy_->SetOnlySynchronouslyAnimateRootFlings(this); |
| 56 } | 52 } |
| 57 | 53 |
| 58 SynchronousCompositorProxy::~SynchronousCompositorProxy() { | 54 SynchronousCompositorProxy::~SynchronousCompositorProxy() { |
| 59 SetOutputSurface(nullptr); | 55 SetOutputSurface(nullptr); |
| 60 begin_frame_source_->SetClient(nullptr); | 56 begin_frame_source_->SetClient(nullptr); |
| 61 input_handler_proxy_->SetOnlySynchronouslyAnimateRootFlings(nullptr); | 57 input_handler_proxy_->SetOnlySynchronouslyAnimateRootFlings(nullptr); |
| 62 } | 58 } |
| 63 | 59 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 params->need_begin_frame = need_begin_frame_; | 138 params->need_begin_frame = need_begin_frame_; |
| 143 params->did_activate_pending_tree_count = did_activate_pending_tree_count_; | 139 params->did_activate_pending_tree_count = did_activate_pending_tree_count_; |
| 144 } | 140 } |
| 145 | 141 |
| 146 void SynchronousCompositorProxy::OnMessageReceived( | 142 void SynchronousCompositorProxy::OnMessageReceived( |
| 147 const IPC::Message& message) { | 143 const IPC::Message& message) { |
| 148 if (output_surface_ && output_surface_->OnMessageReceived(message)) | 144 if (output_surface_ && output_surface_->OnMessageReceived(message)) |
| 149 return; | 145 return; |
| 150 | 146 |
| 151 IPC_BEGIN_MESSAGE_MAP(SynchronousCompositorProxy, message) | 147 IPC_BEGIN_MESSAGE_MAP(SynchronousCompositorProxy, message) |
| 152 IPC_MESSAGE_HANDLER(SyncCompositorMsg_HandleInputEvent, HandleInputEvent) | |
| 153 IPC_MESSAGE_HANDLER(SyncCompositorMsg_BeginFrame, BeginFrame) | 148 IPC_MESSAGE_HANDLER(SyncCompositorMsg_BeginFrame, BeginFrame) |
| 154 IPC_MESSAGE_HANDLER(SyncCompositorMsg_ComputeScroll, OnComputeScroll) | 149 IPC_MESSAGE_HANDLER(SyncCompositorMsg_ComputeScroll, OnComputeScroll) |
| 155 IPC_MESSAGE_HANDLER_DELAY_REPLY(SyncCompositorMsg_DemandDrawHw, | 150 IPC_MESSAGE_HANDLER_DELAY_REPLY(SyncCompositorMsg_DemandDrawHw, |
| 156 DemandDrawHw) | 151 DemandDrawHw) |
| 157 IPC_MESSAGE_HANDLER(SyncCompositorMsg_SetSharedMemory, SetSharedMemory) | 152 IPC_MESSAGE_HANDLER(SyncCompositorMsg_SetSharedMemory, SetSharedMemory) |
| 158 IPC_MESSAGE_HANDLER(SyncCompositorMsg_ZeroSharedMemory, ZeroSharedMemory) | 153 IPC_MESSAGE_HANDLER(SyncCompositorMsg_ZeroSharedMemory, ZeroSharedMemory) |
| 159 IPC_MESSAGE_HANDLER_DELAY_REPLY(SyncCompositorMsg_DemandDrawSw, | 154 IPC_MESSAGE_HANDLER_DELAY_REPLY(SyncCompositorMsg_DemandDrawSw, |
| 160 DemandDrawSw) | 155 DemandDrawSw) |
| 161 IPC_MESSAGE_HANDLER(SyncCompositorMsg_UpdateState, ProcessCommonParams) | 156 IPC_MESSAGE_HANDLER(SyncCompositorMsg_UpdateState, ProcessCommonParams) |
| 162 IPC_MESSAGE_HANDLER(SyncCompositorMsg_ZoomBy, SynchronouslyZoomBy) | 157 IPC_MESSAGE_HANDLER(SyncCompositorMsg_ZoomBy, SynchronouslyZoomBy) |
| 163 IPC_MESSAGE_HANDLER(SyncCompositorMsg_SetScroll, SetScroll) | 158 IPC_MESSAGE_HANDLER(SyncCompositorMsg_SetScroll, SetScroll) |
| 164 IPC_END_MESSAGE_MAP() | 159 IPC_END_MESSAGE_MAP() |
| 165 } | 160 } |
| 166 | 161 |
| 167 bool SynchronousCompositorProxy::Send(IPC::Message* message) { | 162 bool SynchronousCompositorProxy::Send(IPC::Message* message) { |
| 168 return sender_->Send(message); | 163 return sender_->Send(message); |
| 169 } | 164 } |
| 170 | 165 |
| 171 void SynchronousCompositorProxy::HandleInputEvent( | |
| 172 const SyncCompositorCommonBrowserParams& common_params, | |
| 173 const blink::WebInputEvent* event, | |
| 174 SyncCompositorCommonRendererParams* common_renderer_params, | |
| 175 InputEventAckState* ack) { | |
| 176 DCHECK(!inside_receive_); | |
| 177 base::AutoReset<bool> scoped_inside_receive(&inside_receive_, true); | |
| 178 | |
| 179 ProcessCommonParams(common_params); | |
| 180 DCHECK(!input_handler_->is_null()); | |
| 181 ui::LatencyInfo latency; | |
| 182 *ack = input_handler_->Run(routing_id_, event, &latency); | |
| 183 PopulateCommonParams(common_renderer_params); | |
| 184 } | |
| 185 | |
| 186 void SynchronousCompositorProxy::BeginFrame( | 166 void SynchronousCompositorProxy::BeginFrame( |
| 187 const SyncCompositorCommonBrowserParams& common_params, | 167 const SyncCompositorCommonBrowserParams& common_params, |
| 188 const cc::BeginFrameArgs& args, | 168 const cc::BeginFrameArgs& args, |
| 189 SyncCompositorCommonRendererParams* common_renderer_params) { | 169 SyncCompositorCommonRendererParams* common_renderer_params) { |
| 190 DCHECK(!inside_receive_); | 170 DCHECK(!inside_receive_); |
| 191 base::AutoReset<bool> scoped_inside_receive(&inside_receive_, true); | 171 base::AutoReset<bool> scoped_inside_receive(&inside_receive_, true); |
| 192 | 172 |
| 193 ProcessCommonParams(common_params); | 173 ProcessCommonParams(common_params); |
| 194 if (need_begin_frame_) { | 174 if (need_begin_frame_) { |
| 195 begin_frame_source_->BeginFrame(args); | 175 begin_frame_source_->BeginFrame(args); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 } | 363 } |
| 384 | 364 |
| 385 void SynchronousCompositorProxy::SetScroll( | 365 void SynchronousCompositorProxy::SetScroll( |
| 386 const gfx::ScrollOffset& new_total_scroll_offset) { | 366 const gfx::ScrollOffset& new_total_scroll_offset) { |
| 387 if (total_scroll_offset_ == new_total_scroll_offset) | 367 if (total_scroll_offset_ == new_total_scroll_offset) |
| 388 return; | 368 return; |
| 389 total_scroll_offset_ = new_total_scroll_offset; | 369 total_scroll_offset_ = new_total_scroll_offset; |
| 390 input_handler_proxy_->SynchronouslySetRootScrollOffset(total_scroll_offset_); | 370 input_handler_proxy_->SynchronouslySetRootScrollOffset(total_scroll_offset_); |
| 391 } | 371 } |
| 392 | 372 |
| 393 void SynchronousCompositorProxy::DidOverscroll( | |
| 394 const DidOverscrollParams& did_overscroll_params) { | |
| 395 SyncCompositorCommonRendererParams params; | |
| 396 PopulateCommonParams(¶ms); | |
| 397 Send(new SyncCompositorHostMsg_OverScroll(routing_id_, params, | |
| 398 did_overscroll_params)); | |
| 399 } | |
| 400 | |
| 401 void SynchronousCompositorProxy::ProcessCommonParams( | 373 void SynchronousCompositorProxy::ProcessCommonParams( |
| 402 const SyncCompositorCommonBrowserParams& common_params) { | 374 const SyncCompositorCommonBrowserParams& common_params) { |
| 403 begin_frame_source_->SetBeginFrameSourcePaused( | 375 begin_frame_source_->SetBeginFrameSourcePaused( |
| 404 common_params.begin_frame_source_paused); | 376 common_params.begin_frame_source_paused); |
| 405 } | 377 } |
| 406 | 378 |
| 407 } // namespace content | 379 } // namespace content |
| OLD | NEW |