Mir

Merge lp:~alan-griffiths/mir/tidy-up-nested-class-responsibilities into lp:~mir-team/mir/trunk

Proposed by Alan Griffiths
Status: Merged
Approved by: Alan Griffiths
Approved revision: no longer in the source branch.
Merged at revision: 1046
Proposed branch: lp:~alan-griffiths/mir/tidy-up-nested-class-responsibilities
Merge into: lp:~mir-team/mir/trunk
Diff against target: 555 lines (+240/-160)
6 files modified
src/server/graphics/nested/CMakeLists.txt (+1/-0)
src/server/graphics/nested/nested_display.cpp (+38/-115)
src/server/graphics/nested/nested_display.h (+12/-44)
src/server/graphics/nested/nested_output.cpp (+105/-0)
src/server/graphics/nested/nested_output.h (+83/-0)
src/server/graphics/nested/nested_platform.cpp (+1/-1)
To merge this branch: bzr merge lp:~alan-griffiths/mir/tidy-up-nested-class-responsibilities
Reviewer Review Type Date Requested Status
Eleni Maria Stea (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+183233@code.launchpad.net

Commit message

graphics: tidy up the roles and responsibilities of nested classes

Description of the change

graphics: tidy up the roles and responsibilities of nested classes

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Eleni Maria Stea (hikiko) wrote :

nice you moved this piece of code, looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/server/graphics/nested/CMakeLists.txt'
2--- src/server/graphics/nested/CMakeLists.txt 2013-08-30 09:01:48 +0000
3+++ src/server/graphics/nested/CMakeLists.txt 2013-08-30 17:00:40 +0000
4@@ -7,6 +7,7 @@
5
6 nested_display.cpp
7 nested_display_configuration.cpp
8+ nested_output.cpp
9 nested_platform.cpp
10 host_connection.cpp
11 )
12
13=== modified file 'src/server/graphics/nested/nested_display.cpp'
14--- src/server/graphics/nested/nested_display.cpp 2013-08-29 03:48:16 +0000
15+++ src/server/graphics/nested/nested_display.cpp 2013-08-30 17:00:40 +0000
16@@ -18,70 +18,21 @@
17
18 #include "nested_display.h"
19 #include "nested_display_configuration.h"
20+#include "nested_output.h"
21 #include "mir_api_wrappers.h"
22
23 #include "mir/geometry/rectangle.h"
24 #include "mir/graphics/gl_context.h"
25+#include "mir/graphics/nested/host_connection.h"
26
27 #include <boost/throw_exception.hpp>
28 #include <stdexcept>
29-#include <atomic>
30
31 namespace mg = mir::graphics;
32 namespace mgn = mir::graphics::nested;
33 namespace mgnw = mir::graphics::nested::mir_api_wrappers;
34 namespace geom = mir::geometry;
35
36-namespace
37-{
38-EGLint const egl_attribs[] = {
39- EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
40- EGL_RED_SIZE, 8,
41- EGL_GREEN_SIZE, 8,
42- EGL_BLUE_SIZE, 8,
43- EGL_ALPHA_SIZE, 8,
44- EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
45- EGL_NONE
46-};
47-
48-EGLint const egl_context_attribs[] = {
49- EGL_CONTEXT_CLIENT_VERSION, 2,
50- EGL_NONE
51-};
52-}
53-
54-
55-mgn::detail::MirSurfaceHandle::MirSurfaceHandle(MirConnection* connection, DisplayConfigurationOutput const& output)
56-{
57- auto const& egl_display_mode = output.modes[output.current_mode_index];
58- auto const egl_display_format = output.pixel_formats[output.current_format_index];
59-
60- MirSurfaceParameters const request_params =
61- {
62- "Mir nested display",
63- egl_display_mode.size.width.as_int(),
64- egl_display_mode.size.height.as_int(),
65- MirPixelFormat(egl_display_format),
66- mir_buffer_usage_hardware,
67- static_cast<uint32_t>(output.id.as_value())
68- };
69-
70- mir_surface = mir_connection_create_surface_sync(connection, &request_params);
71-
72- if (!mir_surface_is_valid(mir_surface))
73- BOOST_THROW_EXCEPTION(std::runtime_error(mir_surface_get_error_message(mir_surface)));
74-}
75-
76-mgn::detail::MirSurfaceHandle::~MirSurfaceHandle() noexcept
77-{
78- mir_surface_release_sync(mir_surface);
79-}
80-
81-namespace
82-{
83-std::atomic<int> display_handles{-1};
84-}
85-
86 mgn::detail::EGLDisplayHandle::EGLDisplayHandle(MirConnection* connection)
87 {
88 auto const native_display = (EGLNativeDisplayType) mir_connection_get_egl_native_display(connection);
89@@ -91,8 +42,6 @@
90 egl_display = eglGetDisplay(native_display);
91 if (egl_display == EGL_NO_DISPLAY)
92 BOOST_THROW_EXCEPTION(std::runtime_error("Nested Mir Display Error: Failed to fetch EGL display."));
93-
94- display_handles.fetch_add(1);
95 }
96
97 void mgn::detail::EGLDisplayHandle::initialize() const
98@@ -133,62 +82,16 @@
99
100 mgn::detail::EGLDisplayHandle::~EGLDisplayHandle() noexcept
101 {
102- if (!display_handles.fetch_add(-1)) eglTerminate(egl_display);
103-}
104-
105-mgn::detail::NestedOutput::NestedOutput(MirConnection* connection, DisplayConfigurationOutput const& output) :
106- mir_surface(connection, output),
107- egl_display{connection},
108- egl_config{(egl_display.initialize(), egl_display.choose_config(egl_attribs))},
109- egl_context{egl_display, eglCreateContext(egl_display, egl_config, EGL_NO_CONTEXT, egl_context_attribs)},
110- area{output.top_left, output.modes[output.current_mode_index].size},
111- egl_surface{EGL_NO_SURFACE}
112-{
113-}
114-
115-geom::Rectangle mgn::detail::NestedOutput::view_area() const
116-{
117- return area;
118-}
119-
120-void mgn::detail::NestedOutput::make_current()
121-{
122- egl_surface = egl_display.egl_surface(egl_config, mir_surface);
123-
124- if (eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context) != EGL_TRUE)
125- BOOST_THROW_EXCEPTION(std::runtime_error("Nested Mir Display Error: Failed to update EGL surface.\n"));
126-}
127-
128-void mgn::detail::NestedOutput::release_current()
129-{
130- eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
131- eglDestroySurface(egl_display, egl_surface);
132- egl_surface = EGL_NO_SURFACE;
133-}
134-
135-void mgn::detail::NestedOutput::post_update()
136-{
137- mir_surface_swap_buffers_sync(mir_surface);
138-}
139-
140-bool mgn::detail::NestedOutput::can_bypass() const
141-{
142- // TODO we really should return "true" - but we need to support bypass properly then
143- return false;
144-}
145-
146-
147-mgn::detail::NestedOutput::~NestedOutput() noexcept
148-{
149- if (egl_surface != EGL_NO_SURFACE)
150- eglDestroySurface(egl_display, egl_surface);
151-}
152-
153-mgn::NestedDisplay::NestedDisplay(MirConnection* connection, std::shared_ptr<mg::DisplayReport> const& display_report) :
154+ eglTerminate(egl_display);
155+}
156+
157+mgn::NestedDisplay::NestedDisplay(std::shared_ptr<HostConnection> const& connection, std::shared_ptr<mg::DisplayReport> const& display_report) :
158 connection{connection},
159 display_report{display_report},
160+ egl_display{*connection},
161 outputs{}
162 {
163+ egl_display.initialize();
164 configure(*configuration());
165 }
166
167@@ -204,7 +107,7 @@
168
169 std::shared_ptr<mg::DisplayConfiguration> mgn::NestedDisplay::configuration()
170 {
171- return std::make_shared<NestedDisplayConfiguration>(mir_connection_create_display_config(connection));
172+ return std::make_shared<NestedDisplayConfiguration>(mir_connection_create_display_config(*connection));
173 }
174
175 void mgn::NestedDisplay::configure(mg::DisplayConfiguration const& configuration)
176@@ -219,7 +122,27 @@
177 {
178 if (output.used)
179 {
180- result[output.id] = std::make_shared<mgn::detail::NestedOutput>(connection, output);
181+ geometry::Rectangle const area{output.top_left, output.modes[output.current_mode_index].size};
182+
183+ auto const& egl_display_mode = output.modes[output.current_mode_index];
184+ auto const egl_display_format = output.pixel_formats[output.current_format_index];
185+
186+ MirSurfaceParameters const request_params =
187+ {
188+ "Mir nested display",
189+ egl_display_mode.size.width.as_int(),
190+ egl_display_mode.size.height.as_int(),
191+ MirPixelFormat(egl_display_format),
192+ mir_buffer_usage_hardware,
193+ static_cast<uint32_t>(output.id.as_value())
194+ };
195+
196+ auto const mir_surface = mir_connection_create_surface_sync(*connection, &request_params);
197+
198+ if (!mir_surface_is_valid(mir_surface))
199+ BOOST_THROW_EXCEPTION(std::runtime_error(mir_surface_get_error_message(mir_surface)));
200+
201+ result[output.id] = std::make_shared<mgn::detail::NestedOutput>(egl_display, mir_surface, area);
202 }
203 });
204
205@@ -229,7 +152,7 @@
206 auto const& conf = dynamic_cast<NestedDisplayConfiguration const&>(configuration);
207
208 outputs.swap(result);
209- mir_connection_apply_display_config(connection, conf);
210+ mir_connection_apply_display_config(*connection, conf);
211 }
212
213 namespace
214@@ -245,7 +168,7 @@
215 DisplayConfigurationChangeHandler const& conf_change_handler)
216 {
217 mir_connection_set_display_config_change_callback(
218- connection,
219+ *connection,
220 &display_config_callback_thunk,
221 &(my_conf_change_handler = conf_change_handler));
222 }
223@@ -281,10 +204,10 @@
224 class NestedGLContext : public mg::GLContext
225 {
226 public:
227- NestedGLContext(MirConnection* connection) :
228- egl_display{connection},
229- egl_config{(egl_display.initialize(), egl_display.choose_config(egl_attribs))},
230- egl_context{egl_display, eglCreateContext(egl_display, egl_config, EGL_NO_CONTEXT, egl_context_attribs)}
231+ NestedGLContext(detail::EGLDisplayHandle const& egl_display) :
232+ egl_display{egl_display},
233+ egl_config{egl_display.choose_config(detail::egl_attribs)},
234+ egl_context{egl_display, eglCreateContext(egl_display, egl_config, EGL_NO_CONTEXT, detail::egl_context_attribs)}
235 {
236 }
237
238@@ -299,10 +222,10 @@
239 }
240
241 private:
242- detail::EGLDisplayHandle const egl_display;
243+ EGLDisplay const egl_display;
244 EGLConfig const egl_config;
245 EGLContextStore const egl_context;
246 };
247
248- return std::unique_ptr<mg::GLContext>{new NestedGLContext(connection)};
249+ return std::unique_ptr<mg::GLContext>{new NestedGLContext(egl_display)};
250 }
251
252=== modified file 'src/server/graphics/nested/nested_display.h'
253--- src/server/graphics/nested/nested_display.h 2013-08-29 03:48:16 +0000
254+++ src/server/graphics/nested/nested_display.h 2013-08-30 17:00:40 +0000
255@@ -24,7 +24,7 @@
256 #include "mir/graphics/display_configuration.h"
257 #include "mir/graphics/egl_resources.h"
258
259-#include "mir_toolkit/mir_client_library.h"
260+#include "mir_toolkit/client_types.h"
261
262 #include <EGL/egl.h>
263
264@@ -45,21 +45,6 @@
265 {
266 namespace detail
267 {
268-class MirSurfaceHandle
269-{
270-public:
271- explicit MirSurfaceHandle(MirConnection* connection, DisplayConfigurationOutput const& output);
272- ~MirSurfaceHandle() noexcept;
273-
274- operator MirSurface*() const { return mir_surface; }
275-
276-private:
277- MirSurface* mir_surface;
278-
279- MirSurfaceHandle(MirSurfaceHandle const&) = delete;
280- MirSurfaceHandle operator=(MirSurfaceHandle const&) = delete;
281-};
282-
283 class EGLDisplayHandle
284 {
285 public:
286@@ -79,38 +64,19 @@
287 EGLDisplayHandle operator=(EGLDisplayHandle const&) = delete;
288 };
289
290-class NestedOutput : public DisplayBuffer
291-{
292-public:
293- NestedOutput(MirConnection* connection, DisplayConfigurationOutput const& output);
294- ~NestedOutput() noexcept;
295-
296- geometry::Rectangle view_area() const override;
297- void make_current() override;
298- void release_current() override;
299- void post_update() override;
300- virtual bool can_bypass() const;
301-
302- NestedOutput(NestedOutput const&) = delete;
303- NestedOutput operator=(NestedOutput const&) = delete;
304-private:
305- detail::MirSurfaceHandle const mir_surface;
306- detail::EGLDisplayHandle const egl_display;
307-
308- EGLConfig const egl_config;
309- EGLContextStore const egl_context;
310-
311- geometry::Rectangle const area;
312- EGLSurface egl_surface;
313-};
314-
315+class NestedOutput;
316 }
317
318+class HostConnection;
319+
320 class NestedDisplay : public Display
321 {
322 public:
323- NestedDisplay(MirConnection* connection, std::shared_ptr<DisplayReport>const& display_report);
324- virtual ~NestedDisplay() noexcept;
325+ NestedDisplay(
326+ std::shared_ptr<HostConnection> const& connection,
327+ std::shared_ptr<DisplayReport> const& display_report);
328+
329+ ~NestedDisplay() noexcept;
330
331 void for_each_display_buffer(std::function<void(DisplayBuffer&)>const& f) override;
332
333@@ -133,8 +99,10 @@
334 std::unique_ptr<graphics::GLContext> create_gl_context() override;
335
336 private:
337- MirConnection* const connection;
338+ std::shared_ptr<HostConnection> const connection;
339 std::shared_ptr<DisplayReport> const display_report;
340+ detail::EGLDisplayHandle const egl_display;
341+
342 std::unordered_map<DisplayConfigurationOutputId, std::shared_ptr<detail::NestedOutput>> outputs;
343 DisplayConfigurationChangeHandler my_conf_change_handler;
344 };
345
346=== added file 'src/server/graphics/nested/nested_output.cpp'
347--- src/server/graphics/nested/nested_output.cpp 1970-01-01 00:00:00 +0000
348+++ src/server/graphics/nested/nested_output.cpp 2013-08-30 17:00:40 +0000
349@@ -0,0 +1,105 @@
350+/*
351+ * Copyright © 2013 Canonical Ltd.
352+ *
353+ * This program is free software: you can redistribute it and/or modify it
354+ * under the terms of the GNU General Public License version 3,
355+ * as published by the Free Software Foundation.
356+ *
357+ * This program is distributed in the hope that it will be useful,
358+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
359+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
360+ * GNU General Public License for more details.
361+ *
362+ * You should have received a copy of the GNU General Public License
363+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
364+ *
365+ * Authored by: Alan Griffiths <alan@octopull.co.uk>
366+ */
367+
368+#include "nested_output.h"
369+
370+#include "mir_toolkit/mir_client_library.h"
371+
372+#include <boost/throw_exception.hpp>
373+#include <stdexcept>
374+
375+namespace mgn = mir::graphics::nested;
376+namespace geom = mir::geometry;
377+
378+mgn::detail::MirSurfaceHandle::MirSurfaceHandle(MirSurface* mir_surface) :
379+ mir_surface(mir_surface)
380+{
381+}
382+
383+mgn::detail::MirSurfaceHandle::~MirSurfaceHandle() noexcept
384+{
385+ mir_surface_release_sync(mir_surface);
386+}
387+
388+EGLint const mgn::detail::egl_attribs[] = {
389+ EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
390+ EGL_RED_SIZE, 8,
391+ EGL_GREEN_SIZE, 8,
392+ EGL_BLUE_SIZE, 8,
393+ EGL_ALPHA_SIZE, 8,
394+ EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
395+ EGL_NONE
396+};
397+
398+EGLint const mgn::detail::egl_context_attribs[] = {
399+ EGL_CONTEXT_CLIENT_VERSION, 2,
400+ EGL_NONE
401+};
402+
403+mgn::detail::NestedOutput::NestedOutput(
404+ EGLDisplayHandle const& egl_display,
405+ MirSurface* mir_surface,
406+ geometry::Rectangle const& area) :
407+ egl_display(egl_display),
408+ mir_surface{mir_surface},
409+ egl_config{egl_display.choose_config(egl_attribs)},
410+ egl_context{egl_display, eglCreateContext(egl_display, egl_config, EGL_NO_CONTEXT, egl_context_attribs)},
411+ area{area.top_left, area.size},
412+ egl_surface{EGL_NO_SURFACE}
413+{
414+}
415+
416+geom::Rectangle mgn::detail::NestedOutput::view_area() const
417+{
418+ return area;
419+}
420+
421+void mgn::detail::NestedOutput::make_current()
422+{
423+ egl_surface = egl_display.egl_surface(egl_config, mir_surface);
424+
425+ if (eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context) != EGL_TRUE)
426+ BOOST_THROW_EXCEPTION(std::runtime_error("Nested Mir Display Error: Failed to update EGL surface.\n"));
427+}
428+
429+void mgn::detail::NestedOutput::release_current()
430+{
431+ eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
432+ eglDestroySurface(egl_display, egl_surface);
433+ egl_surface = EGL_NO_SURFACE;
434+}
435+
436+void mgn::detail::NestedOutput::post_update()
437+{
438+ mir_surface_swap_buffers_sync(mir_surface);
439+}
440+
441+bool mgn::detail::NestedOutput::can_bypass() const
442+{
443+ // TODO we really should return "true" - but we need to support bypass properly then
444+ return false;
445+}
446+
447+
448+mgn::detail::NestedOutput::~NestedOutput() noexcept
449+{
450+ if (egl_surface != EGL_NO_SURFACE)
451+ eglDestroySurface(egl_display, egl_surface);
452+}
453+
454+
455
456=== added file 'src/server/graphics/nested/nested_output.h'
457--- src/server/graphics/nested/nested_output.h 1970-01-01 00:00:00 +0000
458+++ src/server/graphics/nested/nested_output.h 2013-08-30 17:00:40 +0000
459@@ -0,0 +1,83 @@
460+/*
461+ * Copyright © 2013 Canonical Ltd.
462+ *
463+ * This program is free software: you can redistribute it and/or modify it
464+ * under the terms of the GNU General Public License version 3,
465+ * as published by the Free Software Foundation.
466+ *
467+ * This program is distributed in the hope that it will be useful,
468+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
469+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
470+ * GNU General Public License for more details.
471+ *
472+ * You should have received a copy of the GNU General Public License
473+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
474+ *
475+ * Authored by: Alan Griffiths <alan@octopull.co.uk>
476+ */
477+
478+#ifndef MIR_GRAPHICS_NESTED_DETAIL_NESTED_OUTPUT_H_
479+#define MIR_GRAPHICS_NESTED_DETAIL_NESTED_OUTPUT_H_
480+
481+#include "nested_display.h"
482+
483+namespace mir
484+{
485+namespace graphics
486+{
487+namespace nested
488+{
489+namespace detail
490+{
491+class MirSurfaceHandle
492+{
493+public:
494+ explicit MirSurfaceHandle(MirSurface* mir_surface);
495+
496+ ~MirSurfaceHandle() noexcept;
497+
498+ operator MirSurface*() const { return mir_surface; }
499+
500+private:
501+ MirSurface* mir_surface;
502+
503+ MirSurfaceHandle(MirSurfaceHandle const&) = delete;
504+ MirSurfaceHandle operator=(MirSurfaceHandle const&) = delete;
505+};
506+
507+class NestedOutput : public DisplayBuffer
508+{
509+public:
510+ NestedOutput(
511+ EGLDisplayHandle const& egl_display,
512+ MirSurface* mir_surface,
513+ geometry::Rectangle const& area);
514+
515+ ~NestedOutput() noexcept;
516+
517+ geometry::Rectangle view_area() const override;
518+ void make_current() override;
519+ void release_current() override;
520+ void post_update() override;
521+ virtual bool can_bypass() const override;
522+
523+ NestedOutput(NestedOutput const&) = delete;
524+ NestedOutput operator=(NestedOutput const&) = delete;
525+private:
526+ EGLDisplayHandle const& egl_display;
527+ MirSurfaceHandle const mir_surface;
528+ EGLConfig const egl_config;
529+ EGLContextStore const egl_context;
530+ geometry::Rectangle const area;
531+
532+ EGLSurface egl_surface;
533+};
534+
535+extern EGLint const egl_attribs[];
536+extern EGLint const egl_context_attribs[];
537+}
538+}
539+}
540+}
541+
542+#endif /* MIR_GRAPHICS_NESTED_DETAIL_NESTED_OUTPUT_H_ */
543
544=== modified file 'src/server/graphics/nested/nested_platform.cpp'
545--- src/server/graphics/nested/nested_platform.cpp 2013-08-30 09:01:48 +0000
546+++ src/server/graphics/nested/nested_platform.cpp 2013-08-30 17:00:40 +0000
547@@ -55,7 +55,7 @@
548
549 std::shared_ptr<mg::Display> mgn::NestedPlatform::create_display(std::shared_ptr<mg::DisplayConfigurationPolicy> const& /*initial_conf_policy*/)
550 {
551- return std::make_shared<mgn::NestedDisplay>(*connection, display_report);
552+ return std::make_shared<mgn::NestedDisplay>(connection, display_report);
553 }
554
555 std::shared_ptr<mg::PlatformIPCPackage> mgn::NestedPlatform::get_ipc_package()

Subscribers

People subscribed via source and target branches