Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Replace WinRT/C++ dependency with custom COM+ code.

Pāvels Nadtočajevsc6a028541a04
diff --git a/.github/workflows/windows_builds.yml b/.github/workflows/windows_builds.yml
index ef50065c0a6..9bdbc6b65c5 100644
--- a/.github/workflows/windows_builds.yml
+++ b/.github/workflows/windows_builds.yml
@@ -93,11 +93,6 @@ jobs:
echo "ANGLE_ENABLED=no" >> "$GITHUB_OUTPUT"
fi
- - name: Download WinRT components
- shell: sh
- run: python ./misc/scripts/install_winrt.py
- continue-on-error: true
-
- name: Download pre-built AccessKit
shell: sh
id: accesskit-sdk
diff --git a/SConstruct b/SConstruct
index b44cd914daf..2bfb79709b2 100644
--- a/SConstruct
+++ b/SConstruct
@@ -720,25 +720,14 @@ if cc_version_major == -1:
"Build may fail if the compiler doesn't support C++17 fully."
)
elif methods.using_gcc(env):
- if env.get("winrt"):
- if cc_version_major < 11:
- print_error(
- "Detected GCC version older than 11, which does not fully support "
- "C++20, or has bugs when compiling Godot. Supported versions are 12 "
- "and later. Use a newer GCC version, or Clang 14 or later by passing "
- '"use_llvm=yes" to the SCons command line, or disable WinRT support by '
- 'passing "winrt=no" to the SCons command line.'
- )
- Exit(255)
- else:
- if cc_version_major < 9:
- print_error(
- "Detected GCC version older than 9, which does not fully support "
- "C++17, or has bugs when compiling Godot. Supported versions are 9 "
- "and later. Use a newer GCC version, or Clang 6 or later by passing "
- '"use_llvm=yes" to the SCons command line.'
- )
- Exit(255)
+ if cc_version_major < 9:
+ print_error(
+ "Detected GCC version older than 9, which does not fully support "
+ "C++17, or has bugs when compiling Godot. Supported versions are 9 "
+ "and later. Use a newer GCC version, or Clang 6 or later by passing "
+ '"use_llvm=yes" to the SCons command line.'
+ )
+ Exit(255)
if cc_version_metadata1 == "win32":
print_error(
"Detected mingw version is not using posix threads. Only posix "
@@ -757,24 +746,15 @@ elif methods.using_clang(env):
)
Exit(255)
else:
- if env.get("winrt"):
- if cc_version_major < 13:
- print_error(
- "Detected Clang version older than 13, which does not fully support "
- "C++20. Supported versions are Clang 14 and later, or disable WinRT "
- 'support by passing "winrt=no" to the SCons command line.'
- )
- Exit(255)
- else:
- if cc_version_major < 6:
- print_error(
- "Detected Clang version older than 6, which does not fully support "
- "C++17. Supported versions are Clang 6 and later."
- )
- Exit(255)
- elif env["debug_paths_relative"] and cc_version_major < 10:
- print_warning("Clang < 10 doesn't support -ffile-prefix-map, disabling `debug_paths_relative` option.")
- env["debug_paths_relative"] = False
+ if cc_version_major < 6:
+ print_error(
+ "Detected Clang version older than 6, which does not fully support "
+ "C++17. Supported versions are Clang 6 and later."
+ )
+ Exit(255)
+ elif env["debug_paths_relative"] and cc_version_major < 10:
+ print_warning("Clang < 10 doesn't support -ffile-prefix-map, disabling `debug_paths_relative` option.")
+ env["debug_paths_relative"] = False
elif env.msvc:
if cc_version_major == 16 and cc_version_minor < 11:
diff --git a/misc/scripts/install_winrt.py b/misc/scripts/install_winrt.py
deleted file mode 100755
index ba1c87ffbf4..00000000000
--- a/misc/scripts/install_winrt.py
+++ /dev/null
@@ -1,48 +0,0 @@
-#!/usr/bin/env python3
-
-if __name__ != "__main__":
- raise SystemExit(f'Utility script "{__file__}" should not be used as a module!')
-
-import os
-import shutil
-import sys
-import urllib.request
-
-sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../"))
-
-
-# Base Godot dependencies path
-# If cross-compiling (no LOCALAPPDATA), we install in `bin`
-deps_folder = os.getenv("LOCALAPPDATA")
-if deps_folder and not os.getenv("MSYSTEM"):
- deps_folder = os.path.join(deps_folder, "Godot", "build_deps")
-else:
- deps_folder = os.path.join("bin", "build_deps")
-
-# WinRT
-winrt_version = "72"
-
-# Create dependencies folder
-if not os.path.exists(deps_folder):
- os.makedirs(deps_folder)
-
-winrt_filename = "winrt-headers.zip"
-winrt_archive = os.path.join(deps_folder, winrt_filename)
-winrt_folder = os.path.join(deps_folder, "winrt_mingw")
-
-if os.path.isfile(winrt_archive):
- os.remove(winrt_archive)
-
-print(f"Downloading WinRT {winrt_filename} ...")
-urllib.request.urlretrieve(
- f"https://github.com/godotengine/winrt-mingw/releases/download/{winrt_version}/{winrt_filename}",
- winrt_archive,
-)
-if os.path.exists(winrt_folder):
- print(f"Removing existing local WinRT installation in {winrt_folder} ...")
- shutil.rmtree(winrt_folder)
-print(f"Extracting WinRT {winrt_filename} to {winrt_folder} ...")
-shutil.unpack_archive(winrt_archive, winrt_folder)
-os.remove(winrt_archive)
-
-print("WinRT installed successfully.\n")
diff --git a/platform/windows/SCsub b/platform/windows/SCsub
index 71316b783ef..246fc610624 100644
--- a/platform/windows/SCsub
+++ b/platform/windows/SCsub
@@ -8,7 +8,7 @@ from pathlib import Path
import platform_windows_builders
-from methods import get_compiler_version, redirect_emitter
+from methods import redirect_emitter
sources = []
@@ -23,6 +23,10 @@ common_win = [
"wgl_detect_version.cpp",
"rendering_context_driver_vulkan_windows.cpp",
"drop_target_windows.cpp",
+ "winrt_utils.cpp",
+ "tts_windows.cpp",
+ "tts_driver_sapi.cpp",
+ "tts_driver_onecore.cpp",
]
if env["angle"]:
@@ -81,31 +85,6 @@ env.Depends(res_obj, "#core/version_generated.gen.h")
env.add_source_files(sources, common_win)
-env_winrt = env.Clone()
-tts_sources = ["tts_windows.cpp", "tts_driver_sapi.cpp", "winrt_utils.cpp"]
-if env["winrt"]:
- if not env_winrt.msvc:
- if "-std=gnu++17" in env_winrt["CXXFLAGS"]:
- env_winrt["CXXFLAGS"].remove("-std=gnu++17")
- env_winrt.Append(CXXFLAGS=["-std=gnu++20"])
- if "-fno-exceptions" in env_winrt["CXXFLAGS"]:
- env_winrt["CXXFLAGS"].remove("-fno-exceptions")
- env_winrt.Append(CXXFLAGS=["-fexceptions"])
- else:
- cc_version = get_compiler_version(env)
- cc_version_major = cc_version["major"]
- if "/std:c++17" in env_winrt["CXXFLAGS"]:
- env_winrt["CXXFLAGS"].remove("/std:c++17")
- env_winrt.Append(CXXFLAGS=["/std:c++20"])
- if "_HAS_EXCEPTIONS" in env_winrt["CPPDEFINES"]:
- env_winrt["CPPDEFINES"].remove("_HAS_EXCEPTIONS")
- env_winrt.Append(CXXFLAGS=["/EHsc"])
- if not env_winrt.msvc:
- env_winrt.Append(CPPPATH=[env["winrt_path"]])
- env_winrt.AppendUnique(CPPDEFINES=["WINRT_ENABLED"])
- tts_sources += ["tts_driver_onecore.cpp"]
-env_winrt.add_source_files(sources, tts_sources)
-
sources += res_obj
if env["accesskit"] and not env.msvc:
diff --git a/platform/windows/detect.py b/platform/windows/detect.py
index e9f1775acd2..80bb9958c59 100644
--- a/platform/windows/detect.py
+++ b/platform/windows/detect.py
@@ -151,23 +151,6 @@ def check_mssdk_version(env, version, msvc_ver):
print_error(f"Specified Windows SDK version {mssdk} is not installed, installed versions are: {mssdk_list}.")
sys.exit(255)
- if env["winrt"]:
- if msvc_ver == "14.2": # Visual Studio 2019, force supported SDK.
- if "10.0.22621.0" in mssdk_list:
- mssdk = "10.0.22621.0"
- else:
- print_error(
- "Visual Studio 2019 require Windows SDK 10.0.22621.0 to use WinRT, install supported Windows SDK version "
- 'or disable WinRT support by passing "winrt=no" to the SCons command line.'
- )
- sys.exit(255)
- elif ver_parse(mssdk)[2] < 22621:
- print_error(
- "Windows SDK 10.0.22621.0 or newer is required to use WinRT, install supported Windows SDK version "
- 'or disable WinRT support by passing "winrt=no" to the SCons command line.'
- )
- sys.exit(255)
-
print(f"Using Visual Studio {msvc_ver} with Windows SDK {mssdk}.")
return mssdk
@@ -232,7 +215,6 @@ def get_opts():
BoolVariable("debug_crt", "Compile with MSVC's debug CRT (/MDd)", False),
BoolVariable("incremental_link", "Use MSVC incremental linking. May increase or decrease build times.", False),
BoolVariable("silence_msvc", "Silence MSVC's cl/link stdout bloat, redirecting any errors to stderr.", True),
- BoolVariable("winrt", "Use WinRT API (OneCore TTS support).", True),
# Screen reader support.
(
"accesskit_sdk_path",
@@ -245,12 +227,6 @@ def get_opts():
"Path to the ANGLE static libraries",
os.path.join(deps_folder, "angle"),
),
- # WinRT.
- (
- "winrt_path",
- "Path to the WinRT headers (MinGW only)",
- os.path.join(deps_folder, "winrt_mingw"),
- ),
# Direct3D 12 support.
(
"mesa_libs",
@@ -868,30 +844,6 @@ def configure_mingw(env: "SConsEnvironment"):
]
)
- if env["winrt"]:
- if not os.path.exists(env["winrt_path"]):
- prefix = os.getenv("MINGW_PREFIX", "")
- msys = os.getenv("MSYSTEM", "")
- if msys != "" and prefix != "":
- if not os.path.exists(os.path.join(prefix, "include/winrt")):
- print_warning(
- "The WinRT/OneCore API requires dependencies to be installed.\n"
- f"You can install them by installing `cppwinrt` MSYS2 package or by running `python {os.path.join('misc', 'scripts', 'install_winrt.py')}`.\n"
- "See the documentation for more information:\n"
- "\thttps://docs.godotengine.org/en/latest/engine_details/development/compiling/compiling_for_windows.html\n"
- "Alternatively, disable this driver by compiling with `winrt=no` explicitly."
- )
- env["winrt"] = False
- else:
- print_warning(
- "The WinRT/OneCore API requires dependencies to be installed.\n"
- f"You can install them by running `python {os.path.join('misc', 'scripts', 'install_winrt.py')}`.\n"
- "See the documentation for more information:\n"
- "\thttps://docs.godotengine.org/en/latest/engine_details/development/compiling/compiling_for_windows.html\n"
- "Alternatively, disable this driver by compiling with `winrt=no` explicitly."
- )
- env["winrt"] = False
-
if env["accesskit"]:
if os.path.exists(env["accesskit_sdk_path"]):
env.Prepend(CPPPATH=[env["accesskit_sdk_path"] + "/include"])
diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp
index 8ca3838cc23..1439ae6c4c7 100644
--- a/platform/windows/display_server_windows.cpp
+++ b/platform/windows/display_server_windows.cpp
@@ -7635,14 +7635,16 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Dis
rendering_driver = p_rendering_driver;
- // Init TTS
+ native_menu = memnew(NativeMenuWindows);
+
+ // Init WinRT API and create dispatch queue.
+ has_winrt_queue = WinRTUtils::create_queue();
+
+ // Init TTS (note: should be called after WinRT init).
bool tts_enabled = GLOBAL_GET("audio/general/text_to_speech");
if (tts_enabled) {
initialize_tts();
}
- native_menu = memnew(NativeMenuWindows);
-
- has_winrt_queue = WinRTUtils::create_queue();
// Enforce default keep screen on value.
screen_set_keep_on(GLOBAL_GET("display/window/energy_saving/keep_screen_on"));
diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp
index 26e25605466..62d02f2e3d8 100644
--- a/platform/windows/os_windows.cpp
+++ b/platform/windows/os_windows.cpp
@@ -2906,6 +2906,8 @@ OS_Windows::OS_Windows(HINSTANCE _hInstance) {
CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
+ WinRTUtils::init();
+
#ifdef WASAPI_ENABLED
AudioDriverManager::add_driver(&driver_wasapi);
#endif
@@ -2935,5 +2937,6 @@ OS_Windows::OS_Windows(HINSTANCE _hInstance) {
}
OS_Windows::~OS_Windows() {
+ WinRTUtils::cleanup();
CoUninitialize();
}
diff --git a/platform/windows/tts_driver_onecore.cpp b/platform/windows/tts_driver_onecore.cpp
index 48e1c698b08..f0ece1ff622 100644
--- a/platform/windows/tts_driver_onecore.cpp
+++ b/platform/windows/tts_driver_onecore.cpp
@@ -33,6 +33,117 @@
#include "core/object/callable_mp.h"
#include "servers/display/display_server.h"
+static const WCHAR *ROSpeechSynthesizerName = L"Windows.Media.SpeechSynthesis.SpeechSynthesizer";
+static const WCHAR *ROMediaPlayerName = L"Windows.Media.Playback.MediaPlayer";
+static const WCHAR *ROMediaSourceName = L"Windows.Media.Core.MediaSource";
+static const WCHAR *ROMediaPlaybackItemName = L"Windows.Media.Playback.MediaPlaybackItem";
+static const WCHAR *ROSpeechSynthesisStreamName = L"Windows.Media.SpeechSynthesis.SpeechSynthesisStream";
+
+/**************************************************************************/
+/* MediaPlayer events */
+/**************************************************************************/
+
+GODOT_GCC_WARNING_PUSH
+GODOT_GCC_WARNING_IGNORE("-Wnon-virtual-dtor")
+GODOT_GCC_WARNING_IGNORE("-Wctor-dtor-privacy")
+GODOT_GCC_WARNING_IGNORE("-Wshadow")
+GODOT_GCC_WARNING_IGNORE("-Wstrict-aliasing")
+GODOT_CLANG_WARNING_PUSH
+GODOT_CLANG_WARNING_IGNORE("-Wnon-virtual-dtor")
+
+class GodotMediaEndedEventHandler : public ROTypedEventHandler_MediaPlayer_IInspectable {
+ TYPED_EVENT_HANDLER_CLASS(GodotMediaEndedEventHandler, ROTypedEventHandler_MediaPlayer_IInspectable)
+
+ HRESULT STDMETHODCALLTYPE Invoke(ROMediaPlayer *p_sender, IInspectable *p_args) {
+ ERR_FAIL_NULL_V(TTSDriverOneCore::singleton, E_ABORT);
+ TTSDriverOneCore::singleton->_dispose_current(false, false);
+ return S_OK;
+ }
+};
+
+class GodotMediaFailedEventHandler : public ROTypedEventHandler_MediaPlayer_MediaPlayerFailedEventArgs {
+ TYPED_EVENT_HANDLER_CLASS(GodotMediaFailedEventHandler, ROTypedEventHandler_MediaPlayer_MediaPlayerFailedEventArgs)
+
+ HRESULT STDMETHODCALLTYPE Invoke(ROMediaPlayer *p_sender, ROMediaPlayerFailedEventArgs *p_args) {
+ ERR_FAIL_NULL_V(TTSDriverOneCore::singleton, E_ABORT);
+ TTSDriverOneCore::singleton->_dispose_current(false, true);
+ return S_OK;
+ }
+};
+
+class GodotMediaMarkerReachedEventHandler : public ROTypedEventHandler_MediaPlayer_PlaybackMediaMarkerReachedEventArgs {
+ TYPED_EVENT_HANDLER_CLASS(GodotMediaMarkerReachedEventHandler, ROTypedEventHandler_MediaPlayer_PlaybackMediaMarkerReachedEventArgs)
+
+ HRESULT STDMETHODCALLTYPE Invoke(ROMediaPlayer *p_sender, ROPlaybackMediaMarkerReachedEventArgs *p_args) {
+ ERR_FAIL_NULL_V(TTSDriverOneCore::singleton, E_ABORT);
+
+ ComPtr<ROPlaybackMediaMarkerReachedEventArgs> args_marker = p_args;
+ ComPtr<ROPlaybackMediaMarker> marker;
+ ERR_FAIL_COND_V(FAILED(args_marker->get_PlaybackMediaMarker((void **)marker.GetAddressOf())), E_ABORT);
+
+ Ref<HStringWrapper> htext;
+ htext.instantiate();
+ ERR_FAIL_COND_V(FAILED(marker->get_Text((void **)htext->get_ptrw())), E_ABORT);
+
+ String text = htext->get_string();
+ TTSDriverOneCore::singleton->offset += text.length() + 1;
+ int pos = 0;
+ for (int j = 0; j < MIN(TTSDriverOneCore::singleton->offset, TTSDriverOneCore::singleton->string.length()); j++) {
+ char16_t c = TTSDriverOneCore::singleton->string[j];
+ if ((c & 0xfffffc00) == 0xd800) {
+ j++;
+ }
+ pos++;
+ }
+ callable_mp(TTSDriverOneCore::singleton, &TTSDriverOneCore::_speech_index_mark).call_deferred(TTSDriverOneCore::singleton->id, pos);
+ return S_OK;
+ }
+};
+
+/**************************************************************************/
+/* TimedMetadataTrack events */
+/**************************************************************************/
+
+class GodotMediaCueEventHandler : public ROTypedEventHandler_TimedMetadataTrack_MediaCueEventArgs {
+ TYPED_EVENT_HANDLER_CLASS(GodotMediaCueEventHandler, ROTypedEventHandler_TimedMetadataTrack_MediaCueEventArgs)
+
+ HRESULT STDMETHODCALLTYPE Invoke(ROTimedMetadataTrack *p_sender, ROMediaCueEventArgs *p_args) {
+ ERR_FAIL_NULL_V(TTSDriverOneCore::singleton, E_ABORT);
+
+ ComPtr<ROMediaCueEventArgs> args_cue = p_args;
+ ComPtr<ROMediaCue> media_cue;
+ ERR_FAIL_COND_V(FAILED(args_cue->get_Cue((void **)media_cue.GetAddressOf())), E_ABORT);
+ ComPtr<ROSpeechCue> sp_cue;
+ ERR_FAIL_COND_V(FAILED(media_cue.As(&sp_cue)), E_ABORT);
+
+ ComPtr<IInspectable> start_ref_ii;
+ ERR_FAIL_COND_V(FAILED(sp_cue->get_StartPositionInInput((void **)start_ref_ii.GetAddressOf())), E_ABORT);
+ ComPtr<ROReference_1_Int32> start_ref;
+ ERR_FAIL_COND_V(FAILED(start_ref_ii.As(&start_ref)), E_ABORT);
+
+ int32_t pos16 = 0;
+ ERR_FAIL_COND_V(FAILED(start_ref->get_Value(&pos16)), E_ABORT);
+
+ int pos = 0;
+ for (int j = 0; j < MIN(pos16, TTSDriverOneCore::singleton->string.length()); j++) {
+ char16_t c = TTSDriverOneCore::singleton->string[j];
+ if ((c & 0xfffffc00) == 0xd800) {
+ j++;
+ }
+ pos++;
+ }
+ callable_mp(TTSDriverOneCore::singleton, &TTSDriverOneCore::_speech_index_mark).call_deferred(TTSDriverOneCore::singleton->id, pos);
+ return S_OK;
+ }
+};
+
+GODOT_GCC_WARNING_POP
+GODOT_CLANG_WARNING_POP
+
+/**************************************************************************/
+/* TTSDriverOneCore */
+/**************************************************************************/
+
TTSDriverOneCore *TTSDriverOneCore::singleton = nullptr;
void TTSDriverOneCore::_speech_index_mark(int p_msg_id, int p_index_mark) {
@@ -48,18 +159,20 @@ void TTSDriverOneCore::_speech_end(int p_msg_id) {
}
void TTSDriverOneCore::_dispose_current(bool p_silent, bool p_canceled) {
- if (media.get() != nullptr) {
+ if (media) {
for (const TrackData &T : tracks) {
- T.track.CueEntered(T.token);
+ T.track->remove_CueEntered(T.token_c);
}
tracks.clear();
- media->MediaFailed(singleton->token_f);
- media->MediaEnded(singleton->token_e);
- if (!ApiInformation::IsApiContractPresent(L"Windows.Foundation.UniversalApiContract", 4)) {
- media->PlaybackMediaMarkerReached(singleton->token_s);
+ media->remove_MediaFailed(token_f);
+ media->remove_MediaEnded(token_e);
+ if (token_s) {
+ media->remove_PlaybackMediaMarkerReached(token_s);
}
- media->Close();
- media.reset();
+ media.Reset();
+ token_e.reset();
+ token_f.reset();
+ token_s.reset();
if (!p_silent) {
if (p_canceled) {
@@ -82,87 +195,159 @@ void TTSDriverOneCore::process_events() {
_dispose_current(true);
playing = true;
- SpeechSynthesizer synth = SpeechSynthesizer();
-
- if (ApiInformation::IsApiContractPresent(L"Windows.Foundation.UniversalApiContract", 4)) {
- synth.Options().IncludeWordBoundaryMetadata(true);
- }
- if (ApiInformation::IsApiContractPresent(L"Windows.Foundation.UniversalApiContract", 5)) {
- synth.Options().SpeakingRate(CLAMP(message.rate, 0.5, 6.0));
- synth.Options().AudioPitch(CLAMP(message.pitch, 0.0, 2.0));
- synth.Options().AudioVolume(CLAMP((double)message.volume / 100.0, 0.0, 1.0));
+ ComPtr<IActivationFactory> synth_fact;
+ ERR_FAIL_COND(FAILED(WinRTUtils::activation_factory(ROSpeechSynthesizerName, IID_PPV_ARGS(&synth_fact))));
+
+ ComPtr<ROSpeechSynthesizer> synth;
+ ERR_FAIL_COND(FAILED(synth_fact->ActivateInstance((IInspectable **)synth.GetAddressOf())));
+
+ if (WinRTUtils::is_api_contract_present(L"Windows.Foundation.UniversalApiContract", 4)) {
+ ComPtr<ROSpeechSynthesizer2> synth2;
+ HRESULT res = synth.As(&synth2);
+ if (SUCCEEDED(res)) {
+ ComPtr<ROSpeechSynthesizerOptions> opts;
+ res = synth2->get_Options((void **)opts.GetAddressOf());
+ if (SUCCEEDED(res)) {
+ opts->put_IncludeWordBoundaryMetadata(true);
+ if (WinRTUtils::is_api_contract_present(L"Windows.Foundation.UniversalApiContract", 5)) {
+ ComPtr<ROSpeechSynthesizerOptions2> opts2;
+ res = opts.As(&opts2);
+ if (SUCCEEDED(res)) {
+ opts2->put_AudioVolume(CLAMP((double)message.volume / 100.0, 0.0, 1.0));
+ opts2->put_SpeakingRate(CLAMP(message.rate, 0.5, 6.0));
+ opts2->put_AudioPitch(CLAMP(message.pitch, 0.0, 2.0));
+ }
+ }
+ }
+ }
}
- winrt::hstring name = winrt::hstring((const wchar_t *)message.voice.utf16().get_data());
- IVectorView<VoiceInformation> voices = SpeechSynthesizer::AllVoices();
- for (uint32_t i = 0; i < voices.Size(); i++) {
- VoiceInformation voice = voices.GetAt(i);
- if (voice.Id() == name) {
- synth.Voice(voice);
- break;
+ ComPtr<ROInstalledVoicesStatic> synth_static;
+ ERR_FAIL_COND(FAILED(WinRTUtils::activation_factory(ROSpeechSynthesizerName, IID_PPV_ARGS(&synth_static))));
+
+ ComPtr<ROVectorView_IInspectable> voices;
+ ERR_FAIL_COND(FAILED(synth_static->get_AllVoices((void **)voices.GetAddressOf())));
+
+ uint32_t size = 0;
+ ERR_FAIL_COND(FAILED(voices->get_Size(&size)));
+
+ for (uint32_t i = 0; i < size; i++) {
+ ComPtr<ROVoiceInformation> voice;
+ ERR_CONTINUE(FAILED(voices->GetAt(i, (IInspectable **)voice.GetAddressOf())));
+
+ Ref<HStringWrapper> vid;
+ vid.instantiate();
+ ERR_CONTINUE(FAILED(voice->get_Id((void **)vid->get_ptrw())));
+
+ if (vid->get_string() == message.voice) {
+ synth->put_Voice((void **)voice.Get());
}
}
+ Ref<HStringWrapper> text;
+ text.instantiate();
+ text->set_string(message.text);
string = message.text.utf16();
- winrt::hstring text = winrt::hstring((const wchar_t *)string.get_data());
-
- SpeechSynthesisStream stream = synth.SynthesizeTextToStreamAsync(text).get();
-
- media = std::make_shared<MediaPlayer>();
- token_f = media->MediaFailed([=, this](const MediaPlayer &p_sender, const MediaPlayerFailedEventArgs &p_args) {
- _dispose_current(false, true);
- });
- token_e = media->MediaEnded([=, this](const MediaPlayer &p_sender, const IInspectable &p_args) {
- _dispose_current(false, false);
- });
- if (ApiInformation::IsApiContractPresent(L"Windows.Foundation.UniversalApiContract", 4)) {
- MediaPlaybackItem mitem = MediaPlaybackItem(MediaSource::CreateFromStream(stream, stream.ContentType()));
- media->Source(mitem);
- MediaPlaybackTimedMetadataTrackList list = mitem.TimedMetadataTracks();
-
- for (uint32_t i = 0; i < list.Size(); i++) {
- TimedMetadataTrack track = list.GetAt(i);
- if (track.TimedMetadataKind() == TimedMetadataKind::Speech) {
- winrt::event_token token = track.CueEntered([=, this](const TimedMetadataTrack &p_sender, const MediaCueEventArgs &p_args) {
- SpeechCue sq;
- p_args.Cue().as(sq);
- int32_t pos16 = sq.StartPositionInInput().Value();
- int pos = 0;
- for (int j = 0; j < MIN(pos16, string.length()); j++) {
- char16_t c = string[j];
- if ((c & 0xfffffc00) == 0xd800) {
- j++;
- }
- pos++;
- }
- callable_mp(singleton, &TTSDriverOneCore::_speech_index_mark).call_deferred(id, pos);
- });
- tracks.push_back({ track, token });
- list.SetPresentationMode(i, TimedMetadataTrackPresentationMode::ApplicationPresented);
+
+ ComPtr<ROAsyncOperation> stream_op;
+ ERR_FAIL_COND(FAILED(synth->SynthesizeTextToStreamAsync(text->get_ptr(), (void **)stream_op.GetAddressOf())));
+
+ ComPtr<ROAsyncInfo> stream_op_info;
+ ERR_FAIL_COND(FAILED(stream_op.As(&stream_op_info)));
+
+ ROAsyncStatus stream_op_status = ROAsyncStatus::Started;
+ while (stream_op_status == ROAsyncStatus::Started) {
+ Sleep(1);
+ stream_op_info->get_Status((int32_t *)&stream_op_status);
+ }
+ ERR_FAIL_COND_MSG(stream_op_status != ROAsyncStatus::Completed, "AsyncOperation<SpeechSynthesisStream> failed.");
+
+ ComPtr<IInspectable> stream_ii;
+ ERR_FAIL_COND(FAILED(stream_op->GetResults((void **)stream_ii.GetAddressOf())));
+ ComPtr<ROSpeechSynthesisStream> stream;
+ ERR_FAIL_COND(FAILED(stream_ii.As(&stream)));
+ ComPtr<ROContentTypeProvider> stream_ct;
+ ERR_FAIL_COND(FAILED(stream.As(&stream_ct)));
+
+ ComPtr<IActivationFactory> media_fact;
+ ERR_FAIL_COND(FAILED(WinRTUtils::activation_factory(ROMediaPlayerName, IID_PPV_ARGS(&media_fact))));
+
+ ComPtr<IInspectable> media_ii;
+ ERR_FAIL_COND(FAILED(media_fact->ActivateInstance((IInspectable **)media_ii.GetAddressOf())));
+ ERR_FAIL_COND(FAILED(media_ii.As(&media)));
+
+ GodotMediaEndedEventHandler *handler_end = new GodotMediaEndedEventHandler();
+ ERR_FAIL_COND(FAILED(handler_end->QueryInterface(IID_PPV_ARGS(&handler_e))));
+ ERR_FAIL_COND(FAILED(media->add_MediaEnded(handler_e.Get(), &token_e)));
+ GodotMediaFailedEventHandler *handler_fail = new GodotMediaFailedEventHandler();
+ ERR_FAIL_COND(FAILED(handler_fail->QueryInterface(IID_PPV_ARGS(&handler_f))));
+ ERR_FAIL_COND(FAILED(media->add_MediaFailed(handler_f.Get(), &token_f)));
+
+ ComPtr<ROMediaSourceStatics> source_static;
+ ERR_FAIL_COND(FAILED(WinRTUtils::activation_factory(ROMediaSourceName, IID_PPV_ARGS(&source_static))));
+
+ Ref<HStringWrapper> ctype;
+ ctype.instantiate();
+ ERR_FAIL_COND(FAILED(stream_ct->get_ContentType((void **)ctype->get_ptrw())));
+
+ ComPtr<RORandomAccessStream> stream_ra;
+ ERR_FAIL_COND(FAILED(stream.As(&stream_ra)));
+
+ ComPtr<ROMediaSource> source;
+ ERR_FAIL_COND(FAILED(source_static->CreateFromStream(stream_ra.Get(), ctype->get_ptr(), (void **)source.GetAddressOf())));
+
+ ComPtr<ROMediaPlayerSource2> player_source;
+ ERR_FAIL_COND(FAILED(media.As(&player_source)));
+
+ if (WinRTUtils::is_api_contract_present(L"Windows.Foundation.UniversalApiContract", 4) && WinRTUtils::is_type_present(ROMediaPlaybackItemName)) {
+ ComPtr<ROMediaPlaybackItemFactory> mitem_fact;
+ ERR_FAIL_COND(FAILED(WinRTUtils::activation_factory(ROMediaPlaybackItemName, IID_PPV_ARGS(&mitem_fact))));
+
+ ComPtr<ROMediaPlaybackItem> mitem;
+ ERR_FAIL_COND(FAILED(mitem_fact->Create(source.Get(), (void **)mitem.GetAddressOf())));
+ ERR_FAIL_COND(FAILED(player_source->put_Source(mitem.Get())));
+
+ ComPtr<IInspectable> list_ii;
+ ERR_FAIL_COND(FAILED(mitem->get_TimedMetadataTracks((void **)list_ii.GetAddressOf())));
+ ComPtr<ROMediaPlaybackTimedMetadataTrackList> list;
+ ComPtr<ROVectorView_TimedMetadataTrack> list_items;
+ ERR_FAIL_COND(FAILED(list_ii.As(&list)));
+ ERR_FAIL_COND(FAILED(list_ii.As(&list_items)));
+
+ uint32_t list_size = 0;
+ ERR_FAIL_COND(FAILED(list_items->get_Size(&list_size)));
+ for (uint32_t i = 0; i < list_size; i++) {
+ ComPtr<ROTimedMetadataTrack> track;
+ ERR_CONTINUE(FAILED(list_items->GetAt(i, track.GetAddressOf())));
+
+ int32_t track_kind = 0;
+ ERR_CONTINUE(FAILED(track->get_TimedMetadataKind(&track_kind)));
+ if ((ROTimedMetadataKind)track_kind == ROTimedMetadataKind::Speech) {
+ ROEventToken token_c;
+ ComPtr<ROTypedEventHandler_TimedMetadataTrack_MediaCueEventArgs> handler_c;
+ GodotMediaCueEventHandler *handler_cue = new GodotMediaCueEventHandler();
+ ERR_CONTINUE(FAILED(handler_cue->QueryInterface(IID_PPV_ARGS(&handler_c))));
+ ERR_CONTINUE(FAILED(track->add_CueEntered(handler_c.Get(), &token_c)));
+ ERR_CONTINUE(FAILED(list->SetPresentationMode(i, (int32_t)RoTimedMetadataTrackPresentationMode::ApplicationPresented)));
+
+ tracks.push_back({ token_c, handler_c, track });
}
}
} else {
- media->Source(MediaSource::CreateFromStream(stream, stream.ContentType()));
- token_s = media->PlaybackMediaMarkerReached([=, this](const MediaPlayer &p_sender, const PlaybackMediaMarkerReachedEventArgs &p_args) {
- offset += p_args.PlaybackMediaMarker().Text().size() + 1;
- int pos = 0;
- for (int j = 0; j < MIN(offset, string.length()); j++) {
- char16_t c = string[j];
- if ((c & 0xfffffc00) == 0xd800) {
- j++;
- }
- pos++;
- }
- callable_mp(singleton, &TTSDriverOneCore::_speech_index_mark).call_deferred(id, pos);
- });
+ ERR_FAIL_COND(FAILED(player_source->put_Source(source.Get())));
+
+ GodotMediaMarkerReachedEventHandler *handler_marker = new GodotMediaMarkerReachedEventHandler();
+ ERR_FAIL_COND(FAILED(handler_marker->QueryInterface(IID_PPV_ARGS(&handler_s))));
+ ERR_FAIL_COND(FAILED(media->add_PlaybackMediaMarkerReached(handler_s.Get(), &token_s)));
}
- media->AutoPlay(true);
+
+ ERR_FAIL_COND(FAILED(media->put_AutoPlay(true)));
id = message.id;
update_requested = false;
paused = false;
- media->Play();
+ ERR_FAIL_COND(FAILED(media->Play()));
DisplayServer::get_singleton()->tts_post_utterance_event(DisplayServerEnums::TTS_UTTERANCE_STARTED, message.id);
queue.pop_front();
@@ -180,17 +365,35 @@ bool TTSDriverOneCore::is_paused() const {
Array TTSDriverOneCore::get_voices() const {
Array list;
- IVectorView<VoiceInformation> voices = SpeechSynthesizer::AllVoices();
- for (uint32_t i = 0; i < voices.Size(); i++) {
- VoiceInformation voice = voices.GetAt(i);
- winrt::hstring vname = voice.DisplayName();
- winrt::hstring vid = voice.Id();
- winrt::hstring vlang = voice.Language();
+ ComPtr<ROInstalledVoicesStatic> synth_static;
+ ERR_FAIL_COND_V(FAILED(WinRTUtils::activation_factory(ROSpeechSynthesizerName, IID_PPV_ARGS(&synth_static))), list);
+
+ ComPtr<ROVectorView_IInspectable> voices;
+ ERR_FAIL_COND_V(FAILED(synth_static->get_AllVoices((void **)voices.GetAddressOf())), list);
+
+ uint32_t size = 0;
+ ERR_FAIL_COND_V(FAILED(voices->get_Size(&size)), list);
+
+ for (uint32_t i = 0; i < size; i++) {
+ ComPtr<ROVoiceInformation> voice;
+ ERR_CONTINUE(FAILED(voices->GetAt(i, (IInspectable **)voice.GetAddressOf())));
+
+ Ref<HStringWrapper> vname;
+ vname.instantiate();
+ ERR_CONTINUE(FAILED(voice->get_DisplayName((void **)vname->get_ptrw())));
+
+ Ref<HStringWrapper> vid;
+ vid.instantiate();
+ ERR_CONTINUE(FAILED(voice->get_Id((void **)vid->get_ptrw())));
+
+ Ref<HStringWrapper> vlang;
+ vlang.instantiate();
+ ERR_CONTINUE(FAILED(voice->get_Language((void **)vlang->get_ptrw())));
Dictionary voice_d;
- voice_d["id"] = String::utf16((const char16_t *)vid.c_str(), vid.size());
- voice_d["name"] = String::utf16((const char16_t *)vname.c_str(), vname.size());
- voice_d["language"] = String::utf16((const char16_t *)vlang.c_str(), vlang.size()).replace_char('-', '_');
+ voice_d["id"] = vid->get_string();
+ voice_d["name"] = vname->get_string();
+ voice_d["language"] = vlang->get_string().replace_char('-', '_');
list.push_back(voice_d);
}
return list;
@@ -245,14 +448,29 @@ void TTSDriverOneCore::stop() {
}
bool TTSDriverOneCore::init() {
- if (!ApiInformation::IsApiContractPresent(L"Windows.Foundation.UniversalApiContract", 1)) {
- print_verbose("Text-to-Speech: Cannot initialize OneCore driver, API contract not present!");
+ if (!WinRTUtils::is_initialized()) {
+ print_verbose("Text-to-Speech: Cannot initialize OneCore driver, WinRT API not supported!");
+ return false;
+ }
+ if (!WinRTUtils::is_api_contract_present(L"Windows.Foundation.UniversalApiContract", 1) || !WinRTUtils::is_type_present(ROSpeechSynthesizerName) || !WinRTUtils::is_type_present(ROSpeechSynthesisStreamName) || !WinRTUtils::is_type_present(ROMediaPlayerName)) {
+ print_verbose("Text-to-Speech: Cannot initialize OneCore driver, API contract or type not present!");
+ }
+ ComPtr<ROInstalledVoicesStatic> synth_static;
+ if (FAILED(WinRTUtils::activation_factory(ROSpeechSynthesizerName, IID_PPV_ARGS(&synth_static)))) {
+ print_verbose("Text-to-Speech: Cannot initialize OneCore driver, interface not supported!");
return false;
}
- if (SpeechSynthesizer::AllVoices().Size() == 0) {
+
+ ComPtr<ROVectorView_IInspectable> voices;
+ ERR_FAIL_COND_V(FAILED(synth_static->get_AllVoices((void **)voices.GetAddressOf())), false);
+
+ uint32_t size = 0;
+ ERR_FAIL_COND_V(FAILED(voices->get_Size(&size)), false);
+ if (size == 0) {
print_verbose("Text-to-Speech: Cannot initialize OneCore driver, no voices found!");
return false;
}
+
print_verbose("Text-to-Speech: OneCore initialized.");
return true;
}
diff --git a/platform/windows/tts_driver_onecore.h b/platform/windows/tts_driver_onecore.h
index 6cd8f181e23..8a570fca5a2 100644
--- a/platform/windows/tts_driver_onecore.h
+++ b/platform/windows/tts_driver_onecore.h
@@ -31,57 +31,45 @@
#pragma once
#include "tts_driver.h"
-
-GODOT_GCC_WARNING_PUSH
-GODOT_GCC_WARNING_IGNORE("-Wnon-virtual-dtor")
-GODOT_GCC_WARNING_IGNORE("-Wctor-dtor-privacy")
-GODOT_GCC_WARNING_IGNORE("-Wshadow")
-GODOT_GCC_WARNING_IGNORE("-Wstrict-aliasing")
-GODOT_CLANG_WARNING_PUSH
-GODOT_CLANG_WARNING_IGNORE("-Wnon-virtual-dtor")
-
-#include <winrt/Windows.Foundation.Collections.h>
-#include <winrt/Windows.Foundation.Metadata.h>
-#include <winrt/Windows.Media.Core.h>
-#include <winrt/Windows.Media.Playback.h>
-#include <winrt/Windows.Media.SpeechSynthesis.h>
-#include <winrt/Windows.Storage.Streams.h>
-
-GODOT_GCC_WARNING_POP
-GODOT_CLANG_WARNING_POP
-
-using namespace winrt::Windows::Foundation;
-using namespace winrt::Windows::Foundation::Collections;
-using namespace winrt::Windows::Foundation::Metadata;
-using namespace winrt::Windows::Media::Core;
-using namespace winrt::Windows::Media::Playback;
-using namespace winrt::Windows::Media::SpeechSynthesis;
-using namespace winrt::Windows::Storage::Streams;
+#include "winrt_utils.h"
struct TTSUtterance;
+class GodotMediaEndedEventHandler;
+class GodotMediaFailedEventHandler;
+class GodotMediaMarkerReachedEventHandler;
+class GodotMediaCueEventHandler;
+
class TTSDriverOneCore : public TTSDriver {
+ friend class GodotMediaEndedEventHandler;
+ friend class GodotMediaFailedEventHandler;
+ friend class GodotMediaMarkerReachedEventHandler;
+ friend class GodotMediaCueEventHandler;
+
List<TTSUtterance> queue;
bool playing = false;
bool paused = false;
bool update_requested = false;
- int64_t id = -1;
- Char16String string;
- std::shared_ptr<MediaPlayer> media;
+ ComPtr<ROMediaPlayer> media;
struct TrackData {
- TimedMetadataTrack track;
- winrt::event_token token{};
+ ROEventToken token_c;
+ ComPtr<ROTypedEventHandler_TimedMetadataTrack_MediaCueEventArgs> handler_c;
+ ComPtr<ROTimedMetadataTrack> track;
};
Vector<TrackData> tracks;
- winrt::event_token token_s{};
- winrt::event_token token_f{};
- winrt::event_token token_e{};
+ ComPtr<ROTypedEventHandler_MediaPlayer_PlaybackMediaMarkerReachedEventArgs> handler_s;
+ ComPtr<ROTypedEventHandler_MediaPlayer_MediaPlayerFailedEventArgs> handler_f;
+ ComPtr<ROTypedEventHandler_MediaPlayer_IInspectable> handler_e;
+ ROEventToken token_s;
+ ROEventToken token_f;
+ ROEventToken token_e;
int64_t offset = 0;
+ int64_t id = -1;
+ Char16String string;
void _dispose_current(bool p_silent = false, bool p_canceled = false);
-
void _speech_cancel(int p_msg_id);
void _speech_end(int p_msg_id);
void _speech_index_mark(int p_msg_id, int p_index_mark);
diff --git a/platform/windows/tts_windows.cpp b/platform/windows/tts_windows.cpp
index c61133c13e1..5a8ab741623 100644
--- a/platform/windows/tts_windows.cpp
+++ b/platform/windows/tts_windows.cpp
@@ -30,11 +30,8 @@
#include "tts_windows.h"
-#include "tts_driver_sapi.h"
-
-#ifdef WINRT_ENABLED
#include "tts_driver_onecore.h"
-#endif
+#include "tts_driver_sapi.h"
TTS_Windows *TTS_Windows::singleton = nullptr;
@@ -94,7 +91,6 @@ void TTS_Windows::process_events() {
}
TTS_Windows::TTS_Windows() {
-#ifdef WINRT_ENABLED
// Try OneCore driver.
if (!driver) {
driver = memnew(TTSDriverOneCore);
@@ -103,7 +99,6 @@ TTS_Windows::TTS_Windows() {
driver = nullptr;
}
}
-#endif
// Try SAPI driver.
if (!driver) {
driver = memnew(TTSDriverSAPI);
diff --git a/platform/windows/winrt_defines.h b/platform/windows/winrt_defines.h
new file mode 100644
index 00000000000..67592126887
--- /dev/null
+++ b/platform/windows/winrt_defines.h
@@ -0,0 +1,635 @@
+/**************************************************************************/
+/* winrt_defines.h */
+/**************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/**************************************************************************/
+/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
+/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/**************************************************************************/
+
+#pragma once
+
+#include "core/object/ref_counted.h"
+#include "core/typedefs.h"
+
+#include <activation.h>
+#include <inspectable.h>
+#include <shlwapi.h>
+#include <winstring.h>
+#include <wrl/client.h>
+
+using namespace Microsoft::WRL;
+
+class HStringWrapper : public RefCounted {
+ HSTRING string = nullptr;
+
+public:
+ String get_string() const {
+ String ret;
+ if (!string) {
+ return ret;
+ }
+ uint32_t size = 0;
+ PCWSTR utf16 = WindowsGetStringRawBuffer(string, &size);
+ if (utf16 && size > 0) {
+ ret = String::utf16((const char16_t *)utf16, size);
+ }
+
+ return ret;
+ }
+
+ void set_string(const String &p_string) {
+ if (string) {
+ WindowsDeleteString(string);
+ string = nullptr;
+ }
+ Char16String cs = p_string.utf16();
+ HRESULT res = WindowsCreateString((PCNZWCH)cs.get_data(), cs.length(), &string);
+ if (FAILED(res)) {
+ string = nullptr;
+ ERR_PRINT(vformat("Failed to create HSTRING with error 0x%08ux.", (uint64_t)res));
+ }
+ }
+
+ HSTRING get_ptr() { return string; }
+ HSTRING *get_ptrw() { return &string; }
+
+ HStringWrapper() {}
+ HStringWrapper(const String p_string) { set_string(p_string); }
+
+ ~HStringWrapper() {
+ if (string) {
+ WindowsDeleteString(string);
+ string = nullptr;
+ }
+ }
+};
+
+// Common code for ROTypedEventHandler implementations.
+#define TYPED_EVENT_HANDLER_CLASS(m_this, m_iface) \
+ LONG ref_count = 1; \
+\
+public: \
+ HRESULT STDMETHODCALLTYPE QueryInterface(REFIID p_riid, void **p_ppv) { \
+ static const QITAB qit[] = { \
+ { &__uuidof(m_iface), static_cast<decltype(qit[0].dwOffset)>(OFFSETOFCLASS(m_iface, m_this)) }, \
+ { nullptr, 0 }, \
+ }; \
+ return QISearch(this, qit, p_riid, p_ppv); \
+ } \
+ ULONG STDMETHODCALLTYPE AddRef() { \
+ return InterlockedIncrement(&ref_count); \
+ } \
+ ULONG STDMETHODCALLTYPE Release() { \
+ long ref = InterlockedDecrement(&ref_count); \
+ if (!ref) { \
+ delete this; \
+ } \
+ return ref; \
+ } \
+ virtual ~m_this() {}
+
+struct ROEventToken {
+ int64_t value = 0;
+ operator bool() const {
+ return value != 0;
+ }
+ void reset() {
+ value = 0;
+ }
+};
+enum class ROAdvancedColorKind : int32_t {
+ StandardDynamicRange = 0,
+ WideColorGamut = 1,
+ HighDynamicRange = 2,
+};
+
+enum class ROAsyncStatus : int32_t {
+ Canceled = 2,
+ Completed = 1,
+ Error = 3,
+ Started = 0,
+};
+
+enum class ROCoreInputViewKind : int32_t {
+ Default = 0,
+ Keyboard = 1,
+ Handwriting = 2,
+ Emoji = 3,
+ Symbols = 4,
+ Clipboard = 5,
+ Dictation = 6,
+ Gamepad = 7,
+};
+
+enum class ROTimedMetadataKind : int32_t {
+ Caption = 0,
+ Chapter = 1,
+ Custom = 2,
+ Data = 3,
+ Description = 4,
+ Subtitle = 5,
+ ImageSubtitle = 6,
+ Speech = 7,
+};
+
+enum class RoTimedMetadataTrackPresentationMode : int32_t {
+ Disabled = 0,
+ Hidden = 1,
+ ApplicationPresented = 2,
+ PlatformPresented = 3,
+};
+
+GODOT_GCC_WARNING_PUSH
+GODOT_GCC_WARNING_IGNORE("-Wnon-virtual-dtor")
+GODOT_GCC_WARNING_IGNORE("-Wctor-dtor-privacy")
+GODOT_GCC_WARNING_IGNORE("-Wshadow")
+GODOT_GCC_WARNING_IGNORE("-Wstrict-aliasing")
+GODOT_CLANG_WARNING_PUSH
+GODOT_CLANG_WARNING_IGNORE("-Wnon-virtual-dtor")
+
+// clang-format off
+
+MIDL_INTERFACE("997439FE-F681-4A11-B416-C13A47E8BA36")
+ROApiInformationStatics : public IInspectable {
+public:
+ virtual HRESULT STDMETHODCALLTYPE IsTypePresent(void *, bool *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE IsMethodPresent(void *, void *, bool *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE IsMethodPresentWithArity(void *, void *, uint32_t, bool *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE IsEventPresent(void *, void *, bool *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE IsPropertyPresent(void *, void *, bool *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE IsReadOnlyPropertyPresent(void *, void *, bool *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE IsWriteablePropertyPresent(void *, void *, bool *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE IsEnumNamedValuePresent(void *, void *, bool *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE IsApiContractPresentByMajor(void *, uint16_t, bool *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE IsApiContractPresentByMajorAndMinor(void *, uint16_t, uint16_t, bool *) = 0;
+};
+
+MIDL_INTERFACE("7449121C-382B-4705-8DA7-A795BA482013")
+RODisplayInformationStaticsInterop : public IInspectable {
+public:
+ virtual HRESULT STDMETHODCALLTYPE GetForWindow(HWND, REFIID, void **) = 0;
+ virtual HRESULT STDMETHODCALLTYPE GetForMonitor(HMONITOR, REFIID, void **) = 0;
+};
+
+MIDL_INTERFACE("22F34E66-50DB-4E36-A98D-61C01B384D20")
+RODispatcherQueueController : public IInspectable {
+public:
+ virtual HRESULT STDMETHODCALLTYPE get_DispatcherQueue(void **) = 0;
+ virtual HRESULT STDMETHODCALLTYPE ShutdownQueueAsync(void **) = 0;
+};
+
+MIDL_INTERFACE("548CEFBD-BC8A-5FA0-8DF2-957440FC8BF4")
+ROReference_1_Int32 : public IInspectable {
+public:
+ virtual HRESULT STDMETHODCALLTYPE get_Value(int32_t *) = 0;
+};
+
+MIDL_INTERFACE("5A648006-843A-4DA9-865B-9D26E5DFAD7B")
+ROAsyncAction : public IInspectable {
+public:
+ virtual HRESULT STDMETHODCALLTYPE put_Completed(void *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_Completed(void **) = 0;
+ virtual HRESULT STDMETHODCALLTYPE GetResults() = 0;
+};
+
+MIDL_INTERFACE("00000036-0000-0000-C000-000000000046")
+ROAsyncInfo : public IInspectable {
+public:
+ virtual HRESULT STDMETHODCALLTYPE get_Id(uint32_t *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_Status(int32_t *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_ErrorCode(HRESULT *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE Cancel() = 0;
+ virtual HRESULT STDMETHODCALLTYPE Close() = 0;
+};
+
+MIDL_INTERFACE("9FC2B0BB-E446-44E2-AA61-9CAB8F636AF2")
+ROAsyncOperation : public IInspectable {
+public:
+ virtual HRESULT STDMETHODCALLTYPE put_Completed(void *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_Completed(void **) = 0;
+ virtual HRESULT STDMETHODCALLTYPE GetResults(void **) = 0;
+};
+
+MIDL_INTERFACE("3A5442DC-2CDE-4A8D-80D1-21DC5ADCC1AA")
+RODisplayInformation5 : public IInspectable {
+public:
+ virtual HRESULT STDMETHODCALLTYPE GetAdvancedColorInfo(void **) = 0;
+ virtual HRESULT STDMETHODCALLTYPE add_AdvancedColorInfoChanged(void *, ROEventToken *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE remove_AdvancedColorInfoChanged(ROEventToken) = 0;
+};
+
+MIDL_INTERFACE("8797DCFB-B229-4081-AE9A-2CC85E34AD6A")
+ROAdvancedColorInfo : public IInspectable {
+public:
+ virtual HRESULT STDMETHODCALLTYPE get_CurrentAdvancedColorKind(int32_t *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_RedPrimary(void *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_GreenPrimary(void *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_BluePrimary(void *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_WhitePoint(void *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_MaxLuminanceInNits(float *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_MinLuminanceInNits(float *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_MaxAverageFullFrameLuminanceInNits(float *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_SdrWhiteLevelInNits(float *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE IsHdrMetadataFormatCurrentlySupported(int32_t, bool *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE IsAdvancedColorKindAvailable(int32_t, bool *) = 0;
+};
+
+MIDL_INTERFACE("9DE1C534-6AE1-11E0-84E1-18A905BCC53F")
+ROTypedEventHandler : public IUnknown {
+public:
+ virtual HRESULT STDMETHODCALLTYPE Invoke(void *, IInspectable *) = 0;
+};
+
+MIDL_INTERFACE("2F13C006-A03A-5F69-B090-75A43E33423E")
+ROVectorView_HSTRING : public IInspectable {
+public:
+ virtual HRESULT STDMETHODCALLTYPE GetAt(uint32_t, HSTRING *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_Size(uint32_t *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE IndexOf(HSTRING, uint32_t *, BOOLEAN *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE GetMany(uint32_t, uint32_t, HSTRING *, uint32_t *) = 0;
+};
+
+MIDL_INTERFACE("A6487363-B074-5C60-AB16-866DCE4EE54D")
+ROVectorView_IInspectable : public IInspectable {
+public:
+ virtual HRESULT STDMETHODCALLTYPE GetAt(uint32_t, IInspectable **) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_Size(uint32_t *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE IndexOf(IInspectable *, uint32_t *, BOOLEAN *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE GetMany(uint32_t, uint32_t, IInspectable **, uint32_t *) = 0;
+};
+
+MIDL_INTERFACE("01BF4326-ED37-4E96-B0E9-C1340D1EA158")
+ROGlobalizationPreferencesStatics : public IInspectable {
+public:
+ virtual HRESULT STDMETHODCALLTYPE get_Calendars(void **) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_Clocks(void **) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_Currencies(void **) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_Languages(void **) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_HomeGeographicRegion(void **) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_WeekStartsOn(int32_t *) = 0;
+};
+
+MIDL_INTERFACE("7D9B97CD-EDBE-49CF-A54F-337DE052907F")
+ROCoreInputViewStatics : public IInspectable {
+public:
+ virtual HRESULT STDMETHODCALLTYPE GetForCurrentView(void **) = 0;
+};
+
+MIDL_INTERFACE("BC941653-3AB9-4849-8F58-46E7F0353CFC")
+ROCoreInputView3 : public IInspectable {
+public:
+ virtual HRESULT STDMETHODCALLTYPE TryShow(bool *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE TryShowWithKind(int32_t, bool *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE TryHide(bool *) = 0;
+};
+
+MIDL_INTERFACE("7D526ECC-7533-4C3F-85BE-888C2BAEEBDC")
+ROInstalledVoicesStatic : public IInspectable {
+public:
+ virtual HRESULT STDMETHODCALLTYPE get_AllVoices(void **) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_DefaultVoice(void **) = 0;
+};
+
+MIDL_INTERFACE("B127D6A4-1291-4604-AA9C-83134083352C")
+ROVoiceInformation : public IInspectable {
+public:
+ virtual HRESULT STDMETHODCALLTYPE get_DisplayName(void **) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_Id(void **) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_Language(void **) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_Description(void **) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_Gender(int32_t *) = 0;
+};
+
+MIDL_INTERFACE("CE9F7C76-97F4-4CED-AD68-D51C458E45C6")
+ROSpeechSynthesizer : public IInspectable {
+public:
+ virtual HRESULT STDMETHODCALLTYPE SynthesizeTextToStreamAsync(void *, void **) = 0;
+ virtual HRESULT STDMETHODCALLTYPE SynthesizeSsmlToStreamAsync(void *, void **) = 0;
+ virtual HRESULT STDMETHODCALLTYPE put_Voice(void *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_Voice(void **) = 0;
+};
+
+MIDL_INTERFACE("A7C5ECB2-4339-4D6A-BBF8-C7A4F1544C2E")
+ROSpeechSynthesizer2 : public IInspectable {
+public:
+ virtual HRESULT STDMETHODCALLTYPE get_Options(void **) = 0;
+};
+
+MIDL_INTERFACE("A0E23871-CC3D-43C9-91B1-EE185324D83D")
+ROSpeechSynthesizerOptions : public IInspectable {
+public:
+ virtual HRESULT STDMETHODCALLTYPE get_IncludeWordBoundaryMetadata(bool *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE put_IncludeWordBoundaryMetadata(bool) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_IncludeSentenceBoundaryMetadata(bool *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE put_IncludeSentenceBoundaryMetadata(bool) = 0;
+};
+
+MIDL_INTERFACE("1CBEF60E-119C-4BED-B118-D250C3A25793")
+ROSpeechSynthesizerOptions2 : public IInspectable {
+public:
+ virtual HRESULT STDMETHODCALLTYPE get_AudioVolume(double *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE put_AudioVolume(double) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_SpeakingRate(double *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE put_SpeakingRate(double) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_AudioPitch(double *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE put_AudioPitch(double) = 0;
+};
+
+MIDL_INTERFACE("905A0FE1-BC53-11DF-8C49-001E4FC686DA")
+RORandomAccessStream : public IInspectable {
+public:
+ virtual HRESULT STDMETHODCALLTYPE get_Size(uint64_t *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE put_Size(uint64_t) = 0;
+ virtual HRESULT STDMETHODCALLTYPE GetInputStreamAt(uint64_t, void **) = 0;
+ virtual HRESULT STDMETHODCALLTYPE GetOutputStreamAt(uint64_t, void **) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_Position(uint64_t *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE Seek(uint64_t) = 0;
+ virtual HRESULT STDMETHODCALLTYPE CloneStream(void **) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_CanRead(bool *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_CanWrite(bool *) = 0;
+};
+
+MIDL_INTERFACE("83E46E93-244C-4622-BA0B-6229C4D0D65D")
+ROSpeechSynthesisStream : public IInspectable {
+public:
+ virtual HRESULT STDMETHODCALLTYPE get_Markers(void **) = 0;
+};
+
+MIDL_INTERFACE("381A83CB-6FFF-499B-8D64-2885DFC1249E")
+ROMediaPlayer : public IInspectable {
+public:
+ virtual HRESULT STDMETHODCALLTYPE get_AutoPlay(bool *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE put_AutoPlay(bool) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_NaturalDuration(int64_t *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_Position(int64_t *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE put_Position(int64_t) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_BufferingProgress(double *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_CurrentState(int32_t *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_CanSeek(bool *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_CanPause(bool *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_IsLoopingEnabled(bool *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE put_IsLoopingEnabled(bool) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_IsProtected(bool *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_IsMuted(bool *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE put_IsMuted(bool) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_PlaybackRate(double *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE put_PlaybackRate(double) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_Volume(double *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE put_Volume(double) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_PlaybackMediaMarkers(void **) = 0;
+ virtual HRESULT STDMETHODCALLTYPE add_MediaOpened(void *, ROEventToken *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE remove_MediaOpened(ROEventToken) = 0;
+ virtual HRESULT STDMETHODCALLTYPE add_MediaEnded(void *, ROEventToken *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE remove_MediaEnded(ROEventToken) = 0;
+ virtual HRESULT STDMETHODCALLTYPE add_MediaFailed(void *, ROEventToken *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE remove_MediaFailed(ROEventToken) = 0;
+ virtual HRESULT STDMETHODCALLTYPE add_CurrentStateChanged(void *, ROEventToken *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE remove_CurrentStateChanged(ROEventToken) = 0;
+ virtual HRESULT STDMETHODCALLTYPE add_PlaybackMediaMarkerReached(void *, ROEventToken *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE remove_PlaybackMediaMarkerReached(ROEventToken) = 0;
+ virtual HRESULT STDMETHODCALLTYPE add_MediaPlayerRateChanged(void *, ROEventToken *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE remove_MediaPlayerRateChanged(ROEventToken) = 0;
+ virtual HRESULT STDMETHODCALLTYPE add_VolumeChanged(void *, ROEventToken *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE remove_VolumeChanged(ROEventToken) = 0;
+ virtual HRESULT STDMETHODCALLTYPE add_SeekCompleted(void *, ROEventToken *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE remove_SeekCompleted(ROEventToken) = 0;
+ virtual HRESULT STDMETHODCALLTYPE add_BufferingStarted(void *, ROEventToken *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE remove_BufferingStarted(ROEventToken) = 0;
+ virtual HRESULT STDMETHODCALLTYPE add_BufferingEnded(void *, ROEventToken *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE remove_BufferingEnded(ROEventToken) = 0;
+ virtual HRESULT STDMETHODCALLTYPE Play() = 0;
+ virtual HRESULT STDMETHODCALLTYPE Pause() = 0;
+ virtual HRESULT STDMETHODCALLTYPE SetUriSource(void *) = 0;
+};
+
+MIDL_INTERFACE("E7BFB599-A09D-4C21-BCDF-20AF4F86B3D9")
+ROMediaSource : public IInspectable {
+};
+
+MIDL_INTERFACE("82449B9F-7322-4C0B-B03B-3E69A48260C5")
+ROMediaPlayerSource2 : public IInspectable {
+ virtual HRESULT STDMETHODCALLTYPE get_Source(void **) = 0;
+ virtual HRESULT STDMETHODCALLTYPE put_Source(void *) = 0;
+};
+
+MIDL_INTERFACE("F77D6FA4-4652-410E-B1D8-E9A5E245A45C")
+ROMediaSourceStatics : public IInspectable {
+public:
+ virtual HRESULT STDMETHODCALLTYPE CreateFromAdaptiveMediaSource(void *, void **) = 0;
+ virtual HRESULT STDMETHODCALLTYPE CreateFromMediaStreamSource(void *, void **) = 0;
+ virtual HRESULT STDMETHODCALLTYPE CreateFromMseStreamSource(void *, void **) = 0;
+ virtual HRESULT STDMETHODCALLTYPE CreateFromIMediaSource(void *, void **) = 0;
+ virtual HRESULT STDMETHODCALLTYPE CreateFromStorageFile(void *, void **) = 0;
+ virtual HRESULT STDMETHODCALLTYPE CreateFromStream(void *, void *, void **) = 0;
+ virtual HRESULT STDMETHODCALLTYPE CreateFromStreamReference(void *, void *, void **) = 0;
+ virtual HRESULT STDMETHODCALLTYPE CreateFromUri(void *, void **) = 0;
+};
+
+MIDL_INTERFACE("047097D2-E4AF-48AB-B283-6929E674ECE2")
+ROMediaPlaybackItem : public IInspectable {
+public:
+ virtual HRESULT STDMETHODCALLTYPE add_AudioTracksChanged(void *, ROEventToken *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE remove_AudioTracksChanged(ROEventToken) = 0;
+ virtual HRESULT STDMETHODCALLTYPE add_VideoTracksChanged(void *, ROEventToken *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE remove_VideoTracksChanged(ROEventToken) = 0;
+ virtual HRESULT STDMETHODCALLTYPE add_TimedMetadataTracksChanged(void *, ROEventToken *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE remove_TimedMetadataTracksChanged(ROEventToken) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_Source(void **) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_AudioTracks(void **) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_VideoTracks(void **) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_TimedMetadataTracks(void **) = 0;
+};
+
+MIDL_INTERFACE("7133FCE1-1769-4FF9-A7C1-38D2C4D42360")
+ROMediaPlaybackItemFactory : public IInspectable {
+public:
+ virtual HRESULT STDMETHODCALLTYPE Create(void *, void **) = 0;
+};
+
+MIDL_INTERFACE("72B41319-BBFB-46A3-9372-9C9C744B9438")
+ROMediaPlaybackTimedMetadataTrackList : public IInspectable {
+public:
+ virtual HRESULT STDMETHODCALLTYPE add_PresentationModeChanged(void *, ROEventToken *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE remove_PresentationModeChanged(ROEventToken) = 0;
+ virtual HRESULT STDMETHODCALLTYPE GetPresentationMode(uint32_t, int32_t *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE SetPresentationMode(uint32_t, int32_t) = 0;
+};
+
+MIDL_INTERFACE("9E6AED9E-F67A-49A9-B330-CF03B0E9CF07")
+ROTimedMetadataTrack : public IInspectable {
+public:
+ virtual HRESULT STDMETHODCALLTYPE add_CueEntered(void *, ROEventToken *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE remove_CueEntered(ROEventToken) = 0;
+ virtual HRESULT STDMETHODCALLTYPE add_CueExited(void *, ROEventToken *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE remove_CueExited(ROEventToken) = 0;
+ virtual HRESULT STDMETHODCALLTYPE add_TrackFailed(void *, ROEventToken *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE remove_TrackFailed(ROEventToken) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_Cues(void **) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_ActiveCues(void **) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_TimedMetadataKind(int32_t *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_DispatchType(void **) = 0;
+ virtual HRESULT STDMETHODCALLTYPE AddCue(void *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE RemoveCue(void *) = 0;
+};
+
+MIDL_INTERFACE("0313AE7A-2803-5D45-B5A1-A0FC5CD55E7C")
+ROVectorView_TimedMetadataTrack : public IInspectable {
+public:
+ virtual HRESULT STDMETHODCALLTYPE GetAt(uint32_t, ROTimedMetadataTrack **) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_Size(uint32_t *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE IndexOf(ROTimedMetadataTrack *, uint32_t *, BOOLEAN *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE GetMany(uint32_t, uint32_t, ROTimedMetadataTrack **, uint32_t *) = 0;
+};
+
+MIDL_INTERFACE("578CD1B9-90E2-4E60-ABC4-8740B01F6196")
+ROPlaybackMediaMarkerReachedEventArgs : public IInspectable {
+public:
+ virtual HRESULT STDMETHODCALLTYPE get_PlaybackMediaMarker(void **) = 0;
+};
+
+MIDL_INTERFACE("C4D22F5C-3C1C-4444-B6B9-778B0422D41A")
+ROPlaybackMediaMarker : public IInspectable {
+public:
+ virtual HRESULT STDMETHODCALLTYPE get_Time(int64_t *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_MediaMarkerType(void **) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_Text(void **) = 0;
+};
+
+MIDL_INTERFACE("D12F47F7-5FA4-4E68-9FE5-32160DCEE57E")
+ROMediaCueEventArgs : public IInspectable {
+public:
+ virtual HRESULT STDMETHODCALLTYPE get_Cue(void **) = 0;
+};
+
+MIDL_INTERFACE("2744E9B9-A7E3-4F16-BAC4-7914EBC08301")
+ROMediaPlayerFailedEventArgs : public IInspectable {
+public:
+ virtual HRESULT STDMETHODCALLTYPE get_Error(int32_t *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_ExtendedErrorCode(HRESULT *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_ErrorMessage(void **) = 0;
+};
+
+MIDL_INTERFACE("362C45A7-3A0A-5E27-99CE-CFF6D1B770E1")
+ROTypedEventHandler_MediaPlayer_MediaPlayerFailedEventArgs : public IUnknown {
+public:
+ virtual HRESULT STDMETHODCALLTYPE Invoke(ROMediaPlayer *, ROMediaPlayerFailedEventArgs *) = 0;
+};
+
+MIDL_INTERFACE("F1A6A51E-D078-5C40-BA3F-348870BA5C87")
+ROTypedEventHandler_MediaPlayer_IInspectable : public IUnknown {
+public:
+ virtual HRESULT STDMETHODCALLTYPE Invoke(ROMediaPlayer *, IInspectable *) = 0;
+};
+
+MIDL_INTERFACE("67A4F43C-C254-57F0-A39D-A475A342D21D")
+ROTypedEventHandler_MediaPlayer_PlaybackMediaMarkerReachedEventArgs : public IUnknown {
+public:
+ virtual HRESULT STDMETHODCALLTYPE Invoke(ROMediaPlayer *, ROPlaybackMediaMarkerReachedEventArgs *) = 0;
+};
+
+MIDL_INTERFACE("4AAC9411-C355-5C95-8C78-5A0F5CA1A54D")
+ROTypedEventHandler_TimedMetadataTrack_MediaCueEventArgs : public IUnknown {
+public:
+ virtual HRESULT STDMETHODCALLTYPE Invoke(ROTimedMetadataTrack *, ROMediaCueEventArgs *) = 0;
+};
+
+MIDL_INTERFACE("C7D15E5D-59DC-431F-A0EE-27744323B36D")
+ROMediaCue : public IInspectable {
+public:
+ virtual HRESULT STDMETHODCALLTYPE put_StartTime(int64_t) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_StartTime(int64_t *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE put_Duration(int64_t) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_Duration(int64_t *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE put_Id(void *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_Id(void **) = 0;
+};
+
+MIDL_INTERFACE("AEE254DC-1725-4BAD-8043-A98499B017A2")
+ROSpeechCue : public IInspectable {
+public:
+ virtual HRESULT STDMETHODCALLTYPE get_Text(void **) = 0;
+ virtual HRESULT STDMETHODCALLTYPE put_Text(void *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_StartPositionInInput(void **) = 0;
+ virtual HRESULT STDMETHODCALLTYPE put_StartPositionInInput(void *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE get_EndPositionInInput(void **) = 0;
+ virtual HRESULT STDMETHODCALLTYPE put_EndPositionInInput(void *) = 0;
+};
+
+MIDL_INTERFACE("97D098A5-3B99-4DE9-88A5-E11D2F50C795")
+ROContentTypeProvider : public IInspectable {
+public:
+ virtual HRESULT STDMETHODCALLTYPE get_ContentType(void **) = 0;
+};
+
+// clang-format on
+
+#ifdef __CRT_UUID_DECL
+__CRT_UUID_DECL(ROApiInformationStatics, 0x997439FE, 0xF681, 0x4A11, 0xB4, 0x16, 0xC1, 0x3A, 0x47, 0xE8, 0xBA, 0x36)
+__CRT_UUID_DECL(RODisplayInformationStaticsInterop, 0x7449121C, 0x382B, 0x4705, 0x8D, 0xA7, 0xA7, 0x95, 0xBA, 0x48, 0x20, 0x13)
+__CRT_UUID_DECL(RODispatcherQueueController, 0x22F34E66, 0x50DB, 0x4E36, 0xA9, 0x8D, 0x61, 0xC0, 0x1B, 0x38, 0x4D, 0x20)
+__CRT_UUID_DECL(ROReference_1_Int32, 0x548CEFBD, 0xBC8A, 0x5FA0, 0x8D, 0xF2, 0x95, 0x74, 0x40, 0xFC, 0x8B, 0xF4)
+__CRT_UUID_DECL(ROAsyncOperation, 0x9FC2B0BB, 0xE446, 0x44E2, 0xAA, 0x61, 0x9C, 0xAB, 0x8F, 0x63, 0x6A, 0xF2)
+__CRT_UUID_DECL(ROAsyncAction, 0x5A648006, 0x843A, 0x4DA9, 0x86, 0x5B, 0x9D, 0x26, 0xE5, 0xDF, 0xAD, 0x7B)
+__CRT_UUID_DECL(ROAsyncInfo, 0x00000036, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46)
+__CRT_UUID_DECL(RODisplayInformation5, 0x3A5442DC, 0x2CDE, 0x4A8D, 0x80, 0xD1, 0x21, 0xDC, 0x5A, 0xDC, 0xC1, 0xAA)
+__CRT_UUID_DECL(ROAdvancedColorInfo, 0x8797DCFB, 0xB229, 0x4081, 0xAE, 0x9A, 0x2C, 0xC8, 0x5E, 0x34, 0xAD, 0x6A)
+__CRT_UUID_DECL(ROTypedEventHandler, 0x9DE1C534, 0x6AE1, 0x11E0, 0x84, 0xE1, 0x18, 0xA9, 0x05, 0xBC, 0xC5, 0x3F)
+__CRT_UUID_DECL(ROTypedEventHandler_MediaPlayer_MediaPlayerFailedEventArgs, 0x362C45A7, 0x3A0A, 0x5E27, 0x99, 0xCE, 0xCF, 0xF6, 0xD1, 0xB7, 0x70, 0xE1)
+__CRT_UUID_DECL(ROTypedEventHandler_MediaPlayer_IInspectable, 0xF1A6A51E, 0xD078, 0x5C40, 0xBA, 0x3F, 0x34, 0x88, 0x70, 0xBA, 0x5C, 0x87)
+__CRT_UUID_DECL(ROTypedEventHandler_MediaPlayer_PlaybackMediaMarkerReachedEventArgs, 0x67A4F43C, 0xC254, 0x57F0, 0xA3, 0x9D, 0xA4, 0x75, 0xA3, 0x42, 0xD2, 0x1D)
+__CRT_UUID_DECL(ROTypedEventHandler_TimedMetadataTrack_MediaCueEventArgs, 0x4AAC9411, 0xC355, 0x5C95, 0x8C, 0x78, 0x5A, 0x0F, 0x5C, 0xA1, 0xA5, 0x4D)
+__CRT_UUID_DECL(ROVectorView_HSTRING, 0x2F13C006, 0xA03A, 0x5F69, 0xB0, 0x90, 0x75, 0xA4, 0x3E, 0x33, 0x42, 0x3E)
+__CRT_UUID_DECL(ROVectorView_IInspectable, 0xA6487363, 0xB074, 0x5C60, 0xAB, 0x16, 0x86, 0x6D, 0xCE, 0x4E, 0xE5, 0x4D)
+__CRT_UUID_DECL(ROVectorView_TimedMetadataTrack, 0x0313AE7A, 0x2803, 0x5D45, 0xB5, 0xA1, 0xA0, 0xFC, 0x5C, 0xD5, 0x5E, 0x7C)
+__CRT_UUID_DECL(ROGlobalizationPreferencesStatics, 0x01BF4326, 0xED37, 0x4E96, 0xB0, 0xE9, 0xC1, 0x34, 0x0D, 0x1E, 0xA1, 0x58)
+__CRT_UUID_DECL(ROCoreInputViewStatics, 0x7D9B97CD, 0xEDBE, 0x49CF, 0xA5, 0x4F, 0x33, 0x7D, 0xE0, 0x52, 0x90, 0x7F)
+__CRT_UUID_DECL(ROCoreInputView3, 0xBC941653, 0x3AB9, 0x4849, 0x8F, 0x58, 0x46, 0xE7, 0xF0, 0x35, 0x3C, 0xFC)
+__CRT_UUID_DECL(ROInstalledVoicesStatic, 0x7D526ECC, 0x7533, 0x4C3F, 0x85, 0xBE, 0x88, 0x8C, 0x2B, 0xAE, 0xEB, 0xDC)
+__CRT_UUID_DECL(ROVoiceInformation, 0xB127D6A4, 0x1291, 0x4604, 0xAA, 0x9C, 0x83, 0x13, 0x40, 0x83, 0x35, 0x2C)
+__CRT_UUID_DECL(ROSpeechSynthesizer, 0xCE9F7C76, 0x97F4, 0x4CED, 0xAD, 0x68, 0xD5, 0x1C, 0x45, 0x8E, 0x45, 0xC6)
+__CRT_UUID_DECL(ROSpeechSynthesizer2, 0xA7C5ECB2, 0x4339, 0x4D6A, 0xBB, 0xF8, 0xC7, 0xA4, 0xF1, 0x54, 0x4C, 0x2E)
+__CRT_UUID_DECL(ROSpeechSynthesizerOptions, 0xA0E23871, 0xCC3D, 0x43C9, 0x91, 0xB1, 0xEE, 0x18, 0x53, 0x24, 0xD8, 0x3D)
+__CRT_UUID_DECL(ROSpeechSynthesizerOptions2, 0x1CBEF60E, 0x119C, 0x4BED, 0xB1, 0x18, 0xD2, 0x50, 0xC3, 0xA2, 0x57, 0x93)
+__CRT_UUID_DECL(ROSpeechSynthesisStream, 0x83E46E93, 0x244C, 0x4622, 0xBA, 0x0B, 0x62, 0x29, 0xC4, 0xD0, 0xD6, 0x5D)
+__CRT_UUID_DECL(RORandomAccessStream, 0x905A0FE1, 0xBC53, 0x11DF, 0x8C, 0x49, 0x00, 0x1E, 0x4F, 0xC6, 0x86, 0xDA)
+__CRT_UUID_DECL(ROMediaPlayer, 0x381A83CB, 0x6FFF, 0x499B, 0x8D, 0x64, 0x28, 0x85, 0xDF, 0xC1, 0x24, 0x9E)
+__CRT_UUID_DECL(ROMediaSource, 0xE7BFB599, 0xA09D, 0x4C21, 0xBC, 0xDF, 0x20, 0xAF, 0x4F, 0x86, 0xB3, 0xD9)
+__CRT_UUID_DECL(ROMediaPlayerSource2, 0x82449B9F, 0x7322, 0x4C0B, 0xB0, 0x3B, 0x3E, 0x69, 0xA4, 0x82, 0x60, 0xC5)
+__CRT_UUID_DECL(ROMediaSourceStatics, 0xF77D6FA4, 0x4652, 0x410E, 0xB1, 0xD8, 0xE9, 0xA5, 0xE2, 0x45, 0xA4, 0x5C)
+__CRT_UUID_DECL(ROMediaPlaybackItem, 0x047097D2, 0xE4AF, 0x48AB, 0xB2, 0x83, 0x69, 0x29, 0xE6, 0x74, 0xEC, 0xE2)
+__CRT_UUID_DECL(ROMediaPlaybackItemFactory, 0x7133FCE1, 0x1769, 0x4FF9, 0xA7, 0xC1, 0x38, 0xD2, 0xC4, 0xD4, 0x23, 0x60)
+__CRT_UUID_DECL(ROMediaPlaybackTimedMetadataTrackList, 0x72B41319, 0xBBFB, 0x46A3, 0x93, 0x72, 0x9C, 0x9C, 0x74, 0x4B, 0x94, 0x38)
+__CRT_UUID_DECL(ROTimedMetadataTrack, 0x9E6AED9E, 0xF67A, 0x49A9, 0xB3, 0x30, 0xCF, 0x03, 0xB0, 0xE9, 0xCF, 0x07)
+__CRT_UUID_DECL(ROPlaybackMediaMarkerReachedEventArgs, 0x578CD1B9, 0x90E2, 0x4E60, 0xAB, 0xC4, 0x87, 0x40, 0xB0, 0x1F, 0x61, 0x96)
+__CRT_UUID_DECL(ROPlaybackMediaMarker, 0xC4D22F5C, 0x3C1C, 0x4444, 0xB6, 0xB9, 0x77, 0x8B, 0x04, 0x22, 0xD4, 0x1A)
+__CRT_UUID_DECL(ROMediaCueEventArgs, 0xD12F47F7, 0x5FA4, 0x4E68, 0x9F, 0xE5, 0x32, 0x16, 0x0D, 0xCE, 0xE5, 0x7E)
+__CRT_UUID_DECL(ROMediaCue, 0xC7D15E5D, 0x59DC, 0x431F, 0xA0, 0xEE, 0x27, 0x74, 0x43, 0x23, 0xB3, 0x6D)
+__CRT_UUID_DECL(ROSpeechCue, 0xAEE254DC, 0x1725, 0x4BAD, 0x80, 0x43, 0xA9, 0x84, 0x99, 0xB0, 0x17, 0xA2)
+__CRT_UUID_DECL(ROMediaPlayerFailedEventArgs, 0x2744E9B9, 0xA7E3, 0x4F16, 0xBA, 0xC4, 0x79, 0x14, 0xEB, 0xC0, 0x83, 0x01)
+__CRT_UUID_DECL(ROContentTypeProvider, 0x97D098A5, 0x3B99, 0x4DE9, 0x88, 0xA5, 0xE1, 0x1D, 0x2F, 0x50, 0xC7, 0x95)
+#endif // __CRT_UUID_DECL
+
+GODOT_GCC_WARNING_POP
+GODOT_CLANG_WARNING_POP
diff --git a/platform/windows/winrt_utils.cpp b/platform/windows/winrt_utils.cpp
index b2a7a54864b..4ccce17c09d 100644
--- a/platform/windows/winrt_utils.cpp
+++ b/platform/windows/winrt_utils.cpp
@@ -30,27 +30,6 @@
#include "winrt_utils.h"
-#include "core/typedefs.h"
-
-#ifdef WINRT_ENABLED
-
-GODOT_GCC_WARNING_PUSH
-GODOT_GCC_WARNING_IGNORE("-Wnon-virtual-dtor")
-GODOT_GCC_WARNING_IGNORE("-Wctor-dtor-privacy")
-GODOT_GCC_WARNING_IGNORE("-Wshadow")
-GODOT_GCC_WARNING_IGNORE("-Wstrict-aliasing")
-GODOT_CLANG_WARNING_PUSH
-GODOT_CLANG_WARNING_IGNORE("-Wnon-virtual-dtor")
-
-#include <inspectable.h>
-#include <winrt/Windows.Foundation.Collections.h>
-#include <winrt/Windows.Foundation.Metadata.h>
-#include <winrt/Windows.Graphics.Display.h>
-#include <winrt/Windows.System.UserProfile.h>
-#include <winrt/Windows.System.h>
-#include <winrt/Windows.UI.Input.h>
-#include <winrt/Windows.UI.ViewManagement.Core.h>
-
enum DISPATCHERQUEUE_THREAD_APARTMENTTYPE {
DQTAT_COM_NONE = 0,
DQTAT_COM_ASTA = 1,
@@ -69,112 +48,249 @@ struct DispatcherQueueOptions {
};
typedef HRESULT(WINAPI *CreateDispatcherQueueControllerPtr)(DispatcherQueueOptions options, void *dispatcherQueueController);
-CreateDispatcherQueueControllerPtr CreateDispatcherQueueController;
+CreateDispatcherQueueControllerPtr GD_CreateDispatcherQueueController;
-#ifndef E_BOUNDS
-#define E_BOUNDS _HRESULT_TYPEDEF_(0x8000000B)
-#endif // E_BOUNDS
+typedef HRESULT(WINAPI *RoGetActivationFactoryPtr)(void *classId, REFIID iid, void **factory);
+RoGetActivationFactoryPtr GD_RoGetActivationFactory;
-#if defined __MINGW32__ || defined __MINGW64__
+typedef HRESULT(WINAPI *CoIncrementMTAUsagePtr)(void **pCookie);
+CoIncrementMTAUsagePtr GD_CoIncrementMTAUsage;
-#ifndef __IDisplayInformationStaticsInterop_INTERFACE_DEFINED__
-#define __IDisplayInformationStaticsInterop_INTERFACE_DEFINED__
+typedef HRESULT(WINAPI *CoDecrementMTAUsagePtr)(void *pCookie);
+CoDecrementMTAUsagePtr GD_CoDecrementMTAUsage;
-// clang-format off
-MIDL_INTERFACE("7449121c-382b-4705-8da7-a795ba482013")
-IDisplayInformationStaticsInterop : public IInspectable {
-public:
- virtual HRESULT STDMETHODCALLTYPE GetForWindow(
- HWND window,
- REFIID riid,
- void **displayInfo) = 0;
-
- virtual HRESULT STDMETHODCALLTYPE GetForMonitor(
- HMONITOR monitor,
- REFIID riid,
- void **displayInfo) = 0;
-};
-// clang-format on
-#ifdef __CRT_UUID_DECL
-__CRT_UUID_DECL(IDisplayInformationStaticsInterop, 0x7449121c, 0x382b, 0x4705, 0x8d, 0xa7, 0xa7, 0x95, 0xba, 0x48, 0x20, 0x13)
-#endif // __CRT_UUID_DECL
+static const WCHAR *RODisplayInformationName = L"Windows.Graphics.Display.DisplayInformation";
+static const WCHAR *ROGlobalizationPreferencesStaticsName = L"Windows.System.UserProfile.GlobalizationPreferences";
+static const WCHAR *ROCoreInputViewName = L"Windows.UI.ViewManagement.Core.CoreInputView";
+static const WCHAR *ROApiInformationName = L"Windows.Foundation.Metadata.ApiInformation";
+
+GODOT_GCC_WARNING_PUSH
+GODOT_GCC_WARNING_IGNORE("-Wnon-virtual-dtor")
+GODOT_GCC_WARNING_IGNORE("-Wctor-dtor-privacy")
+GODOT_GCC_WARNING_IGNORE("-Wshadow")
+GODOT_GCC_WARNING_IGNORE("-Wstrict-aliasing")
+GODOT_CLANG_WARNING_PUSH
+GODOT_CLANG_WARNING_IGNORE("-Wnon-virtual-dtor")
-#endif // __IDisplayInformationStaticsInterop_INTERFACE_DEFINED__
+/**************************************************************************/
+/* DisplayInformation5 events */
+/**************************************************************************/
-#else // defined __MINGW32__ || defined __MINGW64__
+class GodotAdvancedColorInfoChangedEventHandler : public ROTypedEventHandler {
+ TYPED_EVENT_HANDLER_CLASS(GodotAdvancedColorInfoChangedEventHandler, ROTypedEventHandler)
-#include <windows.graphics.display.interop.h>
+private:
+ int64_t id = 0;
+ Callable cb;
-#endif // defined __MINGW32__ || defined __MINGW64__
+public:
+ HRESULT STDMETHODCALLTYPE Invoke(void *p_sender, IInspectable *p_args) {
+ cb.call_deferred(id);
+ return S_OK;
+ }
+
+ GodotAdvancedColorInfoChangedEventHandler(int64_t p_id, const Callable &p_cb) {
+ id = p_id;
+ cb = p_cb;
+ }
+};
GODOT_GCC_WARNING_POP
GODOT_CLANG_WARNING_POP
-using namespace winrt::Windows::Graphics::Display;
-using namespace winrt::Windows::System;
-using namespace winrt::Windows::System::UserProfile;
-using namespace winrt::Windows::Foundation;
-using namespace winrt::Windows::Foundation::Collections;
-using namespace winrt::Windows::Foundation::Metadata;
-using namespace winrt::Windows::UI::ViewManagement::Core;
+/**************************************************************************/
+/* WinRTUtils */
+/**************************************************************************/
+
+ComPtr<RODispatcherQueueController> queue_ctrl;
+void *mta_cookie = nullptr;
+bool api_initialized = false;
+
+bool WinRTUtils::is_api_contract_present(const String &p_contract, uint16_t p_version) {
+ ComPtr<ROApiInformationStatics> api_info;
+ HRESULT res = activation_factory(ROApiInformationName, IID_PPV_ARGS(&api_info));
+ if (FAILED(res)) {
+ return false;
+ }
+ Ref<HStringWrapper> name;
+ name.instantiate();
+ name->set_string(p_contract);
+
+ bool ret = false;
+ ERR_FAIL_COND_V(FAILED(api_info->IsApiContractPresentByMajor(name->get_ptr(), p_version, &ret)), false);
+ return ret;
+}
-DispatcherQueueController controller{ nullptr };
+bool WinRTUtils::is_type_present(const String &p_type) {
+ ComPtr<ROApiInformationStatics> api_info;
+ HRESULT res = activation_factory(ROApiInformationName, IID_PPV_ARGS(&api_info));
+ if (FAILED(res)) {
+ return false;
+ }
+ Ref<HStringWrapper> name;
+ name.instantiate();
+ name->set_string(p_type);
+
+ bool ret = false;
+ ERR_FAIL_COND_V(FAILED(api_info->IsTypePresent(name->get_ptr(), &ret)), false);
+ return ret;
+}
+
+HRESULT WinRTUtils::activation_factory(const String &p_class_name, REFIID p_iid, void **p_factory) {
+ Ref<HStringWrapper> name;
+ name.instantiate();
+ name->set_string(p_class_name);
+
+ HRESULT res = GD_RoGetActivationFactory(name->get_ptr(), p_iid, p_factory);
+ if (res == (HRESULT)0x800401F0 && !mta_cookie) {
+ ERR_FAIL_COND_V(FAILED(GD_CoIncrementMTAUsage(&mta_cookie)), E_ABORT);
+ res = GD_RoGetActivationFactory(name->get_ptr(), p_iid, p_factory);
+ }
+ if (res == (HRESULT)0x80004001 || res == (HRESULT)0x80004002) {
+ print_verbose(vformat("RoGetActivationFactory(%s) not supported.", p_class_name));
+ return res;
+ }
+ ERR_FAIL_COND_V_MSG(FAILED(res), res, vformat("RoGetActivationFactory(%s) failed with error 0x%08ux.", p_class_name, (uint64_t)res));
+
+ return res;
+}
class WinRTWindowData {
friend class WinRTUtils;
- int64_t id = 0;
bool has_disp_info = false;
- DisplayInformation disp_info{ nullptr };
- Callable cb;
- winrt::event_token token{};
+ ComPtr<RODisplayInformation5> disp_info;
+ ComPtr<ROTypedEventHandler> handler;
+ ROEventToken token;
};
+bool WinRTUtils::is_initialized() {
+ return api_initialized;
+}
+
+void WinRTUtils::init() {
+ HMODULE combase = LoadLibraryW(L"combase.dll");
+ if (!combase) {
+ return;
+ }
+ GD_RoGetActivationFactory = (RoGetActivationFactoryPtr)(void *)GetProcAddress(combase, "RoGetActivationFactory");
+ if (!GD_RoGetActivationFactory) {
+ return;
+ }
+ GD_CoIncrementMTAUsage = (CoIncrementMTAUsagePtr)(void *)GetProcAddress(combase, "CoIncrementMTAUsage");
+ if (!GD_CoIncrementMTAUsage) {
+ return;
+ }
+ GD_CoDecrementMTAUsage = (CoDecrementMTAUsagePtr)(void *)GetProcAddress(combase, "CoDecrementMTAUsage");
+ if (!GD_CoDecrementMTAUsage) {
+ return;
+ }
+ api_initialized = true;
+}
+
bool WinRTUtils::create_queue() {
+ ERR_FAIL_COND_V(!api_initialized, false);
+
HMODULE coremessaging = LoadLibraryW(L"coremessaging.dll");
if (!coremessaging) {
return false;
}
- CreateDispatcherQueueController = (CreateDispatcherQueueControllerPtr)(void *)GetProcAddress(coremessaging, "CreateDispatcherQueueController");
- if (!CreateDispatcherQueueController) {
+ GD_CreateDispatcherQueueController = (CreateDispatcherQueueControllerPtr)(void *)GetProcAddress(coremessaging, "CreateDispatcherQueueController");
+ if (!GD_CreateDispatcherQueueController) {
return false;
}
DispatcherQueueOptions options{ sizeof(options), DQTYPE_THREAD_CURRENT, DQTAT_COM_NONE };
- HRESULT res = CreateDispatcherQueueController(options, winrt::put_abi(controller));
- return SUCCEEDED(res);
+ HRESULT res = GD_CreateDispatcherQueueController(options, queue_ctrl.GetAddressOf());
+ ERR_FAIL_COND_V_MSG(FAILED(res), false, "CreateDispatcherQueueController failed with error " + vformat("0x%08ux", (uint64_t)res) + ".");
+
+ return true;
}
void WinRTUtils::destroy_queue() {
- IAsyncAction action = controller.ShutdownQueueAsync();
- while (action.Status() == AsyncStatus::Started) {
+ ERR_FAIL_COND(!api_initialized);
+
+ ComPtr<ROAsyncAction> action;
+ ERR_FAIL_COND(FAILED(queue_ctrl->ShutdownQueueAsync((void **)action.GetAddressOf())));
+
+ ComPtr<ROAsyncInfo> info;
+ ERR_FAIL_COND(FAILED(action.As(&info)));
+
+ ROAsyncStatus status = ROAsyncStatus::Started;
+ while (status == ROAsyncStatus::Started) {
+ info->get_Status((int32_t *)&status);
MSG msg = {};
while (PeekMessageW(&msg, nullptr, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
}
- ERR_FAIL_COND_MSG(action.Status() == AsyncStatus::Error, "DispatcherQueueController shutdown failed.");
+ ERR_FAIL_COND_MSG(status == ROAsyncStatus::Error, "DispatcherQueueController shutdown failed.");
+}
+
+void WinRTUtils::cleanup() {
+ if (mta_cookie) {
+ GD_CoDecrementMTAUsage(mta_cookie);
+ mta_cookie = nullptr;
+ }
}
Vector<String> WinRTUtils::get_preferred_locales() {
Vector<String> out;
- IVectorView<winrt::hstring> languages = GlobalizationPreferences::Languages();
- for (uint32_t i = 0; i < languages.Size(); i++) {
- winrt::hstring lang = languages.GetAt(i);
- out.push_back(String::utf16((const char16_t *)lang.c_str(), lang.size()).replace_char('-', '_'));
+ ERR_FAIL_COND_V(!api_initialized, out);
+
+ ComPtr<ROGlobalizationPreferencesStatics> glob_prefs;
+ if (FAILED(activation_factory(ROGlobalizationPreferencesStaticsName, IID_PPV_ARGS(&glob_prefs)))) {
+ return out;
+ }
+
+ ComPtr<ROVectorView_HSTRING> languages;
+ HRESULT res = glob_prefs->get_Languages((void **)languages.GetAddressOf());
+ ERR_FAIL_COND_V_MSG(FAILED(res), out, "GlobalizationPreferencesStatics::get_Languages failed with error " + vformat("0x%08ux", (uint64_t)res) + ".");
+
+ uint32_t size = 0;
+ res = languages->get_Size(&size);
+ ERR_FAIL_COND_V_MSG(FAILED(res), out, "VectorView<HSTRING>::get_Size failed with error " + vformat("0x%08ux", (uint64_t)res) + ".");
+
+ for (uint32_t i = 0; i < size; i++) {
+ Ref<HStringWrapper> lang;
+ lang.instantiate();
+ ERR_CONTINUE(FAILED(languages->GetAt(i, lang->get_ptrw())));
+
+ String lang_str = lang->get_string();
+ if (!lang_str.is_empty()) {
+ out.push_back(lang_str.replace_char('-', '_'));
+ }
}
+
return out;
}
bool WinRTUtils::try_show_onecore_emoji_picker() {
- if (ApiInformation::IsApiContractPresent(L"Windows.Foundation.UniversalApiContract", 7)) { // Windows 10, 1809+
- return CoreInputView::GetForCurrentView().TryShow(CoreInputViewKind::Emoji);
+ ERR_FAIL_COND_V(!api_initialized, false);
+
+ if (!WinRTUtils::is_api_contract_present(L"Windows.Foundation.UniversalApiContract", 7)) {
+ return false;
}
- return false;
+
+ ComPtr<ROCoreInputViewStatics> core_view;
+ if (FAILED(activation_factory(ROCoreInputViewName, IID_PPV_ARGS(&core_view)))) {
+ return false;
+ }
+
+ ComPtr<IInspectable> core_input_view_ii;
+ ComPtr<ROCoreInputView3> core_input_view;
+ ERR_FAIL_COND_V(FAILED(core_view->GetForCurrentView((void **)core_input_view_ii.GetAddressOf())), false);
+ ERR_FAIL_COND_V(FAILED(core_input_view_ii.As(&core_input_view)), false);
+
+ bool status = false;
+ ERR_FAIL_COND_V(FAILED(core_input_view->TryShowWithKind((int32_t)ROCoreInputViewKind::Emoji, &status)), false);
+ return status;
}
bool WinRTUtils::window_has_display_info(const WinRTWindowData *p_data) {
+ ERR_FAIL_COND_V(!api_initialized, false);
+
if (p_data) {
return p_data->has_disp_info;
} else {
@@ -183,77 +299,51 @@ bool WinRTUtils::window_has_display_info(const WinRTWindowData *p_data) {
}
void WinRTUtils::window_get_advanced_color_info(const WinRTWindowData *p_data, bool &r_hdr_supported, float &r_min_luminance, float &r_max_luminance, float &r_max_average_luminance, float &r_sdr_white_level) {
+ ERR_FAIL_COND(!api_initialized);
+
if (p_data && p_data->has_disp_info) {
- AdvancedColorInfo adv_info = p_data->disp_info.GetAdvancedColorInfo();
+ ComPtr<ROAdvancedColorInfo> adv_info;
- r_hdr_supported = (adv_info.CurrentAdvancedColorKind() == AdvancedColorKind::HighDynamicRange);
- r_min_luminance = adv_info.MinLuminanceInNits();
- r_max_luminance = adv_info.MaxLuminanceInNits();
- r_max_average_luminance = adv_info.MaxAverageFullFrameLuminanceInNits();
- r_sdr_white_level = adv_info.SdrWhiteLevelInNits();
+ ERR_FAIL_COND(FAILED(p_data->disp_info->GetAdvancedColorInfo((void **)adv_info.GetAddressOf())));
+
+ ROAdvancedColorKind color_type = ROAdvancedColorKind::StandardDynamicRange;
+ ERR_FAIL_COND(FAILED(adv_info->get_CurrentAdvancedColorKind((int32_t *)&color_type)));
+ r_hdr_supported = (color_type == ROAdvancedColorKind::HighDynamicRange);
+
+ ERR_FAIL_COND(FAILED(adv_info->get_MinLuminanceInNits(&r_min_luminance)));
+ ERR_FAIL_COND(FAILED(adv_info->get_MaxLuminanceInNits(&r_max_luminance)));
+ ERR_FAIL_COND(FAILED(adv_info->get_MaxAverageFullFrameLuminanceInNits(&r_max_average_luminance)));
+ ERR_FAIL_COND(FAILED(adv_info->get_SdrWhiteLevelInNits(&r_sdr_white_level)));
}
}
WinRTWindowData *WinRTUtils::create_wd(HWND p_window, const Callable &p_color_cb, int64_t p_window_id) {
WinRTWindowData *wd = memnew(WinRTWindowData);
- wd->id = p_window_id;
- wd->cb = p_color_cb;
- if (ApiInformation::IsApiContractPresent(L"Windows.Foundation.UniversalApiContract", 6)) {
- try {
- HRESULT res = winrt::get_activation_factory<DisplayInformation, IDisplayInformationStaticsInterop>()->GetForWindow(p_window, winrt::guid_of<DisplayInformation>(), winrt::put_abi(wd->disp_info));
- if (res == S_OK && wd->disp_info) {
- wd->has_disp_info = true;
- wd->token = wd->disp_info.AdvancedColorInfoChanged([wd](const DisplayInformation &p_sender, auto &&) {
- wd->cb.call_deferred(wd->id);
- });
- }
- } catch (...) {
- memdelete(wd);
- return nullptr;
+ ERR_FAIL_COND_V(!api_initialized, wd);
+ if (WinRTUtils::is_api_contract_present(L"Windows.Foundation.UniversalApiContract", 6)) {
+ ComPtr<RODisplayInformationStaticsInterop> interop;
+ if (FAILED(activation_factory(RODisplayInformationName, IID_PPV_ARGS(&interop)))) {
+ return wd;
}
- }
+ ERR_FAIL_COND_V(FAILED(interop->GetForWindow(p_window, IID_PPV_ARGS(&wd->disp_info))), wd);
+
+ GodotAdvancedColorInfoChangedEventHandler *handler = new GodotAdvancedColorInfoChangedEventHandler(p_window_id, p_color_cb);
+ ERR_FAIL_COND_V(FAILED(handler->QueryInterface(IID_PPV_ARGS(&wd->handler))), wd);
+ ERR_FAIL_COND_V(FAILED(wd->disp_info->add_AdvancedColorInfoChanged(wd->handler.Get(), &wd->token)), wd);
+
+ wd->has_disp_info = true;
+ }
return wd;
}
void WinRTUtils::destroy_wd(WinRTWindowData *p_data) {
+ ERR_FAIL_COND(!api_initialized);
if (p_data) {
if (p_data->token) {
- p_data->disp_info.AdvancedColorInfoChanged(p_data->token);
+ p_data->disp_info->remove_AdvancedColorInfoChanged(p_data->token);
}
- p_data->disp_info = nullptr;
-
memdelete(p_data);
}
}
-
-#else
-
-bool WinRTUtils::try_show_onecore_emoji_picker() {
- return false;
-}
-
-bool WinRTUtils::create_queue() {
- return false;
-}
-
-void WinRTUtils::destroy_queue() {}
-
-Vector<String> WinRTUtils::get_preferred_locales() {
- return Vector<String>();
-}
-
-bool WinRTUtils::window_has_display_info(const WinRTWindowData *p_data) {
- return false;
-}
-
-void WinRTUtils::window_get_advanced_color_info(const WinRTWindowData *p_data, bool &r_hdr_supported, float &r_min_luminance, float &r_max_luminance, float &r_max_average_luminance, float &r_sdr_white_level) {}
-
-WinRTWindowData *WinRTUtils::create_wd(HWND p_window, const Callable &p_color_cb, int64_t p_window_id) {
- return nullptr;
-}
-
-void WinRTUtils::destroy_wd(WinRTWindowData *p_data) {}
-
-#endif
diff --git a/platform/windows/winrt_utils.h b/platform/windows/winrt_utils.h
index 611b0c55548..6d08f5d0e76 100644
--- a/platform/windows/winrt_utils.h
+++ b/platform/windows/winrt_utils.h
@@ -30,6 +30,8 @@
#pragma once
+#include "winrt_defines.h"
+
#include "core/typedefs.h"
#include "core/variant/callable.h"
#include "core/variant/variant.h"
@@ -40,11 +42,18 @@ class WinRTWindowData;
class WinRTUtils {
public:
- static bool try_show_onecore_emoji_picker();
+ static bool is_api_contract_present(const String &p_contract, uint16_t p_version);
+ static bool is_type_present(const String &p_type);
+ static HRESULT activation_factory(const String &p_class_name, REFIID p_iid, void **p_factory);
+ static bool is_initialized();
+
+ static void init();
static bool create_queue();
static void destroy_queue();
+ static void cleanup();
+ static bool try_show_onecore_emoji_picker();
static Vector<String> get_preferred_locales();
static WinRTWindowData *create_wd(HWND p_window, const Callable &p_color_cb, int64_t p_window_id);