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" |
11 #include "content/browser/android/in_process/synchronous_compositor_external_beg
in_frame_source.h" | 11 #include "content/browser/android/in_process/synchronous_compositor_external_beg
in_frame_source.h" |
12 #include "content/browser/android/in_process/synchronous_compositor_factory_impl
.h" | 12 #include "content/browser/android/in_process/synchronous_compositor_factory_impl
.h" |
13 #include "content/browser/android/in_process/synchronous_compositor_registry.h" | 13 #include "content/browser/android/in_process/synchronous_compositor_registry.h" |
14 #include "content/browser/android/in_process/synchronous_input_event_filter.h" | 14 #include "content/browser/android/in_process/synchronous_input_event_filter.h" |
15 #include "content/browser/gpu/gpu_process_host.h" | 15 #include "content/browser/gpu/gpu_process_host.h" |
16 #include "content/browser/renderer_host/render_widget_host_view_android.h" | 16 #include "content/browser/renderer_host/render_widget_host_view_android.h" |
| 17 #include "content/browser/web_contents/web_contents_android.h" |
| 18 #include "content/browser/web_contents/web_contents_impl.h" |
17 #include "content/common/input/did_overscroll_params.h" | 19 #include "content/common/input/did_overscroll_params.h" |
18 #include "content/common/input_messages.h" | 20 #include "content/common/input_messages.h" |
19 #include "content/public/browser/android/synchronous_compositor_client.h" | 21 #include "content/public/browser/android/synchronous_compositor_client.h" |
20 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
21 #include "content/public/browser/render_process_host.h" | 23 #include "content/public/browser/render_process_host.h" |
22 #include "content/public/browser/render_view_host.h" | 24 #include "content/public/browser/render_view_host.h" |
| 25 #include "content/public/common/child_process_host.h" |
23 #include "ui/gfx/geometry/scroll_offset.h" | 26 #include "ui/gfx/geometry/scroll_offset.h" |
24 #include "ui/gl/gl_surface.h" | 27 #include "ui/gl/gl_surface.h" |
25 | 28 |
26 namespace content { | 29 namespace content { |
27 | 30 |
28 namespace { | 31 namespace { |
29 | 32 |
30 int GetInProcessRendererId() { | 33 int g_process_id = ChildProcessHost::kInvalidUniqueID; |
31 content::RenderProcessHost::iterator it = | |
32 content::RenderProcessHost::AllHostsIterator(); | |
33 if (it.IsAtEnd()) { | |
34 // There should always be one RPH in single process mode. | |
35 NOTREACHED(); | |
36 return 0; | |
37 } | |
38 | |
39 int id = it.GetCurrentValue()->GetID(); | |
40 it.Advance(); | |
41 DCHECK(it.IsAtEnd()); // Not multiprocess compatible. | |
42 return id; | |
43 } | |
44 | 34 |
45 base::LazyInstance<SynchronousCompositorFactoryImpl>::Leaky g_factory = | 35 base::LazyInstance<SynchronousCompositorFactoryImpl>::Leaky g_factory = |
46 LAZY_INSTANCE_INITIALIZER; | 36 LAZY_INSTANCE_INITIALIZER; |
47 | 37 |
48 base::Thread* CreateInProcessGpuThreadForSynchronousCompositor( | 38 base::Thread* CreateInProcessGpuThreadForSynchronousCompositor( |
49 const InProcessChildThreadParams& params) { | 39 const InProcessChildThreadParams& params) { |
50 return g_factory.Get().CreateInProcessGpuThread(params); | 40 return g_factory.Get().CreateInProcessGpuThread(params); |
51 } | 41 } |
52 | 42 |
53 } // namespace | 43 } // namespace |
54 | 44 |
55 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SynchronousCompositorImpl); | 45 SynchronousCompositorImpl* SynchronousCompositorImpl::FromRoutingID( |
| 46 int routing_id) { |
| 47 if (g_factory == nullptr) |
| 48 return nullptr; |
| 49 if (g_process_id == ChildProcessHost::kInvalidUniqueID) |
| 50 return nullptr; |
| 51 RenderViewHost* rvh = RenderViewHost::FromID(g_process_id, routing_id); |
| 52 if (!rvh) |
| 53 return nullptr; |
| 54 RenderWidgetHostViewAndroid* rwhva = |
| 55 static_cast<RenderWidgetHostViewAndroid*>(rvh->GetView()); |
| 56 if (!rwhva) |
| 57 return nullptr; |
| 58 return rwhva->GetSynchronousCompositorImpl(); |
| 59 } |
56 | 60 |
57 // static | 61 // static |
58 SynchronousCompositorImpl* SynchronousCompositorImpl::FromID(int process_id, | 62 scoped_ptr<SynchronousCompositorImpl> SynchronousCompositorImpl::Create( |
59 int routing_id) { | 63 RenderWidgetHostViewAndroid* rwhva, |
60 if (g_factory == nullptr) | 64 WebContents* web_contents) { |
61 return nullptr; | 65 DCHECK(web_contents); |
62 RenderViewHost* rvh = RenderViewHost::FromID(process_id, routing_id); | 66 WebContentsAndroid* web_contents_android = |
63 if (!rvh) | 67 static_cast<WebContentsImpl*>(web_contents)->GetWebContentsAndroid(); |
64 return nullptr; | 68 if (!web_contents_android->synchronous_compositor_client()) |
65 WebContents* contents = WebContents::FromRenderViewHost(rvh); | 69 return nullptr; // Not using sync compositing. |
66 if (!contents) | 70 |
67 return nullptr; | 71 return make_scoped_ptr(new SynchronousCompositorImpl( |
68 return FromWebContents(contents); | 72 rwhva, web_contents_android->synchronous_compositor_client())); |
69 } | 73 } |
70 | 74 |
71 SynchronousCompositorImpl* SynchronousCompositorImpl::FromRoutingID( | 75 SynchronousCompositorImpl::SynchronousCompositorImpl( |
72 int routing_id) { | 76 RenderWidgetHostViewAndroid* rwhva, |
73 return FromID(GetInProcessRendererId(), routing_id); | 77 SynchronousCompositorClient* client) |
74 } | 78 : rwhva_(rwhva), |
75 | 79 routing_id_(rwhva_->GetRenderWidgetHost()->GetRoutingID()), |
76 SynchronousCompositorImpl::SynchronousCompositorImpl(WebContents* contents) | 80 compositor_client_(client), |
77 : compositor_client_(nullptr), | |
78 output_surface_(nullptr), | 81 output_surface_(nullptr), |
79 begin_frame_source_(nullptr), | 82 begin_frame_source_(nullptr), |
80 contents_(contents), | |
81 routing_id_(contents->GetRoutingID()), | |
82 synchronous_input_handler_proxy_(nullptr), | 83 synchronous_input_handler_proxy_(nullptr), |
83 registered_with_client_(false), | 84 registered_with_client_(false), |
84 is_active_(true), | 85 is_active_(true), |
85 renderer_needs_begin_frames_(false), | 86 renderer_needs_begin_frames_(false), |
86 need_animate_input_(false), | 87 need_animate_input_(false), |
87 weak_ptr_factory_(this) { | 88 weak_ptr_factory_(this) { |
88 DCHECK(contents); | |
89 DCHECK_NE(routing_id_, MSG_ROUTING_NONE); | 89 DCHECK_NE(routing_id_, MSG_ROUTING_NONE); |
| 90 |
| 91 int process_id = rwhva_->GetRenderWidgetHost()->GetProcess()->GetID(); |
| 92 if (g_process_id == ChildProcessHost::kInvalidUniqueID) { |
| 93 g_process_id = process_id; |
| 94 } else { |
| 95 DCHECK_EQ(g_process_id, process_id); // Not multiprocess compatible. |
| 96 } |
| 97 |
| 98 SynchronousCompositorRegistry::GetInstance()->RegisterCompositor( |
| 99 routing_id_, this); |
90 } | 100 } |
91 | 101 |
92 SynchronousCompositorImpl::~SynchronousCompositorImpl() { | 102 SynchronousCompositorImpl::~SynchronousCompositorImpl() { |
93 DCHECK(!output_surface_); | 103 SynchronousCompositorRegistry::GetInstance()->UnregisterCompositor( |
94 DCHECK(!begin_frame_source_); | 104 routing_id_, this); |
95 DCHECK(!synchronous_input_handler_proxy_); | |
96 } | |
97 | |
98 void SynchronousCompositorImpl::SetClient( | |
99 SynchronousCompositorClient* compositor_client) { | |
100 DCHECK(CalledOnValidThread()); | |
101 DCHECK_IMPLIES(compositor_client, !compositor_client_); | |
102 DCHECK_IMPLIES(!compositor_client, compositor_client_); | |
103 | |
104 if (!compositor_client) { | |
105 SynchronousCompositorRegistry::GetInstance()->UnregisterCompositor( | |
106 routing_id_, this); | |
107 } | |
108 | |
109 compositor_client_ = compositor_client; | |
110 | |
111 // SetClient is essentially the constructor and destructor of | |
112 // SynchronousCompositorImpl. | |
113 if (compositor_client_) { | |
114 SynchronousCompositorRegistry::GetInstance()->RegisterCompositor( | |
115 routing_id_, this); | |
116 } | |
117 } | 105 } |
118 | 106 |
119 void SynchronousCompositorImpl::RegisterWithClient() { | 107 void SynchronousCompositorImpl::RegisterWithClient() { |
120 DCHECK(CalledOnValidThread()); | 108 DCHECK(CalledOnValidThread()); |
121 DCHECK(compositor_client_); | |
122 DCHECK(output_surface_); | 109 DCHECK(output_surface_); |
123 DCHECK(synchronous_input_handler_proxy_); | 110 DCHECK(synchronous_input_handler_proxy_); |
124 DCHECK(!registered_with_client_); | 111 DCHECK(!registered_with_client_); |
125 registered_with_client_ = true; | 112 registered_with_client_ = true; |
126 | 113 |
127 compositor_client_->DidInitializeCompositor(this); | 114 compositor_client_->DidInitializeCompositor(this); |
128 | 115 |
129 output_surface_->SetTreeActivationCallback( | 116 output_surface_->SetTreeActivationCallback( |
130 base::Bind(&SynchronousCompositorImpl::DidActivatePendingTree, | 117 base::Bind(&SynchronousCompositorImpl::DidActivatePendingTree, |
131 weak_ptr_factory_.GetWeakPtr())); | 118 weak_ptr_factory_.GetWeakPtr())); |
(...skipping 14 matching lines...) Expand all Loading... |
146 } | 133 } |
147 | 134 |
148 void SynchronousCompositorImpl::DidInitializeRendererObjects( | 135 void SynchronousCompositorImpl::DidInitializeRendererObjects( |
149 SynchronousCompositorOutputSurface* output_surface, | 136 SynchronousCompositorOutputSurface* output_surface, |
150 SynchronousCompositorExternalBeginFrameSource* begin_frame_source, | 137 SynchronousCompositorExternalBeginFrameSource* begin_frame_source, |
151 SynchronousInputHandlerProxy* synchronous_input_handler_proxy) { | 138 SynchronousInputHandlerProxy* synchronous_input_handler_proxy) { |
152 DCHECK(!output_surface_); | 139 DCHECK(!output_surface_); |
153 DCHECK(!begin_frame_source_); | 140 DCHECK(!begin_frame_source_); |
154 DCHECK(output_surface); | 141 DCHECK(output_surface); |
155 DCHECK(begin_frame_source); | 142 DCHECK(begin_frame_source); |
156 DCHECK(compositor_client_); | |
157 DCHECK(synchronous_input_handler_proxy); | 143 DCHECK(synchronous_input_handler_proxy); |
158 | 144 |
159 output_surface_ = output_surface; | 145 output_surface_ = output_surface; |
160 begin_frame_source_ = begin_frame_source; | 146 begin_frame_source_ = begin_frame_source; |
161 synchronous_input_handler_proxy_ = synchronous_input_handler_proxy; | 147 synchronous_input_handler_proxy_ = synchronous_input_handler_proxy; |
162 | 148 |
163 output_surface_->SetCompositor(this); | 149 output_surface_->SetCompositor(this); |
164 begin_frame_source_->SetCompositor(this); | 150 begin_frame_source_->SetCompositor(this); |
165 } | 151 } |
166 | 152 |
167 void SynchronousCompositorImpl::DidDestroyRendererObjects() { | 153 void SynchronousCompositorImpl::DidDestroyRendererObjects() { |
168 DCHECK(output_surface_); | 154 DCHECK(output_surface_); |
169 DCHECK(begin_frame_source_); | 155 DCHECK(begin_frame_source_); |
170 DCHECK(compositor_client_); | |
171 | 156 |
172 if (registered_with_client_) { | 157 if (registered_with_client_) { |
173 output_surface_->SetTreeActivationCallback(base::Closure()); | 158 output_surface_->SetTreeActivationCallback(base::Closure()); |
174 compositor_client_->DidDestroyCompositor(this); | 159 compositor_client_->DidDestroyCompositor(this); |
175 registered_with_client_ = false; | 160 registered_with_client_ = false; |
176 } | 161 } |
177 | 162 |
178 // This object is being destroyed, so remove pointers to it. | 163 // This object is being destroyed, so remove pointers to it. |
179 begin_frame_source_->SetCompositor(nullptr); | 164 begin_frame_source_->SetCompositor(nullptr); |
180 output_surface_->SetCompositor(nullptr); | 165 output_surface_->SetCompositor(nullptr); |
181 synchronous_input_handler_proxy_->SetOnlySynchronouslyAnimateRootFlings( | 166 synchronous_input_handler_proxy_->SetOnlySynchronouslyAnimateRootFlings( |
182 nullptr); | 167 nullptr); |
183 | 168 |
184 synchronous_input_handler_proxy_ = nullptr; | 169 synchronous_input_handler_proxy_ = nullptr; |
185 begin_frame_source_ = nullptr; | 170 begin_frame_source_ = nullptr; |
186 output_surface_ = nullptr; | 171 output_surface_ = nullptr; |
187 // Don't propogate this signal from one renderer to the next. | 172 // Don't propogate this signal from one renderer to the next. |
188 need_animate_input_ = false; | 173 need_animate_input_ = false; |
189 } | 174 } |
190 | 175 |
191 scoped_ptr<cc::CompositorFrame> SynchronousCompositorImpl::DemandDrawHw( | 176 scoped_ptr<cc::CompositorFrame> SynchronousCompositorImpl::DemandDrawHw( |
192 gfx::Size surface_size, | 177 gfx::Size surface_size, |
193 const gfx::Transform& transform, | 178 const gfx::Transform& transform, |
194 gfx::Rect viewport, | 179 gfx::Rect viewport, |
195 gfx::Rect clip, | 180 gfx::Rect clip, |
196 gfx::Rect viewport_rect_for_tile_priority, | 181 gfx::Rect viewport_rect_for_tile_priority, |
197 const gfx::Transform& transform_for_tile_priority) { | 182 const gfx::Transform& transform_for_tile_priority) { |
198 DCHECK(CalledOnValidThread()); | 183 DCHECK(CalledOnValidThread()); |
199 DCHECK(output_surface_); | 184 DCHECK(output_surface_); |
200 DCHECK(compositor_client_); | |
201 DCHECK(begin_frame_source_); | 185 DCHECK(begin_frame_source_); |
202 | 186 |
203 scoped_ptr<cc::CompositorFrame> frame = | 187 scoped_ptr<cc::CompositorFrame> frame = |
204 output_surface_->DemandDrawHw(surface_size, | 188 output_surface_->DemandDrawHw(surface_size, |
205 transform, | 189 transform, |
206 viewport, | 190 viewport, |
207 clip, | 191 clip, |
208 viewport_rect_for_tile_priority, | 192 viewport_rect_for_tile_priority, |
209 transform_for_tile_priority); | 193 transform_for_tile_priority); |
210 | 194 |
211 if (frame.get()) | 195 if (frame.get()) |
212 UpdateFrameMetaData(frame->metadata); | 196 UpdateFrameMetaData(frame->metadata); |
213 | 197 |
214 return frame.Pass(); | 198 return frame.Pass(); |
215 } | 199 } |
216 | 200 |
217 void SynchronousCompositorImpl::ReturnResources( | 201 void SynchronousCompositorImpl::ReturnResources( |
218 const cc::CompositorFrameAck& frame_ack) { | 202 const cc::CompositorFrameAck& frame_ack) { |
219 DCHECK(CalledOnValidThread()); | 203 DCHECK(CalledOnValidThread()); |
220 output_surface_->ReturnResources(frame_ack); | 204 output_surface_->ReturnResources(frame_ack); |
221 } | 205 } |
222 | 206 |
223 bool SynchronousCompositorImpl::DemandDrawSw(SkCanvas* canvas) { | 207 bool SynchronousCompositorImpl::DemandDrawSw(SkCanvas* canvas) { |
224 DCHECK(CalledOnValidThread()); | 208 DCHECK(CalledOnValidThread()); |
225 DCHECK(output_surface_); | 209 DCHECK(output_surface_); |
226 DCHECK(compositor_client_); | |
227 DCHECK(begin_frame_source_); | 210 DCHECK(begin_frame_source_); |
228 | 211 |
229 scoped_ptr<cc::CompositorFrame> frame = | 212 scoped_ptr<cc::CompositorFrame> frame = |
230 output_surface_->DemandDrawSw(canvas); | 213 output_surface_->DemandDrawSw(canvas); |
231 | 214 |
232 if (frame.get()) | 215 if (frame.get()) |
233 UpdateFrameMetaData(frame->metadata); | 216 UpdateFrameMetaData(frame->metadata); |
234 | 217 |
235 return !!frame.get(); | 218 return !!frame.get(); |
236 } | 219 } |
237 | 220 |
238 void SynchronousCompositorImpl::UpdateFrameMetaData( | 221 void SynchronousCompositorImpl::UpdateFrameMetaData( |
239 const cc::CompositorFrameMetadata& frame_metadata) { | 222 const cc::CompositorFrameMetadata& frame_metadata) { |
240 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( | 223 rwhva_->SynchronousFrameMetadata(frame_metadata); |
241 contents_->GetRenderWidgetHostView()); | |
242 if (rwhv) | |
243 rwhv->SynchronousFrameMetadata(frame_metadata); | |
244 DeliverMessages(); | 224 DeliverMessages(); |
245 } | 225 } |
246 | 226 |
247 void SynchronousCompositorImpl::SetMemoryPolicy(size_t bytes_limit) { | 227 void SynchronousCompositorImpl::SetMemoryPolicy(size_t bytes_limit) { |
248 DCHECK(CalledOnValidThread()); | 228 DCHECK(CalledOnValidThread()); |
249 DCHECK(output_surface_); | 229 DCHECK(output_surface_); |
250 | 230 |
251 size_t current_bytes_limit = output_surface_->GetMemoryPolicy(); | 231 size_t current_bytes_limit = output_surface_->GetMemoryPolicy(); |
252 output_surface_->SetMemoryPolicy(bytes_limit); | 232 output_surface_->SetMemoryPolicy(bytes_limit); |
253 | 233 |
254 if (bytes_limit && !current_bytes_limit) { | 234 if (bytes_limit && !current_bytes_limit) { |
255 g_factory.Get().CompositorInitializedHardwareDraw(); | 235 g_factory.Get().CompositorInitializedHardwareDraw(); |
256 } else if (!bytes_limit && current_bytes_limit) { | 236 } else if (!bytes_limit && current_bytes_limit) { |
257 g_factory.Get().CompositorReleasedHardwareDraw(); | 237 g_factory.Get().CompositorReleasedHardwareDraw(); |
258 } | 238 } |
259 } | 239 } |
260 | 240 |
261 void SynchronousCompositorImpl::PostInvalidate() { | 241 void SynchronousCompositorImpl::PostInvalidate() { |
262 DCHECK(CalledOnValidThread()); | 242 DCHECK(CalledOnValidThread()); |
263 DCHECK(compositor_client_); | |
264 if (registered_with_client_) | 243 if (registered_with_client_) |
265 compositor_client_->PostInvalidate(); | 244 compositor_client_->PostInvalidate(); |
266 } | 245 } |
267 | 246 |
268 void SynchronousCompositorImpl::DidChangeRootLayerScrollOffset( | 247 void SynchronousCompositorImpl::DidChangeRootLayerScrollOffset( |
269 const gfx::ScrollOffset& root_offset) { | 248 const gfx::ScrollOffset& root_offset) { |
270 DCHECK(CalledOnValidThread()); | 249 DCHECK(CalledOnValidThread()); |
271 if (!synchronous_input_handler_proxy_) | 250 if (!synchronous_input_handler_proxy_) |
272 return; | 251 return; |
273 synchronous_input_handler_proxy_->SynchronouslySetRootScrollOffset( | 252 synchronous_input_handler_proxy_->SynchronouslySetRootScrollOffset( |
(...skipping 26 matching lines...) Expand all Loading... |
300 // Make sure this is a BeginFrame that renderer side explicitly requested. | 279 // Make sure this is a BeginFrame that renderer side explicitly requested. |
301 // Otherwise it is possible renderer objects not initialized. | 280 // Otherwise it is possible renderer objects not initialized. |
302 RegisterWithClient(); | 281 RegisterWithClient(); |
303 DCHECK(registered_with_client_); | 282 DCHECK(registered_with_client_); |
304 } | 283 } |
305 if (begin_frame_source_) | 284 if (begin_frame_source_) |
306 begin_frame_source_->BeginFrame(args); | 285 begin_frame_source_->BeginFrame(args); |
307 } | 286 } |
308 | 287 |
309 void SynchronousCompositorImpl::UpdateNeedsBeginFrames() { | 288 void SynchronousCompositorImpl::UpdateNeedsBeginFrames() { |
310 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( | 289 rwhva_->OnSetNeedsBeginFrames(is_active_ && renderer_needs_begin_frames_); |
311 contents_->GetRenderWidgetHostView()); | |
312 if (rwhv) | |
313 rwhv->OnSetNeedsBeginFrames(is_active_ && renderer_needs_begin_frames_); | |
314 } | 290 } |
315 | 291 |
316 void SynchronousCompositorImpl::DidOverscroll( | 292 void SynchronousCompositorImpl::DidOverscroll( |
317 const DidOverscrollParams& params) { | 293 const DidOverscrollParams& params) { |
318 DCHECK(compositor_client_); | |
319 if (registered_with_client_) { | 294 if (registered_with_client_) { |
320 compositor_client_->DidOverscroll(params.accumulated_overscroll, | 295 compositor_client_->DidOverscroll(params.accumulated_overscroll, |
321 params.latest_overscroll_delta, | 296 params.latest_overscroll_delta, |
322 params.current_fling_velocity); | 297 params.current_fling_velocity); |
323 } | 298 } |
324 } | 299 } |
325 | 300 |
326 void SynchronousCompositorImpl::DidStopFlinging() { | 301 void SynchronousCompositorImpl::DidStopFlinging() { |
327 // It's important that the fling-end notification follow the same path as it | 302 // It's important that the fling-end notification follow the same path as it |
328 // takes on other platforms (using an IPC). This ensures consistent | 303 // takes on other platforms (using an IPC). This ensures consistent |
329 // bookkeeping at all stages of the input pipeline. | 304 // bookkeeping at all stages of the input pipeline. |
330 contents_->GetRenderProcessHost()->OnMessageReceived( | 305 rwhva_->GetRenderWidgetHost()->GetProcess()->OnMessageReceived( |
331 InputHostMsg_DidStopFlinging(routing_id_)); | 306 InputHostMsg_DidStopFlinging(routing_id_)); |
332 } | 307 } |
333 | 308 |
334 InputEventAckState SynchronousCompositorImpl::HandleInputEvent( | 309 InputEventAckState SynchronousCompositorImpl::HandleInputEvent( |
335 const blink::WebInputEvent& input_event) { | 310 const blink::WebInputEvent& input_event) { |
336 DCHECK(CalledOnValidThread()); | 311 DCHECK(CalledOnValidThread()); |
337 return g_factory.Get().synchronous_input_event_filter()->HandleInputEvent( | 312 return g_factory.Get().synchronous_input_event_filter()->HandleInputEvent( |
338 contents_->GetRoutingID(), input_event); | 313 routing_id_, input_event); |
339 } | 314 } |
340 | 315 |
341 void SynchronousCompositorImpl::DeliverMessages() { | 316 void SynchronousCompositorImpl::DeliverMessages() { |
342 ScopedVector<IPC::Message> messages; | 317 ScopedVector<IPC::Message> messages; |
343 output_surface_->GetMessagesToDeliver(&messages); | 318 output_surface_->GetMessagesToDeliver(&messages); |
344 RenderProcessHost* rph = contents_->GetRenderProcessHost(); | 319 RenderProcessHost* rph = rwhva_->GetRenderWidgetHost()->GetProcess(); |
345 for (ScopedVector<IPC::Message>::const_iterator i = messages.begin(); | 320 for (ScopedVector<IPC::Message>::const_iterator i = messages.begin(); |
346 i != messages.end(); | 321 i != messages.end(); |
347 ++i) { | 322 ++i) { |
348 rph->OnMessageReceived(**i); | 323 rph->OnMessageReceived(**i); |
349 } | 324 } |
350 } | 325 } |
351 | 326 |
352 void SynchronousCompositorImpl::DidActivatePendingTree() { | 327 void SynchronousCompositorImpl::DidActivatePendingTree() { |
353 DCHECK(compositor_client_); | |
354 if (registered_with_client_) | 328 if (registered_with_client_) |
355 compositor_client_->DidUpdateContent(); | 329 compositor_client_->DidUpdateContent(); |
356 DeliverMessages(); | 330 DeliverMessages(); |
357 } | 331 } |
358 | 332 |
359 void SynchronousCompositorImpl::SetNeedsSynchronousAnimateInput() { | 333 void SynchronousCompositorImpl::SetNeedsSynchronousAnimateInput() { |
360 DCHECK(CalledOnValidThread()); | 334 DCHECK(CalledOnValidThread()); |
361 DCHECK(compositor_client_); | |
362 if (!registered_with_client_) | 335 if (!registered_with_client_) |
363 return; | 336 return; |
364 need_animate_input_ = true; | 337 need_animate_input_ = true; |
365 compositor_client_->PostInvalidate(); | 338 compositor_client_->PostInvalidate(); |
366 } | 339 } |
367 | 340 |
368 void SynchronousCompositorImpl::UpdateRootLayerState( | 341 void SynchronousCompositorImpl::UpdateRootLayerState( |
369 const gfx::ScrollOffset& total_scroll_offset, | 342 const gfx::ScrollOffset& total_scroll_offset, |
370 const gfx::ScrollOffset& max_scroll_offset, | 343 const gfx::ScrollOffset& max_scroll_offset, |
371 const gfx::SizeF& scrollable_size, | 344 const gfx::SizeF& scrollable_size, |
372 float page_scale_factor, | 345 float page_scale_factor, |
373 float min_page_scale_factor, | 346 float min_page_scale_factor, |
374 float max_page_scale_factor) { | 347 float max_page_scale_factor) { |
375 DCHECK(CalledOnValidThread()); | 348 DCHECK(CalledOnValidThread()); |
376 DCHECK(compositor_client_); | |
377 | 349 |
378 if (registered_with_client_) { | 350 if (registered_with_client_) { |
379 // TODO(miletus): Pass in ScrollOffset. crbug.com/414283. | 351 // TODO(miletus): Pass in ScrollOffset. crbug.com/414283. |
380 compositor_client_->UpdateRootLayerState( | 352 compositor_client_->UpdateRootLayerState( |
381 gfx::ScrollOffsetToVector2dF(total_scroll_offset), | 353 gfx::ScrollOffsetToVector2dF(total_scroll_offset), |
382 gfx::ScrollOffsetToVector2dF(max_scroll_offset), | 354 gfx::ScrollOffsetToVector2dF(max_scroll_offset), |
383 scrollable_size, | 355 scrollable_size, |
384 page_scale_factor, | 356 page_scale_factor, |
385 min_page_scale_factor, | 357 min_page_scale_factor, |
386 max_page_scale_factor); | 358 max_page_scale_factor); |
387 } | 359 } |
388 } | 360 } |
389 | 361 |
390 // Not using base::NonThreadSafe as we want to enforce a more exacting threading | 362 // Not using base::NonThreadSafe as we want to enforce a more exacting threading |
391 // requirement: SynchronousCompositorImpl() must only be used on the UI thread. | 363 // requirement: SynchronousCompositorImpl() must only be used on the UI thread. |
392 bool SynchronousCompositorImpl::CalledOnValidThread() const { | 364 bool SynchronousCompositorImpl::CalledOnValidThread() const { |
393 return BrowserThread::CurrentlyOn(BrowserThread::UI); | 365 return BrowserThread::CurrentlyOn(BrowserThread::UI); |
394 } | 366 } |
395 | 367 |
396 // static | 368 // static |
397 void SynchronousCompositor::SetClientForWebContents( | 369 void SynchronousCompositor::SetClientForWebContents( |
398 WebContents* contents, | 370 WebContents* contents, |
399 SynchronousCompositorClient* client) { | 371 SynchronousCompositorClient* client) { |
400 DCHECK(contents); | 372 DCHECK(contents); |
401 if (client) { | 373 DCHECK(client); |
402 g_factory.Get(); // Ensure it's initialized. | 374 g_factory.Get(); // Ensure it's initialized. |
403 SynchronousCompositorImpl::CreateForWebContents(contents); | 375 WebContentsAndroid* web_contents_android = |
404 } | 376 static_cast<WebContentsImpl*>(contents)->GetWebContentsAndroid(); |
405 SynchronousCompositorImpl* instance = | 377 DCHECK(!web_contents_android->synchronous_compositor_client()); |
406 SynchronousCompositorImpl::FromWebContents(contents); | 378 web_contents_android->set_synchronous_compositor_client(client); |
407 DCHECK(instance); | |
408 instance->SetClient(client); | |
409 } | 379 } |
410 | 380 |
411 } // namespace content | 381 } // namespace content |
OLD | NEW |