Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion shell/platform/windows/angle_surface_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ void AngleSurfaceManager::CleanUp() {
}

bool AngleSurfaceManager::CreateSurface(WindowsRenderTarget* render_target,
#ifndef WINUWP
bool enable_direct_composition,
#endif
EGLint width,
EGLint height) {
if (!render_target || !initialize_succeeded_) {
Expand All @@ -205,7 +208,12 @@ bool AngleSurfaceManager::CreateSurface(WindowsRenderTarget* render_target,

EGLSurface surface = EGL_NO_SURFACE;

const EGLint surfaceAttributes[] = {EGL_NONE};
const EGLint surfaceAttributes[] = {
#ifndef WINUWP
EGL_DIRECT_COMPOSITION_ANGLE,
enable_direct_composition ? EGL_TRUE : EGL_FALSE,
#endif
EGL_NONE};

#ifdef WINUWP
#ifdef USECOREWINDOW
Expand Down
3 changes: 3 additions & 0 deletions shell/platform/windows/angle_surface_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class AngleSurfaceManager {
// Target represents the visual entity to bind to. Width and
// height represent dimensions surface is created at.
bool CreateSurface(WindowsRenderTarget* render_target,
#ifndef WINUWP

Choose a reason for hiding this comment

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

Not sure how much of the angle code will need to be conditionalized vs a case statement. Maybe the entrypoint won't but the internals will, that will become obvious as you work through it.

bool enable_direct_composition,
#endif
EGLint width,
EGLint height);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ FlutterDesktopViewRef FlutterDesktopViewControllerGetView(
void FlutterDesktopViewControllerForceRedraw(
FlutterDesktopViewControllerRef controller) {}

#ifndef WINUWP
void FlutterDesktopViewControllerEnableDirectComposition(
FlutterDesktopViewControllerRef controller,
bool enable_direct_composition) {}
#endif

bool FlutterDesktopViewControllerHandleTopLevelWindowProc(
FlutterDesktopViewControllerRef controller,
HWND hwnd,
Expand Down
10 changes: 10 additions & 0 deletions shell/platform/windows/flutter_windows.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ void FlutterDesktopViewControllerForceRedraw(
controller->view->ForceRedraw();
}

#ifndef WINUWP

FLUTTER_EXPORT void FlutterDesktopViewControllerEnableDirectComposition(

Choose a reason for hiding this comment

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

I would rather this wasn't conditionalized but instead was a FlutterSetDesktopCompositionMode taking an enum with values None, DirectComposition, WinUIComposition returning a bool to indicate success

FlutterDesktopViewControllerRef controller,
bool enable_direct_composition) {
controller->view->EnableDirectComposition(enable_direct_composition);
}

#endif

FlutterDesktopEngineRef FlutterDesktopEngineCreate(
const FlutterDesktopEngineProperties& engine_properties) {
flutter::FlutterProjectBundle project(engine_properties);
Expand Down
15 changes: 15 additions & 0 deletions shell/platform/windows/flutter_windows_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ void FlutterWindowsView::ForceRedraw() {
}
}

#ifndef WINUWP

Choose a reason for hiding this comment

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

If we have a SetCompositionMode style API, then that should be indirected through WindowBindingHandler to the respective win32 or winuwp window. rather than ifdef'ing here. Each underlying impl can figure out if the requested mode is supported and configure, return true else false. For Win32 it would succeed if composition mode is DirectComposition and OS version >= win8. In the future we can also succeed for WinUIComp once the angle parts land with a version check. For Win32 mode, only WinUIComp mode would succeed. It would also be good to have a prefereddefault method on the binding handler to allow each platform to express a preference for the default for the case when setcompositionmode isn't called. for win32 that can default to none initially and we can then flip it to DirectComposition at the point we're happy with the stability.

We should also verify that linking changes don't break win7.. will need to loadlibrary / getprocaddress and dcomp calls

Copy link
Member Author

Choose a reason for hiding this comment

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

Angle already does that. It loads the direct composition calls through loadlibrary. we could do the same to determine whether dcomp si supported so that API can return true if supported.

void FlutterWindowsView::EnableDirectComposition(bool enable) {

Choose a reason for hiding this comment

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

SetCompositionMode and not conditionalized

if (enable != enable_direct_composition_) {
enable_direct_composition_ = enable;
DestroyRenderSurface();
CreateRenderSurface();
}
}
#endif

void FlutterWindowsView::OnWindowSizeChanged(size_t width, size_t height) {
// Called on the platform thread.
std::unique_lock<std::mutex> lock(resize_mutex_);
Expand Down Expand Up @@ -403,8 +413,13 @@ bool FlutterWindowsView::SwapBuffers() {

void FlutterWindowsView::CreateRenderSurface() {
PhysicalWindowBounds bounds = binding_handler_->GetPhysicalWindowBounds();
#ifndef WINUWP
surface_manager_->CreateSurface(GetRenderTarget(), enable_direct_composition_,
bounds.width, bounds.height);
#else
surface_manager_->CreateSurface(GetRenderTarget(), bounds.width,
bounds.height);
#endif
}

void FlutterWindowsView::DestroyRenderSurface() {
Expand Down
10 changes: 10 additions & 0 deletions shell/platform/windows/flutter_windows_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ class FlutterWindowsView : public WindowBindingHandlerDelegate,
// Tells the engine to generate a new frame
void ForceRedraw();

#ifndef WINUWP

Choose a reason for hiding this comment

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

SetCompositionMode and not conditionalized

// Determines whether view surface is posted to screen using the direct
// composition API
void EnableDirectComposition(bool enable);
#endif

// Callbacks for clearing context, settings context and swapping buffers,
// these are typically called on an engine-controlled (non-platform) thread.
bool ClearContext();
Expand Down Expand Up @@ -297,6 +303,10 @@ class FlutterWindowsView : public WindowBindingHandlerDelegate,
// Target for the window width. Valid when resize_pending_ is set. Guarded by
// resize_mutex_.
size_t resize_target_height_ = 0;

#ifndef WINUWP
bool enable_direct_composition_ = false;
#endif
};

} // namespace flutter
Expand Down
7 changes: 7 additions & 0 deletions shell/platform/windows/public/flutter_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ FLUTTER_EXPORT void FlutterDesktopViewControllerForceRedraw(
FlutterDesktopViewControllerRef controller);

#ifndef WINUWP

// Enables or disables the use of Direct Composition API when presenting
// flutter view surface to screen.
FLUTTER_EXPORT void FlutterDesktopViewControllerEnableDirectComposition(

Choose a reason for hiding this comment

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

SetCompositionMode and not conditionalized

FlutterDesktopViewControllerRef controller,
bool enable_direct_composition);

// Allows the Flutter engine and any interested plugins an opportunity to
// handle the given message.
//
Expand Down