Flutter Engine
android_context_gl.h
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 #ifndef FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_CONTEXT_GL_H_
6 #define FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_CONTEXT_GL_H_
7 
8 #include "flutter/fml/macros.h"
9 #include "flutter/fml/memory/ref_counted.h"
10 #include "flutter/fml/memory/ref_ptr.h"
11 #include "flutter/shell/common/platform_view.h"
12 #include "flutter/shell/platform/android/android_environment_gl.h"
13 #include "flutter/shell/platform/android/context/android_context.h"
14 #include "flutter/shell/platform/android/surface/android_native_window.h"
15 #include "third_party/skia/include/core/SkSize.h"
16 
17 namespace flutter {
18 
19 //------------------------------------------------------------------------------
20 /// Holds an `EGLSurface` reference.
21 ///
22 ///
23 /// This can be used in conjunction to unique_ptr to provide better guarantees
24 /// about the lifespan of the `EGLSurface` object.
25 ///
27  public:
28  AndroidEGLSurface(EGLSurface surface, EGLDisplay display, EGLContext context);
30 
31  //----------------------------------------------------------------------------
32  /// @return Whether the current `EGLSurface` reference is valid. That is,
33  /// if
34  /// the surface doesn't point to `EGL_NO_SURFACE`.
35  ///
36  bool IsValid() const;
37 
38  //----------------------------------------------------------------------------
39  /// @brief Binds the EGLContext context to the current rendering thread
40  /// and to the draw and read surface.
41  ///
42  /// @return Whether the surface was made current.
43  ///
44  bool MakeCurrent() const;
45 
46  //----------------------------------------------------------------------------
47  /// @brief This only applies to on-screen surfaces such as those created
48  /// by `AndroidContextGL::CreateOnscreenSurface`.
49  ///
50  /// @return Whether the EGL surface color buffer was swapped.
51  ///
52  bool SwapBuffers();
53 
54  //----------------------------------------------------------------------------
55  /// @return The size of an `EGLSurface`.
56  ///
57  SkISize GetSize() const;
58 
59  private:
60  const EGLSurface surface_;
61  const EGLDisplay display_;
62  const EGLContext context_;
63 };
64 
65 //------------------------------------------------------------------------------
66 /// The Android context is used by `AndroidSurfaceGL` to create and manage
67 /// EGL surfaces.
68 ///
69 /// This context binds `EGLContext` to the current rendering thread and to the
70 /// draw and read `EGLSurface`s.
71 ///
73  public:
76 
78 
79  //----------------------------------------------------------------------------
80  /// @brief Allocates an new EGL window surface that is used for on-screen
81  /// pixels.
82  ///
83  /// @return The window surface.
84  ///
85  std::unique_ptr<AndroidEGLSurface> CreateOnscreenSurface(
87 
88  //----------------------------------------------------------------------------
89  /// @brief Allocates an 1x1 pbuffer surface that is used for making the
90  /// offscreen current for texture uploads.
91  ///
92  /// @return The pbuffer surface.
93  ///
94  std::unique_ptr<AndroidEGLSurface> CreateOffscreenSurface() const;
95 
96  //----------------------------------------------------------------------------
97  /// @brief Allocates an 1x1 pbuffer surface that is used for making the
98  /// onscreen context current for snapshotting.
99  ///
100  /// @return The pbuffer surface.
101  ///
102  std::unique_ptr<AndroidEGLSurface> CreatePbufferSurface() const;
103 
104  //----------------------------------------------------------------------------
105  /// @return The Android environment that contains a reference to the
106  /// display.
107  ///
108  fml::RefPtr<AndroidEnvironmentGL> Environment() const;
109 
110  //----------------------------------------------------------------------------
111  /// @return Whether the current context is valid. That is, if the EGL
112  /// contexts were successfully created.
113  ///
114  bool IsValid() const override;
115 
116  //----------------------------------------------------------------------------
117  /// @return Whether the current context was successfully clear.
118  ///
119  bool ClearCurrent() const;
120 
121  //----------------------------------------------------------------------------
122  /// @brief Create a new EGLContext using the same EGLConfig.
123  ///
124  /// @return The EGLContext.
125  ///
126  EGLContext CreateNewContext() const;
127 
128  private:
130  EGLConfig config_;
131  EGLContext context_;
132  EGLContext resource_context_;
133  bool valid_ = false;
134 
136 };
137 
138 } // namespace flutter
139 
140 #endif // FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_CONTEXT_GL_H_
AndroidEGLSurface(EGLSurface surface, EGLDisplay display, EGLContext context)
Holds state that is shared across Android surfaces.
bool MakeCurrent() const
Binds the EGLContext context to the current rendering thread and to the draw and read surface...
bool SwapBuffers()
This only applies to on-screen surfaces such as those created by AndroidContextGL::CreateOnscreenSurf...
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition: macros.h:27