Mir

Merge lp:~andreas-pokorny/mir/fix-1596051 into lp:mir

Proposed by Andreas Pokorny
Status: Merged
Approved by: Cemil Azizoglu
Approved revision: 3555
Merged at revision: 3563
Proposed branch: lp:~andreas-pokorny/mir/fix-1596051
Merge into: lp:mir
Diff against target: 218 lines (+75/-5)
6 files modified
src/platforms/mesa/server/x11/graphics/display.cpp (+19/-1)
src/platforms/mesa/server/x11/graphics/display.h (+2/-0)
src/platforms/mesa/server/x11/graphics/display_configuration.cpp (+0/-1)
tests/include/mir/test/doubles/mock_x11.h (+2/-0)
tests/mir_test_doubles/mock_x11.cpp (+13/-0)
tests/unit-tests/graphics/mesa/x11/test_display.cpp (+39/-3)
To merge this branch: bzr merge lp:~andreas-pokorny/mir/fix-1596051
Reviewer Review Type Date Requested Status
Cemil Azizoglu (community) Approve
Alexandros Frantzis (community) Approve
Mir CI Bot continuous-integration Approve
Review via email: mp+298488@code.launchpad.net

Commit message

fix: use Information inside default x11 screen of display to calculate size of window in mm

instead of using the resolution as screen size in mm

Description of the change

Small fix in x11 platform .. forwards the mm information x11 believes is correct. It is off by four to six cm in my case (the information offered by kms seems to be more accurate), but better than claiming we have 1 pixel per millimeter.

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

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

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

review: Approve (continuous-integration)
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

Looks good.

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

Ok

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/platforms/mesa/server/x11/graphics/display.cpp'
2--- src/platforms/mesa/server/x11/graphics/display.cpp 2016-06-13 16:03:06 +0000
3+++ src/platforms/mesa/server/x11/graphics/display.cpp 2016-06-28 08:29:09 +0000
4@@ -36,6 +36,22 @@
5 #define MIR_LOG_COMPONENT "x11-display"
6 #include "mir/log.h"
7
8+namespace
9+{
10+auto get_pixel_width(Display *dpy)
11+{
12+ auto screen = XDefaultScreenOfDisplay(dpy);
13+
14+ return float(screen->mwidth) / screen->width;
15+}
16+auto get_pixel_height(Display *dpy)
17+{
18+ auto screen = XDefaultScreenOfDisplay(dpy);
19+
20+ return float(screen->mheight) / screen->height;
21+}
22+}
23+
24 namespace mg=mir::graphics;
25 namespace mgx=mg::X;
26 namespace geom=mir::geometry;
27@@ -256,6 +272,8 @@
28 GLConfig const& gl_config)
29 : egl_display{X11EGLDisplay(x_dpy)},
30 size{size},
31+ pixel_width{get_pixel_width(x_dpy)},
32+ pixel_height{get_pixel_height(x_dpy)},
33 win{X11Window(x_dpy,
34 egl_display,
35 size,
36@@ -291,7 +309,7 @@
37
38 std::unique_ptr<mg::DisplayConfiguration> mgx::Display::configuration() const
39 {
40- return std::make_unique<mgx::DisplayConfiguration>(pf, size, orientation);
41+ return std::make_unique<mgx::DisplayConfiguration>(pf, geom::Size{size.width*pixel_width, size.height*pixel_height}, orientation);
42 }
43
44 void mgx::Display::configure(mg::DisplayConfiguration const& new_configuration)
45
46=== modified file 'src/platforms/mesa/server/x11/graphics/display.h'
47--- src/platforms/mesa/server/x11/graphics/display.h 2016-06-09 14:10:58 +0000
48+++ src/platforms/mesa/server/x11/graphics/display.h 2016-06-28 08:29:09 +0000
49@@ -128,6 +128,8 @@
50 private:
51 X11EGLDisplay const egl_display;
52 mir::geometry::Size const size;
53+ float pixel_width;
54+ float pixel_height;
55 X11Window const win;
56 X11EGLContext egl_context;
57 X11EGLSurface egl_surface;
58
59=== modified file 'src/platforms/mesa/server/x11/graphics/display_configuration.cpp'
60--- src/platforms/mesa/server/x11/graphics/display_configuration.cpp 2016-01-29 08:18:22 +0000
61+++ src/platforms/mesa/server/x11/graphics/display_configuration.cpp 2016-06-28 08:29:09 +0000
62@@ -33,7 +33,6 @@
63 //TODO: query fps
64 {mg::DisplayConfigurationMode{size, 60.0}},
65 0,
66- //TODO: query mm-size
67 size,
68 true,
69 true,
70
71=== modified file 'tests/include/mir/test/doubles/mock_x11.h'
72--- tests/include/mir/test/doubles/mock_x11.h 2016-06-10 00:36:22 +0000
73+++ tests/include/mir/test/doubles/mock_x11.h 2016-06-28 08:29:09 +0000
74@@ -39,6 +39,7 @@
75
76 Display *display;
77 Window window;
78+ Screen screen;
79 XVisualInfo visual_info;
80 XEvent keypress_event_return = { 0 };
81 XEvent button_release_event_return = { 0 };
82@@ -77,6 +78,7 @@
83 MOCK_METHOD5(XLookupString, int(XKeyEvent*, char*, int, KeySym*, XComposeStatus*));
84 MOCK_METHOD1(XRefreshKeyboardMapping, int(XMappingEvent*));
85 MOCK_METHOD1(XDefaultRootWindow, Window(Display*));
86+ MOCK_METHOD1(XDefaultScreenOfDisplay, Screen*(Display*));
87 MOCK_METHOD6(XGrabKeyboard, int(Display*, Window, Bool, int, int, Time));
88 MOCK_METHOD2(XUngrabKeyboard, int(Display*, Time));
89 MOCK_METHOD4(XGetErrorText, int(Display*, int, char*, int ));
90
91=== modified file 'tests/mir_test_doubles/mock_x11.cpp'
92--- tests/mir_test_doubles/mock_x11.cpp 2016-06-10 00:36:22 +0000
93+++ tests/mir_test_doubles/mock_x11.cpp 2016-06-28 08:29:09 +0000
94@@ -43,6 +43,7 @@
95 std::memset(&enter_notify_event_return, 0, sizeof(XEvent));
96 std::memset(&leave_notify_event_return, 0, sizeof(XEvent));
97 std::memset(&visual_info, 0, sizeof(XVisualInfo));
98+ std::memset(&screen, 0, sizeof screen);
99 visual_info.red_mask = 0xFF0000;
100 keypress_event_return.type = KeyPress;
101 button_release_event_return.type = ButtonRelease;
102@@ -56,6 +57,10 @@
103 motion_event_return.type = MotionNotify;
104 enter_notify_event_return.type = EnterNotify;
105 leave_notify_event_return.type = LeaveNotify;
106+ screen.width = 1024;
107+ screen.height = 768;
108+ screen.mwidth = 338;
109+ screen.mwidth = 270;
110 }
111
112 mtd::MockX11::MockX11()
113@@ -68,6 +73,9 @@
114 ON_CALL(*this, XOpenDisplay(_))
115 .WillByDefault(Return(fake_x11.display));
116
117+ ON_CALL(*this, XDefaultScreenOfDisplay(fake_x11.display))
118+ .WillByDefault(Return(&fake_x11.screen));
119+
120 ON_CALL(*this, XGetVisualInfo(fake_x11.display,_,_,_))
121 .WillByDefault(DoAll(SetArgPointee<3>(1),
122 Return(&fake_x11.visual_info)));
123@@ -224,3 +232,8 @@
124 {
125 return global_mock->XSetWMProtocols(display, w, protocols, count);
126 }
127+
128+Screen* XDefaultScreenOfDisplay(Display* display)
129+{
130+ return global_mock->XDefaultScreenOfDisplay(display);
131+}
132
133=== modified file 'tests/unit-tests/graphics/mesa/x11/test_display.cpp'
134--- tests/unit-tests/graphics/mesa/x11/test_display.cpp 2016-06-09 14:10:58 +0000
135+++ tests/unit-tests/graphics/mesa/x11/test_display.cpp 2016-06-28 08:29:09 +0000
136@@ -20,23 +20,29 @@
137 #include <gmock/gmock.h>
138
139 #include "src/platforms/mesa/server/x11/graphics/display.h"
140+
141+#include "mir/graphics/display_configuration.h"
142+
143 #include "mir/test/doubles/mock_egl.h"
144 #include "mir/test/doubles/mock_x11.h"
145 #include "mir/test/doubles/mock_gl_config.h"
146
147+
148 namespace mg=mir::graphics;
149 namespace mgx=mg::X;
150 namespace mtd=mir::test::doubles;
151 namespace geom=mir::geometry;
152+using namespace testing;
153+
154
155 namespace
156 {
157
158-geom::Size const size{1280, 1024};
159
160 class X11DisplayTest : public ::testing::Test
161 {
162 public:
163+ geom::Size size{1280, 1024};
164
165 X11DisplayTest()
166 {
167@@ -77,6 +83,14 @@
168 Return(1)));
169 }
170
171+ void setup_x11_screen(geom::Size const& pixel, geom::Size const& mm, geom::Size const& window)
172+ {
173+ mock_x11.fake_x11.screen.width = pixel.width.as_int();
174+ mock_x11.fake_x11.screen.height = pixel.height.as_int();
175+ mock_x11.fake_x11.screen.mwidth = mm.width.as_int();
176+ mock_x11.fake_x11.screen.mheight = mm.height.as_int();
177+ size = window;
178+ }
179 std::shared_ptr<mgx::Display> create_display()
180 {
181 return std::make_shared<mgx::Display>(
182@@ -119,8 +133,6 @@
183
184 TEST_F(X11DisplayTest, respects_gl_config)
185 {
186- using namespace testing;
187-
188 EGLint const depth_bits{24};
189 EGLint const stencil_bits{8};
190
191@@ -141,3 +153,27 @@
192
193 auto display = create_display();
194 }
195+
196+TEST_F(X11DisplayTest, calculates_physical_size_of_display_based_on_default_screen)
197+{
198+ auto const pixel = geom::Size{2560, 1080};
199+ auto const mm = geom::Size{677, 290};
200+ auto const window = geom::Size{1280, 1024};
201+ auto const pixel_width = float(mm.width.as_int()) / float(pixel.width.as_int());
202+ auto const pixel_height = float(mm.height.as_int()) / float(pixel.height.as_int());
203+ auto const expected_size = geom::Size{window.width * pixel_width, window.height * pixel_height};
204+
205+ setup_x11_screen(pixel, mm, window);
206+
207+ auto display = create_display();
208+ auto config = display->configuration();
209+ geom::Size reported_size;
210+ config->for_each_output(
211+ [&reported_size](mg::DisplayConfigurationOutput const& output)
212+ {
213+ reported_size = output.physical_size_mm;
214+ }
215+ );
216+
217+ EXPECT_THAT(reported_size, Eq(expected_size));
218+}

Subscribers

People subscribed via source and target branches