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>
14 #include <xmlreader/xmlreader.hxx>
15 
16 #include <string_view>
17 #include <vector>
18 
19 namespace DriverBlocklist
20 {
21 // Details of how to treat a version number.
22 enum class VersionType
23 {
24  OpenGL, // a.b.c.d, 1.98 > 1.978
25  Vulkan // a.b.c , 1.98 < 1.978
26 };
27 
28 VCL_DLLPUBLIC bool IsDeviceBlocked(const OUString& blocklistURL, VersionType versionType,
29  const OUString& driverVersion, std::u16string_view vendorId,
30  const OUString& deviceId);
31 
32 #ifdef _WIN32
33 VCL_DLLPUBLIC int32_t GetWindowsVersion();
34 #endif
35 
37 {
43 };
45 
48 
49 VCL_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 
93 struct DriverInfo
94 {
95  DriverInfo(OperatingSystem os, const OUString& vendor, VersionComparisonOp op,
96  uint64_t driverVersion, bool bAllowListed = false,
97  const char* suggestedVersion = nullptr);
98 
99  DriverInfo();
100 
102  OUString maAdapterVendor;
103  std::vector<OUString> maDevices;
104 
106 
108 
109  /* versions are assumed to be A.B.C.D packed as 0xAAAABBBBCCCCDDDD */
110  uint64_t mnDriverVersion;
112 
114  OUString maMsg;
115 };
116 
118 {
119 public:
120  Parser(const OUString& rURL, std::vector<DriverInfo>& rDriverList, VersionType versionType);
121  bool parse();
122 
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(const OString& rString);
129 
130  enum class BlockType
131  {
132  ALLOWLIST,
133  DENYLIST,
134  UNKNOWN
135  };
136 
138  std::vector<DriverInfo>& mrDriverList;
139  OUString maURL;
141 };
142 
144 
146  std::vector<DriverInfo>& aDeviceInfos, VersionType versionType, OUString const& sDriverVersion,
147  std::u16string_view sAdapterVendorID, OUString const& sAdapterDeviceID, OperatingSystem system,
148  const OUString& blocklistURL = OUString());
149 
150 #define GFX_DRIVER_VERSION(a, b, c, d) \
151  ((uint64_t(a) << 48) | (uint64_t(b) << 32) | (uint64_t(c) << 16) | uint64_t(d))
152 
153 inline uint64_t OpenGLVersion(uint32_t a, uint32_t b, uint32_t c, uint32_t d)
154 {
155  // We make sure every driver number is padded by 0s, this will allow us the
156  // easiest 'compare as if decimals' approach. See ParseDriverVersion for a
157  // more extensive explanation of this approach.
158  while (b > 0 && b < 1000)
159  {
160  b *= 10;
161  }
162  while (c > 0 && c < 1000)
163  {
164  c *= 10;
165  }
166  while (d > 0 && d < 1000)
167  {
168  d *= 10;
169  }
170  return GFX_DRIVER_VERSION(a, b, c, d);
171 }
172 
173 } // namespace
174 
175 #endif
176 
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
VersionComparisonOp meComparisonOp
std::vector< OUString > maDevices
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
static OUString GetVendorId(const OString &rString)
uint64_t OpenGLVersion(uint32_t a, uint32_t b, uint32_t c, uint32_t d)
DeviceVendor GetVendorFromId(uint32_t id)
Returns vendor for the given vendor ID, or VendorAll if not known.
std::string_view GetVendorNameFromId(uint32_t id)
#define GFX_DRIVER_VERSION(a, b, c, d)
UNKNOWN
const VersionType mVersionType
bool FindBlocklistedDeviceInList(std::vector< DriverInfo > &aDeviceInfos, VersionType versionType, OUString const &sDriverVersion, std::u16string_view sAdapterVendorID, OUString const &sAdapterDeviceID, OperatingSystem system, const OUString &blocklistURL)
VCL_DLLPUBLIC uint32_t vendorId
const int DeviceVendorMax
bool IsDeviceBlocked(const OUString &blocklistURL, VersionType versionType, const OUString &driverVersion, std::u16string_view vendorId, const OUString &deviceId)
std::vector< DriverInfo > & mrDriverList
bool parse(OUString const &uri, SourceProviderScannerData *data)