Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(314)

Side by Side Diff: content/browser/android/in_process/synchronous_compositor_impl.cc

Issue 817603002: cc: Make scheduling be driven by vsync for android webview. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 SynchronousCompositorExternalBeginFrameSource* begin_frame_source) { 112 SynchronousCompositorExternalBeginFrameSource* begin_frame_source) {
113 DCHECK(!output_surface_); 113 DCHECK(!output_surface_);
114 DCHECK(!begin_frame_source_); 114 DCHECK(!begin_frame_source_);
115 DCHECK(output_surface); 115 DCHECK(output_surface);
116 DCHECK(begin_frame_source); 116 DCHECK(begin_frame_source);
117 DCHECK(compositor_client_); 117 DCHECK(compositor_client_);
118 118
119 output_surface_ = output_surface; 119 output_surface_ = output_surface;
120 begin_frame_source_ = begin_frame_source; 120 begin_frame_source_ = begin_frame_source;
121 121
122 begin_frame_source_->SetCompositor(this); 122 output_surface_->SetInvalidateCallback(
123 output_surface_->SetBeginFrameSource(begin_frame_source_); 123 base::Bind(&SynchronousCompositorImpl::DidInvalidateOutputSurface,
124 weak_ptr_factory_.GetWeakPtr()));
124 output_surface_->SetTreeActivationCallback( 125 output_surface_->SetTreeActivationCallback(
125 base::Bind(&SynchronousCompositorImpl::DidActivatePendingTree, 126 base::Bind(&SynchronousCompositorImpl::DidActivatePendingTree,
126 weak_ptr_factory_.GetWeakPtr())); 127 weak_ptr_factory_.GetWeakPtr()));
127 NeedsBeginFramesChanged(); 128 NeedsBeginFramesChanged();
128 compositor_client_->DidInitializeCompositor(this); 129 compositor_client_->DidInitializeCompositor(this);
129 } 130 }
130 131
131 void SynchronousCompositorImpl::DidDestroyRendererObjects() { 132 void SynchronousCompositorImpl::DidDestroyRendererObjects() {
132 DCHECK(output_surface_); 133 DCHECK(output_surface_);
133 DCHECK(begin_frame_source_); 134 DCHECK(begin_frame_source_);
134 135
135 begin_frame_source_->SetCompositor(nullptr); 136 begin_frame_source_->SetCompositor(nullptr);
136 output_surface_->SetBeginFrameSource(nullptr);
137 if (compositor_client_) 137 if (compositor_client_)
138 compositor_client_->DidDestroyCompositor(this); 138 compositor_client_->DidDestroyCompositor(this);
139 compositor_client_ = nullptr; 139 compositor_client_ = nullptr;
140 output_surface_ = nullptr; 140 output_surface_ = nullptr;
141 begin_frame_source_ = nullptr; 141 begin_frame_source_ = nullptr;
142 } 142 }
143 143
144 void SynchronousCompositorImpl::NotifyDidDestroyCompositorToClient() { 144 void SynchronousCompositorImpl::NotifyDidDestroyCompositorToClient() {
145 if (compositor_client_) 145 if (compositor_client_)
146 compositor_client_->DidDestroyCompositor(this); 146 compositor_client_->DidDestroyCompositor(this);
(...skipping 29 matching lines...) Expand all
176 gfx::Rect viewport_rect_for_tile_priority, 176 gfx::Rect viewport_rect_for_tile_priority,
177 const gfx::Transform& transform_for_tile_priority) { 177 const gfx::Transform& transform_for_tile_priority) {
178 DCHECK(CalledOnValidThread()); 178 DCHECK(CalledOnValidThread());
179 DCHECK(output_surface_); 179 DCHECK(output_surface_);
180 DCHECK(!invoking_composite_); 180 DCHECK(!invoking_composite_);
181 DCHECK(compositor_client_); 181 DCHECK(compositor_client_);
182 DCHECK(begin_frame_source_); 182 DCHECK(begin_frame_source_);
183 183
184 base::AutoReset<bool> invoking_composite_resetter(&invoking_composite_, 184 base::AutoReset<bool> invoking_composite_resetter(&invoking_composite_,
185 true); 185 true);
186
187 // This is to handle draws that are not initiated by the platform.
188 // Platform draws happen synchronously after OnVSync is called.
189 if (!begin_frame_source_->InsideBeginFrame())
190 begin_frame_source_->SendBeginFrameNow();
191
186 scoped_ptr<cc::CompositorFrame> frame = 192 scoped_ptr<cc::CompositorFrame> frame =
187 output_surface_->DemandDrawHw(surface_size, 193 output_surface_->DemandDrawHw(surface_size,
188 transform, 194 transform,
189 viewport, 195 viewport,
190 clip, 196 clip,
191 viewport_rect_for_tile_priority, 197 viewport_rect_for_tile_priority,
192 transform_for_tile_priority); 198 transform_for_tile_priority);
199
200 DCHECK(!begin_frame_source_->InsideBeginFrame());
201
193 if (frame.get()) 202 if (frame.get())
194 UpdateFrameMetaData(frame->metadata); 203 UpdateFrameMetaData(frame->metadata);
195 204
196 compositor_client_->SetContinuousInvalidate(
197 begin_frame_source_->NeedsBeginFrames());
198
199 return frame.Pass(); 205 return frame.Pass();
200 } 206 }
201 207
202 void SynchronousCompositorImpl::ReturnResources( 208 void SynchronousCompositorImpl::ReturnResources(
203 const cc::CompositorFrameAck& frame_ack) { 209 const cc::CompositorFrameAck& frame_ack) {
204 DCHECK(CalledOnValidThread()); 210 DCHECK(CalledOnValidThread());
205 output_surface_->ReturnResources(frame_ack); 211 output_surface_->ReturnResources(frame_ack);
206 } 212 }
207 213
208 bool SynchronousCompositorImpl::DemandDrawSw(SkCanvas* canvas) { 214 bool SynchronousCompositorImpl::DemandDrawSw(SkCanvas* canvas) {
209 DCHECK(CalledOnValidThread()); 215 DCHECK(CalledOnValidThread());
210 DCHECK(output_surface_); 216 DCHECK(output_surface_);
211 DCHECK(!invoking_composite_); 217 DCHECK(!invoking_composite_);
212 DCHECK(compositor_client_); 218 DCHECK(compositor_client_);
213 DCHECK(begin_frame_source_); 219 DCHECK(begin_frame_source_);
214 220
215 base::AutoReset<bool> invoking_composite_resetter(&invoking_composite_, 221 base::AutoReset<bool> invoking_composite_resetter(&invoking_composite_,
216 true); 222 true);
223
224 // This is to handle draws that are not initiated by the platform.
225 // Platform draws happen synchronously after OnVSync is called.
226 if (!begin_frame_source_->InsideBeginFrame())
227 begin_frame_source_->SendBeginFrameNow();
228
217 scoped_ptr<cc::CompositorFrame> frame = 229 scoped_ptr<cc::CompositorFrame> frame =
218 output_surface_->DemandDrawSw(canvas); 230 output_surface_->DemandDrawSw(canvas);
231
232 DCHECK(!begin_frame_source_->InsideBeginFrame());
233
219 if (frame.get()) 234 if (frame.get())
220 UpdateFrameMetaData(frame->metadata); 235 UpdateFrameMetaData(frame->metadata);
221 236
222 compositor_client_->SetContinuousInvalidate(
223 begin_frame_source_->NeedsBeginFrames());
224
225 return !!frame.get(); 237 return !!frame.get();
226 } 238 }
227 239
228 void SynchronousCompositorImpl::UpdateFrameMetaData( 240 void SynchronousCompositorImpl::UpdateFrameMetaData(
229 const cc::CompositorFrameMetadata& frame_metadata) { 241 const cc::CompositorFrameMetadata& frame_metadata) {
230 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( 242 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>(
231 contents_->GetRenderWidgetHostView()); 243 contents_->GetRenderWidgetHostView());
232 if (rwhv) 244 if (rwhv)
233 rwhv->SynchronousFrameMetadata(frame_metadata); 245 rwhv->SynchronousFrameMetadata(frame_metadata);
234 DeliverMessages(); 246 DeliverMessages();
235 } 247 }
236 248
237 void SynchronousCompositorImpl::SetMemoryPolicy(size_t bytes_limit) { 249 void SynchronousCompositorImpl::SetMemoryPolicy(size_t bytes_limit) {
238 DCHECK(CalledOnValidThread()); 250 DCHECK(CalledOnValidThread());
239 DCHECK(output_surface_); 251 DCHECK(output_surface_);
240 252
241 output_surface_->SetMemoryPolicy(bytes_limit); 253 output_surface_->SetMemoryPolicy(bytes_limit);
242 } 254 }
243 255
256 void SynchronousCompositorImpl::NeedsBeginFramesChanged() const {
257 compositor_client_->SetNeedsVSyncs(begin_frame_source_->NeedsBeginFrames());
258 }
259
244 void SynchronousCompositorImpl::DidChangeRootLayerScrollOffset() { 260 void SynchronousCompositorImpl::DidChangeRootLayerScrollOffset() {
245 if (input_handler_) 261 if (input_handler_)
246 input_handler_->OnRootLayerDelegatedScrollOffsetChanged(); 262 input_handler_->OnRootLayerDelegatedScrollOffsetChanged();
247 } 263 }
248 264
265 void SynchronousCompositorImpl::OnVSync(base::TimeTicks frame_time,
266 base::TimeDelta vsync_period) {
267 DCHECK(CalledOnValidThread());
268 begin_frame_source_->SendBeginFrame(frame_time, vsync_period);
269 }
270
249 void SynchronousCompositorImpl::SetInputHandler( 271 void SynchronousCompositorImpl::SetInputHandler(
250 cc::InputHandler* input_handler) { 272 cc::InputHandler* input_handler) {
251 DCHECK(CalledOnValidThread()); 273 DCHECK(CalledOnValidThread());
252 274
253 if (input_handler_) 275 if (input_handler_)
254 input_handler_->SetRootLayerScrollOffsetDelegate(NULL); 276 input_handler_->SetRootLayerScrollOffsetDelegate(NULL);
255 277
256 input_handler_ = input_handler; 278 input_handler_ = input_handler;
257 279
258 if (input_handler_) 280 if (input_handler_)
259 input_handler_->SetRootLayerScrollOffsetDelegate(this); 281 input_handler_->SetRootLayerScrollOffsetDelegate(this);
260 } 282 }
261 283
262 void SynchronousCompositorImpl::DidOverscroll( 284 void SynchronousCompositorImpl::DidOverscroll(
263 const DidOverscrollParams& params) { 285 const DidOverscrollParams& params) {
264 if (compositor_client_) { 286 if (compositor_client_) {
265 compositor_client_->DidOverscroll(params.accumulated_overscroll, 287 compositor_client_->DidOverscroll(params.accumulated_overscroll,
266 params.latest_overscroll_delta, 288 params.latest_overscroll_delta,
267 params.current_fling_velocity); 289 params.current_fling_velocity);
268 } 290 }
269 } 291 }
270 292
271 void SynchronousCompositorImpl::DidStopFlinging() { 293 void SynchronousCompositorImpl::DidStopFlinging() {
272 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( 294 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>(
273 contents_->GetRenderWidgetHostView()); 295 contents_->GetRenderWidgetHostView());
274 if (rwhv) 296 if (rwhv)
275 rwhv->DidStopFlinging(); 297 rwhv->DidStopFlinging();
276 } 298 }
277 299
278 void SynchronousCompositorImpl::NeedsBeginFramesChanged() const {
279 DCHECK(CalledOnValidThread());
280 DCHECK(begin_frame_source_);
281 if (invoking_composite_)
282 return;
283
284 if (compositor_client_) {
285 compositor_client_->SetContinuousInvalidate(
286 begin_frame_source_->NeedsBeginFrames());
287 }
288 }
289
290 InputEventAckState SynchronousCompositorImpl::HandleInputEvent( 300 InputEventAckState SynchronousCompositorImpl::HandleInputEvent(
291 const blink::WebInputEvent& input_event) { 301 const blink::WebInputEvent& input_event) {
292 DCHECK(CalledOnValidThread()); 302 DCHECK(CalledOnValidThread());
293 return g_factory.Get().synchronous_input_event_filter()->HandleInputEvent( 303 return g_factory.Get().synchronous_input_event_filter()->HandleInputEvent(
294 contents_->GetRoutingID(), input_event); 304 contents_->GetRoutingID(), input_event);
295 } 305 }
296 306
297 void SynchronousCompositorImpl::DeliverMessages() { 307 void SynchronousCompositorImpl::DeliverMessages() {
298 ScopedVector<IPC::Message> messages; 308 ScopedVector<IPC::Message> messages;
299 output_surface_->GetMessagesToDeliver(&messages); 309 output_surface_->GetMessagesToDeliver(&messages);
300 RenderProcessHost* rph = contents_->GetRenderProcessHost(); 310 RenderProcessHost* rph = contents_->GetRenderProcessHost();
301 for (ScopedVector<IPC::Message>::const_iterator i = messages.begin(); 311 for (ScopedVector<IPC::Message>::const_iterator i = messages.begin();
302 i != messages.end(); 312 i != messages.end();
303 ++i) { 313 ++i) {
304 rph->OnMessageReceived(**i); 314 rph->OnMessageReceived(**i);
305 } 315 }
306 } 316 }
307 317
318 void SynchronousCompositorImpl::DidInvalidateOutputSurface() {
319 // Ignore invalidations while inside a draw.
320 if (compositor_client_ && !invoking_composite_)
321 compositor_client_->PostInvalidate();
322 }
323
308 void SynchronousCompositorImpl::DidActivatePendingTree() { 324 void SynchronousCompositorImpl::DidActivatePendingTree() {
309 if (compositor_client_) 325 if (compositor_client_)
310 compositor_client_->DidUpdateContent(); 326 compositor_client_->DidUpdateContent();
311 } 327 }
312 328
313 gfx::ScrollOffset SynchronousCompositorImpl::GetTotalScrollOffset() { 329 gfx::ScrollOffset SynchronousCompositorImpl::GetTotalScrollOffset() {
314 DCHECK(CalledOnValidThread()); 330 DCHECK(CalledOnValidThread());
315 if (compositor_client_) { 331 if (compositor_client_) {
316 // TODO(miletus): Make GetTotalRootLayerScrollOffset return 332 // TODO(miletus): Make GetTotalRootLayerScrollOffset return
317 // ScrollOffset. crbug.com/414283. 333 // ScrollOffset. crbug.com/414283.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 g_factory.Get(); // Ensure it's initialized. 380 g_factory.Get(); // Ensure it's initialized.
365 SynchronousCompositorImpl::CreateForWebContents(contents); 381 SynchronousCompositorImpl::CreateForWebContents(contents);
366 } 382 }
367 SynchronousCompositorImpl* instance = 383 SynchronousCompositorImpl* instance =
368 SynchronousCompositorImpl::FromWebContents(contents); 384 SynchronousCompositorImpl::FromWebContents(contents);
369 DCHECK(instance); 385 DCHECK(instance);
370 instance->SetClient(client); 386 instance->SetClient(client);
371 } 387 }
372 388
373 } // namespace content 389 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698