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), |
| 73 invoking_composite_(false), | |
| 70 weak_ptr_factory_(this) { | 74 weak_ptr_factory_(this) { |
| 71 DCHECK(contents); | 75 DCHECK(contents); |
| 72 } | 76 } |
| 73 | 77 |
| 74 SynchronousCompositorImpl::~SynchronousCompositorImpl() { | 78 SynchronousCompositorImpl::~SynchronousCompositorImpl() { |
| 75 if (compositor_client_) | 79 if (compositor_client_) |
| 76 compositor_client_->DidDestroyCompositor(this); | 80 compositor_client_->DidDestroyCompositor(this); |
| 77 SetInputHandler(NULL); | 81 SetInputHandler(NULL); |
| 78 } | 82 } |
| 79 | 83 |
| 80 void SynchronousCompositorImpl::SetClient( | 84 void SynchronousCompositorImpl::SetClient( |
| 81 SynchronousCompositorClient* compositor_client) { | 85 SynchronousCompositorClient* compositor_client) { |
| 82 DCHECK(CalledOnValidThread()); | 86 DCHECK(CalledOnValidThread()); |
| 83 compositor_client_ = compositor_client; | 87 compositor_client_ = compositor_client; |
| 84 } | 88 } |
| 85 | 89 |
| 86 // static | 90 // static |
| 87 void SynchronousCompositor::SetGpuService( | 91 void SynchronousCompositor::SetGpuService( |
| 88 scoped_refptr<gpu::InProcessCommandBuffer::Service> service) { | 92 scoped_refptr<gpu::InProcessCommandBuffer::Service> service) { |
| 89 g_factory.Get().SetDeferredGpuService(service); | 93 g_factory.Get().SetDeferredGpuService(service); |
| 90 } | 94 } |
| 91 | 95 |
| 92 // static | 96 // static |
| 93 void SynchronousCompositor::SetRecordFullDocument(bool record_full_document) { | 97 void SynchronousCompositor::SetRecordFullDocument(bool record_full_document) { |
| 94 g_factory.Get().SetRecordFullDocument(record_full_document); | 98 g_factory.Get().SetRecordFullDocument(record_full_document); |
| 95 } | 99 } |
| 96 | 100 |
| 101 void SynchronousCompositorImpl::SetExternalBeginFrameSource( | |
| 102 SynchronousCompositorExternalBeginFrameSource* begin_frame_source) { | |
| 103 begin_frame_source_ = begin_frame_source; | |
|
boliu
2014/10/24 17:42:40
Need keep BeginFrameSource and compositor_client_
simonhong
2014/10/29 14:47:13
DCHECK(compositor_client_) is added.
And, begin_fr
| |
| 104 } | |
| 105 | |
| 97 bool SynchronousCompositorImpl::InitializeHwDraw() { | 106 bool SynchronousCompositorImpl::InitializeHwDraw() { |
| 98 DCHECK(CalledOnValidThread()); | 107 DCHECK(CalledOnValidThread()); |
| 99 DCHECK(output_surface_); | 108 DCHECK(output_surface_); |
| 100 | 109 |
| 101 scoped_refptr<cc::ContextProvider> onscreen_context = | 110 scoped_refptr<cc::ContextProvider> onscreen_context = |
| 102 g_factory.Get().CreateOnscreenContextProviderForCompositorThread(); | 111 g_factory.Get().CreateOnscreenContextProviderForCompositorThread(); |
| 103 | 112 |
| 104 bool success = output_surface_->InitializeHwDraw(onscreen_context); | 113 bool success = output_surface_->InitializeHwDraw(onscreen_context); |
| 105 | 114 |
| 106 if (success) | 115 if (success) |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 117 | 126 |
| 118 scoped_ptr<cc::CompositorFrame> SynchronousCompositorImpl::DemandDrawHw( | 127 scoped_ptr<cc::CompositorFrame> SynchronousCompositorImpl::DemandDrawHw( |
| 119 gfx::Size surface_size, | 128 gfx::Size surface_size, |
| 120 const gfx::Transform& transform, | 129 const gfx::Transform& transform, |
| 121 gfx::Rect viewport, | 130 gfx::Rect viewport, |
| 122 gfx::Rect clip, | 131 gfx::Rect clip, |
| 123 gfx::Rect viewport_rect_for_tile_priority, | 132 gfx::Rect viewport_rect_for_tile_priority, |
| 124 const gfx::Transform& transform_for_tile_priority) { | 133 const gfx::Transform& transform_for_tile_priority) { |
| 125 DCHECK(CalledOnValidThread()); | 134 DCHECK(CalledOnValidThread()); |
| 126 DCHECK(output_surface_); | 135 DCHECK(output_surface_); |
| 136 DCHECK(!invoking_composite_); | |
| 137 DCHECK(begin_frame_source_); | |
|
boliu
2014/10/24 17:42:40
This DCHECK is not guaranteed.
Note we only call
simonhong
2014/10/29 14:47:13
Removed.
| |
| 138 base::AutoReset<bool> invoking_composite_resetter(&invoking_composite_, true); | |
| 127 | 139 |
| 128 scoped_ptr<cc::CompositorFrame> frame = | 140 scoped_ptr<cc::CompositorFrame> frame = |
| 129 output_surface_->DemandDrawHw(surface_size, | 141 output_surface_->DemandDrawHw(surface_size, |
| 130 transform, | 142 transform, |
| 131 viewport, | 143 viewport, |
| 132 clip, | 144 clip, |
| 133 viewport_rect_for_tile_priority, | 145 viewport_rect_for_tile_priority, |
| 134 transform_for_tile_priority); | 146 transform_for_tile_priority); |
| 135 if (frame.get()) | 147 if (frame.get()) |
| 136 UpdateFrameMetaData(frame->metadata); | 148 UpdateFrameMetaData(frame->metadata); |
| 137 | 149 |
|
boliu
2014/10/24 17:42:40
Where is the BeginFrame and SetContinuousInvalidat
simonhong
2014/10/29 14:47:13
SetContinuousInvalidate() is added.
| |
| 138 return frame.Pass(); | 150 return frame.Pass(); |
| 139 } | 151 } |
| 140 | 152 |
| 153 void SynchronousCompositorImpl::RequestBeginFrame() { | |
|
boliu
2014/10/24 17:42:40
Super confusing name, should be just BeginFrame. B
simonhong
2014/10/29 14:47:13
This function is removed.
| |
| 154 begin_frame_source_->BeginFrame(); | |
|
boliu
2014/10/24 17:42:40
DCHECK(begin_frame_source_)
| |
| 155 SetContinuousInvalidate(begin_frame_source_->NeedsBeginFrames()); | |
|
boliu
2014/10/24 17:42:40
Why?
| |
| 156 } | |
| 157 | |
| 141 void SynchronousCompositorImpl::ReturnResources( | 158 void SynchronousCompositorImpl::ReturnResources( |
| 142 const cc::CompositorFrameAck& frame_ack) { | 159 const cc::CompositorFrameAck& frame_ack) { |
| 143 DCHECK(CalledOnValidThread()); | 160 DCHECK(CalledOnValidThread()); |
| 144 output_surface_->ReturnResources(frame_ack); | 161 output_surface_->ReturnResources(frame_ack); |
| 145 } | 162 } |
| 146 | 163 |
| 147 bool SynchronousCompositorImpl::DemandDrawSw(SkCanvas* canvas) { | 164 bool SynchronousCompositorImpl::DemandDrawSw(SkCanvas* canvas) { |
| 148 DCHECK(CalledOnValidThread()); | 165 DCHECK(CalledOnValidThread()); |
| 149 DCHECK(output_surface_); | 166 DCHECK(output_surface_); |
| 167 DCHECK(!invoking_composite_); | |
| 168 DCHECK(begin_frame_source_); | |
| 169 base::AutoReset<bool> invoking_composite_resetter(&invoking_composite_, true); | |
| 150 | 170 |
| 151 scoped_ptr<cc::CompositorFrame> frame = output_surface_->DemandDrawSw(canvas); | 171 scoped_ptr<cc::CompositorFrame> frame = output_surface_->DemandDrawSw(canvas); |
| 152 if (frame.get()) | 172 if (frame.get()) |
| 153 UpdateFrameMetaData(frame->metadata); | 173 UpdateFrameMetaData(frame->metadata); |
| 174 | |
| 175 begin_frame_source_->BeginFrame(); | |
|
boliu
2014/10/24 17:42:40
Why?
simonhong
2014/10/29 14:47:13
Removed.
| |
| 176 SetContinuousInvalidate(begin_frame_source_->NeedsBeginFrames()); | |
| 177 | |
| 154 return !!frame.get(); | 178 return !!frame.get(); |
| 155 } | 179 } |
| 156 | 180 |
| 157 void SynchronousCompositorImpl::UpdateFrameMetaData( | 181 void SynchronousCompositorImpl::UpdateFrameMetaData( |
| 158 const cc::CompositorFrameMetadata& frame_metadata) { | 182 const cc::CompositorFrameMetadata& frame_metadata) { |
| 159 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( | 183 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( |
| 160 contents_->GetRenderWidgetHostView()); | 184 contents_->GetRenderWidgetHostView()); |
| 161 if (rwhv) | 185 if (rwhv) |
| 162 rwhv->SynchronousFrameMetadata(frame_metadata); | 186 rwhv->SynchronousFrameMetadata(frame_metadata); |
| 163 DeliverMessages(); | 187 DeliverMessages(); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 } | 244 } |
| 221 } | 245 } |
| 222 | 246 |
| 223 void SynchronousCompositorImpl::DidStopFlinging() { | 247 void SynchronousCompositorImpl::DidStopFlinging() { |
| 224 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( | 248 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( |
| 225 contents_->GetRenderWidgetHostView()); | 249 contents_->GetRenderWidgetHostView()); |
| 226 if (rwhv) | 250 if (rwhv) |
| 227 rwhv->DidStopFlinging(); | 251 rwhv->DidStopFlinging(); |
| 228 } | 252 } |
| 229 | 253 |
| 230 void SynchronousCompositorImpl::SetContinuousInvalidate(bool enable) { | 254 void SynchronousCompositorImpl::SetContinuousInvalidate( |
| 255 bool needs_begin_frames) const { | |
| 231 DCHECK(CalledOnValidThread()); | 256 DCHECK(CalledOnValidThread()); |
| 232 if (compositor_client_) | 257 if (compositor_client_) |
| 233 compositor_client_->SetContinuousInvalidate(enable); | 258 compositor_client_->SetContinuousInvalidate(needs_begin_frames); |
|
boliu
2014/10/24 17:42:40
We want to hold off on this if invoking_composite_
simonhong
2014/10/29 14:47:13
Made early out if invoking_composite_ is true.
| |
| 234 } | 259 } |
| 235 | 260 |
| 236 InputEventAckState SynchronousCompositorImpl::HandleInputEvent( | 261 InputEventAckState SynchronousCompositorImpl::HandleInputEvent( |
| 237 const blink::WebInputEvent& input_event) { | 262 const blink::WebInputEvent& input_event) { |
| 238 DCHECK(CalledOnValidThread()); | 263 DCHECK(CalledOnValidThread()); |
| 239 return g_factory.Get().synchronous_input_event_filter()->HandleInputEvent( | 264 return g_factory.Get().synchronous_input_event_filter()->HandleInputEvent( |
| 240 contents_->GetRoutingID(), input_event); | 265 contents_->GetRoutingID(), input_event); |
| 241 } | 266 } |
| 242 | 267 |
| 243 void SynchronousCompositorImpl::DeliverMessages() { | 268 void SynchronousCompositorImpl::DeliverMessages() { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 310 g_factory.Get(); // Ensure it's initialized. | 335 g_factory.Get(); // Ensure it's initialized. |
| 311 SynchronousCompositorImpl::CreateForWebContents(contents); | 336 SynchronousCompositorImpl::CreateForWebContents(contents); |
| 312 } | 337 } |
| 313 if (SynchronousCompositorImpl* instance = | 338 if (SynchronousCompositorImpl* instance = |
| 314 SynchronousCompositorImpl::FromWebContents(contents)) { | 339 SynchronousCompositorImpl::FromWebContents(contents)) { |
| 315 instance->SetClient(client); | 340 instance->SetClient(client); |
| 316 } | 341 } |
| 317 } | 342 } |
| 318 | 343 |
| 319 } // namespace content | 344 } // namespace content |
| OLD | NEW |