Mir

Merge lp:~albaguirre/mir/fix-1539268 into lp:mir

Proposed by Alberto Aguirre
Status: Merged
Approved by: Alberto Aguirre
Approved revision: no longer in the source branch.
Merged at revision: 3283
Proposed branch: lp:~albaguirre/mir/fix-1539268
Merge into: lp:mir
Diff against target: 124 lines (+68/-2)
3 files modified
src/server/graphics/nested/display.cpp (+21/-2)
src/server/graphics/nested/display.h (+3/-0)
tests/unit-tests/graphics/nested/test_nested_display.cpp (+44/-0)
To merge this branch: bzr merge lp:~albaguirre/mir/fix-1539268
Reviewer Review Type Date Requested Status
Alan Griffiths Approve
Chris Halse Rogers Approve
Daniel van Vugt Needs Information
PS Jenkins bot (community) continuous-integration Approve
Mir CI Bot continuous-integration Approve
Review via email: mp+284361@code.launchpad.net

Commit message

nested-display: Use matching egl configs when creating any context (display, display buffer, shared gl context) (LP: #1539268)

Do not use arbitrary attributes when choosing an egl config for the context created during create_gl_context.

Description of the change

As described in bug report:

The surfacelesscontext created uses a default attribute list which may not match the actual attribute list used to create the egl context associated with the nested display.

This is problematic for qtmir - as it creates a temporary context in an effort to query the underlying eglconfig used for the display and inform Qt about R/G/B/A/Depth/stencil sizes.

If the surfaceless context happens to choose a config that has no alpha, qtmir will inform Qt that there's no alpha (when there actually is) and rendering artifacts can occur.

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

PASSED: Continuous integration, rev:3276
https://mir-jenkins.ubuntu.com/job/mir-ci/182/
Executed test runs:
    None: https://mir-jenkins.ubuntu.com/job/generic-update-mp/182/console

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

review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:3276
http://jenkins.qa.ubuntu.com/job/mir-ci/6156/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/mir-android-vivid-i386-build/5728
    SUCCESS: http://jenkins.qa.ubuntu.com/job/mir-clang-vivid-amd64-build/4635
    SUCCESS: http://jenkins.qa.ubuntu.com/job/mir-mediumtests-vivid-touch/5684
    FAILURE: http://jenkins.qa.ubuntu.com/job/mir-mediumtests-xenial-touch/356/console
    SUCCESS: http://jenkins.qa.ubuntu.com/job/mir-xenial-amd64-ci/480
        deb: http://jenkins.qa.ubuntu.com/job/mir-xenial-amd64-ci/480/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/mir-xenial-i386-ci/480
        deb: http://jenkins.qa.ubuntu.com/job/mir-xenial-i386-ci/480/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/mir-mediumtests-builder-vivid-armhf/5681
        deb: http://jenkins.qa.ubuntu.com/job/mir-mediumtests-builder-vivid-armhf/5681/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/mir-mediumtests-runner-touch/8108
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/touch-flash-device/27150
    SUCCESS: http://jenkins.qa.ubuntu.com/job/mir-mediumtests-builder-xenial-armhf/352
        deb: http://jenkins.qa.ubuntu.com/job/mir-mediumtests-builder-xenial-armhf/352/artifact/work/output/*zip*/output.zip
    FAILURE: http://jenkins.qa.ubuntu.com/job/mir-mediumtests-runner-xenial-touch/208/console
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/touch-flash-device/27152

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/mir-ci/6156/rebuild

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

Looks harmless, but I wonder; is this a case where mir_connection_get_egl_pixel_format or something similar would be more robust?

review: Needs Information
Revision history for this message
Chris Halse Rogers (raof) wrote :

Looks sensible.

review: Approve
Revision history for this message
Alberto Aguirre (albaguirre) wrote :

> Looks harmless, but I wonder; is this a case where
> mir_connection_get_egl_pixel_format or something similar would be more robust?

But we already know what mir pixel format has been selected for the nested display. This MP just makes sure all other contexts created also match the same egl configuration.

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

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/server/graphics/nested/display.cpp'
2--- src/server/graphics/nested/display.cpp 2016-01-20 23:59:18 +0000
3+++ src/server/graphics/nested/display.cpp 2016-01-28 22:38:43 +0000
4@@ -67,7 +67,8 @@
5 std::shared_ptr<GLConfig> const& gl_config)
6 : egl_display(EGL_NO_DISPLAY),
7 egl_context_(EGL_NO_CONTEXT),
8- gl_config{gl_config}
9+ gl_config{gl_config},
10+ pixel_format{mir_pixel_format_invalid}
11 {
12 egl_display = eglGetDisplay(native_display);
13 if (egl_display == EGL_NO_DISPLAY)
14@@ -84,6 +85,7 @@
15 BOOST_THROW_EXCEPTION(mg::egl_error("Nested Mir Display Error: Failed to initialize EGL."));
16 }
17
18+ pixel_format = format;
19 egl_context_ = eglCreateContext(egl_display, choose_windowed_es_config(format), EGL_NO_CONTEXT, detail::nested_egl_context_attribs);
20
21 if (egl_context_ == EGL_NO_CONTEXT)
22@@ -119,6 +121,23 @@
23 return egl_context_;
24 }
25
26+std::unique_ptr<mg::GLContext> mgn::detail::EGLDisplayHandle::create_gl_context()
27+{
28+ EGLint const attribs[] =
29+ {
30+ EGL_SURFACE_TYPE, EGL_DONT_CARE,
31+ EGL_RED_SIZE, mg::red_channel_depth(pixel_format),
32+ EGL_GREEN_SIZE, mg::green_channel_depth(pixel_format),
33+ EGL_BLUE_SIZE, mg::blue_channel_depth(pixel_format),
34+ EGL_ALPHA_SIZE, mg::alpha_channel_depth(pixel_format),
35+ EGL_DEPTH_SIZE, gl_config->depth_buffer_bits(),
36+ EGL_STENCIL_SIZE, gl_config->stencil_buffer_bits(),
37+ EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
38+ EGL_NONE
39+ };
40+ return std::make_unique<SurfacelessEGLContext>(egl_display, attribs, EGL_NO_CONTEXT);
41+}
42+
43 mgn::detail::EGLDisplayHandle::~EGLDisplayHandle() noexcept
44 {
45 eglTerminate(egl_display);
46@@ -349,5 +368,5 @@
47
48 std::unique_ptr<mg::GLContext> mgn::Display::create_gl_context()
49 {
50- return std::make_unique<SurfacelessEGLContext>(egl_display, EGL_NO_CONTEXT);
51+ return egl_display.create_gl_context();
52 }
53
54=== modified file 'src/server/graphics/nested/display.h'
55--- src/server/graphics/nested/display.h 2016-01-20 23:59:18 +0000
56+++ src/server/graphics/nested/display.h 2016-01-28 22:38:43 +0000
57@@ -80,12 +80,15 @@
58 void initialize(MirPixelFormat format);
59 EGLConfig choose_windowed_es_config(MirPixelFormat format) const;
60 EGLContext egl_context() const;
61+ std::unique_ptr<graphics::GLContext> create_gl_context();
62+
63 operator EGLDisplay() const { return egl_display; }
64
65 private:
66 EGLDisplay egl_display;
67 EGLContext egl_context_;
68 std::shared_ptr<GLConfig> const gl_config;
69+ MirPixelFormat pixel_format;
70
71 EGLDisplayHandle(EGLDisplayHandle const&) = delete;
72 EGLDisplayHandle operator=(EGLDisplayHandle const&) = delete;
73
74=== modified file 'tests/unit-tests/graphics/nested/test_nested_display.cpp'
75--- tests/unit-tests/graphics/nested/test_nested_display.cpp 2015-06-29 03:29:31 +0000
76+++ tests/unit-tests/graphics/nested/test_nested_display.cpp 2016-01-28 22:38:43 +0000
77@@ -200,3 +200,47 @@
78 EXPECT_CALL(mock_egl,
79 eglMakeCurrent(_, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
80 }
81+
82+TEST_F(NestedDisplay, shared_context_uses_matching_egl_attributes)
83+{
84+ using namespace testing;
85+
86+ NiceMock<mtd::MockGLConfig> mock_gl_config;
87+ EGLint const depth_bits{24};
88+ EGLint const stencil_bits{8};
89+
90+ std::string extensions{"EGL_KHR_surfaceless_context"};
91+ ON_CALL(mock_gl_config, depth_buffer_bits())
92+ .WillByDefault(Return(depth_bits));
93+ ON_CALL(mock_gl_config, stencil_buffer_bits())
94+ .WillByDefault(Return(stencil_bits));
95+ ON_CALL(mock_egl, eglChooseConfig(_,_,_,_,_))
96+ .WillByDefault(DoAll(SetArgPointee<2>(mock_egl.fake_configs[0]),
97+ SetArgPointee<4>(1),
98+ Return(EGL_TRUE)));
99+ ON_CALL(mock_egl, eglQueryString(_, EGL_EXTENSIONS))
100+ .WillByDefault(Return(extensions.c_str()));
101+
102+ // mt::build_trivial_configuration sets mir_pixel_format_abgr_8888
103+ EGLint const expected_alpha_bits = 8;
104+ EGLint const expected_red_bits = 8;
105+ EGLint const expected_green_bits = 8;
106+ EGLint const expected_blue_bits = 8;
107+ EXPECT_CALL(mock_egl,
108+ eglChooseConfig(
109+ _,
110+ AllOf(mtd::EGLConfigContainsAttrib(EGL_DEPTH_SIZE, depth_bits),
111+ mtd::EGLConfigContainsAttrib(EGL_STENCIL_SIZE, stencil_bits),
112+ mtd::EGLConfigContainsAttrib(EGL_RED_SIZE, expected_red_bits),
113+ mtd::EGLConfigContainsAttrib(EGL_GREEN_SIZE, expected_green_bits),
114+ mtd::EGLConfigContainsAttrib(EGL_BLUE_SIZE, expected_blue_bits),
115+ mtd::EGLConfigContainsAttrib(EGL_ALPHA_SIZE, expected_alpha_bits)),
116+ _,_,_))
117+ .Times(AtLeast(1));
118+
119+ auto const nested_display = create_nested_display(
120+ null_platform,
121+ mt::fake_shared(mock_gl_config));
122+
123+ auto dummy_context = nested_display->create_gl_context();
124+}

Subscribers

People subscribed via source and target branches