Merge lp:~cemil-azizoglu/mir/mir-render-surface-examples into lp:mir
- mir-render-surface-examples
- Merge into development-branch
Status: | Merged |
---|---|
Approved by: | Daniel van Vugt |
Approved revision: | no longer in the source branch. |
Merged at revision: | 3789 |
Proposed branch: | lp:~cemil-azizoglu/mir/mir-render-surface-examples |
Merge into: | lp:mir |
Prerequisite: | lp:~cemil-azizoglu/mir/mir-render-surface-v3 |
Diff against target: |
481 lines (+453/-4) 4 files modified
playground/CMakeLists.txt (+19/-0) playground/README (+3/-4) playground/eglflash_render_surface.c (+176/-0) playground/render_surface.cpp (+255/-0) |
To merge this branch: | bzr merge lp:~cemil-azizoglu/mir/mir-render-surface-examples |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Mir CI Bot | continuous-integration | Approve | |
Kevin DuBois (community) | Approve | ||
Alan Griffiths | Approve | ||
Brandon Schaefer (community) | Approve | ||
Review via email:
|
Commit message
MirRenderSurface playground examples for CPU and GPU clients.
Description of the change
MirRenderSurface playground examples for CPU and GPU clients.
- These will be removed once the headers become public. Instead, RS support will be added to 'examples' activated by a switch.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Mir CI Bot (mir-ci-bot) wrote : | # |
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Mir CI Bot (mir-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:3730
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
FAILURE: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Mir CI Bot (mir-ci-bot) wrote : | # |
PASSED: Continuous integration, rev:3731
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Brandon Schaefer (brandontschaefer) wrote : | # |
Yay more examples +1
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Alan Griffiths (alan-griffiths) wrote : | # |
Trivial conflict:
Text conflict in src/client/
1 conflicts encountered.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Alan Griffiths (alan-griffiths) wrote : | # |
+As such functionality matures, related headers become public and the relevant playground
We tend to keep the line length to 80 in these files
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Mir CI Bot (mir-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:3733
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
FAILURE: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Mir CI Bot (mir-ci-bot) wrote : | # |
PASSED: Continuous integration, rev:3734
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Kevin DuBois (kdub) wrote : | # |
lgtm too, although once RS goes public, I'd guess we will get rid of eglflash_
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Cemil Azizoglu (cemil-azizoglu) wrote : | # |
> lgtm too, although once RS goes public, I'd guess we will get rid of
> eglflash_
As I mentioned in the description :
"These will be removed once the headers become public. Instead, RS support will be added to 'examples' activated by a switch."
So yeah a switch in eglapp.c, e.g..
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Mir CI Bot (mir-ci-bot) wrote : | # |
PASSED: Continuous integration, rev:3751
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
Preview Diff
1 | === modified file 'playground/CMakeLists.txt' | |||
2 | --- playground/CMakeLists.txt 2016-08-09 08:13:02 +0000 | |||
3 | +++ playground/CMakeLists.txt 2016-10-12 21:50:47 +0000 | |||
4 | @@ -37,3 +37,22 @@ | |||
5 | 37 | target_link_libraries(mir_demo_client_chain_jumping_buffers | 37 | target_link_libraries(mir_demo_client_chain_jumping_buffers |
6 | 38 | mirclient | 38 | mirclient |
7 | 39 | ) | 39 | ) |
8 | 40 | |||
9 | 41 | mir_add_wrapped_executable(mir_demo_client_render_surface | ||
10 | 42 | render_surface.cpp | ||
11 | 43 | ) | ||
12 | 44 | |||
13 | 45 | target_link_libraries(mir_demo_client_render_surface | ||
14 | 46 | mirclient | ||
15 | 47 | eglapp | ||
16 | 48 | ) | ||
17 | 49 | |||
18 | 50 | mir_add_wrapped_executable(mir_demo_client_eglflash_render_surface | ||
19 | 51 | eglflash_render_surface.c | ||
20 | 52 | ) | ||
21 | 53 | |||
22 | 54 | target_link_libraries(mir_demo_client_eglflash_render_surface | ||
23 | 55 | mirclient | ||
24 | 56 | ${EGL_LIBRARIES} | ||
25 | 57 | ${GLESv2_LIBRARIES} | ||
26 | 58 | ) | ||
27 | 40 | 59 | ||
28 | === modified file 'playground/README' | |||
29 | --- playground/README 2014-09-10 01:45:14 +0000 | |||
30 | +++ playground/README 2016-10-12 21:50:47 +0000 | |||
31 | @@ -1,6 +1,5 @@ | |||
32 | 1 | The Playground | 1 | The Playground |
33 | 2 | 2 | ||
38 | 3 | These are mir demos that excercise private in-flux mir functionality. | 3 | These are mir demos that exercise private, in-flux mir functionality. As such |
39 | 4 | As such functionality matures, related headers become public and the playground | 4 | functionality matures, related headers become public and the relevant playground |
40 | 5 | code may become an example of how to use such feature. | 5 | code may be moved to 'examples/'. |
37 | 6 | |||
41 | 7 | 6 | ||
42 | === added file 'playground/eglflash_render_surface.c' | |||
43 | --- playground/eglflash_render_surface.c 1970-01-01 00:00:00 +0000 | |||
44 | +++ playground/eglflash_render_surface.c 2016-10-12 21:50:47 +0000 | |||
45 | @@ -0,0 +1,176 @@ | |||
46 | 1 | /* | ||
47 | 2 | * Trivial GL demo; flashes the screen with colors using a MirRenderSurface. | ||
48 | 3 | * | ||
49 | 4 | * Copyright © 2016 Canonical Ltd. | ||
50 | 5 | * | ||
51 | 6 | * This program is free software: you can redistribute it and/or modify | ||
52 | 7 | * it under the terms of the GNU General Public License version 3 as | ||
53 | 8 | * published by the Free Software Foundation. | ||
54 | 9 | * | ||
55 | 10 | * This program is distributed in the hope that it will be useful, | ||
56 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
57 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
58 | 13 | * GNU General Public License for more details. | ||
59 | 14 | * | ||
60 | 15 | * You should have received a copy of the GNU General Public License | ||
61 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
62 | 17 | * | ||
63 | 18 | * Author: Daniel van Vugt <daniel.van.vugt@canonical.com> | ||
64 | 19 | * Cemil Azizoglu <cemil.azizoglu@canonical.com> | ||
65 | 20 | */ | ||
66 | 21 | |||
67 | 22 | #include "mir_toolkit/mir_client_library.h" | ||
68 | 23 | #include "mir_toolkit/mir_render_surface.h" | ||
69 | 24 | |||
70 | 25 | #include <stdio.h> | ||
71 | 26 | #include <string.h> | ||
72 | 27 | #include <unistd.h> | ||
73 | 28 | #include <signal.h> | ||
74 | 29 | #include <pthread.h> | ||
75 | 30 | #include <EGL/egl.h> | ||
76 | 31 | #include <GLES2/gl2.h> | ||
77 | 32 | |||
78 | 33 | static volatile sig_atomic_t running = 0; | ||
79 | 34 | |||
80 | 35 | static void shutdown(int signum) | ||
81 | 36 | { | ||
82 | 37 | if (running) | ||
83 | 38 | { | ||
84 | 39 | running = 0; | ||
85 | 40 | printf("Signal %d received. Good night.\n", signum); | ||
86 | 41 | } | ||
87 | 42 | } | ||
88 | 43 | |||
89 | 44 | typedef struct Color | ||
90 | 45 | { | ||
91 | 46 | GLfloat r, g, b, a; | ||
92 | 47 | } Color; | ||
93 | 48 | |||
94 | 49 | #define CHECK(_cond, _err) \ | ||
95 | 50 | if (!(_cond)) \ | ||
96 | 51 | { \ | ||
97 | 52 | printf("%s\n", (_err)); \ | ||
98 | 53 | return -1; \ | ||
99 | 54 | } | ||
100 | 55 | |||
101 | 56 | int main(int argc, char *argv[]) | ||
102 | 57 | { | ||
103 | 58 | (void) argc; | ||
104 | 59 | (void) argv; | ||
105 | 60 | const char* appname = "EGL Render Surface Demo"; | ||
106 | 61 | int width = 100; | ||
107 | 62 | int height = 100; | ||
108 | 63 | EGLDisplay egldisplay; | ||
109 | 64 | EGLSurface eglsurface; | ||
110 | 65 | EGLint ctxattribs[] = | ||
111 | 66 | { | ||
112 | 67 | EGL_CONTEXT_CLIENT_VERSION, 2, | ||
113 | 68 | EGL_NONE | ||
114 | 69 | }; | ||
115 | 70 | EGLContext eglctx; | ||
116 | 71 | EGLConfig eglconfig; | ||
117 | 72 | EGLint neglconfigs; | ||
118 | 73 | EGLBoolean ok; | ||
119 | 74 | MirConnection* connection = NULL; | ||
120 | 75 | MirSurface* surface = NULL; | ||
121 | 76 | MirRenderSurface* render_surface = NULL; | ||
122 | 77 | |||
123 | 78 | signal(SIGINT, shutdown); | ||
124 | 79 | signal(SIGTERM, shutdown); | ||
125 | 80 | signal(SIGHUP, shutdown); | ||
126 | 81 | |||
127 | 82 | connection = mir_connect_sync(NULL, appname); | ||
128 | 83 | CHECK(mir_connection_is_valid(connection), "Can't get connection"); | ||
129 | 84 | |||
130 | 85 | egldisplay = eglGetDisplay( | ||
131 | 86 | mir_connection_get_egl_native_display(connection)); | ||
132 | 87 | CHECK(egldisplay != EGL_NO_DISPLAY, "Can't eglGetDisplay"); | ||
133 | 88 | |||
134 | 89 | ok = eglInitialize(egldisplay, NULL, NULL); | ||
135 | 90 | CHECK(ok, "Can't eglInitialize"); | ||
136 | 91 | |||
137 | 92 | const EGLint attribs[] = | ||
138 | 93 | { | ||
139 | 94 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT, | ||
140 | 95 | EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, | ||
141 | 96 | EGL_RED_SIZE, 8, | ||
142 | 97 | EGL_GREEN_SIZE, 8, | ||
143 | 98 | EGL_BLUE_SIZE, 8, | ||
144 | 99 | EGL_ALPHA_SIZE, 8, | ||
145 | 100 | EGL_NONE | ||
146 | 101 | }; | ||
147 | 102 | |||
148 | 103 | ok = eglChooseConfig(egldisplay, attribs, &eglconfig, 1, &neglconfigs); | ||
149 | 104 | CHECK(ok, "Could not eglChooseConfig"); | ||
150 | 105 | CHECK(neglconfigs > 0, "No EGL config available"); | ||
151 | 106 | |||
152 | 107 | MirPixelFormat pixel_format = | ||
153 | 108 | mir_connection_get_egl_pixel_format(connection, egldisplay, eglconfig); | ||
154 | 109 | |||
155 | 110 | printf("Mir chose pixel format %d.\n", pixel_format); | ||
156 | 111 | |||
157 | 112 | MirSurfaceSpec *spec = | ||
158 | 113 | mir_connection_create_spec_for_normal_surface(connection, width, height, pixel_format); | ||
159 | 114 | CHECK(spec, "Can't create a surface spec"); | ||
160 | 115 | |||
161 | 116 | mir_surface_spec_set_name(spec, appname); | ||
162 | 117 | mir_surface_spec_set_buffer_usage(spec, mir_buffer_usage_hardware); | ||
163 | 118 | |||
164 | 119 | render_surface = mir_connection_create_render_surface(connection); | ||
165 | 120 | CHECK(mir_render_surface_is_valid(render_surface), "could not create render surface"); | ||
166 | 121 | |||
167 | 122 | MirBufferStream* buffer_stream = | ||
168 | 123 | mir_render_surface_create_buffer_stream_sync(render_surface, | ||
169 | 124 | width, height, | ||
170 | 125 | pixel_format, | ||
171 | 126 | mir_buffer_usage_hardware); | ||
172 | 127 | |||
173 | 128 | mir_surface_spec_add_render_surface(spec, render_surface, width, height, 0, 0); | ||
174 | 129 | |||
175 | 130 | surface = mir_surface_create_sync(spec); | ||
176 | 131 | |||
177 | 132 | mir_surface_spec_release(spec); | ||
178 | 133 | |||
179 | 134 | eglsurface = eglCreateWindowSurface(egldisplay, eglconfig, | ||
180 | 135 | (EGLNativeWindowType)render_surface, NULL); | ||
181 | 136 | CHECK(eglsurface != EGL_NO_SURFACE, "eglCreateWindowSurface failed"); | ||
182 | 137 | |||
183 | 138 | eglctx = eglCreateContext(egldisplay, eglconfig, EGL_NO_CONTEXT, | ||
184 | 139 | ctxattribs); | ||
185 | 140 | CHECK(eglctx != EGL_NO_CONTEXT, "eglCreateContext failed"); | ||
186 | 141 | |||
187 | 142 | ok = eglMakeCurrent(egldisplay, eglsurface, eglsurface, eglctx); | ||
188 | 143 | CHECK(ok, "Can't eglMakeCurrent"); | ||
189 | 144 | |||
190 | 145 | Color red = {1.0f, 0.0f, 0.0f, 1.0f}; | ||
191 | 146 | Color green = {0.0f, 1.0f, 0.0f, 1.0f}; | ||
192 | 147 | Color blue = {0.0f, 0.0f, 1.0f, 1.0f}; | ||
193 | 148 | |||
194 | 149 | running = 1; | ||
195 | 150 | while (running) | ||
196 | 151 | { | ||
197 | 152 | glClearColor(red.r, red.g, red.b, red.a); | ||
198 | 153 | glClear(GL_COLOR_BUFFER_BIT); | ||
199 | 154 | eglSwapBuffers(egldisplay, eglsurface); | ||
200 | 155 | sleep(1); | ||
201 | 156 | |||
202 | 157 | glClearColor(green.r, green.g, green.b, green.a); | ||
203 | 158 | glClear(GL_COLOR_BUFFER_BIT); | ||
204 | 159 | eglSwapBuffers(egldisplay, eglsurface); | ||
205 | 160 | sleep(1); | ||
206 | 161 | |||
207 | 162 | glClearColor(blue.r, blue.g, blue.b, blue.a); | ||
208 | 163 | glClear(GL_COLOR_BUFFER_BIT); | ||
209 | 164 | eglSwapBuffers(egldisplay, eglsurface); | ||
210 | 165 | sleep(1); | ||
211 | 166 | } | ||
212 | 167 | |||
213 | 168 | eglMakeCurrent(egldisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); | ||
214 | 169 | eglTerminate(egldisplay); | ||
215 | 170 | mir_buffer_stream_release_sync(buffer_stream); | ||
216 | 171 | mir_render_surface_release(render_surface); | ||
217 | 172 | mir_surface_release_sync(surface); | ||
218 | 173 | mir_connection_release(connection); | ||
219 | 174 | |||
220 | 175 | return 0; | ||
221 | 176 | } | ||
222 | 0 | 177 | ||
223 | === added file 'playground/render_surface.cpp' | |||
224 | --- playground/render_surface.cpp 1970-01-01 00:00:00 +0000 | |||
225 | +++ playground/render_surface.cpp 2016-10-12 21:50:47 +0000 | |||
226 | @@ -0,0 +1,255 @@ | |||
227 | 1 | /* | ||
228 | 2 | * Copyright © 2016 Canonical Ltd. | ||
229 | 3 | * | ||
230 | 4 | * This program is free software: you can redistribute it and/or modify | ||
231 | 5 | * it under the terms of the GNU General Public License version 3 as | ||
232 | 6 | * published by the Free Software Foundation. | ||
233 | 7 | * | ||
234 | 8 | * This program is distributed in the hope that it will be useful, | ||
235 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
236 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
237 | 11 | * GNU General Public License for more details. | ||
238 | 12 | * | ||
239 | 13 | * You should have received a copy of the GNU General Public License | ||
240 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
241 | 15 | * | ||
242 | 16 | * Author: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com> | ||
243 | 17 | * Cemil Azizoglu <cemil.azizoglu@canonical.com> | ||
244 | 18 | */ | ||
245 | 19 | |||
246 | 20 | #include <boost/program_options.hpp> | ||
247 | 21 | #include <iostream> | ||
248 | 22 | #include <thread> | ||
249 | 23 | #include <signal.h> | ||
250 | 24 | #include <sys/signalfd.h> | ||
251 | 25 | #include <poll.h> | ||
252 | 26 | |||
253 | 27 | #include "mir_toolkit/mir_client_library.h" | ||
254 | 28 | #include "mir_toolkit/mir_render_surface.h" | ||
255 | 29 | |||
256 | 30 | #include "client_helpers.h" | ||
257 | 31 | |||
258 | 32 | namespace me = mir::examples; | ||
259 | 33 | |||
260 | 34 | class Pixel | ||
261 | 35 | { | ||
262 | 36 | public: | ||
263 | 37 | Pixel(void* addr, MirPixelFormat format) | ||
264 | 38 | : addr{addr}, | ||
265 | 39 | format{format} | ||
266 | 40 | { | ||
267 | 41 | } | ||
268 | 42 | |||
269 | 43 | void write(int r, int g, int b, int a) | ||
270 | 44 | { | ||
271 | 45 | switch (format) | ||
272 | 46 | { | ||
273 | 47 | case mir_pixel_format_abgr_8888: | ||
274 | 48 | *((uint32_t*) addr) = | ||
275 | 49 | (uint32_t) a << 24 | | ||
276 | 50 | (uint32_t) b << 16 | | ||
277 | 51 | (uint32_t) g << 8 | | ||
278 | 52 | (uint32_t) r; | ||
279 | 53 | break; | ||
280 | 54 | case mir_pixel_format_xbgr_8888: | ||
281 | 55 | *((uint32_t*) addr) = | ||
282 | 56 | /* Not filling in the X byte is correct but buggy (LP: #1423462) */ | ||
283 | 57 | (uint32_t) b << 16 | | ||
284 | 58 | (uint32_t) g << 8 | | ||
285 | 59 | (uint32_t) r; | ||
286 | 60 | break; | ||
287 | 61 | case mir_pixel_format_argb_8888: | ||
288 | 62 | *((uint32_t*) addr) = | ||
289 | 63 | (uint32_t) a << 24 | | ||
290 | 64 | (uint32_t) r << 16 | | ||
291 | 65 | (uint32_t) g << 8 | | ||
292 | 66 | (uint32_t) b; | ||
293 | 67 | break; | ||
294 | 68 | case mir_pixel_format_xrgb_8888: | ||
295 | 69 | *((uint32_t*) addr) = | ||
296 | 70 | /* Not filling in the X byte is correct but buggy (LP: #1423462) */ | ||
297 | 71 | (uint32_t) r << 16 | | ||
298 | 72 | (uint32_t) g << 8 | | ||
299 | 73 | (uint32_t) b; | ||
300 | 74 | break; | ||
301 | 75 | case mir_pixel_format_rgb_888: | ||
302 | 76 | *((uint8_t*) addr) = r; | ||
303 | 77 | *((uint8_t*) addr + 1) = g; | ||
304 | 78 | *((uint8_t*) addr + 2) = b; | ||
305 | 79 | break; | ||
306 | 80 | case mir_pixel_format_bgr_888: | ||
307 | 81 | *((uint8_t*) addr) = b; | ||
308 | 82 | *((uint8_t*) addr + 1) = g; | ||
309 | 83 | *((uint8_t*) addr + 2) = r; | ||
310 | 84 | break; | ||
311 | 85 | default: | ||
312 | 86 | throw std::runtime_error{"Pixel format unsupported by Pixel::write!"}; | ||
313 | 87 | } | ||
314 | 88 | } | ||
315 | 89 | |||
316 | 90 | public: | ||
317 | 91 | void* const addr; | ||
318 | 92 | MirPixelFormat const format; | ||
319 | 93 | }; | ||
320 | 94 | |||
321 | 95 | class pixel_iterator : std::iterator<std::random_access_iterator_tag, Pixel> | ||
322 | 96 | { | ||
323 | 97 | public: | ||
324 | 98 | pixel_iterator(MirGraphicsRegion const& region, int x, int y) | ||
325 | 99 | : x{x}, | ||
326 | 100 | y{y}, | ||
327 | 101 | buffer(region) | ||
328 | 102 | { | ||
329 | 103 | } | ||
330 | 104 | |||
331 | 105 | pixel_iterator(MirGraphicsRegion const& region) | ||
332 | 106 | : pixel_iterator(region, 0, 0) | ||
333 | 107 | { | ||
334 | 108 | } | ||
335 | 109 | |||
336 | 110 | |||
337 | 111 | pixel_iterator& operator++() | ||
338 | 112 | { | ||
339 | 113 | x++; | ||
340 | 114 | if (x == buffer.width) | ||
341 | 115 | { | ||
342 | 116 | x = 0; | ||
343 | 117 | y++; | ||
344 | 118 | } | ||
345 | 119 | return *this; | ||
346 | 120 | } | ||
347 | 121 | pixel_iterator operator++(int) | ||
348 | 122 | { | ||
349 | 123 | auto old = *this; | ||
350 | 124 | ++(*this); | ||
351 | 125 | return old; | ||
352 | 126 | } | ||
353 | 127 | |||
354 | 128 | Pixel operator*() const | ||
355 | 129 | { | ||
356 | 130 | return Pixel{ | ||
357 | 131 | buffer.vaddr + (x * MIR_BYTES_PER_PIXEL(buffer.pixel_format)) | ||
358 | 132 | + (y * buffer.stride), buffer.pixel_format}; | ||
359 | 133 | } | ||
360 | 134 | |||
361 | 135 | bool operator==(pixel_iterator const& rhs) | ||
362 | 136 | { | ||
363 | 137 | return rhs.buffer.vaddr == buffer.vaddr && | ||
364 | 138 | rhs.x == x && | ||
365 | 139 | rhs.y == y; | ||
366 | 140 | } | ||
367 | 141 | |||
368 | 142 | bool operator!=(pixel_iterator const& rhs) | ||
369 | 143 | { | ||
370 | 144 | return !(*this == rhs); | ||
371 | 145 | } | ||
372 | 146 | |||
373 | 147 | private: | ||
374 | 148 | int x, y; | ||
375 | 149 | MirGraphicsRegion const buffer; | ||
376 | 150 | }; | ||
377 | 151 | |||
378 | 152 | pixel_iterator begin(MirGraphicsRegion const& region) | ||
379 | 153 | { | ||
380 | 154 | return pixel_iterator(region); | ||
381 | 155 | } | ||
382 | 156 | |||
383 | 157 | pixel_iterator end(MirGraphicsRegion const& region) | ||
384 | 158 | { | ||
385 | 159 | return pixel_iterator{region, 0, region.height}; | ||
386 | 160 | } | ||
387 | 161 | |||
388 | 162 | void fill_stream_with(MirBufferStream* stream, int r, int g, int b, int a) | ||
389 | 163 | { | ||
390 | 164 | MirGraphicsRegion buffer; | ||
391 | 165 | mir_buffer_stream_get_graphics_region(stream, &buffer); | ||
392 | 166 | |||
393 | 167 | for (auto pixel : buffer) | ||
394 | 168 | { | ||
395 | 169 | pixel.write(r, g, b, a); | ||
396 | 170 | } | ||
397 | 171 | } | ||
398 | 172 | |||
399 | 173 | void bounce_position(int& position, int& delta, int min, int max) | ||
400 | 174 | { | ||
401 | 175 | if (position <= min || position >= max) | ||
402 | 176 | { | ||
403 | 177 | delta = -delta; | ||
404 | 178 | } | ||
405 | 179 | position += delta; | ||
406 | 180 | } | ||
407 | 181 | |||
408 | 182 | int main(int /*argc*/, char* /*argv*/[]) | ||
409 | 183 | { | ||
410 | 184 | char const* socket = nullptr; | ||
411 | 185 | int const width = 200; | ||
412 | 186 | int const height = 200; | ||
413 | 187 | int baseColour = 255, dbase = 1; | ||
414 | 188 | unsigned int nformats{0}; | ||
415 | 189 | MirPixelFormat pixel_format; | ||
416 | 190 | |||
417 | 191 | me::Connection connection{socket, "MirRenderSurface example"}; | ||
418 | 192 | |||
419 | 193 | mir_connection_get_available_surface_formats(connection, &pixel_format, 1, &nformats); | ||
420 | 194 | if (nformats == 0) | ||
421 | 195 | throw std::runtime_error("no pixel formats for buffer stream"); | ||
422 | 196 | printf("Mir selected pixel format %d\n", pixel_format); | ||
423 | 197 | |||
424 | 198 | auto render_surface = mir_connection_create_render_surface(connection); | ||
425 | 199 | |||
426 | 200 | if (!mir_render_surface_is_valid(render_surface)) | ||
427 | 201 | throw std::runtime_error(std::string("could not create render surface")); | ||
428 | 202 | |||
429 | 203 | auto spec = mir_connection_create_spec_for_normal_surface( | ||
430 | 204 | connection, | ||
431 | 205 | width, height, | ||
432 | 206 | pixel_format); | ||
433 | 207 | |||
434 | 208 | mir_surface_spec_set_name(spec, "Stream"); | ||
435 | 209 | mir_surface_spec_set_buffer_usage(spec, mir_buffer_usage_software); | ||
436 | 210 | |||
437 | 211 | auto buffer_stream = | ||
438 | 212 | mir_render_surface_create_buffer_stream_sync(render_surface, | ||
439 | 213 | width, height, | ||
440 | 214 | pixel_format, | ||
441 | 215 | mir_buffer_usage_software); | ||
442 | 216 | |||
443 | 217 | mir_surface_spec_add_render_surface(spec, render_surface, width, height, 0, 0); | ||
444 | 218 | |||
445 | 219 | auto surface = mir_surface_create_sync(spec); | ||
446 | 220 | mir_surface_spec_release(spec); | ||
447 | 221 | |||
448 | 222 | fill_stream_with(buffer_stream, 255, 0, 0, 128); | ||
449 | 223 | mir_buffer_stream_swap_buffers_sync(buffer_stream); | ||
450 | 224 | |||
451 | 225 | sigset_t halt_signals; | ||
452 | 226 | sigemptyset(&halt_signals); | ||
453 | 227 | sigaddset(&halt_signals, SIGTERM); | ||
454 | 228 | sigaddset(&halt_signals, SIGQUIT); | ||
455 | 229 | sigaddset(&halt_signals, SIGINT); | ||
456 | 230 | |||
457 | 231 | sigprocmask(SIG_BLOCK, &halt_signals, nullptr); | ||
458 | 232 | int const signal_watch{signalfd(-1, &halt_signals, SFD_CLOEXEC)}; | ||
459 | 233 | |||
460 | 234 | pollfd signal_poll{ | ||
461 | 235 | signal_watch, | ||
462 | 236 | POLLIN | POLLERR, | ||
463 | 237 | 0 | ||
464 | 238 | }; | ||
465 | 239 | |||
466 | 240 | while (poll(&signal_poll, 1, 0) <= 0) | ||
467 | 241 | { | ||
468 | 242 | bounce_position(baseColour, dbase, 128, 255); | ||
469 | 243 | |||
470 | 244 | fill_stream_with(buffer_stream, baseColour, 0, 0, 128); | ||
471 | 245 | |||
472 | 246 | mir_buffer_stream_swap_buffers_sync(buffer_stream); | ||
473 | 247 | } | ||
474 | 248 | |||
475 | 249 | mir_buffer_stream_release_sync(buffer_stream); | ||
476 | 250 | mir_render_surface_release(render_surface); | ||
477 | 251 | mir_surface_release_sync(surface); | ||
478 | 252 | close(signal_watch); | ||
479 | 253 | |||
480 | 254 | return 0; | ||
481 | 255 | } |
FAILED: Continuous integration, rev:3730 /mir-jenkins. ubuntu. com/job/ mir-ci/ 1762/ /mir-jenkins. ubuntu. com/job/ build-mir/ 2209/console /mir-jenkins. ubuntu. com/job/ build-0- fetch/2272 /mir-jenkins. ubuntu. com/job/ build-1- sourcepkg/ release= vivid+overlay/ 2263 /mir-jenkins. ubuntu. com/job/ build-1- sourcepkg/ release= xenial+ overlay/ 2263 /mir-jenkins. ubuntu. com/job/ build-1- sourcepkg/ release= yakkety/ 2263 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= clang,platform= mesa,release= yakkety/ 2237/console /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= gcc,platform= mesa,release= xenial+ overlay/ 2237 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= gcc,platform= mesa,release= xenial+ overlay/ 2237/artifact/ output/ *zip*/output. zip /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= gcc,platform= mesa,release= yakkety/ 2237 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= gcc,platform= mesa,release= yakkety/ 2237/artifact/ output/ *zip*/output. zip /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= i386,compiler= gcc,platform= android, release= vivid+overlay/ 2237 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= i386,compiler= gcc,platform= android, release= vivid+overlay/ 2237/artifact/ output/ *zip*/output. zip /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= i386,compiler= gcc,platform= mesa,release= xenial+ overlay/ 2237 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= i386,compiler= gcc,platform= mesa,release= xenial+ overlay/ 2237/artifact/ output/ *zip*/output. zip
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
FAILURE: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild: /mir-jenkins. ubuntu. com/job/ mir-ci/ 1762/rebuild
https:/