Mir
display.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2013 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: Eleni Maria Stea <elenimaria.stea@canonical.com>
17  */
18 
19 #ifndef MIR_GRAPHICS_NESTED_DISPLAY_H_
20 #define MIR_GRAPHICS_NESTED_DISPLAY_H_
21 
22 #include "mir/graphics/display.h"
26 
28 
29 #include <EGL/egl.h>
30 
31 #include <mutex>
32 #include <unordered_map>
33 
34 namespace mir
35 {
36 namespace geometry
37 {
38 struct Rectangle;
39 }
40 namespace graphics
41 {
42 class DisplayReport;
43 class DisplayBuffer;
44 class DisplayConfigurationPolicy;
45 class GLConfig;
46 class Platform;
47 
48 namespace nested
49 {
50 class NestedDisplayConfiguration;
51 
52 namespace detail
53 {
54 
56 {
57 public:
58  explicit EGLSurfaceHandle(EGLDisplay display, EGLNativeWindowType native_window, EGLConfig cfg);
59  ~EGLSurfaceHandle() noexcept;
60 
61  operator EGLSurface() const { return egl_surface; }
62 
63 private:
64  EGLDisplay const egl_display;
65  EGLSurface const egl_surface;
66 };
67 
69 {
70 public:
71  EGLDisplayHandle(EGLNativeDisplayType native_display,
72  std::shared_ptr<GLConfig> const& gl_config);
73  ~EGLDisplayHandle() noexcept;
74 
75  void initialize(MirPixelFormat format);
76  EGLConfig choose_windowed_config(MirPixelFormat format) const;
77  EGLContext egl_context() const;
78  std::unique_ptr<graphics::GLContext> create_gl_context();
79 
80  operator EGLDisplay() const { return egl_display; }
81 
82 private:
83  EGLDisplay egl_display;
84  EGLContext egl_context_;
85  std::shared_ptr<GLConfig> const gl_config;
86  MirPixelFormat pixel_format;
87 
88  EGLDisplayHandle(EGLDisplayHandle const&) = delete;
89  EGLDisplayHandle operator=(EGLDisplayHandle const&) = delete;
90 };
91 
92 class DisplayBuffer;
93 
95 {
96 public:
97  DisplaySyncGroup(std::shared_ptr<detail::DisplayBuffer> const& output);
98  void for_each_display_buffer(std::function<void(graphics::DisplayBuffer&)> const&) override;
99  void post() override;
100  std::chrono::milliseconds recommended_sleep() const override;
101 
102  geometry::Rectangle view_area() const;
103 private:
104  std::shared_ptr<detail::DisplayBuffer> const output;
105 };
106 
107 extern EGLint const nested_egl_context_attribs[];
108 }
109 
110 class HostConnection;
111 
113 {
114 public:
115  Display(
116  std::shared_ptr<Platform> const& platform,
117  std::shared_ptr<HostConnection> const& connection,
118  std::shared_ptr<DisplayReport> const& display_report,
119  std::shared_ptr<DisplayConfigurationPolicy> const& conf_policy,
120  std::shared_ptr<GLConfig> const& gl_config);
121 
122  ~Display() noexcept;
123 
124  void for_each_display_sync_group(std::function<void(DisplaySyncGroup&)>const& f) override;
125 
126  std::unique_ptr<DisplayConfiguration> configuration() const override;
127  void configure(DisplayConfiguration const&) override;
128 
129  void register_configuration_change_handler(
130  EventHandlerRegister& handlers,
131  DisplayConfigurationChangeHandler const& conf_change_handler) override;
132 
133  void register_pause_resume_handlers(
134  EventHandlerRegister& handlers,
135  DisplayPauseHandler const& pause_handler,
136  DisplayResumeHandler const& resume_handler) override;
137 
138  void pause() override;
139  void resume() override;
140 
141  std::shared_ptr<graphics::Cursor> create_hardware_cursor(std::shared_ptr<CursorImage> const& initial_image) override;
142  std::unique_ptr<graphics::GLContext> create_gl_context() override;
143  std::unique_ptr<VirtualOutput> create_virtual_output(int width, int height) override;
144 
145 private:
146  std::shared_ptr<Platform> const platform;
147  std::shared_ptr<HostConnection> const connection;
148  std::shared_ptr<DisplayReport> const display_report;
149  detail::EGLDisplayHandle egl_display;
150 
151  std::mutex outputs_mutex;
152  std::unordered_map<DisplayConfigurationOutputId, std::shared_ptr<detail::DisplaySyncGroup>> outputs;
153 
154  std::mutex mutable configuration_mutex;
155  std::unique_ptr<NestedDisplayConfiguration> current_configuration;
156 
157  void create_surfaces(mir::graphics::DisplayConfiguration const& configuration);
158  void complete_display_initialization(MirPixelFormat format);
159 };
160 
161 }
162 }
163 }
164 
165 #endif // MIR_GRAPHICS_NESTED_DISPLAY_H_
void initialize(std::shared_ptr< mir::logging::Logger > const &logger)
All things Mir.
Definition: atomic_callback.h:25
Interface to an output framebuffer.
Definition: display_buffer.h:47
DisplaySyncGroup represents a group of displays that need to be output in unison as a single post() c...
Definition: display.h:55
Definition: host_connection.h:43
Definition: display.h:112
std::function< bool()> DisplayResumeHandler
Definition: display.h:41
EGLint const nested_egl_context_attribs[]
unsigned int width
Definition: touchspot_image.c:4
MirPixelFormat
32-bit pixel formats (8888): The order of components in the enum matches the order of the components ...
Definition: common.h:134
Definition: display_buffer.h:40
std::function< bool()> DisplayPauseHandler
Definition: display.h:38
Definition: rectangle.h:33
unsigned int height
Definition: touchspot_image.c:5
#define EGLNativeWindowType
Definition: client_buffer_stream.h:55
Interface to the display subsystem.
Definition: display.h:88
std::function< void()> DisplayConfigurationChangeHandler
Definition: display.h:42
Interface to a configuration of display cards and outputs.
Definition: display_configuration.h:168
Definition: event_handler_register.h:32

Copyright © 2012-2015 Canonical Ltd.
Generated on Thu Sep 8 14:50:19 UTC 2016