Mir

Merge lp:~cemil-azizoglu/mir/x11-better-display-handling into lp:mir

Proposed by Cemil Azizoglu
Status: Merged
Merged at revision: 3732
Proposed branch: lp:~cemil-azizoglu/mir/x11-better-display-handling
Merge into: lp:mir
Diff against target: 1158 lines (+397/-414)
15 files modified
src/platforms/mesa/server/kms/display_buffer.cpp (+1/-1)
src/platforms/mesa/server/x11/graphics/CMakeLists.txt (+1/-2)
src/platforms/mesa/server/x11/graphics/display.cpp (+60/-127)
src/platforms/mesa/server/x11/graphics/display.h (+11/-48)
src/platforms/mesa/server/x11/graphics/display_buffer.cpp (+36/-18)
src/platforms/mesa/server/x11/graphics/display_buffer.h (+18/-9)
src/platforms/mesa/server/x11/graphics/display_group.cpp (+0/-47)
src/platforms/mesa/server/x11/graphics/display_group.h (+0/-52)
src/platforms/mesa/server/x11/graphics/egl_helper.cpp (+184/-0)
src/platforms/mesa/server/x11/graphics/egl_helper.h (+78/-0)
src/platforms/mesa/server/x11/graphics/gl_context.cpp (+0/-45)
src/platforms/mesa/server/x11/graphics/gl_context.h (+0/-52)
src/platforms/mesa/server/x11/graphics/platform.cpp (+1/-1)
tests/unit-tests/graphics/test_platform_prober.cpp (+3/-1)
tests/unit-tests/platforms/mesa/x11/test_display.cpp (+4/-11)
To merge this branch: bzr merge lp:~cemil-azizoglu/mir/x11-better-display-handling
Reviewer Review Type Date Requested Status
Mir CI Bot continuous-integration Needs Fixing
Alan Griffiths Approve
Daniel van Vugt Abstain
Alexandros Frantzis (community) Approve
Review via email: mp+306681@code.launchpad.net

Commit message

Overhauled mgx::Display and mgx::DisplayBuffer implementations to bring it more inline with mesa-kms.

Description of the change

Overhauled mgx::Display and mgx::DisplayBuffer implementations.

 - Previously, mgx::Display created a window *and* set up the egl window surface. With this branch it only creates the window as that's the "display", but leaves the egl window creation/management to mgx::DisplayBuffer much like its kms counterpart.

 - Created an EGL helper, much like the mgmh::EGLHelper, though too bad it can't reuse the same code as mesa-kms uses gbm while mesa-x11 uses x11 objects in the headers.

 - Fixed the bug where mir_demo_standalone_render_surfaces didn't work. The mir_demo_standalone_render_to_fb still seems to crash inside the gl driver. I investigated further but haven't been able to uncover the root cause of the crash. I verified the EGL/GL call sequences of kms and x11 backends are the same. I can only imagine that this is a driver bug in the shared context handling code (though I haven't tried it on another GPU - I only have Intel i965).

 - Similar to mesa-kms, made mgx::DisplayBuffer inherit from DisplaySyncGroup, which simplifies the code.

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

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

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

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

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

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

review: Approve (continuous-integration)
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Please have a look at this before we have major conflicts:
https://code.launchpad.net/~vanvugt/mir/physical-frame/+merge/306199

review: Needs Information
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

Looks good.

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

> Please have a look at this before we have major conflicts:
> https://code.launchpad.net/~vanvugt/mir/physical-frame/+merge/306199

We will definitely conflict. It'd be good if you could rebase to this MP as the Display/DisplayBuffer handling is much better now. It should be easy to rebase as the branch is limited to mir-on-x.

Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Well I've had that code written in some form for months. It would be nice if I didn't have to rewrite parts due to this branch.

Revision history for this message
Daniel van Vugt (vanvugt) :
review: Abstain
Revision history for this message
Cemil Azizoglu (cemil-azizoglu) wrote :

> Well I've had that code written in some form for months. It would be nice if I
> didn't have to rewrite parts due to this branch.

Understood. I guess this is part of the game. No worries. If this one lands before yours I can help you rebase it.

Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Also, please check this list in case you're fixing more bugs than you know(!)

https://bugs.launchpad.net/mir/+bugs?field.tag=mesa-x11

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

Well, the code looks no worse than before ;)

And it does seem to fix Mir-on-X11 mode for mir_demo_standalone_render_surfaces.

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

FAILED: Autolanding.
More details in the following jenkins job:
https://mir-jenkins.ubuntu.com/job/mir-autolanding/646/
Executed test runs:
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-mir/2365/console
    None: https://mir-jenkins.ubuntu.com/job/generic-land-mp/687/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/2428
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/2420
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial+overlay/2420
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=yakkety/2420
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=yakkety/2394/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/2394
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/2394/artifact/output/*zip*/output.zip
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=yakkety/2394/console
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/2394/console
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/2394/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/2394
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/2394/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/2394
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/2394/artifact/output/*zip*/output.zip

review: Needs Fixing (continuous-integration)
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

^^^
Archive sync problems are new today. Also bug 1628828 is happening.

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

FAILED: Autolanding.
More details in the following jenkins job:
https://mir-jenkins.ubuntu.com/job/mir-autolanding/649/
Executed test runs:
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-mir/2369/console
    None: https://mir-jenkins.ubuntu.com/job/generic-land-mp/690/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/2432
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/2424
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial+overlay/2424
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=yakkety/2424
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=yakkety/2398
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=yakkety/2398/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/2398
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/2398/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=yakkety/2398
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=yakkety/2398/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/2398/console
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/2398/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/2398
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/2398/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/2398
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/2398/artifact/output/*zip*/output.zip

review: Needs Fixing (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/platforms/mesa/server/kms/display_buffer.cpp'
--- src/platforms/mesa/server/kms/display_buffer.cpp 2016-09-19 06:09:48 +0000
+++ src/platforms/mesa/server/kms/display_buffer.cpp 2016-09-26 01:54:42 +0000
@@ -152,7 +152,7 @@
152152
153 set_crtc(scheduled_composite_frame);153 set_crtc(scheduled_composite_frame);
154154
155 egl.release_current();155 release_current();
156156
157 listener->report_successful_drm_mode_set_crtc_on_construction();157 listener->report_successful_drm_mode_set_crtc_on_construction();
158 listener->report_successful_display_construction();158 listener->report_successful_display_construction();
159159
=== modified file 'src/platforms/mesa/server/x11/graphics/CMakeLists.txt'
--- src/platforms/mesa/server/x11/graphics/CMakeLists.txt 2016-07-28 03:39:52 +0000
+++ src/platforms/mesa/server/x11/graphics/CMakeLists.txt 2016-09-26 01:54:42 +0000
@@ -19,9 +19,8 @@
19 guest_platform.cpp19 guest_platform.cpp
20 display.cpp20 display.cpp
21 display_configuration.cpp21 display_configuration.cpp
22 gl_context.cpp
23 display_group.cpp
24 display_buffer.cpp22 display_buffer.cpp
23 egl_helper.cpp
25)24)
2625
27add_library(26add_library(
2827
=== modified file 'src/platforms/mesa/server/x11/graphics/display.cpp'
--- src/platforms/mesa/server/x11/graphics/display.cpp 2016-09-15 00:57:28 +0000
+++ src/platforms/mesa/server/x11/graphics/display.cpp 2016-09-26 01:54:42 +0000
@@ -18,24 +18,25 @@
1818
19#include "mir/graphics/platform.h"19#include "mir/graphics/platform.h"
20#include "mir/graphics/display_report.h"20#include "mir/graphics/display_report.h"
21#include "mir/graphics/egl_resources.h"
22#include "mir/graphics/egl_error.h"21#include "mir/graphics/egl_error.h"
23#include "mir/graphics/virtual_output.h"22#include "mir/graphics/virtual_output.h"
23#include "mir/renderer/gl/context.h"
24#include "mir/graphics/gl_config.h"24#include "mir/graphics/gl_config.h"
25#include "display_configuration.h"25#include "display_configuration.h"
26#include "display.h"26#include "display.h"
27#include "display_buffer.h"27#include "display_buffer.h"
28#include "gl_context.h"
2928
30#include <boost/throw_exception.hpp>29#include <boost/throw_exception.hpp>
31#include <fcntl.h>
32#include <mutex>
3330
34#include <X11/Xatom.h>31#include <X11/Xatom.h>
3532
36#define MIR_LOG_COMPONENT "x11-display"33#define MIR_LOG_COMPONENT "x11-display"
37#include "mir/log.h"34#include "mir/log.h"
3835
36namespace mg=mir::graphics;
37namespace mgx=mg::X;
38namespace geom=mir::geometry;
39
39namespace40namespace
40{41{
41auto get_pixel_width(Display *dpy)42auto get_pixel_width(Display *dpy)
@@ -50,66 +51,45 @@
5051
51 return float(screen->mheight) / screen->height;52 return float(screen->mheight) / screen->height;
52}53}
53}54
5455class XGLContext : public mir::renderer::gl::Context
55namespace mg=mir::graphics;56{
56namespace mgx=mg::X;57public:
57namespace geom=mir::geometry;58 XGLContext(::Display* const x_dpy,
5859 std::shared_ptr<mg::GLConfig> const& gl_config,
59mgx::X11EGLDisplay::X11EGLDisplay(::Display* x_dpy)60 EGLContext const shared_ctx)
60 : egl_dpy{eglGetDisplay(x_dpy)}61 : egl{*gl_config}
61{62 {
62 if (!egl_dpy)63 egl.setup(x_dpy, shared_ctx);
63 BOOST_THROW_EXCEPTION(mg::egl_error("Cannot get an egl display"));64 }
6465
65 EGLint egl_major, egl_minor;66 ~XGLContext() = default;
66 if (!eglInitialize(egl_dpy, &egl_major, &egl_minor))67
67 BOOST_THROW_EXCEPTION(mg::egl_error("eglInitialize failed"));68 void make_current() const override
6869 {
69 mir::log_info("EGL Version %d.%d", egl_major, egl_minor);70 egl.make_current();
70}71 }
7172
72mgx::X11EGLDisplay::~X11EGLDisplay()73 void release_current() const override
73{74 {
74 eglTerminate(egl_dpy);75 egl.release_current();
75}76 }
7677
77mgx::X11EGLDisplay::operator EGLDisplay() const78private:
78{79 mgx::helpers::EGLHelper egl;
79 return egl_dpy;80};
80}81}
8182
82mgx::X11Window::X11Window(::Display* x_dpy,83mgx::X11Window::X11Window(::Display* x_dpy,
83 EGLDisplay egl_dpy,84 EGLDisplay egl_dpy,
84 geom::Size const size,85 geom::Size const size,
85 GLConfig const& gl_config)86 EGLConfig const egl_cfg)
86 : x_dpy{x_dpy}87 : x_dpy{x_dpy}
87{88{
88 EGLint const att[] = {
89 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
90 EGL_RED_SIZE, 8,
91 EGL_GREEN_SIZE, 8,
92 EGL_BLUE_SIZE, 8,
93 EGL_ALPHA_SIZE, 8,
94 EGL_DEPTH_SIZE, gl_config.depth_buffer_bits(),
95 EGL_STENCIL_SIZE, gl_config.stencil_buffer_bits(),
96 EGL_RENDERABLE_TYPE, MIR_SERVER_EGL_OPENGL_BIT,
97 EGL_NONE
98 };
99
100 auto root = XDefaultRootWindow(x_dpy);89 auto root = XDefaultRootWindow(x_dpy);
10190
102 EGLint num_configs;
103 if (!eglChooseConfig(egl_dpy, att, &config, 1, &num_configs))
104 BOOST_THROW_EXCEPTION(mg::egl_error("Cannot get an EGL config"));
105
106 mir::log_info("%d config(s) found", num_configs);
107
108 if (num_configs <= 0)
109 BOOST_THROW_EXCEPTION(mg::egl_error("Cannot get an EGL config"));
110
111 EGLint vid;91 EGLint vid;
112 if (!eglGetConfigAttrib(egl_dpy, config, EGL_NATIVE_VISUAL_ID, &vid))92 if (!eglGetConfigAttrib(egl_dpy, egl_cfg, EGL_NATIVE_VISUAL_ID, &vid))
113 BOOST_THROW_EXCEPTION(mg::egl_error("Cannot get config attrib"));93 BOOST_THROW_EXCEPTION(mg::egl_error("Cannot get config attrib"));
11494
115 XVisualInfo visTemplate;95 XVisualInfo visTemplate;
@@ -214,103 +194,56 @@
214 return win;194 return win;
215}195}
216196
217EGLConfig mgx::X11Window::egl_config() const
218{
219 return config;
220}
221
222unsigned long mgx::X11Window::red_mask() const197unsigned long mgx::X11Window::red_mask() const
223{198{
224 return r_mask;199 return r_mask;
225}200}
226201
227mgx::X11EGLContext::X11EGLContext(EGLDisplay egl_dpy, EGLConfig config)
228 : egl_dpy{egl_dpy}
229{
230 eglBindAPI(MIR_SERVER_EGL_OPENGL_API);
231
232 static const EGLint ctx_attribs[] = {
233#if MIR_SERVER_EGL_OPENGL_BIT == EGL_OPENGL_ES2_BIT
234 EGL_CONTEXT_CLIENT_VERSION, 2,
235#endif
236 EGL_NONE };
237
238 egl_ctx = eglCreateContext(egl_dpy, config, EGL_NO_CONTEXT, ctx_attribs);
239 if (!egl_ctx)
240 BOOST_THROW_EXCEPTION(mg::egl_error("eglCreateContext failed"));
241}
242
243mgx::X11EGLContext::~X11EGLContext()
244{
245 eglDestroyContext(egl_dpy, egl_ctx);
246}
247
248mgx::X11EGLContext::operator EGLContext() const
249{
250 return egl_ctx;
251}
252
253mgx::X11EGLSurface::X11EGLSurface(EGLDisplay egl_dpy, EGLConfig config, Window win)
254 : egl_dpy{egl_dpy}, egl_surf{eglCreateWindowSurface(egl_dpy, config, win, NULL)}
255{
256 if (!egl_surf)
257 BOOST_THROW_EXCEPTION(mg::egl_error("eglCreateWindowSurface failed"));
258}
259
260mgx::X11EGLSurface::~X11EGLSurface()
261{
262 eglDestroySurface(egl_dpy, egl_surf);
263}
264
265mgx::X11EGLSurface::operator EGLSurface() const
266{
267 return egl_surf;
268}
269
270mgx::Display::Display(::Display* x_dpy,202mgx::Display::Display(::Display* x_dpy,
271 geom::Size const size,203 geom::Size const size,
272 GLConfig const& gl_config,204 std::shared_ptr<GLConfig> const& gl_config,
273 std::shared_ptr<DisplayReport> const& report)205 std::shared_ptr<DisplayReport> const& report)
274 : egl_display{X11EGLDisplay(x_dpy)},206 : shared_egl{*gl_config},
207 x_dpy{x_dpy},
275 size{size},208 size{size},
209 gl_config{gl_config},
276 pixel_width{get_pixel_width(x_dpy)},210 pixel_width{get_pixel_width(x_dpy)},
277 pixel_height{get_pixel_height(x_dpy)},211 pixel_height{get_pixel_height(x_dpy)},
278 win{X11Window(x_dpy,
279 egl_display,
280 size,
281 gl_config)},
282 egl_context{X11EGLContext(egl_display,
283 win.egl_config())},
284 egl_surface{X11EGLSurface(egl_display,
285 win.egl_config(),
286 win)},
287 report{report},212 report{report},
288 orientation{mir_orientation_normal}213 orientation{mir_orientation_normal}
289{214{
290 auto red_mask = win.red_mask();215 shared_egl.setup(x_dpy);
216
217 win = std::make_unique<X11Window>(x_dpy,
218 shared_egl.display(),
219 size,
220 shared_egl.config());
221
222 auto red_mask = win->red_mask();
291 pf = (red_mask == 0xFF0000 ? mir_pixel_format_argb_8888223 pf = (red_mask == 0xFF0000 ? mir_pixel_format_argb_8888
292 : mir_pixel_format_abgr_8888);224 : mir_pixel_format_abgr_8888);
293225
294 display_group = std::make_unique<mgx::DisplayGroup>(226 display_buffer = std::make_unique<mgx::DisplayBuffer>(
295 std::make_unique<mgx::DisplayBuffer>(size,227 x_dpy,
296 egl_display,228 *win,
297 egl_surface,229 size,
298 egl_context,230 shared_egl.context(),
299 report,231 report,
300 orientation));232 orientation,
301233 *gl_config);
302 report->report_egl_configuration(egl_display, win.egl_config());234
235 shared_egl.make_current();
236
303 report->report_successful_display_construction();237 report->report_successful_display_construction();
304}238}
305239
306mgx::Display::~Display() noexcept240mgx::Display::~Display() noexcept
307{241{
308 eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
309}242}
310243
311void mgx::Display::for_each_display_sync_group(std::function<void(mg::DisplaySyncGroup&)> const& f)244void mgx::Display::for_each_display_sync_group(std::function<void(mg::DisplaySyncGroup&)> const& f)
312{245{
313 f(*display_group);246 f(*display_buffer);
314}247}
315248
316std::unique_ptr<mg::DisplayConfiguration> mgx::Display::configuration() const249std::unique_ptr<mg::DisplayConfiguration> mgx::Display::configuration() const
@@ -335,7 +268,7 @@
335 });268 });
336269
337 orientation = o;270 orientation = o;
338 display_group->set_orientation(orientation);271 display_buffer->set_orientation(orientation);
339}272}
340273
341void mgx::Display::register_configuration_change_handler(274void mgx::Display::register_configuration_change_handler(
@@ -378,7 +311,7 @@
378311
379std::unique_ptr<mir::renderer::gl::Context> mgx::Display::create_gl_context()312std::unique_ptr<mir::renderer::gl::Context> mgx::Display::create_gl_context()
380{313{
381 return std::make_unique<mgx::XGLContext>(egl_display, egl_surface, egl_context);314 return std::make_unique<XGLContext>(x_dpy, gl_config, shared_egl.context());
382}315}
383316
384bool mgx::Display::apply_if_configuration_preserves_display_buffers(317bool mgx::Display::apply_if_configuration_preserves_display_buffers(
385318
=== modified file 'src/platforms/mesa/server/x11/graphics/display.h'
--- src/platforms/mesa/server/x11/graphics/display.h 2016-09-15 00:57:28 +0000
+++ src/platforms/mesa/server/x11/graphics/display.h 2016-09-26 01:54:42 +0000
@@ -20,10 +20,10 @@
20#define MIR_GRAPHICS_X_DISPLAY_H_20#define MIR_GRAPHICS_X_DISPLAY_H_
2121
22#include "mir/graphics/display.h"22#include "mir/graphics/display.h"
23#include "mir/geometry/size.h"
23#include "mir/renderer/gl/context_source.h"24#include "mir/renderer/gl/context_source.h"
24#include "mir_toolkit/common.h"25#include "mir_toolkit/common.h"
25#include "display_group.h"26#include "egl_helper.h"
26#include "mir/geometry/size.h"
2727
28#include <X11/Xlib.h>28#include <X11/Xlib.h>
29#include <X11/Xutil.h>29#include <X11/Xutil.h>
@@ -35,21 +35,12 @@
35{35{
3636
37class GLConfig;37class GLConfig;
38class DisplayReport;
3839
39namespace X40namespace X
40{41{
4142
42class X11EGLDisplay43class DisplayBuffer;
43{
44public:
45 X11EGLDisplay(::Display* x_dpy);
46 ~X11EGLDisplay();
47
48 operator EGLDisplay() const;
49
50private:
51 EGLDisplay const egl_dpy;
52};
5344
54class X11Window45class X11Window
55{46{
@@ -57,46 +48,18 @@
57 X11Window(::Display* const x_dpy,48 X11Window(::Display* const x_dpy,
58 EGLDisplay egl_dpy,49 EGLDisplay egl_dpy,
59 geometry::Size const size,50 geometry::Size const size,
60 GLConfig const& gl_config);51 EGLConfig const egl_cfg);
61 ~X11Window();52 ~X11Window();
6253
63 operator Window() const;54 operator Window() const;
64 EGLConfig egl_config() const;
65 unsigned long red_mask() const;55 unsigned long red_mask() const;
6656
67private:57private:
68 ::Display* const x_dpy;58 ::Display* const x_dpy;
69 Window win;59 Window win;
70 EGLConfig config;
71 unsigned long r_mask;60 unsigned long r_mask;
72};61};
7362
74class X11EGLContext
75{
76public:
77 X11EGLContext(EGLDisplay egl_dpy, EGLConfig config);
78 ~X11EGLContext();
79
80 operator EGLContext() const;
81
82private:
83 EGLContext egl_ctx;
84 EGLDisplay const egl_dpy;
85};
86
87class X11EGLSurface
88{
89public:
90 X11EGLSurface(EGLDisplay egl_dpy, EGLConfig config, Window win);
91 ~X11EGLSurface();
92
93 operator EGLSurface() const;
94
95private:
96 EGLDisplay const egl_dpy;
97 EGLSurface const egl_surf;
98};
99
100class Display : public graphics::Display,63class Display : public graphics::Display,
101 public graphics::NativeDisplay,64 public graphics::NativeDisplay,
102 public renderer::gl::ContextSource65 public renderer::gl::ContextSource
@@ -104,7 +67,7 @@
104public:67public:
105 explicit Display(::Display* x_dpy,68 explicit Display(::Display* x_dpy,
106 geometry::Size const size,69 geometry::Size const size,
107 GLConfig const& gl_config,70 std::shared_ptr<GLConfig> const& gl_config,
108 std::shared_ptr<DisplayReport> const& report);71 std::shared_ptr<DisplayReport> const& report);
109 ~Display() noexcept;72 ~Display() noexcept;
11073
@@ -136,17 +99,17 @@
136 std::unique_ptr<renderer::gl::Context> create_gl_context() override;99 std::unique_ptr<renderer::gl::Context> create_gl_context() override;
137100
138private:101private:
139 X11EGLDisplay const egl_display;102 helpers::EGLHelper shared_egl;
103 ::Display* const x_dpy;
140 mir::geometry::Size const size;104 mir::geometry::Size const size;
105 std::shared_ptr<GLConfig> const gl_config;
141 float pixel_width;106 float pixel_width;
142 float pixel_height;107 float pixel_height;
143 X11Window const win;108 std::unique_ptr<X11Window> win;
144 X11EGLContext egl_context;
145 X11EGLSurface egl_surface;
146 MirPixelFormat pf;109 MirPixelFormat pf;
147 std::unique_ptr<DisplayGroup> display_group;
148 std::shared_ptr<DisplayReport> const report;110 std::shared_ptr<DisplayReport> const report;
149 MirOrientation orientation; //TODO: keep entire current display configuration111 MirOrientation orientation; //TODO: keep entire current display configuration
112 std::unique_ptr<DisplayBuffer> display_buffer;
150};113};
151114
152}115}
153116
=== modified file 'src/platforms/mesa/server/x11/graphics/display_buffer.cpp'
--- src/platforms/mesa/server/x11/graphics/display_buffer.cpp 2016-09-19 06:09:48 +0000
+++ src/platforms/mesa/server/x11/graphics/display_buffer.cpp 2016-09-26 01:54:42 +0000
@@ -17,29 +17,33 @@
17 *17 *
18 */18 */
1919
20#include "mir/graphics/egl_error.h"20#include "mir/fatal.h"
21#include "display_buffer.h"21#include "display_buffer.h"
22#include "display_configuration.h"22#include "display_configuration.h"
2323#include "mir/graphics/display_report.h"
24#include <boost/throw_exception.hpp>
2524
26namespace mg=mir::graphics;25namespace mg=mir::graphics;
27namespace mgx=mg::X;26namespace mgx=mg::X;
28namespace geom=mir::geometry;27namespace geom=mir::geometry;
2928
30mgx::DisplayBuffer::DisplayBuffer(geom::Size const sz,29mgx::DisplayBuffer::DisplayBuffer(::Display* const x_dpy,
31 EGLDisplay const d,30 Window const win,
32 EGLSurface const s,31 geom::Size const sz,
33 EGLContext const c,32 EGLContext const shared_context,
34 std::shared_ptr<DisplayReport> const& r,33 std::shared_ptr<DisplayReport> const& r,
35 MirOrientation const o)34 MirOrientation const o,
35 GLConfig const& gl_config)
36 : size{sz},36 : size{sz},
37 egl_dpy{d},
38 egl_surf{s},
39 egl_ctx{c},
40 report{r},37 report{r},
41 orientation_{o}38 orientation_{o},
39 egl{gl_config}
42{40{
41 egl.setup(x_dpy, win, shared_context);
42 egl.report_egl_configuration(
43 [&r] (EGLDisplay disp, EGLConfig cfg)
44 {
45 r->report_egl_configuration(disp, cfg);
46 });
43}47}
4448
45geom::Rectangle mgx::DisplayBuffer::view_area() const49geom::Rectangle mgx::DisplayBuffer::view_area() const
@@ -56,14 +60,13 @@
5660
57void mgx::DisplayBuffer::make_current()61void mgx::DisplayBuffer::make_current()
58{62{
59 if (!eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx))63 if (!egl.make_current())
60 BOOST_THROW_EXCEPTION(mg::egl_error("Cannot make current"));64 fatal_error("Failed to make EGL surface current");
61}65}
6266
63void mgx::DisplayBuffer::release_current()67void mgx::DisplayBuffer::release_current()
64{68{
65 if (!eglMakeCurrent(egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT))69 egl.release_current();
66 BOOST_THROW_EXCEPTION(mg::egl_error("Cannot make uncurrent"));
67}70}
6871
69bool mgx::DisplayBuffer::overlay(RenderableList const& /*renderlist*/)72bool mgx::DisplayBuffer::overlay(RenderableList const& /*renderlist*/)
@@ -73,8 +76,8 @@
7376
74void mgx::DisplayBuffer::swap_buffers()77void mgx::DisplayBuffer::swap_buffers()
75{78{
76 if (!eglSwapBuffers(egl_dpy, egl_surf))79 if (!egl.swap_buffers())
77 BOOST_THROW_EXCEPTION(mg::egl_error("Cannot swap"));80 fatal_error("Failed to perform buffer swap");
7881
79 /*82 /*
80 * Admittedly we are not a real display and will miss some real vsyncs83 * Admittedly we are not a real display and will miss some real vsyncs
@@ -107,3 +110,18 @@
107{110{
108 return this;111 return this;
109}112}
113
114void mgx::DisplayBuffer::for_each_display_buffer(
115 std::function<void(graphics::DisplayBuffer&)> const& f)
116{
117 f(*this);
118}
119
120void mgx::DisplayBuffer::post()
121{
122}
123
124std::chrono::milliseconds mgx::DisplayBuffer::recommended_sleep() const
125{
126 return std::chrono::milliseconds::zero();
127}
110128
=== modified file 'src/platforms/mesa/server/x11/graphics/display_buffer.h'
--- src/platforms/mesa/server/x11/graphics/display_buffer.h 2016-09-19 06:09:48 +0000
+++ src/platforms/mesa/server/x11/graphics/display_buffer.h 2016-09-26 01:54:42 +0000
@@ -20,10 +20,10 @@
20#ifndef MIR_GRAPHICS_X_DISPLAY_BUFFER_H_20#ifndef MIR_GRAPHICS_X_DISPLAY_BUFFER_H_
21#define MIR_GRAPHICS_X_DISPLAY_BUFFER_H_21#define MIR_GRAPHICS_X_DISPLAY_BUFFER_H_
2222
23#include "mir/graphics/display_report.h"
24#include "mir/graphics/display_buffer.h"23#include "mir/graphics/display_buffer.h"
24#include "mir/graphics/display.h"
25#include "mir/renderer/gl/render_target.h"25#include "mir/renderer/gl/render_target.h"
26#include "gl_context.h"26#include "egl_helper.h"
2727
28#include <EGL/egl.h>28#include <EGL/egl.h>
29#include <memory>29#include <memory>
@@ -32,21 +32,27 @@
32{32{
33namespace graphics33namespace graphics
34{34{
35
36class GLConfig;
37class DisplayReport;
38
35namespace X39namespace X
36{40{
3741
38class DisplayBuffer : public graphics::DisplayBuffer,42class DisplayBuffer : public graphics::DisplayBuffer,
43 public graphics::DisplaySyncGroup,
39 public graphics::NativeDisplayBuffer,44 public graphics::NativeDisplayBuffer,
40 public renderer::gl::RenderTarget45 public renderer::gl::RenderTarget
41{46{
42public:47public:
43 DisplayBuffer(48 DisplayBuffer(
49 ::Display* const x_dpy,
50 Window const win,
44 geometry::Size const sz,51 geometry::Size const sz,
45 EGLDisplay const d,52 EGLContext const shared_context,
46 EGLSurface const s,
47 EGLContext const c,
48 std::shared_ptr<DisplayReport> const& r,53 std::shared_ptr<DisplayReport> const& r,
49 MirOrientation const o);54 MirOrientation const o,
55 GLConfig const& gl_config);
5056
51 geometry::Rectangle view_area() const override;57 geometry::Rectangle view_area() const override;
52 void make_current() override;58 void make_current() override;
@@ -56,17 +62,20 @@
56 bool overlay(RenderableList const& renderlist) override;62 bool overlay(RenderableList const& renderlist) override;
57 void set_orientation(MirOrientation const new_orientation);63 void set_orientation(MirOrientation const new_orientation);
5864
65 void for_each_display_buffer(
66 std::function<void(graphics::DisplayBuffer&)> const& f) override;
67 void post() override;
68 std::chrono::milliseconds recommended_sleep() const override;
69
59 MirOrientation orientation() const override;70 MirOrientation orientation() const override;
60 MirMirrorMode mirror_mode() const override;71 MirMirrorMode mirror_mode() const override;
61 NativeDisplayBuffer* native_display_buffer() override;72 NativeDisplayBuffer* native_display_buffer() override;
6273
63private:74private:
64 geometry::Size const size;75 geometry::Size const size;
65 EGLDisplay const egl_dpy;
66 EGLSurface const egl_surf;
67 EGLContext const egl_ctx;
68 std::shared_ptr<DisplayReport> const report;76 std::shared_ptr<DisplayReport> const report;
69 MirOrientation orientation_;77 MirOrientation orientation_;
78 helpers::EGLHelper egl;
70};79};
7180
72}81}
7382
=== removed file 'src/platforms/mesa/server/x11/graphics/display_group.cpp'
--- src/platforms/mesa/server/x11/graphics/display_group.cpp 2016-01-29 08:18:22 +0000
+++ src/platforms/mesa/server/x11/graphics/display_group.cpp 1970-01-01 00:00:00 +0000
@@ -1,47 +0,0 @@
1/*
2 * Copyright © 2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 3,
6 * as 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 Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Cemil Azizoglu <cemil.azizoglu@canonical.com>
17 *
18 */
19
20#include "display_group.h"
21
22namespace mg = mir::graphics;
23namespace mgx = mg::X;
24
25mgx::DisplayGroup::DisplayGroup(std::unique_ptr<mgx::DisplayBuffer> primary_buffer)
26{
27 display_buffer = std::move(primary_buffer);
28}
29
30void mgx::DisplayGroup::for_each_display_buffer(std::function<void(mg::DisplayBuffer&)> const& f)
31{
32 f(*display_buffer);
33}
34
35void mgx::DisplayGroup::post()
36{
37}
38
39std::chrono::milliseconds mgx::DisplayGroup::recommended_sleep() const
40{
41 return std::chrono::milliseconds::zero();
42}
43
44void mgx::DisplayGroup::set_orientation(MirOrientation orientation)
45{
46 display_buffer->set_orientation(orientation);
47}
480
=== removed file 'src/platforms/mesa/server/x11/graphics/display_group.h'
--- src/platforms/mesa/server/x11/graphics/display_group.h 2016-01-29 08:18:22 +0000
+++ src/platforms/mesa/server/x11/graphics/display_group.h 1970-01-01 00:00:00 +0000
@@ -1,52 +0,0 @@
1/*
2 * Copyright © 2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 3,
6 * as 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 Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Cemil Azizoglu <cemil.azizoglu@canonical.com>
17 *
18 */
19
20#ifndef MIR_GRAPHICS_X_DISPLAY_GROUP_H_
21#define MIR_GRAPHICS_X_DISPLAY_GROUP_H_
22
23#include "mir_toolkit/common.h"
24#include "mir/graphics/display.h"
25#include "display_buffer.h"
26
27namespace mir
28{
29namespace graphics
30{
31namespace X
32{
33
34class DisplayGroup : public graphics::DisplaySyncGroup
35{
36public:
37 DisplayGroup(std::unique_ptr<DisplayBuffer> primary_buffer);
38
39 void for_each_display_buffer(std::function<void(graphics::DisplayBuffer&)> const& f) override;
40 void post() override;
41 std::chrono::milliseconds recommended_sleep() const override;
42 void set_orientation(MirOrientation orientation);
43
44private:
45 std::unique_ptr<DisplayBuffer> display_buffer;
46};
47
48}
49}
50}
51
52#endif /* MIR_GRAPHICS_X_DISPLAY_GROUP_H_ */
530
=== added file 'src/platforms/mesa/server/x11/graphics/egl_helper.cpp'
--- src/platforms/mesa/server/x11/graphics/egl_helper.cpp 1970-01-01 00:00:00 +0000
+++ src/platforms/mesa/server/x11/graphics/egl_helper.cpp 2016-09-26 01:54:42 +0000
@@ -0,0 +1,184 @@
1/*
2 * Copyright © 2016 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 3,
6 * as 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 Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Cemil Azizoglu <cemil.azizoglu@canonical.com>
17 */
18
19#include "egl_helper.h"
20
21#include "mir/graphics/gl_config.h"
22#include "mir/graphics/egl_error.h"
23
24#include <boost/throw_exception.hpp>
25
26namespace mg = mir::graphics;
27namespace mgx = mg::X;
28namespace mgxh = mgx::helpers;
29
30mgxh::EGLHelper::EGLHelper(GLConfig const& gl_config)
31 : depth_buffer_bits{gl_config.depth_buffer_bits()},
32 stencil_buffer_bits{gl_config.stencil_buffer_bits()},
33 egl_display{EGL_NO_DISPLAY}, egl_config{0},
34 egl_context{EGL_NO_CONTEXT}, egl_surface{EGL_NO_SURFACE},
35 should_terminate_egl{false}
36{
37}
38
39void mgxh::EGLHelper::setup(::Display* const x_dpy)
40{
41 eglBindAPI(MIR_SERVER_EGL_OPENGL_API);
42
43 static const EGLint context_attr[] = {
44#if MIR_SERVER_EGL_OPENGL_BIT == EGL_OPENGL_ES2_BIT
45 EGL_CONTEXT_CLIENT_VERSION, 2,
46#endif
47 EGL_NONE
48 };
49
50 setup_internal(x_dpy, true);
51
52 egl_context = eglCreateContext(egl_display, egl_config, EGL_NO_CONTEXT, context_attr);
53 if (egl_context == EGL_NO_CONTEXT)
54 BOOST_THROW_EXCEPTION(mg::egl_error("Failed to create EGL context"));
55}
56
57void mgxh::EGLHelper::setup(::Display* const x_dpy, EGLContext shared_context)
58{
59 eglBindAPI(MIR_SERVER_EGL_OPENGL_API);
60
61 static const EGLint context_attr[] = {
62#if MIR_SERVER_EGL_OPENGL_BIT == EGL_OPENGL_ES2_BIT
63 EGL_CONTEXT_CLIENT_VERSION, 2,
64#endif
65 EGL_NONE
66 };
67
68 setup_internal(x_dpy, false);
69
70 egl_context = eglCreateContext(egl_display, egl_config, shared_context, context_attr);
71 if (egl_context == EGL_NO_CONTEXT)
72 BOOST_THROW_EXCEPTION(mg::egl_error("Failed to create EGL context"));
73}
74
75void mgxh::EGLHelper::setup(::Display* const x_dpy, Window win,
76 EGLContext shared_context)
77{
78 eglBindAPI(MIR_SERVER_EGL_OPENGL_API);
79
80 static const EGLint context_attr[] = {
81#if MIR_SERVER_EGL_OPENGL_BIT == EGL_OPENGL_ES2_BIT
82 EGL_CONTEXT_CLIENT_VERSION, 2,
83#endif
84 EGL_NONE
85 };
86
87 setup_internal(x_dpy, false);
88
89 egl_surface = eglCreateWindowSurface(egl_display, egl_config, win, nullptr);
90 if(egl_surface == EGL_NO_SURFACE)
91 BOOST_THROW_EXCEPTION(mg::egl_error("Failed to create EGL window surface"));
92
93 egl_context = eglCreateContext(egl_display, egl_config, shared_context, context_attr);
94 if (egl_context == EGL_NO_CONTEXT)
95 BOOST_THROW_EXCEPTION(mg::egl_error("Failed to create EGL context"));
96}
97
98mgxh::EGLHelper::~EGLHelper() noexcept
99{
100 if (egl_display != EGL_NO_DISPLAY) {
101 if (egl_context != EGL_NO_CONTEXT)
102 {
103 eglBindAPI(MIR_SERVER_EGL_OPENGL_API);
104 if (eglGetCurrentContext() == egl_context)
105 eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
106 eglDestroyContext(egl_display, egl_context);
107 }
108 if (egl_surface != EGL_NO_SURFACE)
109 eglDestroySurface(egl_display, egl_surface);
110 if (should_terminate_egl)
111 eglTerminate(egl_display);
112 }
113}
114
115bool mgxh::EGLHelper::swap_buffers()
116{
117 auto ret = eglSwapBuffers(egl_display, egl_surface);
118 return (ret == EGL_TRUE);
119}
120
121bool mgxh::EGLHelper::make_current() const
122{
123 auto ret = eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context);
124 eglBindAPI(MIR_SERVER_EGL_OPENGL_API);
125 return (ret == EGL_TRUE);
126}
127
128bool mgxh::EGLHelper::release_current() const
129{
130 auto ret = eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
131 return (ret == EGL_TRUE);
132}
133
134void mgxh::EGLHelper::setup_internal(::Display* const x_dpy, bool initialize)
135{
136 EGLint const config_attr[] = {
137 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
138 EGL_RED_SIZE, 8,
139 EGL_GREEN_SIZE, 8,
140 EGL_BLUE_SIZE, 8,
141 EGL_ALPHA_SIZE, 8,
142 EGL_DEPTH_SIZE, depth_buffer_bits,
143 EGL_STENCIL_SIZE, stencil_buffer_bits,
144 EGL_RENDERABLE_TYPE, MIR_SERVER_EGL_OPENGL_BIT,
145 EGL_NONE
146 };
147
148 static const EGLint required_egl_version_major = 1;
149 static const EGLint required_egl_version_minor = 4;
150
151 EGLint num_egl_configs;
152
153 egl_display = eglGetDisplay(static_cast<EGLNativeDisplayType>(x_dpy));
154 if (egl_display == EGL_NO_DISPLAY)
155 BOOST_THROW_EXCEPTION(mg::egl_error("Failed to get EGL display"));
156
157 if (initialize)
158 {
159 EGLint major, minor;
160
161 if (eglInitialize(egl_display, &major, &minor) == EGL_FALSE)
162 BOOST_THROW_EXCEPTION(mg::egl_error("Failed to initialize EGL display"));
163
164 if ((major != required_egl_version_major) || (minor != required_egl_version_minor))
165 {
166 BOOST_THROW_EXCEPTION(
167 boost::enable_error_info(std::runtime_error("Incompatible EGL version")));
168 // TODO: Insert egl version major and minor into exception
169 }
170
171 should_terminate_egl = true;
172 }
173
174 if (eglChooseConfig(egl_display, config_attr, &egl_config, 1, &num_egl_configs) == EGL_FALSE ||
175 num_egl_configs != 1)
176 {
177 BOOST_THROW_EXCEPTION(mg::egl_error("Failed to choose ARGB EGL config"));
178 }
179}
180
181void mgxh::EGLHelper::report_egl_configuration(std::function<void(EGLDisplay, EGLConfig)> f)
182{
183 f(egl_display, egl_config);
184}
0185
=== added file 'src/platforms/mesa/server/x11/graphics/egl_helper.h'
--- src/platforms/mesa/server/x11/graphics/egl_helper.h 1970-01-01 00:00:00 +0000
+++ src/platforms/mesa/server/x11/graphics/egl_helper.h 2016-09-26 01:54:42 +0000
@@ -0,0 +1,78 @@
1/*
2 * Copyright © 2016 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 3,
6 * as 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 Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Cemil Azizoglu <cemil.azizoglu@canonical.com>
17 */
18
19#ifndef MIR_GRAPHICS_X11_EGL_HELPER_H_
20#define MIR_GRAPHICS_X11_EGL_HELPER_H_
21
22#include <memory>
23
24#include <X11/Xlib.h>
25#include <EGL/egl.h>
26
27namespace mir
28{
29namespace graphics
30{
31class GLConfig;
32
33namespace X
34{
35
36namespace helpers
37{
38
39class EGLHelper
40{
41public:
42 EGLHelper(GLConfig const& gl_config);
43 ~EGLHelper() noexcept;
44
45 EGLHelper(const EGLHelper&) = delete;
46 EGLHelper& operator=(const EGLHelper&) = delete;
47
48 void setup(::Display* const x_dpy);
49 void setup(::Display* const x_dpy, EGLContext shared_context);
50 void setup(::Display* const x_dpy, Window win,
51 EGLContext shared_context);
52
53 bool swap_buffers();
54 bool make_current() const;
55 bool release_current() const;
56
57 EGLContext context() { return egl_context; }
58 EGLDisplay display() { return egl_display; }
59 EGLConfig config() { return egl_config; }
60
61 void report_egl_configuration(std::function<void(EGLDisplay, EGLConfig)>);
62private:
63 void setup_internal(::Display* const x_dpy, bool initialize);
64
65 EGLint const depth_buffer_bits;
66 EGLint const stencil_buffer_bits;
67 EGLDisplay egl_display;
68 EGLConfig egl_config;
69 EGLContext egl_context;
70 EGLSurface egl_surface;
71 bool should_terminate_egl;
72};
73
74}
75}
76}
77}
78#endif /* MIR_GRAPHICS_X11_EGL_HELPER_H_ */
079
=== removed file 'src/platforms/mesa/server/x11/graphics/gl_context.cpp'
--- src/platforms/mesa/server/x11/graphics/gl_context.cpp 2016-01-29 08:18:22 +0000
+++ src/platforms/mesa/server/x11/graphics/gl_context.cpp 1970-01-01 00:00:00 +0000
@@ -1,45 +0,0 @@
1/*
2 * Copyright © 2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 3,
6 * as 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 Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Cemil Azizoglu <cemil.azizoglu@canonical.com>
17 *
18 */
19
20#include "mir/graphics/egl_error.h"
21#include "gl_context.h"
22#include <boost/throw_exception.hpp>
23#include <stdexcept>
24
25namespace mg=mir::graphics;
26namespace mgx=mg::X;
27
28mgx::XGLContext::XGLContext(EGLDisplay const d, EGLSurface const s, EGLContext const c)
29 : egl_dpy{d},
30 egl_surf{s},
31 egl_ctx{c}
32{
33}
34
35void mgx::XGLContext::make_current() const
36{
37 if (!eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx))
38 BOOST_THROW_EXCEPTION(mg::egl_error("Cannot make current"));
39}
40
41void mgx::XGLContext::release_current() const
42{
43 if (!eglMakeCurrent(egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT))
44 BOOST_THROW_EXCEPTION(mg::egl_error("Cannot make uncurrent"));
45}
460
=== removed file 'src/platforms/mesa/server/x11/graphics/gl_context.h'
--- src/platforms/mesa/server/x11/graphics/gl_context.h 2016-07-28 09:10:43 +0000
+++ src/platforms/mesa/server/x11/graphics/gl_context.h 1970-01-01 00:00:00 +0000
@@ -1,52 +0,0 @@
1/*
2 * Copyright © 2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 3,
6 * as 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 Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Cemil Azizoglu <cemil.azizoglu@canonical.com>
17 *
18 */
19
20#ifndef MIR_GRAPHICS_X_GL_CONTEXT_H_
21#define MIR_GRAPHICS_X_GL_CONTEXT_H_
22
23#include "mir/renderer/gl/context.h"
24
25#include <EGL/egl.h>
26
27namespace mir
28{
29namespace graphics
30{
31namespace X
32{
33
34class XGLContext : public renderer::gl::Context
35{
36public:
37 XGLContext(EGLDisplay const d, EGLSurface const s, EGLContext const c);
38 ~XGLContext() = default;
39 void make_current() const override;
40 void release_current() const override;
41
42private:
43 EGLDisplay const egl_dpy;
44 EGLSurface const egl_surf;
45 EGLContext const egl_ctx;
46};
47
48}
49}
50}
51
52#endif /* MIR_GRAPHICS_X_GL_CONTEXT_H_ */
530
=== modified file 'src/platforms/mesa/server/x11/graphics/platform.cpp'
--- src/platforms/mesa/server/x11/graphics/platform.cpp 2016-09-07 03:37:03 +0000
+++ src/platforms/mesa/server/x11/graphics/platform.cpp 2016-09-26 01:54:42 +0000
@@ -51,7 +51,7 @@
51 std::shared_ptr<DisplayConfigurationPolicy> const& /*initial_conf_policy*/,51 std::shared_ptr<DisplayConfigurationPolicy> const& /*initial_conf_policy*/,
52 std::shared_ptr<GLConfig> const& gl_config)52 std::shared_ptr<GLConfig> const& gl_config)
53{53{
54 return make_module_ptr<mgx::Display>(x11_connection.get(), size, *gl_config,54 return make_module_ptr<mgx::Display>(x11_connection.get(), size, gl_config,
55 report);55 report);
56}56}
5757
5858
=== modified file 'tests/unit-tests/graphics/test_platform_prober.cpp'
--- tests/unit-tests/graphics/test_platform_prober.cpp 2016-06-23 17:53:10 +0000
+++ tests/unit-tests/graphics/test_platform_prober.cpp 2016-09-26 01:54:42 +0000
@@ -25,8 +25,10 @@
25#include "mir/raii.h"25#include "mir/raii.h"
2626
27#include "mir/test/doubles/mock_egl.h"27#include "mir/test/doubles/mock_egl.h"
28#ifdef MIR_BUILD_PLATFORM_MESA_KMS28#if defined(MIR_BUILD_PLATFORM_MESA_KMS) || defined(MIR_BUILD_PLATFORM_MESA_X11)
29#include "mir/test/doubles/mock_drm.h"29#include "mir/test/doubles/mock_drm.h"
30#endif
31#ifdef MIR_BUILD_PLATFORM_MESA_KMS
30#include "mir/test/doubles/mock_gbm.h"32#include "mir/test/doubles/mock_gbm.h"
31#endif33#endif
3234
3335
=== modified file 'tests/unit-tests/platforms/mesa/x11/test_display.cpp'
--- tests/unit-tests/platforms/mesa/x11/test_display.cpp 2016-09-07 04:45:58 +0000
+++ tests/unit-tests/platforms/mesa/x11/test_display.cpp 2016-09-26 01:54:42 +0000
@@ -27,11 +27,13 @@
27#include "mir/test/doubles/mock_egl.h"27#include "mir/test/doubles/mock_egl.h"
28#include "mir/test/doubles/mock_x11.h"28#include "mir/test/doubles/mock_x11.h"
29#include "mir/test/doubles/mock_gl_config.h"29#include "mir/test/doubles/mock_gl_config.h"
30#include "mir/test/fake_shared.h"
3031
3132
32namespace mg=mir::graphics;33namespace mg=mir::graphics;
33namespace mgx=mg::X;34namespace mgx=mg::X;
34namespace mtd=mir::test::doubles;35namespace mt=mir::test;
36namespace mtd=mt::doubles;
35namespace geom=mir::geometry;37namespace geom=mir::geometry;
36using namespace testing;38using namespace testing;
3739
@@ -97,7 +99,7 @@
97 return std::make_shared<mgx::Display>(99 return std::make_shared<mgx::Display>(
98 mock_x11.fake_x11.display,100 mock_x11.fake_x11.display,
99 size,101 size,
100 mock_gl_config,102 mt::fake_shared(mock_gl_config),
101 std::make_shared<mir::report::null::DisplayReport>());103 std::make_shared<mir::report::null::DisplayReport>());
102 }104 }
103105
@@ -112,18 +114,9 @@
112{114{
113 using namespace testing;115 using namespace testing;
114116
115 EXPECT_CALL(mock_egl, eglGetDisplay(mock_x11.fake_x11.display))
116 .Times(Exactly(1));
117
118 EXPECT_CALL(mock_x11, XCreateWindow_wrapper(mock_x11.fake_x11.display,_, size.width.as_int(), size.height.as_int(),_,_,_,_,_,_))117 EXPECT_CALL(mock_x11, XCreateWindow_wrapper(mock_x11.fake_x11.display,_, size.width.as_int(), size.height.as_int(),_,_,_,_,_,_))
119 .Times(Exactly(1));118 .Times(Exactly(1));
120119
121 EXPECT_CALL(mock_egl, eglCreateContext(mock_egl.fake_egl_display,_, EGL_NO_CONTEXT,_))
122 .Times(Exactly(1));
123
124 EXPECT_CALL(mock_egl, eglCreateWindowSurface(mock_egl.fake_egl_display,_, reinterpret_cast<mtd::MockEGL::AnyNativeType>(mock_x11.fake_x11.window), nullptr))
125 .Times(Exactly(1));
126
127 EXPECT_CALL(mock_x11, XNextEvent(mock_x11.fake_x11.display,_))120 EXPECT_CALL(mock_x11, XNextEvent(mock_x11.fake_x11.display,_))
128 .Times(AtLeast(1));121 .Times(AtLeast(1));
129122

Subscribers

People subscribed via source and target branches