Chromium Code Reviews| 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 "content/common/android/sync_compositor_messages.h" | 10 #include "content/common/android/sync_compositor_messages.h" |
| 11 #include "content/common/cc_messages.h" | 11 #include "content/common/cc_messages.h" |
| 12 #include "content/public/common/content_switches.h" | 12 #include "content/public/common/content_switches.h" |
| 13 #include "ipc/ipc_message.h" | 13 #include "ipc/ipc_message.h" |
| 14 #include "ipc/ipc_sender.h" | 14 #include "ipc/ipc_sender.h" |
| 15 #include "third_party/skia/include/core/SkBitmap.h" | 15 #include "third_party/skia/include/core/SkBitmap.h" |
| 16 #include "third_party/skia/include/core/SkCanvas.h" | 16 #include "third_party/skia/include/core/SkCanvas.h" |
| 17 #include "third_party/skia/include/core/SkImageInfo.h" | 17 #include "third_party/skia/include/core/SkImageInfo.h" |
| 18 #include "third_party/skia/include/core/SkRegion.h" | 18 #include "third_party/skia/include/core/SkRegion.h" |
| 19 #include "ui/events/latency_info.h" | 19 #include "ui/events/latency_info.h" |
| 20 #include "ui/gfx/skia_util.h" | 20 #include "ui/gfx/skia_util.h" |
| 21 | 21 |
| 22 namespace content { | 22 namespace content { |
| 23 | 23 |
| 24 SynchronousCompositorProxy::SynchronousCompositorProxy( | 24 SynchronousCompositorProxy::SynchronousCompositorProxy( |
| 25 int routing_id, | 25 int routing_id, |
| 26 IPC::Sender* sender, | 26 IPC::Sender* sender, |
| 27 SynchronousCompositorOutputSurface* output_surface, | |
| 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) | 29 InputHandlerManagerClient::Handler* handler) |
| 31 : routing_id_(routing_id), | 30 : routing_id_(routing_id), |
| 32 sender_(sender), | 31 sender_(sender), |
| 33 output_surface_(output_surface), | |
| 34 begin_frame_source_(begin_frame_source), | 32 begin_frame_source_(begin_frame_source), |
| 35 input_handler_proxy_(input_handler_proxy), | 33 input_handler_proxy_(input_handler_proxy), |
| 36 input_handler_(handler), | 34 input_handler_(handler), |
| 37 use_in_process_zero_copy_software_draw_( | 35 use_in_process_zero_copy_software_draw_( |
| 38 base::CommandLine::ForCurrentProcess()->HasSwitch( | 36 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 39 switches::kSingleProcess)), | 37 switches::kSingleProcess)), |
| 38 output_surface_(nullptr), | |
| 40 inside_receive_(false), | 39 inside_receive_(false), |
| 41 hardware_draw_reply_(nullptr), | 40 hardware_draw_reply_(nullptr), |
| 42 software_draw_reply_(nullptr), | 41 software_draw_reply_(nullptr), |
| 43 bytes_limit_(0u), | 42 bytes_limit_(0u), |
| 44 version_(0u), | 43 version_(0u), |
| 45 page_scale_factor_(0.f), | 44 page_scale_factor_(0.f), |
| 46 min_page_scale_factor_(0.f), | 45 min_page_scale_factor_(0.f), |
| 47 max_page_scale_factor_(0.f), | 46 max_page_scale_factor_(0.f), |
| 48 need_animate_scroll_(false), | 47 need_animate_scroll_(false), |
| 49 need_invalidate_count_(0u), | 48 need_invalidate_count_(0u), |
| 50 need_begin_frame_(false), | 49 need_begin_frame_(false), |
| 51 did_activate_pending_tree_count_(0u) { | 50 did_activate_pending_tree_count_(0u) { |
| 52 DCHECK(output_surface_); | |
| 53 DCHECK(begin_frame_source_); | 51 DCHECK(begin_frame_source_); |
| 54 DCHECK(input_handler_proxy_); | 52 DCHECK(input_handler_proxy_); |
| 55 DCHECK(input_handler_); | 53 DCHECK(input_handler_); |
| 56 output_surface_->SetSyncClient(this); | |
| 57 output_surface_->SetTreeActivationCallback( | |
| 58 base::Bind(&SynchronousCompositorProxy::DidActivatePendingTree, | |
| 59 base::Unretained(this))); | |
| 60 begin_frame_source_->SetClient(this); | 54 begin_frame_source_->SetClient(this); |
| 61 input_handler_proxy_->SetOnlySynchronouslyAnimateRootFlings(this); | 55 input_handler_proxy_->SetOnlySynchronouslyAnimateRootFlings(this); |
| 62 } | 56 } |
| 63 | 57 |
| 64 SynchronousCompositorProxy::~SynchronousCompositorProxy() { | 58 SynchronousCompositorProxy::~SynchronousCompositorProxy() { |
| 65 output_surface_->SetSyncClient(nullptr); | 59 SetOutputSurface(nullptr); |
| 66 output_surface_->SetTreeActivationCallback(base::Closure()); | |
| 67 begin_frame_source_->SetClient(nullptr); | 60 begin_frame_source_->SetClient(nullptr); |
| 68 input_handler_proxy_->SetOnlySynchronouslyAnimateRootFlings(nullptr); | 61 input_handler_proxy_->SetOnlySynchronouslyAnimateRootFlings(nullptr); |
| 69 } | 62 } |
| 70 | 63 |
| 64 void SynchronousCompositorProxy::SetOutputSurface( | |
| 65 SynchronousCompositorOutputSurface* output_surface) { | |
| 66 DCHECK_NE(output_surface_, output_surface); | |
| 67 if (output_surface_) { | |
| 68 output_surface_->SetSyncClient(nullptr); | |
| 69 output_surface_->SetTreeActivationCallback(base::Closure()); | |
| 70 } | |
| 71 output_surface_ = output_surface; | |
| 72 if (output_surface_) { | |
| 73 output_surface_->SetSyncClient(this); | |
| 74 output_surface_->SetTreeActivationCallback( | |
| 75 base::Bind(&SynchronousCompositorProxy::DidActivatePendingTree, | |
| 76 base::Unretained(this))); | |
| 77 output_surface_->SetMemoryPolicy(bytes_limit_); | |
|
Tobias Sargeant
2016/03/23 10:10:55
I guess previously we would never have called SetM
boliu
2016/03/23 15:52:53
Same behavior either way.
| |
| 78 } | |
| 79 } | |
| 80 | |
| 71 void SynchronousCompositorProxy::SetNeedsSynchronousAnimateInput() { | 81 void SynchronousCompositorProxy::SetNeedsSynchronousAnimateInput() { |
| 72 need_animate_scroll_ = true; | 82 need_animate_scroll_ = true; |
| 73 Invalidate(); | 83 Invalidate(); |
| 74 } | 84 } |
| 75 | 85 |
| 76 void SynchronousCompositorProxy::UpdateRootLayerState( | 86 void SynchronousCompositorProxy::UpdateRootLayerState( |
| 77 const gfx::ScrollOffset& total_scroll_offset, | 87 const gfx::ScrollOffset& total_scroll_offset, |
| 78 const gfx::ScrollOffset& max_scroll_offset, | 88 const gfx::ScrollOffset& max_scroll_offset, |
| 79 const gfx::SizeF& scrollable_size, | 89 const gfx::SizeF& scrollable_size, |
| 80 float page_scale_factor, | 90 float page_scale_factor, |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 110 SendAsyncRendererStateIfNeeded(); | 120 SendAsyncRendererStateIfNeeded(); |
| 111 } | 121 } |
| 112 | 122 |
| 113 void SynchronousCompositorProxy::DidActivatePendingTree() { | 123 void SynchronousCompositorProxy::DidActivatePendingTree() { |
| 114 ++did_activate_pending_tree_count_; | 124 ++did_activate_pending_tree_count_; |
| 115 SendAsyncRendererStateIfNeeded(); | 125 SendAsyncRendererStateIfNeeded(); |
| 116 DeliverMessages(); | 126 DeliverMessages(); |
| 117 } | 127 } |
| 118 | 128 |
| 119 void SynchronousCompositorProxy::DeliverMessages() { | 129 void SynchronousCompositorProxy::DeliverMessages() { |
| 130 DCHECK(output_surface_); | |
| 120 std::vector<scoped_ptr<IPC::Message>> messages; | 131 std::vector<scoped_ptr<IPC::Message>> messages; |
| 121 output_surface_->GetMessagesToDeliver(&messages); | 132 output_surface_->GetMessagesToDeliver(&messages); |
| 122 for (auto& msg : messages) { | 133 for (auto& msg : messages) { |
| 123 Send(msg.release()); | 134 Send(msg.release()); |
| 124 } | 135 } |
| 125 } | 136 } |
| 126 | 137 |
| 127 void SynchronousCompositorProxy::SendAsyncRendererStateIfNeeded() { | 138 void SynchronousCompositorProxy::SendAsyncRendererStateIfNeeded() { |
| 128 if (inside_receive_) | 139 if (inside_receive_) |
| 129 return; | 140 return; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 199 void SynchronousCompositorProxy::DemandDrawHw( | 210 void SynchronousCompositorProxy::DemandDrawHw( |
| 200 const SyncCompositorCommonBrowserParams& common_params, | 211 const SyncCompositorCommonBrowserParams& common_params, |
| 201 const SyncCompositorDemandDrawHwParams& params, | 212 const SyncCompositorDemandDrawHwParams& params, |
| 202 IPC::Message* reply_message) { | 213 IPC::Message* reply_message) { |
| 203 DCHECK(!inside_receive_); | 214 DCHECK(!inside_receive_); |
| 204 DCHECK(reply_message); | 215 DCHECK(reply_message); |
| 205 | 216 |
| 206 inside_receive_ = true; | 217 inside_receive_ = true; |
| 207 ProcessCommonParams(common_params); | 218 ProcessCommonParams(common_params); |
| 208 | 219 |
| 209 { | 220 if (output_surface_) { |
| 210 base::AutoReset<IPC::Message*> scoped_hardware_draw_reply( | 221 base::AutoReset<IPC::Message*> scoped_hardware_draw_reply( |
| 211 &hardware_draw_reply_, reply_message); | 222 &hardware_draw_reply_, reply_message); |
| 212 output_surface_->DemandDrawHw(params.surface_size, params.transform, | 223 output_surface_->DemandDrawHw(params.surface_size, params.transform, |
| 213 params.viewport, params.clip, | 224 params.viewport, params.clip, |
| 214 params.viewport_rect_for_tile_priority, | 225 params.viewport_rect_for_tile_priority, |
| 215 params.transform_for_tile_priority); | 226 params.transform_for_tile_priority); |
| 216 } | 227 } |
| 217 | 228 |
| 218 if (inside_receive_) { | 229 if (inside_receive_) { |
| 219 // Did not swap. | 230 // Did not swap. |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 295 software_draw_shm_->zeroed = true; | 306 software_draw_shm_->zeroed = true; |
| 296 } | 307 } |
| 297 | 308 |
| 298 void SynchronousCompositorProxy::DemandDrawSw( | 309 void SynchronousCompositorProxy::DemandDrawSw( |
| 299 const SyncCompositorCommonBrowserParams& common_params, | 310 const SyncCompositorCommonBrowserParams& common_params, |
| 300 const SyncCompositorDemandDrawSwParams& params, | 311 const SyncCompositorDemandDrawSwParams& params, |
| 301 IPC::Message* reply_message) { | 312 IPC::Message* reply_message) { |
| 302 DCHECK(!inside_receive_); | 313 DCHECK(!inside_receive_); |
| 303 inside_receive_ = true; | 314 inside_receive_ = true; |
| 304 ProcessCommonParams(common_params); | 315 ProcessCommonParams(common_params); |
| 305 { | 316 if (output_surface_) { |
| 306 base::AutoReset<IPC::Message*> scoped_software_draw_reply( | 317 base::AutoReset<IPC::Message*> scoped_software_draw_reply( |
| 307 &software_draw_reply_, reply_message); | 318 &software_draw_reply_, reply_message); |
| 308 if (use_in_process_zero_copy_software_draw_) { | 319 if (use_in_process_zero_copy_software_draw_) { |
| 309 DCHECK(g_sk_canvas_for_draw); | 320 DCHECK(g_sk_canvas_for_draw); |
| 310 output_surface_->DemandDrawSw(g_sk_canvas_for_draw); | 321 output_surface_->DemandDrawSw(g_sk_canvas_for_draw); |
| 311 } else { | 322 } else { |
| 312 DCHECK(!g_sk_canvas_for_draw); | 323 DCHECK(!g_sk_canvas_for_draw); |
| 313 DoDemandDrawSw(params); | 324 DoDemandDrawSw(params); |
| 314 } | 325 } |
| 315 } | 326 } |
| 316 if (inside_receive_) { | 327 if (inside_receive_) { |
| 317 // Did not swap. | 328 // Did not swap. |
| 318 cc::CompositorFrame empty_frame; | 329 cc::CompositorFrame empty_frame; |
| 319 SendDemandDrawSwReply(false, &empty_frame, reply_message); | 330 SendDemandDrawSwReply(false, &empty_frame, reply_message); |
| 320 inside_receive_ = false; | 331 inside_receive_ = false; |
| 321 } else { | 332 } else { |
| 322 DeliverMessages(); | 333 DeliverMessages(); |
| 323 } | 334 } |
| 324 } | 335 } |
| 325 | 336 |
| 326 void SynchronousCompositorProxy::DoDemandDrawSw( | 337 void SynchronousCompositorProxy::DoDemandDrawSw( |
| 327 const SyncCompositorDemandDrawSwParams& params) { | 338 const SyncCompositorDemandDrawSwParams& params) { |
| 339 DCHECK(output_surface_); | |
| 328 DCHECK(software_draw_shm_->zeroed); | 340 DCHECK(software_draw_shm_->zeroed); |
| 329 software_draw_shm_->zeroed = false; | 341 software_draw_shm_->zeroed = false; |
| 330 | 342 |
| 331 SkImageInfo info = | 343 SkImageInfo info = |
| 332 SkImageInfo::MakeN32Premul(params.size.width(), params.size.height()); | 344 SkImageInfo::MakeN32Premul(params.size.width(), params.size.height()); |
| 333 size_t stride = info.minRowBytes(); | 345 size_t stride = info.minRowBytes(); |
| 334 size_t buffer_size = info.getSafeSize(stride); | 346 size_t buffer_size = info.getSafeSize(stride); |
| 335 DCHECK_EQ(software_draw_shm_->buffer_size, buffer_size); | 347 DCHECK_EQ(software_draw_shm_->buffer_size, buffer_size); |
| 336 | 348 |
| 337 SkBitmap bitmap; | 349 SkBitmap bitmap; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 389 SyncCompositorCommonRendererParams params; | 401 SyncCompositorCommonRendererParams params; |
| 390 PopulateCommonParams(¶ms); | 402 PopulateCommonParams(¶ms); |
| 391 Send(new SyncCompositorHostMsg_OverScroll(routing_id_, params, | 403 Send(new SyncCompositorHostMsg_OverScroll(routing_id_, params, |
| 392 did_overscroll_params)); | 404 did_overscroll_params)); |
| 393 } | 405 } |
| 394 | 406 |
| 395 void SynchronousCompositorProxy::ProcessCommonParams( | 407 void SynchronousCompositorProxy::ProcessCommonParams( |
| 396 const SyncCompositorCommonBrowserParams& common_params) { | 408 const SyncCompositorCommonBrowserParams& common_params) { |
| 397 if (bytes_limit_ != common_params.bytes_limit) { | 409 if (bytes_limit_ != common_params.bytes_limit) { |
| 398 bytes_limit_ = common_params.bytes_limit; | 410 bytes_limit_ = common_params.bytes_limit; |
| 399 output_surface_->SetMemoryPolicy(bytes_limit_); | 411 if (output_surface_) |
| 412 output_surface_->SetMemoryPolicy(bytes_limit_); | |
| 400 } | 413 } |
| 401 if (common_params.update_root_scroll_offset && | 414 if (common_params.update_root_scroll_offset && |
| 402 total_scroll_offset_ != common_params.root_scroll_offset) { | 415 total_scroll_offset_ != common_params.root_scroll_offset) { |
| 403 total_scroll_offset_ = common_params.root_scroll_offset; | 416 total_scroll_offset_ = common_params.root_scroll_offset; |
| 404 input_handler_proxy_->SynchronouslySetRootScrollOffset( | 417 input_handler_proxy_->SynchronouslySetRootScrollOffset( |
| 405 total_scroll_offset_); | 418 total_scroll_offset_); |
| 406 } | 419 } |
| 407 begin_frame_source_->SetBeginFrameSourcePaused( | 420 begin_frame_source_->SetBeginFrameSourcePaused( |
| 408 common_params.begin_frame_source_paused); | 421 common_params.begin_frame_source_paused); |
| 409 if (!common_params.ack.resources.empty()) { | 422 if (output_surface_ && !common_params.ack.resources.empty()) { |
| 410 output_surface_->ReturnResources( | 423 output_surface_->ReturnResources( |
| 411 common_params.output_surface_id_for_returned_resources, | 424 common_params.output_surface_id_for_returned_resources, |
| 412 common_params.ack); | 425 common_params.ack); |
| 413 } | 426 } |
| 414 } | 427 } |
| 415 | 428 |
| 416 } // namespace content | 429 } // namespace content |
| OLD | NEW |