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

Skip to content

[Windows] Add public API to get the view's D3D11 device #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

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/*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you undo this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really annoying to open code under .../engine but yeah

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh for engine development you probably should open either the repo's root or engine/src/flutter/. That has the proper .gitignore here:

https://github.com/flutter/flutter/blob/master/engine/src/flutter/.gitignore#L51

.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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised to see an opaque struct here. I would imagine the user would want the raw ID3D11Device* instead. Should we just return ID3D11Device* instead of a 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should call out the lifetime of the returned value. Should we be pessimistic and state the lifetime is only as long as the view? (This isn't strictly true today, the lifetime is as long as the engine. But being conservative here seems useful?)
 

Suggested change
// Returns the ID3D11Device used for rendering or nullptr in case of error.
// Returns the ID3D11Device used for rendering or nullptr in case of error.
//
// The ID3D11Device's lifetime is the same as the |view|'s.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm since multi-window is going to be a thing ig would be right to say engine here

FLUTTER_EXPORT FlutterID3D11DeviceRef FlutterDesktopPluginViewGetID3D11Device(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's call this FlutterDesktopViewGetID3D11Device for consistency with existing APIs.

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