From 6575e49613e0795f7206d154f1fe49d205b632ac Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Fri, 10 Jul 2020 07:37:59 +0900 Subject: [PATCH 01/16] DSCompositor: change _onPrepareCanvas to _onInitialized Change-Id: Id76ac816ca4fd159bb43ddf212b21b7969714c91 --- samples/exampleCompositor.cpp | 2 +- src/DSCompositor/DSCompositor.h | 2 +- tests/DSCompositor-test.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/exampleCompositor.cpp b/samples/exampleCompositor.cpp index 6fd2a2e..a7650ff 100644 --- a/samples/exampleCompositor.cpp +++ b/samples/exampleCompositor.cpp @@ -53,7 +53,7 @@ public: virtual ~MyCompositor() {} - void _onPrepareCanvas() override + void _onInitialized() override { int width = __displayArea->getWidth(); int height = __displayArea->getHeight(); diff --git a/src/DSCompositor/DSCompositor.h b/src/DSCompositor/DSCompositor.h index 4d9ae43..c85fd81 100644 --- a/src/DSCompositor/DSCompositor.h +++ b/src/DSCompositor/DSCompositor.h @@ -23,7 +23,7 @@ public: bool quit(); protected: - virtual void _onPrepareCanvas() = 0; + virtual void _onInitialized() = 0; virtual void _onOutputAdded(std::shared_ptr output) = 0; virtual void _onOutputRemoved(std::shared_ptr output) = 0; virtual void _onInputAdded(std::shared_ptr input) = 0; diff --git a/tests/DSCompositor-test.cpp b/tests/DSCompositor-test.cpp index 15bf9fc..6ef70cf 100644 --- a/tests/DSCompositor-test.cpp +++ b/tests/DSCompositor-test.cpp @@ -24,7 +24,7 @@ public: MockCompositor() {} ~MockCompositor() {} - void _onPrepareCanvas() override + void _onInitialized() override {} void _onOutputAdded(std::shared_ptr output) override -- 2.7.4 From 77e7fd5933264cf3f31ce8da1d90a9d3fef46039 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Fri, 10 Jul 2020 08:19:36 +0900 Subject: [PATCH 02/16] DSCompositor: initialize the Display Device with TDM - initialize the Display Device with TDM - get the Device Ouptuts form Display Device and call the _onOutputAdded() at run() method - After that, call the _onInitialization at run() method Change-Id: I783764547f11cebbbd565f5815bc69163a041c06 --- src/DSCompositor/DSCompositor.cpp | 32 +++++++++++++++++++++++++++++++- src/DSCompositor/DSCompositorPrivate.h | 5 +++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/DSCompositor/DSCompositor.cpp b/src/DSCompositor/DSCompositor.cpp index 8a54e48..6bbbfda 100644 --- a/src/DSCompositor/DSCompositor.cpp +++ b/src/DSCompositor/DSCompositor.cpp @@ -1,6 +1,8 @@ #include "DSCompositor.h" #include "DSCompositorPrivate.h" #include "DSDebugLog.h" +#include "DSDisplayDeviceTDMImpl.h" +#include "DSOutputImpl.h" #include namespace display_server @@ -39,9 +41,12 @@ bool DSCompositor::quit() DSCompositorPrivate::DSCompositorPrivate(DSCompositor *p_ptr) : DSObjectPrivate(p_ptr), - __p_ptr(p_ptr) + __p_ptr(p_ptr), + __displayDevice(nullptr) + { __eventLoop = std::make_unique(); + __displayDevice = std::make_unique(); } DSCompositorPrivate::~DSCompositorPrivate() @@ -49,6 +54,10 @@ DSCompositorPrivate::~DSCompositorPrivate() bool DSCompositorPrivate::run() { + DS_GET_PUB(DSCompositor); + + __initializeOutputs(); + pub->_onInitialized(); if (!__eventLoop->run()) { DSLOG_ERR("Compositor", "__eventLoop->run() fails."); return false; @@ -67,4 +76,25 @@ bool DSCompositorPrivate::quit() return true; } +void DSCompositorPrivate::__initializeOutputs() +{ + DS_GET_PUB(DSCompositor); + + auto displayDeviceOutputList = __displayDevice->getOutputList(); + if (displayDeviceOutputList.empty()) { + DSLOG_INF("Compositor", "displayDeviceOutputList.empty()."); + return; + } + + // make a IDSOutput only when the IDSDisplayDeviceOutput is connected and + // then call the _onOutputAdded() + for (auto displayDeviceOutput : displayDeviceOutputList) { + if (displayDeviceOutput->getConnectState() == IDSDisplayDeviceOutput::STATE_DISCONNECTED) + continue; + + __outputList.push_back(std::make_shared(displayDeviceOutput)); + pub->_onOutputAdded(__outputList.back()); + } +} + } // namespace display_server \ No newline at end of file diff --git a/src/DSCompositor/DSCompositorPrivate.h b/src/DSCompositor/DSCompositorPrivate.h index 797b9cb..e6875d2 100644 --- a/src/DSCompositor/DSCompositorPrivate.h +++ b/src/DSCompositor/DSCompositorPrivate.h @@ -3,6 +3,7 @@ #include "DSCompositor.h" #include "DSEventLoop.h" +#include "IDSDisplayDevice.h" #include namespace display_server @@ -23,6 +24,10 @@ protected: private: std::unique_ptr __eventLoop; + std::unique_ptr __displayDevice; + std::list> __outputList; + + void __initializeOutputs(); }; } -- 2.7.4 From 7ec65c933e63faddd74eb97ed88aae9cd6f7ffae Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Fri, 10 Jul 2020 08:21:19 +0900 Subject: [PATCH 03/16] DSCanvas: initialize RenderEngine with EcoreEvas implemenation Change-Id: I9cf476b148994c94d231ef9c6691fe65a840334e --- src/DSCanvas/DSCanvas.cpp | 24 +++++++++++++++++++++++- src/DSCanvas/DSCanvasPrivate.h | 2 ++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/DSCanvas/DSCanvas.cpp b/src/DSCanvas/DSCanvas.cpp index bc9f066..2552c0e 100644 --- a/src/DSCanvas/DSCanvas.cpp +++ b/src/DSCanvas/DSCanvas.cpp @@ -1,5 +1,7 @@ #include "DSCanvas.h" #include "DSCanvasPrivate.h" +#include "DSOutputImpl.h" +#include "DSRenderEngineEcoreEvasImpl.h" #include "DSDebugLog.h" namespace display_server @@ -36,7 +38,8 @@ DSCanvasPrivate::DSCanvasPrivate(DSCanvas *p_ptr) : DSObjectPrivate(p_ptr), __p_ptr(p_ptr), __policyArea(nullptr), - __displayArea(nullptr) + __displayArea(nullptr), + __RenderEngine(nullptr) {} DSCanvasPrivate::~DSCanvasPrivate() @@ -61,6 +64,25 @@ bool DSCanvasPrivate::attachDisplayArea(std::shared_ptr displayAr return false; } + auto output = displayArea->getOutput(); + if (!output) { + DSLOG_ERR("DSCanvasPrivate", "output is null."); + return false; + } + + auto outputImpl = std::dynamic_pointer_cast(output); // down-casting of std::shared_ptr + auto bufferQueue = outputImpl->getDisplayBufferQueue(); + if (!bufferQueue) { + DSLOG_ERR("DSCanvasPrivate", "bufferQueue is null."); + return false; + } + + __RenderEngine = std::make_shared(bufferQueue); + if (!__RenderEngine) { + DSLOG_ERR("DSCanvasPrivate", "__RenderEngine is null."); + return false; + } + __displayArea = displayArea; return true; diff --git a/src/DSCanvas/DSCanvasPrivate.h b/src/DSCanvas/DSCanvasPrivate.h index bded0a9..faef7e8 100644 --- a/src/DSCanvas/DSCanvasPrivate.h +++ b/src/DSCanvas/DSCanvasPrivate.h @@ -2,6 +2,7 @@ #define __DS_CANVAS_PRIVATE_H__ #include "DSCanvas.h" +#include "IDSRenderEngine.h" namespace display_server { @@ -20,6 +21,7 @@ public: private: std::shared_ptr __policyArea; std::shared_ptr __displayArea; + std::shared_ptr __RenderEngine; }; } -- 2.7.4 From cc145d5263c4877a1554664cb73eeabcd716fd41 Mon Sep 17 00:00:00 2001 From: Sung-Jin Park Date: Thu, 9 Jul 2020 16:11:42 +0900 Subject: [PATCH 04/16] DSWaylandServer: implements DSWaylandCompositor, DSWaylandClient and DSWaylandSeat Change-Id: I706b76ebd3fbb0eba4e9a49285a3985c98144ee6 Signed-off-by: Sung-Jin Park --- src/DSWaylandServer/DSWaylandClient.cpp | 105 ++++++++ src/DSWaylandServer/DSWaylandClient.h | 38 +++ src/DSWaylandServer/DSWaylandClientPrivate.h | 33 +++ src/DSWaylandServer/DSWaylandCompositor.cpp | 310 +++++++++++++++++++++++ src/DSWaylandServer/DSWaylandCompositor.h | 47 ++++ src/DSWaylandServer/DSWaylandCompositorPrivate.h | 93 +++++++ src/DSWaylandServer/DSWaylandSeat.cpp | 78 ++++++ src/DSWaylandServer/DSWaylandSeat.h | 43 ++++ src/DSWaylandServer/DSWaylandSeatPrivate.h | 33 +++ src/meson.build | 9 + tests/DSWaylandClient-test.cpp | 139 ++++++++++ tests/DSWaylandCompositor-test.cpp | 156 ++++++++++++ tests/DSWaylandSeat-test.cpp | 65 +++++ tests/meson.build | 3 + 14 files changed, 1152 insertions(+) create mode 100644 src/DSWaylandServer/DSWaylandClient.cpp create mode 100644 src/DSWaylandServer/DSWaylandClient.h create mode 100644 src/DSWaylandServer/DSWaylandClientPrivate.h create mode 100644 src/DSWaylandServer/DSWaylandCompositor.cpp create mode 100644 src/DSWaylandServer/DSWaylandCompositor.h create mode 100644 src/DSWaylandServer/DSWaylandCompositorPrivate.h create mode 100644 src/DSWaylandServer/DSWaylandSeat.cpp create mode 100644 src/DSWaylandServer/DSWaylandSeat.h create mode 100644 src/DSWaylandServer/DSWaylandSeatPrivate.h create mode 100644 tests/DSWaylandClient-test.cpp create mode 100644 tests/DSWaylandCompositor-test.cpp create mode 100644 tests/DSWaylandSeat-test.cpp diff --git a/src/DSWaylandServer/DSWaylandClient.cpp b/src/DSWaylandServer/DSWaylandClient.cpp new file mode 100644 index 0000000..8b8b231 --- /dev/null +++ b/src/DSWaylandServer/DSWaylandClient.cpp @@ -0,0 +1,105 @@ + +#include "DSWaylandClient.h" +#include "DSWaylandClientPrivate.h" + +#include + +namespace display_server +{ + +/* Begin Private Class Implementation */ +DSWaylandClientPrivate::DSWaylandClientPrivate(DSWaylandCompositor *compositor, DSWaylandClient *client) + : DSObjectPrivate(client), + __p_ptr(client), + __client(nullptr), + __pid(0), + __uid(0), + __gid(0), + __compositor(compositor) +{ +} + +DSWaylandClientPrivate::~DSWaylandClientPrivate() +{ +} + +/* Begin Public Class Implementation */ +DSWaylandClient::DSWaylandClient(DSWaylandCompositor *compositor, wl_client *wlClient) + : DSObject(), + _d_ptr(std::make_unique(compositor, this)) +{ + pid_t pid = 0; + uid_t uid = 0; + gid_t gid = 0; + + DS_GET_PRIV(DSWaylandClient); + + if (wlClient) + { + wl_client_get_credentials(wlClient, &pid, &uid, &gid); + + priv->__pid = pid; + priv->__uid = uid; + priv->__gid = gid; + priv->__client = wlClient; + } + else + { + priv->__pid = 0; + priv->__uid = 0; + priv->__gid = 0; + priv->__client = nullptr; + } + + //TODO : add client destroyed listener + //TODO : call get_compositor()->addClient(this); +} + +DSWaylandClient::~DSWaylandClient() +{ + //TODO : remove client destroy listener link + //TODO : call get_compositor()->removeClient(this); +} + +DSWaylandClient *DSWaylandClient::fromWlClient(wl_client *wlClient) +{ + //TODO get DSWaylandClient * from wlClient and return it + return nullptr; +} + +DSWaylandCompositor *DSWaylandClient::getCompositor() +{ + DS_GET_PRIV(DSWaylandClient); + + return priv->__compositor; +} + +pid_t DSWaylandClient::pid(void) +{ + DS_GET_PRIV(DSWaylandClient); + + return priv->__pid; +} + +uid_t DSWaylandClient::uid(void) +{ + DS_GET_PRIV(DSWaylandClient); + + return priv->__uid; +} + +gid_t DSWaylandClient::gid(void) +{ + DS_GET_PRIV(DSWaylandClient); + + return priv->__gid; +} + +wl_client *DSWaylandClient::wlClient(void) +{ + DS_GET_PRIV(DSWaylandClient); + + return priv->__client; +} + +} diff --git a/src/DSWaylandServer/DSWaylandClient.h b/src/DSWaylandServer/DSWaylandClient.h new file mode 100644 index 0000000..0215f47 --- /dev/null +++ b/src/DSWaylandServer/DSWaylandClient.h @@ -0,0 +1,38 @@ +#ifndef __DS_WAYLAND_CLIENT_H__ +#define __DS_WAYLAND_CLIENT_H__ + +#include "DSCore.h" +#include "DSObject.h" + +struct wl_client; + +namespace display_server +{ + +class DSWaylandClientPrivate; +class DSWaylandCompositor; +class DS_DECL_EXPORT DSWaylandClient : public DSObject +{ + DS_PIMPL_USE_PRIVATE(DSWaylandClient); +public: + DSWaylandClient(DSWaylandCompositor *compositor, wl_client *wlClient); + ~DSWaylandClient() override; + + static DSWaylandClient *fromWlClient(wl_client *wlClient); + DSWaylandCompositor *getCompositor(void); + pid_t pid(void); + uid_t uid(void); + gid_t gid(void); + wl_client *wlClient(void); + + //TODO + +protected: + +private: + +}; + +} + +#endif //__DS_WAYLAND_CLIENT_H__ diff --git a/src/DSWaylandServer/DSWaylandClientPrivate.h b/src/DSWaylandServer/DSWaylandClientPrivate.h new file mode 100644 index 0000000..4228a2a --- /dev/null +++ b/src/DSWaylandServer/DSWaylandClientPrivate.h @@ -0,0 +1,33 @@ +#ifndef __DS_WAYLAND_CLIENT_PRIVATE_H__ +#define __DS_WAYLAND_CLIENT_PRIVATE_H__ + +#include "DSCore.h" +#include "DSObjectPrivate.h" + +namespace display_server +{ + +class DSWaylandCompositor; +class DS_DECL_EXPORT DSWaylandClientPrivate : public DSObjectPrivate +{ + DS_PIMPL_USE_PUBLIC(DSWaylandClient); +public: + DSWaylandClientPrivate(DSWaylandCompositor *compositor, DSWaylandClient *client); + ~DSWaylandClientPrivate() override; + + //TODO : add listener for client destroyed + //TODO + +protected: + +private: + wl_client *__client; + pid_t __pid; + uid_t __uid; + gid_t __gid; + DSWaylandCompositor *__compositor; +}; + +} + +#endif //__DS_WAYLAND_CLIENT_PRIVATE_H__ diff --git a/src/DSWaylandServer/DSWaylandCompositor.cpp b/src/DSWaylandServer/DSWaylandCompositor.cpp new file mode 100644 index 0000000..9832e50 --- /dev/null +++ b/src/DSWaylandServer/DSWaylandCompositor.cpp @@ -0,0 +1,310 @@ +#include "DSWaylandCompositor.h" +#include "DSWaylandCompositorPrivate.h" +#include "DSDebugLog.h" + +namespace display_server +{ + +/* Begin Private Class Implementation */ +DSWaylandCompositorPrivate::DSWaylandCompositorPrivate(DSWaylandCompositor *compositor) + : DSObjectPrivate(compositor), + __p_ptr(compositor), + _created(false), + _socketFD(-1), + _socketName(), + _display(nullptr), + _loop(nullptr), + _socket_fd_handler(nullptr), + _compositor(compositor) +{ + if (!ecore_init()) + { + DSLOG_ERR("DSWaylandCompositor", "ecore_init() fails.\n"); + return; + } + + _display = wl_display_create(); + DS_ASSERT(_display != nullptr); + + //TODO : add listener for client creation using wl_display_add_client_created_listener() + //TODO : leave log (log system needed) + //TODO +} + +DSWaylandCompositorPrivate::~DSWaylandCompositorPrivate() +{ + //TODO : destroy all allocated resources + //TODO : remove listener link (installed for checking client creation) + + _clients.clear(); + _seats.clear(); + _socketName.clear(); + + if (_socket_fd_handler) + { + ecore_main_fd_handler_del(_socket_fd_handler); + ecore_main_fd_handler_prepare_callback_set(_socket_fd_handler, nullptr, nullptr); + _socket_fd_handler = nullptr; + } + + if (_display) + { + wl_display_destroy(_display); + _display = nullptr; + } + + _created = false; + _socketFD = -1; + _loop = nullptr; + _compositor = nullptr; + __p_ptr = nullptr; + + ecore_shutdown(); +} + +void DSWaylandCompositorPrivate::initSocket(std::string sName, std::string sDir) +{ + std::string socketPath = std::move(sDir); + + socketPath.append(1, '/'); + socketPath.append(_socketName); + + (void) socketPath; + + //TODO : set permissions for Owner, Group and Other + //TODO : set Smack attributes for socket + //TODO : set symbolic link for socket +} + +bool DSWaylandCompositorPrivate::initCompositor() +{ + if (!_display) + { + DSLOG_ERR("DSWaylandCompositor", "_display(wl_display) is NULL !\n"); + return false; + } + + //Initialize needed interfaces + //TODO : get/set DSConfig::version("wl_compositor") + wl_compositor::init(_display, 4); + + //TODO : get socketName from DSConfig::socketName() + //TODO : create socket with wl_display_add_socket() if socketName not empty + _socketName = wl_display_add_socket_auto(_display); + + if (_socketName.empty()) + { + DSLOG_ERR("DSWaylandCompositor", "_socketName is empty()\n"); + return false; + } + + initSocket(_socketName, "/run"); + + //TODO : DSConfig::setEnv("WAYLAND_DISPLAY", _socketName); + + //TODO : initialize compositor signals (signals.surface.create/activate/kill) + //ex> implment using DSWaylandSignal class + //wl_signal_init(&cdata->signals.surface.create); + //-> DSWayalndSignal::add("surface_create", wl_notify_func_t *notify or ¬ify_func); + + //TODO : add event dispatcher for wayland socket and other fd(s) + _loop = wl_display_get_event_loop(_display); + + if (!_loop) + { + DSLOG_ERR("DSWaylandCompositor", "_loop is nullptr.\n"); + return false; + } + + _socketFD = wl_event_loop_get_fd(_loop); + + if (0 > _socketFD) + { + DSLOG_ERR("DSWaylandCompositor", "_socketFD is invalid. (_socketFD=%d)\n", _socketFD); + return false; + } + + auto evFlags = ECORE_FD_READ | ECORE_FD_ERROR; + + _socket_fd_handler = ecore_main_fd_handler_add(_socketFD, + static_cast(evFlags), + __readEvents, this, NULL, NULL); + + if (!_socket_fd_handler) + { + DSLOG_ERR("DSWaylandCompositor", "_socket_fd_handler is invalid.\n"); + } + + ecore_main_fd_handler_prepare_callback_set(_socket_fd_handler, + __prepareFunc, this); + + return true; +} + +Eina_Bool DSWaylandCompositorPrivate::__readEvents(void *data, Ecore_Fd_Handler *hdlr) +{ + DSWaylandCompositorPrivate *compPrivate = (DSWaylandCompositorPrivate *) data; + + if (!compPrivate) + { + DSLOG_DBG("DSWaylandCompositor", "compPrivate is invalid.\n"); + return ECORE_CALLBACK_RENEW; + } + + (void) hdlr; + + /* dispatch pending wayland events */ + int ret = wl_event_loop_dispatch(compPrivate->_loop, 0); + + if (ret) + { + DSLOG_ERR("DSWaylandCompositor", "Failed on wl_event_loop_dispatch()\n"); + } + + return ECORE_CALLBACK_RENEW; +} + +void DSWaylandCompositorPrivate::__prepareFunc(void *data, Ecore_Fd_Handler *hdlr) +{ + DSWaylandCompositorPrivate *compPrivate = (DSWaylandCompositorPrivate *) data; + + if (!compPrivate) + { + DSLOG_DBG("DSWaylandCompositor", "compPrivate is invalid.\n"); + return; + } + + (void) hdlr; + + /* flush pending client events */ + wl_display_flush_clients(compPrivate->_display); +} + +void DSWaylandCompositorPrivate::compositor_bind_resource(wl_compositor::Resource *resource) +{ + //TODO : Leave log (pid/uid/gid and process name) + //TODO : Update connected client list (add) +} + +void DSWaylandCompositorPrivate::compositor_destroy_resource(wl_compositor::Resource *resource) +{ + //TODO : Leave log (pid/uid/gid and process name) + //TODO : Update connected client list (remove) +} + +void DSWaylandCompositorPrivate::compositor_create_surface(wl_compositor::Resource *resource, uint32_t id) +{ + //TODO : Create DSWindow here. +} + +void DSWaylandCompositorPrivate::compositor_create_region(wl_compositor::Resource *resource, uint32_t id) +{ + //TODO +} + +/* Begin Public Class Implementation */ +DSWaylandCompositor::DSWaylandCompositor(DSObject *parent) + : DSObject(), + DS_INIT_PRIVATE_PTR(DSWaylandCompositor) +{ + //TODO +} + +DSWaylandCompositor::~DSWaylandCompositor() +{ + //TODO +} + +bool DSWaylandCompositor::create() +{ + DS_GET_PRIV(DSWaylandCompositor); + + bool res = false; + + res = priv->initCompositor(); + if (!res) + { + DSLOG_ERR("DSWaylandCompositor", "Failed on initCompositor ! (res=%d)\n", res); + return false; + } + + priv->_created = true; + return true; +} + +bool DSWaylandCompositor::isCreated() +{ + DS_GET_PRIV(DSWaylandCompositor); + + return priv->_created; +} + +std::string DSWaylandCompositor::socketName() +{ + DS_GET_PRIV(DSWaylandCompositor); + + return priv->_socketName; +} + +struct wl_display *DSWaylandCompositor::display() +{ + DS_GET_PRIV(DSWaylandCompositor); + + return priv->_display; +} + +uint32_t DSWaylandCompositor::nextSerial() +{ + DS_GET_PRIV(DSWaylandCompositor); + + return wl_display_next_serial(priv->_display); +} + +void DSWaylandCompositor::addClient(DSWaylandClient *client) +{ + DS_GET_PRIV(DSWaylandCompositor); + + priv->addClient(client); +} + +void DSWaylandCompositor::removeClient(DSWaylandClient *client) +{ + DS_GET_PRIV(DSWaylandCompositor); + + priv->removeClient(client); +} + +void DSWaylandCompositor::addSeat(DSWaylandSeat *seat) +{ + DS_GET_PRIV(DSWaylandCompositor); + + priv->addSeat(seat); +} + +void DSWaylandCompositor::removeSeat(DSWaylandSeat *seat) +{ + DS_GET_PRIV(DSWaylandCompositor); + + priv->removeSeat(seat); +} + +std::list DSWaylandCompositor::clients() +{ + DS_GET_PRIV(DSWaylandCompositor); + + return priv->_clients; +} + +DSWaylandSeat *DSWaylandCompositor::defaultSeat() +{ + DS_GET_PRIV(DSWaylandCompositor); + + if (!priv->_seats.empty()) + { + return priv->_seats.front(); + } + + return nullptr; +} + +} diff --git a/src/DSWaylandServer/DSWaylandCompositor.h b/src/DSWaylandServer/DSWaylandCompositor.h new file mode 100644 index 0000000..d999ac2 --- /dev/null +++ b/src/DSWaylandServer/DSWaylandCompositor.h @@ -0,0 +1,47 @@ +#ifndef __DS_WAYLAND_COMPOSITOR_H__ +#define __DS_WAYLAND_COMPOSITOR_H__ + +#include "DSCore.h" +#include "DSObject.h" + +struct wl_display; + +namespace display_server +{ + +class DSWaylandClient; +class DSWaylandSeat; +class DSWaylandCompositorPrivate; +class DS_DECL_EXPORT DSWaylandCompositor : public DSObject +{ + DS_PIMPL_USE_PRIVATE(DSWaylandCompositor); +public: + DSWaylandCompositor(DSObject *parent = nullptr); + ~DSWaylandCompositor() override; + + bool create(); + bool isCreated(); + + void addClient(DSWaylandClient *client); + void removeClient(DSWaylandClient *client); + void addSeat(DSWaylandSeat *seat); + void removeSeat(DSWaylandSeat *seat); + + std::string socketName(); + ::wl_display *display(); + uint32_t nextSerial(); + std::list clients(); + DSWaylandSeat *defaultSeat(); + + //TODO + +protected: + //TODO + +private: + //TODO +}; + +} + +#endif //__DS_WAYLAND_COMPOSITOR_H__ \ No newline at end of file diff --git a/src/DSWaylandServer/DSWaylandCompositorPrivate.h b/src/DSWaylandServer/DSWaylandCompositorPrivate.h new file mode 100644 index 0000000..e55529d --- /dev/null +++ b/src/DSWaylandServer/DSWaylandCompositorPrivate.h @@ -0,0 +1,93 @@ +#ifndef __DS_WAYLAND_COMPOSITOR_PRIVATE_H__ +#define __DS_WAYLAND_COMPOSITOR_PRIVATE_H__ + +#include "DSCore.h" +#include "DSObjectPrivate.h" +#include "dswayland-server-wayland.h" + +#include + +namespace display_server +{ + +class DSWaylandClient; +class DSWaylandSeat; +class DSWaylandCompositor; +class DS_DECL_EXPORT DSWaylandCompositorPrivate : public DSObjectPrivate, public DSWaylandServer::wl_compositor +{ + DS_PIMPL_USE_PUBLIC(DSWaylandCompositor); +public: + DSWaylandCompositorPrivate(DSWaylandCompositor *compositor); + ~DSWaylandCompositorPrivate() override; + + bool initCompositor(); + void initSocket(std::string sName, std::string sDir); + inline void addClient(DSWaylandClient *client); + inline void removeClient(DSWaylandClient *client); + inline void addSeat(DSWaylandSeat *seat); + inline void removeSeat(DSWaylandSeat *seat); + + //TODO : add listener for client created event + //TODO + +protected: + //virtual Resource *compositor_allocate(); + void compositor_bind_resource(Resource *resource) override; + void compositor_destroy_resource(Resource *resource) override; + void compositor_create_surface(Resource *resource, uint32_t id) override; + void compositor_create_region(Resource *resource, uint32_t id) override; + + std::list _clients; + std::list _seats; + + bool _created; + int _socketFD; + std::string _socketName; + struct wl_display *_display; + wl_event_loop *_loop; + Ecore_Fd_Handler *_socket_fd_handler; + DSWaylandCompositor *_compositor; + + //TODO : add DSOutput list + //TODO : add DSWindow (DSSurface ?) list + +private: + static Eina_Bool __readEvents(void *data, Ecore_Fd_Handler *hdlr); + static void __prepareFunc(void *data, Ecore_Fd_Handler *hdlr); +}; + +void DSWaylandCompositorPrivate::addClient(DSWaylandClient *client) +{ + DS_ASSERT(client != nullptr); + + //TODO : check if the client is in clients already ? + _clients.push_back(client); +} + +void DSWaylandCompositorPrivate::removeClient(DSWaylandClient *client) +{ + DS_ASSERT(client != nullptr); + + //TODO : check if the client is in clients already ? + _clients.remove(client); +} + +void DSWaylandCompositorPrivate::addSeat(DSWaylandSeat *seat) +{ + DS_ASSERT(seat != nullptr); + + //TODO : check if the client is in clients already ? + _seats.push_back(seat); +} + +void DSWaylandCompositorPrivate::removeSeat(DSWaylandSeat *seat) +{ + DS_ASSERT(seat != nullptr); + + //TODO : check if the client is in clients already ? + _seats.remove(seat); +} + +} + +#endif //__DS_WAYLAND_COMPOSITOR_PRIVATE_H__ \ No newline at end of file diff --git a/src/DSWaylandServer/DSWaylandSeat.cpp b/src/DSWaylandServer/DSWaylandSeat.cpp new file mode 100644 index 0000000..1104844 --- /dev/null +++ b/src/DSWaylandServer/DSWaylandSeat.cpp @@ -0,0 +1,78 @@ +#include "DSWaylandSeat.h" +#include "DSWaylandSeatPrivate.h" + +namespace display_server +{ + +/* Begin Private Class Implementation */ +DSWaylandSeatPrivate::DSWaylandSeatPrivate(DSWaylandCompositor *compositor, DSWaylandSeat *seat) + : DSObjectPrivate(seat), + __p_ptr(seat), + __cap(DSWaylandSeat::capNone), + __compositor(compositor) +{ +} + +DSWaylandSeatPrivate::~DSWaylandSeatPrivate() +{ +} + +void DSWaylandSeatPrivate::seat_bind_resource(Resource *resource) +{ +} + +void DSWaylandSeatPrivate::seat_destroy_resource(Resource *resource) +{ +} + +void DSWaylandSeatPrivate::seat_get_pointer(Resource *resource, uint32_t id) +{ +} + +void DSWaylandSeatPrivate::seat_get_keyboard(Resource *resource, uint32_t id) +{ +} + +void DSWaylandSeatPrivate::seat_get_touch(Resource *resource, uint32_t id) +{ +} + +void DSWaylandSeatPrivate::seat_release(Resource *resource) +{ +} + +/* Begin Public Class Implementation */ +DSWaylandSeat::DSWaylandSeat(DSWaylandCompositor *compositor, DSWaylandSeat::seatCapability cap) + : DSObject(), _d_ptr(std::make_unique(compositor, this)) +{ + DS_GET_PRIV(DSWaylandSeat); + + priv->__cap = cap; +} + +DSWaylandSeat::~DSWaylandSeat() +{ +} + +void DSWaylandSeat::setCapability(DSWaylandSeat::seatCapability cap) +{ + DS_GET_PRIV(DSWaylandSeat); + + priv->__cap = cap; +} + +void DSWaylandSeat::updateCapability(DSWaylandSeat::seatCapability cap) +{ + DS_GET_PRIV(DSWaylandSeat); + + priv->__cap = (DSWaylandSeat::seatCapability)((int)priv->__cap | cap); +} + +DSWaylandSeat::seatCapability DSWaylandSeat::getCapability(void) +{ + DS_GET_PRIV(DSWaylandSeat); + + return priv->__cap; +} + +} diff --git a/src/DSWaylandServer/DSWaylandSeat.h b/src/DSWaylandServer/DSWaylandSeat.h new file mode 100644 index 0000000..6d329a3 --- /dev/null +++ b/src/DSWaylandServer/DSWaylandSeat.h @@ -0,0 +1,43 @@ +#ifndef __DS_WAYLAND_SEAT_H__ +#define __DS_WAYLAND_SEAT_H__ + +#include "DSCore.h" +#include "DSObject.h" + +namespace display_server +{ + +class DSWaylandSeatPrivate; +class DSWaylandCompositor; +class DS_DECL_EXPORT DSWaylandSeat : public DSObject +{ + DS_PIMPL_USE_PRIVATE(DSWaylandSeat); +public: + enum seatCapability { + capNone = 0x0, + capPointer = 0x1, + capKeyboard = 0x2, + capPointerKeyboard = capPointer | capKeyboard, + capTouch = 0x4, + capPointerTouch = capPointer | capTouch, + capKeyboardTouch = capKeyboard | capTouch, + capAll = capPointer | capKeyboard | capTouch, + capDefault = capPointer | capKeyboard | capTouch, + }; + + DSWaylandSeat(DSWaylandCompositor *compositor, DSWaylandSeat::seatCapability cap); + ~DSWaylandSeat() override; + + void setCapability(DSWaylandSeat::seatCapability cap); + void updateCapability(DSWaylandSeat::seatCapability cap); + DSWaylandSeat::seatCapability getCapability(void); + +protected: + +private: + +}; + +} + +#endif //__DS_WAYLAND_SEAT_H__ diff --git a/src/DSWaylandServer/DSWaylandSeatPrivate.h b/src/DSWaylandServer/DSWaylandSeatPrivate.h new file mode 100644 index 0000000..c7b6056 --- /dev/null +++ b/src/DSWaylandServer/DSWaylandSeatPrivate.h @@ -0,0 +1,33 @@ +#ifndef __DS_WAYLAND_SEAT_PRIVATE_H__ +#define __DS_WAYLAND_SEAT_PRIVATE_H__ + +#include "DSCore.h" +#include "DSObjectPrivate.h" +#include "dswayland-server-wayland.h" + +namespace display_server +{ + +class DS_DECL_EXPORT DSWaylandSeatPrivate : public DSObjectPrivate, public DSWaylandServer::wl_seat +{ + DS_PIMPL_USE_PUBLIC(DSWaylandSeat); +public: + DSWaylandSeatPrivate(DSWaylandCompositor *compositor, DSWaylandSeat *seat); + ~DSWaylandSeatPrivate() override; + +protected: + void seat_bind_resource(Resource *resource) override; + void seat_destroy_resource(Resource *resource) override; + void seat_get_pointer(Resource *resource, uint32_t id) override; + void seat_get_keyboard(Resource *resource, uint32_t id) override; + void seat_get_touch(Resource *resource, uint32_t id) override; + void seat_release(Resource *resource) override; + +private: + DSWaylandSeat::seatCapability __cap; + DSWaylandCompositor *__compositor; +}; + +} + +#endif //__DS_WAYLAND_SEAT_PRIVATE_H__ diff --git a/src/meson.build b/src/meson.build index f0370b7..8a114d1 100644 --- a/src/meson.build +++ b/src/meson.build @@ -92,6 +92,15 @@ libds_wayland_srcs = [ 'DSWaylandServer/DSWaylandZxdgPopupV6.cpp', 'DSWaylandServer/DSWaylandZxdgPopupV6.h', 'DSWaylandServer/DSWaylandZxdgPopupV6Private.h', + 'DSWaylandServer/DSWaylandCompositorPrivate.h', + 'DSWaylandServer/DSWaylandCompositor.h', + 'DSWaylandServer/DSWaylandCompositor.cpp', + 'DSWaylandServer/DSWaylandClientPrivate.h', + 'DSWaylandServer/DSWaylandClient.h', + 'DSWaylandServer/DSWaylandClient.cpp', + 'DSWaylandServer/DSWaylandSeatPrivate.h', + 'DSWaylandServer/DSWaylandSeat.h', + 'DSWaylandServer/DSWaylandSeat.cpp', ] libds_srcs += libds_wayland_srcs diff --git a/tests/DSWaylandClient-test.cpp b/tests/DSWaylandClient-test.cpp new file mode 100644 index 0000000..53a0f82 --- /dev/null +++ b/tests/DSWaylandClient-test.cpp @@ -0,0 +1,139 @@ +#include "libds-tests.h" +#include "DSWaylandCompositor.h" +#include "DSWaylandClient.h" + +using namespace display_server; + +class DSWaylandClientTest : public ::testing::Test +{ +public: + void SetUp(void) override + { + setenv("XDG_RUNTIME_DIR", "/run", 1); + } + void TearDown(void) override + { + unsetenv("XDG_RUNTIME_DIR"); + } +}; + +/* Test cases */ +TEST_F(DSWaylandClientTest, NewDSWaylandClient) +{ + DSWaylandCompositor *comp = new DSWaylandCompositor(new DSObject); + EXPECT_TRUE(comp != nullptr); + + if (comp) + { + /* client must be created with a valid wl_client ptr later. */ + DSWaylandClient *client = new DSWaylandClient(comp, (wl_client *)nullptr); + EXPECT_TRUE(client != nullptr); + + if (client) + delete client; + + delete comp; + } +} + +TEST_F(DSWaylandClientTest, GetClientFromWlClient) +{ + DSWaylandCompositor *comp = new DSWaylandCompositor(new DSObject); + EXPECT_TRUE(comp != nullptr); + + if (comp) + { + /* client must be created with a valid wl_client ptr later. */ + DSWaylandClient *client = new DSWaylandClient(comp, (wl_client *)nullptr); + EXPECT_TRUE(client != nullptr); + + if (client) + { + DSWaylandClient *client2 = client->fromWlClient((wl_client *)nullptr); + EXPECT_TRUE(client2 == client); + + delete client; + } + + delete comp; + } +} + +TEST_F(DSWaylandClientTest, GetWlClient) +{ + DSWaylandCompositor *comp = new DSWaylandCompositor(new DSObject); + EXPECT_TRUE(comp != nullptr); + + if (comp) + { + /* client must be created with a valid wl_client ptr later. */ + DSWaylandClient *client = new DSWaylandClient(comp, (wl_client *)nullptr); + EXPECT_TRUE(client != nullptr); + + if (client) + { + wl_client *wclient = client->wlClient(); + EXPECT_TRUE(wclient != nullptr); + + delete client; + } + + delete comp; + } +} + +TEST_F(DSWaylandClientTest, GetCompositor) +{ + DSWaylandCompositor *comp = new DSWaylandCompositor(new DSObject); + EXPECT_TRUE(comp != nullptr); + + if (comp) + { + /* client must be created with a valid wl_client ptr later. */ + DSWaylandClient *client = new DSWaylandClient(comp, (wl_client *)nullptr); + EXPECT_TRUE(client != nullptr); + + if (client) + { + DSWaylandCompositor *comp2 = client->getCompositor(); + EXPECT_TRUE(comp2 == comp); + + delete client; + } + + delete comp; + } +} + +TEST_F(DSWaylandClientTest, GetPidUidGid) +{ + DSWaylandCompositor *comp = new DSWaylandCompositor(new DSObject); + EXPECT_TRUE(comp != nullptr); + + if (comp) + { + /* client must be created with a valid wl_client ptr later. */ + DSWaylandClient *client = new DSWaylandClient(comp, (wl_client *)nullptr); + EXPECT_TRUE(client != nullptr); + + if (client) + { + pid_t pID; + uid_t uID; + gid_t gID; + + pID = client->pid(); + uID = client->uid(); + gID = client->gid(); + + EXPECT_TRUE(pID != 0); + EXPECT_TRUE(uID != 0); + EXPECT_TRUE(gID != 0); + + delete client; + } + + delete comp; + } +} + diff --git a/tests/DSWaylandCompositor-test.cpp b/tests/DSWaylandCompositor-test.cpp new file mode 100644 index 0000000..2b8a74f --- /dev/null +++ b/tests/DSWaylandCompositor-test.cpp @@ -0,0 +1,156 @@ +#include "libds-tests.h" +#include "DSWaylandCompositor.h" +#include "DSWaylandClient.h" +#include "DSWaylandSeat.h" +#include "Ecore.h" + +using namespace display_server; + +class DSWaylandCompositorTest : public ::testing::Test +{ +public: + void SetUp(void) override + { + setenv("XDG_RUNTIME_DIR", "/run", 1); + } + void TearDown(void) override + { + unsetenv("XDG_RUNTIME_DIR"); + } +}; + +/* Test cases */ +TEST_F(DSWaylandCompositorTest, NewDSWaylandCompositor) +{ + DSWaylandCompositor *comp = new DSWaylandCompositor(new DSObject); + EXPECT_TRUE(comp != nullptr); + + if (comp) + delete comp; +} + +TEST_F(DSWaylandCompositorTest, CreateTest) +{ + bool res; + + DSWaylandCompositor *comp = new DSWaylandCompositor(new DSObject); + EXPECT_TRUE(comp != nullptr); + + if (comp) + { + res = comp->create(); + EXPECT_TRUE(res == true); + + res = comp->isCreated(); + EXPECT_TRUE(res == true); + + std::string sockName = comp->socketName().substr(0, 8); + EXPECT_TRUE(sockName.compare(std::string{"wayland-"}) == 0); + + sockName.clear(); + delete comp; + } +} + +TEST_F(DSWaylandCompositorTest, DisplayGet) +{ + bool res; + + DSWaylandCompositor *comp = new DSWaylandCompositor(new DSObject); + EXPECT_TRUE(comp != nullptr); + + if (comp) + { + res = comp->create(); + EXPECT_TRUE(res == true); + EXPECT_TRUE(comp->display() != nullptr); + + delete comp; + } +} + +TEST_F(DSWaylandCompositorTest, NextSerialGet) +{ + bool res; + uint32_t nSerial; + + DSWaylandCompositor *comp = new DSWaylandCompositor(new DSObject); + EXPECT_TRUE(comp != nullptr); + + if (comp) + { + res = comp->create(); + EXPECT_TRUE(res == true); + + nSerial = comp->nextSerial(); + EXPECT_TRUE((nSerial+1) == comp->nextSerial()); + + delete comp; + } +} + +TEST_F(DSWaylandCompositorTest, AddRemoveClient) +{ + bool res; + std::list l; + + DSWaylandCompositor *comp = new DSWaylandCompositor(new DSObject); + EXPECT_TRUE(comp != nullptr); + + if (comp) + { + res = comp->create(); + EXPECT_TRUE(res == true); + + DSWaylandClient *client = new DSWaylandClient(comp, (wl_client *)nullptr); + EXPECT_TRUE(client != nullptr); + + if (client) + { + comp->addClient(client); + + l = comp->clients(); + EXPECT_TRUE(l.size() != 0); + + comp->removeClient(client); + + l = comp->clients(); + EXPECT_TRUE(l.size() == 0); + + delete client; + } + + delete comp; + } +} + +TEST_F(DSWaylandCompositorTest, GetDefaultSeat) +{ + bool res; + + DSWaylandCompositor *comp = new DSWaylandCompositor(new DSObject); + EXPECT_TRUE(comp != nullptr); + + if (comp) + { + res = comp->create(); + EXPECT_TRUE(res == true); + + DSWaylandSeat *seat = new DSWaylandSeat(comp, DSWaylandSeat::capDefault); + EXPECT_TRUE(seat != nullptr); + + if (seat) + { + comp->addSeat(seat); + EXPECT_TRUE(comp->defaultSeat() != nullptr); + + comp->removeSeat(seat); + EXPECT_TRUE(comp->defaultSeat() == nullptr); + + delete seat; + } + + delete comp; + } +} + diff --git a/tests/DSWaylandSeat-test.cpp b/tests/DSWaylandSeat-test.cpp new file mode 100644 index 0000000..6152f17 --- /dev/null +++ b/tests/DSWaylandSeat-test.cpp @@ -0,0 +1,65 @@ +#include "libds-tests.h" +#include "DSWaylandCompositor.h" +#include "DSWaylandSeat.h" + +using namespace display_server; + +class DSWaylandSeatTest : public ::testing::Test +{ +public: + void SetUp(void) override + { + setenv("XDG_RUNTIME_DIR", "/run", 1); + } + void TearDown(void) override + { + unsetenv("XDG_RUNTIME_DIR"); + } +}; + +/* Test cases */ +TEST_F(DSWaylandSeatTest, NewDSWaylandSeat) +{ + DSWaylandCompositor *comp = new DSWaylandCompositor(new DSObject); + EXPECT_TRUE(comp != nullptr); + + if (comp) + { + DSWaylandSeat *seat = new DSWaylandSeat(comp, DSWaylandSeat::capDefault); + EXPECT_TRUE(seat != nullptr); + + if (seat) + delete seat; + + delete comp; + } +} + +TEST_F(DSWaylandSeatTest, SetUpdateGetCapabilities) +{ + DSWaylandCompositor *comp = new DSWaylandCompositor(new DSObject); + EXPECT_TRUE(comp != nullptr); + + if (comp) + { + DSWaylandSeat *seat = new DSWaylandSeat(comp, DSWaylandSeat::capDefault); + EXPECT_TRUE(seat != nullptr); + + if (seat) + { + EXPECT_TRUE(DSWaylandSeat::capDefault == seat->getCapability()); + + seat->setCapability(DSWaylandSeat::capKeyboard); + EXPECT_TRUE(DSWaylandSeat::capKeyboard == seat->getCapability()); + + seat->updateCapability(DSWaylandSeat::capPointer); + EXPECT_TRUE(DSWaylandSeat::capKeyboard & seat->getCapability()); + EXPECT_TRUE(DSWaylandSeat::capPointer & seat->getCapability()); + + delete seat; + } + + delete comp; + } +} + diff --git a/tests/meson.build b/tests/meson.build index 06296a3..20ae0ed 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -27,6 +27,9 @@ libds_tests_srcs = [ 'DSWaylandZxdgPopupV6-test.cpp', 'DSObject-test.cpp', 'DSEventLoop-test.cpp', + 'DSWaylandCompositor-test.cpp', + 'DSWaylandSeat-test.cpp', + 'DSWaylandClient-test.cpp', ] gmock_dep = dependency('gmock', method : 'pkg-config') -- 2.7.4 From 2c1a0a98fccce08d68f9328fd954f2ac9437600c Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Fri, 10 Jul 2020 13:00:20 +0900 Subject: [PATCH 05/16] DSLOG: remove new lines Change-Id: I027f45c33f5e56f7ee120079c5d72fc0fcd0155c --- src/DSBuffer/DSBufferQueueTBMImpl.cpp | 4 ++-- src/DSBuffer/DSBufferTBMImpl.cpp | 6 +++--- src/DSDisplayDevice/DSDisplayDeviceHWCTDMImpl.cpp | 14 +++++++------- src/DSDisplayDevice/DSDisplayDeviceOutputTDMImpl.cpp | 10 +++++----- src/DSDisplayDevice/DSDisplayDeviceTDMImpl.cpp | 6 +++--- src/DSRender/DSRenderEngineEcoreEvasImpl.cpp | 6 +++--- tests/DSProperty-test.cpp | 8 ++------ tests/DSRefBase-test.cpp | 8 ++------ tests/DSSignal-test.cpp | 4 ++-- 9 files changed, 29 insertions(+), 37 deletions(-) diff --git a/src/DSBuffer/DSBufferQueueTBMImpl.cpp b/src/DSBuffer/DSBufferQueueTBMImpl.cpp index d4e35d8..08eb77e 100644 --- a/src/DSBuffer/DSBufferQueueTBMImpl.cpp +++ b/src/DSBuffer/DSBufferQueueTBMImpl.cpp @@ -14,7 +14,7 @@ DSBufferQueueTBMImpl::DSBufferQueueTBMImpl(int slotSize, int bufferWidth, int bu { __tqueue = tbm_surface_queue_create(__slotSize, __bufferWidth, __bufferHeight, DSBufferTBMImpl::getTBMFormat(__format), TBM_BO_SCANOUT); if (!__tqueue) { - DSLOG_ERR("DSBufferTBM", "tbm_surface_queue_create fails.\n"); + DSLOG_ERR("DSBufferTBM", "tbm_surface_queue_create fails."); } } @@ -54,7 +54,7 @@ std::shared_ptr DSBufferQueueTBMImpl::dequeueBuffer() terror = tbm_surface_queue_dequeue(__tqueue, &tsurface); if (terror != TBM_SURFACE_QUEUE_ERROR_NONE) { - DSLOG_ERR("BuffeQueueTBM", "tbm_surface_queue_dequeue fails.\n"); + DSLOG_ERR("BuffeQueueTBM", "tbm_surface_queue_dequeue fails."); return nullptr; } diff --git a/src/DSBuffer/DSBufferTBMImpl.cpp b/src/DSBuffer/DSBufferTBMImpl.cpp index 9a3dc9c..bf17ae6 100644 --- a/src/DSBuffer/DSBufferTBMImpl.cpp +++ b/src/DSBuffer/DSBufferTBMImpl.cpp @@ -11,7 +11,7 @@ DSBufferTBMImpl::DSBufferTBMImpl(int width, int height, IDSBuffer::Format format { __tsurface = tbm_surface_create(__width, __height, getTBMFormat(__format)); if (!__tsurface) { - DSLOG_ERR("DSBufferTBM", "tbm_surface_create fails.\n"); + DSLOG_ERR("DSBufferTBM", "tbm_surface_create fails."); } } @@ -41,7 +41,7 @@ tbm_format DSBufferTBMImpl::getTBMFormat(const IDSBuffer::Format &format) tformat = TBM_FORMAT_ARGB8888; break; default: - DSLOG_ERR("DSBufferTBM", "(%d) format is not supported.\n", format); + DSLOG_ERR("DSBufferTBM", "(%d) format is not supported.", format); } return tformat; @@ -56,7 +56,7 @@ IDSBuffer::Format DSBufferTBMImpl::getBufferFormat(const tbm_format &tformat) format = IDSBuffer::Format::FORMAT_ARGB8888 ; break; default: - DSLOG_ERR("DSBufferTBM", "(%d) format is not supported.\n", tformat); + DSLOG_ERR("DSBufferTBM", "(%d) format is not supported.", tformat); } return format; diff --git a/src/DSDisplayDevice/DSDisplayDeviceHWCTDMImpl.cpp b/src/DSDisplayDevice/DSDisplayDeviceHWCTDMImpl.cpp index f7b1cce..fea17fd 100644 --- a/src/DSDisplayDevice/DSDisplayDeviceHWCTDMImpl.cpp +++ b/src/DSDisplayDevice/DSDisplayDeviceHWCTDMImpl.cpp @@ -29,7 +29,7 @@ std::shared_ptr DSDisplayDeviceHWCTDMImpl::getTargetBufferQueue( tqueue = tdm_hwc_get_client_target_buffer_queue(__thwc, &terror); if (terror != TDM_ERROR_NONE) { - DSLOG_ERR("HWCTDM", "tdm_hwc_get_client_target_buffer_queue fails.\n"); + DSLOG_ERR("HWCTDM", "tdm_hwc_get_client_target_buffer_queue fails."); } __bufferQueue = std::make_shared(tqueue); @@ -60,13 +60,13 @@ std::shared_ptr DSDisplayDeviceHWCTDMImpl::makeHWCWin twindow = tdm_hwc_create_window(__thwc, &terror); if (!twindow) { - DSLOG_ERR("HWCTDM", "tdm_hwc_create_window fails.\n"); + DSLOG_ERR("HWCTDM", "tdm_hwc_create_window fails."); return nullptr; } deviceHWCWindow = std::make_shared(twindow); if (!deviceHWCWindow) { - DSLOG_ERR("HWCTDM", "new DSDisplayDeviceHWCWindowTDMImpl fails.\n"); + DSLOG_ERR("HWCTDM", "new DSDisplayDeviceHWCWindowTDMImpl fails."); return nullptr; } @@ -98,19 +98,19 @@ bool DSDisplayDeviceHWCTDMImpl::commit() uint32_t numChanges; if (!__validate(numChanges)) { - DSLOG_ERR("HWCTDM", "__validate fails.\n"); + DSLOG_ERR("HWCTDM", "__validate fails."); return false; } if (numChanges > 0) { if (!__updateChanges(numChanges)) { - DSLOG_ERR("HWCTDM", "__updateChanges fails.\n"); + DSLOG_ERR("HWCTDM", "__updateChanges fails."); return false; } } if (!__acceptValidation()) { - DSLOG_ERR("HWCTDM", "__acceptValidation fails.\n"); + DSLOG_ERR("HWCTDM", "__acceptValidation fails."); return false; } @@ -202,7 +202,7 @@ bool DSDisplayDeviceHWCTDMImpl::__acceptValidation() // TODO: accept_validation is depending on the transitions. terror = tdm_hwc_accept_validation(__thwc); if (terror != TDM_ERROR_NONE) { - DSLOG_ERR("TDM_HWC", "tdm_hwc_accept_validation fails.\n"); + DSLOG_ERR("TDM_HWC", "tdm_hwc_accept_validation fails."); return false; } diff --git a/src/DSDisplayDevice/DSDisplayDeviceOutputTDMImpl.cpp b/src/DSDisplayDevice/DSDisplayDeviceOutputTDMImpl.cpp index 21d1e3e..4ef1821 100644 --- a/src/DSDisplayDevice/DSDisplayDeviceOutputTDMImpl.cpp +++ b/src/DSDisplayDevice/DSDisplayDeviceOutputTDMImpl.cpp @@ -98,7 +98,7 @@ bool DSDisplayDeviceOutputTDMImpl::setMode(std::shared_ptr void * { @@ -30,7 +30,7 @@ DSRenderEngineEcoreEvasImpl::DSRenderEngineEcoreEvasImpl(std::shared_ptr Date: Fri, 10 Jul 2020 13:33:01 +0900 Subject: [PATCH 06/16] DSInput: Add device add/remove signals Change-Id: I39a13760d26abb5283cfa8cfcc3990915bbcf684 --- src/DSInput/DSInput.cpp | 25 ++++++++++++++++++++++--- src/DSInput/DSInput.h | 10 ++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/DSInput/DSInput.cpp b/src/DSInput/DSInput.cpp index 63838dd..b59361f 100644 --- a/src/DSInput/DSInput.cpp +++ b/src/DSInput/DSInput.cpp @@ -37,15 +37,19 @@ void DSInputPrivate::PostDeviceRemoveEvent(std::string seat, std::string name, s DSInput::DSInput() : DS_INIT_PRIVATE_PTR(DSInput) { - DS_GET_PRIV(DSInput); - - priv->Init(); } DSInput::~DSInput() { } +void DSInput::Init() +{ + DS_GET_PRIV(DSInput); + + priv->Init(); +} + void DSInput::deviceAdd(std::string name, std::string identifier, DSInput::DeviceClass devClass, DSInput::DeviceSubclass devSubclass) { DSInputDevice *device = new DSInputDevice(name, identifier, devClass, devSubclass); @@ -59,6 +63,8 @@ void DSInput::deviceAdd(std::string name, std::string identifier, DSInput::Devic } } + this->__deviceAddSignal.emit(std::make_shared(*device)); + devList.push_back(device); } @@ -70,6 +76,8 @@ void DSInput::deviceRemove(std::string name, std::string identifier, DSInput::De { if (*dev == *device) { + this->__deviceRemoveSignal.emit(std::make_shared(*dev)); + devList.remove(dev); delete dev; break; @@ -79,6 +87,17 @@ void DSInput::deviceRemove(std::string name, std::string identifier, DSInput::De delete device; } +void DSInput::registerCallbackDeviceAdd(DSObject *slot, std::function)> func) +{ + this->__deviceAddSignal.connect(slot, func); +} + +void DSInput::registerCallbackDeviceRemove(DSObject *slot, std::function)> func) +{ + this->__deviceRemoveSignal.connect(slot, func); +} + + DSInputDevice::DSInputDevice() : __deviceName(""), __deviceIdentifier(""), diff --git a/src/DSInput/DSInput.h b/src/DSInput/DSInput.h index 1cde6bf..86931e3 100644 --- a/src/DSInput/DSInput.h +++ b/src/DSInput/DSInput.h @@ -6,6 +6,8 @@ #include #include #include +#include +#include namespace display_server { @@ -30,11 +32,19 @@ public: DSInput(); ~DSInput() override; + void Init(); + void deviceAdd(std::string name, std::string identifier, DSInput::DeviceClass devClass, DSInput::DeviceSubclass devSubclass); void deviceRemove(std::string name, std::string identifier, DSInput::DeviceClass devClass, DSInput::DeviceSubclass devSubclass); + void registerCallbackDeviceAdd(DSObject *slot, std::function)> func); + void registerCallbackDeviceRemove(DSObject *slot, std::function)> func); + private: std::list devList; + + DSSignal> __deviceAddSignal; + DSSignal> __deviceRemoveSignal; }; class DSInputDevice -- 2.7.4 From 21663277ebe80eaf8dae8a49b3ac1d9fb0758f24 Mon Sep 17 00:00:00 2001 From: jeon Date: Fri, 10 Jul 2020 13:33:41 +0900 Subject: [PATCH 07/16] DSSeat: connects signals for device add/remove Change-Id: I43e987af82bbb1f82d3191d3bb8a0acfd6913e48 --- src/DSSeat/DSSeat.cpp | 20 ++++++++++++++++++-- src/DSSeat/DSSeat.h | 6 +++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/DSSeat/DSSeat.cpp b/src/DSSeat/DSSeat.cpp index df0657e..ff5663c 100644 --- a/src/DSSeat/DSSeat.cpp +++ b/src/DSSeat/DSSeat.cpp @@ -15,12 +15,28 @@ DSSeat::~DSSeat() bool DSSeat::addInput(std::shared_ptr input) { - return false; + __input = input.get(); + __input->registerCallbackDeviceAdd(this, std::bind(&DSSeat::slotDeviceAdd, this, std::placeholders::_1)); + __input->registerCallbackDeviceRemove(this, std::bind(&DSSeat::slotDeviceRemove, this, std::placeholders::_1)); + return true; } bool DSSeat::removeInput(std::shared_ptr input) { - return false; + __input = nullptr; + return true; +} + +void DSSeat::slotDeviceAdd(std::shared_ptr device) +{ + std::cout << "DSSeat slotDeviceAdd!" << std::endl; + device->print(); +} + +void DSSeat::slotDeviceRemove(std::shared_ptr device) +{ + std::cout << "DSSeat slotDeviceRemove!" << std::endl; + device->print(); } } // namespace display_server \ No newline at end of file diff --git a/src/DSSeat/DSSeat.h b/src/DSSeat/DSSeat.h index b0a2d2d..b4585ad 100644 --- a/src/DSSeat/DSSeat.h +++ b/src/DSSeat/DSSeat.h @@ -10,8 +10,9 @@ namespace display_server class DSKeyboard; class DSPointer; class DSTouch; +class DSInputDevice; -class DSSeat +class DSSeat : public DSObject { public: DSSeat(); @@ -20,6 +21,9 @@ public: bool addInput(std::shared_ptr input); bool removeInput(std::shared_ptr input); + void slotDeviceAdd(std::shared_ptr device); + void slotDeviceRemove(std::shared_ptr device); + private: DSInput *__input; DSKeyboard *__keyboard; -- 2.7.4 From 91130725d89bb03858f6842797f07f93836619c8 Mon Sep 17 00:00:00 2001 From: jeon Date: Fri, 10 Jul 2020 14:06:22 +0900 Subject: [PATCH 08/16] DSLibinput: init/shutdown ecore system to use ecore fd handler Change-Id: I410cf725045082983e49f7617b92b1a0fb00031a --- src/DSInput/DSLibinput.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/DSInput/DSLibinput.cpp b/src/DSInput/DSLibinput.cpp index e6c2683..2515654 100644 --- a/src/DSInput/DSLibinput.cpp +++ b/src/DSInput/DSLibinput.cpp @@ -14,6 +14,7 @@ const struct ::libinput_interface DSLibinput::__input_interface = { DSLibinput::DSLibinput(DSInputPrivate *p_ptr) { inputPrivate = p_ptr; + ecore_init(); __udev = udev_new(); __libinput = libinput_udev_create_context(&__input_interface, this, __udev); @@ -35,6 +36,7 @@ DSLibinput::~DSLibinput() { ecore_main_fd_handler_del(__libinput_handler); } + ecore_shutdown(); libinput_unref(__libinput); udev_unref(__udev); } @@ -114,12 +116,10 @@ Eina_Bool DSLibinput::__handleEvents(void *data, Ecore_Fd_Handler *hdlr) void DSLibinput::__processDeviceAddEvent(struct ::libinput_event *event) { - struct ::libinput *libinput; struct ::libinput_seat *libinput_seat; struct ::libinput_device *device; std::string seatName, devName, identifier; - libinput = libinput_event_get_context(event); device = libinput_event_get_device(event); libinput_seat = libinput_device_get_seat(device); @@ -143,12 +143,10 @@ void DSLibinput::__processDeviceAddEvent(struct ::libinput_event *event) void DSLibinput::__processDeviceRemoveEvent(struct ::libinput_event *event) { - struct ::libinput *libinput; struct ::libinput_seat *libinput_seat; struct ::libinput_device *device; std::string seatName, devName, identifier; - libinput = libinput_event_get_context(event); device = libinput_event_get_device(event); libinput_seat = libinput_device_get_seat(device); -- 2.7.4 From 74a4d3d9338c1ecbfadab76944cc71acfd662580 Mon Sep 17 00:00:00 2001 From: Sung-Jin Park Date: Fri, 10 Jul 2020 10:05:47 +0900 Subject: [PATCH 09/16] DSWaylandServer: implements DSWaylandPointer, DSWaylandKeyboard and DSWaylandTouch Change-Id: I274e70c4acffccb245e8da589eea24f68ef37015 Signed-off-by: Sung-Jin Park --- src/DSWaylandServer/DSWaylandKeyboard.cpp | 80 ++++++++++++++++++++++++++ src/DSWaylandServer/DSWaylandKeyboard.h | 36 ++++++++++++ src/DSWaylandServer/DSWaylandKeyboardPrivate.h | 37 ++++++++++++ src/DSWaylandServer/DSWaylandPointer.cpp | 52 +++++++++++++++++ src/DSWaylandServer/DSWaylandPointer.h | 31 ++++++++++ src/DSWaylandServer/DSWaylandPointerPrivate.h | 35 +++++++++++ src/DSWaylandServer/DSWaylandTouch.cpp | 47 +++++++++++++++ src/DSWaylandServer/DSWaylandTouch.h | 31 ++++++++++ src/DSWaylandServer/DSWaylandTouchPrivate.h | 34 +++++++++++ src/meson.build | 9 +++ tests/DSWaylandKeyboard-test.cpp | 67 +++++++++++++++++++++ tests/DSWaylandPointer-test.cpp | 47 +++++++++++++++ tests/DSWaylandTouch-test.cpp | 47 +++++++++++++++ tests/meson.build | 3 + 14 files changed, 556 insertions(+) create mode 100644 src/DSWaylandServer/DSWaylandKeyboard.cpp create mode 100644 src/DSWaylandServer/DSWaylandKeyboard.h create mode 100644 src/DSWaylandServer/DSWaylandKeyboardPrivate.h create mode 100644 src/DSWaylandServer/DSWaylandPointer.cpp create mode 100644 src/DSWaylandServer/DSWaylandPointer.h create mode 100644 src/DSWaylandServer/DSWaylandPointerPrivate.h create mode 100644 src/DSWaylandServer/DSWaylandTouch.cpp create mode 100644 src/DSWaylandServer/DSWaylandTouch.h create mode 100644 src/DSWaylandServer/DSWaylandTouchPrivate.h create mode 100644 tests/DSWaylandKeyboard-test.cpp create mode 100644 tests/DSWaylandPointer-test.cpp create mode 100644 tests/DSWaylandTouch-test.cpp diff --git a/src/DSWaylandServer/DSWaylandKeyboard.cpp b/src/DSWaylandServer/DSWaylandKeyboard.cpp new file mode 100644 index 0000000..aa3b02f --- /dev/null +++ b/src/DSWaylandServer/DSWaylandKeyboard.cpp @@ -0,0 +1,80 @@ +#include "DSWaylandKeyboard.h" +#include "DSWaylandKeyboardPrivate.h" + +namespace display_server +{ + +/* Begin Private Class Implementation */ +DSWaylandKeyboardPrivate::DSWaylandKeyboardPrivate(DSWaylandSeat *seat, DSWaylandKeyboard *keyboard) + : DSObjectPrivate(keyboard), + __p_ptr(keyboard), + __seat(seat), + __repeatRate(0), + __repeatDelay(0) +{ + +} + +DSWaylandKeyboardPrivate::~DSWaylandKeyboardPrivate() +{ +} + +void DSWaylandKeyboardPrivate::keyboard_bind_resource(Resource *resource) +{ +} + +void DSWaylandKeyboardPrivate::keyboard_destroy_resource(Resource *resource) +{ +} + +void DSWaylandKeyboardPrivate::keyboard_release(Resource *resource) +{ +} + +/* Begin Public Class Implementation */ +DSWaylandKeyboard::DSWaylandKeyboard(DSWaylandSeat *seat) + : DSObject(), _d_ptr(std::make_unique(seat, this)) +{ + +} + +DSWaylandKeyboard::~DSWaylandKeyboard() +{ +} + +DSWaylandSeat *DSWaylandKeyboard::seat() +{ + DS_GET_PRIV(DSWaylandKeyboard); + + return priv->__seat; +} + +void DSWaylandKeyboard::setRepeatRate(uint32_t rate) +{ + DS_GET_PRIV(DSWaylandKeyboard); + + priv->__repeatRate = rate; +} + +void DSWaylandKeyboard::setRepeatDelay(uint32_t delay) +{ + DS_GET_PRIV(DSWaylandKeyboard); + + priv->__repeatDelay = delay; +} + +uint32_t DSWaylandKeyboard::repeatRate(void) +{ + DS_GET_PRIV(DSWaylandKeyboard); + + return priv->__repeatRate; +} + +uint32_t DSWaylandKeyboard::repeatDelay(void) +{ + DS_GET_PRIV(DSWaylandKeyboard); + + return priv->__repeatDelay; +} + +} diff --git a/src/DSWaylandServer/DSWaylandKeyboard.h b/src/DSWaylandServer/DSWaylandKeyboard.h new file mode 100644 index 0000000..e1ceeb2 --- /dev/null +++ b/src/DSWaylandServer/DSWaylandKeyboard.h @@ -0,0 +1,36 @@ +#ifndef __DS_WAYLAND_KEYBOARD_H__ +#define __DS_WAYLAND_KEYBOARD_H__ + +#include "DSCore.h" +#include "DSObject.h" + +namespace display_server +{ + +class DSWaylandSeat; +class DSWaylandKeyboardPrivate; +class DS_DECL_EXPORT DSWaylandKeyboard : public DSObject +{ + DS_PIMPL_USE_PRIVATE(DSWaylandKeyboard); +public: + DSWaylandKeyboard(DSWaylandSeat *seat); + ~DSWaylandKeyboard() override; + + DSWaylandSeat *seat(); + + void setRepeatRate(uint32_t rate); + void setRepeatDelay(uint32_t delay); + uint32_t repeatRate(void); + uint32_t repeatDelay(void); + + //TODO + +protected: + +private: + +}; + +} + +#endif //__DS_WAYLAND_KEYBOARD_H__ diff --git a/src/DSWaylandServer/DSWaylandKeyboardPrivate.h b/src/DSWaylandServer/DSWaylandKeyboardPrivate.h new file mode 100644 index 0000000..ecb34af --- /dev/null +++ b/src/DSWaylandServer/DSWaylandKeyboardPrivate.h @@ -0,0 +1,37 @@ +#ifndef __DS_WAYLAND_KEYBOARD_PRIVATE_H__ +#define __DS_WAYLAND_KEYBOARD_PRIVATE_H__ + +#include "dswayland-server-wayland.h" + +#include "DSCore.h" +#include "DSObjectPrivate.h" + +namespace display_server +{ + +class DSWaylandSeat; +class DS_DECL_EXPORT DSWaylandKeyboardPrivate : public DSObjectPrivate, public DSWaylandServer::wl_keyboard +{ + DS_PIMPL_USE_PUBLIC(DSWaylandKeyboard); +public: + DSWaylandKeyboardPrivate(DSWaylandSeat *seat, DSWaylandKeyboard *keyboard); + ~DSWaylandKeyboardPrivate() override; + + //TO DO + +protected: + //virtual Resource *keyboard_allocate(); + virtual void keyboard_bind_resource(Resource *resource); + virtual void keyboard_destroy_resource(Resource *resource); + virtual void keyboard_release(Resource *resource); + +private: + DSWaylandSeat *__seat; + + uint32_t __repeatRate; + uint32_t __repeatDelay; +}; + +} + +#endif //__DS_WAYLAND_KEYBOARD_PRIVATE_H__ diff --git a/src/DSWaylandServer/DSWaylandPointer.cpp b/src/DSWaylandServer/DSWaylandPointer.cpp new file mode 100644 index 0000000..b2422e5 --- /dev/null +++ b/src/DSWaylandServer/DSWaylandPointer.cpp @@ -0,0 +1,52 @@ +#include "DSWaylandPointer.h" +#include "DSWaylandPointerPrivate.h" + +namespace display_server +{ + +/* Begin Private Class Implementation */ +DSWaylandPointerPrivate::DSWaylandPointerPrivate(DSWaylandSeat *seat, DSWaylandPointer *pointer) + : DSObjectPrivate(pointer), + __p_ptr(pointer), + __seat(seat) +{ +} + +DSWaylandPointerPrivate::~DSWaylandPointerPrivate() +{ +} + +void DSWaylandPointerPrivate::pointer_bind_resource(Resource *resource) +{ +} + +void DSWaylandPointerPrivate::pointer_destroy_resource(Resource *resource) +{ +} + +void DSWaylandPointerPrivate::pointer_set_cursor(Resource *resource, uint32_t serial, struct ::wl_resource *surface, int32_t hotspot_x, int32_t hotspot_y) +{ +} + +void DSWaylandPointerPrivate::pointer_release(Resource *resource) +{ +} + +/* Begin Public Class Implementation */ +DSWaylandPointer::DSWaylandPointer(DSWaylandSeat *seat) + : DSObject(), _d_ptr(std::make_unique(seat, this)) +{ +} + +DSWaylandPointer::~DSWaylandPointer() +{ +} + +DSWaylandSeat *DSWaylandPointer::seat() +{ + DS_GET_PRIV(DSWaylandPointer); + + return priv->__seat; +} + +} \ No newline at end of file diff --git a/src/DSWaylandServer/DSWaylandPointer.h b/src/DSWaylandServer/DSWaylandPointer.h new file mode 100644 index 0000000..0a00f84 --- /dev/null +++ b/src/DSWaylandServer/DSWaylandPointer.h @@ -0,0 +1,31 @@ +#ifndef __DS_WAYLAND_POINTER_H__ +#define __DS_WAYLAND_POINTER_H__ + +#include "DSCore.h" +#include "DSObject.h" + +namespace display_server +{ + +class DSWaylandSeat; +class DSWaylandPointerPrivate; +class DS_DECL_EXPORT DSWaylandPointer : public DSObject +{ + DS_PIMPL_USE_PRIVATE(DSWaylandPointer); +public: + DSWaylandPointer(DSWaylandSeat *seat); + ~DSWaylandPointer() override; + + DSWaylandSeat *seat(); + + //TODO + +protected: + +private: + +}; + +} + +#endif //__DS_WAYLAND_POINTER_H__ diff --git a/src/DSWaylandServer/DSWaylandPointerPrivate.h b/src/DSWaylandServer/DSWaylandPointerPrivate.h new file mode 100644 index 0000000..deaa902 --- /dev/null +++ b/src/DSWaylandServer/DSWaylandPointerPrivate.h @@ -0,0 +1,35 @@ +#ifndef __DS_WAYLAND_POINTER_PRIVATE_H__ +#define __DS_WAYLAND_POINTER_PRIVATE_H__ + +#include "dswayland-server-wayland.h" + +#include "DSCore.h" +#include "DSObjectPrivate.h" + +namespace display_server +{ + +class DSWaylandSeat; +class DS_DECL_EXPORT DSWaylandPointerPrivate : public DSObjectPrivate, public DSWaylandServer::wl_pointer +{ + DS_PIMPL_USE_PUBLIC(DSWaylandPointer); +public: + DSWaylandPointerPrivate(DSWaylandSeat *seat, DSWaylandPointer *pointer); + ~DSWaylandPointerPrivate() override; + + //TODO + +protected: + //virtual Resource *pointer_allocate(); + void pointer_bind_resource(Resource *resource) override; + void pointer_destroy_resource(Resource *resource) override; + void pointer_set_cursor(Resource *resource, uint32_t serial, struct ::wl_resource *surface, int32_t hotspot_x, int32_t hotspot_y) override; + void pointer_release(Resource *resource) override; + +private: + DSWaylandSeat *__seat; +}; + +} + +#endif //__DS_WAYLAND_POINTER_PRIVATE_H__ diff --git a/src/DSWaylandServer/DSWaylandTouch.cpp b/src/DSWaylandServer/DSWaylandTouch.cpp new file mode 100644 index 0000000..f09a370 --- /dev/null +++ b/src/DSWaylandServer/DSWaylandTouch.cpp @@ -0,0 +1,47 @@ +#include "DSWaylandTouch.h" +#include "DSWaylandTouchPrivate.h" + +namespace display_server { + +/* Begin Private Class Implementation */ +DSWaylandTouchPrivate::DSWaylandTouchPrivate(DSWaylandSeat *seat, DSWaylandTouch *touch) + : DSObjectPrivate(touch), + __p_ptr(touch), + __seat(seat) +{ +} + +DSWaylandTouchPrivate::~DSWaylandTouchPrivate() +{ +} + +void DSWaylandTouchPrivate::touch_bind_resource(Resource *resource) +{ +} + +void DSWaylandTouchPrivate::touch_destroy_resource(Resource *resource) +{ +} + +void DSWaylandTouchPrivate::touch_release(Resource *resource) +{ +} + +/* Begin Public Class Implementation */ +DSWaylandTouch::DSWaylandTouch(DSWaylandSeat *seat) + : DSObject(), _d_ptr(std::make_unique(seat, this)) +{ +} + +DSWaylandTouch::~DSWaylandTouch() +{ +} + +DSWaylandSeat *DSWaylandTouch::seat() +{ + DS_GET_PRIV(DSWaylandTouch); + + return priv->__seat; +} + +} \ No newline at end of file diff --git a/src/DSWaylandServer/DSWaylandTouch.h b/src/DSWaylandServer/DSWaylandTouch.h new file mode 100644 index 0000000..60c645f --- /dev/null +++ b/src/DSWaylandServer/DSWaylandTouch.h @@ -0,0 +1,31 @@ +#ifndef __DS_WAYLAND_TOUCH_H__ +#define __DS_WAYLAND_TOUCH_H__ + +#include "DSCore.h" +#include "DSObject.h" + +namespace display_server +{ + +class DSWaylandSeat; +class DSWaylandTouchPrivate; +class DS_DECL_EXPORT DSWaylandTouch : public DSObject +{ + DS_PIMPL_USE_PRIVATE(DSWaylandTouch); +public: + DSWaylandTouch(DSWaylandSeat *seat); + ~DSWaylandTouch() override; + + DSWaylandSeat *seat(); + + //TODO + +protected: + +private: + +}; + +} + +#endif //__DS_WAYLAND_TOUCH_H__ diff --git a/src/DSWaylandServer/DSWaylandTouchPrivate.h b/src/DSWaylandServer/DSWaylandTouchPrivate.h new file mode 100644 index 0000000..3dd6031 --- /dev/null +++ b/src/DSWaylandServer/DSWaylandTouchPrivate.h @@ -0,0 +1,34 @@ +#ifndef __DS_WAYLAND_TOUCH_PRIVATE_H__ +#define __DS_WAYLAND_TOUCH_PRIVATE_H__ + +#include "dswayland-server-wayland.h" + +#include "DSCore.h" +#include "DSObjectPrivate.h" + +namespace display_server +{ + +class DSWaylandSeat; +class DS_DECL_EXPORT DSWaylandTouchPrivate : public DSObjectPrivate, public DSWaylandServer::wl_touch +{ + DS_PIMPL_USE_PUBLIC(DSWaylandTouch); +public: + DSWaylandTouchPrivate(DSWaylandSeat *seat, DSWaylandTouch *touch); + ~DSWaylandTouchPrivate() override; + + //TODO + +protected: + //virtual Resource *touch_allocate(); + virtual void touch_bind_resource(Resource *resource); + virtual void touch_destroy_resource(Resource *resource); + virtual void touch_release(Resource *resource); + +private: + DSWaylandSeat *__seat; +}; + +} + +#endif //__DS_WAYLAND_TOUCH_PRIVATE_H__ diff --git a/src/meson.build b/src/meson.build index 8a114d1..8ad9161 100644 --- a/src/meson.build +++ b/src/meson.build @@ -101,6 +101,15 @@ libds_wayland_srcs = [ 'DSWaylandServer/DSWaylandSeatPrivate.h', 'DSWaylandServer/DSWaylandSeat.h', 'DSWaylandServer/DSWaylandSeat.cpp', + 'DSWaylandServer/DSWaylandPointerPrivate.h', + 'DSWaylandServer/DSWaylandPointer.h', + 'DSWaylandServer/DSWaylandPointer.cpp', + 'DSWaylandServer/DSWaylandKeyboardPrivate.h', + 'DSWaylandServer/DSWaylandKeyboard.h', + 'DSWaylandServer/DSWaylandKeyboard.cpp', + 'DSWaylandServer/DSWaylandTouchPrivate.h', + 'DSWaylandServer/DSWaylandTouch.h', + 'DSWaylandServer/DSWaylandTouch.cpp', ] libds_srcs += libds_wayland_srcs diff --git a/tests/DSWaylandKeyboard-test.cpp b/tests/DSWaylandKeyboard-test.cpp new file mode 100644 index 0000000..4701297 --- /dev/null +++ b/tests/DSWaylandKeyboard-test.cpp @@ -0,0 +1,67 @@ +#include "libds-tests.h" +#include "DSWaylandKeyboard.h" +#include "DSWaylandSeat.h" + +using namespace display_server; + +class DSWaylandKeyboardTest : public ::testing::Test +{ +public: + void SetUp(void) override + { + } + void TearDown(void) override + { + } +}; + +/* Test cases */ +TEST_F(DSWaylandKeyboardTest, NewDSWaylandKeyboard) +{ + DSWaylandKeyboard *keyboard = new DSWaylandKeyboard(nullptr); + EXPECT_TRUE(keyboard != nullptr); + + if (keyboard) + delete keyboard; +} + +TEST_F(DSWaylandKeyboardTest, GetSeat) +{ + DSWaylandSeat *seat = new DSWaylandSeat(nullptr, DSWaylandSeat::capDefault); + EXPECT_TRUE(seat != nullptr); + + if (seat) + { + DSWaylandKeyboard *keyboard = new DSWaylandKeyboard(seat); + EXPECT_TRUE(keyboard != nullptr); + + if (keyboard) + { + EXPECT_TRUE(keyboard->seat() == seat); + + delete keyboard; + } + + delete seat; + } +} + +TEST_F(DSWaylandKeyboardTest, SetGetRepeatRateDelay) +{ + DSWaylandKeyboard *keyboard = new DSWaylandKeyboard(nullptr); + EXPECT_TRUE(keyboard != nullptr); + + if (keyboard) + { + uint32_t uRepeatRate = 25; + uint32_t uRepeatDelay = 400; + + keyboard->setRepeatRate(uRepeatRate); + EXPECT_TRUE(keyboard->repeatRate() == uRepeatRate); + + keyboard->setRepeatDelay(uRepeatDelay); + EXPECT_TRUE(keyboard->repeatDelay() == uRepeatDelay); + + delete keyboard; + } +} diff --git a/tests/DSWaylandPointer-test.cpp b/tests/DSWaylandPointer-test.cpp new file mode 100644 index 0000000..24281fd --- /dev/null +++ b/tests/DSWaylandPointer-test.cpp @@ -0,0 +1,47 @@ +#include "libds-tests.h" +#include "DSWaylandPointer.h" +#include "DSWaylandSeat.h" + +using namespace display_server; + +class DSWaylandPointerTest : public ::testing::Test +{ +public: + void SetUp(void) override + { + } + void TearDown(void) override + { + } +}; + +/* Test cases */ +TEST_F(DSWaylandPointerTest, NewDSWaylandPointer) +{ + DSWaylandPointer *pointer = new DSWaylandPointer(nullptr); + EXPECT_TRUE(pointer != nullptr); + + if (pointer) + delete pointer; +} + +TEST_F(DSWaylandPointerTest, GetSeat) +{ + DSWaylandSeat *seat = new DSWaylandSeat(nullptr, DSWaylandSeat::capDefault); + EXPECT_TRUE(seat != nullptr); + + if (seat) + { + DSWaylandPointer *pointer = new DSWaylandPointer(seat); + EXPECT_TRUE(pointer != nullptr); + + if (pointer) + { + EXPECT_TRUE(pointer->seat() == seat); + + delete pointer; + } + + delete seat; + } +} diff --git a/tests/DSWaylandTouch-test.cpp b/tests/DSWaylandTouch-test.cpp new file mode 100644 index 0000000..3fe8b85 --- /dev/null +++ b/tests/DSWaylandTouch-test.cpp @@ -0,0 +1,47 @@ +#include "libds-tests.h" +#include "DSWaylandTouch.h" +#include "DSWaylandSeat.h" + +using namespace display_server; + +class DSWaylandTouchTest : public ::testing::Test +{ +public: + void SetUp(void) override + { + } + void TearDown(void) override + { + } +}; + +/* Test cases */ +TEST_F(DSWaylandTouchTest, NewDSWaylandTouch) +{ + DSWaylandTouch *touch = new DSWaylandTouch(nullptr); + EXPECT_TRUE(touch != nullptr); + + if (touch) + delete touch; +} + +TEST_F(DSWaylandTouchTest, GetSeat) +{ + DSWaylandSeat *seat = new DSWaylandSeat(nullptr, DSWaylandSeat::capDefault); + EXPECT_TRUE(seat != nullptr); + + if (seat) + { + DSWaylandTouch *touch = new DSWaylandTouch(seat); + EXPECT_TRUE(touch != nullptr); + + if (touch) + { + EXPECT_TRUE(touch->seat() == seat); + + delete touch; + } + + delete seat; + } +} diff --git a/tests/meson.build b/tests/meson.build index 20ae0ed..cadcf19 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -30,6 +30,9 @@ libds_tests_srcs = [ 'DSWaylandCompositor-test.cpp', 'DSWaylandSeat-test.cpp', 'DSWaylandClient-test.cpp', + 'DSWaylandPointer-test.cpp', + 'DSWaylandKeyboard-test.cpp', + 'DSWaylandTouch-test.cpp', ] gmock_dep = dependency('gmock', method : 'pkg-config') -- 2.7.4 From 59d7e89f6efbdbaf6b9ade623402db56a0c8258f Mon Sep 17 00:00:00 2001 From: Doyoun Kang Date: Thu, 9 Jul 2020 17:11:22 +0000 Subject: [PATCH 10/16] DSWindow: add skeleton class Change-Id: I2e934f4536424a23ff4f47d5a5cf7430fe59476c --- src/DSWindow/DSWindow.cpp | 96 ++++++++++++++++++++++++++++++++++++++++ src/DSWindow/DSWindow.h | 42 ++++++++++++++++++ src/DSWindow/DSWindowPrivate.cpp | 82 ++++++++++++++++++++++++++++++++++ src/DSWindow/DSWindowPrivate.h | 38 ++++++++++++++++ src/meson.build | 3 ++ tests/DSWindow-test.cpp | 40 +++++++++++++++++ tests/meson.build | 1 + 7 files changed, 302 insertions(+) create mode 100644 src/DSWindow/DSWindow.cpp create mode 100644 src/DSWindow/DSWindow.h create mode 100644 src/DSWindow/DSWindowPrivate.cpp create mode 100644 src/DSWindow/DSWindowPrivate.h create mode 100644 tests/DSWindow-test.cpp diff --git a/src/DSWindow/DSWindow.cpp b/src/DSWindow/DSWindow.cpp new file mode 100644 index 0000000..5c2b797 --- /dev/null +++ b/src/DSWindow/DSWindow.cpp @@ -0,0 +1,96 @@ +#include "DSWindow.h" +#include "DSWindowPrivate.h" + +namespace display_server +{ + +DSWindow::DSWindow() + : DS_INIT_PRIVATE_PTR(DSWindow) +{} + +DSWindow::~DSWindow() +{} + +bool DSWindow::create(DSWindow *pParent) +{ + DS_GET_PRIV(DSWindow); + + if (priv->create(this, pParent) == false) + { + return false; + } + + return true; +} + +bool DSWindow::create(int x, int y, unsigned int w, unsigned int h, DSWindow *pParent) +{ + DS_GET_PRIV(DSWindow); + + if (priv->create(x, y, w, h, this, pParent) == false) + { + return false; + } + + return true; +} + +void DSWindow::destroy(void) +{ + DS_GET_PRIV(DSWindow); + + priv->destroy(); +} + +bool DSWindow::show(void) +{ + DS_GET_PRIV(DSWindow); + + return priv->show(); +} + +bool DSWindow::hide(bool autoFocus) +{ + DS_GET_PRIV(DSWindow); + + return priv->hide(autoFocus); +} + +int DSWindow::showState(void) +{ + DS_GET_PRIV(DSWindow); + + return priv->showState(); +} + + +bool DSWindow::setLayer(int layer) +{ + DS_GET_PRIV(DSWindow); + + return priv->setLayer(layer); +} + +bool DSWindow::raise(void) +{ + DS_GET_PRIV(DSWindow); + + return priv->raise(); +} + +bool DSWindow::lower(void) +{ + DS_GET_PRIV(DSWindow); + + return priv->lower(); +} + +bool DSWindow::setFocus(void) +{ + DS_GET_PRIV(DSWindow); + + return priv->setFocus(); +} + + +} // namespace display_server \ No newline at end of file diff --git a/src/DSWindow/DSWindow.h b/src/DSWindow/DSWindow.h new file mode 100644 index 0000000..cd59a0d --- /dev/null +++ b/src/DSWindow/DSWindow.h @@ -0,0 +1,42 @@ +#ifndef _DS_WINDOW_H_ +#define _DS_WINDOW_H_ + +#include "DSCore.h" +#include "DSObject.h" + +namespace display_server +{ + +class DSWindowPrivate; + +class DSWindow : public DSObject +{ + DS_PIMPL_USE_PRIVATE(DSWindow) + +public: + explicit DSWindow(); + virtual ~DSWindow(); + + bool create(DSWindow *pParent); + bool create(int x, int y, unsigned int w, unsigned int h, DSWindow *pParent); + + void destroy(void); + + bool show(void); + bool hide(bool autoFocus = true); + int showState(void); + + bool setLayer(int layer); + bool raise(void); + bool lower(void); + + bool setFocus(void); + +protected: + //virtual bool _onFocus(void); + //virtual bool _onShowStateChange(void); +}; + +} + +#endif // _DS_WINDOW_H_ \ No newline at end of file diff --git a/src/DSWindow/DSWindowPrivate.cpp b/src/DSWindow/DSWindowPrivate.cpp new file mode 100644 index 0000000..caa062a --- /dev/null +++ b/src/DSWindow/DSWindowPrivate.cpp @@ -0,0 +1,82 @@ +#include "DSWindow.h" +#include "DSWindowPrivate.h" + +namespace display_server +{ + +DSWindowPrivate::DSWindowPrivate(DSWindow *p_ptr) + : DSObjectPrivate(p_ptr), + __p_ptr(p_ptr) +{ +} + +DSWindowPrivate::~DSWindowPrivate() +{ +} + +bool DSWindowPrivate::create(DSWindow *pWin, DSWindow *pParent) +{ + int x = 0; + int y = 0; + unsigned int w = 1; + unsigned int h = 1; + + // get screen position (x, y) + + // get screen width (w, h) + + return __create(x, y, w, h, pWin, pParent); +} + +bool DSWindowPrivate::create(int x, int y, unsigned int w, unsigned int h, DSWindow *pWin, DSWindow *pParent) +{ + return __create(x, y, w, h, pWin, pParent); +} + +void DSWindowPrivate::destroy(void) +{ +} + +bool DSWindowPrivate::show(void) +{ + return true; +} + +bool DSWindowPrivate::hide(bool autoFocus) +{ + return true; +} + +int DSWindowPrivate::showState(void) +{ + return 0; +} + +bool DSWindowPrivate::setLayer(int layer) +{ + return true; +} + +bool DSWindowPrivate::raise(void) +{ + return true; +} + +bool DSWindowPrivate::lower(void) +{ + return true; +} + +bool DSWindowPrivate::setFocus(void) +{ + return true; +} + +bool DSWindowPrivate::__create(int x, int y, unsigned int w, unsigned int h, DSWindow *pWin, DSWindow *pParent) +{ + // Do something + + return true; +} + +} // namespace display_server \ No newline at end of file diff --git a/src/DSWindow/DSWindowPrivate.h b/src/DSWindow/DSWindowPrivate.h new file mode 100644 index 0000000..507cd56 --- /dev/null +++ b/src/DSWindow/DSWindowPrivate.h @@ -0,0 +1,38 @@ +#ifndef _DS_WINDOW_PRIVATE_H_ +#define _DS_WINDOW_PRIVATE_H_ + +namespace display_server +{ + +class DSWindowPrivate : public DSObjectPrivate +{ + DS_PIMPL_USE_PUBLIC(DSWindow) + +public: + DSWindowPrivate() = delete; + DSWindowPrivate(DSWindow *p_ptr); + ~DSWindowPrivate(); + + bool create(DSWindow *pWin, DSWindow *pParent); + bool create(int x, int y, unsigned int w, unsigned int h, DSWindow *pWin, DSWindow *pParent); + + void destroy(void); + + bool show(void); + bool hide(bool autoFocus); + int showState(void); + + bool setLayer(int layer); + bool raise(void); + bool lower(void); + + bool setFocus(void); + +private: + bool __create(int x, int y, unsigned int w, unsigned int h, DSWindow *pWin, DSWindow *pParent); + +}; + +} + +#endif // _DS_WINDOW_PRIVATE_H_ \ No newline at end of file diff --git a/src/meson.build b/src/meson.build index 8ad9161..923c788 100644 --- a/src/meson.build +++ b/src/meson.build @@ -45,6 +45,8 @@ libds_srcs = [ 'DSSignal/DSSignal.cpp', 'DSSignal/DSSignal.h', 'DSCore/DSCore.h', + 'DSWindow/DSWindow.cpp', + 'DSWindow/DSWindowPrivate.cpp', ] libds_wayland_srcs = [ @@ -161,6 +163,7 @@ libds_include_dirs = include_directories( './DSSignal', './DSCore', './DSWaylandServer', + './DSWindow', ) libds_lib = shared_library( diff --git a/tests/DSWindow-test.cpp b/tests/DSWindow-test.cpp new file mode 100644 index 0000000..07b41fe --- /dev/null +++ b/tests/DSWindow-test.cpp @@ -0,0 +1,40 @@ +#include "libds-tests.h" +#include "DSObject.h" +#include "DSWindow.h" + +using namespace display_server; + +class DSWindowTest : public ::testing::Test +{ +public: + void SetUp(void) override + {} + void TearDown(void) override + {} +}; + +TEST_F(DSWindowTest, NewDSWindow) +{ + std::unique_ptr Window = std::make_unique(); + EXPECT_TRUE(Window != nullptr); +} + +TEST_F(DSWindowTest, BasicMethods) +{ + std::unique_ptr Window = std::make_unique(); + EXPECT_TRUE(Window != nullptr); + + EXPECT_TRUE(Window->create(nullptr) == true); + EXPECT_TRUE(Window->create(0, 0, 720, 1280, nullptr) == true); + + EXPECT_TRUE(Window->show() == true); + EXPECT_TRUE(Window->hide(true) == true); + EXPECT_TRUE(Window->showState() == 0); + + EXPECT_TRUE(Window->setLayer(100) == true); + + EXPECT_TRUE(Window->raise() == true); + EXPECT_TRUE(Window->lower() == true); + + EXPECT_TRUE(Window->setFocus() == true); +} \ No newline at end of file diff --git a/tests/meson.build b/tests/meson.build index cadcf19..6e4ecfd 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -15,6 +15,7 @@ libds_tests_srcs = [ 'DSDebugLog-test.cpp', 'DSDisplayDeviceTDMImpl-test.cpp', 'DSSignal-test.cpp', + 'DSWindow-test.cpp', 'DSWaylandCallback-test.cpp', 'DSWaylandOutput-test.cpp', 'DSWaylandSurface-test.cpp', -- 2.7.4 From f2b192a89338086f99be00678d5acbd978c1bdd7 Mon Sep 17 00:00:00 2001 From: Sung-Jin Park Date: Fri, 10 Jul 2020 20:08:43 +0900 Subject: [PATCH 11/16] DSCompositor: initialize wayland display and input in run() Change-Id: Ica38577e8dbffe3645d991e07894c4e78c9a3e95 Signed-off-by: Sung-Jin Park --- src/DSCompositor/DSCompositor.cpp | 23 ++++++++++++++++++++++- src/DSCompositor/DSCompositorPrivate.h | 8 ++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/DSCompositor/DSCompositor.cpp b/src/DSCompositor/DSCompositor.cpp index 6bbbfda..89a24f4 100644 --- a/src/DSCompositor/DSCompositor.cpp +++ b/src/DSCompositor/DSCompositor.cpp @@ -1,8 +1,12 @@ +#include "DSCore.h" #include "DSCompositor.h" #include "DSCompositorPrivate.h" #include "DSDebugLog.h" #include "DSDisplayDeviceTDMImpl.h" #include "DSOutputImpl.h" +#include "DSSeat.h" +#include "DSInput.h" +#include "DSWaylandCompositor.h" #include namespace display_server @@ -46,16 +50,22 @@ DSCompositorPrivate::DSCompositorPrivate(DSCompositor *p_ptr) { __eventLoop = std::make_unique(); + __wlCompositor = std::make_unique(new DSObject); __displayDevice = std::make_unique(); + __seat = std::make_unique(); + __input = std::make_shared(); } DSCompositorPrivate::~DSCompositorPrivate() -{} +{ +} bool DSCompositorPrivate::run() { DS_GET_PUB(DSCompositor); + __initializeWlDisplay(); + __initializeInput(); __initializeOutputs(); pub->_onInitialized(); if (!__eventLoop->run()) { @@ -76,6 +86,17 @@ bool DSCompositorPrivate::quit() return true; } +void DSCompositorPrivate::__initializeWlDisplay() +{ + __wlCompositor->create(); +} + +void DSCompositorPrivate::__initializeInput() +{ + __seat->addInput(__input); + __input->Init(); +} + void DSCompositorPrivate::__initializeOutputs() { DS_GET_PUB(DSCompositor); diff --git a/src/DSCompositor/DSCompositorPrivate.h b/src/DSCompositor/DSCompositorPrivate.h index e6875d2..2e266e6 100644 --- a/src/DSCompositor/DSCompositorPrivate.h +++ b/src/DSCompositor/DSCompositorPrivate.h @@ -9,6 +9,9 @@ namespace display_server { +class DSSeat; +class DSInput; +class DSWaylandCompositor; class DSCompositorPrivate : public DSObjectPrivate { DS_PIMPL_USE_PUBLIC(DSCompositor); @@ -25,8 +28,13 @@ protected: private: std::unique_ptr __eventLoop; std::unique_ptr __displayDevice; + std::unique_ptr __seat; + std::shared_ptr __input; + std::unique_ptr __wlCompositor; std::list> __outputList; + void __initializeWlDisplay(); + void __initializeInput(); void __initializeOutputs(); }; -- 2.7.4 From b02fecfb9430b97ba9f72f8f09347a005b1d66cd Mon Sep 17 00:00:00 2001 From: jeon Date: Mon, 13 Jul 2020 17:32:57 +0900 Subject: [PATCH 12/16] DSInput: initialize values to nullptr Change-Id: If8d113b7d04dcc03fbf5fc6481030317b5268afc --- src/DSInput/DSInput.cpp | 3 ++- src/DSInput/DSLibinput.cpp | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/DSInput/DSInput.cpp b/src/DSInput/DSInput.cpp index b59361f..8cec16c 100644 --- a/src/DSInput/DSInput.cpp +++ b/src/DSInput/DSInput.cpp @@ -6,7 +6,8 @@ namespace display_server DSInputPrivate::DSInputPrivate(DSInput * p_ptr) : DSObjectPrivate(p_ptr), - __p_ptr(p_ptr) + __p_ptr(p_ptr), + __dsLibinput(nullptr) { } diff --git a/src/DSInput/DSLibinput.cpp b/src/DSInput/DSLibinput.cpp index 2515654..6dbc195 100644 --- a/src/DSInput/DSLibinput.cpp +++ b/src/DSInput/DSLibinput.cpp @@ -12,16 +12,26 @@ const struct ::libinput_interface DSLibinput::__input_interface = { }; DSLibinput::DSLibinput(DSInputPrivate *p_ptr) + : __udev(nullptr), + __libinput(nullptr), + __libinput_handler(nullptr) { inputPrivate = p_ptr; ecore_init(); __udev = udev_new(); + DS_ASSERT(__udev); __libinput = libinput_udev_create_context(&__input_interface, this, __udev); + if (!__libinput) + { + udev_unref(__udev); + DS_ASSERT(false); + } if (libinput_udev_assign_seat(__libinput, "seat0")) { libinput_unref(__libinput); udev_unref(__udev); + DS_ASSERT(false); } __fd = libinput_get_fd(__libinput); @@ -35,6 +45,7 @@ DSLibinput::~DSLibinput() if (__libinput_handler) { ecore_main_fd_handler_del(__libinput_handler); + __libinput_handler = nullptr; } ecore_shutdown(); libinput_unref(__libinput); -- 2.7.4 From b45f40ef121093e7256e7fbe20c31ff078eaae0a Mon Sep 17 00:00:00 2001 From: jeon Date: Mon, 13 Jul 2020 16:23:21 +0900 Subject: [PATCH 13/16] DSInput-test: add DSInput DeviceAdd/Remove slot test Change-Id: I8c327eba437b3735a89cb4883be08f20c43f00d0 --- tests/DSInput-test.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/tests/DSInput-test.cpp b/tests/DSInput-test.cpp index 28aecb6..75c4aaf 100644 --- a/tests/DSInput-test.cpp +++ b/tests/DSInput-test.cpp @@ -12,6 +12,29 @@ public: {} }; +class MockInput : public DSObject +{ +public: + MockInput() + : device(std::make_shared("None", "None", DSInput::NoneClass, DSInput::NoneSubclass)) + {} + ~MockInput() + {} + + void slotDeviceAdded(std::shared_ptr device) { + this->device.reset(); + this->device = device; + } + + void slotDeviceRemoved(std::shared_ptr device) { + this->device.reset(); + this->device = device; + } + + std::shared_ptr device; +}; + + TEST_F(DSInputTest, NewDSInput) { DSInput *input = new DSInput; @@ -19,13 +42,49 @@ TEST_F(DSInputTest, NewDSInput) ASSERT_TRUE(true); } -TEST_F(DSInputTest, BasicMethods) +TEST_F(DSInputTest, DSInputInit) { - DSInput input; + DSInput *input = new DSInput; + + input->Init(); + delete input; EXPECT_TRUE(true); } +TEST_F(DSInputTest, DSInputDeviceAddedRemoved) +{ + DSInput *input = new DSInput; + DSInputDevice *device = new DSInputDevice("MockTestDevice", "MockTest", DSInput::KeyboardClass, DSInput::NoneSubclass); + MockInput *mockInput = new MockInput; + MockInput *mockInput2 = new MockInput; + + input->Init(); + + input->registerCallbackDeviceAdd(mockInput, std::bind(&MockInput::slotDeviceAdded, mockInput, std::placeholders::_1)); + input->deviceAdd(device->getName(), device->getIdentifier(), device->getClass(), device->getSubclass()); + EXPECT_TRUE(*(mockInput->device.get()) == *device); + + input->registerCallbackDeviceAdd(mockInput2, std::bind(&MockInput::slotDeviceAdded, mockInput2, std::placeholders::_1)); + input->deviceAdd(device->getName(), device->getIdentifier(), device->getClass(), device->getSubclass()); + EXPECT_FALSE(*(mockInput2->device.get()) == *device); + + input->registerCallbackDeviceRemove(mockInput, std::bind(&MockInput::slotDeviceRemoved, mockInput, std::placeholders::_1)); + input->deviceRemove(device->getName(), device->getIdentifier(), device->getClass(), device->getSubclass()); + EXPECT_TRUE(*(mockInput->device.get()) == *device); + + input->registerCallbackDeviceRemove(mockInput2, std::bind(&MockInput::slotDeviceRemoved, mockInput2, std::placeholders::_1)); + input->deviceRemove(device->getName(), device->getIdentifier(), device->getClass(), device->getSubclass()); + + EXPECT_FALSE(*(mockInput2->device.get()) == *device); + + delete mockInput2; + delete mockInput; + delete device; + delete input; +} + + class DSInputDeviceTest : public ::testing::Test { public: -- 2.7.4 From d43fc0670f81798fbc6a06ebc46fdb17cf664770 Mon Sep 17 00:00:00 2001 From: jeon Date: Mon, 13 Jul 2020 19:08:39 +0900 Subject: [PATCH 14/16] DSInput: code refactoring - re-order private value initialize in constructor - remove initialize in destructor Change-Id: I24ca6c12002f73a47f827b0e99467cf1d35866b1 --- src/DSInput/DSLibinput.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/DSInput/DSLibinput.cpp b/src/DSInput/DSLibinput.cpp index 6dbc195..d766da3 100644 --- a/src/DSInput/DSLibinput.cpp +++ b/src/DSInput/DSLibinput.cpp @@ -12,8 +12,8 @@ const struct ::libinput_interface DSLibinput::__input_interface = { }; DSLibinput::DSLibinput(DSInputPrivate *p_ptr) - : __udev(nullptr), - __libinput(nullptr), + : __libinput(nullptr), + __udev(nullptr), __libinput_handler(nullptr) { inputPrivate = p_ptr; @@ -45,7 +45,6 @@ DSLibinput::~DSLibinput() if (__libinput_handler) { ecore_main_fd_handler_del(__libinput_handler); - __libinput_handler = nullptr; } ecore_shutdown(); libinput_unref(__libinput); -- 2.7.4 From 4bfbfb8437849e03ee796206cb7cc3fa693e0089 Mon Sep 17 00:00:00 2001 From: Sung-Jin Park Date: Mon, 13 Jul 2020 19:38:21 +0900 Subject: [PATCH 15/16] DSWaylandClient: add client destroy handler Change-Id: I99479e64432a1e5a80ce58dc8f3b79efb1fd85be Signed-off-by: Sung-Jin Park --- src/DSWaylandServer/DSWaylandClient.cpp | 48 ++++++++++++++++++++++------ src/DSWaylandServer/DSWaylandClient.h | 2 +- src/DSWaylandServer/DSWaylandClientPrivate.h | 10 ++++-- 3 files changed, 48 insertions(+), 12 deletions(-) diff --git a/src/DSWaylandServer/DSWaylandClient.cpp b/src/DSWaylandServer/DSWaylandClient.cpp index 8b8b231..76c3445 100644 --- a/src/DSWaylandServer/DSWaylandClient.cpp +++ b/src/DSWaylandServer/DSWaylandClient.cpp @@ -1,8 +1,7 @@ - #include "DSWaylandClient.h" #include "DSWaylandClientPrivate.h" - -#include +#include "DSWaylandCompositor.h" +#include "DSDebugLog.h" namespace display_server { @@ -23,8 +22,24 @@ DSWaylandClientPrivate::~DSWaylandClientPrivate() { } +void DSWaylandClientPrivate::client_destroy_callback(struct ::wl_listener *listener, void *data) +{ + struct ::wl_client *wlClient = (struct ::wl_client *)data; + + (void) wlClient; + + DSWaylandClient *client = reinterpret_cast(listener)->parent; + if (client != nullptr) + { + DSLOG_INF("DSWaylandClientPrivate", "Client is going to be destoryed ! (pid:%d, uid:%d, gid:%d)", + client->pid(), client->uid(), client->gid()); + + delete client; + } +} + /* Begin Public Class Implementation */ -DSWaylandClient::DSWaylandClient(DSWaylandCompositor *compositor, wl_client *wlClient) +DSWaylandClient::DSWaylandClient(DSWaylandCompositor *compositor, struct ::wl_client *wlClient) : DSObject(), _d_ptr(std::make_unique(compositor, this)) { @@ -42,6 +57,12 @@ DSWaylandClient::DSWaylandClient(DSWaylandCompositor *compositor, wl_client *wlC priv->__uid = uid; priv->__gid = gid; priv->__client = wlClient; + + priv->m_clientDestroyListener.parent = this; + priv->m_clientDestroyListener.notify = DSWaylandClientPrivate::client_destroy_callback; + wl_client_add_destroy_listener(wlClient, &priv->m_clientDestroyListener); + + //compositor->addClient(this); } else { @@ -49,16 +70,25 @@ DSWaylandClient::DSWaylandClient(DSWaylandCompositor *compositor, wl_client *wlC priv->__uid = 0; priv->__gid = 0; priv->__client = nullptr; - } - //TODO : add client destroyed listener - //TODO : call get_compositor()->addClient(this); + DSLOG_ERR("DSWaylandClient", "wlClient is invalid."); + } } DSWaylandClient::~DSWaylandClient() { - //TODO : remove client destroy listener link - //TODO : call get_compositor()->removeClient(this); + DS_GET_PRIV(DSWaylandClient); + + if (priv->__client) + { + wl_list_remove(&priv->m_clientDestroyListener.link); + } + else + { + DSLOG_ERR("DSWaylandClient", "wlClient is invalid."); + } + + //getCompositor()->removeClient(this); } DSWaylandClient *DSWaylandClient::fromWlClient(wl_client *wlClient) diff --git a/src/DSWaylandServer/DSWaylandClient.h b/src/DSWaylandServer/DSWaylandClient.h index 0215f47..007ea6e 100644 --- a/src/DSWaylandServer/DSWaylandClient.h +++ b/src/DSWaylandServer/DSWaylandClient.h @@ -15,7 +15,7 @@ class DS_DECL_EXPORT DSWaylandClient : public DSObject { DS_PIMPL_USE_PRIVATE(DSWaylandClient); public: - DSWaylandClient(DSWaylandCompositor *compositor, wl_client *wlClient); + DSWaylandClient(DSWaylandCompositor *compositor, struct ::wl_client *wlClient); ~DSWaylandClient() override; static DSWaylandClient *fromWlClient(wl_client *wlClient); diff --git a/src/DSWaylandServer/DSWaylandClientPrivate.h b/src/DSWaylandServer/DSWaylandClientPrivate.h index 4228a2a..d5f5a74 100644 --- a/src/DSWaylandServer/DSWaylandClientPrivate.h +++ b/src/DSWaylandServer/DSWaylandClientPrivate.h @@ -4,9 +4,12 @@ #include "DSCore.h" #include "DSObjectPrivate.h" +#include + namespace display_server { +class DSWaylandClient; class DSWaylandCompositor; class DS_DECL_EXPORT DSWaylandClientPrivate : public DSObjectPrivate { @@ -15,8 +18,11 @@ public: DSWaylandClientPrivate(DSWaylandCompositor *compositor, DSWaylandClient *client); ~DSWaylandClientPrivate() override; - //TODO : add listener for client destroyed - //TODO + static void client_destroy_callback(struct ::wl_listener *listener, void *data); + struct ClientDestroyListener : ::wl_listener{ + DSWaylandClient *parent = nullptr; + }; + ClientDestroyListener m_clientDestroyListener; protected: -- 2.7.4 From 134ccb8aef3bfdbb401eae6ee5dc1c1d701edfbd Mon Sep 17 00:00:00 2001 From: Sung-Jin Park Date: Mon, 13 Jul 2020 21:38:43 +0900 Subject: [PATCH 16/16] DSWaylandCompositor: add client created handler Change-Id: Id03e8f7ef21ed93cef4327f9d6e85e03465089b8 Signed-off-by: Sung-Jin Park --- src/DSWaylandServer/DSWaylandCompositor.cpp | 28 ++++++++++++++++++++---- src/DSWaylandServer/DSWaylandCompositorPrivate.h | 16 ++++++++++---- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/DSWaylandServer/DSWaylandCompositor.cpp b/src/DSWaylandServer/DSWaylandCompositor.cpp index 9832e50..49e1eac 100644 --- a/src/DSWaylandServer/DSWaylandCompositor.cpp +++ b/src/DSWaylandServer/DSWaylandCompositor.cpp @@ -1,5 +1,6 @@ #include "DSWaylandCompositor.h" #include "DSWaylandCompositorPrivate.h" +#include "DSWaylandClient.h" #include "DSDebugLog.h" namespace display_server @@ -26,15 +27,16 @@ DSWaylandCompositorPrivate::DSWaylandCompositorPrivate(DSWaylandCompositor *comp _display = wl_display_create(); DS_ASSERT(_display != nullptr); - //TODO : add listener for client creation using wl_display_add_client_created_listener() - //TODO : leave log (log system needed) - //TODO + m_clientCreatedListener.notify = DSWaylandCompositorPrivate::client_created_callback; + m_clientCreatedListener.parent = this; + wl_display_add_client_created_listener(_display, &m_clientCreatedListener); } DSWaylandCompositorPrivate::~DSWaylandCompositorPrivate() { //TODO : destroy all allocated resources - //TODO : remove listener link (installed for checking client creation) + + wl_list_remove(&m_clientCreatedListener.link); _clients.clear(); _seats.clear(); @@ -62,6 +64,24 @@ DSWaylandCompositorPrivate::~DSWaylandCompositorPrivate() ecore_shutdown(); } +void DSWaylandCompositorPrivate::client_created_callback(struct ::wl_listener *listener, void *data) +{ + struct ::wl_client *wlClient = (struct ::wl_client *)data; + DS_ASSERT(wlClient != nullptr); + + DSWaylandClient *client = nullptr; + DSWaylandCompositorPrivate *compPriv = reinterpret_cast(listener)->parent; + + if (compPriv != nullptr) + { + client = new DSWaylandClient(compPriv->_compositor, wlClient); + DS_ASSERT(client != nullptr); + + DSLOG_INF("DSWaylandCompositorPrivate", "Client created ! (pid:%d, uid:%d, gid:%d)", + client->pid(), client->uid(), client->gid()); + } +} + void DSWaylandCompositorPrivate::initSocket(std::string sName, std::string sDir) { std::string socketPath = std::move(sDir); diff --git a/src/DSWaylandServer/DSWaylandCompositorPrivate.h b/src/DSWaylandServer/DSWaylandCompositorPrivate.h index e55529d..0cce28d 100644 --- a/src/DSWaylandServer/DSWaylandCompositorPrivate.h +++ b/src/DSWaylandServer/DSWaylandCompositorPrivate.h @@ -4,7 +4,10 @@ #include "DSCore.h" #include "DSObjectPrivate.h" #include "dswayland-server-wayland.h" +#include "DSWaylandClient.h" +#include "DSDebugLog.h" +#include #include namespace display_server @@ -27,8 +30,11 @@ public: inline void addSeat(DSWaylandSeat *seat); inline void removeSeat(DSWaylandSeat *seat); - //TODO : add listener for client created event - //TODO + static void client_created_callback(struct ::wl_listener *listener, void *data); + struct ClientCreatedListener : ::wl_listener { + DSWaylandCompositorPrivate *parent; + }; + ClientCreatedListener m_clientCreatedListener; protected: //virtual Resource *compositor_allocate(); @@ -59,17 +65,19 @@ private: void DSWaylandCompositorPrivate::addClient(DSWaylandClient *client) { DS_ASSERT(client != nullptr); - + //TODO : check if the client is in clients already ? _clients.push_back(client); + DSLOG_INF("DSWaylandCompositorPrivate", "Client(%p, PID:%d) has been added.", client, client->pid()); } void DSWaylandCompositorPrivate::removeClient(DSWaylandClient *client) { DS_ASSERT(client != nullptr); - + //TODO : check if the client is in clients already ? _clients.remove(client); + DSLOG_INF("DSWaylandCompositorPrivate", "Client(%p, PID:%d) has been removed.", client, client->pid()); } void DSWaylandCompositorPrivate::addSeat(DSWaylandSeat *seat) -- 2.7.4