Skip to content

Commit f65eec9

Browse files
[Impeller] Call glfwTerminate during global test environment teardown if a playground test called glfwInit (#189523)
glfwTerminate will call eglTerminate, which will execute an orderly shutdown of ANGLE before the test process exits.
1 parent 8a82082 commit f65eec9

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

‎engine/src/flutter/impeller/playground/playground.cc‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ std::string PlaygroundBackendToString(PlaygroundBackend backend) {
8383
FML_UNREACHABLE();
8484
}
8585

86-
static void InitializeGLFWOnce() {
86+
std::atomic<bool> Playground::glfw_initialized_ = false;
87+
88+
void Playground::InitializeGLFWOnce() {
8789
// This guard is a hack to work around a problem where glfwCreateWindow
8890
// hangs when opening a second window after GLFW has been reinitialized (for
8991
// example, when flipping through multiple playground tests).
@@ -106,9 +108,16 @@ static void InitializeGLFWOnce() {
106108
FML_LOG(ERROR) << "GLFW Error '" << description << "' (" << code << ").";
107109
});
108110
FML_CHECK(::glfwInit() == GLFW_TRUE);
111+
glfw_initialized_ = true;
109112
});
110113
}
111114

115+
void Playground::OnTearDownTestEnvironment() {
116+
if (glfw_initialized_) {
117+
::glfwTerminate();
118+
}
119+
}
120+
112121
testing::GoldenDigestManager* Playground::GetGoldenDigestManager() const {
113122
return nullptr;
114123
}

‎engine/src/flutter/impeller/playground/playground.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#ifndef FLUTTER_IMPELLER_PLAYGROUND_PLAYGROUND_H_
66
#define FLUTTER_IMPELLER_PLAYGROUND_PLAYGROUND_H_
77

8+
#include <atomic>
89
#include <chrono>
910
#include <memory>
1011

@@ -47,6 +48,8 @@ class Playground {
4748

4849
virtual ~Playground();
4950

51+
static void OnTearDownTestEnvironment();
52+
5053
static bool ShouldOpenNewPlaygrounds();
5154

5255
bool IsPlaygroundEnabled() const;
@@ -197,6 +200,9 @@ class Playground {
197200
virtual testing::GoldenDigestManager* GetGoldenDigestManager() const;
198201

199202
private:
203+
static void InitializeGLFWOnce();
204+
static std::atomic<bool> glfw_initialized_;
205+
200206
const PlaygroundBackend backend_;
201207
PlaygroundSwitches switches_;
202208

‎engine/src/flutter/impeller/playground/playground_test.cc‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ class PlaygroundTestEnvironment : public ::testing::Environment {
115115
golden_manager_.reset();
116116
}
117117
PlaygroundImpl::OnTearDownTestEnvironment();
118+
Playground::OnTearDownTestEnvironment();
118119
}
119120

120121
static testing::GoldenDigestManager* GetGoldenDigestManager() {

0 commit comments

Comments
 (0)