Add basic infrastructure for our window manager

This commit is contained in:
Simon Fels 2016-11-15 08:51:17 +01:00
commit 1e168fd4aa
16 changed files with 508 additions and 132 deletions

View file

@ -95,6 +95,12 @@ set(SOURCES
anbox/graphics/gl_renderer_server.cpp
anbox/graphics/window_creator.cpp
anbox/graphics/density.h
anbox/graphics/rect.cpp
anbox/wm/display.cpp
anbox/wm/task.cpp
anbox/wm/manager.cpp
anbox/wm/window_state.cpp
anbox/input/manager.cpp
anbox/input/device.cpp
@ -116,7 +122,6 @@ set(SOURCES
anbox/bridge/platform_api_skeleton.cpp
anbox/bridge/android_api_stub.cpp
anbox/ubuntu/platform_api_skeleton.cpp
anbox/ubuntu/window_creator.cpp
anbox/ubuntu/window.cpp
anbox/ubuntu/keycode_converter.cpp

View file

@ -16,17 +16,68 @@
*/
#include "anbox/bridge/platform_api_skeleton.h"
#include "anbox/wm/manager.h"
#include "anbox/wm/window_state.h"
#include "anbox/logger.h"
#include "anbox_bridge.pb.h"
namespace anbox {
namespace bridge {
PlatformApiSkeleton::PlatformApiSkeleton(const std::shared_ptr<rpc::PendingCallCache> &pending_calls) :
pending_calls_(pending_calls) {
PlatformApiSkeleton::PlatformApiSkeleton(const std::shared_ptr<rpc::PendingCallCache> &pending_calls,
const std::shared_ptr<wm::Manager> &window_manager) :
pending_calls_(pending_calls),
window_manager_(window_manager) {
}
PlatformApiSkeleton::~PlatformApiSkeleton() {
}
void PlatformApiSkeleton::boot_finished(anbox::protobuf::rpc::Void const *request,
anbox::protobuf::rpc::Void *response,
google::protobuf::Closure *done) {
(void) request;
(void) response;
if (on_boot_finished_action_)
on_boot_finished_action_();
done->Run();
}
void PlatformApiSkeleton::update_window_state(anbox::protobuf::bridge::WindowStateUpdate const *request,
anbox::protobuf::rpc::Void *response,
google::protobuf::Closure *done) {
(void) response;
auto convert_window_state = [](const ::anbox::protobuf::bridge::WindowStateUpdate_WindowState &window) {
return wm::WindowState(
wm::Display::Id(window.display_id()),
window.has_surface(),
graphics::Rect(window.frame_left(), window.frame_top(), window.frame_right(), window.frame_bottom()),
window.package_name(),
wm::Task::Id(window.task_id()));
};
wm::WindowState::List updated;
for (int n = 0; n < request->windows_size(); n++) {
const auto window = request->windows(n);
updated.push_back(convert_window_state(window));
}
wm::WindowState::List removed;
for (int n = 0; n < request->removed_windows_size(); n++) {
const auto window = request->removed_windows(n);
updated.push_back(convert_window_state(window));
}
window_manager_->apply_window_state_update(updated, removed);
done->Run();
}
void PlatformApiSkeleton::on_boot_finished(const std::function<void()> &action) {
on_boot_finished_action_ = action;
}
} // namespace bridge
} // namespace anbox

View file

@ -39,22 +39,30 @@ class WindowStateUpdate;
namespace rpc {
class PendingCallCache;
} // namespace rpc
namespace wm {
class Manager;
} // namespace wm
namespace bridge {
class PlatformApiSkeleton {
public:
PlatformApiSkeleton(const std::shared_ptr<rpc::PendingCallCache> &pending_calls);
PlatformApiSkeleton(const std::shared_ptr<rpc::PendingCallCache> &pending_calls,
const std::shared_ptr<wm::Manager> &window_manager);
virtual ~PlatformApiSkeleton();
virtual void boot_finished(anbox::protobuf::rpc::Void const *request,
anbox::protobuf::rpc::Void *response,
google::protobuf::Closure *done) = 0;
void boot_finished(anbox::protobuf::rpc::Void const *request,
anbox::protobuf::rpc::Void *response,
google::protobuf::Closure *done);
virtual void update_window_state(anbox::protobuf::bridge::WindowStateUpdate const *request,
anbox::protobuf::rpc::Void *response,
google::protobuf::Closure *done) = 0;
void update_window_state(anbox::protobuf::bridge::WindowStateUpdate const *request,
anbox::protobuf::rpc::Void *response,
google::protobuf::Closure *done);
void on_boot_finished(const std::function<void()> &action);
private:
std::shared_ptr<rpc::PendingCallCache> pending_calls_;
std::shared_ptr<wm::Manager> window_manager_;
std::function<void()> on_boot_finished_action_;
};
} // namespace bridge
} // namespace anbox

View file

@ -32,10 +32,11 @@
#include "anbox/rpc/channel.h"
#include "anbox/bridge/platform_message_processor.h"
#include "anbox/bridge/android_api_stub.h"
#include "anbox/ubuntu/platform_api_skeleton.h"
#include "anbox/bridge/platform_api_skeleton.h"
#include "anbox/ubuntu/window_creator.h"
#include "anbox/dbus/skeleton/service.h"
#include "anbox/container/client.h"
#include "anbox/wm/manager.h"
#include <sys/prctl.h>
@ -88,6 +89,8 @@ anbox::cmds::Run::Run(const BusFactory& bus_factory)
auto input_manager = std::make_shared<input::Manager>(rt);
auto window_manager = std::make_shared<wm::Manager>();
auto window_creator = std::make_shared<ubuntu::WindowCreator>(input_manager);
auto renderer = std::make_shared<graphics::GLRendererServer>(window_creator);
renderer->start();
@ -123,7 +126,7 @@ anbox::cmds::Run::Run(const BusFactory& bus_factory)
// more than one one day we need proper dispatching to the right one.
android_api_stub->set_rpc_channel(rpc_channel);
auto server = std::make_shared<ubuntu::PlatformApiSekeleton>(pending_calls);
auto server = std::make_shared<bridge::PlatformApiSkeleton>(pending_calls, window_manager);
server->on_boot_finished([&]() {
dispatcher->dispatch([&]() {
// FIXME make this configurable or once we have a bridge let the host

View file

@ -0,0 +1,25 @@
/*
* 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/rect.h"
namespace anbox {
namespace graphics {
const Rect Rect::Invalid{-1,-1,-1,-1};
const Rect Rect::Empty{0,0,0,0};
} // namespace graphics
} // namespace anbox

101
src/anbox/graphics/rect.h Normal file
View file

@ -0,0 +1,101 @@
/*
* 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_RECT_H_
#define ANBOX_GRAPHICS_RECT_H_
#include <cstdint>
namespace anbox {
namespace graphics {
class Rect {
public:
static const Rect Invalid;
static const Rect Empty;
inline Rect() : Rect(Empty) {}
inline Rect(const std::int32_t &left,
const std::int32_t &top,
const std::int32_t &right,
const std::int32_t &bottom) :
left_(left),
top_(top),
right_(right),
bottom_(bottom) {
}
inline Rect(const std::int32_t &width, const std::int32_t &height) :
left_(0),
top_(0),
right_(width),
bottom_(height) {
}
inline void clear() {
left_ = top_ = right_ = bottom_ = 0;
}
inline bool valid() const {
return width() >= 0 && height() >= 0;
}
inline std::int32_t width() const {
return right_ - left_;
}
inline std::int32_t height() const {
return bottom_ - top_;
}
inline std::int32_t left() const {
return left_;
}
inline std::int32_t top() const {
return top_;
}
inline std::int32_t right() const {
return right_;
}
inline std::int32_t bottom() const {
return bottom_;
}
inline bool operator == (const Rect &rhs) const {
return (left_ == rhs.left() &&
top_ == rhs.top() &&
right_ == rhs.right() &&
bottom_ == rhs.bottom());
}
inline bool operator != (const Rect &rhs) const {
return !operator == (rhs);
}
private:
std::int32_t left_;
std::int32_t top_;
std::int32_t right_;
std::int32_t bottom_;
};
} // namespace graphics
} // namespace anbox
#endif

View file

@ -1,64 +0,0 @@
/*
* 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/ubuntu/platform_api_skeleton.h"
#include "anbox/common/dispatcher.h"
#include "anbox/bridge/android_api_stub.h"
#include "anbox/rpc/pending_call_cache.h"
#include "anbox/logger.h"
#include "anbox_rpc.pb.h"
#include "anbox_bridge.pb.h"
namespace anbox {
namespace ubuntu {
PlatformApiSekeleton::PlatformApiSekeleton(const std::shared_ptr<rpc::PendingCallCache> &pending_calls) :
bridge::PlatformApiSkeleton(pending_calls) {
}
PlatformApiSekeleton::~PlatformApiSekeleton() {
}
void PlatformApiSekeleton::boot_finished(anbox::protobuf::rpc::Void const *request,
anbox::protobuf::rpc::Void *response,
google::protobuf::Closure *done) {
(void) request;
(void) response;
if (on_boot_finished_action_)
on_boot_finished_action_();
done->Run();
}
void PlatformApiSekeleton::update_window_state(anbox::protobuf::bridge::WindowStateUpdate const *request,
anbox::protobuf::rpc::Void *response,
google::protobuf::Closure *done) {
(void) request;
(void) response;
DEBUG("");
done->Run();
}
void PlatformApiSekeleton::on_boot_finished(const std::function<void()> &action) {
on_boot_finished_action_ = action;
}
} // namespace ubuntu
} // namespace anbox

View file

@ -1,56 +0,0 @@
/*
* 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_UBUNTU_PLATFORM_SERVER_H_
#define ANBOX_UBUNTU_PLATFORM_SERVER_H_
#include "anbox/bridge/platform_api_skeleton.h"
namespace anbox {
namespace common {
class Dispatcher;
} // namespace common
namespace bridge {
class AndroidApiStub;
class WindowStateUpdate;
} // namespace bridge
namespace rpc {
class PendingCallCache;
} // namespace rpc;
namespace ubuntu {
class PlatformApiSekeleton : public bridge::PlatformApiSkeleton {
public:
PlatformApiSekeleton(const std::shared_ptr<rpc::PendingCallCache> &pending_calls);
virtual ~PlatformApiSekeleton();
void boot_finished(anbox::protobuf::rpc::Void const *request,
anbox::protobuf::rpc::Void *response,
google::protobuf::Closure *done) override;
void update_window_state(anbox::protobuf::bridge::WindowStateUpdate const *request,
anbox::protobuf::rpc::Void *response,
google::protobuf::Closure *done) override;
void on_boot_finished(const std::function<void()> &action);
private:
std::function<void()> on_boot_finished_action_;
};
} // namespace bridge
} // namespace anbox
#endif

25
src/anbox/wm/display.cpp Normal file
View file

@ -0,0 +1,25 @@
/*
* 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/wm/display.h"
namespace anbox {
namespace wm {
Display::Id Display::Invalid = -1;
Display::Id Display::Default = 0;
} // namespace wm
} // namespace anbox

38
src/anbox/wm/display.h Normal file
View file

@ -0,0 +1,38 @@
/*
* 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_WM_DISPLAY_H_
#define ANBOX_WM_DISPLAY_H_
#include <cstdint>
namespace anbox {
namespace wm {
class Display {
public:
typedef std::int32_t Id;
static Id Invalid;
static Id Default;
Display() = delete;
Display(const Display&) = delete;
};
} // namespace wm
} // namespace anbox
#endif

37
src/anbox/wm/manager.cpp Normal file
View file

@ -0,0 +1,37 @@
/*
* 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/wm/manager.h"
#include "anbox/logger.h"
namespace anbox {
namespace wm {
Manager::Manager() {
}
Manager::~Manager() {
}
void Manager::apply_window_state_update(const WindowState::List &updated,
const WindowState::List &removed) {
(void) updated;
(void) removed;
DEBUG("updated %d removed %d", updated.size(), removed.size());
}
} // namespace wm
} // namespace anbox

38
src/anbox/wm/manager.h Normal file
View file

@ -0,0 +1,38 @@
/*
* 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_WM_MANAGER_H_
#define ANBOX_WM_MANAGER_H_
#include "anbox/wm/window_state.h"
namespace anbox {
namespace wm {
class Manager {
public:
Manager();
~Manager();
void apply_window_state_update(const WindowState::List &updated,
const WindowState::List &removed);
private:
};
} // namespace wm
} // namespace anbox
#endif

24
src/anbox/wm/task.cpp Normal file
View file

@ -0,0 +1,24 @@
/*
* 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/wm/task.h"
namespace anbox {
namespace wm {
Task::Id Task::Invalid = -1;
} // namespace wm
} // namespace anbox

37
src/anbox/wm/task.h Normal file
View file

@ -0,0 +1,37 @@
/*
* 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_WM_TASK_H_
#define ANBOX_WM_TASK_H_
#include <cstdint>
namespace anbox {
namespace wm {
class Task {
public:
typedef std::int32_t Id;
static Id Invalid;
Task() = delete;
Task(const Task&) = delete;
};
} // namespace wm
} // namespace anbox
#endif

View file

@ -0,0 +1,45 @@
/*
* 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/wm/window_state.h"
namespace anbox {
namespace wm {
WindowState::WindowState() :
display_(Display::Invalid),
has_surface_(false),
frame_(graphics::Rect::Invalid),
package_name_(""),
task_(Task::Invalid) {
}
WindowState::WindowState(const Display::Id &display,
bool has_surface,
const graphics::Rect &frame,
const std::string &package_name,
const Task::Id &task) :
display_(display),
has_surface_(has_surface),
frame_(frame),
package_name_(package_name),
task_(task) {
}
WindowState::~WindowState() {
}
} // namespace wm
} // namespace anbox

View file

@ -0,0 +1,59 @@
/*
* 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_WM_WINDOW_STATE_H_
#define ANBOX_WM_WINDOW_STATE_H_
#include "anbox/graphics/rect.h"
#include "anbox/wm/display.h"
#include "anbox/wm/task.h"
#include <vector>
#include <string>
namespace anbox {
namespace wm {
class WindowState {
public:
typedef std::vector<WindowState> List;
WindowState();
WindowState(const Display::Id &display,
bool has_surface,
const graphics::Rect &frame,
const std::string &package_name,
const Task::Id &task);
~WindowState();
Display::Id display() const { return display_; }
bool has_surface() const { return has_surface_; }
graphics::Rect frame() const { return frame_; }
std::string package_name() const { return package_name_; }
Task::Id task() const { return task_; }
private:
Display::Id display_;
bool has_surface_;
graphics::Rect frame_;
std::string package_name_;
Task::Id task_;
};
} // namespace wm
} // namespace anbox
#endif