Skip to content

Commit

Permalink
[Android] Stop calling eglSwapBuffers immediately. (#3076)
Browse files Browse the repository at this point in the history
Since we're seeing ANRs at SCREEN_OFF where the rasterizer thread
appears to be hanging during eglSwapBuffers, this change attempts to
avoid those ANRs by immediately skip calls to eglSwapBuffers when a
surfaceDestroyed event is received, until a the next SurfaceCreated.
Since Cobalt uses GameActivity, those are received in calls to
OnNativeWindowDestroyed respectively OnNativeWindowCreated.

b/225209442
  • Loading branch information
jellefoks committed Apr 30, 2024
1 parent 37c31fb commit ad53292
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions starboard/android/shared/android_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
namespace starboard {
namespace android {
namespace shared {

atomic_bool g_block_swapbuffers;

namespace {

using ::starboard::shared::starboard::CommandLine;
Expand Down Expand Up @@ -314,13 +317,15 @@ void OnWindowFocusChanged(GameActivity* activity, bool focused) {
}

void OnNativeWindowCreated(GameActivity* activity, ANativeWindow* window) {
g_block_swapbuffers.store(false);
if (g_app_running.load()) {
ApplicationAndroid::Get()->SendAndroidCommand(
AndroidCommand::kNativeWindowCreated, window);
}
}

void OnNativeWindowDestroyed(GameActivity* activity, ANativeWindow* window) {
g_block_swapbuffers.store(true);
if (g_app_running.load()) {
ApplicationAndroid::Get()->SendAndroidCommand(
AndroidCommand::kNativeWindowDestroyed);
Expand Down
11 changes: 11 additions & 0 deletions starboard/android/shared/egl_swap_buffers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,25 @@
#include <GLES2/gl2.h>

#include "starboard/android/shared/video_window.h"
#include "starboard/common/atomic.h"
#include "starboard/shared/gles/gl_call.h"

namespace starboard {
namespace android {
namespace shared {
extern atomic_bool g_block_swapbuffers;
} // namespace shared
} // namespace android
} // namespace starboard

extern "C" {
EGLBoolean __real_eglSwapBuffers(EGLDisplay dpy, EGLSurface surface);

// This needs to be exported to ensure shared_library targets include it.
SB_EXPORT_PLATFORM EGLBoolean __wrap_eglSwapBuffers(EGLDisplay dpy,
EGLSurface surface) {
if (starboard::android::shared::g_block_swapbuffers.load())
return;
// Kick off the GPU while waiting for new player bounds to take effect.
GL_CALL(glFlush());

Expand Down

0 comments on commit ad53292

Please sign in to comment.