Flutter Engine
 
Loading...
Searching...
No Matches
embedder_surface_gl_skia.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
6
7#include <utility>
8
10
11namespace flutter {
12
14 GLDispatchTable gl_dispatch_table,
15 bool fbo_reset_after_present,
16 std::shared_ptr<EmbedderExternalViewEmbedder> external_view_embedder)
17 : gl_dispatch_table_(std::move(gl_dispatch_table)),
18 fbo_reset_after_present_(fbo_reset_after_present),
19 external_view_embedder_(std::move(external_view_embedder)) {
20 // Make sure all required members of the dispatch table are checked.
21 if (!gl_dispatch_table_.gl_make_current_callback ||
22 !gl_dispatch_table_.gl_clear_current_callback ||
23 !gl_dispatch_table_.gl_present_callback ||
24 !gl_dispatch_table_.gl_fbo_callback ||
25 !gl_dispatch_table_.gl_populate_existing_damage) {
26 return;
27 }
28
29 valid_ = true;
30}
31
33
34// |EmbedderSurface|
35bool EmbedderSurfaceGLSkia::IsValid() const {
36 return valid_;
37}
38
39// |GPUSurfaceGLDelegate|
40std::unique_ptr<GLContextResult> EmbedderSurfaceGLSkia::GLContextMakeCurrent() {
41 return std::make_unique<GLContextDefaultResult>(
42 gl_dispatch_table_.gl_make_current_callback());
43}
44
45// |GPUSurfaceGLDelegate|
46bool EmbedderSurfaceGLSkia::GLContextClearCurrent() {
47 return gl_dispatch_table_.gl_clear_current_callback();
48}
49
50// |GPUSurfaceGLDelegate|
51bool EmbedderSurfaceGLSkia::GLContextPresent(
52 const GLPresentInfo& present_info) {
53 // Pass the present information to the embedder present callback.
54 return gl_dispatch_table_.gl_present_callback(present_info);
55}
56
57// |GPUSurfaceGLDelegate|
58GLFBOInfo EmbedderSurfaceGLSkia::GLContextFBO(GLFrameInfo frame_info) const {
59 // Get the FBO ID using the gl_fbo_callback and then get exiting damage by
60 // passing that ID to the gl_populate_existing_damage.
61 return gl_dispatch_table_.gl_populate_existing_damage(
62 gl_dispatch_table_.gl_fbo_callback(frame_info));
63}
64
65// |GPUSurfaceGLDelegate|
66bool EmbedderSurfaceGLSkia::GLContextFBOResetAfterPresent() const {
67 return fbo_reset_after_present_;
68}
69
70// |GPUSurfaceGLDelegate|
71DlMatrix EmbedderSurfaceGLSkia::GLContextSurfaceTransformation() const {
72 auto callback = gl_dispatch_table_.gl_surface_transformation_callback;
73 if (!callback) {
74 return DlMatrix();
75 }
76 return callback();
77}
78
79// |GPUSurfaceGLDelegate|
80EmbedderSurfaceGLSkia::GLProcResolver EmbedderSurfaceGLSkia::GetGLProcResolver()
81 const {
82 return gl_dispatch_table_.gl_proc_resolver;
83}
84
85// |GPUSurfaceGLDelegate|
86SurfaceFrame::FramebufferInfo EmbedderSurfaceGLSkia::GLContextFramebufferInfo()
87 const {
88 // Enable partial repaint by default on the embedders.
89 auto info = SurfaceFrame::FramebufferInfo{};
90 info.supports_readback = true;
91 info.supports_partial_repaint =
92 gl_dispatch_table_.gl_populate_existing_damage != nullptr;
93 return info;
94}
95
96// |EmbedderSurface|
97std::unique_ptr<Surface> EmbedderSurfaceGLSkia::CreateGPUSurface() {
98 const bool render_to_surface = !external_view_embedder_;
99 return std::make_unique<GPUSurfaceGLSkia>(
100 this, // GPU surface GL delegate
101 render_to_surface // render to surface
102 );
103}
104
105// |EmbedderSurface|
106sk_sp<GrDirectContext> EmbedderSurfaceGLSkia::CreateResourceContext() const {
107 auto callback = gl_dispatch_table_.gl_make_resource_current_callback;
108 if (callback && callback()) {
110 GrBackendApi::kOpenGL, GetGLInterface())) {
111 return context;
112 } else {
113 FML_LOG(ERROR)
114 << "Internal error: Resource context available but could not create "
115 "a compatible Skia context.";
116 return nullptr;
117 }
118 }
119
120 // The callback was not available or failed.
121 FML_LOG(ERROR)
122 << "Could not create a resource context for async texture uploads. "
123 "Expect degraded performance. Set a valid make_resource_current "
124 "callback on FlutterOpenGLRendererConfig.";
125 return nullptr;
126}
127
128} // namespace flutter
EmbedderSurfaceGLSkia(GLDispatchTable gl_dispatch_table, bool fbo_reset_after_present, std::shared_ptr< EmbedderExternalViewEmbedder > external_view_embedder)
std::function< void *(const char *)> GLProcResolver
virtual sk_sp< const GrGLInterface > GetGLInterface() const
static sk_sp< GrDirectContext > CreateCompatibleResourceLoadingContext(GrBackendApi backend, const sk_sp< const GrGLInterface > &gl_interface)
FlutterDesktopBinaryReply callback
#define FML_LOG(severity)
Definition logging.h:101
impeller::Matrix DlMatrix
Definition ref_ptr.h:261
std::function< GLFBOInfo(intptr_t)> gl_populate_existing_damage
std::function< intptr_t(GLFrameInfo)> gl_fbo_callback
std::function< bool(GLPresentInfo)> gl_present_callback
std::function< void *(const char *)> gl_proc_resolver
std::function< DlMatrix(void)> gl_surface_transformation_callback