提交 a453635b 编写于 作者: S Simon Fels

Refactor actual window creation into ubuntu specific namespace

上级 cbd43fb7
......@@ -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)
#####################################################################
......
......@@ -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
......
......@@ -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 <sys/prctl.h>
......@@ -69,7 +71,8 @@ anbox::cmds::Run::Run()
auto input_manager = std::make_shared<input::Manager>(rt);
auto renderer = std::make_shared<graphics::GLRendererServer>(input_manager);
auto window_creator = std::make_shared<ubuntu::WindowCreator>(input_manager);
auto renderer = std::make_shared<graphics::GLRendererServer>(window_creator);
renderer->start();
// Socket which will be used by the qemud service inside the Android
......
......@@ -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> &input_manager) :
window_creator_(std::make_shared<MirNativeWindowCreator>(input_manager)) {
GLRendererServer::GLRendererServer(const std::shared_ptr<WindowCreator> &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))
......
......@@ -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> &input_manager);
GLRendererServer(const std::shared_ptr<WindowCreator> &window_creator);
~GLRendererServer();
void start();
......@@ -39,7 +38,7 @@ public:
private:
std::string socket_path_;
std::shared_ptr<MirNativeWindowCreator> window_creator_;
std::shared_ptr<WindowCreator> window_creator_;
};
} // namespace graphics
......
/*
* Copyright (C) 2016 Simon Fels <morphis@gravedo.de>
*
* 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 <http://www.gnu.org/licenses/>.
*
*/
#include "anbox/graphics/window_creator.h"
namespace anbox {
namespace graphics {
WindowCreator::WindowCreator(const std::shared_ptr<input::Manager> &input_manager) :
input_manager_(input_manager) {
}
WindowCreator::~WindowCreator() {
}
} // namespace graphics
} // namespace anbox
/*
* Copyright (C) 2016 Simon Fels <morphis@gravedo.de>
*
* 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 <http://www.gnu.org/licenses/>.
*
*/
#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> &input_manager);
virtual ~WindowCreator();
struct DisplayInfo {
int horizontal_resolution;
int vertical_resolution;
};
virtual DisplayInfo display_info() const = 0;
protected:
std::shared_ptr<input::Manager> input_manager_;
};
} // namespace graphics
} // namespace anbox
#endif
......@@ -14,7 +14,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "anbox/graphics/mir_display_connection.h"
#include "anbox/ubuntu/mir_display_connection.h"
#include "anbox/logger.h"
#include <boost/throw_exception.hpp>
......@@ -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<MirDisplayConnection*>(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
......@@ -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 <EGL/egl.h>
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
......@@ -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 <boost/throw_exception.hpp>
namespace {
class SlotFingerMapper {
......@@ -64,9 +66,12 @@ private:
};
}
namespace anbox {
namespace graphics {
MirWindow::MirWindow(const std::shared_ptr<MirDisplayConnection> &display, const std::shared_ptr<input::Manager> &input_manager) :
namespace ubuntu {
Window::Window(const std::shared_ptr<MirDisplayConnection> &display,
const std::shared_ptr<input::Manager> &input_manager,
int width, int height) :
native_window_(0),
surface_(nullptr) {
......@@ -76,14 +81,15 @@ MirWindow::MirWindow(const std::shared_ptr<MirDisplayConnection> &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<MirDisplayConnection> &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<MirWindow*>(context);
auto thiz = static_cast<Window*>(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
......@@ -15,29 +15,28 @@
*
*/
#ifndef ANBOX_GRAPHICS_MIR_WINDOW_H_
#define ANBOX_GRAPHICS_MIR_WINDOW_H_
#define MIR_EGL_PLATFORM
#include <mirclient/mir_toolkit/mir_client_library.h>
#ifndef ANBOX_UBUNTU_WINDOW_H_
#define ANBOX_UBUNTU_WINDOW_H_
#include <EGL/egl.h>
#include <memory>
#include <mirclient/mir_toolkit/mir_client_library.h>
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<MirDisplayConnection> &display, const std::shared_ptr<input::Manager> &input_manager);
~MirWindow();
Window(const std::shared_ptr<MirDisplayConnection> &display,
const std::shared_ptr<input::Manager> &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
......@@ -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 <boost/throw_exception.hpp>
namespace anbox {
namespace graphics {
MirNativeWindowCreator::MirNativeWindowCreator(const std::shared_ptr<input::Manager> &input_manager) :
namespace ubuntu {
WindowCreator::WindowCreator(const std::shared_ptr<input::Manager> &input_manager) :
graphics::WindowCreator(input_manager),
input_manager_(input_manager),
display_connection_(std::make_shared<MirDisplayConnection>()) {
display_(std::make_shared<MirDisplayConnection>()) {
}
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<MirWindow>(display_connection_, input_manager_);
auto window = std::make_shared<Window>(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<MirDisplayConnection> 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
......@@ -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 <memory>
#include <map>
namespace anbox {
namespace input {
class Manager;
}
namespace graphics {
#include <EGL/egl.h>
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::Manager> &input_channel);
virtual ~MirNativeWindowCreator();
WindowCreator(const std::shared_ptr<input::Manager> &input_manager);
~WindowCreator();
EGLNativeWindowType create_window(int x, int y, int width, int height) override;
void destroy_window(EGLNativeWindowType win) override;
std::shared_ptr<MirDisplayConnection> display() const;
DisplayInfo display_info() const override;
private:
std::shared_ptr<input::Manager> input_manager_;
std::shared_ptr<MirDisplayConnection> display_connection_;
std::map<EGLNativeWindowType,std::shared_ptr<MirWindow>> windows_;
std::shared_ptr<MirDisplayConnection> display_;
std::map<EGLNativeWindowType,std::shared_ptr<Window>> windows_;
};
} // namespace graphics
} // namespace bridge
} // namespace anbox
#endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册