bump product version to 7.2.5.1
[LibreOffice.git] / vcl / inc / driverblocklist.hxx
blob542677aa3454bc264d459501ccc8f0c8ed7559ba
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #ifndef INCLUDED_VCL_DRIVERBLOCKLIST_HXX
11 #define INCLUDED_VCL_DRIVERBLOCKLIST_HXX
13 #include <vcl/dllapi.h>
14 #include <xmlreader/xmlreader.hxx>
16 #include <string_view>
17 #include <vector>
19 namespace DriverBlocklist
21 // Details of how to treat a version number.
22 enum class VersionType
24 OpenGL, // a.b.c.d, 1.98 > 1.978
25 Vulkan // a.b.c , 1.98 < 1.978
28 VCL_DLLPUBLIC bool IsDeviceBlocked(const OUString& blocklistURL, VersionType versionType,
29 std::u16string_view driverVersion, std::u16string_view vendorId,
30 const OUString& deviceId);
32 #ifdef _WIN32
33 VCL_DLLPUBLIC int32_t GetWindowsVersion();
34 #endif
36 enum DeviceVendor
38 VendorAll,
39 VendorIntel,
40 VendorNVIDIA,
41 VendorAMD,
42 VendorMicrosoft,
44 const int DeviceVendorMax = VendorMicrosoft + 1;
46 /// Returns vendor for the given vendor ID, or VendorAll if not known.
47 VCL_DLLPUBLIC DeviceVendor GetVendorFromId(uint32_t id);
49 VCL_DLLPUBLIC std::string_view GetVendorNameFromId(uint32_t id);
51 // The rest should be private (only for the unittest).
53 struct InvalidFileException
57 enum OperatingSystem
59 DRIVER_OS_UNKNOWN = 0,
60 DRIVER_OS_WINDOWS_FIRST,
61 DRIVER_OS_WINDOWS_7 = DRIVER_OS_WINDOWS_FIRST,
62 DRIVER_OS_WINDOWS_8,
63 DRIVER_OS_WINDOWS_8_1,
64 DRIVER_OS_WINDOWS_10,
65 DRIVER_OS_WINDOWS_LAST = DRIVER_OS_WINDOWS_10,
66 DRIVER_OS_WINDOWS_ALL,
67 DRIVER_OS_LINUX,
68 DRIVER_OS_OSX_FIRST,
69 DRIVER_OS_OSX_10_5 = DRIVER_OS_OSX_FIRST,
70 DRIVER_OS_OSX_10_6,
71 DRIVER_OS_OSX_10_7,
72 DRIVER_OS_OSX_10_8,
73 DRIVER_OS_OSX_LAST = DRIVER_OS_OSX_10_8,
74 DRIVER_OS_OSX_ALL,
75 DRIVER_OS_ANDROID,
76 DRIVER_OS_ALL
79 enum VersionComparisonOp
81 DRIVER_LESS_THAN, // driver < version
82 DRIVER_LESS_THAN_OR_EQUAL, // driver <= version
83 DRIVER_GREATER_THAN, // driver > version
84 DRIVER_GREATER_THAN_OR_EQUAL, // driver >= version
85 DRIVER_EQUAL, // driver == version
86 DRIVER_NOT_EQUAL, // driver != version
87 DRIVER_BETWEEN_EXCLUSIVE, // driver > version && driver < versionMax
88 DRIVER_BETWEEN_INCLUSIVE, // driver >= version && driver <= versionMax
89 DRIVER_BETWEEN_INCLUSIVE_START, // driver >= version && driver < versionMax
90 DRIVER_COMPARISON_IGNORED
93 struct DriverInfo
95 DriverInfo(OperatingSystem os, const OUString& vendor, VersionComparisonOp op,
96 uint64_t driverVersion, bool bAllowListed = false,
97 const char* suggestedVersion = nullptr);
99 DriverInfo();
101 OperatingSystem meOperatingSystem;
102 OUString maAdapterVendor;
103 std::vector<OUString> maDevices;
105 bool mbAllowlisted;
107 VersionComparisonOp meComparisonOp;
109 /* versions are assumed to be A.B.C.D packed as 0xAAAABBBBCCCCDDDD */
110 uint64_t mnDriverVersion;
111 uint64_t mnDriverVersionMax;
113 OUString maSuggestedVersion;
114 OUString maMsg;
117 class VCL_DLLPUBLIC Parser
119 public:
120 Parser(const OUString& rURL, std::vector<DriverInfo>& rDriverList, VersionType versionType);
121 bool parse();
123 private:
124 void handleEntry(DriverInfo& rDriver, xmlreader::XmlReader& rReader);
125 void handleList(xmlreader::XmlReader& rReader);
126 void handleContent(xmlreader::XmlReader& rReader);
127 static void handleDevices(DriverInfo& rDriver, xmlreader::XmlReader& rReader);
128 uint64_t getVersion(std::string_view rString);
130 enum class BlockType
132 ALLOWLIST,
133 DENYLIST,
134 UNKNOWN
137 BlockType meBlockType;
138 std::vector<DriverInfo>& mrDriverList;
139 OUString maURL;
140 const VersionType mVersionType;
143 OUString VCL_DLLPUBLIC GetVendorId(DeviceVendor id);
145 bool VCL_DLLPUBLIC FindBlocklistedDeviceInList(std::vector<DriverInfo>& aDeviceInfos,
146 VersionType versionType,
147 std::u16string_view sDriverVersion,
148 std::u16string_view sAdapterVendorID,
149 OUString const& sAdapterDeviceID,
150 OperatingSystem system,
151 const OUString& blocklistURL = OUString());
153 #define GFX_DRIVER_VERSION(a, b, c, d) \
154 ((uint64_t(a) << 48) | (uint64_t(b) << 32) | (uint64_t(c) << 16) | uint64_t(d))
156 inline uint64_t OpenGLVersion(uint32_t a, uint32_t b, uint32_t c, uint32_t d)
158 // We make sure every driver number is padded by 0s, this will allow us the
159 // easiest 'compare as if decimals' approach. See ParseDriverVersion for a
160 // more extensive explanation of this approach.
161 while (b > 0 && b < 1000)
163 b *= 10;
165 while (c > 0 && c < 1000)
167 c *= 10;
169 while (d > 0 && d < 1000)
171 d *= 10;
173 return GFX_DRIVER_VERSION(a, b, c, d);
176 } // namespace
178 #endif
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */