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

Use SDL for window creation and management

上级 5ee8c02b
......@@ -62,9 +62,7 @@ find_package(EGL REQUIRED)
find_package(GLESv2 REQUIRED)
find_package(Protobuf 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)
pkg_check_modules(SDL2 sdl2)
pkg_check_modules(DBUS_CPP dbus-cpp REQUIRED)
pkg_check_modules(DBUS dbus-1 REQUIRED)
......
......@@ -6,6 +6,7 @@ include_directories(
${MIRCLIENT_INCLUDE_DIRS}
${DBUS_CPP_INCLUDE_DIRS}
${DBUS_INCLUDE_DIRS}
${SDL2_INCLUDE_DIRS}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/src
......@@ -90,7 +91,6 @@ set(SOURCES
anbox/bridge/android_api_stub.cpp
anbox/ubuntu/platform_api_skeleton.cpp
anbox/ubuntu/mir_display_connection.cpp
anbox/ubuntu/window_creator.cpp
anbox/ubuntu/window.cpp
......@@ -117,6 +117,7 @@ target_link_libraries(anbox-core
${MIRCLIENT_LDFLAGS}
${MIRCLIENT_LIBRARIES}
${DBUS_CPP_LIBRARIES}
${SDL2_LIBRARIES}
pthread
process-cpp
OpenglRender
......
此差异已折叠。
......@@ -23,7 +23,7 @@
#include <memory>
#include <vector>
#include <mirclient/mir_toolkit/mir_client_library.h>
#include <SDL.h>
namespace anbox {
namespace input {
......@@ -32,29 +32,23 @@ class Device;
class Event;
} // namespace input
namespace ubuntu {
class MirDisplayConnection;
class Window {
public:
Window(const std::shared_ptr<MirDisplayConnection> &display,
const std::shared_ptr<input::Manager> &input_manager,
Window(const std::shared_ptr<input::Manager> &input_manager,
int width, int height);
~Window();
void process_input_event(const SDL_Event &event);
EGLNativeWindowType native_window() const;
private:
static void handle_surface_event(MirSurface *surface, MirEvent const* event, void *context);
void handle_input_event(MirInputEvent const* input_event);
void handle_touch_event(MirTouchEvent const* touch_event);
void handle_pointer_event(MirPointerEvent const* pointer_event);
void handle_pointer_button_event(std::vector<input::Event> &events,
MirPointerEvent const* pointer_event, bool pressed);
std::shared_ptr<input::Device> touchpanel_;
std::shared_ptr<input::Device> pointer_;
std::shared_ptr<input::Device> keyboard_;
EGLNativeDisplayType native_display_;
EGLNativeWindowType native_window_;
MirSurface *surface_;
SDL_Window *window_;
};
} // namespace bridge
} // namespace anbox
......
......@@ -17,7 +17,6 @@
#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>
......@@ -26,20 +25,62 @@ namespace anbox {
namespace ubuntu {
WindowCreator::WindowCreator(const std::shared_ptr<input::Manager> &input_manager) :
graphics::WindowCreator(input_manager),
input_manager_(input_manager),
display_(std::make_shared<MirDisplayConnection>()) {
input_manager_(input_manager) {
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS) < 0)
BOOST_THROW_EXCEPTION(std::runtime_error("Failed to initialize SDL"));
event_thread = std::thread(&WindowCreator::process_events, this);
}
WindowCreator::~WindowCreator() {
}
void WindowCreator::process_window_event(const SDL_Event &event) {
}
void WindowCreator::process_events() {
while(true) {
SDL_Event event;
while (SDL_WaitEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
// FIXME once one of our windows is closed we need to decide what
// to do base on the configuration we're running in.
break;
case SDL_WINDOWEVENT:
process_window_event(event);
break;
case SDL_FINGERUP:
case SDL_FINGERMOTION:
case SDL_FINGERDOWN:
case SDL_MOUSEMOTION:
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
case SDL_MOUSEWHEEL:
case SDL_KEYDOWN:
case SDL_KEYUP:
if (current_window_)
current_window_->process_input_event(event);
break;
}
}
}
}
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);
auto window = std::make_shared<Window>(display_, input_manager_,
width, height);
if (windows_.size() == 1) {
WARNING("Tried to create another window but we currently only allow one");
return 0;
}
auto window = std::make_shared<Window>(input_manager_, width, height);
windows_.insert({window->native_window(), window});
current_window_ = window;
return window->native_window();
}
......@@ -52,11 +93,12 @@ void WindowCreator::destroy_window(EGLNativeWindowType win) {
}
WindowCreator::DisplayInfo WindowCreator::display_info() const {
return {display_->horizontal_resolution(), display_->vertical_resolution()};
// FIXME: force for now until we have real detection for this
return {1280, 720};
}
EGLNativeDisplayType WindowCreator::native_display() const {
return display_->native_display();
return 0;
}
} // namespace bridge
} // namespace anbox
......@@ -21,8 +21,10 @@
#include "anbox/graphics/window_creator.h"
#include <map>
#include <thread>
#include <EGL/egl.h>
#include <SDL.h>
namespace anbox {
namespace ubuntu {
......@@ -40,9 +42,13 @@ public:
EGLNativeDisplayType native_display() const override;
private:
void process_events();
void process_window_event(const SDL_Event &event);
std::shared_ptr<input::Manager> input_manager_;
std::shared_ptr<MirDisplayConnection> display_;
std::map<EGLNativeWindowType,std::shared_ptr<Window>> windows_;
std::shared_ptr<Window> current_window_;
std::thread event_thread;
};
} // namespace bridge
} // namespace anbox
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册