Don't register platform policy as display manager but use a singleton instead

This commit is contained in:
Simon Fels 2017-05-12 08:36:03 +02:00
commit 583e191071
6 changed files with 40 additions and 44 deletions

View file

@ -159,8 +159,6 @@ anbox::cmds::SessionManager::SessionManager(const BusFactory &bus_factory)
display_frame = window_size_; display_frame = window_size_;
auto policy = std::make_shared<ubuntu::PlatformPolicy>(input_manager, display_frame, single_window_); auto policy = std::make_shared<ubuntu::PlatformPolicy>(input_manager, display_frame, single_window_);
// FIXME this needs to be removed and solved differently behind the scenes
registerDisplayManager(policy);
auto app_db = std::make_shared<application::Database>(); auto app_db = std::make_shared<application::Database>();

View file

@ -17,22 +17,22 @@
#include "DisplayManager.h" #include "DisplayManager.h"
namespace { namespace anbox {
std::shared_ptr<DisplayManager> display_mgr; namespace graphics {
namespace emugl {
class NullDisplayManager : public DisplayManager { std::shared_ptr<DisplayInfo> DisplayInfo::get() {
public: static auto info = std::make_shared<DisplayInfo>();
DisplayInfo display_info() const override { return {1280, 720}; } return info;
};
} }
DisplayManager::~DisplayManager() {} void DisplayInfo::set_resolution(const std::uint32_t &vertical, const std::uint32_t horizontal) {
vertical_resolution_ = vertical;
std::shared_ptr<DisplayManager> DisplayManager::get() { horizontal_resolution_ = horizontal;
if (!display_mgr) display_mgr = std::make_shared<NullDisplayManager>();
return display_mgr;
} }
void registerDisplayManager(const std::shared_ptr<DisplayManager> &mgr) { std::uint32_t DisplayInfo::vertical_resolution() const { return vertical_resolution_; }
display_mgr = mgr;
} std::uint32_t DisplayInfo::horizontal_resolution() const { return horizontal_resolution_; }
} // namespace emugl
} // namespace graphics
} // namespace anbox

View file

@ -15,25 +15,32 @@
* *
*/ */
#ifndef DISPLAY_MANAGER_H_ #ifndef ANBOX_GRAPHICS_EMUGL_DISPLAY_INFO_H_
#define DISPLAY_MANAGER_H_ #define ANBOX_GRAPHICS_EMUGL_DISPLAY_INFO_H_
#include <cstdint>
#include <memory> #include <memory>
class DisplayManager { namespace anbox {
namespace graphics {
namespace emugl {
class DisplayInfo {
public: public:
virtual ~DisplayManager(); DisplayInfo() = default;
struct DisplayInfo { static std::shared_ptr<DisplayInfo> get();
int horizontal_resolution;
int vertical_resolution;
};
virtual DisplayInfo display_info() const = 0; void set_resolution(const std::uint32_t &vertical, const std::uint32_t horizontal);
static std::shared_ptr<DisplayManager> get(); std::uint32_t vertical_resolution() const;
std::uint32_t horizontal_resolution() const;
private:
std::uint32_t vertical_resolution_ = 1280;
std::uint32_t horizontal_resolution_ = 720;
}; };
} // namespace emugl
void registerDisplayManager(const std::shared_ptr<DisplayManager> &mgr); } // namespace graphics
} // namespace anbox
#endif #endif

View file

@ -169,10 +169,10 @@ static EGLint rcGetFBParam(EGLint param) {
switch (param) { switch (param) {
case FB_WIDTH: case FB_WIDTH:
ret = DisplayManager::get()->display_info().horizontal_resolution; ret = static_cast<EGLint>(anbox::graphics::emugl::DisplayInfo::get()->horizontal_resolution());
break; break;
case FB_HEIGHT: case FB_HEIGHT:
ret = DisplayManager::get()->display_info().vertical_resolution; ret = static_cast<EGLint>(anbox::graphics::emugl::DisplayInfo::get()->vertical_resolution());
break; break;
case FB_XDPI: case FB_XDPI:
ret = 72; // XXX: should be implemented ret = 72; // XXX: should be implemented
@ -360,12 +360,12 @@ int rcGetNumDisplays() {
int rcGetDisplayWidth(uint32_t display_id) { int rcGetDisplayWidth(uint32_t display_id) {
(void)display_id; (void)display_id;
return DisplayManager::get()->display_info().horizontal_resolution; return static_cast<int>(anbox::graphics::emugl::DisplayInfo::get()->horizontal_resolution());
} }
int rcGetDisplayHeight(uint32_t display_id) { int rcGetDisplayHeight(uint32_t display_id) {
(void)display_id; (void)display_id;
return DisplayManager::get()->display_info().vertical_resolution; return static_cast<int>(anbox::graphics::emugl::DisplayInfo::get()->vertical_resolution());
} }
int rcGetDisplayDpiX(uint32_t display_id) { int rcGetDisplayDpiX(uint32_t display_id) {

View file

@ -68,8 +68,7 @@ PlatformPolicy::PlatformPolicy(
window_size_immutable_ = true; window_size_immutable_ = true;
} }
display_info_.horizontal_resolution = display_frame.width(); graphics::emugl::DisplayInfo::get()->set_resolution(display_frame.width(), display_frame.height());
display_info_.vertical_resolution = display_frame.height();
pointer_ = input_manager->create_device(); pointer_ = input_manager->create_device();
pointer_->set_name("anbox-pointer"); pointer_->set_name("anbox-pointer");
@ -285,10 +284,6 @@ void PlatformPolicy::window_resized(const Window::Id &id,
} }
} }
DisplayManager::DisplayInfo PlatformPolicy::display_info() const {
return display_info_;
}
void PlatformPolicy::set_clipboard_data(const ClipboardData &data) { void PlatformPolicy::set_clipboard_data(const ClipboardData &data) {
if (data.text.empty()) if (data.text.empty())
return; return;

View file

@ -41,8 +41,7 @@ class Manager;
namespace ubuntu { namespace ubuntu {
class PlatformPolicy : public std::enable_shared_from_this<PlatformPolicy>, class PlatformPolicy : public std::enable_shared_from_this<PlatformPolicy>,
public platform::Policy, public platform::Policy,
public Window::Observer, public Window::Observer {
public DisplayManager {
public: public:
PlatformPolicy(const std::shared_ptr<input::Manager> &input_manager, PlatformPolicy(const std::shared_ptr<input::Manager> &input_manager,
const graphics::Rect &static_display_frame = graphics::Rect::Invalid, const graphics::Rect &static_display_frame = graphics::Rect::Invalid,
@ -61,8 +60,6 @@ class PlatformPolicy : public std::enable_shared_from_this<PlatformPolicy>,
void window_resized(const Window::Id &id, const std::int32_t &width, void window_resized(const Window::Id &id, const std::int32_t &width,
const std::int32_t &height) override; const std::int32_t &height) override;
DisplayInfo display_info() const override;
void set_renderer(const std::shared_ptr<Renderer> &renderer); void set_renderer(const std::shared_ptr<Renderer> &renderer);
void set_window_manager(const std::shared_ptr<wm::Manager> &window_manager); void set_window_manager(const std::shared_ptr<wm::Manager> &window_manager);
@ -89,7 +86,6 @@ class PlatformPolicy : public std::enable_shared_from_this<PlatformPolicy>,
bool event_thread_running_; bool event_thread_running_;
std::shared_ptr<input::Device> pointer_; std::shared_ptr<input::Device> pointer_;
std::shared_ptr<input::Device> keyboard_; std::shared_ptr<input::Device> keyboard_;
DisplayManager::DisplayInfo display_info_;
bool window_size_immutable_ = false; bool window_size_immutable_ = false;
bool single_window_ = false; bool single_window_ = false;
}; };