OSDN Git Service

Remove unused variable 'id' in va_wayland_emgd_create.
[android-x86/hardware-intel-common-libva.git] / va / wayland / va_wayland_emgd.c
1 /*
2  * va_wayland_emgd.c - Wayland/EMGD helpers
3  *
4  * Copyright (c) 2012 Intel Corporation. All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sub license, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  * 
14  * The above copyright notice and this permission notice (including the
15  * next paragraph) shall be included in all copies or substantial portions
16  * of the Software.
17  * 
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21  * IN NO EVENT SHALL INTEL AND/OR ITS SUPPLIERS BE LIABLE FOR
22  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  */
26
27 #include "sysdeps.h"
28 #include <unistd.h>
29 #include <dlfcn.h>
30 #include "va_drmcommon.h"
31 #include "va_wayland_emgd.h"
32 #include "va_wayland_private.h"
33
34 /* XXX: Wayland/EMGD support currently lives in libwayland-emgd.so.* library */
35 #define LIBWAYLAND_EMGD_NAME "libwayland-emgd.so.1"
36
37 typedef struct va_wayland_emgd_context {
38     struct va_wayland_context   base;
39     void                       *handle;
40     struct wl_emgd             *emgd;
41     void                       *emgd_interface;
42     unsigned int                is_created      : 1;
43     struct wl_registry         *registry;
44 } VADisplayContextWaylandEMGD;
45
46 static inline void
47 wl_emgd_destroy(struct wl_emgd *emgd)
48 {
49     wl_proxy_destroy((struct wl_proxy *)emgd);
50 }
51
52 static VAStatus
53 va_DisplayContextGetDriverName(
54     VADisplayContextP pDisplayContext,
55     char            **driver_name_ptr
56 )
57 {
58     *driver_name_ptr = strdup("emgd");
59     return VA_STATUS_SUCCESS;
60 }
61
62 void
63 va_wayland_emgd_destroy(VADisplayContextP pDisplayContext)
64 {
65     VADriverContextP const ctx = pDisplayContext->pDriverContext;
66     VADisplayContextWaylandEMGD * const wl_emgd_ctx = pDisplayContext->opaque;
67     struct drm_state * const drm_state = ctx->drm_state;
68
69     if (wl_emgd_ctx->emgd) {
70         wl_emgd_destroy(wl_emgd_ctx->emgd);
71         wl_emgd_ctx->emgd = NULL;
72     }
73     wl_emgd_ctx->is_created = 0;
74
75     if (wl_emgd_ctx->handle) {
76         dlclose(wl_emgd_ctx->handle);
77         wl_emgd_ctx->handle = NULL;
78     }
79
80     if (drm_state) {
81         if (drm_state->fd >= 0) {
82             close(drm_state->fd);
83             drm_state->fd = -1;
84         }
85         free(ctx->drm_state);
86         ctx->drm_state = NULL;
87     }
88 }
89
90 static void
91 registry_handle_global(
92     void               *data,
93     struct wl_registry *registry,
94     uint32_t            id,
95     const char         *interface,
96     uint32_t            version
97 )
98 {
99     VADisplayContextWaylandEMGD *wl_emgd_ctx = data;
100
101     if (strcmp(interface, "wl_emgd") == 0) {
102         wl_emgd_ctx->emgd =
103             wl_registry_bind(registry, id, wl_emgd_ctx->emgd_interface, 1);
104     }
105 }
106
107 static const struct wl_registry_listener registry_listener = {
108     registry_handle_global,
109     NULL,
110 };
111
112 bool
113 va_wayland_emgd_create(VADisplayContextP pDisplayContext)
114 {
115     VADriverContextP const ctx = pDisplayContext->pDriverContext;
116     VADisplayContextWaylandEMGD *wl_emgd_ctx;
117     struct drm_state *drm_state;
118
119     wl_emgd_ctx = malloc(sizeof(*wl_emgd_ctx));
120     if (!wl_emgd_ctx)
121         return false;
122     wl_emgd_ctx->base.destroy           = va_wayland_emgd_destroy;
123     wl_emgd_ctx->handle                 = NULL;
124     wl_emgd_ctx->emgd                   = NULL;
125     wl_emgd_ctx->emgd_interface         = NULL;
126     wl_emgd_ctx->is_created             = 0;
127     pDisplayContext->opaque             = wl_emgd_ctx;
128     pDisplayContext->vaGetDriverName    = va_DisplayContextGetDriverName;
129
130     drm_state = calloc(1, sizeof(struct drm_state));
131     if (!drm_state)
132         return false;
133     drm_state->fd        = -1;
134     drm_state->auth_type = 0;
135     ctx->drm_state       = drm_state;
136
137     wl_emgd_ctx->handle = dlopen(LIBWAYLAND_EMGD_NAME, RTLD_LAZY|RTLD_LOCAL);
138     if (!wl_emgd_ctx->handle)
139         return false;
140
141     wl_emgd_ctx->emgd_interface =
142         dlsym(wl_emgd_ctx->handle, "wl_emgd_interface");
143     if (!wl_emgd_ctx->emgd_interface)
144         return false;
145
146     wl_emgd_ctx->registry = wl_display_get_registry(ctx->native_dpy);
147     wl_registry_add_listener(wl_emgd_ctx->registry, &registry_listener, wl_emgd_ctx);
148     wl_display_roundtrip(ctx->native_dpy);
149
150     /* registry_handle_global should have been called by the
151      * wl_display_roundtrip above
152      */
153     if (!wl_emgd_ctx->emgd)
154         return false;
155     return true;
156 }