1From 9809b77e3fb1fb7fc74dad0aa6f5bd3482255271 Mon Sep 17 00:00:00 2001
2From: Jeffy Chen <jeffy.chen@rock-chips.com>
3Date: Tue, 30 Aug 2022 16:32:54 +0800
4Subject: [PATCH 17/17] Revert "Client: Don't send fake
5 SurfaceCreated/Destroyed events"
6
7This reverts commit cd21404f99b486ff62225699e1a4bdc0d5b3d5c1.
8
9Others, e.g. Quick scenegraph, still need surfaceAboutToBeDestroyed
10event to cleanup renderer resources.
11
12Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
13---
14 src/client/qwaylandwindow.cpp | 10 ++++++++--
15 src/client/qwaylandwindow_p.h |  2 +-
16 2 files changed, 9 insertions(+), 3 deletions(-)
17
18diff --git a/src/client/qwaylandwindow.cpp b/src/client/qwaylandwindow.cpp
19index 81d4aef..fdb3d17 100644
20--- a/src/client/qwaylandwindow.cpp
21+++ b/src/client/qwaylandwindow.cpp
22@@ -97,7 +97,7 @@ QWaylandWindow::~QWaylandWindow()
23     delete mWindowDecoration;
24
25     if (mSurface)
26-        reset();
27+        reset(false);
28
29     const QWindow *parent = window();
30     const auto tlw = QGuiApplication::topLevelWindows();
31@@ -153,6 +153,8 @@ void QWaylandWindow::initWindow()
32
33     if (!mSurface) {
34         initializeWlSurface();
35+        QPlatformSurfaceEvent e(QPlatformSurfaceEvent::SurfaceCreated);
36+        QGuiApplication::sendEvent(window(), &e);
37     }
38
39     if (shouldCreateSubSurface()) {
40@@ -286,8 +288,12 @@ bool QWaylandWindow::shouldCreateSubSurface() const
41     return QPlatformWindow::parent() != nullptr;
42 }
43
44-void QWaylandWindow::reset()
45+void QWaylandWindow::reset(bool sendDestroyEvent)
46 {
47+    if (mSurface && sendDestroyEvent) {
48+        QPlatformSurfaceEvent e(QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed);
49+        QGuiApplication::sendEvent(window(), &e);
50+    }
51     mWaitingToApplyConfigure = false;
52
53     delete mShellSurface;
54diff --git a/src/client/qwaylandwindow_p.h b/src/client/qwaylandwindow_p.h
55index afd318c..63901a0 100644
56--- a/src/client/qwaylandwindow_p.h
57+++ b/src/client/qwaylandwindow_p.h
58@@ -273,7 +273,7 @@ private:
59     void initializeWlSurface();
60     bool shouldCreateShellSurface() const;
61     bool shouldCreateSubSurface() const;
62-    void reset();
63+    void reset(bool sendDestroyEvent = true);
64     void sendExposeEvent(const QRect &rect);
65     static void closePopups(QWaylandWindow *parent);
66     QPlatformScreen *calculateScreenFromSurfaceEvents() const;
67--
682.20.1
69
70