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

Commit abd3a55

Browse files
authored
[Windows] Refactor the GLES proc table (#48688)
GLES functions are resolved at runtime. This refactors how these functions are stored by introducing the `GlProcTable` abstraction. This is a step towards switching the Windows embedder to `FlutterCompositor` rendering as the present callback will use the `GlProcTable` to render OpenGL backing stores.   Part of flutter/flutter#128904 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent ab89510 commit abd3a55

16 files changed

Lines changed: 289 additions & 159 deletions

ci/licenses_golden/licenses_flutter

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7138,6 +7138,8 @@ ORIGIN: ../../../flutter/shell/platform/windows/flutter_windows_texture_registra
71387138
ORIGIN: ../../../flutter/shell/platform/windows/flutter_windows_view.cc + ../../../flutter/LICENSE
71397139
ORIGIN: ../../../flutter/shell/platform/windows/flutter_windows_view.h + ../../../flutter/LICENSE
71407140
ORIGIN: ../../../flutter/shell/platform/windows/flutter_windows_view_controller.h + ../../../flutter/LICENSE
7141+
ORIGIN: ../../../flutter/shell/platform/windows/gl_proc_table.cc + ../../../flutter/LICENSE
7142+
ORIGIN: ../../../flutter/shell/platform/windows/gl_proc_table.h + ../../../flutter/LICENSE
71417143
ORIGIN: ../../../flutter/shell/platform/windows/keyboard_handler_base.h + ../../../flutter/LICENSE
71427144
ORIGIN: ../../../flutter/shell/platform/windows/keyboard_key_channel_handler.cc + ../../../flutter/LICENSE
71437145
ORIGIN: ../../../flutter/shell/platform/windows/keyboard_key_channel_handler.h + ../../../flutter/LICENSE
@@ -9961,6 +9963,8 @@ FILE: ../../../flutter/shell/platform/windows/flutter_windows_texture_registrar.
99619963
FILE: ../../../flutter/shell/platform/windows/flutter_windows_view.cc
99629964
FILE: ../../../flutter/shell/platform/windows/flutter_windows_view.h
99639965
FILE: ../../../flutter/shell/platform/windows/flutter_windows_view_controller.h
9966+
FILE: ../../../flutter/shell/platform/windows/gl_proc_table.cc
9967+
FILE: ../../../flutter/shell/platform/windows/gl_proc_table.h
99649968
FILE: ../../../flutter/shell/platform/windows/keyboard_handler_base.h
99659969
FILE: ../../../flutter/shell/platform/windows/keyboard_key_channel_handler.cc
99669970
FILE: ../../../flutter/shell/platform/windows/keyboard_key_channel_handler.h

shell/platform/windows/BUILD.gn

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ source_set("flutter_windows_source") {
7070
"flutter_windows_view.cc",
7171
"flutter_windows_view.h",
7272
"flutter_windows_view_controller.h",
73+
"gl_proc_table.cc",
74+
"gl_proc_table.h",
7375
"keyboard_handler_base.h",
7476
"keyboard_key_channel_handler.cc",
7577
"keyboard_key_channel_handler.h",
@@ -198,7 +200,7 @@ executable("flutter_windows_unittests") {
198200
"testing/flutter_windows_engine_builder.cc",
199201
"testing/flutter_windows_engine_builder.h",
200202
"testing/mock_direct_manipulation.h",
201-
"testing/mock_gl_functions.h",
203+
"testing/mock_gl_proc_table.h",
202204
"testing/mock_text_input_manager.cc",
203205
"testing/mock_text_input_manager.h",
204206
"testing/mock_window.cc",

shell/platform/windows/external_texture.h

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,6 @@
1212

1313
namespace flutter {
1414

15-
typedef void (*glGenTexturesProc)(GLsizei n, GLuint* textures);
16-
typedef void (*glDeleteTexturesProc)(GLsizei n, const GLuint* textures);
17-
typedef void (*glBindTextureProc)(GLenum target, GLuint texture);
18-
typedef void (*glTexParameteriProc)(GLenum target, GLenum pname, GLint param);
19-
typedef void (*glTexImage2DProc)(GLenum target,
20-
GLint level,
21-
GLint internalformat,
22-
GLsizei width,
23-
GLsizei height,
24-
GLint border,
25-
GLenum format,
26-
GLenum type,
27-
const void* data);
28-
29-
// A struct containing pointers to resolved gl* functions.
30-
struct GlProcs {
31-
glGenTexturesProc glGenTextures;
32-
glDeleteTexturesProc glDeleteTextures;
33-
glBindTextureProc glBindTexture;
34-
glTexParameteriProc glTexParameteri;
35-
glTexImage2DProc glTexImage2D;
36-
bool valid;
37-
};
38-
3915
// Abstract external texture.
4016
class ExternalTexture {
4117
public:

shell/platform/windows/external_texture_d3d.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ ExternalTextureD3d::ExternalTextureD3d(
1414
const FlutterDesktopGpuSurfaceTextureCallback texture_callback,
1515
void* user_data,
1616
const AngleSurfaceManager* surface_manager,
17-
const GlProcs& gl_procs)
17+
std::shared_ptr<GlProcTable> gl)
1818
: type_(type),
1919
texture_callback_(texture_callback),
2020
user_data_(user_data),
2121
surface_manager_(surface_manager),
22-
gl_(gl_procs) {}
22+
gl_(std::move(gl)) {}
2323

2424
ExternalTextureD3d::~ExternalTextureD3d() {
2525
ReleaseImage();
2626

2727
if (gl_texture_ != 0) {
28-
gl_.glDeleteTextures(1, &gl_texture_);
28+
gl_->DeleteTextures(1, &gl_texture_);
2929
}
3030
}
3131

@@ -69,15 +69,15 @@ bool ExternalTextureD3d::CreateOrUpdateTexture(
6969
}
7070

7171
if (gl_texture_ == 0) {
72-
gl_.glGenTextures(1, &gl_texture_);
72+
gl_->GenTextures(1, &gl_texture_);
7373

74-
gl_.glBindTexture(GL_TEXTURE_2D, gl_texture_);
75-
gl_.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
76-
gl_.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
77-
gl_.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
78-
gl_.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
74+
gl_->BindTexture(GL_TEXTURE_2D, gl_texture_);
75+
gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
76+
gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
77+
gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
78+
gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
7979
} else {
80-
gl_.glBindTexture(GL_TEXTURE_2D, gl_texture_);
80+
gl_->BindTexture(GL_TEXTURE_2D, gl_texture_);
8181
}
8282

8383
auto handle = SAFE_ACCESS(descriptor, handle, nullptr);

shell/platform/windows/external_texture_d3d.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
#ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_EXTERNAL_TEXTURE_D3D_H_
66
#define FLUTTER_SHELL_PLATFORM_WINDOWS_EXTERNAL_TEXTURE_D3D_H_
77

8+
#include <memory>
9+
810
#include "flutter/fml/macros.h"
911
#include "flutter/shell/platform/windows/angle_surface_manager.h"
1012
#include "flutter/shell/platform/windows/external_texture.h"
13+
#include "flutter/shell/platform/windows/gl_proc_table.h"
1114

1215
namespace flutter {
1316

@@ -19,7 +22,7 @@ class ExternalTextureD3d : public ExternalTexture {
1922
const FlutterDesktopGpuSurfaceTextureCallback texture_callback,
2023
void* user_data,
2124
const AngleSurfaceManager* surface_manager,
22-
const GlProcs& gl_procs);
25+
std::shared_ptr<GlProcTable> gl);
2326
virtual ~ExternalTextureD3d();
2427

2528
// |ExternalTexture|
@@ -39,7 +42,7 @@ class ExternalTextureD3d : public ExternalTexture {
3942
const FlutterDesktopGpuSurfaceTextureCallback texture_callback_;
4043
void* const user_data_;
4144
const AngleSurfaceManager* surface_manager_;
42-
const GlProcs& gl_;
45+
std::shared_ptr<GlProcTable> gl_;
4346
GLuint gl_texture_ = 0;
4447
EGLSurface egl_surface_ = EGL_NO_SURFACE;
4548
void* last_surface_handle_ = nullptr;

shell/platform/windows/external_texture_pixelbuffer.cc

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ namespace flutter {
99
ExternalTexturePixelBuffer::ExternalTexturePixelBuffer(
1010
const FlutterDesktopPixelBufferTextureCallback texture_callback,
1111
void* user_data,
12-
const GlProcs& gl_procs)
12+
std::shared_ptr<GlProcTable> gl)
1313
: texture_callback_(texture_callback),
1414
user_data_(user_data),
15-
gl_(gl_procs) {}
15+
gl_(std::move(gl)) {}
1616

1717
ExternalTexturePixelBuffer::~ExternalTexturePixelBuffer() {
1818
if (gl_texture_ != 0) {
19-
gl_.glDeleteTextures(1, &gl_texture_);
19+
gl_->DeleteTextures(1, &gl_texture_);
2020
}
2121
}
2222

@@ -51,20 +51,20 @@ bool ExternalTexturePixelBuffer::CopyPixelBuffer(size_t& width,
5151
height = pixel_buffer->height;
5252

5353
if (gl_texture_ == 0) {
54-
gl_.glGenTextures(1, &gl_texture_);
54+
gl_->GenTextures(1, &gl_texture_);
5555

56-
gl_.glBindTexture(GL_TEXTURE_2D, gl_texture_);
57-
gl_.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
58-
gl_.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
59-
gl_.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
60-
gl_.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
56+
gl_->BindTexture(GL_TEXTURE_2D, gl_texture_);
57+
gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
58+
gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
59+
gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
60+
gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
6161

6262
} else {
63-
gl_.glBindTexture(GL_TEXTURE_2D, gl_texture_);
63+
gl_->BindTexture(GL_TEXTURE_2D, gl_texture_);
6464
}
65-
gl_.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pixel_buffer->width,
66-
pixel_buffer->height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
67-
pixel_buffer->buffer);
65+
gl_->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pixel_buffer->width,
66+
pixel_buffer->height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
67+
pixel_buffer->buffer);
6868
if (pixel_buffer->release_callback) {
6969
pixel_buffer->release_callback(pixel_buffer->release_context);
7070
}

shell/platform/windows/external_texture_pixelbuffer.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "flutter/fml/macros.h"
99
#include "flutter/shell/platform/common/public/flutter_texture_registrar.h"
1010
#include "flutter/shell/platform/windows/external_texture.h"
11+
#include "flutter/shell/platform/windows/gl_proc_table.h"
1112

1213
namespace flutter {
1314

@@ -17,7 +18,7 @@ class ExternalTexturePixelBuffer : public ExternalTexture {
1718
ExternalTexturePixelBuffer(
1819
const FlutterDesktopPixelBufferTextureCallback texture_callback,
1920
void* user_data,
20-
const GlProcs& gl_procs);
21+
std::shared_ptr<GlProcTable> gl);
2122

2223
virtual ~ExternalTexturePixelBuffer();
2324

@@ -37,7 +38,7 @@ class ExternalTexturePixelBuffer : public ExternalTexture {
3738

3839
const FlutterDesktopPixelBufferTextureCallback texture_callback_ = nullptr;
3940
void* const user_data_ = nullptr;
40-
const GlProcs& gl_;
41+
std::shared_ptr<GlProcTable> gl_;
4142
GLuint gl_texture_ = 0;
4243

4344
FML_DISALLOW_COPY_AND_ASSIGN(ExternalTexturePixelBuffer);

shell/platform/windows/flutter_windows_engine.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ FlutterWindowsEngine::FlutterWindowsEngine(
168168
windows_proc_table_ = std::make_shared<WindowsProcTable>();
169169
}
170170

171+
gl_ = GlProcTable::Create();
172+
171173
embedder_api_.struct_size = sizeof(FlutterEngineProcTable);
172174
FlutterEngineGetProcAddresses(&embedder_api_);
173175

@@ -204,9 +206,8 @@ FlutterWindowsEngine::FlutterWindowsEngine(
204206
},
205207
static_cast<void*>(this));
206208

207-
FlutterWindowsTextureRegistrar::ResolveGlFunctions(gl_procs_);
208209
texture_registrar_ =
209-
std::make_unique<FlutterWindowsTextureRegistrar>(this, gl_procs_);
210+
std::make_unique<FlutterWindowsTextureRegistrar>(this, gl_);
210211

211212
// Check for impeller support.
212213
auto& switches = project_->GetSwitches();

shell/platform/windows/flutter_windows_engine.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,6 @@ class FlutterWindowsEngine {
360360
// The texture registrar.
361361
std::unique_ptr<FlutterWindowsTextureRegistrar> texture_registrar_;
362362

363-
// Resolved OpenGL functions used by external texture implementations.
364-
GlProcs gl_procs_ = {};
365-
366363
// An object used for intializing Angle and creating / destroying render
367364
// surfaces. Surface creation functionality requires a valid render_target.
368365
// May be nullptr if ANGLE failed to initialize.
@@ -422,6 +419,8 @@ class FlutterWindowsEngine {
422419

423420
std::shared_ptr<WindowsProcTable> windows_proc_table_;
424421

422+
std::shared_ptr<GlProcTable> gl_;
423+
425424
FML_DISALLOW_COPY_AND_ASSIGN(FlutterWindowsEngine);
426425
};
427426

shell/platform/windows/flutter_windows_texture_registrar.cc

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ namespace flutter {
2020

2121
FlutterWindowsTextureRegistrar::FlutterWindowsTextureRegistrar(
2222
FlutterWindowsEngine* engine,
23-
const GlProcs& gl_procs)
24-
: engine_(engine), gl_procs_(gl_procs) {}
23+
std::shared_ptr<GlProcTable> gl)
24+
: engine_(engine), gl_(std::move(gl)) {}
2525

2626
int64_t FlutterWindowsTextureRegistrar::RegisterTexture(
2727
const FlutterDesktopTextureInfo* texture_info) {
28-
if (!gl_procs_.valid) {
28+
if (!gl_) {
2929
return kInvalidTexture;
3030
}
3131

@@ -37,7 +37,7 @@ int64_t FlutterWindowsTextureRegistrar::RegisterTexture(
3737

3838
return EmplaceTexture(std::make_unique<flutter::ExternalTexturePixelBuffer>(
3939
texture_info->pixel_buffer_config.callback,
40-
texture_info->pixel_buffer_config.user_data, gl_procs_));
40+
texture_info->pixel_buffer_config.user_data, gl_));
4141
} else if (texture_info->type == kFlutterDesktopGpuSurfaceTexture) {
4242
const FlutterDesktopGpuSurfaceTextureConfig* gpu_surface_config =
4343
&texture_info->gpu_surface_config;
@@ -53,8 +53,7 @@ int64_t FlutterWindowsTextureRegistrar::RegisterTexture(
5353

5454
auto user_data = SAFE_ACCESS(gpu_surface_config, user_data, nullptr);
5555
return EmplaceTexture(std::make_unique<flutter::ExternalTextureD3d>(
56-
surface_type, callback, user_data, engine_->surface_manager(),
57-
gl_procs_));
56+
surface_type, callback, user_data, engine_->surface_manager(), gl_));
5857
}
5958
}
6059

@@ -126,21 +125,4 @@ bool FlutterWindowsTextureRegistrar::PopulateTexture(
126125
return texture->PopulateTexture(width, height, opengl_texture);
127126
}
128127

129-
void FlutterWindowsTextureRegistrar::ResolveGlFunctions(GlProcs& procs) {
130-
procs.glGenTextures =
131-
reinterpret_cast<glGenTexturesProc>(eglGetProcAddress("glGenTextures"));
132-
procs.glDeleteTextures = reinterpret_cast<glDeleteTexturesProc>(
133-
eglGetProcAddress("glDeleteTextures"));
134-
procs.glBindTexture =
135-
reinterpret_cast<glBindTextureProc>(eglGetProcAddress("glBindTexture"));
136-
procs.glTexParameteri = reinterpret_cast<glTexParameteriProc>(
137-
eglGetProcAddress("glTexParameteri"));
138-
procs.glTexImage2D =
139-
reinterpret_cast<glTexImage2DProc>(eglGetProcAddress("glTexImage2D"));
140-
141-
procs.valid = procs.glGenTextures && procs.glDeleteTextures &&
142-
procs.glBindTexture && procs.glTexParameteri &&
143-
procs.glTexImage2D;
144-
}
145-
146128
}; // namespace flutter

0 commit comments

Comments
 (0)