From 14e855c87e84e0cdedda56ea630f6af180db83e3 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Fri, 3 Jul 2020 17:22:38 +0900 Subject: [PATCH 01/16] DSDisplayDevice: add the IDSDisplayDeviceOutputMode Change-Id: I9b304b8d976bd169603499c76122e087d6852647 --- .../DSDisplayDeviceOutputModeTDMImpl.cpp | 42 ++++++++++++++++++++++ .../DSDisplayDeviceOutputModeTDMImpl.h | 29 +++++++++++++++ .../DSDisplayDeviceOutputTDMImpl.cpp | 41 ++++++++++----------- src/DSDisplayDevice/DSDisplayDeviceOutputTDMImpl.h | 18 ++++++---- src/DSDisplayDevice/IDSDisplayDeviceOutput.h | 40 +++++++++------------ src/DSDisplayDevice/IDSDisplayDeviceOutputMode.h | 22 ++++++++++++ src/meson.build | 1 + tests/DSDisplayDeviceTDMImpl-test.cpp | 42 +++++----------------- 8 files changed, 150 insertions(+), 85 deletions(-) create mode 100644 src/DSDisplayDevice/DSDisplayDeviceOutputModeTDMImpl.cpp create mode 100644 src/DSDisplayDevice/DSDisplayDeviceOutputModeTDMImpl.h create mode 100644 src/DSDisplayDevice/IDSDisplayDeviceOutputMode.h diff --git a/src/DSDisplayDevice/DSDisplayDeviceOutputModeTDMImpl.cpp b/src/DSDisplayDevice/DSDisplayDeviceOutputModeTDMImpl.cpp new file mode 100644 index 0000000..371c4d3 --- /dev/null +++ b/src/DSDisplayDevice/DSDisplayDeviceOutputModeTDMImpl.cpp @@ -0,0 +1,42 @@ + +#include "DSDisplayDeviceOutputModeTDMImpl.h" +#include "DSDebugLog.h" + +namespace display_server +{ + +DSDisplayDeviceOutputModeTDMImpl::DSDisplayDeviceOutputModeTDMImpl(const tdm_output_mode *tmode) + : __tmode{tmode} +{} + +DSDisplayDeviceOutputModeTDMImpl::~DSDisplayDeviceOutputModeTDMImpl() +{} + +unsigned int DSDisplayDeviceOutputModeTDMImpl::getRefreshRate() +{ + return __tmode->vrefresh; +} + +unsigned int DSDisplayDeviceOutputModeTDMImpl::getHorizontalSize() +{ + return __tmode->hdisplay; +} + +unsigned int DSDisplayDeviceOutputModeTDMImpl::getVertialSize() +{ + return __tmode->vdisplay; +} + +std::string DSDisplayDeviceOutputModeTDMImpl::getName() +{ + std::string name(__tmode->name); + + return name; +} + +const tdm_output_mode *DSDisplayDeviceOutputModeTDMImpl::getNative() +{ + return __tmode; +} + +} diff --git a/src/DSDisplayDevice/DSDisplayDeviceOutputModeTDMImpl.h b/src/DSDisplayDevice/DSDisplayDeviceOutputModeTDMImpl.h new file mode 100644 index 0000000..5606b8c --- /dev/null +++ b/src/DSDisplayDevice/DSDisplayDeviceOutputModeTDMImpl.h @@ -0,0 +1,29 @@ +#ifndef __DS_DISPLAY_DEVICE_OUTPUT_MODE_TDM_IMPL_H__ +#define __DS_DISPLAY_DEVICE_OUTPUT_MODE_TDM_IMPL_H__ + +#include "IDSDisplayDeviceOutputMode.h" +#include + +namespace display_server +{ + +class DSDisplayDeviceOutputModeTDMImpl : public IDSDisplayDeviceOutputMode +{ +public: + DSDisplayDeviceOutputModeTDMImpl(const tdm_output_mode *tmode); + ~DSDisplayDeviceOutputModeTDMImpl(); + + unsigned int getRefreshRate() override; + unsigned int getHorizontalSize() override; + unsigned int getVertialSize() override; + std::string getName() override; + + const tdm_output_mode *getNative(); + +private: + const tdm_output_mode *__tmode; +}; + +} + +#endif \ No newline at end of file diff --git a/src/DSDisplayDevice/DSDisplayDeviceOutputTDMImpl.cpp b/src/DSDisplayDevice/DSDisplayDeviceOutputTDMImpl.cpp index ed1e9c9..21d1e3e 100644 --- a/src/DSDisplayDevice/DSDisplayDeviceOutputTDMImpl.cpp +++ b/src/DSDisplayDevice/DSDisplayDeviceOutputTDMImpl.cpp @@ -1,5 +1,6 @@ #include "DSDisplayDeviceOutputTDMImpl.h" #include "DSDisplayDeviceHWCTDMImpl.h" +#include "DSDisplayDeviceOutputModeTDMImpl.h" #include "DSDebugLog.h" #include @@ -12,7 +13,7 @@ DSDisplayDeviceOutputTDMImpl::DSDisplayDeviceOutputTDMImpl() __resolutionHeight(0), __physicalMMWidth(0), __physicalMMHeight(0), - __mode(nullptr), + __outputMode(nullptr), __dpmsMode(IDSDisplayDeviceOutput::DPMS_OFF), __displayDeviceHWC(nullptr) { @@ -26,7 +27,7 @@ DSDisplayDeviceOutputTDMImpl::DSDisplayDeviceOutputTDMImpl(tdm_output *toutput) __resolutionHeight(0), __physicalMMWidth(0), __physicalMMHeight(0), - __mode(nullptr), + __outputMode(nullptr), __dpmsMode(IDSDisplayDeviceOutput::DPMS_OFF), __displayDeviceHWC(nullptr) { @@ -64,7 +65,7 @@ IDSDisplayDeviceOutput::ConnectState DSDisplayDeviceOutputTDMImpl::getConnectSta return __connectState; } -std::list DSDisplayDeviceOutputTDMImpl::getAvailableModes() +std::list> DSDisplayDeviceOutputTDMImpl::getAvailableModes() { return __availableModeList; } @@ -89,10 +90,11 @@ int DSDisplayDeviceOutputTDMImpl::getPhysicalMMHeight() return __physicalMMHeight; } -bool DSDisplayDeviceOutputTDMImpl::setMode(DSDisplayDeviceOutputMode *mode) +bool DSDisplayDeviceOutputTDMImpl::setMode(std::shared_ptr outputMode) { tdm_error terror; - const tdm_output_mode *ttmode = (tdm_output_mode *)mode->private_mode; + auto outputModeTDM = std::dynamic_pointer_cast(outputMode); // down-casting of std::shared_ptr + const tdm_output_mode *ttmode = outputModeTDM->getNative(); terror = tdm_output_set_mode(__toutput, ttmode); if (terror != TDM_ERROR_NONE) { @@ -100,14 +102,14 @@ bool DSDisplayDeviceOutputTDMImpl::setMode(DSDisplayDeviceOutputMode *mode) return false; } - __mode = mode; + __outputMode = outputMode; return true; } -DSDisplayDeviceOutputMode *DSDisplayDeviceOutputTDMImpl::getMode() +std::shared_ptr DSDisplayDeviceOutputTDMImpl::getMode() { - return __mode; + return __outputMode; } bool DSDisplayDeviceOutputTDMImpl::setDPMSMode(DPMSMode dpmsMode) @@ -210,9 +212,6 @@ void DSDisplayDeviceOutputTDMImpl::__updatePhysicalMMSize() void DSDisplayDeviceOutputTDMImpl::__deleteAvailableModeList() { - for (auto mode : __availableModeList) { - delete mode; - } __availableModeList.clear(); } @@ -221,7 +220,6 @@ void DSDisplayDeviceOutputTDMImpl::__updateAvailableModeList() tdm_error terror; const tdm_output_mode *tmodes, *tmode; int count = 0; - DSDisplayDeviceOutputMode *outputMode; // delete the existing availableModeList. __deleteAvailableModeList(); @@ -233,18 +231,17 @@ void DSDisplayDeviceOutputTDMImpl::__updateAvailableModeList() } for (int i = 0; i < count; i++) { - outputMode = new DSDisplayDeviceOutputMode(); - if (outputMode == nullptr) { - DSLOG_ERR("TDM OUTPUT", "allocation of outputMode fails.\n"); - break; - } - tmode = &tmodes[i]; - memcpy(outputMode, tmode, (size_t)sizeof(tmode)); - outputMode->private_mode = (void *)tmode; - - __availableModeList.push_back(outputMode); + __availableModeList.push_back(std::make_shared(tmode)); } + + auto sortBestModeFunc = [](auto first, auto second) -> bool { + unsigned int firstPrio = first->getRefreshRate() * first->getHorizontalSize() * first->getVertialSize(); + unsigned int secondPrio = second->getRefreshRate() * second->getHorizontalSize() * second->getVertialSize(); + return firstPrio < secondPrio; + }; + + __availableModeList.sort(sortBestModeFunc); } void DSDisplayDeviceOutputTDMImpl::registerCallbackOutputConnected(DSObject *slot, std::function)> func) diff --git a/src/DSDisplayDevice/DSDisplayDeviceOutputTDMImpl.h b/src/DSDisplayDevice/DSDisplayDeviceOutputTDMImpl.h index 7baf670..36cebfe 100644 --- a/src/DSDisplayDevice/DSDisplayDeviceOutputTDMImpl.h +++ b/src/DSDisplayDevice/DSDisplayDeviceOutputTDMImpl.h @@ -16,16 +16,20 @@ public: ~DSDisplayDeviceOutputTDMImpl(); IDSDisplayDeviceOutput::ConnectorType getConnectType() override; - IDSDisplayDeviceOutput::ConnectState getConnectState() override; - std::list getAvailableModes() override; + IDSDisplayDeviceOutput::ConnectState getConnectState() override; + int getResolutionWidth() override; int getResolutionHeight() override; int getPhysicalMMWidth() override; int getPhysicalMMHeight() override; - bool setMode(DSDisplayDeviceOutputMode *mode) override; - DSDisplayDeviceOutputMode *getMode() override; - bool setDPMSMode(IDSDisplayDeviceOutput::DPMSMode dpmsMode) override; + + std::list> getAvailableModes() override; + bool setMode(std::shared_ptr outputMode) override; + std::shared_ptr getMode() override; + + bool setDPMSMode(IDSDisplayDeviceOutput::DPMSMode dpmsMode) override; DPMSMode getDPMSMode() override; + std::shared_ptr getHWC() override; // register callback functions @@ -49,10 +53,10 @@ private: IDSDisplayDeviceOutput::ConnectState __connectState; IDSDisplayDeviceOutput::ConnectorType __connectorType; - std::list __availableModeList; + std::list> __availableModeList; unsigned int __resolutionWidth, __resolutionHeight; unsigned int __physicalMMWidth, __physicalMMHeight; - DSDisplayDeviceOutputMode *__mode; + std::shared_ptr __outputMode; IDSDisplayDeviceOutput::DPMSMode __dpmsMode; std::shared_ptr __displayDeviceHWC; diff --git a/src/DSDisplayDevice/IDSDisplayDeviceOutput.h b/src/DSDisplayDevice/IDSDisplayDeviceOutput.h index 2da0ca6..766bb9d 100644 --- a/src/DSDisplayDevice/IDSDisplayDeviceOutput.h +++ b/src/DSDisplayDevice/IDSDisplayDeviceOutput.h @@ -3,6 +3,7 @@ #include "DSObject.h" #include "IDSDisplayDeviceHWC.h" +#include "IDSDisplayDeviceOutputMode.h" #include #include #include @@ -12,17 +13,6 @@ namespace display_server { -typedef struct _DSDisplayDeviceOutputMode { - unsigned int clock; - unsigned int hdisplay, hsync_start, hsync_end, htotal, hskew; - unsigned int vdisplay, vsync_start, vsync_end, vtotal, vscan; - unsigned int vrefresh; - unsigned int flags; - unsigned int type; - char name[NAME_LEN]; - const void *private_mode; -} DSDisplayDeviceOutputMode; - class IDSDisplayDeviceOutput : public DSObject { public: @@ -61,18 +51,22 @@ public: public: virtual ~IDSDisplayDeviceOutput() = default; - virtual ConnectorType getConnectType() = 0; - virtual ConnectState getConnectState() = 0; - virtual std::list getAvailableModes() = 0; - virtual int getResolutionWidth() = 0; - virtual int getResolutionHeight() = 0; - virtual int getPhysicalMMWidth() = 0; - virtual int getPhysicalMMHeight() = 0; - virtual bool setMode(DSDisplayDeviceOutputMode *mode) = 0; - virtual DSDisplayDeviceOutputMode *getMode() = 0; - virtual bool setDPMSMode(DPMSMode dpmsMode) = 0; - virtual DPMSMode getDPMSMode() = 0; - virtual std::shared_ptr getHWC() = 0; + virtual ConnectorType getConnectType() = 0; + virtual ConnectState getConnectState() = 0; + + virtual int getResolutionWidth() = 0; + virtual int getResolutionHeight() = 0; + virtual int getPhysicalMMWidth() = 0; + virtual int getPhysicalMMHeight() = 0; + + virtual std::list> getAvailableModes() = 0; + virtual bool setMode(std::shared_ptr outputMode) = 0; + virtual std::shared_ptr getMode() = 0; + + virtual bool setDPMSMode(DPMSMode dpmsMode) = 0; + virtual DPMSMode getDPMSMode() = 0; + + virtual std::shared_ptr getHWC() = 0; // Callback methods virtual void registerCallbackOutputConnected(DSObject *slot, std::function)> func) = 0; diff --git a/src/DSDisplayDevice/IDSDisplayDeviceOutputMode.h b/src/DSDisplayDevice/IDSDisplayDeviceOutputMode.h new file mode 100644 index 0000000..df8d6e5 --- /dev/null +++ b/src/DSDisplayDevice/IDSDisplayDeviceOutputMode.h @@ -0,0 +1,22 @@ +#ifndef __I_DS_DISPLAY_DEVICE_OUTPUT_MODE_H__ +#define __I_DS_DISPLAY_DEVICE_OUTPUT_MODE_H__ + +#include + +namespace display_server +{ + +class IDSDisplayDeviceOutputMode +{ +public: + virtual ~IDSDisplayDeviceOutputMode() = default; + + virtual unsigned int getRefreshRate() = 0; + virtual unsigned int getHorizontalSize() = 0; + virtual unsigned int getVertialSize() = 0; + virtual std::string getName() = 0; +}; + +} + +#endif diff --git a/src/meson.build b/src/meson.build index 3eace65..26969ab 100644 --- a/src/meson.build +++ b/src/meson.build @@ -11,6 +11,7 @@ libds_srcs = [ 'DSDisplayArea/DSDisplayArea.cpp', 'DSDisplayDevice/DSDisplayDeviceHWCTDMImpl.cpp', 'DSDisplayDevice/DSDisplayDeviceHWCWindowTDMImpl.cpp', + 'DSDisplayDevice/DSDisplayDeviceOutputModeTDMImpl.cpp', 'DSDisplayDevice/DSDisplayDeviceOutputTDMImpl.cpp', 'DSDisplayDevice/DSDisplayDeviceTDMImpl.cpp', 'DSInput/DSInput.cpp', diff --git a/tests/DSDisplayDeviceTDMImpl-test.cpp b/tests/DSDisplayDeviceTDMImpl-test.cpp index b8cf18e..b9a3b89 100644 --- a/tests/DSDisplayDeviceTDMImpl-test.cpp +++ b/tests/DSDisplayDeviceTDMImpl-test.cpp @@ -123,30 +123,16 @@ TEST_F(DSDisplayDeviceTDMImplTest, DeviceOutput_setModeBestResolution) IDSDisplayDeviceOutput::ConnectorType connType; IDSDisplayDeviceOutput::ConnectState connState; - DSDisplayDeviceOutputMode *bestMode; for (std::shared_ptr output : outputList) { connType = output->getConnectType(); EXPECT_TRUE(connType <= IDSDisplayDeviceOutput::TYPE_DSI); connState = output->getConnectState(); EXPECT_TRUE(connState <= IDSDisplayDeviceOutput::STATE_MODESET); - if (connState == IDSDisplayDeviceOutput::STATE_DISCONNECTED) continue; - - bestMode = nullptr; - - for (DSDisplayDeviceOutputMode *mode : output->getAvailableModes()) { - if (bestMode == nullptr) { - bestMode = mode; - continue; - } - - int resSize = mode->hdisplay * mode->vdisplay; - int resSizeBest = bestMode->hdisplay *bestMode->vdisplay; - if (resSize > resSizeBest) { - bestMode = mode; - } - } + if (connState == IDSDisplayDeviceOutput::STATE_DISCONNECTED) + continue; + auto bestMode = (output->getAvailableModes()).front(); EXPECT_TRUE(output->setMode(bestMode) == true); EXPECT_TRUE(output->getMode() == bestMode); } @@ -239,7 +225,8 @@ TEST_F(DSDisplayDeviceTDMImplTest, DeviceOutput_makeHWCWindow) EXPECT_TRUE(connType <= IDSDisplayDeviceOutput::TYPE_DSI); connState = output->getConnectState(); EXPECT_TRUE(connState <= IDSDisplayDeviceOutput::STATE_MODESET); - if (connState == IDSDisplayDeviceOutput::STATE_DISCONNECTED) continue; + if (connState == IDSDisplayDeviceOutput::STATE_DISCONNECTED) + continue; deviceHWC = output->getHWC(); EXPECT_TRUE(deviceHWC != nullptr); @@ -265,21 +252,10 @@ TEST_F(DSDisplayDeviceTDMImplTest, DeviceHWC_commit) EXPECT_TRUE(connType <= IDSDisplayDeviceOutput::TYPE_DSI); connState = output->getConnectState(); EXPECT_TRUE(connState <= IDSDisplayDeviceOutput::STATE_MODESET); - if (connState == IDSDisplayDeviceOutput::STATE_DISCONNECTED) continue; - - DSDisplayDeviceOutputMode *bestMode = nullptr; - for (DSDisplayDeviceOutputMode *mode : output->getAvailableModes()) { - if (bestMode == nullptr) { - bestMode = mode; - continue; - } - - int resSize = mode->hdisplay * mode->vdisplay; - int resSizeBest = bestMode->hdisplay *bestMode->vdisplay; - if (resSize > resSizeBest) { - bestMode = mode; - } - } + if (connState == IDSDisplayDeviceOutput::STATE_DISCONNECTED) + continue; + + auto bestMode = (output->getAvailableModes()).front(); EXPECT_TRUE(output->setMode(bestMode) == true); EXPECT_TRUE(output->getMode() == bestMode); -- 2.7.4 From 0ac7de7c490b687ba85e9e0c9c2a3c33b6ee5f01 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Thu, 2 Jul 2020 13:56:01 +0900 Subject: [PATCH 02/16] DSWaylandServer: add prototype codes related to wl_surface interface. Change-Id: If5b19488bb98135deadb0d15b62259782ee30b2d Signed-off-by: Joonbum Ko --- src/DSWaylandServer/DSWaylandSurface.cpp | 73 +++++++++++++++++++++++++++ src/DSWaylandServer/DSWaylandSurface.h | 34 +++++++++++++ src/DSWaylandServer/DSWaylandSurfacePrivate.h | 38 ++++++++++++++ src/meson.build | 3 ++ tests/DSWaylandSurface-test.cpp | 20 ++++++++ tests/meson.build | 1 + 6 files changed, 169 insertions(+) create mode 100644 src/DSWaylandServer/DSWaylandSurface.cpp create mode 100644 src/DSWaylandServer/DSWaylandSurface.h create mode 100644 src/DSWaylandServer/DSWaylandSurfacePrivate.h create mode 100644 tests/DSWaylandSurface-test.cpp diff --git a/src/DSWaylandServer/DSWaylandSurface.cpp b/src/DSWaylandServer/DSWaylandSurface.cpp new file mode 100644 index 0000000..29429c6 --- /dev/null +++ b/src/DSWaylandServer/DSWaylandSurface.cpp @@ -0,0 +1,73 @@ +#include "DSWaylandSurface.h" +#include "DSWaylandSurfacePrivate.h" + +namespace display_server +{ + +DSWaylandSurfacePrivate::DSWaylandSurfacePrivate(DSWaylandSurface *p_ptr) + : DSObjectPrivate(p_ptr) +{ +} + +DSWaylandSurfacePrivate::~DSWaylandSurfacePrivate() +{ +} + +void DSWaylandSurfacePrivate::surface_bind_resource(Resource *resource) +{ +} + +void DSWaylandSurfacePrivate::surface_destroy_resource(Resource *resource) +{ +} + +void DSWaylandSurfacePrivate::surface_destroy(Resource *resource) +{ +} + +void DSWaylandSurfacePrivate::surface_attach(Resource *resource, struct ::wl_resource *buffer, int32_t x, int32_t y) +{ +} + +void DSWaylandSurfacePrivate::surface_damage(Resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) +{ +} + +void DSWaylandSurfacePrivate::surface_frame(Resource *resource, uint32_t callback) +{ +} + +void DSWaylandSurfacePrivate::surface_set_opaque_region(Resource *resource, struct ::wl_resource *region) +{ +} + +void DSWaylandSurfacePrivate::surface_set_input_region(Resource *resource, struct ::wl_resource *region) +{ +} + +void DSWaylandSurfacePrivate::surface_commit(Resource *resource) +{ +} + +void DSWaylandSurfacePrivate::surface_set_buffer_transform(Resource *resource, int32_t transform) +{ +} + +void DSWaylandSurfacePrivate::surface_set_buffer_scale(Resource *resource, int32_t scale) +{ +} + +void DSWaylandSurfacePrivate::surface_damage_buffer(Resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) +{ +} + +DSWaylandSurface::DSWaylandSurface() + : DSObject(std::make_unique(this)) +{ +} + +DSWaylandSurface::~DSWaylandSurface() +{ +} + +} /* namespace display_server */ diff --git a/src/DSWaylandServer/DSWaylandSurface.h b/src/DSWaylandServer/DSWaylandSurface.h new file mode 100644 index 0000000..f662ce9 --- /dev/null +++ b/src/DSWaylandServer/DSWaylandSurface.h @@ -0,0 +1,34 @@ +#ifndef _DS_WAYLAND_SURFACE_H_ +#define _DS_WAYLAND_SURFACE_H_ + +#include + +namespace display_server +{ + +class DSWaylandSurfacePrivate; + + +class DSWaylandSurface : public DSObject +{ +public: + DSWaylandSurface(); + virtual ~DSWaylandSurface(); + +private: + inline DSWaylandSurfacePrivate *__d_func() + { + return reinterpret_cast(_d_ptr.get()); + } + + inline const DSWaylandSurfacePrivate *__d_func() const + { + return reinterpret_cast(_d_ptr.get()); + } + + friend class DSWaylandSurfacePrivate; +}; + +} /* namespace display_server */ + +#endif /* _DS_WAYLAND_SURFACE_H_ */ diff --git a/src/DSWaylandServer/DSWaylandSurfacePrivate.h b/src/DSWaylandServer/DSWaylandSurfacePrivate.h new file mode 100644 index 0000000..7434c6a --- /dev/null +++ b/src/DSWaylandServer/DSWaylandSurfacePrivate.h @@ -0,0 +1,38 @@ +#ifndef _DS_WAYLAND_SURFACE_PRIVATE_H_ +#define _DS_WAYLAND_SURFACE_PRIVATE_H_ + +#include "dswayland-server-wayland.h" +#include "DSWaylandSurface.h" + +namespace display_server +{ + +class DSWaylandSurfacePrivate : public DSObjectPrivate, public DSWaylandServer::wl_surface +{ +public: + DSWaylandSurfacePrivate() = delete; + DSWaylandSurfacePrivate(DSWaylandSurface *p_ptr); + ~DSWaylandSurfacePrivate() override; + +protected: + void surface_bind_resource(Resource *resource) override; + void surface_destroy_resource(Resource *resource) override; + + void surface_destroy(Resource *resource) override; + void surface_attach(Resource *resource, struct ::wl_resource *buffer, int32_t x, int32_t y) override; + void surface_damage(Resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) override; + void surface_frame(Resource *resource, uint32_t callback) override; + void surface_set_opaque_region(Resource *resource, struct ::wl_resource *region) override; + void surface_set_input_region(Resource *resource, struct ::wl_resource *region) override; + void surface_commit(Resource *resource) override; + void surface_set_buffer_transform(Resource *resource, int32_t transform) override; + void surface_set_buffer_scale(Resource *resource, int32_t scale) override; + void surface_damage_buffer(Resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) override; + +private: + +}; + +} /*namespace display_server */ + +#endif /* _DS_WAYLAND_SURFACE_PRIVATE_H_ */ diff --git a/src/meson.build b/src/meson.build index 26969ab..d1218b4 100644 --- a/src/meson.build +++ b/src/meson.build @@ -58,6 +58,9 @@ libds_wayland_srcs = [ 'DSWaylandServer/DSWaylandOutput.cpp', 'DSWaylandServer/DSWaylandOutput.h', 'DSWaylandServer/DSWaylandOutputPrivate.h', + 'DSWaylandServer/DSWaylandSurface.cpp', + 'DSWaylandServer/DSWaylandSurface.h', + 'DSWaylandServer/DSWaylandSurfacePrivate.h', 'DSWaylandServer/DSWaylandTizenInputDevice.cpp', 'DSWaylandServer/DSWaylandTizenInputDevice.h', 'DSWaylandServer/DSWaylandTizenInputDevicePrivate.h', diff --git a/tests/DSWaylandSurface-test.cpp b/tests/DSWaylandSurface-test.cpp new file mode 100644 index 0000000..87b91cd --- /dev/null +++ b/tests/DSWaylandSurface-test.cpp @@ -0,0 +1,20 @@ +#include "libds-tests.h" +#include "DSWaylandSurface.h" + +using namespace display_server; + +class DSWaylandSurfaceTest : public ::testing::Test +{ +public: + void SetUp(void) override + {} + void TearDown(void) override + {} +}; + +TEST_F(DSWaylandSurfaceTest, NewDSWaylandSurface) +{ + DSWaylandSurface *surface = new DSWaylandSurface; + delete surface; + EXPECT_TRUE(true); +} diff --git a/tests/meson.build b/tests/meson.build index f09eed5..5d9935e 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -16,6 +16,7 @@ libds_tests_srcs = [ 'DSDisplayDeviceTDMImpl-test.cpp', 'DSSignal-test.cpp', 'DSWaylandOutput-test.cpp', + 'DSWaylandSurface-test.cpp', 'DSWaylandTizenInputDeviceManager-test.cpp', 'DSWaylandTizenInputDevice-test.cpp', 'DSObject-test.cpp', -- 2.7.4 From 008c336ed4dc66311b98e08758ea7e2526251d27 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Fri, 3 Jul 2020 19:09:17 +0900 Subject: [PATCH 03/16] DSWaylandServer: add prototype codes related to wl_callback interface. Change-Id: I73eeeffd6029b9791647d51e51ba651036dc4e84 Signed-off-by: Joonbum Ko --- src/DSWaylandServer/DSWaylandCallback.cpp | 33 +++++++++++++++++++++++++ src/DSWaylandServer/DSWaylandCallback.h | 34 ++++++++++++++++++++++++++ src/DSWaylandServer/DSWaylandCallbackPrivate.h | 27 ++++++++++++++++++++ src/meson.build | 3 +++ tests/DSWaylandCallback-test.cpp | 20 +++++++++++++++ tests/meson.build | 1 + 6 files changed, 118 insertions(+) create mode 100644 src/DSWaylandServer/DSWaylandCallback.cpp create mode 100644 src/DSWaylandServer/DSWaylandCallback.h create mode 100644 src/DSWaylandServer/DSWaylandCallbackPrivate.h create mode 100644 tests/DSWaylandCallback-test.cpp diff --git a/src/DSWaylandServer/DSWaylandCallback.cpp b/src/DSWaylandServer/DSWaylandCallback.cpp new file mode 100644 index 0000000..b98afcc --- /dev/null +++ b/src/DSWaylandServer/DSWaylandCallback.cpp @@ -0,0 +1,33 @@ +#include "DSWaylandCallback.h" +#include "DSWaylandCallbackPrivate.h" + +namespace display_server +{ + +DSWaylandCallbackPrivate::DSWaylandCallbackPrivate(DSWaylandCallback *p_ptr) + : DSObjectPrivate(p_ptr) +{ +} + +DSWaylandCallbackPrivate::~DSWaylandCallbackPrivate() +{ +} + +void DSWaylandCallbackPrivate::callback_bind_resource(Resource *resource) +{ +} + +void DSWaylandCallbackPrivate::callback_destroy_resource(Resource *resource) +{ +} + +DSWaylandCallback::DSWaylandCallback() + : DSObject(std::make_unique(this)) +{ +} + +DSWaylandCallback::~DSWaylandCallback() +{ +} + +} /* namespace display_server */ diff --git a/src/DSWaylandServer/DSWaylandCallback.h b/src/DSWaylandServer/DSWaylandCallback.h new file mode 100644 index 0000000..1ea69d3 --- /dev/null +++ b/src/DSWaylandServer/DSWaylandCallback.h @@ -0,0 +1,34 @@ +#ifndef _DS_WAYLAND_CALLBACK_H_ +#define _DS_WAYLAND_CALLBACK_H_ + +#include + +namespace display_server +{ + +class DSWaylandCallbackPrivate; + + +class DSWaylandCallback : public DSObject +{ +public: + DSWaylandCallback(); + virtual ~DSWaylandCallback(); + +private: + inline DSWaylandCallbackPrivate *__d_func() + { + return reinterpret_cast(_d_ptr.get()); + } + + inline const DSWaylandCallbackPrivate *__d_func() const + { + return reinterpret_cast(_d_ptr.get()); + } + + friend class DSWaylandCallbackPrivate; +}; + +} /* namespace display_server */ + +#endif /* _DS_WAYLAND_CALLBACK_H_ */ diff --git a/src/DSWaylandServer/DSWaylandCallbackPrivate.h b/src/DSWaylandServer/DSWaylandCallbackPrivate.h new file mode 100644 index 0000000..da3f837 --- /dev/null +++ b/src/DSWaylandServer/DSWaylandCallbackPrivate.h @@ -0,0 +1,27 @@ +#ifndef _DS_WAYLAND_CALLBACK_PRIVATE_H_ +#define _DS_WAYLAND_CALLBACK_PRIVATE_H_ + +#include "dswayland-server-wayland.h" +#include "DSWaylandCallback.h" + +namespace display_server +{ + +class DSWaylandCallbackPrivate : public DSObjectPrivate, public DSWaylandServer::wl_callback +{ +public: + DSWaylandCallbackPrivate() = delete; + DSWaylandCallbackPrivate(DSWaylandCallback *p_ptr); + ~DSWaylandCallbackPrivate() override; + +protected: + void callback_bind_resource(Resource *resource) override; + void callback_destroy_resource(Resource *resource) override; + +private: + +}; + +} /* namespace display_server */ + +#endif /* _DS_WAYLAND_CALLBACK_PRIVATE_H_ */ diff --git a/src/meson.build b/src/meson.build index d1218b4..68c1816 100644 --- a/src/meson.build +++ b/src/meson.build @@ -55,6 +55,9 @@ libds_wayland_srcs = [ 'DSWaylandServer/dswayland-server-text.h', 'DSWaylandServer/dswayland-server-tizen-launch.cpp', 'DSWaylandServer/dswayland-server-tizen-launch.h', + 'DSWaylandServer/DSWaylandCallback.cpp', + 'DSWaylandServer/DSWaylandCallback.h', + 'DSWaylandServer/DSWaylandCallbackPrivate.h', 'DSWaylandServer/DSWaylandOutput.cpp', 'DSWaylandServer/DSWaylandOutput.h', 'DSWaylandServer/DSWaylandOutputPrivate.h', diff --git a/tests/DSWaylandCallback-test.cpp b/tests/DSWaylandCallback-test.cpp new file mode 100644 index 0000000..65dbf1c --- /dev/null +++ b/tests/DSWaylandCallback-test.cpp @@ -0,0 +1,20 @@ +#include "libds-tests.h" +#include "DSWaylandCallback.h" + +using namespace display_server; + +class DSWaylandCallbackTest : public ::testing::Test +{ +public: + void SetUp(void) override + {} + void TearDown(void) override + {} +}; + +TEST_F(DSWaylandCallbackTest, NewDSWaylandCallback) +{ + DSWaylandCallback *callback = new DSWaylandCallback; + delete callback; + EXPECT_TRUE(true); +} diff --git a/tests/meson.build b/tests/meson.build index 5d9935e..2fb88e4 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', + 'DSWaylandCallback-test.cpp', 'DSWaylandOutput-test.cpp', 'DSWaylandSurface-test.cpp', 'DSWaylandTizenInputDeviceManager-test.cpp', -- 2.7.4 From 82077169b1a907a9062dedcc858b90063b4abec1 Mon Sep 17 00:00:00 2001 From: jeon Date: Mon, 6 Jul 2020 15:03:29 +0900 Subject: [PATCH 04/16] DSSeat: add keyboard/mouse/touch skeleton classes Change-Id: Ia712e6f5d237caf06c239341cfabe9e1ac9cd771 --- src/DSSeat/DSKeyboard.cpp | 19 +++++++++++++++++++ src/DSSeat/DSKeyboard.h | 22 ++++++++++++++++++++++ src/DSSeat/DSPointer.cpp | 19 +++++++++++++++++++ src/DSSeat/DSPointer.h | 22 ++++++++++++++++++++++ src/DSSeat/DSSeat.cpp | 5 ++++- src/DSSeat/DSSeat.h | 7 +++++++ src/DSSeat/DSTouch.cpp | 19 +++++++++++++++++++ src/DSSeat/DSTouch.h | 22 ++++++++++++++++++++++ src/meson.build | 6 ++++++ 9 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 src/DSSeat/DSKeyboard.cpp create mode 100644 src/DSSeat/DSKeyboard.h create mode 100644 src/DSSeat/DSPointer.cpp create mode 100644 src/DSSeat/DSPointer.h create mode 100644 src/DSSeat/DSTouch.cpp create mode 100644 src/DSSeat/DSTouch.h diff --git a/src/DSSeat/DSKeyboard.cpp b/src/DSSeat/DSKeyboard.cpp new file mode 100644 index 0000000..c8ea7a7 --- /dev/null +++ b/src/DSSeat/DSKeyboard.cpp @@ -0,0 +1,19 @@ +#include "DSKeyboard.h" + +namespace display_server +{ + +DSKeyboard::DSKeyboard() + : __seat(nullptr) +{ +} + +DSKeyboard::DSKeyboard(DSSeat *seat) + : __seat(seat) +{ +} + +DSKeyboard::~DSKeyboard() +{} + +} // namespace display_server \ No newline at end of file diff --git a/src/DSSeat/DSKeyboard.h b/src/DSSeat/DSKeyboard.h new file mode 100644 index 0000000..db5081e --- /dev/null +++ b/src/DSSeat/DSKeyboard.h @@ -0,0 +1,22 @@ +#ifndef _DSKEYBOARD_H_ +#define _DSKEYBOARD_H_ + +#include + +namespace display_server +{ + +class DSKeyboard +{ +public: + DSKeyboard(); + DSKeyboard(DSSeat *seat); + virtual ~DSKeyboard(); + +private: + DSSeat *__seat; +}; + +} + +#endif \ No newline at end of file diff --git a/src/DSSeat/DSPointer.cpp b/src/DSSeat/DSPointer.cpp new file mode 100644 index 0000000..8f243ef --- /dev/null +++ b/src/DSSeat/DSPointer.cpp @@ -0,0 +1,19 @@ +#include "DSPointer.h" + +namespace display_server +{ + +DSPointer::DSPointer() + : __seat(nullptr) +{ +} + +DSPointer::DSPointer(DSSeat *seat) + : __seat(seat) +{ +} + +DSPointer::~DSPointer() +{} + +} // namespace display_server \ No newline at end of file diff --git a/src/DSSeat/DSPointer.h b/src/DSSeat/DSPointer.h new file mode 100644 index 0000000..d5ac041 --- /dev/null +++ b/src/DSSeat/DSPointer.h @@ -0,0 +1,22 @@ +#ifndef _DSKEYBOARD_H_ +#define _DSPOINTER_H_ + +#include + +namespace display_server +{ + +class DSPointer +{ +public: + DSPointer(); + DSPointer(DSSeat *seat); + virtual ~DSPointer(); + +private: + DSSeat *__seat; +}; + +} + +#endif \ No newline at end of file diff --git a/src/DSSeat/DSSeat.cpp b/src/DSSeat/DSSeat.cpp index ba66418..69e29ac 100644 --- a/src/DSSeat/DSSeat.cpp +++ b/src/DSSeat/DSSeat.cpp @@ -4,7 +4,10 @@ namespace display_server { DSSeat::DSSeat() - : __input(nullptr) + : __input(nullptr), + __keyboard(nullptr), + __pointer(nullptr), + __touch(nullptr) {} DSSeat::~DSSeat() diff --git a/src/DSSeat/DSSeat.h b/src/DSSeat/DSSeat.h index 78f06b4..97bc076 100644 --- a/src/DSSeat/DSSeat.h +++ b/src/DSSeat/DSSeat.h @@ -6,6 +6,10 @@ namespace display_server { +class DSKeyboard; +class DSPointer; +class DSTouch; + class DSSeat { public: @@ -17,6 +21,9 @@ public: private: DSInput *__input; + DSKeyboard *__keyboard; + DSPointer *__pointer; + DSTouch *__touch; }; } diff --git a/src/DSSeat/DSTouch.cpp b/src/DSSeat/DSTouch.cpp new file mode 100644 index 0000000..6913f4d --- /dev/null +++ b/src/DSSeat/DSTouch.cpp @@ -0,0 +1,19 @@ +#include "DSTouch.h" + +namespace display_server +{ + +DSTouch::DSTouch() + : __seat(nullptr) +{ +} + +DSTouch::DSTouch(DSSeat *seat) + : __seat(seat) +{ +} + +DSTouch::~DSTouch() +{} + +} // namespace display_server \ No newline at end of file diff --git a/src/DSSeat/DSTouch.h b/src/DSSeat/DSTouch.h new file mode 100644 index 0000000..df3e8f3 --- /dev/null +++ b/src/DSSeat/DSTouch.h @@ -0,0 +1,22 @@ +#ifndef _DSTOUCH_H_ +#define _DSTOUCH_H_ + +#include + +namespace display_server +{ + +class DSTouch +{ +public: + DSTouch(); + DSTouch(DSSeat *seat); + virtual ~DSTouch(); + +private: + DSSeat *__seat; +}; + +} + +#endif \ No newline at end of file diff --git a/src/meson.build b/src/meson.build index 68c1816..62f3f3a 100644 --- a/src/meson.build +++ b/src/meson.build @@ -35,6 +35,12 @@ libds_srcs = [ 'DSRender/DSRenderViewEcoreEvasImpl.cpp', 'DSRender/DSRenderViewDaliImpl.cpp', 'DSSeat/DSSeat.cpp', + 'DSSeat/DSKeyboard.cpp', + 'DSSeat/DSKeyboard.h', + 'DSSeat/DSPointer.cpp', + 'DSSeat/DSPointer.h', + 'DSSeat/DSTouch.cpp', + 'DSSeat/DSTouch.h', 'DSSignal/DSSignal.cpp', 'DSSignal/DSSignal.h', 'DSCore/DSCore.h', -- 2.7.4 From 25d4b59e3cc5e41d98cd96820ba99704fdb61f40 Mon Sep 17 00:00:00 2001 From: jeon Date: Mon, 6 Jul 2020 15:04:05 +0900 Subject: [PATCH 05/16] DSInput: Add a DSInputDevice class Change-Id: Ie9eff1f32b3ca35b2506ddb7b6185557d06ea68a --- src/DSInput/DSInput.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ src/DSInput/DSInput.h | 33 ++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) diff --git a/src/DSInput/DSInput.cpp b/src/DSInput/DSInput.cpp index 8a38125..b515294 100644 --- a/src/DSInput/DSInput.cpp +++ b/src/DSInput/DSInput.cpp @@ -22,4 +22,54 @@ DSInput::~DSInput() { } + +DSInputDevice::DSInputDevice() + : __deviceName(nullptr), + __deviceIdentifier(nullptr), + __deviceClass(DSInput::DeviceClass::None) +{ +} + +DSInputDevice::DSInputDevice(string name, string identifier, DSInput::DeviceClass clas) + : __deviceName(name), + __deviceIdentifier(identifier), + __deviceClass(clas) +{ +} + +DSInputDevice::~DSInputDevice() +{ +} + +string DSInputDevice::getName() const +{ + return __deviceName; +} + +void DSInputDevice::setName(string name) +{ + __deviceName = name; +} + +string DSInputDevice::getIdentifier() const +{ + return __deviceIdentifier; +} + +void DSInputDevice::setIdentifier(string identifier) +{ + __deviceIdentifier = identifier; +} + +DSInput::DeviceClass DSInputDevice::getClass() const +{ + return __deviceClass; +} + +void DSInputDevice::setClass(DSInput::DeviceClass clas) +{ + __deviceClass = clas; +} + + } // namespace display_server diff --git a/src/DSInput/DSInput.h b/src/DSInput/DSInput.h index 6b89638..725653c 100644 --- a/src/DSInput/DSInput.h +++ b/src/DSInput/DSInput.h @@ -2,6 +2,10 @@ #define _DSINPUT_H_ #include +#include +#include + +using namespace std; namespace display_server { @@ -11,6 +15,13 @@ class DSInputPrivate; class DSInput : public DSObject { public: + enum DeviceClass { + None = 0, + Pointer = (1 << 0), + Keyboard = (1 << 1), + Touch = (1 << 2), + }; +public: DSInput(); virtual ~DSInput(); @@ -26,6 +37,28 @@ private: friend class DSInputPrivate; }; +class DSInputDevice +{ +public: + DSInputDevice(); + DSInputDevice(string name, string identifier, DSInput::DeviceClass clas); + ~DSInputDevice(); + + string getName() const; + void setName(string name); + + string getIdentifier() const; + void setIdentifier(string identifier); + + DSInput::DeviceClass getClass() const; + void setClass(DSInput::DeviceClass clas); +private: + string __deviceName; + string __deviceIdentifier; + DSInput::DeviceClass __deviceClass; + +}; + } #endif -- 2.7.4 From 0b5590908035103c22f3e5724c976d15b43b396a Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Mon, 6 Jul 2020 17:48:11 +0900 Subject: [PATCH 06/16] DSEventLoop: add DSEventLoop class Change-Id: Ib6c530c400abc8b8b9915add28288dfdad520a98 --- src/DSEventLoop/DSEventLoop.cpp | 49 +++++++++++++++++++++++++++++++++++++++++ src/DSEventLoop/DSEventLoop.h | 24 ++++++++++++++++++++ src/meson.build | 2 ++ tests/DSEventLoop-test.cpp | 41 ++++++++++++++++++++++++++++++++++ tests/meson.build | 1 + 5 files changed, 117 insertions(+) create mode 100644 src/DSEventLoop/DSEventLoop.cpp create mode 100644 src/DSEventLoop/DSEventLoop.h create mode 100644 tests/DSEventLoop-test.cpp diff --git a/src/DSEventLoop/DSEventLoop.cpp b/src/DSEventLoop/DSEventLoop.cpp new file mode 100644 index 0000000..6cbf6aa --- /dev/null +++ b/src/DSEventLoop/DSEventLoop.cpp @@ -0,0 +1,49 @@ +#include "DSEventLoop.h" +#include "DSDebugLog.h" +#include + +namespace display_server +{ + +DSEventLoop::DSEventLoop() + : __running(false) +{ + if (!ecore_init()) { + DSLOG_ERR("EventLoop", "ecore_init() fails."); + } +} + +DSEventLoop::~DSEventLoop() +{ + ecore_shutdown(); +} + +bool DSEventLoop::isRunning() +{ + return __running; +} + +bool DSEventLoop::run() +{ + if (__running) + return true; + + __running = true; + ecore_main_loop_begin(); + __running = false; + + return true; +} + +bool DSEventLoop::quit() +{ + if (!__running) { + return false; + } + + ecore_main_loop_quit(); + + return true; +} + +} // namespace display_server \ No newline at end of file diff --git a/src/DSEventLoop/DSEventLoop.h b/src/DSEventLoop/DSEventLoop.h new file mode 100644 index 0000000..d343371 --- /dev/null +++ b/src/DSEventLoop/DSEventLoop.h @@ -0,0 +1,24 @@ +#ifndef __DS_EVENT_LOOP_H__ +#define __DS_EVENT_LOOP_H__ + +namespace display_server +{ + +class DSEventLoop +{ +public: + DSEventLoop(); + virtual ~DSEventLoop(); + + bool run(); + bool quit(); + + bool isRunning(); + +private: + bool __running; +}; + +} + +#endif \ No newline at end of file diff --git a/src/meson.build b/src/meson.build index 62f3f3a..7b24fbd 100644 --- a/src/meson.build +++ b/src/meson.build @@ -14,6 +14,7 @@ libds_srcs = [ 'DSDisplayDevice/DSDisplayDeviceOutputModeTDMImpl.cpp', 'DSDisplayDevice/DSDisplayDeviceOutputTDMImpl.cpp', 'DSDisplayDevice/DSDisplayDeviceTDMImpl.cpp', + 'DSEventLoop/DSEventLoop.cpp', 'DSInput/DSInput.cpp', 'DSInput/DSInput.h', 'DSInput/DSInputPrivate.h', @@ -116,6 +117,7 @@ libds_include_dirs = include_directories( './DSDebug', './DSDisplayArea', './DSDisplayDevice', + './DSEventLoop', './DSHWC', './DSInput', './DSObject', diff --git a/tests/DSEventLoop-test.cpp b/tests/DSEventLoop-test.cpp new file mode 100644 index 0000000..773d890 --- /dev/null +++ b/tests/DSEventLoop-test.cpp @@ -0,0 +1,41 @@ +#include "libds-tests.h" +#include "DSEventLoop.h" +#include + +using namespace display_server; + +class DSEventLoopTest : public ::testing::Test +{ +public: + void SetUp(void) override + {} + void TearDown(void) override + {} +}; + +TEST_F(DSEventLoopTest, NewDSEventLoop) +{ + DSEventLoop *eventLoop = new DSEventLoop; + delete eventLoop; + EXPECT_TRUE(true); +} + +TEST_F(DSEventLoopTest, RunAndQuit) +{ + DSEventLoop eventLoop; + + Ecore_Timer *timer = nullptr; + double delayInSecond = 1.0; + auto cb = [](void *data) -> Eina_Bool { + DSEventLoop *loop = (DSEventLoop *)data; + EXPECT_TRUE(loop->quit() == true); + return EINA_FALSE; + }; + + timer = ecore_timer_loop_add(delayInSecond, cb, &eventLoop); + EXPECT_TRUE(timer != nullptr); + + if (timer != nullptr) { + EXPECT_TRUE(eventLoop.run() == true); + } +} \ No newline at end of file diff --git a/tests/meson.build b/tests/meson.build index 2fb88e4..a0991d3 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -21,6 +21,7 @@ libds_tests_srcs = [ 'DSWaylandTizenInputDeviceManager-test.cpp', 'DSWaylandTizenInputDevice-test.cpp', 'DSObject-test.cpp', + 'DSEventLoop-test.cpp', ] gmock_dep = dependency('gmock', method : 'pkg-config') -- 2.7.4 From 52be5a4d923b1e19b811a0e9c131c0b0d20cb973 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Mon, 6 Jul 2020 17:49:37 +0900 Subject: [PATCH 07/16] DSCompositor: implement the eventloop with DSEventLoop object. Change-Id: Ic0ce513dbac26dabb3107a92ebc79dd999ea5e12 --- src/DSCompositor/DSCompositor.cpp | 44 ++++++--------------------------------- src/DSCompositor/DSCompositor.h | 17 +++++++-------- tests/DSCompositor-test.cpp | 19 +++++++---------- 3 files changed, 21 insertions(+), 59 deletions(-) diff --git a/src/DSCompositor/DSCompositor.cpp b/src/DSCompositor/DSCompositor.cpp index 10de008..2733cd6 100644 --- a/src/DSCompositor/DSCompositor.cpp +++ b/src/DSCompositor/DSCompositor.cpp @@ -1,4 +1,5 @@ #include "DSCompositor.h" +#include "DSDebugLog.h" #include @@ -6,63 +7,30 @@ namespace display_server { DSCompositor::DSCompositor() - : __running(false), - __init(false) { - init(); + __eventLoop = std::make_unique(); } DSCompositor::~DSCompositor() {} -bool DSCompositor::isRunning() -{ - return __running; -} - -bool DSCompositor::isInitDone() -{ - return __init; -} - -bool DSCompositor::init() -{ - if (__init) - { - return true; - } - - if (ecore_init()) - { - __init = true; - } - - return __init; -} - - bool DSCompositor::run() { - if (!__init) - { + if (!__eventLoop->run()) { + DSLOG_ERR("Compositor", "__eventLoop->run() fails."); return false; } - __running = true; - ecore_main_loop_begin(); - __running = false; - return true; } bool DSCompositor::quit() { - if (!__init || !__running) - { + if (!__eventLoop->quit()) { + DSLOG_ERR("Compositor", "__eventLoop->quit() fails."); return false; } - ecore_main_loop_quit(); return true; } diff --git a/src/DSCompositor/DSCompositor.h b/src/DSCompositor/DSCompositor.h index 250484b..24d294e 100644 --- a/src/DSCompositor/DSCompositor.h +++ b/src/DSCompositor/DSCompositor.h @@ -1,26 +1,25 @@ -#ifndef _DSCOMPOSITOR_H_ -#define _DSCOMPOSITOR_H_ +#ifndef __DS_COMPOSITOR_H__ +#define __DS_COMPOSITOR_H__ +#include "DSEventLoop.h" +#include namespace display_server { + class DSCompositor { public: DSCompositor(); virtual ~DSCompositor(); - bool isRunning(); - bool isInitDone(); - - bool init(); bool run(); bool quit(); private: - /* data */ - bool __running; - bool __init; + std::unique_ptr __eventLoop; + }; + } #endif \ No newline at end of file diff --git a/tests/DSCompositor-test.cpp b/tests/DSCompositor-test.cpp index cfaca5c..af1dcf5 100644 --- a/tests/DSCompositor-test.cpp +++ b/tests/DSCompositor-test.cpp @@ -4,7 +4,7 @@ using namespace display_server; -class DSComopsitorTest : public ::testing::Test +class DSCompositorTest : public ::testing::Test { public: void SetUp(void) override @@ -13,34 +13,29 @@ public: {} }; -TEST_F(DSComopsitorTest, NewDSCompositor) +TEST_F(DSCompositorTest, NewDSCompositor) { DSCompositor *compositor = new DSCompositor; delete compositor; - ASSERT_TRUE(true); + EXPECT_TRUE(true); } -TEST_F(DSComopsitorTest, BasicMethods) +TEST_F(DSCompositorTest, RunAndQuit) { DSCompositor compositor; Ecore_Timer *timer = nullptr; - double delayInSecond = 3.0; + double delayInSecond = 1.0; auto cb = [](void *data) -> Eina_Bool { DSCompositor *comp = (DSCompositor *)data; - - EXPECT_TRUE(comp->isRunning() == true); - - comp->quit(); + EXPECT_TRUE(comp->quit() == true); return EINA_FALSE; }; timer = ecore_timer_loop_add(delayInSecond, cb, &compositor); EXPECT_TRUE(timer != nullptr); - if (timer != nullptr) - { - EXPECT_TRUE(compositor.isInitDone() == true); + if (timer != nullptr) { EXPECT_TRUE(compositor.run() == true); } } -- 2.7.4 From 28a2ee8788d9d8bbf2a1612927c4c7cb9055d331 Mon Sep 17 00:00:00 2001 From: Sung-Jin Park Date: Wed, 8 Jul 2020 13:13:31 +0900 Subject: [PATCH 08/16] DSCore: add DS_ASSERT macro Change-Id: I29f33d8a3a09e9523e0ff7a497da96346e2d6bad Signed-off-by: Sung-Jin Park --- src/DSCore/DSCore.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/DSCore/DSCore.h b/src/DSCore/DSCore.h index 5a99e3b..54374a8 100644 --- a/src/DSCore/DSCore.h +++ b/src/DSCore/DSCore.h @@ -36,5 +36,9 @@ #define DS_GET_PUB(Class) \ Class * const pub = p_func() +#ifndef DS_ASSERT +#define DS_ASSERT(COND) assert(COND) +#endif + #endif //__DS_CORE_H__ -- 2.7.4 From 779d01a1d59be7037ef4af50d7750abdfb1c9bab Mon Sep 17 00:00:00 2001 From: Sung-Jin Park Date: Wed, 8 Jul 2020 13:22:33 +0900 Subject: [PATCH 09/16] DSCore: clarify macros for PIMPL idiom Change-Id: I5b56d6120b9d8c23d8338806bc168ea3c0a5429f Signed-off-by: Sung-Jin Park --- src/DSCore/DSCore.h | 38 +++++++++++++++++++------------------- tests/DSObject-test.cpp | 7 ++----- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/DSCore/DSCore.h b/src/DSCore/DSCore.h index 54374a8..0fde067 100644 --- a/src/DSCore/DSCore.h +++ b/src/DSCore/DSCore.h @@ -7,25 +7,25 @@ /* Macros for supporting PImpl(Pointer to implementation) Idiom */ /* Regarding PImpl Idiom, refer to https://www.geeksforgeeks.org/pimpl-idiom-in-c-with-examples */ -#define DS_DECLARE_PUBLIC(Class) \ - inline Class* p_func() { return static_cast(__p_ptr); } \ - inline const Class* p_func() const { return static_cast(__p_ptr); } \ - friend class Class; - -#define DS_DECLARE_PUBLIC_PTR(Class) \ - Class* __p_ptr; - -#define DS_DECLARE_PRIVATE(Class) \ - inline Class##Private *__d_func() \ - { return reinterpret_cast(_d_ptr.get()); } \ - inline const Class##Private *__d_func() const \ - { return reinterpret_cast(_d_ptr.get()); } \ - friend class Class##Private; - -#define DS_DECLARE_PRIVATE_PTR(Class) \ - std::unique_ptr _d_ptr; \ - inline Class(std::unique_ptr ptr) \ - { _d_ptr = std::move(ptr); } +#define DS_PIMPL_USE_PRIVATE(Class) \ + protected: \ + std::unique_ptr _d_ptr; \ + \ + private: \ + inline Class##Private *__d_func() \ + { return reinterpret_cast(_d_ptr.get()); } \ + inline const Class##Private *__d_func() const \ + { return reinterpret_cast(_d_ptr.get()); } \ + friend class Class##Private; + +#define DS_PIMPL_USE_PUBLIC(Class) \ + protected: \ + inline Class* p_func() { return static_cast(__p_ptr); } \ + inline const Class* p_func() const { return static_cast(__p_ptr); } \ + friend class Class; \ + \ + private: \ + Class* __p_ptr; #define DS_INIT_PRIVATE_PTR(Class) \ _d_ptr(std::make_unique(this)) diff --git a/tests/DSObject-test.cpp b/tests/DSObject-test.cpp index eb500da..e7f08fe 100644 --- a/tests/DSObject-test.cpp +++ b/tests/DSObject-test.cpp @@ -17,6 +17,7 @@ public: class TempObject; class TempObjectPrivate : public DSObjectPrivate { + DS_PIMPL_USE_PUBLIC(TempObject); public: TempObjectPrivate() = delete; TempObjectPrivate(TempObject *p_ptr); @@ -25,14 +26,13 @@ public: unsigned int funcMiddle(void); protected: - DS_DECLARE_PUBLIC(TempObject) private: - DS_DECLARE_PUBLIC_PTR(TempObject) }; class TempObject : public DSObject { + DS_PIMPL_USE_PRIVATE(TempObject); public: explicit TempObject(); virtual ~TempObject(); @@ -41,12 +41,9 @@ public: unsigned int funcExit(); protected: - DS_DECLARE_PRIVATE_PTR(TempObject) private: unsigned int __val = 0; - - DS_DECLARE_PRIVATE(TempObject) }; TempObjectPrivate::TempObjectPrivate(TempObject *p_ptr) -- 2.7.4 From 31692545aa8094269b125c5706bb72637dcdad3f Mon Sep 17 00:00:00 2001 From: jeon Date: Wed, 8 Jul 2020 14:13:51 +0900 Subject: [PATCH 10/16] DSInput: Imply pimpl macros Change-Id: I4814aa431461b00a56b4249d1be56f20a3efb0d3 --- src/DSInput/DSInput.cpp | 16 ++++++++-------- src/DSInput/DSInput.h | 36 ++++++++++++------------------------ src/DSInput/DSInputPrivate.h | 1 + 3 files changed, 21 insertions(+), 32 deletions(-) diff --git a/src/DSInput/DSInput.cpp b/src/DSInput/DSInput.cpp index b515294..9a71a11 100644 --- a/src/DSInput/DSInput.cpp +++ b/src/DSInput/DSInput.cpp @@ -5,7 +5,8 @@ namespace display_server { DSInputPrivate::DSInputPrivate(DSInput * p_ptr) - : DSObjectPrivate(p_ptr) + : DSObjectPrivate(p_ptr), + __p_ptr(p_ptr) { } @@ -14,7 +15,7 @@ DSInputPrivate::~DSInputPrivate() } DSInput::DSInput() - : DSObject(std::make_unique(this)) + : DS_INIT_PRIVATE_PTR(DSInput) { } @@ -22,7 +23,6 @@ DSInput::~DSInput() { } - DSInputDevice::DSInputDevice() : __deviceName(nullptr), __deviceIdentifier(nullptr), @@ -30,7 +30,7 @@ DSInputDevice::DSInputDevice() { } -DSInputDevice::DSInputDevice(string name, string identifier, DSInput::DeviceClass clas) +DSInputDevice::DSInputDevice(std::string name, std::string identifier, DSInput::DeviceClass clas) : __deviceName(name), __deviceIdentifier(identifier), __deviceClass(clas) @@ -41,22 +41,22 @@ DSInputDevice::~DSInputDevice() { } -string DSInputDevice::getName() const +std::string DSInputDevice::getName() const { return __deviceName; } -void DSInputDevice::setName(string name) +void DSInputDevice::setName(std::string name) { __deviceName = name; } -string DSInputDevice::getIdentifier() const +std::string DSInputDevice::getIdentifier() const { return __deviceIdentifier; } -void DSInputDevice::setIdentifier(string identifier) +void DSInputDevice::setIdentifier(std::string identifier) { __deviceIdentifier = identifier; } diff --git a/src/DSInput/DSInput.h b/src/DSInput/DSInput.h index 725653c..2568878 100644 --- a/src/DSInput/DSInput.h +++ b/src/DSInput/DSInput.h @@ -1,11 +1,8 @@ #ifndef _DSINPUT_H_ #define _DSINPUT_H_ -#include -#include -#include - -using namespace std; +#include "DSCore.h" +#include "DSObject.h" namespace display_server { @@ -14,6 +11,7 @@ class DSInputPrivate; class DSInput : public DSObject { +DS_PIMPL_USE_PRIVATE(DSInput); public: enum DeviceClass { None = 0, @@ -23,38 +21,28 @@ public: }; public: DSInput(); - virtual ~DSInput(); - -private: - inline DSInputPrivate *__d_func() - { - return reinterpret_cast(_d_ptr.get()); - } - inline const DSInputPrivate *__d_func() const - { - return reinterpret_cast(_d_ptr.get()); - } - friend class DSInputPrivate; + ~DSInput() override; }; class DSInputDevice { public: DSInputDevice(); - DSInputDevice(string name, string identifier, DSInput::DeviceClass clas); + DSInputDevice(std::string name, std::string identifier, DSInput::DeviceClass clas); ~DSInputDevice(); - string getName() const; - void setName(string name); + std::string getName() const; + void setName(std::string name); - string getIdentifier() const; - void setIdentifier(string identifier); + std::string getIdentifier() const; + void setIdentifier(std::string identifier); DSInput::DeviceClass getClass() const; void setClass(DSInput::DeviceClass clas); + private: - string __deviceName; - string __deviceIdentifier; + std::string __deviceName; + std::string __deviceIdentifier; DSInput::DeviceClass __deviceClass; }; diff --git a/src/DSInput/DSInputPrivate.h b/src/DSInput/DSInputPrivate.h index bacb7fd..bfd7d16 100644 --- a/src/DSInput/DSInputPrivate.h +++ b/src/DSInput/DSInputPrivate.h @@ -8,6 +8,7 @@ namespace display_server class DSInputPrivate : public DSObjectPrivate { +DS_PIMPL_USE_PUBLIC(DSInput); public: DSInputPrivate() = delete; DSInputPrivate(DSInput *p_ptr); -- 2.7.4 From 10854607a0ea0a014394f53212628ad14d3f7886 Mon Sep 17 00:00:00 2001 From: jeon Date: Wed, 8 Jul 2020 14:23:40 +0900 Subject: [PATCH 11/16] DSInput: add DeviceSubclass enum Change-Id: I9588a1c34876b72fb3fcf9e866907ff8fbcb188c --- src/DSInput/DSInput.cpp | 21 ++++++++++++++++----- src/DSInput/DSInput.h | 20 +++++++++++++------- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/DSInput/DSInput.cpp b/src/DSInput/DSInput.cpp index 9a71a11..43b31d7 100644 --- a/src/DSInput/DSInput.cpp +++ b/src/DSInput/DSInput.cpp @@ -26,14 +26,16 @@ DSInput::~DSInput() DSInputDevice::DSInputDevice() : __deviceName(nullptr), __deviceIdentifier(nullptr), - __deviceClass(DSInput::DeviceClass::None) + __deviceClass(DSInput::DeviceClass::NoneClass), + __deviceSubclass(DSInput::DeviceSubclass::NoneSubclass) { } -DSInputDevice::DSInputDevice(std::string name, std::string identifier, DSInput::DeviceClass clas) +DSInputDevice::DSInputDevice(std::string name, std::string identifier, DSInput::DeviceClass devClass, DSInput::DeviceSubclass devSubclass) : __deviceName(name), __deviceIdentifier(identifier), - __deviceClass(clas) + __deviceClass(devClass), + __deviceSubclass(devSubclass) { } @@ -66,10 +68,19 @@ DSInput::DeviceClass DSInputDevice::getClass() const return __deviceClass; } -void DSInputDevice::setClass(DSInput::DeviceClass clas) +void DSInputDevice::setClass(DSInput::DeviceClass devClass) { - __deviceClass = clas; + __deviceClass = devClass; } +DSInput::DeviceSubclass DSInputDevice::getSubclass() const +{ + return __deviceSubclass; +} + +void DSInputDevice::setSubclass(DSInput::DeviceSubclass devSubclass) +{ + __deviceSubclass = devSubclass; +} } // namespace display_server diff --git a/src/DSInput/DSInput.h b/src/DSInput/DSInput.h index 2568878..a05d5e3 100644 --- a/src/DSInput/DSInput.h +++ b/src/DSInput/DSInput.h @@ -14,10 +14,13 @@ class DSInput : public DSObject DS_PIMPL_USE_PRIVATE(DSInput); public: enum DeviceClass { - None = 0, - Pointer = (1 << 0), - Keyboard = (1 << 1), - Touch = (1 << 2), + NoneClass, + PointerClass, + KeyboardClass, + TouchClass, + }; + enum DeviceSubclass { + NoneSubclass, }; public: DSInput(); @@ -28,7 +31,7 @@ class DSInputDevice { public: DSInputDevice(); - DSInputDevice(std::string name, std::string identifier, DSInput::DeviceClass clas); + DSInputDevice(std::string name, std::string identifier, DSInput::DeviceClass devClass, DSInput::DeviceSubclass devSubclass); ~DSInputDevice(); std::string getName() const; @@ -38,13 +41,16 @@ public: void setIdentifier(std::string identifier); DSInput::DeviceClass getClass() const; - void setClass(DSInput::DeviceClass clas); + void setClass(DSInput::DeviceClass devClass); + + DSInput::DeviceSubclass getSubclass() const; + void setSubclass(DSInput::DeviceSubclass devSubclass); private: std::string __deviceName; std::string __deviceIdentifier; DSInput::DeviceClass __deviceClass; - + DSInput::DeviceSubclass __deviceSubclass; }; } -- 2.7.4 From d217315cc1e4d8415286ccc2a3369459102b2e84 Mon Sep 17 00:00:00 2001 From: jeon Date: Wed, 8 Jul 2020 16:13:29 +0900 Subject: [PATCH 12/16] DSInput: Add DSInputDevice's test cases Change-Id: Ie0ac1c63b343a64b9f3260f37f8ded37f4d4ecb2 --- src/DSInput/DSInput.cpp | 4 +-- tests/DSInput-test.cpp | 76 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 2 deletions(-) diff --git a/src/DSInput/DSInput.cpp b/src/DSInput/DSInput.cpp index 43b31d7..8fe740a 100644 --- a/src/DSInput/DSInput.cpp +++ b/src/DSInput/DSInput.cpp @@ -24,8 +24,8 @@ DSInput::~DSInput() } DSInputDevice::DSInputDevice() - : __deviceName(nullptr), - __deviceIdentifier(nullptr), + : __deviceName(""), + __deviceIdentifier(""), __deviceClass(DSInput::DeviceClass::NoneClass), __deviceSubclass(DSInput::DeviceSubclass::NoneSubclass) { diff --git a/tests/DSInput-test.cpp b/tests/DSInput-test.cpp index 3e4f18c..28aecb6 100644 --- a/tests/DSInput-test.cpp +++ b/tests/DSInput-test.cpp @@ -25,3 +25,79 @@ TEST_F(DSInputTest, BasicMethods) EXPECT_TRUE(true); } + +class DSInputDeviceTest : public ::testing::Test +{ +public: + void SetUp(void) override + {} + void TearDown(void) override + {} +}; + +TEST_F(DSInputDeviceTest, NewDSInputDevice) +{ + DSInputDevice *inputDevice = new DSInputDevice; + delete inputDevice; + inputDevice = new DSInputDevice("TestDevice", "virtual-0", DSInput::NoneClass, DSInput::NoneSubclass); + delete inputDevice; + ASSERT_TRUE(true); +} + +TEST_F(DSInputDeviceTest, DSInputDeviceSetGetName) +{ + std::string tName = "TestDevice"; + DSInputDevice *inputDevice = new DSInputDevice; + inputDevice->setName(tName); + std::string name = inputDevice->getName(); + EXPECT_TRUE(name.compare(tName) == 0); + delete inputDevice; +} + +TEST_F(DSInputDeviceTest, DSInputDeviceSetGetIdentifier) +{ + std::string tIdentifier = "virtual-0"; + DSInputDevice *inputDevice = new DSInputDevice; + inputDevice->setIdentifier(tIdentifier); + std::string identifier = inputDevice->getIdentifier(); + EXPECT_TRUE(identifier.compare(tIdentifier) == 0); + delete inputDevice; +} + +TEST_F(DSInputDeviceTest, DSInputDeviceSetGetClass) +{ + DSInput::DeviceClass tDevClass; + DSInput::DeviceClass devClass; + DSInputDevice *inputDevice = new DSInputDevice; + + tDevClass = DSInput::PointerClass; + inputDevice->setClass(tDevClass); + devClass = inputDevice->getClass(); + EXPECT_TRUE(tDevClass == devClass); + + tDevClass = DSInput::KeyboardClass; + inputDevice->setClass(tDevClass); + devClass = inputDevice->getClass(); + EXPECT_TRUE(tDevClass == devClass); + + tDevClass = DSInput::TouchClass; + inputDevice->setClass(tDevClass); + devClass = inputDevice->getClass(); + EXPECT_TRUE(tDevClass == devClass); + + delete inputDevice; +} + +TEST_F(DSInputDeviceTest, DSInputDeviceSetGetSubclass) +{ + DSInput::DeviceSubclass tDevSubclass; + DSInputDevice *inputDevice = new DSInputDevice; + + tDevSubclass = DSInput::NoneSubclass; + inputDevice->setSubclass(tDevSubclass); + DSInput::DeviceSubclass devSubclass = inputDevice->getSubclass(); + EXPECT_TRUE(tDevSubclass == devSubclass); + + delete inputDevice; +} + -- 2.7.4 From 17b2d63808fe97229d1116b129073449a1d76df7 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Wed, 8 Jul 2020 14:51:15 +0900 Subject: [PATCH 13/16] change the raw pointers into the smart pointers Change-Id: Idddc7a14ec8eed73899ebe2975169a8de9d6a481 --- samples/exampleCompositor.cpp | 58 ++++++++++++++++++------------------- src/DSCanvas/DSCanvas.cpp | 27 +++++++++++++---- src/DSCanvas/DSCanvas.h | 9 +++--- src/DSCompositor/DSCompositor.cpp | 2 -- src/DSCompositor/DSCompositor.h | 11 +++++++ src/DSDisplayArea/DSDisplayArea.cpp | 2 +- src/DSDisplayArea/DSDisplayArea.h | 5 ++-- src/DSInput/DSInput.h | 7 +++-- src/DSOutput/DSOutput.cpp | 4 +-- src/DSOutput/DSOutput.h | 2 ++ src/DSPolicyArea/DSPolicyArea.cpp | 2 +- src/DSPolicyArea/DSPolicyArea.h | 4 +-- src/DSSeat/DSSeat.cpp | 4 +-- src/DSSeat/DSSeat.h | 5 ++-- tests/DSCanvas-test.cpp | 15 +++++----- tests/DSCompositor-test.cpp | 43 ++++++++++++++++++++++----- tests/DSDisplayArea-test.cpp | 37 +++++++++++++---------- tests/DSOutput-test.cpp | 5 ++-- tests/DSPolicyArea-test.cpp | 17 ++++++----- tests/DSSeat-test.cpp | 6 ++-- tests/libds-tests.h | 1 + 21 files changed, 165 insertions(+), 101 deletions(-) diff --git a/samples/exampleCompositor.cpp b/samples/exampleCompositor.cpp index cae7261..a53ea35 100644 --- a/samples/exampleCompositor.cpp +++ b/samples/exampleCompositor.cpp @@ -44,66 +44,64 @@ class MyCompositor : public DSCompositor { public: MyCompositor() - { - int width, height; + : __canvas{nullptr}, + __seat{nullptr}, + __policyArea{nullptr}, + __displayArea{nullptr} + {} - width = __displayArea->getWidth(); - height = __displayArea->getHeight(); + virtual ~MyCompositor() + {} - __canvas = new DSCanvas(); + void _onPrepareCanvas() override + { + int width = __displayArea->getWidth(); + int height = __displayArea->getHeight(); - __policyArea = new DSPolicyArea(); - //__policyArea->selectWmPolicy(PolicyAreaWmPolicy::MOBILE); - //__policyArea->selectEffectPolicy(PolicyAreaEffectPolicy::MOBILE); + __policyArea = std::make_shared(); __policyArea->setPosition(0, 0); __policyArea->setSize(width, height); __policyArea->attachSeat(__seat); + __canvas = std::make_unique(); + __canvas->attachPolicyArea(__policyArea); __canvas->attachDisplayArea(__displayArea); } - virtual ~MyCompositor() - { - delete __policyArea; - delete __canvas; - } - - void OutputAdd(DSOutput *output) + void _onOutputAdded(std::shared_ptr output) override { // set the resolution. output->applyResolutionAuto(); - } - void OutputResolutionSet(DSOutput *output, int width, int height) - { - __displayArea = new DSDisplayArea(output); + // make a display area. + __displayArea = std::make_shared(output); __displayArea->setPosition(0, 0); - __displayArea->setSize(width, height); + __displayArea->setSize(output->getResolutionWidth(), output->getResolutionHeight()); } - void OutputRemove(DSOutput *output) + void _onOutputRemoved(std::shared_ptr output) override { - delete __displayArea; + __displayArea.reset(); // delete shared_ptr } - void InputAdd(DSInput *input) + void _onInputAdded(std::shared_ptr input) override { - __seat = new DSSeat(); + __seat = std::make_shared(); __seat->addInput(input); // add an input device to a seat } - void InputRemove(DSInput *input) + void _onInputRemoved(std::shared_ptr input) override { __seat->removeInput(input); // remove an input device from a seat - delete(__seat); + __seat.reset(); // delete shared_ptr } private: - DSCanvas *__canvas; - DSSeat *__seat; - DSPolicyArea *__policyArea; - DSDisplayArea *__displayArea; + std::unique_ptr __canvas; + std::shared_ptr __seat; + std::shared_ptr __policyArea; + std::shared_ptr __displayArea; }; int main() { diff --git a/src/DSCanvas/DSCanvas.cpp b/src/DSCanvas/DSCanvas.cpp index 1dbb985..f952083 100644 --- a/src/DSCanvas/DSCanvas.cpp +++ b/src/DSCanvas/DSCanvas.cpp @@ -1,24 +1,39 @@ #include "DSCanvas.h" +#include "DSDebugLog.h" namespace display_server { DSCanvas::DSCanvas() - : __polcyArea(nullptr), + : __policyArea(nullptr), __displayArea(nullptr) {} DSCanvas::~DSCanvas() {} -bool DSCanvas::attachPolicyArea(DSPolicyArea *polcyArea) +bool DSCanvas::attachPolicyArea(std::shared_ptr policyArea) { - return false; + if (policyArea) { + DSLOG_ERR("DSCanvas", "canvas has already policyArea(%p).", policyArea); + return false; + } + + __policyArea = policyArea; + + return true; } -bool DSCanvas::attachDisplayArea(DSDisplayArea *displayArea) +bool DSCanvas::attachDisplayArea(std::shared_ptr displayArea) { - return false; + if (__displayArea) { + DSLOG_ERR("DSCanvas", "canvas has already displayArea(%p).", __displayArea); + return false; + } + + __displayArea = displayArea; + + return true; } -} // namespace display_server \ No newline at end of file +} // namespace display_server diff --git a/src/DSCanvas/DSCanvas.h b/src/DSCanvas/DSCanvas.h index 0d45cad..6e62fe2 100644 --- a/src/DSCanvas/DSCanvas.h +++ b/src/DSCanvas/DSCanvas.h @@ -3,6 +3,7 @@ #include #include +#include namespace display_server { @@ -12,12 +13,12 @@ public: DSCanvas(); virtual ~DSCanvas(); - bool attachPolicyArea(DSPolicyArea *polcyArea); - bool attachDisplayArea(DSDisplayArea *displayArea); + bool attachPolicyArea(std::shared_ptr polcyArea); + bool attachDisplayArea(std::shared_ptr displayArea); private: - DSPolicyArea *__polcyArea; - DSDisplayArea *__displayArea; + std::shared_ptr __policyArea; + std::shared_ptr __displayArea; }; } diff --git a/src/DSCompositor/DSCompositor.cpp b/src/DSCompositor/DSCompositor.cpp index 2733cd6..94a7db4 100644 --- a/src/DSCompositor/DSCompositor.cpp +++ b/src/DSCompositor/DSCompositor.cpp @@ -1,8 +1,6 @@ #include "DSCompositor.h" #include "DSDebugLog.h" -#include - namespace display_server { diff --git a/src/DSCompositor/DSCompositor.h b/src/DSCompositor/DSCompositor.h index 24d294e..b950aa7 100644 --- a/src/DSCompositor/DSCompositor.h +++ b/src/DSCompositor/DSCompositor.h @@ -2,7 +2,10 @@ #define __DS_COMPOSITOR_H__ #include "DSEventLoop.h" +#include "DSOutput.h" +#include "DSInput.h" #include + namespace display_server { @@ -15,6 +18,14 @@ public: bool run(); bool quit(); +protected: + virtual void _onPrepareCanvas() = 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; + virtual void _onInputRemoved(std::shared_ptr input) = 0; + private: std::unique_ptr __eventLoop; diff --git a/src/DSDisplayArea/DSDisplayArea.cpp b/src/DSDisplayArea/DSDisplayArea.cpp index a3ab96b..81b9035 100644 --- a/src/DSDisplayArea/DSDisplayArea.cpp +++ b/src/DSDisplayArea/DSDisplayArea.cpp @@ -11,7 +11,7 @@ DSDisplayArea::DSDisplayArea() __height(0) {} -DSDisplayArea::DSDisplayArea(DSOutput *output) +DSDisplayArea::DSDisplayArea(std::shared_ptr output) : __output(output), __x(0), __y(0), diff --git a/src/DSDisplayArea/DSDisplayArea.h b/src/DSDisplayArea/DSDisplayArea.h index 3e3cc99..87fea02 100644 --- a/src/DSDisplayArea/DSDisplayArea.h +++ b/src/DSDisplayArea/DSDisplayArea.h @@ -2,6 +2,7 @@ #define _DSDISPLAYAREA_H_ #include +#include namespace display_server { @@ -10,7 +11,7 @@ class DSDisplayArea public: DSDisplayArea(); - DSDisplayArea(DSOutput *output); + DSDisplayArea(std::shared_ptr output); virtual ~DSDisplayArea(); bool setPosition(int x, int y); @@ -19,7 +20,7 @@ public: int getHeight(); private: - DSOutput *__output; + std::shared_ptr __output; int __x, __y; int __width, __height; }; diff --git a/src/DSInput/DSInput.h b/src/DSInput/DSInput.h index a05d5e3..fa63afb 100644 --- a/src/DSInput/DSInput.h +++ b/src/DSInput/DSInput.h @@ -1,8 +1,11 @@ #ifndef _DSINPUT_H_ #define _DSINPUT_H_ -#include "DSCore.h" -#include "DSObject.h" +#include +#include +#include +#include +#include namespace display_server { diff --git a/src/DSOutput/DSOutput.cpp b/src/DSOutput/DSOutput.cpp index c9a18e7..095fc9c 100644 --- a/src/DSOutput/DSOutput.cpp +++ b/src/DSOutput/DSOutput.cpp @@ -3,8 +3,8 @@ namespace display_server { DSOutput::DSOutput() - : __resolutionWidth(0), - __resolutionHeight(0) + : __resolutionWidth{0}, + __resolutionHeight{0} {} DSOutput::~DSOutput() diff --git a/src/DSOutput/DSOutput.h b/src/DSOutput/DSOutput.h index 47d279d..2587ca6 100644 --- a/src/DSOutput/DSOutput.h +++ b/src/DSOutput/DSOutput.h @@ -1,6 +1,8 @@ #ifndef _DSOUTPUT_H_ #define _DSOUTPUT_H_ +#include + namespace display_server { diff --git a/src/DSPolicyArea/DSPolicyArea.cpp b/src/DSPolicyArea/DSPolicyArea.cpp index d9d1241..18b3138 100644 --- a/src/DSPolicyArea/DSPolicyArea.cpp +++ b/src/DSPolicyArea/DSPolicyArea.cpp @@ -23,7 +23,7 @@ bool DSPolicyArea::setSize(int width, int height) return false; } -bool DSPolicyArea::attachSeat(DSSeat *seat) +bool DSPolicyArea::attachSeat(std::shared_ptr seat) { return false; } diff --git a/src/DSPolicyArea/DSPolicyArea.h b/src/DSPolicyArea/DSPolicyArea.h index 9264548..bffa273 100644 --- a/src/DSPolicyArea/DSPolicyArea.h +++ b/src/DSPolicyArea/DSPolicyArea.h @@ -13,12 +13,12 @@ public: bool setPosition(int x, int y); bool setSize(int width, int height); - bool attachSeat(DSSeat *seat); + bool attachSeat(std::shared_ptr seat); private: int __x, __y; int __width, __height; - DSSeat *__seat; + std::shared_ptr __seat; }; } diff --git a/src/DSSeat/DSSeat.cpp b/src/DSSeat/DSSeat.cpp index 69e29ac..df0657e 100644 --- a/src/DSSeat/DSSeat.cpp +++ b/src/DSSeat/DSSeat.cpp @@ -13,12 +13,12 @@ DSSeat::DSSeat() DSSeat::~DSSeat() {} -bool DSSeat::addInput(DSInput *input) +bool DSSeat::addInput(std::shared_ptr input) { return false; } -bool DSSeat::removeInput(DSInput *input) +bool DSSeat::removeInput(std::shared_ptr input) { return false; } diff --git a/src/DSSeat/DSSeat.h b/src/DSSeat/DSSeat.h index 97bc076..b0a2d2d 100644 --- a/src/DSSeat/DSSeat.h +++ b/src/DSSeat/DSSeat.h @@ -2,6 +2,7 @@ #define _DSSEAT_H_ #include +#include namespace display_server { @@ -16,8 +17,8 @@ public: DSSeat(); virtual ~DSSeat(); - bool addInput(DSInput *input); - bool removeInput(DSInput *input); + bool addInput(std::shared_ptr input); + bool removeInput(std::shared_ptr input); private: DSInput *__input; diff --git a/tests/DSCanvas-test.cpp b/tests/DSCanvas-test.cpp index c9138df..a0946d0 100644 --- a/tests/DSCanvas-test.cpp +++ b/tests/DSCanvas-test.cpp @@ -14,17 +14,18 @@ public: TEST_F(DSCanvasTest, NewDSCanvas) { - DSCanvas *canvas = new DSCanvas; - delete canvas; - ASSERT_TRUE(true); + std::unique_ptr canvas = std::make_unique(); + EXPECT_TRUE(canvas != nullptr); } TEST_F(DSCanvasTest, BasicMethods) { DSCanvas canvas; - DSPolicyArea policyArea; - DSDisplayArea displayArea; + auto policyArea = std::make_shared(); + EXPECT_TRUE(policyArea != nullptr); + auto displayArea = std::make_shared(); + EXPECT_TRUE(displayArea != nullptr); - EXPECT_TRUE(canvas.attachPolicyArea(&policyArea) == true); - EXPECT_TRUE(canvas.attachDisplayArea(&displayArea) == true); + EXPECT_TRUE(canvas.attachPolicyArea(policyArea) == true); + EXPECT_TRUE(canvas.attachDisplayArea(displayArea) == true); } \ No newline at end of file diff --git a/tests/DSCompositor-test.cpp b/tests/DSCompositor-test.cpp index af1dcf5..8404f23 100644 --- a/tests/DSCompositor-test.cpp +++ b/tests/DSCompositor-test.cpp @@ -8,34 +8,61 @@ class DSCompositorTest : public ::testing::Test { public: void SetUp(void) override - {} + { + // for wl_display_add_socket(private_loop->wl_display, "tdm-socket") at tdm_server_init + setenv("XDG_RUNTIME_DIR", "/run", 1); + } void TearDown(void) override + { + unsetenv("XDG_RUNTIME_DIR"); + } +}; + +class MockCompositor : public DSCompositor +{ +public: + MockCompositor() {} + ~MockCompositor() {} + + void _onPrepareCanvas() override + {} + + void _onOutputAdded(std::shared_ptr output) override + {} + + void _onOutputRemoved(std::shared_ptr output) override + {} + + void _onInputAdded(std::shared_ptr input) override + {} + + void _onInputRemoved(std::shared_ptr input) override {} }; TEST_F(DSCompositorTest, NewDSCompositor) { - DSCompositor *compositor = new DSCompositor; - delete compositor; - EXPECT_TRUE(true); + std::shared_ptr compositor = std::make_shared(); + EXPECT_TRUE(compositor != nullptr); } TEST_F(DSCompositorTest, RunAndQuit) { - DSCompositor compositor; + std::shared_ptr compositor = std::make_shared(); + EXPECT_TRUE(compositor != nullptr); Ecore_Timer *timer = nullptr; double delayInSecond = 1.0; auto cb = [](void *data) -> Eina_Bool { - DSCompositor *comp = (DSCompositor *)data; + MockCompositor *comp = (MockCompositor *)data; EXPECT_TRUE(comp->quit() == true); return EINA_FALSE; }; - timer = ecore_timer_loop_add(delayInSecond, cb, &compositor); + timer = ecore_timer_loop_add(delayInSecond, cb, compositor.get()); EXPECT_TRUE(timer != nullptr); if (timer != nullptr) { - EXPECT_TRUE(compositor.run() == true); + EXPECT_TRUE(compositor->run() == true); } } diff --git a/tests/DSDisplayArea-test.cpp b/tests/DSDisplayArea-test.cpp index a8de0ad..8794aa0 100644 --- a/tests/DSDisplayArea-test.cpp +++ b/tests/DSDisplayArea-test.cpp @@ -1,5 +1,6 @@ #include "libds-tests.h" #include "DSDisplayArea.h" +#include "DSDisplayDeviceOutputTDMImpl.h" using namespace display_server; @@ -7,31 +8,35 @@ class DSDisplayAreaTest : public ::testing::Test { public: void SetUp(void) override - {} + { + // for wl_display_add_socket(private_loop->wl_display, "tdm-socket") at tdm_server_init + setenv("XDG_RUNTIME_DIR", "/run", 1); + } void TearDown(void) override - {} + { + unsetenv("XDG_RUNTIME_DIR"); + } }; TEST_F(DSDisplayAreaTest, NewDSDisplayArea) { - DSDisplayArea *displayArea = new DSDisplayArea; - delete displayArea; + auto output = std::make_shared(); + EXPECT_TRUE(output != nullptr); - DSOutput *output = new DSOutput; - DSDisplayArea *displayArea1 = new DSDisplayArea(output); - delete displayArea1; - delete output; - - ASSERT_TRUE(true); + auto displayArea = std::make_unique(output); + EXPECT_TRUE(displayArea != nullptr); } TEST_F(DSDisplayAreaTest, BasicMethods) { - DSOutput output; - DSDisplayArea displayArea(&output); + auto output = std::make_shared(); + EXPECT_TRUE(output != nullptr); + + auto displayArea = std::make_unique(output); + EXPECT_TRUE(displayArea != nullptr); - EXPECT_TRUE(displayArea.setPosition(0, 0) != 0); - EXPECT_TRUE(displayArea.setSize(100, 100) != 0); - EXPECT_TRUE(displayArea.getHeight() != 0); - EXPECT_TRUE(displayArea.getWidth() != 0); + EXPECT_TRUE(displayArea->setPosition(0, 0) != 0); + EXPECT_TRUE(displayArea->setSize(100, 100) != 0); + EXPECT_TRUE(displayArea->getHeight() != 0); + EXPECT_TRUE(displayArea->getWidth() != 0); } diff --git a/tests/DSOutput-test.cpp b/tests/DSOutput-test.cpp index 5b8b046..9ac5a15 100644 --- a/tests/DSOutput-test.cpp +++ b/tests/DSOutput-test.cpp @@ -14,9 +14,8 @@ public: TEST_F(DSOutputTest, NewDSOutput) { - DSOutput *output = new DSOutput; - delete output; - ASSERT_TRUE(true); + std::shared_ptr output = std::make_shared(); + EXPECT_TRUE(output != nullptr); } TEST_F(DSOutputTest, BasicMethods) diff --git a/tests/DSPolicyArea-test.cpp b/tests/DSPolicyArea-test.cpp index ed4e1a4..1db77f0 100644 --- a/tests/DSPolicyArea-test.cpp +++ b/tests/DSPolicyArea-test.cpp @@ -14,17 +14,18 @@ public: TEST_F(DSPolicyAreaTest, NewDSPolicyArea) { - DSPolicyArea *policyArea = new DSPolicyArea; - delete policyArea; - ASSERT_TRUE(true); + std::unique_ptr policyArea = std::make_unique(); + EXPECT_TRUE(policyArea != nullptr); } TEST_F(DSPolicyAreaTest, BasicMethods) { - DSPolicyArea policyArea; - DSSeat seat; + std::unique_ptr policyArea = std::make_unique(); + EXPECT_TRUE(policyArea != nullptr); + std::shared_ptr seat = std::make_shared(); + EXPECT_TRUE(seat != nullptr); - EXPECT_TRUE(policyArea.setPosition(10, 10) == true); - EXPECT_TRUE(policyArea.setSize(100, 100) == true); - EXPECT_TRUE(policyArea.attachSeat(&seat) == true); + EXPECT_TRUE(policyArea->setPosition(10, 10) == true); + EXPECT_TRUE(policyArea->setSize(100, 100) == true); + EXPECT_TRUE(policyArea->attachSeat(seat) == true); } \ No newline at end of file diff --git a/tests/DSSeat-test.cpp b/tests/DSSeat-test.cpp index 40128cd..4cc99ac 100644 --- a/tests/DSSeat-test.cpp +++ b/tests/DSSeat-test.cpp @@ -22,8 +22,8 @@ TEST_F(DSSeatTest, NewDSSeat) TEST_F(DSSeatTest, BasicMethods) { DSSeat seat; - DSInput input; + auto input = std::make_shared(); - EXPECT_TRUE(seat.addInput(&input) == true); - EXPECT_TRUE(seat.removeInput(&input) == true); + EXPECT_TRUE(seat.addInput(input) == true); + EXPECT_TRUE(seat.removeInput(input) == true); } diff --git a/tests/libds-tests.h b/tests/libds-tests.h index 6f280b7..8965fec 100644 --- a/tests/libds-tests.h +++ b/tests/libds-tests.h @@ -30,6 +30,7 @@ #define _LIBDS_TESTS_H_ #include +#include #include #include "DSDebugLog.h" -- 2.7.4 From ff56d2497db5d3fcc4947b3a801634e653e50c4d Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Wed, 8 Jul 2020 17:25:58 +0900 Subject: [PATCH 14/16] DSCompositor: make the DSCompositorPrivate. use Pimpl pattern on DSCompsitor Change-Id: I3199c8653bb57a16a710f5a949e971a3d6211e8b --- src/DSCompositor/DSCompositor.cpp | 41 +++++++++++++++++++++++++++++++--- src/DSCompositor/DSCompositor.h | 19 ++++++++-------- src/DSCompositor/DSCompositorPrivate.h | 30 +++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 13 deletions(-) create mode 100644 src/DSCompositor/DSCompositorPrivate.h diff --git a/src/DSCompositor/DSCompositor.cpp b/src/DSCompositor/DSCompositor.cpp index 94a7db4..8a54e48 100644 --- a/src/DSCompositor/DSCompositor.cpp +++ b/src/DSCompositor/DSCompositor.cpp @@ -1,18 +1,53 @@ #include "DSCompositor.h" +#include "DSCompositorPrivate.h" #include "DSDebugLog.h" +#include namespace display_server { DSCompositor::DSCompositor() + : DS_INIT_PRIVATE_PTR(DSCompositor) +{} + +DSCompositor::~DSCompositor() +{} + +bool DSCompositor::run() +{ + DS_GET_PRIV(DSCompositor); + + if (!priv->run()) { + DSLOG_ERR("Compositor", "priv->run() fails."); + return false; + } + + return true; +} + +bool DSCompositor::quit() +{ + DS_GET_PRIV(DSCompositor); + + if (!priv->quit()) { + DSLOG_ERR("Compositor", "priv->quit() fails."); + return false; + } + + return true; +} + +DSCompositorPrivate::DSCompositorPrivate(DSCompositor *p_ptr) + : DSObjectPrivate(p_ptr), + __p_ptr(p_ptr) { __eventLoop = std::make_unique(); } -DSCompositor::~DSCompositor() +DSCompositorPrivate::~DSCompositorPrivate() {} -bool DSCompositor::run() +bool DSCompositorPrivate::run() { if (!__eventLoop->run()) { DSLOG_ERR("Compositor", "__eventLoop->run() fails."); @@ -22,7 +57,7 @@ bool DSCompositor::run() return true; } -bool DSCompositor::quit() +bool DSCompositorPrivate::quit() { if (!__eventLoop->quit()) { DSLOG_ERR("Compositor", "__eventLoop->quit() fails."); diff --git a/src/DSCompositor/DSCompositor.h b/src/DSCompositor/DSCompositor.h index b950aa7..5963cce 100644 --- a/src/DSCompositor/DSCompositor.h +++ b/src/DSCompositor/DSCompositor.h @@ -1,18 +1,22 @@ #ifndef __DS_COMPOSITOR_H__ #define __DS_COMPOSITOR_H__ -#include "DSEventLoop.h" -#include "DSOutput.h" -#include "DSInput.h" +#include +#include +#include +#include #include namespace display_server { -class DSCompositor +class DSCompositorPrivate; + +class DSCompositor : public DSObject { +DS_PIMPL_USE_PRIVATE(DSCompositor); public: - DSCompositor(); + explicit DSCompositor(); virtual ~DSCompositor(); bool run(); @@ -20,15 +24,10 @@ public: protected: virtual void _onPrepareCanvas() = 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; virtual void _onInputRemoved(std::shared_ptr input) = 0; - -private: - std::unique_ptr __eventLoop; - }; } diff --git a/src/DSCompositor/DSCompositorPrivate.h b/src/DSCompositor/DSCompositorPrivate.h new file mode 100644 index 0000000..797b9cb --- /dev/null +++ b/src/DSCompositor/DSCompositorPrivate.h @@ -0,0 +1,30 @@ +#ifndef __DS_COMPOSITORPRIVATE_H__ +#define __DS_COMPOSITORPRIVATE_H__ + +#include "DSCompositor.h" +#include "DSEventLoop.h" +#include + +namespace display_server +{ + +class DSCompositorPrivate : public DSObjectPrivate +{ +DS_PIMPL_USE_PUBLIC(DSCompositor); +public: + DSCompositorPrivate() = delete; + DSCompositorPrivate(DSCompositor *p_ptr); + ~DSCompositorPrivate(); + + bool run(); + bool quit(); + +protected: + +private: + std::unique_ptr __eventLoop; +}; + +} + +#endif -- 2.7.4 From e316b81af93d5a51cb88b90861f2ad83ccaac81f Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Wed, 8 Jul 2020 18:32:19 +0900 Subject: [PATCH 15/16] DSCanvas: make the DSCanvasPrivate. use Pimpl pattern on DSCanvas Change-Id: I3b9811531ddf784f5f36b0c800540eca5bf41b99 --- src/DSCanvas/DSCanvas.cpp | 42 ++++++++++++++++++++++++++++++++++++------ src/DSCanvas/DSCanvas.h | 19 +++++++++++-------- src/DSCanvas/DSCanvasPrivate.h | 27 +++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 14 deletions(-) create mode 100644 src/DSCanvas/DSCanvasPrivate.h diff --git a/src/DSCanvas/DSCanvas.cpp b/src/DSCanvas/DSCanvas.cpp index f952083..bc9f066 100644 --- a/src/DSCanvas/DSCanvas.cpp +++ b/src/DSCanvas/DSCanvas.cpp @@ -1,12 +1,12 @@ #include "DSCanvas.h" +#include "DSCanvasPrivate.h" #include "DSDebugLog.h" namespace display_server { DSCanvas::DSCanvas() - : __policyArea(nullptr), - __displayArea(nullptr) + : DS_INIT_PRIVATE_PTR(DSCanvas) {} DSCanvas::~DSCanvas() @@ -14,8 +14,38 @@ DSCanvas::~DSCanvas() bool DSCanvas::attachPolicyArea(std::shared_ptr policyArea) { - if (policyArea) { - DSLOG_ERR("DSCanvas", "canvas has already policyArea(%p).", policyArea); + DS_GET_PRIV(DSCanvas); + + if (!priv->attachPolicyArea(policyArea)) + return false; + + return true; +} + +bool DSCanvas::attachDisplayArea(std::shared_ptr displayArea) +{ + DS_GET_PRIV(DSCanvas); + + if (!priv->attachDisplayArea(displayArea)) + return false; + + return true; +} + +DSCanvasPrivate::DSCanvasPrivate(DSCanvas *p_ptr) + : DSObjectPrivate(p_ptr), + __p_ptr(p_ptr), + __policyArea(nullptr), + __displayArea(nullptr) +{} + +DSCanvasPrivate::~DSCanvasPrivate() +{} + +bool DSCanvasPrivate::attachPolicyArea(std::shared_ptr policyArea) +{ + if (__policyArea) { + DSLOG_ERR("DSCanvasPrivate", "canvas has already policyArea(%p).", policyArea); return false; } @@ -24,10 +54,10 @@ bool DSCanvas::attachPolicyArea(std::shared_ptr policyArea) return true; } -bool DSCanvas::attachDisplayArea(std::shared_ptr displayArea) +bool DSCanvasPrivate::attachDisplayArea(std::shared_ptr displayArea) { if (__displayArea) { - DSLOG_ERR("DSCanvas", "canvas has already displayArea(%p).", __displayArea); + DSLOG_ERR("DSCanvasPrivate", "canvas has already displayArea(%p).", __displayArea); return false; } diff --git a/src/DSCanvas/DSCanvas.h b/src/DSCanvas/DSCanvas.h index 6e62fe2..1be8ead 100644 --- a/src/DSCanvas/DSCanvas.h +++ b/src/DSCanvas/DSCanvas.h @@ -1,25 +1,28 @@ -#ifndef _DSCANVAS_H_ -#define _DSCANVAS_H_ +#ifndef __DS_CANVAS_H__ +#define __DS_CANVAS_H__ +#include +#include #include #include #include namespace display_server { -class DSCanvas + +class DSCanvasPrivate; + +class DSCanvas : public DSObject { +DS_PIMPL_USE_PRIVATE(DSCanvas); public: - DSCanvas(); + explicit DSCanvas(); virtual ~DSCanvas(); bool attachPolicyArea(std::shared_ptr polcyArea); bool attachDisplayArea(std::shared_ptr displayArea); - -private: - std::shared_ptr __policyArea; - std::shared_ptr __displayArea; }; + } #endif \ No newline at end of file diff --git a/src/DSCanvas/DSCanvasPrivate.h b/src/DSCanvas/DSCanvasPrivate.h new file mode 100644 index 0000000..bded0a9 --- /dev/null +++ b/src/DSCanvas/DSCanvasPrivate.h @@ -0,0 +1,27 @@ +#ifndef __DS_CANVAS_PRIVATE_H__ +#define __DS_CANVAS_PRIVATE_H__ + +#include "DSCanvas.h" + +namespace display_server +{ + +class DSCanvasPrivate : public DSObjectPrivate +{ +DS_PIMPL_USE_PUBLIC(DSCanvas); +public: + DSCanvasPrivate() = delete; + DSCanvasPrivate(DSCanvas *p_ptr); + ~DSCanvasPrivate(); + + bool attachPolicyArea(std::shared_ptr polcyArea); + bool attachDisplayArea(std::shared_ptr displayArea); + +private: + std::shared_ptr __policyArea; + std::shared_ptr __displayArea; +}; + +} + +#endif \ No newline at end of file -- 2.7.4 From 6ef90dad8d4ae2eb5f16d82fb646facd92b08975 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Thu, 9 Jul 2020 14:02:11 +0900 Subject: [PATCH 16/16] DSDisplayArea: make the DSDisplayAreaPrivate. use Pimpl pattern on DSDisplayArea Change-Id: I08da8fcbaa60fb917399c0bc653fbd9975c1934e --- src/DSDisplayArea/DSDisplayArea.cpp | 87 ++++++++++++++++++++++++++------ src/DSDisplayArea/DSDisplayArea.h | 21 ++++---- src/DSDisplayArea/DSDisplayAreaPrivate.h | 35 +++++++++++++ tests/DSCanvas-test.cpp | 22 +++++--- tests/DSDisplayArea-test.cpp | 1 - 5 files changed, 131 insertions(+), 35 deletions(-) create mode 100644 src/DSDisplayArea/DSDisplayAreaPrivate.h diff --git a/src/DSDisplayArea/DSDisplayArea.cpp b/src/DSDisplayArea/DSDisplayArea.cpp index 81b9035..52c4e0a 100644 --- a/src/DSDisplayArea/DSDisplayArea.cpp +++ b/src/DSDisplayArea/DSDisplayArea.cpp @@ -1,39 +1,88 @@ #include "DSDisplayArea.h" +#include "DSDisplayAreaPrivate.h" +#include "DSDebugLog.h" namespace display_server { -DSDisplayArea::DSDisplayArea() - : __output(nullptr), - __x(0), - __y(0), - __width(0), - __height(0) +DSDisplayArea::DSDisplayArea(std::shared_ptr output) + : _d_ptr(std::make_unique(this, output)) {} -DSDisplayArea::DSDisplayArea(std::shared_ptr output) - : __output(output), +DSDisplayArea::~DSDisplayArea() +{} + +bool DSDisplayArea::setPosition(int x, int y) +{ + DS_GET_PRIV(DSDisplayArea); + + if (!priv->setPosition(x, y)) + return false; + + return true; +} + +bool DSDisplayArea::setSize(int width, int height) +{ + DS_GET_PRIV(DSDisplayArea); + + if (!priv->setSize(width, height)) + return false; + + return true; +} + +int DSDisplayArea::getWidth() +{ + DS_GET_PRIV(DSDisplayArea); + + return priv->getWidth(); +} + +int DSDisplayArea::getHeight() +{ + DS_GET_PRIV(DSDisplayArea); + + return priv->getHeight(); +} + +std::shared_ptr DSDisplayArea::getOutput() +{ + DS_GET_PRIV(DSDisplayArea); + + return priv->getOutput(); +} + +DSDisplayAreaPrivate::DSDisplayAreaPrivate(DSDisplayArea *p_ptr, std::shared_ptr output) + : DSObjectPrivate(p_ptr), + __p_ptr(p_ptr), + __output(output), __x(0), __y(0), __width(0), __height(0) {} -DSDisplayArea::~DSDisplayArea() +DSDisplayAreaPrivate::~DSDisplayAreaPrivate() {} -bool DSDisplayArea::setPosition(int x, int y) +bool DSDisplayAreaPrivate::setPosition(int x, int y) { - // position to canvas. - return false; + __x = x; + __y = y; + + return true; } -bool DSDisplayArea::setSize(int width, int height) +bool DSDisplayAreaPrivate::setSize(int width, int height) { - return false; + __width = width; + __height = height; + + return true; } -int DSDisplayArea::getWidth() +int DSDisplayAreaPrivate::getWidth() { if (__output == nullptr) return -1; @@ -41,7 +90,7 @@ int DSDisplayArea::getWidth() return __width; } -int DSDisplayArea::getHeight() +int DSDisplayAreaPrivate::getHeight() { if (__output == nullptr) return -1; @@ -49,4 +98,10 @@ int DSDisplayArea::getHeight() return __height; } +std::shared_ptr DSDisplayAreaPrivate::getOutput() +{ + return __output; +} + + } // namespace display_server diff --git a/src/DSDisplayArea/DSDisplayArea.h b/src/DSDisplayArea/DSDisplayArea.h index 87fea02..6c1f1bf 100644 --- a/src/DSDisplayArea/DSDisplayArea.h +++ b/src/DSDisplayArea/DSDisplayArea.h @@ -1,28 +1,27 @@ -#ifndef _DSDISPLAYAREA_H_ -#define _DSDISPLAYAREA_H_ +#ifndef __DS_DISPLAY_AREA_H__ +#define __DS_DISPLAY_AREA_H__ +#include +#include #include #include namespace display_server { -class DSDisplayArea -{ +class DSDisplayAreaPrivate; +class DSDisplayArea : public DSObject +{ +DS_PIMPL_USE_PRIVATE(DSDisplayArea); public: - DSDisplayArea(); - DSDisplayArea(std::shared_ptr output); + explicit DSDisplayArea(std::shared_ptr output); virtual ~DSDisplayArea(); bool setPosition(int x, int y); bool setSize(int width, int height); int getWidth(); int getHeight(); - -private: - std::shared_ptr __output; - int __x, __y; - int __width, __height; + std::shared_ptr getOutput(); }; } diff --git a/src/DSDisplayArea/DSDisplayAreaPrivate.h b/src/DSDisplayArea/DSDisplayAreaPrivate.h new file mode 100644 index 0000000..761c03b --- /dev/null +++ b/src/DSDisplayArea/DSDisplayAreaPrivate.h @@ -0,0 +1,35 @@ +#ifndef __DS_DISPLAY_AREA_PRIVATE_H__ +#define __DS_DISPLAY_AREA_PRIVATE_H__ + +#include "DSDisplayArea.h" +#include +#include + +namespace display_server +{ + +class DSDisplayAreaPrivate : public DSObjectPrivate +{ +DS_PIMPL_USE_PUBLIC(DSDisplayArea); +public: + DSDisplayAreaPrivate() = delete; + DSDisplayAreaPrivate(DSDisplayArea *p_ptr, std::shared_ptr output); + virtual ~DSDisplayAreaPrivate(); + + bool setPosition(int x, int y); + bool setSize(int width, int height); + int getWidth(); + int getHeight(); + + bool setOutput(std::shared_ptr output); + std::shared_ptr getOutput(); + +private: + std::shared_ptr __output; + int __x, __y; + int __width, __height; +}; + +} + +#endif \ No newline at end of file diff --git a/tests/DSCanvas-test.cpp b/tests/DSCanvas-test.cpp index a0946d0..3850ba5 100644 --- a/tests/DSCanvas-test.cpp +++ b/tests/DSCanvas-test.cpp @@ -18,14 +18,22 @@ TEST_F(DSCanvasTest, NewDSCanvas) EXPECT_TRUE(canvas != nullptr); } -TEST_F(DSCanvasTest, BasicMethods) +TEST_F(DSCanvasTest, attachPolicyArea) { - DSCanvas canvas; + std::unique_ptr canvas = std::make_unique(); + EXPECT_TRUE(canvas != nullptr); auto policyArea = std::make_shared(); EXPECT_TRUE(policyArea != nullptr); - auto displayArea = std::make_shared(); - EXPECT_TRUE(displayArea != nullptr); + EXPECT_TRUE(canvas->attachPolicyArea(policyArea) == true); +} - EXPECT_TRUE(canvas.attachPolicyArea(policyArea) == true); - EXPECT_TRUE(canvas.attachDisplayArea(displayArea) == true); -} \ No newline at end of file +TEST_F(DSCanvasTest, displayArea_Negetive1) +{ + std::unique_ptr canvas = std::make_unique(); + EXPECT_TRUE(canvas != nullptr); + auto output = std::make_shared(); + EXPECT_TRUE(output != nullptr); + auto displayArea = std::make_shared(output); + EXPECT_TRUE(displayArea != nullptr); + EXPECT_TRUE(canvas->attachDisplayArea(displayArea) == false); +} diff --git a/tests/DSDisplayArea-test.cpp b/tests/DSDisplayArea-test.cpp index 8794aa0..1361d83 100644 --- a/tests/DSDisplayArea-test.cpp +++ b/tests/DSDisplayArea-test.cpp @@ -1,6 +1,5 @@ #include "libds-tests.h" #include "DSDisplayArea.h" -#include "DSDisplayDeviceOutputTDMImpl.h" using namespace display_server; -- 2.7.4