1*26e4beaaSAndrew GeisslerFrom ffdcdf7605f4f266b408cf161e7c76dab54d689b Mon Sep 17 00:00:00 2001
21a4b7ee2SBrad BishopFrom: Jeff Wannamaker <jeff_wannamaker@cable.comcast.com>
31a4b7ee2SBrad BishopDate: Thu, 19 Jan 2017 18:56:07 +0000
4*26e4beaaSAndrew GeisslerSubject: [PATCH] Implement triple buffering for wayland
51a4b7ee2SBrad Bishop
61a4b7ee2SBrad BishopChange from double to triple buffering for wayland.
71a4b7ee2SBrad BishopThis enables higher frame rates without tearing artifacts
81a4b7ee2SBrad Bishopby allowing both the glFinish and the buffer release
91a4b7ee2SBrad Bishopinterlock to operate without pushing the frame period
101a4b7ee2SBrad Bishopto two vertical intervals
111a4b7ee2SBrad Bishop
121a4b7ee2SBrad BishopSigned-off-by: Jeff Wannamaker <jeff_wannamaker@cable.comcast.com>
131a4b7ee2SBrad BishopSigned-off-by: Khem Raj <raj.khem@gmail.com>
141a4b7ee2SBrad Bishop---
151a4b7ee2SBrad Bishop interface/khronos/egl/egl_client.c         |  3 ++-
161a4b7ee2SBrad Bishop interface/khronos/egl/egl_client_surface.c |  8 ++++++++
171a4b7ee2SBrad Bishop interface/khronos/egl/egl_client_surface.h | 11 +++++++++++
181a4b7ee2SBrad Bishop 3 files changed, 21 insertions(+), 1 deletion(-)
191a4b7ee2SBrad Bishop
201a4b7ee2SBrad Bishopdiff --git a/interface/khronos/egl/egl_client.c b/interface/khronos/egl/egl_client.c
211a4b7ee2SBrad Bishopindex 13a110c..0380274 100644
221a4b7ee2SBrad Bishop--- a/interface/khronos/egl/egl_client.c
231a4b7ee2SBrad Bishop+++ b/interface/khronos/egl/egl_client.c
241a4b7ee2SBrad Bishop@@ -2323,7 +2323,8 @@ EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffers(EGLDisplay dpy, EGLSurface surf)
251a4b7ee2SBrad Bishop
261a4b7ee2SBrad Bishop                   buffer_temp = surface->front_wl_buffer;
271a4b7ee2SBrad Bishop                   surface->front_wl_buffer = surface->back_wl_buffer;
281a4b7ee2SBrad Bishop-                  surface->back_wl_buffer = buffer_temp;
291a4b7ee2SBrad Bishop+                  surface->back_wl_buffer = surface->middle_wl_buffer;
301a4b7ee2SBrad Bishop+                  surface->middle_wl_buffer = buffer_temp;
311a4b7ee2SBrad Bishop
321a4b7ee2SBrad Bishop                   configid = egl_config_to_id(surface->config);
331a4b7ee2SBrad Bishop                   color = egl_config_get_color_format(configid);
341a4b7ee2SBrad Bishopdiff --git a/interface/khronos/egl/egl_client_surface.c b/interface/khronos/egl/egl_client_surface.c
351a4b7ee2SBrad Bishopindex 9a9582c..10b3b04 100644
361a4b7ee2SBrad Bishop--- a/interface/khronos/egl/egl_client_surface.c
371a4b7ee2SBrad Bishop+++ b/interface/khronos/egl/egl_client_surface.c
381a4b7ee2SBrad Bishop@@ -402,12 +402,14 @@ EGL_SURFACE_T *egl_surface_create(
391a4b7ee2SBrad Bishop    if (type == WINDOW && wl_display) {
401a4b7ee2SBrad Bishop       surface->wl_egl_window = (struct wl_egl_window*)win;
411a4b7ee2SBrad Bishop       surface->front_wl_buffer = NULL;
421a4b7ee2SBrad Bishop+      surface->middle_wl_buffer = NULL;
431a4b7ee2SBrad Bishop       surface->back_wl_buffer = allocate_wl_buffer(
441a4b7ee2SBrad Bishop             surface->wl_egl_window, color);
451a4b7ee2SBrad Bishop       resource = surface->back_wl_buffer->resource;
461a4b7ee2SBrad Bishop    } else {
471a4b7ee2SBrad Bishop       surface->wl_egl_window = NULL;
481a4b7ee2SBrad Bishop       surface->front_wl_buffer = NULL;
491a4b7ee2SBrad Bishop+      surface->middle_wl_buffer = NULL;
501a4b7ee2SBrad Bishop       surface->back_wl_buffer = NULL;
511a4b7ee2SBrad Bishop       resource = DISPMANX_NO_HANDLE;
521a4b7ee2SBrad Bishop    }
531a4b7ee2SBrad Bishop@@ -696,6 +698,12 @@ void egl_surface_free(EGL_SURFACE_T *surface)
541a4b7ee2SBrad Bishop          surface->back_wl_buffer = 0;
551a4b7ee2SBrad Bishop       }
561a4b7ee2SBrad Bishop
571a4b7ee2SBrad Bishop+      if (surface->middle_wl_buffer) {
581a4b7ee2SBrad Bishop+         wl_buffer_destroy(surface->middle_wl_buffer->wl_buffer);
591a4b7ee2SBrad Bishop+         free(surface->middle_wl_buffer);
601a4b7ee2SBrad Bishop+         surface->middle_wl_buffer = 0;
611a4b7ee2SBrad Bishop+      }
621a4b7ee2SBrad Bishop+
631a4b7ee2SBrad Bishop       if (surface->front_wl_buffer) {
641a4b7ee2SBrad Bishop          wl_buffer_destroy(surface->front_wl_buffer->wl_buffer);
651a4b7ee2SBrad Bishop          free(surface->front_wl_buffer);
661a4b7ee2SBrad Bishopdiff --git a/interface/khronos/egl/egl_client_surface.h b/interface/khronos/egl/egl_client_surface.h
671a4b7ee2SBrad Bishopindex e328b77..58a3184 100644
681a4b7ee2SBrad Bishop--- a/interface/khronos/egl/egl_client_surface.h
691a4b7ee2SBrad Bishop+++ b/interface/khronos/egl/egl_client_surface.h
701a4b7ee2SBrad Bishop@@ -312,6 +312,17 @@ typedef struct {
711a4b7ee2SBrad Bishop    */
721a4b7ee2SBrad Bishop    struct wl_dispmanx_client_buffer *front_wl_buffer;
731a4b7ee2SBrad Bishop
741a4b7ee2SBrad Bishop+   /*
751a4b7ee2SBrad Bishop+      middle_wl_buffer
761a4b7ee2SBrad Bishop+
771a4b7ee2SBrad Bishop+      Validity:
781a4b7ee2SBrad Bishop+      type == WINDOW
791a4b7ee2SBrad Bishop+
801a4b7ee2SBrad Bishop+      Invariant:
811a4b7ee2SBrad Bishop+      client-side information about the wl_buffer in the middle
821a4b7ee2SBrad Bishop+   */
831a4b7ee2SBrad Bishop+   struct wl_dispmanx_client_buffer *middle_wl_buffer;
841a4b7ee2SBrad Bishop+
851a4b7ee2SBrad Bishop    /*
861a4b7ee2SBrad Bishop       back_wl_buffer
871a4b7ee2SBrad Bishop
88