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

« back to all changes in this revision

Viewing changes to src/server/scene/basic_surface.cpp

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release
  • Date: 2014-01-08 02:04:38 UTC
  • mto: This revision was merged to the branch mainline in revision 58.
  • Revision ID: package-import@ubuntu.com-20140108020438-e1npu0pm7qdv5wc4
Tags: upstream-0.1.3+14.04.20140108
Import upstream version 0.1.3+14.04.20140108

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2012 Canonical Ltd.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify it
 
5
 * under the terms of the GNU 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 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:
 
17
 *   Alan Griffiths <alan@octopull.co.uk>
 
18
 *   Thomas Voss <thomas.voss@canonical.com>
 
19
 */
 
20
 
 
21
#include "basic_surface.h"
 
22
#include "surface_data.h"
 
23
#include "mir/compositor/buffer_stream.h"
 
24
#include "mir/input/input_channel.h"
 
25
#include "mir/graphics/buffer.h"
 
26
 
 
27
#include "mir/scene/scene_report.h"
 
28
 
 
29
#include <boost/throw_exception.hpp>
 
30
 
 
31
#include <stdexcept>
 
32
 
 
33
namespace mc = mir::compositor;
 
34
namespace ms = mir::scene;
 
35
namespace mg = mir::graphics;
 
36
namespace mi = mir::input;
 
37
namespace geom = mir::geometry;
 
38
 
 
39
ms::BasicSurface::BasicSurface(
 
40
    std::shared_ptr<SurfaceData> const& surface_data,
 
41
    std::shared_ptr<mc::BufferStream> const& buffer_stream,
 
42
    std::shared_ptr<input::InputChannel> const& input_channel,
 
43
    std::shared_ptr<SceneReport> const& report) :
 
44
    surface_data(surface_data),
 
45
    surface_buffer_stream(buffer_stream),
 
46
    server_input_channel(input_channel),
 
47
    report(report)
 
48
{
 
49
    report->surface_created(this);
 
50
}
 
51
 
 
52
void ms::BasicSurface::force_requests_to_complete()
 
53
{
 
54
    surface_buffer_stream->force_requests_to_complete();
 
55
}
 
56
 
 
57
ms::BasicSurface::~BasicSurface()
 
58
{
 
59
    report->surface_deleted(this);
 
60
}
 
61
 
 
62
std::shared_ptr<mc::BufferStream> ms::BasicSurface::buffer_stream() const
 
63
{
 
64
    return surface_buffer_stream;
 
65
}
 
66
 
 
67
std::shared_ptr<mc::CompositingCriteria> ms::BasicSurface::compositing_criteria()
 
68
{
 
69
    return surface_data;
 
70
}
 
71
 
 
72
std::string const& ms::BasicSurface::name() const
 
73
{
 
74
    return surface_data->name();
 
75
}
 
76
 
 
77
void ms::BasicSurface::move_to(geometry::Point const& top_left)
 
78
{
 
79
    surface_data->move_to(top_left);
 
80
}
 
81
 
 
82
void ms::BasicSurface::set_rotation(float degrees, glm::vec3 const& axis)
 
83
{
 
84
    surface_data->apply_rotation(degrees, axis);
 
85
}
 
86
 
 
87
void ms::BasicSurface::set_alpha(float alpha_v)
 
88
{
 
89
    surface_data->apply_alpha(alpha_v);
 
90
}
 
91
 
 
92
void ms::BasicSurface::set_hidden(bool hide)
 
93
{
 
94
    surface_data->set_hidden(hide);
 
95
}
 
96
 
 
97
geom::Point ms::BasicSurface::top_left() const
 
98
{
 
99
    return surface_data->position();
 
100
}
 
101
 
 
102
mir::geometry::Size ms::BasicSurface::size() const
 
103
{
 
104
    return surface_data->size();
 
105
}
 
106
 
 
107
MirPixelFormat ms::BasicSurface::pixel_format() const
 
108
{
 
109
    return surface_buffer_stream->get_stream_pixel_format();
 
110
}
 
111
 
 
112
void ms::BasicSurface::swap_buffers(graphics::Buffer*& buffer)
 
113
{
 
114
    bool const posting{!!buffer};
 
115
 
 
116
    surface_buffer_stream->swap_client_buffers(buffer);
 
117
 
 
118
    if (posting)
 
119
    {
 
120
        surface_data->frame_posted();
 
121
    }
 
122
}
 
123
 
 
124
void ms::BasicSurface::allow_framedropping(bool allow)
 
125
{
 
126
    surface_buffer_stream->allow_framedropping(allow);
 
127
}
 
128
 
 
129
std::shared_ptr<mg::Buffer> ms::BasicSurface::snapshot_buffer() const
 
130
{
 
131
    return surface_buffer_stream->lock_snapshot_buffer();
 
132
}
 
133
 
 
134
bool ms::BasicSurface::supports_input() const
 
135
{
 
136
    if (server_input_channel)
 
137
        return true;
 
138
    return false;
 
139
}
 
140
 
 
141
int ms::BasicSurface::client_input_fd() const
 
142
{
 
143
    if (!supports_input())
 
144
        BOOST_THROW_EXCEPTION(std::logic_error("Surface does not support input"));
 
145
    return server_input_channel->client_fd();
 
146
}
 
147
 
 
148
std::shared_ptr<mi::InputChannel> ms::BasicSurface::input_channel() const
 
149
{
 
150
    return server_input_channel;
 
151
}
 
152
 
 
153
std::shared_ptr<mi::Surface> ms::BasicSurface::input_surface() const
 
154
{
 
155
    return surface_data;
 
156
}
 
157
 
 
158
void ms::BasicSurface::set_input_region(std::vector<geom::Rectangle> const& input_rectangles)
 
159
{
 
160
    surface_data->set_input_region(input_rectangles);
 
161
}
 
162
 
 
163
void ms::BasicSurface::resize(geom::Size const& size)
 
164
{
 
165
    if (size.width <= geom::Width{0} || size.height <= geom::Height{0})
 
166
    {
 
167
        BOOST_THROW_EXCEPTION(std::logic_error("Impossible resize requested"));
 
168
    }
 
169
    /*
 
170
     * Other combinations may still be invalid (like dimensions too big or
 
171
     * insufficient resources), but those are runtime and platform-specific, so
 
172
     * not predictable here. Such critical exceptions would arise from
 
173
     * the platform buffer allocator as a runtime_error via:
 
174
     */
 
175
    surface_buffer_stream->resize(size);
 
176
 
 
177
    // Now the buffer stream has successfully resized, update the state second;
 
178
    surface_data->resize(size);
 
179
}