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

Side by Side Diff: ui/compositor/compositor.cc

Issue 996453002: Allow ui::Compositor to disable commits during tab-switch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleaned up version 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/compositor/compositor.h" 5 #include "ui/compositor/compositor.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <deque> 8 #include <deque>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 29 matching lines...) Expand all
40 const double kTestRefreshRate = 200.0; 40 const double kTestRefreshRate = 200.0;
41 41
42 const int kCompositorLockTimeoutMs = 67; 42 const int kCompositorLockTimeoutMs = 67;
43 43
44 } // namespace 44 } // namespace
45 45
46 namespace ui { 46 namespace ui {
47 47
48 CompositorLock::CompositorLock(Compositor* compositor) 48 CompositorLock::CompositorLock(Compositor* compositor)
49 : compositor_(compositor) { 49 : compositor_(compositor) {
50 compositor_->task_runner_->PostDelayedTask( 50 if (compositor_->locks_will_time_out_) {
51 FROM_HERE, 51 compositor_->task_runner_->PostDelayedTask(
52 base::Bind(&CompositorLock::CancelLock, AsWeakPtr()), 52 FROM_HERE,
53 base::TimeDelta::FromMilliseconds(kCompositorLockTimeoutMs)); 53 base::Bind(&CompositorLock::CancelLock, AsWeakPtr()),
54 base::TimeDelta::FromMilliseconds(kCompositorLockTimeoutMs));
55 }
54 } 56 }
55 57
56 CompositorLock::~CompositorLock() { 58 CompositorLock::~CompositorLock() {
57 CancelLock(); 59 CancelLock();
58 } 60 }
59 61
60 void CompositorLock::CancelLock() { 62 void CompositorLock::CancelLock() {
61 if (!compositor_) 63 if (!compositor_)
62 return; 64 return;
63 compositor_->UnlockCompositor(); 65 compositor_->UnlockCompositor();
64 compositor_ = NULL; 66 compositor_ = NULL;
65 } 67 }
66 68
67 Compositor::Compositor(gfx::AcceleratedWidget widget, 69 Compositor::Compositor(gfx::AcceleratedWidget widget,
68 ui::ContextFactory* context_factory, 70 ui::ContextFactory* context_factory,
69 scoped_refptr<base::SingleThreadTaskRunner> task_runner) 71 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
70 : context_factory_(context_factory), 72 : context_factory_(context_factory),
71 root_layer_(NULL), 73 root_layer_(NULL),
72 widget_(widget), 74 widget_(widget),
73 surface_id_allocator_(context_factory->CreateSurfaceIdAllocator()), 75 surface_id_allocator_(context_factory->CreateSurfaceIdAllocator()),
74 task_runner_(task_runner), 76 task_runner_(task_runner),
75 vsync_manager_(new CompositorVSyncManager()), 77 vsync_manager_(new CompositorVSyncManager()),
76 device_scale_factor_(0.0f), 78 device_scale_factor_(0.0f),
77 last_started_frame_(0), 79 last_started_frame_(0),
78 last_ended_frame_(0), 80 last_ended_frame_(0),
79 disable_schedule_composite_(false), 81 locks_will_time_out_(true),
80 compositor_lock_(NULL), 82 compositor_lock_(NULL),
81 layer_animator_collection_(this), 83 layer_animator_collection_(this),
82 weak_ptr_factory_(this) { 84 weak_ptr_factory_(this) {
83 root_web_layer_ = cc::Layer::Create(); 85 root_web_layer_ = cc::Layer::Create();
84 86
85 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 87 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
86 88
87 cc::LayerTreeSettings settings; 89 cc::LayerTreeSettings settings;
88 // When impl-side painting is enabled, this will ensure PictureLayers always 90 // When impl-side painting is enabled, this will ensure PictureLayers always
89 // can have LCD text, to match the previous behaviour with ContentLayers, 91 // can have LCD text, to match the previous behaviour with ContentLayers,
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 animation_observer_list_, 289 animation_observer_list_,
288 OnAnimationStep(args.frame_time)); 290 OnAnimationStep(args.frame_time));
289 if (animation_observer_list_.might_have_observers()) 291 if (animation_observer_list_.might_have_observers())
290 host_->SetNeedsAnimate(); 292 host_->SetNeedsAnimate();
291 } 293 }
292 294
293 void Compositor::BeginMainFrameNotExpectedSoon() { 295 void Compositor::BeginMainFrameNotExpectedSoon() {
294 } 296 }
295 297
296 void Compositor::Layout() { 298 void Compositor::Layout() {
297 // We're sending damage that will be addressed during this composite
298 // cycle, so we don't need to schedule another composite to address it.
299 disable_schedule_composite_ = true;
300 if (root_layer_) 299 if (root_layer_)
301 root_layer_->SendDamagedRects(); 300 root_layer_->SendDamagedRects();
302 disable_schedule_composite_ = false;
303 } 301 }
304 302
305 void Compositor::RequestNewOutputSurface() { 303 void Compositor::RequestNewOutputSurface() {
306 context_factory_->CreateOutputSurface(weak_ptr_factory_.GetWeakPtr()); 304 context_factory_->CreateOutputSurface(weak_ptr_factory_.GetWeakPtr());
307 } 305 }
308 306
309 void Compositor::DidInitializeOutputSurface() { 307 void Compositor::DidInitializeOutputSurface() {
310 } 308 }
311 309
312 void Compositor::DidFailToInitializeOutputSurface() { 310 void Compositor::DidFailToInitializeOutputSurface() {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 346
349 void Compositor::SetLayerTreeDebugState( 347 void Compositor::SetLayerTreeDebugState(
350 const cc::LayerTreeDebugState& debug_state) { 348 const cc::LayerTreeDebugState& debug_state) {
351 host_->SetDebugState(debug_state); 349 host_->SetDebugState(debug_state);
352 } 350 }
353 351
354 const cc::RendererSettings& Compositor::GetRendererSettings() const { 352 const cc::RendererSettings& Compositor::GetRendererSettings() const {
355 return host_->settings().renderer_settings; 353 return host_->settings().renderer_settings;
356 } 354 }
357 355
358 scoped_refptr<CompositorLock> Compositor::GetCompositorLock() { 356 scoped_refptr<CompositorLock> Compositor::GetCompositorLock() {
danakj 2015/03/12 00:07:15 Rather than adding state to ui::Compositor class,
ccameron 2015/03/12 01:01:34 This was the approach that I first went with, but
359 if (!compositor_lock_) { 357 if (!compositor_lock_) {
360 compositor_lock_ = new CompositorLock(this); 358 compositor_lock_ = new CompositorLock(this);
361 host_->SetDeferCommits(true); 359 host_->SetDeferCommits(true);
362 FOR_EACH_OBSERVER(CompositorObserver, 360 FOR_EACH_OBSERVER(CompositorObserver,
363 observer_list_, 361 observer_list_,
364 OnCompositingLockStateChanged(this)); 362 OnCompositingLockStateChanged(this));
365 } 363 }
366 return compositor_lock_; 364 return compositor_lock_;
367 } 365 }
368 366
369 void Compositor::UnlockCompositor() { 367 void Compositor::UnlockCompositor() {
370 DCHECK(compositor_lock_); 368 DCHECK(compositor_lock_);
371 compositor_lock_ = NULL; 369 compositor_lock_ = NULL;
372 host_->SetDeferCommits(false); 370 host_->SetDeferCommits(false);
373 FOR_EACH_OBSERVER(CompositorObserver, 371 FOR_EACH_OBSERVER(CompositorObserver,
374 observer_list_, 372 observer_list_,
375 OnCompositingLockStateChanged(this)); 373 OnCompositingLockStateChanged(this));
376 } 374 }
377 375
378 void Compositor::CancelCompositorLock() { 376 void Compositor::CancelCompositorLock() {
379 if (compositor_lock_) 377 if (compositor_lock_)
380 compositor_lock_->CancelLock(); 378 compositor_lock_->CancelLock();
381 } 379 }
382 380
383 } // namespace ui 381 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698