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
16 changes: 15 additions & 1 deletion shell/gpu/gpu_surface_gl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "third_party/skia/include/core/SkSurface.h"
#include "third_party/skia/include/gpu/GrBackendSurface.h"
#include "third_party/skia/include/gpu/GrContextOptions.h"
#include "third_party/skia/include/gpu/gl/GrGLAssembleInterface.h"
#include "third_party/skia/include/gpu/gl/GrGLInterface.h"

// These are common defines present on all OpenGL headers. However, we don't
Expand Down Expand Up @@ -42,14 +43,27 @@ GPUSurfaceGL::GPUSurfaceGL(GPUSurfaceGLDelegate* delegate)
return;
}

proc_resolver_ = delegate_->GetGLProcResolver();

GrContextOptions options;
options.fAvoidStencilBuffers = true;

// To get video playback on the widest range of devices, we limit Skia to
// ES2 shading language when the ES3 external image extension is missing.
options.fPreferExternalImagesOverES3 = true;

auto context = GrContext::MakeGL(GrGLMakeNativeInterface(), options);
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();

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

if (context == nullptr) {
FML_LOG(ERROR) << "Failed to setup Skia Gr context.";
Expand Down
6 changes: 6 additions & 0 deletions shell/gpu/gpu_surface_gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef SHELL_GPU_GPU_SURFACE_GL_H_
#define SHELL_GPU_GPU_SURFACE_GL_H_

#include <functional>
#include <memory>

#include "flutter/fml/macros.h"
Expand Down Expand Up @@ -33,6 +34,10 @@ class GPUSurfaceGLDelegate {
matrix.setIdentity();
return matrix;
}

using GLProcResolver =
std::function<void* /* proc name */ (const char* /* proc address */)>;
virtual GLProcResolver GetGLProcResolver() const { return nullptr; }
};

class GPUSurfaceGL : public Surface {
Expand All @@ -55,6 +60,7 @@ class GPUSurfaceGL : public Surface {

private:
GPUSurfaceGLDelegate* delegate_;
GPUSurfaceGLDelegate::GLProcResolver proc_resolver_;
sk_sp<GrContext> context_;
sk_sp<SkSurface> onscreen_surface_;
sk_sp<SkSurface> offscreen_surface_;
Expand Down
21 changes: 15 additions & 6 deletions shell/platform/embedder/embedder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,25 @@ InferOpenGLPlatformViewCreationCallback(
};
}

shell::GPUSurfaceGLDelegate::GLProcResolver gl_proc_resolver = nullptr;
if (SAFE_ACCESS(open_gl_config, gl_proc_resolver, nullptr) != nullptr) {
gl_proc_resolver = [ptr = config->open_gl.gl_proc_resolver,
user_data](const char* gl_proc_name) {
return ptr(user_data, gl_proc_name);
};
}

bool fbo_reset_after_present =
SAFE_ACCESS(open_gl_config, fbo_reset_after_present, false);

shell::EmbedderSurfaceGL::GLDispatchTable gl_dispatch_table = {
gl_make_current, // gl_make_current_callback
gl_clear_current, // gl_clear_current_callback
gl_present, // gl_present_callback
gl_fbo_callback, // gl_fbo_callback
gl_make_resource_current_callback, // gl_make_resource_current_callback
gl_surface_transformation_callback // gl_surface_transformation_callback
gl_make_current, // gl_make_current_callback
gl_clear_current, // gl_clear_current_callback
gl_present, // gl_present_callback
gl_fbo_callback, // gl_fbo_callback
gl_make_resource_current_callback, // gl_make_resource_current_callback
gl_surface_transformation_callback, // gl_surface_transformation_callback
gl_proc_resolver, // gl_proc_resolver
};

return [gl_dispatch_table, fbo_reset_after_present,
Expand Down
2 changes: 2 additions & 0 deletions shell/platform/embedder/embedder.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ typedef bool (*SoftwareSurfacePresentCallback)(void* /* user data */,
const void* /* allocation */,
size_t /* row bytes */,
size_t /* height */);
typedef void* (*ProcResolver)(void* /* user data */, const char* /* name */);

typedef struct {
// The size of this struct. Must be sizeof(FlutterOpenGLRendererConfig).
Expand All @@ -77,6 +78,7 @@ typedef struct {
// The transformation to apply to the render target before any rendering
// operations. This callback is optional.
TransformationCallback surface_transformation;
ProcResolver gl_proc_resolver;
} FlutterOpenGLRendererConfig;

typedef struct {
Expand Down
5 changes: 5 additions & 0 deletions shell/platform/embedder/embedder_surface_gl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ SkMatrix EmbedderSurfaceGL::GLContextSurfaceTransformation() const {
return callback();
}

// |shell::GPUSurfaceGLDelegate|
EmbedderSurfaceGL::GLProcResolver EmbedderSurfaceGL::GetGLProcResolver() const {
return gl_dispatch_table_.gl_proc_resolver;
}

// |shell::EmbedderSurface|
std::unique_ptr<Surface> EmbedderSurfaceGL::CreateGPUSurface() {
return std::make_unique<GPUSurfaceGL>(this);
Expand Down
6 changes: 5 additions & 1 deletion shell/platform/embedder/embedder_surface_gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class EmbedderSurfaceGL final : public EmbedderSurface,
std::function<intptr_t(void)> gl_fbo_callback; // required
std::function<bool(void)> gl_make_resource_current_callback; // optional
std::function<SkMatrix(void)>
gl_surface_transformation_callback; // optional
gl_surface_transformation_callback; // optional
std::function<void*(const char*)> gl_proc_resolver; // optional
};

EmbedderSurfaceGL(GLDispatchTable gl_dispatch_table,
Expand Down Expand Up @@ -61,6 +62,9 @@ class EmbedderSurfaceGL final : public EmbedderSurface,
// |shell::GPUSurfaceGLDelegate|
SkMatrix GLContextSurfaceTransformation() const override;

// |shell::GPUSurfaceGLDelegate|
GLProcResolver GetGLProcResolver() const override;

FML_DISALLOW_COPY_AND_ASSIGN(EmbedderSurfaceGL);
};

Expand Down