~ubuntu-branches/ubuntu/vivid/mir/vivid

« back to all changes in this revision

Viewing changes to examples/pixel_format_selector.cpp

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release
  • Date: 2014-02-04 14:49:07 UTC
  • mto: This revision was merged to the branch mainline in revision 61.
  • Revision ID: package-import@ubuntu.com-20140204144907-o3ruhix0ey26lchl
Tags: upstream-0.1.4+14.04.20140204
Import upstream version 0.1.4+14.04.20140204

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2014 Canonical Ltd.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License version 3 as
 
6
 * 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 General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Authored by: Andreas Pokorny <andreas.pokorny@canonical.com>
 
17
 */
 
18
 
 
19
#include "pixel_format_selector.h"
 
20
 
 
21
#include "mir/graphics/display_configuration.h"
 
22
#include "mir/graphics/pixel_format_utils.h"
 
23
 
 
24
#include <stdexcept>
 
25
#include <algorithm>
 
26
 
 
27
 
 
28
namespace mir
 
29
{
 
30
namespace examples
 
31
{
 
32
 
 
33
PixelFormatSelector::PixelFormatSelector(std::shared_ptr<DisplayConfigurationPolicy> const& base_policy,
 
34
                                         bool with_alpha)
 
35
    : base_policy{base_policy},
 
36
    with_alpha{with_alpha}
 
37
{}
 
38
 
 
39
void PixelFormatSelector::apply_to(graphics::DisplayConfiguration & conf)
 
40
{
 
41
    base_policy->apply_to(conf);
 
42
    conf.for_each_output(
 
43
        [&](graphics::DisplayConfigurationOutput const& conf_output)
 
44
        {
 
45
            if (!conf_output.connected || !conf_output.used) return;
 
46
 
 
47
            auto const& pos = find_if(conf_output.pixel_formats.begin(),
 
48
                                      conf_output.pixel_formats.end(),
 
49
                                      [&](MirPixelFormat format) -> bool
 
50
                                          {
 
51
                                              return graphics::contains_alpha(format) == with_alpha;
 
52
                                          }
 
53
                                     );
 
54
 
 
55
            // keep the default settings if nothing was found
 
56
            if (pos == conf_output.pixel_formats.end())
 
57
                return;
 
58
 
 
59
            conf.configure_output(conf_output.id, true, conf_output.top_left,
 
60
                                  conf_output.current_mode_index,
 
61
                                  *pos,
 
62
                                  conf_output.power_mode,
 
63
                                  conf_output.orientation
 
64
                                 );
 
65
        });
 
66
}
 
67
 
 
68
}
 
69
}
 
70