Mir

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

Proposed by Alan Griffiths
Status: Merged
Approved by: Gerry Boland
Approved revision: no longer in the source branch.
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 (community) Approve
Andreas Pokorny (community) Approve
Mir CI Bot continuous-integration Approve
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.
Revision history for this message
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)
Revision history for this message
Andreas Pokorny (andreas-pokorny) wrote :

lgtm

review: Approve
Revision history for this message
Gerry Boland (gerboland) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'examples/client_helpers.cpp'
--- examples/client_helpers.cpp 2017-05-19 09:51:35 +0000
+++ examples/client_helpers.cpp 2017-05-23 10:53:07 +0000
@@ -1,5 +1,5 @@
1/*1/*
2 * Copyright © 2015 Canonical Ltd.2 * Copyright © 2015-2017 Canonical Ltd.
3 *3 *
4 * This program is free software: you can redistribute it and/or modify4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as5 * it under the terms of the GNU General Public License version 3 as
@@ -18,12 +18,6 @@
1818
19#include "client_helpers.h"19#include "client_helpers.h"
20#include "mir_toolkit/mir_client_library.h"20#include "mir_toolkit/mir_client_library.h"
21#include <thread>
22#include <chrono>
23#include <iostream>
24#include <cstring>
25#include <unistd.h>
26#include <signal.h>
2721
28namespace me = mir::examples;22namespace me = mir::examples;
2923
@@ -51,10 +45,14 @@
51 return connection;45 return connection;
52}46}
5347
54#pragma GCC diagnostic push48me::NormalWindow::NormalWindow(me::Connection& connection, unsigned int width, unsigned int height) :
55#pragma GCC diagnostic ignored "-Wdeprecated-declarations"49 window{create_window(connection, width, height, nullptr), &mir_window_release_sync}
56me::NormalWindow::NormalWindow(me::Connection& connection, unsigned int width, unsigned int height, bool prefers_alpha, bool hardware) :50{
57 window{create_window(connection, width, height, prefers_alpha, hardware), window_deleter}51}
52
53mir::examples::NormalWindow::NormalWindow(
54 mir::examples::Connection& connection, unsigned int width, unsigned int height, mir::examples::Context& eglcontext) :
55 window{create_window(connection, width, height, eglcontext.mir_surface()), &mir_window_release_sync}
58{56{
59}57}
6058
@@ -64,51 +62,26 @@
64}62}
6563
66MirWindow* me::NormalWindow::create_window(64MirWindow* me::NormalWindow::create_window(
67 MirConnection* connection,65 MirConnection* connection, unsigned int width, unsigned int height, MirRenderSurface* surface)
68 unsigned int width,
69 unsigned int height,
70 bool prefers_alpha,
71 bool hardware)
72{66{
73 MirPixelFormat selected_format;67 std::unique_ptr<MirWindowSpec, decltype(&mir_window_spec_release)> spec{
74 unsigned int valid_formats{0};
75 MirPixelFormat pixel_formats[mir_pixel_formats];
76 mir_connection_get_available_surface_formats(connection, pixel_formats, mir_pixel_formats, &valid_formats);
77 if (valid_formats == 0)
78 throw std::runtime_error("no pixel formats for surface");
79 selected_format = pixel_formats[0];
80 //select an 8 bit opaque format if we can
81 if (!prefers_alpha)
82 {
83 for(auto i = 0u; i < valid_formats; i++)
84 {
85 if (pixel_formats[i] == mir_pixel_format_xbgr_8888 ||
86 pixel_formats[i] == mir_pixel_format_xrgb_8888)
87 {
88 selected_format = pixel_formats[i];
89 break;
90 }
91 }
92 }
93
94 auto deleter = [](MirWindowSpec *spec) { mir_window_spec_release(spec); };
95 std::unique_ptr<MirWindowSpec, decltype(deleter)> spec{
96 mir_create_normal_window_spec(connection, width, height),68 mir_create_normal_window_spec(connection, width, height),
97 deleter69 &mir_window_spec_release
98 };70 };
9971
100 mir_window_spec_set_pixel_format(spec.get(), selected_format);
101 mir_window_spec_set_name(spec.get(), __PRETTY_FUNCTION__);72 mir_window_spec_set_name(spec.get(), __PRETTY_FUNCTION__);
102 mir_window_spec_set_buffer_usage(spec.get(), hardware ? mir_buffer_usage_hardware : mir_buffer_usage_software);73
74 if (surface)
75 mir_window_spec_add_render_surface(spec.get(), surface, width, height, 0, 0);
76
103 auto window = mir_create_window_sync(spec.get());77 auto window = mir_create_window_sync(spec.get());
104 return window;78 return window;
105}79}
10680
107me::Context::Context(Connection& connection, MirWindow* window, int swap_interval) :81me::Context::Context(Connection& connection, int swap_interval, unsigned int width, unsigned int height) :
108 native_display(reinterpret_cast<EGLNativeDisplayType>(82 rsurface{mir_connection_create_render_surface_sync(connection, width, height), &mir_render_surface_release},
109 mir_connection_get_egl_native_display(connection))),83 native_display(connection),
110 native_window(reinterpret_cast<EGLNativeWindowType>(84 native_window(reinterpret_cast<EGLNativeWindowType>(rsurface.get())),
111 mir_buffer_stream_get_egl_native_window(mir_window_get_buffer_stream(window)))),
112 display(native_display),85 display(native_display),
113 config(chooseconfig(display.disp)),86 config(chooseconfig(display.disp)),
114 surface(display.disp, config, native_window),87 surface(display.disp, config, native_window),
@@ -117,7 +90,6 @@
117 make_current();90 make_current();
118 eglSwapInterval(display.disp, swap_interval);91 eglSwapInterval(display.disp, swap_interval);
119}92}
120#pragma GCC diagnostic pop
12193
122void me::Context::make_current()94void me::Context::make_current()
123{95{
12496
=== modified file 'examples/client_helpers.h'
--- examples/client_helpers.h 2017-05-19 09:51:35 +0000
+++ examples/client_helpers.h 2017-05-23 10:53:07 +0000
@@ -1,5 +1,5 @@
1/*1/*
2 * Copyright © 2015 Canonical Ltd.2 * Copyright © 2015-2017 Canonical Ltd.
3 *3 *
4 * This program is free software: you can redistribute it and/or modify4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as5 * it under the terms of the GNU General Public License version 3 as
@@ -41,32 +41,18 @@
41 MirConnection* connection;41 MirConnection* connection;
42};42};
4343
44class NormalWindow
45{
46public:
47 NormalWindow(Connection& connection, unsigned int width, unsigned int height, bool prefers_alpha = false, bool hardware = true);
48
49 operator MirWindow*() const;
50private:
51 MirWindow* create_window(MirConnection* connection, unsigned int width, unsigned int height, bool prefers_alpha, bool hardware);
52 std::function<void(MirWindow*)> const window_deleter{
53 [](MirWindow* window) { mir_window_release_sync(window); }
54 };
55 std::unique_ptr<MirWindow, decltype(window_deleter)> window;
56 NormalWindow(NormalWindow const&) = delete;
57 NormalWindow& operator=(NormalWindow const&) = delete;
58};
59
60class Context44class Context
61{45{
62public:46public:
63 Context(Connection& connection, MirWindow* surface, int swap_interval);47 Context(Connection& connection, int swap_interval, unsigned int width, unsigned int height);
64 void make_current();48 void make_current();
65 void release_current();49 void release_current();
66 void swapbuffers();50 void swapbuffers();
51 MirRenderSurface* mir_surface() const { return rsurface.get(); }
67 Context(Context const&) = delete;52 Context(Context const&) = delete;
68 Context& operator=(Context const&) = delete;53 Context& operator=(Context const&) = delete;
69private:54private:
55 std::unique_ptr<MirRenderSurface, decltype(&mir_render_surface_release)> rsurface;
70 EGLConfig chooseconfig(EGLDisplay disp);56 EGLConfig chooseconfig(EGLDisplay disp);
71 EGLNativeDisplayType native_display;57 EGLNativeDisplayType native_display;
72 EGLNativeWindowType native_window;58 EGLNativeWindowType native_window;
@@ -94,6 +80,22 @@
94 } context;80 } context;
95};81};
9682
83class NormalWindow
84{
85public:
86 NormalWindow(Connection& connection, unsigned int width, unsigned int height);
87 NormalWindow(Connection& connection, unsigned int width, unsigned int height, Context& eglcontext);
88
89 operator MirWindow*() const;
90private:
91 MirWindow* create_window(
92 MirConnection* connection, unsigned int width, unsigned int height, MirRenderSurface* surface);
93 std::unique_ptr<MirWindow, decltype(&mir_window_release_sync)> window;
94 NormalWindow(NormalWindow const&) = delete;
95 NormalWindow& operator=(NormalWindow const&) = delete;
96};
97
98
97struct Shader99struct Shader
98{100{
99 Shader(GLchar const* const* src, GLuint type);101 Shader(GLchar const* const* src, GLuint type);
100102
=== modified file 'examples/eglsquare.cpp'
--- examples/eglsquare.cpp 2017-05-08 03:04:26 +0000
+++ examples/eglsquare.cpp 2017-05-23 10:53:07 +0000
@@ -105,8 +105,8 @@
105public:105public:
106 SquareRenderingSurface(me::Connection& connection, int swap_interval) :106 SquareRenderingSurface(me::Connection& connection, int swap_interval) :
107 dimensions(active_output_dimensions(connection)),107 dimensions(active_output_dimensions(connection)),
108 window{connection, dimensions.width, dimensions.height},108 context{connection, swap_interval, dimensions.width, dimensions.height},
109 context{connection, window, swap_interval},109 window{connection, dimensions.width, dimensions.height, context},
110 program{context, dimensions.width, dimensions.height}110 program{context, dimensions.width, dimensions.height}
111 {111 {
112 mir_window_set_event_handler(window, &on_event, this);112 mir_window_set_event_handler(window, &on_event, this);
@@ -151,8 +151,8 @@
151 unsigned int const height;151 unsigned int const height;
152 } const dimensions;152 } const dimensions;
153153
154 me::Context context;
154 me::NormalWindow window;155 me::NormalWindow window;
155 me::Context context;
156 RenderProgram program;156 RenderProgram program;
157157
158 OutputDimensions active_output_dimensions(MirConnection* connection)158 OutputDimensions active_output_dimensions(MirConnection* connection)
159159
=== modified file 'examples/input_shapes.cpp'
--- examples/input_shapes.cpp 2017-05-08 03:04:26 +0000
+++ examples/input_shapes.cpp 2017-05-23 10:53:07 +0000
@@ -104,8 +104,8 @@
104{104{
105public:105public:
106 SurfaceWithAHole(me::Connection& connection) :106 SurfaceWithAHole(me::Connection& connection) :
107 window{connection, width_and_height, width_and_height, true},107 context{connection, 1, width_and_height, width_and_height},
108 context{connection, window, 1},108 window{connection, width_and_height, width_and_height, context},
109 program{context, width_and_height, width_and_height}109 program{context, width_and_height, width_and_height}
110 {110 {
111 context.make_current();111 context.make_current();
@@ -122,8 +122,8 @@
122 SurfaceWithAHole(SurfaceWithAHole const&) = delete;122 SurfaceWithAHole(SurfaceWithAHole const&) = delete;
123 SurfaceWithAHole& operator=(SurfaceWithAHole const&) = delete;123 SurfaceWithAHole& operator=(SurfaceWithAHole const&) = delete;
124private:124private:
125 me::Context context;
125 me::NormalWindow window;126 me::NormalWindow window;
126 me::Context context;
127 RenderProgram program;127 RenderProgram program;
128128
129 static int const width_and_height = 500;129 static int const width_and_height = 500;
130130
=== modified file 'examples/multi_stream.cpp'
--- examples/multi_stream.cpp 2017-05-19 13:49:04 +0000
+++ examples/multi_stream.cpp 2017-05-23 10:53:07 +0000
@@ -241,8 +241,6 @@
241241
242 me::Connection connection{socket, "Multiple MirBufferStream example"};242 me::Connection connection{socket, "Multiple MirBufferStream example"};
243243
244 me::NormalWindow window{connection, 200, 200, true, false};
245
246 std::vector<MyBufferStream> stream;244 std::vector<MyBufferStream> stream;
247245
248 stream.emplace_back(connection, 200, 200, 0, 0);246 stream.emplace_back(connection, 200, 200, 0, 0);
@@ -280,6 +278,8 @@
280 0278 0
281 };279 };
282280
281 me::NormalWindow window{connection, 200, 200};
282
283 while (poll(&signal_poll, 1, 0) <= 0)283 while (poll(&signal_poll, 1, 0) <= 0)
284 {284 {
285 bounce_position(stream[1].displacement_x, bottom_dx, -100, 300);285 bounce_position(stream[1].displacement_x, bottom_dx, -100, 300);

Subscribers

People subscribed via source and target branches