Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
gpu_surface_gl_delegate.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "flutter/shell/gpu/gpu_surface_gl_delegate.h"
6
7#include <cstring>
8
10
11namespace flutter {
12
14
16 return false;
17}
18
25
27 SkMatrix matrix;
28 matrix.setIdentity();
29 return matrix;
30}
31
36
38 const GPUSurfaceGLDelegate::GLProcResolver& proc_resolver) {
39 // Version string prefix that identifies an OpenGL ES implementation.
40#define GPU_GL_VERSION 0x1F02
41 constexpr char kGLESVersionPrefix[] = "OpenGL ES";
42
43#ifdef WIN32
44 using GLGetStringProc = const char*(__stdcall*)(uint32_t);
45#else
46 using GLGetStringProc = const char* (*)(uint32_t);
47#endif
48
49 GLGetStringProc gl_get_string =
50 reinterpret_cast<GLGetStringProc>(proc_resolver("glGetString"));
51
52 FML_CHECK(gl_get_string)
53 << "The GL proc resolver could not resolve glGetString";
54
55 const char* gl_version_string = gl_get_string(GPU_GL_VERSION);
56
57 FML_CHECK(gl_version_string)
58 << "The GL proc resolver's glGetString(GL_VERSION) failed";
59
60 return strncmp(gl_version_string, kGLESVersionPrefix,
61 strlen(kGLESVersionPrefix)) == 0;
62}
63
65 const GPUSurfaceGLDelegate::GLProcResolver& proc_resolver) {
66 if (proc_resolver == nullptr) {
67 // If there is no custom proc resolver, ask Skia to guess the native
68 // interface. This often leads to interesting results on most platforms.
70 }
71
72 struct ProcResolverContext {
74 };
75
76 ProcResolverContext context = {proc_resolver};
77
78 GrGLGetProc gl_get_proc = [](void* context,
79 const char gl_proc_name[]) -> GrGLFuncPtr {
80 auto proc_resolver_context =
81 reinterpret_cast<ProcResolverContext*>(context);
82 return reinterpret_cast<GrGLFuncPtr>(
83 proc_resolver_context->resolver(gl_proc_name));
84 };
85
86 // glGetString indicates an OpenGL ES interface.
87 if (IsProcResolverOpenGLES(proc_resolver)) {
88 return GrGLMakeAssembledGLESInterface(&context, gl_get_proc);
89 }
90
91 // Fallback to OpenGL.
92 if (auto interface = GrGLMakeAssembledGLInterface(&context, gl_get_proc)) {
93 return interface;
94 }
95
96 FML_LOG(ERROR) << "Could not create a valid GL interface.";
97 return nullptr;
98}
99
103
108
110 return true;
111}
112
113} // namespace flutter
SK_API sk_sp< const GrGLInterface > GrGLMakeAssembledGLInterface(void *ctx, GrGLGetProc get)
GrGLFuncPtr(* GrGLGetProc)(void *ctx, const char name[])
SK_API sk_sp< const GrGLInterface > GrGLMakeAssembledGLESInterface(void *ctx, GrGLGetProc get)
SK_API sk_sp< const GrGLInterface > GrGLMakeNativeInterface()
void(* GrGLFuncPtr)()
virtual bool AllowsDrawingWhenGpuDisabled() const
std::function< void *(const char *)> GLProcResolver
static sk_sp< const GrGLInterface > GetDefaultPlatformGLInterface()
virtual GLProcResolver GetGLProcResolver() const
virtual SkMatrix GLContextSurfaceTransformation() const
virtual sk_sp< const GrGLInterface > GetGLInterface() const
virtual bool GLContextFBOResetAfterPresent() const
virtual SurfaceFrame::FramebufferInfo GLContextFramebufferInfo() const
#define FML_LOG(severity)
Definition logging.h:82
#define FML_CHECK(condition)
Definition logging.h:85
#define GPU_GL_VERSION
static sk_sp< const GrGLInterface > CreateGLInterface(const GPUSurfaceGLDelegate::GLProcResolver &proc_resolver)
static bool IsProcResolverOpenGLES(const GPUSurfaceGLDelegate::GLProcResolver &proc_resolver)
#define ERROR(message)