tdf#151341 Use lzfse compression instead of bzip2
[LibreOffice.git] / vcl / inc / driverblocklist.hxx
blobf3fc81c6642d03a47cca18db90903e378d1954d3
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, OUString vendor, VersionComparisonOp op, uint64_t driverVersion,
96 bool bAllowListed = false, const char* suggestedVersion = nullptr);
98 DriverInfo();
100 OperatingSystem meOperatingSystem;
101 OUString maAdapterVendor;
102 std::vector<OUString> maDevices;
104 bool mbAllowlisted;
106 VersionComparisonOp meComparisonOp;
108 /* versions are assumed to be A.B.C.D packed as 0xAAAABBBBCCCCDDDD */
109 uint64_t mnDriverVersion;
110 uint64_t mnDriverVersionMax;
112 OUString maSuggestedVersion;
113 OUString maMsg;
116 class VCL_DLLPUBLIC Parser
118 public:
119 Parser(OUString aURL, std::vector<DriverInfo>& rDriverList, VersionType versionType);
120 bool parse();
122 private:
123 void handleEntry(DriverInfo& rDriver, xmlreader::XmlReader& rReader);
124 void handleList(xmlreader::XmlReader& rReader);
125 void handleContent(xmlreader::XmlReader& rReader);
126 static void handleDevices(DriverInfo& rDriver, xmlreader::XmlReader& rReader);
127 uint64_t getVersion(std::string_view rString);
129 enum class BlockType
131 ALLOWLIST,
132 DENYLIST,
133 UNKNOWN
136 BlockType meBlockType;
137 std::vector<DriverInfo>& mrDriverList;
138 OUString maURL;
139 const VersionType mVersionType;
142 OUString VCL_DLLPUBLIC GetVendorId(DeviceVendor id);
144 bool VCL_DLLPUBLIC FindBlocklistedDeviceInList(std::vector<DriverInfo>& aDeviceInfos,
145 VersionType versionType,
146 std::u16string_view sDriverVersion,
147 std::u16string_view sAdapterVendorID,
148 OUString const& sAdapterDeviceID,
149 OperatingSystem system,
150 const OUString& blocklistURL = OUString());
152 #define GFX_DRIVER_VERSION(a, b, c, d) \
153 ((uint64_t(a) << 48) | (uint64_t(b) << 32) | (uint64_t(c) << 16) | uint64_t(d))
155 inline uint64_t OpenGLVersion(uint32_t a, uint32_t b, uint32_t c, uint32_t d)
157 // We make sure every driver number is padded by 0s, this will allow us the
158 // easiest 'compare as if decimals' approach. See ParseDriverVersion for a
159 // more extensive explanation of this approach.
160 while (b > 0 && b < 1000)
162 b *= 10;
164 while (c > 0 && c < 1000)
166 c *= 10;
168 while (d > 0 && d < 1000)
170 d *= 10;
172 return GFX_DRIVER_VERSION(a, b, c, d);
175 } // namespace
177 #endif
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */