Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion shell/platform/windows/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
24 changes: 0 additions & 24 deletions shell/platform/windows/external_texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 10 additions & 10 deletions shell/platform/windows/external_texture_d3d.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
}
}

Expand Down Expand Up @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions shell/platform/windows/external_texture_d3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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|
Expand All @@ -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;
Expand Down
26 changes: 13 additions & 13 deletions shell/platform/windows/external_texture_pixelbuffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
}
}

Expand Down Expand Up @@ -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);
}
Expand Down
5 changes: 3 additions & 2 deletions shell/platform/windows/external_texture_pixelbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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();

Expand All @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions shell/platform/windows/flutter_windows_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_);

Expand Down Expand Up @@ -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();
Expand Down
5 changes: 2 additions & 3 deletions shell/platform/windows/flutter_windows_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -422,6 +419,8 @@ class FlutterWindowsEngine {

std::shared_ptr<WindowsProcTable> windows_proc_table_;

std::shared_ptr<GlProcTable> gl_;

FML_DISALLOW_COPY_AND_ASSIGN(FlutterWindowsEngine);
};

Expand Down
28 changes: 5 additions & 23 deletions shell/platform/windows/flutter_windows_texture_registrar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
Expand All @@ -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_));
}
}

Expand Down Expand Up @@ -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
8 changes: 3 additions & 5 deletions shell/platform/windows/flutter_windows_texture_registrar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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.
Expand All @@ -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>>
Expand Down
Loading