DSZone: add code to release DSWaylandSurface 22/241822/1
authorDoyoun Kang <doyoun.kang@samsung.com>
Fri, 14 Aug 2020 03:53:51 +0000 (12:53 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Thu, 20 Aug 2020 10:11:42 +0000 (19:11 +0900)
Change-Id: I7344bd0bb03e01c491f951b8b4b0c300d23e30f5

src/DSZone/DSZone.cpp
src/DSZone/DSZone.h

index 10545dc..c1844c3 100644 (file)
@@ -38,6 +38,7 @@ DSZone::DSZone()
 {
        __waylandCompositor = DSWaylandCompositor::getInstance();
        __waylandCompositor->registerCallbackSurfaceCreated(this, std::bind(&DSZone::__onSurfaceCreated, this, std::placeholders::_1));
+       __waylandCompositor->registerCallbackSurfaceDestroy(this, std::bind(&DSZone::__onSurfaceDestroy, this, std::placeholders::_1));
 
        __waylandShell = __waylandCompositor->getShell();
        if (__waylandShell)
@@ -108,6 +109,17 @@ void DSZone::__onSurfaceCreated(std::shared_ptr<DSWaylandSurface> waylandSurface
        window->setWindowShell(shell.get());
 }
 
+void DSZone::__onSurfaceDestroy(std::shared_ptr<DSWaylandSurface> waylandSurface)
+{
+       DSWaylandSurface *dswSurfacePtr = waylandSurface.get();
+
+       DSWindowShell *shell = __findWindowShell(dswSurfacePtr);
+       __destroyWindowShell(shell, dswSurfacePtr);
+
+       std::shared_ptr<DSWindow> window = __findWindow(dswSurfacePtr);
+       __destroyWindow(window);
+}
+
 void DSZone::__onShellSurfaceCreated(IDSWaylandShellSurface *waylandShellSurface)
 {
        DSLOG_DBG("DSZone", "waylandShellSurface:(pure:%p)", waylandShellSurface);
@@ -144,6 +156,11 @@ std::list<std::shared_ptr<DSWindow>> DSZone::getWindowList()
        return __windowList;
 }
 
+std::list<std::shared_ptr<DSWindowShell>> DSZone::getWindowShellList()
+{
+       return __windowShellList;
+}
+
 std::shared_ptr<DSWindow> DSZone::__findWindow(DSWaylandSurface *dswlSurface)
 {
        std::list<std::shared_ptr<DSWindow>> wList = getWindowList();
@@ -188,12 +205,19 @@ std::shared_ptr<DSWindow> DSZone::__createWindow(std::shared_ptr<DSWaylandSurfac
        return window;
 }
 
+void DSZone::__destroyWindow(std::shared_ptr<DSWindow> window)
+{
+       __windowDestroySignal.emit(window);
+       __windowList.remove(window);
+}
+
 std::shared_ptr<DSWindowShell> DSZone::__createWindowShell(std::shared_ptr<DSWindow> window)
 {
        DSWindow *ptrWindow = window.get();
 
        std::shared_ptr<DSWindowShell> shell = std::make_shared<DSWindowShell>(ptrWindow);
        __windowShellList.push_front(shell);
+
        __windowShellMap.insert(std::make_pair(ptrWindow->surface(), shell.get()));
 
        shell->setGeometry(__position.x, __position.y, __size.w, __size.h);
@@ -204,5 +228,22 @@ std::shared_ptr<DSWindowShell> DSZone::__createWindowShell(std::shared_ptr<DSWin
        return shell;
 }
 
+void DSZone::__destroyWindowShell(DSWindowShell* windowShell, DSWaylandSurface *surface)
+{
+       // remove from map
+       __windowShellMap.erase(surface);
+
+       // remove from __windowShellList
+       std::list<std::shared_ptr<DSWindowShell>> wsList = getWindowShellList();
+       for (auto ws : wsList)
+       {
+               if (ws.get() == windowShell)
+               {
+                       __windowShellDestroySignal.emit(ws);
+                       __windowShellList.remove(ws);
+                       break;
+               }
+       }
+}
 
 } //  namespace display_server
index 191d0bc..e464e31 100644 (file)
@@ -58,12 +58,20 @@ public:
        void callCallbackWindowShellCreated();
 
        std::list<std::shared_ptr<DSWindow>> getWindowList();
+       std::list<std::shared_ptr<DSWindowShell>> getWindowShellList();
 
 private:
        void __onSurfaceCreated(std::shared_ptr<DSWaylandSurface> waylandSurface);
+       void __onSurfaceDestroy(std::shared_ptr<DSWaylandSurface> waylandSurface);
+
        void __onShellSurfaceCreated(IDSWaylandShellSurface *waylandShellSurface);
+
        std::shared_ptr<DSWindow> __createWindow(std::shared_ptr<DSWaylandSurface> waylandSurface);
+       void __destroyWindow(std::shared_ptr<DSWindow> window);
+
        std::shared_ptr<DSWindowShell> __createWindowShell(std::shared_ptr<DSWindow> window);
+       void __destroyWindowShell(DSWindowShell* windowShell, DSWaylandSurface *surface);
+
        std::shared_ptr<DSWindow> __findWindow(DSWaylandSurface *dswlSurface);
        DSWindowShell* __findWindowShell(DSWaylandSurface *dswlSurface);
 
@@ -78,7 +86,9 @@ private:
 
        // signals
        DSSignal<std::shared_ptr<DSWindow>> __windowCreatedSignal;
+       DSSignal<std::shared_ptr<DSWindow>> __windowDestroySignal;
        DSSignal<std::shared_ptr<DSWindowShell>> __windowShellCreatedSignal;
+       DSSignal<std::shared_ptr<DSWindowShell>> __windowShellDestroySignal;
 };
 
 }