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

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

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

Powered by Google App Engine
This is Rietveld 408576698