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 <cstring>
8 
9 #include "third_party/skia/include/gpu/gl/GrGLAssembleInterface.h"
10 
11 namespace flutter {
12 
14 
16  return false;
17 }
18 
20  return true;
21 }
22 
24  SkMatrix matrix;
25  matrix.setIdentity();
26  return matrix;
27 }
28 
30  const {
31  return nullptr;
32 }
33 
36  // Version string prefix that identifies an OpenGL ES implementation.
37 #define GPU_GL_VERSION 0x1F02
38  constexpr char kGLESVersionPrefix[] = "OpenGL ES";
39 
40  using GLGetStringProc = const char* (*)(uint32_t);
41 
42  GLGetStringProc gl_get_string =
43  reinterpret_cast<GLGetStringProc>(proc_resolver("glGetString"));
44 
45  FML_CHECK(gl_get_string)
46  << "The GL proc resolver could not resolve glGetString";
47 
48  const char* gl_version_string = gl_get_string(GPU_GL_VERSION);
49 
50  FML_CHECK(gl_version_string)
51  << "The GL proc resolver's glGetString(GL_VERSION) failed";
52 
53  return strncmp(gl_version_string, kGLESVersionPrefix,
54  strlen(kGLESVersionPrefix)) == 0;
55 }
56 
57 static sk_sp<const GrGLInterface> CreateGLInterface(
59  if (proc_resolver == nullptr) {
60  // If there is no custom proc resolver, ask Skia to guess the native
61  // interface. This often leads to interesting results on most platforms.
62  return GrGLMakeNativeInterface();
63  }
64 
65  struct ProcResolverContext {
67  };
68 
69  ProcResolverContext context = {proc_resolver};
70 
71  GrGLGetProc gl_get_proc = [](void* context,
72  const char gl_proc_name[]) -> GrGLFuncPtr {
73  auto proc_resolver_context =
74  reinterpret_cast<ProcResolverContext*>(context);
75  return reinterpret_cast<GrGLFuncPtr>(
76  proc_resolver_context->resolver(gl_proc_name));
77  };
78 
79  // glGetString indicates an OpenGL ES interface.
80  if (IsProcResolverOpenGLES(proc_resolver)) {
81  return GrGLMakeAssembledGLESInterface(&context, gl_get_proc);
82  }
83 
84  // Fallback to OpenGL.
85  if (auto interface = GrGLMakeAssembledGLInterface(&context, gl_get_proc)) {
86  return interface;
87  }
88 
89  FML_LOG(ERROR) << "Could not create a valid GL interface.";
90  return nullptr;
91 }
92 
93 sk_sp<const GrGLInterface> GPUSurfaceGLDelegate::GetGLInterface() const {
95 }
96 
97 sk_sp<const GrGLInterface>
99  return CreateGLInterface(nullptr);
100 }
101 
103  return nullptr;
104 }
105 
106 } // namespace flutter
static sk_sp< const GrGLInterface > CreateGLInterface(GPUSurfaceGLDelegate::GLProcResolver proc_resolver)
virtual SkMatrix GLContextSurfaceTransformation() const
#define GPU_GL_VERSION
virtual bool GLContextFBOResetAfterPresent() const
static bool IsProcResolverOpenGLES(GPUSurfaceGLDelegate::GLProcResolver proc_resolver)
#define FML_LOG(severity)
Definition: logging.h:65
std::function< void *(const char *)> GLProcResolver
virtual bool SurfaceSupportsReadback() const
ExternalViewEmbedder * GetExternalViewEmbedder() override
Gets the view embedder that controls how the Flutter layer hierarchy split into multiple chunks shoul...
#define FML_CHECK(condition)
Definition: logging.h:68
virtual GLProcResolver GetGLProcResolver() const
static sk_sp< const GrGLInterface > GetDefaultPlatformGLInterface()
virtual sk_sp< const GrGLInterface > GetGLInterface() const