Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
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
31 changes: 30 additions & 1 deletion shell/platform/windows/angle_surface_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,37 @@ bool AngleSurfaceManager::Initialize() {
return false;
}

egl_resource_context_ = eglCreateContext(
egl_display_, egl_config_, egl_context_, display_context_attributes);

if (egl_resource_context_ == EGL_NO_CONTEXT) {
OutputDebugString(L"EGL: Failed to create EGL resource context");
return false;
}

return true;
}

void AngleSurfaceManager::CleanUp() {
EGLBoolean result = EGL_FALSE;

if (egl_display_ != EGL_NO_DISPLAY && egl_context_ != EGL_NO_CONTEXT) {
eglDestroyContext(egl_display_, egl_context_);
result = eglDestroyContext(egl_display_, egl_context_);
egl_context_ = EGL_NO_CONTEXT;

if (result == EGL_FALSE) {
OutputDebugString(L"EGL: Failed to destroy context");
}
}

if (egl_display_ != EGL_NO_DISPLAY &&
egl_resource_context_ != EGL_NO_CONTEXT) {
result = eglDestroyContext(egl_display_, egl_resource_context_);
egl_resource_context_ = EGL_NO_CONTEXT;

if (result == EGL_FALSE) {
OutputDebugString(L"EGL: Failed to destroy resource context");
}
}

if (egl_display_ != EGL_NO_DISPLAY) {
Expand Down Expand Up @@ -184,6 +208,11 @@ bool AngleSurfaceManager::MakeCurrent(const EGLSurface surface) {
EGL_TRUE);
}

bool AngleSurfaceManager::MakeResourceCurrent() {
return (eglMakeCurrent(egl_display_, EGL_NO_SURFACE, EGL_NO_SURFACE,
egl_resource_context_) == EGL_TRUE);
}

EGLBoolean AngleSurfaceManager::SwapBuffers(const EGLSurface surface) {
return (eglSwapBuffers(egl_display_, surface));
}
Expand Down
14 changes: 11 additions & 3 deletions shell/platform/windows/angle_surface_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ class AngleSurfaceManager {
// surfaces returning a boolean result reflecting success.
bool MakeCurrent(const EGLSurface surface);

// Binds egl_resource_context_ to the current rendering thread and to the draw
// and read surfaces returning a boolean result reflecting success.
bool MakeResourceCurrent();

// Swaps the front and back buffers of the DX11 swapchain backing surface if
// not null.
EGLBoolean SwapBuffers(const EGLSurface surface);
Expand All @@ -55,13 +59,17 @@ class AngleSurfaceManager {
void CleanUp();

private:
// EGL representation of native display
// EGL representation of native display.
EGLDisplay egl_display_;

// EGL representation of current rendering context
// EGL representation of current rendering context.
EGLContext egl_context_;

// current frame buffer configuration
// EGL representation of current rendering context used for async texture
// uploads.
EGLContext egl_resource_context_;

// current frame buffer configuration.
EGLConfig egl_config_;

// State representing success or failure of display initialization used when
Expand Down
4 changes: 4 additions & 0 deletions shell/platform/windows/flutter_windows.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ static FLUTTER_API_SYMBOL(FlutterEngine)
const char* what) -> void* {
return eglGetProcAddress(what);
};
config.open_gl.make_resource_current = [](void* user_data) -> bool {
auto host = static_cast<flutter::Win32FlutterWindow*>(user_data);
return host->MakeResourceCurrent();
};

FlutterProjectArgs args = {};
args.struct_size = sizeof(FlutterProjectArgs);
Expand Down
4 changes: 4 additions & 0 deletions shell/platform/windows/win32_flutter_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,10 @@ bool Win32FlutterWindow::MakeCurrent() {
return surface_manager->MakeCurrent(render_surface);
}

bool Win32FlutterWindow::MakeResourceCurrent() {
return surface_manager->MakeResourceCurrent();
}

bool Win32FlutterWindow::ClearContext() {
return surface_manager->MakeCurrent(nullptr);
}
Expand Down
1 change: 1 addition & 0 deletions shell/platform/windows/win32_flutter_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class Win32FlutterWindow : public Win32Window {
// Callbacks for clearing context, settings context and swapping buffers.
bool ClearContext();
bool MakeCurrent();
bool MakeResourceCurrent();
bool SwapBuffers();

// Sends a window metrics update to the Flutter engine using current window
Expand Down