summaryrefslogtreecommitdiffstats
path: root/src/angle/patches/0018-ANGLE-WinRT-Create-swap-chain-using-physical-resolut.patch
blob: d46851b1e840a665b7b3f41723c006599dec0859 (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
From 59c6d4c94acb4735a73f50f46f91a6cce7389f94 Mon Sep 17 00:00:00 2001
From: Andrew Knight <andrew.knight@digia.com>
Date: Wed, 21 May 2014 00:58:21 +0300
Subject: [PATCH] ANGLE WinRT: Create swap chain using physical resolution

ANGLE has been creating the framebuffer in logical pixels instead of
physical pixels, which leads to unexpected results and side effects like
smudged anti-aliased text. This fixes the issue by multiplying the DIP
resolution by the scale factor, making the framebuffer match the physical
pixel resolution of the screen.

Change-Id: I3594995ce8e18a31b47e27165f72bc6a391b97b6
---
 src/3rdparty/angle/src/libEGL/Surface.cpp | 97 ++++++++++++++++++++++++++-----
 1 file changed, 83 insertions(+), 14 deletions(-)

diff --git a/src/3rdparty/angle/src/libEGL/Surface.cpp b/src/3rdparty/angle/src/libEGL/Surface.cpp
index 3443355..a2e2306 100644
--- a/src/3rdparty/angle/src/libEGL/Surface.cpp
+++ b/src/3rdparty/angle/src/libEGL/Surface.cpp
@@ -24,8 +24,83 @@
 #include "libEGL/Display.h"
 
 #if defined(ANGLE_OS_WINRT)
+#include <wrl.h>
 #include <windows.foundation.h>
 #include <windows.ui.core.h>
+#include <windows.graphics.display.h>
+
+static bool getCoreWindowSize(const EGLNativeWindowType win, int *width, int *height)
+{
+    Microsoft::WRL::ComPtr<ABI::Windows::UI::Core::ICoreWindow> window;
+    HRESULT hr = win->QueryInterface(IID_PPV_ARGS(&window));
+    if (FAILED(hr))
+    {
+        ERR("Failed to cast native display pointer to ICoreWindow *.");
+        return false;
+    }
+
+#if _MSC_VER<=1700
+    Microsoft::WRL::ComPtr<ABI::Windows::Graphics::Display::IDisplayPropertiesStatics> displayInformation;
+    hr = RoGetActivationFactory(Microsoft::WRL::Wrappers::HString::MakeReference(RuntimeClass_Windows_Graphics_Display_DisplayProperties).Get(),
+                                IID_PPV_ARGS(&displayInformation));
+#else
+    Microsoft::WRL::ComPtr<ABI::Windows::Graphics::Display::IDisplayInformationStatics> displayInformationFactory;
+    hr = RoGetActivationFactory(Microsoft::WRL::Wrappers::HString::MakeReference(RuntimeClass_Windows_Graphics_Display_DisplayInformation).Get(),
+                                IID_PPV_ARGS(&displayInformationFactory));
+    if (FAILED(hr))
+    {
+        ERR("Failed to get display information factory.");
+        return false;
+    }
+
+    Microsoft::WRL::ComPtr<ABI::Windows::Graphics::Display::IDisplayInformation> displayInformation;
+    hr = displayInformationFactory->GetForCurrentView(&displayInformation);
+#endif
+    if (FAILED(hr))
+    {
+        ERR("Failed to get display information.");
+        return false;
+    }
+
+#if defined(ANGLE_OS_WINPHONE) && _MSC_VER>=1800 // Windows Phone 8.1
+    Microsoft::WRL::ComPtr<ABI::Windows::Graphics::Display::IDisplayInformation2> displayInformation2;
+    hr = displayInformation.As(&displayInformation2);
+    if (FAILED(hr))
+    {
+        ERR("Failed to get extended display information.");
+        return false;
+    }
+
+    DOUBLE scaleFactor;
+    hr = displayInformation2->get_RawPixelsPerViewPixel(&scaleFactor);
+    if (FAILED(hr))
+    {
+        ERR("Failed to get raw pixels per view pixel.");
+        return false;
+    }
+#else
+    ABI::Windows::Graphics::Display::ResolutionScale resolutionScale;
+    hr = displayInformation->get_ResolutionScale(&resolutionScale);
+    if (FAILED(hr))
+    {
+        ERR("Failed to get resolution scale.");
+        return false;
+    }
+    DOUBLE scaleFactor = DOUBLE(resolutionScale) / 100.0;
+#endif
+
+    ABI::Windows::Foundation::Rect windowRect;
+    hr = window->get_Bounds(&windowRect);
+    if (FAILED(hr))
+    {
+        ERR("Failed to get ICoreWindow bounds.");
+        return false;
+    }
+
+    *width = std::floor(windowRect.Width * scaleFactor + 0.5);
+    *height = std::floor(windowRect.Height * scaleFactor + 0.5);
+    return true;
+}
 #endif
 
 namespace egl
@@ -117,14 +192,10 @@ bool Surface::resetSwapChain()
         width = windowRect.right - windowRect.left;
         height = windowRect.bottom - windowRect.top;
 #else
-        ABI::Windows::Foundation::Rect windowRect;
-        ABI::Windows::UI::Core::ICoreWindow *window;
-        HRESULT hr = mWindow->QueryInterface(IID_PPV_ARGS(&window));
-        if (FAILED(hr))
+        if (!getCoreWindowSize(mWindow, &width, &height))
+        {
             return false;
-        window->get_Bounds(&windowRect);
-        width = windowRect.Width;
-        height = windowRect.Height;
+        }
 #endif
     }
     else
@@ -336,14 +407,12 @@ bool Surface::checkForOutOfDateSwapChain()
     int clientWidth = client.right - client.left;
     int clientHeight = client.bottom - client.top;
 #else
-    ABI::Windows::Foundation::Rect windowRect;
-    ABI::Windows::UI::Core::ICoreWindow *window;
-    HRESULT hr = mWindow->QueryInterface(IID_PPV_ARGS(&window));
-    if (FAILED(hr))
+    int clientWidth;
+    int clientHeight;
+    if (!getCoreWindowSize(mWindow, &clientWidth, &clientHeight))
+    {
         return false;
-    window->get_Bounds(&windowRect);
-    int clientWidth = windowRect.Width;
-    int clientHeight = windowRect.Height;
+    }
 #endif
     bool sizeDirty = clientWidth != getWidth() || clientHeight != getHeight();
 
-- 
1.9.0.msysgit.0