2
* Copyright © 2012 Canonical Ltd.
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.
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.
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/>.
17
* Alan Griffiths <alan@octopull.co.uk>
18
* Thomas Voss <thomas.voss@canonical.com>
22
#include "surface_state.h"
23
#include "mir/compositor/buffer_stream.h"
24
#include "mir/input/input_channel.h"
25
#include "mir/graphics/buffer.h"
27
#include "mir/scene/scene_report.h"
29
#include <boost/throw_exception.hpp>
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;
40
std::shared_ptr<SurfaceState> const& state,
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) :
45
surface_buffer_stream(buffer_stream),
46
server_input_channel(input_channel),
48
surface_in_startup(true)
50
report->surface_created(this);
53
void ms::Surface::force_requests_to_complete()
55
surface_buffer_stream->force_requests_to_complete();
58
ms::Surface::~Surface()
60
report->surface_deleted(this);
63
std::shared_ptr<mc::BufferStream> ms::Surface::buffer_stream() const
65
return surface_buffer_stream;
68
std::shared_ptr<mc::CompositingCriteria> ms::Surface::compositing_criteria()
73
std::string const& ms::Surface::name() const
75
return surface_state->name();
78
void ms::Surface::move_to(geometry::Point const& top_left)
80
surface_state->move_to(top_left);
83
void ms::Surface::set_rotation(float degrees, glm::vec3 const& axis)
85
surface_state->apply_rotation(degrees, axis);
88
void ms::Surface::set_alpha(float alpha_v)
90
surface_state->apply_alpha(alpha_v);
93
void ms::Surface::set_hidden(bool hide)
95
surface_state->set_hidden(hide);
98
geom::Point ms::Surface::top_left() const
100
return surface_state->position();
103
mir::geometry::Size ms::Surface::size() const
105
return surface_state->size();
108
geom::PixelFormat ms::Surface::pixel_format() const
110
return surface_buffer_stream->get_stream_pixel_format();
113
std::shared_ptr<mg::Buffer> ms::Surface::advance_client_buffer()
115
if (surface_in_startup)
117
surface_in_startup = false;
121
// TODO There is something crazy about assuming that giving out any buffer
122
// TODO after the first implies that previous buffers have been rendered.
126
return surface_buffer_stream->secure_client_buffer();
129
void ms::Surface::allow_framedropping(bool allow)
131
surface_buffer_stream->allow_framedropping(allow);
134
std::shared_ptr<mg::Buffer> ms::Surface::snapshot_buffer() const
136
return surface_buffer_stream->lock_snapshot_buffer();
139
//TODO: this is just used in example code, could be private
140
void ms::Surface::flag_for_render()
142
surface_state->frame_posted();
145
bool ms::Surface::supports_input() const
147
if (server_input_channel)
152
int ms::Surface::client_input_fd() const
154
if (!supports_input())
155
BOOST_THROW_EXCEPTION(std::logic_error("Surface does not support input"));
156
return server_input_channel->client_fd();
159
std::shared_ptr<mi::InputChannel> ms::Surface::input_channel() const
161
return server_input_channel;
164
std::shared_ptr<mi::Surface> ms::Surface::input_surface() const
166
return surface_state;
169
void ms::Surface::set_input_region(std::vector<geom::Rectangle> const& input_rectangles)
171
surface_state->set_input_region(input_rectangles);
174
void ms::Surface::resize(geom::Size const& size)
176
if (size.width <= geom::Width{0} || size.height <= geom::Height{0})
178
BOOST_THROW_EXCEPTION(std::logic_error("Impossible resize requested"));
181
* Other combinations may still be invalid (like dimensions too big or
182
* insufficient resources), but those are runtime and platform-specific, so
183
* not predictable here. Such critical exceptions would arise from
184
* the platform buffer allocator as a runtime_error via:
186
surface_buffer_stream->resize(size);
188
// Now the buffer stream has successfully resized, update the state second;
189
surface_state->resize(size);