From a453635b5518e18de1717f6bfdcc18afb9267484 Mon Sep 17 00:00:00 2001 From: Simon Fels Date: Mon, 27 Jun 2016 23:41:23 +0200 Subject: [PATCH] Refactor actual window creation into ubuntu specific namespace --- CMakeLists.txt | 2 + src/CMakeLists.txt | 9 ++-- src/anbox/cmds/run.cpp | 5 ++- src/anbox/graphics/gl_renderer_server.cpp | 13 +++--- src/anbox/graphics/gl_renderer_server.h | 9 ++-- src/anbox/graphics/window_creator.cpp | 30 +++++++++++++ src/anbox/graphics/window_creator.h | 45 +++++++++++++++++++ .../mir_display_connection.cpp | 14 ++++-- .../mir_display_connection.h | 10 ++--- .../mir_window.cpp => ubuntu/window.cpp} | 38 +++++++++------- .../mir_window.h => ubuntu/window.h} | 26 +++++------ .../window_creator.cpp} | 39 +++++++--------- .../window_creator.h} | 33 ++++++-------- 13 files changed, 177 insertions(+), 96 deletions(-) create mode 100644 src/anbox/graphics/window_creator.cpp create mode 100644 src/anbox/graphics/window_creator.h rename src/anbox/{graphics => ubuntu}/mir_display_connection.cpp (91%) rename src/anbox/{graphics => ubuntu}/mir_display_connection.h (89%) rename src/anbox/{graphics/mir_window.cpp => ubuntu/window.cpp} (88%) rename src/anbox/{graphics/mir_window.h => ubuntu/window.h} (80%) rename src/anbox/{graphics/mir_native_window_creator.cpp => ubuntu/window_creator.cpp} (50%) rename src/anbox/{graphics/mir_native_window_creator.h => ubuntu/window_creator.h} (59%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e38339b..93ca1692 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,6 +61,8 @@ find_package(Threads) find_package(EGL REQUIRED) find_package(GLESv2 REQUIRED) +# TODO(morphis): make mir an optional requirement so we can also add support +# for X11, wayland, ... at a later point if needed. pkg_check_modules(MIRCLIENT REQUIRED mirclient) ##################################################################### diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 65ad03fc..3633eeb1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -43,10 +43,8 @@ set(SOURCES anbox/network/delegate_connection_creator.h anbox/graphics/opengles_message_processor.cpp - anbox/graphics/mir_display_connection.cpp - anbox/graphics/mir_window.cpp - anbox/graphics/mir_native_window_creator.cpp anbox/graphics/gl_renderer_server.cpp + anbox/graphics/window_creator.cpp anbox/input/manager.cpp anbox/input/device.cpp @@ -59,6 +57,11 @@ set(SOURCES anbox/support/camera_message_processor.cpp anbox/support/fingerprint_message_processor.cpp + anbox/ubuntu/platform_server.cpp + anbox/ubuntu/mir_display_connection.cpp + anbox/ubuntu/window_creator.cpp + anbox/ubuntu/window.cpp + anbox/cmds/version.cpp anbox/cmds/run.cpp anbox/cmds/shell.cpp diff --git a/src/anbox/cmds/run.cpp b/src/anbox/cmds/run.cpp index 757a3975..24482713 100644 --- a/src/anbox/cmds/run.cpp +++ b/src/anbox/cmds/run.cpp @@ -29,6 +29,8 @@ #include "anbox/network/qemu_pipe_connection_creator.h" #include "anbox/graphics/gl_renderer_server.h" #include "anbox/input/manager.h" +#include "anbox/ubuntu/platform_server.h" +#include "anbox/ubuntu/window_creator.h" #include @@ -69,7 +71,8 @@ anbox::cmds::Run::Run() auto input_manager = std::make_shared(rt); - auto renderer = std::make_shared(input_manager); + auto window_creator = std::make_shared(input_manager); + auto renderer = std::make_shared(window_creator); renderer->start(); // Socket which will be used by the qemud service inside the Android diff --git a/src/anbox/graphics/gl_renderer_server.cpp b/src/anbox/graphics/gl_renderer_server.cpp index 32b00bb9..5b3fa243 100644 --- a/src/anbox/graphics/gl_renderer_server.cpp +++ b/src/anbox/graphics/gl_renderer_server.cpp @@ -17,8 +17,7 @@ #include "anbox/logger.h" #include "anbox/graphics/gl_renderer_server.h" -#include "anbox/graphics/mir_native_window_creator.h" -#include "anbox/graphics/mir_display_connection.h" +#include "anbox/graphics/window_creator.h" #include "OpenglRender/render_api.h" @@ -28,8 +27,8 @@ namespace anbox { namespace graphics { -GLRendererServer::GLRendererServer(const std::shared_ptr &input_manager) : - window_creator_(std::make_shared(input_manager)) { +GLRendererServer::GLRendererServer(const std::shared_ptr &window_creator) : + window_creator_(window_creator) { // Force the host EGL/GLES libraries as translator implementation ::setenv("ANDROID_EGL_LIB", "libEGL.so.1", 1); @@ -65,9 +64,9 @@ void GLRendererServer::start() { log_funcs.coarse = logger_write; log_funcs.fine = logger_write; - auto display = window_creator_->display(); - const auto width = display->horizontal_resolution(); - const auto height = display->vertical_resolution(); + auto display_info = window_creator_->display_info(); + const auto width = display_info.horizontal_resolution; + const auto height = display_info.vertical_resolution; char server_addr[256] = { 0 }; if (!initOpenGLRenderer(width, height, true, server_addr, sizeof(server_addr), log_funcs, logger_write)) diff --git a/src/anbox/graphics/gl_renderer_server.h b/src/anbox/graphics/gl_renderer_server.h index afc3cf29..4b5fad91 100644 --- a/src/anbox/graphics/gl_renderer_server.h +++ b/src/anbox/graphics/gl_renderer_server.h @@ -24,13 +24,12 @@ namespace anbox { namespace input { class Manager; -} +} // namespace input namespace graphics { -class MirNativeWindowCreator; - +class WindowCreator; class GLRendererServer { public: - GLRendererServer(const std::shared_ptr &input_manager); + GLRendererServer(const std::shared_ptr &window_creator); ~GLRendererServer(); void start(); @@ -39,7 +38,7 @@ public: private: std::string socket_path_; - std::shared_ptr window_creator_; + std::shared_ptr window_creator_; }; } // namespace graphics diff --git a/src/anbox/graphics/window_creator.cpp b/src/anbox/graphics/window_creator.cpp new file mode 100644 index 00000000..f93d73db --- /dev/null +++ b/src/anbox/graphics/window_creator.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2016 Simon Fels + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + */ + +#include "anbox/graphics/window_creator.h" + + +namespace anbox { +namespace graphics { +WindowCreator::WindowCreator(const std::shared_ptr &input_manager) : + input_manager_(input_manager) { +} + +WindowCreator::~WindowCreator() { +} +} // namespace graphics +} // namespace anbox diff --git a/src/anbox/graphics/window_creator.h b/src/anbox/graphics/window_creator.h new file mode 100644 index 00000000..ab0578a5 --- /dev/null +++ b/src/anbox/graphics/window_creator.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2016 Simon Fels + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + */ + +#ifndef ANBOX_GRAPHICS_WINDOW_CREATOR_H_ +#define ANBOX_GRAPHICS_WINDOW_CREATOR_H_ + +#include "external/android-emugl/host/libs/libOpenglRender/NativeSubWindow.h" + +namespace anbox { +namespace input { +class Manager; +} // namespace input +namespace graphics { +class WindowCreator : public SubWindowHandler { +public: + WindowCreator(const std::shared_ptr &input_manager); + virtual ~WindowCreator(); + + struct DisplayInfo { + int horizontal_resolution; + int vertical_resolution; + }; + + virtual DisplayInfo display_info() const = 0; + +protected: + std::shared_ptr input_manager_; +}; +} // namespace graphics +} // namespace anbox +#endif diff --git a/src/anbox/graphics/mir_display_connection.cpp b/src/anbox/ubuntu/mir_display_connection.cpp similarity index 91% rename from src/anbox/graphics/mir_display_connection.cpp rename to src/anbox/ubuntu/mir_display_connection.cpp index 9ac1008a..da0aa83c 100644 --- a/src/anbox/graphics/mir_display_connection.cpp +++ b/src/anbox/ubuntu/mir_display_connection.cpp @@ -14,7 +14,7 @@ * with this program. If not, see . * */ -#include "anbox/graphics/mir_display_connection.h" +#include "anbox/ubuntu/mir_display_connection.h" #include "anbox/logger.h" #include @@ -48,7 +48,7 @@ static const MirDisplayOutput *find_active_output( } namespace anbox { -namespace graphics { +namespace ubuntu { MirDisplayConnection::MirDisplayConnection() : connection_(nullptr), output_id_(-1), @@ -70,6 +70,13 @@ MirDisplayConnection::MirDisplayConnection() : BOOST_THROW_EXCEPTION(std::runtime_error(msg.c_str())); } + mir_connection_set_display_config_change_callback( + connection_, + [](MirConnection* connection, void* context) { + auto thiz = reinterpret_cast(context); + DEBUG(""); + }, this); + MirDisplayConfiguration* display_config = mir_connection_create_display_config(connection_); @@ -82,6 +89,7 @@ MirDisplayConnection::MirDisplayConnection() : output_id_ = output->output_id; const MirDisplayMode *mode = &output->modes[output->current_mode]; + vertical_resolution_ = mode->vertical_resolution; horizontal_resolution_ = mode->horizontal_resolution; @@ -118,5 +126,5 @@ int MirDisplayConnection::vertical_resolution() const { int MirDisplayConnection::horizontal_resolution() const { return horizontal_resolution_; } -} // namespace graphics +} // namespace ubuntu } // namespace anbox diff --git a/src/anbox/graphics/mir_display_connection.h b/src/anbox/ubuntu/mir_display_connection.h similarity index 89% rename from src/anbox/graphics/mir_display_connection.h rename to src/anbox/ubuntu/mir_display_connection.h index b0c9f297..e3176acf 100644 --- a/src/anbox/graphics/mir_display_connection.h +++ b/src/anbox/ubuntu/mir_display_connection.h @@ -15,8 +15,8 @@ * */ -#ifndef ANBOX_GRAPHICS_MIR_DISPLAY_CONNECTION_H_ -#define ANBOX_GRAPHICS_MIR_DISPLAY_CONNECTION_H_ +#ifndef ANBOX_UBUNTU_MIR_DISPLAY_CONNECTION_H_ +#define ANBOX_UBUNTU_MIR_DISPLAY_CONNECTION_H_ #define MIR_EGL_PLATFORM @@ -25,8 +25,7 @@ #include namespace anbox { -namespace graphics { - +namespace ubuntu { class MirDisplayConnection { public: MirDisplayConnection(); @@ -47,8 +46,7 @@ private: int vertical_resolution_; int horizontal_resolution_; }; - -} // namespace graphics +} // namespace ubuntu } // namespace anbox #endif diff --git a/src/anbox/graphics/mir_window.cpp b/src/anbox/ubuntu/window.cpp similarity index 88% rename from src/anbox/graphics/mir_window.cpp rename to src/anbox/ubuntu/window.cpp index dd4afdf8..655943ae 100644 --- a/src/anbox/graphics/mir_window.cpp +++ b/src/anbox/ubuntu/window.cpp @@ -15,11 +15,13 @@ * */ -#include "anbox/graphics/mir_window.h" -#include "anbox/graphics/mir_display_connection.h" -#include "anbox/logger.h" +#include "anbox/ubuntu/window.h" +#include "anbox/ubuntu/mir_display_connection.h" #include "anbox/input/manager.h" #include "anbox/input/device.h" +#include "anbox/logger.h" + +#include namespace { class SlotFingerMapper { @@ -64,9 +66,12 @@ private: }; } + namespace anbox { -namespace graphics { -MirWindow::MirWindow(const std::shared_ptr &display, const std::shared_ptr &input_manager) : +namespace ubuntu { +Window::Window(const std::shared_ptr &display, + const std::shared_ptr &input_manager, + int width, int height) : native_window_(0), surface_(nullptr) { @@ -76,14 +81,15 @@ MirWindow::MirWindow(const std::shared_ptr &display, const auto spec = mir_connection_create_spec_for_normal_surface( display->connection(), - display->vertical_resolution(), - display->horizontal_resolution(), + width, + height, pixel_format); mir_surface_spec_set_name(spec, "anbox"); mir_surface_spec_set_event_handler(spec, handle_surface_event, this); mir_surface_spec_set_fullscreen_on_output(spec, display->output_id()); mir_surface_spec_set_buffer_usage(spec, mir_buffer_usage_hardware); + mir_surface_spec_set_shell_chrome(spec, mir_shell_chrome_normal); surface_ = mir_surface_create_sync(spec); mir_surface_spec_release(spec); @@ -116,19 +122,19 @@ MirWindow::MirWindow(const std::shared_ptr &display, const input_device_->set_abs_bit(ABS_MT_POSITION_Y); input_device_->set_prop_bit(INPUT_PROP_DIRECT); input_device_->set_abs_min(ABS_MT_POSITION_X, 0); - input_device_->set_abs_max(ABS_MT_POSITION_X, display->horizontal_resolution()); + input_device_->set_abs_max(ABS_MT_POSITION_X, parameters.width); input_device_->set_abs_min(ABS_MT_POSITION_Y, 0); - input_device_->set_abs_max(ABS_MT_POSITION_Y, display->vertical_resolution()); + input_device_->set_abs_max(ABS_MT_POSITION_Y, parameters.height); input_device_->set_abs_max(ABS_MT_SLOT, 10); input_device_->set_abs_max(ABS_MT_TRACKING_ID, 255); input_device_->set_key_bit(BTN_TOUCH); input_device_->set_key_bit(BTN_TOOL_FINGER); } -MirWindow::~MirWindow() { +Window::~Window() { } -void MirWindow::handle_touch_event(MirTouchEvent const* touch_event) { +void Window::handle_touch_event(MirTouchEvent const* touch_event) { const auto point_count = mir_touch_event_point_count(touch_event); static SlotFingerMapper mapper; @@ -178,7 +184,7 @@ void MirWindow::handle_touch_event(MirTouchEvent const* touch_event) { } } -void MirWindow::handle_input_event(MirInputEvent const* input_event) { +void Window::handle_input_event(MirInputEvent const* input_event) { const auto type = mir_input_event_get_type(input_event); MirTouchEvent const* touch_event = nullptr; MirKeyboardEvent const* key_event = nullptr; @@ -196,9 +202,9 @@ void MirWindow::handle_input_event(MirInputEvent const* input_event) { } } -void MirWindow::handle_surface_event(MirSurface *surface, MirEvent const* event, void *context) { +void Window::handle_surface_event(MirSurface*, MirEvent const* event, void *context) { const auto event_type = mir_event_get_type(event); - auto thiz = static_cast(context); + auto thiz = static_cast(context); switch (event_type) { case mir_event_type_input: @@ -209,8 +215,8 @@ void MirWindow::handle_surface_event(MirSurface *surface, MirEvent const* event, } } -EGLNativeWindowType MirWindow::native_window() const { +EGLNativeWindowType Window::native_window() const { return native_window_; } -} // namespace graphics +} // namespace bridge } // namespace anbox diff --git a/src/anbox/graphics/mir_window.h b/src/anbox/ubuntu/window.h similarity index 80% rename from src/anbox/graphics/mir_window.h rename to src/anbox/ubuntu/window.h index da6c6141..1f3cc10d 100644 --- a/src/anbox/graphics/mir_window.h +++ b/src/anbox/ubuntu/window.h @@ -15,29 +15,28 @@ * */ -#ifndef ANBOX_GRAPHICS_MIR_WINDOW_H_ -#define ANBOX_GRAPHICS_MIR_WINDOW_H_ - -#define MIR_EGL_PLATFORM - -#include +#ifndef ANBOX_UBUNTU_WINDOW_H_ +#define ANBOX_UBUNTU_WINDOW_H_ #include #include +#include + namespace anbox { namespace input { class Manager; class Device; -} -namespace graphics { +} // namespace input +namespace ubuntu { class MirDisplayConnection; - -class MirWindow { +class Window { public: - MirWindow(const std::shared_ptr &display, const std::shared_ptr &input_manager); - ~MirWindow(); + Window(const std::shared_ptr &display, + const std::shared_ptr &input_manager, + int width, int height); + ~Window(); EGLNativeWindowType native_window() const; @@ -51,8 +50,7 @@ private: EGLNativeWindowType native_window_; MirSurface *surface_; }; - -} // namespace graphics +} // namespace bridge } // namespace anbox #endif diff --git a/src/anbox/graphics/mir_native_window_creator.cpp b/src/anbox/ubuntu/window_creator.cpp similarity index 50% rename from src/anbox/graphics/mir_native_window_creator.cpp rename to src/anbox/ubuntu/window_creator.cpp index a8577304..4fd77ec0 100644 --- a/src/anbox/graphics/mir_native_window_creator.cpp +++ b/src/anbox/ubuntu/window_creator.cpp @@ -15,39 +15,35 @@ * */ -#include "anbox/graphics/mir_native_window_creator.h" -#include "anbox/graphics/mir_display_connection.h" -#include "anbox/graphics/mir_window.h" -#include "anbox/input/manager.h" +#include "anbox/ubuntu/window_creator.h" +#include "anbox/ubuntu/window.h" +#include "anbox/ubuntu/mir_display_connection.h" +#include "anbox/logger.h" #include namespace anbox { -namespace graphics { -MirNativeWindowCreator::MirNativeWindowCreator(const std::shared_ptr &input_manager) : +namespace ubuntu { +WindowCreator::WindowCreator(const std::shared_ptr &input_manager) : + graphics::WindowCreator(input_manager), input_manager_(input_manager), - display_connection_(std::make_shared()) { + display_(std::make_shared()) { } -MirNativeWindowCreator::~MirNativeWindowCreator() { +WindowCreator::~WindowCreator() { } -EGLNativeWindowType MirNativeWindowCreator::create_window(int x, int y, int width, int height) { - (void) x; - (void) y; - (void) width; - (void) height; +EGLNativeWindowType WindowCreator::create_window(int x, int y, int width, int height) { + DEBUG("x %i y %i width %i height %i", x, y, width, height); - if (windows_.size() > 0) - BOOST_THROW_EXCEPTION(std::runtime_error("We currently only allow a single native window")); - - auto window = std::make_shared(display_connection_, input_manager_); + auto window = std::make_shared(display_, input_manager_, + width, height); windows_.insert({window->native_window(), window}); return window->native_window(); } -void MirNativeWindowCreator::destroy_window(EGLNativeWindowType win) { +void WindowCreator::destroy_window(EGLNativeWindowType win) { auto iter = windows_.find(win); if (iter == windows_.end()) return; @@ -55,9 +51,8 @@ void MirNativeWindowCreator::destroy_window(EGLNativeWindowType win) { windows_.erase(iter); } -std::shared_ptr MirNativeWindowCreator::display() const { - return display_connection_; +WindowCreator::DisplayInfo WindowCreator::display_info() const { + return {display_->horizontal_resolution(), display_->vertical_resolution()}; } - -} // namespace graphics +} // namespace bridge } // namespace anbox diff --git a/src/anbox/graphics/mir_native_window_creator.h b/src/anbox/ubuntu/window_creator.h similarity index 59% rename from src/anbox/graphics/mir_native_window_creator.h rename to src/anbox/ubuntu/window_creator.h index 2c7f3ebf..60a2f8de 100644 --- a/src/anbox/graphics/mir_native_window_creator.h +++ b/src/anbox/ubuntu/window_creator.h @@ -15,40 +15,35 @@ * */ -#ifndef ANBOX_GRAPHICS_MIR_NATIVE_WINDOW_CREATOR_H_ -#define ANBOX_GRAPHICS_MIR_NATIVE_WINDOW_CREATOR_H_ +#ifndef ANBOX_UBUNTU_WINDOW_CREATOR_H_ +#define ANBOX_UBUNTU_WINDOW_CREATOR_H_ -#include "external/android-emugl/host/libs/libOpenglRender/NativeSubWindow.h" +#include "anbox/graphics/window_creator.h" -#include #include -namespace anbox { -namespace input { -class Manager; -} -namespace graphics { +#include +namespace anbox { +namespace ubuntu { class MirDisplayConnection; -class MirWindow; - -class MirNativeWindowCreator : public SubWindowHandler { +class Window; +class WindowCreator : public graphics::WindowCreator { public: - MirNativeWindowCreator(const std::shared_ptr &input_channel); - virtual ~MirNativeWindowCreator(); + WindowCreator(const std::shared_ptr &input_manager); + ~WindowCreator(); EGLNativeWindowType create_window(int x, int y, int width, int height) override; void destroy_window(EGLNativeWindowType win) override; - std::shared_ptr display() const; + DisplayInfo display_info() const override; private: std::shared_ptr input_manager_; - std::shared_ptr display_connection_; - std::map> windows_; + std::shared_ptr display_; + std::map> windows_; }; - -} // namespace graphics +} // namespace bridge } // namespace anbox #endif -- GitLab