Windows: Client wrapper: Support querying the graphics adapter chosen by ANGLE (flutter/engine#29294)
This commit is contained in:
@@ -16,6 +16,10 @@ namespace {
|
||||
// Stub implementation to validate calls to the API.
|
||||
class TestWindowsApi : public testing::StubFlutterWindowsApi {
|
||||
HWND ViewGetHWND() override { return reinterpret_cast<HWND>(7); }
|
||||
|
||||
IDXGIAdapter* ViewGetGraphicsAdapter() override {
|
||||
return reinterpret_cast<IDXGIAdapter*>(8);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
@@ -28,4 +32,14 @@ TEST(FlutterViewTest, HwndAccessPassesThrough) {
|
||||
EXPECT_EQ(view.GetNativeWindow(), reinterpret_cast<HWND>(7));
|
||||
}
|
||||
|
||||
TEST(FlutterViewTest, GraphicsAdapterAccessPassesThrough) {
|
||||
testing::ScopedStubFlutterWindowsApi scoped_api_stub(
|
||||
std::make_unique<TestWindowsApi>());
|
||||
auto test_api = static_cast<TestWindowsApi*>(scoped_api_stub.stub());
|
||||
FlutterView view(reinterpret_cast<FlutterDesktopViewRef>(2));
|
||||
|
||||
IDXGIAdapter* adapter = view.GetGraphicsAdapter();
|
||||
EXPECT_EQ(adapter, reinterpret_cast<IDXGIAdapter*>(8));
|
||||
}
|
||||
|
||||
} // namespace flutter
|
||||
|
||||
@@ -23,6 +23,11 @@ class FlutterView {
|
||||
// Returns the backing HWND for the view.
|
||||
HWND GetNativeWindow() { return FlutterDesktopViewGetHWND(view_); }
|
||||
|
||||
// Returns the DXGI adapter used for rendering or nullptr in case of error.
|
||||
IDXGIAdapter* GetGraphicsAdapter() {
|
||||
return FlutterDesktopViewGetGraphicsAdapter(view_);
|
||||
}
|
||||
|
||||
private:
|
||||
// Handle for interacting with the C API's view.
|
||||
FlutterDesktopViewRef view_ = nullptr;
|
||||
|
||||
@@ -151,6 +151,13 @@ HWND FlutterDesktopViewGetHWND(FlutterDesktopViewRef controller) {
|
||||
return reinterpret_cast<HWND>(-1);
|
||||
}
|
||||
|
||||
IDXGIAdapter* FlutterDesktopViewGetGraphicsAdapter(FlutterDesktopViewRef view) {
|
||||
if (s_stub_implementation) {
|
||||
return s_stub_implementation->ViewGetGraphicsAdapter();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
FlutterDesktopViewRef FlutterDesktopPluginRegistrarGetView(
|
||||
FlutterDesktopPluginRegistrarRef controller) {
|
||||
// The stub ignores this, so just return an arbitrary non-zero value.
|
||||
|
||||
@@ -72,6 +72,11 @@ class StubFlutterWindowsApi {
|
||||
// Called for FlutterDesktopViewGetHWND.
|
||||
virtual HWND ViewGetHWND() { return reinterpret_cast<HWND>(1); }
|
||||
|
||||
// Called for FlutterDesktopViewGetGraphicsAdapter.
|
||||
virtual IDXGIAdapter* ViewGetGraphicsAdapter() {
|
||||
return reinterpret_cast<IDXGIAdapter*>(2);
|
||||
}
|
||||
|
||||
// Called for FlutterDesktopPluginRegistrarRegisterTopLevelWindowProcDelegate.
|
||||
virtual void PluginRegistrarRegisterTopLevelWindowProcDelegate(
|
||||
FlutterDesktopWindowProcCallback delegate,
|
||||
|
||||
@@ -188,6 +188,22 @@ HWND FlutterDesktopViewGetHWND(FlutterDesktopViewRef view) {
|
||||
return ViewFromHandle(view)->GetPlatformWindow();
|
||||
}
|
||||
|
||||
IDXGIAdapter* FlutterDesktopViewGetGraphicsAdapter(FlutterDesktopViewRef view) {
|
||||
auto surface_manager = ViewFromHandle(view)->GetEngine()->surface_manager();
|
||||
if (surface_manager) {
|
||||
Microsoft::WRL::ComPtr<ID3D11Device> d3d_device;
|
||||
Microsoft::WRL::ComPtr<IDXGIDevice> dxgi_device;
|
||||
if (surface_manager->GetDevice(d3d_device.GetAddressOf()) &&
|
||||
SUCCEEDED(d3d_device.As(&dxgi_device))) {
|
||||
IDXGIAdapter* adapter;
|
||||
if (SUCCEEDED(dxgi_device->GetAdapter(&adapter))) {
|
||||
return adapter;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
FlutterDesktopViewRef FlutterDesktopPluginRegistrarGetView(
|
||||
FlutterDesktopPluginRegistrarRef registrar) {
|
||||
return HandleForView(registrar->engine->view());
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
#include "flutter/shell/platform/windows/public/flutter_windows.h"
|
||||
|
||||
#include <dxgi.h>
|
||||
#include <wrl/client.h>
|
||||
#include <thread>
|
||||
|
||||
#include "flutter/fml/synchronization/count_down_latch.h"
|
||||
@@ -253,5 +255,19 @@ TEST_F(WindowsTest, NextFrameCallback) {
|
||||
captures.frame_drawn_latch.Wait();
|
||||
}
|
||||
|
||||
TEST_F(WindowsTest, GetGraphicsAdapter) {
|
||||
auto& context = GetContext();
|
||||
WindowsConfigBuilder builder(context);
|
||||
ViewControllerPtr controller{builder.Run()};
|
||||
ASSERT_NE(controller, nullptr);
|
||||
auto view = FlutterDesktopViewControllerGetView(controller.get());
|
||||
|
||||
Microsoft::WRL::ComPtr<IDXGIAdapter> dxgi_adapter;
|
||||
dxgi_adapter = FlutterDesktopViewGetGraphicsAdapter(view);
|
||||
ASSERT_NE(dxgi_adapter, nullptr);
|
||||
DXGI_ADAPTER_DESC desc{};
|
||||
ASSERT_TRUE(SUCCEEDED(dxgi_adapter->GetDesc(&desc)));
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
} // namespace flutter
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_PUBLIC_FLUTTER_H_
|
||||
#define FLUTTER_SHELL_PLATFORM_WINDOWS_PUBLIC_FLUTTER_H_
|
||||
|
||||
#include <dxgi.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <windows.h>
|
||||
@@ -201,6 +202,10 @@ FLUTTER_EXPORT void FlutterDesktopEngineSetNextFrameCallback(
|
||||
// Return backing HWND for manipulation in host application.
|
||||
FLUTTER_EXPORT HWND FlutterDesktopViewGetHWND(FlutterDesktopViewRef view);
|
||||
|
||||
// Returns the DXGI adapter used for rendering or nullptr in case of error.
|
||||
FLUTTER_EXPORT IDXGIAdapter* FlutterDesktopViewGetGraphicsAdapter(
|
||||
FlutterDesktopViewRef view);
|
||||
|
||||
// ========== Plugin Registrar (extensions) ==========
|
||||
// These are Windows-specific extensions to flutter_plugin_registrar.h
|
||||
|
||||
|
||||
Reference in New Issue
Block a user