LibreOffice Module vcl (master) 1
driverblocklist.hxx
Go to the documentation of this file.
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_DRIVERBLOCKLIST_HXX
11#define INCLUDED_VCL_DRIVERBLOCKLIST_HXX
12
13#include <vcl/dllapi.h>
15
16#include <string_view>
17#include <vector>
18
19namespace DriverBlocklist
20{
21// Details of how to treat a version number.
22enum class VersionType
23{
24 OpenGL, // a.b.c.d, 1.98 > 1.978
25 Vulkan // a.b.c , 1.98 < 1.978
26};
27
28VCL_DLLPUBLIC bool IsDeviceBlocked(const OUString& blocklistURL, VersionType versionType,
29 std::u16string_view driverVersion, std::u16string_view vendorId,
30 const OUString& deviceId);
31
32#ifdef _WIN32
33VCL_DLLPUBLIC int32_t GetWindowsVersion();
34#endif
35
37{
43};
45
48
49VCL_DLLPUBLIC std::string_view GetVendorNameFromId(uint32_t id);
50
51// The rest should be private (only for the unittest).
52
54{
55};
56
58{
77};
78
80{
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
91};
92
94{
95 DriverInfo(OperatingSystem os, OUString vendor, VersionComparisonOp op, uint64_t driverVersion,
96 bool bAllowListed = false, const char* suggestedVersion = nullptr);
97
98 DriverInfo();
99
102 std::vector<OUString> maDevices;
103
105
107
108 /* versions are assumed to be A.B.C.D packed as 0xAAAABBBBCCCCDDDD */
111
113 OUString maMsg;
114};
115
117{
118public:
119 Parser(OUString aURL, std::vector<DriverInfo>& rDriverList, VersionType versionType);
120 bool parse();
121
122private:
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);
128
129 enum class BlockType
130 {
131 ALLOWLIST,
132 DENYLIST,
133 UNKNOWN
134 };
135
137 std::vector<DriverInfo>& mrDriverList;
138 OUString maURL;
140};
141
143
144bool 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());
151
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))
154
155inline uint64_t OpenGLVersion(uint32_t a, uint32_t b, uint32_t c, uint32_t d)
156{
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)
161 {
162 b *= 10;
163 }
164 while (c > 0 && c < 1000)
165 {
166 c *= 10;
167 }
168 while (d > 0 && d < 1000)
169 {
170 d *= 10;
171 }
172 return GFX_DRIVER_VERSION(a, b, c, d);
173}
174
175} // namespace
176
177#endif
178
179/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
double d
const VersionType mVersionType
std::vector< DriverInfo > & mrDriverList
URL aURL
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
#define GFX_DRIVER_VERSION(a, b, c, d)
UNKNOWN
uno_Any a
DeviceVendor GetVendorFromId(uint32_t id)
Returns vendor for the given vendor ID, or VendorAll if not known.
std::string_view GetVendorNameFromId(uint32_t id)
bool FindBlocklistedDeviceInList(std::vector< DriverInfo > &aDeviceInfos, VersionType versionType, std::u16string_view sDriverVersion, std::u16string_view sAdapterVendorID, OUString const &sAdapterDeviceID, OperatingSystem system, const OUString &blocklistURL)
const int DeviceVendorMax
static OUString GetVendorId(std::string_view rString)
bool IsDeviceBlocked(const OUString &blocklistURL, VersionType versionType, std::u16string_view driverVersion, std::u16string_view vendorId, const OUString &deviceId)
uint64_t OpenGLVersion(uint32_t a, uint32_t b, uint32_t c, uint32_t d)
VCL_DLLPUBLIC uint32_t vendorId
bool parse(OUString const &uri, SourceProviderScannerData *data)
std::vector< OUString > maDevices
VersionComparisonOp meComparisonOp