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 conjuction 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();
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  /// @return The Android environment that contains a reference to the
98  /// display.
99  ///
100  fml::RefPtr<AndroidEnvironmentGL> Environment() const;
101 
102  //----------------------------------------------------------------------------
103  /// @return Whether the current context is valid. That is, if the EGL
104  /// contexts were successfully created.
105  ///
106  bool IsValid() const;
107 
108  //----------------------------------------------------------------------------
109  /// @return Whether the current context was successfully clear.
110  ///
111  bool ClearCurrent();
112 
113  //----------------------------------------------------------------------------
114  /// @brief Create a new EGLContext using the same EGLConfig.
115  ///
116  /// @return The EGLContext.
117  ///
118  EGLContext CreateNewContext() const;
119 
120  private:
122  EGLConfig config_;
123  EGLContext context_;
124  EGLContext resource_context_;
125  bool valid_ = false;
126 
128 };
129 
130 } // namespace flutter
131 
132 #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()
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