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 } | 67 } |
| 68 | 68 |
| 69 SynchronousCompositorImpl::SynchronousCompositorImpl(WebContents* contents) | 69 SynchronousCompositorImpl::SynchronousCompositorImpl(WebContents* contents) |
| 70 : compositor_client_(NULL), | 70 : compositor_client_(NULL), |
| 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 invoking_composite_(false), | 76 invoking_composite_(false), |
| 77 is_active_(false), | |
| 78 renderer_needs_begin_frames_(false), | |
| 77 weak_ptr_factory_(this) { | 79 weak_ptr_factory_(this) { |
| 78 DCHECK(contents); | 80 DCHECK(contents); |
| 79 DCHECK_NE(routing_id_, MSG_ROUTING_NONE); | 81 DCHECK_NE(routing_id_, MSG_ROUTING_NONE); |
| 80 SynchronousCompositorRegistry::GetInstance()->RegisterCompositor(routing_id_, | 82 SynchronousCompositorRegistry::GetInstance()->RegisterCompositor(routing_id_, |
| 81 this); | 83 this); |
| 82 } | 84 } |
| 83 | 85 |
| 84 SynchronousCompositorImpl::~SynchronousCompositorImpl() { | 86 SynchronousCompositorImpl::~SynchronousCompositorImpl() { |
| 85 SynchronousCompositorRegistry::GetInstance()->UnregisterCompositor( | 87 SynchronousCompositorRegistry::GetInstance()->UnregisterCompositor( |
| 86 routing_id_, this); | 88 routing_id_, this); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 113 DCHECK(!output_surface_); | 115 DCHECK(!output_surface_); |
| 114 DCHECK(!begin_frame_source_); | 116 DCHECK(!begin_frame_source_); |
| 115 DCHECK(output_surface); | 117 DCHECK(output_surface); |
| 116 DCHECK(begin_frame_source); | 118 DCHECK(begin_frame_source); |
| 117 DCHECK(compositor_client_); | 119 DCHECK(compositor_client_); |
| 118 | 120 |
| 119 output_surface_ = output_surface; | 121 output_surface_ = output_surface; |
| 120 begin_frame_source_ = begin_frame_source; | 122 begin_frame_source_ = begin_frame_source; |
| 121 | 123 |
| 122 begin_frame_source_->SetCompositor(this); | 124 begin_frame_source_->SetCompositor(this); |
| 123 output_surface_->SetBeginFrameSource(begin_frame_source_); | 125 output_surface_->SetCompositor(this); |
| 126 | |
| 124 output_surface_->SetTreeActivationCallback( | 127 output_surface_->SetTreeActivationCallback( |
| 125 base::Bind(&SynchronousCompositorImpl::DidActivatePendingTree, | 128 base::Bind(&SynchronousCompositorImpl::DidActivatePendingTree, |
| 126 weak_ptr_factory_.GetWeakPtr())); | 129 weak_ptr_factory_.GetWeakPtr())); |
| 127 NeedsBeginFramesChanged(); | 130 |
| 131 OnNeedsBeginFramesChange(begin_frame_source_->NeedsBeginFrames()); | |
|
boliu
2015/02/11 02:28:14
Move this to BFS::SetCompositor
| |
| 132 | |
| 128 compositor_client_->DidInitializeCompositor(this); | 133 compositor_client_->DidInitializeCompositor(this); |
| 129 } | 134 } |
| 130 | 135 |
| 131 void SynchronousCompositorImpl::DidDestroyRendererObjects() { | 136 void SynchronousCompositorImpl::DidDestroyRendererObjects() { |
| 132 DCHECK(output_surface_); | 137 DCHECK(output_surface_); |
| 133 DCHECK(begin_frame_source_); | 138 DCHECK(begin_frame_source_); |
| 134 | 139 |
| 135 begin_frame_source_->SetCompositor(nullptr); | 140 begin_frame_source_->SetCompositor(nullptr); |
| 136 output_surface_->SetBeginFrameSource(nullptr); | 141 output_surface_->SetCompositor(nullptr); |
| 137 if (compositor_client_) | 142 if (compositor_client_) |
| 138 compositor_client_->DidDestroyCompositor(this); | 143 compositor_client_->DidDestroyCompositor(this); |
| 139 compositor_client_ = nullptr; | 144 compositor_client_ = nullptr; |
| 140 output_surface_ = nullptr; | 145 output_surface_ = nullptr; |
| 141 begin_frame_source_ = nullptr; | 146 begin_frame_source_ = nullptr; |
| 142 } | 147 } |
| 143 | 148 |
| 144 void SynchronousCompositorImpl::NotifyDidDestroyCompositorToClient() { | 149 void SynchronousCompositorImpl::NotifyDidDestroyCompositorToClient() { |
| 145 if (compositor_client_) | 150 if (compositor_client_) |
| 146 compositor_client_->DidDestroyCompositor(this); | 151 compositor_client_->DidDestroyCompositor(this); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 176 gfx::Rect viewport_rect_for_tile_priority, | 181 gfx::Rect viewport_rect_for_tile_priority, |
| 177 const gfx::Transform& transform_for_tile_priority) { | 182 const gfx::Transform& transform_for_tile_priority) { |
| 178 DCHECK(CalledOnValidThread()); | 183 DCHECK(CalledOnValidThread()); |
| 179 DCHECK(output_surface_); | 184 DCHECK(output_surface_); |
| 180 DCHECK(!invoking_composite_); | 185 DCHECK(!invoking_composite_); |
| 181 DCHECK(compositor_client_); | 186 DCHECK(compositor_client_); |
| 182 DCHECK(begin_frame_source_); | 187 DCHECK(begin_frame_source_); |
| 183 | 188 |
| 184 base::AutoReset<bool> invoking_composite_resetter(&invoking_composite_, | 189 base::AutoReset<bool> invoking_composite_resetter(&invoking_composite_, |
| 185 true); | 190 true); |
| 191 | |
| 186 scoped_ptr<cc::CompositorFrame> frame = | 192 scoped_ptr<cc::CompositorFrame> frame = |
| 187 output_surface_->DemandDrawHw(surface_size, | 193 output_surface_->DemandDrawHw(surface_size, |
| 188 transform, | 194 transform, |
| 189 viewport, | 195 viewport, |
| 190 clip, | 196 clip, |
| 191 viewport_rect_for_tile_priority, | 197 viewport_rect_for_tile_priority, |
| 192 transform_for_tile_priority); | 198 transform_for_tile_priority); |
| 199 | |
| 193 if (frame.get()) | 200 if (frame.get()) |
| 194 UpdateFrameMetaData(frame->metadata); | 201 UpdateFrameMetaData(frame->metadata); |
| 195 | 202 |
| 196 compositor_client_->SetContinuousInvalidate( | |
| 197 begin_frame_source_->NeedsBeginFrames()); | |
| 198 | |
| 199 return frame.Pass(); | 203 return frame.Pass(); |
| 200 } | 204 } |
| 201 | 205 |
| 202 void SynchronousCompositorImpl::ReturnResources( | 206 void SynchronousCompositorImpl::ReturnResources( |
| 203 const cc::CompositorFrameAck& frame_ack) { | 207 const cc::CompositorFrameAck& frame_ack) { |
| 204 DCHECK(CalledOnValidThread()); | 208 DCHECK(CalledOnValidThread()); |
| 205 output_surface_->ReturnResources(frame_ack); | 209 output_surface_->ReturnResources(frame_ack); |
| 206 } | 210 } |
| 207 | 211 |
| 208 bool SynchronousCompositorImpl::DemandDrawSw(SkCanvas* canvas) { | 212 bool SynchronousCompositorImpl::DemandDrawSw(SkCanvas* canvas) { |
| 209 DCHECK(CalledOnValidThread()); | 213 DCHECK(CalledOnValidThread()); |
| 210 DCHECK(output_surface_); | 214 DCHECK(output_surface_); |
| 211 DCHECK(!invoking_composite_); | 215 DCHECK(!invoking_composite_); |
| 212 DCHECK(compositor_client_); | 216 DCHECK(compositor_client_); |
| 213 DCHECK(begin_frame_source_); | 217 DCHECK(begin_frame_source_); |
| 214 | 218 |
| 215 base::AutoReset<bool> invoking_composite_resetter(&invoking_composite_, | 219 base::AutoReset<bool> invoking_composite_resetter(&invoking_composite_, |
| 216 true); | 220 true); |
| 221 | |
| 217 scoped_ptr<cc::CompositorFrame> frame = | 222 scoped_ptr<cc::CompositorFrame> frame = |
| 218 output_surface_->DemandDrawSw(canvas); | 223 output_surface_->DemandDrawSw(canvas); |
| 224 | |
| 219 if (frame.get()) | 225 if (frame.get()) |
| 220 UpdateFrameMetaData(frame->metadata); | 226 UpdateFrameMetaData(frame->metadata); |
| 221 | 227 |
| 222 compositor_client_->SetContinuousInvalidate( | |
| 223 begin_frame_source_->NeedsBeginFrames()); | |
| 224 | |
| 225 return !!frame.get(); | 228 return !!frame.get(); |
| 226 } | 229 } |
| 227 | 230 |
| 228 void SynchronousCompositorImpl::UpdateFrameMetaData( | 231 void SynchronousCompositorImpl::UpdateFrameMetaData( |
| 229 const cc::CompositorFrameMetadata& frame_metadata) { | 232 const cc::CompositorFrameMetadata& frame_metadata) { |
| 230 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( | 233 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( |
| 231 contents_->GetRenderWidgetHostView()); | 234 contents_->GetRenderWidgetHostView()); |
| 232 if (rwhv) | 235 if (rwhv) |
| 233 rwhv->SynchronousFrameMetadata(frame_metadata); | 236 rwhv->SynchronousFrameMetadata(frame_metadata); |
| 234 DeliverMessages(); | 237 DeliverMessages(); |
| 235 } | 238 } |
| 236 | 239 |
| 237 void SynchronousCompositorImpl::SetMemoryPolicy(size_t bytes_limit) { | 240 void SynchronousCompositorImpl::SetMemoryPolicy(size_t bytes_limit) { |
| 238 DCHECK(CalledOnValidThread()); | 241 DCHECK(CalledOnValidThread()); |
| 239 DCHECK(output_surface_); | 242 DCHECK(output_surface_); |
| 240 | 243 |
| 241 output_surface_->SetMemoryPolicy(bytes_limit); | 244 output_surface_->SetMemoryPolicy(bytes_limit); |
| 242 } | 245 } |
| 243 | 246 |
| 247 void SynchronousCompositorImpl::PostInvalidate() { | |
| 248 DCHECK(CalledOnValidThread()); | |
| 249 DCHECK(compositor_client_); | |
| 250 compositor_client_->PostInvalidate(); | |
| 251 } | |
| 252 | |
| 244 void SynchronousCompositorImpl::DidChangeRootLayerScrollOffset() { | 253 void SynchronousCompositorImpl::DidChangeRootLayerScrollOffset() { |
| 245 if (input_handler_) | 254 if (input_handler_) |
| 246 input_handler_->OnRootLayerDelegatedScrollOffsetChanged(); | 255 input_handler_->OnRootLayerDelegatedScrollOffsetChanged(); |
| 247 } | 256 } |
| 248 | 257 |
| 258 void SynchronousCompositorImpl::SetIsActive(bool is_active) { | |
| 259 is_active_ = is_active; | |
| 260 UpdateNeedsBeginFrames(); | |
| 261 } | |
| 262 | |
| 263 void SynchronousCompositorImpl::OnNeedsBeginFramesChange( | |
| 264 bool needs_begin_frames) { | |
| 265 renderer_needs_begin_frames_ = needs_begin_frames; | |
| 266 UpdateNeedsBeginFrames(); | |
| 267 } | |
| 268 | |
| 269 void SynchronousCompositorImpl::SendBeginFrame(cc::BeginFrameArgs args) { | |
| 270 DCHECK(begin_frame_source_); | |
| 271 begin_frame_source_->SendBeginFrameOnAnimate(args); | |
| 272 } | |
| 273 | |
| 274 void SynchronousCompositorImpl::SendBeginFrameOnDraw() { | |
| 275 DCHECK(begin_frame_source_); | |
| 276 begin_frame_source_->SendBeginFrameOnDraw(); | |
| 277 } | |
| 278 | |
| 279 void SynchronousCompositorImpl::UpdateNeedsBeginFrames() { | |
| 280 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( | |
|
boliu
2015/02/11 02:28:14
nts and general comment I guess: should check life
| |
| 281 contents_->GetRenderWidgetHostView()); | |
| 282 if (rwhv) | |
| 283 rwhv->OnSetNeedsBeginFrames(is_active_ && renderer_needs_begin_frames_); | |
| 284 } | |
| 285 | |
| 249 void SynchronousCompositorImpl::SetInputHandler( | 286 void SynchronousCompositorImpl::SetInputHandler( |
| 250 cc::InputHandler* input_handler) { | 287 cc::InputHandler* input_handler) { |
| 251 DCHECK(CalledOnValidThread()); | 288 DCHECK(CalledOnValidThread()); |
| 252 | 289 |
| 253 if (input_handler_) | 290 if (input_handler_) |
| 254 input_handler_->SetRootLayerScrollOffsetDelegate(NULL); | 291 input_handler_->SetRootLayerScrollOffsetDelegate(NULL); |
| 255 | 292 |
| 256 input_handler_ = input_handler; | 293 input_handler_ = input_handler; |
| 257 | 294 |
| 258 if (input_handler_) | 295 if (input_handler_) |
| 259 input_handler_->SetRootLayerScrollOffsetDelegate(this); | 296 input_handler_->SetRootLayerScrollOffsetDelegate(this); |
| 260 } | 297 } |
| 261 | 298 |
| 262 void SynchronousCompositorImpl::DidOverscroll( | 299 void SynchronousCompositorImpl::DidOverscroll( |
| 263 const DidOverscrollParams& params) { | 300 const DidOverscrollParams& params) { |
| 264 if (compositor_client_) { | 301 if (compositor_client_) { |
| 265 compositor_client_->DidOverscroll(params.accumulated_overscroll, | 302 compositor_client_->DidOverscroll(params.accumulated_overscroll, |
| 266 params.latest_overscroll_delta, | 303 params.latest_overscroll_delta, |
| 267 params.current_fling_velocity); | 304 params.current_fling_velocity); |
| 268 } | 305 } |
| 269 } | 306 } |
| 270 | 307 |
| 271 void SynchronousCompositorImpl::DidStopFlinging() { | 308 void SynchronousCompositorImpl::DidStopFlinging() { |
| 272 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( | 309 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( |
| 273 contents_->GetRenderWidgetHostView()); | 310 contents_->GetRenderWidgetHostView()); |
| 274 if (rwhv) | 311 if (rwhv) |
| 275 rwhv->DidStopFlinging(); | 312 rwhv->DidStopFlinging(); |
| 276 } | 313 } |
| 277 | 314 |
| 278 void SynchronousCompositorImpl::NeedsBeginFramesChanged() const { | |
| 279 DCHECK(CalledOnValidThread()); | |
| 280 DCHECK(begin_frame_source_); | |
| 281 if (invoking_composite_) | |
| 282 return; | |
| 283 | |
| 284 if (compositor_client_) { | |
| 285 compositor_client_->SetContinuousInvalidate( | |
| 286 begin_frame_source_->NeedsBeginFrames()); | |
| 287 } | |
| 288 } | |
| 289 | |
| 290 InputEventAckState SynchronousCompositorImpl::HandleInputEvent( | 315 InputEventAckState SynchronousCompositorImpl::HandleInputEvent( |
| 291 const blink::WebInputEvent& input_event) { | 316 const blink::WebInputEvent& input_event) { |
| 292 DCHECK(CalledOnValidThread()); | 317 DCHECK(CalledOnValidThread()); |
| 293 return g_factory.Get().synchronous_input_event_filter()->HandleInputEvent( | 318 return g_factory.Get().synchronous_input_event_filter()->HandleInputEvent( |
| 294 contents_->GetRoutingID(), input_event); | 319 contents_->GetRoutingID(), input_event); |
| 295 } | 320 } |
| 296 | 321 |
| 297 void SynchronousCompositorImpl::DeliverMessages() { | 322 void SynchronousCompositorImpl::DeliverMessages() { |
| 298 ScopedVector<IPC::Message> messages; | 323 ScopedVector<IPC::Message> messages; |
| 299 output_surface_->GetMessagesToDeliver(&messages); | 324 output_surface_->GetMessagesToDeliver(&messages); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 364 g_factory.Get(); // Ensure it's initialized. | 389 g_factory.Get(); // Ensure it's initialized. |
| 365 SynchronousCompositorImpl::CreateForWebContents(contents); | 390 SynchronousCompositorImpl::CreateForWebContents(contents); |
| 366 } | 391 } |
| 367 SynchronousCompositorImpl* instance = | 392 SynchronousCompositorImpl* instance = |
| 368 SynchronousCompositorImpl::FromWebContents(contents); | 393 SynchronousCompositorImpl::FromWebContents(contents); |
| 369 DCHECK(instance); | 394 DCHECK(instance); |
| 370 instance->SetClient(client); | 395 instance->SetClient(client); |
| 371 } | 396 } |
| 372 | 397 |
| 373 } // namespace content | 398 } // namespace content |
| OLD | NEW |