2
* Copyright © 2015 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU Lesser General Public License version 3,
6
* as published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Kevin DuBois <kevin.dubois@canonical.com>
19
#include "display_group.h"
20
#include "configurable_display_buffer.h"
21
#include <boost/throw_exception.hpp>
24
namespace mg = mir::graphics;
25
namespace mga = mir::graphics::android;
27
mga::DisplayGroup::DisplayGroup(
28
std::shared_ptr<mga::DisplayDevice> const& device,
29
std::unique_ptr<mga::ConfigurableDisplayBuffer> primary_buffer) :
32
dbs.emplace(std::make_pair(mga::DisplayName::primary, std::move(primary_buffer)));
35
void mga::DisplayGroup::for_each_display_buffer(std::function<void(mg::DisplayBuffer&)> const& f)
37
std::unique_lock<decltype(guard)> lk(guard);
38
for(auto const& db : dbs)
39
if (db.second->power_mode() != mir_power_mode_off)
43
void mga::DisplayGroup::add(DisplayName name, std::unique_ptr<ConfigurableDisplayBuffer> buffer)
45
std::unique_lock<decltype(guard)> lk(guard);
46
dbs.emplace(std::make_pair(name, std::move(buffer)));
49
void mga::DisplayGroup::remove(DisplayName name)
51
if (name == mga::DisplayName::primary)
52
BOOST_THROW_EXCEPTION(std::logic_error("cannot remove primary display"));
54
std::unique_lock<decltype(guard)> lk(guard);
55
auto it = dbs.find(name);
60
bool mga::DisplayGroup::display_present(DisplayName name) const
62
std::unique_lock<decltype(guard)> lk(guard);
63
return (dbs.end() != dbs.find(name));
66
void mga::DisplayGroup::configure(DisplayName name, MirPowerMode mode, MirOrientation orientation)
68
std::unique_lock<decltype(guard)> lk(guard);
69
auto it = dbs.find(name);
71
it->second->configure(mode, orientation);
74
void mga::DisplayGroup::post()
76
std::list<DisplayContents> contents;
77
std::unique_lock<decltype(guard)> lk(guard);
78
for(auto const& db : dbs)
79
contents.emplace_back(db.second->contents());
80
device->commit(contents);