misc
This commit is contained in:
@@ -5,11 +5,6 @@
|
|||||||
// platform includes
|
// platform includes
|
||||||
#include <dxgi1_2.h>
|
#include <dxgi1_2.h>
|
||||||
|
|
||||||
// local includes
|
|
||||||
#include "display.h"
|
|
||||||
#include "misc.h"
|
|
||||||
#include "src/logging.h"
|
|
||||||
|
|
||||||
// Gross hack to work around MINGW-packages#22160
|
// Gross hack to work around MINGW-packages#22160
|
||||||
#define ____FIReference_1_boolean_INTERFACE_DEFINED__
|
#define ____FIReference_1_boolean_INTERFACE_DEFINED__
|
||||||
|
|
||||||
@@ -18,6 +13,11 @@
|
|||||||
#include <winrt/windows.foundation.metadata.h>
|
#include <winrt/windows.foundation.metadata.h>
|
||||||
#include <winrt/windows.graphics.directx.direct3d11.h>
|
#include <winrt/windows.graphics.directx.direct3d11.h>
|
||||||
|
|
||||||
|
// local includes
|
||||||
|
#include "display.h"
|
||||||
|
#include "misc.h"
|
||||||
|
#include "src/logging.h"
|
||||||
|
|
||||||
namespace platf {
|
namespace platf {
|
||||||
using namespace std::literals;
|
using namespace std::literals;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1744,7 +1744,7 @@ namespace platf {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring from_utf8(const std::string &string) {
|
std::wstring from_utf8(const std::string_view &string) {
|
||||||
// No conversion needed if the string is empty
|
// No conversion needed if the string is empty
|
||||||
if (string.empty()) {
|
if (string.empty()) {
|
||||||
return {};
|
return {};
|
||||||
@@ -1770,7 +1770,7 @@ namespace platf {
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string to_utf8(const std::wstring &string) {
|
std::string to_utf8(const std::wstring_view &string) {
|
||||||
// No conversion needed if the string is empty
|
// No conversion needed if the string is empty
|
||||||
if (string.empty()) {
|
if (string.empty()) {
|
||||||
return {};
|
return {};
|
||||||
|
|||||||
@@ -25,12 +25,12 @@ namespace platf {
|
|||||||
* @param string The UTF-8 string.
|
* @param string The UTF-8 string.
|
||||||
* @return The converted UTF-16 wide string.
|
* @return The converted UTF-16 wide string.
|
||||||
*/
|
*/
|
||||||
std::wstring from_utf8(const std::string &string);
|
std::wstring from_utf8(const std::string_view &string);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Convert a UTF-16 wide string into a UTF-8 string.
|
* @brief Convert a UTF-16 wide string into a UTF-8 string.
|
||||||
* @param string The UTF-16 wide string.
|
* @param string The UTF-16 wide string.
|
||||||
* @return The converted UTF-8 string.
|
* @return The converted UTF-8 string.
|
||||||
*/
|
*/
|
||||||
std::string to_utf8(const std::wstring &string);
|
std::string to_utf8(const std::wstring_view &string);
|
||||||
} // namespace platf
|
} // namespace platf
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ using namespace SUDOVDA;
|
|||||||
|
|
||||||
namespace VDISPLAY {
|
namespace VDISPLAY {
|
||||||
// {dff7fd29-5b75-41d1-9731-b32a17a17104}
|
// {dff7fd29-5b75-41d1-9731-b32a17a17104}
|
||||||
static const GUID DEFAULT_DISPLAY_GUID = { 0xdff7fd29, 0x5b75, 0x41d1, { 0x97, 0x31, 0xb3, 0x2a, 0x17, 0xa1, 0x71, 0x04 } };
|
// static const GUID DEFAULT_DISPLAY_GUID = { 0xdff7fd29, 0x5b75, 0x41d1, { 0x97, 0x31, 0xb3, 0x2a, 0x17, 0xa1, 0x71, 0x04 } };
|
||||||
|
|
||||||
HANDLE SUDOVDA_DRIVER_HANDLE = INVALID_HANDLE_VALUE;
|
HANDLE SUDOVDA_DRIVER_HANDLE = INVALID_HANDLE_VALUE;
|
||||||
|
|
||||||
@@ -263,7 +263,7 @@ LONG changeDisplaySettings2(const wchar_t* deviceName, int width, int height, in
|
|||||||
}
|
}
|
||||||
|
|
||||||
LONG changeDisplaySettings(const wchar_t* deviceName, int width, int height, int refresh_rate) {
|
LONG changeDisplaySettings(const wchar_t* deviceName, int width, int height, int refresh_rate) {
|
||||||
DEVMODEW devMode = {0};
|
DEVMODEW devMode = {};
|
||||||
devMode.dmSize = sizeof(devMode);
|
devMode.dmSize = sizeof(devMode);
|
||||||
|
|
||||||
// Old method to set at least baseline refresh rate
|
// Old method to set at least baseline refresh rate
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.20)
|
|||||||
|
|
||||||
project(sunshine_tools)
|
project(sunshine_tools)
|
||||||
|
|
||||||
include_directories("${CMAKE_SOURCE_DIR}")
|
include_directories(${CMAKE_SOURCE_DIR})
|
||||||
|
|
||||||
add_executable(dxgi-info dxgi.cpp)
|
add_executable(dxgi-info dxgi.cpp)
|
||||||
set_target_properties(dxgi-info PROPERTIES CXX_STANDARD 20)
|
set_target_properties(dxgi-info PROPERTIES CXX_STANDARD 20)
|
||||||
@@ -12,7 +12,7 @@ target_link_libraries(dxgi-info
|
|||||||
${PLATFORM_LIBRARIES})
|
${PLATFORM_LIBRARIES})
|
||||||
target_compile_options(dxgi-info PRIVATE ${SUNSHINE_COMPILE_OPTIONS})
|
target_compile_options(dxgi-info PRIVATE ${SUNSHINE_COMPILE_OPTIONS})
|
||||||
|
|
||||||
add_executable(audio-info audio.cpp)
|
add_executable(audio-info audio.cpp utils.cpp)
|
||||||
set_target_properties(audio-info PROPERTIES CXX_STANDARD 20)
|
set_target_properties(audio-info PROPERTIES CXX_STANDARD 20)
|
||||||
target_link_libraries(audio-info
|
target_link_libraries(audio-info
|
||||||
${CMAKE_THREAD_LIBS_INIT}
|
${CMAKE_THREAD_LIBS_INIT}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
#define INITGUID
|
#define INITGUID
|
||||||
#include "src/utility.h"
|
#include "src/utility.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
#include <audioclient.h>
|
#include <audioclient.h>
|
||||||
#include <codecvt>
|
#include <codecvt>
|
||||||
@@ -46,8 +47,6 @@ namespace audio {
|
|||||||
|
|
||||||
using handle_t = util::safe_ptr_v2<void, BOOL, CloseHandle>;
|
using handle_t = util::safe_ptr_v2<void, BOOL, CloseHandle>;
|
||||||
|
|
||||||
static std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> converter;
|
|
||||||
|
|
||||||
class prop_var_t {
|
class prop_var_t {
|
||||||
public:
|
public:
|
||||||
prop_var_t() {
|
prop_var_t() {
|
||||||
@@ -206,7 +205,7 @@ namespace audio {
|
|||||||
// so we can take the first match as the current format to display.
|
// so we can take the first match as the current format to display.
|
||||||
auto audio_client = make_audio_client(device, format);
|
auto audio_client = make_audio_client(device, format);
|
||||||
if (audio_client) {
|
if (audio_client) {
|
||||||
current_format = converter.from_bytes(format.name.data());
|
current_format = from_utf8(format.name);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
55
tools/utils.cpp
Normal file
55
tools/utils.cpp
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
#include "utils.h"
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
std::wstring from_utf8(const std::string_view &string) {
|
||||||
|
// No conversion needed if the string is empty
|
||||||
|
if (string.empty()) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the output size required to store the string
|
||||||
|
auto output_size = MultiByteToWideChar(CP_UTF8, 0, string.data(), string.size(), nullptr, 0);
|
||||||
|
if (output_size == 0) {
|
||||||
|
// auto winerr = GetLastError();
|
||||||
|
// BOOST_LOG(error) << "Failed to get UTF-16 buffer size: "sv << winerr;
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Perform the conversion
|
||||||
|
std::wstring output(output_size, L'\0');
|
||||||
|
output_size = MultiByteToWideChar(CP_UTF8, 0, string.data(), string.size(), output.data(), output.size());
|
||||||
|
if (output_size == 0) {
|
||||||
|
// auto winerr = GetLastError();
|
||||||
|
// BOOST_LOG(error) << "Failed to convert string to UTF-16: "sv << winerr;
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string to_utf8(const std::wstring_view &string) {
|
||||||
|
// No conversion needed if the string is empty
|
||||||
|
if (string.empty()) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the output size required to store the string
|
||||||
|
auto output_size = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, string.data(), string.size(), nullptr, 0, nullptr, nullptr);
|
||||||
|
if (output_size == 0) {
|
||||||
|
// auto winerr = GetLastError();
|
||||||
|
// BOOST_LOG(error) << "Failed to get UTF-8 buffer size: "sv << winerr;
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Perform the conversion
|
||||||
|
std::string output(output_size, '\0');
|
||||||
|
output_size = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, string.data(), string.size(), output.data(), output.size(), nullptr, nullptr);
|
||||||
|
if (output_size == 0) {
|
||||||
|
// auto winerr = GetLastError();
|
||||||
|
// BOOST_LOG(error) << "Failed to convert string to UTF-8: "sv << winerr;
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
15
tools/utils.h
Normal file
15
tools/utils.h
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#include <string>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Convert a UTF-8 string into a UTF-16 wide string.
|
||||||
|
* @param string The UTF-8 string.
|
||||||
|
* @return The converted UTF-16 wide string.
|
||||||
|
*/
|
||||||
|
std::wstring from_utf8(const std::string_view &string);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Convert a UTF-16 wide string into a UTF-8 string.
|
||||||
|
* @param string The UTF-16 wide string.
|
||||||
|
* @return The converted UTF-8 string.
|
||||||
|
*/
|
||||||
|
std::string to_utf8(const std::wstring_view &string);
|
||||||
Reference in New Issue
Block a user