Skip to content

Commit

Permalink
[android] clear gl context after rendering op (#1472)
Browse files Browse the repository at this point in the history
Clear context current after rendering op to avoid reuse of the same gl
context on a different thread, this is a change for the native sdk
4.3.0, the callback thread may be from a different thread after native
sdk 4.3.0.
  • Loading branch information
littleGnAl authored Dec 22, 2023
1 parent ed0c095 commit 57b0725
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions android/src/main/cpp/iris_rtc_rendering_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class GLContext {
return is_setup_surface_;
}

bool CreateContextAndMakeCurrent(const void *share_context) {
bool GLContextMakeCurrent(const void *share_context) {
// Need recreate context
if (context_ != EGL_NO_CONTEXT && share_context_ != share_context) {
eglMakeCurrent(display_, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
Expand Down Expand Up @@ -120,6 +120,12 @@ class GLContext {
return result;
}

void GLContextClearCurrent() {
if (context_ != EGL_NO_CONTEXT) {
eglMakeCurrent(display_, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
}
}

EGLint Swap() {
eglSwapBuffers(display_, surface_);
CHECK_GL_ERROR()
Expand Down Expand Up @@ -522,8 +528,6 @@ class YUVRendering final : public RenderingOp {
CHECK_GL_ERROR()
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
CHECK_GL_ERROR()
glViewport(0, 0, width, height);
CHECK_GL_ERROR()

glEnableVertexAttribArray(aPositionLoc_);
CHECK_GL_ERROR()
Expand Down Expand Up @@ -730,7 +734,7 @@ class NativeTextureRenderer final
return;
}

if (!gl_context_->CreateContextAndMakeCurrent(video_frame->sharedContext)) {
if (!gl_context_->GLContextMakeCurrent(video_frame->sharedContext)) {
LOGCATE("GLContext#CreateContextAndMakeCurrent failed ");
return;
}
Expand All @@ -756,6 +760,8 @@ class NativeTextureRenderer final
}

rendering_op_->Rendering(video_frame);

gl_context_->GLContextClearCurrent();
}

void Dispose() {
Expand Down

0 comments on commit 57b0725

Please sign in to comment.