8#include <sys/system_properties.h>
18 struct EGLNameErrorPair {
23#define _EGL_ERROR_DESC(a) \
28 const EGLNameErrorPair pairs[] = {
48 const auto count =
sizeof(pairs) /
sizeof(EGLNameErrorPair);
50 EGLint last_error = eglGetError();
52 for (
size_t i = 0;
i < count;
i++) {
53 if (last_error == pairs[
i].code) {
54 FML_LOG(ERROR) <<
"EGL Error: " << pairs[
i].name <<
" (" << pairs[
i].code
60 FML_LOG(ERROR) <<
"Unknown EGL Error";
65 void init(EGLDisplay display, EGLContext context) {}
69 const std::optional<DlIRect>& region) {}
75 std::optional<DlIRect>
InitialDamage(EGLDisplay display, EGLSurface surface) {
81 const std::optional<DlIRect>& damage) {
82 return eglSwapBuffers(display,
surface);
93 damage_->init(display_, context);
97 [[maybe_unused]]
auto result = eglDestroySurface(display_, surface_);
102 return surface_ != EGL_NO_SURFACE;
105bool AndroidEGLSurface::IsContextCurrent()
const {
106 EGLContext current_egl_context = eglGetCurrentContext();
107 if (context_ != current_egl_context) {
111 EGLDisplay current_egl_display = eglGetCurrentDisplay();
112 if (display_ != current_egl_display) {
116 EGLSurface draw_surface = eglGetCurrentSurface(EGL_DRAW);
117 if (draw_surface != surface_) {
121 EGLSurface read_surface = eglGetCurrentSurface(EGL_READ);
122 if (read_surface != surface_) {
130 if (IsContextCurrent()) {
133 if (eglMakeCurrent(display_, surface_, surface_, context_) != EGL_TRUE) {
134 FML_LOG(ERROR) <<
"Could not make the context current";
142 const std::optional<DlIRect>& buffer_damage) {
143 damage_->SetDamageRegion(display_, surface_, buffer_damage);
148 if (presentation_time_proc_) {
150 return presentation_time_proc_(display_, surface_, time_ns);
157 const std::optional<DlIRect>& surface_damage) {
158 TRACE_EVENT0(
"flutter",
"AndroidContextGL::SwapBuffers");
159 return damage_->SwapBuffersWithDamage(display_, surface_, surface_damage);
163 return damage_->SupportsPartialRepaint();
167 return damage_->InitialDamage(display_, surface_);
174 if (!eglQuerySurface(display_, surface_, EGL_WIDTH, &
width) ||
175 !eglQuerySurface(display_, surface_, EGL_HEIGHT, &
height)) {
176 FML_LOG(ERROR) <<
"Unable to query EGL surface size";
#define _EGL_ERROR_DESC(a)
bool SupportsPartialRepaint() const
std::optional< DlIRect > InitialDamage(EGLDisplay display, EGLSurface surface)
void SetDamageRegion(EGLDisplay display, EGLSurface surface, const std::optional< DlIRect > ®ion)
void init(EGLDisplay display, EGLContext context)
bool SwapBuffersWithDamage(EGLDisplay display, EGLSurface surface, const std::optional< DlIRect > &damage)
std::optional< DlIRect > InitialDamage()
This is the minimal area that needs to be repainted to get correct result.
void SetDamageRegion(const std::optional< DlIRect > &buffer_damage)
Sets the damage region for current surface. Corresponds to.
bool SupportsPartialRepaint() const
bool SwapBuffers(const std::optional< DlIRect > &surface_damage)
This only applies to on-screen surfaces such as those created by AndroidContextGL::CreateOnscreenSurf...
AndroidEGLSurface(EGLSurface surface, EGLDisplay display, EGLContext context)
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.
constexpr int64_t ToNanoseconds() const
constexpr TimeDelta ToEpochDelta() const
#define FML_LOG(severity)
#define FML_DCHECK(condition)
impeller::ISize32 DlISize
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.
#define TRACE_EVENT0(category_group, name)