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>
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"
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;
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),
49
report->surface_created(this);
52
void ms::BasicSurface::force_requests_to_complete()
54
surface_buffer_stream->force_requests_to_complete();
57
ms::BasicSurface::~BasicSurface()
59
report->surface_deleted(this);
62
std::shared_ptr<mc::BufferStream> ms::BasicSurface::buffer_stream() const
64
return surface_buffer_stream;
67
std::shared_ptr<mc::CompositingCriteria> ms::BasicSurface::compositing_criteria()
72
std::string const& ms::BasicSurface::name() const
74
return surface_data->name();
77
void ms::BasicSurface::move_to(geometry::Point const& top_left)
79
surface_data->move_to(top_left);
82
void ms::BasicSurface::set_rotation(float degrees, glm::vec3 const& axis)
84
surface_data->apply_rotation(degrees, axis);
87
void ms::BasicSurface::set_alpha(float alpha_v)
89
surface_data->apply_alpha(alpha_v);
92
void ms::BasicSurface::set_hidden(bool hide)
94
surface_data->set_hidden(hide);
97
geom::Point ms::BasicSurface::top_left() const
99
return surface_data->position();
102
mir::geometry::Size ms::BasicSurface::size() const
104
return surface_data->size();
107
MirPixelFormat ms::BasicSurface::pixel_format() const
109
return surface_buffer_stream->get_stream_pixel_format();
112
void ms::BasicSurface::swap_buffers(graphics::Buffer*& buffer)
114
bool const posting{!!buffer};
116
surface_buffer_stream->swap_client_buffers(buffer);
120
surface_data->frame_posted();
124
void ms::BasicSurface::allow_framedropping(bool allow)
126
surface_buffer_stream->allow_framedropping(allow);
129
std::shared_ptr<mg::Buffer> ms::BasicSurface::snapshot_buffer() const
131
return surface_buffer_stream->lock_snapshot_buffer();
134
bool ms::BasicSurface::supports_input() const
136
if (server_input_channel)
141
int ms::BasicSurface::client_input_fd() const
143
if (!supports_input())
144
BOOST_THROW_EXCEPTION(std::logic_error("Surface does not support input"));
145
return server_input_channel->client_fd();
148
std::shared_ptr<mi::InputChannel> ms::BasicSurface::input_channel() const
150
return server_input_channel;
153
std::shared_ptr<mi::Surface> ms::BasicSurface::input_surface() const
158
void ms::BasicSurface::set_input_region(std::vector<geom::Rectangle> const& input_rectangles)
160
surface_data->set_input_region(input_rectangles);
163
void ms::BasicSurface::resize(geom::Size const& size)
165
if (size.width <= geom::Width{0} || size.height <= geom::Height{0})
167
BOOST_THROW_EXCEPTION(std::logic_error("Impossible resize requested"));
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:
175
surface_buffer_stream->resize(size);
177
// Now the buffer stream has successfully resized, update the state second;
178
surface_data->resize(size);