blob: 352c7f0f8075ad0c1d0c6f73aaafd3f5902799c6 [file] [log] [blame]
[email protected]72bce522014-02-10 21:11:261// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "ash/display/projecting_observer_chromeos.h"
6
Steven Bennetts7683e342018-01-02 21:29:527#include "ash/shell.h"
pneubeck8be1f5422014-10-09 16:46:188#include "base/logging.h"
Steven Bennetts7683e342018-01-02 21:29:529#include "chromeos/dbus/dbus_thread_manager.h"
[email protected]72bce522014-02-10 21:11:2610#include "chromeos/dbus/power_manager_client.h"
spangcef10972014-09-18 15:47:1011#include "ui/display/types/display_snapshot.h"
[email protected]72bce522014-02-10 21:11:2612
13namespace ash {
14
pneubeck8be1f5422014-10-09 16:46:1815ProjectingObserver::ProjectingObserver(
Steven Bennetts7683e342018-01-02 21:29:5216 display::DisplayConfigurator* display_configurator)
17 : display_configurator_(display_configurator) {
18 if (Shell::HasInstance())
19 Shell::Get()->AddShellObserver(this);
20 if (display_configurator_)
21 display_configurator_->AddObserver(this);
pneubeck8be1f5422014-10-09 16:46:1822}
[email protected]72bce522014-02-10 21:11:2623
Steven Bennetts7683e342018-01-02 21:29:5224ProjectingObserver::~ProjectingObserver() {
25 if (Shell::HasInstance())
26 Shell::Get()->RemoveShellObserver(this);
27 if (display_configurator_)
28 display_configurator_->RemoveObserver(this);
29}
[email protected]72bce522014-02-10 21:11:2630
31void ProjectingObserver::OnDisplayModeChanged(
kylechar7a067ec2017-01-07 01:16:2832 const display::DisplayConfigurator::DisplayStateList& display_states) {
[email protected]72bce522014-02-10 21:11:2633 has_internal_output_ = false;
[email protected]bcec7fb62014-04-08 20:59:0934 output_count_ = display_states.size();
[email protected]72bce522014-02-10 21:11:2635
[email protected]bcec7fb62014-04-08 20:59:0936 for (size_t i = 0; i < display_states.size(); ++i) {
kylechar7a067ec2017-01-07 01:16:2837 if (display_states[i]->type() ==
38 display::DISPLAY_CONNECTION_TYPE_INTERNAL) {
[email protected]72bce522014-02-10 21:11:2639 has_internal_output_ = true;
40 break;
41 }
42 }
43
44 SetIsProjecting();
45}
46
47void ProjectingObserver::OnCastingSessionStartedOrStopped(bool started) {
48 if (started) {
49 ++casting_session_count_;
50 } else {
51 DCHECK_GT(casting_session_count_, 0);
52 --casting_session_count_;
53 if (casting_session_count_ < 0)
54 casting_session_count_ = 0;
55 }
56
57 SetIsProjecting();
58}
59
60void ProjectingObserver::SetIsProjecting() {
61 // "Projecting" is defined as having more than 1 output connected while at
62 // least one of them is an internal output.
jamescookb8dcef522016-06-25 14:42:5563 bool projecting =
64 has_internal_output_ && (output_count_ + casting_session_count_ > 1);
[email protected]72bce522014-02-10 21:11:2665
Steven Bennetts7683e342018-01-02 21:29:5266 chromeos::PowerManagerClient* power_manager_client =
67 power_manager_client_for_test_
68 ? power_manager_client_for_test_
69 : chromeos::DBusThreadManager::Get()->GetPowerManagerClient();
70 if (power_manager_client)
71 power_manager_client->SetIsProjecting(projecting);
[email protected]72bce522014-02-10 21:11:2672}
73
[email protected]72bce522014-02-10 21:11:2674} // namespace ash