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

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: Small fix after rebase. Created 5 years, 9 months 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 } 67 }
68 68
69 SynchronousCompositorImpl::SynchronousCompositorImpl(WebContents* contents) 69 SynchronousCompositorImpl::SynchronousCompositorImpl(WebContents* contents)
70 : compositor_client_(NULL), 70 : compositor_client_(NULL),
71 output_surface_(NULL), 71 output_surface_(NULL),
72 begin_frame_source_(nullptr), 72 begin_frame_source_(nullptr),
73 contents_(contents), 73 contents_(contents),
74 routing_id_(contents->GetRoutingID()), 74 routing_id_(contents->GetRoutingID()),
75 input_handler_(NULL), 75 input_handler_(NULL),
76 invoking_composite_(false), 76 invoking_composite_(false),
77 is_active_(false),
78 renderer_needs_begin_frames_(false),
77 weak_ptr_factory_(this) { 79 weak_ptr_factory_(this) {
78 DCHECK(contents); 80 DCHECK(contents);
79 DCHECK_NE(routing_id_, MSG_ROUTING_NONE); 81 DCHECK_NE(routing_id_, MSG_ROUTING_NONE);
80 SynchronousCompositorRegistry::GetInstance()->RegisterCompositor(routing_id_, 82 SynchronousCompositorRegistry::GetInstance()->RegisterCompositor(routing_id_,
81 this); 83 this);
82 } 84 }
83 85
84 SynchronousCompositorImpl::~SynchronousCompositorImpl() { 86 SynchronousCompositorImpl::~SynchronousCompositorImpl() {
85 SynchronousCompositorRegistry::GetInstance()->UnregisterCompositor( 87 SynchronousCompositorRegistry::GetInstance()->UnregisterCompositor(
86 routing_id_, this); 88 routing_id_, this);
(...skipping 26 matching lines...) Expand all
113 DCHECK(!output_surface_); 115 DCHECK(!output_surface_);
114 DCHECK(!begin_frame_source_); 116 DCHECK(!begin_frame_source_);
115 DCHECK(output_surface); 117 DCHECK(output_surface);
116 DCHECK(begin_frame_source); 118 DCHECK(begin_frame_source);
117 DCHECK(compositor_client_); 119 DCHECK(compositor_client_);
118 120
119 output_surface_ = output_surface; 121 output_surface_ = output_surface;
120 begin_frame_source_ = begin_frame_source; 122 begin_frame_source_ = begin_frame_source;
121 123
122 begin_frame_source_->SetCompositor(this); 124 begin_frame_source_->SetCompositor(this);
123 output_surface_->SetBeginFrameSource(begin_frame_source_); 125 output_surface_->SetCompositor(this);
126
124 output_surface_->SetTreeActivationCallback( 127 output_surface_->SetTreeActivationCallback(
125 base::Bind(&SynchronousCompositorImpl::DidActivatePendingTree, 128 base::Bind(&SynchronousCompositorImpl::DidActivatePendingTree,
126 weak_ptr_factory_.GetWeakPtr())); 129 weak_ptr_factory_.GetWeakPtr()));
127 NeedsBeginFramesChanged(); 130
131 OnNeedsBeginFramesChange(begin_frame_source_->NeedsBeginFrames());
132
128 compositor_client_->DidInitializeCompositor(this); 133 compositor_client_->DidInitializeCompositor(this);
129 } 134 }
130 135
131 void SynchronousCompositorImpl::DidDestroyRendererObjects() { 136 void SynchronousCompositorImpl::DidDestroyRendererObjects() {
132 DCHECK(output_surface_); 137 DCHECK(output_surface_);
133 DCHECK(begin_frame_source_); 138 DCHECK(begin_frame_source_);
134 139
135 begin_frame_source_->SetCompositor(nullptr); 140 begin_frame_source_->SetCompositor(nullptr);
136 output_surface_->SetBeginFrameSource(nullptr); 141 output_surface_->SetCompositor(nullptr);
137 if (compositor_client_) 142 if (compositor_client_)
138 compositor_client_->DidDestroyCompositor(this); 143 compositor_client_->DidDestroyCompositor(this);
139 compositor_client_ = nullptr; 144 compositor_client_ = nullptr;
140 output_surface_ = nullptr; 145 output_surface_ = nullptr;
141 begin_frame_source_ = nullptr; 146 begin_frame_source_ = nullptr;
142 } 147 }
143 148
144 void SynchronousCompositorImpl::NotifyDidDestroyCompositorToClient() { 149 void SynchronousCompositorImpl::NotifyDidDestroyCompositorToClient() {
145 if (compositor_client_) 150 if (compositor_client_)
146 compositor_client_->DidDestroyCompositor(this); 151 compositor_client_->DidDestroyCompositor(this);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 gfx::Rect viewport_rect_for_tile_priority, 185 gfx::Rect viewport_rect_for_tile_priority,
181 const gfx::Transform& transform_for_tile_priority) { 186 const gfx::Transform& transform_for_tile_priority) {
182 DCHECK(CalledOnValidThread()); 187 DCHECK(CalledOnValidThread());
183 DCHECK(output_surface_); 188 DCHECK(output_surface_);
184 DCHECK(!invoking_composite_); 189 DCHECK(!invoking_composite_);
185 DCHECK(compositor_client_); 190 DCHECK(compositor_client_);
186 DCHECK(begin_frame_source_); 191 DCHECK(begin_frame_source_);
187 192
188 base::AutoReset<bool> invoking_composite_resetter(&invoking_composite_, 193 base::AutoReset<bool> invoking_composite_resetter(&invoking_composite_,
189 true); 194 true);
195
190 scoped_ptr<cc::CompositorFrame> frame = 196 scoped_ptr<cc::CompositorFrame> frame =
191 output_surface_->DemandDrawHw(surface_size, 197 output_surface_->DemandDrawHw(surface_size,
192 transform, 198 transform,
193 viewport, 199 viewport,
194 clip, 200 clip,
195 viewport_rect_for_tile_priority, 201 viewport_rect_for_tile_priority,
196 transform_for_tile_priority); 202 transform_for_tile_priority);
203
197 if (frame.get()) 204 if (frame.get())
198 UpdateFrameMetaData(frame->metadata); 205 UpdateFrameMetaData(frame->metadata);
199 206
200 compositor_client_->SetContinuousInvalidate(
201 begin_frame_source_->NeedsBeginFrames());
202
203 return frame.Pass(); 207 return frame.Pass();
204 } 208 }
205 209
206 void SynchronousCompositorImpl::ReturnResources( 210 void SynchronousCompositorImpl::ReturnResources(
207 const cc::CompositorFrameAck& frame_ack) { 211 const cc::CompositorFrameAck& frame_ack) {
208 DCHECK(CalledOnValidThread()); 212 DCHECK(CalledOnValidThread());
209 output_surface_->ReturnResources(frame_ack); 213 output_surface_->ReturnResources(frame_ack);
210 } 214 }
211 215
212 bool SynchronousCompositorImpl::DemandDrawSw(SkCanvas* canvas) { 216 bool SynchronousCompositorImpl::DemandDrawSw(SkCanvas* canvas) {
213 DCHECK(CalledOnValidThread()); 217 DCHECK(CalledOnValidThread());
214 DCHECK(output_surface_); 218 DCHECK(output_surface_);
215 DCHECK(!invoking_composite_); 219 DCHECK(!invoking_composite_);
boliu 2015/03/20 18:59:06 invoking_composite_ isn't really needed anymore (e
sunnyps 2015/03/20 22:48:39 Done.
216 DCHECK(compositor_client_); 220 DCHECK(compositor_client_);
217 DCHECK(begin_frame_source_); 221 DCHECK(begin_frame_source_);
218 222
219 base::AutoReset<bool> invoking_composite_resetter(&invoking_composite_, 223 base::AutoReset<bool> invoking_composite_resetter(&invoking_composite_,
220 true); 224 true);
225
221 scoped_ptr<cc::CompositorFrame> frame = 226 scoped_ptr<cc::CompositorFrame> frame =
222 output_surface_->DemandDrawSw(canvas); 227 output_surface_->DemandDrawSw(canvas);
228
223 if (frame.get()) 229 if (frame.get())
224 UpdateFrameMetaData(frame->metadata); 230 UpdateFrameMetaData(frame->metadata);
225 231
226 compositor_client_->SetContinuousInvalidate(
227 begin_frame_source_->NeedsBeginFrames());
228
229 return !!frame.get(); 232 return !!frame.get();
230 } 233 }
231 234
232 void SynchronousCompositorImpl::UpdateFrameMetaData( 235 void SynchronousCompositorImpl::UpdateFrameMetaData(
233 const cc::CompositorFrameMetadata& frame_metadata) { 236 const cc::CompositorFrameMetadata& frame_metadata) {
234 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( 237 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>(
235 contents_->GetRenderWidgetHostView()); 238 contents_->GetRenderWidgetHostView());
236 if (rwhv) 239 if (rwhv)
237 rwhv->SynchronousFrameMetadata(frame_metadata); 240 rwhv->SynchronousFrameMetadata(frame_metadata);
238 DeliverMessages(); 241 DeliverMessages();
239 } 242 }
240 243
241 void SynchronousCompositorImpl::SetMemoryPolicy(size_t bytes_limit) { 244 void SynchronousCompositorImpl::SetMemoryPolicy(size_t bytes_limit) {
242 DCHECK(CalledOnValidThread()); 245 DCHECK(CalledOnValidThread());
243 DCHECK(output_surface_); 246 DCHECK(output_surface_);
244 247
245 output_surface_->SetMemoryPolicy(bytes_limit); 248 output_surface_->SetMemoryPolicy(bytes_limit);
246 } 249 }
247 250
251 void SynchronousCompositorImpl::PostInvalidate() {
252 DCHECK(CalledOnValidThread());
253 DCHECK(compositor_client_);
254 compositor_client_->PostInvalidate();
255 }
256
248 void SynchronousCompositorImpl::DidChangeRootLayerScrollOffset() { 257 void SynchronousCompositorImpl::DidChangeRootLayerScrollOffset() {
249 if (input_handler_) 258 if (input_handler_)
250 input_handler_->OnRootLayerDelegatedScrollOffsetChanged(); 259 input_handler_->OnRootLayerDelegatedScrollOffsetChanged();
251 } 260 }
252 261
262 void SynchronousCompositorImpl::SetIsActive(bool is_active) {
263 TRACE_EVENT1("cc", "SynchronousCompositorImpl::SetIsActive", "is_active",
264 is_active);
265 is_active_ = is_active;
266 UpdateNeedsBeginFrames();
267 }
268
269 void SynchronousCompositorImpl::OnNeedsBeginFramesChange(
270 bool needs_begin_frames) {
271 renderer_needs_begin_frames_ = needs_begin_frames;
272 UpdateNeedsBeginFrames();
273 }
274
275 void SynchronousCompositorImpl::SendBeginFrame(const cc::BeginFrameArgs& args) {
276 if (begin_frame_source_)
277 begin_frame_source_->SendBeginFrame(args);
278 }
279
280 void SynchronousCompositorImpl::UpdateNeedsBeginFrames() {
281 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>(
282 contents_->GetRenderWidgetHostView());
283 if (rwhv)
284 rwhv->OnSetNeedsBeginFrames(is_active_ && renderer_needs_begin_frames_);
285 }
286
253 void SynchronousCompositorImpl::SetInputHandler( 287 void SynchronousCompositorImpl::SetInputHandler(
254 cc::InputHandler* input_handler) { 288 cc::InputHandler* input_handler) {
255 DCHECK(CalledOnValidThread()); 289 DCHECK(CalledOnValidThread());
256 290
257 if (input_handler_) 291 if (input_handler_)
258 input_handler_->SetRootLayerScrollOffsetDelegate(NULL); 292 input_handler_->SetRootLayerScrollOffsetDelegate(NULL);
259 293
260 input_handler_ = input_handler; 294 input_handler_ = input_handler;
261 295
262 if (input_handler_) 296 if (input_handler_)
263 input_handler_->SetRootLayerScrollOffsetDelegate(this); 297 input_handler_->SetRootLayerScrollOffsetDelegate(this);
264 } 298 }
265 299
266 void SynchronousCompositorImpl::DidOverscroll( 300 void SynchronousCompositorImpl::DidOverscroll(
267 const DidOverscrollParams& params) { 301 const DidOverscrollParams& params) {
268 if (compositor_client_) { 302 if (compositor_client_) {
269 compositor_client_->DidOverscroll(params.accumulated_overscroll, 303 compositor_client_->DidOverscroll(params.accumulated_overscroll,
270 params.latest_overscroll_delta, 304 params.latest_overscroll_delta,
271 params.current_fling_velocity); 305 params.current_fling_velocity);
272 } 306 }
273 } 307 }
274 308
275 void SynchronousCompositorImpl::DidStopFlinging() { 309 void SynchronousCompositorImpl::DidStopFlinging() {
276 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( 310 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>(
277 contents_->GetRenderWidgetHostView()); 311 contents_->GetRenderWidgetHostView());
278 if (rwhv) 312 if (rwhv)
279 rwhv->DidStopFlinging(); 313 rwhv->DidStopFlinging();
280 } 314 }
281 315
282 void SynchronousCompositorImpl::NeedsBeginFramesChanged() const {
283 DCHECK(CalledOnValidThread());
284 DCHECK(begin_frame_source_);
285 if (invoking_composite_)
286 return;
287
288 if (compositor_client_) {
289 compositor_client_->SetContinuousInvalidate(
290 begin_frame_source_->NeedsBeginFrames());
291 }
292 }
293
294 InputEventAckState SynchronousCompositorImpl::HandleInputEvent( 316 InputEventAckState SynchronousCompositorImpl::HandleInputEvent(
295 const blink::WebInputEvent& input_event) { 317 const blink::WebInputEvent& input_event) {
296 DCHECK(CalledOnValidThread()); 318 DCHECK(CalledOnValidThread());
297 return g_factory.Get().synchronous_input_event_filter()->HandleInputEvent( 319 return g_factory.Get().synchronous_input_event_filter()->HandleInputEvent(
298 contents_->GetRoutingID(), input_event); 320 contents_->GetRoutingID(), input_event);
299 } 321 }
300 322
301 void SynchronousCompositorImpl::DeliverMessages() { 323 void SynchronousCompositorImpl::DeliverMessages() {
302 ScopedVector<IPC::Message> messages; 324 ScopedVector<IPC::Message> messages;
303 output_surface_->GetMessagesToDeliver(&messages); 325 output_surface_->GetMessagesToDeliver(&messages);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 g_factory.Get(); // Ensure it's initialized. 390 g_factory.Get(); // Ensure it's initialized.
369 SynchronousCompositorImpl::CreateForWebContents(contents); 391 SynchronousCompositorImpl::CreateForWebContents(contents);
370 } 392 }
371 SynchronousCompositorImpl* instance = 393 SynchronousCompositorImpl* instance =
372 SynchronousCompositorImpl::FromWebContents(contents); 394 SynchronousCompositorImpl::FromWebContents(contents);
373 DCHECK(instance); 395 DCHECK(instance);
374 instance->SetClient(client); 396 instance->SetClient(client);
375 } 397 }
376 398
377 } // namespace content 399 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698