From a3151b6a07294c15ffa37c6b59ef3f03eb81cc07 Mon Sep 17 00:00:00 2001 From: Simon Fels Date: Mon, 19 Dec 2016 08:00:50 +0100 Subject: [PATCH] Calculate display bounds for all available displays The hwcomposer module for Android doesn't support multi-monitor well enough for our use case yet so we give Android a large enough primary display. This may have negative effects performance wise for the until we disabled all non freeform stack and wallpaper related rendering on the Android side so that only visible windows are drawn to not waste any GPU cycles on things we don't render anyway. --- src/anbox/ubuntu/platform_policy.cpp | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/anbox/ubuntu/platform_policy.cpp b/src/anbox/ubuntu/platform_policy.cpp index b065fce5..e0d3e533 100644 --- a/src/anbox/ubuntu/platform_policy.cpp +++ b/src/anbox/ubuntu/platform_policy.cpp @@ -39,16 +39,26 @@ PlatformPolicy::PlatformPolicy( if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS) < 0) BOOST_THROW_EXCEPTION(std::runtime_error("Failed to initialize SDL")); - event_thread_ = std::thread(&PlatformPolicy::process_events, this); + auto display_frame = graphics::Rect::Invalid; + for (auto n = 0; n < SDL_GetNumVideoDisplays(); n++) { + SDL_Rect r; + if (SDL_GetDisplayBounds(n, &r) != 0) + continue; + + graphics::Rect frame{r.x, r.y, r.x + r.w, r.y + r.h}; - SDL_DisplayMode display_mode; - // FIXME statically just check the first (primary) display for its mode; - // once we get multi-monitor support we need to do this better. - if (SDL_GetCurrentDisplayMode(0, &display_mode) == 0) { - display_info_.horizontal_resolution = display_mode.w; - display_info_.vertical_resolution = display_mode.h; + if (display_frame == graphics::Rect::Invalid) + display_frame = frame; + else + display_frame.merge(frame); } + if (display_frame == graphics::Rect::Invalid) + BOOST_THROW_EXCEPTION(std::runtime_error("No valid display configuration found")); + + display_info_.horizontal_resolution = display_frame.width(); + display_info_.vertical_resolution = display_frame.height(); + pointer_ = input_manager->create_device(); pointer_->set_name("anbox-pointer"); pointer_->set_driver_version(1); @@ -70,6 +80,8 @@ PlatformPolicy::PlatformPolicy( keyboard_->set_physical_location("none"); keyboard_->set_key_bit(BTN_MISC); keyboard_->set_key_bit(KEY_OK); + + event_thread_ = std::thread(&PlatformPolicy::process_events, this); } PlatformPolicy::~PlatformPolicy() { -- GitLab