From 1ea949429ceeb6061e7aab1cada1d7dfc20f7d8b Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Sun, 6 Jun 2021 06:31:58 +0000 Subject: [PATCH] egl/android: fix cached buffer slots for EGL Android winsys Android WSI api contract requires to allocate min_undequeued_buffers + 2 to achieve "triple buffering" effect, which is when the composer backend acquired the allowed max numbder of buffers, the producer still has 2 buffers to rotate. ANativeWindow either belongs to SurfaceView which presents directly to SurfaceFlinger or belongs to other surfaces from the UI framework. For the former, SurfaceFlinger hardcodes triple buffering for EGL. For the latter, the surface caps decide the buffer limits or HWUI intercepts and adjusts the min_undequeued_buffers to hint the EGL implementation to prepare enough buffer cache slots while HWUI sets the max dequeued buffer count accordingly. Signed-off-by: Yiwei Zhang Reviewed-by: Rob Clark Part-of: --- src/egl/drivers/dri2/platform_android.c | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/src/egl/drivers/dri2/platform_android.c b/src/egl/drivers/dri2/platform_android.c index 585c4432a37..480b69bf2a5 100644 --- a/src/egl/drivers/dri2/platform_android.c +++ b/src/egl/drivers/dri2/platform_android.c @@ -573,7 +573,7 @@ droid_create_surface(_EGLDisplay *disp, EGLint type, _EGLConfig *conf, if (type == EGL_WINDOW_BIT) { int format; int buffer_count; - int min_buffer_count, max_buffer_count; + int min_undequeued_buffers; /* Prefer triple buffering for performance reasons. */ const int preferred_buffer_count = 3; @@ -591,30 +591,14 @@ droid_create_surface(_EGLDisplay *disp, EGLint type, _EGLConfig *conf, * of undequeued buffers. */ if (window->query(window, NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS, - &min_buffer_count)) { + &min_undequeued_buffers)) { _eglError(EGL_BAD_NATIVE_WINDOW, "droid_create_surface"); goto cleanup_surface; } - /* Query for maximum buffer count, application can set this - * to limit the total amount of buffers. - */ - if (window->query(window, NATIVE_WINDOW_MAX_BUFFER_COUNT, - &max_buffer_count)) { - _eglError(EGL_BAD_NATIVE_WINDOW, "droid_create_surface"); - goto cleanup_surface; - } + /* Required buffer caching slots. */ + buffer_count = min_undequeued_buffers + 2; - /* Clamp preferred between minimum (min undequeued + 1 dequeued) - * and maximum. - */ - buffer_count = CLAMP(preferred_buffer_count, min_buffer_count + 1, - max_buffer_count); - - if (native_window_set_buffer_count(window, buffer_count)) { - _eglError(EGL_BAD_NATIVE_WINDOW, "droid_create_surface"); - goto cleanup_surface; - } dri2_surf->color_buffers = calloc(buffer_count, sizeof(*dri2_surf->color_buffers)); if (!dri2_surf->color_buffers) {