diff --git a/shell/platform/windows/angle_surface_manager.cc b/shell/platform/windows/angle_surface_manager.cc index 08492b4879add..6756a285d91d5 100644 --- a/shell/platform/windows/angle_surface_manager.cc +++ b/shell/platform/windows/angle_surface_manager.cc @@ -26,6 +26,8 @@ static void LogEglError(std::string message) { namespace flutter { +int AngleSurfaceManager::instance_count_ = 0; + std::unique_ptr AngleSurfaceManager::Create() { std::unique_ptr manager; manager.reset(new AngleSurfaceManager()); @@ -40,10 +42,12 @@ AngleSurfaceManager::AngleSurfaceManager() egl_display_(EGL_NO_DISPLAY), egl_context_(EGL_NO_CONTEXT) { initialize_succeeded_ = Initialize(); + ++instance_count_; } AngleSurfaceManager::~AngleSurfaceManager() { CleanUp(); + --instance_count_; } bool AngleSurfaceManager::InitializeEGL( @@ -200,7 +204,11 @@ void AngleSurfaceManager::CleanUp() { } if (egl_display_ != EGL_NO_DISPLAY) { - eglTerminate(egl_display_); + // Display is reused between instances so only terminate display + // if destroying last instance + if (instance_count_ == 1) { + eglTerminate(egl_display_); + } egl_display_ = EGL_NO_DISPLAY; } } diff --git a/shell/platform/windows/angle_surface_manager.h b/shell/platform/windows/angle_surface_manager.h index 49a6fe459965e..119f57d3e4f78 100644 --- a/shell/platform/windows/angle_surface_manager.h +++ b/shell/platform/windows/angle_surface_manager.h @@ -107,6 +107,9 @@ class AngleSurfaceManager { // Requested dimensions for current surface EGLint surface_width_ = 0; EGLint surface_height_ = 0; + + // Number of active instances of AngleSurfaceManager + static int instance_count_; }; } // namespace flutter