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

« back to all changes in this revision

Viewing changes to src/server/scene/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 "surface.h"
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"
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::Surface::Surface(
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) :
44
 
    surface_state(state),
45
 
    surface_buffer_stream(buffer_stream),
46
 
    server_input_channel(input_channel),
47
 
    report(report),
48
 
    surface_in_startup(true)
49
 
{
50
 
    report->surface_created(this);
51
 
}
52
 
 
53
 
void ms::Surface::force_requests_to_complete()
54
 
{
55
 
    surface_buffer_stream->force_requests_to_complete();
56
 
}
57
 
 
58
 
ms::Surface::~Surface()
59
 
{
60
 
    report->surface_deleted(this);
61
 
}
62
 
 
63
 
std::shared_ptr<mc::BufferStream> ms::Surface::buffer_stream() const
64
 
{
65
 
    return surface_buffer_stream;
66
 
}
67
 
 
68
 
std::shared_ptr<mc::CompositingCriteria> ms::Surface::compositing_criteria()
69
 
{
70
 
    return surface_state;
71
 
}
72
 
 
73
 
std::string const& ms::Surface::name() const
74
 
{
75
 
    return surface_state->name();
76
 
}
77
 
 
78
 
void ms::Surface::move_to(geometry::Point const& top_left)
79
 
{
80
 
    surface_state->move_to(top_left);
81
 
}
82
 
 
83
 
void ms::Surface::set_rotation(float degrees, glm::vec3 const& axis)
84
 
{
85
 
    surface_state->apply_rotation(degrees, axis);
86
 
}
87
 
 
88
 
void ms::Surface::set_alpha(float alpha_v)
89
 
{
90
 
    surface_state->apply_alpha(alpha_v);
91
 
}
92
 
 
93
 
void ms::Surface::set_hidden(bool hide)
94
 
{
95
 
    surface_state->set_hidden(hide);
96
 
}
97
 
 
98
 
geom::Point ms::Surface::top_left() const
99
 
{
100
 
    return surface_state->position();
101
 
}
102
 
 
103
 
mir::geometry::Size ms::Surface::size() const
104
 
{
105
 
    return surface_state->size();
106
 
}
107
 
 
108
 
geom::PixelFormat ms::Surface::pixel_format() const
109
 
{
110
 
    return surface_buffer_stream->get_stream_pixel_format();
111
 
}
112
 
 
113
 
std::shared_ptr<mg::Buffer> ms::Surface::advance_client_buffer()
114
 
{
115
 
    if (surface_in_startup)
116
 
    {
117
 
        surface_in_startup = false;
118
 
    }
119
 
    else
120
 
    {
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.
123
 
        flag_for_render();
124
 
    }
125
 
 
126
 
    return surface_buffer_stream->secure_client_buffer();
127
 
}
128
 
 
129
 
void ms::Surface::allow_framedropping(bool allow)
130
 
{
131
 
    surface_buffer_stream->allow_framedropping(allow);
132
 
}
133
 
 
134
 
std::shared_ptr<mg::Buffer> ms::Surface::snapshot_buffer() const
135
 
{
136
 
    return surface_buffer_stream->lock_snapshot_buffer();
137
 
}
138
 
 
139
 
//TODO: this is just used in example code, could be private
140
 
void ms::Surface::flag_for_render()
141
 
{
142
 
    surface_state->frame_posted();
143
 
}
144
 
 
145
 
bool ms::Surface::supports_input() const
146
 
{
147
 
    if (server_input_channel)
148
 
        return true;
149
 
    return false;
150
 
}
151
 
 
152
 
int ms::Surface::client_input_fd() const
153
 
{
154
 
    if (!supports_input())
155
 
        BOOST_THROW_EXCEPTION(std::logic_error("Surface does not support input"));
156
 
    return server_input_channel->client_fd();
157
 
}
158
 
 
159
 
std::shared_ptr<mi::InputChannel> ms::Surface::input_channel() const
160
 
{
161
 
    return server_input_channel;
162
 
}
163
 
 
164
 
std::shared_ptr<mi::Surface> ms::Surface::input_surface() const
165
 
{
166
 
    return surface_state;
167
 
}
168
 
 
169
 
void ms::Surface::set_input_region(std::vector<geom::Rectangle> const& input_rectangles)
170
 
{
171
 
    surface_state->set_input_region(input_rectangles);
172
 
}
173
 
 
174
 
void ms::Surface::resize(geom::Size const& size)
175
 
{
176
 
    if (size.width <= geom::Width{0} || size.height <= geom::Height{0})
177
 
    {
178
 
        BOOST_THROW_EXCEPTION(std::logic_error("Impossible resize requested"));
179
 
    }
180
 
    /*
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:
185
 
     */
186
 
    surface_buffer_stream->resize(size);
187
 
 
188
 
    // Now the buffer stream has successfully resized, update the state second;
189
 
    surface_state->resize(size);
190
 
}