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 #include <opengl/win/blocklist_parser.hxx>
12 WinBlocklistParser::WinBlocklistParser(const OUString
& rURL
,
13 std::vector
<wgl::DriverInfo
>& rDriverList
)
14 : meBlockType(BlockType::UNKNOWN
)
15 , mrDriverList(rDriverList
)
20 void WinBlocklistParser::parse()
22 xmlreader::XmlReader
aReader(maURL
);
23 handleContent(aReader
);
28 wgl::OperatingSystem
getOperatingSystem(const OString
& rString
)
32 return wgl::DRIVER_OS_ALL
;
34 else if (rString
== "xp")
36 return wgl::DRIVER_OS_WINDOWS_XP
;
38 else if (rString
== "server2003")
40 return wgl::DRIVER_OS_WINDOWS_SERVER_2003
;
42 else if (rString
== "vista")
44 return wgl::DRIVER_OS_WINDOWS_VISTA
;
46 else if (rString
== "7")
48 return wgl::DRIVER_OS_WINDOWS_7
;
50 else if (rString
== "8")
52 return wgl::DRIVER_OS_WINDOWS_8
;
54 else if (rString
== "8_1")
56 return wgl::DRIVER_OS_WINDOWS_8_1
;
58 else if (rString
== "10")
60 return wgl::DRIVER_OS_WINDOWS_10
;
63 return wgl::DRIVER_OS_UNKNOWN
;
66 wgl::VersionComparisonOp
getComparison(const OString
& rString
)
68 if (rString
== "less")
70 return wgl::DRIVER_LESS_THAN
;
72 else if (rString
== "less_equal")
74 return wgl::DRIVER_LESS_THAN_OR_EQUAL
;
76 else if (rString
== "greater")
78 return wgl::DRIVER_GREATER_THAN
;
80 else if (rString
== "greater_equal")
82 return wgl::DRIVER_GREATER_THAN_OR_EQUAL
;
84 else if (rString
== "equal")
86 return wgl::DRIVER_EQUAL
;
88 else if (rString
== "not_equal")
90 return wgl::DRIVER_NOT_EQUAL
;
92 else if (rString
== "between_exclusive")
94 return wgl::DRIVER_BETWEEN_EXCLUSIVE
;
96 else if (rString
== "between_inclusive")
98 return wgl::DRIVER_BETWEEN_INCLUSIVE
;
100 else if (rString
== "between_inclusive_start")
102 return wgl::DRIVER_BETWEEN_INCLUSIVE_START
;
105 throw InvalidFileException();
108 OUString
getVendor(const OString
& rString
)
110 if (rString
== "all")
114 else if (rString
== "intel")
118 else if (rString
== "nvidia")
122 else if (rString
== "amd")
126 else if (rString
== "ati")
130 else if (rString
== "microsoft")
136 // Allow having simply the hex number as such there, too. After all, it's hex numbers that
137 // are output to opengl_device.log.
138 return OStringToOUString(rString
, RTL_TEXTENCODING_UTF8
);
142 uint64_t getVersion(const OString
& rString
)
144 OUString aString
= OStringToOUString(rString
, RTL_TEXTENCODING_UTF8
);
146 bool bResult
= wgl::ParseDriverVersion(aString
, nVersion
);
150 throw InvalidFileException();
156 void handleDevices(wgl::DriverInfo
& rDriver
, xmlreader::XmlReader
& rReader
)
163 xmlreader::Span name
;
166 xmlreader::XmlReader::Result res
= rReader
.nextItem(
167 xmlreader::XmlReader::Text::Normalized
, &name
, &nsId
);
169 if (res
== xmlreader::XmlReader::Result::Begin
)
173 throw InvalidFileException();
175 if (name
.equals("msg"))
179 else if (name
.equals("device"))
182 while (rReader
.nextAttribute(&nsIdDeveice
, &name
))
184 if (name
.equals("id"))
186 name
= rReader
.getAttributeValue(false);
187 OString
aDeviceId(name
.begin
, name
.length
);
188 rDriver
.maDevices
.push_back(OStringToOUString(aDeviceId
, RTL_TEXTENCODING_UTF8
));
193 throw InvalidFileException();
195 else if (res
== xmlreader::XmlReader::Result::End
)
202 else if (res
== xmlreader::XmlReader::Result::Text
)
206 OString
sMsg(name
.begin
, name
.length
);
207 rDriver
.maMsg
= OStringToOUString(sMsg
, RTL_TEXTENCODING_UTF8
);
215 void WinBlocklistParser::handleEntry(wgl::DriverInfo
& rDriver
, xmlreader::XmlReader
& rReader
)
217 if (meBlockType
== BlockType::WHITELIST
)
219 rDriver
.mbWhitelisted
= true;
221 else if (meBlockType
== BlockType::BLACKLIST
)
223 rDriver
.mbWhitelisted
= false;
225 else if (meBlockType
== BlockType::UNKNOWN
)
227 throw InvalidFileException();
230 xmlreader::Span name
;
233 while (rReader
.nextAttribute(&nsId
, &name
))
235 if (name
.equals("os"))
237 name
= rReader
.getAttributeValue(false);
238 OString
sOS(name
.begin
, name
.length
);
239 rDriver
.meOperatingSystem
= getOperatingSystem(sOS
);
241 else if (name
.equals("vendor"))
243 name
= rReader
.getAttributeValue(false);
244 OString
sVendor(name
.begin
, name
.length
);
245 rDriver
.maAdapterVendor
= getVendor(sVendor
);
247 else if (name
.equals("compare"))
249 name
= rReader
.getAttributeValue(false);
250 OString
sCompare(name
.begin
, name
.length
);
251 rDriver
.meComparisonOp
= getComparison(sCompare
);
253 else if (name
.equals("version"))
255 name
= rReader
.getAttributeValue(false);
256 OString
sVersion(name
.begin
, name
.length
);
257 rDriver
.mnDriverVersion
= getVersion(sVersion
);
259 else if (name
.equals("minVersion"))
261 name
= rReader
.getAttributeValue(false);
262 OString
sMinVersion(name
.begin
, name
.length
);
263 rDriver
.mnDriverVersion
= getVersion(sMinVersion
);
265 else if (name
.equals("maxVersion"))
267 name
= rReader
.getAttributeValue(false);
268 OString
sMaxVersion(name
.begin
, name
.length
);
269 rDriver
.mnDriverVersionMax
= getVersion(sMaxVersion
);
273 OString
aAttrName(name
.begin
, name
.length
);
274 SAL_WARN("vcl.opengl", "unsupported attribute: " << aAttrName
);
278 handleDevices(rDriver
, rReader
);
281 void WinBlocklistParser::handleList(xmlreader::XmlReader
& rReader
)
283 xmlreader::Span name
;
288 xmlreader::XmlReader::Result res
= rReader
.nextItem(
289 xmlreader::XmlReader::Text::NONE
, &name
, &nsId
);
291 if (res
== xmlreader::XmlReader::Result::Begin
)
293 if (name
.equals("entry"))
295 wgl::DriverInfo aDriver
;
296 handleEntry(aDriver
, rReader
);
297 mrDriverList
.push_back(aDriver
);
299 else if (name
.equals("entryRange"))
301 wgl::DriverInfo aDriver
;
302 handleEntry(aDriver
, rReader
);
303 mrDriverList
.push_back(aDriver
);
307 throw InvalidFileException();
310 else if (res
== xmlreader::XmlReader::Result::End
)
317 void WinBlocklistParser::handleContent(xmlreader::XmlReader
& rReader
)
321 xmlreader::Span name
;
324 xmlreader::XmlReader::Result res
= rReader
.nextItem(
325 xmlreader::XmlReader::Text::NONE
, &name
, &nsId
);
327 if (res
== xmlreader::XmlReader::Result::Begin
)
329 if (name
.equals("whitelist"))
331 meBlockType
= BlockType::WHITELIST
;
334 else if (name
.equals("blacklist"))
336 meBlockType
= BlockType::BLACKLIST
;
339 else if (name
.equals("root"))
344 throw InvalidFileException();
347 else if (res
== xmlreader::XmlReader::Result::End
)
349 if (name
.equals("whitelist")
351 name
.equals("blacklist"))
353 meBlockType
= BlockType::UNKNOWN
;
356 else if (res
== xmlreader::XmlReader::Result::Done
)
363 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */