summaryrefslogtreecommitdiffstats
path: root/src/angle/patches/0001-Dynamically-resolve-functions-of-dwmapi.dll.patch
blob: b259aa3f80085c290e7e949068231ae2f85060ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
From 211954dffc6a0ee52db130017ae4bea00e80748f Mon Sep 17 00:00:00 2001
From: Friedemann Kleint <Friedemann.Klient@digia.com>
Date: Mon, 18 Mar 2013 15:35:13 +0200
Subject: [PATCH 1/6] Dynamically resolve functions of dwmapi.dll.

The library is not present on Windows XP, for which /DELAYLOAD
is used in ANGLE. However, as this causes problems with MinGW,
use dynamic resolution.

Task-number: QTBUG-27741
Change-Id: I16214d6f98a184d89858c50ee5306371ea25469e
---
 src/3rdparty/angle/src/libEGL/Surface.cpp | 39 ++++++++++++++++++++++++++++-----------
 1 file changed, 28 insertions(+), 11 deletions(-)

diff --git a/src/3rdparty/angle/src/libEGL/Surface.cpp b/src/3rdparty/angle/src/libEGL/Surface.cpp
index 78203b0..5ece724 100644
--- a/src/3rdparty/angle/src/libEGL/Surface.cpp
+++ b/src/3rdparty/angle/src/libEGL/Surface.cpp
@@ -71,6 +71,9 @@ Surface::~Surface()
 
 bool Surface::initialize()
 {
+    typedef HRESULT (STDAPICALLTYPE *PtrDwmIsCompositionEnabled)(BOOL*);
+    typedef HRESULT (STDAPICALLTYPE *PtrDwmSetPresentParameters)(HWND, DWM_PRESENT_PARAMETERS *);
+
     if (!resetSwapChain())
       return false;
 
@@ -78,17 +81,31 @@ bool Surface::initialize()
     // to minimize the amount of queuing done by DWM between our calls to
     // present and the actual screen.
     if (mWindow && (getComparableOSVersion() >= versionWindowsVista)) {
-      BOOL isComposited;
-      HRESULT result = DwmIsCompositionEnabled(&isComposited);
-      if (SUCCEEDED(result) && isComposited) {
-        DWM_PRESENT_PARAMETERS presentParams;
-        memset(&presentParams, 0, sizeof(presentParams));
-        presentParams.cbSize = sizeof(DWM_PRESENT_PARAMETERS);
-        presentParams.cBuffer = 2;
-
-        result = DwmSetPresentParameters(mWindow, &presentParams);
-        if (FAILED(result))
-          ERR("Unable to set present parameters: 0x%08X", result);
+      // Resolve dwmapi.dll functions dynamically as the Library is
+      // not present on Windows XP. Alternatively, /DELAYLOAD could be used.
+      static PtrDwmIsCompositionEnabled dwmIsCompositionEnabled = 0;
+      static PtrDwmSetPresentParameters dwmSetPresentParameters = 0;
+      if (!dwmIsCompositionEnabled) {
+        if (const HMODULE dwmLibrary = LoadLibraryW(L"dwmapi.dll")) {
+          dwmIsCompositionEnabled =
+            (PtrDwmIsCompositionEnabled)GetProcAddress(dwmLibrary, "DwmIsCompositionEnabled");
+          dwmSetPresentParameters =
+            (PtrDwmSetPresentParameters)GetProcAddress(dwmLibrary, "DwmSetPresentParameters");
+        }
+      }
+      if (dwmIsCompositionEnabled && dwmSetPresentParameters) {
+        BOOL isComposited;
+        HRESULT result = dwmIsCompositionEnabled(&isComposited);
+        if (SUCCEEDED(result) && isComposited) {
+          DWM_PRESENT_PARAMETERS presentParams;
+          memset(&presentParams, 0, sizeof(presentParams));
+          presentParams.cbSize = sizeof(DWM_PRESENT_PARAMETERS);
+          presentParams.cBuffer = 2;
+
+          result = dwmSetPresentParameters(mWindow, &presentParams);
+          if (FAILED(result))
+            ERR("Unable to set present parameters: 0x%08X", result);
+        }
       }
     }
 
-- 
1.8.1.msysgit.1