From 20e53004772253dacef389a2e30a5154863003ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Sharma?= <737941+loic-sharma@users.noreply.github.com> Date: Mon, 4 Dec 2023 12:53:03 -0800 Subject: [PATCH] [Windows] Decouple the GL context from the view (flutter/engine#48636) In the future, the GL context will be shared between zero or more views. The engine will also need to be able to make the GL context current even if the app is currently in headless mode. No tests are updated as this is a refactoring with no functionality changes. Part of https://github.com/flutter/flutter/issues/137267 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style --- .../shell/platform/windows/flutter_windows_engine.cc | 12 ++++++------ .../shell/platform/windows/flutter_windows_view.cc | 12 ------------ .../shell/platform/windows/flutter_windows_view.h | 11 ++++++----- 3 files changed, 12 insertions(+), 23 deletions(-) diff --git a/engine/src/flutter/shell/platform/windows/flutter_windows_engine.cc b/engine/src/flutter/shell/platform/windows/flutter_windows_engine.cc index fa43c057490..d58a576eae0 100644 --- a/engine/src/flutter/shell/platform/windows/flutter_windows_engine.cc +++ b/engine/src/flutter/shell/platform/windows/flutter_windows_engine.cc @@ -53,17 +53,17 @@ FlutterRendererConfig GetOpenGLRendererConfig() { config.open_gl.struct_size = sizeof(config.open_gl); config.open_gl.make_current = [](void* user_data) -> bool { auto host = static_cast(user_data); - if (!host->view()) { + if (!host->surface_manager()) { return false; } - return host->view()->MakeCurrent(); + return host->surface_manager()->MakeCurrent(); }; config.open_gl.clear_current = [](void* user_data) -> bool { auto host = static_cast(user_data); - if (!host->view()) { + if (!host->surface_manager()) { return false; } - return host->view()->ClearContext(); + return host->surface_manager()->ClearContext(); }; config.open_gl.present = [](void* user_data) -> bool { auto host = static_cast(user_data); @@ -89,10 +89,10 @@ FlutterRendererConfig GetOpenGLRendererConfig() { }; config.open_gl.make_resource_current = [](void* user_data) -> bool { auto host = static_cast(user_data); - if (!host->view()) { + if (!host->surface_manager()) { return false; } - return host->view()->MakeResourceCurrent(); + return host->surface_manager()->MakeResourceCurrent(); }; config.open_gl.gl_external_texture_frame_callback = [](void* user_data, int64_t texture_id, size_t width, size_t height, diff --git a/engine/src/flutter/shell/platform/windows/flutter_windows_view.cc b/engine/src/flutter/shell/platform/windows/flutter_windows_view.cc index dc5488122e5..00623ff810e 100644 --- a/engine/src/flutter/shell/platform/windows/flutter_windows_view.cc +++ b/engine/src/flutter/shell/platform/windows/flutter_windows_view.cc @@ -535,18 +535,6 @@ void FlutterWindowsView::SendPointerEventWithData( } } -bool FlutterWindowsView::MakeCurrent() { - return engine_->surface_manager()->MakeCurrent(); -} - -bool FlutterWindowsView::MakeResourceCurrent() { - return engine_->surface_manager()->MakeResourceCurrent(); -} - -bool FlutterWindowsView::ClearContext() { - return engine_->surface_manager()->ClearContext(); -} - bool FlutterWindowsView::SwapBuffers() { // Called on an engine-controlled (non-platform) thread. std::unique_lock lock(resize_mutex_); diff --git a/engine/src/flutter/shell/platform/windows/flutter_windows_view.h b/engine/src/flutter/shell/platform/windows/flutter_windows_view.h index 3f116779025..55125f8551f 100644 --- a/engine/src/flutter/shell/platform/windows/flutter_windows_view.h +++ b/engine/src/flutter/shell/platform/windows/flutter_windows_view.h @@ -65,11 +65,12 @@ class FlutterWindowsView : public WindowBindingHandlerDelegate { // Tells the engine to generate a new frame void ForceRedraw(); - // Callbacks for clearing context, settings context and swapping buffers, - // these are typically called on an engine-controlled (non-platform) thread. - bool ClearContext(); - bool MakeCurrent(); - bool MakeResourceCurrent(); + // Swap the view's surface buffers. Must be called on the engine's raster + // thread. Returns true if the buffers were swapped. + // + // If the view is resizing, this returns false if the frame is not the target + // size. Otherwise, it unblocks the platform thread and blocks the raster + // thread until the v-blank. bool SwapBuffers(); // Callback for presenting a software bitmap.