Provide a default GL function resolver in the embedder (flutter/engine#6523)

Also check whether the implementation behind the resolver is OpenGL or
OpenGL ES
This commit is contained in:
Jason Simmons
2018-10-12 15:07:46 -07:00
committed by GitHub
parent 564d7d7b27
commit 0a6f678613
3 changed files with 50 additions and 10 deletions

View File

@@ -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
@@ -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()) {
@@ -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);
@@ -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_;

View File

@@ -75,6 +75,8 @@ class GPUSurfaceGL : public Surface {
bool PresentSurface(SkCanvas* canvas);
bool IsProcResolverOpenGLES();
FML_DISALLOW_COPY_AND_ASSIGN(GPUSurfaceGL);
};

View File

@@ -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)
@@ -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,
@@ -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 =