diff --git a/docs/runtime_imports.md b/docs/runtime_imports.md index 0d82077815..3abcbe03df 100644 --- a/docs/runtime_imports.md +++ b/docs/runtime_imports.md @@ -494,10 +494,10 @@ layout with the documented argument count, and each behaves as Microsoft's refer | Class | Interface asked for | Slots (args after `this`) | Offline behaviour | |---|---|---|---| -| `XGameRuntimeFeatureImpl` | its class id | 3 `XGameRuntimeIsFeatureAvailable` (1, returns `bool`) | True when `QueryApiImpl` serves the class the feature's functions go through (whichever `xgameruntime*.cpp` serves it) and the feature is documented for Windows: today XAccessibility, XSpeechSynthesizer, XLauncher, XAsync, XAsyncProvider, XTaskQueue, XThread, XError, XGame, XGameSave, XGameUI, XNetworking, XPackage, XPersistentLocalStorage, XStore, XSystem, XUser, XGameEvent, XGameStreaming. False for XDisplay (served, but documented for the consoles only), for the classes not served (XAppCapture, XGameInvite) and for values past the enum | +| `XGameRuntimeFeatureImpl` | its class id | 3 `XGameRuntimeIsFeatureAvailable` (1, returns `bool`) | True when `QueryApiImpl` serves the class the feature's functions go through (whichever `xgameruntime*.cpp` serves it) and the feature is documented for Windows: today XAccessibility, XSpeechSynthesizer, XAppCapture, XLauncher, XAsync, XAsyncProvider, XTaskQueue, XThread, XError, XGame, XGameSave, XGameUI, XNetworking, XPackage, XPersistentLocalStorage, XStore, XSystem, XUser, XGameEvent, XGameStreaming. False for XDisplay (served, but documented for the consoles only), for the classes not served (XGameInvite) and for values past the enum. For XAppCapture, "served" means the class id and the v1-v4 interface ids answer `QueryApiImpl` while every method of the offline object returns `E_NOTIMPL` - the feature is reported available, capture itself is not | | `XSystemAnalyticsImpl` | its class id | 3 `XSystemGetAnalyticsInfo` (1: the result's address, as MSVC passes a returned struct to a member function) | The named export's `XSystemAnalyticsInfo` | -Not served yet, though `libHttpClient.GDK.dll` has thunks for them: `XAppCaptureImpl` and `XGameInviteImpl`, +Not served yet, though `libHttpClient.GDK.dll` has thunks for them: `XGameInviteImpl`, among others. Which classes the package's GDK modules reference, from a byte search for the class and interface GUIDs that @@ -530,7 +530,7 @@ therefore needs no module name beyond the `xgameruntime.dll` it already has, whi | Class | Thunks | Referenced | Served | |---|---:|---:|---| | `XAccessibilityImpl` | 10 | 9 | no | -| `XAppCaptureImpl` | 1 | 1 | no | +| `XAppCaptureImpl` | 1 | 1 | yes | | `XLauncherImpl` | 3 | 3 | no | | `XDisplayImpl` | 1 | 1 | yes | | `XGameEventImpl` | 1 | 1 | yes | @@ -547,10 +547,14 @@ therefore needs no module name beyond the `xgameruntime.dll` it already has, whi | `XThreadingImpl` | 18 | 17 | yes | | `XUserImpl` | 21 | 21 | yes | -"Served" is the tool's answer for the runtime sources at that commit. The three that are not: `XAccessibilityImpl` -(the speech-synthesizer slots 8-13, 15, 16 and 21 are referenced; slot 14 is not), `XAppCaptureImpl` (slot 5, -`XAppCaptureTakeScreenshot`) and `XLauncherImpl` (slots 3-5: `XLaunchUri` and the two display timeout-deferral calls). -Open pull requests serve them: #4235, #4307 and #4248. The slots of `XUserImpl`, `XStoreImpl` and `XGameSaveImpl` the +"Served" is the tool's answer for the runtime sources at that commit. `XAppCaptureImpl` (class +`a4f1aee2-4bf1-4485-b008-a7c26d52ac27`) is served by this change: `g_app_capture` in `runtime/shims/xgameruntime.cpp` +answers its class and interface ids in `QueryApiImpl`, and its 18-slot `IXAppCaptureImpl` through +`IXAppCaptureImpl4` vtable is present in full, every slot answering `E_NOTIMPL` offline. `XAccessibilityImpl` and +`XLauncherImpl` are served in `runtime/shims/xgameruntime_offline.cpp`, landed on main by the merged pull request +#401 (RT-GDK-SPEECH-DISPLAY-LIFECYCLE, commit `05318a387`) - the table's `no` for the two is the measurement at +`main` `1cc6e3c1`, before that merge. `XAppCaptureImpl` was the last of the executable's referenced thunks that no +shim served: with it, all 158 referenced thunks are covered. The slots of `XUserImpl`, `XStoreImpl` and `XGameSaveImpl` the executable calls, and the argument counts the tool estimates from the registers, are in the report the tool writes. `XErrorImpl`, which `XCurl.dll` and `libHttpClient.GDK.dll` call, is not among the executable's classes. diff --git a/runtime/shims/xgameruntime.cpp b/runtime/shims/xgameruntime.cpp index 2b44229be4..ec366ebf7a 100644 --- a/runtime/shims/xgameruntime.cpp +++ b/runtime/shims/xgameruntime.cpp @@ -586,6 +586,44 @@ RuntimeObject g_networking{kNetworkingVtable, &kNetworkingClass, kNetworkingIids const GUID* const kPersistentStorageIids[] = {&kPersistentStorage2, &kPersistentStorage3, nullptr}; RuntimeObject g_persistent_storage{kPersistentStorageVtable, &kPersistentStorageClass, kPersistentStorageIids}; +// ---- XAppCaptureImpl (IXAppCaptureImpl .. 4): the retail executable references it; offline there is no capture ---- +// +// The retail executable's one xgameruntime reference this file used to refuse: it queries the class id (which is +// also IXAppCaptureImpl's, per the public xgameruntime IDL and tools/gdk_runtime_classes.json) for +// IXAppCaptureImpl4 and calls slot 5, XAppCaptureTakeScreenshot (one thunk, measured). There is no console capture +// or record offline, so every method refuses: a title that checks the HRESULT sees unsupported, and one that does +// not is no worse off than QueryApiImpl's kClassNotProvided on a null pointer. +constexpr GUID kAppCaptureClass = {0xa4f1aee2, 0x4bf1, 0x4485, {0xb0, 0x08, 0xa7, 0xc2, 0x6d, 0x52, 0xac, 0x27}}; +constexpr GUID kAppCapture2 = {0x3a949778, 0x772e, 0x4799, {0xbd, 0xea, 0x0a, 0x66, 0x39, 0xe9, 0x6b, 0xaa}}; +constexpr GUID kAppCapture3 = {0x2bbca60a, 0x619c, 0x4fe1, {0x81, 0x2e, 0xfb, 0x5c, 0x1d, 0xbd, 0xcf, 0x51}}; +constexpr GUID kAppCapture4 = {0x22e672d7, 0xb4e3, 0x406c, {0xbd, 0x50, 0x8f, 0x0d, 0x25, 0x23, 0x6f, 0x9e}}; + +HRESULT STDMETHODCALLTYPE appcapture_not_implemented(void*) { return E_NOTIMPL; } + +#define APPCAP(fn) reinterpret_cast(&fn) +const void* const kAppCaptureVtable[] = { + APPCAP(object_query_interface), APPCAP(object_add_ref), APPCAP(object_release), + APPCAP(appcapture_not_implemented), // 3 XAppCaptureTakeDiagnosticScreenshot + APPCAP(appcapture_not_implemented), // 4 XAppCaptureRecordDiagnosticClip + APPCAP(appcapture_not_implemented), // 5 XAppCaptureTakeScreenshot (the executable's call) + APPCAP(appcapture_not_implemented), // 6 XAppCaptureOpenScreenshotStream + APPCAP(appcapture_not_implemented), // 7 XAppCaptureReadScreenshotStream + APPCAP(appcapture_not_implemented), // 8 XAppCaptureCloseScreenshotStream + APPCAP(appcapture_not_implemented), // 9 XAppCaptureEnableRecord + APPCAP(appcapture_not_implemented), // 10 XAppCaptureDisableRecord + APPCAP(appcapture_not_implemented), // 11 XAppCaptureGetVideoCaptureSettings (IXAppCaptureImpl2) + APPCAP(appcapture_not_implemented), // 12 XAppCaptureRecordTimespan + APPCAP(appcapture_not_implemented), // 13 XAppCaptureReadLocalStream + APPCAP(appcapture_not_implemented), // 14 XAppCaptureCloseLocalStream + APPCAP(appcapture_not_implemented), // 15 XAppCaptureStartUserRecord (IXAppCaptureImpl3) + APPCAP(appcapture_not_implemented), // 16 XAppCaptureStopUserRecord + APPCAP(appcapture_not_implemented), // 17 XAppCaptureCancelUserRecord (IXAppCaptureImpl4) +}; +#undef APPCAP +static_assert(std::size(kAppCaptureVtable) == 18, "IUnknown + IXAppCaptureImpl's 8 + Impl2's 4 + Impl3's 2 + Impl4's 1"); +const GUID* const kAppCaptureIids[] = {&kAppCapture2, &kAppCapture3, &kAppCapture4, nullptr}; +RuntimeObject g_app_capture{kAppCaptureVtable, &kAppCaptureClass, kAppCaptureIids}; + RuntimeObject& system_object(); // XSystemImpl, defined after the XSystem functions it serves RuntimeObject& package_object(); // XPackageImpl, after the XPackage functions RuntimeObject& game_object(); // XGameImpl, after XPackageImpl @@ -593,8 +631,8 @@ RuntimeObject* const* measured_objects(); // XGameRuntimeFeatureImpl and XSyste // The object this file hands out for a class id, or null when the class isn't one of this file's. RuntimeObject* find_object(const GUID& class_id) { - for (RuntimeObject* o : {&g_threading, &g_error, &g_networking, &g_persistent_storage, &system_object(), - &package_object(), &game_object()}) + for (RuntimeObject* o : {&g_threading, &g_error, &g_networking, &g_persistent_storage, &g_app_capture, + &system_object(), &package_object(), &game_object()}) if (class_id == *o->class_id) return o; for (RuntimeObject* const* o = measured_objects(); *o; ++o) if (class_id == *(*o)->class_id) return *o; @@ -1293,7 +1331,6 @@ constexpr GUID kGameRuntimeFeatureClass = {0x8836fe87, 0xedb9, 0x4fe3, {0x8d, 0x // The classes no object in this file stands for; the other files serve some of them. Named ...ClassId, not ...Class, // because tools/gdk_runtime_calls.py counts every `constexpr GUID k...Class` in these files as a served class. constexpr GUID kAccessibilityClassId = {0x3e241977, 0x6237, 0x41e9, {0x85, 0x59, 0x10, 0x2c, 0x2d, 0x99, 0x83, 0xf1}}; -constexpr GUID kAppCaptureClassId = {0xa4f1aee2, 0x4bf1, 0x4485, {0xb0, 0x08, 0xa7, 0xc2, 0x6d, 0x52, 0xac, 0x27}}; constexpr GUID kDisplayClassId = {0x03f0fe74, 0xfdd9, 0x4e5c, {0xb6, 0x30, 0xf9, 0x33, 0x9c, 0x47, 0xac, 0xc5}}; constexpr GUID kGameEventClassId = {0xbbfbdcc7, 0xbfe7, 0x409b, {0xa5, 0xca, 0xed, 0xf0, 0x54, 0x96, 0x0b, 0x4d}}; constexpr GUID kGameInviteClassId = {0x0651aae2, 0x4012, 0x4077, {0xbf, 0x84, 0x8b, 0x90, 0x97, 0x09, 0x0e, 0x2c}}; @@ -1310,7 +1347,7 @@ struct RuntimeFeature { }; const RuntimeFeature kRuntimeFeatures[] = { {&kAccessibilityClassId, false}, // 0 XAccessibility - {&kAppCaptureClassId, false}, // 1 XAppCapture + {&kAppCaptureClass, false}, // 1 XAppCapture {&kThreadingClass, false}, // 2 XAsync {&kThreadingClass, false}, // 3 XAsyncProvider {&kDisplayClassId, true}, // 4 XDisplay diff --git a/runtime/test/xgameruntime_test.cpp b/runtime/test/xgameruntime_test.cpp index af67045d42..fa9f97d668 100644 --- a/runtime/test/xgameruntime_test.cpp +++ b/runtime/test/xgameruntime_test.cpp @@ -252,9 +252,25 @@ void check_measured_classes(QueryFn query, XSystemAnalyticsInfo (*named_analytic release_object(a); } - // Classes nobody serves are still refused, and logged, as before. + // XAppCaptureImpl: the retail executable's one reference to a class this file used to refuse. It queries the + // class id for IXAppCaptureImpl4 and calls slot 5, XAppCaptureTakeScreenshot. Offline there is no capture or + // record, so every method refuses instead of QueryApiImpl's kClassNotProvided. + const GUID appcapture_cls = {0xa4f1aee2, 0x4bf1, 0x4485, {0xb0, 0x08, 0xa7, 0xc2, 0x6d, 0x52, 0xac, 0x27}}; + const GUID appcapture4 = {0x22e672d7, 0xb4e3, 0x406c, {0xbd, 0x50, 0x8f, 0x0d, 0x25, 0x23, 0x6f, 0x9e}}; + void* cap = ask(query, appcapture_cls, appcapture4); + check(cap != nullptr, "QueryApiImpl hands out XAppCaptureImpl for its class id and the v4 interface id"); + if (cap) { + using TakeScreenshot = HRESULT(STDMETHODCALLTYPE*)(void*); + check(method(cap, 5)(cap) == E_NOTIMPL, "slot 5 (XAppCaptureTakeScreenshot) refuses offline"); + void* other = reinterpret_cast(1); + const GUID bogus = {0x0a0a0a0a, 0x0b0b, 0x0c0c, {0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14}}; + check(query(&appcapture_cls, bogus, &other) == E_NOINTERFACE && other == nullptr, + "XAppCaptureImpl answers its class id and the interface ids, not another class's interface"); + release_object(cap); + } + + // A class nobody serves is still refused, and logged, as before. const GUID refused[] = { - {0xa4f1aee2, 0x4bf1, 0x4485, {0xb0, 0x08, 0xa7, 0xc2, 0x6d, 0x52, 0xac, 0x27}}, // XAppCaptureImpl {0x12345678, 0x9abc, 0xdef0, {0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0}}, // no such class }; bool all_refused = true; @@ -262,7 +278,7 @@ void check_measured_classes(QueryFn query, XSystemAnalyticsInfo (*named_analytic void* out = reinterpret_cast(1); all_refused = all_refused && query(&cls, cls, &out) == static_cast(0x80070032) && out == nullptr; } - check(all_refused, "XAppCaptureImpl and an unknown class are still refused"); + check(all_refused, "an unknown class is still refused"); } // xgameruntime.lib's thunks don't import the runtime: they LoadLibraryW(L"xgameruntime.dll") and GetProcAddress five diff --git a/tests/test_gdk_runtime_calls.py b/tests/test_gdk_runtime_calls.py index d9f2d9426a..b8a86c4841 100644 --- a/tests/test_gdk_runtime_calls.py +++ b/tests/test_gdk_runtime_calls.py @@ -417,7 +417,7 @@ def test_the_default_source_is_every_runtime_shim(self): # xgameruntime.cpp serves XGameRuntimeFeatureImpl; the ids its feature table only names (k...ClassId) don't count. self.assertEqual(served.get("8836fe87-edb9-4fe3-8dad-05f0d2cd5b40"), "kGameRuntimeFeatureClass") self.assertEqual(served.get("1b339674-328d-4283-a200-3171f18d3639"), "kLauncherClass") # XLauncherImpl, xgameruntime_offline.cpp - self.assertNotIn("a4f1aee2-4bf1-4485-b008-a7c26d52ac27", served) # XAppCaptureImpl + self.assertEqual(served.get("a4f1aee2-4bf1-4485-b008-a7c26d52ac27"), "kAppCaptureClass") # XAppCaptureImpl, served empty = os.path.join(self.tmp, "no-shims") os.makedirs(empty, exist_ok=True) with self.assertRaises(OSError):