~ubuntu-branches/ubuntu/wily/mir/wily-proposed

« back to all changes in this revision

Viewing changes to src/platforms/android/server/display_group.cpp

  • Committer: Package Import Robot
  • Author(s): CI Train Bot
  • Date: 2015-05-12 13:12:55 UTC
  • mto: This revision was merged to the branch mainline in revision 96.
  • Revision ID: package-import@ubuntu.com-20150512131255-y7z12i8n4pbvo70x
Tags: upstream-0.13.0+15.10.20150512
Import upstream version 0.13.0+15.10.20150512

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2015 Canonical Ltd.
 
3
 *
 
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.
 
7
 *
 
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.
 
12
 *
 
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/>.
 
15
 *
 
16
 * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
 
17
 */
 
18
 
 
19
#include "display_group.h"
 
20
#include "configurable_display_buffer.h"
 
21
#include <boost/throw_exception.hpp>
 
22
#include <stdexcept>
 
23
 
 
24
namespace mg = mir::graphics;
 
25
namespace mga = mir::graphics::android;
 
26
 
 
27
mga::DisplayGroup::DisplayGroup(
 
28
    std::shared_ptr<mga::DisplayDevice> const& device,
 
29
    std::unique_ptr<mga::ConfigurableDisplayBuffer> primary_buffer) :
 
30
    device(device)
 
31
{
 
32
    dbs.emplace(std::make_pair(mga::DisplayName::primary, std::move(primary_buffer)));
 
33
}
 
34
 
 
35
void mga::DisplayGroup::for_each_display_buffer(std::function<void(mg::DisplayBuffer&)> const& f)
 
36
{
 
37
    std::unique_lock<decltype(guard)> lk(guard);
 
38
    for(auto const& db : dbs)
 
39
        if (db.second->power_mode() != mir_power_mode_off)
 
40
            f(*db.second);
 
41
}
 
42
 
 
43
void mga::DisplayGroup::add(DisplayName name, std::unique_ptr<ConfigurableDisplayBuffer> buffer)
 
44
{
 
45
    std::unique_lock<decltype(guard)> lk(guard);
 
46
    dbs.emplace(std::make_pair(name, std::move(buffer)));
 
47
}
 
48
 
 
49
void mga::DisplayGroup::remove(DisplayName name)
 
50
{
 
51
    if (name == mga::DisplayName::primary)
 
52
        BOOST_THROW_EXCEPTION(std::logic_error("cannot remove primary display"));
 
53
 
 
54
    std::unique_lock<decltype(guard)> lk(guard);
 
55
    auto it = dbs.find(name);
 
56
    if (it != dbs.end())
 
57
        dbs.erase(it);
 
58
}
 
59
 
 
60
bool mga::DisplayGroup::display_present(DisplayName name) const
 
61
{
 
62
    std::unique_lock<decltype(guard)> lk(guard);
 
63
    return (dbs.end() != dbs.find(name));
 
64
}
 
65
 
 
66
void mga::DisplayGroup::configure(DisplayName name, MirPowerMode mode, MirOrientation orientation)
 
67
{
 
68
    std::unique_lock<decltype(guard)> lk(guard);
 
69
    auto it = dbs.find(name);
 
70
    if (it != dbs.end())
 
71
        it->second->configure(mode, orientation);
 
72
}
 
73
 
 
74
void mga::DisplayGroup::post()
 
75
{
 
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); 
 
81
}