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

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

Issue 2773433003: Fix CompositorResizeLock to do something. (Closed)
Patch Set: resizelock: . Created 3 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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <deque> 10 #include <deque>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/metrics/histogram_macros.h" 16 #include "base/metrics/histogram_macros.h"
17 #include "base/stl_util.h"
17 #include "base/strings/string_util.h" 18 #include "base/strings/string_util.h"
18 #include "base/sys_info.h" 19 #include "base/sys_info.h"
19 #include "base/trace_event/trace_event.h" 20 #include "base/trace_event/trace_event.h"
20 #include "build/build_config.h" 21 #include "build/build_config.h"
21 #include "cc/animation/animation_host.h" 22 #include "cc/animation/animation_host.h"
22 #include "cc/animation/animation_id_provider.h" 23 #include "cc/animation/animation_id_provider.h"
23 #include "cc/animation/animation_timeline.h" 24 #include "cc/animation/animation_timeline.h"
24 #include "cc/base/switches.h" 25 #include "cc/base/switches.h"
25 #include "cc/input/input_handler.h" 26 #include "cc/input/input_handler.h"
26 #include "cc/layers/layer.h" 27 #include "cc/layers/layer.h"
(...skipping 12 matching lines...) Expand all
39 #include "ui/compositor/compositor_vsync_manager.h" 40 #include "ui/compositor/compositor_vsync_manager.h"
40 #include "ui/compositor/dip_util.h" 41 #include "ui/compositor/dip_util.h"
41 #include "ui/compositor/layer.h" 42 #include "ui/compositor/layer.h"
42 #include "ui/compositor/layer_animator_collection.h" 43 #include "ui/compositor/layer_animator_collection.h"
43 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 44 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
44 #include "ui/gfx/icc_profile.h" 45 #include "ui/gfx/icc_profile.h"
45 #include "ui/gl/gl_switches.h" 46 #include "ui/gl/gl_switches.h"
46 47
47 namespace { 48 namespace {
48 49
49 const double kDefaultRefreshRate = 60.0; 50 constexpr double kDefaultRefreshRate = 60.0;
50 const double kTestRefreshRate = 200.0; 51 constexpr double kTestRefreshRate = 200.0;
51 52
52 } // namespace 53 } // namespace
53 54
54 namespace ui { 55 namespace ui {
55 56
56 CompositorLock::CompositorLock(Compositor* compositor)
57 : compositor_(compositor) {
58 if (compositor_->locks_will_time_out_) {
59 compositor_->task_runner_->PostDelayedTask(
60 FROM_HERE,
61 base::Bind(&CompositorLock::CancelLock, AsWeakPtr()),
62 base::TimeDelta::FromMilliseconds(kCompositorLockTimeoutMs));
63 }
64 }
65
66 CompositorLock::~CompositorLock() {
67 CancelLock();
68 }
69
70 void CompositorLock::CancelLock() {
71 if (!compositor_)
72 return;
73 compositor_->UnlockCompositor();
74 compositor_ = NULL;
75 }
76
77 Compositor::Compositor(const cc::FrameSinkId& frame_sink_id, 57 Compositor::Compositor(const cc::FrameSinkId& frame_sink_id,
78 ui::ContextFactory* context_factory, 58 ui::ContextFactory* context_factory,
79 ui::ContextFactoryPrivate* context_factory_private, 59 ui::ContextFactoryPrivate* context_factory_private,
80 scoped_refptr<base::SingleThreadTaskRunner> task_runner) 60 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
81 : context_factory_(context_factory), 61 : context_factory_(context_factory),
82 context_factory_private_(context_factory_private), 62 context_factory_private_(context_factory_private),
83 root_layer_(NULL),
84 widget_(gfx::kNullAcceleratedWidget),
85 committed_frame_number_(0),
86 widget_valid_(false),
87 compositor_frame_sink_requested_(false),
88 frame_sink_id_(frame_sink_id), 63 frame_sink_id_(frame_sink_id),
89 task_runner_(task_runner), 64 task_runner_(task_runner),
90 vsync_manager_(new CompositorVSyncManager()), 65 vsync_manager_(new CompositorVSyncManager()),
91 device_scale_factor_(0.0f),
92 locks_will_time_out_(true),
93 compositor_lock_(NULL),
94 layer_animator_collection_(this), 66 layer_animator_collection_(this),
95 weak_ptr_factory_(this) { 67 weak_ptr_factory_(this),
68 lock_timeout_weak_ptr_factory_(this) {
96 if (context_factory_private) { 69 if (context_factory_private) {
97 context_factory_private->GetSurfaceManager()->RegisterFrameSinkId( 70 context_factory_private->GetSurfaceManager()->RegisterFrameSinkId(
98 frame_sink_id_); 71 frame_sink_id_);
99 } 72 }
100 root_web_layer_ = cc::Layer::Create(); 73 root_web_layer_ = cc::Layer::Create();
101 74
102 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 75 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
103 76
104 cc::LayerTreeSettings settings; 77 cc::LayerTreeSettings settings;
105 78
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 194
222 if (command_line->HasSwitch(switches::kUISlowAnimations)) { 195 if (command_line->HasSwitch(switches::kUISlowAnimations)) {
223 slow_animations_ = base::MakeUnique<ScopedAnimationDurationScaleMode>( 196 slow_animations_ = base::MakeUnique<ScopedAnimationDurationScaleMode>(
224 ScopedAnimationDurationScaleMode::SLOW_DURATION); 197 ScopedAnimationDurationScaleMode::SLOW_DURATION);
225 } 198 }
226 } 199 }
227 200
228 Compositor::~Compositor() { 201 Compositor::~Compositor() {
229 TRACE_EVENT0("shutdown", "Compositor::destructor"); 202 TRACE_EVENT0("shutdown", "Compositor::destructor");
230 203
231 CancelCompositorLock();
232 DCHECK(!compositor_lock_);
233
234 for (auto& observer : observer_list_) 204 for (auto& observer : observer_list_)
235 observer.OnCompositingShuttingDown(this); 205 observer.OnCompositingShuttingDown(this);
236 206
237 for (auto& observer : animation_observer_list_) 207 for (auto& observer : animation_observer_list_)
238 observer.OnCompositingShuttingDown(this); 208 observer.OnCompositingShuttingDown(this);
239 209
240 if (root_layer_) 210 if (root_layer_)
241 root_layer_->ResetCompositor(); 211 root_layer_->ResetCompositor();
242 212
243 if (animation_timeline_) 213 if (animation_timeline_)
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 522
553 void Compositor::SetLayerTreeDebugState( 523 void Compositor::SetLayerTreeDebugState(
554 const cc::LayerTreeDebugState& debug_state) { 524 const cc::LayerTreeDebugState& debug_state) {
555 host_->SetDebugState(debug_state); 525 host_->SetDebugState(debug_state);
556 } 526 }
557 527
558 const cc::RendererSettings& Compositor::GetRendererSettings() const { 528 const cc::RendererSettings& Compositor::GetRendererSettings() const {
559 return host_->GetSettings().renderer_settings; 529 return host_->GetSettings().renderer_settings;
560 } 530 }
561 531
562 scoped_refptr<CompositorLock> Compositor::GetCompositorLock() { 532 std::unique_ptr<CompositorLock> Compositor::GetCompositorLock(
563 if (!compositor_lock_) { 533 CompositorLockClient* client,
564 compositor_lock_ = new CompositorLock(this); 534 base::TimeDelta timeout) {
535 if (active_locks_.empty()) {
565 host_->SetDeferCommits(true); 536 host_->SetDeferCommits(true);
566 for (auto& observer : observer_list_) 537 for (auto& observer : observer_list_)
567 observer.OnCompositingLockStateChanged(this); 538 observer.OnCompositingLockStateChanged(this);
539
540 if (!timeout.is_zero()) {
541 task_runner_->PostDelayedTask(
542 FROM_HERE,
543 base::Bind(&Compositor::TimeoutLocks,
544 lock_timeout_weak_ptr_factory_.GetWeakPtr()),
545 timeout);
546 }
568 } 547 }
569 return compositor_lock_; 548 auto lock = base::MakeUnique<CompositorLock>(client, this);
549 active_locks_.push_back(lock.get());
550 return lock;
570 } 551 }
571 552
572 void Compositor::UnlockCompositor() { 553 void Compositor::RemoveCompositorLock(CompositorLock* lock) {
573 DCHECK(compositor_lock_); 554 base::Erase(active_locks_, lock);
574 compositor_lock_ = NULL; 555 if (active_locks_.empty()) {
575 host_->SetDeferCommits(false); 556 host_->SetDeferCommits(false);
576 for (auto& observer : observer_list_) 557 for (auto& observer : observer_list_)
577 observer.OnCompositingLockStateChanged(this); 558 observer.OnCompositingLockStateChanged(this);
559 }
578 } 560 }
579 561
580 void Compositor::CancelCompositorLock() { 562 void Compositor::TimeoutLocks() {
581 if (compositor_lock_) 563 // Make a copy, we're going to cause |active_locks_| to become
582 compositor_lock_->CancelLock(); 564 // empty.
565 std::vector<CompositorLock*> locks = active_locks_;
566 for (auto* lock : locks)
567 lock->TimeoutLock();
568 DCHECK(active_locks_.empty());
583 } 569 }
584 570
585 } // namespace ui 571 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698