1 From b6d084f68434fea7402d4989d4d8344523b1a939 Mon Sep 17 00:00:00 2001
2 From: Harunobu Kurokawa <harunobu.kurokawa.dn@renesas.com>
3 Date: Thu, 10 Aug 2017 15:42:38 +0900
4 Subject: [PATCH 1/4] Add virtual output support
6 This patch is ported to weston 2.0.0.
9 Author: Damian Hobson-Garcia <dhobsong@igel.co.jp>
10 Date: Thu Apr 27 16:47:00 2017 +0900
12 Following patch ported to Weston 1.11 with minor updates
14 Author: Grigory Kletsko <grigory.kletsko@cogentembedded.com>
15 Date: Wed Nov 2 17:14:43 2016 +0300
17 To enable virtual output set "virtual" property in core section
18 to desirable number of virtual outputs. Then add settings to
19 each virtual output in output sections. Name of the outputs
20 will be virtual1, virtual2... etc.
23 libweston/compositor-drm.c | 352 +++++++++++++++++++++++++++++++++++++++++++++
24 libweston/compositor-drm.h | 1 +
25 2 files changed, 353 insertions(+)
27 diff --git a/libweston/compositor-drm.c b/libweston/compositor-drm.c
28 index 1d38f05..d0f07e9 100644
29 --- a/libweston/compositor-drm.c
30 +++ b/libweston/compositor-drm.c
31 @@ -182,6 +182,11 @@ struct drm_output {
33 struct vaapi_recorder *recorder;
34 struct wl_listener recorder_frame_listener;
36 + /* not real output device */
38 + /* Timer for updating frame */
39 + struct wl_event_source *virtual_finish_frame_timer;
43 @@ -211,6 +216,9 @@ struct drm_sprite {
45 static struct gl_renderer_interface *gl_renderer;
48 +recorder_enable(struct drm_backend *b, struct drm_output *output);
50 static const char default_seat[] = "seat0";
52 static inline struct drm_output *
53 @@ -2347,6 +2355,99 @@ connector_get_current_mode(drmModeConnector *connector, int drm_fd,
57 +virtual_output_set_mode(struct weston_output *base,
58 + enum weston_drm_backend_output_mode mode,
59 + const char *modeline)
61 + struct drm_output *output = to_drm_output(base);
62 + struct drm_backend *b = to_drm_backend(base->compositor);
63 + struct weston_config *config = wet_get_config(b->compositor);
65 + struct drm_mode *drm_mode, *next, *current;
68 + int recorded_output;
69 + int width, height, scale, fps;
70 + struct weston_config_section *section;
72 + drmModeModeInfo crtc_mode;
74 + output->base.make = "CogentEmbedded,Inc";
76 + section = weston_config_get_section(config, "output", "name",
79 + weston_config_section_get_bool(section, "recorder", &recorded_output, 0);
81 + if (recorded_output) {
82 + output->base.model = "Virtual RTP Display";
84 + output->base.model = "Virtual Display";
87 + output->base.serial_number = "";
88 + wl_list_init(&output->base.mode_list);
90 + if (mode == WESTON_DRM_BACKEND_OUTPUT_PREFERRED) {
91 + if (modeline && sscanf(modeline, "%dx%d@%d", &width, &height, &fps) >= 3)
95 + weston_config_section_get_int(section, "scale", &scale, 1);
96 + weston_config_section_get_string(section, "transform", &s, "normal");
97 + if (weston_parse_transform(s, &transform) < 0)
98 + weston_log("Invalid transform \"%s\" for output %s\n",
99 + s, output->base.name);
102 + weston_config_section_get_string(section, "seat", &s, "");
105 + output->original_crtc = NULL;
106 + output->dpms_prop = NULL;
108 + /* set static mode */
110 + /* TODO: calculate proper mode settings to get desirable framerate */
111 + drmModeModeInfo static_drm_mode = {
112 + width * height * fps,
113 + width, 0, 0, width, width,
114 + height, 0, 0, height, height,
120 + drm_mode = drm_output_add_mode(output, &static_drm_mode);
124 + drm_mode->base.refresh = fps * 1000;
127 + current = drm_output_choose_initial_mode(b, output, mode, &modeline,
131 + output->base.current_mode = ¤t->base;
132 + output->base.current_mode->flags |= WL_OUTPUT_MODE_CURRENT;
137 + drmModeFreeCrtc(output->original_crtc);
138 + output->original_crtc = NULL;
140 + wl_list_for_each_safe(drm_mode, next, &output->base.mode_list,
142 + wl_list_remove(&drm_mode->base.link);
150 drm_output_set_mode(struct weston_output *base,
151 enum weston_drm_backend_output_mode mode,
152 const char *modeline)
153 @@ -2357,6 +2458,8 @@ drm_output_set_mode(struct weston_output *base,
154 struct drm_mode *drm_mode, *next, *current;
155 drmModeModeInfo crtc_mode;
157 + if ( output->virtual == 1 )
158 + return virtual_output_set_mode(base, mode, modeline);
160 output->base.make = "unknown";
161 output->base.model = "unknown";
162 @@ -2453,6 +2556,10 @@ drm_output_enable(struct weston_output *base)
163 weston_log("Failed to initialize backlight\n");
166 + /* enable GST recording-streaming */
167 + if (b->enable_recorder)
168 + recorder_enable(b, output);
170 output->base.start_repaint_loop = drm_output_start_repaint_loop;
171 output->base.repaint = drm_output_repaint;
172 output->base.assign_planes = drm_assign_planes;
173 @@ -2630,6 +2737,227 @@ create_output_for_connector(struct drm_backend *b,
177 +virtual_output_deinit(struct weston_output *base)
179 + struct drm_output *output = to_drm_output(base);
180 + struct drm_backend *b = to_drm_backend(base->compositor);
183 + drm_output_fini_pixman(output);
185 + drm_output_fini_egl(output);
187 + weston_plane_release(&output->fb_plane);
188 + weston_plane_release(&output->cursor_plane);
192 +virtual_output_destroy(struct weston_output *base)
194 + struct drm_output *output = to_drm_output(base);
196 + if (output->base.enabled)
197 + virtual_output_deinit(&output->base);
199 + weston_output_destroy(&output->base);
205 +virtual_output_start_repaint_loop(struct weston_output *output)
207 + struct timespec now;
209 + weston_compositor_read_presentation_clock(output->compositor, &now);
210 + weston_output_finish_frame(output, &now, WP_PRESENTATION_FEEDBACK_INVALID);
215 +virtual_output_repaint(struct weston_output *output_base,
216 + pixman_region32_t *damage)
218 + struct drm_output *output = (struct drm_output *) output_base;
219 + struct timespec ts;
220 + uint32_t msec_next;
221 + uint32_t msec_current;
223 + msec_next = (output->base.frame_time + 1000000UL / output->base.current_mode->refresh) ;
225 + if (output->disable_pending || output->destroy_pending)
229 + drm_output_render(output, damage);
233 + drm_output_set_cursor(output);
235 + output->page_flip_pending = 1;
237 + weston_compositor_read_presentation_clock(output_base->compositor, &ts);
239 + msec_current = ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
242 + * If we somehow late with updating frame, then fireup timer immediately (1 msec)
244 + wl_event_source_timer_update(output->virtual_finish_frame_timer, (msec_next > msec_current) ?
245 + msec_next - msec_current : 1);
251 +virtual_finish_frame_handler(void *data)
253 + struct drm_output *output = (struct drm_output *) data;
254 + struct timespec ts;
256 + /* We don't set page_flip_pending on start_repaint_loop, in that case
257 + * we just want to page flip to the current buffer to get an accurate
259 + if (output->page_flip_pending) {
260 + drm_output_release_fb(output, output->current);
261 + output->current = output->next;
262 + output->next = NULL;
265 + output->page_flip_pending = 0;
267 + if (output->destroy_pending)
268 + drm_output_destroy(&output->base);
269 + else if (!output->vblank_pending) {
270 + weston_compositor_read_presentation_clock(output->base.compositor, &ts);
272 + weston_output_finish_frame(&output->base, &ts,
273 + WP_PRESENTATION_FEEDBACK_INVALID);
275 + /* We can't call this from frame_notify, because the output's
276 + * repaint needed flag is cleared just after that */
277 + if (output->recorder)
278 + weston_output_schedule_repaint(&output->base);
285 +virtual_output_enable(struct weston_output *base)
287 + struct drm_output *output = to_drm_output(base);
288 + struct drm_backend *b = to_drm_backend(base->compositor);
289 + struct weston_mode *m;
291 + if (b->use_pixman) {
292 + if (drm_output_init_pixman(output, b) < 0) {
293 + weston_log("Failed to init output pixman state\n");
296 + } else if (drm_output_init_egl(output, b) < 0) {
297 + weston_log("Failed to init output gl state\n");
301 + output->base.start_repaint_loop = virtual_output_start_repaint_loop;
302 + output->base.repaint = virtual_output_repaint;
303 + output->base.assign_planes = NULL;
304 + output->base.set_dpms = NULL;
305 + output->base.switch_mode = drm_output_switch_mode;
307 + output->base.gamma_size = 0;
308 + output->base.set_gamma = drm_output_set_gamma;
310 + output->base.subpixel = WL_OUTPUT_SUBPIXEL_NONE; //drm_subpixel_to_wayland(connector->subpixel);
312 + weston_plane_init(&output->cursor_plane, b->compositor,
313 + INT32_MIN, INT32_MIN);
314 + weston_plane_init(&output->fb_plane, b->compositor, 0, 0);
316 + weston_compositor_stack_plane(b->compositor, &output->cursor_plane, NULL);
317 + weston_compositor_stack_plane(b->compositor, &output->fb_plane,
318 + &b->compositor->primary_plane);
320 + weston_log("Output %s, ()\n",
321 + output->base.name);
322 + wl_list_for_each(m, &output->base.mode_list, link)
323 + weston_log_continue(STAMP_SPACE "mode %dx%d@%.1f\n",
324 + m->width, m->height, m->refresh / 1000.0);
326 + /* enable GST recording-streaming */
327 + if (b->enable_recorder)
328 + recorder_enable(b, output);
339 +virtual_output_disable(struct weston_output *base)
341 + struct drm_output *output = to_drm_output(base);
343 + if (output->base.enabled)
344 + virtual_output_deinit(&output->base);
346 + output->disable_pending = 0;
348 + weston_log("Disabling output %s\n", output->base.name);
354 + * Virtual output connector that could be used for simulating output
355 + * device for clients and/or streaming of video
358 +create_output_for_virtual_connector(struct drm_backend *b,
359 + struct udev_device *drm_device)
361 + struct wl_event_loop *loop;
362 + struct drm_output *output;
363 + static int virtual_id = 1; /* as other outputs numbered */
366 + output = zalloc(sizeof *output);
367 + if (output == NULL)
371 + output->connector_id = 0;
373 + /* this is virtual output */
374 + output->virtual = 1;
376 + output->backlight = NULL;
378 + loop = wl_display_get_event_loop(b->compositor->wl_display);
379 + output->virtual_finish_frame_timer = wl_event_loop_add_timer(loop, virtual_finish_frame_handler, output);
381 + output->base.enable = virtual_output_enable;
382 + output->base.destroy = virtual_output_destroy;
383 + output->base.disable = virtual_output_disable;
385 + output->destroy_pending = 0;
386 + output->disable_pending = 0;
387 + output->original_crtc = NULL;
388 + snprintf(name, 32, "virtual%d", virtual_id++);
389 + output->base.name = strdup(name);
391 + weston_output_init(&output->base, b->compositor);
392 + weston_compositor_add_pending_output(&output->base, b->compositor);
398 create_sprites(struct drm_backend *b)
400 struct drm_sprite *sprite;
401 @@ -2701,9 +3029,12 @@ destroy_sprites(struct drm_backend *backend)
403 create_outputs(struct drm_backend *b, struct udev_device *drm_device)
405 + struct weston_config_section *section;
406 + struct weston_config *config = wet_get_config(b->compositor);
407 drmModeConnector *connector;
408 drmModeRes *resources;
412 resources = drmModeGetResources(b->drm.fd);
414 @@ -2735,6 +3066,14 @@ create_outputs(struct drm_backend *b, struct udev_device *drm_device)
418 + section = weston_config_get_section(config, "core", NULL, NULL);
419 + weston_config_section_get_int(section, "virtual", &virtual, 0);
421 + for (i = 0; i < virtual; i++) {
422 + if (create_output_for_virtual_connector(b, drm_device) < 0)
426 if (wl_list_empty(&b->compositor->output_list) &&
427 wl_list_empty(&b->compositor->pending_output_list))
428 weston_log("No currently active connector found.\n");
429 @@ -3181,6 +3520,12 @@ renderer_switch_binding(struct weston_keyboard *keyboard, uint32_t time,
430 switch_to_gl_renderer(b);
433 +static const struct weston_drm_output_api virtual_api = {
434 + virtual_output_set_mode,
435 + drm_output_set_gbm_format,
436 + drm_output_set_seat,
439 static const struct weston_drm_output_api api = {
441 drm_output_set_gbm_format,
442 @@ -3346,6 +3691,13 @@ drm_backend_create(struct weston_compositor *compositor,
443 goto err_udev_monitor;
446 + ret = weston_plugin_api_register(compositor, WESTON_DRM_VIRTUAL_OUTPUT_API_NAME,
447 + &virtual_api, sizeof(virtual_api));
450 + weston_log("Failed to register output API.\n");
451 + goto err_udev_monitor;
456 diff --git a/libweston/compositor-drm.h b/libweston/compositor-drm.h
457 index 2e2995a..00171c8 100644
458 --- a/libweston/compositor-drm.h
459 +++ b/libweston/compositor-drm.h
460 @@ -53,6 +53,7 @@ enum weston_drm_backend_output_mode {
463 #define WESTON_DRM_OUTPUT_API_NAME "weston_drm_output_api_v1"
464 +#define WESTON_DRM_VIRTUAL_OUTPUT_API_NAME "weston_virtual_output_api_v1"
466 struct weston_drm_output_api {
467 /** The mode to be used by the output. Refer to the documentation