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
46 changes: 36 additions & 10 deletions shell/gpu/gpu_surface_gl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#define GPU_GL_RGBA8 0x8058
#define GPU_GL_RGBA4 0x8056
#define GPU_GL_RGB565 0x8D62
#define GPU_GL_VERSION 0x1F02

#ifdef ERROR
#undef ERROR
Expand All @@ -36,6 +37,9 @@ static const int kGrCacheMaxCount = 8192;
// cache.
static const size_t kGrCacheMaxByteSize = 512 * (1 << 20);

// Version string prefix that identifies an OpenGL ES implementation.
static const char kGLESVersionPrefix[] = "OpenGL ES";

GPUSurfaceGL::GPUSurfaceGL(GPUSurfaceGLDelegate* delegate)
: delegate_(delegate), weak_factory_(this) {
if (!delegate_->GLContextMakeCurrent()) {
Expand All @@ -56,16 +60,24 @@ GPUSurfaceGL::GPUSurfaceGL(GPUSurfaceGLDelegate* delegate)
// ES2 shading language when the ES3 external image extension is missing.
options.fPreferExternalImagesOverES3 = true;

auto interface =
proc_resolver_
? GrGLMakeAssembledGLESInterface(
this /* context */,
[](void* context, const char gl_proc_name[]) -> GrGLFuncPtr {
return reinterpret_cast<GrGLFuncPtr>(
reinterpret_cast<GPUSurfaceGL*>(context)->proc_resolver_(
gl_proc_name));
})
: GrGLMakeNativeInterface();
sk_sp<const GrGLInterface> interface;

if (proc_resolver_ == nullptr) {
interface = GrGLMakeNativeInterface();
} else {
auto gl_get_proc = [](void* context,
const char gl_proc_name[]) -> GrGLFuncPtr {
return reinterpret_cast<GrGLFuncPtr>(
reinterpret_cast<GPUSurfaceGL*>(context)->proc_resolver_(
gl_proc_name));
};

if (IsProcResolverOpenGLES()) {
interface = GrGLMakeAssembledGLESInterface(this, gl_get_proc);
} else {
interface = GrGLMakeAssembledGLInterface(this, gl_get_proc);
}
}

auto context = GrContext::MakeGL(interface, options);

Expand Down Expand Up @@ -101,6 +113,20 @@ GPUSurfaceGL::~GPUSurfaceGL() {
delegate_->GLContextClearCurrent();
}

bool GPUSurfaceGL::IsProcResolverOpenGLES() {
using GLGetStringProc = const char* (*)(uint32_t);
GLGetStringProc gl_get_string =
reinterpret_cast<GLGetStringProc>(proc_resolver_("glGetString"));
FML_CHECK(gl_get_string)
<< "The GL proc resolver could not resolve glGetString";
const char* gl_version_string = gl_get_string(GPU_GL_VERSION);
FML_CHECK(gl_version_string)
<< "The GL proc resolver's glGetString(GL_VERSION) failed";

return strncmp(gl_version_string, kGLESVersionPrefix,
strlen(kGLESVersionPrefix)) == 0;
}

// |shell::Surface|
bool GPUSurfaceGL::IsValid() {
return valid_;
Expand Down
2 changes: 2 additions & 0 deletions shell/gpu/gpu_surface_gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class GPUSurfaceGL : public Surface {

bool PresentSurface(SkCanvas* canvas);

bool IsProcResolverOpenGLES();

FML_DISALLOW_COPY_AND_ASSIGN(GPUSurfaceGL);
};

Expand Down
12 changes: 12 additions & 0 deletions shell/platform/embedder/embedder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#define FML_USED_ON_EMBEDDER

#include "flutter/fml/build_config.h"
#include "flutter/fml/native_library.h"

#if OS_WIN
#define FLUTTER_EXPORT __declspec(dllexport)
Expand Down Expand Up @@ -88,6 +89,13 @@ static bool IsRendererValid(const FlutterRendererConfig* config) {
return false;
}

static void* DefaultGLProcResolver(const char* name) {
static fml::RefPtr<fml::NativeLibrary> proc_library =
fml::NativeLibrary::CreateForCurrentProcess();
return static_cast<void*>(
const_cast<uint8_t*>(proc_library->ResolveSymbol(name)));
}

static shell::Shell::CreateCallback<shell::PlatformView>
InferOpenGLPlatformViewCreationCallback(
const FlutterRendererConfig* config,
Expand Down Expand Up @@ -144,6 +152,10 @@ InferOpenGLPlatformViewCreationCallback(
user_data](const char* gl_proc_name) {
return ptr(user_data, gl_proc_name);
};
} else {
#if OS_LINUX || OS_WIN
gl_proc_resolver = DefaultGLProcResolver;
#endif
}

bool fbo_reset_after_present =
Expand Down