Mir

Merge lp:~alan-griffiths/mir/port-examples-off-obsolete-APIs into lp:mir

Proposed by Alan Griffiths on 2017-05-23
Status: Merged
Approved by: Gerry Boland on 2017-05-26
Approved revision: 4174
Merged at revision: 4180
Proposed branch: lp:~alan-griffiths/mir/port-examples-off-obsolete-APIs
Merge into: lp:mir
Diff against target: 255 lines (+48/-74)
5 files modified
examples/client_helpers.cpp (+20/-48)
examples/client_helpers.h (+20/-18)
examples/eglsquare.cpp (+3/-3)
examples/input_shapes.cpp (+3/-3)
examples/multi_stream.cpp (+2/-2)
To merge this branch: bzr merge lp:~alan-griffiths/mir/port-examples-off-obsolete-APIs
Reviewer Review Type Date Requested Status
Gerry Boland 2017-05-23 Approve on 2017-05-26
Andreas Pokorny (community) Approve on 2017-05-23
Mir CI Bot continuous-integration Approve on 2017-05-23
Review via email: mp+324463@code.launchpad.net

Commit message

Complete the migration of example code to the render surfaces APIs in client_helpers.cpp

To post a comment you must log in.
Mir CI Bot (mir-ci-bot) wrote :

PASSED: Continuous integration, rev:4174
https://mir-jenkins.ubuntu.com/job/mir-ci/3408/
Executed test runs:
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-mir/4636
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/4765
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial+overlay/4754
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=zesty/4754
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=zesty/4668
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=zesty/4668/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/4668
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/4668/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=zesty/4668
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=zesty/4668/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=zesty/4668
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=zesty/4668/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/4668
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/4668/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://mir-jenkins.ubuntu.com/job/mir-ci/3408/rebuild

review: Approve (continuous-integration)
Andreas Pokorny (andreas-pokorny) wrote :

lgtm

review: Approve
Gerry Boland (gerboland) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'examples/client_helpers.cpp'
2--- examples/client_helpers.cpp 2017-05-19 09:51:35 +0000
3+++ examples/client_helpers.cpp 2017-05-23 10:53:07 +0000
4@@ -1,5 +1,5 @@
5 /*
6- * Copyright © 2015 Canonical Ltd.
7+ * Copyright © 2015-2017 Canonical Ltd.
8 *
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 3 as
11@@ -18,12 +18,6 @@
12
13 #include "client_helpers.h"
14 #include "mir_toolkit/mir_client_library.h"
15-#include <thread>
16-#include <chrono>
17-#include <iostream>
18-#include <cstring>
19-#include <unistd.h>
20-#include <signal.h>
21
22 namespace me = mir::examples;
23
24@@ -51,10 +45,14 @@
25 return connection;
26 }
27
28-#pragma GCC diagnostic push
29-#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
30-me::NormalWindow::NormalWindow(me::Connection& connection, unsigned int width, unsigned int height, bool prefers_alpha, bool hardware) :
31- window{create_window(connection, width, height, prefers_alpha, hardware), window_deleter}
32+me::NormalWindow::NormalWindow(me::Connection& connection, unsigned int width, unsigned int height) :
33+ window{create_window(connection, width, height, nullptr), &mir_window_release_sync}
34+{
35+}
36+
37+mir::examples::NormalWindow::NormalWindow(
38+ mir::examples::Connection& connection, unsigned int width, unsigned int height, mir::examples::Context& eglcontext) :
39+ window{create_window(connection, width, height, eglcontext.mir_surface()), &mir_window_release_sync}
40 {
41 }
42
43@@ -64,51 +62,26 @@
44 }
45
46 MirWindow* me::NormalWindow::create_window(
47- MirConnection* connection,
48- unsigned int width,
49- unsigned int height,
50- bool prefers_alpha,
51- bool hardware)
52+ MirConnection* connection, unsigned int width, unsigned int height, MirRenderSurface* surface)
53 {
54- MirPixelFormat selected_format;
55- unsigned int valid_formats{0};
56- MirPixelFormat pixel_formats[mir_pixel_formats];
57- mir_connection_get_available_surface_formats(connection, pixel_formats, mir_pixel_formats, &valid_formats);
58- if (valid_formats == 0)
59- throw std::runtime_error("no pixel formats for surface");
60- selected_format = pixel_formats[0];
61- //select an 8 bit opaque format if we can
62- if (!prefers_alpha)
63- {
64- for(auto i = 0u; i < valid_formats; i++)
65- {
66- if (pixel_formats[i] == mir_pixel_format_xbgr_8888 ||
67- pixel_formats[i] == mir_pixel_format_xrgb_8888)
68- {
69- selected_format = pixel_formats[i];
70- break;
71- }
72- }
73- }
74-
75- auto deleter = [](MirWindowSpec *spec) { mir_window_spec_release(spec); };
76- std::unique_ptr<MirWindowSpec, decltype(deleter)> spec{
77+ std::unique_ptr<MirWindowSpec, decltype(&mir_window_spec_release)> spec{
78 mir_create_normal_window_spec(connection, width, height),
79- deleter
80+ &mir_window_spec_release
81 };
82
83- mir_window_spec_set_pixel_format(spec.get(), selected_format);
84 mir_window_spec_set_name(spec.get(), __PRETTY_FUNCTION__);
85- mir_window_spec_set_buffer_usage(spec.get(), hardware ? mir_buffer_usage_hardware : mir_buffer_usage_software);
86+
87+ if (surface)
88+ mir_window_spec_add_render_surface(spec.get(), surface, width, height, 0, 0);
89+
90 auto window = mir_create_window_sync(spec.get());
91 return window;
92 }
93
94-me::Context::Context(Connection& connection, MirWindow* window, int swap_interval) :
95- native_display(reinterpret_cast<EGLNativeDisplayType>(
96- mir_connection_get_egl_native_display(connection))),
97- native_window(reinterpret_cast<EGLNativeWindowType>(
98- mir_buffer_stream_get_egl_native_window(mir_window_get_buffer_stream(window)))),
99+me::Context::Context(Connection& connection, int swap_interval, unsigned int width, unsigned int height) :
100+ rsurface{mir_connection_create_render_surface_sync(connection, width, height), &mir_render_surface_release},
101+ native_display(connection),
102+ native_window(reinterpret_cast<EGLNativeWindowType>(rsurface.get())),
103 display(native_display),
104 config(chooseconfig(display.disp)),
105 surface(display.disp, config, native_window),
106@@ -117,7 +90,6 @@
107 make_current();
108 eglSwapInterval(display.disp, swap_interval);
109 }
110-#pragma GCC diagnostic pop
111
112 void me::Context::make_current()
113 {
114
115=== modified file 'examples/client_helpers.h'
116--- examples/client_helpers.h 2017-05-19 09:51:35 +0000
117+++ examples/client_helpers.h 2017-05-23 10:53:07 +0000
118@@ -1,5 +1,5 @@
119 /*
120- * Copyright © 2015 Canonical Ltd.
121+ * Copyright © 2015-2017 Canonical Ltd.
122 *
123 * This program is free software: you can redistribute it and/or modify
124 * it under the terms of the GNU General Public License version 3 as
125@@ -41,32 +41,18 @@
126 MirConnection* connection;
127 };
128
129-class NormalWindow
130-{
131-public:
132- NormalWindow(Connection& connection, unsigned int width, unsigned int height, bool prefers_alpha = false, bool hardware = true);
133-
134- operator MirWindow*() const;
135-private:
136- MirWindow* create_window(MirConnection* connection, unsigned int width, unsigned int height, bool prefers_alpha, bool hardware);
137- std::function<void(MirWindow*)> const window_deleter{
138- [](MirWindow* window) { mir_window_release_sync(window); }
139- };
140- std::unique_ptr<MirWindow, decltype(window_deleter)> window;
141- NormalWindow(NormalWindow const&) = delete;
142- NormalWindow& operator=(NormalWindow const&) = delete;
143-};
144-
145 class Context
146 {
147 public:
148- Context(Connection& connection, MirWindow* surface, int swap_interval);
149+ Context(Connection& connection, int swap_interval, unsigned int width, unsigned int height);
150 void make_current();
151 void release_current();
152 void swapbuffers();
153+ MirRenderSurface* mir_surface() const { return rsurface.get(); }
154 Context(Context const&) = delete;
155 Context& operator=(Context const&) = delete;
156 private:
157+ std::unique_ptr<MirRenderSurface, decltype(&mir_render_surface_release)> rsurface;
158 EGLConfig chooseconfig(EGLDisplay disp);
159 EGLNativeDisplayType native_display;
160 EGLNativeWindowType native_window;
161@@ -94,6 +80,22 @@
162 } context;
163 };
164
165+class NormalWindow
166+{
167+public:
168+ NormalWindow(Connection& connection, unsigned int width, unsigned int height);
169+ NormalWindow(Connection& connection, unsigned int width, unsigned int height, Context& eglcontext);
170+
171+ operator MirWindow*() const;
172+private:
173+ MirWindow* create_window(
174+ MirConnection* connection, unsigned int width, unsigned int height, MirRenderSurface* surface);
175+ std::unique_ptr<MirWindow, decltype(&mir_window_release_sync)> window;
176+ NormalWindow(NormalWindow const&) = delete;
177+ NormalWindow& operator=(NormalWindow const&) = delete;
178+};
179+
180+
181 struct Shader
182 {
183 Shader(GLchar const* const* src, GLuint type);
184
185=== modified file 'examples/eglsquare.cpp'
186--- examples/eglsquare.cpp 2017-05-08 03:04:26 +0000
187+++ examples/eglsquare.cpp 2017-05-23 10:53:07 +0000
188@@ -105,8 +105,8 @@
189 public:
190 SquareRenderingSurface(me::Connection& connection, int swap_interval) :
191 dimensions(active_output_dimensions(connection)),
192- window{connection, dimensions.width, dimensions.height},
193- context{connection, window, swap_interval},
194+ context{connection, swap_interval, dimensions.width, dimensions.height},
195+ window{connection, dimensions.width, dimensions.height, context},
196 program{context, dimensions.width, dimensions.height}
197 {
198 mir_window_set_event_handler(window, &on_event, this);
199@@ -151,8 +151,8 @@
200 unsigned int const height;
201 } const dimensions;
202
203+ me::Context context;
204 me::NormalWindow window;
205- me::Context context;
206 RenderProgram program;
207
208 OutputDimensions active_output_dimensions(MirConnection* connection)
209
210=== modified file 'examples/input_shapes.cpp'
211--- examples/input_shapes.cpp 2017-05-08 03:04:26 +0000
212+++ examples/input_shapes.cpp 2017-05-23 10:53:07 +0000
213@@ -104,8 +104,8 @@
214 {
215 public:
216 SurfaceWithAHole(me::Connection& connection) :
217- window{connection, width_and_height, width_and_height, true},
218- context{connection, window, 1},
219+ context{connection, 1, width_and_height, width_and_height},
220+ window{connection, width_and_height, width_and_height, context},
221 program{context, width_and_height, width_and_height}
222 {
223 context.make_current();
224@@ -122,8 +122,8 @@
225 SurfaceWithAHole(SurfaceWithAHole const&) = delete;
226 SurfaceWithAHole& operator=(SurfaceWithAHole const&) = delete;
227 private:
228+ me::Context context;
229 me::NormalWindow window;
230- me::Context context;
231 RenderProgram program;
232
233 static int const width_and_height = 500;
234
235=== modified file 'examples/multi_stream.cpp'
236--- examples/multi_stream.cpp 2017-05-19 13:49:04 +0000
237+++ examples/multi_stream.cpp 2017-05-23 10:53:07 +0000
238@@ -241,8 +241,6 @@
239
240 me::Connection connection{socket, "Multiple MirBufferStream example"};
241
242- me::NormalWindow window{connection, 200, 200, true, false};
243-
244 std::vector<MyBufferStream> stream;
245
246 stream.emplace_back(connection, 200, 200, 0, 0);
247@@ -280,6 +278,8 @@
248 0
249 };
250
251+ me::NormalWindow window{connection, 200, 200};
252+
253 while (poll(&signal_poll, 1, 0) <= 0)
254 {
255 bounce_position(stream[1].displacement_x, bottom_dx, -100, 300);

Subscribers

People subscribed via source and target branches