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
=== modified file 'playground/CMakeLists.txt'
--- playground/CMakeLists.txt 2016-08-09 08:13:02 +0000
+++ playground/CMakeLists.txt 2016-10-12 21:50:47 +0000
@@ -37,3 +37,22 @@
37target_link_libraries(mir_demo_client_chain_jumping_buffers37target_link_libraries(mir_demo_client_chain_jumping_buffers
38 mirclient38 mirclient
39)39)
40
41mir_add_wrapped_executable(mir_demo_client_render_surface
42 render_surface.cpp
43)
44
45target_link_libraries(mir_demo_client_render_surface
46 mirclient
47 eglapp
48)
49
50mir_add_wrapped_executable(mir_demo_client_eglflash_render_surface
51 eglflash_render_surface.c
52)
53
54target_link_libraries(mir_demo_client_eglflash_render_surface
55 mirclient
56 ${EGL_LIBRARIES}
57 ${GLESv2_LIBRARIES}
58)
4059
=== modified file 'playground/README'
--- playground/README 2014-09-10 01:45:14 +0000
+++ playground/README 2016-10-12 21:50:47 +0000
@@ -1,6 +1,5 @@
1The Playground1The Playground
22
3These are mir demos that excercise private in-flux mir functionality.3These are mir demos that exercise private, in-flux mir functionality. As such
4As such functionality matures, related headers become public and the playground4functionality matures, related headers become public and the relevant playground
5code may become an example of how to use such feature.5code may be moved to 'examples/'.
6
76
=== added file 'playground/eglflash_render_surface.c'
--- playground/eglflash_render_surface.c 1970-01-01 00:00:00 +0000
+++ playground/eglflash_render_surface.c 2016-10-12 21:50:47 +0000
@@ -0,0 +1,176 @@
1/*
2 * Trivial GL demo; flashes the screen with colors using a MirRenderSurface.
3 *
4 * Copyright © 2016 Canonical Ltd.
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 3 as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Author: Daniel van Vugt <daniel.van.vugt@canonical.com>
19 * Cemil Azizoglu <cemil.azizoglu@canonical.com>
20 */
21
22#include "mir_toolkit/mir_client_library.h"
23#include "mir_toolkit/mir_render_surface.h"
24
25#include <stdio.h>
26#include <string.h>
27#include <unistd.h>
28#include <signal.h>
29#include <pthread.h>
30#include <EGL/egl.h>
31#include <GLES2/gl2.h>
32
33static volatile sig_atomic_t running = 0;
34
35static void shutdown(int signum)
36{
37 if (running)
38 {
39 running = 0;
40 printf("Signal %d received. Good night.\n", signum);
41 }
42}
43
44typedef struct Color
45{
46 GLfloat r, g, b, a;
47} Color;
48
49#define CHECK(_cond, _err) \
50 if (!(_cond)) \
51 { \
52 printf("%s\n", (_err)); \
53 return -1; \
54 }
55
56int main(int argc, char *argv[])
57{
58 (void) argc;
59 (void) argv;
60 const char* appname = "EGL Render Surface Demo";
61 int width = 100;
62 int height = 100;
63 EGLDisplay egldisplay;
64 EGLSurface eglsurface;
65 EGLint ctxattribs[] =
66 {
67 EGL_CONTEXT_CLIENT_VERSION, 2,
68 EGL_NONE
69 };
70 EGLContext eglctx;
71 EGLConfig eglconfig;
72 EGLint neglconfigs;
73 EGLBoolean ok;
74 MirConnection* connection = NULL;
75 MirSurface* surface = NULL;
76 MirRenderSurface* render_surface = NULL;
77
78 signal(SIGINT, shutdown);
79 signal(SIGTERM, shutdown);
80 signal(SIGHUP, shutdown);
81
82 connection = mir_connect_sync(NULL, appname);
83 CHECK(mir_connection_is_valid(connection), "Can't get connection");
84
85 egldisplay = eglGetDisplay(
86 mir_connection_get_egl_native_display(connection));
87 CHECK(egldisplay != EGL_NO_DISPLAY, "Can't eglGetDisplay");
88
89 ok = eglInitialize(egldisplay, NULL, NULL);
90 CHECK(ok, "Can't eglInitialize");
91
92 const EGLint attribs[] =
93 {
94 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
95 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
96 EGL_RED_SIZE, 8,
97 EGL_GREEN_SIZE, 8,
98 EGL_BLUE_SIZE, 8,
99 EGL_ALPHA_SIZE, 8,
100 EGL_NONE
101 };
102
103 ok = eglChooseConfig(egldisplay, attribs, &eglconfig, 1, &neglconfigs);
104 CHECK(ok, "Could not eglChooseConfig");
105 CHECK(neglconfigs > 0, "No EGL config available");
106
107 MirPixelFormat pixel_format =
108 mir_connection_get_egl_pixel_format(connection, egldisplay, eglconfig);
109
110 printf("Mir chose pixel format %d.\n", pixel_format);
111
112 MirSurfaceSpec *spec =
113 mir_connection_create_spec_for_normal_surface(connection, width, height, pixel_format);
114 CHECK(spec, "Can't create a surface spec");
115
116 mir_surface_spec_set_name(spec, appname);
117 mir_surface_spec_set_buffer_usage(spec, mir_buffer_usage_hardware);
118
119 render_surface = mir_connection_create_render_surface(connection);
120 CHECK(mir_render_surface_is_valid(render_surface), "could not create render surface");
121
122 MirBufferStream* buffer_stream =
123 mir_render_surface_create_buffer_stream_sync(render_surface,
124 width, height,
125 pixel_format,
126 mir_buffer_usage_hardware);
127
128 mir_surface_spec_add_render_surface(spec, render_surface, width, height, 0, 0);
129
130 surface = mir_surface_create_sync(spec);
131
132 mir_surface_spec_release(spec);
133
134 eglsurface = eglCreateWindowSurface(egldisplay, eglconfig,
135 (EGLNativeWindowType)render_surface, NULL);
136 CHECK(eglsurface != EGL_NO_SURFACE, "eglCreateWindowSurface failed");
137
138 eglctx = eglCreateContext(egldisplay, eglconfig, EGL_NO_CONTEXT,
139 ctxattribs);
140 CHECK(eglctx != EGL_NO_CONTEXT, "eglCreateContext failed");
141
142 ok = eglMakeCurrent(egldisplay, eglsurface, eglsurface, eglctx);
143 CHECK(ok, "Can't eglMakeCurrent");
144
145 Color red = {1.0f, 0.0f, 0.0f, 1.0f};
146 Color green = {0.0f, 1.0f, 0.0f, 1.0f};
147 Color blue = {0.0f, 0.0f, 1.0f, 1.0f};
148
149 running = 1;
150 while (running)
151 {
152 glClearColor(red.r, red.g, red.b, red.a);
153 glClear(GL_COLOR_BUFFER_BIT);
154 eglSwapBuffers(egldisplay, eglsurface);
155 sleep(1);
156
157 glClearColor(green.r, green.g, green.b, green.a);
158 glClear(GL_COLOR_BUFFER_BIT);
159 eglSwapBuffers(egldisplay, eglsurface);
160 sleep(1);
161
162 glClearColor(blue.r, blue.g, blue.b, blue.a);
163 glClear(GL_COLOR_BUFFER_BIT);
164 eglSwapBuffers(egldisplay, eglsurface);
165 sleep(1);
166 }
167
168 eglMakeCurrent(egldisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
169 eglTerminate(egldisplay);
170 mir_buffer_stream_release_sync(buffer_stream);
171 mir_render_surface_release(render_surface);
172 mir_surface_release_sync(surface);
173 mir_connection_release(connection);
174
175 return 0;
176}
0177
=== added file 'playground/render_surface.cpp'
--- playground/render_surface.cpp 1970-01-01 00:00:00 +0000
+++ playground/render_surface.cpp 2016-10-12 21:50:47 +0000
@@ -0,0 +1,255 @@
1/*
2 * Copyright © 2016 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 * Author: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com>
17 * Cemil Azizoglu <cemil.azizoglu@canonical.com>
18 */
19
20#include <boost/program_options.hpp>
21#include <iostream>
22#include <thread>
23#include <signal.h>
24#include <sys/signalfd.h>
25#include <poll.h>
26
27#include "mir_toolkit/mir_client_library.h"
28#include "mir_toolkit/mir_render_surface.h"
29
30#include "client_helpers.h"
31
32namespace me = mir::examples;
33
34class Pixel
35{
36public:
37 Pixel(void* addr, MirPixelFormat format)
38 : addr{addr},
39 format{format}
40 {
41 }
42
43 void write(int r, int g, int b, int a)
44 {
45 switch (format)
46 {
47 case mir_pixel_format_abgr_8888:
48 *((uint32_t*) addr) =
49 (uint32_t) a << 24 |
50 (uint32_t) b << 16 |
51 (uint32_t) g << 8 |
52 (uint32_t) r;
53 break;
54 case mir_pixel_format_xbgr_8888:
55 *((uint32_t*) addr) =
56 /* Not filling in the X byte is correct but buggy (LP: #1423462) */
57 (uint32_t) b << 16 |
58 (uint32_t) g << 8 |
59 (uint32_t) r;
60 break;
61 case mir_pixel_format_argb_8888:
62 *((uint32_t*) addr) =
63 (uint32_t) a << 24 |
64 (uint32_t) r << 16 |
65 (uint32_t) g << 8 |
66 (uint32_t) b;
67 break;
68 case mir_pixel_format_xrgb_8888:
69 *((uint32_t*) addr) =
70 /* Not filling in the X byte is correct but buggy (LP: #1423462) */
71 (uint32_t) r << 16 |
72 (uint32_t) g << 8 |
73 (uint32_t) b;
74 break;
75 case mir_pixel_format_rgb_888:
76 *((uint8_t*) addr) = r;
77 *((uint8_t*) addr + 1) = g;
78 *((uint8_t*) addr + 2) = b;
79 break;
80 case mir_pixel_format_bgr_888:
81 *((uint8_t*) addr) = b;
82 *((uint8_t*) addr + 1) = g;
83 *((uint8_t*) addr + 2) = r;
84 break;
85 default:
86 throw std::runtime_error{"Pixel format unsupported by Pixel::write!"};
87 }
88 }
89
90public:
91 void* const addr;
92 MirPixelFormat const format;
93};
94
95class pixel_iterator : std::iterator<std::random_access_iterator_tag, Pixel>
96{
97public:
98 pixel_iterator(MirGraphicsRegion const& region, int x, int y)
99 : x{x},
100 y{y},
101 buffer(region)
102 {
103 }
104
105 pixel_iterator(MirGraphicsRegion const& region)
106 : pixel_iterator(region, 0, 0)
107 {
108 }
109
110
111 pixel_iterator& operator++()
112 {
113 x++;
114 if (x == buffer.width)
115 {
116 x = 0;
117 y++;
118 }
119 return *this;
120 }
121 pixel_iterator operator++(int)
122 {
123 auto old = *this;
124 ++(*this);
125 return old;
126 }
127
128 Pixel operator*() const
129 {
130 return Pixel{
131 buffer.vaddr + (x * MIR_BYTES_PER_PIXEL(buffer.pixel_format))
132 + (y * buffer.stride), buffer.pixel_format};
133 }
134
135 bool operator==(pixel_iterator const& rhs)
136 {
137 return rhs.buffer.vaddr == buffer.vaddr &&
138 rhs.x == x &&
139 rhs.y == y;
140 }
141
142 bool operator!=(pixel_iterator const& rhs)
143 {
144 return !(*this == rhs);
145 }
146
147private:
148 int x, y;
149 MirGraphicsRegion const buffer;
150};
151
152pixel_iterator begin(MirGraphicsRegion const& region)
153{
154 return pixel_iterator(region);
155}
156
157pixel_iterator end(MirGraphicsRegion const& region)
158{
159 return pixel_iterator{region, 0, region.height};
160}
161
162void fill_stream_with(MirBufferStream* stream, int r, int g, int b, int a)
163{
164 MirGraphicsRegion buffer;
165 mir_buffer_stream_get_graphics_region(stream, &buffer);
166
167 for (auto pixel : buffer)
168 {
169 pixel.write(r, g, b, a);
170 }
171}
172
173void bounce_position(int& position, int& delta, int min, int max)
174{
175 if (position <= min || position >= max)
176 {
177 delta = -delta;
178 }
179 position += delta;
180}
181
182int main(int /*argc*/, char* /*argv*/[])
183{
184 char const* socket = nullptr;
185 int const width = 200;
186 int const height = 200;
187 int baseColour = 255, dbase = 1;
188 unsigned int nformats{0};
189 MirPixelFormat pixel_format;
190
191 me::Connection connection{socket, "MirRenderSurface example"};
192
193 mir_connection_get_available_surface_formats(connection, &pixel_format, 1, &nformats);
194 if (nformats == 0)
195 throw std::runtime_error("no pixel formats for buffer stream");
196 printf("Mir selected pixel format %d\n", pixel_format);
197
198 auto render_surface = mir_connection_create_render_surface(connection);
199
200 if (!mir_render_surface_is_valid(render_surface))
201 throw std::runtime_error(std::string("could not create render surface"));
202
203 auto spec = mir_connection_create_spec_for_normal_surface(
204 connection,
205 width, height,
206 pixel_format);
207
208 mir_surface_spec_set_name(spec, "Stream");
209 mir_surface_spec_set_buffer_usage(spec, mir_buffer_usage_software);
210
211 auto buffer_stream =
212 mir_render_surface_create_buffer_stream_sync(render_surface,
213 width, height,
214 pixel_format,
215 mir_buffer_usage_software);
216
217 mir_surface_spec_add_render_surface(spec, render_surface, width, height, 0, 0);
218
219 auto surface = mir_surface_create_sync(spec);
220 mir_surface_spec_release(spec);
221
222 fill_stream_with(buffer_stream, 255, 0, 0, 128);
223 mir_buffer_stream_swap_buffers_sync(buffer_stream);
224
225 sigset_t halt_signals;
226 sigemptyset(&halt_signals);
227 sigaddset(&halt_signals, SIGTERM);
228 sigaddset(&halt_signals, SIGQUIT);
229 sigaddset(&halt_signals, SIGINT);
230
231 sigprocmask(SIG_BLOCK, &halt_signals, nullptr);
232 int const signal_watch{signalfd(-1, &halt_signals, SFD_CLOEXEC)};
233
234 pollfd signal_poll{
235 signal_watch,
236 POLLIN | POLLERR,
237 0
238 };
239
240 while (poll(&signal_poll, 1, 0) <= 0)
241 {
242 bounce_position(baseColour, dbase, 128, 255);
243
244 fill_stream_with(buffer_stream, baseColour, 0, 0, 128);
245
246 mir_buffer_stream_swap_buffers_sync(buffer_stream);
247 }
248
249 mir_buffer_stream_release_sync(buffer_stream);
250 mir_render_surface_release(render_surface);
251 mir_surface_release_sync(surface);
252 close(signal_watch);
253
254 return 0;
255}

Subscribers

People subscribed via source and target branches