From 2f8866eb9fecc82191de0566cd837b483497e9af Mon Sep 17 00:00:00 2001 From: Doyoun Kang Date: Fri, 14 Aug 2020 16:31:47 +0900 Subject: [PATCH] DSWindowManager: initial code for DSWindowManager Class Change-Id: I90e9ac5ae820c9e333db73bb16efc34501566d32 --- src/DSCompositor/DSCompositor.cpp | 10 ++- src/DSCompositor/DSCompositorPrivate.h | 3 + src/DSWindowManager/DSWindowManager.cpp | 95 ++++++++++++++++++++++++++++ src/DSWindowManager/DSWindowManager.h | 59 +++++++++++++++++ src/DSWindowManager/DSWindowManagerPrivate.h | 46 ++++++++++++++ src/meson.build | 2 + tests/DSWindowManager-test.cpp | 47 ++++++++++++++ tests/meson.build | 1 + 8 files changed, 262 insertions(+), 1 deletion(-) create mode 100644 src/DSWindowManager/DSWindowManager.cpp create mode 100644 src/DSWindowManager/DSWindowManager.h create mode 100644 src/DSWindowManager/DSWindowManagerPrivate.h create mode 100644 tests/DSWindowManager-test.cpp diff --git a/src/DSCompositor/DSCompositor.cpp b/src/DSCompositor/DSCompositor.cpp index 5e70a1b..c86bba3 100644 --- a/src/DSCompositor/DSCompositor.cpp +++ b/src/DSCompositor/DSCompositor.cpp @@ -71,7 +71,8 @@ DSCompositorPrivate::DSCompositorPrivate(DSCompositor *p_ptr) __p_ptr(p_ptr), __displayDevice(nullptr), __canvas(nullptr), - __dsAppinfoMgr(nullptr) + __dsAppinfoMgr(nullptr), + __dsWindowMgr(nullptr) { __eventLoop = DSEventLoop::getInstance(); @@ -81,6 +82,7 @@ DSCompositorPrivate::DSCompositorPrivate(DSCompositor *p_ptr) DSCompositorPrivate::~DSCompositorPrivate() { + DSWindowManager::releaseInstance(); DSWaylandCompositor::releaseInstance(); DSBufferManager::releaseInstance(); DSEventLoop::releaseInstance(); @@ -95,6 +97,7 @@ bool DSCompositorPrivate::run() __initializeOutputs(); __initializeBufferManager(); __initializeTizenAppinfoMgr(); + __initializeWindowManager(); __canvas = pub->_onInitialized(); if (!__canvas) { DSLOG_ERR("Compositor", "_onInitialized() fails."); @@ -155,4 +158,9 @@ void DSCompositorPrivate::__initializeTizenAppinfoMgr() __dsAppinfoMgr = DSTizenAppinfoMgr::getInstance(); } +void DSCompositorPrivate::__initializeWindowManager() +{ + __dsWindowMgr = DSWindowManager::getInstance(); +} + } // namespace display_server diff --git a/src/DSCompositor/DSCompositorPrivate.h b/src/DSCompositor/DSCompositorPrivate.h index 3f5dc81..e926204 100644 --- a/src/DSCompositor/DSCompositorPrivate.h +++ b/src/DSCompositor/DSCompositorPrivate.h @@ -29,6 +29,7 @@ #include "IDSDisplayDevice.h" #include "DSBufferManager.h" #include "DSTizenAppinfoMgr.h" +#include "DSWindowManager.h" namespace display_server { @@ -62,11 +63,13 @@ private: std::shared_ptr __canvas; DSBufferManager *__dsBufferManager; DSTizenAppinfoMgr * __dsAppinfoMgr; + DSWindowManager *__dsWindowMgr; void __initializeWlDisplay(); void __initializeOutputs(); void __initializeBufferManager(); void __initializeTizenAppinfoMgr(); + void __initializeWindowManager(); }; } diff --git a/src/DSWindowManager/DSWindowManager.cpp b/src/DSWindowManager/DSWindowManager.cpp new file mode 100644 index 0000000..10dc622 --- /dev/null +++ b/src/DSWindowManager/DSWindowManager.cpp @@ -0,0 +1,95 @@ +/* +* Copyright © 2020 Samsung Electronics co., Ltd. All Rights Reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice (including the next +* paragraph) shall be included in all copies or substantial portions of the +* Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +* DEALINGS IN THE SOFTWARE. +*/ + +#include "DSWindowManager.h" +#include "DSWindowManagerPrivate.h" +#include "DSDebugLog.h" + +namespace display_server +{ + +/* reference count, mutex and compositor pointer for DSWindowManager singleton */ +int DSWindowManager::__refCount { 0 }; +std::mutex DSWindowManager::__mutex; +DSWindowManager* DSWindowManager::__windowMgr { nullptr }; + +DSWindowManagerPrivate::DSWindowManagerPrivate(DSWindowManager *p_ptr) + : DSObjectPrivate(p_ptr), + __p_ptr(p_ptr) +{ +} + +DSWindowManagerPrivate::~DSWindowManagerPrivate() +{ +} + +DSWindowManager::DSWindowManager(DSObject *parent) + : DS_INIT_PRIVATE_PTR(DSWindowManager) +{ +} + +DSWindowManager::~DSWindowManager() +{ +} + +/* getInstance for DSWindowManager singleton */ +DSWindowManager *DSWindowManager::getInstance() +{ + std::lock_guard tLock(__mutex); + + DSLOG_INF("DSWindowManager", + "[Get] instance __refCount=%d !", __refCount); + + if (!__windowMgr && (__refCount == 0)) + { + __windowMgr = new DSWindowManager(new DSObject); + DSLOG_INF("DSWindowManager", + "DSWindowManager instance has been created !"); + } + + ++__refCount; + return __windowMgr; +} + +/* releaseInstance for DSWindowManager singleton */ +void DSWindowManager::releaseInstance() +{ + std::lock_guard tLock(__mutex); + + --__refCount; + if (__refCount < 0) + __refCount = 0; + DSLOG_INF("DSWindowManager", + "[Release] instance __refCount=%d !", __refCount); + + if ((0 == __refCount) && __windowMgr) + { + delete __windowMgr; + __windowMgr = nullptr; + DSLOG_INF("DSWindowManager", + "DSWindowManager instance has been removed !"); + } +} + + +} // namespace display_server \ No newline at end of file diff --git a/src/DSWindowManager/DSWindowManager.h b/src/DSWindowManager/DSWindowManager.h new file mode 100644 index 0000000..0dd3252 --- /dev/null +++ b/src/DSWindowManager/DSWindowManager.h @@ -0,0 +1,59 @@ +/* +* Copyright © 2020 Samsung Electronics co., Ltd. All Rights Reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice (including the next +* paragraph) shall be included in all copies or substantial portions of the +* Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +* DEALINGS IN THE SOFTWARE. +*/ + +#ifndef __DS_WINDOW_MANAGER_H__ +#define __DS_WINDOW_MANAGER_H__ + +#include "DSCore.h" +#include "DSObject.h" + +namespace display_server +{ + +class DSWindowManagerPrivate; + +class DSWindowManager : public DSObject +{ +DS_PIMPL_USE_PRIVATE(DSWindowManager) + +public: + static DSWindowManager *getInstance(); + static void releaseInstance(); + +protected: + +private: + DSWindowManager() = delete; + ~DSWindowManager(); + DSWindowManager(DSObject *parent); + DSWindowManager& operator=(const DSWindowManager&) = delete; + +private: + static std::mutex __mutex; + static DSWindowManager *__windowMgr; + static int __refCount; +}; + +} + +#endif // __DS_WINDOW_MANAGER_H__ diff --git a/src/DSWindowManager/DSWindowManagerPrivate.h b/src/DSWindowManager/DSWindowManagerPrivate.h new file mode 100644 index 0000000..8538009 --- /dev/null +++ b/src/DSWindowManager/DSWindowManagerPrivate.h @@ -0,0 +1,46 @@ +/* +* Copyright © 2020 Samsung Electronics co., Ltd. All Rights Reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice (including the next +* paragraph) shall be included in all copies or substantial portions of the +* Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +* DEALINGS IN THE SOFTWARE. +*/ + +#ifndef __DS_WINDOW_MANAGER_PRIVATE__ +#define __DS_WINDOW_MANAGER_PRIVATE__ + +#include "DSWindowManager.h" + +namespace display_server +{ + +class DSWindowManagerPrivate : public DSObjectPrivate +{ + DS_PIMPL_USE_PUBLIC(DSWindowManager); + +public: + DSWindowManagerPrivate() = delete; + DSWindowManagerPrivate(DSWindowManager *p_ptr); + ~DSWindowManagerPrivate(); + +private: +}; + +} // namespace display_server + +#endif \ No newline at end of file diff --git a/src/meson.build b/src/meson.build index c58f4d5..53a0f9e 100644 --- a/src/meson.build +++ b/src/meson.build @@ -63,6 +63,7 @@ libds_srcs = [ 'DSWindow/DSWindow.h', 'DSWindow/DSWindowPrivate.h', 'DSWindow/DSWindow.cpp', + 'DSWindowManager/DSWindowManager.cpp', 'DSWindowShell/DSWindowShell.cpp', 'DSWindowShell/DSWindowShellPrivate.cpp', 'DSZone/DSZone.cpp', @@ -223,6 +224,7 @@ libds_include_dirs = include_directories( './DSWaylandExtension', './DSWaylandServer', './DSWindow', + './DSWindowManager', './DSWindowShell', './DSZone', './DSClient', diff --git a/tests/DSWindowManager-test.cpp b/tests/DSWindowManager-test.cpp new file mode 100644 index 0000000..918651e --- /dev/null +++ b/tests/DSWindowManager-test.cpp @@ -0,0 +1,47 @@ +/* +* Copyright © 2020 Samsung Electronics co., Ltd. All Rights Reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice (including the next +* paragraph) shall be included in all copies or substantial portions of the +* Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +* DEALINGS IN THE SOFTWARE. +*/ + +#include "libds-tests.h" +#include "DSWaylandCompositor.h" +#include "DSWindowManager.h" + +using namespace display_server; + +class DSWindowManagerTest : public ::testing::Test +{ +public: + void SetUp(void) override + { + setenv("XDG_RUNTIME_DIR", "/run", 1); + } + void TearDown(void) override + { + unsetenv("XDG_RUNTIME_DIR"); + } +}; + +TEST_F(DSWindowManagerTest, GetWindowManager) +{ + DSWindowManager* winMgr = DSWindowManager::getInstance(); + EXPECT_TRUE(winMgr != nullptr); +} diff --git a/tests/meson.build b/tests/meson.build index 946b46d..cab5ea3 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -17,6 +17,7 @@ libds_tests_srcs = [ 'DSDebugLog-test.cpp', 'DSDisplayDeviceTDMImpl-test.cpp', 'DSSignal-test.cpp', + 'DSWindowManager-test.cpp', 'DSWindow-test.cpp', 'DSWindowShell-test.cpp', 'DSWaylandCallback-test.cpp', -- 2.7.4