summarylogtreecommitdiffstats
path: root/0005-backend-drm-Add-support-for-EGLDevice-EGLOutput.patch
blob: 857a9721ffe26ce02e83a9abea655c87cbff77e8 (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
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
From 8f9701ca16c53caa96edbdf0d0e5fc5cd6f6efbe Mon Sep 17 00:00:00 2001
From: "Miguel A. Vico" <mvicomoya@nvidia.com>
Date: Mon, 26 Aug 2019 09:48:49 -0700
Subject: [PATCH 5/6] backend-drm: Add support for EGLDevice+EGLOutput

As previously stated, EGLDevice and EGLOutput will provide means
to access native device objects and different portions of display
control hardware respectively.

Whenever EGL_EXT_device_drm extension is present, EGLDevice can
be used to enumerate and access DRM KMS devices, and EGLOutputLayer
to enumerate and access DRM KMS crtcs and planes.

By using EGLStreams and attaching an EGLOutputLayer consumer
(representing a DRM KMS crtc or plane) to it, backend-drm can
produce final composition frames and present them on a DRM device.

This change adds required logic to support presentation through
EGLDevice+EGLOutput+EGLStream. Whether GBM or EGLDevice should be
used can be controlled by --use-egldevice backend argument.

Signed-off-by: Miguel A Vico Moya <mvicomoya@nvidia.com>
Reviewed-by: Andy Ritger <aritger@nvidia.com>
Reviewed-by: Adam Cheney <acheney@nvidia.com>
Reviewed-by: James Jones <jajones@nvidia.com>
---
 compositor/main.c                            |   4 +-
 include/libweston/backend-drm.h              |   4 +
 libweston/backend-drm/drm-gbm.c              | 262 +++++++++++++------
 libweston/backend-drm/drm-internal.h         |  14 +
 libweston/backend-drm/drm.c                  |  15 +-
 libweston/backend-drm/kms.c                  |  23 +-
 libweston/backend-headless/headless.c        |   1 +
 libweston/backend-wayland/wayland.c          |   1 +
 libweston/backend-x11/x11.c                  |   1 +
 libweston/renderer-gl/egl-glue.c             |   5 +-
 libweston/renderer-gl/gl-renderer-internal.h |   4 +-
 libweston/renderer-gl/gl-renderer.c          |   4 +-
 libweston/renderer-gl/gl-renderer.h          |   2 +
 shared/weston-egl-ext.h                      |   9 +
 14 files changed, 259 insertions(+), 90 deletions(-)

diff --git a/compositor/main.c b/compositor/main.c
index 65da9dbc..2361cc63 100644
--- a/compositor/main.c
+++ b/compositor/main.c
@@ -677,7 +677,8 @@ usage(int error_code)
 		"  --drm-device=CARD\tThe DRM device to use, e.g. \"card0\".\n"
 		"  --use-pixman\t\tUse the pixman (CPU) renderer\n"
 		"  --current-mode\tPrefer current KMS mode over EDID preferred mode\n"
-		"  --continue-without-input\tAllow the compositor to start without input devices\n\n");
+		"  --continue-without-input\tAllow the compositor to start without input devices\n\n"
+		"  --use-egldevice\tUse EGLDevice and EGLOutput with the GL renderer\n");
 #endif
 
 #if defined(BUILD_FBDEV_COMPOSITOR)
@@ -2525,6 +2526,7 @@ load_drm_backend(struct weston_compositor *c,
 		{ WESTON_OPTION_BOOLEAN, "current-mode", 0, &wet->drm_use_current_mode },
 		{ WESTON_OPTION_BOOLEAN, "use-pixman", 0, &config.use_pixman },
 		{ WESTON_OPTION_BOOLEAN, "continue-without-input", 0, &config.continue_without_input },
+		{ WESTON_OPTION_BOOLEAN, "use-egldevice", 0, &config.use_egldevice },
 	};
 
 	parse_options(options, ARRAY_LENGTH(options), argc, argv);
diff --git a/include/libweston/backend-drm.h b/include/libweston/backend-drm.h
index 350eeb0d..8916f98d 100644
--- a/include/libweston/backend-drm.h
+++ b/include/libweston/backend-drm.h
@@ -177,6 +177,10 @@ struct weston_drm_backend_config {
 	/** Whether to use the pixman renderer instead of the OpenGL ES renderer. */
 	bool use_pixman;
 
+	/** Whether to use the GL composition based off EGLDevice & friends instead
+	 * of GBM. */
+	bool use_egldevice;
+
 	/** The seat to be used for input and output.
 	 *
 	 * If seat_id is NULL, the seat is taken from XDG_SEAT environment
diff --git a/libweston/backend-drm/drm-gbm.c b/libweston/backend-drm/drm-gbm.c
index 30609e3e..04a9f89b 100644
--- a/libweston/backend-drm/drm-gbm.c
+++ b/libweston/backend-drm/drm-gbm.c
@@ -51,11 +51,6 @@ create_gbm_device(int fd)
 {
 	struct gbm_device *gbm;
 
-	gl_renderer = weston_load_module("gl-renderer.so",
-					 "gl_renderer_interface");
-	if (!gl_renderer)
-		return NULL;
-
 	/* GBM will load a dri driver, but even though they need symbols from
 	 * libglapi, in some version of Mesa they are not linked to it. Since
 	 * only the gl-renderer module links to it, the call above won't make
@@ -68,6 +63,40 @@ create_gbm_device(int fd)
 	return gbm;
 }
 
+static EGLDeviceEXT
+find_egldevice(const char *filename)
+{
+	EGLDeviceEXT egldevice = EGL_NO_DEVICE_EXT;
+	EGLDeviceEXT *devices;
+	EGLint num_devices;
+	const char *drm_path;
+	int i;
+
+	if (gl_renderer->get_devices(0, NULL, &num_devices) < 0 ||
+	    num_devices < 1)
+		return EGL_NO_DEVICE_EXT;
+
+	devices = zalloc(num_devices * sizeof *devices);
+	if (!devices)
+		return EGL_NO_DEVICE_EXT;
+
+	if (gl_renderer->get_devices(num_devices, devices, &num_devices) < 0) {
+		free(devices);
+		return EGL_NO_DEVICE_EXT;
+	}
+
+	for (i = 0; i < num_devices; i++)
+		if (gl_renderer->get_drm_device_file(devices[i],
+						     &drm_path) == 0 &&
+		    strcmp(filename, drm_path) == 0) {
+			egldevice = devices[i];
+			break;
+		}
+
+	free(devices);
+	return egldevice;
+}
+
 /* When initializing EGL, if the preferred buffer format isn't available
  * we may be able to substitute an ARGB format for an XRGB one.
  *
@@ -98,33 +127,57 @@ drm_backend_create_gl_renderer(struct drm_backend *b)
 		fallback_format_for(b->gbm_format),
 		0,
 	};
-	struct gl_renderer_display_options options = {
-		.egl_platform = EGL_PLATFORM_GBM_KHR,
-		.egl_native_display = b->gbm,
-		.egl_surface_type = EGL_WINDOW_BIT,
-		.drm_formats = format,
-		.drm_formats_count = 2,
+
+	EGLint device_platform_attribs[] = {
+	    EGL_DRM_MASTER_FD_EXT, b->drm.fd,
+	    EGL_NONE
 	};
 
+	struct gl_renderer_display_options options;
+	if (b->use_egldevice) {
+	    options.egl_platform = EGL_PLATFORM_DEVICE_EXT;
+	    options.egl_native_display = b->egldevice;
+	    options.egl_surface_type = EGL_STREAM_BIT_KHR;
+	    options.egl_platform_attribs = device_platform_attribs;
+	    options.drm_formats = format;
+	    options.drm_formats_count = 2;
+	} else {
+	    options.egl_platform = EGL_PLATFORM_GBM_KHR;
+	    options.egl_native_display = b->gbm;
+	    options.egl_surface_type = EGL_WINDOW_BIT;
+	    options.egl_platform_attribs = NULL;
+	    options.drm_formats = format;
+	    options.drm_formats_count = 2;
+	}
+
 	if (format[1])
 		options.drm_formats_count = 3;
 
-	if (gl_renderer->display_create(b->compositor, &options) < 0)
-		return -1;
-
-	return 0;
+	return gl_renderer->display_create(b->compositor, &options);
 }
 
 int
 init_egl(struct drm_backend *b)
 {
-	b->gbm = create_gbm_device(b->drm.fd);
-
-	if (!b->gbm)
+	gl_renderer = weston_load_module("gl-renderer.so",
+					 "gl_renderer_interface");
+	if (!gl_renderer)
 		return -1;
 
+	if (b->use_egldevice) {
+		b->egldevice = find_egldevice(b->drm.filename);
+		if (b->egldevice == EGL_NO_DEVICE_EXT)
+			return -1;
+	} else {
+		b->gbm = create_gbm_device(b->drm.fd);
+
+		if (!b->gbm)
+			return -1;
+	}
+
 	if (drm_backend_create_gl_renderer(b) < 0) {
-		gbm_device_destroy(b->gbm);
+		if (b->gbm)
+			gbm_device_destroy(b->gbm);
 		return -1;
 	}
 
@@ -181,71 +234,98 @@ err:
 int
 drm_output_init_egl(struct drm_output *output, struct drm_backend *b)
 {
-	uint32_t format[2] = {
+	if (b->use_egldevice) {
+		int w = output->base.current_mode->width;
+		int h = output->base.current_mode->height;
+
+		/* Create a black dumb fb for modesetting */
+		output->dumb[0] = drm_fb_create_dumb(b, w, h,
+						     DRM_FORMAT_XRGB8888);
+		if (!output->dumb[0]) {
+			weston_log("failed to create dumb framebuffer\n");
+			return -1;
+		}
+		memset(output->dumb[0]->map, 0, output->dumb[0]->size);
+
+		if (gl_renderer->output_stream_create(&output->base, ~0u,
+						      output->crtc_id) < 0) {
+			weston_log("failed to create gl renderer output stream "
+				   "state\n");
+			drm_fb_unref(output->dumb[0]);
+			output->dumb[0] = NULL;
+			return -1;
+		}
+
+		/* FIXME: Add hw planes and cursors for EGL device when supported */
+		b->sprites_are_broken = 1;
+		b->cursors_are_broken = 1;
+	} else {
+	    uint32_t format[2] = {
 		output->gbm_format,
 		fallback_format_for(output->gbm_format),
-	};
-	struct gl_renderer_output_options options = {
+	    };
+	    struct gl_renderer_output_options options = {
 		.drm_formats = format,
 		.drm_formats_count = 1,
-	};
-	struct weston_mode *mode = output->base.current_mode;
-	struct drm_plane *plane = output->scanout_plane;
-	unsigned int i;
+	    };
+	    struct weston_mode *mode = output->base.current_mode;
+	    struct drm_plane *plane = output->scanout_plane;
+	    unsigned int i;
 
-	assert(output->gbm_surface == NULL);
+	    assert(output->gbm_surface == NULL);
 
-	for (i = 0; i < plane->count_formats; i++) {
+	    for (i = 0; i < plane->count_formats; i++) {
 		if (plane->formats[i].format == output->gbm_format)
-			break;
-	}
+		    break;
+	    }
 
-	if (i == plane->count_formats) {
+	    if (i == plane->count_formats) {
 		weston_log("format 0x%x not supported by output %s\n",
 			   output->gbm_format, output->base.name);
 		return -1;
-	}
+	    }
 
 #ifdef HAVE_GBM_MODIFIERS
-	if (plane->formats[i].count_modifiers > 0) {
+	    if (plane->formats[i].count_modifiers > 0) {
 		output->gbm_surface =
-			gbm_surface_create_with_modifiers(b->gbm,
-							  mode->width,
-							  mode->height,
-							  output->gbm_format,
-							  plane->formats[i].modifiers,
-							  plane->formats[i].count_modifiers);
-	}
-
-	/* If allocating with modifiers fails, try again without. This can
-	 * happen when the KMS display device supports modifiers but the
-	 * GBM driver does not, e.g. the old i915 Mesa driver. */
-	if (!output->gbm_surface)
+		    gbm_surface_create_with_modifiers(b->gbm,
+						      mode->width,
+						      mode->height,
+						      output->gbm_format,
+						      plane->formats[i].modifiers,
+						      plane->formats[i].count_modifiers);
+	    }
+
+	    /* If allocating with modifiers fails, try again without. This can
+	     * happen when the KMS display device supports modifiers but the
+	     * GBM driver does not, e.g. the old i915 Mesa driver. */
+	    if (!output->gbm_surface)
 #endif
-	{
+	    {
 		output->gbm_surface =
 		    gbm_surface_create(b->gbm, mode->width, mode->height,
 				       output->gbm_format,
 				       output->gbm_bo_flags);
-	}
+	    }
 
-	if (!output->gbm_surface) {
+	    if (!output->gbm_surface) {
 		weston_log("failed to create gbm surface\n");
 		return -1;
-	}
+	    }
 
-	if (options.drm_formats[1])
+	    if (options.drm_formats[1])
 		options.drm_formats_count = 2;
-	options.window_for_legacy = (EGLNativeWindowType) output->gbm_surface;
-	options.window_for_platform = output->gbm_surface;
-	if (gl_renderer->output_window_create(&output->base, &options) < 0) {
+	    options.window_for_legacy = (EGLNativeWindowType) output->gbm_surface;
+	    options.window_for_platform = output->gbm_surface;
+	    if (gl_renderer->output_window_create(&output->base, &options) < 0) {
 		weston_log("failed to create gl renderer output state\n");
 		gbm_surface_destroy(output->gbm_surface);
 		output->gbm_surface = NULL;
 		return -1;
-	}
+	    }
 
-	drm_output_init_cursor_egl(output, b);
+	    drm_output_init_cursor_egl(output, b);
+	}
 
 	return 0;
 }
@@ -258,14 +338,23 @@ drm_output_fini_egl(struct drm_output *output)
 	/* Destroying the GBM surface will destroy all our GBM buffers,
 	 * regardless of refcount. Ensure we destroy them here. */
 	if (!b->shutting_down &&
-	    output->scanout_plane->state_cur->fb &&
-	    output->scanout_plane->state_cur->fb->type == BUFFER_GBM_SURFACE) {
+	    ((output->scanout_plane->state_cur->fb &&
+	      output->scanout_plane->state_cur->fb->type == BUFFER_GBM_SURFACE) ||
+	     b->use_egldevice)) {
 		drm_plane_reset_state(output->scanout_plane);
 	}
 
 	gl_renderer->output_destroy(&output->base);
-	gbm_surface_destroy(output->gbm_surface);
-	output->gbm_surface = NULL;
+
+	if (output->dumb[0]) {
+		drm_fb_unref(output->dumb[0]);
+		output->dumb[0] = NULL;
+	}
+
+	if (output->gbm_surface) {
+		gbm_surface_destroy(output->gbm_surface);
+		output->gbm_surface = NULL;
+	}
 	drm_output_fini_cursor_egl(output);
 }
 
@@ -279,22 +368,25 @@ drm_output_render_gl(struct drm_output_state *state, pixman_region32_t *damage)
 
 	output->base.compositor->renderer->repaint_output(&output->base,
 							  damage);
-
-	bo = gbm_surface_lock_front_buffer(output->gbm_surface);
-	if (!bo) {
-		weston_log("failed to lock front buffer: %s\n",
-			   strerror(errno));
-		return NULL;
-	}
-
-	/* The renderer always produces an opaque image. */
-	ret = drm_fb_get_from_bo(bo, b, true, BUFFER_GBM_SURFACE);
-	if (!ret) {
-		weston_log("failed to get drm_fb for bo\n");
-		gbm_surface_release_buffer(output->gbm_surface, bo);
-		return NULL;
+	if (b->use_egldevice)
+		ret = drm_fb_ref(output->dumb[0]);
+	else {
+		bo = gbm_surface_lock_front_buffer(output->gbm_surface);
+		if (!bo) {
+			weston_log("failed to lock front buffer: %s\n",
+				   strerror(errno));
+			return NULL;
+		}
+	
+		/* The renderer always produces an opaque image. */
+		ret = drm_fb_get_from_bo(bo, b, true, BUFFER_GBM_SURFACE);
+		if (!ret) {
+			weston_log("failed to get drm_fb for bo\n");
+			gbm_surface_release_buffer(output->gbm_surface, bo);
+			return NULL;
+		}
+		ret->gbm_surface = output->gbm_surface;
 	}
-	ret->gbm_surface = output->gbm_surface;
 
 	return ret;
 }
@@ -315,11 +407,20 @@ switch_to_gl_renderer(struct drm_backend *b)
 
 	weston_log("Switching to GL renderer\n");
 
-	b->gbm = create_gbm_device(b->drm.fd);
-	if (!b->gbm) {
-		weston_log("Failed to create gbm device. "
-			   "Aborting renderer switch\n");
-		return;
+	if (b->use_egldevice) {
+		b->egldevice = find_egldevice(b->drm.filename);
+		if (b->egldevice == EGL_NO_DEVICE_EXT) {
+			weston_log("Failed to create EGL device. "
+				   "Aborting renderer switch\n");
+			return;
+		}
+	} else {	
+		b->gbm = create_gbm_device(b->drm.fd);
+		if (!b->gbm) {
+			weston_log("Failed to create gbm device. "
+				   "Aborting renderer switch\n");
+			return;
+		}
 	}
 
 	wl_list_for_each(output, &b->compositor->output_list, base.link)
@@ -328,7 +429,8 @@ switch_to_gl_renderer(struct drm_backend *b)
 	b->compositor->renderer->destroy(b->compositor);
 
 	if (drm_backend_create_gl_renderer(b) < 0) {
-		gbm_device_destroy(b->gbm);
+		if (b->gbm)
+			gbm_device_destroy(b->gbm);
 		weston_log("Failed to create GL renderer. Quitting.\n");
 		/* FIXME: we need a function to shutdown cleanly */
 		assert(0);
diff --git a/libweston/backend-drm/drm-internal.h b/libweston/backend-drm/drm-internal.h
index 06f952f2..8bc9c92b 100644
--- a/libweston/backend-drm/drm-internal.h
+++ b/libweston/backend-drm/drm-internal.h
@@ -60,6 +60,17 @@
 #include "backend.h"
 #include "libweston-internal.h"
 
+#ifdef ENABLE_EGL
+
+#include <EGL/egl.h>
+#include <EGL/eglext.h>
+
+#else
+
+typedef void *EGLDeviceEXT;
+
+#endif
+
 #ifndef DRM_CLIENT_CAP_ASPECT_RATIO
 #define DRM_CLIENT_CAP_ASPECT_RATIO	4
 #endif
@@ -262,6 +273,9 @@ struct drm_backend {
 	struct wl_listener session_listener;
 	uint32_t gbm_format;
 
+	EGLDeviceEXT egldevice;
+	bool use_egldevice;
+
 	/* we need these parameters in order to not fail drmModeAddFB2()
 	 * due to out of bounds dimensions, and then mistakenly set
 	 * sprites_are_broken:
diff --git a/libweston/backend-drm/drm.c b/libweston/backend-drm/drm.c
index 94a2bf2a..94246bb2 100644
--- a/libweston/backend-drm/drm.c
+++ b/libweston/backend-drm/drm.c
@@ -390,7 +390,8 @@ drm_output_render(struct drm_output_state *state, pixman_region32_t *damage)
 	 * the damaged region into the renderer to re-render the affected
 	 * area.
 	 */
-	if (!pixman_region32_not_empty(damage) &&
+	if (!b->use_egldevice &&
+	    !pixman_region32_not_empty(damage) &&
 	    scanout_plane->state_cur->fb &&
 	    (scanout_plane->state_cur->fb->type == BUFFER_GBM_SURFACE ||
 	     scanout_plane->state_cur->fb->type == BUFFER_PIXMAN_DUMB)) {
@@ -2798,6 +2799,11 @@ recorder_binding(struct weston_keyboard *keyboard, const struct timespec *time,
 	struct drm_output *output;
 	int width, height;
 
+	if (b->use_egldevice) {
+		weston_log("recorder not supported with EGL device\n");
+		return;
+	}
+
 	output = container_of(b->compositor->output_list.next,
 			      struct drm_output, base.link);
 
@@ -2879,6 +2885,13 @@ drm_backend_create(struct weston_compositor *compositor,
 	b->use_pixman = config->use_pixman;
 	b->pageflip_timeout = config->pageflip_timeout;
 	b->use_pixman_shadow = config->use_pixman_shadow;
+	b->use_egldevice = config->use_egldevice;
+	if (b->use_egldevice) {
+#if !BUILD_DRM_GBM
+		weston_log("fatal: drm backend with EGLDevice requires GL renderer.\n");
+		goto err_compositor;
+#endif
+	}
 
 	b->debug = weston_compositor_add_log_scope(compositor, "drm-backend",
 						   "Debug messages from DRM/KMS backend\n",
diff --git a/libweston/backend-drm/kms.c b/libweston/backend-drm/kms.c
index c91e3810..0033dba2 100644
--- a/libweston/backend-drm/kms.c
+++ b/libweston/backend-drm/kms.c
@@ -42,6 +42,11 @@
 #include "pixel-formats.h"
 #include "presentation-time-server-protocol.h"
 
+#if BUILD_DRM_GBM
+#include "renderer-gl/gl-renderer.h"
+extern struct gl_renderer_interface *gl_renderer;
+#endif
+
 #ifndef DRM_FORMAT_MOD_LINEAR
 #define DRM_FORMAT_MOD_LINEAR 0
 #endif
@@ -752,9 +757,19 @@ drm_output_apply_state_legacy(struct drm_output_state *state)
 			   output->crtc_id, scanout_state->plane->plane_id,
 			   pinfo ? pinfo->drm_format_name : "UNKNOWN");
 
-	if (drmModePageFlip(backend->drm.fd, output->crtc_id,
-			    scanout_state->fb->fb_id,
-			    DRM_MODE_PAGE_FLIP_EVENT, output) < 0) {
+	if (backend->use_egldevice) {
+#if BUILD_DRM_GBM
+		ret = gl_renderer->output_stream_flip(&output->base, output);
+#else
+		assert(!"Can't flip output EGLStream without GL renderer.\n");
+		ret = -1;
+#endif
+	} else
+		ret = drmModePageFlip(backend->drm.fd, output->crtc_id,
+				      scanout_state->fb->fb_id,
+				      DRM_MODE_PAGE_FLIP_EVENT, output);
+
+	if (ret < 0) {
 		weston_log("queueing pageflip failed: %s\n", strerror(errno));
 		goto err;
 	}
@@ -1468,7 +1483,7 @@ init_kms_caps(struct drm_backend *b)
 		b->universal_planes = (ret == 0);
 	}
 
-	if (b->universal_planes && !getenv("WESTON_DISABLE_ATOMIC")) {
+	if (b->universal_planes && !getenv("WESTON_DISABLE_ATOMIC") && !b->use_egldevice) {
 		ret = drmGetCap(b->drm.fd, DRM_CAP_CRTC_IN_VBLANK_EVENT, &cap);
 		if (ret != 0)
 			cap = 0;
diff --git a/libweston/backend-headless/headless.c b/libweston/backend-headless/headless.c
index c312a0f2..94f4e998 100644
--- a/libweston/backend-headless/headless.c
+++ b/libweston/backend-headless/headless.c
@@ -396,6 +396,7 @@ headless_gl_renderer_init(struct headless_backend *b)
 		.egl_platform = EGL_PLATFORM_SURFACELESS_MESA,
 		.egl_native_display = EGL_DEFAULT_DISPLAY,
 		.egl_surface_type = EGL_PBUFFER_BIT,
+		.egl_platform_attribs = NULL,
 		.drm_formats = headless_formats,
 		.drm_formats_count = ARRAY_LENGTH(headless_formats),
 	};
diff --git a/libweston/backend-wayland/wayland.c b/libweston/backend-wayland/wayland.c
index 60d42bf3..a8bca921 100644
--- a/libweston/backend-wayland/wayland.c
+++ b/libweston/backend-wayland/wayland.c
@@ -2781,6 +2781,7 @@ wayland_backend_create(struct weston_compositor *compositor,
 			.egl_platform = EGL_PLATFORM_WAYLAND_KHR,
 			.egl_native_display = b->parent.wl_display,
 			.egl_surface_type = EGL_WINDOW_BIT,
+			.egl_platform_attribs = NULL,
 			.drm_formats = wayland_formats,
 			.drm_formats_count = ARRAY_LENGTH(wayland_formats),
 		};
diff --git a/libweston/backend-x11/x11.c b/libweston/backend-x11/x11.c
index 387e97a4..46af8f02 100644
--- a/libweston/backend-x11/x11.c
+++ b/libweston/backend-x11/x11.c
@@ -1806,6 +1806,7 @@ init_gl_renderer(struct x11_backend *b)
 		.egl_platform = EGL_PLATFORM_X11_KHR,
 		.egl_native_display = b->dpy,
 		.egl_surface_type = EGL_WINDOW_BIT,
+		.egl_platform_attribs = NULL,
 		.drm_formats = x11_formats,
 		.drm_formats_count = ARRAY_LENGTH(x11_formats),
 	};
diff --git a/libweston/renderer-gl/egl-glue.c b/libweston/renderer-gl/egl-glue.c
index abe10b46..c1fa17d8 100644
--- a/libweston/renderer-gl/egl-glue.c
+++ b/libweston/renderer-gl/egl-glue.c
@@ -457,7 +457,8 @@ gl_renderer_get_egl_config(struct gl_renderer *gr,
 
 int
 gl_renderer_setup_egl_display(struct gl_renderer *gr,
-			      void *native_display)
+			      void *native_display,
+			      const EGLint *attribs)
 {
 	gr->egl_display = NULL;
 
@@ -465,7 +466,7 @@ gl_renderer_setup_egl_display(struct gl_renderer *gr,
 	if (gr->has_platform_base)
 		gr->egl_display = gr->get_platform_display(gr->platform,
 							   native_display,
-							   NULL);
+							   attribs);
 
 	if (!gr->egl_display) {
 		weston_log("warning: either no EGL_EXT_platform_base "
diff --git a/libweston/renderer-gl/gl-renderer-internal.h b/libweston/renderer-gl/gl-renderer-internal.h
index 5b0bd4b5..ae76a81e 100644
--- a/libweston/renderer-gl/gl-renderer-internal.h
+++ b/libweston/renderer-gl/gl-renderer-internal.h
@@ -171,7 +171,9 @@ gl_renderer_get_egl_config(struct gl_renderer *gr,
 			   unsigned drm_formats_count);
 
 int
-gl_renderer_setup_egl_display(struct gl_renderer *gr, void *native_display);
+gl_renderer_setup_egl_display(struct gl_renderer *gr,
+			      void *native_display,
+			      const EGLint *attribs);
 
 int
 gl_renderer_setup_egl_client_extensions(struct gl_renderer *gr);
diff --git a/libweston/renderer-gl/gl-renderer.c b/libweston/renderer-gl/gl-renderer.c
index f834a7cb..19a2e730 100644
--- a/libweston/renderer-gl/gl-renderer.c
+++ b/libweston/renderer-gl/gl-renderer.c
@@ -3800,7 +3800,9 @@ gl_renderer_display_create(struct weston_compositor *ec,
 		gl_renderer_surface_get_content_size;
 	gr->base.surface_copy_content = gl_renderer_surface_copy_content;
 
-	if (gl_renderer_setup_egl_display(gr, options->egl_native_display) < 0)
+	if (gl_renderer_setup_egl_display(gr,
+					  options->egl_native_display,
+					  options->egl_platform_attribs) < 0)
 		goto fail;
 
 	log_egl_info(gr->egl_display);
diff --git a/libweston/renderer-gl/gl-renderer.h b/libweston/renderer-gl/gl-renderer.h
index f46c21c6..8ad069d9 100644
--- a/libweston/renderer-gl/gl-renderer.h
+++ b/libweston/renderer-gl/gl-renderer.h
@@ -49,6 +49,7 @@ typedef intptr_t EGLNativeWindowType;
 #define EGL_DEFAULT_DISPLAY ((EGLNativeDisplayType)0)
 #define EGL_PBUFFER_BIT                   0x0001
 #define EGL_WINDOW_BIT                    0x0004
+#define EGL_NO_DEVICE_EXT   ((EGLDeviceEXT)0)
 
 #endif /* ENABLE_EGL */
 
@@ -71,6 +72,7 @@ struct gl_renderer_display_options {
 	void *egl_native_display;
 	/** EGL_SURFACE_TYPE bits for the base EGLConfig */
 	EGLint egl_surface_type;
+	const EGLint *egl_platform_attribs;
 	/** Array of DRM pixel formats acceptable for the base EGLConfig */
 	const uint32_t *drm_formats;
 	/** The \c drm_formats array length */
diff --git a/shared/weston-egl-ext.h b/shared/weston-egl-ext.h
index d348a5c0..30e4eaba 100644
--- a/shared/weston-egl-ext.h
+++ b/shared/weston-egl-ext.h
@@ -212,6 +212,10 @@ typedef EGLint (EGLAPIENTRYP PFNEGLDUPNATIVEFENCEFDANDROIDPROC) (EGLDisplay dpy,
 #define EGL_PLATFORM_DEVICE_EXT 0x313F
 #endif
 
+#ifndef EGL_DRM_MASTER_FD_EXT
+#define EGL_DRM_MASTER_FD_EXT 0x333C
+#endif
+
 /*
  * FIXME: Remove both EGL_EXT_stream_acquire_mode and
  *        EGL_NV_output_drm_flip_event definitions below once both extensions
@@ -261,6 +265,11 @@ EGLAPI EGLBoolean EGLAPIENTRY eglStreamConsumerAcquireAttribEXT (EGLDisplay dpy,
 #define EGL_PLATFORM_SURFACELESS_MESA     0x31DD
 #define EGL_PLATFORM_DEVICE_EXT  0x313F
 
+/* EGL_DRM_MASTER_FD_EXT and EGL_NONE enum values are also kept to allow
+ * backend-drm/drm.c to build with EGLDevice and EGLStream support */
+#define EGL_DRM_MASTER_FD_EXT    0x333C
+#define EGL_NONE                 0x3038
+
 #endif /* ENABLE_EGL */
 
 #endif
-- 
2.25.1