Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit c115ccf

Browse files
authored
[Windows] Decouple the GL context from the view (#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 flutter/flutter#137267 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent e532e4b commit c115ccf

3 files changed

Lines changed: 12 additions & 23 deletions

File tree

shell/platform/windows/flutter_windows_engine.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,17 @@ FlutterRendererConfig GetOpenGLRendererConfig() {
5353
config.open_gl.struct_size = sizeof(config.open_gl);
5454
config.open_gl.make_current = [](void* user_data) -> bool {
5555
auto host = static_cast<FlutterWindowsEngine*>(user_data);
56-
if (!host->view()) {
56+
if (!host->surface_manager()) {
5757
return false;
5858
}
59-
return host->view()->MakeCurrent();
59+
return host->surface_manager()->MakeCurrent();
6060
};
6161
config.open_gl.clear_current = [](void* user_data) -> bool {
6262
auto host = static_cast<FlutterWindowsEngine*>(user_data);
63-
if (!host->view()) {
63+
if (!host->surface_manager()) {
6464
return false;
6565
}
66-
return host->view()->ClearContext();
66+
return host->surface_manager()->ClearContext();
6767
};
6868
config.open_gl.present = [](void* user_data) -> bool {
6969
auto host = static_cast<FlutterWindowsEngine*>(user_data);
@@ -89,10 +89,10 @@ FlutterRendererConfig GetOpenGLRendererConfig() {
8989
};
9090
config.open_gl.make_resource_current = [](void* user_data) -> bool {
9191
auto host = static_cast<FlutterWindowsEngine*>(user_data);
92-
if (!host->view()) {
92+
if (!host->surface_manager()) {
9393
return false;
9494
}
95-
return host->view()->MakeResourceCurrent();
95+
return host->surface_manager()->MakeResourceCurrent();
9696
};
9797
config.open_gl.gl_external_texture_frame_callback =
9898
[](void* user_data, int64_t texture_id, size_t width, size_t height,

shell/platform/windows/flutter_windows_view.cc

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -535,18 +535,6 @@ void FlutterWindowsView::SendPointerEventWithData(
535535
}
536536
}
537537

538-
bool FlutterWindowsView::MakeCurrent() {
539-
return engine_->surface_manager()->MakeCurrent();
540-
}
541-
542-
bool FlutterWindowsView::MakeResourceCurrent() {
543-
return engine_->surface_manager()->MakeResourceCurrent();
544-
}
545-
546-
bool FlutterWindowsView::ClearContext() {
547-
return engine_->surface_manager()->ClearContext();
548-
}
549-
550538
bool FlutterWindowsView::SwapBuffers() {
551539
// Called on an engine-controlled (non-platform) thread.
552540
std::unique_lock<std::mutex> lock(resize_mutex_);

shell/platform/windows/flutter_windows_view.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,12 @@ class FlutterWindowsView : public WindowBindingHandlerDelegate {
6565
// Tells the engine to generate a new frame
6666
void ForceRedraw();
6767

68-
// Callbacks for clearing context, settings context and swapping buffers,
69-
// these are typically called on an engine-controlled (non-platform) thread.
70-
bool ClearContext();
71-
bool MakeCurrent();
72-
bool MakeResourceCurrent();
68+
// Swap the view's surface buffers. Must be called on the engine's raster
69+
// thread. Returns true if the buffers were swapped.
70+
//
71+
// If the view is resizing, this returns false if the frame is not the target
72+
// size. Otherwise, it unblocks the platform thread and blocks the raster
73+
// thread until the v-blank.
7374
bool SwapBuffers();
7475

7576
// Callback for presenting a software bitmap.

0 commit comments

Comments
 (0)