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