1From d8ca4f6d0d8fffd8319f340685e03751049678ae Mon Sep 17 00:00:00 2001
2From: Oliver Wolff <oliver.wolff@qt.io>
3Date: Tue, 16 Apr 2019 10:19:27 +0200
4Subject: [PATCH] ANGLE: clean up displays on dll unload
5
6If the displays are not cleaned up on dll unloading, profilers might
7report memory leaks.
8
9Change-Id: I04cbc3c2448bfb450f7d840e216827f86856e963
10---
11 src/3rdparty/angle/src/libANGLE/Display.cpp     | 17 +++++++++++++++++
12 src/3rdparty/angle/src/libANGLE/Display.h       |  1 +
13 .../angle/src/libGLESv2/global_state.cpp        |  2 ++
14 3 files changed, 20 insertions(+)
15
16diff --git a/src/3rdparty/angle/src/libANGLE/Display.cpp b/src/3rdparty/angle/src/libANGLE/Display.cpp
17index 735b472787..0bb0bb05b1 100644
18--- a/src/3rdparty/angle/src/libANGLE/Display.cpp
19+++ b/src/3rdparty/angle/src/libANGLE/Display.cpp
20@@ -364,6 +364,23 @@ Display *Display::GetDisplayFromDevice(Device *device, const AttributeMap &attri
21     return display;
22 }
23
24+//static
25+void Display::CleanupDisplays()
26+{
27+    // ~Display takes care of removing the entry from the according map
28+    {
29+        ANGLEPlatformDisplayMap *displays = GetANGLEPlatformDisplayMap();
30+        while (!displays->empty())
31+            delete displays->begin()->second;
32+    }
33+
34+    {
35+        DevicePlatformDisplayMap *displays = GetDevicePlatformDisplayMap();
36+        while (!displays->empty())
37+            delete displays->begin()->second;
38+    }
39+}
40+
41 Display::Display(EGLenum platform, EGLNativeDisplayType displayId, Device *eglDevice)
42     : mImplementation(nullptr),
43       mDisplayId(displayId),
44diff --git a/src/3rdparty/angle/src/libANGLE/Display.h b/src/3rdparty/angle/src/libANGLE/Display.h
45index aa1d1c3b37..2a1c386d75 100644
46--- a/src/3rdparty/angle/src/libANGLE/Display.h
47+++ b/src/3rdparty/angle/src/libANGLE/Display.h
48@@ -65,6 +65,7 @@ class Display final : angle::NonCopyable
49     static Display *GetDisplayFromDevice(Device *device, const AttributeMap &attribMap);
50     static Display *GetDisplayFromNativeDisplay(EGLNativeDisplayType nativeDisplay,
51                                                 const AttributeMap &attribMap);
52+    static void CleanupDisplays();
53
54     static const ClientExtensions &GetClientExtensions();
55     static const std::string &GetClientExtensionString();
56diff --git a/src/3rdparty/angle/src/libGLESv2/global_state.cpp b/src/3rdparty/angle/src/libGLESv2/global_state.cpp
57index c5f3dfe4e1..26045bf5b2 100644
58--- a/src/3rdparty/angle/src/libGLESv2/global_state.cpp
59+++ b/src/3rdparty/angle/src/libGLESv2/global_state.cpp
60@@ -13,6 +13,7 @@
61 #include "common/tls.h"
62
63 #include "libANGLE/Thread.h"
64+#include "libANGLE/Display.h"
65
66 namespace gl
67 {
68@@ -140,6 +141,7 @@ extern "C" BOOL WINAPI DllMain(HINSTANCE, DWORD reason, LPVOID)
69             return static_cast<BOOL>(egl::DeallocateCurrentThread());
70
71         case DLL_PROCESS_DETACH:
72+            egl::Display::CleanupDisplays();
73             return static_cast<BOOL>(egl::TerminateProcess());
74     }
75
76--
772.20.1.windows.1
78
79