diff --git a/shell/platform/windows/angle_surface_manager.cc b/shell/platform/windows/angle_surface_manager.cc index d210f7c76e0e2..7afc1161c5d6f 100644 --- a/shell/platform/windows/angle_surface_manager.cc +++ b/shell/platform/windows/angle_surface_manager.cc @@ -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_) { @@ -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 diff --git a/shell/platform/windows/angle_surface_manager.h b/shell/platform/windows/angle_surface_manager.h index 4b609e6f79bb0..30be98bdf3dbb 100644 --- a/shell/platform/windows/angle_surface_manager.h +++ b/shell/platform/windows/angle_surface_manager.h @@ -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 + bool enable_direct_composition, +#endif EGLint width, EGLint height); diff --git a/shell/platform/windows/client_wrapper/testing/stub_flutter_windows_api.cc b/shell/platform/windows/client_wrapper/testing/stub_flutter_windows_api.cc index 6f10d82cd43c8..9ca89e9f33f70 100644 --- a/shell/platform/windows/client_wrapper/testing/stub_flutter_windows_api.cc +++ b/shell/platform/windows/client_wrapper/testing/stub_flutter_windows_api.cc @@ -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, diff --git a/shell/platform/windows/flutter_windows.cc b/shell/platform/windows/flutter_windows.cc index 4e1ef6ecc5af1..a0b73c9bc2492 100644 --- a/shell/platform/windows/flutter_windows.cc +++ b/shell/platform/windows/flutter_windows.cc @@ -81,6 +81,16 @@ void FlutterDesktopViewControllerForceRedraw( controller->view->ForceRedraw(); } +#ifndef WINUWP + +FLUTTER_EXPORT void FlutterDesktopViewControllerEnableDirectComposition( + FlutterDesktopViewControllerRef controller, + bool enable_direct_composition) { + controller->view->EnableDirectComposition(enable_direct_composition); +} + +#endif + FlutterDesktopEngineRef FlutterDesktopEngineCreate( const FlutterDesktopEngineProperties& engine_properties) { flutter::FlutterProjectBundle project(engine_properties); diff --git a/shell/platform/windows/flutter_windows_view.cc b/shell/platform/windows/flutter_windows_view.cc index 1eb03b30efb91..010ba745f538e 100644 --- a/shell/platform/windows/flutter_windows_view.cc +++ b/shell/platform/windows/flutter_windows_view.cc @@ -105,6 +105,16 @@ void FlutterWindowsView::ForceRedraw() { } } +#ifndef WINUWP +void FlutterWindowsView::EnableDirectComposition(bool enable) { + 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 lock(resize_mutex_); @@ -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() { diff --git a/shell/platform/windows/flutter_windows_view.h b/shell/platform/windows/flutter_windows_view.h index d65acb7adc9a4..2f841c4388489 100644 --- a/shell/platform/windows/flutter_windows_view.h +++ b/shell/platform/windows/flutter_windows_view.h @@ -67,6 +67,12 @@ class FlutterWindowsView : public WindowBindingHandlerDelegate, // Tells the engine to generate a new frame void ForceRedraw(); +#ifndef WINUWP + // 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(); @@ -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 diff --git a/shell/platform/windows/public/flutter_windows.h b/shell/platform/windows/public/flutter_windows.h index 0b52c97ad72f7..430f64476234c 100644 --- a/shell/platform/windows/public/flutter_windows.h +++ b/shell/platform/windows/public/flutter_windows.h @@ -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( + FlutterDesktopViewControllerRef controller, + bool enable_direct_composition); + // Allows the Flutter engine and any interested plugins an opportunity to // handle the given message. //