1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  */
9 
10 #ifndef INCLUDED_VCL_OPENGL_WIN_WINDEVICEINFO_HXX
11 #define INCLUDED_VCL_OPENGL_WIN_WINDEVICEINFO_HXX
12 
13 #include <vcl/dllapi.h>
14 
15 #include <opengl/DeviceInfo.hxx>
16 
17 #include <rtl/ustring.hxx>
18 #include <vector>
19 #include <cstdint>
20 
21 namespace wgl {
22 
23 enum OperatingSystem {
24     DRIVER_OS_UNKNOWN = 0,
25     DRIVER_OS_WINDOWS_7,
26     DRIVER_OS_WINDOWS_8,
27     DRIVER_OS_WINDOWS_8_1,
28     DRIVER_OS_WINDOWS_10,
29     DRIVER_OS_LINUX,
30     DRIVER_OS_OS_X_10_5,
31     DRIVER_OS_OS_X_10_6,
32     DRIVER_OS_OS_X_10_7,
33     DRIVER_OS_OS_X_10_8,
34     DRIVER_OS_ANDROID,
35     DRIVER_OS_ALL
36 };
37 
38 enum VersionComparisonOp {
39     DRIVER_LESS_THAN,             // driver <  version
40     DRIVER_LESS_THAN_OR_EQUAL,    // driver <= version
41     DRIVER_GREATER_THAN,          // driver >  version
42     DRIVER_GREATER_THAN_OR_EQUAL, // driver >= version
43     DRIVER_EQUAL,                 // driver == version
44     DRIVER_NOT_EQUAL,             // driver != version
45     DRIVER_BETWEEN_EXCLUSIVE,     // driver > version && driver < versionMax
46     DRIVER_BETWEEN_INCLUSIVE,     // driver >= version && driver <= versionMax
47     DRIVER_BETWEEN_INCLUSIVE_START, // driver >= version && driver < versionMax
48     DRIVER_COMPARISON_IGNORED
49 };
50 
51 enum DeviceVendor {
52     VendorAll,
53     VendorIntel,
54     VendorNVIDIA,
55     VendorAMD,
56     VendorATI,
57     VendorMicrosoft,
58     DeviceVendorMax
59 };
60 
61 bool ParseDriverVersion(const OUString& rString, uint64_t& rVersion);
62 
63 struct VCL_DLLPUBLIC DriverInfo
64 {
65 
66     DriverInfo(OperatingSystem os, const OUString& vendor, VersionComparisonOp op,
67             uint64_t driverVersion, bool bWhiteListed = false, const char *suggestedVersion = nullptr);
68 
69     DriverInfo();
70     virtual ~DriverInfo();
71 
72     OperatingSystem meOperatingSystem;
73     uint32_t mnOperatingSystemVersion;
74 
75     OUString maAdapterVendor;
76 
77     std::vector<OUString> maDevices;
78 
79     // Whether the mDevices array should be deleted when this structure is
80     // deallocated. False by default.
81     bool mbDeleteDevices;
82 
83     bool mbWhitelisted;
84 
85     VersionComparisonOp meComparisonOp;
86 
87     /* versions are assumed to be A.B.C.D packed as 0xAAAABBBBCCCCDDDD */
88     uint64_t mnDriverVersion;
89     uint64_t mnDriverVersionMax;
90     static uint64_t allDriverVersions;
91 
92     OUString maSuggestedVersion;
93     OUString maMsg;
94 };
95 
96 #define GFX_DRIVER_VERSION(a,b,c,d) \
97     ((uint64_t(a)<<48) | (uint64_t(b)<<32) | (uint64_t(c)<<16) | uint64_t(d))
98 
V(uint32_t a,uint32_t b,uint32_t c,uint32_t d)99 inline VCL_DLLPUBLIC uint64_t V(uint32_t a, uint32_t b, uint32_t c, uint32_t d)
100 {
101     // We make sure every driver number is padded by 0s, this will allow us the
102     // easiest 'compare as if decimals' approach. See ParseDriverVersion for a
103     // more extensive explanation of this approach.
104     while (b > 0 && b < 1000) {
105         b *= 10;
106     }
107     while (c > 0 && c < 1000) {
108         c *= 10;
109     }
110     while (d > 0 && d < 1000) {
111         d *= 10;
112     }
113     return GFX_DRIVER_VERSION(a, b, c, d);
114 }
115 
116 }
117 
118 class VCL_DLLPUBLIC WinOpenGLDeviceInfo : public OpenGLDeviceInfo
119 {
120 private:
121     OUString maDriverVersion;
122     OUString maDriverVersion2;
123 
124     OUString maDriverDate;
125     OUString maDriverDate2;
126 
127     OUString maDeviceID;
128     OUString maDeviceID2;
129 
130     OUString maAdapterVendorID;
131     OUString maAdapterDeviceID;
132     OUString maAdapterSubsysID;
133 
134     OUString maAdapterVendorID2;
135     OUString maAdapterDeviceID2;
136     OUString maAdapterSubsysID2;
137 
138     OUString maDeviceKey;
139     OUString maDeviceKey2;
140 
141     OUString maDeviceString;
142     OUString maDeviceString2;
143     uint32_t mnWindowsVersion;
144 
145     bool mbHasDualGPU;
146     bool mbRDP;
147 
148     void GetData();
149     static void FillBlacklist();
150     bool FindBlocklistedDeviceInList();
151 
152     static OUString* mpDeviceVendors[wgl::DeviceVendorMax];
153     static std::vector<wgl::DriverInfo> maDriverInfo;
154 
155 public:
156     WinOpenGLDeviceInfo();
157 
158     static OUString GetDeviceVendor(wgl::DeviceVendor eVendor);
159     virtual ~WinOpenGLDeviceInfo() override;
160 
161     virtual bool isDeviceBlocked() override;
162 
GetDriverVersion() const163     const OUString& GetDriverVersion() const
164     {
165         return maDriverVersion;
166     }
167 
GetDriverDate() const168     const OUString& GetDriverDate() const
169     {
170         return maDriverDate;
171     }
172 
GetDeviceID() const173     const OUString& GetDeviceID() const
174     {
175         return maDeviceID;
176     }
177 
GetAdapterVendorID() const178     const OUString& GetAdapterVendorID() const
179     {
180         return maAdapterVendorID;
181     }
182 
GetAdapterDeviceID() const183     const OUString& GetAdapterDeviceID() const
184     {
185         return maAdapterDeviceID;
186     }
187 
GetAdapterSubsysID() const188     const OUString& GetAdapterSubsysID() const
189     {
190         return maAdapterSubsysID;
191     }
GetDeviceKey() const192     const OUString& GetDeviceKey() const
193     {
194         return maDeviceKey;
195     }
196 
GetDeviceString() const197     const OUString& GetDeviceString() const
198     {
199         return maDeviceString;
200     }
201 
GetWindowsVersion() const202     sal_uInt32 GetWindowsVersion() const
203     {
204         return mnWindowsVersion;
205     }
206 
207     static bool FindBlocklistedDeviceInList(std::vector<wgl::DriverInfo>& aDeviceInfos,
208                                             OUString const & sDriverVersion, OUString const & sAdapterVendorID,
209                                             OUString const & sAdapterDeviceID, uint32_t nWindowsVersion);
210 };
211 
212 #endif
213 
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
215