• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

hardware/intel/common/libva


Commit MetaInfo

Revision324a725e5068a538e2446b0b73cccb3c119f3d8b (tree)
Time2017-08-17 12:06:29
AuthorPhilipp Kerling <pkerling@casi...>
CommiterXiang, Haihao

Log Message

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>

Change Summary

Incremental Difference

--- a/va/wayland/va_wayland_drm.c
+++ b/va/wayland/va_wayland_drm.c
@@ -132,22 +132,8 @@ va_wayland_drm_destroy(VADisplayContextP pDisplayContext)
132132
133133 vtable->has_prime_sharing = 0;
134134
135- if (wl_drm_ctx->drm) {
136- wl_drm_destroy(wl_drm_ctx->drm);
137- wl_drm_ctx->drm = NULL;
138- }
139135 wl_drm_ctx->is_authenticated = 0;
140136
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-
151137 if (drm_state) {
152138 if (drm_state->fd >= 0) {
153139 close(drm_state->fd);
@@ -200,16 +186,17 @@ wayland_roundtrip_queue(struct wl_display *display,
200186 bool
201187 va_wayland_drm_create(VADisplayContextP pDisplayContext)
202188 {
189+ bool result = false;
203190 VADriverContextP const ctx = pDisplayContext->pDriverContext;
204191 struct va_wayland_drm_context *wl_drm_ctx;
205192 struct drm_state *drm_state;
206193 struct VADriverVTableWayland *vtable = ctx->vtable_wayland;
207- struct wl_display *wrapped_display;
194+ struct wl_display *wrapped_display = NULL;
208195
209196 wl_drm_ctx = malloc(sizeof(*wl_drm_ctx));
210197 if (!wl_drm_ctx) {
211198 va_wayland_error("could not allocate wl_drm_ctx");
212- return false;
199+ goto end;
213200 }
214201 wl_drm_ctx->base.destroy = va_wayland_drm_destroy;
215202 wl_drm_ctx->queue = NULL;
@@ -222,7 +209,7 @@ va_wayland_drm_create(VADisplayContextP pDisplayContext)
222209 drm_state = calloc(1, sizeof(struct drm_state));
223210 if (!drm_state) {
224211 va_wayland_error("could not allocate drm_state");
225- return false;
212+ goto end;
226213 }
227214 drm_state->fd = -1;
228215 drm_state->auth_type = 0;
@@ -239,22 +226,28 @@ va_wayland_drm_create(VADisplayContextP pDisplayContext)
239226 wl_drm_ctx->queue = wl_display_create_queue(ctx->native_dpy);
240227 if (!wl_drm_ctx->queue) {
241228 va_wayland_error("could not create Wayland event queue");
242- return false;
229+ goto end;
243230 }
244231
245232 wrapped_display = wl_proxy_create_wrapper(ctx->native_dpy);
246233 if (!wrapped_display) {
247234 va_wayland_error("could not create Wayland proxy wrapper");
248- return false;
235+ goto end;
249236 }
250237
251238 /* All created objects will inherit this queue */
252239 wl_proxy_set_queue((struct wl_proxy *) wrapped_display, wl_drm_ctx->queue);
253240 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, &registry_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, &registry_listener, wl_drm_ctx) != 0) {
246+ va_wayland_error("could not add listener to wl_registry");
247+ goto end;
248+ }
256249 if (!wayland_roundtrip_queue(ctx->native_dpy, wl_drm_ctx->queue))
257- return false;
250+ goto end;
258251
259252 /* registry_handle_global should have been called by the
260253 * wl_display_roundtrip_queue above
@@ -262,23 +255,51 @@ va_wayland_drm_create(VADisplayContextP pDisplayContext)
262255
263256 /* Do not print an error, the compositor might just not support wl_drm */
264257 if (!wl_drm_ctx->drm)
265- return false;
258+ goto end;
266259
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+ }
268264 if (!wayland_roundtrip_queue(ctx->native_dpy, wl_drm_ctx->queue))
269- return false;
265+ goto end;
270266 if (drm_state->fd < 0) {
271267 va_wayland_error("did not get DRM device");
272- return false;
268+ goto end;
273269 }
274270
275271 if (!wayland_roundtrip_queue(ctx->native_dpy, wl_drm_ctx->queue))
276- return false;
272+ goto end;
277273
278274 if (!wl_drm_ctx->is_authenticated) {
279275 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+ }
281302 }
282303
283- return true;
304+ return result;
284305 }