diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 049e1c372e03c..c61168f67d35e 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -7138,6 +7138,8 @@ ORIGIN: ../../../flutter/shell/platform/windows/flutter_windows_texture_registra ORIGIN: ../../../flutter/shell/platform/windows/flutter_windows_view.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/windows/flutter_windows_view.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/windows/flutter_windows_view_controller.h + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/shell/platform/windows/gl_proc_table.cc + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/shell/platform/windows/gl_proc_table.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/windows/keyboard_handler_base.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/windows/keyboard_key_channel_handler.cc + ../../../flutter/LICENSE 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. FILE: ../../../flutter/shell/platform/windows/flutter_windows_view.cc FILE: ../../../flutter/shell/platform/windows/flutter_windows_view.h FILE: ../../../flutter/shell/platform/windows/flutter_windows_view_controller.h +FILE: ../../../flutter/shell/platform/windows/gl_proc_table.cc +FILE: ../../../flutter/shell/platform/windows/gl_proc_table.h FILE: ../../../flutter/shell/platform/windows/keyboard_handler_base.h FILE: ../../../flutter/shell/platform/windows/keyboard_key_channel_handler.cc FILE: ../../../flutter/shell/platform/windows/keyboard_key_channel_handler.h diff --git a/shell/platform/windows/BUILD.gn b/shell/platform/windows/BUILD.gn index 9a3a8c59dbb8e..433736a42ff66 100644 --- a/shell/platform/windows/BUILD.gn +++ b/shell/platform/windows/BUILD.gn @@ -70,6 +70,8 @@ source_set("flutter_windows_source") { "flutter_windows_view.cc", "flutter_windows_view.h", "flutter_windows_view_controller.h", + "gl_proc_table.cc", + "gl_proc_table.h", "keyboard_handler_base.h", "keyboard_key_channel_handler.cc", "keyboard_key_channel_handler.h", @@ -198,7 +200,7 @@ executable("flutter_windows_unittests") { "testing/flutter_windows_engine_builder.cc", "testing/flutter_windows_engine_builder.h", "testing/mock_direct_manipulation.h", - "testing/mock_gl_functions.h", + "testing/mock_gl_proc_table.h", "testing/mock_text_input_manager.cc", "testing/mock_text_input_manager.h", "testing/mock_window.cc", diff --git a/shell/platform/windows/external_texture.h b/shell/platform/windows/external_texture.h index be51f0bdf6487..26e9287edd43d 100644 --- a/shell/platform/windows/external_texture.h +++ b/shell/platform/windows/external_texture.h @@ -12,30 +12,6 @@ namespace flutter { -typedef void (*glGenTexturesProc)(GLsizei n, GLuint* textures); -typedef void (*glDeleteTexturesProc)(GLsizei n, const GLuint* textures); -typedef void (*glBindTextureProc)(GLenum target, GLuint texture); -typedef void (*glTexParameteriProc)(GLenum target, GLenum pname, GLint param); -typedef void (*glTexImage2DProc)(GLenum target, - GLint level, - GLint internalformat, - GLsizei width, - GLsizei height, - GLint border, - GLenum format, - GLenum type, - const void* data); - -// A struct containing pointers to resolved gl* functions. -struct GlProcs { - glGenTexturesProc glGenTextures; - glDeleteTexturesProc glDeleteTextures; - glBindTextureProc glBindTexture; - glTexParameteriProc glTexParameteri; - glTexImage2DProc glTexImage2D; - bool valid; -}; - // Abstract external texture. class ExternalTexture { public: diff --git a/shell/platform/windows/external_texture_d3d.cc b/shell/platform/windows/external_texture_d3d.cc index 7e5a84b6d5c26..1b3d776837b84 100644 --- a/shell/platform/windows/external_texture_d3d.cc +++ b/shell/platform/windows/external_texture_d3d.cc @@ -14,18 +14,18 @@ ExternalTextureD3d::ExternalTextureD3d( const FlutterDesktopGpuSurfaceTextureCallback texture_callback, void* user_data, const AngleSurfaceManager* surface_manager, - const GlProcs& gl_procs) + std::shared_ptr gl) : type_(type), texture_callback_(texture_callback), user_data_(user_data), surface_manager_(surface_manager), - gl_(gl_procs) {} + gl_(std::move(gl)) {} ExternalTextureD3d::~ExternalTextureD3d() { ReleaseImage(); if (gl_texture_ != 0) { - gl_.glDeleteTextures(1, &gl_texture_); + gl_->DeleteTextures(1, &gl_texture_); } } @@ -69,15 +69,15 @@ bool ExternalTextureD3d::CreateOrUpdateTexture( } if (gl_texture_ == 0) { - gl_.glGenTextures(1, &gl_texture_); + gl_->GenTextures(1, &gl_texture_); - gl_.glBindTexture(GL_TEXTURE_2D, gl_texture_); - gl_.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - gl_.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - gl_.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - gl_.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + gl_->BindTexture(GL_TEXTURE_2D, gl_texture_); + gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); } else { - gl_.glBindTexture(GL_TEXTURE_2D, gl_texture_); + gl_->BindTexture(GL_TEXTURE_2D, gl_texture_); } auto handle = SAFE_ACCESS(descriptor, handle, nullptr); diff --git a/shell/platform/windows/external_texture_d3d.h b/shell/platform/windows/external_texture_d3d.h index 81b9434b1f84f..1e0d8f125e130 100644 --- a/shell/platform/windows/external_texture_d3d.h +++ b/shell/platform/windows/external_texture_d3d.h @@ -5,9 +5,12 @@ #ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_EXTERNAL_TEXTURE_D3D_H_ #define FLUTTER_SHELL_PLATFORM_WINDOWS_EXTERNAL_TEXTURE_D3D_H_ +#include + #include "flutter/fml/macros.h" #include "flutter/shell/platform/windows/angle_surface_manager.h" #include "flutter/shell/platform/windows/external_texture.h" +#include "flutter/shell/platform/windows/gl_proc_table.h" namespace flutter { @@ -19,7 +22,7 @@ class ExternalTextureD3d : public ExternalTexture { const FlutterDesktopGpuSurfaceTextureCallback texture_callback, void* user_data, const AngleSurfaceManager* surface_manager, - const GlProcs& gl_procs); + std::shared_ptr gl); virtual ~ExternalTextureD3d(); // |ExternalTexture| @@ -39,7 +42,7 @@ class ExternalTextureD3d : public ExternalTexture { const FlutterDesktopGpuSurfaceTextureCallback texture_callback_; void* const user_data_; const AngleSurfaceManager* surface_manager_; - const GlProcs& gl_; + std::shared_ptr gl_; GLuint gl_texture_ = 0; EGLSurface egl_surface_ = EGL_NO_SURFACE; void* last_surface_handle_ = nullptr; diff --git a/shell/platform/windows/external_texture_pixelbuffer.cc b/shell/platform/windows/external_texture_pixelbuffer.cc index 802eeef9e578c..6cd533ca9687c 100644 --- a/shell/platform/windows/external_texture_pixelbuffer.cc +++ b/shell/platform/windows/external_texture_pixelbuffer.cc @@ -9,14 +9,14 @@ namespace flutter { ExternalTexturePixelBuffer::ExternalTexturePixelBuffer( const FlutterDesktopPixelBufferTextureCallback texture_callback, void* user_data, - const GlProcs& gl_procs) + std::shared_ptr gl) : texture_callback_(texture_callback), user_data_(user_data), - gl_(gl_procs) {} + gl_(std::move(gl)) {} ExternalTexturePixelBuffer::~ExternalTexturePixelBuffer() { if (gl_texture_ != 0) { - gl_.glDeleteTextures(1, &gl_texture_); + gl_->DeleteTextures(1, &gl_texture_); } } @@ -51,20 +51,20 @@ bool ExternalTexturePixelBuffer::CopyPixelBuffer(size_t& width, height = pixel_buffer->height; if (gl_texture_ == 0) { - gl_.glGenTextures(1, &gl_texture_); + gl_->GenTextures(1, &gl_texture_); - gl_.glBindTexture(GL_TEXTURE_2D, gl_texture_); - gl_.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - gl_.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - gl_.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - gl_.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + gl_->BindTexture(GL_TEXTURE_2D, gl_texture_); + gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); } else { - gl_.glBindTexture(GL_TEXTURE_2D, gl_texture_); + gl_->BindTexture(GL_TEXTURE_2D, gl_texture_); } - gl_.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pixel_buffer->width, - pixel_buffer->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, - pixel_buffer->buffer); + gl_->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pixel_buffer->width, + pixel_buffer->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, + pixel_buffer->buffer); if (pixel_buffer->release_callback) { pixel_buffer->release_callback(pixel_buffer->release_context); } diff --git a/shell/platform/windows/external_texture_pixelbuffer.h b/shell/platform/windows/external_texture_pixelbuffer.h index 38ac196130176..56d46a168fc30 100644 --- a/shell/platform/windows/external_texture_pixelbuffer.h +++ b/shell/platform/windows/external_texture_pixelbuffer.h @@ -8,6 +8,7 @@ #include "flutter/fml/macros.h" #include "flutter/shell/platform/common/public/flutter_texture_registrar.h" #include "flutter/shell/platform/windows/external_texture.h" +#include "flutter/shell/platform/windows/gl_proc_table.h" namespace flutter { @@ -17,7 +18,7 @@ class ExternalTexturePixelBuffer : public ExternalTexture { ExternalTexturePixelBuffer( const FlutterDesktopPixelBufferTextureCallback texture_callback, void* user_data, - const GlProcs& gl_procs); + std::shared_ptr gl); virtual ~ExternalTexturePixelBuffer(); @@ -37,7 +38,7 @@ class ExternalTexturePixelBuffer : public ExternalTexture { const FlutterDesktopPixelBufferTextureCallback texture_callback_ = nullptr; void* const user_data_ = nullptr; - const GlProcs& gl_; + std::shared_ptr gl_; GLuint gl_texture_ = 0; FML_DISALLOW_COPY_AND_ASSIGN(ExternalTexturePixelBuffer); diff --git a/shell/platform/windows/flutter_windows_engine.cc b/shell/platform/windows/flutter_windows_engine.cc index d58a576eae099..ae0dded84464d 100644 --- a/shell/platform/windows/flutter_windows_engine.cc +++ b/shell/platform/windows/flutter_windows_engine.cc @@ -168,6 +168,8 @@ FlutterWindowsEngine::FlutterWindowsEngine( windows_proc_table_ = std::make_shared(); } + gl_ = GlProcTable::Create(); + embedder_api_.struct_size = sizeof(FlutterEngineProcTable); FlutterEngineGetProcAddresses(&embedder_api_); @@ -204,9 +206,8 @@ FlutterWindowsEngine::FlutterWindowsEngine( }, static_cast(this)); - FlutterWindowsTextureRegistrar::ResolveGlFunctions(gl_procs_); texture_registrar_ = - std::make_unique(this, gl_procs_); + std::make_unique(this, gl_); // Check for impeller support. auto& switches = project_->GetSwitches(); diff --git a/shell/platform/windows/flutter_windows_engine.h b/shell/platform/windows/flutter_windows_engine.h index ff7f6e4a33b2d..a14b8854817a0 100644 --- a/shell/platform/windows/flutter_windows_engine.h +++ b/shell/platform/windows/flutter_windows_engine.h @@ -360,9 +360,6 @@ class FlutterWindowsEngine { // The texture registrar. std::unique_ptr texture_registrar_; - // Resolved OpenGL functions used by external texture implementations. - GlProcs gl_procs_ = {}; - // An object used for intializing Angle and creating / destroying render // surfaces. Surface creation functionality requires a valid render_target. // May be nullptr if ANGLE failed to initialize. @@ -422,6 +419,8 @@ class FlutterWindowsEngine { std::shared_ptr windows_proc_table_; + std::shared_ptr gl_; + FML_DISALLOW_COPY_AND_ASSIGN(FlutterWindowsEngine); }; diff --git a/shell/platform/windows/flutter_windows_texture_registrar.cc b/shell/platform/windows/flutter_windows_texture_registrar.cc index c3371b8d7b5ca..e2a6d547e3627 100644 --- a/shell/platform/windows/flutter_windows_texture_registrar.cc +++ b/shell/platform/windows/flutter_windows_texture_registrar.cc @@ -20,12 +20,12 @@ namespace flutter { FlutterWindowsTextureRegistrar::FlutterWindowsTextureRegistrar( FlutterWindowsEngine* engine, - const GlProcs& gl_procs) - : engine_(engine), gl_procs_(gl_procs) {} + std::shared_ptr gl) + : engine_(engine), gl_(std::move(gl)) {} int64_t FlutterWindowsTextureRegistrar::RegisterTexture( const FlutterDesktopTextureInfo* texture_info) { - if (!gl_procs_.valid) { + if (!gl_) { return kInvalidTexture; } @@ -37,7 +37,7 @@ int64_t FlutterWindowsTextureRegistrar::RegisterTexture( return EmplaceTexture(std::make_unique( texture_info->pixel_buffer_config.callback, - texture_info->pixel_buffer_config.user_data, gl_procs_)); + texture_info->pixel_buffer_config.user_data, gl_)); } else if (texture_info->type == kFlutterDesktopGpuSurfaceTexture) { const FlutterDesktopGpuSurfaceTextureConfig* gpu_surface_config = &texture_info->gpu_surface_config; @@ -53,8 +53,7 @@ int64_t FlutterWindowsTextureRegistrar::RegisterTexture( auto user_data = SAFE_ACCESS(gpu_surface_config, user_data, nullptr); return EmplaceTexture(std::make_unique( - surface_type, callback, user_data, engine_->surface_manager(), - gl_procs_)); + surface_type, callback, user_data, engine_->surface_manager(), gl_)); } } @@ -126,21 +125,4 @@ bool FlutterWindowsTextureRegistrar::PopulateTexture( return texture->PopulateTexture(width, height, opengl_texture); } -void FlutterWindowsTextureRegistrar::ResolveGlFunctions(GlProcs& procs) { - procs.glGenTextures = - reinterpret_cast(eglGetProcAddress("glGenTextures")); - procs.glDeleteTextures = reinterpret_cast( - eglGetProcAddress("glDeleteTextures")); - procs.glBindTexture = - reinterpret_cast(eglGetProcAddress("glBindTexture")); - procs.glTexParameteri = reinterpret_cast( - eglGetProcAddress("glTexParameteri")); - procs.glTexImage2D = - reinterpret_cast(eglGetProcAddress("glTexImage2D")); - - procs.valid = procs.glGenTextures && procs.glDeleteTextures && - procs.glBindTexture && procs.glTexParameteri && - procs.glTexImage2D; -} - }; // namespace flutter diff --git a/shell/platform/windows/flutter_windows_texture_registrar.h b/shell/platform/windows/flutter_windows_texture_registrar.h index 45c1c1d39bffe..a72edf498202d 100644 --- a/shell/platform/windows/flutter_windows_texture_registrar.h +++ b/shell/platform/windows/flutter_windows_texture_registrar.h @@ -13,6 +13,7 @@ #include "flutter/fml/macros.h" #include "flutter/shell/platform/common/public/flutter_texture_registrar.h" #include "flutter/shell/platform/windows/external_texture.h" +#include "flutter/shell/platform/windows/gl_proc_table.h" namespace flutter { @@ -23,7 +24,7 @@ class FlutterWindowsEngine; class FlutterWindowsTextureRegistrar { public: explicit FlutterWindowsTextureRegistrar(FlutterWindowsEngine* engine, - const GlProcs& gl_procs); + std::shared_ptr gl); // Registers a texture described by the given |texture_info| object. // Returns the non-zero, positive texture id or -1 on error. @@ -44,12 +45,9 @@ class FlutterWindowsTextureRegistrar { size_t height, FlutterOpenGLTexture* texture); - // Populates the OpenGL function pointers in |gl_procs|. - static void ResolveGlFunctions(GlProcs& gl_procs); - private: FlutterWindowsEngine* engine_ = nullptr; - const GlProcs& gl_procs_; + std::shared_ptr gl_; // All registered textures, keyed by their IDs. std::unordered_map> diff --git a/shell/platform/windows/flutter_windows_texture_registrar_unittests.cc b/shell/platform/windows/flutter_windows_texture_registrar_unittests.cc index f3bdcb335c255..e5e7337f7d084 100644 --- a/shell/platform/windows/flutter_windows_texture_registrar_unittests.cc +++ b/shell/platform/windows/flutter_windows_texture_registrar_unittests.cc @@ -7,12 +7,15 @@ #include "flutter/shell/platform/windows/flutter_windows_engine.h" #include "flutter/shell/platform/windows/flutter_windows_texture_registrar.h" #include "flutter/shell/platform/windows/testing/engine_modifier.h" -#include "flutter/shell/platform/windows/testing/mock_gl_functions.h" +#include "flutter/shell/platform/windows/testing/mock_gl_proc_table.h" #include "gtest/gtest.h" namespace flutter { namespace testing { +using ::testing::_; +using ::testing::AtLeast; + using Microsoft::WRL::ComPtr; namespace { @@ -62,8 +65,8 @@ ComPtr CreateD3dTexture(FlutterWindowsEngine* engine, TEST(FlutterWindowsTextureRegistrarTest, CreateDestroy) { std::unique_ptr engine = GetTestEngine(); - std::unique_ptr gl = std::make_unique(); - FlutterWindowsTextureRegistrar registrar(engine.get(), gl->gl_procs()); + std::shared_ptr gl = std::make_shared(); + FlutterWindowsTextureRegistrar registrar(engine.get(), gl); EXPECT_TRUE(true); } @@ -71,9 +74,9 @@ TEST(FlutterWindowsTextureRegistrarTest, CreateDestroy) { TEST(FlutterWindowsTextureRegistrarTest, RegisterUnregisterTexture) { std::unique_ptr engine = GetTestEngine(); EngineModifier modifier(engine.get()); - std::unique_ptr gl = std::make_unique(); + std::shared_ptr gl = std::make_shared(); - FlutterWindowsTextureRegistrar registrar(engine.get(), gl->gl_procs()); + FlutterWindowsTextureRegistrar registrar(engine.get(), gl); FlutterDesktopTextureInfo texture_info = {}; texture_info.type = kFlutterDesktopPixelBufferTexture; @@ -135,9 +138,9 @@ TEST(FlutterWindowsTextureRegistrarTest, RegisterUnregisterTexture) { TEST(FlutterWindowsTextureRegistrarTest, RegisterUnknownTextureType) { std::unique_ptr engine = GetTestEngine(); - std::unique_ptr gl = std::make_unique(); + std::shared_ptr gl = std::make_shared(); - FlutterWindowsTextureRegistrar registrar(engine.get(), gl->gl_procs()); + FlutterWindowsTextureRegistrar registrar(engine.get(), gl); FlutterDesktopTextureInfo texture_info = {}; texture_info.type = static_cast(1234); @@ -149,8 +152,9 @@ TEST(FlutterWindowsTextureRegistrarTest, RegisterUnknownTextureType) { TEST(FlutterWindowsTextureRegistrarTest, PopulatePixelBufferTexture) { std::unique_ptr engine = GetTestEngine(); - std::unique_ptr gl = std::make_unique(); - FlutterWindowsTextureRegistrar registrar(engine.get(), gl->gl_procs()); + std::shared_ptr gl = std::make_shared(); + + FlutterWindowsTextureRegistrar registrar(engine.get(), gl); bool release_callback_called = false; size_t width = 100; @@ -180,6 +184,14 @@ TEST(FlutterWindowsTextureRegistrarTest, PopulatePixelBufferTexture) { auto texture_id = registrar.RegisterTexture(&texture_info); EXPECT_NE(texture_id, -1); + EXPECT_CALL(*gl.get(), GenTextures(1, _)) + .Times(1) + .WillOnce([](GLsizei n, GLuint* textures) { textures[0] = 1; }); + EXPECT_CALL(*gl.get(), BindTexture).Times(1); + EXPECT_CALL(*gl.get(), TexParameteri).Times(AtLeast(1)); + EXPECT_CALL(*gl.get(), TexImage2D).Times(1); + EXPECT_CALL(*gl.get(), DeleteTextures(1, _)).Times(1); + auto result = registrar.PopulateTexture(texture_id, 640, 480, &flutter_texture); EXPECT_TRUE(result); @@ -191,8 +203,8 @@ TEST(FlutterWindowsTextureRegistrarTest, PopulatePixelBufferTexture) { TEST(FlutterWindowsTextureRegistrarTest, PopulateD3dTextureWithHandle) { std::unique_ptr engine = GetTestEngine(); - std::unique_ptr gl = std::make_unique(); - FlutterWindowsTextureRegistrar registrar(engine.get(), gl->gl_procs()); + std::shared_ptr gl = std::make_shared(); + FlutterWindowsTextureRegistrar registrar(engine.get(), gl); UINT width = 100; UINT height = 100; @@ -235,6 +247,13 @@ TEST(FlutterWindowsTextureRegistrarTest, PopulateD3dTextureWithHandle) { auto texture_id = registrar.RegisterTexture(&texture_info); EXPECT_NE(texture_id, -1); + EXPECT_CALL(*gl.get(), GenTextures(1, _)) + .Times(1) + .WillOnce([](GLsizei n, GLuint* textures) { textures[0] = 1; }); + EXPECT_CALL(*gl.get(), BindTexture).Times(1); + EXPECT_CALL(*gl.get(), TexParameteri).Times(AtLeast(1)); + EXPECT_CALL(*gl.get(), DeleteTextures(1, _)).Times(1); + auto result = registrar.PopulateTexture(texture_id, 640, 480, &flutter_texture); EXPECT_TRUE(result); @@ -246,8 +265,8 @@ TEST(FlutterWindowsTextureRegistrarTest, PopulateD3dTextureWithHandle) { TEST(FlutterWindowsTextureRegistrarTest, PopulateD3dTexture) { std::unique_ptr engine = GetTestEngine(); - std::unique_ptr gl = std::make_unique(); - FlutterWindowsTextureRegistrar registrar(engine.get(), gl->gl_procs()); + std::shared_ptr gl = std::make_shared(); + FlutterWindowsTextureRegistrar registrar(engine.get(), gl); UINT width = 100; UINT height = 100; @@ -284,6 +303,13 @@ TEST(FlutterWindowsTextureRegistrarTest, PopulateD3dTexture) { auto texture_id = registrar.RegisterTexture(&texture_info); EXPECT_NE(texture_id, -1); + EXPECT_CALL(*gl.get(), GenTextures(1, _)) + .Times(1) + .WillOnce([](GLsizei n, GLuint* textures) { textures[0] = 1; }); + EXPECT_CALL(*gl.get(), BindTexture).Times(1); + EXPECT_CALL(*gl.get(), TexParameteri).Times(AtLeast(1)); + EXPECT_CALL(*gl.get(), DeleteTextures(1, _)).Times(1); + auto result = registrar.PopulateTexture(texture_id, 640, 480, &flutter_texture); EXPECT_TRUE(result); @@ -295,9 +321,9 @@ TEST(FlutterWindowsTextureRegistrarTest, PopulateD3dTexture) { TEST(FlutterWindowsTextureRegistrarTest, PopulateInvalidTexture) { std::unique_ptr engine = GetTestEngine(); - std::unique_ptr gl = std::make_unique(); + std::shared_ptr gl = std::make_shared(); - FlutterWindowsTextureRegistrar registrar(engine.get(), gl->gl_procs()); + FlutterWindowsTextureRegistrar registrar(engine.get(), gl); auto result = registrar.PopulateTexture(1, 640, 480, nullptr); EXPECT_FALSE(result); @@ -306,9 +332,9 @@ TEST(FlutterWindowsTextureRegistrarTest, PopulateInvalidTexture) { TEST(FlutterWindowsTextureRegistrarTest, UnregisterTextureWithEngineDownInvokesCallback) { std::unique_ptr engine = GetTestEngine(); - std::unique_ptr gl = std::make_unique(); + std::shared_ptr gl = std::make_shared(); - FlutterWindowsTextureRegistrar registrar(engine.get(), gl->gl_procs()); + FlutterWindowsTextureRegistrar registrar(engine.get(), gl); fml::AutoResetWaitableEvent latch; registrar.UnregisterTexture(1234, [&]() { latch.Signal(); }); diff --git a/shell/platform/windows/gl_proc_table.cc b/shell/platform/windows/gl_proc_table.cc new file mode 100644 index 0000000000000..8f9b0ac1a52f1 --- /dev/null +++ b/shell/platform/windows/gl_proc_table.cc @@ -0,0 +1,68 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "flutter/shell/platform/windows/gl_proc_table.h" + +#include + +namespace flutter { + +std::shared_ptr GlProcTable::Create() { + auto gl = std::shared_ptr(new GlProcTable()); + + gl->gen_textures_ = + reinterpret_cast(::eglGetProcAddress("glGenTextures")); + gl->delete_textures_ = reinterpret_cast( + ::eglGetProcAddress("glDeleteTextures")); + gl->bind_texture_ = + reinterpret_cast(::eglGetProcAddress("glBindTexture")); + gl->tex_parameteri_ = reinterpret_cast( + ::eglGetProcAddress("glTexParameteri")); + gl->tex_image_2d_ = + reinterpret_cast(::eglGetProcAddress("glTexImage2D")); + + if (!gl->gen_textures_ || !gl->delete_textures_ || !gl->bind_texture_ || + !gl->tex_parameteri_ || !gl->tex_image_2d_) { + return nullptr; + } + + return gl; +} + +GlProcTable::GlProcTable() = default; + +GlProcTable::~GlProcTable() = default; + +void GlProcTable::GenTextures(GLsizei n, GLuint* textures) const { + gen_textures_(n, textures); +} + +void GlProcTable::DeleteTextures(GLsizei n, const GLuint* textures) const { + delete_textures_(n, textures); +} + +void GlProcTable::BindTexture(GLenum target, GLuint texture) const { + bind_texture_(target, texture); +} + +void GlProcTable::TexParameteri(GLenum target, + GLenum pname, + GLint param) const { + tex_parameteri_(target, pname, param); +} + +void GlProcTable::TexImage2D(GLenum target, + GLint level, + GLint internalformat, + GLsizei width, + GLsizei height, + GLint border, + GLenum format, + GLenum type, + const void* data) const { + tex_image_2d_(target, level, internalformat, width, height, border, format, + type, data); +} + +} // namespace flutter diff --git a/shell/platform/windows/gl_proc_table.h b/shell/platform/windows/gl_proc_table.h new file mode 100644 index 0000000000000..e0f75ff5e6f58 --- /dev/null +++ b/shell/platform/windows/gl_proc_table.h @@ -0,0 +1,70 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_GL_PROC_TABLE_H_ +#define FLUTTER_SHELL_PLATFORM_WINDOWS_GL_PROC_TABLE_H_ + +#include +#include +#include +#include + +#include "flutter/fml/macros.h" + +namespace flutter { + +// Lookup table for GLES functions. +class GlProcTable { + public: + static std::shared_ptr Create(); + + virtual ~GlProcTable(); + + virtual void GenTextures(GLsizei n, GLuint* textures) const; + virtual void DeleteTextures(GLsizei n, const GLuint* textures) const; + virtual void BindTexture(GLenum target, GLuint texture) const; + virtual void TexParameteri(GLenum target, GLenum pname, GLint param) const; + virtual void TexImage2D(GLenum target, + GLint level, + GLint internalformat, + GLsizei width, + GLsizei height, + GLint border, + GLenum format, + GLenum type, + const void* data) const; + + protected: + GlProcTable(); + + private: + using GenTexturesProc = void(__stdcall*)(GLsizei n, GLuint* textures); + using DeleteTexturesProc = void(__stdcall*)(GLsizei n, + const GLuint* textures); + using BindTextureProc = void(__stdcall*)(GLenum target, GLuint texture); + using TexParameteriProc = void(__stdcall*)(GLenum target, + GLenum pname, + GLint param); + using TexImage2DProc = void(__stdcall*)(GLenum target, + GLint level, + GLint internalformat, + GLsizei width, + GLsizei height, + GLint border, + GLenum format, + GLenum type, + const void* data); + + GenTexturesProc gen_textures_; + DeleteTexturesProc delete_textures_; + BindTextureProc bind_texture_; + TexParameteriProc tex_parameteri_; + TexImage2DProc tex_image_2d_; + + FML_DISALLOW_COPY_AND_ASSIGN(GlProcTable); +}; + +} // namespace flutter + +#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_GL_PROC_TABLE_H_ diff --git a/shell/platform/windows/testing/mock_gl_functions.h b/shell/platform/windows/testing/mock_gl_functions.h deleted file mode 100644 index 847d822ee8573..0000000000000 --- a/shell/platform/windows/testing/mock_gl_functions.h +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_TESTING_MOCK_GL_FUNCTIONS_H_ -#define FLUTTER_SHELL_PLATFORM_WINDOWS_TESTING_MOCK_GL_FUNCTIONS_H_ - -#include "flutter/fml/macros.h" -#include "flutter/shell/platform/windows/external_texture.h" - -namespace flutter { -namespace testing { - -// A class providing a mocked subset of OpenGL API functions. -class MockGlFunctions { - public: - MockGlFunctions() { - gl_procs_.glGenTextures = &glGenTextures; - gl_procs_.glDeleteTextures = &glDeleteTextures; - gl_procs_.glBindTexture = &glBindTexture; - gl_procs_.glTexParameteri = &glTexParameteri; - gl_procs_.glTexImage2D = &glTexImage2D; - gl_procs_.valid = true; - } - - const GlProcs& gl_procs() { return gl_procs_; } - - static void glGenTextures(GLsizei n, GLuint* textures) { - // The minimum valid texture ID is 1 - for (auto i = 0; i < n; i++) { - textures[i] = i + 1; - } - } - - static void glDeleteTextures(GLsizei n, const GLuint* textures) {} - static void glBindTexture(GLenum target, GLuint texture) {} - static void glTexParameteri(GLenum target, GLenum pname, GLint param) {} - static void glTexImage2D(GLenum target, - GLint level, - GLint internalformat, - GLsizei width, - GLsizei height, - GLint border, - GLenum format, - GLenum type, - const void* data) {} - - private: - GlProcs gl_procs_; - - FML_DISALLOW_COPY_AND_ASSIGN(MockGlFunctions); -}; - -} // namespace testing -} // namespace flutter - -#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_TESTING_MOCK_GL_FUNCTIONS_H_ diff --git a/shell/platform/windows/testing/mock_gl_proc_table.h b/shell/platform/windows/testing/mock_gl_proc_table.h new file mode 100644 index 0000000000000..ad4c17efba96c --- /dev/null +++ b/shell/platform/windows/testing/mock_gl_proc_table.h @@ -0,0 +1,57 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_TESTING_MOCK_GL_PROC_TABLE_H_ +#define FLUTTER_SHELL_PLATFORM_WINDOWS_TESTING_MOCK_GL_PROC_TABLE_H_ + +#include "flutter/fml/macros.h" +#include "flutter/shell/platform/windows/gl_proc_table.h" +#include "gmock/gmock.h" + +namespace flutter { +namespace testing { + +/// Mock for the |GlProcTable| base class. +class MockGlProcTable : public GlProcTable { + public: + MockGlProcTable() = default; + virtual ~MockGlProcTable() = default; + + MOCK_METHOD(void, + GenTextures, + (GLsizei n, GLuint* textures), + (const override)); + MOCK_METHOD(void, + DeleteTextures, + (GLsizei n, const GLuint* textures), + (const override)); + MOCK_METHOD(void, + BindTexture, + (GLenum target, GLuint texture), + (const override)); + MOCK_METHOD(void, + TexParameteri, + (GLenum target, GLenum pname, GLint param), + (const override)); + MOCK_METHOD(void, + TexImage2D, + (GLenum target, + GLint level, + GLint internalformat, + GLsizei width, + GLsizei height, + GLint border, + GLenum format, + GLenum type, + const void* data), + (const override)); + + private: + FML_DISALLOW_COPY_AND_ASSIGN(MockGlProcTable); +}; + +} // namespace testing +} // namespace flutter + +#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_TESTING_MOCK_GL_PROC_TABLE_H_