Mir

Merge lp:~cemil-azizoglu/mir/mir-render-surface-examples into lp:mir

Proposed by Cemil Azizoglu
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
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: mp+306162@code.launchpad.net

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.

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

FAILED: Continuous integration, rev:3730
https://mir-jenkins.ubuntu.com/job/mir-ci/1762/
Executed test runs:
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-mir/2209/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/2272
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/2263
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial+overlay/2263
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=yakkety/2263
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=yakkety/2237/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/2237
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/2237/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=yakkety/2237
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=yakkety/2237/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/2237
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/2237/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/2237
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/2237/artifact/output/*zip*/output.zip

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

review: Needs Fixing (continuous-integration)
Revision history for this message
Mir CI Bot (mir-ci-bot) wrote :

FAILED: Continuous integration, rev:3730
https://mir-jenkins.ubuntu.com/job/mir-ci/1763/
Executed test runs:
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-mir/2210/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/2273
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/2264
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial+overlay/2264
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=yakkety/2264
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=yakkety/2238/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/2238
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/2238/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=yakkety/2238
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=yakkety/2238/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/2238
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/2238/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/2238
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/2238/artifact/output/*zip*/output.zip

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

review: Needs Fixing (continuous-integration)
Revision history for this message
Mir CI Bot (mir-ci-bot) wrote :

PASSED: Continuous integration, rev:3731
https://mir-jenkins.ubuntu.com/job/mir-ci/1768/
Executed test runs:
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-mir/2215
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/2278
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/2269
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial+overlay/2269
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=yakkety/2269
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=yakkety/2243
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=yakkety/2243/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/2243
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/2243/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=yakkety/2243
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=yakkety/2243/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/2243
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/2243/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/2243
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/2243/artifact/output/*zip*/output.zip

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

review: Approve (continuous-integration)
Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

Yay more examples +1

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

Trivial conflict:

Text conflict in src/client/symbols.map
1 conflicts encountered.

review: Needs Fixing
Revision history for this message
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

Revision history for this message
Mir CI Bot (mir-ci-bot) wrote :

FAILED: Continuous integration, rev:3733
https://mir-jenkins.ubuntu.com/job/mir-ci/1847/
Executed test runs:
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-mir/2329/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/2392
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/2384
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial+overlay/2384
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=yakkety/2384
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=yakkety/2358
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=yakkety/2358/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/2358
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/2358/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=yakkety/2358
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=yakkety/2358/artifact/output/*zip*/output.zip
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/2358/console
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/2358/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/2358
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/2358/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/2358
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/2358/artifact/output/*zip*/output.zip

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

review: Needs Fixing (continuous-integration)
Revision history for this message
Mir CI Bot (mir-ci-bot) wrote :

PASSED: Continuous integration, rev:3734
https://mir-jenkins.ubuntu.com/job/mir-ci/1849/
Executed test runs:
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-mir/2332
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/2395
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/2387
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial+overlay/2387
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=yakkety/2387
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=yakkety/2361
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=yakkety/2361/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/2361
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/2361/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=yakkety/2361
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=yakkety/2361/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/2361
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/2361/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/2361
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/2361/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/2361
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/2361/artifact/output/*zip*/output.zip

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

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

OK

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

lgtm too, although once RS goes public, I'd guess we will get rid of eglflash_render_surface, and just make eglapp.c use RS?

review: Approve
Revision history for this message
Cemil Azizoglu (cemil-azizoglu) wrote :

> lgtm too, although once RS goes public, I'd guess we will get rid of
> eglflash_render_surface, and just make eglapp.c use RS?

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..

Revision history for this message
Mir CI Bot (mir-ci-bot) wrote :

PASSED: Continuous integration, rev:3751
https://mir-jenkins.ubuntu.com/job/mir-ci/1960/
Executed test runs:
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-mir/2502
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/2565
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/2557
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial+overlay/2557
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=yakkety/2557
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=yakkety/2531
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=yakkety/2531/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/2531
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/2531/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=yakkety/2531
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=yakkety/2531/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/2531
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/2531/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/2531
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/2531/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/2531
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/2531/artifact/output/*zip*/output.zip

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

review: Approve (continuous-integration)

Preview Diff

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

Subscribers

People subscribed via source and target branches