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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 return FromID(GetInProcessRendererId(), routing_id); | 67 return FromID(GetInProcessRendererId(), routing_id); |
| 68 } | 68 } |
| 69 | 69 |
| 70 SynchronousCompositorImpl::SynchronousCompositorImpl(WebContents* contents) | 70 SynchronousCompositorImpl::SynchronousCompositorImpl(WebContents* contents) |
| 71 : compositor_client_(NULL), | 71 : compositor_client_(NULL), |
| 72 output_surface_(NULL), | 72 output_surface_(NULL), |
| 73 begin_frame_source_(nullptr), | 73 begin_frame_source_(nullptr), |
| 74 contents_(contents), | 74 contents_(contents), |
| 75 routing_id_(contents->GetRoutingID()), | 75 routing_id_(contents->GetRoutingID()), |
| 76 input_handler_(NULL), | 76 input_handler_(NULL), |
| 77 registered_with_client_(false), | |
| 77 is_active_(false), | 78 is_active_(false), |
| 78 renderer_needs_begin_frames_(false), | 79 renderer_needs_begin_frames_(false), |
| 79 weak_ptr_factory_(this) { | 80 weak_ptr_factory_(this) { |
| 80 DCHECK(contents); | 81 DCHECK(contents); |
| 81 DCHECK_NE(routing_id_, MSG_ROUTING_NONE); | 82 DCHECK_NE(routing_id_, MSG_ROUTING_NONE); |
| 82 } | 83 } |
| 83 | 84 |
| 84 SynchronousCompositorImpl::~SynchronousCompositorImpl() { | 85 SynchronousCompositorImpl::~SynchronousCompositorImpl() { |
| 85 DCHECK(!output_surface_); | 86 DCHECK(!output_surface_); |
| 86 DCHECK(!begin_frame_source_); | 87 DCHECK(!begin_frame_source_); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 101 compositor_client_ = compositor_client; | 102 compositor_client_ = compositor_client; |
| 102 | 103 |
| 103 // SetClient is essentially the constructor and destructor of | 104 // SetClient is essentially the constructor and destructor of |
| 104 // SynchronousCompositorImpl. | 105 // SynchronousCompositorImpl. |
| 105 if (compositor_client_) { | 106 if (compositor_client_) { |
| 106 SynchronousCompositorRegistry::GetInstance()->RegisterCompositor( | 107 SynchronousCompositorRegistry::GetInstance()->RegisterCompositor( |
| 107 routing_id_, this); | 108 routing_id_, this); |
| 108 } | 109 } |
| 109 } | 110 } |
| 110 | 111 |
| 112 void SynchronousCompositorImpl::RegisterWithClient() { | |
| 113 DCHECK(CalledOnValidThread()); | |
| 114 | |
| 115 if (registered_with_client_) | |
| 116 return; | |
| 117 | |
| 118 SetIsActive(false); | |
| 119 compositor_client_->DidInitializeCompositor(this); | |
| 120 registered_with_client_ = true; | |
| 121 } | |
| 122 | |
| 111 // static | 123 // static |
| 112 void SynchronousCompositor::SetGpuService( | 124 void SynchronousCompositor::SetGpuService( |
| 113 scoped_refptr<gpu::InProcessCommandBuffer::Service> service) { | 125 scoped_refptr<gpu::InProcessCommandBuffer::Service> service) { |
| 114 g_factory.Get().SetDeferredGpuService(service); | 126 g_factory.Get().SetDeferredGpuService(service); |
| 115 } | 127 } |
| 116 | 128 |
| 117 // static | 129 // static |
| 118 void SynchronousCompositor::SetRecordFullDocument(bool record_full_document) { | 130 void SynchronousCompositor::SetRecordFullDocument(bool record_full_document) { |
| 119 g_factory.Get().SetRecordFullDocument(record_full_document); | 131 g_factory.Get().SetRecordFullDocument(record_full_document); |
| 120 } | 132 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 133 output_surface_ = output_surface; | 145 output_surface_ = output_surface; |
| 134 begin_frame_source_ = begin_frame_source; | 146 begin_frame_source_ = begin_frame_source; |
| 135 | 147 |
| 136 begin_frame_source_->SetCompositor(this); | 148 begin_frame_source_->SetCompositor(this); |
| 137 output_surface_->SetCompositor(this); | 149 output_surface_->SetCompositor(this); |
| 138 | 150 |
| 139 output_surface_->SetTreeActivationCallback( | 151 output_surface_->SetTreeActivationCallback( |
| 140 base::Bind(&SynchronousCompositorImpl::DidActivatePendingTree, | 152 base::Bind(&SynchronousCompositorImpl::DidActivatePendingTree, |
| 141 weak_ptr_factory_.GetWeakPtr())); | 153 weak_ptr_factory_.GetWeakPtr())); |
| 142 | 154 |
| 155 SetInputHandler(input_handler); | |
| 156 | |
| 143 OnNeedsBeginFramesChange(begin_frame_source_->NeedsBeginFrames()); | 157 OnNeedsBeginFramesChange(begin_frame_source_->NeedsBeginFrames()); |
| 144 | 158 SetIsActive(true); |
| 145 compositor_client_->DidInitializeCompositor(this); | |
| 146 | |
| 147 SetInputHandler(input_handler); | |
| 148 } | 159 } |
| 149 | 160 |
| 150 void SynchronousCompositorImpl::DidDestroyRendererObjects() { | 161 void SynchronousCompositorImpl::DidDestroyRendererObjects() { |
| 151 DCHECK(output_surface_); | 162 DCHECK(output_surface_); |
| 152 DCHECK(begin_frame_source_); | 163 DCHECK(begin_frame_source_); |
| 153 DCHECK(compositor_client_); | 164 DCHECK(compositor_client_); |
| 154 | 165 |
| 166 if (registered_with_client_) { | |
| 167 compositor_client_->DidDestroyCompositor(this); | |
| 168 registered_with_client_ = false; | |
| 169 } | |
| 170 | |
| 171 SetIsActive(false); | |
| 172 OnNeedsBeginFramesChange(false); | |
| 173 | |
| 174 SetInputHandler(nullptr); | |
| 155 begin_frame_source_->SetCompositor(nullptr); | 175 begin_frame_source_->SetCompositor(nullptr); |
| 156 output_surface_->SetCompositor(nullptr); | 176 output_surface_->SetCompositor(nullptr); |
| 157 SetInputHandler(nullptr); | |
| 158 compositor_client_->DidDestroyCompositor(this); | |
| 159 output_surface_ = nullptr; | 177 output_surface_ = nullptr; |
| 160 begin_frame_source_ = nullptr; | 178 begin_frame_source_ = nullptr; |
| 161 } | 179 } |
| 162 | 180 |
| 163 scoped_ptr<cc::CompositorFrame> SynchronousCompositorImpl::DemandDrawHw( | 181 scoped_ptr<cc::CompositorFrame> SynchronousCompositorImpl::DemandDrawHw( |
| 164 gfx::Size surface_size, | 182 gfx::Size surface_size, |
| 165 const gfx::Transform& transform, | 183 const gfx::Transform& transform, |
| 166 gfx::Rect viewport, | 184 gfx::Rect viewport, |
| 167 gfx::Rect clip, | 185 gfx::Rect clip, |
| 168 gfx::Rect viewport_rect_for_tile_priority, | 186 gfx::Rect viewport_rect_for_tile_priority, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 if (bytes_limit && !current_bytes_limit) { | 244 if (bytes_limit && !current_bytes_limit) { |
| 227 g_factory.Get().CompositorInitializedHardwareDraw(); | 245 g_factory.Get().CompositorInitializedHardwareDraw(); |
| 228 } else if (!bytes_limit && current_bytes_limit) { | 246 } else if (!bytes_limit && current_bytes_limit) { |
| 229 g_factory.Get().CompositorReleasedHardwareDraw(); | 247 g_factory.Get().CompositorReleasedHardwareDraw(); |
| 230 } | 248 } |
| 231 } | 249 } |
| 232 | 250 |
| 233 void SynchronousCompositorImpl::PostInvalidate() { | 251 void SynchronousCompositorImpl::PostInvalidate() { |
| 234 DCHECK(CalledOnValidThread()); | 252 DCHECK(CalledOnValidThread()); |
| 235 DCHECK(compositor_client_); | 253 DCHECK(compositor_client_); |
| 236 compositor_client_->PostInvalidate(); | 254 if (registered_with_client_) |
| 255 compositor_client_->PostInvalidate(); | |
| 237 } | 256 } |
| 238 | 257 |
| 239 void SynchronousCompositorImpl::DidChangeRootLayerScrollOffset() { | 258 void SynchronousCompositorImpl::DidChangeRootLayerScrollOffset() { |
| 240 if (input_handler_) | 259 if (input_handler_) |
| 241 input_handler_->OnRootLayerDelegatedScrollOffsetChanged(); | 260 input_handler_->OnRootLayerDelegatedScrollOffsetChanged(); |
| 242 } | 261 } |
| 243 | 262 |
| 244 void SynchronousCompositorImpl::SetIsActive(bool is_active) { | 263 void SynchronousCompositorImpl::SetIsActive(bool is_active) { |
| 245 TRACE_EVENT1("cc", "SynchronousCompositorImpl::SetIsActive", "is_active", | 264 TRACE_EVENT1("cc", "SynchronousCompositorImpl::SetIsActive", "is_active", |
| 246 is_active); | 265 is_active); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 275 | 294 |
| 276 input_handler_ = input_handler; | 295 input_handler_ = input_handler; |
| 277 | 296 |
| 278 if (input_handler_) | 297 if (input_handler_) |
| 279 input_handler_->SetRootLayerScrollOffsetDelegate(this); | 298 input_handler_->SetRootLayerScrollOffsetDelegate(this); |
| 280 } | 299 } |
| 281 | 300 |
| 282 void SynchronousCompositorImpl::DidOverscroll( | 301 void SynchronousCompositorImpl::DidOverscroll( |
| 283 const DidOverscrollParams& params) { | 302 const DidOverscrollParams& params) { |
| 284 DCHECK(compositor_client_); | 303 DCHECK(compositor_client_); |
| 285 compositor_client_->DidOverscroll(params.accumulated_overscroll, | 304 if (registered_with_client_) |
| 286 params.latest_overscroll_delta, | 305 compositor_client_->DidOverscroll(params.accumulated_overscroll, |
| 287 params.current_fling_velocity); | 306 params.latest_overscroll_delta, |
| 307 params.current_fling_velocity); | |
| 288 } | 308 } |
| 289 | 309 |
| 290 void SynchronousCompositorImpl::DidStopFlinging() { | 310 void SynchronousCompositorImpl::DidStopFlinging() { |
| 291 // It's important that the fling-end notification follow the same path as it | 311 // It's important that the fling-end notification follow the same path as it |
| 292 // takes on other platforms (using an IPC). This ensures consistent | 312 // takes on other platforms (using an IPC). This ensures consistent |
| 293 // bookkeeping at all stages of the input pipeline. | 313 // bookkeeping at all stages of the input pipeline. |
| 294 contents_->GetRenderProcessHost()->OnMessageReceived( | 314 contents_->GetRenderProcessHost()->OnMessageReceived( |
| 295 InputHostMsg_DidStopFlinging(routing_id_)); | 315 InputHostMsg_DidStopFlinging(routing_id_)); |
| 296 } | 316 } |
| 297 | 317 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 308 RenderProcessHost* rph = contents_->GetRenderProcessHost(); | 328 RenderProcessHost* rph = contents_->GetRenderProcessHost(); |
| 309 for (ScopedVector<IPC::Message>::const_iterator i = messages.begin(); | 329 for (ScopedVector<IPC::Message>::const_iterator i = messages.begin(); |
| 310 i != messages.end(); | 330 i != messages.end(); |
| 311 ++i) { | 331 ++i) { |
| 312 rph->OnMessageReceived(**i); | 332 rph->OnMessageReceived(**i); |
| 313 } | 333 } |
| 314 } | 334 } |
| 315 | 335 |
| 316 void SynchronousCompositorImpl::DidActivatePendingTree() { | 336 void SynchronousCompositorImpl::DidActivatePendingTree() { |
| 317 DCHECK(compositor_client_); | 337 DCHECK(compositor_client_); |
| 338 if (!registered_with_client_) | |
| 339 RegisterWithClient(); | |
| 340 DCHECK(registered_with_client_); | |
| 318 compositor_client_->DidUpdateContent(); | 341 compositor_client_->DidUpdateContent(); |
| 319 DeliverMessages(); | 342 DeliverMessages(); |
| 320 } | 343 } |
| 321 | 344 |
| 322 gfx::ScrollOffset SynchronousCompositorImpl::GetTotalScrollOffset() { | 345 gfx::ScrollOffset SynchronousCompositorImpl::GetTotalScrollOffset() { |
| 323 DCHECK(CalledOnValidThread()); | 346 DCHECK(CalledOnValidThread()); |
| 324 DCHECK(compositor_client_); | 347 DCHECK(compositor_client_); |
| 348 if (!registered_with_client_) | |
| 349 return gfx::ScrollOffset(); | |
| 325 // TODO(miletus): Make GetTotalRootLayerScrollOffset return | 350 // TODO(miletus): Make GetTotalRootLayerScrollOffset return |
| 326 // ScrollOffset. crbug.com/414283. | 351 // ScrollOffset. crbug.com/414283. |
| 327 return gfx::ScrollOffset( | 352 return gfx::ScrollOffset( |
| 328 compositor_client_->GetTotalRootLayerScrollOffset()); | 353 compositor_client_->GetTotalRootLayerScrollOffset()); |
| 329 } | 354 } |
| 330 | 355 |
| 331 bool SynchronousCompositorImpl::IsExternalFlingActive() const { | 356 bool SynchronousCompositorImpl::IsExternalFlingActive() const { |
| 332 DCHECK(CalledOnValidThread()); | 357 DCHECK(CalledOnValidThread()); |
| 333 DCHECK(compositor_client_); | 358 DCHECK(compositor_client_); |
| 359 if (!registered_with_client_) | |
| 360 return false; | |
| 334 return compositor_client_->IsExternalFlingActive(); | 361 return compositor_client_->IsExternalFlingActive(); |
| 335 } | 362 } |
| 336 | 363 |
| 337 void SynchronousCompositorImpl::UpdateRootLayerState( | 364 void SynchronousCompositorImpl::UpdateRootLayerState( |
| 338 const gfx::ScrollOffset& total_scroll_offset, | 365 const gfx::ScrollOffset& total_scroll_offset, |
| 339 const gfx::ScrollOffset& max_scroll_offset, | 366 const gfx::ScrollOffset& max_scroll_offset, |
| 340 const gfx::SizeF& scrollable_size, | 367 const gfx::SizeF& scrollable_size, |
| 341 float page_scale_factor, | 368 float page_scale_factor, |
| 342 float min_page_scale_factor, | 369 float min_page_scale_factor, |
| 343 float max_page_scale_factor) { | 370 float max_page_scale_factor) { |
| 344 DCHECK(CalledOnValidThread()); | 371 DCHECK(CalledOnValidThread()); |
| 345 DCHECK(compositor_client_); | 372 DCHECK(compositor_client_); |
| 346 | 373 |
| 347 // TODO(miletus): Pass in ScrollOffset. crbug.com/414283. | 374 if (registered_with_client_) |
|
boliu
2015/05/30 01:06:29
style: Need braces for if statements with multi-li
| |
| 348 compositor_client_->UpdateRootLayerState( | 375 // TODO(miletus): Pass in ScrollOffset. crbug.com/414283. |
| 349 gfx::ScrollOffsetToVector2dF(total_scroll_offset), | 376 compositor_client_->UpdateRootLayerState( |
| 350 gfx::ScrollOffsetToVector2dF(max_scroll_offset), | 377 gfx::ScrollOffsetToVector2dF(total_scroll_offset), |
| 351 scrollable_size, | 378 gfx::ScrollOffsetToVector2dF(max_scroll_offset), |
| 352 page_scale_factor, | 379 scrollable_size, |
| 353 min_page_scale_factor, | 380 page_scale_factor, |
| 354 max_page_scale_factor); | 381 min_page_scale_factor, |
| 382 max_page_scale_factor); | |
| 355 } | 383 } |
| 356 | 384 |
| 357 // Not using base::NonThreadSafe as we want to enforce a more exacting threading | 385 // Not using base::NonThreadSafe as we want to enforce a more exacting threading |
| 358 // requirement: SynchronousCompositorImpl() must only be used on the UI thread. | 386 // requirement: SynchronousCompositorImpl() must only be used on the UI thread. |
| 359 bool SynchronousCompositorImpl::CalledOnValidThread() const { | 387 bool SynchronousCompositorImpl::CalledOnValidThread() const { |
| 360 return BrowserThread::CurrentlyOn(BrowserThread::UI); | 388 return BrowserThread::CurrentlyOn(BrowserThread::UI); |
| 361 } | 389 } |
| 362 | 390 |
| 363 // static | 391 // static |
| 364 void SynchronousCompositor::SetClientForWebContents( | 392 void SynchronousCompositor::SetClientForWebContents( |
| 365 WebContents* contents, | 393 WebContents* contents, |
| 366 SynchronousCompositorClient* client) { | 394 SynchronousCompositorClient* client) { |
| 367 DCHECK(contents); | 395 DCHECK(contents); |
| 368 if (client) { | 396 if (client) { |
| 369 g_factory.Get(); // Ensure it's initialized. | 397 g_factory.Get(); // Ensure it's initialized. |
| 370 SynchronousCompositorImpl::CreateForWebContents(contents); | 398 SynchronousCompositorImpl::CreateForWebContents(contents); |
| 371 } | 399 } |
| 372 SynchronousCompositorImpl* instance = | 400 SynchronousCompositorImpl* instance = |
| 373 SynchronousCompositorImpl::FromWebContents(contents); | 401 SynchronousCompositorImpl::FromWebContents(contents); |
| 374 DCHECK(instance); | 402 DCHECK(instance); |
| 375 instance->SetClient(client); | 403 instance->SetClient(client); |
| 376 } | 404 } |
| 377 | 405 |
| 378 } // namespace content | 406 } // namespace content |
| OLD | NEW |