hardware/intel/common/libva
Revision | 324a725e5068a538e2446b0b73cccb3c119f3d8b (tree) |
---|---|
Time | 2017-08-17 12:06:29 |
Author | Philipp Kerling <pkerling@casi...> |
Commiter | Xiang, Haihao |
wayland: Immediately destroy wl_* objects when DRM device is authenticated
The Wayland protocol is only used to determine which device driver to
load and initialize the DRM state. After the initial roundtrips that
open and authenticate the DRM device, the Wayland protocol objects
are not used anymore and will only take up memory and possibly have
events queued that never get handled.
As fix, destroy them immediately after DRM auth is through. This commit
also adds more error checking to the initialization function.
Fixes: #100
Signed-off-by: Philipp Kerling <pkerling@casix.org>
@@ -132,22 +132,8 @@ va_wayland_drm_destroy(VADisplayContextP pDisplayContext) | ||
132 | 132 | |
133 | 133 | vtable->has_prime_sharing = 0; |
134 | 134 | |
135 | - if (wl_drm_ctx->drm) { | |
136 | - wl_drm_destroy(wl_drm_ctx->drm); | |
137 | - wl_drm_ctx->drm = NULL; | |
138 | - } | |
139 | 135 | wl_drm_ctx->is_authenticated = 0; |
140 | 136 | |
141 | - if (wl_drm_ctx->registry) { | |
142 | - wl_registry_destroy(wl_drm_ctx->registry); | |
143 | - wl_drm_ctx->registry = NULL; | |
144 | - } | |
145 | - | |
146 | - if (wl_drm_ctx->queue) { | |
147 | - wl_event_queue_destroy(wl_drm_ctx->queue); | |
148 | - wl_drm_ctx->queue = NULL; | |
149 | - } | |
150 | - | |
151 | 137 | if (drm_state) { |
152 | 138 | if (drm_state->fd >= 0) { |
153 | 139 | close(drm_state->fd); |
@@ -200,16 +186,17 @@ wayland_roundtrip_queue(struct wl_display *display, | ||
200 | 186 | bool |
201 | 187 | va_wayland_drm_create(VADisplayContextP pDisplayContext) |
202 | 188 | { |
189 | + bool result = false; | |
203 | 190 | VADriverContextP const ctx = pDisplayContext->pDriverContext; |
204 | 191 | struct va_wayland_drm_context *wl_drm_ctx; |
205 | 192 | struct drm_state *drm_state; |
206 | 193 | struct VADriverVTableWayland *vtable = ctx->vtable_wayland; |
207 | - struct wl_display *wrapped_display; | |
194 | + struct wl_display *wrapped_display = NULL; | |
208 | 195 | |
209 | 196 | wl_drm_ctx = malloc(sizeof(*wl_drm_ctx)); |
210 | 197 | if (!wl_drm_ctx) { |
211 | 198 | va_wayland_error("could not allocate wl_drm_ctx"); |
212 | - return false; | |
199 | + goto end; | |
213 | 200 | } |
214 | 201 | wl_drm_ctx->base.destroy = va_wayland_drm_destroy; |
215 | 202 | wl_drm_ctx->queue = NULL; |
@@ -222,7 +209,7 @@ va_wayland_drm_create(VADisplayContextP pDisplayContext) | ||
222 | 209 | drm_state = calloc(1, sizeof(struct drm_state)); |
223 | 210 | if (!drm_state) { |
224 | 211 | va_wayland_error("could not allocate drm_state"); |
225 | - return false; | |
212 | + goto end; | |
226 | 213 | } |
227 | 214 | drm_state->fd = -1; |
228 | 215 | drm_state->auth_type = 0; |
@@ -239,22 +226,28 @@ va_wayland_drm_create(VADisplayContextP pDisplayContext) | ||
239 | 226 | wl_drm_ctx->queue = wl_display_create_queue(ctx->native_dpy); |
240 | 227 | if (!wl_drm_ctx->queue) { |
241 | 228 | va_wayland_error("could not create Wayland event queue"); |
242 | - return false; | |
229 | + goto end; | |
243 | 230 | } |
244 | 231 | |
245 | 232 | wrapped_display = wl_proxy_create_wrapper(ctx->native_dpy); |
246 | 233 | if (!wrapped_display) { |
247 | 234 | va_wayland_error("could not create Wayland proxy wrapper"); |
248 | - return false; | |
235 | + goto end; | |
249 | 236 | } |
250 | 237 | |
251 | 238 | /* All created objects will inherit this queue */ |
252 | 239 | wl_proxy_set_queue((struct wl_proxy *) wrapped_display, wl_drm_ctx->queue); |
253 | 240 | wl_drm_ctx->registry = wl_display_get_registry(wrapped_display); |
254 | - wl_proxy_wrapper_destroy(wrapped_display); | |
255 | - wl_registry_add_listener(wl_drm_ctx->registry, ®istry_listener, wl_drm_ctx); | |
241 | + if (!wl_drm_ctx->registry) { | |
242 | + va_wayland_error("could not create wl_registry"); | |
243 | + goto end; | |
244 | + } | |
245 | + if (wl_registry_add_listener(wl_drm_ctx->registry, ®istry_listener, wl_drm_ctx) != 0) { | |
246 | + va_wayland_error("could not add listener to wl_registry"); | |
247 | + goto end; | |
248 | + } | |
256 | 249 | if (!wayland_roundtrip_queue(ctx->native_dpy, wl_drm_ctx->queue)) |
257 | - return false; | |
250 | + goto end; | |
258 | 251 | |
259 | 252 | /* registry_handle_global should have been called by the |
260 | 253 | * wl_display_roundtrip_queue above |
@@ -262,23 +255,51 @@ va_wayland_drm_create(VADisplayContextP pDisplayContext) | ||
262 | 255 | |
263 | 256 | /* Do not print an error, the compositor might just not support wl_drm */ |
264 | 257 | if (!wl_drm_ctx->drm) |
265 | - return false; | |
258 | + goto end; | |
266 | 259 | |
267 | - wl_drm_add_listener(wl_drm_ctx->drm, &drm_listener, pDisplayContext); | |
260 | + if (wl_drm_add_listener(wl_drm_ctx->drm, &drm_listener, pDisplayContext) != 0) { | |
261 | + va_wayland_error("could not add listener to wl_drm"); | |
262 | + goto end; | |
263 | + } | |
268 | 264 | if (!wayland_roundtrip_queue(ctx->native_dpy, wl_drm_ctx->queue)) |
269 | - return false; | |
265 | + goto end; | |
270 | 266 | if (drm_state->fd < 0) { |
271 | 267 | va_wayland_error("did not get DRM device"); |
272 | - return false; | |
268 | + goto end; | |
273 | 269 | } |
274 | 270 | |
275 | 271 | if (!wayland_roundtrip_queue(ctx->native_dpy, wl_drm_ctx->queue)) |
276 | - return false; | |
272 | + goto end; | |
277 | 273 | |
278 | 274 | if (!wl_drm_ctx->is_authenticated) { |
279 | 275 | va_wayland_error("Wayland compositor did not respond to DRM authentication"); |
280 | - return false; | |
276 | + goto end; | |
277 | + } | |
278 | + | |
279 | + result = true; | |
280 | + | |
281 | +end: | |
282 | + if (wrapped_display) { | |
283 | + wl_proxy_wrapper_destroy(wrapped_display); | |
284 | + wrapped_display = NULL; | |
285 | + } | |
286 | + | |
287 | + if (wl_drm_ctx) { | |
288 | + if (wl_drm_ctx->drm) { | |
289 | + wl_drm_destroy(wl_drm_ctx->drm); | |
290 | + wl_drm_ctx->drm = NULL; | |
291 | + } | |
292 | + | |
293 | + if (wl_drm_ctx->registry) { | |
294 | + wl_registry_destroy(wl_drm_ctx->registry); | |
295 | + wl_drm_ctx->registry = NULL; | |
296 | + } | |
297 | + | |
298 | + if (wl_drm_ctx->queue) { | |
299 | + wl_event_queue_destroy(wl_drm_ctx->queue); | |
300 | + wl_drm_ctx->queue = NULL; | |
301 | + } | |
281 | 302 | } |
282 | 303 | |
283 | - return true; | |
304 | + return result; | |
284 | 305 | } |