1 From db720086b85046bd0806484bfe63915870bb4323 Mon Sep 17 00:00:00 2001
2 From: Prabhu Sundararaj <prabhu.sundararaj@freescale.com>
3 Date: Tue, 30 Dec 2014 16:09:29 -0600
4 Subject: [PATCH] MGS-389 - Fix for wrong FPS throttling when multibuffer is
6 Organization: O.S. Systems Software LTDA.
8 When the FB_MULTI_BUFFER=2 is set, throtling to 30FPS for a 60Hz display
9 which is suppose to have 60FPS.
10 Adding worker thread to output the frame in async mode for better
13 Upstream-Status: Pending
15 Signed-off-by: Prabhu Sundararaj <prabhu.sundararaj@freescale.com>
17 src/gal2d-renderer.c | 109 +++++++++++++++++++++++++++++++++++++++------------
18 1 file changed, 83 insertions(+), 26 deletions(-)
20 diff --git a/src/gal2d-renderer.c b/src/gal2d-renderer.c
21 index fbe39f6..4cccaf1 100644
22 --- a/src/gal2d-renderer.c
23 +++ b/src/gal2d-renderer.c
30 #include "compositor.h"
31 #include "gal2d-renderer.h"
32 #include "vertex-clipping.h"
35 #define galONERROR(x) if(status < 0) printf("Error in function %s\n", __func__);
38 struct gal2d_output_state {
41 @@ -48,7 +49,12 @@ struct gal2d_output_state {
43 gcoSURF offscreenSurface;
44 gceSURF_FORMAT format;
46 + pthread_mutex_t workerMutex;
48 + gctUINT32 exitWorker;
50 + gctSIGNAL busySignal;
51 + gcsHAL_INTERFACE iface;
54 struct gal2d_surface_state {
55 @@ -373,8 +379,7 @@ gal2d_clear(struct weston_output *base)
56 gcmONERROR(gco2D_SetSource(gr->gcoEngine2d, &dstRect));
57 gcmONERROR(gco2D_SetClipping(gr->gcoEngine2d, &dstRect));
58 gcmONERROR(gco2D_Clear(gr->gcoEngine2d, 1, &dstRect, 0xff0000ff, 0xCC, 0xCC, go->format));
60 - gcmONERROR(gcoHAL_Commit(gr->gcoHal, gcvFALSE));
61 + gcmONERROR(gcoHAL_Commit(gr->gcoHal, gcvTRUE));
65 @@ -465,7 +470,6 @@ gal2dBindBuffer(struct weston_surface* es)
67 gal2d_flip_surface(struct weston_output *output)
69 - struct gal2d_renderer *gr = get_renderer(output->compositor);
70 struct gal2d_output_state *go = get_output_state(output);
72 if(go->nNumBuffers > 1)
73 @@ -473,17 +477,36 @@ gal2d_flip_surface(struct weston_output *output)
77 - gcmVERIFY_OK(gcoHAL_Commit(gr->gcoHal, gcvTRUE));
80 gcmVERIFY_OK(gcoOS_GetDisplayBackbuffer(go->display, gcvNULL,
81 gcvNULL, gcvNULL, &Offset, &X, &Y));
83 gcmVERIFY_OK(gcoOS_SetDisplayVirtual(go->display, gcvNULL,
86 - go->activebuffer = (go->activebuffer+1) % go->nNumBuffers;
90 +static void *gal2d_output_worker(void *arg)
92 + struct weston_output *output = (struct weston_output *)arg;
93 + struct gal2d_output_state *go = get_output_state(output);
97 + if(gcoOS_WaitSignal(gcvNULL, go->signal, gcvINFINITE) == gcvSTATUS_OK )
99 + gal2d_flip_surface(output);
100 + gcoOS_Signal(gcvNULL,go->busySignal, gcvTRUE);
102 + pthread_mutex_lock(&go->workerMutex);
103 + if(go->exitWorker == 1)
105 + pthread_mutex_unlock(&go->workerMutex);
108 + pthread_mutex_unlock(&go->workerMutex);
114 update_surface(struct weston_output *output)
115 @@ -520,11 +543,13 @@ update_surface(struct weston_output *output)
116 gcmONERROR(gco2D_SetClipping(gr->gcoEngine2d, &dstRect));
117 gcmONERROR(gco2D_Blit(gr->gcoEngine2d, 1, &dstRect, 0xCC, 0xCC, go->format));
118 gcmONERROR(gcoSURF_Unlock(srcSurface, (gctPOINTER *)&va));
119 - gcmONERROR(gcoHAL_Commit(gr->gcoHal, gcvFALSE));
120 + gcmONERROR(gcoHAL_Commit(gr->gcoHal, gcvFALSE));
123 - gal2d_flip_surface(output);
125 + else if(go->nNumBuffers > 1)
127 + gcoHAL_ScheduleEvent(gr->gcoHal, &go->iface);
128 + gcmVERIFY_OK(gcoHAL_Commit(gr->gcoHal, gcvFALSE));
133 @@ -746,6 +771,7 @@ repaint_region(struct weston_view *ev, struct weston_output *output, struct gal2
134 0xCC, 0xCC, go->format));
140 printf("cr l=%d r=%d t=%d b=%d w=%d h=%d\n",
141 @@ -759,12 +785,6 @@ repaint_region(struct weston_view *ev, struct weston_output *output, struct gal2
145 - status = (gcoHAL_Commit(gr->gcoHal, gcvFALSE));
148 - printf("Error in gcoHAL_Commit %s\n", __func__);
154 @@ -831,7 +851,15 @@ repaint_views(struct weston_output *output, pixman_region32_t *damage)
156 struct weston_compositor *compositor = output->compositor;
157 struct weston_view *view;
159 + struct gal2d_output_state *go = get_output_state(output);
161 + if(go->nNumBuffers > 1)
163 + /*500ms is more than enough to process a frame */
164 + gcoOS_WaitSignal(gcvNULL, go->busySignal, 500);
166 + go->activebuffer = (go->activebuffer+1) % go->nNumBuffers;
168 wl_list_for_each_reverse(view, &compositor->view_list, link)
169 if (view->plane == &compositor->primary_plane)
170 draw_view(view, output, damage);
171 @@ -1090,12 +1118,19 @@ gal2d_renderer_output_destroy(struct weston_output *output)
172 if(go->offscreenSurface)
173 gcmVERIFY_OK(gcoSURF_Destroy(go->offscreenSurface));
178 + gcoOS_Signal(gcvNULL,go->signal, gcvTRUE);
179 + pthread_mutex_lock(&go->workerMutex);
180 + go->exitWorker = 1;
181 + pthread_mutex_unlock(&go->workerMutex);
182 + pthread_join(go->workerId, NULL);
185 for(i=0; i < go->nNumBuffers; i++)
187 gcmVERIFY_OK(gcoSURF_Destroy(go->renderSurf[i]));
190 free(go->renderSurf);
191 go->renderSurf = gcvNULL;
193 @@ -1182,9 +1217,28 @@ gal2d_renderer_output_create(struct weston_output *output, NativeDisplayType dis
195 go->renderSurf = malloc(sizeof(gcoSURF) * go->nNumBuffers);
196 gcoOS_GetDisplayVirtual(go->display, &width, &height);
197 + gcoOS_SetSwapInterval(go->display, 1);
199 + /*Needed only for multi Buffer */
200 + if(go->nNumBuffers > 1)
202 + gcmVERIFY_OK(gcoOS_CreateSignal(gcvNULL, gcvFALSE,
204 + gcmVERIFY_OK(gcoOS_CreateSignal(gcvNULL, gcvFALSE,
207 + go->iface.command = gcvHAL_SIGNAL;
208 + go->iface.u.Signal.signal = gcmPTR_TO_UINT64(go->signal);
209 + go->iface.u.Signal.auxSignal = 0;
210 + go->iface.u.Signal.process = gcmPTR_TO_UINT64(gcoOS_GetCurrentProcessID());
211 + go->iface.u.Signal.fromWhere = gcvKERNEL_PIXEL;
213 + go->exitWorker = 0;
214 + pthread_create(&go->workerId, NULL, gal2d_output_worker, output);
215 + pthread_mutex_init(&go->workerMutex, gcvNULL);
217 for(i=0; i < go->nNumBuffers; i++)
220 gcmONERROR(gcoSURF_Construct(gr->gcoHal, info.width, info.height, 1,
221 gcvSURF_BITMAP, go->format, gcvPOOL_USER, &go->renderSurf[i]));
223 @@ -1200,7 +1254,7 @@ gal2d_renderer_output_create(struct weston_output *output, NativeDisplayType dis
224 go->activebuffer = 0;
226 go->activebuffer = 1;
229 if(go->nNumBuffers <= 1 )
231 gcmVERIFY_OK(gcoSURF_Construct(gr->gcoHal,
232 @@ -1213,8 +1267,11 @@ gal2d_renderer_output_create(struct weston_output *output, NativeDisplayType dis
233 &go->offscreenSurface));
234 make_current(gr, go->offscreenSurface);
236 - gal2d_flip_surface(output);
240 + gcoOS_Signal(gcvNULL,go->busySignal, gcvTRUE);
243 for (i = 0; i < 2; i++)
244 pixman_region32_init(&go->buffer_damage[i]);