Mir
basic_surface.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2012-2014 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: Thomas Voss <thomas.voss@canonical.com>
17  */
18 
19 #ifndef MIR_SCENE_BASIC_SURFACE_H_
20 #define MIR_SCENE_BASIC_SURFACE_H_
21 
22 #include "mir/scene/surface.h"
23 #include "mir/basic_observers.h"
25 #include "mir/input/validator.h"
26 
27 #include "mir/geometry/rectangle.h"
28 
29 #include "mir_toolkit/common.h"
30 
31 #include <glm/glm.hpp>
32 #include <vector>
33 #include <list>
34 #include <memory>
35 #include <mutex>
36 #include <string>
37 
38 namespace mir
39 {
40 namespace compositor
41 {
42 struct BufferIPCPackage;
43 class BufferStream;
44 }
45 namespace frontend { class EventSink; }
46 namespace graphics
47 {
48 class Buffer;
49 }
50 namespace input
51 {
52 class InputChannel;
53 class InputSender;
54 class Surface;
55 }
56 namespace scene
57 {
58 class SceneReport;
59 class CursorStreamImageAdapter;
60 
61 class BasicSurface : public Surface
62 {
63 public:
65  std::string const& name,
67  bool nonrectangular,
68  std::shared_ptr<compositor::BufferStream> const& buffer_stream,
69  std::shared_ptr<input::InputChannel> const& input_channel,
70  std::shared_ptr<input::InputSender> const& sender,
71  std::shared_ptr<graphics::CursorImage> const& cursor_image,
72  std::shared_ptr<SceneReport> const& report);
73 
75  std::string const& name,
77  std::weak_ptr<Surface> const& parent,
78  bool nonrectangular,
79  std::shared_ptr<compositor::BufferStream> const& buffer_stream,
80  std::shared_ptr<input::InputChannel> const& input_channel,
81  std::shared_ptr<input::InputSender> const& sender,
82  std::shared_ptr<graphics::CursorImage> const& cursor_image,
83  std::shared_ptr<SceneReport> const& report);
84 
85  ~BasicSurface() noexcept;
86 
87  std::string name() const override;
88  void move_to(geometry::Point const& top_left) override;
89  float alpha() const override;
90  void set_hidden(bool is_hidden);
91 
92  geometry::Size size() const override;
93  geometry::Size client_size() const override;
94 
95  std::shared_ptr<frontend::BufferStream> primary_buffer_stream() const override;
96  void set_streams(std::list<scene::StreamInfo> const& streams) override;
97 
98  bool supports_input() const override;
99  int client_input_fd() const override;
100  std::shared_ptr<input::InputChannel> input_channel() const override;
101  input::InputReceptionMode reception_mode() const override;
102  void set_reception_mode(input::InputReceptionMode mode) override;
103 
104  void set_input_region(std::vector<geometry::Rectangle> const& input_rectangles) override;
105 
106  std::shared_ptr<compositor::BufferStream> buffer_stream() const;
107 
108  void resize(geometry::Size const& size) override;
109  geometry::Point top_left() const override;
110  geometry::Rectangle input_bounds() const override;
111  bool input_area_contains(geometry::Point const& point) const override;
112  void consume(MirEvent const* event) override;
113  void set_alpha(float alpha) override;
114  void set_orientation(MirOrientation orientation) override;
115  void set_transformation(glm::mat4 const&) override;
116 
117  bool visible() const override;
118 
119  graphics::RenderableList generate_renderables(compositor::CompositorID id) const override;
120  int buffers_ready_for_compositor(void const* compositor_id) const override;
121 
122  MirSurfaceType type() const override;
123  MirSurfaceState state() const override;
124  int configure(MirSurfaceAttrib attrib, int value) override;
125  int query(MirSurfaceAttrib attrib) const override;
126  void hide() override;
127  void show() override;
128 
129  void set_cursor_image(std::shared_ptr<graphics::CursorImage> const& image) override;
130  std::shared_ptr<graphics::CursorImage> cursor_image() const override;
131 
132  void set_cursor_stream(std::shared_ptr<frontend::BufferStream> const& stream,
133  geometry::Displacement const& hotspot) override;
134  void set_cursor_from_buffer(graphics::Buffer& buffer,
135  geometry::Displacement const& hotspot);
136 
137  void request_client_surface_close() override;
138 
139  std::shared_ptr<Surface> parent() const override;
140 
141  void add_observer(std::shared_ptr<SurfaceObserver> const& observer) override;
142  void remove_observer(std::weak_ptr<SurfaceObserver> const& observer) override;
143 
144  int dpi() const;
145 
146  void set_keymap(MirInputDeviceId id, std::string const& model, std::string const& layout,
147  std::string const& variant, std::string const& options) override;
148 
149  void rename(std::string const& title) override;
150 
151 private:
152  bool visible(std::unique_lock<std::mutex>&) const;
153  MirSurfaceType set_type(MirSurfaceType t); // Use configure() to make public changes
154  MirSurfaceState set_state(MirSurfaceState s);
155  int set_dpi(int);
156  MirSurfaceVisibility set_visibility(MirSurfaceVisibility v);
157  int set_swap_interval(int);
158  MirSurfaceFocusState set_focus_state(MirSurfaceFocusState f);
159  MirOrientationMode set_preferred_orientation(MirOrientationMode mode);
160 
161  SurfaceObservers observers;
162  std::mutex mutable guard;
163  std::string surface_name;
164  geometry::Rectangle surface_rect;
165  glm::mat4 transformation_matrix;
166  float surface_alpha;
167  bool hidden;
168  input::InputReceptionMode input_mode;
169  const bool nonrectangular;
170  std::vector<geometry::Rectangle> custom_input_rectangles;
171  std::shared_ptr<compositor::BufferStream> const surface_buffer_stream;
172  std::shared_ptr<input::InputChannel> const server_input_channel;
173  std::shared_ptr<input::InputSender> const input_sender;
174  std::shared_ptr<graphics::CursorImage> cursor_image_;
175  std::shared_ptr<SceneReport> const report;
176  std::weak_ptr<Surface> const parent_;
177 
178  std::list<StreamInfo> layers;
179  // Surface attributes:
182  int swapinterval_ = 1;
184  int dpi_ = 0;
186  MirOrientationMode pref_orientation_mode = mir_orientation_mode_any;
187 
188  std::unique_ptr<CursorStreamImageAdapter> const cursor_stream_adapter;
189 
190  input::Validator input_validator;
191 };
192 
193 }
194 }
195 
196 #endif // MIR_SCENE_BASIC_SURFACE_H_
Definition: size.h:30
All things Mir.
Definition: atomic_callback.h:25
Definition: common.h:90
Definition: point.h:30
Definition: common.h:84
MirOrientation
Direction relative to the "natural" orientation of the display.
Definition: common.h:164
Definition: validator.h:32
MirSurfaceState
Definition: common.h:64
int64_t MirInputDeviceId
Definition: input_event.h:35
MirSurfaceAttrib
Attributes of a surface that the client and server/shell may wish to get or set over the wire...
Definition: common.h:34
MirSurfaceType
Definition: common.h:48
Definition: basic_surface.h:61
Definition: displacement.h:32
MirSurfaceFocusState
Definition: common.h:82
MirSurfaceVisibility
Definition: common.h:88
void const * CompositorID
Definition: compositor_id.h:27
std::vector< std::shared_ptr< Renderable > > RenderableList
Definition: renderable.h:79
Definition: rectangle.h:33
Definition: surface_observers.h:30
Definition: common.h:67
Definition: event_private.h:181
Definition: common.h:182
Definition: buffer.h:44
MirOrientationMode
Definition: common.h:172
InputReceptionMode
Definition: input_reception_mode.h:27
Definition: surface.h:47
AKA "regular".
Definition: common.h:50
int const size
Definition: make_socket_rpc_channel.cpp:51

Copyright © 2012-2015 Canonical Ltd.
Generated on Wed Mar 30 00:29:56 UTC 2016