OLD | NEW |
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> |
(...skipping 28 matching lines...) Expand all Loading... |
39 #include "ui/compositor/compositor_vsync_manager.h" | 39 #include "ui/compositor/compositor_vsync_manager.h" |
40 #include "ui/compositor/dip_util.h" | 40 #include "ui/compositor/dip_util.h" |
41 #include "ui/compositor/layer.h" | 41 #include "ui/compositor/layer.h" |
42 #include "ui/compositor/layer_animator_collection.h" | 42 #include "ui/compositor/layer_animator_collection.h" |
43 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 43 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
44 #include "ui/gfx/icc_profile.h" | 44 #include "ui/gfx/icc_profile.h" |
45 #include "ui/gl/gl_switches.h" | 45 #include "ui/gl/gl_switches.h" |
46 | 46 |
47 namespace { | 47 namespace { |
48 | 48 |
49 const double kDefaultRefreshRate = 60.0; | 49 constexpr double kDefaultRefreshRate = 60.0; |
50 const double kTestRefreshRate = 200.0; | 50 constexpr double kTestRefreshRate = 200.0; |
51 | 51 |
52 } // namespace | 52 } // namespace |
53 | 53 |
54 namespace ui { | 54 namespace ui { |
55 | 55 |
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, | 56 Compositor::Compositor(const cc::FrameSinkId& frame_sink_id, |
78 ui::ContextFactory* context_factory, | 57 ui::ContextFactory* context_factory, |
79 ui::ContextFactoryPrivate* context_factory_private, | 58 ui::ContextFactoryPrivate* context_factory_private, |
80 scoped_refptr<base::SingleThreadTaskRunner> task_runner) | 59 scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
81 : context_factory_(context_factory), | 60 : context_factory_(context_factory), |
82 context_factory_private_(context_factory_private), | 61 context_factory_private_(context_factory_private), |
83 root_layer_(NULL), | 62 root_layer_(nullptr), |
84 widget_(gfx::kNullAcceleratedWidget), | 63 widget_(gfx::kNullAcceleratedWidget), |
85 committed_frame_number_(0), | 64 committed_frame_number_(0), |
86 widget_valid_(false), | 65 widget_valid_(false), |
87 compositor_frame_sink_requested_(false), | 66 compositor_frame_sink_requested_(false), |
88 frame_sink_id_(frame_sink_id), | 67 frame_sink_id_(frame_sink_id), |
89 task_runner_(task_runner), | 68 task_runner_(task_runner), |
90 vsync_manager_(new CompositorVSyncManager()), | 69 vsync_manager_(new CompositorVSyncManager()), |
91 device_scale_factor_(0.0f), | 70 device_scale_factor_(0.0f), |
92 locks_will_time_out_(true), | 71 compositor_lock_(nullptr), |
93 compositor_lock_(NULL), | |
94 layer_animator_collection_(this), | 72 layer_animator_collection_(this), |
95 weak_ptr_factory_(this) { | 73 weak_ptr_factory_(this) { |
96 if (context_factory_private) { | 74 if (context_factory_private) { |
97 context_factory_private->GetSurfaceManager()->RegisterFrameSinkId( | 75 context_factory_private->GetSurfaceManager()->RegisterFrameSinkId( |
98 frame_sink_id_); | 76 frame_sink_id_); |
99 } | 77 } |
100 root_web_layer_ = cc::Layer::Create(); | 78 root_web_layer_ = cc::Layer::Create(); |
101 | 79 |
102 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 80 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
103 | 81 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 | 199 |
222 if (command_line->HasSwitch(switches::kUISlowAnimations)) { | 200 if (command_line->HasSwitch(switches::kUISlowAnimations)) { |
223 slow_animations_ = base::MakeUnique<ScopedAnimationDurationScaleMode>( | 201 slow_animations_ = base::MakeUnique<ScopedAnimationDurationScaleMode>( |
224 ScopedAnimationDurationScaleMode::SLOW_DURATION); | 202 ScopedAnimationDurationScaleMode::SLOW_DURATION); |
225 } | 203 } |
226 } | 204 } |
227 | 205 |
228 Compositor::~Compositor() { | 206 Compositor::~Compositor() { |
229 TRACE_EVENT0("shutdown", "Compositor::destructor"); | 207 TRACE_EVENT0("shutdown", "Compositor::destructor"); |
230 | 208 |
231 CancelCompositorLock(); | |
232 DCHECK(!compositor_lock_); | |
233 | |
234 for (auto& observer : observer_list_) | 209 for (auto& observer : observer_list_) |
235 observer.OnCompositingShuttingDown(this); | 210 observer.OnCompositingShuttingDown(this); |
236 | 211 |
237 for (auto& observer : animation_observer_list_) | 212 for (auto& observer : animation_observer_list_) |
238 observer.OnCompositingShuttingDown(this); | 213 observer.OnCompositingShuttingDown(this); |
239 | 214 |
240 if (root_layer_) | 215 if (root_layer_) |
241 root_layer_->ResetCompositor(); | 216 root_layer_->ResetCompositor(); |
242 | 217 |
243 if (animation_timeline_) | 218 if (animation_timeline_) |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 | 527 |
553 void Compositor::SetLayerTreeDebugState( | 528 void Compositor::SetLayerTreeDebugState( |
554 const cc::LayerTreeDebugState& debug_state) { | 529 const cc::LayerTreeDebugState& debug_state) { |
555 host_->SetDebugState(debug_state); | 530 host_->SetDebugState(debug_state); |
556 } | 531 } |
557 | 532 |
558 const cc::RendererSettings& Compositor::GetRendererSettings() const { | 533 const cc::RendererSettings& Compositor::GetRendererSettings() const { |
559 return host_->GetSettings().renderer_settings; | 534 return host_->GetSettings().renderer_settings; |
560 } | 535 } |
561 | 536 |
562 scoped_refptr<CompositorLock> Compositor::GetCompositorLock() { | 537 scoped_refptr<CompositorLock> Compositor::GetCompositorLock( |
| 538 CompositorLockClient* client, |
| 539 base::TimeDelta timeout) { |
563 if (!compositor_lock_) { | 540 if (!compositor_lock_) { |
564 compositor_lock_ = new CompositorLock(this); | 541 compositor_lock_ = |
| 542 new CompositorLock(client, this, task_runner_.get(), timeout); |
565 host_->SetDeferCommits(true); | 543 host_->SetDeferCommits(true); |
566 for (auto& observer : observer_list_) | 544 for (auto& observer : observer_list_) |
567 observer.OnCompositingLockStateChanged(this); | 545 observer.OnCompositingLockStateChanged(this); |
568 } | 546 } |
569 return compositor_lock_; | 547 return compositor_lock_; |
570 } | 548 } |
571 | 549 |
572 void Compositor::UnlockCompositor() { | 550 void Compositor::DoUnlockCompositor() { |
573 DCHECK(compositor_lock_); | 551 DCHECK(compositor_lock_); |
574 compositor_lock_ = NULL; | 552 compositor_lock_ = nullptr; |
575 host_->SetDeferCommits(false); | 553 host_->SetDeferCommits(false); |
576 for (auto& observer : observer_list_) | 554 for (auto& observer : observer_list_) |
577 observer.OnCompositingLockStateChanged(this); | 555 observer.OnCompositingLockStateChanged(this); |
578 } | 556 } |
579 | 557 |
580 void Compositor::CancelCompositorLock() { | |
581 if (compositor_lock_) | |
582 compositor_lock_->CancelLock(); | |
583 } | |
584 | |
585 } // namespace ui | 558 } // namespace ui |
OLD | NEW |