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

Move sdl platform into anbox/platform/sdl

上级 db7d18d0
......@@ -168,6 +168,11 @@ set(SOURCES
anbox/platform/null/platform.cpp
anbox/platform/sdl/window.cpp
anbox/platform/sdl/keycode_converter.cpp
anbox/platform/sdl/platform.cpp
anbox/platform/sdl/audio_sink.cpp
anbox/input/manager.cpp
anbox/input/device.cpp
......@@ -188,11 +193,6 @@ set(SOURCES
anbox/bridge/platform_api_skeleton.cpp
anbox/bridge/android_api_stub.cpp
anbox/ubuntu/window.cpp
anbox/ubuntu/keycode_converter.cpp
anbox/ubuntu/platform_policy.cpp
anbox/ubuntu/audio_sink.cpp
anbox/dbus/interface.h
anbox/dbus/codecs.h
anbox/dbus/skeleton/service.cpp
......
......@@ -45,7 +45,7 @@ std::istream& operator>>(std::istream& in, anbox::graphics::GLRendererServer::Co
#include "anbox/rpc/channel.h"
#include "anbox/rpc/connection_creator.h"
#include "anbox/runtime.h"
#include "anbox/ubuntu/platform_policy.h"
#include "anbox/platform/base_platform.h"
#include "anbox/wm/multi_window_manager.h"
#include "anbox/wm/single_window_manager.h"
......@@ -176,7 +176,12 @@ anbox::cmds::SessionManager::SessionManager(const BusFactory &bus_factory)
if (single_window_)
display_frame = window_size_;
auto platform = std::make_shared<ubuntu::PlatformPolicy>(input_manager, display_frame, single_window_);
auto platform = platform::create(utils::get_env_value("ANBOX_PLATFORM", "sdl"),
input_manager,
display_frame,
single_window_);
if (!platform)
return EXIT_FAILURE;
auto app_db = std::make_shared<application::Database>();
......
......@@ -17,14 +17,21 @@
#include "anbox/platform/base_platform.h"
#include "anbox/platform/null/platform.h"
#include "anbox/platform/sdl/platform.h"
#include "anbox/logger.h"
namespace anbox {
namespace platform {
std::shared_ptr<BasePlatform> create(const std::string &name) {
std::shared_ptr<BasePlatform> create(const std::string &name,
const std::shared_ptr<input::Manager> &input_manager,
const graphics::Rect &display_frame,
bool single_window) {
if (name.empty())
return std::make_shared<NullPlatform>();
if (name == "sdl")
return std::make_shared<sdl::Platform>(input_manager, display_frame, single_window);
WARNING("Unsupported platfrom '%s'", name);
return nullptr;
......
......@@ -23,6 +23,8 @@
#include <memory>
class Renderer;
namespace anbox {
namespace audio {
class Sink;
......@@ -30,7 +32,11 @@ class Source;
} // namespace audio
namespace wm {
class Window;
class Manager;
} // namespace wm
namespace input {
class Manager;
} // namespace input
namespace platform {
class BasePlatform {
public:
......@@ -47,9 +53,15 @@ class BasePlatform {
virtual std::shared_ptr<audio::Sink> create_audio_sink() = 0;
virtual std::shared_ptr<audio::Source> create_audio_source() = 0;
virtual void set_renderer(const std::shared_ptr<Renderer> &renderer) = 0;
virtual void set_window_manager(const std::shared_ptr<wm::Manager> &window_manager) = 0;
};
std::shared_ptr<BasePlatform> create(const std::string &name = "");
} // namespace wm
std::shared_ptr<BasePlatform> create(const std::string &name = "",
const std::shared_ptr<input::Manager> &input_manager = nullptr,
const graphics::Rect &display_frame = graphics::Rect::Invalid,
bool single_window = false);
} // namespace platform
} // namespace anbox
#endif
......@@ -57,5 +57,15 @@ std::shared_ptr<audio::Source> NullPlatform::create_audio_source() {
ERROR("Not implemented");
return nullptr;
}
void NullPlatform::set_renderer(const std::shared_ptr<Renderer> &renderer) {
(void) renderer;
ERROR("Not implemented");
}
void NullPlatform::set_window_manager(const std::shared_ptr<wm::Manager> &window_manager) {
(void) window_manager;
ERROR("Not implemented");
}
} // namespace wm
} // namespace anbox
......@@ -33,6 +33,8 @@ class NullPlatform : public BasePlatform {
ClipboardData get_clipboard_data() override;
std::shared_ptr<audio::Sink> create_audio_sink() override;
std::shared_ptr<audio::Source> create_audio_source() override;
void set_renderer(const std::shared_ptr<Renderer> &renderer) override;
void set_window_manager(const std::shared_ptr<wm::Manager> &window_manager) override;
};
} // namespace wm
} // namespace anbox
......
......@@ -15,7 +15,7 @@
*
*/
#include "anbox/ubuntu/audio_sink.h"
#include "anbox/platform/sdl/audio_sink.h"
#include "anbox/logger.h"
#include <stdexcept>
......@@ -27,7 +27,8 @@ const constexpr size_t max_queue_size{16};
}
namespace anbox {
namespace ubuntu {
namespace platform {
namespace sdl {
AudioSink::AudioSink() :
device_id_(0),
queue_(max_queue_size) {
......@@ -113,5 +114,6 @@ void AudioSink::write_data(const std::vector<std::uint8_t> &data) {
graphics::Buffer buffer{data.data(), data.data() + data.size()};
queue_.push_locked(std::move(buffer), l);
}
} // namespace ubuntu
} // namespace sdl
} // namespace platform
} // namespace anbox
......@@ -15,8 +15,8 @@
*
*/
#ifndef ANBOX_UBUNTU_AUDIO_SINK_H_
#define ANBOX_UBUNTU_AUDIO_SINK_H_
#ifndef ANBOX_PLATFORM_SDL_AUDIO_SINK_H_
#define ANBOX_PLATFORM_SDL_AUDIO_SINK_H_
#include "anbox/audio/sink.h"
#include "anbox/graphics/buffer_queue.h"
......@@ -26,7 +26,8 @@
#include <thread>
namespace anbox {
namespace ubuntu {
namespace platform {
namespace sdl {
class AudioSink : public audio::Sink {
public:
AudioSink();
......@@ -48,7 +49,8 @@ class AudioSink : public audio::Sink {
graphics::Buffer read_buffer_;
size_t read_buffer_left_ = 0;
};
} // namespace ubuntu
} // namespace sdl
} // namespace platform
} // namespace anbox
#endif
......@@ -16,13 +16,14 @@
*/
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wswitch-default"
#include "anbox/ubuntu/keycode_converter.h"
#include "anbox/platform/sdl/keycode_converter.h"
#pragma GCC diagnostic pop
#include <linux/input.h>
namespace anbox {
namespace ubuntu {
namespace platform {
namespace sdl {
std::uint16_t KeycodeConverter::convert(const SDL_Scancode &scan_code) {
for (std::uint16_t n = 0; n < code_map.size(); n++) {
if (code_map[n] == scan_code) return n;
......@@ -289,5 +290,6 @@ const std::array<SDL_Scancode, 249> KeycodeConverter::code_map = {{
*/
SDL_SCANCODE_UNKNOWN /* KEY_MICMUTE 248 Mute / unmute the microphone */
}};
} // namespace ubuntu
} // namespace anbox
} // namespace sdl
} // namespace platform
} // namespace anbox
......@@ -15,8 +15,8 @@
*
*/
#ifndef ANBOX_UBUNTU_KEYCODE_CONVERTER_H_
#define ANBOX_UBUNTU_KEYCODE_CONVERTER_H_
#ifndef ANBOX_PLATFORM_SDL_KEYCODE_CONVERTER_H_
#define ANBOX_PLATFORM_SDL_KEYCODE_CONVERTER_H_
#include <SDL_scancode.h>
......@@ -25,7 +25,8 @@
#include <array>
namespace anbox {
namespace ubuntu {
namespace platform {
namespace sdl {
class KeycodeConverter {
public:
static std::uint16_t convert(const SDL_Scancode &scan_code);
......@@ -33,7 +34,8 @@ class KeycodeConverter {
private:
static const std::array<SDL_Scancode, 249> code_map;
};
} // namespace ubuntu
} // namespace anbox
} // namespace sdl
} // namespace platform
} // namespace anbox
#endif
......@@ -14,7 +14,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "anbox/ubuntu/mir_display_connection.h"
#include "anbox/platform/sdlmir_display_connection.h"
#include "anbox/logger.h"
#include <boost/throw_exception.hpp>
......@@ -43,7 +43,7 @@ static const MirDisplayOutput *find_active_output(
}
namespace anbox {
namespace ubuntu {
namespace sdl {
MirDisplayConnection::MirDisplayConnection()
: connection_(nullptr),
output_id_(-1),
......@@ -119,5 +119,5 @@ int MirDisplayConnection::vertical_resolution() const {
int MirDisplayConnection::horizontal_resolution() const {
return horizontal_resolution_;
}
} // namespace ubuntu
} // namespace sdl
} // namespace anbox
......@@ -15,8 +15,8 @@
*
*/
#ifndef ANBOX_UBUNTU_MIR_DISPLAY_CONNECTION_H_
#define ANBOX_UBUNTU_MIR_DISPLAY_CONNECTION_H_
#ifndef ANBOX_PLATFORM_SDL_MIR_DISPLAY_CONNECTION_H_
#define ANBOX_PLATFORM_SDL_MIR_DISPLAY_CONNECTION_H_
#define MIR_EGL_PLATFORM
......@@ -25,7 +25,7 @@
#include <EGL/egl.h>
namespace anbox {
namespace ubuntu {
namespace sdl {
class MirDisplayConnection {
public:
MirDisplayConnection();
......@@ -46,7 +46,7 @@ class MirDisplayConnection {
int vertical_resolution_;
int horizontal_resolution_;
};
} // namespace ubuntu
} // namespace sdl
} // namespace anbox
#endif
......@@ -17,13 +17,13 @@
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wswitch-default"
#include "anbox/ubuntu/platform_policy.h"
#include "anbox/platform/sdl/platform.h"
#include "anbox/input/device.h"
#include "anbox/input/manager.h"
#include "anbox/logger.h"
#include "anbox/ubuntu/keycode_converter.h"
#include "anbox/ubuntu/window.h"
#include "anbox/ubuntu/audio_sink.h"
#include "anbox/platform/sdl/keycode_converter.h"
#include "anbox/platform/sdl/window.h"
#include "anbox/platform/sdl/audio_sink.h"
#include "anbox/wm/manager.h"
#include <boost/throw_exception.hpp>
......@@ -33,8 +33,9 @@
#pragma GCC diagnostic pop
namespace anbox {
namespace ubuntu {
PlatformPolicy::PlatformPolicy(
namespace platform {
namespace sdl {
Platform::Platform(
const std::shared_ptr<input::Manager> &input_manager,
const graphics::Rect &static_display_frame,
bool single_window)
......@@ -92,25 +93,25 @@ PlatformPolicy::PlatformPolicy(
keyboard_->set_key_bit(BTN_MISC);
keyboard_->set_key_bit(KEY_OK);
event_thread_ = std::thread(&PlatformPolicy::process_events, this);
event_thread_ = std::thread(&Platform::process_events, this);
}
PlatformPolicy::~PlatformPolicy() {
Platform::~Platform() {
if (event_thread_running_) {
event_thread_running_ = false;
event_thread_.join();
}
}
void PlatformPolicy::set_renderer(const std::shared_ptr<Renderer> &renderer) {
void Platform::set_renderer(const std::shared_ptr<Renderer> &renderer) {
renderer_ = renderer;
}
void PlatformPolicy::set_window_manager(const std::shared_ptr<wm::Manager> &window_manager) {
void Platform::set_window_manager(const std::shared_ptr<wm::Manager> &window_manager) {
window_manager_ = window_manager;
}
void PlatformPolicy::process_events() {
void Platform::process_events() {
event_thread_running_ = true;
while (event_thread_running_) {
......@@ -144,7 +145,7 @@ void PlatformPolicy::process_events() {
}
}
void PlatformPolicy::process_input_event(const SDL_Event &event) {
void Platform::process_input_event(const SDL_Event &event) {
std::vector<input::Event> mouse_events;
std::vector<input::Event> keyboard_events;
......@@ -216,12 +217,12 @@ void PlatformPolicy::process_input_event(const SDL_Event &event) {
if (keyboard_events.size() > 0) keyboard_->send_events(keyboard_events);
}
Window::Id PlatformPolicy::next_window_id() {
Window::Id Platform::next_window_id() {
static Window::Id next_id = 0;
return next_id++;
}
std::shared_ptr<wm::Window> PlatformPolicy::create_window(
std::shared_ptr<wm::Window> Platform::create_window(
const anbox::wm::Task::Id &task, const anbox::graphics::Rect &frame, const std::string &title) {
if (!renderer_) {
ERROR("Can't create window without a renderer set");
......@@ -234,7 +235,7 @@ std::shared_ptr<wm::Window> PlatformPolicy::create_window(
return w;
}
void PlatformPolicy::window_deleted(const Window::Id &id) {
void Platform::window_deleted(const Window::Id &id) {
auto w = windows_.find(id);
if (w == windows_.end()) {
WARNING("Got window removed event for unknown window (id %d)", id);
......@@ -245,7 +246,7 @@ void PlatformPolicy::window_deleted(const Window::Id &id) {
windows_.erase(w);
}
void PlatformPolicy::window_wants_focus(const Window::Id &id) {
void Platform::window_wants_focus(const Window::Id &id) {
auto w = windows_.find(id);
if (w == windows_.end()) return;
......@@ -253,7 +254,7 @@ void PlatformPolicy::window_wants_focus(const Window::Id &id) {
window_manager_->set_focused_task(window->task());
}
void PlatformPolicy::window_moved(const Window::Id &id, const std::int32_t &x,
void Platform::window_moved(const Window::Id &id, const std::int32_t &x,
const std::int32_t &y) {
auto w = windows_.find(id);
if (w == windows_.end()) return;
......@@ -266,7 +267,7 @@ void PlatformPolicy::window_moved(const Window::Id &id, const std::int32_t &x,
}
}
void PlatformPolicy::window_resized(const Window::Id &id,
void Platform::window_resized(const Window::Id &id,
const std::int32_t &width,
const std::int32_t &height) {
auto w = windows_.find(id);
......@@ -284,13 +285,13 @@ void PlatformPolicy::window_resized(const Window::Id &id,
}
}
void PlatformPolicy::set_clipboard_data(const ClipboardData &data) {
void Platform::set_clipboard_data(const ClipboardData &data) {
if (data.text.empty())
return;
SDL_SetClipboardText(data.text.c_str());
}
PlatformPolicy::ClipboardData PlatformPolicy::get_clipboard_data() {
Platform::ClipboardData Platform::get_clipboard_data() {
if (!SDL_HasClipboardText())
return ClipboardData{};
......@@ -303,13 +304,14 @@ PlatformPolicy::ClipboardData PlatformPolicy::get_clipboard_data() {
return data;
}
std::shared_ptr<audio::Sink> PlatformPolicy::create_audio_sink() {
std::shared_ptr<audio::Sink> Platform::create_audio_sink() {
return std::make_shared<AudioSink>();
}
std::shared_ptr<audio::Source> PlatformPolicy::create_audio_source() {
std::shared_ptr<audio::Source> Platform::create_audio_source() {
ERROR("Not implemented");
return nullptr;
}
} // namespace wm
} // namespace anbox
} // namespace sdl
} // namespace platform
} // namespace anbox
......@@ -15,10 +15,10 @@
*
*/
#ifndef ANBOX_UBUNTU_PLATFORM_POLICY_H_
#define ANBOX_UBUNTU_PLATFORM_POLICY_H_
#ifndef ANBOX_PLATFORM_SDL_PLATFORM_H_
#define ANBOX_PLATFORM_SDL_PLATFORM_H_
#include "anbox/ubuntu/window.h"
#include "anbox/platform/sdl/window.h"
#include "anbox/platform/base_platform.h"
#include "anbox/graphics/emugl/DisplayManager.h"
......@@ -38,15 +38,16 @@ class Manager;
namespace wm {
class Manager;
} // namespace wm
namespace ubuntu {
class PlatformPolicy : public std::enable_shared_from_this<PlatformPolicy>,
namespace platform {
namespace sdl {
class Platform : public std::enable_shared_from_this<Platform>,
public platform::BasePlatform,
public Window::Observer {
public:
PlatformPolicy(const std::shared_ptr<input::Manager> &input_manager,
Platform(const std::shared_ptr<input::Manager> &input_manager,
const graphics::Rect &static_display_frame = graphics::Rect::Invalid,
bool single_window = false);
~PlatformPolicy();
~Platform();
std::shared_ptr<wm::Window> create_window(
const anbox::wm::Task::Id &task,
......@@ -60,8 +61,8 @@ class PlatformPolicy : public std::enable_shared_from_this<PlatformPolicy>,
void window_resized(const Window::Id &id, const std::int32_t &width,
const std::int32_t &height) override;
void set_renderer(const std::shared_ptr<Renderer> &renderer);
void set_window_manager(const std::shared_ptr<wm::Manager> &window_manager);
void set_renderer(const std::shared_ptr<Renderer> &renderer) override;
void set_window_manager(const std::shared_ptr<wm::Manager> &window_manager) override;
void set_clipboard_data(const ClipboardData &data) override;
ClipboardData get_clipboard_data() override;
......@@ -89,7 +90,8 @@ class PlatformPolicy : public std::enable_shared_from_this<PlatformPolicy>,
bool window_size_immutable_ = false;
bool single_window_ = false;
};
} // namespace wm
} // namespace anbox
} // namespace sdl
} // namespace platform
} // namespace anbox
#endif
......@@ -17,7 +17,7 @@
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wswitch-default"
#include "anbox/ubuntu/window.h"
#include "anbox/platform/sdl/window.h"
#include "anbox/logger.h"
#include "anbox/wm/window_state.h"
......@@ -31,7 +31,8 @@
#pragma GCC diagnostic pop
namespace anbox {
namespace ubuntu {
namespace platform {
namespace sdl {
Window::Id Window::Invalid{-1};
Window::Observer::~Observer() {}
......@@ -129,5 +130,6 @@ EGLNativeWindowType Window::native_handle() const { return native_window_; }
Window::Id Window::id() const { return id_; }
std::uint32_t Window::window_id() const { return SDL_GetWindowID(window_); }
} // namespace bridge
} // namespace anbox
} // namespace sdl
} // namespace platform
} // namespace anbox
......@@ -15,8 +15,8 @@
*
*/
#ifndef ANBOX_UBUNTU_WINDOW_H_
#define ANBOX_UBUNTU_WINDOW_H_
#ifndef ANBOX_PLATFORM_SDL_WINDOW_H_
#define ANBOX_PLATFORM_SDL_WINDOW_H_
#include "anbox/wm/window.h"
......@@ -30,7 +30,8 @@
class Renderer;
namespace anbox {
namespace ubuntu {
namespace platform {
namespace sdl {
class Window : public std::enable_shared_from_this<Window>, public wm::Window {
public:
typedef std::int32_t Id;
......@@ -68,7 +69,8 @@ class Window : public std::enable_shared_from_this<Window>, public wm::Window {
EGLNativeWindowType native_window_;
SDL_Window *window_;
};
} // namespace bridge
} // namespace anbox
} // namespace sdl
} // namespace platform
} // namespace anbox
#endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册