summaryrefslogtreecommitdiffstats
path: root/recipes-graphics/wayland/weston/0012-MGS-1783-xwld-Add-clone-mode-support-for-multi-displ.patch
blob: e504d677068e6373e199812eefd4c85cfe1aac21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
From f2025a7e8c178b8c52c2ca553459a7fea6caf5c8 Mon Sep 17 00:00:00 2001
From: "yong.gan" <yong.gan@nxp.com>
Date: Tue, 17 May 2016 09:10:50 +0800
Subject: [PATCH 1/2] MGS-1783: xwld: Add clone mode support for multi display
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Support showing the same contents on multiple displays.
Use the following command to enable multi-display:
    openvt -v -- weston-launch -- --idle-time=0 --use-g2d=1 --device=/dev/fb0,/dev/fb4 --clone-mode --log=/var/log/weston.log

Upstream-Status: Inappropriate [i.MX specific]
Date: May 16, 2016
Signed-off-by: Yong Gan <yong.gan@nxp.com>
---
 src/compositor-fbdev.c |  33 +++++++---
 src/g2d-renderer.c     | 171 ++++++++++++++++++++++++++++++++++++++++---------
 src/g2d-renderer.h     |   4 +-
 3 files changed, 167 insertions(+), 41 deletions(-)

Index: weston-1.11.1/src/compositor-fbdev.c
===================================================================
--- weston-1.11.1.orig/src/compositor-fbdev.c	2017-01-16 13:23:48.925264352 -0600
+++ weston-1.11.1/src/compositor-fbdev.c	2017-01-16 13:23:49.013264789 -0600
@@ -61,6 +61,8 @@
 	struct udev_input input;
 	int use_pixman;
 	int use_g2d;
+	int clone_mode;
+	char *clone_device;
 	uint32_t output_transform;
 	struct wl_listener session_listener;
 #ifdef ENABLE_EGL
@@ -525,12 +527,15 @@
 		if (pixman_renderer_output_create(&output->base) < 0)
 			goto out_hw_surface;
 	} else if(backend->use_g2d) {
+		const char *g2d_device = device;
+		if (backend->clone_mode)
+			g2d_device = backend->clone_device;
+
 		if (g2d_renderer->output_create(&output->base,
-					backend->compositor->wl_display, device) < 0) {
+					backend->compositor->wl_display, g2d_device) < 0) {
 			weston_log("g2d_renderer_output_create failed.\n");
 			goto out_hw_surface;
 		}
-
 	} else {
 #ifdef ENABLE_EGL
 		setenv("HYBRIS_EGLPLATFORM", "wayland", 1);
@@ -803,6 +808,8 @@
 	backend->prev_state = WESTON_COMPOSITOR_ACTIVE;
 	backend->use_pixman = !(param->use_gl || param->use_g2d);
 	backend->use_g2d = param->use_g2d;
+	backend->clone_mode = param->clone_mode;
+	backend->clone_device = param->device;
 	backend->output_transform = param->output_transform;
 
 	weston_setup_vt_switch_bindings(compositor);
@@ -844,16 +851,21 @@
 		displays[dispCount][k] = '\0';
 		dispCount++;
 
-		for(i=0; i<dispCount; i++)
-		{
-			if (fbdev_output_create(backend, x, y, displays[i]) < 0)
+		if(backend->clone_mode){
+			if (fbdev_output_create(backend, x, y, displays[0]) < 0)
 				goto out_launcher;
-			x += container_of(backend->compositor->output_list.prev,
-								  struct weston_output,
-								  link)->width;
+		}
+		else{
+			for(i= 0; i < dispCount; i++){
+				if (fbdev_output_create(backend, x, y, displays[i]) < 0)
+					goto out_launcher;
+				x += container_of(backend->compositor->output_list.prev,
+						struct weston_output,
+						link)->width;
+			}
 		}
 	}
-	 else {
+	else {
 #ifdef ENABLE_EGL
 		gl_renderer = weston_load_module("gl-renderer.so",
 						 "gl_renderer_interface");
Index: weston-1.11.1/src/g2d-renderer.c
===================================================================
--- weston-1.11.1.orig/src/g2d-renderer.c	2017-01-16 13:23:48.925264352 -0600
+++ weston-1.11.1/src/g2d-renderer.c	2017-01-16 13:26:17.000000000 -0600
@@ -37,15 +37,16 @@
 #include <sys/ioctl.h>
 #include <fcntl.h>
 #include <unistd.h>
+#include <g2dExt.h>
+#include <HAL/gc_hal_eglplatform.h>
 
 #include "compositor.h"
 #include "g2d-renderer.h"
 #include "vertex-clipping.h"
 #include "shared/helpers.h"
-#include "HAL/gc_hal_eglplatform.h"
-#include "g2dExt.h"
 
 #define BUFFER_DAMAGE_COUNT 2
+extern struct wl_global* gcoOS_WaylandCreateVivGlobal(struct wl_display* display);
 
 typedef struct _g2dRECT
 {
@@ -63,6 +64,7 @@
 	size_t buffer_length; /* length of frame buffer memory in bytes */
 	size_t physical;
 	enum g2d_format pixel_format; /* frame buffer pixel format */
+	int fb_fd;
 };
 
 struct g2d_output_state {
@@ -74,10 +76,12 @@
 	struct g2d_surfaceEx offscreenSurface;
 	struct g2d_buf *offscreen_buf;
 	struct fb_screeninfo fb_info;
+	struct fb_screeninfo *mirror_fb_info;
+	struct g2d_surfaceEx *mirrorSurf;
 	int directBlit;
+	int clone_display_num;
 	int width;
 	int height;
-	int fb_fd;
 };
 
 struct g2d_surface_state {
@@ -366,7 +370,7 @@
 	struct g2d_output_state *go = get_output_state(output);
 	go->fb_info.varinfo.yoffset  = go->activebuffer * go->fb_info.y_resolution;
 
-	if(ioctl(go->fb_fd, FBIOPAN_DISPLAY, &(go->fb_info.varinfo)) < 0)
+	if(ioctl(go->fb_info.fb_fd, FBIOPAN_DISPLAY, &(go->fb_info.varinfo)) < 0)
 	{
 		weston_log("FBIOPAN_DISPLAY Failed\n");
 	}
@@ -388,6 +392,28 @@
 			&go->renderSurf[go->activebuffer], &srcRect, &dstrect);
 	}
 
+	if(go->clone_display_num)
+	{
+		int i = 0;
+		for(i = 0; i < go->clone_display_num; i++)
+		{
+			g2dRECT srcRect  = {0, 0, go->renderSurf[go->activebuffer].base.width, go->renderSurf[go->activebuffer].base.height};
+			g2dRECT dstrect  = {0, 0, go->mirrorSurf[i].base.width, go->mirrorSurf[i].base.height};
+			g2dRECT clipRect = srcRect;
+			g2d_set_clipping(gr->handle, clipRect.left, clipRect.top, clipRect.right, clipRect.bottom);
+			if(go->directBlit || go->nNumBuffers > 1)
+			{
+				g2d_blitSurface(gr->handle, &go->renderSurf[go->activebuffer],
+				&go->mirrorSurf[i], &srcRect, &dstrect);
+			}
+			else
+			{
+				g2d_blitSurface(gr->handle, &go->offscreenSurface,
+					&go->mirrorSurf[i], &srcRect, &dstrect);
+			}
+		}
+	}
+
 	g2d_finish(gr->handle);
 
 	if(go->nNumBuffers > 1)
@@ -940,10 +966,10 @@
 		go->offscreen_buf = NULL;
 	}
 
-	if(go->fb_fd)
+	if(go->fb_info.fb_fd)
 	{
-		close(go->fb_fd);
-		go->fb_fd = 0;
+		close(go->fb_info.fb_fd);
+		go->fb_info.fb_fd = 0;
 	}
 
 	if(go->renderSurf)
@@ -951,6 +977,24 @@
 		free(go->renderSurf);
 		go->renderSurf = NULL;
 	}
+	for (i = 0; i < go->clone_display_num; i++)
+	{
+		if(go->mirror_fb_info[i].fb_fd)
+		{
+			close(go->mirror_fb_info[i].fb_fd);
+			go->mirror_fb_info[i].fb_fd = 0;
+		}
+	}
+	if(go->mirrorSurf)
+	{
+		free(go->mirrorSurf);
+		go->mirrorSurf = NULL;
+	}
+	if(go->mirror_fb_info)
+	{
+		free(go->mirror_fb_info);
+		go->mirror_fb_info = NULL;
+	}
 
 	free(go);
 }
@@ -1085,39 +1129,27 @@
                         struct fb_screeninfo *screen_info)
 {
 	/* Open the frame buffer device. */
-	output->fb_fd = open(fb_dev, O_RDWR | O_CLOEXEC);
-	if (output->fb_fd < 0) {
+	screen_info->fb_fd = open(fb_dev, O_RDWR | O_CLOEXEC);
+	if (screen_info->fb_fd < 0) {
 		weston_log("Failed to open frame buffer device%s \n", fb_dev);
 		return -1;
 	}
 
 	/* Grab the screen info. */
-	if (fb_query_screen_info(output, output->fb_fd, screen_info) < 0) {
+	if (fb_query_screen_info(output, screen_info->fb_fd, screen_info) < 0) {
 		weston_log("Failed to get frame buffer info \n");
 
-		close(output->fb_fd);
+		close(screen_info->fb_fd);
 		return -1;
 	}
 
 	return 0;
 }
 
-static int
-g2d_renderer_output_create(struct weston_output *output, struct wl_display *wl_display, const char *device)
-
- {
-	struct g2d_renderer *gr = get_renderer(output->compositor);
-	struct g2d_output_state *go;
-	int i = 0;
-	int offset = 0;
+static void
+getBufferNumber(struct g2d_output_state *go)
+{
 	char *p = NULL;
-	go = zalloc(sizeof *go);
-	if (go == NULL)
-		return -1;
-
-	output->renderer_state = go;
-	gr->viv_global = gcoOS_WaylandCreateVivGlobal(wl_display);
-
 	p = getenv("FB_MULTI_BUFFER");
 	if (p == gcvNULL)
 	{
@@ -1126,7 +1158,7 @@
 	else
 	{
 		go->nNumBuffers = atoi(p);
-		if (go->nNumBuffers < 1)
+		if (go->nNumBuffers < 2)
 		{
 			go->nNumBuffers  = 1;
 		}
@@ -1137,13 +1169,19 @@
 		}
 	}
 	weston_log("FB_MULTI_BUFFER = %d\n", go->nNumBuffers);
+}
 
+static int
+g2d_renderer_surface_create(struct g2d_output_state *go, struct g2d_renderer *gr, const char *device)
+{
+	int i = 0;
+	int offset = 0;
+	weston_log("Opend device=%s\n", device);
 	if(fb_frame_buffer_open(go, device, &go->fb_info) < 0)
 	{
 		weston_log("Open frame buffer failed.\n");
 		return -1;
 	}
-
 	go->renderSurf = zalloc(sizeof(struct g2d_surfaceEx) * go->nNumBuffers);
 	offset = go->fb_info.buffer_length/go->nNumBuffers;
 	for(i = 0; i < go->nNumBuffers; i++)
@@ -1161,9 +1199,84 @@
 		go->offscreenSurface.base.planes[0] = go->offscreen_buf->buf_paddr;
 		g2d_clear(gr->handle, &go->offscreenSurface.base);
 	}
+	return 0;
+}
+
+static int
+g2d_renderer_output_create(struct weston_output *output, struct wl_display *wl_display, const char *device)
 
+ {
+	struct g2d_renderer *gr = get_renderer(output->compositor);
+	struct g2d_output_state *go;
+	int i;
+	int clone_display_num = 0;
+	int count = 0;
+	int k=0, dispCount = 0;
+	char displays[5][32];
+	weston_log("g2d_renderer_output_create device=%s\n", device);
+	count = strlen(device);
+
+	if(count > 0)
+	{
+		for(i= 0; i < count; i++)
+		{
+			if(device[i] == ',')
+			{
+				displays[dispCount][k] = '\0';
+				dispCount++;
+				k = 0;
+				continue;
+			}
+			else if(device[i] != ' ')
+			{
+				displays[dispCount][k++] = device[i];
+			}
+		}
+		displays[dispCount][k] = '\0';
+		clone_display_num = dispCount++;
+		weston_log("clone_display_num = %d\n", clone_display_num);
+	}
+	else
+	{
+		weston_log("Invalid device name\n");
+		return -1;
+	}
+
+	go = zalloc(sizeof *go);
+	if (go == NULL)
+		return -1;
+	go->clone_display_num  = clone_display_num;
+	output->renderer_state = go;
+	gr->viv_global = gcoOS_WaylandCreateVivGlobal(wl_display);
+	getBufferNumber(go);
+
+	if(g2d_renderer_surface_create(go, gr, displays[0]) < 0)
+	{
+		weston_log("Create Render surface failed.\n");
+		return -1;
+	}
+
+	if(go->clone_display_num)
+	{
+		go->mirrorSurf = zalloc(sizeof(struct g2d_surfaceEx) * clone_display_num);
+		go->mirror_fb_info = zalloc(sizeof(struct fb_screeninfo) * clone_display_num);
+		if(go->mirrorSurf == NULL || go->mirror_fb_info == NULL)
+			return -1;
+
+		for(i = 0; i < clone_display_num; i++)
+		{
+			if(fb_frame_buffer_open(go, displays[i + 1], &go->mirror_fb_info[i]) < 0)
+			{
+				weston_log("Open frame buffer failed.\n");
+				return -1;
+			}
+			get_G2dSurface_from_screeninfo(&go->mirror_fb_info[i], &go->mirrorSurf[i]);
+			go->mirrorSurf[i].base.planes[0] = go->mirror_fb_info[i].physical;
+			g2d_clear(gr->handle, &go->mirrorSurf[i].base);
+		}
+	}
 	g2d_finish(gr->handle);
-	for (i = 0; i < 2; i++)
+	for (i = 0; i < BUFFER_DAMAGE_COUNT; i++)
 		pixman_region32_init(&go->buffer_damage[i]);
     return 0;
  }
Index: weston-1.11.1/src/g2d-renderer.h
===================================================================
--- weston-1.11.1.orig/src/g2d-renderer.h	2017-01-16 13:23:48.757263519 -0600
+++ weston-1.11.1/src/g2d-renderer.h	2017-01-16 13:26:17.000000000 -0600
@@ -27,13 +27,11 @@
 #define __g2d_renderer_h_
 
 #include  "compositor.h"
+
 #ifdef ENABLE_EGL
 #include <EGL/egl.h>
-#else
-#include <HAL/gc_hal_eglplatform.h>
 #endif
 
-
 struct g2d_renderer_interface {
 
 	int (*create)(struct weston_compositor *ec);
Index: weston-1.11.1/src/main.c
===================================================================
--- weston-1.11.1.orig/src/main.c	2017-01-16 13:23:48.929264372 -0600
+++ weston-1.11.1/src/main.c	2017-01-16 13:32:49.000000000 -0600
@@ -287,11 +287,12 @@
 		"  --device=DEVICE\tThe framebuffer device to use\n"
 #if defined ENABLE_EGL
 		"  --use-gl=1\t\tUse the GL renderer (default is 1)\n"
-		"  --use-g2d=1\t\tUse the G2D renderer (default is 0)\n\n");
+		"  --use-g2d=1\t\tUse the G2D renderer (default is 0)\n"
 #else
 		"  --use-gl=1\t\tUse the GL renderer (default is 0)\n"
-		"  --use-g2d=1\t\tUse the G2D renderer (default is 1)\n\n");
+		"  --use-g2d=1\t\tUse the G2D renderer (default is 1)\n"
 #endif
+		"  --clone-mode\t\tClone display to multiple devices\n\n");
 #endif
 
 #if defined(BUILD_HEADLESS_COMPOSITOR)
@@ -886,6 +887,7 @@
 		{ WESTON_OPTION_STRING, "device", 0, &config.device },
 		{ WESTON_OPTION_INTEGER, "use-gl", 0, &config.use_gl },
 		{ WESTON_OPTION_INTEGER, "use-g2d", 0, &config.use_g2d },
+		{ WESTON_OPTION_BOOLEAN, "clone-mode", 0, &config.clone_mode },
 	};
 
 	parse_options(fbdev_options, ARRAY_LENGTH(fbdev_options), argc, argv);