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
10 changes: 9 additions & 1 deletion shell/platform/windows/angle_surface_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ static void LogEglError(std::string message) {

namespace flutter {

int AngleSurfaceManager::instance_count_ = 0;

std::unique_ptr<AngleSurfaceManager> AngleSurfaceManager::Create() {
std::unique_ptr<AngleSurfaceManager> manager;
manager.reset(new AngleSurfaceManager());
Expand All @@ -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(
Expand Down Expand Up @@ -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) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as defense in depth, worth setting count to 0 when you detect this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I see the point. It is decremented to zero in destructor right after CleanUp returns. This all happens on platform thread so there shouldn't be any concurrency issues.

eglTerminate(egl_display_);
}
egl_display_ = EGL_NO_DISPLAY;
}
}
Expand Down
3 changes: 3 additions & 0 deletions shell/platform/windows/angle_surface_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down