Flutter Engine
The Flutter Engine
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 "flutter/fml/build_config.h"
8
9#include <cstring>
10
13
14#if defined(FML_OS_ANDROID)
16#endif
17
18#if defined(FML_OS_LINUX) && defined(SK_GLX)
20#endif
21
22#if defined(FML_OS_MACOSX)
24#endif
25
26#if defined(FML_OS_IOS)
28#endif
29
30namespace flutter {
31
33
35 return false;
36}
37
39 const {
41 res.supports_readback = true;
42 return res;
43}
44
47 matrix.setIdentity();
48 return matrix;
49}
50
52 const {
53 return nullptr;
54}
55
57 const GPUSurfaceGLDelegate::GLProcResolver& proc_resolver) {
58 // Version string prefix that identifies an OpenGL ES implementation.
59#define GPU_GL_VERSION 0x1F02
60 constexpr char kGLESVersionPrefix[] = "OpenGL ES";
61
62#ifdef WIN32
63 using GLGetStringProc = const char*(__stdcall*)(uint32_t);
64#else
65 using GLGetStringProc = const char* (*)(uint32_t);
66#endif
67
68 GLGetStringProc gl_get_string =
69 reinterpret_cast<GLGetStringProc>(proc_resolver("glGetString"));
70
71 FML_CHECK(gl_get_string)
72 << "The GL proc resolver could not resolve glGetString";
73
74 const char* gl_version_string = gl_get_string(GPU_GL_VERSION);
75
76 FML_CHECK(gl_version_string)
77 << "The GL proc resolver's glGetString(GL_VERSION) failed";
78
79 return strncmp(gl_version_string, kGLESVersionPrefix,
80 strlen(kGLESVersionPrefix)) == 0;
81}
82
84 const GPUSurfaceGLDelegate::GLProcResolver& proc_resolver) {
85 if (proc_resolver == nullptr) {
86#if defined(FML_OS_ANDROID)
88#elif defined(FML_OS_LINUX)
89#if defined(SK_GLX)
91#else
92 return nullptr;
93#endif // defined(SK_GLX)
94#elif defined(FML_OS_IOS)
96#elif defined(FML_OS_MACOSX)
98#else
99 // TODO(kjlubick) update this when Skia has a Windows target for making GL
100 // interfaces. For now, ask Skia to guess the native
101 // interface. This often leads to interesting results on most platforms.
103#endif
104 }
105
106 struct ProcResolverContext {
108 };
109
110 ProcResolverContext context = {proc_resolver};
111
112 GrGLGetProc gl_get_proc = [](void* context,
113 const char gl_proc_name[]) -> GrGLFuncPtr {
114 auto proc_resolver_context =
115 reinterpret_cast<ProcResolverContext*>(context);
116 return reinterpret_cast<GrGLFuncPtr>(
117 proc_resolver_context->resolver(gl_proc_name));
118 };
119
120 // glGetString indicates an OpenGL ES interface.
121 if (IsProcResolverOpenGLES(proc_resolver)) {
122 return GrGLMakeAssembledGLESInterface(&context, gl_get_proc);
123 }
124
125 // Fallback to OpenGL.
126 if (auto interface = GrGLMakeAssembledGLInterface(&context, gl_get_proc)) {
127 return interface;
128 }
129
130 FML_LOG(ERROR) << "Could not create a valid GL interface.";
131 return nullptr;
132}
133
136}
137
140 return CreateGLInterface(nullptr);
141}
142
144 return true;
145}
146
147} // 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)()
Definition: GrGLInterface.h:17
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
SK_API sk_sp< const GrGLInterface > MakeEGL()
SK_API sk_sp< const GrGLInterface > MakeIOS()
SK_API sk_sp< const GrGLInterface > MakeMac()
SK_API sk_sp< const GrGLInterface > MakeGLX()
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
static sk_sp< const GrGLInterface > CreateGLInterface(const GPUSurfaceGLDelegate::GLProcResolver &proc_resolver)
static bool IsProcResolverOpenGLES(const GPUSurfaceGLDelegate::GLProcResolver &proc_resolver)
#define ERROR(message)
Definition: elf_loader.cc:260