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

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

Powered by Google App Engine
This is Rietveld 408576698