hardware/intel/common/libva
Révision | 4cc9a74bd82e9b1c5cfe7fc5fce056a01b99ecdb (tree) |
---|---|
l'heure | 2017-11-22 14:38:52 |
Auteur | Mark Thompson <sw@jkqx...> |
Commiter | Xiang, Haihao |
Move driver context allocation to common code
This will be required to set common options on a newly-created driver
context.
Signed-off-by: Mark Thompson <sw@jkqxz.net>
@@ -125,43 +125,40 @@ VADisplay vaGetDisplay ( | ||
125 | 125 | void *native_dpy /* implementation specific */ |
126 | 126 | ) |
127 | 127 | { |
128 | - VADisplay dpy = NULL; | |
129 | 128 | VADisplayContextP pDisplayContext; |
129 | + VADriverContextP pDriverContext; | |
130 | + struct drm_state *drm_state; | |
130 | 131 | |
131 | 132 | if (!native_dpy) |
132 | 133 | return NULL; |
133 | 134 | |
134 | - if (!dpy) | |
135 | - { | |
136 | - /* create new entry */ | |
137 | - VADriverContextP pDriverContext = 0; | |
138 | - struct drm_state *drm_state = 0; | |
139 | - pDisplayContext = va_newDisplayContext(); | |
140 | - pDriverContext = (VADriverContextP)calloc(1, sizeof(*pDriverContext)); | |
141 | - drm_state = (struct drm_state*)calloc(1, sizeof(*drm_state)); | |
142 | - if (pDisplayContext && pDriverContext && drm_state) | |
143 | - { | |
144 | - pDriverContext->native_dpy = (void *)native_dpy; | |
145 | - pDriverContext->display_type = VA_DISPLAY_ANDROID; | |
146 | - pDisplayContext->pDriverContext = pDriverContext; | |
147 | - pDisplayContext->vaIsValid = va_DisplayContextIsValid; | |
148 | - pDisplayContext->vaDestroy = va_DisplayContextDestroy; | |
149 | - pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName; | |
150 | - pDriverContext->drm_state = drm_state; | |
151 | - dpy = (VADisplay)pDisplayContext; | |
152 | - } | |
153 | - else | |
154 | - { | |
155 | - if (pDisplayContext) | |
156 | - free(pDisplayContext); | |
157 | - if (pDriverContext) | |
158 | - free(pDriverContext); | |
159 | - if (drm_state) | |
160 | - free(drm_state); | |
161 | - } | |
135 | + pDisplayContext = va_newDisplayContext(); | |
136 | + if (!pDisplayContext) | |
137 | + return NULL; | |
138 | + | |
139 | + pDisplayContext->vaIsValid = va_DisplayContextIsValid; | |
140 | + pDisplayContext->vaDestroy = va_DisplayContextDestroy; | |
141 | + pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName; | |
142 | + | |
143 | + pDriverContext = va_newDriverContext(pDisplayContext); | |
144 | + if (!pDriverContext) { | |
145 | + free(pDisplayContext); | |
146 | + return NULL; | |
162 | 147 | } |
163 | - | |
164 | - return dpy; | |
148 | + | |
149 | + pDriverContext->native_dpy = (void *)native_dpy; | |
150 | + pDriverContext->display_type = VA_DISPLAY_ANDROID | |
151 | + | |
152 | + drm_state = calloc(1, sizeof(*drm_state)); | |
153 | + if (!drm_state) { | |
154 | + free(pDisplayContext); | |
155 | + free(pDriverContext); | |
156 | + return NULL; | |
157 | + } | |
158 | + | |
159 | + pDriverContext->drm_state = drm_state; | |
160 | + | |
161 | + return (VADisplay)pDisplayContext; | |
165 | 162 | } |
166 | 163 | |
167 | 164 |
@@ -102,22 +102,23 @@ vaGetDisplayDRM(int fd) | ||
102 | 102 | goto error; |
103 | 103 | drm_state->fd = fd; |
104 | 104 | |
105 | - pDriverContext = calloc(1, sizeof(*pDriverContext)); | |
106 | - if (!pDriverContext) | |
107 | - goto error; | |
108 | - pDriverContext->native_dpy = NULL; | |
109 | - pDriverContext->display_type = is_render_nodes ? | |
110 | - VA_DISPLAY_DRM_RENDERNODES : VA_DISPLAY_DRM; | |
111 | - pDriverContext->drm_state = drm_state; | |
112 | - | |
113 | 105 | pDisplayContext = va_newDisplayContext(); |
114 | 106 | if (!pDisplayContext) |
115 | 107 | goto error; |
116 | 108 | |
117 | - pDisplayContext->pDriverContext = pDriverContext; | |
118 | 109 | pDisplayContext->vaIsValid = va_DisplayContextIsValid; |
119 | 110 | pDisplayContext->vaDestroy = va_DisplayContextDestroy; |
120 | 111 | pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName; |
112 | + | |
113 | + pDriverContext = va_newDriverContext(pDisplayContext); | |
114 | + if (!pDriverContext) | |
115 | + goto error; | |
116 | + | |
117 | + pDriverContext->native_dpy = NULL; | |
118 | + pDriverContext->display_type = is_render_nodes ? | |
119 | + VA_DISPLAY_DRM_RENDERNODES : VA_DISPLAY_DRM; | |
120 | + pDriverContext->drm_state = drm_state; | |
121 | + | |
121 | 122 | return pDisplayContext; |
122 | 123 | |
123 | 124 | error: |
@@ -275,6 +275,17 @@ VADisplayContextP va_newDisplayContext(void) | ||
275 | 275 | return dctx; |
276 | 276 | } |
277 | 277 | |
278 | +VADriverContextP va_newDriverContext(VADisplayContextP dctx) | |
279 | +{ | |
280 | + VADriverContextP ctx = calloc(1, sizeof(*ctx)); | |
281 | + if (!ctx) | |
282 | + return NULL; | |
283 | + | |
284 | + dctx->pDriverContext = ctx; | |
285 | + | |
286 | + return ctx; | |
287 | +} | |
288 | + | |
278 | 289 | static bool va_checkVtable(VADisplay dpy, void *ptr, char *function) |
279 | 290 | { |
280 | 291 | if (!ptr) { |
@@ -39,6 +39,8 @@ int va_parseConfig(char *env, char *env_value); | ||
39 | 39 | |
40 | 40 | VADisplayContextP va_newDisplayContext(void); |
41 | 41 | |
42 | +VADriverContextP va_newDriverContext(VADisplayContextP dctx); | |
43 | + | |
42 | 44 | #ifdef __cplusplus |
43 | 45 | } |
44 | 46 | #endif |
@@ -129,10 +129,9 @@ vaGetDisplayWl(struct wl_display *display) | ||
129 | 129 | pDisplayContext->vaDestroy = va_DisplayContextDestroy; |
130 | 130 | pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName; |
131 | 131 | |
132 | - pDriverContext = calloc(1, sizeof(*pDriverContext)); | |
132 | + pDriverContext = va_newDriverContext(pDisplayContext); | |
133 | 133 | if (!pDriverContext) |
134 | 134 | goto error; |
135 | - pDisplayContext->pDriverContext = pDriverContext; | |
136 | 135 | |
137 | 136 | pDriverContext->native_dpy = display; |
138 | 137 | pDriverContext->display_type = VA_DISPLAY_WAYLAND; |
@@ -153,45 +153,41 @@ VADisplay vaGetDisplay ( | ||
153 | 153 | Display *native_dpy /* implementation specific */ |
154 | 154 | ) |
155 | 155 | { |
156 | - VADisplay dpy = NULL; | |
157 | - VADisplayContextP pDisplayContext; | |
158 | - | |
159 | - if (!native_dpy) | |
160 | - return NULL; | |
161 | - | |
162 | - if (!dpy) | |
163 | - { | |
164 | - /* create new entry */ | |
165 | - VADriverContextP pDriverContext; | |
166 | - struct dri_state *dri_state; | |
167 | - pDisplayContext = va_newDisplayContext(); | |
168 | - pDriverContext = calloc(1, sizeof(*pDriverContext)); | |
169 | - dri_state = calloc(1, sizeof(*dri_state)); | |
170 | - if (pDisplayContext && pDriverContext && dri_state) | |
171 | - { | |
172 | - pDriverContext->native_dpy = (void *)native_dpy; | |
173 | - pDriverContext->x11_screen = XDefaultScreen(native_dpy); | |
174 | - pDriverContext->display_type = VA_DISPLAY_X11; | |
175 | - pDisplayContext->pDriverContext = pDriverContext; | |
176 | - pDisplayContext->vaIsValid = va_DisplayContextIsValid; | |
177 | - pDisplayContext->vaDestroy = va_DisplayContextDestroy; | |
178 | - pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName; | |
179 | - pDisplayContext->opaque = NULL; | |
180 | - pDriverContext->drm_state = dri_state; | |
181 | - dpy = (VADisplay)pDisplayContext; | |
182 | - } | |
183 | - else | |
184 | - { | |
185 | - if (pDisplayContext) | |
186 | - free(pDisplayContext); | |
187 | - if (pDriverContext) | |
188 | - free(pDriverContext); | |
189 | - if (dri_state) | |
190 | - free(dri_state); | |
191 | - } | |
192 | - } | |
193 | - | |
194 | - return dpy; | |
156 | + VADisplayContextP pDisplayContext; | |
157 | + VADriverContextP pDriverContext; | |
158 | + struct dri_state *dri_state; | |
159 | + | |
160 | + if (!native_dpy) | |
161 | + return NULL; | |
162 | + | |
163 | + pDisplayContext = va_newDisplayContext(); | |
164 | + if (!pDisplayContext) | |
165 | + return NULL; | |
166 | + | |
167 | + pDisplayContext->vaIsValid = va_DisplayContextIsValid; | |
168 | + pDisplayContext->vaDestroy = va_DisplayContextDestroy; | |
169 | + pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName; | |
170 | + | |
171 | + pDriverContext = va_newDriverContext(pDisplayContext); | |
172 | + if (!pDriverContext) { | |
173 | + free(pDisplayContext); | |
174 | + return NULL; | |
175 | + } | |
176 | + | |
177 | + pDriverContext->native_dpy = (void *)native_dpy; | |
178 | + pDriverContext->x11_screen = XDefaultScreen(native_dpy); | |
179 | + pDriverContext->display_type = VA_DISPLAY_X11; | |
180 | + | |
181 | + dri_state = calloc(1, sizeof(*dri_state)); | |
182 | + if (!dri_state) { | |
183 | + free(pDisplayContext); | |
184 | + free(pDriverContext); | |
185 | + return NULL; | |
186 | + } | |
187 | + | |
188 | + pDriverContext->drm_state = dri_state; | |
189 | + | |
190 | + return (VADisplay)pDisplayContext; | |
195 | 191 | } |
196 | 192 | |
197 | 193 |