[Windows] Refactor the GLES proc table (flutter/engine#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 https://github.com/flutter/flutter/issues/128904 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -14,18 +14,18 @@ ExternalTextureD3d::ExternalTextureD3d(
|
||||
const FlutterDesktopGpuSurfaceTextureCallback texture_callback,
|
||||
void* user_data,
|
||||
const AngleSurfaceManager* surface_manager,
|
||||
const GlProcs& gl_procs)
|
||||
std::shared_ptr<GlProcTable> 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);
|
||||
|
||||
@@ -5,9 +5,12 @@
|
||||
#ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_EXTERNAL_TEXTURE_D3D_H_
|
||||
#define FLUTTER_SHELL_PLATFORM_WINDOWS_EXTERNAL_TEXTURE_D3D_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#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<GlProcTable> 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<GlProcTable> gl_;
|
||||
GLuint gl_texture_ = 0;
|
||||
EGLSurface egl_surface_ = EGL_NO_SURFACE;
|
||||
void* last_surface_handle_ = nullptr;
|
||||
|
||||
@@ -9,14 +9,14 @@ namespace flutter {
|
||||
ExternalTexturePixelBuffer::ExternalTexturePixelBuffer(
|
||||
const FlutterDesktopPixelBufferTextureCallback texture_callback,
|
||||
void* user_data,
|
||||
const GlProcs& gl_procs)
|
||||
std::shared_ptr<GlProcTable> 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);
|
||||
}
|
||||
|
||||
@@ -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<GlProcTable> 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<GlProcTable> gl_;
|
||||
GLuint gl_texture_ = 0;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(ExternalTexturePixelBuffer);
|
||||
|
||||
@@ -168,6 +168,8 @@ FlutterWindowsEngine::FlutterWindowsEngine(
|
||||
windows_proc_table_ = std::make_shared<WindowsProcTable>();
|
||||
}
|
||||
|
||||
gl_ = GlProcTable::Create();
|
||||
|
||||
embedder_api_.struct_size = sizeof(FlutterEngineProcTable);
|
||||
FlutterEngineGetProcAddresses(&embedder_api_);
|
||||
|
||||
@@ -204,9 +206,8 @@ FlutterWindowsEngine::FlutterWindowsEngine(
|
||||
},
|
||||
static_cast<void*>(this));
|
||||
|
||||
FlutterWindowsTextureRegistrar::ResolveGlFunctions(gl_procs_);
|
||||
texture_registrar_ =
|
||||
std::make_unique<FlutterWindowsTextureRegistrar>(this, gl_procs_);
|
||||
std::make_unique<FlutterWindowsTextureRegistrar>(this, gl_);
|
||||
|
||||
// Check for impeller support.
|
||||
auto& switches = project_->GetSwitches();
|
||||
|
||||
@@ -360,9 +360,6 @@ class FlutterWindowsEngine {
|
||||
// The texture registrar.
|
||||
std::unique_ptr<FlutterWindowsTextureRegistrar> 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<WindowsProcTable> windows_proc_table_;
|
||||
|
||||
std::shared_ptr<GlProcTable> gl_;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(FlutterWindowsEngine);
|
||||
};
|
||||
|
||||
|
||||
@@ -20,12 +20,12 @@ namespace flutter {
|
||||
|
||||
FlutterWindowsTextureRegistrar::FlutterWindowsTextureRegistrar(
|
||||
FlutterWindowsEngine* engine,
|
||||
const GlProcs& gl_procs)
|
||||
: engine_(engine), gl_procs_(gl_procs) {}
|
||||
std::shared_ptr<GlProcTable> 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<flutter::ExternalTexturePixelBuffer>(
|
||||
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<flutter::ExternalTextureD3d>(
|
||||
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<glGenTexturesProc>(eglGetProcAddress("glGenTextures"));
|
||||
procs.glDeleteTextures = reinterpret_cast<glDeleteTexturesProc>(
|
||||
eglGetProcAddress("glDeleteTextures"));
|
||||
procs.glBindTexture =
|
||||
reinterpret_cast<glBindTextureProc>(eglGetProcAddress("glBindTexture"));
|
||||
procs.glTexParameteri = reinterpret_cast<glTexParameteriProc>(
|
||||
eglGetProcAddress("glTexParameteri"));
|
||||
procs.glTexImage2D =
|
||||
reinterpret_cast<glTexImage2DProc>(eglGetProcAddress("glTexImage2D"));
|
||||
|
||||
procs.valid = procs.glGenTextures && procs.glDeleteTextures &&
|
||||
procs.glBindTexture && procs.glTexParameteri &&
|
||||
procs.glTexImage2D;
|
||||
}
|
||||
|
||||
}; // namespace flutter
|
||||
|
||||
@@ -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<GlProcTable> 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<GlProcTable> gl_;
|
||||
|
||||
// All registered textures, keyed by their IDs.
|
||||
std::unordered_map<int64_t, std::unique_ptr<flutter::ExternalTexture>>
|
||||
|
||||
@@ -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<ID3D11Texture2D> CreateD3dTexture(FlutterWindowsEngine* engine,
|
||||
|
||||
TEST(FlutterWindowsTextureRegistrarTest, CreateDestroy) {
|
||||
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
|
||||
std::unique_ptr<MockGlFunctions> gl = std::make_unique<MockGlFunctions>();
|
||||
FlutterWindowsTextureRegistrar registrar(engine.get(), gl->gl_procs());
|
||||
std::shared_ptr<MockGlProcTable> gl = std::make_shared<MockGlProcTable>();
|
||||
FlutterWindowsTextureRegistrar registrar(engine.get(), gl);
|
||||
|
||||
EXPECT_TRUE(true);
|
||||
}
|
||||
@@ -71,9 +74,9 @@ TEST(FlutterWindowsTextureRegistrarTest, CreateDestroy) {
|
||||
TEST(FlutterWindowsTextureRegistrarTest, RegisterUnregisterTexture) {
|
||||
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
|
||||
EngineModifier modifier(engine.get());
|
||||
std::unique_ptr<MockGlFunctions> gl = std::make_unique<MockGlFunctions>();
|
||||
std::shared_ptr<MockGlProcTable> gl = std::make_shared<MockGlProcTable>();
|
||||
|
||||
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<FlutterWindowsEngine> engine = GetTestEngine();
|
||||
std::unique_ptr<MockGlFunctions> gl = std::make_unique<MockGlFunctions>();
|
||||
std::shared_ptr<MockGlProcTable> gl = std::make_shared<MockGlProcTable>();
|
||||
|
||||
FlutterWindowsTextureRegistrar registrar(engine.get(), gl->gl_procs());
|
||||
FlutterWindowsTextureRegistrar registrar(engine.get(), gl);
|
||||
|
||||
FlutterDesktopTextureInfo texture_info = {};
|
||||
texture_info.type = static_cast<FlutterDesktopTextureType>(1234);
|
||||
@@ -149,8 +152,9 @@ TEST(FlutterWindowsTextureRegistrarTest, RegisterUnknownTextureType) {
|
||||
|
||||
TEST(FlutterWindowsTextureRegistrarTest, PopulatePixelBufferTexture) {
|
||||
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
|
||||
std::unique_ptr<MockGlFunctions> gl = std::make_unique<MockGlFunctions>();
|
||||
FlutterWindowsTextureRegistrar registrar(engine.get(), gl->gl_procs());
|
||||
std::shared_ptr<MockGlProcTable> gl = std::make_shared<MockGlProcTable>();
|
||||
|
||||
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<FlutterWindowsEngine> engine = GetTestEngine();
|
||||
std::unique_ptr<MockGlFunctions> gl = std::make_unique<MockGlFunctions>();
|
||||
FlutterWindowsTextureRegistrar registrar(engine.get(), gl->gl_procs());
|
||||
std::shared_ptr<MockGlProcTable> gl = std::make_shared<MockGlProcTable>();
|
||||
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<FlutterWindowsEngine> engine = GetTestEngine();
|
||||
std::unique_ptr<MockGlFunctions> gl = std::make_unique<MockGlFunctions>();
|
||||
FlutterWindowsTextureRegistrar registrar(engine.get(), gl->gl_procs());
|
||||
std::shared_ptr<MockGlProcTable> gl = std::make_shared<MockGlProcTable>();
|
||||
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<FlutterWindowsEngine> engine = GetTestEngine();
|
||||
std::unique_ptr<MockGlFunctions> gl = std::make_unique<MockGlFunctions>();
|
||||
std::shared_ptr<MockGlProcTable> gl = std::make_shared<MockGlProcTable>();
|
||||
|
||||
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<FlutterWindowsEngine> engine = GetTestEngine();
|
||||
std::unique_ptr<MockGlFunctions> gl = std::make_unique<MockGlFunctions>();
|
||||
std::shared_ptr<MockGlProcTable> gl = std::make_shared<MockGlProcTable>();
|
||||
|
||||
FlutterWindowsTextureRegistrar registrar(engine.get(), gl->gl_procs());
|
||||
FlutterWindowsTextureRegistrar registrar(engine.get(), gl);
|
||||
|
||||
fml::AutoResetWaitableEvent latch;
|
||||
registrar.UnregisterTexture(1234, [&]() { latch.Signal(); });
|
||||
|
||||
68
engine/src/flutter/shell/platform/windows/gl_proc_table.cc
Normal file
68
engine/src/flutter/shell/platform/windows/gl_proc_table.cc
Normal file
@@ -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 <EGL/egl.h>
|
||||
|
||||
namespace flutter {
|
||||
|
||||
std::shared_ptr<GlProcTable> GlProcTable::Create() {
|
||||
auto gl = std::shared_ptr<GlProcTable>(new GlProcTable());
|
||||
|
||||
gl->gen_textures_ =
|
||||
reinterpret_cast<GenTexturesProc>(::eglGetProcAddress("glGenTextures"));
|
||||
gl->delete_textures_ = reinterpret_cast<DeleteTexturesProc>(
|
||||
::eglGetProcAddress("glDeleteTextures"));
|
||||
gl->bind_texture_ =
|
||||
reinterpret_cast<BindTextureProc>(::eglGetProcAddress("glBindTexture"));
|
||||
gl->tex_parameteri_ = reinterpret_cast<TexParameteriProc>(
|
||||
::eglGetProcAddress("glTexParameteri"));
|
||||
gl->tex_image_2d_ =
|
||||
reinterpret_cast<TexImage2DProc>(::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
|
||||
70
engine/src/flutter/shell/platform/windows/gl_proc_table.h
Normal file
70
engine/src/flutter/shell/platform/windows/gl_proc_table.h
Normal file
@@ -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 <GLES2/gl2.h>
|
||||
#include <GLES2/gl2ext.h>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
|
||||
namespace flutter {
|
||||
|
||||
// Lookup table for GLES functions.
|
||||
class GlProcTable {
|
||||
public:
|
||||
static std::shared_ptr<GlProcTable> 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_
|
||||
@@ -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_
|
||||
@@ -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_
|
||||
Reference in New Issue
Block a user