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

Commit 70327ae

Browse files
author
George Wright
authored
Increase logging in AngleSurfaceManager (#23906)
1 parent 833d995 commit 70327ae

File tree

2 files changed

+46
-27
lines changed

2 files changed

+46
-27
lines changed

shell/platform/windows/angle_surface_manager.cc

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
#include <winrt/Windows.UI.Core.h>
1717
#endif
1818

19+
// Logs an EGL error to stderr. This automatically calls eglGetError()
20+
// and logs the error code.
21+
static void LogEglError(std::string message) {
22+
EGLint error = eglGetError();
23+
std::cerr << "EGL: " << message << std::endl;
24+
std::cerr << "EGL: eglGetError returned " << error << std::endl;
25+
}
26+
1927
namespace flutter {
2028

2129
AngleSurfaceManager::AngleSurfaceManager()
@@ -29,36 +37,35 @@ AngleSurfaceManager::~AngleSurfaceManager() {
2937
CleanUp();
3038
}
3139

32-
bool AngleSurfaceManager::InitializeEGL(const EGLint* attributes) {
33-
PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT =
34-
reinterpret_cast<PFNEGLGETPLATFORMDISPLAYEXTPROC>(
35-
eglGetProcAddress("eglGetPlatformDisplayEXT"));
36-
if (!eglGetPlatformDisplayEXT) {
37-
std::cerr << "EGL: eglGetPlatformDisplayEXT not available" << std::endl;
38-
return false;
39-
}
40-
41-
egl_display_ = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE,
42-
EGL_DEFAULT_DISPLAY, attributes);
40+
bool AngleSurfaceManager::InitializeEGL(
41+
PFNEGLGETPLATFORMDISPLAYEXTPROC egl_get_platform_display_EXT,
42+
const EGLint* config,
43+
bool should_log) {
44+
egl_display_ = egl_get_platform_display_EXT(EGL_PLATFORM_ANGLE_ANGLE,
45+
EGL_DEFAULT_DISPLAY, config);
4346

4447
if (egl_display_ == EGL_NO_DISPLAY) {
45-
std::cerr << "EGL: Failed to get a compatible EGLdisplay" << std::endl;
48+
if (should_log) {
49+
LogEglError("Failed to get a compatible EGLdisplay");
50+
}
4651
return false;
4752
}
4853

4954
if (eglInitialize(egl_display_, nullptr, nullptr) == EGL_FALSE) {
50-
std::cerr << "EGL: Failed to initialize";
55+
if (should_log) {
56+
LogEglError("Failed to initialize EGL via ANGLE");
57+
}
5158
return false;
5259
}
5360

5461
return true;
5562
}
5663

5764
bool AngleSurfaceManager::Initialize() {
58-
const EGLint configAttributes[] = {EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8,
59-
EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 8,
60-
EGL_DEPTH_SIZE, 8, EGL_STENCIL_SIZE, 8,
61-
EGL_NONE};
65+
const EGLint config_attributes[] = {EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8,
66+
EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 8,
67+
EGL_DEPTH_SIZE, 8, EGL_STENCIL_SIZE, 8,
68+
EGL_NONE};
6269

6370
const EGLint display_context_attributes[] = {EGL_CONTEXT_CLIENT_VERSION, 2,
6471
EGL_NONE};
@@ -118,34 +125,43 @@ bool AngleSurfaceManager::Initialize() {
118125
d3d9_display_attributes,
119126
};
120127

128+
PFNEGLGETPLATFORMDISPLAYEXTPROC egl_get_platform_display_EXT =
129+
reinterpret_cast<PFNEGLGETPLATFORMDISPLAYEXTPROC>(
130+
eglGetProcAddress("eglGetPlatformDisplayEXT"));
131+
if (!egl_get_platform_display_EXT) {
132+
LogEglError("eglGetPlatformDisplayEXT not available");
133+
return false;
134+
}
135+
121136
// Attempt to initialize ANGLE's renderer in order of: D3D11, D3D11 Feature
122137
// Level 9_3, D3D11 WARP and finally D3D9.
123138
for (auto config : display_attributes_configs) {
124-
if (InitializeEGL(config)) {
139+
bool should_log = (config == display_attributes_configs.back());
140+
if (InitializeEGL(egl_get_platform_display_EXT, config, should_log)) {
125141
break;
126142
}
127143
}
128144

129145
EGLint numConfigs = 0;
130-
if ((eglChooseConfig(egl_display_, configAttributes, &egl_config_, 1,
146+
if ((eglChooseConfig(egl_display_, config_attributes, &egl_config_, 1,
131147
&numConfigs) == EGL_FALSE) ||
132148
(numConfigs == 0)) {
133-
std::cerr << "EGL: Failed to choose first context" << std::endl;
149+
LogEglError("Failed to choose first context");
134150
return false;
135151
}
136152

137153
egl_context_ = eglCreateContext(egl_display_, egl_config_, EGL_NO_CONTEXT,
138154
display_context_attributes);
139155
if (egl_context_ == EGL_NO_CONTEXT) {
140-
std::cerr << "EGL: Failed to create EGL context" << std::endl;
156+
LogEglError("Failed to create EGL context");
141157
return false;
142158
}
143159

144160
egl_resource_context_ = eglCreateContext(
145161
egl_display_, egl_config_, egl_context_, display_context_attributes);
146162

147163
if (egl_resource_context_ == EGL_NO_CONTEXT) {
148-
std::cerr << "EGL: Failed to create EGL resource context" << std::endl;
164+
LogEglError("Failed to create EGL resource context");
149165
return false;
150166
}
151167

@@ -160,7 +176,7 @@ void AngleSurfaceManager::CleanUp() {
160176
egl_context_ = EGL_NO_CONTEXT;
161177

162178
if (result == EGL_FALSE) {
163-
std::cerr << "EGL: Failed to destroy context" << std::endl;
179+
LogEglError("Failed to destroy context");
164180
}
165181
}
166182

@@ -170,7 +186,7 @@ void AngleSurfaceManager::CleanUp() {
170186
egl_resource_context_ = EGL_NO_CONTEXT;
171187

172188
if (result == EGL_FALSE) {
173-
std::cerr << "EGL: Failed to destroy resource context" << std::endl;
189+
LogEglError("Failed to destroy resource context");
174190
}
175191
}
176192

@@ -215,7 +231,7 @@ bool AngleSurfaceManager::CreateSurface(WindowsRenderTarget* render_target,
215231
surfaceAttributes);
216232
#endif
217233
if (surface == EGL_NO_SURFACE) {
218-
std::cerr << "Surface creation failed." << std::endl;
234+
LogEglError("Surface creation failed.");
219235
}
220236

221237
render_surface_ = surface;

shell/platform/windows/angle_surface_manager.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,11 @@ class AngleSurfaceManager {
7575
void CleanUp();
7676

7777
private:
78-
// Attempts to initialize EGL with a particular ANGLE configuration.
79-
bool InitializeEGL(const EGLint* attributes);
78+
// Attempts to initialize EGL using ANGLE.
79+
bool InitializeEGL(
80+
PFNEGLGETPLATFORMDISPLAYEXTPROC egl_get_platform_display_EXT,
81+
const EGLint* config,
82+
bool should_log);
8083

8184
// EGL representation of native display.
8285
EGLDisplay egl_display_;

0 commit comments

Comments
 (0)