Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/in_process/synchronous_compositor_impl.h" | 5 #include "content/browser/android/in_process/synchronous_compositor_impl.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 output_surface_(NULL), | 71 output_surface_(NULL), |
| 72 begin_frame_source_(nullptr), | 72 begin_frame_source_(nullptr), |
| 73 contents_(contents), | 73 contents_(contents), |
| 74 routing_id_(contents->GetRoutingID()), | 74 routing_id_(contents->GetRoutingID()), |
| 75 input_handler_(NULL), | 75 input_handler_(NULL), |
| 76 is_active_(false), | 76 is_active_(false), |
| 77 renderer_needs_begin_frames_(false), | 77 renderer_needs_begin_frames_(false), |
| 78 weak_ptr_factory_(this) { | 78 weak_ptr_factory_(this) { |
| 79 DCHECK(contents); | 79 DCHECK(contents); |
| 80 DCHECK_NE(routing_id_, MSG_ROUTING_NONE); | 80 DCHECK_NE(routing_id_, MSG_ROUTING_NONE); |
| 81 SynchronousCompositorRegistry::GetInstance()->RegisterCompositor(routing_id_, | |
| 82 this); | |
| 83 } | 81 } |
| 84 | 82 |
| 85 SynchronousCompositorImpl::~SynchronousCompositorImpl() { | 83 SynchronousCompositorImpl::~SynchronousCompositorImpl() { |
| 86 SynchronousCompositorRegistry::GetInstance()->UnregisterCompositor( | |
| 87 routing_id_, this); | |
| 88 | |
| 89 DCHECK(!output_surface_); | 84 DCHECK(!output_surface_); |
| 90 DCHECK(!begin_frame_source_); | 85 DCHECK(!begin_frame_source_); |
| 91 DCHECK(!input_handler_); | 86 DCHECK(!input_handler_); |
| 92 } | 87 } |
| 93 | 88 |
| 94 void SynchronousCompositorImpl::SetClient( | 89 void SynchronousCompositorImpl::SetClient( |
| 95 SynchronousCompositorClient* compositor_client) { | 90 SynchronousCompositorClient* compositor_client) { |
| 96 DCHECK(CalledOnValidThread()); | 91 DCHECK(CalledOnValidThread()); |
| 92 DCHECK_IMPLIES(compositor_client, !compositor_client_); | |
| 93 DCHECK_IMPLIES(!compositor_client, compositor_client_); | |
|
hush (inactive)
2015/05/06 21:57:49
I'm wondering if the above 2 lines means:
DCHECK_E
boliu
2015/05/06 22:02:49
Umm...yes, yes it does. DCHECK_IMPLIES is clearer
| |
| 94 | |
| 95 if (!compositor_client) { | |
| 96 SynchronousCompositorRegistry::GetInstance()->UnregisterCompositor( | |
| 97 routing_id_, this); | |
| 98 } | |
| 99 | |
| 97 compositor_client_ = compositor_client; | 100 compositor_client_ = compositor_client; |
| 101 | |
| 102 // SetClient is essentially the constructor and destructor of | |
| 103 // SynchronousCompositorImpl. | |
| 104 if (compositor_client_) { | |
| 105 SynchronousCompositorRegistry::GetInstance()->RegisterCompositor( | |
| 106 routing_id_, this); | |
| 107 } | |
| 98 } | 108 } |
| 99 | 109 |
| 100 // static | 110 // static |
| 101 void SynchronousCompositor::SetGpuService( | 111 void SynchronousCompositor::SetGpuService( |
| 102 scoped_refptr<gpu::InProcessCommandBuffer::Service> service) { | 112 scoped_refptr<gpu::InProcessCommandBuffer::Service> service) { |
| 103 g_factory.Get().SetDeferredGpuService(service); | 113 g_factory.Get().SetDeferredGpuService(service); |
| 104 } | 114 } |
| 105 | 115 |
| 106 // static | 116 // static |
| 107 void SynchronousCompositor::SetRecordFullDocument(bool record_full_document) { | 117 void SynchronousCompositor::SetRecordFullDocument(bool record_full_document) { |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 132 OnNeedsBeginFramesChange(begin_frame_source_->NeedsBeginFrames()); | 142 OnNeedsBeginFramesChange(begin_frame_source_->NeedsBeginFrames()); |
| 133 | 143 |
| 134 compositor_client_->DidInitializeCompositor(this); | 144 compositor_client_->DidInitializeCompositor(this); |
| 135 | 145 |
| 136 SetInputHandler(input_handler); | 146 SetInputHandler(input_handler); |
| 137 } | 147 } |
| 138 | 148 |
| 139 void SynchronousCompositorImpl::DidDestroyRendererObjects() { | 149 void SynchronousCompositorImpl::DidDestroyRendererObjects() { |
| 140 DCHECK(output_surface_); | 150 DCHECK(output_surface_); |
| 141 DCHECK(begin_frame_source_); | 151 DCHECK(begin_frame_source_); |
| 152 DCHECK(compositor_client_); | |
| 142 | 153 |
| 143 begin_frame_source_->SetCompositor(nullptr); | 154 begin_frame_source_->SetCompositor(nullptr); |
| 144 output_surface_->SetCompositor(nullptr); | 155 output_surface_->SetCompositor(nullptr); |
| 145 if (compositor_client_) | 156 SetInputHandler(nullptr); |
|
hush (inactive)
2015/05/06 21:57:49
why pulling this line up here? I guess no big deal
boliu
2015/05/06 22:02:49
It also does SetRootLayerScrollOffsetDelegate(NULL
| |
| 146 compositor_client_->DidDestroyCompositor(this); | 157 compositor_client_->DidDestroyCompositor(this); |
| 147 compositor_client_ = nullptr; | |
| 148 output_surface_ = nullptr; | 158 output_surface_ = nullptr; |
| 149 begin_frame_source_ = nullptr; | 159 begin_frame_source_ = nullptr; |
| 150 SetInputHandler(nullptr); | |
| 151 } | |
| 152 | |
| 153 void SynchronousCompositorImpl::NotifyDidDestroyCompositorToClient() { | |
|
hush (inactive)
2015/05/06 21:57:49
there was no code calling this function before you
boliu
2015/05/06 22:02:49
Right. Should have removed this when I added the r
| |
| 154 if (compositor_client_) | |
| 155 compositor_client_->DidDestroyCompositor(this); | |
| 156 compositor_client_ = nullptr; | |
| 157 } | 160 } |
| 158 | 161 |
| 159 scoped_ptr<cc::CompositorFrame> SynchronousCompositorImpl::DemandDrawHw( | 162 scoped_ptr<cc::CompositorFrame> SynchronousCompositorImpl::DemandDrawHw( |
| 160 gfx::Size surface_size, | 163 gfx::Size surface_size, |
| 161 const gfx::Transform& transform, | 164 const gfx::Transform& transform, |
| 162 gfx::Rect viewport, | 165 gfx::Rect viewport, |
| 163 gfx::Rect clip, | 166 gfx::Rect clip, |
| 164 gfx::Rect viewport_rect_for_tile_priority, | 167 gfx::Rect viewport_rect_for_tile_priority, |
| 165 const gfx::Transform& transform_for_tile_priority) { | 168 const gfx::Transform& transform_for_tile_priority) { |
| 166 DCHECK(CalledOnValidThread()); | 169 DCHECK(CalledOnValidThread()); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 270 input_handler_->SetRootLayerScrollOffsetDelegate(NULL); | 273 input_handler_->SetRootLayerScrollOffsetDelegate(NULL); |
| 271 | 274 |
| 272 input_handler_ = input_handler; | 275 input_handler_ = input_handler; |
| 273 | 276 |
| 274 if (input_handler_) | 277 if (input_handler_) |
| 275 input_handler_->SetRootLayerScrollOffsetDelegate(this); | 278 input_handler_->SetRootLayerScrollOffsetDelegate(this); |
| 276 } | 279 } |
| 277 | 280 |
| 278 void SynchronousCompositorImpl::DidOverscroll( | 281 void SynchronousCompositorImpl::DidOverscroll( |
| 279 const DidOverscrollParams& params) { | 282 const DidOverscrollParams& params) { |
| 280 if (compositor_client_) { | 283 DCHECK(compositor_client_); |
| 281 compositor_client_->DidOverscroll(params.accumulated_overscroll, | 284 compositor_client_->DidOverscroll(params.accumulated_overscroll, |
| 282 params.latest_overscroll_delta, | 285 params.latest_overscroll_delta, |
| 283 params.current_fling_velocity); | 286 params.current_fling_velocity); |
| 284 } | |
| 285 } | 287 } |
| 286 | 288 |
| 287 void SynchronousCompositorImpl::DidStopFlinging() { | 289 void SynchronousCompositorImpl::DidStopFlinging() { |
| 288 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( | 290 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( |
| 289 contents_->GetRenderWidgetHostView()); | 291 contents_->GetRenderWidgetHostView()); |
| 290 if (rwhv) | 292 if (rwhv) |
| 291 rwhv->DidStopFlinging(); | 293 rwhv->DidStopFlinging(); |
| 292 } | 294 } |
| 293 | 295 |
| 294 InputEventAckState SynchronousCompositorImpl::HandleInputEvent( | 296 InputEventAckState SynchronousCompositorImpl::HandleInputEvent( |
| 295 const blink::WebInputEvent& input_event) { | 297 const blink::WebInputEvent& input_event) { |
| 296 DCHECK(CalledOnValidThread()); | 298 DCHECK(CalledOnValidThread()); |
| 297 return g_factory.Get().synchronous_input_event_filter()->HandleInputEvent( | 299 return g_factory.Get().synchronous_input_event_filter()->HandleInputEvent( |
| 298 contents_->GetRoutingID(), input_event); | 300 contents_->GetRoutingID(), input_event); |
| 299 } | 301 } |
| 300 | 302 |
| 301 void SynchronousCompositorImpl::DeliverMessages() { | 303 void SynchronousCompositorImpl::DeliverMessages() { |
| 302 ScopedVector<IPC::Message> messages; | 304 ScopedVector<IPC::Message> messages; |
| 303 output_surface_->GetMessagesToDeliver(&messages); | 305 output_surface_->GetMessagesToDeliver(&messages); |
| 304 RenderProcessHost* rph = contents_->GetRenderProcessHost(); | 306 RenderProcessHost* rph = contents_->GetRenderProcessHost(); |
| 305 for (ScopedVector<IPC::Message>::const_iterator i = messages.begin(); | 307 for (ScopedVector<IPC::Message>::const_iterator i = messages.begin(); |
| 306 i != messages.end(); | 308 i != messages.end(); |
| 307 ++i) { | 309 ++i) { |
| 308 rph->OnMessageReceived(**i); | 310 rph->OnMessageReceived(**i); |
| 309 } | 311 } |
| 310 } | 312 } |
| 311 | 313 |
| 312 void SynchronousCompositorImpl::DidActivatePendingTree() { | 314 void SynchronousCompositorImpl::DidActivatePendingTree() { |
| 313 if (compositor_client_) | 315 DCHECK(compositor_client_); |
| 314 compositor_client_->DidUpdateContent(); | 316 compositor_client_->DidUpdateContent(); |
| 315 } | 317 } |
| 316 | 318 |
| 317 gfx::ScrollOffset SynchronousCompositorImpl::GetTotalScrollOffset() { | 319 gfx::ScrollOffset SynchronousCompositorImpl::GetTotalScrollOffset() { |
| 318 DCHECK(CalledOnValidThread()); | 320 DCHECK(CalledOnValidThread()); |
| 319 if (compositor_client_) { | 321 DCHECK(compositor_client_); |
| 320 // TODO(miletus): Make GetTotalRootLayerScrollOffset return | 322 // TODO(miletus): Make GetTotalRootLayerScrollOffset return |
| 321 // ScrollOffset. crbug.com/414283. | 323 // ScrollOffset. crbug.com/414283. |
| 322 return gfx::ScrollOffset( | 324 return gfx::ScrollOffset( |
| 323 compositor_client_->GetTotalRootLayerScrollOffset()); | 325 compositor_client_->GetTotalRootLayerScrollOffset()); |
| 324 } | |
| 325 return gfx::ScrollOffset(); | |
| 326 } | 326 } |
| 327 | 327 |
| 328 bool SynchronousCompositorImpl::IsExternalFlingActive() const { | 328 bool SynchronousCompositorImpl::IsExternalFlingActive() const { |
| 329 DCHECK(CalledOnValidThread()); | 329 DCHECK(CalledOnValidThread()); |
| 330 if (compositor_client_) | 330 DCHECK(compositor_client_); |
| 331 return compositor_client_->IsExternalFlingActive(); | 331 return compositor_client_->IsExternalFlingActive(); |
| 332 return false; | |
| 333 } | 332 } |
| 334 | 333 |
| 335 void SynchronousCompositorImpl::UpdateRootLayerState( | 334 void SynchronousCompositorImpl::UpdateRootLayerState( |
| 336 const gfx::ScrollOffset& total_scroll_offset, | 335 const gfx::ScrollOffset& total_scroll_offset, |
| 337 const gfx::ScrollOffset& max_scroll_offset, | 336 const gfx::ScrollOffset& max_scroll_offset, |
| 338 const gfx::SizeF& scrollable_size, | 337 const gfx::SizeF& scrollable_size, |
| 339 float page_scale_factor, | 338 float page_scale_factor, |
| 340 float min_page_scale_factor, | 339 float min_page_scale_factor, |
| 341 float max_page_scale_factor) { | 340 float max_page_scale_factor) { |
| 342 DCHECK(CalledOnValidThread()); | 341 DCHECK(CalledOnValidThread()); |
| 343 if (!compositor_client_) | 342 DCHECK(compositor_client_); |
| 344 return; | |
| 345 | 343 |
| 346 // TODO(miletus): Pass in ScrollOffset. crbug.com/414283. | 344 // TODO(miletus): Pass in ScrollOffset. crbug.com/414283. |
| 347 compositor_client_->UpdateRootLayerState( | 345 compositor_client_->UpdateRootLayerState( |
| 348 gfx::ScrollOffsetToVector2dF(total_scroll_offset), | 346 gfx::ScrollOffsetToVector2dF(total_scroll_offset), |
| 349 gfx::ScrollOffsetToVector2dF(max_scroll_offset), | 347 gfx::ScrollOffsetToVector2dF(max_scroll_offset), |
| 350 scrollable_size, | 348 scrollable_size, |
| 351 page_scale_factor, | 349 page_scale_factor, |
| 352 min_page_scale_factor, | 350 min_page_scale_factor, |
| 353 max_page_scale_factor); | 351 max_page_scale_factor); |
| 354 } | 352 } |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 368 g_factory.Get(); // Ensure it's initialized. | 366 g_factory.Get(); // Ensure it's initialized. |
| 369 SynchronousCompositorImpl::CreateForWebContents(contents); | 367 SynchronousCompositorImpl::CreateForWebContents(contents); |
| 370 } | 368 } |
| 371 SynchronousCompositorImpl* instance = | 369 SynchronousCompositorImpl* instance = |
| 372 SynchronousCompositorImpl::FromWebContents(contents); | 370 SynchronousCompositorImpl::FromWebContents(contents); |
| 373 DCHECK(instance); | 371 DCHECK(instance); |
| 374 instance->SetClient(client); | 372 instance->SetClient(client); |
| 375 } | 373 } |
| 376 | 374 |
| 377 } // namespace content | 375 } // namespace content |
| OLD | NEW |