Mir

Merge lp:~albaguirre/mir/simplify-scroll-example into lp:mir

Proposed by Alberto Aguirre
Status: Merged
Approved by: Kevin DuBois
Approved revision: no longer in the source branch.
Merged at revision: 3423
Proposed branch: lp:~albaguirre/mir/simplify-scroll-example
Merge into: lp:mir
Diff against target: 224 lines (+18/-173)
2 files modified
examples/CMakeLists.txt (+1/-7)
examples/scroll.cpp (+17/-166)
To merge this branch: bzr merge lp:~albaguirre/mir/simplify-scroll-example
Reviewer Review Type Date Requested Status
Alan Griffiths Disapprove
Kevin DuBois (community) Approve
Mir CI Bot continuous-integration Approve
Review via email: mp+290167@code.launchpad.net

Commit message

simplify scroll example

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

PASSED: Continuous integration, rev:3423
https://mir-jenkins.ubuntu.com/job/mir-ci/669/
Executed test runs:
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-mir/617
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/654
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/646
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial/646
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=vivid+overlay/627
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=vivid+overlay/627/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/627
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/627/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/627
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/627/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/627
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/627/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/627
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/627/artifact/output/*zip*/output.zip

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

review: Approve (continuous-integration)
Revision history for this message
Kevin DuBois (kdub) wrote :

lgtm

review: Approve
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

In isolation this change looks sensible, but...

- // Exiting without closing surfaces and connection is impolite but should
- // not kill the server. It actually did kill the server prior to -r 3385.
- // Running this example in CI acts as a smoke test for that failure.

...it loses a test scenario.

review: Disapprove

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'examples/CMakeLists.txt'
2--- examples/CMakeLists.txt 2016-03-23 06:39:56 +0000
3+++ examples/CMakeLists.txt 2016-03-26 15:41:04 +0000
4@@ -166,14 +166,8 @@
5 )
6
7 target_link_libraries(mir_demo_client_scroll
8+ eglapp
9 mirdraw
10- mirclient
11-
12- ${Boost_LIBRARIES}
13- ${CMAKE_THREAD_LIBS_INIT}
14- ${EGL_LIBRARIES}
15- ${GLESv2_LIBRARIES}
16-
17 )
18
19 mir_add_wrapped_executable(mir_demo_client_prompt_session prompt_session.c)
20
21=== modified file 'examples/scroll.cpp'
22--- examples/scroll.cpp 2016-03-26 00:19:29 +0000
23+++ examples/scroll.cpp 2016-03-26 15:41:04 +0000
24@@ -16,183 +16,34 @@
25 * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
26 */
27
28-#include "mir_toolkit/mir_client_library.h"
29+#include "eglapp.h"
30 #include "graphics.h"
31
32-#ifdef NDEBUG
33-// We have no error handling so rely on assert() always being present.
34-#undef NDEBUG
35-#endif
36-#include <assert.h>
37-#include <signal.h>
38-#include <string.h>
39-#include <stdio.h>
40-#include <stdlib.h>
41-#include <unistd.h>
42-#include <getopt.h>
43-#include <EGL/egl.h>
44-#include <GLES2/gl2.h>
45-
46-#include <thread>
47-
48-static char const *socket_file = NULL;
49-static EGLDisplay disp;
50-
51-
52-void create_and_run_scroll_surface(MirConnection *connection)
53+#include <exception>
54+#include <iostream>
55+
56+int main(int argc, char* argv[])
57+try
58 {
59- /* egl setup */
60- int major, minor, n, rc;
61- EGLContext context;
62- EGLSurface egl_surface;
63- EGLConfig egl_config;
64- EGLint attribs[] = {
65- EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
66- EGL_RED_SIZE, 8,
67- EGL_GREEN_SIZE, 8,
68- EGL_BLUE_SIZE, 8,
69- EGL_ALPHA_SIZE, 8,
70- EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
71- EGL_NONE };
72- EGLint context_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
73-
74- rc = eglInitialize(disp, &major, &minor);
75- assert(rc == EGL_TRUE);
76- assert(major == 1);
77- assert(minor == 4);
78-
79- rc = eglChooseConfig(disp, attribs, &egl_config, 1, &n);
80- assert(rc == EGL_TRUE);
81- assert(n == 1);
82-
83- MirPixelFormat pixel_format =
84- mir_connection_get_egl_pixel_format(connection, disp, egl_config);
85-
86- printf("Mir chose pixel format %d\n", pixel_format);
87-
88- auto deleter = [](MirSurfaceSpec *spec) { mir_surface_spec_release(spec); };
89- std::unique_ptr<MirSurfaceSpec, decltype(deleter)> spec{
90- mir_connection_create_spec_for_normal_surface(connection, 640, 480,
91- pixel_format),
92- deleter
93- };
94-
95- assert(spec != nullptr);
96-
97- mir_surface_spec_set_name(spec.get(), __PRETTY_FUNCTION__);
98- mir_surface_spec_set_buffer_usage(spec.get(), mir_buffer_usage_hardware);
99-
100- MirSurface *surface = mir_surface_create_sync(spec.get());
101- spec.reset();
102-
103- assert(surface != NULL);
104- assert(mir_surface_is_valid(surface));
105- assert(strcmp(mir_surface_get_error_message(surface), "") == 0);
106- puts("Surface created");
107-
108- EGLNativeWindowType native_window =
109- (EGLNativeWindowType)mir_buffer_stream_get_egl_native_window(
110- mir_surface_get_buffer_stream(surface));
111- assert(native_window != (EGLNativeWindowType)NULL);
112-
113- egl_surface = eglCreateWindowSurface(disp, egl_config, native_window, NULL);
114- assert(egl_surface != EGL_NO_SURFACE);
115-
116- context = eglCreateContext(disp, egl_config, EGL_NO_CONTEXT, context_attribs);
117- assert(context != EGL_NO_CONTEXT);
118-
119- rc = eglMakeCurrent(disp, egl_surface, egl_surface, context);
120- assert(rc == EGL_TRUE);
121+ unsigned int width = 640, height = 480;
122+ if (!mir_eglapp_init(argc, argv, &width, &height))
123+ return 1;
124
125 mir::draw::glAnimationBasic gl_animation;
126 gl_animation.init_gl();
127
128- for(;;)
129+ while (mir_eglapp_running())
130 {
131 gl_animation.render_gl();
132- rc = eglSwapBuffers(disp, egl_surface);
133- assert(rc == EGL_TRUE);
134+ mir_eglapp_swap_buffers();
135 gl_animation.step();
136 }
137
138- eglDestroySurface(disp, egl_surface);
139- eglDestroyContext(disp, context);
140-
141- mir_surface_release_sync(surface);
142- puts("Surface released");
143-}
144-
145-static void shutdown(int signum)
146-{
147- // Exiting without closing surfaces and connection is impolite but should
148- // not kill the server. It actually did kill the server prior to -r 3385.
149- // Running this example in CI acts as a smoke test for that failure.
150- printf("Signal %d received. Good night.\n", signum);
151- quick_exit(EXIT_SUCCESS); // quick_exit() doesn't seem to hit lp:1560943
152-}
153-
154-int main(int argc, char* argv[])
155-{
156- MirConnection *connection = 0;
157- unsigned num_windows = 1;
158- int arg;
159- opterr = 0;
160- while ((arg = getopt (argc, argv, "hm:w:")) != -1)
161- {
162- switch (arg)
163- {
164- case 'm':
165- socket_file = optarg;
166- break;
167- case 'w':
168- num_windows = atoi(optarg);
169- break;
170- case '?':
171- case 'h':
172- default:
173- puts(argv[0]);
174- puts("Usage:");
175- puts(" -m <Mir server socket>");
176- puts(" -w <Number of windows to create>:");
177- puts(" -h: this help text");
178- return -1;
179- }
180- }
181-
182- puts("Starting");
183-
184- signal(SIGINT, shutdown);
185- signal(SIGTERM, shutdown);
186- signal(SIGHUP, shutdown);
187-
188- connection = mir_connect_sync(socket_file, __PRETTY_FUNCTION__);
189- assert(connection != NULL);
190- assert(mir_connection_is_valid(connection));
191- assert(strcmp(mir_connection_get_error_message(connection), "") == 0);
192- puts("Connected");
193-
194- EGLNativeDisplayType native_display = (EGLNativeDisplayType) mir_connection_get_egl_native_display(connection);
195- disp = eglGetDisplay(native_display);
196- assert(disp != EGL_NO_DISPLAY);
197-
198- if (num_windows == 1)
199- {
200- create_and_run_scroll_surface(connection);
201- }
202- else
203- {
204- for (unsigned i = 0; i < num_windows; i++) std::thread(create_and_run_scroll_surface, connection).detach();
205- for(;;) {}
206- }
207-
208-
209- eglTerminate(disp);
210-
211- mir_connection_release(connection);
212- puts("Connection released");
213-
214+ mir_eglapp_shutdown();
215 return 0;
216 }
217-
218-
219-
220+catch(std::exception& e)
221+{
222+ std::cerr << "error : " << e.what() << std::endl;
223+ return 1;
224+}

Subscribers

People subscribed via source and target branches