Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Expose-the-d3d11-device-used-by-flutter-engine #164578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
.classpath
.project
.settings/
.vscode/*
**/.vscode/*
.ccls-cache

# This file, on the master branch, should never exist or be checked-in.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ class FlutterView {
return FlutterDesktopViewGetGraphicsAdapter(view_);
}

FlutterID3D11DeviceRef GetID3D11Device() {
return FlutterDesktopPluginViewGetID3D11Device(view_);
}

private:
// Handle for interacting with the C API's view.
FlutterDesktopViewRef view_ = nullptr;
Expand Down
15 changes: 15 additions & 0 deletions engine/src/flutter/shell/platform/windows/flutter_windows.cc
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,21 @@ IDXGIAdapter* FlutterDesktopViewGetGraphicsAdapter(FlutterDesktopViewRef view) {
return nullptr;
}

FlutterID3D11DeviceRef FlutterDesktopPluginViewGetID3D11Device(
FlutterDesktopViewRef view) {
auto egl_manager = ViewFromHandle(view)->GetEngine()->egl_manager();
if (egl_manager) {
Microsoft::WRL::ComPtr<ID3D11Device> d3d_device;
if (egl_manager->GetDevice(d3d_device.GetAddressOf())) {
// Since we pass this to C we can't use smart pointers.
// The user should not use the pointer for the device when flutter
// disposes the engine.
return reinterpret_cast<FlutterID3D11DeviceRef>(d3d_device.Get());
}
}
return nullptr;
}

bool FlutterDesktopEngineProcessExternalWindowMessage(
FlutterDesktopEngineRef engine,
HWND hwnd,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ typedef struct FlutterDesktopViewController* FlutterDesktopViewControllerRef;
struct FlutterDesktopView;
typedef struct FlutterDesktopView* FlutterDesktopViewRef;

// Opaque reference to a Flutter's ID3D11Device.
struct FlutterID3D11Device;
typedef struct FlutterID3D11Device* FlutterID3D11DeviceRef;

// Opaque reference to a Flutter engine instance.
struct FlutterDesktopEngine;
typedef struct FlutterDesktopEngine* FlutterDesktopEngineRef;
Expand Down Expand Up @@ -245,6 +249,10 @@ FLUTTER_EXPORT HWND FlutterDesktopViewGetHWND(FlutterDesktopViewRef view);
FLUTTER_EXPORT IDXGIAdapter* FlutterDesktopViewGetGraphicsAdapter(
FlutterDesktopViewRef view);

// Returns the ID3D11Device used for rendering or nullptr in case of error.
FLUTTER_EXPORT FlutterID3D11DeviceRef FlutterDesktopPluginViewGetID3D11Device(
FlutterDesktopViewRef view);

// Called to pass an external window message to the engine for lifecycle
// state updates. Non-Flutter windows must call this method in their WndProc
// in order to be included in the logic for application lifecycle state
Expand Down