summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Hochstein <tom.hochstein@nxp.com>2017-01-25 08:57:22 -0600
committerOtavio Salvador <otavio@ossystems.com.br>2017-01-25 14:28:30 -0200
commit7dddff9f7ad69d79e3daf4c47d7aa14c740db369 (patch)
tree5ed2297fd89fdd7557aa6e77e5913c444e6d031b
parent37619f7e5e9d62ecb0a4effbc675c601b959af14 (diff)
downloadmeta-freescale-7dddff9f7ad69d79e3daf4c47d7aa14c740db369.tar.gz
weston: Consolidate i.MX GPU patches
This is a non-functional change with one small exception, an additional variable initialization that has no known behavioral effect: Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
-rw-r--r--recipes-graphics/wayland/weston/0001-MGS-2352-ccc-Add-GPU-VIV-support-for-weston-1.11.patch135
-rw-r--r--recipes-graphics/wayland/weston/0002-MGS-1111-Add-GPU-VIV-suport-for-wayland-and-weston-1.patch1708
-rw-r--r--recipes-graphics/wayland/weston/0002-MGS-2521-ccc-Enable-g2d-renderer-for-weston-1.11.patch1605
-rw-r--r--recipes-graphics/wayland/weston/0003-MGS-1192-xwld-g2d-compositor-dose-not-work.patch28
-rw-r--r--recipes-graphics/wayland/weston/0003-MGS-1783-xwld-Add-clone-mode-support-for-multi-displ.patch104
-rw-r--r--recipes-graphics/wayland/weston/0004-MGS-1235-Fix-setenv-and-clear-environments.patch41
-rw-r--r--recipes-graphics/wayland/weston/0004-MGS-1668-xwld-System-can-not-boot-up-to-desktop.patch (renamed from recipes-graphics/wayland/weston/0019-MGS-1668-xwld-System-can-not-boot-up-to-desktop.patch)8
-rw-r--r--recipes-graphics/wayland/weston/0005-MGS-1252-Fix-for-Qt5_CinematicExperience-will-meet-s.patch93
-rw-r--r--recipes-graphics/wayland/weston/0005-MGS-1724-xwld-G2D-compositor-build-failed-in-slevk-b.patch146
-rw-r--r--recipes-graphics/wayland/weston/0006-Link-compositor-to-egl.patch (renamed from recipes-graphics/wayland/weston/0016-Link-compositor-to-egl.patch)0
-rw-r--r--recipes-graphics/wayland/weston/0006-MGS-1236-imx6qp-imx6dl-First-frame-distored-when-som.patch106
-rw-r--r--recipes-graphics/wayland/weston/0007-MGS-1236-1-imx6qp-imx6dl-First-frame-distored-when-s.patch51
-rw-r--r--recipes-graphics/wayland/weston/0007-xwayland-Fix-crash-when-run-with-no-input-device.patch (renamed from recipes-graphics/wayland/weston/0020-xwayland-Fix-crash-when-run-with-no-input-device.patch)0
-rw-r--r--recipes-graphics/wayland/weston/0009-MGS-1284-xwld-Re-implement-weston-2d-renderer-with-p.patch2843
-rw-r--r--recipes-graphics/wayland/weston/0010-MGS-1284-1-xwld-Re-implement-weston-2d-renderer-with.patch36
-rw-r--r--recipes-graphics/wayland/weston/0011-MGS-1724-xwld-G2D-compositor-build-failed-in-slevk-b.patch129
-rw-r--r--recipes-graphics/wayland/weston/0012-MGS-1783-xwld-Add-clone-mode-support-for-multi-displ.patch421
-rw-r--r--recipes-graphics/wayland/weston/0013-MGS-1945-Use-common-API-to-support-G2d-compositor.patch196
-rw-r--r--recipes-graphics/wayland/weston/0014-MGS-1987-Get-stride-from-the-FB-buffe.patch76
-rw-r--r--recipes-graphics/wayland/weston/0015-MGS-2221-imx-171-Fix-weston-build-failed.patch62
-rw-r--r--recipes-graphics/wayland/weston/0017-MGS-2343-ccc-XWLD-T3DStressTest_Wayland-displays-abn.patch40
-rw-r--r--recipes-graphics/wayland/weston/0018-MGS-2397-ccc-Enable-double-buffer-with-fb_pan_displa.patch48
-rw-r--r--recipes-graphics/wayland/weston_%.bbappend25
23 files changed, 2001 insertions, 5900 deletions
diff --git a/recipes-graphics/wayland/weston/0001-MGS-2352-ccc-Add-GPU-VIV-support-for-weston-1.11.patch b/recipes-graphics/wayland/weston/0001-MGS-2352-ccc-Add-GPU-VIV-support-for-weston-1.11.patch
new file mode 100644
index 00000000..37a2d4c2
--- /dev/null
+++ b/recipes-graphics/wayland/weston/0001-MGS-2352-ccc-Add-GPU-VIV-support-for-weston-1.11.patch
@@ -0,0 +1,135 @@
1From dfad4d734412e4ec53bfff29c7c503479857f66c Mon Sep 17 00:00:00 2001
2From: Meng Mingming <mingming.meng@nxp.com>
3Date: Mon, 9 Jan 2017 15:04:27 +0800
4Subject: [PATCH 1/5] MGS-2352 [#ccc] Add GPU-VIV support for weston 1.11
5
6Add GPU-VIV support for weston 1.11
7
8Upstream Status: Inappropriate [i.MX specific]
9
10Date: Jan 09, 2017
11Signed-off-by: Meng Mingming <mingming.meng@nxp.com>
12---
13 src/compositor-fbdev.c | 37 ++++++++++++++++++++++++++++---------
14 1 file changed, 28 insertions(+), 9 deletions(-)
15
16diff --git a/src/compositor-fbdev.c b/src/compositor-fbdev.c
17index ee762e3..06f4696 100644
18--- a/src/compositor-fbdev.c
19+++ b/src/compositor-fbdev.c
20@@ -61,6 +61,7 @@ struct fbdev_backend {
21 int use_pixman;
22 uint32_t output_transform;
23 struct wl_listener session_listener;
24+ NativeDisplayType display;
25 };
26
27 struct fbdev_screeninfo {
28@@ -93,6 +94,9 @@ struct fbdev_output {
29 /* pixman details. */
30 pixman_image_t *hw_surface;
31 uint8_t depth;
32+
33+ NativeDisplayType display;
34+ NativeWindowType window;
35 };
36
37 struct gl_renderer_interface *gl_renderer;
38@@ -443,6 +447,10 @@ fbdev_frame_buffer_destroy(struct fbdev_output *output)
39 strerror(errno));
40
41 output->fb = NULL;
42+ if(output->window)
43+ fbDestroyWindow(output->window);
44+ if(output->display)
45+ fbDestroyDisplay(output->display);
46 }
47
48 static void fbdev_output_destroy(struct weston_output *base);
49@@ -450,13 +458,13 @@ static void fbdev_output_disable(struct weston_output *base);
50
51 static int
52 fbdev_output_create(struct fbdev_backend *backend,
53- const char *device)
54+ int x, int y, const char *device)
55 {
56 struct fbdev_output *output;
57 int fb_fd;
58 struct wl_event_loop *loop;
59
60- weston_log("Creating fbdev output.\n");
61+ weston_log("Creating fbdev output. %s x=%d y=%d\n", device, x, y);
62
63 output = zalloc(sizeof *output);
64 if (output == NULL)
65@@ -500,7 +508,7 @@ fbdev_output_create(struct fbdev_backend *backend,
66 output->base.name = strdup("fbdev");
67
68 weston_output_init(&output->base, backend->compositor,
69- 0, 0, output->fb_info.width_mm,
70+ x, y, output->fb_info.width_mm,
71 output->fb_info.height_mm,
72 backend->output_transform,
73 1);
74@@ -510,8 +518,13 @@ fbdev_output_create(struct fbdev_backend *backend,
75 goto out_hw_surface;
76 } else {
77 setenv("HYBRIS_EGLPLATFORM", "wayland", 1);
78+ output->window = fbCreateWindow(backend->display, -1, -1, 0, 0);
79+ if (output->window == NULL) {
80+ fprintf(stderr, "failed to create window\n");
81+ return 0;
82+ }
83 if (gl_renderer->output_create(&output->base,
84- (EGLNativeWindowType)NULL, NULL,
85+ (EGLNativeWindowType)output->window, NULL,
86 gl_renderer->opaque_attribs,
87 NULL, 0) < 0) {
88 weston_log("gl_renderer_output_create failed.\n");
89@@ -622,7 +635,7 @@ fbdev_output_reenable(struct fbdev_backend *backend,
90 * are re-initialised. */
91 device = strdup(output->device);
92 fbdev_output_destroy(&output->base);
93- fbdev_output_create(backend, device);
94+ fbdev_output_create(backend, 0, 0, device);
95 free(device);
96
97 return 0;
98@@ -785,17 +798,21 @@ fbdev_backend_create(struct weston_compositor *compositor, int *argc, char *argv
99 goto out_launcher;
100 }
101
102+ backend->display = fbGetDisplay(backend->compositor->wl_display);
103+ if (backend->display == NULL) {
104+ weston_log("fbGetDisplay failed.\n");
105+ goto out_launcher;
106+ }
107 if (gl_renderer->create(compositor, NO_EGL_PLATFORM,
108- EGL_DEFAULT_DISPLAY,
109+ backend->display,
110 gl_renderer->opaque_attribs,
111 NULL, 0) < 0) {
112 weston_log("gl_renderer_create failed.\n");
113 goto out_launcher;
114 }
115 }
116-
117- if (fbdev_output_create(backend, param->device) < 0)
118- goto out_launcher;
119+ if (fbdev_output_create(backend, 0, 0, param->device) < 0)
120+ goto out_launcher;
121
122 udev_input_init(&backend->input, compositor, backend->udev, seat_id);
123
124@@ -844,6 +861,8 @@ backend_init(struct weston_compositor *compositor, int *argc, char *argv[],
125 config_init_to_defaults(&config);
126 memcpy(&config, config_base, config_base->struct_size);
127
128+ config.use_gl = 1;
129+
130 b = fbdev_backend_create(compositor, argc, argv, wc, &config);
131 if (b == NULL)
132 return -1;
133--
1342.7.4
135
diff --git a/recipes-graphics/wayland/weston/0002-MGS-1111-Add-GPU-VIV-suport-for-wayland-and-weston-1.patch b/recipes-graphics/wayland/weston/0002-MGS-1111-Add-GPU-VIV-suport-for-wayland-and-weston-1.patch
deleted file mode 100644
index cfe8f605..00000000
--- a/recipes-graphics/wayland/weston/0002-MGS-1111-Add-GPU-VIV-suport-for-wayland-and-weston-1.patch
+++ /dev/null
@@ -1,1708 +0,0 @@
1From e766967ae24d15048c01d03de09fc39757d13ec3 Mon Sep 17 00:00:00 2001
2From: Prabhu <prabhu.sundararaj@freescale.com>
3Date: Sat, 3 Oct 2015 19:44:33 -0500
4Subject: [PATCH] MGS-1111: Add GPU-VIV suport for wayland and weston 1.9
5
6Add support GPU-VIV support for weston 1.9
7
8Signed-off-by: Prabhu <prabhu.sundararaj@freescale.com>
9---
10 Makefile.am | 12 +
11 src/compositor-fbdev.c | 128 ++++-
12 src/gal2d-renderer.c | 1342 ++++++++++++++++++++++++++++++++++++++++++++++++
13 src/gal2d-renderer.h | 50 ++
14 4 files changed, 1519 insertions(+), 13 deletions(-)
15 create mode 100644 src/gal2d-renderer.c
16 create mode 100644 src/gal2d-renderer.h
17
18Index: weston-1.11.1/Makefile.am
19===================================================================
20--- weston-1.11.1.orig/Makefile.am 2016-09-20 19:35:22.000000000 -0500
21+++ weston-1.11.1/Makefile.am 2017-01-14 08:35:10.000000000 -0600
22@@ -247,6 +247,18 @@
23 src/vertex-clipping.h \
24 shared/helpers.h
25 endif
26+module_LTLIBRARIES += gal2d-renderer.la
27+gal2d_renderer_la_LDFLAGS = -module -avoid-version
28+gal2d_renderer_la_LIBADD = $(COMPOSITOR_LIBS) $(EGL_LIBS)
29+gal2d_renderer_la_CFLAGS = \
30+ $(COMPOSITOR_CFLAGS) \
31+ $(EGL_CFLAGS) \
32+ $(GCC_CFLAGS)
33+gal2d_renderer_la_SOURCES = \
34+ src/gal2d-renderer.h \
35+ src/gal2d-renderer.c \
36+ src/vertex-clipping.c \
37+ src/vertex-clipping.h
38
39 if ENABLE_X11_COMPOSITOR
40 module_LTLIBRARIES += x11-backend.la
41Index: weston-1.11.1/src/compositor-fbdev.c
42===================================================================
43--- weston-1.11.1.orig/src/compositor-fbdev.c 2016-09-20 19:35:22.000000000 -0500
44+++ weston-1.11.1/src/compositor-fbdev.c 2017-01-14 08:35:11.000000000 -0600
45@@ -50,6 +50,7 @@
46 #include "libinput-seat.h"
47 #include "gl-renderer.h"
48 #include "presentation-time-server-protocol.h"
49+#include "gal2d-renderer.h"
50
51 struct fbdev_backend {
52 struct weston_backend base;
53@@ -59,8 +60,10 @@
54 struct udev *udev;
55 struct udev_input input;
56 int use_pixman;
57+ int use_gal2d;
58 uint32_t output_transform;
59 struct wl_listener session_listener;
60+ NativeDisplayType display;
61 };
62
63 struct fbdev_screeninfo {
64@@ -93,9 +96,13 @@
65 /* pixman details. */
66 pixman_image_t *hw_surface;
67 uint8_t depth;
68+
69+ NativeDisplayType display;
70+ NativeWindowType window;
71 };
72
73 struct gl_renderer_interface *gl_renderer;
74+struct gal2d_renderer_interface *gal2d_renderer;
75
76 static const char default_seat[] = "seat0";
77
78@@ -443,6 +450,10 @@
79 strerror(errno));
80
81 output->fb = NULL;
82+ if(output->window)
83+ fbDestroyWindow(output->window);
84+ if(output->display)
85+ fbDestroyDisplay(output->display);
86 }
87
88 static void fbdev_output_destroy(struct weston_output *base);
89@@ -450,13 +461,13 @@
90
91 static int
92 fbdev_output_create(struct fbdev_backend *backend,
93- const char *device)
94+ int x, int y, const char *device)
95 {
96 struct fbdev_output *output;
97 int fb_fd;
98 struct wl_event_loop *loop;
99
100- weston_log("Creating fbdev output.\n");
101+ weston_log("Creating fbdev output. %s x=%d y=%d\n", device, x, y);
102
103 output = zalloc(sizeof *output);
104 if (output == NULL)
105@@ -500,7 +511,7 @@
106 output->base.name = strdup("fbdev");
107
108 weston_output_init(&output->base, backend->compositor,
109- 0, 0, output->fb_info.width_mm,
110+ x, y, output->fb_info.width_mm,
111 output->fb_info.height_mm,
112 backend->output_transform,
113 1);
114@@ -508,10 +519,39 @@
115 if (backend->use_pixman) {
116 if (pixman_renderer_output_create(&output->base) < 0)
117 goto out_hw_surface;
118+ } else if(backend->use_gal2d) {
119+
120+ char* fbenv = getenv("FB_FRAMEBUFFER_0");
121+ setenv("FB_FRAMEBUFFER_0", device, 1);
122+ output->display = fbGetDisplay(backend->compositor->wl_display);
123+ if (output->display == NULL) {
124+ fprintf(stderr, "failed to get display\n");
125+ return 0;
126+ }
127+
128+ output->window = fbCreateWindow(output->display, -1, -1, 0, 0);
129+ if (output->window == NULL) {
130+ fprintf(stderr, "failed to create window\n");
131+ return 0;
132+ }
133+ setenv("FB_FRAMEBUFFER_0", fbenv, 1);
134+
135+ if (gal2d_renderer->output_create(&output->base,
136+ output->display,
137+ (NativeWindowType)output->window) < 0) {
138+ weston_log("gal_renderer_output_create failed.\n");
139+ goto out_hw_surface;
140+ }
141+
142 } else {
143 setenv("HYBRIS_EGLPLATFORM", "wayland", 1);
144+ output->window = fbCreateWindow(backend->display, -1, -1, 0, 0);
145+ if (output->window == NULL) {
146+ fprintf(stderr, "failed to create window\n");
147+ return 0;
148+ }
149 if (gl_renderer->output_create(&output->base,
150- (EGLNativeWindowType)NULL, NULL,
151+ (EGLNativeWindowType)output->window, NULL,
152 gl_renderer->opaque_attribs,
153 NULL, 0) < 0) {
154 weston_log("gl_renderer_output_create failed.\n");
155@@ -558,6 +598,8 @@
156 if (backend->use_pixman) {
157 if (base->renderer_state != NULL)
158 pixman_renderer_output_destroy(base);
159+ } else if (backend->use_gal2d) {
160+ gal2d_renderer->output_destroy(base);
161 } else {
162 gl_renderer->output_destroy(base);
163 }
164@@ -622,7 +664,7 @@
165 * are re-initialised. */
166 device = strdup(output->device);
167 fbdev_output_destroy(&output->base);
168- fbdev_output_create(backend, device);
169+ fbdev_output_create(backend, 0, 0, device);
170 free(device);
171
172 return 0;
173@@ -777,7 +819,50 @@
174 if (backend->use_pixman) {
175 if (pixman_renderer_init(compositor) < 0)
176 goto out_launcher;
177- } else {
178+ }
179+ else if (backend->use_gal2d) {
180+ int x = 0, y = 0;
181+ int i=0;
182+ int count = 0;
183+ int k=0, dispCount = 0;
184+ char displays[5][32];
185+ gal2d_renderer = weston_load_module("gal2d-renderer.so",
186+ "gal2d_renderer_interface");
187+ if (!gal2d_renderer) {
188+ weston_log("could not load gal2d renderer\n");
189+ goto out_launcher;
190+ }
191+
192+ if (gal2d_renderer->create(backend->compositor) < 0) {
193+ weston_log("gal2d_renderer_create failed.\n");
194+ goto out_launcher;
195+ }
196+
197+ weston_log("param->device=%s\n",param->device);
198+ count = strlen(param->device);
199+
200+ for(i= 0; i < count; i++) {
201+ if(param->device[i] == ',') {
202+ displays[dispCount][k] = '\0';
203+ dispCount++;
204+ k = 0;
205+ continue;
206+ }
207+ displays[dispCount][k++] = param->device[i];
208+ }
209+ displays[dispCount][k] = '\0';
210+ dispCount++;
211+
212+ for(i=0; i<dispCount; i++)
213+ {
214+ if (fbdev_output_create(backend, x, y, displays[i]) < 0)
215+ goto out_launcher;
216+ x += container_of(backend->compositor->output_list.prev,
217+ struct weston_output,
218+ link)->width;
219+ }
220+ }
221+ else {
222 gl_renderer = weston_load_module("gl-renderer.so",
223 "gl_renderer_interface");
224 if (!gl_renderer) {
225@@ -785,17 +870,22 @@
226 goto out_launcher;
227 }
228
229+ backend->display = fbGetDisplay(backend->compositor->wl_display);
230+ if (backend->display == NULL) {
231+ weston_log("fbGetDisplay failed.\n");
232+ goto out_launcher;
233+ }
234 if (gl_renderer->create(compositor, NO_EGL_PLATFORM,
235- EGL_DEFAULT_DISPLAY,
236+ backend->display,
237 gl_renderer->opaque_attribs,
238 NULL, 0) < 0) {
239 weston_log("gl_renderer_create failed.\n");
240 goto out_launcher;
241 }
242 }
243-
244- if (fbdev_output_create(backend, param->device) < 0)
245- goto out_launcher;
246+ if(!backend->use_gal2d)
247+ if (fbdev_output_create(backend, 0, 0, param->device) < 0)
248+ goto out_launcher;
249
250 udev_input_init(&backend->input, compositor, backend->udev, seat_id);
251
252@@ -822,7 +912,13 @@
253 * udev, rather than passing a device node in as a parameter. */
254 config->tty = 0; /* default to current tty */
255 config->device = "/dev/fb0"; /* default frame buffer */
256+#ifdef ENABLE_EGL
257+ config->use_gl = 1;
258+ config->use_gal2d = 0;
259+#else
260 config->use_gl = 0;
261+ config->use_gal2d = 1;
262+#endif
263 config->output_transform = WL_OUTPUT_TRANSFORM_NORMAL;
264 }
265
266Index: weston-1.11.1/src/gal2d-renderer.c
267===================================================================
268--- /dev/null 1970-01-01 00:00:00.000000000 +0000
269+++ weston-1.11.1/src/gal2d-renderer.c 2017-01-14 08:35:10.000000000 -0600
270@@ -0,0 +1,1342 @@
271+/*
272+ * Copyright (c) 2015 Freescale Semiconductor, Inc.
273+ * Copyright © 2012 Intel Corporation
274+ * Copyright © 2015 Collabora, Ltd.
275+ *
276+ * Permission is hereby granted, free of charge, to any person obtaining
277+ * a copy of this software and associated documentation files (the
278+ * "Software"), to deal in the Software without restriction, including
279+ * without limitation the rights to use, copy, modify, merge, publish,
280+ * distribute, sublicense, and/or sell copies of the Software, and to
281+ * permit persons to whom the Software is furnished to do so, subject to
282+ * the following conditions:
283+ *
284+ * The above copyright notice and this permission notice (including the
285+ * next paragraph) shall be included in all copies or substantial
286+ * portions of the Software.
287+ *
288+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
289+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
290+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
291+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
292+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
293+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
294+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
295+ * SOFTWARE.
296+ */
297+
298+#define _GNU_SOURCE
299+
300+#include <stdlib.h>
301+#include <string.h>
302+#include <ctype.h>
303+#include <float.h>
304+#include <assert.h>
305+#include <pthread.h>
306+
307+#include "compositor.h"
308+#include "gal2d-renderer.h"
309+#include "vertex-clipping.h"
310+#include "shared/helpers.h"
311+#include "HAL/gc_hal.h"
312+#include "HAL/gc_hal_raster.h"
313+#include "HAL/gc_hal_eglplatform.h"
314+
315+#define galONERROR(x) if(status < 0) printf("Error in function %s\n", __func__);
316+
317+struct gal2d_output_state {
318+
319+ int current_buffer;
320+ pixman_region32_t buffer_damage[2];
321+ NativeDisplayType display;
322+ gcoSURF* renderSurf;
323+ gctUINT32 nNumBuffers;
324+ int activebuffer;
325+ gcoSURF offscreenSurface;
326+ gceSURF_FORMAT format;
327+ pthread_mutex_t workerMutex;
328+ pthread_t workerId;
329+ gctUINT32 exitWorker;
330+ gctSIGNAL signal;
331+ gctSIGNAL busySignal;
332+ gcsHAL_INTERFACE iface;
333+ int directBlit;
334+ gctINT width;
335+ gctINT height;
336+};
337+
338+struct gal2d_surface_state {
339+ float color[4];
340+ struct weston_buffer_reference buffer_ref;
341+ int pitch; /* in pixels */
342+ pixman_region32_t texture_damage;
343+ gcoSURF gco_Surface;
344+
345+ struct weston_surface *surface;
346+ struct wl_listener surface_destroy_listener;
347+ struct wl_listener renderer_destroy_listener;
348+};
349+
350+struct gal2d_renderer {
351+ struct weston_renderer base;
352+ struct wl_signal destroy_signal;
353+ gcoOS gcos;
354+ gcoHAL gcoHal;
355+ gco2D gcoEngine2d;
356+ gctPOINTER localInfo;
357+};
358+
359+static int
360+gal2d_renderer_create_surface(struct weston_surface *surface);
361+
362+static inline struct gal2d_surface_state *
363+get_surface_state(struct weston_surface *surface)
364+{
365+ if (!surface->renderer_state)
366+ gal2d_renderer_create_surface(surface);
367+ return (struct gal2d_surface_state *)surface->renderer_state;
368+}
369+
370+static inline struct gal2d_renderer *
371+get_renderer(struct weston_compositor *ec)
372+{
373+ return (struct gal2d_renderer *)ec->renderer;
374+}
375+
376+
377+
378+#define max(a, b) (((a) > (b)) ? (a) : (b))
379+#define min(a, b) (((a) > (b)) ? (b) : (a))
380+/*
381+ * Compute the boundary vertices of the intersection of the global coordinate
382+ * aligned rectangle 'rect', and an arbitrary quadrilateral produced from
383+ * 'surf_rect' when transformed from surface coordinates into global coordinates.
384+ * The vertices are written to 'ex' and 'ey', and the return value is the
385+ * number of vertices. Vertices are produced in clockwise winding order.
386+ * Guarantees to produce either zero vertices, or 3-8 vertices with non-zero
387+ * polygon area.
388+ */
389+static int
390+calculate_edges(struct weston_view *ev, pixman_box32_t *rect,
391+ pixman_box32_t *surf_rect, float *ex, float *ey)
392+{
393+
394+ struct clip_context ctx;
395+ int i, n;
396+ float min_x, max_x, min_y, max_y;
397+ struct polygon8 surf = {
398+ { surf_rect->x1, surf_rect->x2, surf_rect->x2, surf_rect->x1 },
399+ { surf_rect->y1, surf_rect->y1, surf_rect->y2, surf_rect->y2 },
400+ 4
401+ };
402+
403+ ctx.clip.x1 = rect->x1;
404+ ctx.clip.y1 = rect->y1;
405+ ctx.clip.x2 = rect->x2;
406+ ctx.clip.y2 = rect->y2;
407+
408+ /* transform surface to screen space: */
409+ for (i = 0; i < surf.n; i++)
410+ weston_view_to_global_float(ev, surf.x[i], surf.y[i],
411+ &surf.x[i], &surf.y[i]);
412+
413+ /* find bounding box: */
414+ min_x = max_x = surf.x[0];
415+ min_y = max_y = surf.y[0];
416+
417+ for (i = 1; i < surf.n; i++) {
418+ min_x = min(min_x, surf.x[i]);
419+ max_x = max(max_x, surf.x[i]);
420+ min_y = min(min_y, surf.y[i]);
421+ max_y = max(max_y, surf.y[i]);
422+ }
423+
424+ /* First, simple bounding box check to discard early transformed
425+ * surface rects that do not intersect with the clip region:
426+ */
427+ if ((min_x >= ctx.clip.x2) || (max_x <= ctx.clip.x1) ||
428+ (min_y >= ctx.clip.y2) || (max_y <= ctx.clip.y1))
429+ return 0;
430+
431+ /* Simple case, bounding box edges are parallel to surface edges,
432+ * there will be only four edges. We just need to clip the surface
433+ * vertices to the clip rect bounds:
434+ */
435+ if (!ev->transform.enabled)
436+ return clip_simple(&ctx, &surf, ex, ey);
437+
438+ /* Transformed case: use a general polygon clipping algorithm to
439+ * clip the surface rectangle with each side of 'rect'.
440+ * The algorithm is Sutherland-Hodgman, as explained in
441+ * http://www.codeguru.com/cpp/misc/misc/graphics/article.php/c8965/Polygon-Clipping.htm
442+ * but without looking at any of that code.
443+ */
444+ n = clip_transformed(&ctx, &surf, ex, ey);
445+
446+ if (n < 3)
447+ return 0;
448+
449+ return n;
450+}
451+
452+
453+static inline struct gal2d_output_state *
454+get_output_state(struct weston_output *output)
455+{
456+ return (struct gal2d_output_state *)output->renderer_state;
457+}
458+
459+static gctUINT32
460+galGetStretchFactor(gctINT32 SrcSize, gctINT32 DestSize)
461+{
462+ gctUINT stretchFactor;
463+ if ( (SrcSize > 0) && (DestSize > 1) )
464+ {
465+ stretchFactor = ((SrcSize - 1) << 16) / (DestSize - 1);
466+ }
467+ else
468+ {
469+ stretchFactor = 0;
470+ }
471+ return stretchFactor;
472+}
473+
474+static gceSTATUS
475+galGetStretchFactors(
476+ IN gcsRECT_PTR SrcRect,
477+ IN gcsRECT_PTR DestRect,
478+ OUT gctUINT32 * HorFactor,
479+ OUT gctUINT32 * VerFactor
480+ )
481+{
482+ if (HorFactor != gcvNULL)
483+ {
484+ gctINT32 src, dest;
485+
486+ /* Compute width of rectangles. */
487+ gcmVERIFY_OK(gcsRECT_Width(SrcRect, &src));
488+ gcmVERIFY_OK(gcsRECT_Width(DestRect, &dest));
489+
490+ /* Compute and return horizontal stretch factor. */
491+ *HorFactor = galGetStretchFactor(src, dest);
492+ }
493+
494+ if (VerFactor != gcvNULL)
495+ {
496+ gctINT32 src, dest;
497+
498+ /* Compute height of rectangles. */
499+ gcmVERIFY_OK(gcsRECT_Height(SrcRect, &src));
500+ gcmVERIFY_OK(gcsRECT_Height(DestRect, &dest));
501+
502+ /* Compute and return vertical stretch factor. */
503+ *VerFactor = galGetStretchFactor(src, dest);
504+ }
505+ /* Success. */
506+ return gcvSTATUS_OK;
507+}
508+
509+static gceSTATUS
510+gal2d_getSurfaceFormat(halDISPLAY_INFO info, gceSURF_FORMAT * Format)
511+{
512+ /* Get the color format. */
513+ switch (info.greenLength)
514+ {
515+ case 4:
516+ if (info.blueOffset == 0)
517+ {
518+ *Format = (info.alphaLength == 0) ? gcvSURF_X4R4G4B4 : gcvSURF_A4R4G4B4;
519+ }
520+ else
521+ {
522+ *Format = (info.alphaLength == 0) ? gcvSURF_X4B4G4R4 : gcvSURF_A4B4G4R4;
523+ }
524+ break;
525+
526+ case 5:
527+ if (info.blueOffset == 0)
528+ {
529+ *Format = (info.alphaLength == 0) ? gcvSURF_X1R5G5B5 : gcvSURF_A1R5G5B5;
530+ }
531+ else
532+ {
533+ *Format = (info.alphaLength == 0) ? gcvSURF_X1B5G5R5 : gcvSURF_A1B5G5R5;
534+ }
535+ break;
536+
537+ case 6:
538+ *Format = gcvSURF_R5G6B5;
539+ break;
540+
541+ case 8:
542+ if (info.blueOffset == 0)
543+ {
544+ *Format = (info.alphaLength == 0) ? gcvSURF_X8R8G8B8 : gcvSURF_A8R8G8B8;
545+ }
546+ else
547+ {
548+ *Format = (info.alphaLength == 0) ? gcvSURF_X8B8G8R8 : gcvSURF_A8B8G8R8;
549+ }
550+ break;
551+
552+ default:
553+ /* Unsupported color depth. */
554+ return gcvSTATUS_INVALID_ARGUMENT;
555+ }
556+ /* Success. */
557+ return gcvSTATUS_OK;
558+}
559+
560+static gceSTATUS galIsYUVFormat(IN gceSURF_FORMAT Format)
561+{
562+ switch (Format)
563+ {
564+ case gcvSURF_YUY2:
565+ case gcvSURF_UYVY:
566+ case gcvSURF_I420:
567+ case gcvSURF_YV12:
568+ case gcvSURF_NV16:
569+ case gcvSURF_NV12:
570+ case gcvSURF_NV61:
571+ case gcvSURF_NV21:
572+
573+ return gcvSTATUS_TRUE;
574+
575+ default:
576+ return gcvSTATUS_FALSE;
577+ }
578+}
579+
580+static gceSTATUS galQueryUVStride(
581+ IN gceSURF_FORMAT Format,
582+ IN gctUINT32 yStride,
583+ OUT gctUINT32_PTR uStride,
584+ OUT gctUINT32_PTR vStride
585+ )
586+{
587+ switch (Format)
588+ {
589+ case gcvSURF_YUY2:
590+ case gcvSURF_UYVY:
591+ *uStride = *vStride = 0;
592+ break;
593+
594+ case gcvSURF_I420:
595+ case gcvSURF_YV12:
596+ *uStride = *vStride = yStride / 2;
597+ break;
598+
599+ case gcvSURF_NV16:
600+ case gcvSURF_NV12:
601+ case gcvSURF_NV61:
602+ case gcvSURF_NV21:
603+
604+ *uStride = yStride;
605+ *vStride = 0;
606+ break;
607+
608+ default:
609+ return gcvSTATUS_NOT_SUPPORTED;
610+ }
611+
612+ return gcvSTATUS_OK;
613+}
614+
615+static int
616+make_current(struct gal2d_renderer *gr, gcoSURF surface)
617+{
618+ gceSTATUS status = gcvSTATUS_OK;
619+ gctUINT width = 0;
620+ gctUINT height = 0;
621+ gctINT stride = 0;
622+ gctUINT32 physical[3];
623+ gctPOINTER va =0;
624+ gceSURF_FORMAT format;
625+
626+ if(!surface)
627+ goto OnError;
628+
629+
630+ gcmONERROR(gcoSURF_GetAlignedSize(surface, &width, &height, &stride));
631+ gcmONERROR(gcoSURF_GetFormat(surface, gcvNULL, &format));
632+ gcmONERROR(gcoSURF_Lock(surface, &physical[0], (gctPOINTER *)&va));
633+ gco2D_SetGenericTarget(gr->gcoEngine2d,
634+ &physical[0], 1,
635+ &stride, 1,
636+ gcvLINEAR, format,
637+ gcvSURF_0_DEGREE, width, height);
638+
639+ gcmONERROR(gcoSURF_Unlock(surface, (gctPOINTER *)&va));
640+OnError:
641+ galONERROR(status);
642+ return status;
643+}
644+
645+static gceSTATUS
646+gal2d_clear(struct weston_output *base)
647+{
648+ struct gal2d_renderer *gr = get_renderer(base->compositor);
649+ struct gal2d_output_state *go = get_output_state(base);
650+ gceSTATUS status = gcvSTATUS_OK;
651+
652+ gctINT stride = 0;
653+ gctUINT width = 0, height = 0;
654+ gcsRECT dstRect = {0};
655+ gcmONERROR(gcoSURF_GetAlignedSize(go->renderSurf[go->activebuffer],
656+ &width, &height, &stride));
657+ dstRect.right = width;
658+ dstRect.bottom = height;
659+ gcmONERROR(gco2D_SetSource(gr->gcoEngine2d, &dstRect));
660+ gcmONERROR(gco2D_SetClipping(gr->gcoEngine2d, &dstRect));
661+ gcmONERROR(gco2D_Clear(gr->gcoEngine2d, 1, &dstRect, 0xff0000ff, 0xCC, 0xCC, go->format));
662+ gcmONERROR(gcoHAL_Commit(gr->gcoHal, gcvTRUE));
663+
664+OnError:
665+ galONERROR(status);
666+
667+ return status;
668+}
669+
670+static gcoSURF getSurfaceFromShm(struct weston_surface *es, struct weston_buffer *buffer)
671+{
672+ struct gal2d_renderer *gr = get_renderer(es->compositor);
673+
674+ gcoSURF surface = 0;
675+ gceSURF_FORMAT format;
676+ gcePOOL pool = gcvPOOL_DEFAULT;
677+
678+ if (wl_shm_buffer_get_format(buffer->shm_buffer) == WL_SHM_FORMAT_XRGB8888)
679+ format = gcvSURF_X8R8G8B8;
680+ else
681+ format = gcvSURF_A8R8G8B8;
682+
683+ if(buffer->width == ((buffer->width + 0x7) & ~0x7))
684+ {
685+ pool = gcvPOOL_USER;
686+ }
687+
688+ gcmVERIFY_OK(gcoSURF_Construct(gr->gcoHal,
689+ (gctUINT) buffer->width,
690+ (gctUINT) buffer->height,
691+ 1, gcvSURF_BITMAP,
692+ format, pool, &surface));
693+
694+ if(pool == gcvPOOL_USER)
695+ {
696+ gcmVERIFY_OK(gcoSURF_MapUserSurface(surface, 1,
697+ (gctPOINTER)wl_shm_buffer_get_data(buffer->shm_buffer), gcvINVALID_ADDRESS));
698+ }
699+
700+ return surface;
701+}
702+
703+static int
704+gal2dBindBuffer(struct weston_surface* es)
705+{
706+ struct gal2d_surface_state *gs = get_surface_state(es);
707+ gceSTATUS status = gcvSTATUS_OK;
708+ gcoSURF surface = gs->gco_Surface;
709+ struct weston_buffer *buffer = gs->buffer_ref.buffer;
710+ gcePOOL pool = gcvPOOL_DEFAULT;
711+
712+ gcmVERIFY_OK(gcoSURF_QueryVidMemNode(surface, gcvNULL,
713+ &pool, gcvNULL));
714+
715+ if(pool != gcvPOOL_USER)
716+ {
717+ gctUINT alignedWidth;
718+ gctPOINTER logical = (gctPOINTER)wl_shm_buffer_get_data(buffer->shm_buffer);
719+ gctPOINTER va =0;
720+
721+
722+ gcmVERIFY_OK(gcoSURF_GetAlignedSize(surface, &alignedWidth, gcvNULL, gcvNULL));
723+ gcmVERIFY_OK(gcoSURF_Lock(surface, gcvNULL, (gctPOINTER *)&va));
724+
725+ if(alignedWidth == (unsigned int)buffer->width)
726+ {
727+ int size = wl_shm_buffer_get_stride(buffer->shm_buffer)*buffer->height;
728+ memcpy(va, logical, size);
729+ }
730+ else
731+ {
732+ int i, j;
733+ for (i = 0; i < buffer->height; i++)
734+ {
735+ for (j = 0; j < buffer->width; j++)
736+ {
737+ gctUINT dstOff = i * alignedWidth + j;
738+ gctUINT srcOff = (i * buffer->width + j);
739+
740+ memcpy(va + dstOff * 4, logical + srcOff * 4, 4);
741+ }
742+ }
743+ }
744+ gcmVERIFY_OK(gcoSURF_Unlock(surface, (gctPOINTER)va));
745+ }
746+
747+ return status;
748+}
749+
750+static void
751+gal2d_flip_surface(struct weston_output *output)
752+{
753+ struct gal2d_output_state *go = get_output_state(output);
754+
755+ if(go->nNumBuffers > 1)
756+ {
757+ gctUINT Offset;
758+ gctINT X;
759+ gctINT Y;
760+
761+ gcmVERIFY_OK(gcoOS_GetDisplayBackbuffer(go->display, gcvNULL,
762+ gcvNULL, gcvNULL, &Offset, &X, &Y));
763+
764+ gcmVERIFY_OK(gcoOS_SetDisplayVirtual(go->display, gcvNULL,
765+ Offset, X, Y));
766+ }
767+}
768+
769+static void *gal2d_output_worker(void *arg)
770+{
771+ struct weston_output *output = (struct weston_output *)arg;
772+ struct gal2d_output_state *go = get_output_state(output);
773+
774+ while(1)
775+ {
776+ if(gcoOS_WaitSignal(gcvNULL, go->signal, gcvINFINITE) == gcvSTATUS_OK )
777+ {
778+ gal2d_flip_surface(output);
779+ gcoOS_Signal(gcvNULL,go->busySignal, gcvTRUE);
780+ }
781+ pthread_mutex_lock(&go->workerMutex);
782+ if(go->exitWorker == 1)
783+ {
784+ pthread_mutex_unlock(&go->workerMutex);
785+ break;
786+ }
787+ pthread_mutex_unlock(&go->workerMutex);
788+ }
789+ return 0;
790+}
791+
792+static int
793+update_surface(struct weston_output *output)
794+{
795+ struct gal2d_renderer *gr = get_renderer(output->compositor);
796+ struct gal2d_output_state *go = get_output_state(output);
797+ gceSTATUS status = gcvSTATUS_OK;
798+
799+ if(go->nNumBuffers == 1)
800+ {
801+ if(!go->directBlit && go->offscreenSurface)
802+ {
803+ make_current(gr, go->renderSurf[go->activebuffer]);
804+
805+ gctUINT srcWidth = 0;
806+ gctUINT srcHeight = 0;
807+ gceSURF_FORMAT srcFormat;;
808+ gcsRECT dstRect = {0};
809+ gcoSURF srcSurface = go->offscreenSurface;
810+ gctUINT32 srcPhyAddr[3];
811+ gctUINT32 srcStride[3];
812+
813+ gctPOINTER va =0;
814+
815+ gcmONERROR(gcoSURF_GetAlignedSize(srcSurface, &srcWidth, &srcHeight, (gctINT *)&srcStride[0]));
816+ gcmONERROR(gcoSURF_GetFormat(srcSurface, gcvNULL, &srcFormat));
817+
818+ gcmONERROR(gcoSURF_Lock(srcSurface, srcPhyAddr, (gctPOINTER *)&va));
819+ gcmONERROR(gco2D_SetCurrentSourceIndex(gr->gcoEngine2d, 0U));
820+
821+ gco2D_SetGenericSource(gr->gcoEngine2d, srcPhyAddr, 1,
822+ srcStride, 1,
823+ gcvLINEAR, srcFormat, gcvSURF_0_DEGREE,
824+ srcWidth, srcHeight);
825+
826+ dstRect.left = 0;
827+ dstRect.top = 0;
828+ dstRect.right = srcWidth;
829+ dstRect.bottom = srcHeight;
830+
831+ gcmONERROR(gco2D_SetSource(gr->gcoEngine2d, &dstRect));
832+ gcmONERROR(gco2D_SetClipping(gr->gcoEngine2d, &dstRect));
833+ gcmONERROR(gco2D_Blit(gr->gcoEngine2d, 1, &dstRect, 0xCC, 0xCC, go->format));
834+ gcmONERROR(gcoSURF_Unlock(srcSurface, (gctPOINTER *)&va));
835+ }
836+ gcmONERROR(gcoHAL_Commit(gr->gcoHal, gcvFALSE));
837+ }
838+ else if(go->nNumBuffers > 1)
839+ {
840+ gcoHAL_ScheduleEvent(gr->gcoHal, &go->iface);
841+ gcmVERIFY_OK(gcoHAL_Commit(gr->gcoHal, gcvFALSE));
842+ }
843+OnError:
844+ galONERROR(status);
845+ return status;
846+ }
847+
848+static int
849+is_view_visible(struct weston_view *view)
850+{
851+ /* Return false, if surface is guaranteed to be totally obscured. */
852+ int ret;
853+ pixman_region32_t unocc;
854+
855+ pixman_region32_init(&unocc);
856+ pixman_region32_subtract(&unocc, &view->transform.boundingbox,
857+ &view->clip);
858+ ret = pixman_region32_not_empty(&unocc);
859+ pixman_region32_fini(&unocc);
860+
861+ return ret;
862+}
863+
864+static int
865+use_output(struct weston_output *output)
866+{
867+ struct weston_compositor *compositor = output->compositor;
868+ struct weston_view *view;
869+ struct gal2d_output_state *go = get_output_state(output);
870+ struct gal2d_renderer *gr = get_renderer(output->compositor);
871+ gceSTATUS status = gcvSTATUS_OK;
872+
873+ gcoSURF surface;
874+ int visibleViews=0;
875+ int fullscreenViews=0;
876+
877+ surface = go->renderSurf[go->activebuffer];
878+ if(go->nNumBuffers == 1)
879+ {
880+ wl_list_for_each_reverse(view, &compositor->view_list, link)
881+ if (view->plane == &compositor->primary_plane && is_view_visible(view))
882+ {
883+ visibleViews++;
884+ if(view->surface->width == go->width && view->surface->height == go->height)
885+ {
886+ pixman_box32_t *bb_rects;
887+ int nbb=0;
888+ bb_rects = pixman_region32_rectangles(&view->transform.boundingbox, &nbb);
889+ if(nbb == 1)
890+ if(bb_rects[0].x1 == 0 && bb_rects[0].y1 ==0)
891+ fullscreenViews++;
892+ }
893+ }
894+
895+ go->directBlit = ((visibleViews == 1) || (fullscreenViews > 1));
896+
897+ if(!go->directBlit)
898+ {
899+ surface = go->offscreenSurface;
900+ }
901+ }
902+ make_current(gr, surface);
903+ return status;
904+}
905+
906+static int
907+gal2d_renderer_read_pixels(struct weston_output *output,
908+ pixman_format_code_t format, void *pixels,
909+ uint32_t x, uint32_t y,
910+ uint32_t width, uint32_t height)
911+{
912+ return 0;
913+}
914+
915+static int gal2d_int_from_double(double d)
916+{
917+ return wl_fixed_to_int(wl_fixed_from_double(d));
918+}
919+
920+static void
921+repaint_region(struct weston_view *ev, struct weston_output *output, struct gal2d_output_state *go, pixman_region32_t *region,
922+ pixman_region32_t *surf_region){
923+
924+ struct gal2d_renderer *gr = get_renderer(ev->surface->compositor);
925+ struct gal2d_surface_state *gs = get_surface_state(ev->surface);
926+
927+ pixman_box32_t *rects, *surf_rects, *bb_rects;
928+ int i, j, nrects, nsurf, nbb=0;
929+ gceSTATUS status = gcvSTATUS_OK;
930+ gcoSURF srcSurface = gs->gco_Surface;
931+ gcsRECT srcRect = {0};
932+ gcsRECT dstrect = {0};
933+ gctUINT32 horFactor, verFactor;
934+ int useStretch =1;
935+ int useFilterBlit = 0;
936+ gctUINT srcWidth = 0;
937+ gctUINT srcHeight = 0;
938+ gctUINT32 srcStride[3];
939+ gceSURF_FORMAT srcFormat;;
940+ gctUINT32 srcPhyAddr[3];
941+ gctUINT32 dstPhyAddr[3];
942+ gctUINT dstWidth = 0;
943+ gctUINT dstHeight = 0;
944+ gctUINT32 dstStrides[3];
945+ gcoSURF dstsurface;
946+ int geoWidth = ev->surface->width;
947+ int geoheight = ev->surface->height;
948+ gceTILING tiling;
949+
950+ bb_rects = pixman_region32_rectangles(&ev->transform.boundingbox, &nbb);
951+
952+ if(!srcSurface || nbb <= 0)
953+ goto OnError;
954+ rects = pixman_region32_rectangles(region, &nrects);
955+ surf_rects = pixman_region32_rectangles(surf_region, &nsurf);
956+
957+ gcmVERIFY_OK(gcoSURF_GetAlignedSize(srcSurface, &srcWidth, &srcHeight, (gctINT *)&srcStride[0]));
958+
959+ gcmVERIFY_OK(gcoSURF_GetFormat(srcSurface, gcvNULL, &srcFormat));
960+
961+ if(galIsYUVFormat(srcFormat) == gcvSTATUS_TRUE)
962+ {
963+ useFilterBlit = 1;
964+ }
965+
966+ gcmVERIFY_OK(gcoSURF_Lock(srcSurface, &srcPhyAddr[0], gcvNULL));
967+
968+ gcmVERIFY_OK(gcoSURF_Unlock(srcSurface, gcvNULL));
969+
970+ srcRect.left = ev->geometry.x < 0.0 ? gal2d_int_from_double(fabsf(ev->geometry.x)) : 0;
971+ srcRect.top = 0; /*es->geometry.y < 0.0 ? gal2d_int_from_double(fabsf(es->geometry.y)) : 0;*/
972+ srcRect.right = ev->surface->width;
973+ srcRect.bottom = ev->surface->height;
974+
975+ if(useFilterBlit)
976+ {
977+ dstsurface = go->nNumBuffers > 1 ?
978+ go->renderSurf[go->activebuffer] :
979+ go->offscreenSurface;
980+ gcmVERIFY_OK(gcoSURF_GetAlignedSize(dstsurface, &dstWidth, &dstHeight, (gctINT *)&dstStrides));
981+ gcmVERIFY_OK(gcoSURF_Lock(dstsurface, &dstPhyAddr[0], gcvNULL));
982+ gcmVERIFY_OK(gcoSURF_Unlock(dstsurface, gcvNULL));
983+ }
984+ else
985+ {
986+ gcoSURF_GetTiling(srcSurface, &tiling);
987+ if (gcoHAL_IsFeatureAvailable(gr->gcoHal, gcvFEATURE_2D_TILING) != gcvTRUE && (tiling > gcvLINEAR))
988+ {
989+ weston_log("Tiling not supported \n");
990+ status = gcvSTATUS_NOT_SUPPORTED;
991+ gcmONERROR(status);
992+ }
993+ gco2D_SetGenericSource(gr->gcoEngine2d, srcPhyAddr, 1,
994+ srcStride, 1,
995+ tiling, srcFormat, gcvSURF_0_DEGREE,
996+ srcWidth, srcHeight);
997+ /* Setup mirror. */
998+ gcmONERROR(gco2D_SetBitBlitMirror(gr->gcoEngine2d, gcvFALSE, gcvFALSE));
999+ gcmONERROR(gco2D_SetROP(gr->gcoEngine2d, 0xCC, 0xCC));
1000+ }
1001+
1002+ for (i = 0; i < nrects; i++)
1003+ {
1004+ pixman_box32_t *rect = &rects[i];
1005+ gctFLOAT min_x, max_x, min_y, max_y;
1006+
1007+ dstrect.left = (bb_rects[0].x1 < 0) ? rect->x1 : bb_rects[0].x1;
1008+ dstrect.top = (bb_rects[0].y1 < 0) ? rect->y1 : bb_rects[0].y1;
1009+ dstrect.right = bb_rects[0].x2;
1010+ dstrect.bottom = bb_rects[0].y2;
1011+
1012+ if(dstrect.right < 0 || dstrect.bottom < 0)
1013+ {
1014+ break;
1015+ }
1016+
1017+ for (j = 0; j < nsurf; j++)
1018+ {
1019+ pixman_box32_t *surf_rect = &surf_rects[j];
1020+ gctFLOAT ex[8], ey[8]; /* edge points in screen space */
1021+ int n;
1022+ gcsRECT clipRect = {0};
1023+ int m=0;
1024+ n = calculate_edges(ev, rect, surf_rect, ex, ey);
1025+ if (n < 3)
1026+ continue;
1027+
1028+ min_x = max_x = ex[0];
1029+ min_y = max_y = ey[0];
1030+ for (m = 1; m < n; m++)
1031+ {
1032+ min_x = min(min_x, ex[m]);
1033+ max_x = max(max_x, ex[m]);
1034+ min_y = min(min_y, ey[m]);
1035+ max_y = max(max_y, ey[m]);
1036+ }
1037+
1038+ clipRect.left = gal2d_int_from_double(min_x);
1039+ clipRect.top = gal2d_int_from_double(min_y);
1040+ clipRect.right = gal2d_int_from_double(max_x);
1041+ clipRect.bottom = gal2d_int_from_double(max_y);
1042+
1043+ if(output->x > 0)
1044+ {
1045+ dstrect.left = dstrect.left - output->x;
1046+ dstrect.right = dstrect.right - output->x;
1047+ clipRect.left = clipRect.left - output->x;
1048+ clipRect.right = clipRect.right - output->x;
1049+ }
1050+
1051+ dstrect.left = (dstrect.left < 0) ? 0 : dstrect.left;
1052+
1053+ status = gco2D_SetClipping(gr->gcoEngine2d, &clipRect);
1054+ if(status < 0)
1055+ {
1056+ weston_log("Error in gco2D_SetClipping %s\n", __func__);
1057+ goto OnError;
1058+ }
1059+
1060+ if(useFilterBlit)
1061+ {
1062+ gctINT srcStrideNum;
1063+ gctINT srcAddressNum;
1064+ gcmVERIFY_OK(galQueryUVStride(srcFormat, srcStride[0],
1065+ &srcStride[1], &srcStride[2]));
1066+
1067+ switch (srcFormat)
1068+ {
1069+ case gcvSURF_YUY2:
1070+ case gcvSURF_UYVY:
1071+ srcStrideNum = srcAddressNum = 1;
1072+ break;
1073+
1074+ case gcvSURF_I420:
1075+ case gcvSURF_YV12:
1076+ srcStrideNum = srcAddressNum = 3;
1077+ break;
1078+
1079+ case gcvSURF_NV16:
1080+ case gcvSURF_NV12:
1081+ case gcvSURF_NV61:
1082+ case gcvSURF_NV21:
1083+ srcStrideNum = srcAddressNum = 2;
1084+ break;
1085+
1086+ default:
1087+ gcmONERROR(gcvSTATUS_NOT_SUPPORTED);
1088+ }
1089+ gco2D_FilterBlitEx2(gr->gcoEngine2d,
1090+ srcPhyAddr, srcAddressNum,
1091+ srcStride, srcStrideNum,
1092+ gcvLINEAR, srcFormat, gcvSURF_0_DEGREE,
1093+ geoWidth, geoheight, &srcRect,
1094+ dstPhyAddr, 1,
1095+ dstStrides, 1,
1096+ gcvLINEAR, go->format, gcvSURF_0_DEGREE,
1097+ dstWidth, dstHeight,
1098+ &dstrect, gcvNULL);
1099+ }
1100+ else
1101+ {
1102+ if(useStretch)
1103+ gcmVERIFY_OK(galGetStretchFactors(&srcRect, &dstrect, &horFactor, &verFactor));
1104+
1105+ if(verFactor == 65536 && horFactor == 65536)
1106+ {
1107+ gcmVERIFY_OK(gco2D_Blit(gr->gcoEngine2d, 1, &dstrect,
1108+ 0xCC, 0xCC, go->format));
1109+ }
1110+ else
1111+ {
1112+ /* Program the stretch factors. */
1113+ gcmVERIFY_OK(gco2D_SetStretchFactors(gr->gcoEngine2d, horFactor, verFactor));
1114+
1115+ gcmVERIFY_OK(gco2D_StretchBlit(gr->gcoEngine2d, 1, &dstrect,
1116+ 0xCC, 0xCC, go->format));
1117+ }
1118+ }
1119+
1120+ if(status < 0)
1121+ {
1122+ printf("cr l=%d r=%d t=%d b=%d w=%d h=%d\n",
1123+ clipRect.left, clipRect.right, clipRect.top ,clipRect.bottom,
1124+ clipRect.right - clipRect.left, clipRect.bottom -clipRect.top);
1125+ printf("dr l=%d r=%d t=%d b=%d w=%d h=%d\n",
1126+ dstrect.left, dstrect.right, dstrect.top ,dstrect.bottom,
1127+ dstrect.right - dstrect.left, dstrect.bottom -dstrect.top);
1128+ printf("horFactor=%d, verFactor=%d\n",horFactor, verFactor);
1129+
1130+ goto OnError;
1131+ }
1132+ }
1133+ }
1134+
1135+OnError:
1136+ galONERROR(status);
1137+}
1138+
1139+static void
1140+draw_view(struct weston_view *ev, struct weston_output *output,
1141+ pixman_region32_t *damage) /* in global coordinates */
1142+{
1143+ struct weston_compositor *ec = ev->surface->compositor;
1144+ struct gal2d_output_state *go = get_output_state(output);
1145+ /* repaint bounding region in global coordinates: */
1146+ pixman_region32_t repaint;
1147+ /* non-opaque region in surface coordinates: */
1148+ pixman_region32_t surface_blend;
1149+ pixman_region32_t *buffer_damage;
1150+
1151+ pixman_region32_init(&repaint);
1152+ pixman_region32_intersect(&repaint,
1153+ &ev->transform.boundingbox, damage);
1154+ pixman_region32_subtract(&repaint, &repaint, &ev->clip);
1155+
1156+ if (!pixman_region32_not_empty(&repaint))
1157+ goto out;
1158+
1159+ buffer_damage = &go->buffer_damage[go->current_buffer];
1160+ pixman_region32_subtract(buffer_damage, buffer_damage, &repaint);
1161+
1162+ /* blended region is whole surface minus opaque region: */
1163+ pixman_region32_init_rect(&surface_blend, 0, 0,
1164+ ev->surface->width, ev->surface->height);
1165+ pixman_region32_subtract(&surface_blend, &surface_blend, &ev->surface->opaque);
1166+
1167+ struct gal2d_renderer *gr = get_renderer(ec);
1168+ gco2D_SetCurrentSourceIndex(gr->gcoEngine2d, 0U);
1169+
1170+ if (pixman_region32_not_empty(&ev->surface->opaque)) {
1171+ repaint_region(ev, output, go, &repaint, &ev->surface->opaque);
1172+ }
1173+
1174+ if (pixman_region32_not_empty(&surface_blend)) {
1175+ gco2D_EnableAlphaBlend(gr->gcoEngine2d,
1176+ ev->alpha * 0xFF, ev->alpha * 0xFF,
1177+ gcvSURF_PIXEL_ALPHA_STRAIGHT, gcvSURF_PIXEL_ALPHA_STRAIGHT,
1178+ gcvSURF_GLOBAL_ALPHA_SCALE, gcvSURF_GLOBAL_ALPHA_SCALE,
1179+ gcvSURF_BLEND_STRAIGHT, gcvSURF_BLEND_INVERSED,
1180+ gcvSURF_COLOR_STRAIGHT, gcvSURF_COLOR_STRAIGHT);
1181+
1182+ repaint_region(ev, output, go, &repaint, &surface_blend);
1183+ }
1184+
1185+ gco2D_DisableAlphaBlend(gr->gcoEngine2d);
1186+ pixman_region32_fini(&surface_blend);
1187+
1188+out:
1189+ pixman_region32_fini(&repaint);
1190+
1191+}
1192+
1193+static void
1194+repaint_views(struct weston_output *output, pixman_region32_t *damage)
1195+{
1196+ struct weston_compositor *compositor = output->compositor;
1197+ struct weston_view *view;
1198+ struct gal2d_output_state *go = get_output_state(output);
1199+
1200+ if(go->nNumBuffers > 1)
1201+ {
1202+ /*500ms is more than enough to process a frame */
1203+ gcoOS_WaitSignal(gcvNULL, go->busySignal, 500);
1204+ }
1205+ go->activebuffer = (go->activebuffer+1) % go->nNumBuffers;
1206+
1207+ wl_list_for_each_reverse(view, &compositor->view_list, link)
1208+ if (view->plane == &compositor->primary_plane)
1209+ draw_view(view, output, damage);
1210+}
1211+
1212+static void
1213+gal2d_renderer_repaint_output(struct weston_output *output,
1214+ pixman_region32_t *output_damage)
1215+{
1216+ struct gal2d_output_state *go = get_output_state(output);
1217+ gctUINT32 i;
1218+
1219+ if (use_output(output) < 0)
1220+ return;
1221+
1222+ for (i = 0; i < 2; i++)
1223+ pixman_region32_union(&go->buffer_damage[i],
1224+ &go->buffer_damage[i],
1225+ output_damage);
1226+
1227+ pixman_region32_union(output_damage, output_damage,
1228+ &go->buffer_damage[go->current_buffer]);
1229+
1230+ repaint_views(output, output_damage);
1231+
1232+ pixman_region32_copy(&output->previous_damage, output_damage);
1233+ wl_signal_emit(&output->frame_signal, output);
1234+
1235+ update_surface(output);
1236+
1237+ go->current_buffer ^= 1;
1238+}
1239+
1240+static void
1241+gal2d_renderer_attach_egl(struct weston_surface *es, struct weston_buffer *buffer)
1242+{
1243+ gcsWL_VIV_BUFFER *vivBuffer = wl_resource_get_user_data(buffer->resource);
1244+ gcoSURF srcSurf = vivBuffer->surface;
1245+ gceSTATUS status = gcvSTATUS_OK;
1246+ struct gal2d_surface_state *gs = get_surface_state(es);
1247+
1248+ if(gs->gco_Surface != gcvNULL)
1249+ {
1250+ gcmONERROR(gcoSURF_Destroy(gs->gco_Surface));
1251+ }
1252+
1253+ gs->gco_Surface = srcSurf;
1254+ gcoSURF_ReferenceSurface(srcSurf);
1255+ buffer->width = vivBuffer->width;
1256+ buffer->height = vivBuffer->height;
1257+
1258+ OnError:
1259+ galONERROR(status);
1260+}
1261+
1262+static void
1263+gal2d_renderer_flush_damage(struct weston_surface *surface)
1264+{
1265+ struct gal2d_surface_state *gs = get_surface_state(surface);
1266+ struct weston_buffer *buffer = gs->buffer_ref.buffer;
1267+ struct weston_view *view;
1268+ int texture_used;
1269+ pixman_region32_union(&gs->texture_damage,
1270+ &gs->texture_damage, &surface->damage);
1271+
1272+ if (!buffer)
1273+ return;
1274+
1275+ texture_used = 0;
1276+ wl_list_for_each(view, &surface->views, surface_link) {
1277+ if (view->plane == &surface->compositor->primary_plane) {
1278+ texture_used = 1;
1279+ break;
1280+ }
1281+ }
1282+ if (!texture_used)
1283+ return;
1284+
1285+ if (!pixman_region32_not_empty(&gs->texture_damage))
1286+ goto done;
1287+
1288+ if(wl_shm_buffer_get(buffer->resource))
1289+ {
1290+ if(gs->gco_Surface==NULL)
1291+ {
1292+ gs->gco_Surface = getSurfaceFromShm(surface, buffer);
1293+ }
1294+ gal2dBindBuffer(surface);
1295+ }
1296+ else
1297+ gal2d_renderer_attach_egl(surface, buffer);
1298+
1299+done:
1300+ pixman_region32_fini(&gs->texture_damage);
1301+ pixman_region32_init(&gs->texture_damage);
1302+
1303+ weston_buffer_reference(&gs->buffer_ref, NULL);
1304+}
1305+
1306+static void
1307+gal2d_renderer_attach(struct weston_surface *es, struct weston_buffer *buffer)
1308+{
1309+ struct gal2d_surface_state *gs = get_surface_state(es);
1310+ struct wl_shm_buffer *shm_buffer;
1311+ weston_buffer_reference(&gs->buffer_ref, buffer);
1312+
1313+ if(buffer==NULL)
1314+ return;
1315+
1316+ shm_buffer = wl_shm_buffer_get(buffer->resource);
1317+
1318+ if(shm_buffer)
1319+ {
1320+ buffer->width = wl_shm_buffer_get_width(shm_buffer);
1321+ buffer->height = wl_shm_buffer_get_height(shm_buffer);
1322+ buffer->shm_buffer = shm_buffer;
1323+
1324+ if(gs->gco_Surface)
1325+ {
1326+ gcoSURF_Destroy(gs->gco_Surface);
1327+ gs->gco_Surface = getSurfaceFromShm(es, buffer);
1328+ }
1329+ }
1330+ else
1331+ gal2d_renderer_attach_egl(es, buffer);
1332+}
1333+
1334+static void
1335+surface_state_destroy(struct gal2d_surface_state *gs, struct gal2d_renderer *gr)
1336+{
1337+ if(gs->gco_Surface)
1338+ {
1339+ gcoSURF_Destroy(gs->gco_Surface);
1340+ }
1341+ wl_list_remove(&gs->surface_destroy_listener.link);
1342+ wl_list_remove(&gs->renderer_destroy_listener.link);
1343+ if(gs->surface)
1344+ gs->surface->renderer_state = NULL;
1345+
1346+ weston_buffer_reference(&gs->buffer_ref, NULL);
1347+ free(gs);
1348+}
1349+
1350+static void
1351+surface_state_handle_surface_destroy(struct wl_listener *listener, void *data)
1352+{
1353+ struct gal2d_surface_state *gs;
1354+ struct gal2d_renderer *gr;
1355+
1356+ gs = container_of(listener, struct gal2d_surface_state,
1357+ surface_destroy_listener);
1358+
1359+ gr = get_renderer(gs->surface->compositor);
1360+ surface_state_destroy(gs, gr);
1361+}
1362+
1363+static void
1364+surface_state_handle_renderer_destroy(struct wl_listener *listener, void *data)
1365+{
1366+ struct gal2d_surface_state *gs;
1367+ struct gal2d_renderer *gr;
1368+
1369+ gr = data;
1370+
1371+ gs = container_of(listener, struct gal2d_surface_state,
1372+ renderer_destroy_listener);
1373+
1374+ surface_state_destroy(gs, gr);
1375+}
1376+
1377+
1378+static int
1379+gal2d_renderer_create_surface(struct weston_surface *surface)
1380+{
1381+ struct gal2d_surface_state *gs;
1382+ struct gal2d_renderer *gr = get_renderer(surface->compositor);
1383+
1384+ gs = zalloc(sizeof *gs);
1385+ if (gs == NULL)
1386+ return -1;
1387+
1388+ /* A buffer is never attached to solid color surfaces, yet
1389+ * they still go through texcoord computations. Do not divide
1390+ * by zero there.
1391+ */
1392+ gs->pitch = 1;
1393+
1394+ gs->surface = surface;
1395+
1396+ pixman_region32_init(&gs->texture_damage);
1397+ surface->renderer_state = gs;
1398+
1399+ gs->surface_destroy_listener.notify =
1400+ surface_state_handle_surface_destroy;
1401+ wl_signal_add(&surface->destroy_signal,
1402+ &gs->surface_destroy_listener);
1403+
1404+ gs->renderer_destroy_listener.notify =
1405+ surface_state_handle_renderer_destroy;
1406+ wl_signal_add(&gr->destroy_signal,
1407+ &gs->renderer_destroy_listener);
1408+
1409+ if (surface->buffer_ref.buffer) {
1410+ gal2d_renderer_attach(surface, surface->buffer_ref.buffer);
1411+ gal2d_renderer_flush_damage(surface);
1412+ }
1413+
1414+ return 0;
1415+}
1416+
1417+static void
1418+gal2d_renderer_surface_set_color(struct weston_surface *surface,
1419+ float red, float green, float blue, float alpha)
1420+{
1421+ struct gal2d_surface_state *gs = get_surface_state(surface);
1422+
1423+ gs->color[0] = red;
1424+ gs->color[1] = green;
1425+ gs->color[2] = blue;
1426+ gs->color[3] = alpha;
1427+}
1428+
1429+
1430+static void
1431+gal2d_renderer_output_destroy(struct weston_output *output)
1432+{
1433+ struct gal2d_output_state *go = get_output_state(output);
1434+ gctUINT32 i;
1435+
1436+ for (i = 0; i < 2; i++)
1437+ {
1438+ pixman_region32_fini(&go->buffer_damage[i]);
1439+ }
1440+ if(go->nNumBuffers <= 1 )
1441+ {
1442+ if(go->offscreenSurface)
1443+ gcmVERIFY_OK(gcoSURF_Destroy(go->offscreenSurface));
1444+ }
1445+ else
1446+ {
1447+ gcoOS_Signal(gcvNULL,go->signal, gcvTRUE);
1448+ pthread_mutex_lock(&go->workerMutex);
1449+ go->exitWorker = 1;
1450+ pthread_mutex_unlock(&go->workerMutex);
1451+ pthread_join(go->workerId, NULL);
1452+ }
1453+
1454+ for(i=0; i < go->nNumBuffers; i++)
1455+ {
1456+ gcmVERIFY_OK(gcoSURF_Destroy(go->renderSurf[i]));
1457+ }
1458+ free(go->renderSurf);
1459+ go->renderSurf = gcvNULL;
1460+
1461+ free(go);
1462+}
1463+
1464+static void
1465+gal2d_renderer_destroy(struct weston_compositor *ec)
1466+{
1467+ struct gal2d_renderer *gr = get_renderer(ec);
1468+
1469+ wl_signal_emit(&gr->destroy_signal, gr);
1470+ free(ec->renderer);
1471+ ec->renderer = NULL;
1472+}
1473+
1474+
1475+static int
1476+gal2d_renderer_create(struct weston_compositor *ec)
1477+{
1478+ struct gal2d_renderer *gr;
1479+ gceSTATUS status = gcvSTATUS_OK;
1480+ gr = malloc(sizeof *gr);
1481+ if (gr == NULL)
1482+ return -1;
1483+
1484+ gr->base.read_pixels = gal2d_renderer_read_pixels;
1485+ gr->base.repaint_output = gal2d_renderer_repaint_output;
1486+ gr->base.flush_damage = gal2d_renderer_flush_damage;
1487+ gr->base.attach = gal2d_renderer_attach;
1488+ gr->base.surface_set_color = gal2d_renderer_surface_set_color;
1489+ gr->base.destroy = gal2d_renderer_destroy;
1490+
1491+ /* Construct the gcoOS object. */
1492+ gcmONERROR(gcoOS_Construct(gcvNULL, &gr->gcos));
1493+
1494+ /* Construct the gcoHAL object. */
1495+ gcmONERROR(gcoHAL_Construct(gcvNULL, gr->gcos, &gr->gcoHal));
1496+ gcmONERROR(gcoHAL_Get2DEngine(gr->gcoHal, &gr->gcoEngine2d));
1497+ gcmONERROR(gcoHAL_SetHardwareType(gr->gcoHal, gcvHARDWARE_2D));
1498+
1499+ ec->renderer = &gr->base;
1500+ wl_signal_init(&gr->destroy_signal);
1501+OnError:
1502+ galONERROR(status);
1503+
1504+ /* Return the status. */
1505+ return status;
1506+
1507+}
1508+
1509+static int
1510+gal2d_renderer_output_create(struct weston_output *output, NativeDisplayType display,
1511+ NativeWindowType window)
1512+
1513+ {
1514+ struct gal2d_renderer *gr = get_renderer(output->compositor);
1515+ struct gal2d_output_state *go;
1516+ halDISPLAY_INFO info;
1517+ gctUINT32 backOffset = 0;
1518+ gceSTATUS status = gcvSTATUS_OK;
1519+ gctUINT32 i;
1520+
1521+ go = zalloc(sizeof *go);
1522+ if (go == NULL)
1523+ return -1;
1524+
1525+ output->renderer_state = go;
1526+ go->display = display;
1527+ gcmONERROR(gcoOS_InitLocalDisplayInfo(go->display, &gr->localInfo));
1528+
1529+ /* Get display information. */
1530+ gcmONERROR(gcoOS_GetDisplayInfoEx2(
1531+ go->display, gcvNULL, gr->localInfo,
1532+ sizeof(info), &info));
1533+ go->nNumBuffers = info.multiBuffer;
1534+
1535+ weston_log("Number of buffers=%d\n",go->nNumBuffers);
1536+
1537+ gcmONERROR(gal2d_getSurfaceFormat(info, &go->format));
1538+ backOffset = (gctUINT32)(info.stride * info.height );
1539+
1540+ go->activebuffer = 0;
1541+
1542+ go->renderSurf = malloc(sizeof(gcoSURF) * go->nNumBuffers);
1543+ gcoOS_GetDisplayVirtual(go->display, &go->width, &go->height);
1544+ gcoOS_SetSwapInterval(go->display, 1);
1545+
1546+ /*Needed only for multi Buffer */
1547+ if(go->nNumBuffers > 1)
1548+ {
1549+ gcmVERIFY_OK(gcoOS_CreateSignal(gcvNULL, gcvFALSE,
1550+ &go->signal));
1551+ gcmVERIFY_OK(gcoOS_CreateSignal(gcvNULL, gcvFALSE,
1552+ &go->busySignal));
1553+
1554+ go->iface.command = gcvHAL_SIGNAL;
1555+ go->iface.u.Signal.signal = gcmPTR_TO_UINT64(go->signal);
1556+ go->iface.u.Signal.auxSignal = 0;
1557+ go->iface.u.Signal.process = gcmPTR_TO_UINT64(gcoOS_GetCurrentProcessID());
1558+ go->iface.u.Signal.fromWhere = gcvKERNEL_PIXEL;
1559+
1560+ go->exitWorker = 0;
1561+ pthread_create(&go->workerId, NULL, gal2d_output_worker, output);
1562+ pthread_mutex_init(&go->workerMutex, gcvNULL);
1563+ }
1564+ for(i=0; i < go->nNumBuffers; i++)
1565+ {
1566+ gcmONERROR(gcoSURF_Construct(gr->gcoHal, info.width, info.height, 1,
1567+ gcvSURF_BITMAP, go->format, gcvPOOL_USER, &go->renderSurf[i]));
1568+
1569+ gcoSURF_MapUserSurface(go->renderSurf[i], 0,info.logical + (i * backOffset),
1570+ info.physical + (i * backOffset));
1571+
1572+ //Clear surfaces
1573+ make_current(gr, go->renderSurf[go->activebuffer]);
1574+ gal2d_clear(output);
1575+ gal2d_flip_surface(output);
1576+ }
1577+ if(go->nNumBuffers <= 1)
1578+ go->activebuffer = 0;
1579+ else
1580+ go->activebuffer = 1;
1581+
1582+ if(go->nNumBuffers <= 1 )
1583+ {
1584+ gcmVERIFY_OK(gcoSURF_Construct(gr->gcoHal,
1585+ (gctUINT) info.width,
1586+ (gctUINT) info.height,
1587+ 1,
1588+ gcvSURF_BITMAP,
1589+ go->format,
1590+ gcvPOOL_DEFAULT,
1591+ &go->offscreenSurface));
1592+ make_current(gr, go->offscreenSurface);
1593+ gal2d_clear(output);
1594+ }
1595+ else
1596+ {
1597+ gcoOS_Signal(gcvNULL,go->busySignal, gcvTRUE);
1598+ }
1599+
1600+ for (i = 0; i < 2; i++)
1601+ pixman_region32_init(&go->buffer_damage[i]);
1602+OnError:
1603+ galONERROR(status);
1604+ /* Return the status. */
1605+ return status;
1606+ }
1607+
1608+ WL_EXPORT struct gal2d_renderer_interface gal2d_renderer_interface = {
1609+ .create = gal2d_renderer_create,
1610+ .output_create = gal2d_renderer_output_create,
1611+ .output_destroy = gal2d_renderer_output_destroy,
1612+};
1613Index: weston-1.11.1/src/gal2d-renderer.h
1614===================================================================
1615--- /dev/null 1970-01-01 00:00:00.000000000 +0000
1616+++ weston-1.11.1/src/gal2d-renderer.h 2017-01-14 08:35:10.000000000 -0600
1617@@ -0,0 +1,50 @@
1618+/*
1619+ * Copyright (c) 2015 Freescale Semiconductor, Inc.
1620+ * Copyright © 2013 Vasily Khoruzhick <anarsoul@gmail.com>
1621+ *
1622+ * Permission is hereby granted, free of charge, to any person obtaining
1623+ * a copy of this software and associated documentation files (the
1624+ * "Software"), to deal in the Software without restriction, including
1625+ * without limitation the rights to use, copy, modify, merge, publish,
1626+ * distribute, sublicense, and/or sell copies of the Software, and to
1627+ * permit persons to whom the Software is furnished to do so, subject to
1628+ * the following conditions:
1629+ *
1630+ * The above copyright notice and this permission notice (including the
1631+ * next paragraph) shall be included in all copies or substantial
1632+ * portions of the Software.
1633+ *
1634+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1635+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1636+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1637+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
1638+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
1639+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1640+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1641+ * SOFTWARE.
1642+ */
1643+#ifndef __gal_2d_renderer_h_
1644+#define __gal_2d_renderer_h_
1645+
1646+#include "compositor.h"
1647+#ifdef ENABLE_EGL
1648+#include <EGL/egl.h>
1649+#else
1650+#include <HAL/gc_hal_eglplatform.h>
1651+typedef HALNativeDisplayType NativeDisplayType;
1652+typedef HALNativeWindowType NativeWindowType;
1653+#endif
1654+
1655+
1656+struct gal2d_renderer_interface {
1657+
1658+ int (*create)(struct weston_compositor *ec);
1659+
1660+ int (*output_create)(struct weston_output *output,
1661+ NativeDisplayType display,
1662+ NativeWindowType window);
1663+
1664+ void (*output_destroy)(struct weston_output *output);
1665+};
1666+
1667+#endif
1668Index: weston-1.11.1/src/compositor-fbdev.h
1669===================================================================
1670--- weston-1.11.1.orig/src/compositor-fbdev.h 2016-09-20 19:35:22.000000000 -0500
1671+++ weston-1.11.1/src/compositor-fbdev.h 2017-01-14 08:35:10.000000000 -0600
1672@@ -40,6 +40,7 @@
1673 int tty;
1674 char *device;
1675 int use_gl;
1676+ int use_gal2d;
1677
1678 uint32_t output_transform;
1679 };
1680Index: weston-1.11.1/src/main.c
1681===================================================================
1682--- weston-1.11.1.orig/src/main.c 2017-01-14 08:34:10.030218137 -0600
1683+++ weston-1.11.1/src/main.c 2017-01-14 08:54:45.000000000 -0600
1684@@ -285,7 +285,13 @@
1685 "Options for fbdev-backend.so:\n\n"
1686 " --tty=TTY\t\tThe tty to use\n"
1687 " --device=DEVICE\tThe framebuffer device to use\n"
1688- " --use-gl\t\tUse the GL renderer\n\n");
1689+#if defined ENABLE_EGL
1690+ " --use-gl=1\t\tUse the GL renderer (default is 1)\n"
1691+ " --use-gal2d=1\t\tUse the GAL2D renderer (default is 0)\n\n");
1692+#else
1693+ " --use-gl=1\t\tUse the GL renderer (default is 0)\n"
1694+ " --use-gal2d=1\t\tUse the GAL2D renderer (default is 1)\n\n");
1695+#endif
1696 #endif
1697
1698 #if defined(BUILD_HEADLESS_COMPOSITOR)
1699@@ -868,7 +874,8 @@
1700 const struct weston_option fbdev_options[] = {
1701 { WESTON_OPTION_INTEGER, "tty", 0, &config.tty },
1702 { WESTON_OPTION_STRING, "device", 0, &config.device },
1703- { WESTON_OPTION_BOOLEAN, "use-gl", 0, &config.use_gl },
1704+ { WESTON_OPTION_INTEGER, "use-gl", 0, &config.use_gl },
1705+ { WESTON_OPTION_INTEGER, "use-gal2d", 0, &config.use_gal2d },
1706 };
1707
1708 parse_options(fbdev_options, ARRAY_LENGTH(fbdev_options), argc, argv);
diff --git a/recipes-graphics/wayland/weston/0002-MGS-2521-ccc-Enable-g2d-renderer-for-weston-1.11.patch b/recipes-graphics/wayland/weston/0002-MGS-2521-ccc-Enable-g2d-renderer-for-weston-1.11.patch
new file mode 100644
index 00000000..858cb81f
--- /dev/null
+++ b/recipes-graphics/wayland/weston/0002-MGS-2521-ccc-Enable-g2d-renderer-for-weston-1.11.patch
@@ -0,0 +1,1605 @@
1From 1995ec08267c8063ca72590e700c8612b04a63b5 Mon Sep 17 00:00:00 2001
2From: Meng Mingming <mingming.meng@nxp.com>
3Date: Mon, 16 Jan 2017 10:15:02 +0800
4Subject: [PATCH 2/5] MGS-2521 [#ccc] Enable g2d-renderer for weston 1.11
5
6Enable g2d-renderer for weston 1.11
7weston-start -- --use-g2d=1(--use-gl=1) $OPTARGS
8
9Upstream Status: Inappropriate [i.MX specific]
10
11Date: Jan 16, 2017
12Signed-off-by: Meng Mingming <mingming.meng@nxp.com>
13---
14 Makefile.am | 16 +
15 src/compositor-fbdev.c | 66 ++-
16 src/compositor-fbdev.h | 1 +
17 src/g2d-renderer.c | 1317 ++++++++++++++++++++++++++++++++++++++++++++++++
18 src/g2d-renderer.h | 47 ++
19 src/main.c | 6 +-
20 6 files changed, 1448 insertions(+), 5 deletions(-)
21 create mode 100644 src/g2d-renderer.c
22 create mode 100644 src/g2d-renderer.h
23
24diff --git a/Makefile.am b/Makefile.am
25index 00b74e5..a044b64 100644
26--- a/Makefile.am
27+++ b/Makefile.am
28@@ -248,6 +248,22 @@ gl_renderer_la_SOURCES = \
29 shared/helpers.h
30 endif
31
32+module_LTLIBRARIES += g2d-renderer.la
33+g2d_renderer_la_LDFLAGS = -module -avoid-version
34+g2d_renderer_la_LIBADD = $(COMPOSITOR_LIBS) $(EGL_LIBS) -lg2d
35+g2d_renderer_la_CFLAGS = \
36+ $(COMPOSITOR_CFLAGS) \
37+ $(EGL_CFLAGS) \
38+ $(GCC_CFLAGS) -DHAVE_G2D
39+g2d_renderer_la_SOURCES = \
40+ src/g2d-renderer.h \
41+ src/g2d-renderer.c \
42+ src/vertex-clipping.c \
43+ src/vertex-clipping.h
44+if ENABLE_EGL
45+g2d_renderer_la_CFLAGS += -DENABLE_EGL
46+endif
47+
48 if ENABLE_X11_COMPOSITOR
49 module_LTLIBRARIES += x11-backend.la
50 x11_backend_la_LDFLAGS = -module -avoid-version
51diff --git a/src/compositor-fbdev.c b/src/compositor-fbdev.c
52index 06f4696..cff9513 100644
53--- a/src/compositor-fbdev.c
54+++ b/src/compositor-fbdev.c
55@@ -50,6 +50,7 @@
56 #include "libinput-seat.h"
57 #include "gl-renderer.h"
58 #include "presentation-time-server-protocol.h"
59+#include "g2d-renderer.h"
60
61 struct fbdev_backend {
62 struct weston_backend base;
63@@ -59,6 +60,7 @@ struct fbdev_backend {
64 struct udev *udev;
65 struct udev_input input;
66 int use_pixman;
67+ int use_g2d;
68 uint32_t output_transform;
69 struct wl_listener session_listener;
70 NativeDisplayType display;
71@@ -100,6 +102,7 @@ struct fbdev_output {
72 };
73
74 struct gl_renderer_interface *gl_renderer;
75+struct g2d_renderer_interface *g2d_renderer;
76
77 static const char default_seat[] = "seat0";
78
79@@ -516,6 +519,14 @@ fbdev_output_create(struct fbdev_backend *backend,
80 if (backend->use_pixman) {
81 if (pixman_renderer_output_create(&output->base) < 0)
82 goto out_hw_surface;
83+ } else if(backend->use_g2d) {
84+ const char *g2d_device = device;
85+
86+ if (g2d_renderer->output_create(&output->base,
87+ backend->compositor->wl_display, g2d_device) < 0) {
88+ weston_log("g2d_renderer_output_create failed.\n");
89+ goto out_hw_surface;
90+ }
91 } else {
92 setenv("HYBRIS_EGLPLATFORM", "wayland", 1);
93 output->window = fbCreateWindow(backend->display, -1, -1, 0, 0);
94@@ -571,6 +582,8 @@ fbdev_output_destroy(struct weston_output *base)
95 if (backend->use_pixman) {
96 if (base->renderer_state != NULL)
97 pixman_renderer_output_destroy(base);
98+ } else if(backend->use_g2d) {
99+ g2d_renderer->output_destroy(base);
100 } else {
101 gl_renderer->output_destroy(base);
102 }
103@@ -782,7 +795,8 @@ fbdev_backend_create(struct weston_compositor *compositor, int *argc, char *argv
104 backend->base.restore = fbdev_restore;
105
106 backend->prev_state = WESTON_COMPOSITOR_ACTIVE;
107- backend->use_pixman = !param->use_gl;
108+ backend->use_pixman = !(param->use_gl || param->use_g2d);
109+ backend->use_g2d = param->use_g2d;
110 backend->output_transform = param->output_transform;
111
112 weston_setup_vt_switch_bindings(compositor);
113@@ -790,6 +804,46 @@ fbdev_backend_create(struct weston_compositor *compositor, int *argc, char *argv
114 if (backend->use_pixman) {
115 if (pixman_renderer_init(compositor) < 0)
116 goto out_launcher;
117+ } else if(backend->use_g2d) {
118+ int x = 0, y = 0;
119+ int i=0;
120+ int count = 0;
121+ int k=0, dispCount = 0;
122+ char displays[5][32];
123+ g2d_renderer = weston_load_module("g2d-renderer.so",
124+ "g2d_renderer_interface");
125+ if (!g2d_renderer) {
126+ weston_log("could not load g2d renderer\n");
127+ goto out_launcher;
128+ }
129+
130+ if (g2d_renderer->create(backend->compositor) < 0) {
131+ weston_log("g2d_renderer_create failed.\n");
132+ goto out_launcher;
133+ }
134+
135+ weston_log("param->device=%s\n",param->device);
136+ count = strlen(param->device);
137+
138+ for(i= 0; i < count; i++) {
139+ if(param->device[i] == ',') {
140+ displays[dispCount][k] = '\0';
141+ dispCount++;
142+ k = 0;
143+ continue;
144+ }
145+ displays[dispCount][k++] = param->device[i];
146+ }
147+ displays[dispCount][k] = '\0';
148+ dispCount++;
149+
150+ for(i= 0; i < dispCount; i++){
151+ if (fbdev_output_create(backend, x, y, displays[i]) < 0)
152+ goto out_launcher;
153+ x += container_of(backend->compositor->output_list.prev,
154+ struct weston_output,
155+ link)->width;
156+ }
157 } else {
158 gl_renderer = weston_load_module("gl-renderer.so",
159 "gl_renderer_interface");
160@@ -811,7 +865,8 @@ fbdev_backend_create(struct weston_compositor *compositor, int *argc, char *argv
161 goto out_launcher;
162 }
163 }
164- if (fbdev_output_create(backend, 0, 0, param->device) < 0)
165+ if(!backend->use_g2d)
166+ if (fbdev_output_create(backend, 0, 0, param->device) < 0)
167 goto out_launcher;
168
169 udev_input_init(&backend->input, compositor, backend->udev, seat_id);
170@@ -840,6 +895,7 @@ config_init_to_defaults(struct weston_fbdev_backend_config *config)
171 config->tty = 0; /* default to current tty */
172 config->device = "/dev/fb0"; /* default frame buffer */
173 config->use_gl = 0;
174+ config->use_g2d = 0;
175 config->output_transform = WL_OUTPUT_TRANSFORM_NORMAL;
176 }
177
178@@ -861,7 +917,11 @@ backend_init(struct weston_compositor *compositor, int *argc, char *argv[],
179 config_init_to_defaults(&config);
180 memcpy(&config, config_base, config_base->struct_size);
181
182- config.use_gl = 1;
183+ if(config.use_g2d) {
184+ config.use_gl = 0;
185+ } else {
186+ config.use_gl = 1;
187+ }
188
189 b = fbdev_backend_create(compositor, argc, argv, wc, &config);
190 if (b == NULL)
191diff --git a/src/compositor-fbdev.h b/src/compositor-fbdev.h
192index bd60bdc..32a8598 100644
193--- a/src/compositor-fbdev.h
194+++ b/src/compositor-fbdev.h
195@@ -40,6 +40,7 @@ struct weston_fbdev_backend_config {
196 int tty;
197 char *device;
198 int use_gl;
199+ int use_g2d;
200
201 uint32_t output_transform;
202 };
203diff --git a/src/g2d-renderer.c b/src/g2d-renderer.c
204new file mode 100644
205index 0000000..c30aa62
206--- /dev/null
207+++ b/src/g2d-renderer.c
208@@ -0,0 +1,1317 @@
209+/*
210+ * Copyright (c) 2016 Freescale Semiconductor, Inc.
211+ * Copyright © 2012 Intel Corporation
212+ * Copyright © 2015 Collabora, Ltd.
213+ *
214+ * Permission is hereby granted, free of charge, to any person obtaining
215+ * a copy of this software and associated documentation files (the
216+ * "Software"), to deal in the Software without restriction, including
217+ * without limitation the rights to use, copy, modify, merge, publish,
218+ * distribute, sublicense, and/or sell copies of the Software, and to
219+ * permit persons to whom the Software is furnished to do so, subject to
220+ * the following conditions:
221+ *
222+ * The above copyright notice and this permission notice (including the
223+ * next paragraph) shall be included in all copies or substantial
224+ * portions of the Software.
225+ *
226+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
227+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
228+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
229+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
230+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
231+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
232+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
233+ * SOFTWARE.
234+ */
235+
236+#define _GNU_SOURCE
237+
238+#include <stdlib.h>
239+#include <string.h>
240+#include <ctype.h>
241+#include <float.h>
242+#include <assert.h>
243+#include <pthread.h>
244+#include <linux/fb.h>
245+#include <sys/ioctl.h>
246+#include <fcntl.h>
247+#include <unistd.h>
248+#include <g2dExt.h>
249+#include <HAL/gc_hal_eglplatform.h>
250+
251+#include "compositor.h"
252+#include "g2d-renderer.h"
253+#include "vertex-clipping.h"
254+#include "shared/helpers.h"
255+
256+#define BUFFER_DAMAGE_COUNT 2
257+#define ALIGN_WIDTH(a) (((a) + 15) & ~15)
258+
259+struct wl_viv_buffer
260+{
261+ struct wl_resource *resource;
262+ gcoSURF surface;
263+ gctINT32 width;
264+ gctINT32 height;
265+ gctINT32 format;
266+ gctUINT alignedWidth;
267+ gctUINT alignedHeight;
268+ gctUINT32 physical[3];
269+ gctUINT32 gpuBaseAddr;
270+ gceTILING tiling;
271+};
272+
273+typedef struct _g2dRECT
274+{
275+ int left;
276+ int top;
277+ int right;
278+ int bottom;
279+} g2dRECT;
280+
281+struct fb_screeninfo {
282+ struct fb_var_screeninfo varinfo;
283+ struct fb_fix_screeninfo fixinfo;
284+ unsigned int x_resolution;
285+ unsigned int y_resolution;
286+ size_t buffer_length; /* length of frame buffer memory in bytes */
287+ size_t physical;
288+ size_t stride;
289+ size_t stride_bytes;
290+ enum g2d_format pixel_format; /* frame buffer pixel format */
291+ int fb_fd;
292+};
293+
294+struct g2d_output_state {
295+ int current_buffer;
296+ pixman_region32_t buffer_damage[BUFFER_DAMAGE_COUNT];
297+ struct g2d_surfaceEx *renderSurf;
298+ int nNumBuffers;
299+ int activebuffer;
300+ struct g2d_surfaceEx offscreenSurface;
301+ struct g2d_buf *offscreen_buf;
302+ struct fb_screeninfo fb_info;
303+ struct fb_screeninfo *mirror_fb_info;
304+ struct g2d_surfaceEx *mirrorSurf;
305+ int directBlit;
306+ int clone_display_num;
307+ int width;
308+ int height;
309+};
310+
311+struct g2d_surface_state {
312+ float color[4];
313+ struct weston_buffer_reference buffer_ref;
314+ int pitch; /* in pixels */
315+ int attached;
316+ pixman_region32_t texture_damage;
317+ struct g2d_surfaceEx g2d_surface;
318+ struct g2d_buf *shm_buf;
319+ int shm_buf_length;
320+ int bpp;
321+
322+ struct weston_surface *surface;
323+ struct wl_listener surface_destroy_listener;
324+ struct wl_listener renderer_destroy_listener;
325+};
326+
327+struct g2d_renderer {
328+ struct weston_renderer base;
329+ struct wl_signal destroy_signal;
330+#ifdef ENABLE_EGL
331+ NativeDisplayType display;
332+ EGLDisplay egl_display;
333+ struct wl_display *wl_display;
334+#endif
335+ void *handle;
336+};
337+
338+static int
339+g2d_renderer_create_surface(struct weston_surface *surface);
340+
341+static inline struct g2d_surface_state *
342+get_surface_state(struct weston_surface *surface)
343+{
344+ if (!surface->renderer_state)
345+ g2d_renderer_create_surface(surface);
346+ return (struct g2d_surface_state *)surface->renderer_state;
347+}
348+
349+static inline struct g2d_renderer *
350+get_renderer(struct weston_compositor *ec)
351+{
352+ return (struct g2d_renderer *)ec->renderer;
353+}
354+
355+#define max(a, b) (((a) > (b)) ? (a) : (b))
356+#define min(a, b) (((a) > (b)) ? (b) : (a))
357+/*
358+ * Compute the boundary vertices of the intersection of the global coordinate
359+ * aligned rectangle 'rect', and an arbitrary quadrilateral produced from
360+ * 'surf_rect' when transformed from surface coordinates into global coordinates.
361+ * The vertices are written to 'ex' and 'ey', and the return value is the
362+ * number of vertices. Vertices are produced in clockwise winding order.
363+ * Guarantees to produce either zero vertices, or 3-8 vertices with non-zero
364+ * polygon area.
365+ */
366+static int
367+calculate_edges(struct weston_view *ev, pixman_box32_t *rect,
368+ pixman_box32_t *surf_rect, float *ex, float *ey)
369+{
370+
371+ struct clip_context ctx;
372+ int i, n;
373+ float min_x, max_x, min_y, max_y;
374+ struct polygon8 surf = {
375+ { surf_rect->x1, surf_rect->x2, surf_rect->x2, surf_rect->x1 },
376+ { surf_rect->y1, surf_rect->y1, surf_rect->y2, surf_rect->y2 },
377+ 4
378+ };
379+
380+ ctx.clip.x1 = rect->x1;
381+ ctx.clip.y1 = rect->y1;
382+ ctx.clip.x2 = rect->x2;
383+ ctx.clip.y2 = rect->y2;
384+
385+ /* transform surface to screen space: */
386+ for (i = 0; i < surf.n; i++)
387+ weston_view_to_global_float(ev, surf.x[i], surf.y[i],
388+ &surf.x[i], &surf.y[i]);
389+
390+ /* find bounding box: */
391+ min_x = max_x = surf.x[0];
392+ min_y = max_y = surf.y[0];
393+
394+ for (i = 1; i < surf.n; i++) {
395+ min_x = min(min_x, surf.x[i]);
396+ max_x = max(max_x, surf.x[i]);
397+ min_y = min(min_y, surf.y[i]);
398+ max_y = max(max_y, surf.y[i]);
399+ }
400+
401+ /* First, simple bounding box check to discard early transformed
402+ * surface rects that do not intersect with the clip region:
403+ */
404+ if ((min_x >= ctx.clip.x2) || (max_x <= ctx.clip.x1) ||
405+ (min_y >= ctx.clip.y2) || (max_y <= ctx.clip.y1))
406+ return 0;
407+
408+ /* Simple case, bounding box edges are parallel to surface edges,
409+ * there will be only four edges. We just need to clip the surface
410+ * vertices to the clip rect bounds:
411+ */
412+ if (!ev->transform.enabled)
413+ return clip_simple(&ctx, &surf, ex, ey);
414+
415+ /* Transformed case: use a general polygon clipping algorithm to
416+ * clip the surface rectangle with each side of 'rect'.
417+ * The algorithm is Sutherland-Hodgman, as explained in
418+ * http://www.codeguru.com/cpp/misc/misc/graphics/article.php/c8965/Polygon-Clipping.htm
419+ * but without looking at any of that code.
420+ */
421+ n = clip_transformed(&ctx, &surf, ex, ey);
422+
423+ if (n < 3)
424+ return 0;
425+
426+ return n;
427+}
428+
429+
430+static inline struct g2d_output_state *
431+get_output_state(struct weston_output *output)
432+{
433+ return (struct g2d_output_state *)output->renderer_state;
434+}
435+
436+static void
437+g2d_getG2dTiling(IN gceTILING tiling, enum g2d_tiling* g2dTiling)
438+{
439+ switch(tiling)
440+ {
441+ case gcvLINEAR:
442+ *g2dTiling = G2D_LINEAR;
443+ break;
444+ case gcvTILED:
445+ *g2dTiling = G2D_TILED;
446+ break;
447+ case gcvSUPERTILED:
448+ *g2dTiling = G2D_SUPERTILED;
449+ break;
450+ default:
451+ weston_log("Error in function %s\n", __func__);
452+ break;
453+ }
454+}
455+
456+static void
457+g2d_getG2dFormat(IN gceSURF_FORMAT Format, enum g2d_format* g2dFormat)
458+{
459+ switch(Format)
460+ {
461+ case gcvSURF_R5G6B5:
462+ *g2dFormat = G2D_RGB565;
463+ break;
464+ case gcvSURF_A8B8G8R8:
465+ *g2dFormat = G2D_RGBA8888;
466+ break;
467+ case gcvSURF_X8B8G8R8:
468+ *g2dFormat = G2D_RGBA8888;
469+ break;
470+ case gcvSURF_A8R8G8B8:
471+ *g2dFormat = G2D_BGRA8888;
472+ break;
473+ case gcvSURF_X8R8G8B8:
474+ *g2dFormat = G2D_BGRX8888;
475+ break;
476+ case gcvSURF_B5G6R5:
477+ *g2dFormat = G2D_BGR565;
478+ break;
479+ case gcvSURF_B8G8R8A8:
480+ *g2dFormat = G2D_ARGB8888;
481+ break;
482+ case gcvSURF_R8G8B8A8:
483+ *g2dFormat = G2D_ABGR8888;
484+ break;
485+ case gcvSURF_B8G8R8X8:
486+ *g2dFormat = G2D_XRGB8888;
487+ break;
488+ case gcvSURF_R8G8B8X8:
489+ *g2dFormat = G2D_XBGR8888;
490+ break;
491+ case gcvSURF_NV12:
492+ *g2dFormat = G2D_NV12;
493+ break;
494+ case gcvSURF_NV21:
495+ *g2dFormat = G2D_NV21;
496+ break;
497+ case gcvSURF_I420:
498+ *g2dFormat = G2D_I420;
499+ break;
500+ case gcvSURF_YV12:
501+ *g2dFormat = G2D_YV12;
502+ break;
503+ case gcvSURF_YUY2:
504+ *g2dFormat = G2D_YUYV;
505+ break;
506+ case gcvSURF_YVYU:
507+ *g2dFormat = G2D_YVYU;
508+ break;
509+ case gcvSURF_UYVY:
510+ *g2dFormat = G2D_UYVY;
511+ break;
512+ case gcvSURF_VYUY:
513+ *g2dFormat = G2D_VYUY;
514+ break;
515+ case gcvSURF_NV16:
516+ *g2dFormat = G2D_NV16;
517+ break;
518+ case gcvSURF_NV61:
519+ *g2dFormat = G2D_NV61;
520+ break;
521+ default:
522+ weston_log("Error in function %s, Format not supported\n", __func__);
523+ break;
524+ }
525+}
526+
527+static void printG2dSurfaceInfo(struct g2d_surfaceEx* g2dSurface, const char* msg)
528+{
529+ weston_log("%s physicAddr = %x left = %d right = %d top=%d bottom=%d stride= %d tiling = %d, format=%d \n",
530+ msg,
531+ g2dSurface->base.planes[0],
532+ g2dSurface->base.left,
533+ g2dSurface->base.right,
534+ g2dSurface->base.top,
535+ g2dSurface->base.bottom,
536+ g2dSurface->base.stride,
537+ g2dSurface->tiling,
538+ g2dSurface->base.format);
539+}
540+
541+static void
542+get_g2dSurface(struct wl_viv_buffer *buffer, struct g2d_surfaceEx *g2dSurface)
543+{
544+ if(buffer->width < 0 || buffer->height < 0)
545+ {
546+ weston_log("invalid EGL buffer in function %s\n", __func__);
547+ return;
548+ }
549+ g2d_getG2dFormat(buffer->format, &g2dSurface->base.format);
550+ g2d_getG2dTiling(buffer->tiling, &g2dSurface->tiling);
551+ g2dSurface->base.planes[0] = buffer->physical[0] + buffer->gpuBaseAddr;
552+ g2dSurface->base.planes[1] = buffer->physical[1] + buffer->gpuBaseAddr;
553+ g2dSurface->base.planes[2] = buffer->physical[2] + buffer->gpuBaseAddr;
554+ g2dSurface->base.left = 0;
555+ g2dSurface->base.top = 0;
556+ g2dSurface->base.right = buffer->width;
557+ g2dSurface->base.bottom = buffer->height;
558+ g2dSurface->base.stride = buffer->alignedWidth;
559+ g2dSurface->base.width = buffer->width;
560+ g2dSurface->base.height = buffer->height;
561+ g2dSurface->base.rot = G2D_ROTATION_0;
562+}
563+
564+static void
565+g2d_SetSurfaceRect(struct g2d_surfaceEx* g2dSurface, g2dRECT* rect)
566+{
567+ if(g2dSurface && rect)
568+ {
569+ g2dSurface->base.left = rect->left;
570+ g2dSurface->base.top = rect->top;
571+ g2dSurface->base.right = rect->right;
572+ g2dSurface->base.bottom = rect->bottom;
573+ }
574+}
575+
576+static int
577+g2d_blitSurface(void *handle, struct g2d_surfaceEx * srcG2dSurface, struct g2d_surfaceEx *dstG2dSurface,
578+ g2dRECT *srcRect, g2dRECT *dstRect)
579+{
580+ g2d_SetSurfaceRect(srcG2dSurface, srcRect);
581+ g2d_SetSurfaceRect(dstG2dSurface, dstRect);
582+ srcG2dSurface->base.blendfunc = G2D_ONE;
583+ dstG2dSurface->base.blendfunc = G2D_ONE_MINUS_SRC_ALPHA;
584+
585+ if(g2d_blitEx(handle, srcG2dSurface, dstG2dSurface))
586+ {
587+ printG2dSurfaceInfo(srcG2dSurface, "SRC:");
588+ printG2dSurfaceInfo(dstG2dSurface, "DST:");
589+ return -1;
590+ }
591+ return 0;
592+}
593+
594+static void
595+g2d_flip_surface(struct weston_output *output)
596+{
597+ struct g2d_output_state *go = get_output_state(output);
598+ go->fb_info.varinfo.yoffset = go->activebuffer * go->fb_info.y_resolution;
599+
600+ if(ioctl(go->fb_info.fb_fd, FBIOPAN_DISPLAY, &(go->fb_info.varinfo)) < 0)
601+ {
602+ weston_log("FBIOPAN_DISPLAY Failed\n");
603+ }
604+ go->activebuffer = (go->activebuffer + 1) % go->nNumBuffers;
605+}
606+
607+static void
608+copy_to_framebuffer(struct weston_output *output)
609+{
610+ struct g2d_renderer *gr = get_renderer(output->compositor);
611+ struct g2d_output_state *go = get_output_state(output);
612+ if(!go->directBlit && go->nNumBuffers == 1)
613+ {
614+ g2dRECT srcRect = {0, 0, go->offscreenSurface.base.width, go->offscreenSurface.base.height};
615+ g2dRECT dstrect = srcRect;
616+ g2dRECT clipRect = srcRect;
617+ g2d_set_clipping(gr->handle, clipRect.left, clipRect.top, clipRect.right, clipRect.bottom);
618+ g2d_blitSurface(gr->handle, &go->offscreenSurface,
619+ &go->renderSurf[go->activebuffer], &srcRect, &dstrect);
620+ }
621+
622+ if(go->clone_display_num)
623+ {
624+ int i = 0;
625+ for(i = 0; i < go->clone_display_num; i++)
626+ {
627+ g2dRECT srcRect = {0, 0, go->renderSurf[go->activebuffer].base.width, go->renderSurf[go->activebuffer].base.height};
628+ g2dRECT dstrect = {0, 0, go->mirrorSurf[i].base.width, go->mirrorSurf[i].base.height};
629+ g2dRECT clipRect = srcRect;
630+ g2d_set_clipping(gr->handle, clipRect.left, clipRect.top, clipRect.right, clipRect.bottom);
631+ if(go->directBlit || go->nNumBuffers > 1)
632+ {
633+ g2d_blitSurface(gr->handle, &go->renderSurf[go->activebuffer],
634+ &go->mirrorSurf[i], &srcRect, &dstrect);
635+ }
636+ else
637+ {
638+ g2d_blitSurface(gr->handle, &go->offscreenSurface,
639+ &go->mirrorSurf[i], &srcRect, &dstrect);
640+ }
641+ }
642+ }
643+
644+ g2d_finish(gr->handle);
645+
646+ if(go->nNumBuffers > 1)
647+ {
648+ g2d_flip_surface(output);
649+ }
650+}
651+
652+static int
653+is_view_visible(struct weston_view *view)
654+{
655+ /* Return false, if surface is guaranteed to be totally obscured. */
656+ int ret;
657+ pixman_region32_t unocc;
658+
659+ pixman_region32_init(&unocc);
660+ pixman_region32_subtract(&unocc, &view->transform.boundingbox,
661+ &view->clip);
662+ ret = pixman_region32_not_empty(&unocc);
663+ pixman_region32_fini(&unocc);
664+
665+ return ret;
666+}
667+
668+static void
669+use_output(struct weston_output *output)
670+{
671+ struct weston_compositor *compositor = output->compositor;
672+ struct weston_view *view;
673+ struct g2d_output_state *go = get_output_state(output);
674+ int visibleViews=0;
675+ int fullscreenViews=0;
676+
677+ if(go->nNumBuffers == 1)
678+ {
679+ wl_list_for_each_reverse(view, &compositor->view_list, link)
680+ if (view->plane == &compositor->primary_plane && is_view_visible(view))
681+ {
682+ visibleViews++;
683+ if(view->surface->width == go->width && view->surface->height == go->height)
684+ {
685+ pixman_box32_t *bb_rects;
686+ int nbb=0;
687+ bb_rects = pixman_region32_rectangles(&view->transform.boundingbox, &nbb);
688+ if(nbb == 1)
689+ if(bb_rects[0].x1 == 0 && bb_rects[0].y1 ==0)
690+ fullscreenViews++;
691+ }
692+ }
693+
694+ go->directBlit = ((visibleViews == 1) || (fullscreenViews > 1));
695+ }
696+}
697+
698+static int
699+g2d_renderer_read_pixels(struct weston_output *output,
700+ pixman_format_code_t format, void *pixels,
701+ uint32_t x, uint32_t y,
702+ uint32_t width, uint32_t height)
703+{
704+ return 0;
705+}
706+
707+static int g2d_int_from_double(double d)
708+{
709+ return wl_fixed_to_int(wl_fixed_from_double(d));
710+}
711+
712+static void
713+repaint_region(struct weston_view *ev, struct weston_output *output, struct g2d_output_state *go, pixman_region32_t *region,
714+ pixman_region32_t *surf_region){
715+
716+ struct g2d_renderer *gr = get_renderer(ev->surface->compositor);
717+ struct g2d_surface_state *gs = get_surface_state(ev->surface);
718+
719+ pixman_box32_t *rects, *surf_rects, *bb_rects;
720+ int i, j, nrects, nsurf, nbb=0;
721+ g2dRECT srcRect = {0};
722+ g2dRECT dstrect = {0};
723+ g2dRECT clipRect = {0};
724+ int dstWidth = 0;
725+ int dstHeight = 0;
726+ struct g2d_surfaceEx *dstsurface;
727+
728+ bb_rects = pixman_region32_rectangles(&ev->transform.boundingbox, &nbb);
729+
730+ if(!gs->attached || nbb <= 0)
731+ {
732+ return;
733+ }
734+
735+ rects = pixman_region32_rectangles(region, &nrects);
736+ surf_rects = pixman_region32_rectangles(surf_region, &nsurf);
737+ srcRect.left = ev->geometry.x < 0.0 ? g2d_int_from_double(fabsf(ev->geometry.x)) : 0;
738+ srcRect.top = ev->geometry.y < 0.0 ? g2d_int_from_double(fabsf(ev->geometry.y)) : 0;
739+ srcRect.right = ev->surface->width;
740+ srcRect.bottom = ev->surface->height;
741+ if(go->nNumBuffers > 1 || go->directBlit)
742+ {
743+ dstsurface = &go->renderSurf[go->activebuffer];
744+ }
745+ else
746+ {
747+ dstsurface = &go->offscreenSurface;
748+ }
749+ dstWidth = dstsurface->base.width;
750+ dstHeight = dstsurface->base.height;
751+ for (i = 0; i < nrects; i++)
752+ {
753+ pixman_box32_t *rect = &rects[i];
754+ gctFLOAT min_x, max_x, min_y, max_y;
755+
756+ dstrect.left = (bb_rects[0].x1 < 0) ? rect->x1 : bb_rects[0].x1;
757+ dstrect.top = (bb_rects[0].y1 < 0) ? rect->y1 : bb_rects[0].y1;
758+ dstrect.right = bb_rects[0].x2;
759+ dstrect.bottom = bb_rects[0].y2;
760+ /*Multi display support*/
761+ if(output->x > 0)
762+ {
763+ dstrect.left = dstrect.left - output->x;
764+ dstrect.right = dstrect.right - output->x;
765+ }
766+ if(dstrect.left < 0)
767+ {
768+ srcRect.left -= dstrect.left;
769+ dstrect.left = 0;
770+ if(srcRect.left > ev->surface->width)
771+ break;
772+ }
773+ if(dstrect.right > dstWidth)
774+ {
775+ dstrect.right = dstWidth;
776+ srcRect.right = srcRect.left + dstrect.right - dstrect.left;
777+ if(srcRect.right > ev->surface->width)
778+ break;
779+ }
780+ if(dstrect.bottom > dstHeight)
781+ {
782+ dstrect.bottom = dstHeight;
783+ srcRect.bottom = srcRect.top + dstrect.bottom - dstrect.top;
784+ if(srcRect.bottom < 0)
785+ break;
786+ }
787+
788+ for (j = 0; j < nsurf; j++)
789+ {
790+ pixman_box32_t *surf_rect = &surf_rects[j];
791+ gctFLOAT ex[8], ey[8]; /* edge points in screen space */
792+ int n;
793+ int m=0;
794+ n = calculate_edges(ev, rect, surf_rect, ex, ey);
795+ if (n < 3)
796+ continue;
797+
798+ min_x = max_x = ex[0];
799+ min_y = max_y = ey[0];
800+ for (m = 1; m < n; m++)
801+ {
802+ min_x = min(min_x, ex[m]);
803+ max_x = max(max_x, ex[m]);
804+ min_y = min(min_y, ey[m]);
805+ max_y = max(max_y, ey[m]);
806+ }
807+
808+ clipRect.left = g2d_int_from_double(min_x);
809+ clipRect.top = g2d_int_from_double(min_y);
810+ clipRect.right = g2d_int_from_double(max_x);
811+ clipRect.bottom = g2d_int_from_double(max_y);
812+
813+ if(output->x > 0)
814+ {
815+ clipRect.left = clipRect.left - output->x;
816+ clipRect.right = clipRect.right - output->x;
817+ }
818+ g2d_set_clipping(gr->handle, clipRect.left, clipRect.top, clipRect.right, clipRect.bottom);
819+ g2d_blitSurface(gr->handle, &gs->g2d_surface, dstsurface, &srcRect, &dstrect);
820+ }
821+ }
822+}
823+
824+static void
825+draw_view(struct weston_view *ev, struct weston_output *output,
826+ pixman_region32_t *damage) /* in global coordinates */
827+{
828+ struct weston_compositor *ec = ev->surface->compositor;
829+ struct g2d_output_state *go = get_output_state(output);
830+ struct g2d_surface_state *gs = get_surface_state(ev->surface);
831+ /* repaint bounding region in global coordinates: */
832+ pixman_region32_t repaint;
833+ /* non-opaque region in surface coordinates: */
834+ pixman_region32_t surface_blend;
835+ pixman_region32_t *buffer_damage;
836+
837+ pixman_region32_init(&repaint);
838+ pixman_region32_intersect(&repaint,
839+ &ev->transform.boundingbox, damage);
840+ pixman_region32_subtract(&repaint, &repaint, &ev->clip);
841+
842+ if (!pixman_region32_not_empty(&repaint))
843+ goto out;
844+
845+ buffer_damage = &go->buffer_damage[go->current_buffer];
846+ pixman_region32_subtract(buffer_damage, buffer_damage, &repaint);
847+
848+ /* blended region is whole surface minus opaque region: */
849+ pixman_region32_init_rect(&surface_blend, 0, 0,
850+ ev->surface->width, ev->surface->height);
851+ pixman_region32_subtract(&surface_blend, &surface_blend, &ev->surface->opaque);
852+
853+ struct g2d_renderer *gr = get_renderer(ec);
854+ if (pixman_region32_not_empty(&ev->surface->opaque)) {
855+ repaint_region(ev, output, go, &repaint, &ev->surface->opaque);
856+ }
857+
858+ if (pixman_region32_not_empty(&surface_blend)) {
859+ g2d_enable(gr->handle,G2D_BLEND);
860+ if (ev->alpha < 1.0)
861+ {
862+ g2d_enable(gr->handle, G2D_GLOBAL_ALPHA);
863+ gs->g2d_surface.base.global_alpha = ev->alpha * 0xFF;
864+ }
865+ repaint_region(ev, output, go, &repaint, &surface_blend);
866+ g2d_disable(gr->handle, G2D_GLOBAL_ALPHA);
867+ g2d_disable(gr->handle, G2D_BLEND);
868+ }
869+ pixman_region32_fini(&surface_blend);
870+
871+out:
872+ pixman_region32_fini(&repaint);
873+}
874+
875+static void
876+repaint_views(struct weston_output *output, pixman_region32_t *damage)
877+{
878+ struct weston_compositor *compositor = output->compositor;
879+ struct weston_view *view;
880+
881+ wl_list_for_each_reverse(view, &compositor->view_list, link)
882+ if (view->plane == &compositor->primary_plane)
883+ draw_view(view, output, damage);
884+}
885+
886+static void
887+g2d_renderer_repaint_output(struct weston_output *output,
888+ pixman_region32_t *output_damage)
889+{
890+ struct g2d_output_state *go = get_output_state(output);
891+ struct weston_compositor *compositor = output->compositor;
892+ struct g2d_renderer *gr = get_renderer(compositor);
893+ int i;
894+
895+ use_output(output);
896+ for (i = 0; i < 2; i++)
897+ pixman_region32_union(&go->buffer_damage[i],
898+ &go->buffer_damage[i],
899+ output_damage);
900+
901+ pixman_region32_union(output_damage, output_damage,
902+ &go->buffer_damage[go->current_buffer]);
903+
904+ repaint_views(output, output_damage);
905+ g2d_finish(gr->handle);
906+
907+ pixman_region32_copy(&output->previous_damage, output_damage);
908+ wl_signal_emit(&output->frame_signal, output);
909+ copy_to_framebuffer(output);
910+ go->current_buffer ^= 1;
911+}
912+
913+static void
914+g2d_renderer_attach_egl(struct weston_surface *es, struct weston_buffer *buffer)
915+{
916+ struct wl_viv_buffer *vivBuffer = wl_resource_get_user_data(buffer->resource);
917+ struct g2d_surface_state *gs = get_surface_state(es);
918+ buffer->width = vivBuffer->width;
919+ buffer->height = vivBuffer->height;
920+ get_g2dSurface(vivBuffer, &gs->g2d_surface);
921+}
922+
923+static void
924+g2d_renderer_flush_damage(struct weston_surface *surface)
925+{
926+ struct g2d_surface_state *gs = get_surface_state(surface);
927+ struct weston_buffer *buffer = gs->buffer_ref.buffer;
928+ struct weston_view *view;
929+ int texture_used;
930+ pixman_region32_union(&gs->texture_damage,
931+ &gs->texture_damage, &surface->damage);
932+
933+ if (!buffer)
934+ return;
935+
936+ texture_used = 0;
937+ wl_list_for_each(view, &surface->views, surface_link) {
938+ if (view->plane == &surface->compositor->primary_plane) {
939+ texture_used = 1;
940+ break;
941+ }
942+ }
943+ if (!texture_used)
944+ return;
945+
946+ if (!pixman_region32_not_empty(&gs->texture_damage))
947+ goto done;
948+
949+ if(wl_shm_buffer_get(buffer->resource))
950+ {
951+ uint8_t *src = wl_shm_buffer_get_data(buffer->shm_buffer);
952+ uint8_t *dst = gs->shm_buf->buf_vaddr;
953+ int bpp = gs->bpp;
954+ wl_shm_buffer_begin_access(buffer->shm_buffer);
955+ if(gs->shm_buf)
956+ {
957+ int alignedWidth = ALIGN_WIDTH(buffer->width);
958+ if(alignedWidth == buffer->width)
959+ {
960+ int size = wl_shm_buffer_get_stride(buffer->shm_buffer)*buffer->height;
961+ memcpy(dst, src, size);
962+ }
963+ else
964+ {
965+ int i, j;
966+ for (i = 0; i < buffer->height; i++)
967+ {
968+ for (j = 0; j < buffer->width; j++)
969+ {
970+ int dstOff = i * alignedWidth + j;
971+ int srcOff = (i * buffer->width + j);
972+ memcpy(dst + dstOff * bpp, src + srcOff * bpp, bpp);
973+ }
974+ }
975+ }
976+ }
977+ else
978+ {
979+ weston_log("Error: This shm buffer was not attached\n");
980+ }
981+ wl_shm_buffer_end_access(buffer->shm_buffer);
982+ }
983+ else
984+ {
985+ g2d_renderer_attach_egl(surface, buffer);
986+ }
987+
988+done:
989+ pixman_region32_fini(&gs->texture_damage);
990+ pixman_region32_init(&gs->texture_damage);
991+
992+ weston_buffer_reference(&gs->buffer_ref, NULL);
993+}
994+
995+static void
996+g2d_renderer_attach_shm(struct weston_surface *es, struct weston_buffer *buffer,
997+ struct wl_shm_buffer *shm_buffer)
998+{
999+ struct g2d_surface_state *gs = get_surface_state(es);
1000+ int buffer_length = 0;
1001+ int alloc_new_buff = 1;
1002+ int alignedWidth = 0;
1003+ enum g2d_format g2dFormat = 0;
1004+ buffer->shm_buffer = shm_buffer;
1005+ buffer->width = wl_shm_buffer_get_width(shm_buffer);
1006+ buffer->height = wl_shm_buffer_get_height(shm_buffer);
1007+ alignedWidth = ALIGN_WIDTH(buffer->width);
1008+
1009+ switch (wl_shm_buffer_get_format(shm_buffer)) {
1010+ case WL_SHM_FORMAT_XRGB8888:
1011+ g2dFormat = G2D_BGRX8888;
1012+ gs->bpp = 4;
1013+ break;
1014+ case WL_SHM_FORMAT_ARGB8888:
1015+ g2dFormat = G2D_BGRA8888;
1016+ gs->bpp = 4;
1017+ break;
1018+ case WL_SHM_FORMAT_RGB565:
1019+ g2dFormat = G2D_RGB565;
1020+ gs->bpp = 2;
1021+ break;
1022+ default:
1023+ weston_log("warning: unknown shm buffer format: %08x\n",
1024+ wl_shm_buffer_get_format(shm_buffer));
1025+ return;
1026+ }
1027+
1028+ buffer_length = alignedWidth * buffer->height * gs->bpp;
1029+
1030+ /* Only allocate a new g2d buff if it is larger than existing one.*/
1031+ gs->shm_buf_length = buffer_length;
1032+ if(gs->shm_buf && gs->shm_buf->buf_size > buffer_length)
1033+ {
1034+ alloc_new_buff = 0;
1035+ }
1036+
1037+ if(alloc_new_buff)
1038+ {
1039+ if(gs->shm_buf)
1040+ g2d_free(gs->shm_buf);
1041+ gs->shm_buf = g2d_alloc(buffer_length, 0);
1042+ gs->g2d_surface.base.planes[0] = gs->shm_buf->buf_paddr;
1043+ }
1044+ gs->g2d_surface.base.left = 0;
1045+ gs->g2d_surface.base.top = 0;
1046+ gs->g2d_surface.base.right = buffer->width;
1047+ gs->g2d_surface.base.bottom = buffer->height;
1048+ gs->g2d_surface.base.stride = alignedWidth;
1049+ gs->g2d_surface.base.width = buffer->width;
1050+ gs->g2d_surface.base.height = buffer->height;
1051+ gs->g2d_surface.base.rot = G2D_ROTATION_0;
1052+ gs->g2d_surface.base.clrcolor = 0xFF400000;
1053+ gs->g2d_surface.tiling = G2D_LINEAR;
1054+ gs->g2d_surface.base.format = g2dFormat;
1055+}
1056+
1057+static void
1058+g2d_renderer_attach(struct weston_surface *es, struct weston_buffer *buffer)
1059+{
1060+ struct g2d_surface_state *gs = get_surface_state(es);
1061+ struct wl_shm_buffer *shm_buffer;
1062+ weston_buffer_reference(&gs->buffer_ref, buffer);
1063+
1064+ if(buffer==NULL)
1065+ return;
1066+
1067+ shm_buffer = wl_shm_buffer_get(buffer->resource);
1068+
1069+ if(shm_buffer)
1070+ {
1071+ g2d_renderer_attach_shm(es, buffer, shm_buffer);
1072+ }
1073+ else
1074+ {
1075+ g2d_renderer_attach_egl(es, buffer);
1076+ }
1077+ gs->attached = 1;
1078+}
1079+
1080+static void
1081+surface_state_destroy(struct g2d_surface_state *gs, struct g2d_renderer *gr)
1082+{
1083+ wl_list_remove(&gs->surface_destroy_listener.link);
1084+ wl_list_remove(&gs->renderer_destroy_listener.link);
1085+ if(gs->surface)
1086+ gs->surface->renderer_state = NULL;
1087+
1088+ if(gs->shm_buf)
1089+ {
1090+ g2d_free(gs->shm_buf);
1091+ gs->shm_buf = NULL;
1092+ }
1093+
1094+ weston_buffer_reference(&gs->buffer_ref, NULL);
1095+ free(gs);
1096+}
1097+
1098+static void
1099+surface_state_handle_surface_destroy(struct wl_listener *listener, void *data)
1100+{
1101+ struct g2d_surface_state *gs;
1102+ struct g2d_renderer *gr;
1103+
1104+ gs = container_of(listener, struct g2d_surface_state,
1105+ surface_destroy_listener);
1106+
1107+ gr = get_renderer(gs->surface->compositor);
1108+ surface_state_destroy(gs, gr);
1109+}
1110+
1111+static void
1112+surface_state_handle_renderer_destroy(struct wl_listener *listener, void *data)
1113+{
1114+ struct g2d_surface_state *gs;
1115+ struct g2d_renderer *gr;
1116+
1117+ gr = data;
1118+
1119+ gs = container_of(listener, struct g2d_surface_state,
1120+ renderer_destroy_listener);
1121+
1122+ surface_state_destroy(gs, gr);
1123+}
1124+
1125+
1126+static int
1127+g2d_renderer_create_surface(struct weston_surface *surface)
1128+{
1129+ struct g2d_surface_state *gs;
1130+ struct g2d_renderer *gr = get_renderer(surface->compositor);
1131+
1132+ gs = zalloc(sizeof *gs);
1133+ if (gs == NULL)
1134+ return -1;
1135+
1136+ /* A buffer is never attached to solid color surfaces, yet
1137+ * they still go through texcoord computations. Do not divide
1138+ * by zero there.
1139+ */
1140+ gs->pitch = 1;
1141+
1142+ gs->surface = surface;
1143+
1144+ pixman_region32_init(&gs->texture_damage);
1145+ surface->renderer_state = gs;
1146+
1147+ gs->surface_destroy_listener.notify =
1148+ surface_state_handle_surface_destroy;
1149+ wl_signal_add(&surface->destroy_signal,
1150+ &gs->surface_destroy_listener);
1151+
1152+ gs->renderer_destroy_listener.notify =
1153+ surface_state_handle_renderer_destroy;
1154+ wl_signal_add(&gr->destroy_signal,
1155+ &gs->renderer_destroy_listener);
1156+
1157+ if (surface->buffer_ref.buffer) {
1158+ g2d_renderer_attach(surface, surface->buffer_ref.buffer);
1159+ g2d_renderer_flush_damage(surface);
1160+ }
1161+
1162+ return 0;
1163+}
1164+
1165+static void
1166+g2d_renderer_surface_set_color(struct weston_surface *surface,
1167+ float red, float green, float blue, float alpha)
1168+{
1169+ struct g2d_surface_state *gs = get_surface_state(surface);
1170+
1171+ gs->color[0] = red;
1172+ gs->color[1] = green;
1173+ gs->color[2] = blue;
1174+ gs->color[3] = alpha;
1175+}
1176+
1177+
1178+static void
1179+g2d_renderer_output_destroy(struct weston_output *output)
1180+{
1181+ struct g2d_output_state *go = get_output_state(output);
1182+ int i;
1183+
1184+ for (i = 0; i < 2; i++)
1185+ {
1186+ pixman_region32_fini(&go->buffer_damage[i]);
1187+ }
1188+
1189+ if(go->offscreen_buf)
1190+ {
1191+ g2d_free(go->offscreen_buf);
1192+ go->offscreen_buf = NULL;
1193+ }
1194+
1195+ if(go->fb_info.fb_fd)
1196+ {
1197+ close(go->fb_info.fb_fd);
1198+ go->fb_info.fb_fd = 0;
1199+ }
1200+
1201+ if(go->renderSurf)
1202+ {
1203+ free(go->renderSurf);
1204+ go->renderSurf = NULL;
1205+ }
1206+ for (i = 0; i < go->clone_display_num; i++)
1207+ {
1208+ if(go->mirror_fb_info[i].fb_fd)
1209+ {
1210+ close(go->mirror_fb_info[i].fb_fd);
1211+ go->mirror_fb_info[i].fb_fd = 0;
1212+ }
1213+ }
1214+ if(go->mirrorSurf)
1215+ {
1216+ free(go->mirrorSurf);
1217+ go->mirrorSurf = NULL;
1218+ }
1219+ if(go->mirror_fb_info)
1220+ {
1221+ free(go->mirror_fb_info);
1222+ go->mirror_fb_info = NULL;
1223+ }
1224+
1225+ free(go);
1226+}
1227+
1228+static void
1229+g2d_renderer_destroy(struct weston_compositor *ec)
1230+{
1231+ struct g2d_renderer *gr = get_renderer(ec);
1232+
1233+ wl_signal_emit(&gr->destroy_signal, gr);
1234+ g2d_close(gr->handle);
1235+#ifdef ENABLE_EGL
1236+ eglUnbindWaylandDisplayWL(gr->egl_display);
1237+ eglTerminate(gr->egl_display);
1238+ fbDestroyDisplay(gr->display);
1239+#endif
1240+ free(ec->renderer);
1241+ ec->renderer = NULL;
1242+}
1243+
1244+static int
1245+g2d_renderer_create(struct weston_compositor *ec)
1246+{
1247+ struct g2d_renderer *gr;
1248+ gr = malloc(sizeof *gr);
1249+ if (gr == NULL)
1250+ return -1;
1251+
1252+ gr->base.read_pixels = g2d_renderer_read_pixels;
1253+ gr->base.repaint_output = g2d_renderer_repaint_output;
1254+ gr->base.flush_damage = g2d_renderer_flush_damage;
1255+ gr->base.attach = g2d_renderer_attach;
1256+ gr->base.surface_set_color = g2d_renderer_surface_set_color;
1257+ gr->base.destroy = g2d_renderer_destroy;
1258+
1259+ if(g2d_open(&gr->handle))
1260+ {
1261+ weston_log("g2d_open fail.\n");
1262+ return -1;
1263+ }
1264+ ec->renderer = &gr->base;
1265+ wl_signal_init(&gr->destroy_signal);
1266+ return 0;
1267+}
1268+
1269+static int
1270+calculate_g2d_format(struct fb_var_screeninfo *varinfo, enum g2d_format *g2dFormat)
1271+{
1272+ /* Get the color format. */
1273+ switch (varinfo->green.length)
1274+ {
1275+ case 6:
1276+ *g2dFormat= G2D_RGB565;
1277+ break;
1278+
1279+ case 8:
1280+ if (varinfo->blue.offset == 0)
1281+ {
1282+ *g2dFormat = (varinfo->transp.length == 0) ? G2D_BGRX8888 : G2D_BGRA8888;
1283+ }
1284+ else
1285+ {
1286+ *g2dFormat = (varinfo->transp.length == 0) ? G2D_RGBX8888 : G2D_RGBA8888;
1287+ }
1288+ break;
1289+
1290+ default:
1291+ *g2dFormat = -1;
1292+ break;
1293+ }
1294+ return 0;
1295+}
1296+
1297+static int
1298+get_G2dSurface_from_screeninfo(struct fb_screeninfo *info, struct g2d_surfaceEx* g2dSurface)
1299+{
1300+ if(info && g2dSurface)
1301+ {
1302+ g2dSurface->base.planes[0] = info->physical;
1303+ g2dSurface->base.left = 0;
1304+ g2dSurface->base.top = 0;
1305+ g2dSurface->base.right = info->x_resolution;
1306+ g2dSurface->base.bottom = info->y_resolution;
1307+ g2dSurface->base.stride = info->stride;
1308+ g2dSurface->base.width = info->x_resolution;
1309+ g2dSurface->base.height = info->y_resolution;
1310+ g2dSurface->base.format = info->pixel_format;
1311+ g2dSurface->base.rot = G2D_ROTATION_0;
1312+ g2dSurface->base.clrcolor = 0xFF400000;
1313+ g2dSurface->tiling = G2D_LINEAR;
1314+ return 0;
1315+ }
1316+ return -1;
1317+}
1318+
1319+static int
1320+fb_query_screen_info(struct g2d_output_state *output, int fd,
1321+ struct fb_screeninfo *info)
1322+{
1323+ struct g2d_output_state *go = output;
1324+ struct fb_var_screeninfo *varinfo = &info->varinfo;
1325+ struct fb_fix_screeninfo *fixinfo = &info->fixinfo;
1326+
1327+ /* Probe the device for screen information. */
1328+ if (ioctl(fd, FBIOGET_VSCREENINFO, varinfo) < 0) {
1329+ return -1;
1330+ }
1331+
1332+ if(go->nNumBuffers > 1){
1333+ varinfo->yres_virtual = varinfo->yres * go->nNumBuffers;
1334+ if (ioctl(fd, FBIOPUT_VSCREENINFO, varinfo) < 0)
1335+ return -1;
1336+ }
1337+
1338+ if (ioctl(fd, FBIOGET_FSCREENINFO, fixinfo) < 0 ||
1339+ ioctl(fd, FBIOGET_VSCREENINFO, varinfo) < 0){
1340+ return -1;
1341+ }
1342+ /* Store the pertinent data. */
1343+ info->x_resolution = varinfo->xres;
1344+ info->y_resolution = varinfo->yres;
1345+ info->physical = fixinfo->smem_start;
1346+ info->buffer_length = fixinfo->smem_len;
1347+ info->stride = fixinfo->line_length / (varinfo->bits_per_pixel >> 3);
1348+ info->stride_bytes = fixinfo->line_length;
1349+ calculate_g2d_format(varinfo, &info->pixel_format);
1350+
1351+ if (info->pixel_format < 0) {
1352+ weston_log("Frame buffer uses an unsupported format.\n");
1353+ return -1;
1354+ }
1355+
1356+ return 0;
1357+}
1358+
1359+static int
1360+fb_frame_buffer_open(struct g2d_output_state *output, const char *fb_dev,
1361+ struct fb_screeninfo *screen_info)
1362+{
1363+ /* Open the frame buffer device. */
1364+ screen_info->fb_fd = open(fb_dev, O_RDWR | O_CLOEXEC);
1365+ if (screen_info->fb_fd < 0) {
1366+ weston_log("Failed to open frame buffer device%s \n", fb_dev);
1367+ return -1;
1368+ }
1369+
1370+ /* Grab the screen info. */
1371+ if (fb_query_screen_info(output, screen_info->fb_fd, screen_info) < 0) {
1372+ weston_log("Failed to get frame buffer info \n");
1373+
1374+ close(screen_info->fb_fd);
1375+ return -1;
1376+ }
1377+
1378+ return 0;
1379+}
1380+
1381+static void
1382+getBufferNumber(struct g2d_output_state *go)
1383+{
1384+ char *p = NULL;
1385+ p = getenv("FB_MULTI_BUFFER");
1386+ if (p == gcvNULL)
1387+ {
1388+ go->nNumBuffers = 1;
1389+ }
1390+ else
1391+ {
1392+ go->nNumBuffers = atoi(p);
1393+ if (go->nNumBuffers < 2)
1394+ {
1395+ go->nNumBuffers = 1;
1396+ }
1397+ else if(go->nNumBuffers >= 2)
1398+ {
1399+ go->nNumBuffers = 2;
1400+ go->activebuffer = 1;
1401+ }
1402+ }
1403+ weston_log("FB_MULTI_BUFFER = %d\n", go->nNumBuffers);
1404+}
1405+
1406+static int
1407+g2d_renderer_surface_create(struct g2d_output_state *go, struct g2d_renderer *gr, const char *device)
1408+{
1409+ int i = 0;
1410+ int offset = 0;
1411+ weston_log("Opend device=%s\n", device);
1412+ if(fb_frame_buffer_open(go, device, &go->fb_info) < 0)
1413+ {
1414+ weston_log("Open frame buffer failed.\n");
1415+ return -1;
1416+ }
1417+ go->renderSurf = zalloc(sizeof(struct g2d_surfaceEx) * go->nNumBuffers);
1418+ offset = go->fb_info.stride_bytes * go->fb_info.y_resolution;
1419+ for(i = 0; i < go->nNumBuffers; i++)
1420+ {
1421+ get_G2dSurface_from_screeninfo(&go->fb_info, &go->renderSurf[i]);
1422+ go->renderSurf[i].base.planes[0] = go->fb_info.physical
1423+ + (offset * i);
1424+ g2d_clear(gr->handle, &go->renderSurf[i].base);
1425+ }
1426+
1427+ if(go->nNumBuffers == 1)
1428+ {
1429+ go->offscreenSurface = (go->renderSurf[go->activebuffer]);
1430+ go->offscreen_buf = g2d_alloc(go->fb_info.buffer_length, 0);
1431+ go->offscreenSurface.base.planes[0] = go->offscreen_buf->buf_paddr;
1432+ g2d_clear(gr->handle, &go->offscreenSurface.base);
1433+ }
1434+ return 0;
1435+}
1436+
1437+static int
1438+g2d_renderer_output_create(struct weston_output *output, struct wl_display *wl_display, const char *device)
1439+
1440+ {
1441+ struct g2d_renderer *gr = get_renderer(output->compositor);
1442+ struct g2d_output_state *go;
1443+ int i;
1444+ int clone_display_num = 0;
1445+ int count = 0;
1446+ int k=0, dispCount = 0;
1447+ char displays[5][32];
1448+ weston_log("g2d_renderer_output_create device=%s\n", device);
1449+ count = strlen(device);
1450+
1451+ if(count > 0)
1452+ {
1453+ for(i= 0; i < count; i++)
1454+ {
1455+ if(device[i] == ',')
1456+ {
1457+ displays[dispCount][k] = '\0';
1458+ dispCount++;
1459+ k = 0;
1460+ continue;
1461+ }
1462+ else if(device[i] != ' ')
1463+ {
1464+ displays[dispCount][k++] = device[i];
1465+ }
1466+ }
1467+ displays[dispCount][k] = '\0';
1468+ clone_display_num = dispCount++;
1469+ weston_log("clone_display_num = %d\n", clone_display_num);
1470+ }
1471+ else
1472+ {
1473+ weston_log("Invalid device name\n");
1474+ return -1;
1475+ }
1476+
1477+ go = zalloc(sizeof *go);
1478+ if (go == NULL)
1479+ return -1;
1480+ go->clone_display_num = clone_display_num;
1481+ output->renderer_state = go;
1482+#ifdef ENABLE_EGL
1483+ gr->wl_display = wl_display;
1484+ gr->display = fbGetDisplay(wl_display);
1485+ gr->egl_display = eglGetDisplay(gr->display);
1486+ eglBindWaylandDisplayWL(gr->egl_display, wl_display);
1487+#endif
1488+ getBufferNumber(go);
1489+
1490+ if(g2d_renderer_surface_create(go, gr, displays[0]) < 0)
1491+ {
1492+ weston_log("Create Render surface failed.\n");
1493+ return -1;
1494+ }
1495+
1496+ if(go->clone_display_num)
1497+ {
1498+ go->mirrorSurf = zalloc(sizeof(struct g2d_surfaceEx) * clone_display_num);
1499+ go->mirror_fb_info = zalloc(sizeof(struct fb_screeninfo) * clone_display_num);
1500+ if(go->mirrorSurf == NULL || go->mirror_fb_info == NULL)
1501+ return -1;
1502+
1503+ for(i = 0; i < clone_display_num; i++)
1504+ {
1505+ if(fb_frame_buffer_open(go, displays[i + 1], &go->mirror_fb_info[i]) < 0)
1506+ {
1507+ weston_log("Open frame buffer failed.\n");
1508+ return -1;
1509+ }
1510+ get_G2dSurface_from_screeninfo(&go->mirror_fb_info[i], &go->mirrorSurf[i]);
1511+ go->mirrorSurf[i].base.planes[0] = go->mirror_fb_info[i].physical;
1512+ g2d_clear(gr->handle, &go->mirrorSurf[i].base);
1513+ }
1514+ }
1515+ g2d_finish(gr->handle);
1516+ for (i = 0; i < BUFFER_DAMAGE_COUNT; i++)
1517+ pixman_region32_init(&go->buffer_damage[i]);
1518+ return 0;
1519+ }
1520+
1521+ WL_EXPORT struct g2d_renderer_interface g2d_renderer_interface = {
1522+ .create = g2d_renderer_create,
1523+ .output_create = g2d_renderer_output_create,
1524+ .output_destroy = g2d_renderer_output_destroy,
1525+};
1526diff --git a/src/g2d-renderer.h b/src/g2d-renderer.h
1527new file mode 100644
1528index 0000000..fc4ca49
1529--- /dev/null
1530+++ b/src/g2d-renderer.h
1531@@ -0,0 +1,47 @@
1532+/*
1533+ * Copyright (c) 2015 Freescale Semiconductor, Inc.
1534+ * Copyright © 2013 Vasily Khoruzhick <anarsoul@gmail.com>
1535+ *
1536+ * Permission is hereby granted, free of charge, to any person obtaining
1537+ * a copy of this software and associated documentation files (the
1538+ * "Software"), to deal in the Software without restriction, including
1539+ * without limitation the rights to use, copy, modify, merge, publish,
1540+ * distribute, sublicense, and/or sell copies of the Software, and to
1541+ * permit persons to whom the Software is furnished to do so, subject to
1542+ * the following conditions:
1543+ *
1544+ * The above copyright notice and this permission notice (including the
1545+ * next paragraph) shall be included in all copies or substantial
1546+ * portions of the Software.
1547+ *
1548+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1549+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1550+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1551+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
1552+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
1553+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1554+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1555+ * SOFTWARE.
1556+ */
1557+#ifndef __g2d_renderer_h_
1558+#define __g2d_renderer_h_
1559+
1560+#include "compositor.h"
1561+
1562+#ifdef ENABLE_EGL
1563+#include <EGL/egl.h>
1564+#include <EGL/eglext.h>
1565+#endif
1566+
1567+struct g2d_renderer_interface {
1568+
1569+ int (*create)(struct weston_compositor *ec);
1570+
1571+ int (*output_create)(struct weston_output *output,
1572+ struct wl_display *wl_display,
1573+ const char *device);
1574+
1575+ void (*output_destroy)(struct weston_output *output);
1576+};
1577+
1578+#endif
1579diff --git a/src/main.c b/src/main.c
1580index 3279ac6..5d0bdc4 100644
1581--- a/src/main.c
1582+++ b/src/main.c
1583@@ -285,7 +285,8 @@ usage(int error_code)
1584 "Options for fbdev-backend.so:\n\n"
1585 " --tty=TTY\t\tThe tty to use\n"
1586 " --device=DEVICE\tThe framebuffer device to use\n"
1587- " --use-gl\t\tUse the GL renderer\n\n");
1588+ " --use-gl=1\t\tUse the GL renderer\n"
1589+ " --use-g2d=1\t\tUse the g2d renderer\n\n");
1590 #endif
1591
1592 #if defined(BUILD_HEADLESS_COMPOSITOR)
1593@@ -868,7 +869,8 @@ load_fbdev_backend(struct weston_compositor *c, char const * backend,
1594 const struct weston_option fbdev_options[] = {
1595 { WESTON_OPTION_INTEGER, "tty", 0, &config.tty },
1596 { WESTON_OPTION_STRING, "device", 0, &config.device },
1597- { WESTON_OPTION_BOOLEAN, "use-gl", 0, &config.use_gl },
1598+ { WESTON_OPTION_INTEGER, "use-gl", 0, &config.use_gl },
1599+ { WESTON_OPTION_INTEGER, "use-g2d", 0, &config.use_g2d },
1600 };
1601
1602 parse_options(fbdev_options, ARRAY_LENGTH(fbdev_options), argc, argv);
1603--
16042.7.4
1605
diff --git a/recipes-graphics/wayland/weston/0003-MGS-1192-xwld-g2d-compositor-dose-not-work.patch b/recipes-graphics/wayland/weston/0003-MGS-1192-xwld-g2d-compositor-dose-not-work.patch
deleted file mode 100644
index 019b7105..00000000
--- a/recipes-graphics/wayland/weston/0003-MGS-1192-xwld-g2d-compositor-dose-not-work.patch
+++ /dev/null
@@ -1,28 +0,0 @@
1From 9de82e2b39f839b5547308bf25d0d71f79936631 Mon Sep 17 00:00:00 2001
2From: Yong Gan <b45748@freescale.com>
3Date: Tue, 27 Oct 2015 15:07:02 +0800
4Subject: [PATCH] MGS-1192: xwld: g2d compositor dose not work
5
6Initial the backend->use_gal2d by input parameters.
7
8Upstream-Status: Inappropriate [i.MX specific]
9
10Signed-off-by: Yong Gan <yong.gan@freescale.com>
11---
12 src/compositor-fbdev.c | 3 ++-
13 1 file changed, 2 insertions(+), 1 deletion(-)
14
15Index: weston-1.11.0/src/compositor-fbdev.c
16===================================================================
17--- weston-1.11.0.orig/src/compositor-fbdev.c 2016-08-31 20:23:38.109228731 -0500
18+++ weston-1.11.0/src/compositor-fbdev.c 2016-08-31 20:30:25.000000000 -0500
19@@ -811,7 +811,8 @@
20 backend->base.restore = fbdev_restore;
21
22 backend->prev_state = WESTON_COMPOSITOR_ACTIVE;
23- backend->use_pixman = !param->use_gl;
24+ backend->use_pixman = !(param->use_gl || param->use_gal2d);
25+ backend->use_gal2d = param->use_gal2d;
26 backend->output_transform = param->output_transform;
27
28 weston_setup_vt_switch_bindings(compositor);
diff --git a/recipes-graphics/wayland/weston/0003-MGS-1783-xwld-Add-clone-mode-support-for-multi-displ.patch b/recipes-graphics/wayland/weston/0003-MGS-1783-xwld-Add-clone-mode-support-for-multi-displ.patch
new file mode 100644
index 00000000..328213c4
--- /dev/null
+++ b/recipes-graphics/wayland/weston/0003-MGS-1783-xwld-Add-clone-mode-support-for-multi-displ.patch
@@ -0,0 +1,104 @@
1From d22509cd41f9d44d9e66522307e30ad4ae4bace0 Mon Sep 17 00:00:00 2001
2From: Meng Mingming <mingming.meng@nxp.com>
3Date: Mon, 16 Jan 2017 10:23:13 +0800
4Subject: [PATCH 3/5] MGS-1783: xwld: Add clone mode support for multi display
5
6Support more than two displays to show the same contents
7
8Upstream Status: Inappropriate [i.MX specific]
9
10Date: May 16, 2016
11Signed-off-by: Yong Gan <yong.gan@nxp.com>
12---
13 src/compositor-fbdev.c | 18 +++++++++++++++---
14 src/compositor-fbdev.h | 1 +
15 src/main.c | 1 +
16 3 files changed, 17 insertions(+), 3 deletions(-)
17
18diff --git a/src/compositor-fbdev.c b/src/compositor-fbdev.c
19index cff9513..0a05e7d 100644
20--- a/src/compositor-fbdev.c
21+++ b/src/compositor-fbdev.c
22@@ -61,6 +61,8 @@ struct fbdev_backend {
23 struct udev_input input;
24 int use_pixman;
25 int use_g2d;
26+ int clone_mode;
27+ char *clone_device;
28 uint32_t output_transform;
29 struct wl_listener session_listener;
30 NativeDisplayType display;
31@@ -521,6 +523,8 @@ fbdev_output_create(struct fbdev_backend *backend,
32 goto out_hw_surface;
33 } else if(backend->use_g2d) {
34 const char *g2d_device = device;
35+ if (backend->clone_mode)
36+ g2d_device = backend->clone_device;
37
38 if (g2d_renderer->output_create(&output->base,
39 backend->compositor->wl_display, g2d_device) < 0) {
40@@ -797,6 +801,8 @@ fbdev_backend_create(struct weston_compositor *compositor, int *argc, char *argv
41 backend->prev_state = WESTON_COMPOSITOR_ACTIVE;
42 backend->use_pixman = !(param->use_gl || param->use_g2d);
43 backend->use_g2d = param->use_g2d;
44+ backend->clone_mode = param->clone_mode;
45+ backend->clone_device = param->device;
46 backend->output_transform = param->output_transform;
47
48 weston_setup_vt_switch_bindings(compositor);
49@@ -837,12 +843,17 @@ fbdev_backend_create(struct weston_compositor *compositor, int *argc, char *argv
50 displays[dispCount][k] = '\0';
51 dispCount++;
52
53- for(i= 0; i < dispCount; i++){
54- if (fbdev_output_create(backend, x, y, displays[i]) < 0)
55+ if(backend->clone_mode){
56+ if (fbdev_output_create(backend, x, y, displays[0]) < 0)
57 goto out_launcher;
58- x += container_of(backend->compositor->output_list.prev,
59+ } else {
60+ for(i= 0; i < dispCount; i++){
61+ if (fbdev_output_create(backend, x, y, displays[i]) < 0)
62+ goto out_launcher;
63+ x += container_of(backend->compositor->output_list.prev,
64 struct weston_output,
65 link)->width;
66+ }
67 }
68 } else {
69 gl_renderer = weston_load_module("gl-renderer.so",
70@@ -896,6 +907,7 @@ config_init_to_defaults(struct weston_fbdev_backend_config *config)
71 config->device = "/dev/fb0"; /* default frame buffer */
72 config->use_gl = 0;
73 config->use_g2d = 0;
74+ config->clone_mode = 0;
75 config->output_transform = WL_OUTPUT_TRANSFORM_NORMAL;
76 }
77
78diff --git a/src/compositor-fbdev.h b/src/compositor-fbdev.h
79index 32a8598..a28ef3b 100644
80--- a/src/compositor-fbdev.h
81+++ b/src/compositor-fbdev.h
82@@ -41,6 +41,7 @@ struct weston_fbdev_backend_config {
83 char *device;
84 int use_gl;
85 int use_g2d;
86+ int clone_mode;
87
88 uint32_t output_transform;
89 };
90diff --git a/src/main.c b/src/main.c
91index 5d0bdc4..18fe5e0 100644
92--- a/src/main.c
93+++ b/src/main.c
94@@ -871,6 +871,7 @@ load_fbdev_backend(struct weston_compositor *c, char const * backend,
95 { WESTON_OPTION_STRING, "device", 0, &config.device },
96 { WESTON_OPTION_INTEGER, "use-gl", 0, &config.use_gl },
97 { WESTON_OPTION_INTEGER, "use-g2d", 0, &config.use_g2d },
98+ { WESTON_OPTION_BOOLEAN, "clone-mode", 0, &config.clone_mode },
99 };
100
101 parse_options(fbdev_options, ARRAY_LENGTH(fbdev_options), argc, argv);
102--
1032.7.4
104
diff --git a/recipes-graphics/wayland/weston/0004-MGS-1235-Fix-setenv-and-clear-environments.patch b/recipes-graphics/wayland/weston/0004-MGS-1235-Fix-setenv-and-clear-environments.patch
deleted file mode 100644
index e4f8cd9c..00000000
--- a/recipes-graphics/wayland/weston/0004-MGS-1235-Fix-setenv-and-clear-environments.patch
+++ /dev/null
@@ -1,41 +0,0 @@
1From d09d0595b472d6bae35e78272fc670d494f6e408 Mon Sep 17 00:00:00 2001
2From: Prabhu <prabhu.sundararaj@freescale.com>
3Date: Tue, 17 Nov 2015 22:00:42 -0600
4Subject: [PATCH] MGS-1235 : Fix setenv and clear environments
5
6When setenv is set with parameter null causing crash.
7Fixed with unsetenv to restore to previous state
8
9Date: Nov 17, 2015
10Signed-off-by: Prabhu <prabhu.sundararaj@freescale.com>
11
12-1235
13---
14 src/compositor-fbdev.c | 11 ++++++++++-
15 1 file changed, 10 insertions(+), 1 deletion(-)
16
17diff --git a/src/compositor-fbdev.c b/src/compositor-fbdev.c
18index ed25576..c6b8e5a 100644
19--- a/src/compositor-fbdev.c
20+++ b/src/compositor-fbdev.c
21@@ -598,7 +598,16 @@ fbdev_output_create(struct fbdev_backend *backend,
22 fprintf(stderr, "failed to create window\n");
23 return 0;
24 }
25- setenv("FB_FRAMEBUFFER_0", fbenv, 1);
26+ /* restore the previous value*/
27+ if(fbenv != NULL)
28+ {
29+ setenv("FB_FRAMEBUFFER_0", fbenv, 1);
30+ }
31+ else
32+ {
33+ unsetenv("FB_FRAMEBUFFER_0");
34+ }
35+
36
37 if (gal2d_renderer->output_create(&output->base,
38 output->display,
39--
402.5.1
41
diff --git a/recipes-graphics/wayland/weston/0019-MGS-1668-xwld-System-can-not-boot-up-to-desktop.patch b/recipes-graphics/wayland/weston/0004-MGS-1668-xwld-System-can-not-boot-up-to-desktop.patch
index 09404caf..95a88e69 100644
--- a/recipes-graphics/wayland/weston/0019-MGS-1668-xwld-System-can-not-boot-up-to-desktop.patch
+++ b/recipes-graphics/wayland/weston/0004-MGS-1668-xwld-System-can-not-boot-up-to-desktop.patch
@@ -1,12 +1,12 @@
1From d3bc23ef2031e2749362bb0b90e5d164ef5d5942 Mon Sep 17 00:00:00 2001 1From 2e5260168b59c96688b10912cff3d95ec1fbb3d8 Mon Sep 17 00:00:00 2001
2From: Meng Mingming <mingming.meng@nxp.com> 2From: Meng Mingming <mingming.meng@nxp.com>
3Date: Mon, 9 Jan 2017 15:08:51 +0800 3Date: Mon, 16 Jan 2017 10:25:29 +0800
4Subject: [PATCH 4/6] MGS-1668: xwld: System can not boot up to desktop 4Subject: [PATCH 4/5] MGS-1668: xwld: System can not boot up to desktop
5 5
6System can not boot up to desktop if press touch panel continuously during booting up. 6System can not boot up to desktop if press touch panel continuously during booting up.
7The weston view was not initialed completely, so add a protection to the pointer. 7The weston view was not initialed completely, so add a protection to the pointer.
8 8
9Upstream Status: Inappropriate [i.MX specific] 9Upstream Status: Denied [Could not reproduce]
10 10
11Date: MAR 08, 2016 11Date: MAR 08, 2016
12Signed-off-by: Yong Gan <yong.gan@nxp.com> 12Signed-off-by: Yong Gan <yong.gan@nxp.com>
diff --git a/recipes-graphics/wayland/weston/0005-MGS-1252-Fix-for-Qt5_CinematicExperience-will-meet-s.patch b/recipes-graphics/wayland/weston/0005-MGS-1252-Fix-for-Qt5_CinematicExperience-will-meet-s.patch
deleted file mode 100644
index 82d37986..00000000
--- a/recipes-graphics/wayland/weston/0005-MGS-1252-Fix-for-Qt5_CinematicExperience-will-meet-s.patch
+++ /dev/null
@@ -1,93 +0,0 @@
1From 515b1f1c1902ae22914a93982935e2328d2240d2 Mon Sep 17 00:00:00 2001
2From: Yong Gan <b45748@freescale.com>
3Date: Thu, 19 Nov 2015 15:30:24 +0800
4Subject: [PATCH 2/2] MGS-1252: Fix for Qt5_CinematicExperience will meet
5 screen blur
6
7When the Qt5_CinematicExperience is created, window creates with 1920x1080
8and the starting coordiantes more than screen coordinate.
9Ths cause access beyond the surface and system hang on lcd display
10
11Date: Nov 18, 2015
12Signed-off-by: Prabhu <prabhu.sundararaj@freescale.com>
13---
14 src/gal2d-renderer.c | 30 ++++++++++++++++++------------
15 1 file changed, 18 insertions(+), 12 deletions(-)
16
17diff --git a/src/gal2d-renderer.c b/src/gal2d-renderer.c
18index c68f02c..6e7d640 100644
19--- a/src/gal2d-renderer.c
20+++ b/src/gal2d-renderer.c
21@@ -661,12 +661,11 @@ repaint_region(struct weston_view *ev, struct weston_output *output, struct gal2
22 gcsRECT srcRect = {0};
23 gcsRECT dstrect = {0};
24 gctUINT32 horFactor, verFactor;
25- int useStretch =1;
26 int useFilterBlit = 0;
27 gctUINT srcWidth = 0;
28 gctUINT srcHeight = 0;
29 gctUINT32 srcStride[3];
30- gceSURF_FORMAT srcFormat;;
31+ gceSURF_FORMAT srcFormat;
32 gctUINT32 srcPhyAddr[3];
33 gctUINT32 dstPhyAddr[3];
34 gctUINT dstWidth = 0;
35@@ -702,14 +701,16 @@ repaint_region(struct weston_view *ev, struct weston_output *output, struct gal2
36 srcRect.right = ev->surface->width;
37 srcRect.bottom = ev->surface->height;
38
39- if(useFilterBlit)
40+ dstsurface = go->nNumBuffers > 1 ?
41+ go->renderSurf[go->activebuffer] :
42+ go->offscreenSurface;
43+ gcmVERIFY_OK(gcoSURF_GetAlignedSize(dstsurface, &dstWidth, &dstHeight, (gctINT *)&dstStrides));
44+ gcmVERIFY_OK(gcoSURF_Lock(dstsurface, &dstPhyAddr[0], gcvNULL));
45+ gcmVERIFY_OK(gcoSURF_Unlock(dstsurface, gcvNULL));
46+
47+ if(galIsYUVFormat(srcFormat) == gcvSTATUS_TRUE)
48 {
49- dstsurface = go->nNumBuffers > 1 ?
50- go->renderSurf[go->activebuffer] :
51- go->offscreenSurface;
52- gcmVERIFY_OK(gcoSURF_GetAlignedSize(dstsurface, &dstWidth, &dstHeight, (gctINT *)&dstStrides));
53- gcmVERIFY_OK(gcoSURF_Lock(dstsurface, &dstPhyAddr[0], gcvNULL));
54- gcmVERIFY_OK(gcoSURF_Unlock(dstsurface, gcvNULL));
55+ useFilterBlit = 1;
56 }
57 else
58 {
59@@ -739,7 +740,7 @@ repaint_region(struct weston_view *ev, struct weston_output *output, struct gal2
60 dstrect.right = bb_rects[0].x2;
61 dstrect.bottom = bb_rects[0].y2;
62
63- if(dstrect.right < 0 || dstrect.bottom < 0)
64+ if(dstrect.right < 0 || dstrect.bottom < 0 || dstrect.left > dstWidth || dstrect.top > dstHeight)
65 {
66 break;
67 }
68@@ -829,8 +830,7 @@ repaint_region(struct weston_view *ev, struct weston_output *output, struct gal2
69 }
70 else
71 {
72- if(useStretch)
73- gcmVERIFY_OK(galGetStretchFactors(&srcRect, &dstrect, &horFactor, &verFactor));
74+ gcmVERIFY_OK(galGetStretchFactors(&srcRect, &dstrect, &horFactor, &verFactor));
75
76 if(verFactor == 65536 && horFactor == 65536)
77 {
78@@ -839,6 +839,12 @@ repaint_region(struct weston_view *ev, struct weston_output *output, struct gal2
79 }
80 else
81 {
82+ dstrect.right = dstrect.right < dstWidth ? dstrect.right : dstWidth;
83+ dstrect.bottom = dstrect.bottom < dstHeight ? dstrect.bottom : dstHeight;
84+ srcRect.right = srcRect.right < dstWidth ? srcRect.right : dstWidth;
85+ srcRect.bottom = srcRect.bottom < dstHeight ? srcRect.bottom : dstHeight;
86+
87+ gcmVERIFY_OK(galGetStretchFactors(&srcRect, &dstrect, &horFactor, &verFactor));
88 /* Program the stretch factors. */
89 gcmVERIFY_OK(gco2D_SetStretchFactors(gr->gcoEngine2d, horFactor, verFactor));
90
91--
921.9.1
93
diff --git a/recipes-graphics/wayland/weston/0005-MGS-1724-xwld-G2D-compositor-build-failed-in-slevk-b.patch b/recipes-graphics/wayland/weston/0005-MGS-1724-xwld-G2D-compositor-build-failed-in-slevk-b.patch
new file mode 100644
index 00000000..73b298cf
--- /dev/null
+++ b/recipes-graphics/wayland/weston/0005-MGS-1724-xwld-G2D-compositor-build-failed-in-slevk-b.patch
@@ -0,0 +1,146 @@
1From 3c11ac3c4b8416752c0e147ccde067070005597e Mon Sep 17 00:00:00 2001
2From: Meng Mingming <mingming.meng@nxp.com>
3Date: Mon, 16 Jan 2017 10:28:28 +0800
4Subject: [PATCH 5/5] MGS-1724: xwld: G2D compositor build failed in slevk
5 board
6
7Add macro ENABLE_EGL to make sure the EGL was not built in slevk board.
8
9Upstream Status: Inappropriate [i.MX specific]
10
11Date: Jan 16, 2017
12Signed-off-by: Meng Mingming <mingming.meng@nxp.com>
13---
14 src/compositor-fbdev.c | 18 ++++++++++++------
15 src/main.c | 22 +++++++++++++++++++---
16 2 files changed, 31 insertions(+), 9 deletions(-)
17
18diff --git a/src/compositor-fbdev.c b/src/compositor-fbdev.c
19index 0a05e7d..22d349b 100644
20--- a/src/compositor-fbdev.c
21+++ b/src/compositor-fbdev.c
22@@ -65,7 +65,9 @@ struct fbdev_backend {
23 char *clone_device;
24 uint32_t output_transform;
25 struct wl_listener session_listener;
26+#ifdef ENABLE_EGL
27 NativeDisplayType display;
28+#endif
29 };
30
31 struct fbdev_screeninfo {
32@@ -99,8 +101,10 @@ struct fbdev_output {
33 pixman_image_t *hw_surface;
34 uint8_t depth;
35
36+#ifdef ENABLE_EGL
37 NativeDisplayType display;
38 NativeWindowType window;
39+#endif
40 };
41
42 struct gl_renderer_interface *gl_renderer;
43@@ -452,10 +456,13 @@ fbdev_frame_buffer_destroy(struct fbdev_output *output)
44 strerror(errno));
45
46 output->fb = NULL;
47+
48+#ifdef ENABLE_EGL
49 if(output->window)
50 fbDestroyWindow(output->window);
51 if(output->display)
52 fbDestroyDisplay(output->display);
53+#endif
54 }
55
56 static void fbdev_output_destroy(struct weston_output *base);
57@@ -532,6 +539,7 @@ fbdev_output_create(struct fbdev_backend *backend,
58 goto out_hw_surface;
59 }
60 } else {
61+#ifdef ENABLE_EGL
62 setenv("HYBRIS_EGLPLATFORM", "wayland", 1);
63 output->window = fbCreateWindow(backend->display, -1, -1, 0, 0);
64 if (output->window == NULL) {
65@@ -545,6 +553,7 @@ fbdev_output_create(struct fbdev_backend *backend,
66 weston_log("gl_renderer_output_create failed.\n");
67 goto out_hw_surface;
68 }
69+#endif
70 }
71
72 loop = wl_display_get_event_loop(backend->compositor->wl_display);
73@@ -856,6 +865,7 @@ fbdev_backend_create(struct weston_compositor *compositor, int *argc, char *argv
74 }
75 }
76 } else {
77+#ifdef ENABLE_EGL
78 gl_renderer = weston_load_module("gl-renderer.so",
79 "gl_renderer_interface");
80 if (!gl_renderer) {
81@@ -875,7 +885,9 @@ fbdev_backend_create(struct weston_compositor *compositor, int *argc, char *argv
82 weston_log("gl_renderer_create failed.\n");
83 goto out_launcher;
84 }
85+#endif
86 }
87+
88 if(!backend->use_g2d)
89 if (fbdev_output_create(backend, 0, 0, param->device) < 0)
90 goto out_launcher;
91@@ -929,12 +941,6 @@ backend_init(struct weston_compositor *compositor, int *argc, char *argv[],
92 config_init_to_defaults(&config);
93 memcpy(&config, config_base, config_base->struct_size);
94
95- if(config.use_g2d) {
96- config.use_gl = 0;
97- } else {
98- config.use_gl = 1;
99- }
100-
101 b = fbdev_backend_create(compositor, argc, argv, wc, &config);
102 if (b == NULL)
103 return -1;
104diff --git a/src/main.c b/src/main.c
105index 18fe5e0..a0a5471 100644
106--- a/src/main.c
107+++ b/src/main.c
108@@ -285,8 +285,14 @@ usage(int error_code)
109 "Options for fbdev-backend.so:\n\n"
110 " --tty=TTY\t\tThe tty to use\n"
111 " --device=DEVICE\tThe framebuffer device to use\n"
112- " --use-gl=1\t\tUse the GL renderer\n"
113- " --use-g2d=1\t\tUse the g2d renderer\n\n");
114+#if defined(ENABLE_EGL)
115+ " --use-gl=1\t\tUse the GL renderer (default is 1)\n"
116+ " --use-g2d=1\t\tUse the G2D renderer (default is 0)\n"
117+#else
118+ " --use-gl=1\t\tUse the GL renderer (default is 0)\n"
119+ " --use-g2d=1\t\tUse the G2D renderer (default is 1)\n"
120+#endif
121+ " --clone-mode\t\tClone display to multiple devices\n\n");
122 #endif
123
124 #if defined(BUILD_HEADLESS_COMPOSITOR)
125@@ -861,7 +867,17 @@ static int
126 load_fbdev_backend(struct weston_compositor *c, char const * backend,
127 int *argc, char **argv, struct weston_config *wc)
128 {
129- struct weston_fbdev_backend_config config = {{ 0, }};
130+ struct weston_fbdev_backend_config config = {
131+ .base = {0},
132+#ifdef ENABLE_EGL
133+ .use_gl = 1,
134+ .use_g2d = 0,
135+#else
136+ .use_gl = 0,
137+ .use_g2d = 1,
138+#endif
139+ .clone_mode = 0,
140+ };
141 struct weston_config_section *section;
142 char *s = NULL;
143 int ret = 0;
144--
1452.7.4
146
diff --git a/recipes-graphics/wayland/weston/0016-Link-compositor-to-egl.patch b/recipes-graphics/wayland/weston/0006-Link-compositor-to-egl.patch
index 3cad74fd..3cad74fd 100644
--- a/recipes-graphics/wayland/weston/0016-Link-compositor-to-egl.patch
+++ b/recipes-graphics/wayland/weston/0006-Link-compositor-to-egl.patch
diff --git a/recipes-graphics/wayland/weston/0006-MGS-1236-imx6qp-imx6dl-First-frame-distored-when-som.patch b/recipes-graphics/wayland/weston/0006-MGS-1236-imx6qp-imx6dl-First-frame-distored-when-som.patch
deleted file mode 100644
index bed6f0c8..00000000
--- a/recipes-graphics/wayland/weston/0006-MGS-1236-imx6qp-imx6dl-First-frame-distored-when-som.patch
+++ /dev/null
@@ -1,106 +0,0 @@
1From 2bd1096ac342e251980c639543c0fad2f7173e82 Mon Sep 17 00:00:00 2001
2From: Prabhu Sundararaj <prabhu.sundararaj@freescale.com>
3Date: Wed, 9 Dec 2015 18:20:35 -0600
4Subject: [PATCH] MGS-1236 : [imx6qp/imx6dl] First frame distored when some
5 wayland apps run continuously using g2d
6
7gco2D_SetSource was missing when using the blit operations and
8hence causing the issue.
9
10If the weston started without weston.ini, animations will be disabled,
11for xwayland the weston.ini need to be included and hence the error
12was shown.
13
14Also removing util functions reusing from libGAL.so
15
16Date: Dec 10, 2015
17Signed-off-by: Prabhu Sundararaj <prabhu.sundararaj@freescale.com>
18---
19 src/gal2d-renderer.c | 57 ++++++----------------------------------------------
20 1 file changed, 6 insertions(+), 51 deletions(-)
21
22diff --git a/src/gal2d-renderer.c b/src/gal2d-renderer.c
23index 6e7d640..dbec2d0 100644
24--- a/src/gal2d-renderer.c
25+++ b/src/gal2d-renderer.c
26@@ -186,56 +186,6 @@ get_output_state(struct weston_output *output)
27 return (struct gal2d_output_state *)output->renderer_state;
28 }
29
30-static gctUINT32
31-galGetStretchFactor(gctINT32 SrcSize, gctINT32 DestSize)
32-{
33- gctUINT stretchFactor;
34- if ( (SrcSize > 0) && (DestSize > 1) )
35- {
36- stretchFactor = ((SrcSize - 1) << 16) / (DestSize - 1);
37- }
38- else
39- {
40- stretchFactor = 0;
41- }
42- return stretchFactor;
43-}
44-
45-static gceSTATUS
46-galGetStretchFactors(
47- IN gcsRECT_PTR SrcRect,
48- IN gcsRECT_PTR DestRect,
49- OUT gctUINT32 * HorFactor,
50- OUT gctUINT32 * VerFactor
51- )
52-{
53- if (HorFactor != gcvNULL)
54- {
55- gctINT32 src, dest;
56-
57- /* Compute width of rectangles. */
58- gcmVERIFY_OK(gcsRECT_Width(SrcRect, &src));
59- gcmVERIFY_OK(gcsRECT_Width(DestRect, &dest));
60-
61- /* Compute and return horizontal stretch factor. */
62- *HorFactor = galGetStretchFactor(src, dest);
63- }
64-
65- if (VerFactor != gcvNULL)
66- {
67- gctINT32 src, dest;
68-
69- /* Compute height of rectangles. */
70- gcmVERIFY_OK(gcsRECT_Height(SrcRect, &src));
71- gcmVERIFY_OK(gcsRECT_Height(DestRect, &dest));
72-
73- /* Compute and return vertical stretch factor. */
74- *VerFactor = galGetStretchFactor(src, dest);
75- }
76- /* Success. */
77- return gcvSTATUS_OK;
78-}
79-
80 static gceSTATUS
81 gal2d_getSurfaceFormat(halDISPLAY_INFO info, gceSURF_FORMAT * Format)
82 {
83@@ -725,6 +675,7 @@ repaint_region(struct weston_view *ev, struct weston_output *output, struct gal2
84 srcStride, 1,
85 tiling, srcFormat, gcvSURF_0_DEGREE,
86 srcWidth, srcHeight);
87+ gcmVERIFY_OK(gco2D_SetSource(gr->gcoEngine2d, &srcRect));
88 /* Setup mirror. */
89 gcmONERROR(gco2D_SetBitBlitMirror(gr->gcoEngine2d, gcvFALSE, gcvFALSE));
90 gcmONERROR(gco2D_SetROP(gr->gcoEngine2d, 0xCC, 0xCC));
91@@ -830,7 +781,11 @@ repaint_region(struct weston_view *ev, struct weston_output *output, struct gal2
92 }
93 else
94 {
95- gcmVERIFY_OK(galGetStretchFactors(&srcRect, &dstrect, &horFactor, &verFactor));
96+ gcmVERIFY_OK(gco2D_CalcStretchFactor(gr->gcoEngine2d, srcRect.right - srcRect.left,
97+ dstrect.right - dstrect.left, &horFactor));
98+
99+ gcmONERROR(gco2D_CalcStretchFactor(gr->gcoEngine2d, srcRect.bottom - srcRect.top,
100+ dstrect.bottom - dstrect.top, &verFactor));
101
102 if(verFactor == 65536 && horFactor == 65536)
103 {
104--
1052.6.2
106
diff --git a/recipes-graphics/wayland/weston/0007-MGS-1236-1-imx6qp-imx6dl-First-frame-distored-when-s.patch b/recipes-graphics/wayland/weston/0007-MGS-1236-1-imx6qp-imx6dl-First-frame-distored-when-s.patch
deleted file mode 100644
index 1c094c4d..00000000
--- a/recipes-graphics/wayland/weston/0007-MGS-1236-1-imx6qp-imx6dl-First-frame-distored-when-s.patch
+++ /dev/null
@@ -1,51 +0,0 @@
1From b33d44b736b7b7ae4db31dc32ff9441c753219fb Mon Sep 17 00:00:00 2001
2From: Prabhu Sundararaj <prabhu.sundararaj@freescale.com>
3Date: Mon, 28 Dec 2015 22:15:05 -0600
4Subject: [PATCH] MGS-1236-1 : [imx6qp/imx6dl] First frame distored when some
5 wayland apps run continuously using g2d
6
7Remove residual galGetStretchFactors functions. the function is not needed
8any more
9
10Date: Dec 28, 2015
11Signed-off-by: Prabhu Sundararaj <prabhu.sundararaj@freescale.com>
12---
13 src/gal2d-renderer.c | 14 +++++++++-----
14 1 file changed, 9 insertions(+), 5 deletions(-)
15
16diff --git a/src/gal2d-renderer.c b/src/gal2d-renderer.c
17index dbec2d0..2ecc8ac 100644
18--- a/src/gal2d-renderer.c
19+++ b/src/gal2d-renderer.c
20@@ -781,11 +781,11 @@ repaint_region(struct weston_view *ev, struct weston_output *output, struct gal2
21 }
22 else
23 {
24- gcmVERIFY_OK(gco2D_CalcStretchFactor(gr->gcoEngine2d, srcRect.right - srcRect.left,
25- dstrect.right - dstrect.left, &horFactor));
26+ gcmVERIFY_OK(gco2D_CalcStretchFactor(gr->gcoEngine2d, srcRect.right - srcRect.left,
27+ dstrect.right - dstrect.left, &horFactor));
28
29- gcmONERROR(gco2D_CalcStretchFactor(gr->gcoEngine2d, srcRect.bottom - srcRect.top,
30- dstrect.bottom - dstrect.top, &verFactor));
31+ gcmONERROR(gco2D_CalcStretchFactor(gr->gcoEngine2d, srcRect.bottom - srcRect.top,
32+ dstrect.bottom - dstrect.top, &verFactor));
33
34 if(verFactor == 65536 && horFactor == 65536)
35 {
36@@ -799,7 +799,11 @@ repaint_region(struct weston_view *ev, struct weston_output *output, struct gal2
37 srcRect.right = srcRect.right < dstWidth ? srcRect.right : dstWidth;
38 srcRect.bottom = srcRect.bottom < dstHeight ? srcRect.bottom : dstHeight;
39
40- gcmVERIFY_OK(galGetStretchFactors(&srcRect, &dstrect, &horFactor, &verFactor));
41+ gcmVERIFY_OK(gco2D_CalcStretchFactor(gr->gcoEngine2d, srcRect.right - srcRect.left,
42+ dstrect.right - dstrect.left, &horFactor));
43+
44+ gcmONERROR(gco2D_CalcStretchFactor(gr->gcoEngine2d, srcRect.bottom - srcRect.top,
45+ dstrect.bottom - dstrect.top, &verFactor));
46 /* Program the stretch factors. */
47 gcmVERIFY_OK(gco2D_SetStretchFactors(gr->gcoEngine2d, horFactor, verFactor));
48
49--
502.6.2
51
diff --git a/recipes-graphics/wayland/weston/0020-xwayland-Fix-crash-when-run-with-no-input-device.patch b/recipes-graphics/wayland/weston/0007-xwayland-Fix-crash-when-run-with-no-input-device.patch
index 1304cef2..1304cef2 100644
--- a/recipes-graphics/wayland/weston/0020-xwayland-Fix-crash-when-run-with-no-input-device.patch
+++ b/recipes-graphics/wayland/weston/0007-xwayland-Fix-crash-when-run-with-no-input-device.patch
diff --git a/recipes-graphics/wayland/weston/0009-MGS-1284-xwld-Re-implement-weston-2d-renderer-with-p.patch b/recipes-graphics/wayland/weston/0009-MGS-1284-xwld-Re-implement-weston-2d-renderer-with-p.patch
deleted file mode 100644
index f48785f1..00000000
--- a/recipes-graphics/wayland/weston/0009-MGS-1284-xwld-Re-implement-weston-2d-renderer-with-p.patch
+++ /dev/null
@@ -1,2843 +0,0 @@
1From 7bcbb14a149d0955176855e8ab6289cf68d099e5 Mon Sep 17 00:00:00 2001
2From: "yong.gan" <yong.gan@nxp.com>
3Date: Fri, 11 Mar 2016 10:55:48 +0800
4Subject: [PATCH 1/3] MGS-1284: xwld: Re-implement weston 2d renderer with
5 porting g2d API
6
7Use G2D API to replace Gal2D API.
8Fix the errors in multi display mode.
9Use the standard FB API to operate the frame buffer.
10
11Date: Feb 22, 2016
12Upstream Status: Inappropriate [i.MX specific]
13
14Signed-off-by: Yong Gan <yong.gan@freescale.com>
15---
16 Makefile.am | 16 +-
17 src/compositor-fbdev.c | 74 +--
18 src/g2d-renderer.c | 1175 +++++++++++++++++++++++++++++++++++++++++++
19 src/g2d-renderer.h | 48 ++
20 src/gal2d-renderer.c | 1307 ------------------------------------------------
21 src/gal2d-renderer.h | 50 --
22 6 files changed, 1255 insertions(+), 1415 deletions(-)
23 create mode 100644 src/g2d-renderer.c
24 create mode 100644 src/g2d-renderer.h
25 delete mode 100644 src/gal2d-renderer.c
26 delete mode 100644 src/gal2d-renderer.h
27
28Index: weston-1.11.1/Makefile.am
29===================================================================
30--- weston-1.11.1.orig/Makefile.am 2017-01-14 08:59:52.293865810 -0600
31+++ weston-1.11.1/Makefile.am 2017-01-14 09:08:38.000000000 -0600
32@@ -247,16 +247,16 @@
33 src/vertex-clipping.h \
34 shared/helpers.h
35 endif
36-module_LTLIBRARIES += gal2d-renderer.la
37-gal2d_renderer_la_LDFLAGS = -module -avoid-version
38-gal2d_renderer_la_LIBADD = $(COMPOSITOR_LIBS) $(EGL_LIBS)
39-gal2d_renderer_la_CFLAGS = \
40+module_LTLIBRARIES += g2d-renderer.la
41+g2d_renderer_la_LDFLAGS = -module -avoid-version
42+g2d_renderer_la_LIBADD = $(COMPOSITOR_LIBS) $(EGL_LIBS) -lg2d
43+g2d_renderer_la_CFLAGS = \
44 $(COMPOSITOR_CFLAGS) \
45 $(EGL_CFLAGS) \
46- $(GCC_CFLAGS)
47-gal2d_renderer_la_SOURCES = \
48- src/gal2d-renderer.h \
49- src/gal2d-renderer.c \
50+ $(GCC_CFLAGS) -DHAVE_G2D
51+g2d_renderer_la_SOURCES = \
52+ src/g2d-renderer.h \
53+ src/g2d-renderer.c \
54 src/vertex-clipping.c \
55 src/vertex-clipping.h
56
57Index: weston-1.11.1/src/compositor-fbdev.c
58===================================================================
59--- weston-1.11.1.orig/src/compositor-fbdev.c 2017-01-14 08:59:52.473866702 -0600
60+++ weston-1.11.1/src/compositor-fbdev.c 2017-01-14 09:19:12.000000000 -0600
61@@ -50,7 +50,7 @@
62 #include "libinput-seat.h"
63 #include "gl-renderer.h"
64 #include "presentation-time-server-protocol.h"
65-#include "gal2d-renderer.h"
66+#include "g2d-renderer.h"
67
68 struct fbdev_backend {
69 struct weston_backend base;
70@@ -60,7 +60,7 @@
71 struct udev *udev;
72 struct udev_input input;
73 int use_pixman;
74- int use_gal2d;
75+ int use_g2d;
76 uint32_t output_transform;
77 struct wl_listener session_listener;
78 NativeDisplayType display;
79@@ -102,7 +102,7 @@
80 };
81
82 struct gl_renderer_interface *gl_renderer;
83-struct gal2d_renderer_interface *gal2d_renderer;
84+struct g2d_renderer_interface *g2d_renderer;
85
86 static const char default_seat[] = "seat0";
87
88@@ -519,36 +519,10 @@
89 if (backend->use_pixman) {
90 if (pixman_renderer_output_create(&output->base) < 0)
91 goto out_hw_surface;
92- } else if(backend->use_gal2d) {
93-
94- char* fbenv = getenv("FB_FRAMEBUFFER_0");
95- setenv("FB_FRAMEBUFFER_0", device, 1);
96- output->display = fbGetDisplay(backend->compositor->wl_display);
97- if (output->display == NULL) {
98- fprintf(stderr, "failed to get display\n");
99- return 0;
100- }
101-
102- output->window = fbCreateWindow(output->display, -1, -1, 0, 0);
103- if (output->window == NULL) {
104- fprintf(stderr, "failed to create window\n");
105- return 0;
106- }
107- /* restore the previous value*/
108- if(fbenv != NULL)
109- {
110- setenv("FB_FRAMEBUFFER_0", fbenv, 1);
111- }
112- else
113- {
114- unsetenv("FB_FRAMEBUFFER_0");
115- }
116-
117-
118- if (gal2d_renderer->output_create(&output->base,
119- output->display,
120- (NativeWindowType)output->window) < 0) {
121- weston_log("gal_renderer_output_create failed.\n");
122+ } else if(backend->use_g2d) {
123+ if (g2d_renderer->output_create(&output->base,
124+ backend->compositor->wl_display, device) < 0) {
125+ weston_log("g2d_renderer_output_create failed.\n");
126 goto out_hw_surface;
127 }
128
129@@ -607,8 +581,8 @@
130 if (backend->use_pixman) {
131 if (base->renderer_state != NULL)
132 pixman_renderer_output_destroy(base);
133- } else if (backend->use_gal2d) {
134- gal2d_renderer->output_destroy(base);
135+ } else if (backend->use_g2d) {
136+ g2d_renderer->output_destroy(base);
137 } else {
138 gl_renderer->output_destroy(base);
139 }
140@@ -820,8 +794,8 @@
141 backend->base.restore = fbdev_restore;
142
143 backend->prev_state = WESTON_COMPOSITOR_ACTIVE;
144- backend->use_pixman = !(param->use_gl || param->use_gal2d);
145- backend->use_gal2d = param->use_gal2d;
146+ backend->use_pixman = !(param->use_gl || param->use_g2d);
147+ backend->use_g2d = param->use_g2d;
148 backend->output_transform = param->output_transform;
149
150 weston_setup_vt_switch_bindings(compositor);
151@@ -830,21 +804,21 @@
152 if (pixman_renderer_init(compositor) < 0)
153 goto out_launcher;
154 }
155- else if (backend->use_gal2d) {
156+ else if (backend->use_g2d) {
157 int x = 0, y = 0;
158 int i=0;
159 int count = 0;
160 int k=0, dispCount = 0;
161 char displays[5][32];
162- gal2d_renderer = weston_load_module("gal2d-renderer.so",
163- "gal2d_renderer_interface");
164- if (!gal2d_renderer) {
165- weston_log("could not load gal2d renderer\n");
166+ g2d_renderer = weston_load_module("g2d-renderer.so",
167+ "g2d_renderer_interface");
168+ if (!g2d_renderer) {
169+ weston_log("could not load g2d renderer\n");
170 goto out_launcher;
171 }
172
173- if (gal2d_renderer->create(backend->compositor) < 0) {
174- weston_log("gal2d_renderer_create failed.\n");
175+ if (g2d_renderer->create(backend->compositor) < 0) {
176+ weston_log("g2d_renderer_create failed.\n");
177 goto out_launcher;
178 }
179
180@@ -893,7 +867,7 @@
181 goto out_launcher;
182 }
183 }
184- if(!backend->use_gal2d)
185+ if(!backend->use_g2d)
186 if (fbdev_output_create(backend, 0, 0, param->device) < 0)
187 goto out_launcher;
188
189@@ -922,13 +896,8 @@
190 * udev, rather than passing a device node in as a parameter. */
191 config->tty = 0; /* default to current tty */
192 config->device = "/dev/fb0"; /* default frame buffer */
193-#ifdef ENABLE_EGL
194- config->use_gl = 1;
195- config->use_gal2d = 0;
196-#else
197 config->use_gl = 0;
198- config->use_gal2d = 1;
199-#endif
200+ config->use_g2d = 0;
201 config->output_transform = WL_OUTPUT_TRANSFORM_NORMAL;
202 }
203
204Index: weston-1.11.1/src/g2d-renderer.c
205===================================================================
206--- /dev/null 1970-01-01 00:00:00.000000000 +0000
207+++ weston-1.11.1/src/g2d-renderer.c 2017-01-14 09:08:38.000000000 -0600
208@@ -0,0 +1,1175 @@
209+/*
210+ * Copyright (c) 2016 Freescale Semiconductor, Inc.
211+ * Copyright © 2012 Intel Corporation
212+ * Copyright © 2015 Collabora, Ltd.
213+ *
214+ * Permission is hereby granted, free of charge, to any person obtaining
215+ * a copy of this software and associated documentation files (the
216+ * "Software"), to deal in the Software without restriction, including
217+ * without limitation the rights to use, copy, modify, merge, publish,
218+ * distribute, sublicense, and/or sell copies of the Software, and to
219+ * permit persons to whom the Software is furnished to do so, subject to
220+ * the following conditions:
221+ *
222+ * The above copyright notice and this permission notice (including the
223+ * next paragraph) shall be included in all copies or substantial
224+ * portions of the Software.
225+ *
226+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
227+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
228+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
229+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
230+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
231+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
232+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
233+ * SOFTWARE.
234+ */
235+
236+#define _GNU_SOURCE
237+
238+#include <stdlib.h>
239+#include <string.h>
240+#include <ctype.h>
241+#include <float.h>
242+#include <assert.h>
243+#include <pthread.h>
244+#include <linux/fb.h>
245+#include <sys/ioctl.h>
246+#include <fcntl.h>
247+#include <unistd.h>
248+
249+#include "compositor.h"
250+#include "g2d-renderer.h"
251+#include "vertex-clipping.h"
252+#include "shared/helpers.h"
253+#include "HAL/gc_hal_eglplatform.h"
254+#include "g2dExt.h"
255+
256+#define BUFFER_DAMAGE_COUNT 2
257+
258+typedef struct _g2dRECT
259+{
260+ int left;
261+ int top;
262+ int right;
263+ int bottom;
264+} g2dRECT;
265+
266+struct fb_screeninfo {
267+ struct fb_var_screeninfo varinfo;
268+ struct fb_fix_screeninfo fixinfo;
269+ unsigned int x_resolution;
270+ unsigned int y_resolution;
271+ size_t buffer_length; /* length of frame buffer memory in bytes */
272+ size_t physical;
273+ enum g2d_format pixel_format; /* frame buffer pixel format */
274+};
275+
276+struct g2d_output_state {
277+ int current_buffer;
278+ pixman_region32_t buffer_damage[BUFFER_DAMAGE_COUNT];
279+ struct g2d_surfaceEx *renderSurf;
280+ int nNumBuffers;
281+ int activebuffer;
282+ struct g2d_surfaceEx offscreenSurface;
283+ struct g2d_buf *offscreen_buf;
284+ struct fb_screeninfo fb_info;
285+ int directBlit;
286+ int width;
287+ int height;
288+ int fb_fd;
289+};
290+
291+struct g2d_surface_state {
292+ float color[4];
293+ struct weston_buffer_reference buffer_ref;
294+ int pitch; /* in pixels */
295+ int attached;
296+ pixman_region32_t texture_damage;
297+ struct g2d_surfaceEx g2d_surface;
298+ struct g2d_buf *shm_buf;
299+ int shm_buf_length;
300+ int bpp;
301+
302+ struct weston_surface *surface;
303+ struct wl_listener surface_destroy_listener;
304+ struct wl_listener renderer_destroy_listener;
305+};
306+
307+struct g2d_renderer {
308+ struct weston_renderer base;
309+ struct wl_signal destroy_signal;
310+ struct wl_global *viv_global;
311+ void *handle;
312+};
313+
314+static int
315+g2d_renderer_create_surface(struct weston_surface *surface);
316+
317+static inline struct g2d_surface_state *
318+get_surface_state(struct weston_surface *surface)
319+{
320+ if (!surface->renderer_state)
321+ g2d_renderer_create_surface(surface);
322+ return (struct g2d_surface_state *)surface->renderer_state;
323+}
324+
325+static inline struct g2d_renderer *
326+get_renderer(struct weston_compositor *ec)
327+{
328+ return (struct g2d_renderer *)ec->renderer;
329+}
330+
331+#define max(a, b) (((a) > (b)) ? (a) : (b))
332+#define min(a, b) (((a) > (b)) ? (b) : (a))
333+/*
334+ * Compute the boundary vertices of the intersection of the global coordinate
335+ * aligned rectangle 'rect', and an arbitrary quadrilateral produced from
336+ * 'surf_rect' when transformed from surface coordinates into global coordinates.
337+ * The vertices are written to 'ex' and 'ey', and the return value is the
338+ * number of vertices. Vertices are produced in clockwise winding order.
339+ * Guarantees to produce either zero vertices, or 3-8 vertices with non-zero
340+ * polygon area.
341+ */
342+static int
343+calculate_edges(struct weston_view *ev, pixman_box32_t *rect,
344+ pixman_box32_t *surf_rect, float *ex, float *ey)
345+{
346+
347+ struct clip_context ctx;
348+ int i, n;
349+ float min_x, max_x, min_y, max_y;
350+ struct polygon8 surf = {
351+ { surf_rect->x1, surf_rect->x2, surf_rect->x2, surf_rect->x1 },
352+ { surf_rect->y1, surf_rect->y1, surf_rect->y2, surf_rect->y2 },
353+ 4
354+ };
355+
356+ ctx.clip.x1 = rect->x1;
357+ ctx.clip.y1 = rect->y1;
358+ ctx.clip.x2 = rect->x2;
359+ ctx.clip.y2 = rect->y2;
360+
361+ /* transform surface to screen space: */
362+ for (i = 0; i < surf.n; i++)
363+ weston_view_to_global_float(ev, surf.x[i], surf.y[i],
364+ &surf.x[i], &surf.y[i]);
365+
366+ /* find bounding box: */
367+ min_x = max_x = surf.x[0];
368+ min_y = max_y = surf.y[0];
369+
370+ for (i = 1; i < surf.n; i++) {
371+ min_x = min(min_x, surf.x[i]);
372+ max_x = max(max_x, surf.x[i]);
373+ min_y = min(min_y, surf.y[i]);
374+ max_y = max(max_y, surf.y[i]);
375+ }
376+
377+ /* First, simple bounding box check to discard early transformed
378+ * surface rects that do not intersect with the clip region:
379+ */
380+ if ((min_x >= ctx.clip.x2) || (max_x <= ctx.clip.x1) ||
381+ (min_y >= ctx.clip.y2) || (max_y <= ctx.clip.y1))
382+ return 0;
383+
384+ /* Simple case, bounding box edges are parallel to surface edges,
385+ * there will be only four edges. We just need to clip the surface
386+ * vertices to the clip rect bounds:
387+ */
388+ if (!ev->transform.enabled)
389+ return clip_simple(&ctx, &surf, ex, ey);
390+
391+ /* Transformed case: use a general polygon clipping algorithm to
392+ * clip the surface rectangle with each side of 'rect'.
393+ * The algorithm is Sutherland-Hodgman, as explained in
394+ * http://www.codeguru.com/cpp/misc/misc/graphics/article.php/c8965/Polygon-Clipping.htm
395+ * but without looking at any of that code.
396+ */
397+ n = clip_transformed(&ctx, &surf, ex, ey);
398+
399+ if (n < 3)
400+ return 0;
401+
402+ return n;
403+}
404+
405+
406+static inline struct g2d_output_state *
407+get_output_state(struct weston_output *output)
408+{
409+ return (struct g2d_output_state *)output->renderer_state;
410+}
411+
412+static void
413+g2d_getG2dTiling(IN gceTILING tiling, enum g2d_tiling* g2dTiling)
414+{
415+ switch(tiling)
416+ {
417+ case gcvLINEAR:
418+ *g2dTiling = G2D_LINEAR;
419+ break;
420+ case gcvTILED:
421+ *g2dTiling = G2D_TILED;
422+ break;
423+ case gcvSUPERTILED:
424+ *g2dTiling = G2D_SUPERTILED;
425+ break;
426+ default:
427+ weston_log("Error in function %s\n", __func__);
428+ break;
429+ }
430+}
431+
432+static void
433+g2d_getG2dFormat(IN gceSURF_FORMAT Format, enum g2d_format* g2dFormat)
434+{
435+ switch(Format)
436+ {
437+ case gcvSURF_R5G6B5:
438+ *g2dFormat = G2D_RGB565;
439+ break;
440+ case gcvSURF_A8B8G8R8:
441+ *g2dFormat = G2D_RGBA8888;
442+ break;
443+ case gcvSURF_X8B8G8R8:
444+ *g2dFormat = G2D_RGBA8888;
445+ break;
446+ case gcvSURF_A8R8G8B8:
447+ *g2dFormat = G2D_BGRA8888;
448+ break;
449+ case gcvSURF_X8R8G8B8:
450+ *g2dFormat = G2D_BGRX8888;
451+ break;
452+ case gcvSURF_B5G6R5:
453+ *g2dFormat = G2D_BGR565;
454+ break;
455+ case gcvSURF_B8G8R8A8:
456+ *g2dFormat = G2D_ARGB8888;
457+ break;
458+ case gcvSURF_R8G8B8A8:
459+ *g2dFormat = G2D_ABGR8888;
460+ break;
461+ case gcvSURF_B8G8R8X8:
462+ *g2dFormat = G2D_XRGB8888;
463+ break;
464+ case gcvSURF_R8G8B8X8:
465+ *g2dFormat = G2D_XBGR8888;
466+ break;
467+ case gcvSURF_NV12:
468+ *g2dFormat = G2D_NV12;
469+ break;
470+ case gcvSURF_NV21:
471+ *g2dFormat = G2D_NV21;
472+ break;
473+ case gcvSURF_I420:
474+ *g2dFormat = G2D_I420;
475+ break;
476+ case gcvSURF_YV12:
477+ *g2dFormat = G2D_YV12;
478+ break;
479+ case gcvSURF_YUY2:
480+ *g2dFormat = G2D_YUYV;
481+ break;
482+ case gcvSURF_YVYU:
483+ *g2dFormat = G2D_YVYU;
484+ break;
485+ case gcvSURF_UYVY:
486+ *g2dFormat = G2D_UYVY;
487+ break;
488+ case gcvSURF_VYUY:
489+ *g2dFormat = G2D_VYUY;
490+ break;
491+ case gcvSURF_NV16:
492+ *g2dFormat = G2D_NV16;
493+ break;
494+ case gcvSURF_NV61:
495+ *g2dFormat = G2D_NV61;
496+ break;
497+ default:
498+ weston_log("Error in function %s, Format not supported\n", __func__);
499+ break;
500+ }
501+}
502+
503+static void printG2dSurfaceInfo(struct g2d_surfaceEx* g2dSurface)
504+{
505+ weston_log("physicAddr = %d left = %d right = %d top=%d bottom=%d stride= %d tiling = %d, format=%d \n",
506+ g2dSurface->base.planes[0],
507+ g2dSurface->base.left,
508+ g2dSurface->base.right,
509+ g2dSurface->base.top,
510+ g2dSurface->base.bottom,
511+ g2dSurface->base.stride,
512+ g2dSurface->tiling,
513+ g2dSurface->base.format);
514+}
515+
516+static void
517+get_g2dSurface(gcsWL_VIV_BUFFER *buffer, struct g2d_surfaceEx *g2dSurface)
518+{
519+ if(buffer->width < 0 || buffer->height < 0)
520+ {
521+ weston_log("invalid EGL buffer in function %s\n", __func__);
522+ return;
523+ }
524+ int width = buffer->alignedWidth;
525+ int height = buffer->alignedHeight;
526+ g2d_getG2dFormat(buffer->format, &g2dSurface->base.format);
527+ g2d_getG2dTiling(buffer->tiling, &g2dSurface->tiling);
528+ g2dSurface->base.planes[0] = buffer->physical[0];
529+ g2dSurface->base.planes[1] = buffer->physical[1];
530+ g2dSurface->base.planes[2] = buffer->physical[2];
531+ g2dSurface->base.left = 0;
532+ g2dSurface->base.top = 0;
533+ g2dSurface->base.right = buffer->width;
534+ g2dSurface->base.bottom = buffer->height;
535+ g2dSurface->base.stride = width;
536+ g2dSurface->base.width = width;
537+ g2dSurface->base.height = height;
538+ g2dSurface->base.rot = G2D_ROTATION_0;
539+}
540+
541+static void
542+g2d_SetSurfaceRect(struct g2d_surfaceEx* g2dSurface, g2dRECT* rect)
543+{
544+ if(g2dSurface && rect)
545+ {
546+ g2dSurface->base.left = rect->left;
547+ g2dSurface->base.top = rect->top;
548+ g2dSurface->base.right = rect->right;
549+ g2dSurface->base.bottom = rect->bottom;
550+ }
551+}
552+
553+static int
554+g2d_blitSurface(void *handle, struct g2d_surfaceEx * srcG2dSurface, struct g2d_surfaceEx *dstG2dSurface,
555+ g2dRECT *srcRect, g2dRECT *dstRect)
556+{
557+ g2d_SetSurfaceRect(srcG2dSurface, srcRect);
558+ g2d_SetSurfaceRect(dstG2dSurface, dstRect);
559+ srcG2dSurface->base.blendfunc = G2D_ONE;
560+ dstG2dSurface->base.blendfunc = G2D_ONE_MINUS_SRC_ALPHA;
561+
562+ if(g2d_blitEx(handle, srcG2dSurface, dstG2dSurface))
563+ {
564+ printG2dSurfaceInfo(srcG2dSurface);
565+ printG2dSurfaceInfo(dstG2dSurface);
566+ return -1;
567+ }
568+ return 0;
569+}
570+
571+static void
572+g2d_flip_surface(struct weston_output *output)
573+{
574+ struct g2d_output_state *go = get_output_state(output);
575+ go->fb_info.varinfo.yoffset = go->activebuffer * go->fb_info.y_resolution;
576+
577+ if(ioctl(go->fb_fd, FBIOPAN_DISPLAY, &(go->fb_info.varinfo)) < 0)
578+ {
579+ weston_log("FBIOPAN_DISPLAY Failed\n");
580+ }
581+ go->activebuffer = (go->activebuffer + 1) % go->nNumBuffers;
582+}
583+
584+static void
585+copy_to_framebuffer(struct weston_output *output)
586+{
587+ struct g2d_renderer *gr = get_renderer(output->compositor);
588+ struct g2d_output_state *go = get_output_state(output);
589+ if(!go->directBlit && go->nNumBuffers == 1)
590+ {
591+ g2dRECT srcRect = {0, 0, go->offscreenSurface.base.width, go->offscreenSurface.base.height};
592+ g2dRECT dstrect = srcRect;
593+ g2dRECT clipRect = srcRect;
594+ g2d_set_clipping(gr->handle, clipRect.left, clipRect.top, clipRect.right, clipRect.bottom);
595+ g2d_blitSurface(gr->handle, &go->offscreenSurface,
596+ &go->renderSurf[go->activebuffer], &srcRect, &dstrect);
597+ }
598+
599+ g2d_finish(gr->handle);
600+
601+ if(go->nNumBuffers > 1)
602+ {
603+ g2d_flip_surface(output);
604+ }
605+}
606+
607+static int
608+is_view_visible(struct weston_view *view)
609+{
610+ /* Return false, if surface is guaranteed to be totally obscured. */
611+ int ret;
612+ pixman_region32_t unocc;
613+
614+ pixman_region32_init(&unocc);
615+ pixman_region32_subtract(&unocc, &view->transform.boundingbox,
616+ &view->clip);
617+ ret = pixman_region32_not_empty(&unocc);
618+ pixman_region32_fini(&unocc);
619+
620+ return ret;
621+}
622+
623+static void
624+use_output(struct weston_output *output)
625+{
626+ struct weston_compositor *compositor = output->compositor;
627+ struct weston_view *view;
628+ struct g2d_output_state *go = get_output_state(output);
629+ int visibleViews=0;
630+ int fullscreenViews=0;
631+
632+ if(go->nNumBuffers == 1)
633+ {
634+ wl_list_for_each_reverse(view, &compositor->view_list, link)
635+ if (view->plane == &compositor->primary_plane && is_view_visible(view))
636+ {
637+ visibleViews++;
638+ if(view->surface->width == go->width && view->surface->height == go->height)
639+ {
640+ pixman_box32_t *bb_rects;
641+ int nbb=0;
642+ bb_rects = pixman_region32_rectangles(&view->transform.boundingbox, &nbb);
643+ if(nbb == 1)
644+ if(bb_rects[0].x1 == 0 && bb_rects[0].y1 ==0)
645+ fullscreenViews++;
646+ }
647+ }
648+
649+ go->directBlit = ((visibleViews == 1) || (fullscreenViews > 1));
650+ }
651+}
652+
653+static int
654+g2d_renderer_read_pixels(struct weston_output *output,
655+ pixman_format_code_t format, void *pixels,
656+ uint32_t x, uint32_t y,
657+ uint32_t width, uint32_t height)
658+{
659+ return 0;
660+}
661+
662+static int g2d_int_from_double(double d)
663+{
664+ return wl_fixed_to_int(wl_fixed_from_double(d));
665+}
666+
667+static void
668+repaint_region(struct weston_view *ev, struct weston_output *output, struct g2d_output_state *go, pixman_region32_t *region,
669+ pixman_region32_t *surf_region){
670+
671+ struct g2d_renderer *gr = get_renderer(ev->surface->compositor);
672+ struct g2d_surface_state *gs = get_surface_state(ev->surface);
673+
674+ pixman_box32_t *rects, *surf_rects, *bb_rects;
675+ int i, j, nrects, nsurf, nbb=0;
676+ g2dRECT srcRect = {0};
677+ g2dRECT dstrect = {0};
678+ g2dRECT clipRect = {0};
679+ int dstWidth = 0;
680+ int dstHeight = 0;
681+ struct g2d_surfaceEx *dstsurface;
682+
683+ bb_rects = pixman_region32_rectangles(&ev->transform.boundingbox, &nbb);
684+
685+ if(!gs->attached || nbb <= 0)
686+ {
687+ return;
688+ }
689+
690+ rects = pixman_region32_rectangles(region, &nrects);
691+ surf_rects = pixman_region32_rectangles(surf_region, &nsurf);
692+ srcRect.left = ev->geometry.x < 0.0 ? g2d_int_from_double(fabsf(ev->geometry.x)) : 0;
693+ srcRect.top = ev->geometry.y < 0.0 ? g2d_int_from_double(fabsf(ev->geometry.y)) : 0;
694+ srcRect.right = ev->surface->width;
695+ srcRect.bottom = ev->surface->height;
696+ if(go->nNumBuffers > 1 || go->directBlit)
697+ {
698+ dstsurface = &go->renderSurf[go->activebuffer];
699+ }
700+ else
701+ {
702+ dstsurface = &go->offscreenSurface;
703+ }
704+ dstWidth = dstsurface->base.width;
705+ dstHeight = dstsurface->base.height;
706+ for (i = 0; i < nrects; i++)
707+ {
708+ pixman_box32_t *rect = &rects[i];
709+ gctFLOAT min_x, max_x, min_y, max_y;
710+
711+ dstrect.left = (bb_rects[0].x1 < 0) ? rect->x1 : bb_rects[0].x1;
712+ dstrect.top = (bb_rects[0].y1 < 0) ? rect->y1 : bb_rects[0].y1;
713+ dstrect.right = bb_rects[0].x2;
714+ dstrect.bottom = bb_rects[0].y2;
715+ /*Multi display support*/
716+ if(output->x > 0)
717+ {
718+ dstrect.left = dstrect.left - output->x;
719+ dstrect.right = dstrect.right - output->x;
720+ }
721+ if(dstrect.left < 0)
722+ {
723+ srcRect.left -= dstrect.left;
724+ dstrect.left = 0;
725+ if(srcRect.left > ev->surface->width)
726+ break;
727+ }
728+ if(dstrect.right > dstWidth)
729+ {
730+ dstrect.right = dstWidth;
731+ srcRect.right = srcRect.left + dstrect.right - dstrect.left;
732+ if(srcRect.right > ev->surface->width)
733+ break;
734+ }
735+ if(dstrect.bottom > dstHeight)
736+ {
737+ dstrect.bottom = dstHeight;
738+ srcRect.bottom = srcRect.top + dstrect.bottom - dstrect.top;
739+ if(srcRect.bottom < 0)
740+ break;
741+ }
742+
743+ for (j = 0; j < nsurf; j++)
744+ {
745+ pixman_box32_t *surf_rect = &surf_rects[j];
746+ gctFLOAT ex[8], ey[8]; /* edge points in screen space */
747+ int n;
748+ int m=0;
749+ n = calculate_edges(ev, rect, surf_rect, ex, ey);
750+ if (n < 3)
751+ continue;
752+
753+ min_x = max_x = ex[0];
754+ min_y = max_y = ey[0];
755+ for (m = 1; m < n; m++)
756+ {
757+ min_x = min(min_x, ex[m]);
758+ max_x = max(max_x, ex[m]);
759+ min_y = min(min_y, ey[m]);
760+ max_y = max(max_y, ey[m]);
761+ }
762+
763+ clipRect.left = g2d_int_from_double(min_x);
764+ clipRect.top = g2d_int_from_double(min_y);
765+ clipRect.right = g2d_int_from_double(max_x);
766+ clipRect.bottom = g2d_int_from_double(max_y);
767+
768+ if(output->x > 0)
769+ {
770+ clipRect.left = clipRect.left - output->x;
771+ clipRect.right = clipRect.right - output->x;
772+ }
773+ g2d_set_clipping(gr->handle, clipRect.left, clipRect.top, clipRect.right, clipRect.bottom);
774+ g2d_blitSurface(gr->handle, &gs->g2d_surface, dstsurface, &srcRect, &dstrect);
775+ }
776+ }
777+}
778+
779+static void
780+draw_view(struct weston_view *ev, struct weston_output *output,
781+ pixman_region32_t *damage) /* in global coordinates */
782+{
783+ struct weston_compositor *ec = ev->surface->compositor;
784+ struct g2d_output_state *go = get_output_state(output);
785+ struct g2d_surface_state *gs = get_surface_state(ev->surface);
786+ /* repaint bounding region in global coordinates: */
787+ pixman_region32_t repaint;
788+ /* non-opaque region in surface coordinates: */
789+ pixman_region32_t surface_blend;
790+ pixman_region32_t *buffer_damage;
791+
792+ pixman_region32_init(&repaint);
793+ pixman_region32_intersect(&repaint,
794+ &ev->transform.boundingbox, damage);
795+ pixman_region32_subtract(&repaint, &repaint, &ev->clip);
796+
797+ if (!pixman_region32_not_empty(&repaint))
798+ goto out;
799+
800+ buffer_damage = &go->buffer_damage[go->current_buffer];
801+ pixman_region32_subtract(buffer_damage, buffer_damage, &repaint);
802+
803+ /* blended region is whole surface minus opaque region: */
804+ pixman_region32_init_rect(&surface_blend, 0, 0,
805+ ev->surface->width, ev->surface->height);
806+ pixman_region32_subtract(&surface_blend, &surface_blend, &ev->surface->opaque);
807+
808+ struct g2d_renderer *gr = get_renderer(ec);
809+ if (pixman_region32_not_empty(&ev->surface->opaque)) {
810+ repaint_region(ev, output, go, &repaint, &ev->surface->opaque);
811+ }
812+
813+ if (pixman_region32_not_empty(&surface_blend)) {
814+ g2d_enable(gr->handle,G2D_BLEND);
815+ if (ev->alpha < 1.0)
816+ {
817+ g2d_enable(gr->handle, G2D_GLOBAL_ALPHA);
818+ gs->g2d_surface.base.global_alpha = ev->alpha * 0xFF;
819+ }
820+ repaint_region(ev, output, go, &repaint, &surface_blend);
821+ g2d_disable(gr->handle, G2D_GLOBAL_ALPHA);
822+ g2d_disable(gr->handle, G2D_BLEND);
823+ }
824+ pixman_region32_fini(&surface_blend);
825+
826+out:
827+ pixman_region32_fini(&repaint);
828+}
829+
830+static void
831+repaint_views(struct weston_output *output, pixman_region32_t *damage)
832+{
833+ struct weston_compositor *compositor = output->compositor;
834+ struct weston_view *view;
835+
836+ wl_list_for_each_reverse(view, &compositor->view_list, link)
837+ if (view->plane == &compositor->primary_plane)
838+ draw_view(view, output, damage);
839+}
840+
841+static void
842+g2d_renderer_repaint_output(struct weston_output *output,
843+ pixman_region32_t *output_damage)
844+{
845+ struct g2d_output_state *go = get_output_state(output);
846+ int i;
847+
848+ use_output(output);
849+ for (i = 0; i < 2; i++)
850+ pixman_region32_union(&go->buffer_damage[i],
851+ &go->buffer_damage[i],
852+ output_damage);
853+
854+ pixman_region32_union(output_damage, output_damage,
855+ &go->buffer_damage[go->current_buffer]);
856+
857+ repaint_views(output, output_damage);
858+
859+ pixman_region32_copy(&output->previous_damage, output_damage);
860+ wl_signal_emit(&output->frame_signal, output);
861+ copy_to_framebuffer(output);
862+ go->current_buffer ^= 1;
863+}
864+
865+static void
866+g2d_renderer_attach_egl(struct weston_surface *es, struct weston_buffer *buffer)
867+{
868+ gcsWL_VIV_BUFFER *vivBuffer = wl_resource_get_user_data(buffer->resource);
869+ struct g2d_surface_state *gs = get_surface_state(es);
870+ buffer->width = vivBuffer->width;
871+ buffer->height = vivBuffer->height;
872+ get_g2dSurface(vivBuffer, &gs->g2d_surface);
873+}
874+
875+static void
876+g2d_renderer_flush_damage(struct weston_surface *surface)
877+{
878+ struct g2d_surface_state *gs = get_surface_state(surface);
879+ struct weston_buffer *buffer = gs->buffer_ref.buffer;
880+ struct weston_view *view;
881+ int texture_used;
882+ pixman_region32_union(&gs->texture_damage,
883+ &gs->texture_damage, &surface->damage);
884+
885+ if (!buffer)
886+ return;
887+
888+ texture_used = 0;
889+ wl_list_for_each(view, &surface->views, surface_link) {
890+ if (view->plane == &surface->compositor->primary_plane) {
891+ texture_used = 1;
892+ break;
893+ }
894+ }
895+ if (!texture_used)
896+ return;
897+
898+ if (!pixman_region32_not_empty(&gs->texture_damage))
899+ goto done;
900+
901+ if(wl_shm_buffer_get(buffer->resource))
902+ {
903+ uint8_t *src = wl_shm_buffer_get_data(buffer->shm_buffer);
904+ uint8_t *dst = gs->shm_buf->buf_vaddr;
905+ int bpp = gs->bpp;
906+ wl_shm_buffer_begin_access(buffer->shm_buffer);
907+ if(gs->shm_buf)
908+ {
909+ int alignedWidth = (buffer->width + 15) & ~15;
910+ if(alignedWidth == buffer->width)
911+ {
912+ int size = wl_shm_buffer_get_stride(buffer->shm_buffer)*buffer->height;
913+ memcpy(dst, src, size);
914+ }
915+ else
916+ {
917+ int i, j;
918+ for (i = 0; i < buffer->height; i++)
919+ {
920+ for (j = 0; j < buffer->width; j++)
921+ {
922+ int dstOff = i * alignedWidth + j;
923+ int srcOff = (i * buffer->width + j);
924+ memcpy(dst + dstOff * bpp, src + srcOff * bpp, bpp);
925+ }
926+ }
927+ }
928+ g2d_cache_op(gs->shm_buf, G2D_CACHE_CLEAN);
929+ }
930+ else
931+ {
932+ weston_log("Error: This shm buffer was not attached\n");
933+ }
934+ wl_shm_buffer_end_access(buffer->shm_buffer);
935+ }
936+ else
937+ {
938+ g2d_renderer_attach_egl(surface, buffer);
939+ }
940+
941+done:
942+ pixman_region32_fini(&gs->texture_damage);
943+ pixman_region32_init(&gs->texture_damage);
944+
945+ weston_buffer_reference(&gs->buffer_ref, NULL);
946+}
947+
948+static void
949+g2d_renderer_attach_shm(struct weston_surface *es, struct weston_buffer *buffer,
950+ struct wl_shm_buffer *shm_buffer)
951+{
952+ struct g2d_surface_state *gs = get_surface_state(es);
953+ int stride = 0;
954+ int buffer_length = 0;
955+ int alloc_new_buff = 1;
956+ int alignedWidth = 0;
957+ enum g2d_format g2dFormat = 0;
958+ buffer->shm_buffer = shm_buffer;
959+ buffer->width = wl_shm_buffer_get_width(shm_buffer);
960+ buffer->height = wl_shm_buffer_get_height(shm_buffer);
961+ alignedWidth = (buffer->width + 15) & ~15;
962+ stride = wl_shm_buffer_get_stride(shm_buffer);
963+ buffer_length = stride * buffer->height;
964+
965+ switch (wl_shm_buffer_get_format(shm_buffer)) {
966+ case WL_SHM_FORMAT_XRGB8888:
967+ g2dFormat = G2D_XRGB8888;
968+ gs->bpp = 4;
969+ break;
970+ case WL_SHM_FORMAT_ARGB8888:
971+ g2dFormat = G2D_ARGB8888;
972+ gs->bpp = 4;
973+ break;
974+ case WL_SHM_FORMAT_RGB565:
975+ g2dFormat = G2D_RGB565;
976+ gs->bpp = 2;
977+ break;
978+ default:
979+ weston_log("warning: unknown shm buffer format: %08x\n",
980+ wl_shm_buffer_get_format(shm_buffer));
981+ return;
982+ }
983+
984+ buffer_length = alignedWidth * buffer->height * gs->bpp;
985+
986+ /* Only allocate a new g2d buff if it is larger than existing one.*/
987+ gs->shm_buf_length = buffer_length;
988+ if(gs->shm_buf && gs->shm_buf->buf_size > buffer_length)
989+ {
990+ alloc_new_buff = 0;
991+ }
992+
993+ if(alloc_new_buff)
994+ {
995+ if(gs->shm_buf)
996+ g2d_free(gs->shm_buf);
997+ gs->shm_buf = g2d_alloc(buffer_length, 1);
998+ gs->g2d_surface.base.planes[0] = gs->shm_buf->buf_paddr;
999+ }
1000+ gs->g2d_surface.base.left = 0;
1001+ gs->g2d_surface.base.top = 0;
1002+ gs->g2d_surface.base.right = buffer->width;
1003+ gs->g2d_surface.base.bottom = buffer->height;
1004+ gs->g2d_surface.base.stride = alignedWidth;
1005+ gs->g2d_surface.base.width = buffer->width;
1006+ gs->g2d_surface.base.height = buffer->height;
1007+ gs->g2d_surface.base.rot = G2D_ROTATION_0;
1008+ gs->g2d_surface.base.clrcolor = 0xFF400000;
1009+ gs->g2d_surface.tiling = G2D_LINEAR;
1010+ gs->g2d_surface.base.format = g2dFormat;
1011+}
1012+
1013+static void
1014+g2d_renderer_attach(struct weston_surface *es, struct weston_buffer *buffer)
1015+{
1016+ struct g2d_surface_state *gs = get_surface_state(es);
1017+ struct wl_shm_buffer *shm_buffer;
1018+ weston_buffer_reference(&gs->buffer_ref, buffer);
1019+
1020+ if(buffer==NULL)
1021+ return;
1022+
1023+ shm_buffer = wl_shm_buffer_get(buffer->resource);
1024+
1025+ if(shm_buffer)
1026+ {
1027+ g2d_renderer_attach_shm(es, buffer, shm_buffer);
1028+ }
1029+ else
1030+ {
1031+ g2d_renderer_attach_egl(es, buffer);
1032+ }
1033+ gs->attached = 1;
1034+}
1035+
1036+static void
1037+surface_state_destroy(struct g2d_surface_state *gs, struct g2d_renderer *gr)
1038+{
1039+ wl_list_remove(&gs->surface_destroy_listener.link);
1040+ wl_list_remove(&gs->renderer_destroy_listener.link);
1041+ if(gs->surface)
1042+ gs->surface->renderer_state = NULL;
1043+
1044+ if(gs->shm_buf)
1045+ {
1046+ g2d_free(gs->shm_buf);
1047+ gs->shm_buf = NULL;
1048+ }
1049+
1050+ weston_buffer_reference(&gs->buffer_ref, NULL);
1051+ free(gs);
1052+}
1053+
1054+static void
1055+surface_state_handle_surface_destroy(struct wl_listener *listener, void *data)
1056+{
1057+ struct g2d_surface_state *gs;
1058+ struct g2d_renderer *gr;
1059+
1060+ gs = container_of(listener, struct g2d_surface_state,
1061+ surface_destroy_listener);
1062+
1063+ gr = get_renderer(gs->surface->compositor);
1064+ surface_state_destroy(gs, gr);
1065+}
1066+
1067+static void
1068+surface_state_handle_renderer_destroy(struct wl_listener *listener, void *data)
1069+{
1070+ struct g2d_surface_state *gs;
1071+ struct g2d_renderer *gr;
1072+
1073+ gr = data;
1074+
1075+ gs = container_of(listener, struct g2d_surface_state,
1076+ renderer_destroy_listener);
1077+
1078+ surface_state_destroy(gs, gr);
1079+}
1080+
1081+
1082+static int
1083+g2d_renderer_create_surface(struct weston_surface *surface)
1084+{
1085+ struct g2d_surface_state *gs;
1086+ struct g2d_renderer *gr = get_renderer(surface->compositor);
1087+
1088+ gs = zalloc(sizeof *gs);
1089+ if (gs == NULL)
1090+ return -1;
1091+
1092+ /* A buffer is never attached to solid color surfaces, yet
1093+ * they still go through texcoord computations. Do not divide
1094+ * by zero there.
1095+ */
1096+ gs->pitch = 1;
1097+
1098+ gs->surface = surface;
1099+
1100+ pixman_region32_init(&gs->texture_damage);
1101+ surface->renderer_state = gs;
1102+
1103+ gs->surface_destroy_listener.notify =
1104+ surface_state_handle_surface_destroy;
1105+ wl_signal_add(&surface->destroy_signal,
1106+ &gs->surface_destroy_listener);
1107+
1108+ gs->renderer_destroy_listener.notify =
1109+ surface_state_handle_renderer_destroy;
1110+ wl_signal_add(&gr->destroy_signal,
1111+ &gs->renderer_destroy_listener);
1112+
1113+ if (surface->buffer_ref.buffer) {
1114+ g2d_renderer_attach(surface, surface->buffer_ref.buffer);
1115+ g2d_renderer_flush_damage(surface);
1116+ }
1117+
1118+ return 0;
1119+}
1120+
1121+static void
1122+g2d_renderer_surface_set_color(struct weston_surface *surface,
1123+ float red, float green, float blue, float alpha)
1124+{
1125+ struct g2d_surface_state *gs = get_surface_state(surface);
1126+
1127+ gs->color[0] = red;
1128+ gs->color[1] = green;
1129+ gs->color[2] = blue;
1130+ gs->color[3] = alpha;
1131+}
1132+
1133+
1134+static void
1135+g2d_renderer_output_destroy(struct weston_output *output)
1136+{
1137+ struct g2d_output_state *go = get_output_state(output);
1138+ gctUINT32 i;
1139+
1140+ for (i = 0; i < 2; i++)
1141+ {
1142+ pixman_region32_fini(&go->buffer_damage[i]);
1143+ }
1144+
1145+ if(go->offscreen_buf)
1146+ {
1147+ g2d_free(go->offscreen_buf);
1148+ go->offscreen_buf = NULL;
1149+ }
1150+
1151+ if(go->fb_fd)
1152+ {
1153+ close(go->fb_fd);
1154+ go->fb_fd = 0;
1155+ }
1156+
1157+ if(go->renderSurf)
1158+ {
1159+ free(go->renderSurf);
1160+ go->renderSurf = NULL;
1161+ }
1162+
1163+ free(go);
1164+}
1165+
1166+static void
1167+g2d_renderer_destroy(struct weston_compositor *ec)
1168+{
1169+ struct g2d_renderer *gr = get_renderer(ec);
1170+
1171+ wl_signal_emit(&gr->destroy_signal, gr);
1172+ wl_global_destroy(gr->viv_global);
1173+ g2d_close(gr->handle);
1174+ free(ec->renderer);
1175+ ec->renderer = NULL;
1176+}
1177+
1178+static int
1179+g2d_renderer_create(struct weston_compositor *ec)
1180+{
1181+ struct g2d_renderer *gr;
1182+ gr = malloc(sizeof *gr);
1183+ if (gr == NULL)
1184+ return -1;
1185+
1186+ gr->base.read_pixels = g2d_renderer_read_pixels;
1187+ gr->base.repaint_output = g2d_renderer_repaint_output;
1188+ gr->base.flush_damage = g2d_renderer_flush_damage;
1189+ gr->base.attach = g2d_renderer_attach;
1190+ gr->base.surface_set_color = g2d_renderer_surface_set_color;
1191+ gr->base.destroy = g2d_renderer_destroy;
1192+
1193+ if(g2d_open(&gr->handle))
1194+ {
1195+ weston_log("g2d_open fail.\n");
1196+ return -1;
1197+ }
1198+ ec->renderer = &gr->base;
1199+ wl_signal_init(&gr->destroy_signal);
1200+ return 0;
1201+}
1202+
1203+static int
1204+calculate_g2d_format(struct fb_var_screeninfo *varinfo, enum g2d_format *g2dFormat)
1205+{
1206+ /* Get the color format. */
1207+ switch (varinfo->green.length)
1208+ {
1209+ case 6:
1210+ *g2dFormat= G2D_RGB565;
1211+ break;
1212+
1213+ case 8:
1214+ if (varinfo->blue.offset == 0)
1215+ {
1216+ *g2dFormat = (varinfo->transp.length == 0) ? G2D_BGRX8888 : G2D_BGRA8888;
1217+ }
1218+ else
1219+ {
1220+ *g2dFormat = (varinfo->transp.length == 0) ? G2D_RGBX8888 : G2D_RGBA8888;
1221+ }
1222+ break;
1223+
1224+ default:
1225+ *g2dFormat = -1;
1226+ break;
1227+ }
1228+ return 0;
1229+}
1230+
1231+static int
1232+get_G2dSurface_from_screeninfo(struct fb_screeninfo *info, struct g2d_surfaceEx* g2dSurface)
1233+{
1234+ if(info && g2dSurface)
1235+ {
1236+ g2dSurface->base.planes[0] = info->physical;
1237+ g2dSurface->base.left = 0;
1238+ g2dSurface->base.top = 0;
1239+ g2dSurface->base.right = info->x_resolution;
1240+ g2dSurface->base.bottom = info->y_resolution;
1241+ g2dSurface->base.stride = info->x_resolution;
1242+ g2dSurface->base.width = info->x_resolution;
1243+ g2dSurface->base.height = info->y_resolution;
1244+ g2dSurface->base.format = info->pixel_format;
1245+ g2dSurface->base.rot = G2D_ROTATION_0;
1246+ g2dSurface->base.clrcolor = 0xFF400000;
1247+ g2dSurface->tiling = G2D_LINEAR;
1248+ return 0;
1249+ }
1250+ return -1;
1251+}
1252+
1253+static int
1254+fb_query_screen_info(struct g2d_output_state *output, int fd,
1255+ struct fb_screeninfo *info)
1256+{
1257+ struct g2d_output_state *go = output;
1258+ struct fb_var_screeninfo *varinfo = &info->varinfo;
1259+ struct fb_fix_screeninfo *fixinfo = &info->fixinfo;
1260+
1261+ /* Probe the device for screen information. */
1262+ if (ioctl(fd, FBIOGET_VSCREENINFO, varinfo) < 0) {
1263+ return -1;
1264+ }
1265+
1266+ if(go->nNumBuffers > 1){
1267+ varinfo->yres_virtual = varinfo->yres * go->nNumBuffers;
1268+ if (ioctl(fd, FBIOPUT_VSCREENINFO, varinfo) < 0)
1269+ return -1;
1270+ }
1271+
1272+ if (ioctl(fd, FBIOGET_FSCREENINFO, fixinfo) < 0 ||
1273+ ioctl(fd, FBIOGET_VSCREENINFO, varinfo) < 0){
1274+ return -1;
1275+ }
1276+ /* Store the pertinent data. */
1277+ info->x_resolution = varinfo->xres;
1278+ info->y_resolution = varinfo->yres;
1279+ info->physical = fixinfo->smem_start;
1280+ info->buffer_length = fixinfo->smem_len;
1281+ calculate_g2d_format(varinfo, &info->pixel_format);
1282+
1283+ if (info->pixel_format < 0) {
1284+ weston_log("Frame buffer uses an unsupported format.\n");
1285+ return -1;
1286+ }
1287+
1288+ return 0;
1289+}
1290+
1291+static int
1292+fb_frame_buffer_open(struct g2d_output_state *output, const char *fb_dev,
1293+ struct fb_screeninfo *screen_info)
1294+{
1295+ /* Open the frame buffer device. */
1296+ output->fb_fd = open(fb_dev, O_RDWR | O_CLOEXEC);
1297+ if (output->fb_fd < 0) {
1298+ weston_log("Failed to open frame buffer device%s \n", fb_dev);
1299+ return -1;
1300+ }
1301+
1302+ /* Grab the screen info. */
1303+ if (fb_query_screen_info(output, output->fb_fd, screen_info) < 0) {
1304+ weston_log("Failed to get frame buffer info \n");
1305+
1306+ close(output->fb_fd);
1307+ return -1;
1308+ }
1309+
1310+ return 0;
1311+}
1312+
1313+static int
1314+g2d_renderer_output_create(struct weston_output *output, struct wl_display *wl_display, const char *device)
1315+
1316+ {
1317+ struct g2d_renderer *gr = get_renderer(output->compositor);
1318+ struct g2d_output_state *go;
1319+ int i = 0;
1320+ int offset = 0;
1321+ char *p = NULL;
1322+ go = zalloc(sizeof *go);
1323+ if (go == NULL)
1324+ return -1;
1325+
1326+ output->renderer_state = go;
1327+ gr->viv_global = gcoOS_WaylandCreateVivGlobal(wl_display);
1328+
1329+ p = getenv("FB_MULTI_BUFFER");
1330+ if (p == gcvNULL)
1331+ {
1332+ go->nNumBuffers = 1;
1333+ }
1334+ else
1335+ {
1336+ go->nNumBuffers = atoi(p);
1337+ if (go->nNumBuffers < 1)
1338+ {
1339+ go->nNumBuffers = 1;
1340+ }
1341+ else if(go->nNumBuffers >= 2)
1342+ {
1343+ go->nNumBuffers = 2;
1344+ go->activebuffer = 1;
1345+ }
1346+ }
1347+ weston_log("FB_MULTI_BUFFER = %d\n", go->nNumBuffers);
1348+
1349+ if(fb_frame_buffer_open(go, device, &go->fb_info) < 0)
1350+ {
1351+ weston_log("Open frame buffer failed.\n");
1352+ return -1;
1353+ }
1354+
1355+ go->renderSurf = zalloc(sizeof(struct g2d_surfaceEx) * go->nNumBuffers);
1356+ offset = go->fb_info.buffer_length/go->nNumBuffers;
1357+ for(i = 0; i < go->nNumBuffers; i++)
1358+ {
1359+ get_G2dSurface_from_screeninfo(&go->fb_info, &go->renderSurf[i]);
1360+ go->renderSurf[i].base.planes[0] = go->fb_info.physical
1361+ + (offset * i);
1362+ g2d_clear(gr->handle, &go->renderSurf[i].base);
1363+ }
1364+
1365+ if(go->nNumBuffers == 1)
1366+ {
1367+ go->offscreenSurface = (go->renderSurf[go->activebuffer]);
1368+ go->offscreen_buf = g2d_alloc(go->fb_info.buffer_length, 0);
1369+ go->offscreenSurface.base.planes[0] = go->offscreen_buf->buf_paddr;
1370+ g2d_clear(gr->handle, &go->offscreenSurface.base);
1371+ }
1372+
1373+ g2d_finish(gr->handle);
1374+ for (i = 0; i < 2; i++)
1375+ pixman_region32_init(&go->buffer_damage[i]);
1376+ return 0;
1377+ }
1378+
1379+ WL_EXPORT struct g2d_renderer_interface g2d_renderer_interface = {
1380+ .create = g2d_renderer_create,
1381+ .output_create = g2d_renderer_output_create,
1382+ .output_destroy = g2d_renderer_output_destroy,
1383+};
1384Index: weston-1.11.1/src/g2d-renderer.h
1385===================================================================
1386--- /dev/null 1970-01-01 00:00:00.000000000 +0000
1387+++ weston-1.11.1/src/g2d-renderer.h 2017-01-14 09:08:38.000000000 -0600
1388@@ -0,0 +1,48 @@
1389+/*
1390+ * Copyright (c) 2015 Freescale Semiconductor, Inc.
1391+ * Copyright © 2013 Vasily Khoruzhick <anarsoul@gmail.com>
1392+ *
1393+ * Permission is hereby granted, free of charge, to any person obtaining
1394+ * a copy of this software and associated documentation files (the
1395+ * "Software"), to deal in the Software without restriction, including
1396+ * without limitation the rights to use, copy, modify, merge, publish,
1397+ * distribute, sublicense, and/or sell copies of the Software, and to
1398+ * permit persons to whom the Software is furnished to do so, subject to
1399+ * the following conditions:
1400+ *
1401+ * The above copyright notice and this permission notice (including the
1402+ * next paragraph) shall be included in all copies or substantial
1403+ * portions of the Software.
1404+ *
1405+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1406+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1407+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1408+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
1409+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
1410+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1411+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1412+ * SOFTWARE.
1413+ */
1414+#ifndef __g2d_renderer_h_
1415+#define __g2d_renderer_h_
1416+
1417+#include "compositor.h"
1418+#ifdef ENABLE_EGL
1419+#include <EGL/egl.h>
1420+#else
1421+#include <HAL/gc_hal_eglplatform.h>
1422+#endif
1423+
1424+
1425+struct g2d_renderer_interface {
1426+
1427+ int (*create)(struct weston_compositor *ec);
1428+
1429+ int (*output_create)(struct weston_output *output,
1430+ struct wl_display *wl_display,
1431+ const char *device);
1432+
1433+ void (*output_destroy)(struct weston_output *output);
1434+};
1435+
1436+#endif
1437Index: weston-1.11.1/src/gal2d-renderer.c
1438===================================================================
1439--- weston-1.11.1.orig/src/gal2d-renderer.c 2017-01-14 08:59:52.753868091 -0600
1440+++ /dev/null 1970-01-01 00:00:00.000000000 +0000
1441@@ -1,1307 +0,0 @@
1442-/*
1443- * Copyright (c) 2015 Freescale Semiconductor, Inc.
1444- * Copyright © 2012 Intel Corporation
1445- * Copyright © 2015 Collabora, Ltd.
1446- *
1447- * Permission is hereby granted, free of charge, to any person obtaining
1448- * a copy of this software and associated documentation files (the
1449- * "Software"), to deal in the Software without restriction, including
1450- * without limitation the rights to use, copy, modify, merge, publish,
1451- * distribute, sublicense, and/or sell copies of the Software, and to
1452- * permit persons to whom the Software is furnished to do so, subject to
1453- * the following conditions:
1454- *
1455- * The above copyright notice and this permission notice (including the
1456- * next paragraph) shall be included in all copies or substantial
1457- * portions of the Software.
1458- *
1459- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1460- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1461- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1462- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
1463- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
1464- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1465- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1466- * SOFTWARE.
1467- */
1468-
1469-#define _GNU_SOURCE
1470-
1471-#include <stdlib.h>
1472-#include <string.h>
1473-#include <ctype.h>
1474-#include <float.h>
1475-#include <assert.h>
1476-#include <pthread.h>
1477-
1478-#include "compositor.h"
1479-#include "gal2d-renderer.h"
1480-#include "vertex-clipping.h"
1481-#include "shared/helpers.h"
1482-#include "HAL/gc_hal.h"
1483-#include "HAL/gc_hal_raster.h"
1484-#include "HAL/gc_hal_eglplatform.h"
1485-
1486-#define galONERROR(x) if(status < 0) printf("Error in function %s\n", __func__);
1487-
1488-struct gal2d_output_state {
1489-
1490- int current_buffer;
1491- pixman_region32_t buffer_damage[2];
1492- NativeDisplayType display;
1493- gcoSURF* renderSurf;
1494- gctUINT32 nNumBuffers;
1495- int activebuffer;
1496- gcoSURF offscreenSurface;
1497- gceSURF_FORMAT format;
1498- pthread_mutex_t workerMutex;
1499- pthread_t workerId;
1500- gctUINT32 exitWorker;
1501- gctSIGNAL signal;
1502- gctSIGNAL busySignal;
1503- gcsHAL_INTERFACE iface;
1504- int directBlit;
1505- gctINT width;
1506- gctINT height;
1507-};
1508-
1509-struct gal2d_surface_state {
1510- float color[4];
1511- struct weston_buffer_reference buffer_ref;
1512- int pitch; /* in pixels */
1513- pixman_region32_t texture_damage;
1514- gcoSURF gco_Surface;
1515-
1516- struct weston_surface *surface;
1517- struct wl_listener surface_destroy_listener;
1518- struct wl_listener renderer_destroy_listener;
1519-};
1520-
1521-struct gal2d_renderer {
1522- struct weston_renderer base;
1523- struct wl_signal destroy_signal;
1524- gcoOS gcos;
1525- gcoHAL gcoHal;
1526- gco2D gcoEngine2d;
1527- gctPOINTER localInfo;
1528-};
1529-
1530-static int
1531-gal2d_renderer_create_surface(struct weston_surface *surface);
1532-
1533-static inline struct gal2d_surface_state *
1534-get_surface_state(struct weston_surface *surface)
1535-{
1536- if (!surface->renderer_state)
1537- gal2d_renderer_create_surface(surface);
1538- return (struct gal2d_surface_state *)surface->renderer_state;
1539-}
1540-
1541-static inline struct gal2d_renderer *
1542-get_renderer(struct weston_compositor *ec)
1543-{
1544- return (struct gal2d_renderer *)ec->renderer;
1545-}
1546-
1547-
1548-
1549-#define max(a, b) (((a) > (b)) ? (a) : (b))
1550-#define min(a, b) (((a) > (b)) ? (b) : (a))
1551-/*
1552- * Compute the boundary vertices of the intersection of the global coordinate
1553- * aligned rectangle 'rect', and an arbitrary quadrilateral produced from
1554- * 'surf_rect' when transformed from surface coordinates into global coordinates.
1555- * The vertices are written to 'ex' and 'ey', and the return value is the
1556- * number of vertices. Vertices are produced in clockwise winding order.
1557- * Guarantees to produce either zero vertices, or 3-8 vertices with non-zero
1558- * polygon area.
1559- */
1560-static int
1561-calculate_edges(struct weston_view *ev, pixman_box32_t *rect,
1562- pixman_box32_t *surf_rect, float *ex, float *ey)
1563-{
1564-
1565- struct clip_context ctx;
1566- int i, n;
1567- float min_x, max_x, min_y, max_y;
1568- struct polygon8 surf = {
1569- { surf_rect->x1, surf_rect->x2, surf_rect->x2, surf_rect->x1 },
1570- { surf_rect->y1, surf_rect->y1, surf_rect->y2, surf_rect->y2 },
1571- 4
1572- };
1573-
1574- ctx.clip.x1 = rect->x1;
1575- ctx.clip.y1 = rect->y1;
1576- ctx.clip.x2 = rect->x2;
1577- ctx.clip.y2 = rect->y2;
1578-
1579- /* transform surface to screen space: */
1580- for (i = 0; i < surf.n; i++)
1581- weston_view_to_global_float(ev, surf.x[i], surf.y[i],
1582- &surf.x[i], &surf.y[i]);
1583-
1584- /* find bounding box: */
1585- min_x = max_x = surf.x[0];
1586- min_y = max_y = surf.y[0];
1587-
1588- for (i = 1; i < surf.n; i++) {
1589- min_x = min(min_x, surf.x[i]);
1590- max_x = max(max_x, surf.x[i]);
1591- min_y = min(min_y, surf.y[i]);
1592- max_y = max(max_y, surf.y[i]);
1593- }
1594-
1595- /* First, simple bounding box check to discard early transformed
1596- * surface rects that do not intersect with the clip region:
1597- */
1598- if ((min_x >= ctx.clip.x2) || (max_x <= ctx.clip.x1) ||
1599- (min_y >= ctx.clip.y2) || (max_y <= ctx.clip.y1))
1600- return 0;
1601-
1602- /* Simple case, bounding box edges are parallel to surface edges,
1603- * there will be only four edges. We just need to clip the surface
1604- * vertices to the clip rect bounds:
1605- */
1606- if (!ev->transform.enabled)
1607- return clip_simple(&ctx, &surf, ex, ey);
1608-
1609- /* Transformed case: use a general polygon clipping algorithm to
1610- * clip the surface rectangle with each side of 'rect'.
1611- * The algorithm is Sutherland-Hodgman, as explained in
1612- * http://www.codeguru.com/cpp/misc/misc/graphics/article.php/c8965/Polygon-Clipping.htm
1613- * but without looking at any of that code.
1614- */
1615- n = clip_transformed(&ctx, &surf, ex, ey);
1616-
1617- if (n < 3)
1618- return 0;
1619-
1620- return n;
1621-}
1622-
1623-
1624-static inline struct gal2d_output_state *
1625-get_output_state(struct weston_output *output)
1626-{
1627- return (struct gal2d_output_state *)output->renderer_state;
1628-}
1629-
1630-static gceSTATUS
1631-gal2d_getSurfaceFormat(halDISPLAY_INFO info, gceSURF_FORMAT * Format)
1632-{
1633- /* Get the color format. */
1634- switch (info.greenLength)
1635- {
1636- case 4:
1637- if (info.blueOffset == 0)
1638- {
1639- *Format = (info.alphaLength == 0) ? gcvSURF_X4R4G4B4 : gcvSURF_A4R4G4B4;
1640- }
1641- else
1642- {
1643- *Format = (info.alphaLength == 0) ? gcvSURF_X4B4G4R4 : gcvSURF_A4B4G4R4;
1644- }
1645- break;
1646-
1647- case 5:
1648- if (info.blueOffset == 0)
1649- {
1650- *Format = (info.alphaLength == 0) ? gcvSURF_X1R5G5B5 : gcvSURF_A1R5G5B5;
1651- }
1652- else
1653- {
1654- *Format = (info.alphaLength == 0) ? gcvSURF_X1B5G5R5 : gcvSURF_A1B5G5R5;
1655- }
1656- break;
1657-
1658- case 6:
1659- *Format = gcvSURF_R5G6B5;
1660- break;
1661-
1662- case 8:
1663- if (info.blueOffset == 0)
1664- {
1665- *Format = (info.alphaLength == 0) ? gcvSURF_X8R8G8B8 : gcvSURF_A8R8G8B8;
1666- }
1667- else
1668- {
1669- *Format = (info.alphaLength == 0) ? gcvSURF_X8B8G8R8 : gcvSURF_A8B8G8R8;
1670- }
1671- break;
1672-
1673- default:
1674- /* Unsupported color depth. */
1675- return gcvSTATUS_INVALID_ARGUMENT;
1676- }
1677- /* Success. */
1678- return gcvSTATUS_OK;
1679-}
1680-
1681-static gceSTATUS galIsYUVFormat(IN gceSURF_FORMAT Format)
1682-{
1683- switch (Format)
1684- {
1685- case gcvSURF_YUY2:
1686- case gcvSURF_UYVY:
1687- case gcvSURF_I420:
1688- case gcvSURF_YV12:
1689- case gcvSURF_NV16:
1690- case gcvSURF_NV12:
1691- case gcvSURF_NV61:
1692- case gcvSURF_NV21:
1693-
1694- return gcvSTATUS_TRUE;
1695-
1696- default:
1697- return gcvSTATUS_FALSE;
1698- }
1699-}
1700-
1701-static gceSTATUS galQueryUVStride(
1702- IN gceSURF_FORMAT Format,
1703- IN gctUINT32 yStride,
1704- OUT gctUINT32_PTR uStride,
1705- OUT gctUINT32_PTR vStride
1706- )
1707-{
1708- switch (Format)
1709- {
1710- case gcvSURF_YUY2:
1711- case gcvSURF_UYVY:
1712- *uStride = *vStride = 0;
1713- break;
1714-
1715- case gcvSURF_I420:
1716- case gcvSURF_YV12:
1717- *uStride = *vStride = yStride / 2;
1718- break;
1719-
1720- case gcvSURF_NV16:
1721- case gcvSURF_NV12:
1722- case gcvSURF_NV61:
1723- case gcvSURF_NV21:
1724-
1725- *uStride = yStride;
1726- *vStride = 0;
1727- break;
1728-
1729- default:
1730- return gcvSTATUS_NOT_SUPPORTED;
1731- }
1732-
1733- return gcvSTATUS_OK;
1734-}
1735-
1736-static int
1737-make_current(struct gal2d_renderer *gr, gcoSURF surface)
1738-{
1739- gceSTATUS status = gcvSTATUS_OK;
1740- gctUINT width = 0;
1741- gctUINT height = 0;
1742- gctINT stride = 0;
1743- gctUINT32 physical[3];
1744- gctPOINTER va =0;
1745- gceSURF_FORMAT format;
1746-
1747- if(!surface)
1748- goto OnError;
1749-
1750-
1751- gcmONERROR(gcoSURF_GetAlignedSize(surface, &width, &height, &stride));
1752- gcmONERROR(gcoSURF_GetFormat(surface, gcvNULL, &format));
1753- gcmONERROR(gcoSURF_Lock(surface, &physical[0], (gctPOINTER *)&va));
1754- gco2D_SetGenericTarget(gr->gcoEngine2d,
1755- &physical[0], 1,
1756- &stride, 1,
1757- gcvLINEAR, format,
1758- gcvSURF_0_DEGREE, width, height);
1759-
1760- gcmONERROR(gcoSURF_Unlock(surface, (gctPOINTER *)&va));
1761-OnError:
1762- galONERROR(status);
1763- return status;
1764-}
1765-
1766-static gceSTATUS
1767-gal2d_clear(struct weston_output *base)
1768-{
1769- struct gal2d_renderer *gr = get_renderer(base->compositor);
1770- struct gal2d_output_state *go = get_output_state(base);
1771- gceSTATUS status = gcvSTATUS_OK;
1772-
1773- gctINT stride = 0;
1774- gctUINT width = 0, height = 0;
1775- gcsRECT dstRect = {0};
1776- gcmONERROR(gcoSURF_GetAlignedSize(go->renderSurf[go->activebuffer],
1777- &width, &height, &stride));
1778- dstRect.right = width;
1779- dstRect.bottom = height;
1780- gcmONERROR(gco2D_SetSource(gr->gcoEngine2d, &dstRect));
1781- gcmONERROR(gco2D_SetClipping(gr->gcoEngine2d, &dstRect));
1782- gcmONERROR(gco2D_Clear(gr->gcoEngine2d, 1, &dstRect, 0xff0000ff, 0xCC, 0xCC, go->format));
1783- gcmONERROR(gcoHAL_Commit(gr->gcoHal, gcvTRUE));
1784-
1785-OnError:
1786- galONERROR(status);
1787-
1788- return status;
1789-}
1790-
1791-static gcoSURF getSurfaceFromShm(struct weston_surface *es, struct weston_buffer *buffer)
1792-{
1793- struct gal2d_renderer *gr = get_renderer(es->compositor);
1794-
1795- gcoSURF surface = 0;
1796- gceSURF_FORMAT format;
1797- gcePOOL pool = gcvPOOL_DEFAULT;
1798-
1799- if (wl_shm_buffer_get_format(buffer->shm_buffer) == WL_SHM_FORMAT_XRGB8888)
1800- format = gcvSURF_X8R8G8B8;
1801- else
1802- format = gcvSURF_A8R8G8B8;
1803-
1804- if(buffer->width == ((buffer->width + 0x7) & ~0x7))
1805- {
1806- pool = gcvPOOL_USER;
1807- }
1808-
1809- gcmVERIFY_OK(gcoSURF_Construct(gr->gcoHal,
1810- (gctUINT) buffer->width,
1811- (gctUINT) buffer->height,
1812- 1, gcvSURF_BITMAP,
1813- format, pool, &surface));
1814-
1815- if(pool == gcvPOOL_USER)
1816- {
1817- gcmVERIFY_OK(gcoSURF_MapUserSurface(surface, 1,
1818- (gctPOINTER)wl_shm_buffer_get_data(buffer->shm_buffer), gcvINVALID_ADDRESS));
1819- }
1820-
1821- return surface;
1822-}
1823-
1824-static int
1825-gal2dBindBuffer(struct weston_surface* es)
1826-{
1827- struct gal2d_surface_state *gs = get_surface_state(es);
1828- gceSTATUS status = gcvSTATUS_OK;
1829- gcoSURF surface = gs->gco_Surface;
1830- struct weston_buffer *buffer = gs->buffer_ref.buffer;
1831- gcePOOL pool = gcvPOOL_DEFAULT;
1832-
1833- gcmVERIFY_OK(gcoSURF_QueryVidMemNode(surface, gcvNULL,
1834- &pool, gcvNULL));
1835-
1836- if(pool != gcvPOOL_USER)
1837- {
1838- gctUINT alignedWidth;
1839- gctPOINTER logical = (gctPOINTER)wl_shm_buffer_get_data(buffer->shm_buffer);
1840- gctPOINTER va =0;
1841-
1842-
1843- gcmVERIFY_OK(gcoSURF_GetAlignedSize(surface, &alignedWidth, gcvNULL, gcvNULL));
1844- gcmVERIFY_OK(gcoSURF_Lock(surface, gcvNULL, (gctPOINTER *)&va));
1845-
1846- if(alignedWidth == (unsigned int)buffer->width)
1847- {
1848- int size = wl_shm_buffer_get_stride(buffer->shm_buffer)*buffer->height;
1849- memcpy(va, logical, size);
1850- }
1851- else
1852- {
1853- int i, j;
1854- for (i = 0; i < buffer->height; i++)
1855- {
1856- for (j = 0; j < buffer->width; j++)
1857- {
1858- gctUINT dstOff = i * alignedWidth + j;
1859- gctUINT srcOff = (i * buffer->width + j);
1860-
1861- memcpy(va + dstOff * 4, logical + srcOff * 4, 4);
1862- }
1863- }
1864- }
1865- gcmVERIFY_OK(gcoSURF_Unlock(surface, (gctPOINTER)va));
1866- }
1867-
1868- return status;
1869-}
1870-
1871-static void
1872-gal2d_flip_surface(struct weston_output *output)
1873-{
1874- struct gal2d_output_state *go = get_output_state(output);
1875-
1876- if(go->nNumBuffers > 1)
1877- {
1878- gctUINT Offset;
1879- gctINT X;
1880- gctINT Y;
1881-
1882- gcmVERIFY_OK(gcoOS_GetDisplayBackbuffer(go->display, gcvNULL,
1883- gcvNULL, gcvNULL, &Offset, &X, &Y));
1884-
1885- gcmVERIFY_OK(gcoOS_SetDisplayVirtual(go->display, gcvNULL,
1886- Offset, X, Y));
1887- }
1888-}
1889-
1890-static void *gal2d_output_worker(void *arg)
1891-{
1892- struct weston_output *output = (struct weston_output *)arg;
1893- struct gal2d_output_state *go = get_output_state(output);
1894-
1895- while(1)
1896- {
1897- if(gcoOS_WaitSignal(gcvNULL, go->signal, gcvINFINITE) == gcvSTATUS_OK )
1898- {
1899- gal2d_flip_surface(output);
1900- gcoOS_Signal(gcvNULL,go->busySignal, gcvTRUE);
1901- }
1902- pthread_mutex_lock(&go->workerMutex);
1903- if(go->exitWorker == 1)
1904- {
1905- pthread_mutex_unlock(&go->workerMutex);
1906- break;
1907- }
1908- pthread_mutex_unlock(&go->workerMutex);
1909- }
1910- return 0;
1911-}
1912-
1913-static int
1914-update_surface(struct weston_output *output)
1915-{
1916- struct gal2d_renderer *gr = get_renderer(output->compositor);
1917- struct gal2d_output_state *go = get_output_state(output);
1918- gceSTATUS status = gcvSTATUS_OK;
1919-
1920- if(go->nNumBuffers == 1)
1921- {
1922- if(!go->directBlit && go->offscreenSurface)
1923- {
1924- make_current(gr, go->renderSurf[go->activebuffer]);
1925-
1926- gctUINT srcWidth = 0;
1927- gctUINT srcHeight = 0;
1928- gceSURF_FORMAT srcFormat;;
1929- gcsRECT dstRect = {0};
1930- gcoSURF srcSurface = go->offscreenSurface;
1931- gctUINT32 srcPhyAddr[3];
1932- gctUINT32 srcStride[3];
1933-
1934- gctPOINTER va =0;
1935-
1936- gcmONERROR(gcoSURF_GetAlignedSize(srcSurface, &srcWidth, &srcHeight, (gctINT *)&srcStride[0]));
1937- gcmONERROR(gcoSURF_GetFormat(srcSurface, gcvNULL, &srcFormat));
1938-
1939- gcmONERROR(gcoSURF_Lock(srcSurface, srcPhyAddr, (gctPOINTER *)&va));
1940- gcmONERROR(gco2D_SetCurrentSourceIndex(gr->gcoEngine2d, 0U));
1941-
1942- gco2D_SetGenericSource(gr->gcoEngine2d, srcPhyAddr, 1,
1943- srcStride, 1,
1944- gcvLINEAR, srcFormat, gcvSURF_0_DEGREE,
1945- srcWidth, srcHeight);
1946-
1947- dstRect.left = 0;
1948- dstRect.top = 0;
1949- dstRect.right = srcWidth;
1950- dstRect.bottom = srcHeight;
1951-
1952- gcmONERROR(gco2D_SetSource(gr->gcoEngine2d, &dstRect));
1953- gcmONERROR(gco2D_SetClipping(gr->gcoEngine2d, &dstRect));
1954- gcmONERROR(gco2D_Blit(gr->gcoEngine2d, 1, &dstRect, 0xCC, 0xCC, go->format));
1955- gcmONERROR(gcoSURF_Unlock(srcSurface, (gctPOINTER *)&va));
1956- }
1957- gcmONERROR(gcoHAL_Commit(gr->gcoHal, gcvFALSE));
1958- }
1959- else if(go->nNumBuffers > 1)
1960- {
1961- gcoHAL_ScheduleEvent(gr->gcoHal, &go->iface);
1962- gcmVERIFY_OK(gcoHAL_Commit(gr->gcoHal, gcvFALSE));
1963- }
1964-OnError:
1965- galONERROR(status);
1966- return status;
1967- }
1968-
1969-static int
1970-is_view_visible(struct weston_view *view)
1971-{
1972- /* Return false, if surface is guaranteed to be totally obscured. */
1973- int ret;
1974- pixman_region32_t unocc;
1975-
1976- pixman_region32_init(&unocc);
1977- pixman_region32_subtract(&unocc, &view->transform.boundingbox,
1978- &view->clip);
1979- ret = pixman_region32_not_empty(&unocc);
1980- pixman_region32_fini(&unocc);
1981-
1982- return ret;
1983-}
1984-
1985-static int
1986-use_output(struct weston_output *output)
1987-{
1988- struct weston_compositor *compositor = output->compositor;
1989- struct weston_view *view;
1990- struct gal2d_output_state *go = get_output_state(output);
1991- struct gal2d_renderer *gr = get_renderer(output->compositor);
1992- gceSTATUS status = gcvSTATUS_OK;
1993-
1994- gcoSURF surface;
1995- int visibleViews=0;
1996- int fullscreenViews=0;
1997-
1998- surface = go->renderSurf[go->activebuffer];
1999- if(go->nNumBuffers == 1)
2000- {
2001- wl_list_for_each_reverse(view, &compositor->view_list, link)
2002- if (view->plane == &compositor->primary_plane && is_view_visible(view))
2003- {
2004- visibleViews++;
2005- if(view->surface->width == go->width && view->surface->height == go->height)
2006- {
2007- pixman_box32_t *bb_rects;
2008- int nbb=0;
2009- bb_rects = pixman_region32_rectangles(&view->transform.boundingbox, &nbb);
2010- if(nbb == 1)
2011- if(bb_rects[0].x1 == 0 && bb_rects[0].y1 ==0)
2012- fullscreenViews++;
2013- }
2014- }
2015-
2016- go->directBlit = ((visibleViews == 1) || (fullscreenViews > 1));
2017-
2018- if(!go->directBlit)
2019- {
2020- surface = go->offscreenSurface;
2021- }
2022- }
2023- make_current(gr, surface);
2024- return status;
2025-}
2026-
2027-static int
2028-gal2d_renderer_read_pixels(struct weston_output *output,
2029- pixman_format_code_t format, void *pixels,
2030- uint32_t x, uint32_t y,
2031- uint32_t width, uint32_t height)
2032-{
2033- return 0;
2034-}
2035-
2036-static int gal2d_int_from_double(double d)
2037-{
2038- return wl_fixed_to_int(wl_fixed_from_double(d));
2039-}
2040-
2041-static void
2042-repaint_region(struct weston_view *ev, struct weston_output *output, struct gal2d_output_state *go, pixman_region32_t *region,
2043- pixman_region32_t *surf_region){
2044-
2045- struct gal2d_renderer *gr = get_renderer(ev->surface->compositor);
2046- struct gal2d_surface_state *gs = get_surface_state(ev->surface);
2047-
2048- pixman_box32_t *rects, *surf_rects, *bb_rects;
2049- int i, j, nrects, nsurf, nbb=0;
2050- gceSTATUS status = gcvSTATUS_OK;
2051- gcoSURF srcSurface = gs->gco_Surface;
2052- gcsRECT srcRect = {0};
2053- gcsRECT dstrect = {0};
2054- gctUINT32 horFactor, verFactor;
2055- int useFilterBlit = 0;
2056- gctUINT srcWidth = 0;
2057- gctUINT srcHeight = 0;
2058- gctUINT32 srcStride[3];
2059- gceSURF_FORMAT srcFormat;
2060- gctUINT32 srcPhyAddr[3];
2061- gctUINT32 dstPhyAddr[3];
2062- gctUINT dstWidth = 0;
2063- gctUINT dstHeight = 0;
2064- gctUINT32 dstStrides[3];
2065- gcoSURF dstsurface;
2066- int geoWidth = ev->surface->width;
2067- int geoheight = ev->surface->height;
2068- gceTILING tiling;
2069-
2070- bb_rects = pixman_region32_rectangles(&ev->transform.boundingbox, &nbb);
2071-
2072- if(!srcSurface || nbb <= 0)
2073- goto OnError;
2074- rects = pixman_region32_rectangles(region, &nrects);
2075- surf_rects = pixman_region32_rectangles(surf_region, &nsurf);
2076-
2077- gcmVERIFY_OK(gcoSURF_GetAlignedSize(srcSurface, &srcWidth, &srcHeight, (gctINT *)&srcStride[0]));
2078-
2079- gcmVERIFY_OK(gcoSURF_GetFormat(srcSurface, gcvNULL, &srcFormat));
2080-
2081- if(galIsYUVFormat(srcFormat) == gcvSTATUS_TRUE)
2082- {
2083- useFilterBlit = 1;
2084- }
2085-
2086- gcmVERIFY_OK(gcoSURF_Lock(srcSurface, &srcPhyAddr[0], gcvNULL));
2087-
2088- gcmVERIFY_OK(gcoSURF_Unlock(srcSurface, gcvNULL));
2089-
2090- srcRect.left = ev->geometry.x < 0.0 ? gal2d_int_from_double(fabsf(ev->geometry.x)) : 0;
2091- srcRect.top = 0; /*es->geometry.y < 0.0 ? gal2d_int_from_double(fabsf(es->geometry.y)) : 0;*/
2092- srcRect.right = ev->surface->width;
2093- srcRect.bottom = ev->surface->height;
2094-
2095- dstsurface = go->nNumBuffers > 1 ?
2096- go->renderSurf[go->activebuffer] :
2097- go->offscreenSurface;
2098- gcmVERIFY_OK(gcoSURF_GetAlignedSize(dstsurface, &dstWidth, &dstHeight, (gctINT *)&dstStrides));
2099- gcmVERIFY_OK(gcoSURF_Lock(dstsurface, &dstPhyAddr[0], gcvNULL));
2100- gcmVERIFY_OK(gcoSURF_Unlock(dstsurface, gcvNULL));
2101-
2102- if(galIsYUVFormat(srcFormat) == gcvSTATUS_TRUE)
2103- {
2104- useFilterBlit = 1;
2105- }
2106- else
2107- {
2108- gcoSURF_GetTiling(srcSurface, &tiling);
2109- if (gcoHAL_IsFeatureAvailable(gr->gcoHal, gcvFEATURE_2D_TILING) != gcvTRUE && (tiling > gcvLINEAR))
2110- {
2111- weston_log("Tiling not supported \n");
2112- status = gcvSTATUS_NOT_SUPPORTED;
2113- gcmONERROR(status);
2114- }
2115- gco2D_SetGenericSource(gr->gcoEngine2d, srcPhyAddr, 1,
2116- srcStride, 1,
2117- tiling, srcFormat, gcvSURF_0_DEGREE,
2118- srcWidth, srcHeight);
2119- gcmVERIFY_OK(gco2D_SetSource(gr->gcoEngine2d, &srcRect));
2120- /* Setup mirror. */
2121- gcmONERROR(gco2D_SetBitBlitMirror(gr->gcoEngine2d, gcvFALSE, gcvFALSE));
2122- gcmONERROR(gco2D_SetROP(gr->gcoEngine2d, 0xCC, 0xCC));
2123- }
2124-
2125- for (i = 0; i < nrects; i++)
2126- {
2127- pixman_box32_t *rect = &rects[i];
2128- gctFLOAT min_x, max_x, min_y, max_y;
2129-
2130- dstrect.left = (bb_rects[0].x1 < 0) ? rect->x1 : bb_rects[0].x1;
2131- dstrect.top = (bb_rects[0].y1 < 0) ? rect->y1 : bb_rects[0].y1;
2132- dstrect.right = bb_rects[0].x2;
2133- dstrect.bottom = bb_rects[0].y2;
2134-
2135- if(dstrect.right < 0 || dstrect.bottom < 0 || dstrect.left > dstWidth || dstrect.top > dstHeight)
2136- {
2137- break;
2138- }
2139-
2140- for (j = 0; j < nsurf; j++)
2141- {
2142- pixman_box32_t *surf_rect = &surf_rects[j];
2143- gctFLOAT ex[8], ey[8]; /* edge points in screen space */
2144- int n;
2145- gcsRECT clipRect = {0};
2146- int m=0;
2147- n = calculate_edges(ev, rect, surf_rect, ex, ey);
2148- if (n < 3)
2149- continue;
2150-
2151- min_x = max_x = ex[0];
2152- min_y = max_y = ey[0];
2153- for (m = 1; m < n; m++)
2154- {
2155- min_x = min(min_x, ex[m]);
2156- max_x = max(max_x, ex[m]);
2157- min_y = min(min_y, ey[m]);
2158- max_y = max(max_y, ey[m]);
2159- }
2160-
2161- clipRect.left = gal2d_int_from_double(min_x);
2162- clipRect.top = gal2d_int_from_double(min_y);
2163- clipRect.right = gal2d_int_from_double(max_x);
2164- clipRect.bottom = gal2d_int_from_double(max_y);
2165-
2166- if(output->x > 0)
2167- {
2168- dstrect.left = dstrect.left - output->x;
2169- dstrect.right = dstrect.right - output->x;
2170- clipRect.left = clipRect.left - output->x;
2171- clipRect.right = clipRect.right - output->x;
2172- }
2173-
2174- dstrect.left = (dstrect.left < 0) ? 0 : dstrect.left;
2175-
2176- status = gco2D_SetClipping(gr->gcoEngine2d, &clipRect);
2177- if(status < 0)
2178- {
2179- weston_log("Error in gco2D_SetClipping %s\n", __func__);
2180- goto OnError;
2181- }
2182-
2183- if(useFilterBlit)
2184- {
2185- gctINT srcStrideNum;
2186- gctINT srcAddressNum;
2187- gcmVERIFY_OK(galQueryUVStride(srcFormat, srcStride[0],
2188- &srcStride[1], &srcStride[2]));
2189-
2190- switch (srcFormat)
2191- {
2192- case gcvSURF_YUY2:
2193- case gcvSURF_UYVY:
2194- srcStrideNum = srcAddressNum = 1;
2195- break;
2196-
2197- case gcvSURF_I420:
2198- case gcvSURF_YV12:
2199- srcStrideNum = srcAddressNum = 3;
2200- break;
2201-
2202- case gcvSURF_NV16:
2203- case gcvSURF_NV12:
2204- case gcvSURF_NV61:
2205- case gcvSURF_NV21:
2206- srcStrideNum = srcAddressNum = 2;
2207- break;
2208-
2209- default:
2210- gcmONERROR(gcvSTATUS_NOT_SUPPORTED);
2211- }
2212- gco2D_FilterBlitEx2(gr->gcoEngine2d,
2213- srcPhyAddr, srcAddressNum,
2214- srcStride, srcStrideNum,
2215- gcvLINEAR, srcFormat, gcvSURF_0_DEGREE,
2216- geoWidth, geoheight, &srcRect,
2217- dstPhyAddr, 1,
2218- dstStrides, 1,
2219- gcvLINEAR, go->format, gcvSURF_0_DEGREE,
2220- dstWidth, dstHeight,
2221- &dstrect, gcvNULL);
2222- }
2223- else
2224- {
2225- gcmVERIFY_OK(gco2D_CalcStretchFactor(gr->gcoEngine2d, srcRect.right - srcRect.left,
2226- dstrect.right - dstrect.left, &horFactor));
2227-
2228- gcmONERROR(gco2D_CalcStretchFactor(gr->gcoEngine2d, srcRect.bottom - srcRect.top,
2229- dstrect.bottom - dstrect.top, &verFactor));
2230-
2231- if(verFactor == 65536 && horFactor == 65536)
2232- {
2233- gcmVERIFY_OK(gco2D_Blit(gr->gcoEngine2d, 1, &dstrect,
2234- 0xCC, 0xCC, go->format));
2235- }
2236- else
2237- {
2238- dstrect.right = dstrect.right < dstWidth ? dstrect.right : dstWidth;
2239- dstrect.bottom = dstrect.bottom < dstHeight ? dstrect.bottom : dstHeight;
2240- srcRect.right = srcRect.right < dstWidth ? srcRect.right : dstWidth;
2241- srcRect.bottom = srcRect.bottom < dstHeight ? srcRect.bottom : dstHeight;
2242-
2243- gcmVERIFY_OK(gco2D_CalcStretchFactor(gr->gcoEngine2d, srcRect.right - srcRect.left,
2244- dstrect.right - dstrect.left, &horFactor));
2245-
2246- gcmONERROR(gco2D_CalcStretchFactor(gr->gcoEngine2d, srcRect.bottom - srcRect.top,
2247- dstrect.bottom - dstrect.top, &verFactor));
2248- /* Program the stretch factors. */
2249- gcmVERIFY_OK(gco2D_SetStretchFactors(gr->gcoEngine2d, horFactor, verFactor));
2250-
2251- gcmVERIFY_OK(gco2D_StretchBlit(gr->gcoEngine2d, 1, &dstrect,
2252- 0xCC, 0xCC, go->format));
2253- }
2254- }
2255-
2256- if(status < 0)
2257- {
2258- printf("cr l=%d r=%d t=%d b=%d w=%d h=%d\n",
2259- clipRect.left, clipRect.right, clipRect.top ,clipRect.bottom,
2260- clipRect.right - clipRect.left, clipRect.bottom -clipRect.top);
2261- printf("dr l=%d r=%d t=%d b=%d w=%d h=%d\n",
2262- dstrect.left, dstrect.right, dstrect.top ,dstrect.bottom,
2263- dstrect.right - dstrect.left, dstrect.bottom -dstrect.top);
2264- printf("horFactor=%d, verFactor=%d\n",horFactor, verFactor);
2265-
2266- goto OnError;
2267- }
2268- }
2269- }
2270-
2271-OnError:
2272- galONERROR(status);
2273-}
2274-
2275-static void
2276-draw_view(struct weston_view *ev, struct weston_output *output,
2277- pixman_region32_t *damage) /* in global coordinates */
2278-{
2279- struct weston_compositor *ec = ev->surface->compositor;
2280- struct gal2d_output_state *go = get_output_state(output);
2281- /* repaint bounding region in global coordinates: */
2282- pixman_region32_t repaint;
2283- /* non-opaque region in surface coordinates: */
2284- pixman_region32_t surface_blend;
2285- pixman_region32_t *buffer_damage;
2286-
2287- pixman_region32_init(&repaint);
2288- pixman_region32_intersect(&repaint,
2289- &ev->transform.boundingbox, damage);
2290- pixman_region32_subtract(&repaint, &repaint, &ev->clip);
2291-
2292- if (!pixman_region32_not_empty(&repaint))
2293- goto out;
2294-
2295- buffer_damage = &go->buffer_damage[go->current_buffer];
2296- pixman_region32_subtract(buffer_damage, buffer_damage, &repaint);
2297-
2298- /* blended region is whole surface minus opaque region: */
2299- pixman_region32_init_rect(&surface_blend, 0, 0,
2300- ev->surface->width, ev->surface->height);
2301- pixman_region32_subtract(&surface_blend, &surface_blend, &ev->surface->opaque);
2302-
2303- struct gal2d_renderer *gr = get_renderer(ec);
2304- gco2D_SetCurrentSourceIndex(gr->gcoEngine2d, 0U);
2305-
2306- if (pixman_region32_not_empty(&ev->surface->opaque)) {
2307- repaint_region(ev, output, go, &repaint, &ev->surface->opaque);
2308- }
2309-
2310- if (pixman_region32_not_empty(&surface_blend)) {
2311- gco2D_EnableAlphaBlend(gr->gcoEngine2d,
2312- ev->alpha * 0xFF, ev->alpha * 0xFF,
2313- gcvSURF_PIXEL_ALPHA_STRAIGHT, gcvSURF_PIXEL_ALPHA_STRAIGHT,
2314- gcvSURF_GLOBAL_ALPHA_SCALE, gcvSURF_GLOBAL_ALPHA_SCALE,
2315- gcvSURF_BLEND_STRAIGHT, gcvSURF_BLEND_INVERSED,
2316- gcvSURF_COLOR_STRAIGHT, gcvSURF_COLOR_STRAIGHT);
2317-
2318- repaint_region(ev, output, go, &repaint, &surface_blend);
2319- }
2320-
2321- gco2D_DisableAlphaBlend(gr->gcoEngine2d);
2322- pixman_region32_fini(&surface_blend);
2323-
2324-out:
2325- pixman_region32_fini(&repaint);
2326-
2327-}
2328-
2329-static void
2330-repaint_views(struct weston_output *output, pixman_region32_t *damage)
2331-{
2332- struct weston_compositor *compositor = output->compositor;
2333- struct weston_view *view;
2334- struct gal2d_output_state *go = get_output_state(output);
2335-
2336- if(go->nNumBuffers > 1)
2337- {
2338- /*500ms is more than enough to process a frame */
2339- gcoOS_WaitSignal(gcvNULL, go->busySignal, 500);
2340- }
2341- go->activebuffer = (go->activebuffer+1) % go->nNumBuffers;
2342-
2343- wl_list_for_each_reverse(view, &compositor->view_list, link)
2344- if (view->plane == &compositor->primary_plane)
2345- draw_view(view, output, damage);
2346-}
2347-
2348-static void
2349-gal2d_renderer_repaint_output(struct weston_output *output,
2350- pixman_region32_t *output_damage)
2351-{
2352- struct gal2d_output_state *go = get_output_state(output);
2353- gctUINT32 i;
2354-
2355- if (use_output(output) < 0)
2356- return;
2357-
2358- for (i = 0; i < 2; i++)
2359- pixman_region32_union(&go->buffer_damage[i],
2360- &go->buffer_damage[i],
2361- output_damage);
2362-
2363- pixman_region32_union(output_damage, output_damage,
2364- &go->buffer_damage[go->current_buffer]);
2365-
2366- repaint_views(output, output_damage);
2367-
2368- pixman_region32_copy(&output->previous_damage, output_damage);
2369- wl_signal_emit(&output->frame_signal, output);
2370-
2371- update_surface(output);
2372-
2373- go->current_buffer ^= 1;
2374-}
2375-
2376-static void
2377-gal2d_renderer_attach_egl(struct weston_surface *es, struct weston_buffer *buffer)
2378-{
2379- gcsWL_VIV_BUFFER *vivBuffer = wl_resource_get_user_data(buffer->resource);
2380- gcoSURF srcSurf = vivBuffer->surface;
2381- gceSTATUS status = gcvSTATUS_OK;
2382- struct gal2d_surface_state *gs = get_surface_state(es);
2383-
2384- if(gs->gco_Surface != gcvNULL)
2385- {
2386- gcmONERROR(gcoSURF_Destroy(gs->gco_Surface));
2387- }
2388-
2389- gs->gco_Surface = srcSurf;
2390- gcoSURF_ReferenceSurface(srcSurf);
2391- buffer->width = vivBuffer->width;
2392- buffer->height = vivBuffer->height;
2393-
2394- OnError:
2395- galONERROR(status);
2396-}
2397-
2398-static void
2399-gal2d_renderer_flush_damage(struct weston_surface *surface)
2400-{
2401- struct gal2d_surface_state *gs = get_surface_state(surface);
2402- struct weston_buffer *buffer = gs->buffer_ref.buffer;
2403- struct weston_view *view;
2404- int texture_used;
2405- pixman_region32_union(&gs->texture_damage,
2406- &gs->texture_damage, &surface->damage);
2407-
2408- if (!buffer)
2409- return;
2410-
2411- texture_used = 0;
2412- wl_list_for_each(view, &surface->views, surface_link) {
2413- if (view->plane == &surface->compositor->primary_plane) {
2414- texture_used = 1;
2415- break;
2416- }
2417- }
2418- if (!texture_used)
2419- return;
2420-
2421- if (!pixman_region32_not_empty(&gs->texture_damage))
2422- goto done;
2423-
2424- if(wl_shm_buffer_get(buffer->resource))
2425- {
2426- if(gs->gco_Surface==NULL)
2427- {
2428- gs->gco_Surface = getSurfaceFromShm(surface, buffer);
2429- }
2430- gal2dBindBuffer(surface);
2431- }
2432- else
2433- gal2d_renderer_attach_egl(surface, buffer);
2434-
2435-done:
2436- pixman_region32_fini(&gs->texture_damage);
2437- pixman_region32_init(&gs->texture_damage);
2438-
2439- weston_buffer_reference(&gs->buffer_ref, NULL);
2440-}
2441-
2442-static void
2443-gal2d_renderer_attach(struct weston_surface *es, struct weston_buffer *buffer)
2444-{
2445- struct gal2d_surface_state *gs = get_surface_state(es);
2446- struct wl_shm_buffer *shm_buffer;
2447- weston_buffer_reference(&gs->buffer_ref, buffer);
2448-
2449- if(buffer==NULL)
2450- return;
2451-
2452- shm_buffer = wl_shm_buffer_get(buffer->resource);
2453-
2454- if(shm_buffer)
2455- {
2456- buffer->width = wl_shm_buffer_get_width(shm_buffer);
2457- buffer->height = wl_shm_buffer_get_height(shm_buffer);
2458- buffer->shm_buffer = shm_buffer;
2459-
2460- if(gs->gco_Surface)
2461- {
2462- gcoSURF_Destroy(gs->gco_Surface);
2463- gs->gco_Surface = getSurfaceFromShm(es, buffer);
2464- }
2465- }
2466- else
2467- gal2d_renderer_attach_egl(es, buffer);
2468-}
2469-
2470-static void
2471-surface_state_destroy(struct gal2d_surface_state *gs, struct gal2d_renderer *gr)
2472-{
2473- if(gs->gco_Surface)
2474- {
2475- gcoSURF_Destroy(gs->gco_Surface);
2476- }
2477- wl_list_remove(&gs->surface_destroy_listener.link);
2478- wl_list_remove(&gs->renderer_destroy_listener.link);
2479- if(gs->surface)
2480- gs->surface->renderer_state = NULL;
2481-
2482- weston_buffer_reference(&gs->buffer_ref, NULL);
2483- free(gs);
2484-}
2485-
2486-static void
2487-surface_state_handle_surface_destroy(struct wl_listener *listener, void *data)
2488-{
2489- struct gal2d_surface_state *gs;
2490- struct gal2d_renderer *gr;
2491-
2492- gs = container_of(listener, struct gal2d_surface_state,
2493- surface_destroy_listener);
2494-
2495- gr = get_renderer(gs->surface->compositor);
2496- surface_state_destroy(gs, gr);
2497-}
2498-
2499-static void
2500-surface_state_handle_renderer_destroy(struct wl_listener *listener, void *data)
2501-{
2502- struct gal2d_surface_state *gs;
2503- struct gal2d_renderer *gr;
2504-
2505- gr = data;
2506-
2507- gs = container_of(listener, struct gal2d_surface_state,
2508- renderer_destroy_listener);
2509-
2510- surface_state_destroy(gs, gr);
2511-}
2512-
2513-
2514-static int
2515-gal2d_renderer_create_surface(struct weston_surface *surface)
2516-{
2517- struct gal2d_surface_state *gs;
2518- struct gal2d_renderer *gr = get_renderer(surface->compositor);
2519-
2520- gs = zalloc(sizeof *gs);
2521- if (gs == NULL)
2522- return -1;
2523-
2524- /* A buffer is never attached to solid color surfaces, yet
2525- * they still go through texcoord computations. Do not divide
2526- * by zero there.
2527- */
2528- gs->pitch = 1;
2529-
2530- gs->surface = surface;
2531-
2532- pixman_region32_init(&gs->texture_damage);
2533- surface->renderer_state = gs;
2534-
2535- gs->surface_destroy_listener.notify =
2536- surface_state_handle_surface_destroy;
2537- wl_signal_add(&surface->destroy_signal,
2538- &gs->surface_destroy_listener);
2539-
2540- gs->renderer_destroy_listener.notify =
2541- surface_state_handle_renderer_destroy;
2542- wl_signal_add(&gr->destroy_signal,
2543- &gs->renderer_destroy_listener);
2544-
2545- if (surface->buffer_ref.buffer) {
2546- gal2d_renderer_attach(surface, surface->buffer_ref.buffer);
2547- gal2d_renderer_flush_damage(surface);
2548- }
2549-
2550- return 0;
2551-}
2552-
2553-static void
2554-gal2d_renderer_surface_set_color(struct weston_surface *surface,
2555- float red, float green, float blue, float alpha)
2556-{
2557- struct gal2d_surface_state *gs = get_surface_state(surface);
2558-
2559- gs->color[0] = red;
2560- gs->color[1] = green;
2561- gs->color[2] = blue;
2562- gs->color[3] = alpha;
2563-}
2564-
2565-
2566-static void
2567-gal2d_renderer_output_destroy(struct weston_output *output)
2568-{
2569- struct gal2d_output_state *go = get_output_state(output);
2570- gctUINT32 i;
2571-
2572- for (i = 0; i < 2; i++)
2573- {
2574- pixman_region32_fini(&go->buffer_damage[i]);
2575- }
2576- if(go->nNumBuffers <= 1 )
2577- {
2578- if(go->offscreenSurface)
2579- gcmVERIFY_OK(gcoSURF_Destroy(go->offscreenSurface));
2580- }
2581- else
2582- {
2583- gcoOS_Signal(gcvNULL,go->signal, gcvTRUE);
2584- pthread_mutex_lock(&go->workerMutex);
2585- go->exitWorker = 1;
2586- pthread_mutex_unlock(&go->workerMutex);
2587- pthread_join(go->workerId, NULL);
2588- }
2589-
2590- for(i=0; i < go->nNumBuffers; i++)
2591- {
2592- gcmVERIFY_OK(gcoSURF_Destroy(go->renderSurf[i]));
2593- }
2594- free(go->renderSurf);
2595- go->renderSurf = gcvNULL;
2596-
2597- free(go);
2598-}
2599-
2600-static void
2601-gal2d_renderer_destroy(struct weston_compositor *ec)
2602-{
2603- struct gal2d_renderer *gr = get_renderer(ec);
2604-
2605- wl_signal_emit(&gr->destroy_signal, gr);
2606- free(ec->renderer);
2607- ec->renderer = NULL;
2608-}
2609-
2610-
2611-static int
2612-gal2d_renderer_create(struct weston_compositor *ec)
2613-{
2614- struct gal2d_renderer *gr;
2615- gceSTATUS status = gcvSTATUS_OK;
2616- gr = malloc(sizeof *gr);
2617- if (gr == NULL)
2618- return -1;
2619-
2620- gr->base.read_pixels = gal2d_renderer_read_pixels;
2621- gr->base.repaint_output = gal2d_renderer_repaint_output;
2622- gr->base.flush_damage = gal2d_renderer_flush_damage;
2623- gr->base.attach = gal2d_renderer_attach;
2624- gr->base.surface_set_color = gal2d_renderer_surface_set_color;
2625- gr->base.destroy = gal2d_renderer_destroy;
2626-
2627- /* Construct the gcoOS object. */
2628- gcmONERROR(gcoOS_Construct(gcvNULL, &gr->gcos));
2629-
2630- /* Construct the gcoHAL object. */
2631- gcmONERROR(gcoHAL_Construct(gcvNULL, gr->gcos, &gr->gcoHal));
2632- gcmONERROR(gcoHAL_Get2DEngine(gr->gcoHal, &gr->gcoEngine2d));
2633- gcmONERROR(gcoHAL_SetHardwareType(gr->gcoHal, gcvHARDWARE_2D));
2634-
2635- ec->renderer = &gr->base;
2636- wl_signal_init(&gr->destroy_signal);
2637-OnError:
2638- galONERROR(status);
2639-
2640- /* Return the status. */
2641- return status;
2642-
2643-}
2644-
2645-static int
2646-gal2d_renderer_output_create(struct weston_output *output, NativeDisplayType display,
2647- NativeWindowType window)
2648-
2649- {
2650- struct gal2d_renderer *gr = get_renderer(output->compositor);
2651- struct gal2d_output_state *go;
2652- halDISPLAY_INFO info;
2653- gctUINT32 backOffset = 0;
2654- gceSTATUS status = gcvSTATUS_OK;
2655- gctUINT32 i;
2656-
2657- go = zalloc(sizeof *go);
2658- if (go == NULL)
2659- return -1;
2660-
2661- output->renderer_state = go;
2662- go->display = display;
2663- gcmONERROR(gcoOS_InitLocalDisplayInfo(go->display, &gr->localInfo));
2664-
2665- /* Get display information. */
2666- gcmONERROR(gcoOS_GetDisplayInfoEx2(
2667- go->display, gcvNULL, gr->localInfo,
2668- sizeof(info), &info));
2669- go->nNumBuffers = info.multiBuffer;
2670-
2671- weston_log("Number of buffers=%d\n",go->nNumBuffers);
2672-
2673- gcmONERROR(gal2d_getSurfaceFormat(info, &go->format));
2674- backOffset = (gctUINT32)(info.stride * info.height );
2675-
2676- go->activebuffer = 0;
2677-
2678- go->renderSurf = malloc(sizeof(gcoSURF) * go->nNumBuffers);
2679- gcoOS_GetDisplayVirtual(go->display, &go->width, &go->height);
2680- gcoOS_SetSwapInterval(go->display, 1);
2681-
2682- /*Needed only for multi Buffer */
2683- if(go->nNumBuffers > 1)
2684- {
2685- gcmVERIFY_OK(gcoOS_CreateSignal(gcvNULL, gcvFALSE,
2686- &go->signal));
2687- gcmVERIFY_OK(gcoOS_CreateSignal(gcvNULL, gcvFALSE,
2688- &go->busySignal));
2689-
2690- go->iface.command = gcvHAL_SIGNAL;
2691- go->iface.u.Signal.signal = gcmPTR_TO_UINT64(go->signal);
2692- go->iface.u.Signal.auxSignal = 0;
2693- go->iface.u.Signal.process = gcmPTR_TO_UINT64(gcoOS_GetCurrentProcessID());
2694- go->iface.u.Signal.fromWhere = gcvKERNEL_PIXEL;
2695-
2696- go->exitWorker = 0;
2697- pthread_create(&go->workerId, NULL, gal2d_output_worker, output);
2698- pthread_mutex_init(&go->workerMutex, gcvNULL);
2699- }
2700- for(i=0; i < go->nNumBuffers; i++)
2701- {
2702- gcmONERROR(gcoSURF_Construct(gr->gcoHal, info.width, info.height, 1,
2703- gcvSURF_BITMAP, go->format, gcvPOOL_USER, &go->renderSurf[i]));
2704-
2705- gcoSURF_MapUserSurface(go->renderSurf[i], 0,info.logical + (i * backOffset),
2706- info.physical + (i * backOffset));
2707-
2708- //Clear surfaces
2709- make_current(gr, go->renderSurf[go->activebuffer]);
2710- gal2d_clear(output);
2711- gal2d_flip_surface(output);
2712- }
2713- if(go->nNumBuffers <= 1)
2714- go->activebuffer = 0;
2715- else
2716- go->activebuffer = 1;
2717-
2718- if(go->nNumBuffers <= 1 )
2719- {
2720- gcmVERIFY_OK(gcoSURF_Construct(gr->gcoHal,
2721- (gctUINT) info.width,
2722- (gctUINT) info.height,
2723- 1,
2724- gcvSURF_BITMAP,
2725- go->format,
2726- gcvPOOL_DEFAULT,
2727- &go->offscreenSurface));
2728- make_current(gr, go->offscreenSurface);
2729- gal2d_clear(output);
2730- }
2731- else
2732- {
2733- gcoOS_Signal(gcvNULL,go->busySignal, gcvTRUE);
2734- }
2735-
2736- for (i = 0; i < 2; i++)
2737- pixman_region32_init(&go->buffer_damage[i]);
2738-OnError:
2739- galONERROR(status);
2740- /* Return the status. */
2741- return status;
2742- }
2743-
2744- WL_EXPORT struct gal2d_renderer_interface gal2d_renderer_interface = {
2745- .create = gal2d_renderer_create,
2746- .output_create = gal2d_renderer_output_create,
2747- .output_destroy = gal2d_renderer_output_destroy,
2748-};
2749Index: weston-1.11.1/src/gal2d-renderer.h
2750===================================================================
2751--- weston-1.11.1.orig/src/gal2d-renderer.h 2017-01-14 08:59:52.297865829 -0600
2752+++ /dev/null 1970-01-01 00:00:00.000000000 +0000
2753@@ -1,50 +0,0 @@
2754-/*
2755- * Copyright (c) 2015 Freescale Semiconductor, Inc.
2756- * Copyright © 2013 Vasily Khoruzhick <anarsoul@gmail.com>
2757- *
2758- * Permission is hereby granted, free of charge, to any person obtaining
2759- * a copy of this software and associated documentation files (the
2760- * "Software"), to deal in the Software without restriction, including
2761- * without limitation the rights to use, copy, modify, merge, publish,
2762- * distribute, sublicense, and/or sell copies of the Software, and to
2763- * permit persons to whom the Software is furnished to do so, subject to
2764- * the following conditions:
2765- *
2766- * The above copyright notice and this permission notice (including the
2767- * next paragraph) shall be included in all copies or substantial
2768- * portions of the Software.
2769- *
2770- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2771- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2772- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2773- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
2774- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
2775- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
2776- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2777- * SOFTWARE.
2778- */
2779-#ifndef __gal_2d_renderer_h_
2780-#define __gal_2d_renderer_h_
2781-
2782-#include "compositor.h"
2783-#ifdef ENABLE_EGL
2784-#include <EGL/egl.h>
2785-#else
2786-#include <HAL/gc_hal_eglplatform.h>
2787-typedef HALNativeDisplayType NativeDisplayType;
2788-typedef HALNativeWindowType NativeWindowType;
2789-#endif
2790-
2791-
2792-struct gal2d_renderer_interface {
2793-
2794- int (*create)(struct weston_compositor *ec);
2795-
2796- int (*output_create)(struct weston_output *output,
2797- NativeDisplayType display,
2798- NativeWindowType window);
2799-
2800- void (*output_destroy)(struct weston_output *output);
2801-};
2802-
2803-#endif
2804Index: weston-1.11.1/src/main.c
2805===================================================================
2806--- weston-1.11.1.orig/src/main.c 2017-01-14 08:59:52.297865829 -0600
2807+++ weston-1.11.1/src/main.c 2017-01-14 09:08:38.000000000 -0600
2808@@ -287,10 +287,10 @@
2809 " --device=DEVICE\tThe framebuffer device to use\n"
2810 #if defined ENABLE_EGL
2811 " --use-gl=1\t\tUse the GL renderer (default is 1)\n"
2812- " --use-gal2d=1\t\tUse the GAL2D renderer (default is 0)\n\n");
2813+ " --use-g2d=1\t\tUse the G2D renderer (default is 0)\n\n");
2814 #else
2815 " --use-gl=1\t\tUse the GL renderer (default is 0)\n"
2816- " --use-gal2d=1\t\tUse the GAL2D renderer (default is 1)\n\n");
2817+ " --use-g2d=1\t\tUse the G2D renderer (default is 1)\n\n");
2818 #endif
2819 #endif
2820
2821@@ -875,7 +875,7 @@
2822 { WESTON_OPTION_INTEGER, "tty", 0, &config.tty },
2823 { WESTON_OPTION_STRING, "device", 0, &config.device },
2824 { WESTON_OPTION_INTEGER, "use-gl", 0, &config.use_gl },
2825- { WESTON_OPTION_INTEGER, "use-gal2d", 0, &config.use_gal2d },
2826+ { WESTON_OPTION_INTEGER, "use-g2d", 0, &config.use_g2d },
2827 };
2828
2829 parse_options(fbdev_options, ARRAY_LENGTH(fbdev_options), argc, argv);
2830Index: weston-1.11.1/src/compositor-fbdev.h
2831===================================================================
2832--- weston-1.11.1.orig/src/compositor-fbdev.h 2017-01-14 08:59:52.297865829 -0600
2833+++ weston-1.11.1/src/compositor-fbdev.h 2017-01-14 08:59:52.841868527 -0600
2834@@ -40,7 +40,8 @@
2835 int tty;
2836 char *device;
2837 int use_gl;
2838- int use_gal2d;
2839+ int use_g2d;
2840+ int clone_mode;
2841
2842 uint32_t output_transform;
2843 };
diff --git a/recipes-graphics/wayland/weston/0010-MGS-1284-1-xwld-Re-implement-weston-2d-renderer-with.patch b/recipes-graphics/wayland/weston/0010-MGS-1284-1-xwld-Re-implement-weston-2d-renderer-with.patch
deleted file mode 100644
index 96181aba..00000000
--- a/recipes-graphics/wayland/weston/0010-MGS-1284-1-xwld-Re-implement-weston-2d-renderer-with.patch
+++ /dev/null
@@ -1,36 +0,0 @@
1From 9a19dd911fc79fa828b03fce8cdb16c6cfcb25cb Mon Sep 17 00:00:00 2001
2From: "yong.gan" <yong.gan@nxp.com>
3Date: Tue, 22 Mar 2016 10:15:31 +0800
4Subject: [PATCH 2/3] MGS-1284-1: xwld: Re-implement weston 2d renderer with
5 porting g2d API
6
7Add gpu address to the buffer physical address, fix the mess in sx board.
8
9Date: Feb 22, 2016
10Upstream Status: Inappropriate [i.MX specific]
11
12Signed-off-by: Yong Gan <yong.gan@freescale.com>
13---
14 src/g2d-renderer.c | 6 +++---
15 1 file changed, 3 insertions(+), 3 deletions(-)
16
17diff --git a/src/g2d-renderer.c b/src/g2d-renderer.c
18index 756c8f0..19c93a0 100644
19--- a/src/g2d-renderer.c
20+++ b/src/g2d-renderer.c
21@@ -317,9 +317,9 @@ get_g2dSurface(gcsWL_VIV_BUFFER *buffer, struct g2d_surfaceEx *g2dSurface)
22 int height = buffer->alignedHeight;
23 g2d_getG2dFormat(buffer->format, &g2dSurface->base.format);
24 g2d_getG2dTiling(buffer->tiling, &g2dSurface->tiling);
25- g2dSurface->base.planes[0] = buffer->physical[0];
26- g2dSurface->base.planes[1] = buffer->physical[1];
27- g2dSurface->base.planes[2] = buffer->physical[2];
28+ g2dSurface->base.planes[0] = buffer->physical[0] + buffer->gpuBaseAddr;
29+ g2dSurface->base.planes[1] = buffer->physical[1] + buffer->gpuBaseAddr;
30+ g2dSurface->base.planes[2] = buffer->physical[2] + buffer->gpuBaseAddr;
31 g2dSurface->base.left = 0;
32 g2dSurface->base.top = 0;
33 g2dSurface->base.right = buffer->width;
34--
351.9.1
36
diff --git a/recipes-graphics/wayland/weston/0011-MGS-1724-xwld-G2D-compositor-build-failed-in-slevk-b.patch b/recipes-graphics/wayland/weston/0011-MGS-1724-xwld-G2D-compositor-build-failed-in-slevk-b.patch
deleted file mode 100644
index 42a33394..00000000
--- a/recipes-graphics/wayland/weston/0011-MGS-1724-xwld-G2D-compositor-build-failed-in-slevk-b.patch
+++ /dev/null
@@ -1,129 +0,0 @@
1From b67a6184ed3b6d728894eba37a554a302c1b0312 Mon Sep 17 00:00:00 2001
2From: "yong.gan" <yong.gan@nxp.com>
3Date: Sat, 2 Apr 2016 09:33:56 +0800
4Subject: [PATCH 3/3] MGS-1724: xwld: G2D compositor build failed in slevk
5 board
6
7Add macro ENABLE_EGL to make sure the EGL was not built in slevk board.
8Modify the wrong format for the shm buffer.
9
10Upstream Status: Inappropriate [i.MX specific]
11
12Signed-off-by: Yong Gan <yong.gan@nxp.com>
13---
14 src/compositor-fbdev.c | 11 ++++++++++-
15 src/g2d-renderer.c | 4 ++--
16 2 files changed, 12 insertions(+), 3 deletions(-)
17
18Index: weston-1.11.1/src/compositor-fbdev.c
19===================================================================
20--- weston-1.11.1.orig/src/compositor-fbdev.c 2017-01-14 09:47:24.064006974 -0600
21+++ weston-1.11.1/src/compositor-fbdev.c 2017-01-14 09:55:59.000000000 -0600
22@@ -63,7 +63,9 @@
23 int use_g2d;
24 uint32_t output_transform;
25 struct wl_listener session_listener;
26+#ifdef ENABLE_EGL
27 NativeDisplayType display;
28+#endif
29 };
30
31 struct fbdev_screeninfo {
32@@ -96,9 +98,10 @@
33 /* pixman details. */
34 pixman_image_t *hw_surface;
35 uint8_t depth;
36-
37+#ifdef ENABLE_EGL
38 NativeDisplayType display;
39 NativeWindowType window;
40+#endif
41 };
42
43 struct gl_renderer_interface *gl_renderer;
44@@ -450,10 +453,12 @@
45 strerror(errno));
46
47 output->fb = NULL;
48+#ifdef ENABLE_EGL
49 if(output->window)
50 fbDestroyWindow(output->window);
51 if(output->display)
52 fbDestroyDisplay(output->display);
53+#endif
54 }
55
56 static void fbdev_output_destroy(struct weston_output *base);
57@@ -527,6 +532,7 @@
58 }
59
60 } else {
61+#ifdef ENABLE_EGL
62 setenv("HYBRIS_EGLPLATFORM", "wayland", 1);
63 output->window = fbCreateWindow(backend->display, -1, -1, 0, 0);
64 if (output->window == NULL) {
65@@ -540,6 +546,7 @@
66 weston_log("gl_renderer_output_create failed.\n");
67 goto out_hw_surface;
68 }
69+#endif
70 }
71
72 loop = wl_display_get_event_loop(backend->compositor->wl_display);
73@@ -847,6 +854,7 @@
74 }
75 }
76 else {
77+#ifdef ENABLE_EGL
78 gl_renderer = weston_load_module("gl-renderer.so",
79 "gl_renderer_interface");
80 if (!gl_renderer) {
81@@ -866,6 +874,7 @@
82 weston_log("gl_renderer_create failed.\n");
83 goto out_launcher;
84 }
85+#endif
86 }
87 if(!backend->use_g2d)
88 if (fbdev_output_create(backend, 0, 0, param->device) < 0)
89Index: weston-1.11.1/src/g2d-renderer.c
90===================================================================
91--- weston-1.11.1.orig/src/g2d-renderer.c 2017-01-14 09:47:24.152007410 -0600
92+++ weston-1.11.1/src/g2d-renderer.c 2017-01-14 09:48:56.000000000 -0600
93@@ -756,11 +756,11 @@
94
95 switch (wl_shm_buffer_get_format(shm_buffer)) {
96 case WL_SHM_FORMAT_XRGB8888:
97- g2dFormat = G2D_XRGB8888;
98+ g2dFormat = G2D_BGRX8888;
99 gs->bpp = 4;
100 break;
101 case WL_SHM_FORMAT_ARGB8888:
102- g2dFormat = G2D_ARGB8888;
103+ g2dFormat = G2D_BGRA8888;
104 gs->bpp = 4;
105 break;
106 case WL_SHM_FORMAT_RGB565:
107Index: weston-1.11.1/src/main.c
108===================================================================
109--- weston-1.11.1.orig/src/main.c 2017-01-14 10:02:42.000000000 -0600
110+++ weston-1.11.1/src/main.c 2017-01-14 10:02:58.000000000 -0600
111@@ -866,7 +866,17 @@
112 load_fbdev_backend(struct weston_compositor *c, char const * backend,
113 int *argc, char **argv, struct weston_config *wc)
114 {
115- struct weston_fbdev_backend_config config = {{ 0, }};
116+ struct weston_fbdev_backend_config config = {
117+ .base = {0},
118+#ifdef ENABLE_EGL
119+ .use_gl = 1,
120+ .use_g2d = 0,
121+#else
122+ .use_gl = 0,
123+ .use_g2d = 1,
124+#endif
125+ .clone_mode = 0,
126+ };
127 struct weston_config_section *section;
128 char *s = NULL;
129 int ret = 0;
diff --git a/recipes-graphics/wayland/weston/0012-MGS-1783-xwld-Add-clone-mode-support-for-multi-displ.patch b/recipes-graphics/wayland/weston/0012-MGS-1783-xwld-Add-clone-mode-support-for-multi-displ.patch
deleted file mode 100644
index e504d677..00000000
--- a/recipes-graphics/wayland/weston/0012-MGS-1783-xwld-Add-clone-mode-support-for-multi-displ.patch
+++ /dev/null
@@ -1,421 +0,0 @@
1From f2025a7e8c178b8c52c2ca553459a7fea6caf5c8 Mon Sep 17 00:00:00 2001
2From: "yong.gan" <yong.gan@nxp.com>
3Date: Tue, 17 May 2016 09:10:50 +0800
4Subject: [PATCH 1/2] MGS-1783: xwld: Add clone mode support for multi display
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8
9Support showing the same contents on multiple displays.
10Use the following command to enable multi-display:
11 openvt -v -- weston-launch -- --idle-time=0 --use-g2d=1 --device=/dev/fb0,/dev/fb4 --clone-mode --log=/var/log/weston.log
12
13Upstream-Status: Inappropriate [i.MX specific]
14Date: May 16, 2016
15Signed-off-by: Yong Gan <yong.gan@nxp.com>
16---
17 src/compositor-fbdev.c | 33 +++++++---
18 src/g2d-renderer.c | 171 ++++++++++++++++++++++++++++++++++++++++---------
19 src/g2d-renderer.h | 4 +-
20 3 files changed, 167 insertions(+), 41 deletions(-)
21
22Index: weston-1.11.1/src/compositor-fbdev.c
23===================================================================
24--- weston-1.11.1.orig/src/compositor-fbdev.c 2017-01-16 13:23:48.925264352 -0600
25+++ weston-1.11.1/src/compositor-fbdev.c 2017-01-16 13:23:49.013264789 -0600
26@@ -61,6 +61,8 @@
27 struct udev_input input;
28 int use_pixman;
29 int use_g2d;
30+ int clone_mode;
31+ char *clone_device;
32 uint32_t output_transform;
33 struct wl_listener session_listener;
34 #ifdef ENABLE_EGL
35@@ -525,12 +527,15 @@
36 if (pixman_renderer_output_create(&output->base) < 0)
37 goto out_hw_surface;
38 } else if(backend->use_g2d) {
39+ const char *g2d_device = device;
40+ if (backend->clone_mode)
41+ g2d_device = backend->clone_device;
42+
43 if (g2d_renderer->output_create(&output->base,
44- backend->compositor->wl_display, device) < 0) {
45+ backend->compositor->wl_display, g2d_device) < 0) {
46 weston_log("g2d_renderer_output_create failed.\n");
47 goto out_hw_surface;
48 }
49-
50 } else {
51 #ifdef ENABLE_EGL
52 setenv("HYBRIS_EGLPLATFORM", "wayland", 1);
53@@ -803,6 +808,8 @@
54 backend->prev_state = WESTON_COMPOSITOR_ACTIVE;
55 backend->use_pixman = !(param->use_gl || param->use_g2d);
56 backend->use_g2d = param->use_g2d;
57+ backend->clone_mode = param->clone_mode;
58+ backend->clone_device = param->device;
59 backend->output_transform = param->output_transform;
60
61 weston_setup_vt_switch_bindings(compositor);
62@@ -844,16 +851,21 @@
63 displays[dispCount][k] = '\0';
64 dispCount++;
65
66- for(i=0; i<dispCount; i++)
67- {
68- if (fbdev_output_create(backend, x, y, displays[i]) < 0)
69+ if(backend->clone_mode){
70+ if (fbdev_output_create(backend, x, y, displays[0]) < 0)
71 goto out_launcher;
72- x += container_of(backend->compositor->output_list.prev,
73- struct weston_output,
74- link)->width;
75+ }
76+ else{
77+ for(i= 0; i < dispCount; i++){
78+ if (fbdev_output_create(backend, x, y, displays[i]) < 0)
79+ goto out_launcher;
80+ x += container_of(backend->compositor->output_list.prev,
81+ struct weston_output,
82+ link)->width;
83+ }
84 }
85 }
86- else {
87+ else {
88 #ifdef ENABLE_EGL
89 gl_renderer = weston_load_module("gl-renderer.so",
90 "gl_renderer_interface");
91Index: weston-1.11.1/src/g2d-renderer.c
92===================================================================
93--- weston-1.11.1.orig/src/g2d-renderer.c 2017-01-16 13:23:48.925264352 -0600
94+++ weston-1.11.1/src/g2d-renderer.c 2017-01-16 13:26:17.000000000 -0600
95@@ -37,15 +37,16 @@
96 #include <sys/ioctl.h>
97 #include <fcntl.h>
98 #include <unistd.h>
99+#include <g2dExt.h>
100+#include <HAL/gc_hal_eglplatform.h>
101
102 #include "compositor.h"
103 #include "g2d-renderer.h"
104 #include "vertex-clipping.h"
105 #include "shared/helpers.h"
106-#include "HAL/gc_hal_eglplatform.h"
107-#include "g2dExt.h"
108
109 #define BUFFER_DAMAGE_COUNT 2
110+extern struct wl_global* gcoOS_WaylandCreateVivGlobal(struct wl_display* display);
111
112 typedef struct _g2dRECT
113 {
114@@ -63,6 +64,7 @@
115 size_t buffer_length; /* length of frame buffer memory in bytes */
116 size_t physical;
117 enum g2d_format pixel_format; /* frame buffer pixel format */
118+ int fb_fd;
119 };
120
121 struct g2d_output_state {
122@@ -74,10 +76,12 @@
123 struct g2d_surfaceEx offscreenSurface;
124 struct g2d_buf *offscreen_buf;
125 struct fb_screeninfo fb_info;
126+ struct fb_screeninfo *mirror_fb_info;
127+ struct g2d_surfaceEx *mirrorSurf;
128 int directBlit;
129+ int clone_display_num;
130 int width;
131 int height;
132- int fb_fd;
133 };
134
135 struct g2d_surface_state {
136@@ -366,7 +370,7 @@
137 struct g2d_output_state *go = get_output_state(output);
138 go->fb_info.varinfo.yoffset = go->activebuffer * go->fb_info.y_resolution;
139
140- if(ioctl(go->fb_fd, FBIOPAN_DISPLAY, &(go->fb_info.varinfo)) < 0)
141+ if(ioctl(go->fb_info.fb_fd, FBIOPAN_DISPLAY, &(go->fb_info.varinfo)) < 0)
142 {
143 weston_log("FBIOPAN_DISPLAY Failed\n");
144 }
145@@ -388,6 +392,28 @@
146 &go->renderSurf[go->activebuffer], &srcRect, &dstrect);
147 }
148
149+ if(go->clone_display_num)
150+ {
151+ int i = 0;
152+ for(i = 0; i < go->clone_display_num; i++)
153+ {
154+ g2dRECT srcRect = {0, 0, go->renderSurf[go->activebuffer].base.width, go->renderSurf[go->activebuffer].base.height};
155+ g2dRECT dstrect = {0, 0, go->mirrorSurf[i].base.width, go->mirrorSurf[i].base.height};
156+ g2dRECT clipRect = srcRect;
157+ g2d_set_clipping(gr->handle, clipRect.left, clipRect.top, clipRect.right, clipRect.bottom);
158+ if(go->directBlit || go->nNumBuffers > 1)
159+ {
160+ g2d_blitSurface(gr->handle, &go->renderSurf[go->activebuffer],
161+ &go->mirrorSurf[i], &srcRect, &dstrect);
162+ }
163+ else
164+ {
165+ g2d_blitSurface(gr->handle, &go->offscreenSurface,
166+ &go->mirrorSurf[i], &srcRect, &dstrect);
167+ }
168+ }
169+ }
170+
171 g2d_finish(gr->handle);
172
173 if(go->nNumBuffers > 1)
174@@ -940,10 +966,10 @@
175 go->offscreen_buf = NULL;
176 }
177
178- if(go->fb_fd)
179+ if(go->fb_info.fb_fd)
180 {
181- close(go->fb_fd);
182- go->fb_fd = 0;
183+ close(go->fb_info.fb_fd);
184+ go->fb_info.fb_fd = 0;
185 }
186
187 if(go->renderSurf)
188@@ -951,6 +977,24 @@
189 free(go->renderSurf);
190 go->renderSurf = NULL;
191 }
192+ for (i = 0; i < go->clone_display_num; i++)
193+ {
194+ if(go->mirror_fb_info[i].fb_fd)
195+ {
196+ close(go->mirror_fb_info[i].fb_fd);
197+ go->mirror_fb_info[i].fb_fd = 0;
198+ }
199+ }
200+ if(go->mirrorSurf)
201+ {
202+ free(go->mirrorSurf);
203+ go->mirrorSurf = NULL;
204+ }
205+ if(go->mirror_fb_info)
206+ {
207+ free(go->mirror_fb_info);
208+ go->mirror_fb_info = NULL;
209+ }
210
211 free(go);
212 }
213@@ -1085,39 +1129,27 @@
214 struct fb_screeninfo *screen_info)
215 {
216 /* Open the frame buffer device. */
217- output->fb_fd = open(fb_dev, O_RDWR | O_CLOEXEC);
218- if (output->fb_fd < 0) {
219+ screen_info->fb_fd = open(fb_dev, O_RDWR | O_CLOEXEC);
220+ if (screen_info->fb_fd < 0) {
221 weston_log("Failed to open frame buffer device%s \n", fb_dev);
222 return -1;
223 }
224
225 /* Grab the screen info. */
226- if (fb_query_screen_info(output, output->fb_fd, screen_info) < 0) {
227+ if (fb_query_screen_info(output, screen_info->fb_fd, screen_info) < 0) {
228 weston_log("Failed to get frame buffer info \n");
229
230- close(output->fb_fd);
231+ close(screen_info->fb_fd);
232 return -1;
233 }
234
235 return 0;
236 }
237
238-static int
239-g2d_renderer_output_create(struct weston_output *output, struct wl_display *wl_display, const char *device)
240-
241- {
242- struct g2d_renderer *gr = get_renderer(output->compositor);
243- struct g2d_output_state *go;
244- int i = 0;
245- int offset = 0;
246+static void
247+getBufferNumber(struct g2d_output_state *go)
248+{
249 char *p = NULL;
250- go = zalloc(sizeof *go);
251- if (go == NULL)
252- return -1;
253-
254- output->renderer_state = go;
255- gr->viv_global = gcoOS_WaylandCreateVivGlobal(wl_display);
256-
257 p = getenv("FB_MULTI_BUFFER");
258 if (p == gcvNULL)
259 {
260@@ -1126,7 +1158,7 @@
261 else
262 {
263 go->nNumBuffers = atoi(p);
264- if (go->nNumBuffers < 1)
265+ if (go->nNumBuffers < 2)
266 {
267 go->nNumBuffers = 1;
268 }
269@@ -1137,13 +1169,19 @@
270 }
271 }
272 weston_log("FB_MULTI_BUFFER = %d\n", go->nNumBuffers);
273+}
274
275+static int
276+g2d_renderer_surface_create(struct g2d_output_state *go, struct g2d_renderer *gr, const char *device)
277+{
278+ int i = 0;
279+ int offset = 0;
280+ weston_log("Opend device=%s\n", device);
281 if(fb_frame_buffer_open(go, device, &go->fb_info) < 0)
282 {
283 weston_log("Open frame buffer failed.\n");
284 return -1;
285 }
286-
287 go->renderSurf = zalloc(sizeof(struct g2d_surfaceEx) * go->nNumBuffers);
288 offset = go->fb_info.buffer_length/go->nNumBuffers;
289 for(i = 0; i < go->nNumBuffers; i++)
290@@ -1161,9 +1199,84 @@
291 go->offscreenSurface.base.planes[0] = go->offscreen_buf->buf_paddr;
292 g2d_clear(gr->handle, &go->offscreenSurface.base);
293 }
294+ return 0;
295+}
296+
297+static int
298+g2d_renderer_output_create(struct weston_output *output, struct wl_display *wl_display, const char *device)
299
300+ {
301+ struct g2d_renderer *gr = get_renderer(output->compositor);
302+ struct g2d_output_state *go;
303+ int i;
304+ int clone_display_num = 0;
305+ int count = 0;
306+ int k=0, dispCount = 0;
307+ char displays[5][32];
308+ weston_log("g2d_renderer_output_create device=%s\n", device);
309+ count = strlen(device);
310+
311+ if(count > 0)
312+ {
313+ for(i= 0; i < count; i++)
314+ {
315+ if(device[i] == ',')
316+ {
317+ displays[dispCount][k] = '\0';
318+ dispCount++;
319+ k = 0;
320+ continue;
321+ }
322+ else if(device[i] != ' ')
323+ {
324+ displays[dispCount][k++] = device[i];
325+ }
326+ }
327+ displays[dispCount][k] = '\0';
328+ clone_display_num = dispCount++;
329+ weston_log("clone_display_num = %d\n", clone_display_num);
330+ }
331+ else
332+ {
333+ weston_log("Invalid device name\n");
334+ return -1;
335+ }
336+
337+ go = zalloc(sizeof *go);
338+ if (go == NULL)
339+ return -1;
340+ go->clone_display_num = clone_display_num;
341+ output->renderer_state = go;
342+ gr->viv_global = gcoOS_WaylandCreateVivGlobal(wl_display);
343+ getBufferNumber(go);
344+
345+ if(g2d_renderer_surface_create(go, gr, displays[0]) < 0)
346+ {
347+ weston_log("Create Render surface failed.\n");
348+ return -1;
349+ }
350+
351+ if(go->clone_display_num)
352+ {
353+ go->mirrorSurf = zalloc(sizeof(struct g2d_surfaceEx) * clone_display_num);
354+ go->mirror_fb_info = zalloc(sizeof(struct fb_screeninfo) * clone_display_num);
355+ if(go->mirrorSurf == NULL || go->mirror_fb_info == NULL)
356+ return -1;
357+
358+ for(i = 0; i < clone_display_num; i++)
359+ {
360+ if(fb_frame_buffer_open(go, displays[i + 1], &go->mirror_fb_info[i]) < 0)
361+ {
362+ weston_log("Open frame buffer failed.\n");
363+ return -1;
364+ }
365+ get_G2dSurface_from_screeninfo(&go->mirror_fb_info[i], &go->mirrorSurf[i]);
366+ go->mirrorSurf[i].base.planes[0] = go->mirror_fb_info[i].physical;
367+ g2d_clear(gr->handle, &go->mirrorSurf[i].base);
368+ }
369+ }
370 g2d_finish(gr->handle);
371- for (i = 0; i < 2; i++)
372+ for (i = 0; i < BUFFER_DAMAGE_COUNT; i++)
373 pixman_region32_init(&go->buffer_damage[i]);
374 return 0;
375 }
376Index: weston-1.11.1/src/g2d-renderer.h
377===================================================================
378--- weston-1.11.1.orig/src/g2d-renderer.h 2017-01-16 13:23:48.757263519 -0600
379+++ weston-1.11.1/src/g2d-renderer.h 2017-01-16 13:26:17.000000000 -0600
380@@ -27,13 +27,11 @@
381 #define __g2d_renderer_h_
382
383 #include "compositor.h"
384+
385 #ifdef ENABLE_EGL
386 #include <EGL/egl.h>
387-#else
388-#include <HAL/gc_hal_eglplatform.h>
389 #endif
390
391-
392 struct g2d_renderer_interface {
393
394 int (*create)(struct weston_compositor *ec);
395Index: weston-1.11.1/src/main.c
396===================================================================
397--- weston-1.11.1.orig/src/main.c 2017-01-16 13:23:48.929264372 -0600
398+++ weston-1.11.1/src/main.c 2017-01-16 13:32:49.000000000 -0600
399@@ -287,11 +287,12 @@
400 " --device=DEVICE\tThe framebuffer device to use\n"
401 #if defined ENABLE_EGL
402 " --use-gl=1\t\tUse the GL renderer (default is 1)\n"
403- " --use-g2d=1\t\tUse the G2D renderer (default is 0)\n\n");
404+ " --use-g2d=1\t\tUse the G2D renderer (default is 0)\n"
405 #else
406 " --use-gl=1\t\tUse the GL renderer (default is 0)\n"
407- " --use-g2d=1\t\tUse the G2D renderer (default is 1)\n\n");
408+ " --use-g2d=1\t\tUse the G2D renderer (default is 1)\n"
409 #endif
410+ " --clone-mode\t\tClone display to multiple devices\n\n");
411 #endif
412
413 #if defined(BUILD_HEADLESS_COMPOSITOR)
414@@ -886,6 +887,7 @@
415 { WESTON_OPTION_STRING, "device", 0, &config.device },
416 { WESTON_OPTION_INTEGER, "use-gl", 0, &config.use_gl },
417 { WESTON_OPTION_INTEGER, "use-g2d", 0, &config.use_g2d },
418+ { WESTON_OPTION_BOOLEAN, "clone-mode", 0, &config.clone_mode },
419 };
420
421 parse_options(fbdev_options, ARRAY_LENGTH(fbdev_options), argc, argv);
diff --git a/recipes-graphics/wayland/weston/0013-MGS-1945-Use-common-API-to-support-G2d-compositor.patch b/recipes-graphics/wayland/weston/0013-MGS-1945-Use-common-API-to-support-G2d-compositor.patch
deleted file mode 100644
index 46161737..00000000
--- a/recipes-graphics/wayland/weston/0013-MGS-1945-Use-common-API-to-support-G2d-compositor.patch
+++ /dev/null
@@ -1,196 +0,0 @@
1From bdf9a0349f84997397a1c9352ee041e6fa4256a9 Mon Sep 17 00:00:00 2001
2From: "yong.gan" <yong.gan@nxp.com>
3Date: Thu, 23 Jun 2016 09:15:51 +0800
4Subject: [PATCH] MGS-1945: Use common API to support G2d compositor.
5
6Replace gcoOS_WaylandCreateVivGlobal with eglBindWaylandDisplayWL.
7Fix a width set error in g2d_renderer_attach_shm.
8Use noncached buffer in weston shm buffer.
9
10Upstream-Status: Inappropriate [i.MX specific]
11Date: Jun 21, 2016
12Signed-off-by: Yong Gan <yong.gan@nxp.com>
13---
14 Makefile.am | 4 ++++
15 src/g2d-renderer.c | 44 +++++++++++++++++++++++++++-----------------
16 src/g2d-renderer.h | 1 +
17 3 files changed, 32 insertions(+), 17 deletions(-)
18
19diff --git a/Makefile.am b/Makefile.am
20index f62bfc7..207864f 100644
21--- a/Makefile.am
22+++ b/Makefile.am
23@@ -214,6 +214,7 @@ gl_renderer_la_SOURCES = \
24 src/vertex-clipping.h \
25 shared/helpers.h
26 endif
27+
28 module_LTLIBRARIES += g2d-renderer.la
29 g2d_renderer_la_LDFLAGS = -module -avoid-version
30 g2d_renderer_la_LIBADD = $(COMPOSITOR_LIBS) $(EGL_LIBS) -lg2d
31@@ -226,6 +227,9 @@ g2d_renderer_la_SOURCES = \
32 src/g2d-renderer.c \
33 src/vertex-clipping.c \
34 src/vertex-clipping.h
35+if ENABLE_EGL
36+g2d_renderer_la_CFLAGS += -DENABLE_EGL
37+endif
38
39 if ENABLE_X11_COMPOSITOR
40 module_LTLIBRARIES += x11-backend.la
41diff --git a/src/g2d-renderer.c b/src/g2d-renderer.c
42index 4440fb9..0c26e91 100644
43--- a/src/g2d-renderer.c
44+++ b/src/g2d-renderer.c
45@@ -46,7 +46,7 @@
46 #include "shared/helpers.h"
47
48 #define BUFFER_DAMAGE_COUNT 2
49-extern struct wl_global* gcoOS_WaylandCreateVivGlobal(struct wl_display* display);
50+#define ALIGN_WIDTH(a) (((a) + 15) & ~15)
51
52 typedef struct _g2dRECT
53 {
54@@ -103,7 +103,11 @@ struct g2d_surface_state {
55 struct g2d_renderer {
56 struct weston_renderer base;
57 struct wl_signal destroy_signal;
58- struct wl_global *viv_global;
59+#ifdef ENABLE_EGL
60+ NativeDisplayType display;
61+ EGLDisplay egl_display;
62+ struct wl_display *wl_display;
63+#endif
64 void *handle;
65 };
66
67@@ -296,9 +300,10 @@ g2d_getG2dFormat(IN gceSURF_FORMAT Format, enum g2d_format* g2dFormat)
68 }
69 }
70
71-static void printG2dSurfaceInfo(struct g2d_surfaceEx* g2dSurface)
72+static void printG2dSurfaceInfo(struct g2d_surfaceEx* g2dSurface, const char* msg)
73 {
74- weston_log("physicAddr = %d left = %d right = %d top=%d bottom=%d stride= %d tiling = %d, format=%d \n",
75+ weston_log("%s physicAddr = %x left = %d right = %d top=%d bottom=%d stride= %d tiling = %d, format=%d \n",
76+ msg,
77 g2dSurface->base.planes[0],
78 g2dSurface->base.left,
79 g2dSurface->base.right,
80@@ -357,8 +362,8 @@ g2d_blitSurface(void *handle, struct g2d_surfaceEx * srcG2dSurface, struct g2d_s
81
82 if(g2d_blitEx(handle, srcG2dSurface, dstG2dSurface))
83 {
84- printG2dSurfaceInfo(srcG2dSurface);
85- printG2dSurfaceInfo(dstG2dSurface);
86+ printG2dSurfaceInfo(srcG2dSurface, "SRC:");
87+ printG2dSurfaceInfo(dstG2dSurface, "DST:");
88 return -1;
89 }
90 return 0;
91@@ -724,7 +729,7 @@ g2d_renderer_flush_damage(struct weston_surface *surface)
92 wl_shm_buffer_begin_access(buffer->shm_buffer);
93 if(gs->shm_buf)
94 {
95- int alignedWidth = (buffer->width + 15) & ~15;
96+ int alignedWidth = ALIGN_WIDTH(buffer->width);
97 if(alignedWidth == buffer->width)
98 {
99 int size = wl_shm_buffer_get_stride(buffer->shm_buffer)*buffer->height;
100@@ -743,7 +748,6 @@ g2d_renderer_flush_damage(struct weston_surface *surface)
101 }
102 }
103 }
104- g2d_cache_op(gs->shm_buf, G2D_CACHE_CLEAN);
105 }
106 else
107 {
108@@ -768,7 +772,6 @@ g2d_renderer_attach_shm(struct weston_surface *es, struct weston_buffer *buffer,
109 struct wl_shm_buffer *shm_buffer)
110 {
111 struct g2d_surface_state *gs = get_surface_state(es);
112- int stride = 0;
113 int buffer_length = 0;
114 int alloc_new_buff = 1;
115 int alignedWidth = 0;
116@@ -776,9 +779,7 @@ g2d_renderer_attach_shm(struct weston_surface *es, struct weston_buffer *buffer,
117 buffer->shm_buffer = shm_buffer;
118 buffer->width = wl_shm_buffer_get_width(shm_buffer);
119 buffer->height = wl_shm_buffer_get_height(shm_buffer);
120- alignedWidth = (buffer->width + 15) & ~15;
121- stride = wl_shm_buffer_get_stride(shm_buffer);
122- buffer_length = stride * buffer->height;
123+ alignedWidth = ALIGN_WIDTH(buffer->width);
124
125 switch (wl_shm_buffer_get_format(shm_buffer)) {
126 case WL_SHM_FORMAT_XRGB8888:
127@@ -812,7 +813,7 @@ g2d_renderer_attach_shm(struct weston_surface *es, struct weston_buffer *buffer,
128 {
129 if(gs->shm_buf)
130 g2d_free(gs->shm_buf);
131- gs->shm_buf = g2d_alloc(buffer_length, 1);
132+ gs->shm_buf = g2d_alloc(buffer_length, 0);
133 gs->g2d_surface.base.planes[0] = gs->shm_buf->buf_paddr;
134 }
135 gs->g2d_surface.base.left = 0;
136@@ -820,7 +821,7 @@ g2d_renderer_attach_shm(struct weston_surface *es, struct weston_buffer *buffer,
137 gs->g2d_surface.base.right = buffer->width;
138 gs->g2d_surface.base.bottom = buffer->height;
139 gs->g2d_surface.base.stride = alignedWidth;
140- gs->g2d_surface.base.width = buffer->width;
141+ gs->g2d_surface.base.width = alignedWidth;
142 gs->g2d_surface.base.height = buffer->height;
143 gs->g2d_surface.base.rot = G2D_ROTATION_0;
144 gs->g2d_surface.base.clrcolor = 0xFF400000;
145@@ -953,7 +954,7 @@ static void
146 g2d_renderer_output_destroy(struct weston_output *output)
147 {
148 struct g2d_output_state *go = get_output_state(output);
149- gctUINT32 i;
150+ int i;
151
152 for (i = 0; i < 2; i++)
153 {
154@@ -1005,8 +1006,12 @@ g2d_renderer_destroy(struct weston_compositor *ec)
155 struct g2d_renderer *gr = get_renderer(ec);
156
157 wl_signal_emit(&gr->destroy_signal, gr);
158- wl_global_destroy(gr->viv_global);
159 g2d_close(gr->handle);
160+#ifdef ENABLE_EGL
161+ eglUnbindWaylandDisplayWL(gr->egl_display);
162+ eglTerminate(gr->egl_display);
163+ fbDestroyDisplay(gr->display);
164+#endif
165 free(ec->renderer);
166 ec->renderer = NULL;
167 }
168@@ -1247,7 +1252,12 @@ g2d_renderer_output_create(struct weston_output *output, struct wl_display *wl_d
169 return -1;
170 go->clone_display_num = clone_display_num;
171 output->renderer_state = go;
172- gr->viv_global = gcoOS_WaylandCreateVivGlobal(wl_display);
173+#ifdef ENABLE_EGL
174+ gr->wl_display = wl_display;
175+ gr->display = fbGetDisplay(wl_display);
176+ gr->egl_display = eglGetDisplay(gr->display);
177+ eglBindWaylandDisplayWL(gr->egl_display, wl_display);
178+#endif
179 getBufferNumber(go);
180
181 if(g2d_renderer_surface_create(go, gr, displays[0]) < 0)
182diff --git a/src/g2d-renderer.h b/src/g2d-renderer.h
183index 45c72de..fc4ca49 100644
184--- a/src/g2d-renderer.h
185+++ b/src/g2d-renderer.h
186@@ -30,6 +30,7 @@
187
188 #ifdef ENABLE_EGL
189 #include <EGL/egl.h>
190+#include <EGL/eglext.h>
191 #endif
192
193 struct g2d_renderer_interface {
194--
1951.9.1
196
diff --git a/recipes-graphics/wayland/weston/0014-MGS-1987-Get-stride-from-the-FB-buffe.patch b/recipes-graphics/wayland/weston/0014-MGS-1987-Get-stride-from-the-FB-buffe.patch
deleted file mode 100644
index a4658a7b..00000000
--- a/recipes-graphics/wayland/weston/0014-MGS-1987-Get-stride-from-the-FB-buffe.patch
+++ /dev/null
@@ -1,76 +0,0 @@
1From 735e58c6066fe1148d803168c6241a4d8cb5c973 Mon Sep 17 00:00:00 2001
2From: "yong.gan" <yong.gan@nxp.com>
3Date: Wed, 6 Jul 2016 08:28:18 +0800
4Subject: [PATCH] MGS-1987: Get stride from the FB buffe.
5
6Fix the stride setting error in the fbinfo.
7
8Date: Jul 6, 2016
9Signed-off-by: Yong Gan <yong.gan@nxp.com>
10---
11 src/g2d-renderer.c | 14 +++++++-------
12 1 file changed, 7 insertions(+), 7 deletions(-)
13
14diff --git a/src/g2d-renderer.c b/src/g2d-renderer.c
15index 0c26e91..30bf1a5 100644
16--- a/src/g2d-renderer.c
17+++ b/src/g2d-renderer.c
18@@ -63,6 +63,7 @@ struct fb_screeninfo {
19 unsigned int y_resolution;
20 size_t buffer_length; /* length of frame buffer memory in bytes */
21 size_t physical;
22+ size_t stride;
23 enum g2d_format pixel_format; /* frame buffer pixel format */
24 int fb_fd;
25 };
26@@ -322,8 +323,6 @@ get_g2dSurface(gcsWL_VIV_BUFFER *buffer, struct g2d_surfaceEx *g2dSurface)
27 weston_log("invalid EGL buffer in function %s\n", __func__);
28 return;
29 }
30- int width = buffer->alignedWidth;
31- int height = buffer->alignedHeight;
32 g2d_getG2dFormat(buffer->format, &g2dSurface->base.format);
33 g2d_getG2dTiling(buffer->tiling, &g2dSurface->tiling);
34 g2dSurface->base.planes[0] = buffer->physical[0] + buffer->gpuBaseAddr;
35@@ -333,9 +332,9 @@ get_g2dSurface(gcsWL_VIV_BUFFER *buffer, struct g2d_surfaceEx *g2dSurface)
36 g2dSurface->base.top = 0;
37 g2dSurface->base.right = buffer->width;
38 g2dSurface->base.bottom = buffer->height;
39- g2dSurface->base.stride = width;
40- g2dSurface->base.width = width;
41- g2dSurface->base.height = height;
42+ g2dSurface->base.stride = buffer->alignedWidth;
43+ g2dSurface->base.width = buffer->width;
44+ g2dSurface->base.height = buffer->height;
45 g2dSurface->base.rot = G2D_ROTATION_0;
46 }
47
48@@ -821,7 +820,7 @@ g2d_renderer_attach_shm(struct weston_surface *es, struct weston_buffer *buffer,
49 gs->g2d_surface.base.right = buffer->width;
50 gs->g2d_surface.base.bottom = buffer->height;
51 gs->g2d_surface.base.stride = alignedWidth;
52- gs->g2d_surface.base.width = alignedWidth;
53+ gs->g2d_surface.base.width = buffer->width;
54 gs->g2d_surface.base.height = buffer->height;
55 gs->g2d_surface.base.rot = G2D_ROTATION_0;
56 gs->g2d_surface.base.clrcolor = 0xFF400000;
57@@ -1079,7 +1078,7 @@ get_G2dSurface_from_screeninfo(struct fb_screeninfo *info, struct g2d_surfaceEx*
58 g2dSurface->base.top = 0;
59 g2dSurface->base.right = info->x_resolution;
60 g2dSurface->base.bottom = info->y_resolution;
61- g2dSurface->base.stride = info->x_resolution;
62+ g2dSurface->base.stride = info->stride;
63 g2dSurface->base.width = info->x_resolution;
64 g2dSurface->base.height = info->y_resolution;
65 g2dSurface->base.format = info->pixel_format;
66@@ -1119,6 +1118,7 @@ fb_query_screen_info(struct g2d_output_state *output, int fd,
67 info->y_resolution = varinfo->yres;
68 info->physical = fixinfo->smem_start;
69 info->buffer_length = fixinfo->smem_len;
70+ info->stride = fixinfo->line_length / (varinfo->bits_per_pixel >> 3);
71 calculate_g2d_format(varinfo, &info->pixel_format);
72
73 if (info->pixel_format < 0) {
74--
751.9.1
76
diff --git a/recipes-graphics/wayland/weston/0015-MGS-2221-imx-171-Fix-weston-build-failed.patch b/recipes-graphics/wayland/weston/0015-MGS-2221-imx-171-Fix-weston-build-failed.patch
deleted file mode 100644
index 3f851eed..00000000
--- a/recipes-graphics/wayland/weston/0015-MGS-2221-imx-171-Fix-weston-build-failed.patch
+++ /dev/null
@@ -1,62 +0,0 @@
1From 66a40759e44998edecf242bc100be0fcdd62937e Mon Sep 17 00:00:00 2001
2From: Yong Gan <yong.gan@nxp.com>
3Date: Thu, 1 Sep 2016 09:36:33 +0800
4Subject: [PATCH] MGS-2221 [#imx-171] Fix weston build failed
5
6Expose more variale to G2d compositor, because it is not easy to get the physical address
7in G2d compositor.
8
9Upstream Status: Inappropriate [i.MX specific]
10
11Date: Aug 31, 2016
12Signed-off-by: Yong Gan <yong.gan@nxp.com>
13---
14 src/g2d-renderer.c | 18 ++++++++++++++++--
15 1 file changed, 16 insertions(+), 2 deletions(-)
16
17diff --git a/src/g2d-renderer.c b/src/g2d-renderer.c
18index 30bf1a5..1009115 100644
19--- a/src/g2d-renderer.c
20+++ b/src/g2d-renderer.c
21@@ -48,6 +48,20 @@
22 #define BUFFER_DAMAGE_COUNT 2
23 #define ALIGN_WIDTH(a) (((a) + 15) & ~15)
24
25+struct wl_viv_buffer
26+{
27+ struct wl_resource *resource;
28+ gcoSURF surface;
29+ gctINT32 width;
30+ gctINT32 height;
31+ gctINT32 format;
32+ gctUINT alignedWidth;
33+ gctUINT alignedHeight;
34+ gctUINT32 physical[3];
35+ gctUINT32 gpuBaseAddr;
36+ gceTILING tiling;
37+};
38+
39 typedef struct _g2dRECT
40 {
41 int left;
42@@ -316,7 +330,7 @@ static void printG2dSurfaceInfo(struct g2d_surfaceEx* g2dSurface, const char* ms
43 }
44
45 static void
46-get_g2dSurface(gcsWL_VIV_BUFFER *buffer, struct g2d_surfaceEx *g2dSurface)
47+get_g2dSurface(struct wl_viv_buffer *buffer, struct g2d_surfaceEx *g2dSurface)
48 {
49 if(buffer->width < 0 || buffer->height < 0)
50 {
51@@ -687,7 +701,7 @@ g2d_renderer_repaint_output(struct weston_output *output,
52 static void
53 g2d_renderer_attach_egl(struct weston_surface *es, struct weston_buffer *buffer)
54 {
55- gcsWL_VIV_BUFFER *vivBuffer = wl_resource_get_user_data(buffer->resource);
56+ struct wl_viv_buffer *vivBuffer = wl_resource_get_user_data(buffer->resource);
57 struct g2d_surface_state *gs = get_surface_state(es);
58 buffer->width = vivBuffer->width;
59 buffer->height = vivBuffer->height;
60--
611.9.1
62
diff --git a/recipes-graphics/wayland/weston/0017-MGS-2343-ccc-XWLD-T3DStressTest_Wayland-displays-abn.patch b/recipes-graphics/wayland/weston/0017-MGS-2343-ccc-XWLD-T3DStressTest_Wayland-displays-abn.patch
deleted file mode 100644
index d0b82aa4..00000000
--- a/recipes-graphics/wayland/weston/0017-MGS-2343-ccc-XWLD-T3DStressTest_Wayland-displays-abn.patch
+++ /dev/null
@@ -1,40 +0,0 @@
1From 0cc335a411127feb05e16cbf2803058b2db1b405 Mon Sep 17 00:00:00 2001
2From: Meng Mingming <mingming.meng@nxp.com>
3Date: Thu, 27 Oct 2016 17:00:24 +0800
4Subject: [PATCH 1/2] MGS-2343 [#ccc] XWLD: T3DStressTest_Wayland displays
5 abnormally while using G2D compositor
6
7It need add g2d_finish after repaint_region and before copy to framebuffer.
8Because if using dual dpu cores, the tasks on each core will be executed
9sequently, but it can't ensure one task splited on dual cores can be finished
10synchronously by hardware.
11
12Upstream-Status: Inappropriate [i.MX specific]
13
14Date: Oct 27, 2016
15Signed-off-by: Meng Mingming <mingming.meng@nxp.com>
16---
17 src/g2d-renderer.c | 1 +
18 1 file changed, 1 insertion(+)
19
20Index: weston-1.11.0/src/g2d-renderer.c
21===================================================================
22--- weston-1.11.0.orig/src/g2d-renderer.c 2017-01-12 14:58:11.923607788 -0600
23+++ weston-1.11.0/src/g2d-renderer.c 2017-01-12 18:08:33.328243476 -0600
24@@ -679,6 +679,8 @@
25 pixman_region32_t *output_damage)
26 {
27 struct g2d_output_state *go = get_output_state(output);
28+ struct weston_compositor *compositor = output->compositor;
29+ struct g2d_renderer *gr = get_renderer(compositor);
30 int i;
31
32 use_output(output);
33@@ -691,6 +693,7 @@
34 &go->buffer_damage[go->current_buffer]);
35
36 repaint_views(output, output_damage);
37+ g2d_finish(gr->handle);
38
39 pixman_region32_copy(&output->previous_damage, output_damage);
40 wl_signal_emit(&output->frame_signal, output);
diff --git a/recipes-graphics/wayland/weston/0018-MGS-2397-ccc-Enable-double-buffer-with-fb_pan_displa.patch b/recipes-graphics/wayland/weston/0018-MGS-2397-ccc-Enable-double-buffer-with-fb_pan_displa.patch
deleted file mode 100644
index 4ce18710..00000000
--- a/recipes-graphics/wayland/weston/0018-MGS-2397-ccc-Enable-double-buffer-with-fb_pan_displa.patch
+++ /dev/null
@@ -1,48 +0,0 @@
1From 270319565a07f7ceeb12fac1c267d0dd9ebf2d57 Mon Sep 17 00:00:00 2001
2From: Meng Mingming <mingming.meng@nxp.com>
3Date: Wed, 16 Nov 2016 15:05:51 +0800
4Subject: [PATCH 17/17] MGS-2397 [#ccc] Enable double buffer with
5 fb_pan_display for weston compositor
6
7Refine offset calculation.
8
9Upstream-Status: Inappropriate [i.MX specific]
10
11Date: Nov 16, 2016
12Signed-off-by: Meng Mingming <mingming.meng@nxp.com>
13---
14 src/g2d-renderer.c | 4 +++-
15 1 file changed, 3 insertions(+), 1 deletion(-)
16
17diff --git a/src/g2d-renderer.c b/src/g2d-renderer.c
18index 41c4d9e..c30aa62 100644
19--- a/src/g2d-renderer.c
20+++ b/src/g2d-renderer.c
21@@ -78,6 +78,7 @@ struct fb_screeninfo {
22 size_t buffer_length; /* length of frame buffer memory in bytes */
23 size_t physical;
24 size_t stride;
25+ size_t stride_bytes;
26 enum g2d_format pixel_format; /* frame buffer pixel format */
27 int fb_fd;
28 };
29@@ -1136,6 +1137,7 @@ fb_query_screen_info(struct g2d_output_state *output, int fd,
30 info->physical = fixinfo->smem_start;
31 info->buffer_length = fixinfo->smem_len;
32 info->stride = fixinfo->line_length / (varinfo->bits_per_pixel >> 3);
33+ info->stride_bytes = fixinfo->line_length;
34 calculate_g2d_format(varinfo, &info->pixel_format);
35
36 if (info->pixel_format < 0) {
37@@ -1205,7 +1207,7 @@ g2d_renderer_surface_create(struct g2d_output_state *go, struct g2d_renderer *gr
38 return -1;
39 }
40 go->renderSurf = zalloc(sizeof(struct g2d_surfaceEx) * go->nNumBuffers);
41- offset = go->fb_info.buffer_length/go->nNumBuffers;
42+ offset = go->fb_info.stride_bytes * go->fb_info.y_resolution;
43 for(i = 0; i < go->nNumBuffers; i++)
44 {
45 get_G2dSurface_from_screeninfo(&go->fb_info, &go->renderSurf[i]);
46--
472.7.4
48
diff --git a/recipes-graphics/wayland/weston_%.bbappend b/recipes-graphics/wayland/weston_%.bbappend
index 26b12dcd..74d2359e 100644
--- a/recipes-graphics/wayland/weston_%.bbappend
+++ b/recipes-graphics/wayland/weston_%.bbappend
@@ -1,27 +1,16 @@
1FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" 1FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
2 2
3SRC_URI_append_imxgpu3d = " \ 3SRC_URI_append_imxgpu3d = " \
4 file://0002-MGS-1111-Add-GPU-VIV-suport-for-wayland-and-weston-1.patch \ 4 file://0001-MGS-2352-ccc-Add-GPU-VIV-support-for-weston-1.11.patch \
5 file://0003-MGS-1192-xwld-g2d-compositor-dose-not-work.patch \ 5 file://0002-MGS-2521-ccc-Enable-g2d-renderer-for-weston-1.11.patch \
6 file://0004-MGS-1235-Fix-setenv-and-clear-environments.patch \ 6 file://0003-MGS-1783-xwld-Add-clone-mode-support-for-multi-displ.patch \
7 file://0005-MGS-1252-Fix-for-Qt5_CinematicExperience-will-meet-s.patch \ 7 file://0004-MGS-1668-xwld-System-can-not-boot-up-to-desktop.patch \
8 file://0006-MGS-1236-imx6qp-imx6dl-First-frame-distored-when-som.patch \ 8 file://0005-MGS-1724-xwld-G2D-compositor-build-failed-in-slevk-b.patch \
9 file://0007-MGS-1236-1-imx6qp-imx6dl-First-frame-distored-when-s.patch \ 9 file://0006-Link-compositor-to-egl.patch \
10 file://0009-MGS-1284-xwld-Re-implement-weston-2d-renderer-with-p.patch \
11 file://0010-MGS-1284-1-xwld-Re-implement-weston-2d-renderer-with.patch \
12 file://0011-MGS-1724-xwld-G2D-compositor-build-failed-in-slevk-b.patch \
13 file://0012-MGS-1783-xwld-Add-clone-mode-support-for-multi-displ.patch \
14 file://0013-MGS-1945-Use-common-API-to-support-G2d-compositor.patch \
15 file://0014-MGS-1987-Get-stride-from-the-FB-buffe.patch \
16 file://0015-MGS-2221-imx-171-Fix-weston-build-failed.patch \
17 file://0016-Link-compositor-to-egl.patch \
18 file://0017-MGS-2343-ccc-XWLD-T3DStressTest_Wayland-displays-abn.patch \
19 file://0018-MGS-2397-ccc-Enable-double-buffer-with-fb_pan_displa.patch \
20 file://0019-MGS-1668-xwld-System-can-not-boot-up-to-desktop.patch \
21" 10"
22 11
23SRC_URI_append = " \ 12SRC_URI_append = " \
24 file://0020-xwayland-Fix-crash-when-run-with-no-input-device.patch \ 13 file://0007-xwayland-Fix-crash-when-run-with-no-input-device.patch \
25" 14"
26 15
27# The 'egl' configuration of weston requires gles support, and consideration 16# The 'egl' configuration of weston requires gles support, and consideration