dri2_surf->window->lockBuffer(dri2_surf->window, dri2_surf->buffer);
#endif
+ /* Record all the buffers created by ANativeWindow and update back buffer
+ * for updating buffer's age in swap_buffers.
+ */
+ EGLBoolean updated = EGL_FALSE;
+ for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
+ if (!dri2_surf->color_buffers[i].buffer) {
+ dri2_surf->color_buffers[i].buffer = dri2_surf->buffer;
+ }
+ if (dri2_surf->color_buffers[i].buffer == dri2_surf->buffer) {
+ dri2_surf->back = &dri2_surf->color_buffers[i];
+ updated = EGL_TRUE;
+ break;
+ }
+ }
+
+ if (!updated) {
+ /* 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++) {
+ dri2_surf->color_buffers[i].buffer = NULL;
+ dri2_surf->color_buffers[i].age = 0;
+ }
+ dri2_surf->color_buffers[0].buffer = dri2_surf->buffer;
+ dri2_surf->back = &dri2_surf->color_buffers[0];
+ }
+
return EGL_TRUE;
}
dri2_surf->buffer->common.decRef(&dri2_surf->buffer->common);
dri2_surf->buffer = NULL;
+ dri2_surf->back = NULL;
mtx_lock(&disp->Mutex);
return 1;
}
+static EGLint
+droid_query_buffer_age(_EGLDriver *drv,
+ _EGLDisplay *disp, _EGLSurface *surface)
+{
+ struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surface);
+
+ if (update_buffers(dri2_surf) < 0) {
+ _eglError(EGL_BAD_ALLOC, "droid_query_buffer_age");
+ return 0;
+ }
+
+ return dri2_surf->back->age;
+}
+
static EGLBoolean
droid_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw)
{
if (dri2_surf->base.Type != EGL_WINDOW_BIT)
return EGL_TRUE;
+ for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
+ if (dri2_surf->color_buffers[i].age > 0)
+ dri2_surf->color_buffers[i].age++;
+ }
+ dri2_surf->back->age = 1;
+
dri2_flush_drawable_for_swapbuffers(disp, draw);
if (dri2_surf->buffer)
.swap_buffers_region = dri2_fallback_swap_buffers_region,
.post_sub_buffer = dri2_fallback_post_sub_buffer,
.copy_buffers = dri2_fallback_copy_buffers,
- .query_buffer_age = dri2_fallback_query_buffer_age,
+ .query_buffer_age = droid_query_buffer_age,
.query_surface = droid_query_surface,
.create_wayland_buffer_from_image = dri2_fallback_create_wayland_buffer_from_image,
.get_sync_values = dri2_fallback_get_sync_values,
dpy->Extensions.ANDROID_framebuffer_target = EGL_TRUE;
dpy->Extensions.ANDROID_image_native_buffer = EGL_TRUE;
dpy->Extensions.ANDROID_recordable = EGL_TRUE;
+ dpy->Extensions.EXT_buffer_age = EGL_TRUE;
/* Fill vtbl last to prevent accidentally calling virtual function during
* initialization.