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 input
37 {
38 class InputDispatcher;
39 class CursorListener;
40 }
41 namespace geometry
42 {
43 struct Rectangle;
44 }
45 namespace graphics
46 {
47 class DisplayReport;
48 class DisplayBuffer;
49 class DisplayConfigurationPolicy;
50 class GLConfig;
51 class Platform;
52 
53 namespace nested
54 {
55 namespace detail
56 {
57 
59 {
60 public:
61  explicit EGLSurfaceHandle(EGLDisplay display, EGLNativeWindowType native_window, EGLConfig cfg);
62  ~EGLSurfaceHandle() noexcept;
63 
64  operator EGLSurface() const { return egl_surface; }
65 
66 private:
67  EGLDisplay const egl_display;
68  EGLSurface const egl_surface;
69 };
70 
72 {
73 public:
74  EGLDisplayHandle(EGLNativeDisplayType native_display,
75  std::shared_ptr<GLConfig> const& gl_config);
76  ~EGLDisplayHandle() noexcept;
77 
78  void initialize(MirPixelFormat format);
79  EGLConfig choose_windowed_es_config(MirPixelFormat format) const;
80  EGLContext egl_context() const;
81  operator EGLDisplay() const { return egl_display; }
82 
83 private:
84  EGLDisplay egl_display;
85  EGLContext egl_context_;
86  std::shared_ptr<GLConfig> const gl_config;
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 private:
102  std::shared_ptr<detail::DisplayBuffer> const output;
103 };
104 
105 extern EGLint const nested_egl_context_attribs[];
106 }
107 
108 class HostConnection;
109 
111 {
112 public:
113  Display(
114  std::shared_ptr<Platform> const& platform,
115  std::shared_ptr<HostConnection> const& connection,
116  std::shared_ptr<input::InputDispatcher> const& dispatcher,
117  std::shared_ptr<DisplayReport> const& display_report,
118  std::shared_ptr<DisplayConfigurationPolicy> const& conf_policy,
119  std::shared_ptr<GLConfig> const& gl_config,
120  std::shared_ptr<input::CursorListener> const& cursor_listener);
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 
130  EventHandlerRegister& handlers,
131  DisplayConfigurationChangeHandler const& conf_change_handler) override;
132 
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 
144 private:
145  std::shared_ptr<Platform> const platform;
146  std::shared_ptr<HostConnection> const connection;
147  std::shared_ptr<input::InputDispatcher> const dispatcher;
148  std::shared_ptr<DisplayReport> const display_report;
149  detail::EGLDisplayHandle egl_display;
150  std::shared_ptr<input::CursorListener> const cursor_listener;
151 
152  std::mutex outputs_mutex;
153  std::unordered_map<DisplayConfigurationOutputId, std::shared_ptr<detail::DisplaySyncGroup>> outputs;
154  void create_surfaces(mir::graphics::DisplayConfiguration const& configuration);
155  void apply_to_connection(mir::graphics::DisplayConfiguration const& configuration);
156  void complete_display_initialization(MirPixelFormat format);
157 };
158 
159 }
160 }
161 }
162 
163 #endif // MIR_GRAPHICS_NESTED_DISPLAY_H_
All things Mir.
Definition: atomic_callback.h:25
void for_each_display_sync_group(std::function< void(DisplaySyncGroup &)>const &f) override
Executes a functor for each output group.
void post() override
Post the content of the DisplayBuffers associated with this DisplaySyncGroup.
Interface to an output framebuffer.
Definition: display_buffer.h:47
void register_pause_resume_handlers(EventHandlerRegister &handlers, DisplayPauseHandler const &pause_handler, DisplayResumeHandler const &resume_handler) override
Registers handlers for pausing and resuming the display subsystem.
DisplaySyncGroup represents a group of displays that need to be output in unison as a single post() c...
Definition: display.h:54
EGLSurfaceHandle(EGLDisplay display, EGLNativeWindowType native_window, EGLConfig cfg)
Definition: host_connection.h:40
void for_each_display_buffer(std::function< void(graphics::DisplayBuffer &)> const &) override
void resume() override
Resumes the display.
Definition: display.h:110
std::function< bool()> DisplayResumeHandler
Definition: display.h:40
EGLint const nested_egl_context_attribs[]
std::unique_ptr< graphics::GLContext > create_gl_context() override
Creates a GLContext object that shares resources with the Display's GL context.
MirPixelFormat
32-bit pixel formats (8888): The order of components in the enum matches the order of the components ...
Definition: common.h:134
std::shared_ptr< graphics::Cursor > create_hardware_cursor(std::shared_ptr< CursorImage > const &initial_image) override
Create a hardware cursor object.
std::function< bool()> DisplayPauseHandler
Definition: display.h:37
void configure(DisplayConfiguration const &) override
Sets a new output configuration.
void pause() override
Pauses the display.
EGLConfig choose_windowed_es_config(MirPixelFormat format) const
std::chrono::milliseconds recommended_sleep() const override
Returns a recommendation to the compositor as to how long it should wait before sampling the scene fo...
void register_configuration_change_handler(EventHandlerRegister &handlers, DisplayConfigurationChangeHandler const &conf_change_handler) override
Registers a handler for display configuration changes.
std::unique_ptr< DisplayConfiguration > configuration() const override
Gets a copy of the current output configuration.
EGLDisplayHandle(EGLNativeDisplayType native_display, std::shared_ptr< GLConfig > const &gl_config)
Interface to the display subsystem.
Definition: display.h:87
std::function< void()> DisplayConfigurationChangeHandler
Definition: display.h:41
Interface to a configuration of display cards and outputs.
Definition: display_configuration.h:166
Definition: event_handler_register.h:31

Copyright © 2012-2015 Canonical Ltd.
Generated on Thu Oct 8 16:20:16 UTC 2015