Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit b7c5868

Browse files
committed
Only call make gl context current if not already current
1 parent 2cce4bb commit b7c5868

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

shell/platform/android/android_context_gl.cc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,34 @@ bool AndroidEGLSurface::IsValid() const {
252252
return surface_ != EGL_NO_SURFACE;
253253
}
254254

255+
bool AndroidEGLSurface::IsContextCurrent() const {
256+
EGLContext current_egl_context = eglGetCurrentContext();
257+
if (context_ != current_egl_context) {
258+
return false;
259+
}
260+
261+
EGLDisplay current_egl_display = eglGetCurrentDisplay();
262+
if (display_ != current_egl_display) {
263+
return false;
264+
}
265+
266+
EGLSurface draw_surface = eglGetCurrentSurface(EGL_DRAW);
267+
if (draw_surface != surface_) {
268+
return false;
269+
}
270+
271+
EGLSurface read_surface = eglGetCurrentSurface(EGL_READ);
272+
if (read_surface != surface_) {
273+
return false;
274+
}
275+
276+
return true;
277+
}
278+
255279
bool AndroidEGLSurface::MakeCurrent() const {
280+
if (IsContextCurrent()) {
281+
return true;
282+
}
256283
if (eglMakeCurrent(display_, surface_, surface_, context_) != EGL_TRUE) {
257284
FML_LOG(ERROR) << "Could not make the context current";
258285
LogLastEGLError();

shell/platform/android/android_context_gl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ class AndroidEGLSurface {
8181
SkISize GetSize() const;
8282

8383
private:
84+
/// Returns true if the EGLContext held is current for the display and surface
85+
bool IsContextCurrent() const;
86+
8487
const EGLSurface surface_;
8588
const EGLDisplay display_;
8689
const EGLContext context_;

0 commit comments

Comments
 (0)