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/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 8 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 9 #include "cc/input/input_handler.h" | 10 #include "cc/input/input_handler.h" |
| 11 #include "content/browser/android/in_process/synchronous_compositor_external_beg in_frame_source.h" | |
| 10 #include "content/browser/android/in_process/synchronous_compositor_factory_impl .h" | 12 #include "content/browser/android/in_process/synchronous_compositor_factory_impl .h" |
| 11 #include "content/browser/android/in_process/synchronous_input_event_filter.h" | 13 #include "content/browser/android/in_process/synchronous_input_event_filter.h" |
| 12 #include "content/browser/renderer_host/render_widget_host_view_android.h" | 14 #include "content/browser/renderer_host/render_widget_host_view_android.h" |
| 13 #include "content/common/input/did_overscroll_params.h" | 15 #include "content/common/input/did_overscroll_params.h" |
| 14 #include "content/public/browser/android/synchronous_compositor_client.h" | 16 #include "content/public/browser/android/synchronous_compositor_client.h" |
| 15 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/render_process_host.h" | 18 #include "content/public/browser/render_process_host.h" |
| 17 #include "content/public/browser/render_view_host.h" | 19 #include "content/public/browser/render_view_host.h" |
| 18 #include "ui/gl/gl_surface.h" | 20 #include "ui/gl/gl_surface.h" |
| 19 | 21 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 } | 60 } |
| 59 | 61 |
| 60 SynchronousCompositorImpl* SynchronousCompositorImpl::FromRoutingID( | 62 SynchronousCompositorImpl* SynchronousCompositorImpl::FromRoutingID( |
| 61 int routing_id) { | 63 int routing_id) { |
| 62 return FromID(GetInProcessRendererId(), routing_id); | 64 return FromID(GetInProcessRendererId(), routing_id); |
| 63 } | 65 } |
| 64 | 66 |
| 65 SynchronousCompositorImpl::SynchronousCompositorImpl(WebContents* contents) | 67 SynchronousCompositorImpl::SynchronousCompositorImpl(WebContents* contents) |
| 66 : compositor_client_(NULL), | 68 : compositor_client_(NULL), |
| 67 output_surface_(NULL), | 69 output_surface_(NULL), |
| 70 begin_frame_source_(NULL), | |
| 68 contents_(contents), | 71 contents_(contents), |
| 69 input_handler_(NULL), | 72 input_handler_(NULL), |
| 70 weak_ptr_factory_(this) { | 73 weak_ptr_factory_(this) { |
| 71 DCHECK(contents); | 74 DCHECK(contents); |
| 72 } | 75 } |
| 73 | 76 |
| 74 SynchronousCompositorImpl::~SynchronousCompositorImpl() { | 77 SynchronousCompositorImpl::~SynchronousCompositorImpl() { |
| 75 if (compositor_client_) | 78 if (compositor_client_) |
| 76 compositor_client_->DidDestroyCompositor(this); | 79 compositor_client_->DidDestroyCompositor(this); |
| 77 SetInputHandler(NULL); | 80 SetInputHandler(NULL); |
| 78 } | 81 } |
| 79 | 82 |
| 80 void SynchronousCompositorImpl::SetClient( | 83 void SynchronousCompositorImpl::SetClient( |
| 81 SynchronousCompositorClient* compositor_client) { | 84 SynchronousCompositorClient* compositor_client) { |
| 82 DCHECK(CalledOnValidThread()); | 85 DCHECK(CalledOnValidThread()); |
| 83 compositor_client_ = compositor_client; | 86 compositor_client_ = compositor_client; |
| 84 } | 87 } |
| 85 | 88 |
| 86 // static | 89 // static |
| 87 void SynchronousCompositor::SetGpuService( | 90 void SynchronousCompositor::SetGpuService( |
| 88 scoped_refptr<gpu::InProcessCommandBuffer::Service> service) { | 91 scoped_refptr<gpu::InProcessCommandBuffer::Service> service) { |
| 89 g_factory.Get().SetDeferredGpuService(service); | 92 g_factory.Get().SetDeferredGpuService(service); |
| 90 } | 93 } |
| 91 | 94 |
| 92 // static | 95 // static |
| 93 void SynchronousCompositor::SetRecordFullDocument(bool record_full_document) { | 96 void SynchronousCompositor::SetRecordFullDocument(bool record_full_document) { |
| 94 g_factory.Get().SetRecordFullDocument(record_full_document); | 97 g_factory.Get().SetRecordFullDocument(record_full_document); |
| 95 } | 98 } |
| 96 | 99 |
| 100 scoped_ptr<cc::BeginFrameSource> | |
| 101 SynchronousCompositorImpl::GetExternalBeginFrameSource() { | |
| 102 DCHECK(!begin_frame_source_); | |
| 103 scoped_ptr<SynchronousCompositorExternalBeginFrameSource> source( | |
| 104 new SynchronousCompositorExternalBeginFrameSource(this)); | |
| 105 begin_frame_source_ = source.get(); | |
| 106 return source.Pass(); | |
| 107 } | |
| 108 | |
| 109 bool SynchronousCompositorImpl::IsInvokingComposite() const { | |
| 110 DCHECK(output_surface_); | |
| 111 return output_surface_->invoking_composite(); | |
|
boliu
2014/10/18 00:49:38
Can lift invoking_composite out of OutputSurface t
simonhong
2014/10/23 01:03:08
Done.
| |
| 112 } | |
| 113 | |
| 97 bool SynchronousCompositorImpl::InitializeHwDraw() { | 114 bool SynchronousCompositorImpl::InitializeHwDraw() { |
| 98 DCHECK(CalledOnValidThread()); | 115 DCHECK(CalledOnValidThread()); |
| 99 DCHECK(output_surface_); | 116 DCHECK(output_surface_); |
| 100 | 117 |
| 101 scoped_refptr<cc::ContextProvider> onscreen_context = | 118 scoped_refptr<cc::ContextProvider> onscreen_context = |
| 102 g_factory.Get().CreateOnscreenContextProviderForCompositorThread(); | 119 g_factory.Get().CreateOnscreenContextProviderForCompositorThread(); |
| 103 | 120 |
| 104 bool success = output_surface_->InitializeHwDraw(onscreen_context); | 121 bool success = output_surface_->InitializeHwDraw(onscreen_context); |
| 105 | 122 |
| 106 if (success) | 123 if (success) |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 125 DCHECK(CalledOnValidThread()); | 142 DCHECK(CalledOnValidThread()); |
| 126 DCHECK(output_surface_); | 143 DCHECK(output_surface_); |
| 127 | 144 |
| 128 scoped_ptr<cc::CompositorFrame> frame = | 145 scoped_ptr<cc::CompositorFrame> frame = |
| 129 output_surface_->DemandDrawHw(surface_size, | 146 output_surface_->DemandDrawHw(surface_size, |
| 130 transform, | 147 transform, |
| 131 viewport, | 148 viewport, |
| 132 clip, | 149 clip, |
| 133 viewport_rect_for_tile_priority, | 150 viewport_rect_for_tile_priority, |
| 134 transform_for_tile_priority); | 151 transform_for_tile_priority); |
| 152 | |
| 135 if (frame.get()) | 153 if (frame.get()) |
| 136 UpdateFrameMetaData(frame->metadata); | 154 UpdateFrameMetaData(frame->metadata); |
| 137 | 155 |
| 138 return frame.Pass(); | 156 return frame.Pass(); |
| 139 } | 157 } |
| 140 | 158 |
| 141 void SynchronousCompositorImpl::ReturnResources( | 159 void SynchronousCompositorImpl::ReturnResources( |
| 142 const cc::CompositorFrameAck& frame_ack) { | 160 const cc::CompositorFrameAck& frame_ack) { |
| 143 DCHECK(CalledOnValidThread()); | 161 DCHECK(CalledOnValidThread()); |
| 144 output_surface_->ReturnResources(frame_ack); | 162 output_surface_->ReturnResources(frame_ack); |
| 145 } | 163 } |
| 146 | 164 |
| 147 bool SynchronousCompositorImpl::DemandDrawSw(SkCanvas* canvas) { | 165 bool SynchronousCompositorImpl::DemandDrawSw(SkCanvas* canvas) { |
| 148 DCHECK(CalledOnValidThread()); | 166 DCHECK(CalledOnValidThread()); |
| 149 DCHECK(output_surface_); | 167 DCHECK(output_surface_); |
| 150 | 168 |
| 151 scoped_ptr<cc::CompositorFrame> frame = output_surface_->DemandDrawSw(canvas); | 169 scoped_ptr<cc::CompositorFrame> frame = output_surface_->DemandDrawSw(canvas); |
| 170 | |
| 152 if (frame.get()) | 171 if (frame.get()) |
| 153 UpdateFrameMetaData(frame->metadata); | 172 UpdateFrameMetaData(frame->metadata); |
| 154 return !!frame.get(); | 173 return !!frame.get(); |
| 155 } | 174 } |
| 156 | 175 |
| 157 void SynchronousCompositorImpl::UpdateFrameMetaData( | 176 void SynchronousCompositorImpl::UpdateFrameMetaData( |
| 158 const cc::CompositorFrameMetadata& frame_metadata) { | 177 const cc::CompositorFrameMetadata& frame_metadata) { |
| 159 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( | 178 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( |
| 160 contents_->GetRenderWidgetHostView()); | 179 contents_->GetRenderWidgetHostView()); |
| 161 if (rwhv) | 180 if (rwhv) |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 } | 239 } |
| 221 } | 240 } |
| 222 | 241 |
| 223 void SynchronousCompositorImpl::DidStopFlinging() { | 242 void SynchronousCompositorImpl::DidStopFlinging() { |
| 224 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( | 243 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( |
| 225 contents_->GetRenderWidgetHostView()); | 244 contents_->GetRenderWidgetHostView()); |
| 226 if (rwhv) | 245 if (rwhv) |
| 227 rwhv->DidStopFlinging(); | 246 rwhv->DidStopFlinging(); |
| 228 } | 247 } |
| 229 | 248 |
| 230 void SynchronousCompositorImpl::SetContinuousInvalidate(bool enable) { | 249 void SynchronousCompositorImpl::UpdateContinuousInvalidate() { |
| 231 DCHECK(CalledOnValidThread()); | 250 DCHECK(CalledOnValidThread()); |
| 232 if (compositor_client_) | 251 if (compositor_client_) { |
| 233 compositor_client_->SetContinuousInvalidate(enable); | 252 compositor_client_->SetContinuousInvalidate( |
| 253 begin_frame_source_->NeedsBeginFrames()); | |
| 254 } | |
| 234 } | 255 } |
| 235 | 256 |
| 236 InputEventAckState SynchronousCompositorImpl::HandleInputEvent( | 257 InputEventAckState SynchronousCompositorImpl::HandleInputEvent( |
| 237 const blink::WebInputEvent& input_event) { | 258 const blink::WebInputEvent& input_event) { |
| 238 DCHECK(CalledOnValidThread()); | 259 DCHECK(CalledOnValidThread()); |
| 239 return g_factory.Get().synchronous_input_event_filter()->HandleInputEvent( | 260 return g_factory.Get().synchronous_input_event_filter()->HandleInputEvent( |
| 240 contents_->GetRoutingID(), input_event); | 261 contents_->GetRoutingID(), input_event); |
| 241 } | 262 } |
| 242 | 263 |
| 243 void SynchronousCompositorImpl::DeliverMessages() { | 264 void SynchronousCompositorImpl::DeliverMessages() { |
| 244 ScopedVector<IPC::Message> messages; | 265 ScopedVector<IPC::Message> messages; |
| 245 output_surface_->GetMessagesToDeliver(&messages); | 266 output_surface_->GetMessagesToDeliver(&messages); |
| 246 RenderProcessHost* rph = contents_->GetRenderProcessHost(); | 267 RenderProcessHost* rph = contents_->GetRenderProcessHost(); |
| 247 for (ScopedVector<IPC::Message>::const_iterator i = messages.begin(); | 268 for (ScopedVector<IPC::Message>::const_iterator i = messages.begin(); |
| 248 i != messages.end(); | 269 i != messages.end(); |
| 249 ++i) { | 270 ++i) { |
| 250 rph->OnMessageReceived(**i); | 271 rph->OnMessageReceived(**i); |
| 251 } | 272 } |
| 252 } | 273 } |
| 253 | 274 |
| 254 void SynchronousCompositorImpl::DidActivatePendingTree() { | 275 void SynchronousCompositorImpl::DidActivatePendingTree() { |
| 255 if (compositor_client_) | 276 if (compositor_client_) |
| 256 compositor_client_->DidUpdateContent(); | 277 compositor_client_->DidUpdateContent(); |
| 257 } | 278 } |
| 258 | 279 |
| 280 void SynchronousCompositorImpl::BeginFrame() { | |
| 281 DCHECK(begin_frame_source_); | |
| 282 begin_frame_source_->BeginFrame(); | |
| 283 } | |
| 284 | |
| 259 gfx::ScrollOffset SynchronousCompositorImpl::GetTotalScrollOffset() { | 285 gfx::ScrollOffset SynchronousCompositorImpl::GetTotalScrollOffset() { |
| 260 DCHECK(CalledOnValidThread()); | 286 DCHECK(CalledOnValidThread()); |
| 261 if (compositor_client_) { | 287 if (compositor_client_) { |
| 262 // TODO(miletus): Make GetTotalRootLayerScrollOffset return | 288 // TODO(miletus): Make GetTotalRootLayerScrollOffset return |
| 263 // ScrollOffset. crbug.com/414283. | 289 // ScrollOffset. crbug.com/414283. |
| 264 return gfx::ScrollOffset( | 290 return gfx::ScrollOffset( |
| 265 compositor_client_->GetTotalRootLayerScrollOffset()); | 291 compositor_client_->GetTotalRootLayerScrollOffset()); |
| 266 } | 292 } |
| 267 return gfx::ScrollOffset(); | 293 return gfx::ScrollOffset(); |
| 268 } | 294 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 310 g_factory.Get(); // Ensure it's initialized. | 336 g_factory.Get(); // Ensure it's initialized. |
| 311 SynchronousCompositorImpl::CreateForWebContents(contents); | 337 SynchronousCompositorImpl::CreateForWebContents(contents); |
| 312 } | 338 } |
| 313 if (SynchronousCompositorImpl* instance = | 339 if (SynchronousCompositorImpl* instance = |
| 314 SynchronousCompositorImpl::FromWebContents(contents)) { | 340 SynchronousCompositorImpl::FromWebContents(contents)) { |
| 315 instance->SetClient(client); | 341 instance->SetClient(client); |
| 316 } | 342 } |
| 317 } | 343 } |
| 318 | 344 |
| 319 } // namespace content | 345 } // namespace content |
| OLD | NEW |