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 <zzyiwei@chromium.org>
Reviewed-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11206>
This commit is contained in:
Yiwei Zhang 2021-06-06 06:31:58 +00:00 committed by Marge Bot
parent a4dc2021b8
commit 1ea949429c
1 changed files with 4 additions and 20 deletions

View File

@ -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) {