Skip to content

Commit

Permalink
Replace several calls to GrGLMakeNativeInterface with more direct APIs (
Browse files Browse the repository at this point in the history
#53064)

We are restructuring Skia and plan to remove GrGLMakeNativeInterface at
some point. This updates as many places as possible to use the direct
and explicit instantiation instead of having "Skia guess". This should
ideally not be changing behavior - if it does, then the PR should be
modified.

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide] and the [C++,
Objective-C, Java style guides].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [x] I added new tests to check the change I am making or feature I am
adding, or the PR is [test-exempt]. See [testing the engine] for
instructions on writing and running engine tests.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I signed the [CLA].
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[test-exempt]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[C++, Objective-C, Java style guides]:
https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
[testing the engine]:
https://github.com/flutter/flutter/wiki/Testing-the-engine
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat
  • Loading branch information
kjlubick authored May 30, 2024
1 parent fb64b9a commit 10d254c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/web_ui/skwasm/surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "third_party/skia/include/gpu/GrDirectContext.h"
#include "third_party/skia/include/gpu/ganesh/gl/GrGLBackendSurface.h"
#include "third_party/skia/include/gpu/ganesh/gl/GrGLDirectContext.h"
#include "third_party/skia/include/gpu/ganesh/gl/GrGLMakeWebGLInterface.h"

using namespace Skwasm;

Expand Down Expand Up @@ -101,7 +102,7 @@ void Surface::_init() {
makeCurrent(_glContext);
emscripten_webgl_enable_extension(_glContext, "WEBGL_debug_renderer_info");

_grContext = GrDirectContexts::MakeGL(GrGLMakeNativeInterface());
_grContext = GrDirectContexts::MakeGL(GrGLInterfaces::MakeWebGL());

// WebGL should already be clearing the color and stencil buffers, but do it
// again here to ensure Skia receives them in the expected state.
Expand Down
36 changes: 35 additions & 1 deletion shell/gpu/gpu_surface_gl_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,28 @@

#include "flutter/shell/gpu/gpu_surface_gl_delegate.h"

#include "flutter/fml/build_config.h"

#include <cstring>

#include "third_party/skia/include/gpu/gl/GrGLAssembleInterface.h"
#include "third_party/skia/include/gpu/gl/GrGLInterface.h"

#if defined(FML_OS_ANDROID)
#include "third_party/skia/include/gpu/ganesh/gl/egl/GrGLMakeEGLInterface.h"
#endif

#if defined(FML_OS_LINUX) && defined(SK_GLX)
#include "third_party/skia/include/gpu/ganesh/gl/glx/GrGLMakeGLXInterface.h"
#endif

#if defined(FML_OS_MACOSX)
#include "third_party/skia/include/gpu/ganesh/gl/mac/GrGLMakeMacInterface.h"
#endif

#if defined(FML_OS_IOS)
#include "third_party/skia/include/gpu/ganesh/gl/ios/GrGLMakeIOSInterface.h"
#endif

namespace flutter {

Expand Down Expand Up @@ -64,9 +83,24 @@ static bool IsProcResolverOpenGLES(
static sk_sp<const GrGLInterface> CreateGLInterface(
const GPUSurfaceGLDelegate::GLProcResolver& proc_resolver) {
if (proc_resolver == nullptr) {
// If there is no custom proc resolver, ask Skia to guess the native
#if defined(FML_OS_ANDROID)
return GrGLInterfaces::MakeEGL();
#elif defined(FML_OS_LINUX)
#if defined(SK_GLX)
return GrGLInterfaces::MakeGLX();
#else
return nullptr;
#endif // defined(SK_GLX)
#elif defined(FML_OS_IOS)
return GrGLInterfaces::MakeIOS();
#elif defined(FML_OS_MACOSX)
return GrGLInterfaces::MakeMac();
#else
// TODO(kjlubick) update this when Skia has a Windows target for making GL
// interfaces. For now, ask Skia to guess the native
// interface. This often leads to interesting results on most platforms.
return GrGLMakeNativeInterface();
#endif
}

struct ProcResolverContext {
Expand Down
10 changes: 10 additions & 0 deletions skia/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ optional("gpu") {
if (defined(ndk_api) && ndk_api >= 26) {
libs += [ "android" ]
}
public_defines += [ "SK_EGL" ]
} else if (skia_use_webgl) {
sources += [
"$_skia_root/src/gpu/ganesh/gl/webgl/GrGLMakeNativeInterface_webgl.cpp",
Expand All @@ -436,6 +437,15 @@ optional("gpu") {
"$_skia_root/src/gpu/ganesh/gl/glx/GrGLMakeNativeInterface_glx.cpp",
]
libs += [ "GL" ]
public_defines += [ "SK_GLX" ]
} else if (is_mac) {
sources += [
"$_skia_root/src/gpu/ganesh/gl/mac/GrGLMakeNativeInterface_mac.cpp",
]
} else if (is_ios) {
sources += [
"$_skia_root/src/gpu/ganesh/gl/iOS/GrGLMakeNativeInterface_iOS.cpp",
]
} else if (is_win) {
sources += [
"$_skia_root/src/gpu/ganesh/gl/win/GrGLMakeNativeInterface_win.cpp",
Expand Down

0 comments on commit 10d254c

Please sign in to comment.