| 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 bool SynchronousCompositorImpl::DemandDrawHw(gfx::Size surface_size, |
| 120 const gfx::Transform& transform, |
| 121 gfx::Rect viewport, |
| 122 gfx::Rect clip, |
| 123 bool stencil_enabled, |
| 124 cc::CompositorFrame* frame) { |
| 119 DCHECK(CalledOnValidThread()); | 125 DCHECK(CalledOnValidThread()); |
| 120 DCHECK(output_surface_); | 126 DCHECK(output_surface_); |
| 127 DCHECK(frame); |
| 121 | 128 |
| 122 return output_surface_->DemandDrawHw( | 129 bool result = output_surface_->DemandDrawHw( |
| 123 surface_size, transform, viewport, clip, stencil_enabled); | 130 surface_size, transform, viewport, clip, stencil_enabled, frame); |
| 131 if (result) |
| 132 UpdateFrameMetaData(frame->metadata); |
| 133 return result; |
| 134 } |
| 135 |
| 136 void SynchronousCompositorImpl::ReturnResources( |
| 137 const cc::CompositorFrameAck& frame_ack) { |
| 138 DCHECK(CalledOnValidThread()); |
| 139 output_surface_->ReturnResources(frame_ack); |
| 124 } | 140 } |
| 125 | 141 |
| 126 bool SynchronousCompositorImpl::DemandDrawSw(SkCanvas* canvas) { | 142 bool SynchronousCompositorImpl::DemandDrawSw(SkCanvas* canvas) { |
| 127 DCHECK(CalledOnValidThread()); | 143 DCHECK(CalledOnValidThread()); |
| 128 DCHECK(output_surface_); | 144 DCHECK(output_surface_); |
| 129 | 145 |
| 130 return output_surface_->DemandDrawSw(canvas); | 146 cc::CompositorFrame frame; |
| 147 bool result = output_surface_->DemandDrawSw(canvas, &frame); |
| 148 if (result) |
| 149 UpdateFrameMetaData(frame.metadata); |
| 150 return result; |
| 151 } |
| 152 |
| 153 void SynchronousCompositorImpl::UpdateFrameMetaData( |
| 154 const cc::CompositorFrameMetadata& frame_metadata) { |
| 155 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 156 BrowserThread::PostTask( |
| 157 BrowserThread::UI, |
| 158 FROM_HERE, |
| 159 base::Bind(&SynchronousCompositorImpl::UpdateFrameMetaData, |
| 160 weak_ptr_factory_.GetWeakPtr(), |
| 161 frame_metadata)); |
| 162 return; |
| 163 } |
| 164 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( |
| 165 contents_->GetRenderWidgetHostView()); |
| 166 if (rwhv) |
| 167 rwhv->SynchronousFrameMetadata(frame_metadata); |
| 131 } | 168 } |
| 132 | 169 |
| 133 void SynchronousCompositorImpl::SetMemoryPolicy( | 170 void SynchronousCompositorImpl::SetMemoryPolicy( |
| 134 const SynchronousCompositorMemoryPolicy& policy) { | 171 const SynchronousCompositorMemoryPolicy& policy) { |
| 135 DCHECK(CalledOnValidThread()); | 172 DCHECK(CalledOnValidThread()); |
| 136 DCHECK(output_surface_); | 173 DCHECK(output_surface_); |
| 137 | 174 |
| 138 output_surface_->SetMemoryPolicy(policy); | 175 output_surface_->SetMemoryPolicy(policy); |
| 139 } | 176 } |
| 140 | 177 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 compositor_client_->SetContinuousInvalidate(enable); | 237 compositor_client_->SetContinuousInvalidate(enable); |
| 201 } | 238 } |
| 202 | 239 |
| 203 InputEventAckState SynchronousCompositorImpl::HandleInputEvent( | 240 InputEventAckState SynchronousCompositorImpl::HandleInputEvent( |
| 204 const blink::WebInputEvent& input_event) { | 241 const blink::WebInputEvent& input_event) { |
| 205 DCHECK(CalledOnValidThread()); | 242 DCHECK(CalledOnValidThread()); |
| 206 return g_factory.Get().synchronous_input_event_filter()->HandleInputEvent( | 243 return g_factory.Get().synchronous_input_event_filter()->HandleInputEvent( |
| 207 contents_->GetRoutingID(), input_event); | 244 contents_->GetRoutingID(), input_event); |
| 208 } | 245 } |
| 209 | 246 |
| 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() { | 247 void SynchronousCompositorImpl::DidActivatePendingTree() { |
| 219 if (compositor_client_) | 248 if (compositor_client_) |
| 220 compositor_client_->DidUpdateContent(); | 249 compositor_client_->DidUpdateContent(); |
| 221 } | 250 } |
| 222 | 251 |
| 223 gfx::Vector2dF SynchronousCompositorImpl::GetTotalScrollOffset() { | 252 gfx::Vector2dF SynchronousCompositorImpl::GetTotalScrollOffset() { |
| 224 DCHECK(CalledOnValidThread()); | 253 DCHECK(CalledOnValidThread()); |
| 225 if (compositor_client_) | 254 if (compositor_client_) |
| 226 return compositor_client_->GetTotalRootLayerScrollOffset(); | 255 return compositor_client_->GetTotalRootLayerScrollOffset(); |
| 227 return gfx::Vector2dF(); | 256 return gfx::Vector2dF(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 g_factory.Get(); // Ensure it's initialized. | 297 g_factory.Get(); // Ensure it's initialized. |
| 269 SynchronousCompositorImpl::CreateForWebContents(contents); | 298 SynchronousCompositorImpl::CreateForWebContents(contents); |
| 270 } | 299 } |
| 271 if (SynchronousCompositorImpl* instance = | 300 if (SynchronousCompositorImpl* instance = |
| 272 SynchronousCompositorImpl::FromWebContents(contents)) { | 301 SynchronousCompositorImpl::FromWebContents(contents)) { |
| 273 instance->SetClient(client); | 302 instance->SetClient(client); |
| 274 } | 303 } |
| 275 } | 304 } |
| 276 | 305 |
| 277 } // namespace content | 306 } // namespace content |
| OLD | NEW |