| 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/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "cc/input/input_handler.h" | 9 #include "cc/input/input_handler.h" |
| 10 #include "content/browser/android/in_process/synchronous_compositor_factory_impl
.h" | 10 #include "content/browser/android/in_process/synchronous_compositor_factory_impl
.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 | 59 |
| 60 SynchronousCompositorImpl* SynchronousCompositorImpl::FromRoutingID( | 60 SynchronousCompositorImpl* SynchronousCompositorImpl::FromRoutingID( |
| 61 int routing_id) { | 61 int routing_id) { |
| 62 return FromID(GetInProcessRendererId(), routing_id); | 62 return FromID(GetInProcessRendererId(), routing_id); |
| 63 } | 63 } |
| 64 | 64 |
| 65 SynchronousCompositorImpl::SynchronousCompositorImpl(WebContents* contents) | 65 SynchronousCompositorImpl::SynchronousCompositorImpl(WebContents* contents) |
| 66 : compositor_client_(NULL), | 66 : compositor_client_(NULL), |
| 67 output_surface_(NULL), | 67 output_surface_(NULL), |
| 68 contents_(contents), | 68 contents_(contents), |
| 69 input_handler_(NULL) { | 69 input_handler_(NULL), |
| 70 weak_ptr_factory_(this) { |
| 70 DCHECK(contents); | 71 DCHECK(contents); |
| 71 } | 72 } |
| 72 | 73 |
| 73 SynchronousCompositorImpl::~SynchronousCompositorImpl() { | 74 SynchronousCompositorImpl::~SynchronousCompositorImpl() { |
| 74 if (compositor_client_) | 75 if (compositor_client_) |
| 75 compositor_client_->DidDestroyCompositor(this); | 76 compositor_client_->DidDestroyCompositor(this); |
| 76 SetInputHandler(NULL); | 77 SetInputHandler(NULL); |
| 77 } | 78 } |
| 78 | 79 |
| 79 void SynchronousCompositorImpl::SetClient( | 80 void SynchronousCompositorImpl::SetClient( |
| (...skipping 23 matching lines...) Expand all Loading... |
| 103 return success; | 104 return success; |
| 104 } | 105 } |
| 105 | 106 |
| 106 void SynchronousCompositorImpl::ReleaseHwDraw() { | 107 void SynchronousCompositorImpl::ReleaseHwDraw() { |
| 107 DCHECK(CalledOnValidThread()); | 108 DCHECK(CalledOnValidThread()); |
| 108 DCHECK(output_surface_); | 109 DCHECK(output_surface_); |
| 109 output_surface_->ReleaseHwDraw(); | 110 output_surface_->ReleaseHwDraw(); |
| 110 g_factory.Get().CompositorReleasedHardwareDraw(); | 111 g_factory.Get().CompositorReleasedHardwareDraw(); |
| 111 } | 112 } |
| 112 | 113 |
| 113 bool SynchronousCompositorImpl::DemandDrawHw( | 114 gpu::GLInProcessContext* SynchronousCompositorImpl::GetShareContext() { |
| 114 gfx::Size surface_size, | 115 DCHECK(CalledOnValidThread()); |
| 115 const gfx::Transform& transform, | 116 return g_factory.Get().GetShareContext(); |
| 116 gfx::Rect viewport, | 117 } |
| 117 gfx::Rect clip, | 118 |
| 118 bool stencil_enabled) { | 119 scoped_ptr<cc::CompositorFrame> SynchronousCompositorImpl::DemandDrawHw( |
| 120 gfx::Size surface_size, |
| 121 const gfx::Transform& transform, |
| 122 gfx::Rect viewport, |
| 123 gfx::Rect clip, |
| 124 bool stencil_enabled) { |
| 119 DCHECK(CalledOnValidThread()); | 125 DCHECK(CalledOnValidThread()); |
| 120 DCHECK(output_surface_); | 126 DCHECK(output_surface_); |
| 121 | 127 |
| 122 return output_surface_->DemandDrawHw( | 128 scoped_ptr<cc::CompositorFrame> frame = output_surface_->DemandDrawHw( |
| 123 surface_size, transform, viewport, clip, stencil_enabled); | 129 surface_size, transform, viewport, clip, stencil_enabled); |
| 130 if (frame.get()) |
| 131 UpdateFrameMetaData(frame->metadata); |
| 132 return frame.Pass(); |
| 133 } |
| 134 |
| 135 void SynchronousCompositorImpl::ReturnResources( |
| 136 const cc::CompositorFrameAck& frame_ack) { |
| 137 DCHECK(CalledOnValidThread()); |
| 138 output_surface_->ReturnResources(frame_ack); |
| 124 } | 139 } |
| 125 | 140 |
| 126 bool SynchronousCompositorImpl::DemandDrawSw(SkCanvas* canvas) { | 141 bool SynchronousCompositorImpl::DemandDrawSw(SkCanvas* canvas) { |
| 127 DCHECK(CalledOnValidThread()); | 142 DCHECK(CalledOnValidThread()); |
| 128 DCHECK(output_surface_); | 143 DCHECK(output_surface_); |
| 129 | 144 |
| 130 return output_surface_->DemandDrawSw(canvas); | 145 scoped_ptr<cc::CompositorFrame> frame = output_surface_->DemandDrawSw(canvas); |
| 146 if (frame.get()) |
| 147 UpdateFrameMetaData(frame->metadata); |
| 148 return !!frame.get(); |
| 149 } |
| 150 |
| 151 void SynchronousCompositorImpl::UpdateFrameMetaData( |
| 152 const cc::CompositorFrameMetadata& frame_metadata) { |
| 153 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 154 BrowserThread::PostTask( |
| 155 BrowserThread::UI, |
| 156 FROM_HERE, |
| 157 base::Bind(&SynchronousCompositorImpl::UpdateFrameMetaData, |
| 158 weak_ptr_factory_.GetWeakPtr(), |
| 159 frame_metadata)); |
| 160 return; |
| 161 } |
| 162 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( |
| 163 contents_->GetRenderWidgetHostView()); |
| 164 if (rwhv) |
| 165 rwhv->SynchronousFrameMetadata(frame_metadata); |
| 131 } | 166 } |
| 132 | 167 |
| 133 void SynchronousCompositorImpl::SetMemoryPolicy( | 168 void SynchronousCompositorImpl::SetMemoryPolicy( |
| 134 const SynchronousCompositorMemoryPolicy& policy) { | 169 const SynchronousCompositorMemoryPolicy& policy) { |
| 135 DCHECK(CalledOnValidThread()); | 170 DCHECK(CalledOnValidThread()); |
| 136 DCHECK(output_surface_); | 171 DCHECK(output_surface_); |
| 137 | 172 |
| 138 output_surface_->SetMemoryPolicy(policy); | 173 output_surface_->SetMemoryPolicy(policy); |
| 139 } | 174 } |
| 140 | 175 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 compositor_client_->SetContinuousInvalidate(enable); | 235 compositor_client_->SetContinuousInvalidate(enable); |
| 201 } | 236 } |
| 202 | 237 |
| 203 InputEventAckState SynchronousCompositorImpl::HandleInputEvent( | 238 InputEventAckState SynchronousCompositorImpl::HandleInputEvent( |
| 204 const blink::WebInputEvent& input_event) { | 239 const blink::WebInputEvent& input_event) { |
| 205 DCHECK(CalledOnValidThread()); | 240 DCHECK(CalledOnValidThread()); |
| 206 return g_factory.Get().synchronous_input_event_filter()->HandleInputEvent( | 241 return g_factory.Get().synchronous_input_event_filter()->HandleInputEvent( |
| 207 contents_->GetRoutingID(), input_event); | 242 contents_->GetRoutingID(), input_event); |
| 208 } | 243 } |
| 209 | 244 |
| 210 void SynchronousCompositorImpl::UpdateFrameMetaData( | |
| 211 const cc::CompositorFrameMetadata& frame_metadata) { | |
| 212 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( | |
| 213 contents_->GetRenderWidgetHostView()); | |
| 214 if (rwhv) | |
| 215 rwhv->SynchronousFrameMetadata(frame_metadata); | |
| 216 } | |
| 217 | |
| 218 void SynchronousCompositorImpl::DidActivatePendingTree() { | 245 void SynchronousCompositorImpl::DidActivatePendingTree() { |
| 219 if (compositor_client_) | 246 if (compositor_client_) |
| 220 compositor_client_->DidUpdateContent(); | 247 compositor_client_->DidUpdateContent(); |
| 221 } | 248 } |
| 222 | 249 |
| 223 gfx::Vector2dF SynchronousCompositorImpl::GetTotalScrollOffset() { | 250 gfx::Vector2dF SynchronousCompositorImpl::GetTotalScrollOffset() { |
| 224 DCHECK(CalledOnValidThread()); | 251 DCHECK(CalledOnValidThread()); |
| 225 if (compositor_client_) | 252 if (compositor_client_) |
| 226 return compositor_client_->GetTotalRootLayerScrollOffset(); | 253 return compositor_client_->GetTotalRootLayerScrollOffset(); |
| 227 return gfx::Vector2dF(); | 254 return gfx::Vector2dF(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 g_factory.Get(); // Ensure it's initialized. | 295 g_factory.Get(); // Ensure it's initialized. |
| 269 SynchronousCompositorImpl::CreateForWebContents(contents); | 296 SynchronousCompositorImpl::CreateForWebContents(contents); |
| 270 } | 297 } |
| 271 if (SynchronousCompositorImpl* instance = | 298 if (SynchronousCompositorImpl* instance = |
| 272 SynchronousCompositorImpl::FromWebContents(contents)) { | 299 SynchronousCompositorImpl::FromWebContents(contents)) { |
| 273 instance->SetClient(client); | 300 instance->SetClient(client); |
| 274 } | 301 } |
| 275 } | 302 } |
| 276 | 303 |
| 277 } // namespace content | 304 } // namespace content |
| OLD | NEW |