summaryrefslogtreecommitdiff
path: root/recipes-graphics/wayland/files/0001-compositor-drm-Add-new-gbm-struct-to-allow-for-a-sep.patch
blob: cbd2cd5825b734348abce45ecc39c1df70a5a572 (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
From 0719ed96aa2c41afe342f4c3c19e4ca91f270be2 Mon Sep 17 00:00:00 2001
From: James Thomas <james.thomas@codethink.co.uk>
Date: Fri, 20 Jun 2014 12:12:26 +0100
Subject: [PATCH 1/6] compositor-drm: Add new gbm struct to allow for a
 separate gbm device

This is needed for devices like tegra jetson where the gbm device is not
the same as the drm device
---
 src/compositor-drm.c | 48 +++++++++++++++++++++++++++---------------------
 1 file changed, 27 insertions(+), 21 deletions(-)

diff --git a/src/compositor-drm.c b/src/compositor-drm.c
index 893877d..5db86dc 100644
--- a/src/compositor-drm.c
+++ b/src/compositor-drm.c
@@ -90,8 +90,11 @@ struct drm_backend {
 		int fd;
 		char *filename;
 	} drm;
-	struct gbm_device *gbm;
-	uint32_t *crtcs;
+	struct {
+		int fd;
+		char *filename;
+	} gbm;
+	struct gbm_device *gbm_device;	uint32_t *crtcs;
 	int num_crtcs;
 	uint32_t crtc_allocator;
 	uint32_t connector_allocator;
@@ -478,7 +481,7 @@ drm_output_prepare_scanout_view(struct drm_output *output,
 
 	if (ev->geometry.x != output->base.x ||
 	    ev->geometry.y != output->base.y ||
-	    buffer == NULL || b->gbm == NULL ||
+	    buffer == NULL || b->gbm_device == NULL ||
 	    buffer->width != output->base.current_mode->width ||
 	    buffer->height != output->base.current_mode->height ||
 	    output->base.transform != viewport->buffer.transform ||
@@ -488,7 +491,7 @@ drm_output_prepare_scanout_view(struct drm_output *output,
 	if (ev->geometry.scissor_enabled)
 		return NULL;
 
-	bo = gbm_bo_import(b->gbm, GBM_BO_IMPORT_WL_BUFFER,
+	bo = gbm_bo_import(b->gbm_device, GBM_BO_IMPORT_WL_BUFFER,
 			   buffer->resource, GBM_BO_USE_SCANOUT);
 
 	/* Unable to use the buffer for scanout */
@@ -923,7 +926,7 @@ drm_output_prepare_overlay_view(struct drm_output *output,
 	uint32_t format;
 	wl_fixed_t sx1, sy1, sx2, sy2;
 
-	if (b->gbm == NULL)
+	if (b->gbm_device == NULL)
 		return NULL;
 
 	if (viewport->buffer.transform != output->base.transform)
@@ -985,13 +988,13 @@ drm_output_prepare_overlay_view(struct drm_output *output,
 		if (dmabuf->attributes.n_planes != 1 || dmabuf->attributes.offset[0] != 0)
 			return NULL;
 
-		bo = gbm_bo_import(b->gbm, GBM_BO_IMPORT_FD, &gbm_dmabuf,
+		bo = gbm_bo_import(b->gbm_device, GBM_BO_IMPORT_FD, &gbm_dmabuf,
 				   GBM_BO_USE_SCANOUT);
 #else
 		return NULL;
 #endif
 	} else {
-		bo = gbm_bo_import(b->gbm, GBM_BO_IMPORT_WL_BUFFER,
+		bo = gbm_bo_import(b->gbm_device, GBM_BO_IMPORT_WL_BUFFER,
 				   buffer_resource, GBM_BO_USE_SCANOUT);
 	}
 	if (!bo)
@@ -1091,7 +1094,7 @@ drm_output_prepare_cursor_view(struct drm_output *output,
 	if (ev->transform.enabled &&
 	    (ev->transform.matrix.type > WESTON_MATRIX_TRANSFORM_TRANSLATE))
 		return NULL;
-	if (b->gbm == NULL)
+	if (b->gbm_device == NULL)
 		return NULL;
 	if (output->base.transform != WL_OUTPUT_TRANSFORM_NORMAL)
 		return NULL;
@@ -1493,6 +1496,9 @@ init_drm(struct drm_backend *b, struct udev_device *device)
 	b->drm.fd = fd;
 	b->drm.filename = strdup(filename);
 
+        b->gbm.fd = fd;
+        b->gbm.filename = b->drm.filename;
+
 	ret = drmGetCap(fd, DRM_CAP_TIMESTAMP_MONOTONIC, &cap);
 	if (ret == 0 && cap == 1)
 		clk_id = CLOCK_MONOTONIC;
@@ -1579,7 +1585,7 @@ drm_backend_create_gl_renderer(struct drm_backend *b)
 		n_formats = 3;
 	if (gl_renderer->create(b->compositor,
 				EGL_PLATFORM_GBM_KHR,
-				(void *)b->gbm,
+				(void *)b->gbm_device,
 				gl_renderer->opaque_attribs,
 				format,
 				n_formats) < 0) {
@@ -1592,13 +1598,13 @@ drm_backend_create_gl_renderer(struct drm_backend *b)
 static int
 init_egl(struct drm_backend *b)
 {
-	b->gbm = create_gbm_device(b->drm.fd);
+	b->gbm_device = create_gbm_device(b->gbm.fd);
 
-	if (!b->gbm)
+	if (!b->gbm_device)
 		return -1;
 
 	if (drm_backend_create_gl_renderer(b) < 0) {
-		gbm_device_destroy(b->gbm);
+		gbm_device_destroy(b->gbm_device);
 		return -1;
 	}
 
@@ -1831,7 +1837,7 @@ drm_output_init_egl(struct drm_output *output, struct drm_backend *b)
 	};
 	int i, flags, n_formats = 1;
 
-	output->gbm_surface = gbm_surface_create(b->gbm,
+	output->gbm_surface = gbm_surface_create(b->gbm_device,
 					     output->base.current_mode->width,
 					     output->base.current_mode->height,
 					     format[0],
@@ -1862,7 +1868,7 @@ drm_output_init_egl(struct drm_output *output, struct drm_backend *b)
 			continue;
 
 		output->gbm_cursor_bo[i] =
-			gbm_bo_create(b->gbm, b->cursor_width, b->cursor_height,
+			gbm_bo_create(b->gbm_device, b->cursor_width, b->cursor_height,
 				GBM_FORMAT_ARGB8888, flags);
 	}
 
@@ -2703,8 +2709,8 @@ drm_destroy(struct weston_compositor *ec)
 
 	weston_compositor_shutdown(ec);
 
-	if (b->gbm)
-		gbm_device_destroy(b->gbm);
+	if (b->gbm_device)
+		gbm_device_destroy(b->gbm_device);
 
 	weston_launcher_destroy(ec->launcher);
 
@@ -2989,8 +2995,8 @@ 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) {
+	b->gbm_device = create_gbm_device(b->drm.fd);
+	if (!b->gbm_device) {
 		weston_log("Failed to create gbm device. "
 			   "Aborting renderer switch\n");
 		return;
@@ -3002,7 +3008,7 @@ 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);
+		gbm_device_destroy(b->gbm_device);
 		weston_log("Failed to create GL renderer. Quitting.\n");
 		/* FIXME: we need a function to shutdown cleanly */
 		assert(0);
@@ -3191,8 +3197,8 @@ err_drm_source:
 err_udev_input:
 	udev_input_destroy(&b->input);
 err_sprite:
-	if (b->gbm)
-		gbm_device_destroy(b->gbm);
+	if (b->gbm_device)
+		gbm_device_destroy(b->gbm_device);
 	destroy_sprites(b);
 err_udev_dev:
 	udev_device_unref(drm_device);
-- 
2.9.3