Use Win32 APIs for UTF-16<->UTF-8 conversion

std::codecvt is deprecated since C++17 and broken for some characters/locales
This commit is contained in:
Cameron Gutman 2024-02-11 15:16:41 -06:00
commit 69a3edd9b0
7 changed files with 113 additions and 41 deletions

View file

@ -3,7 +3,6 @@
* @brief todo
*/
#include <cmath>
#include <codecvt>
#include <initguid.h>
#include <thread>
@ -447,10 +446,8 @@ namespace platf::dxgi {
return -1;
}
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> converter;
auto adapter_name = converter.from_bytes(config::video.adapter_name);
auto output_name = converter.from_bytes(display_name);
auto adapter_name = from_utf8(config::video.adapter_name);
auto output_name = from_utf8(display_name);
adapter_t::pointer adapter_p;
for (int tries = 0; tries < 2; ++tries) {
@ -561,7 +558,7 @@ namespace platf::dxgi {
DXGI_ADAPTER_DESC adapter_desc;
adapter->GetDesc(&adapter_desc);
auto description = converter.to_bytes(adapter_desc.Description);
auto description = to_utf8(adapter_desc.Description);
BOOST_LOG(info)
<< std::endl
<< "Device Description : " << description << std::endl
@ -1066,8 +1063,6 @@ namespace platf {
BOOST_LOG(debug) << "Detecting monitors..."sv;
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> converter;
// We must set the GPU preference before calling any DXGI APIs!
if (!dxgi::probe_for_gpu_preference(config::video.output_name)) {
BOOST_LOG(warning) << "Failed to set GPU preference. Capture may not work!"sv;
@ -1088,7 +1083,7 @@ namespace platf {
BOOST_LOG(debug)
<< std::endl
<< "====== ADAPTER ====="sv << std::endl
<< "Device Name : "sv << converter.to_bytes(adapter_desc.Description) << std::endl
<< "Device Name : "sv << to_utf8(adapter_desc.Description) << std::endl
<< "Device Vendor ID : 0x"sv << util::hex(adapter_desc.VendorId).to_string_view() << std::endl
<< "Device Device ID : 0x"sv << util::hex(adapter_desc.DeviceId).to_string_view() << std::endl
<< "Device Video Mem : "sv << adapter_desc.DedicatedVideoMemory / 1048576 << " MiB"sv << std::endl
@ -1104,7 +1099,7 @@ namespace platf {
DXGI_OUTPUT_DESC desc;
output->GetDesc(&desc);
auto device_name = converter.to_bytes(desc.DeviceName);
auto device_name = to_utf8(desc.DeviceName);
auto width = desc.DesktopCoordinates.right - desc.DesktopCoordinates.left;
auto height = desc.DesktopCoordinates.bottom - desc.DesktopCoordinates.top;