1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
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>
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
);
33 VCL_DLLPUBLIC
int32_t GetWindowsVersion();
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
59 DRIVER_OS_UNKNOWN
= 0,
60 DRIVER_OS_WINDOWS_FIRST
,
61 DRIVER_OS_WINDOWS_7
= DRIVER_OS_WINDOWS_FIRST
,
63 DRIVER_OS_WINDOWS_8_1
,
65 DRIVER_OS_WINDOWS_LAST
= DRIVER_OS_WINDOWS_10
,
66 DRIVER_OS_WINDOWS_ALL
,
69 DRIVER_OS_OSX_10_5
= DRIVER_OS_OSX_FIRST
,
73 DRIVER_OS_OSX_LAST
= DRIVER_OS_OSX_10_8
,
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
95 DriverInfo(OperatingSystem os
, const OUString
& vendor
, VersionComparisonOp op
,
96 uint64_t driverVersion
, bool bAllowListed
= false,
97 const char* suggestedVersion
= nullptr);
101 OperatingSystem meOperatingSystem
;
102 OUString maAdapterVendor
;
103 std::vector
<OUString
> maDevices
;
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
;
117 class VCL_DLLPUBLIC Parser
120 Parser(const OUString
& rURL
, std::vector
<DriverInfo
>& rDriverList
, VersionType versionType
);
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
);
137 BlockType meBlockType
;
138 std::vector
<DriverInfo
>& mrDriverList
;
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)
165 while (c
> 0 && c
< 1000)
169 while (d
> 0 && d
< 1000)
173 return GFX_DRIVER_VERSION(a
, b
, c
, d
);
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */