1From ffdcdf7605f4f266b408cf161e7c76dab54d689b Mon Sep 17 00:00:00 2001
2From: Jeff Wannamaker <jeff_wannamaker@cable.comcast.com>
3Date: Thu, 19 Jan 2017 18:56:07 +0000
4Subject: [PATCH] Implement triple buffering for wayland
5
6Change from double to triple buffering for wayland.
7This enables higher frame rates without tearing artifacts
8by allowing both the glFinish and the buffer release
9interlock to operate without pushing the frame period
10to two vertical intervals
11
12Signed-off-by: Jeff Wannamaker <jeff_wannamaker@cable.comcast.com>
13Signed-off-by: Khem Raj <raj.khem@gmail.com>
14---
15Upstream-Status: Pending
16
17 interface/khronos/egl/egl_client.c         |  3 ++-
18 interface/khronos/egl/egl_client_surface.c |  8 ++++++++
19 interface/khronos/egl/egl_client_surface.h | 11 +++++++++++
20 3 files changed, 21 insertions(+), 1 deletion(-)
21
22diff --git a/interface/khronos/egl/egl_client.c b/interface/khronos/egl/egl_client.c
23index 13a110c..0380274 100644
24--- a/interface/khronos/egl/egl_client.c
25+++ b/interface/khronos/egl/egl_client.c
26@@ -2323,7 +2323,8 @@ EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffers(EGLDisplay dpy, EGLSurface surf)
27
28                   buffer_temp = surface->front_wl_buffer;
29                   surface->front_wl_buffer = surface->back_wl_buffer;
30-                  surface->back_wl_buffer = buffer_temp;
31+                  surface->back_wl_buffer = surface->middle_wl_buffer;
32+                  surface->middle_wl_buffer = buffer_temp;
33
34                   configid = egl_config_to_id(surface->config);
35                   color = egl_config_get_color_format(configid);
36diff --git a/interface/khronos/egl/egl_client_surface.c b/interface/khronos/egl/egl_client_surface.c
37index 9a9582c..10b3b04 100644
38--- a/interface/khronos/egl/egl_client_surface.c
39+++ b/interface/khronos/egl/egl_client_surface.c
40@@ -402,12 +402,14 @@ EGL_SURFACE_T *egl_surface_create(
41    if (type == WINDOW && wl_display) {
42       surface->wl_egl_window = (struct wl_egl_window*)win;
43       surface->front_wl_buffer = NULL;
44+      surface->middle_wl_buffer = NULL;
45       surface->back_wl_buffer = allocate_wl_buffer(
46             surface->wl_egl_window, color);
47       resource = surface->back_wl_buffer->resource;
48    } else {
49       surface->wl_egl_window = NULL;
50       surface->front_wl_buffer = NULL;
51+      surface->middle_wl_buffer = NULL;
52       surface->back_wl_buffer = NULL;
53       resource = DISPMANX_NO_HANDLE;
54    }
55@@ -696,6 +698,12 @@ void egl_surface_free(EGL_SURFACE_T *surface)
56          surface->back_wl_buffer = 0;
57       }
58
59+      if (surface->middle_wl_buffer) {
60+         wl_buffer_destroy(surface->middle_wl_buffer->wl_buffer);
61+         free(surface->middle_wl_buffer);
62+         surface->middle_wl_buffer = 0;
63+      }
64+
65       if (surface->front_wl_buffer) {
66          wl_buffer_destroy(surface->front_wl_buffer->wl_buffer);
67          free(surface->front_wl_buffer);
68diff --git a/interface/khronos/egl/egl_client_surface.h b/interface/khronos/egl/egl_client_surface.h
69index e328b77..58a3184 100644
70--- a/interface/khronos/egl/egl_client_surface.h
71+++ b/interface/khronos/egl/egl_client_surface.h
72@@ -312,6 +312,17 @@ typedef struct {
73    */
74    struct wl_dispmanx_client_buffer *front_wl_buffer;
75
76+   /*
77+      middle_wl_buffer
78+
79+      Validity:
80+      type == WINDOW
81+
82+      Invariant:
83+      client-side information about the wl_buffer in the middle
84+   */
85+   struct wl_dispmanx_client_buffer *middle_wl_buffer;
86+
87    /*
88       back_wl_buffer
89
90