Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
android_egl_surface.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_EGL_SURFACE_H_
6#define FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_EGL_SURFACE_H_
7
8#include <EGL/egl.h>
9#include <EGL/eglext.h>
10#include <KHR/khrplatform.h>
11#include <optional>
12
13#include "flutter/fml/macros.h"
14#include "flutter/fml/time/time_point.h"
15#include "flutter/shell/platform/android/android_environment_gl.h"
17
18namespace flutter {
19
20//------------------------------------------------------------------------------
21/// Holds an `EGLSurface` reference.
22///
23///
24/// This can be used in conjunction to unique_ptr to provide better guarantees
25/// about the lifespan of the `EGLSurface` object.
26///
27class AndroidEGLSurfaceDamage;
28
29/// Result of calling MakeCurrent on AndroidEGLSurface.
31 /// Success, the egl context for the surface was already current.
33 /// Success, the egl context for the surface made current.
35 /// Failed to make the egl context for the surface current.
37};
38
39void LogLastEGLError();
40
42 public:
43 AndroidEGLSurface(EGLSurface surface, EGLDisplay display, EGLContext context);
44
46
47 //----------------------------------------------------------------------------
48 /// @return Whether the current `EGLSurface` reference is valid. That is,
49 /// if
50 /// the surface doesn't point to `EGL_NO_SURFACE`.
51 ///
52 bool IsValid() const;
53
54 //----------------------------------------------------------------------------
55 /// @brief Binds the EGLContext context to the current rendering thread
56 /// and to the draw and read surface.
57 ///
58 /// @return Whether the surface was made current.
59 ///
61
62 //----------------------------------------------------------------------------
63 ///
64 /// @return Whether target surface supports partial repaint.
65 ///
66 bool SupportsPartialRepaint() const;
67
68 //----------------------------------------------------------------------------
69 /// @brief This is the minimal area that needs to be repainted to get
70 /// correct result.
71 ///
72 /// With double or triple buffering this buffer content may lag behind
73 /// current front buffer and the rect accounts for accumulated damage.
74 ///
75 /// @return The area of current surface where it is behind front buffer.
76 ///
77 std::optional<SkIRect> InitialDamage();
78
79 //----------------------------------------------------------------------------
80 /// @brief Sets the damage region for current surface. Corresponds to
81 // eglSetDamageRegionKHR
82 void SetDamageRegion(const std::optional<SkIRect>& buffer_damage);
83
84 //----------------------------------------------------------------------------
85 /// @brief Sets the presentation time for the current surface. This
86 // corresponds to calling eglPresentationTimeAndroid when
87 // available.
88 bool SetPresentationTime(const fml::TimePoint& presentation_time);
89
90 //----------------------------------------------------------------------------
91 /// @brief This only applies to on-screen surfaces such as those created
92 /// by `AndroidContextGL::CreateOnscreenSurface`.
93 ///
94 /// @return Whether the EGL surface color buffer was swapped.
95 ///
96 bool SwapBuffers(const std::optional<SkIRect>& surface_damage);
97
98 //----------------------------------------------------------------------------
99 /// @return The size of an `EGLSurface`.
100 ///
101 SkISize GetSize() const;
102
103 private:
104 /// Returns true if the EGLContext held is current for the display and surface
105 bool IsContextCurrent() const;
106
107 const EGLSurface surface_;
108 const EGLDisplay display_;
109 const EGLContext context_;
110 std::unique_ptr<AndroidEGLSurfaceDamage> damage_;
111 PFNEGLPRESENTATIONTIMEANDROIDPROC presentation_time_proc_ = nullptr;
112};
113
114} // namespace flutter
115
116#endif // FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_EGL_SURFACE_H_
std::optional< SkIRect > InitialDamage()
This is the minimal area that needs to be repainted to get correct result.
bool SwapBuffers(const std::optional< SkIRect > &surface_damage)
This only applies to on-screen surfaces such as those created by AndroidContextGL::CreateOnscreenSurf...
void SetDamageRegion(const std::optional< SkIRect > &buffer_damage)
Sets the damage region for current surface. Corresponds to.
bool SetPresentationTime(const fml::TimePoint &presentation_time)
Sets the presentation time for the current surface. This.
AndroidEGLSurfaceMakeCurrentStatus MakeCurrent() const
Binds the EGLContext context to the current rendering thread and to the draw and read surface.
VkSurfaceKHR surface
Definition main.cc:49
void LogLastEGLError()
AndroidEGLSurfaceMakeCurrentStatus
Result of calling MakeCurrent on AndroidEGLSurface.
@ kFailure
Failed to make the egl context for the surface current.
@ kSuccessMadeCurrent
Success, the egl context for the surface made current.
@ kSuccessAlreadyCurrent
Success, the egl context for the surface was already current.