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
, OUString vendor
, VersionComparisonOp op
, uint64_t driverVersion
,
96 bool bAllowListed
= false, const char* suggestedVersion
= nullptr);
100 OperatingSystem meOperatingSystem
;
101 OUString maAdapterVendor
;
102 std::vector
<OUString
> maDevices
;
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
;
116 class VCL_DLLPUBLIC Parser
119 Parser(OUString aURL
, std::vector
<DriverInfo
>& rDriverList
, VersionType versionType
);
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
);
136 BlockType meBlockType
;
137 std::vector
<DriverInfo
>& mrDriverList
;
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)
164 while (c
> 0 && c
< 1000)
168 while (d
> 0 && d
< 1000)
172 return GFX_DRIVER_VERSION(a
, b
, c
, d
);
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */