summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/egl/drivers/dri2/egl_dri2.h7
-rw-r--r--src/egl/drivers/dri2/platform_android.c30
2 files changed, 31 insertions, 6 deletions
diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index fa04e3bb616..3206d00c1ca 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -325,13 +325,14 @@ struct dri2_egl_surface
__DRIimage *dri_image_front;
/* Used to record all the buffers created by ANativeWindow and their ages.
- * Usually Android uses at most triple buffers in ANativeWindow
- * so hardcode the number of color_buffers to 3.
+ * Allocate number of color_buffers based on query to android bufferqueue
+ * and save color_buffers_count.
*/
+ int color_buffers_count;
struct {
struct ANativeWindowBuffer *buffer;
int age;
- } color_buffers[3], *back;
+ } *color_buffers, *back;
#endif
/* surfaceless and device */
diff --git a/src/egl/drivers/dri2/platform_android.c b/src/egl/drivers/dri2/platform_android.c
index d949ed42a38..d37f6b8e447 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -237,7 +237,7 @@ droid_window_dequeue_buffer(struct dri2_egl_surface *dri2_surf)
* for updating buffer's age in swap_buffers.
*/
EGLBoolean updated = EGL_FALSE;
- for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
+ for (int i = 0; i < dri2_surf->color_buffers_count; i++) {
if (!dri2_surf->color_buffers[i].buffer) {
dri2_surf->color_buffers[i].buffer = dri2_surf->buffer;
}
@@ -252,7 +252,7 @@ droid_window_dequeue_buffer(struct dri2_egl_surface *dri2_surf)
/* In case of all the buffers were recreated by ANativeWindow, reset
* the color_buffers
*/
- for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
+ for (int i = 0; i < dri2_surf->color_buffers_count; i++) {
dri2_surf->color_buffers[i].buffer = NULL;
dri2_surf->color_buffers[i].age = 0;
}
@@ -367,6 +367,7 @@ droid_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type,
if (type == EGL_WINDOW_BIT) {
int format;
+ int buffer_count;
if (window->common.magic != ANDROID_NATIVE_WINDOW_MAGIC) {
_eglError(EGL_BAD_NATIVE_WINDOW, "droid_create_surface");
@@ -377,6 +378,26 @@ droid_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type,
goto cleanup_surface;
}
+ /* Query ANativeWindow for MIN_UNDEQUEUED_BUFFER, set buffer count
+ * and allocate color_buffers.
+ */
+ if (window->query(window, NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS,
+ &buffer_count)) {
+ _eglError(EGL_BAD_NATIVE_WINDOW, "droid_create_surface");
+ goto cleanup_surface;
+ }
+ if (native_window_set_buffer_count(window, buffer_count+1)) {
+ _eglError(EGL_BAD_NATIVE_WINDOW, "droid_create_surface");
+ goto cleanup_surface;
+ }
+ dri2_surf->color_buffers = calloc(buffer_count+1,
+ sizeof(*dri2_surf->color_buffers));
+ if (!dri2_surf->color_buffers) {
+ _eglError(EGL_BAD_ALLOC, "droid_create_surface");
+ goto cleanup_surface;
+ }
+ dri2_surf->color_buffers_count = buffer_count+1;
+
if (format != dri2_conf->base.NativeVisualID) {
_eglLog(_EGL_WARNING, "Native format mismatch: 0x%x != 0x%x",
format, dri2_conf->base.NativeVisualID);
@@ -404,6 +425,8 @@ droid_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type,
return &dri2_surf->base;
cleanup_surface:
+ if (dri2_surf->color_buffers_count)
+ free(dri2_surf->color_buffers);
free(dri2_surf);
return NULL;
@@ -456,6 +479,7 @@ droid_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf)
dri2_dpy->core->destroyDrawable(dri2_surf->dri_drawable);
dri2_fini_surface(surf);
+ free(dri2_surf->color_buffers);
free(dri2_surf);
return EGL_TRUE;
@@ -698,7 +722,7 @@ droid_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw)
return EGL_TRUE;
}
- for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
+ for (int i = 0; i < dri2_surf->color_buffers_count; i++) {
if (dri2_surf->color_buffers[i].age > 0)
dri2_surf->color_buffers[i].age++;
}