Mir

Merge lp:~alan-griffiths/mir/fix-1663130 into lp:mir

Proposed by Alan Griffiths
Status: Merged
Approved by: Chris Halse Rogers
Approved revision: no longer in the source branch.
Merged at revision: 4205
Proposed branch: lp:~alan-griffiths/mir/fix-1663130
Merge into: lp:mir
Diff against target: 623 lines (+0/-599)
3 files modified
examples/CMakeLists.txt (+0/-23)
examples/render_surfaces.cpp (+0/-468)
examples/render_to_fb.cpp (+0/-108)
To merge this branch: bzr merge lp:~alan-griffiths/mir/fix-1663130
Reviewer Review Type Date Requested Status
Chris Halse Rogers Approve
Mir CI Bot continuous-integration Approve
Review via email: mp+327420@code.launchpad.net

Commit message

Remove obsolete & broken example code

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

PASSED: Continuous integration, rev:4205
https://mir-jenkins.ubuntu.com/job/mir-ci/3485/
Executed test runs:
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-mir/4760
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/4926
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=artful/4915
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial/4915
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=zesty/4915
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=artful/4797
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=artful/4797/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=zesty/4797
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=zesty/4797/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=artful/4797
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=artful/4797/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/4797
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/4797/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=zesty/4797
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=zesty/4797/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=artful/4797
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=artful/4797/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/4797
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=zesty/4797/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/4797
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/4797/artifact/output/*zip*/output.zip

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

review: Approve (continuous-integration)
Revision history for this message
Chris Halse Rogers (raof) wrote :

Yup, that's not code we want to support.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'examples/CMakeLists.txt'
--- examples/CMakeLists.txt 2017-06-06 16:26:18 +0000
+++ examples/CMakeLists.txt 2017-07-14 11:41:27 +0000
@@ -1,15 +1,3 @@
1mir_add_wrapped_executable(mir_demo_standalone_render_surfaces
2 render_surfaces.cpp
3 buffer_render_target.cpp
4 image_renderer.cpp
5)
6
7target_link_libraries(mir_demo_standalone_render_surfaces
8 mirserver
9 exampleserverconfig
10 ${Boost_LIBRARIES}
11)
12
13set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -Wall -fno-strict-aliasing -Wextra")1set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -Wall -fno-strict-aliasing -Wextra")
142
15add_library(eglapp STATIC3add_library(eglapp STATIC
@@ -192,17 +180,6 @@
192 ${GL_INCLUDE_DIRS}180 ${GL_INCLUDE_DIRS}
193)181)
194182
195mir_add_wrapped_executable(mir_demo_standalone_render_to_fb
196 render_to_fb.cpp
197)
198
199target_link_libraries(mir_demo_standalone_render_to_fb
200 mirserver
201 mirdraw
202 ${GL_LIBRARIES}
203 ${Boost_LIBRARIES}
204)
205
206add_library(mir_demo_server_loadable MODULE183add_library(mir_demo_server_loadable MODULE
207 server_example.cpp184 server_example.cpp
208 glog_logger.cpp185 glog_logger.cpp
209186
=== removed file 'examples/render_surfaces.cpp'
--- examples/render_surfaces.cpp 2017-05-08 03:04:26 +0000
+++ examples/render_surfaces.cpp 1970-01-01 00:00:00 +0000
@@ -1,468 +0,0 @@
1/*
2 * Copyright © 2012-2014 Canonical Ltd.
3 *
4 * 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 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Alexandros Frantzis <alexandros.frantzis@canonical.com>
17 */
18
19#include "server_example_input_event_filter.h"
20#include "server_example_display_configuration_policy.h"
21#include "mir/server_status_listener.h"
22#include "mir/compositor/display_buffer_compositor.h"
23#include "mir/compositor/display_buffer_compositor_factory.h"
24#include "mir/scene/surface_creation_parameters.h"
25#include "mir/geometry/size.h"
26#include "mir/geometry/rectangles.h"
27#include "mir/graphics/display.h"
28#include "mir/graphics/display_buffer.h"
29#include "mir/graphics/platform.h"
30#include "mir/graphics/graphic_buffer_allocator.h"
31#include "mir/options/option.h"
32#include "mir/scene/surface.h"
33#include "mir/scene/buffer_stream_factory.h"
34#include "mir/scene/surface_factory.h"
35#include "mir/shell/surface_stack.h"
36#include "mir/frontend/buffer_sink.h"
37#include "mir/frontend/client_buffers.h"
38#include "mir/server.h"
39#include "mir/report_exception.h"
40#include "mir/renderer/gl/context.h"
41#include "mir/renderer/gl/context_source.h"
42
43#include "mir_image.h"
44#include "buffer_render_target.h"
45#include "image_renderer.h"
46
47#define GLM_FORCE_RADIANS
48#include <glm/gtc/matrix_transform.hpp>
49
50#include <thread>
51#include <atomic>
52#include <chrono>
53#include <csignal>
54#include <iostream>
55#include <sstream>
56#include <vector>
57
58namespace mg = mir::graphics;
59namespace mc = mir::compositor;
60namespace ms = mir::scene;
61namespace mf = mir::frontend;
62namespace mo = mir::options;
63namespace msh = mir::shell;
64namespace mi = mir::input;
65namespace geom = mir::geometry;
66namespace mt = mir::tools;
67namespace me = mir::examples;
68
69
70///\page render_surfaces-example render_surfaces.cpp: A simple program using the mir library.
71///\tableofcontents
72///render_surfaces shows the use of mir to render some moving surfaces
73///\section main main()
74/// The main() function uses a RenderSurfacesServerConfiguration to initialize and run mir.
75/// \snippet render_surfaces.cpp main_tag
76///\section RenderSurfacesServerConfiguration RenderSurfacesServerConfiguration
77/// The configuration stubs out client connectivity and input.
78/// \snippet render_surfaces.cpp RenderSurfacesServerConfiguration_stubs_tag
79/// it also provides a bespoke display buffer compositor
80/// \snippet render_surfaces.cpp RenderSurfacesDisplayBufferCompositor_tag
81///\section Utilities Utility classes
82/// For smooth animation we need to track time and move surfaces accordingly
83///\subsection StopWatch StopWatch
84/// \snippet render_surfaces.cpp StopWatch_tag
85///\subsection Moveable Moveable
86/// \snippet render_surfaces.cpp Moveable_tag
87
88///\example render_surfaces.cpp A simple program using the mir library.
89
90namespace
91{
92std::atomic<bool> created{false};
93
94static const float min_alpha = 0.3f;
95
96char const* const surfaces_to_render = "surfaces-to-render";
97
98auto as_context_source(mg::Display* display)
99{
100 auto ctx = dynamic_cast<mir::renderer::gl::ContextSource*>(display->native_display());
101 if (!ctx)
102 BOOST_THROW_EXCEPTION(std::logic_error("Display does not support GL rendering"));
103 return ctx;
104}
105
106///\internal [StopWatch_tag]
107// tracks elapsed time - for animation.
108class StopWatch
109{
110public:
111 StopWatch() : start(std::chrono::high_resolution_clock::now()),
112 last(start),
113 now(last)
114 {
115 }
116
117 void stop()
118 {
119 now = std::chrono::high_resolution_clock::now();
120 }
121
122 double elapsed_seconds_since_start()
123 {
124 auto elapsed = now - start;
125 float elapsed_sec = std::chrono::duration_cast<std::chrono::microseconds>(elapsed).count() / 1000000.0f;
126 return elapsed_sec;
127 }
128
129 double elapsed_seconds_since_last_restart()
130 {
131 auto elapsed = now - last;
132 float elapsed_sec = std::chrono::duration_cast<std::chrono::microseconds>(elapsed).count() / 1000000.0f;
133 return elapsed_sec;
134 }
135
136 void restart()
137 {
138 std::swap(last, now);
139 }
140
141private:
142 std::chrono::high_resolution_clock::time_point start;
143 std::chrono::high_resolution_clock::time_point last;
144 std::chrono::high_resolution_clock::time_point now;
145};
146///\internal [StopWatch_tag]
147
148///\internal [Moveable_tag]
149// Adapter to support movement of surfaces.
150class Moveable
151{
152public:
153 Moveable() {}
154 Moveable(std::shared_ptr<ms::Surface> const& s, const geom::Size& display_size,
155 float dx, float dy, const glm::vec3& rotation_axis, float alpha_offset)
156 : surface(s), display_size(display_size),
157 x(s->top_left().x.as_int()),
158 y(s->top_left().y.as_int()),
159 w(s->size().width.as_int()),
160 h(s->size().height.as_int()),
161 dx{dx},
162 dy{dy},
163 rotation_axis(rotation_axis),
164 alpha_offset{alpha_offset}
165 {
166 }
167
168 void step()
169 {
170 stop_watch.stop();
171 float elapsed_sec = stop_watch.elapsed_seconds_since_last_restart();
172 float total_elapsed_sec = stop_watch.elapsed_seconds_since_start();
173 stop_watch.restart();
174
175 bool should_update = true;
176 float new_x = x + elapsed_sec * dx;
177 float new_y = y + elapsed_sec * dy;
178 if (new_x < 0.0 || new_x + w > display_size.width.as_uint32_t())
179 {
180 dx = -dx;
181 should_update = false;
182 }
183
184 if (new_y < 0.0 || new_y + h > display_size.height.as_uint32_t())
185 {
186 dy = -dy;
187 should_update = false;
188 }
189
190 if (should_update)
191 {
192 surface->move_to({new_x, new_y});
193 x = new_x;
194 y = new_y;
195 }
196
197 glm::mat4 trans = glm::rotate(glm::mat4(1.0f),
198 glm::radians(total_elapsed_sec * 120.0f),
199 rotation_axis);
200 surface->set_transformation(trans);
201
202 float const alpha_amplitude = (1.0f - min_alpha) / 2.0f;
203 surface->set_alpha(min_alpha + alpha_amplitude +
204 alpha_amplitude *
205 sin(alpha_offset + 2 * M_PI * total_elapsed_sec /
206 3.0));
207 }
208
209private:
210 std::shared_ptr<ms::Surface> surface;
211 geom::Size display_size;
212 float x;
213 float y;
214 float w;
215 float h;
216 float dx;
217 float dy;
218 StopWatch stop_watch;
219 glm::vec3 rotation_axis;
220 float alpha_offset;
221};
222///\internal [Moveable_tag]
223
224void callback_when_started(mir::Server& server, std::function<void()> callback)
225{
226 struct ServerStatusListener : mir::ServerStatusListener
227 {
228 ServerStatusListener(std::function<void()> callback) :
229 callback(callback) {}
230
231 virtual void paused() override {}
232 virtual void resumed() override {}
233 virtual void started() override {callback(); callback = []{}; }
234 virtual void ready_for_user_input() override {}
235 virtual void stop_receiving_input() override {}
236
237 std::function<void()> callback;
238 };
239
240 server.override_the_server_status_listener([callback]
241 {
242 return std::make_shared<ServerStatusListener>(callback);
243 });
244}
245
246///\internal [RenderSurfacesServerConfiguration_stubs_tag]
247class RenderSurfacesDisplayBufferCompositor : public mc::DisplayBufferCompositor
248{
249public:
250 RenderSurfacesDisplayBufferCompositor(
251 std::unique_ptr<DisplayBufferCompositor> db_compositor,
252 std::vector<Moveable>& moveables)
253 : db_compositor{std::move(db_compositor)},
254 moveables(moveables),
255 frames{0}
256 {
257 }
258
259 void composite(mc::SceneElementSequence&& scene_sequence) override
260 {
261 while (!created) std::this_thread::yield();
262 stop_watch.stop();
263 if (stop_watch.elapsed_seconds_since_last_restart() >= 1)
264 {
265 std::cout << "FPS: " << frames << " Frame Time: " << 1.0 / frames << std::endl;
266 frames = 0;
267 stop_watch.restart();
268 }
269
270 db_compositor->composite(std::move(scene_sequence));
271
272 for (auto& m : moveables)
273 m.step();
274
275 frames++;
276 }
277
278private:
279 std::unique_ptr<DisplayBufferCompositor> const db_compositor;
280 StopWatch stop_watch;
281 std::vector<Moveable>& moveables;
282 uint32_t frames;
283};
284///\internal [RenderSurfacesServerConfiguration_stubs_tag]
285
286class RenderSurfacesDisplayBufferCompositorFactory : public mc::DisplayBufferCompositorFactory
287{
288public:
289 RenderSurfacesDisplayBufferCompositorFactory(
290 std::shared_ptr<mc::DisplayBufferCompositorFactory> const& factory,
291 std::vector<Moveable>& moveables)
292 : factory{factory},
293 moveables(moveables)
294 {
295 }
296
297 std::unique_ptr<mc::DisplayBufferCompositor> create_compositor_for(mg::DisplayBuffer& display_buffer)
298 {
299 auto compositor = factory->create_compositor_for(display_buffer);
300 auto raw = new RenderSurfacesDisplayBufferCompositor(
301 std::move(compositor), moveables);
302 return std::unique_ptr<RenderSurfacesDisplayBufferCompositor>(raw);
303 }
304
305private:
306 std::shared_ptr<mc::DisplayBufferCompositorFactory> const factory;
307 std::vector<Moveable>& moveables;
308};
309
310///\internal [RenderSurfacesServer_tag]
311// Extend the default configuration to manage moveables.
312class RenderSurfacesServer : private mir::Server
313{
314 std::shared_ptr<mir::input::EventFilter> const quit_filter{me::make_quit_filter_for(*this)};
315public:
316 RenderSurfacesServer(int argc, char const** argv)
317 {
318 me::add_display_configuration_options_to(*this);
319
320 ///\internal [RenderSurfacesDisplayBufferCompositor_tag]
321 // Decorate the DefaultDisplayBufferCompositor in order to move surfaces.
322 wrap_display_buffer_compositor_factory([this](std::shared_ptr<mc::DisplayBufferCompositorFactory> const& wrapped)
323 {
324 return std::make_shared<RenderSurfacesDisplayBufferCompositorFactory>(
325 wrapped,
326 moveables);
327 });
328 ///\internal [RenderSurfacesDisplayBufferCompositor_tag]
329
330 add_configuration_option(surfaces_to_render, "Number of surfaces to render", 5);
331
332 // Provide the command line and run the *this
333 set_command_line(argc, argv);
334 setenv("MIR_SERVER_NO_FILE", "", 1);
335
336 // If there's a server available, try connecting to it
337 if (auto const socket = getenv("MIR_SOCKET"))
338 setenv("MIR_SERVER_HOST_SOCKET", socket, 0);
339
340 // Unless the compositor starts before we create the surfaces it won't respond to
341 // the change notification that causes.
342 callback_when_started(*this, [this] { create_surfaces(); });
343
344 apply_settings();
345 }
346
347 using mir::Server::run;
348 using mir::Server::exited_normally;
349
350 // New function to initialize moveables with surfaces
351 void create_surfaces()
352 try
353 {
354 moveables.resize(get_options()->get<int>(surfaces_to_render));
355 std::cout << "Rendering " << moveables.size() << " surfaces" << std::endl;
356
357 auto const display = the_display();
358 auto const buffer_stream_factory = the_buffer_stream_factory();
359 auto const gralloc = the_graphics_platform()->create_buffer_allocator();
360 auto const surface_factory = the_surface_factory();
361 auto const surface_stack = the_surface_stack();
362 auto const gl_context = as_context_source(the_display().get())->create_gl_context();
363
364 /* TODO: Get proper configuration */
365 geom::Rectangles view_area;
366 display->for_each_display_sync_group([&](mg::DisplaySyncGroup& group)
367 {
368 group.for_each_display_buffer([&](mg::DisplayBuffer& db)
369 {
370 view_area.add(db.view_area());
371 });
372 });
373 geom::Size const display_size{view_area.bounding_rectangle().size};
374 uint32_t const surface_side{300};
375 geom::Size const surface_size{surface_side, surface_side};
376
377 float const angular_step = 2.0 * M_PI / moveables.size();
378 float const w = display_size.width.as_uint32_t();
379 float const h = display_size.height.as_uint32_t();
380 auto const surface_pf = supported_pixel_formats()[0];
381
382 int i = 0;
383 for (auto& m : moveables)
384 {
385 auto params = ms::a_surface()
386 .of_size(surface_size)
387 .of_pixel_format(surface_pf)
388 .of_buffer_usage(mg::BufferUsage::hardware);
389 mg::BufferProperties properties{params.size, params.pixel_format, params.buffer_usage};
390 struct NullBufferSink : mf::BufferSink
391 {
392 void send_buffer(mf::BufferStreamId, mg::Buffer&, mg::BufferIpcMsgType) override {}
393 void add_buffer(mg::Buffer&) override {}
394 void remove_buffer(mg::Buffer&) override {}
395 void update_buffer(mg::Buffer&) override {}
396 void error_buffer(geom::Size, MirPixelFormat, std::string const&) override {}
397 };
398
399 auto buffers = buffer_stream_factory->create_buffer_map(std::make_shared<NullBufferSink>());
400 auto const stream = buffer_stream_factory->create_buffer_stream({}, buffers, properties);
401 auto const surface = surface_factory->create_surface(
402 {ms::StreamInfo{stream, {}, {}}}, params);
403 surface_stack->add_surface(surface, params.input_mode);
404
405 {
406 auto buffer = gralloc->alloc_buffer(properties);
407
408 {
409 gl_context->make_current();
410
411 mt::ImageRenderer img_renderer{mir_image.pixel_data,
412 geom::Size{mir_image.width, mir_image.height},
413 mir_image.bytes_per_pixel};
414 mt::BufferRenderTarget brt{*buffer};
415 brt.make_current();
416 img_renderer.render();
417
418 gl_context->release_current();
419 }
420 surface->primary_buffer_stream()->submit_buffer(buffer);
421 }
422
423 /*
424 * Place each surface at a different starting location and give it a
425 * different speed, rotation and alpha offset.
426 */
427 uint32_t const x = w * (0.5 + 0.25 * cos(i * angular_step)) - surface_side / 2.0;
428 uint32_t const y = h * (0.5 + 0.25 * sin(i * angular_step)) - surface_side / 2.0;
429
430 surface->move_to({x, y});
431 m = Moveable(surface, display_size,
432 cos(0.1f + i * M_PI / 6.0f) * w / 3.0f,
433 sin(0.1f + i * M_PI / 6.0f) * h / 3.0f,
434 glm::vec3{(i % 3 == 0) * 1.0f, (i % 3 == 1) * 1.0f, (i % 3 == 2) * 1.0f},
435 2.0f * M_PI * cos(i));
436 ++i;
437 }
438
439 created = true;
440 }
441 catch (...)
442 {
443 mir::report_exception();
444 exit(EXIT_FAILURE);
445 }
446
447private:
448 std::vector<Moveable> moveables;
449};
450///\internal [RenderSurfacesServer_tag]
451}
452
453int main(int argc, char const** argv)
454try
455{
456 ///\internal [main_tag]
457 RenderSurfacesServer render_surfaces{argc, argv};
458
459 render_surfaces.run();
460
461 return render_surfaces.exited_normally() ? EXIT_SUCCESS : EXIT_FAILURE;
462 ///\internal [main_tag]
463}
464catch (...)
465{
466 mir::report_exception();
467 return EXIT_FAILURE;
468}
4690
=== removed file 'examples/render_to_fb.cpp'
--- examples/render_to_fb.cpp 2017-05-08 03:04:26 +0000
+++ examples/render_to_fb.cpp 1970-01-01 00:00:00 +0000
@@ -1,108 +0,0 @@
1/*
2 * Copyright © 2012-2014 Canonical Ltd.
3 *
4 * 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 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
17 */
18
19#include "graphics.h"
20#include "as_render_target.h"
21
22#include "mir/server.h"
23#include "mir/report_exception.h"
24#include "mir/graphics/display.h"
25#include "mir/graphics/display_buffer.h"
26#include "mir/renderer/gl/render_target.h"
27
28#include <csignal>
29
30namespace mg=mir::graphics;
31namespace mo=mir::options;
32namespace me=mir::examples;
33
34namespace
35{
36volatile std::sig_atomic_t running = true;
37
38void signal_handler(int /*signum*/)
39{
40 running = false;
41}
42}
43
44void render_loop(mir::Server& server)
45{
46 /* Set up graceful exit on SIGINT and SIGTERM */
47 struct sigaction sa;
48 sa.sa_handler = signal_handler;
49 sa.sa_flags = 0;
50 sigemptyset(&sa.sa_mask);
51
52 sigaction(SIGINT, &sa, NULL);
53 sigaction(SIGTERM, &sa, NULL);
54
55 auto display = server.the_display();
56
57 mir::draw::glAnimationBasic gl_animation;
58
59 display->for_each_display_sync_group([&](mg::DisplaySyncGroup& group)
60 {
61 group.for_each_display_buffer([&](mg::DisplayBuffer& buffer)
62 {
63 me::as_render_target(buffer)->make_current();
64 gl_animation.init_gl();
65 });
66 });
67
68 while (running)
69 {
70 display->for_each_display_sync_group([&](mg::DisplaySyncGroup& group)
71 {
72 group.for_each_display_buffer([&](mg::DisplayBuffer& buffer)
73 {
74 auto const render_target = me::as_render_target(buffer);
75 render_target->make_current();
76 gl_animation.render_gl();
77 render_target->swap_buffers();
78 });
79 group.post();
80 });
81
82 gl_animation.step();
83 }
84}
85
86int main(int argc, char const** argv)
87try
88{
89 // We don't want to act as a server by providing an endpoint
90 setenv("MIR_SERVER_NO_FILE", "", 1);
91
92 // If there's a server available, try connecting to it
93 if (auto const socket = getenv("MIR_SOCKET"))
94 setenv("MIR_SERVER_HOST_SOCKET", socket, 0);
95
96 mir::Server server;
97 server.set_command_line(argc, argv);
98 server.apply_settings();
99
100 render_loop(server);
101
102 return EXIT_SUCCESS;
103}
104catch (...)
105{
106 mir::report_exception();
107 return EXIT_FAILURE;
108}

Subscribers

People subscribed via source and target branches