Mir

Merge lp:~vanvugt/mir/black-bars into lp:mir

Proposed by Daniel van Vugt
Status: Merged
Approved by: Daniel van Vugt
Approved revision: no longer in the source branch.
Merged at revision: 4035
Proposed branch: lp:~vanvugt/mir/black-bars
Merge into: lp:mir
Diff against target: 157 lines (+132/-0)
2 files modified
src/renderers/gl/renderer.cpp (+31/-0)
tests/unit-tests/renderers/gl/test_gl_renderer.cpp (+101/-0)
To merge this branch: bzr merge lp:~vanvugt/mir/black-bars
Reviewer Review Type Date Requested Status
Brandon Schaefer (community) Approve
Mir CI Bot continuous-integration Approve
Review via email: mp+317293@code.launchpad.net

Commit message

Add letterboxing/black bars support to the GL renderer, for when
the logical viewport aspect doesn't match that of the screen.

This will be used in future for arbitrary cloning of one monitor
to another (LP: #1639226)

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

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

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

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

lgtm

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/renderers/gl/renderer.cpp'
--- src/renderers/gl/renderer.cpp 2017-01-27 08:13:36 +0000
+++ src/renderers/gl/renderer.cpp 2017-02-15 10:20:35 +0000
@@ -370,6 +370,37 @@
370 0.0f});370 0.0f});
371371
372 viewport = rect;372 viewport = rect;
373
374 /*
375 * Letterboxing: Move the glViewport to add black bars in the case that
376 * the logical viewport aspect ratio doesn't match the display aspect.
377 * This keeps pixels square. Note "black"-bars are really glClearColor.
378 */
379 auto transformed_viewport = display_transform *
380 glm::vec4(viewport.size.width.as_int(),
381 viewport.size.height.as_int(), 0, 1);
382 auto viewport_width = fabs(transformed_viewport[0]);
383 auto viewport_height = fabs(transformed_viewport[1]);
384 auto dpy = eglGetCurrentDisplay();
385 auto surf = eglGetCurrentSurface(EGL_DRAW);
386 EGLint buf_width = 0, buf_height = 0;
387
388 if (viewport_width > 0.0f && viewport_height > 0.0f &&
389 eglQuerySurface(dpy, surf, EGL_WIDTH, &buf_width) && buf_width > 0 &&
390 eglQuerySurface(dpy, surf, EGL_HEIGHT, &buf_height) && buf_height > 0)
391 {
392 GLint reduced_width = buf_width, reduced_height = buf_height;
393 // if viewport_aspect_ratio >= buf_aspect_ratio
394 if (viewport_width * buf_height >= buf_width * viewport_height)
395 reduced_height = buf_width * viewport_height / viewport_width;
396 else
397 reduced_width = buf_height * viewport_width / viewport_height;
398
399 GLint offset_x = (buf_width - reduced_width) / 2;
400 GLint offset_y = (buf_height - reduced_height) / 2;
401
402 glViewport(offset_x, offset_y, reduced_width, reduced_height);
403 }
373}404}
374405
375void mrg::Renderer::set_output_transform(glm::mat2 const& t)406void mrg::Renderer::set_output_transform(glm::mat2 const& t)
376407
=== modified file 'tests/unit-tests/renderers/gl/test_gl_renderer.cpp'
--- tests/unit-tests/renderers/gl/test_gl_renderer.cpp 2016-01-29 08:18:22 +0000
+++ tests/unit-tests/renderers/gl/test_gl_renderer.cpp 2017-02-15 10:20:35 +0000
@@ -39,6 +39,7 @@
39using testing::Pointee;39using testing::Pointee;
40using testing::AnyNumber;40using testing::AnyNumber;
41using testing::AtLeast;41using testing::AtLeast;
42using testing::DoAll;
42using testing::_;43using testing::_;
4344
44namespace mt=mir::test;45namespace mt=mir::test;
@@ -314,3 +315,103 @@
314315
315 renderer.render(renderable_list);316 renderer.render(renderable_list);
316}317}
318
319TEST_F(GLRenderer, sets_viewport_unscaled_exact)
320{
321 int const screen_width = 1920;
322 int const screen_height = 1080;
323 mir::geometry::Rectangle const view_area{{0,0}, {1920,1080}};
324
325 ON_CALL(mock_egl, eglQuerySurface(_,_,EGL_WIDTH,_))
326 .WillByDefault(DoAll(SetArgPointee<3>(screen_width),
327 Return(EGL_TRUE)));
328 ON_CALL(mock_egl, eglQuerySurface(_,_,EGL_HEIGHT,_))
329 .WillByDefault(DoAll(SetArgPointee<3>(screen_height),
330 Return(EGL_TRUE)));
331 ON_CALL(mock_display_buffer, view_area())
332 .WillByDefault(Return(view_area));
333
334 EXPECT_CALL(mock_gl, glViewport(0, 0, screen_width, screen_height));
335
336 mrg::Renderer renderer(mock_display_buffer);
337}
338
339TEST_F(GLRenderer, sets_viewport_upscaled_exact)
340{
341 int const screen_width = 1920;
342 int const screen_height = 1080;
343 mir::geometry::Rectangle const view_area{{0,0}, {1280,720}};
344
345 ON_CALL(mock_egl, eglQuerySurface(_,_,EGL_WIDTH,_))
346 .WillByDefault(DoAll(SetArgPointee<3>(screen_width),
347 Return(EGL_TRUE)));
348 ON_CALL(mock_egl, eglQuerySurface(_,_,EGL_HEIGHT,_))
349 .WillByDefault(DoAll(SetArgPointee<3>(screen_height),
350 Return(EGL_TRUE)));
351 ON_CALL(mock_display_buffer, view_area())
352 .WillByDefault(Return(view_area));
353
354 EXPECT_CALL(mock_gl, glViewport(0, 0, screen_width, screen_height));
355
356 mrg::Renderer renderer(mock_display_buffer);
357}
358
359TEST_F(GLRenderer, sets_viewport_downscaled_exact)
360{
361 int const screen_width = 1280;
362 int const screen_height = 720;
363 mir::geometry::Rectangle const view_area{{0,0}, {1920,1080}};
364
365 ON_CALL(mock_egl, eglQuerySurface(_,_,EGL_WIDTH,_))
366 .WillByDefault(DoAll(SetArgPointee<3>(screen_width),
367 Return(EGL_TRUE)));
368 ON_CALL(mock_egl, eglQuerySurface(_,_,EGL_HEIGHT,_))
369 .WillByDefault(DoAll(SetArgPointee<3>(screen_height),
370 Return(EGL_TRUE)));
371 ON_CALL(mock_display_buffer, view_area())
372 .WillByDefault(Return(view_area));
373
374 EXPECT_CALL(mock_gl, glViewport(0, 0, screen_width, screen_height));
375
376 mrg::Renderer renderer(mock_display_buffer);
377}
378
379TEST_F(GLRenderer, sets_viewport_upscaled_narrow)
380{
381 int const screen_width = 1920;
382 int const screen_height = 1080;
383 mir::geometry::Rectangle const view_area{{0,0}, {640,480}};
384
385 ON_CALL(mock_egl, eglQuerySurface(_,_,EGL_WIDTH,_))
386 .WillByDefault(DoAll(SetArgPointee<3>(screen_width),
387 Return(EGL_TRUE)));
388 ON_CALL(mock_egl, eglQuerySurface(_,_,EGL_HEIGHT,_))
389 .WillByDefault(DoAll(SetArgPointee<3>(screen_height),
390 Return(EGL_TRUE)));
391 ON_CALL(mock_display_buffer, view_area())
392 .WillByDefault(Return(view_area));
393
394 EXPECT_CALL(mock_gl, glViewport(240, 0, 1440, 1080));
395
396 mrg::Renderer renderer(mock_display_buffer);
397}
398
399TEST_F(GLRenderer, sets_viewport_downscaled_wide)
400{
401 int const screen_width = 640;
402 int const screen_height = 480;
403 mir::geometry::Rectangle const view_area{{0,0}, {1920,1080}};
404
405 ON_CALL(mock_egl, eglQuerySurface(_,_,EGL_WIDTH,_))
406 .WillByDefault(DoAll(SetArgPointee<3>(screen_width),
407 Return(EGL_TRUE)));
408 ON_CALL(mock_egl, eglQuerySurface(_,_,EGL_HEIGHT,_))
409 .WillByDefault(DoAll(SetArgPointee<3>(screen_height),
410 Return(EGL_TRUE)));
411 ON_CALL(mock_display_buffer, view_area())
412 .WillByDefault(Return(view_area));
413
414 EXPECT_CALL(mock_gl, glViewport(0, 60, 640, 360));
415
416 mrg::Renderer renderer(mock_display_buffer);
417}

Subscribers

People subscribed via source and target branches