Flutter Engine
embedder_surface_gl.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/platform/embedder/embedder_surface_gl.h"
6 
7 #include "flutter/shell/common/shell_io_manager.h"
8 
9 namespace flutter {
10 
12  GLDispatchTable gl_dispatch_table,
13  bool fbo_reset_after_present,
14  std::shared_ptr<EmbedderExternalViewEmbedder> external_view_embedder)
15  : gl_dispatch_table_(gl_dispatch_table),
16  fbo_reset_after_present_(fbo_reset_after_present),
17  external_view_embedder_(external_view_embedder) {
18  // Make sure all required members of the dispatch table are checked.
19  if (!gl_dispatch_table_.gl_make_current_callback ||
20  !gl_dispatch_table_.gl_clear_current_callback ||
21  !gl_dispatch_table_.gl_present_callback ||
22  !gl_dispatch_table_.gl_fbo_callback) {
23  return;
24  }
25 
26  valid_ = true;
27 }
28 
30 
31 // |EmbedderSurface|
32 bool EmbedderSurfaceGL::IsValid() const {
33  return valid_;
34 }
35 
36 // |GPUSurfaceGLDelegate|
37 std::unique_ptr<GLContextResult> EmbedderSurfaceGL::GLContextMakeCurrent() {
38  return std::make_unique<GLContextDefaultResult>(
39  gl_dispatch_table_.gl_make_current_callback());
40 }
41 
42 // |GPUSurfaceGLDelegate|
43 bool EmbedderSurfaceGL::GLContextClearCurrent() {
44  return gl_dispatch_table_.gl_clear_current_callback();
45 }
46 
47 // |GPUSurfaceGLDelegate|
48 bool EmbedderSurfaceGL::GLContextPresent(uint32_t fbo_id) {
49  return gl_dispatch_table_.gl_present_callback(fbo_id);
50 }
51 
52 // |GPUSurfaceGLDelegate|
53 intptr_t EmbedderSurfaceGL::GLContextFBO(GLFrameInfo frame_info) const {
54  return gl_dispatch_table_.gl_fbo_callback(frame_info);
55 }
56 
57 // |GPUSurfaceGLDelegate|
58 bool EmbedderSurfaceGL::GLContextFBOResetAfterPresent() const {
59  return fbo_reset_after_present_;
60 }
61 
62 // |GPUSurfaceGLDelegate|
63 SkMatrix EmbedderSurfaceGL::GLContextSurfaceTransformation() const {
64  auto callback = gl_dispatch_table_.gl_surface_transformation_callback;
65  if (!callback) {
66  SkMatrix matrix;
67  matrix.setIdentity();
68  return matrix;
69  }
70  return callback();
71 }
72 
73 // |GPUSurfaceGLDelegate|
74 ExternalViewEmbedder* EmbedderSurfaceGL::GetExternalViewEmbedder() {
75  return external_view_embedder_.get();
76 }
77 
78 // |GPUSurfaceGLDelegate|
79 EmbedderSurfaceGL::GLProcResolver EmbedderSurfaceGL::GetGLProcResolver() const {
80  return gl_dispatch_table_.gl_proc_resolver;
81 }
82 
83 // |EmbedderSurface|
84 std::unique_ptr<Surface> EmbedderSurfaceGL::CreateGPUSurface() {
85  const bool render_to_surface = !external_view_embedder_;
86  return std::make_unique<GPUSurfaceGL>(this, // GPU surface GL delegate
87  render_to_surface // render to surface
88 
89  );
90 }
91 
92 // |EmbedderSurface|
93 sk_sp<GrDirectContext> EmbedderSurfaceGL::CreateResourceContext() const {
94  auto callback = gl_dispatch_table_.gl_make_resource_current_callback;
95  if (callback && callback()) {
97  GrBackend::kOpenGL_GrBackend, GetGLInterface())) {
98  return context;
99  } else {
100  FML_LOG(ERROR)
101  << "Internal error: Resource context available but could not create "
102  "a compatible Skia context.";
103  return nullptr;
104  }
105  }
106 
107  // The callback was not available or failed.
108  FML_LOG(ERROR)
109  << "Could not create a resource context for async texture uploads. "
110  "Expect degraded performance. Set a valid make_resource_current "
111  "callback on FlutterOpenGLRendererConfig.";
112  return nullptr;
113 }
114 
115 } // namespace flutter
std::function< bool(void)> gl_clear_current_callback
std::function< intptr_t(GLFrameInfo)> gl_fbo_callback
std::function< bool(void)> gl_make_resource_current_callback
EmbedderSurfaceGL(GLDispatchTable gl_dispatch_table, bool fbo_reset_after_present, std::shared_ptr< EmbedderExternalViewEmbedder > external_view_embedder)
std::function< bool(uint32_t)> gl_present_callback
std::function< void *(const char *)> gl_proc_resolver
#define FML_LOG(severity)
Definition: logging.h:65
std::function< void *(const char *)> GLProcResolver
static sk_sp< GrDirectContext > CreateCompatibleResourceLoadingContext(GrBackend backend, sk_sp< const GrGLInterface > gl_interface)
std::function< SkMatrix(void)> gl_surface_transformation_callback
std::function< bool(void)> gl_make_current_callback
virtual sk_sp< const GrGLInterface > GetGLInterface() const