Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(249)

Side by Side Diff: third_party/libva/va/x11/va_x11.c

Issue 10375035: Add libva to chromium third_party. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2007 Intel Corporation. All Rights Reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sub license, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
14 * of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 #define _GNU_SOURCE 1
26 #include "sysdeps.h"
27 #include "va.h"
28 #include "va_backend.h"
29 #include "va_trace.h"
30 #include "va_fool.h"
31 #include "va_x11.h"
32 #include "va_dri2.h"
33 #include "va_dricommon.h"
34 #include "va_nvctrl.h"
35 #include "va_fglrx.h"
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <stdarg.h>
39 #include <string.h>
40 #include <unistd.h>
41 #include <sys/types.h>
42 #include <sys/stat.h>
43 #include <fcntl.h>
44 #include <errno.h>
45
46 static int va_DisplayContextIsValid (
47 VADisplayContextP pDisplayContext
48 )
49 {
50 return (pDisplayContext != NULL &&
51 pDisplayContext->pDriverContext != NULL);
52 }
53
54 static void va_DisplayContextDestroy (
55 VADisplayContextP pDisplayContext
56 )
57 {
58 VADriverContextP ctx;
59 struct dri_state *dri_state;
60
61 if (pDisplayContext == NULL)
62 return;
63
64 ctx = pDisplayContext->pDriverContext;
65 dri_state = ctx->dri_state;
66
67 if (dri_state && dri_state->close)
68 dri_state->close(ctx);
69
70 free(pDisplayContext->pDriverContext->dri_state);
71 free(pDisplayContext->pDriverContext);
72 free(pDisplayContext);
73 }
74
75
76 static VAStatus va_DRI2GetDriverName (
77 VADisplayContextP pDisplayContext,
78 char **driver_name
79 )
80 {
81 VADriverContextP ctx = pDisplayContext->pDriverContext;
82
83 if (!isDRI2Connected(ctx, driver_name))
84 return VA_STATUS_ERROR_UNKNOWN;
85
86 return VA_STATUS_SUCCESS;
87 }
88
89 static VAStatus va_NVCTRL_GetDriverName (
90 VADisplayContextP pDisplayContext,
91 char **driver_name
92 )
93 {
94 VADriverContextP ctx = pDisplayContext->pDriverContext;
95 int direct_capable, driver_major, driver_minor, driver_patch;
96 Bool result;
97
98 result = VA_NVCTRLQueryDirectRenderingCapable(ctx->native_dpy, ctx->x11_scre en,
99 &direct_capable);
100 if (!result || !direct_capable)
101 return VA_STATUS_ERROR_UNKNOWN;
102
103 result = VA_NVCTRLGetClientDriverName(ctx->native_dpy, ctx->x11_screen,
104 &driver_major, &driver_minor,
105 &driver_patch, driver_name);
106 if (!result)
107 return VA_STATUS_ERROR_UNKNOWN;
108
109 return VA_STATUS_SUCCESS;
110 }
111
112 static VAStatus va_FGLRX_GetDriverName (
113 VADisplayContextP pDisplayContext,
114 char **driver_name
115 )
116 {
117 VADriverContextP ctx = pDisplayContext->pDriverContext;
118 int driver_major, driver_minor, driver_patch;
119 Bool result;
120
121 result = VA_FGLRXGetClientDriverName(ctx->native_dpy, ctx->x11_screen,
122 &driver_major, &driver_minor,
123 &driver_patch, driver_name);
124 if (!result)
125 return VA_STATUS_ERROR_UNKNOWN;
126
127 return VA_STATUS_SUCCESS;
128 }
129
130 static VAStatus va_DisplayContextGetDriverName (
131 VADisplayContextP pDisplayContext,
132 char **driver_name
133 )
134 {
135 VAStatus vaStatus;
136
137 if (driver_name)
138 *driver_name = NULL;
139
140 vaStatus = va_DRI2GetDriverName(pDisplayContext, driver_name);
141 if (vaStatus != VA_STATUS_SUCCESS)
142 vaStatus = va_NVCTRL_GetDriverName(pDisplayContext, driver_name);
143 if (vaStatus != VA_STATUS_SUCCESS)
144 vaStatus = va_FGLRX_GetDriverName(pDisplayContext, driver_name);
145 return vaStatus;
146 }
147
148 static VAStatus va_CreateNativePixmap(
149 VADisplayContextP pDisplayContext,
150 unsigned int width,
151 unsigned int height,
152 void **native_pixmap)
153 {
154 VADriverContextP ctx = pDisplayContext->pDriverContext;
155 Window root_window;
156 XWindowAttributes wattr;
157 Pixmap pixmap = None;
158
159 root_window = RootWindow(ctx->native_dpy, ctx->x11_screen);
160 XGetWindowAttributes(ctx->native_dpy, root_window, &wattr);
161
162 if (wattr.depth != 24 && wattr.depth != 32)
163 return VA_STATUS_ERROR_INVALID_DISPLAY;
164
165 pixmap = XCreatePixmap(
166 ctx->native_dpy,
167 root_window,
168 width,
169 height,
170 wattr.depth
171 );
172
173 *native_pixmap = (void *)pixmap;
174
175 return !pixmap ? VA_STATUS_ERROR_UNKNOWN : VA_STATUS_SUCCESS;
176 }
177
178 static VAStatus va_FreeNativePixmap(
179 VADisplayContextP pDisplayContext,
180 void *native_pixmap)
181 {
182 VADriverContextP ctx = pDisplayContext->pDriverContext;
183 Pixmap pixmap = (Pixmap)native_pixmap;
184
185 XFreePixmap(ctx->native_dpy, pixmap);
186
187 return VA_STATUS_SUCCESS;
188 }
189
190 VADisplay vaGetDisplay (
191 Display *native_dpy /* implementation specific */
192 )
193 {
194 VADisplay dpy = NULL;
195 VADisplayContextP pDisplayContext;
196
197 if (!native_dpy)
198 return NULL;
199
200 if (!dpy)
201 {
202 /* create new entry */
203 VADriverContextP pDriverContext;
204 struct dri_state *dri_state;
205 pDisplayContext = calloc(1, sizeof(*pDisplayContext));
206 pDriverContext = calloc(1, sizeof(*pDriverContext));
207 dri_state = calloc(1, sizeof(*dri_state));
208 if (pDisplayContext && pDriverContext && dri_state)
209 {
210 pDisplayContext->vadpy_magic = VA_DISPLAY_MAGIC;
211
212 pDriverContext->native_dpy = (void *)native_dpy;
213 pDisplayContext->pDriverContext = pDriverContext;
214 pDisplayContext->vaIsValid = va_DisplayContextIsValid;
215 pDisplayContext->vaDestroy = va_DisplayContextDestroy;
216 pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName;
217 pDisplayContext->opaque = NULL;
218 pDisplayContext->vaCreateNativePixmap = va_CreateNativePixmap;
219 pDisplayContext->vaFreeNativePixmap = va_FreeNativePixmap;
220 pDriverContext->dri_state = dri_state;
221 dpy = (VADisplay)pDisplayContext;
222 }
223 else
224 {
225 if (pDisplayContext)
226 free(pDisplayContext);
227 if (pDriverContext)
228 free(pDriverContext);
229 if (dri_state)
230 free(dri_state);
231 }
232 }
233
234 return dpy;
235 }
236
237 #define CTX(dpy) (((VADisplayContextP)dpy)->pDriverContext)
238 #define CHECK_DISPLAY(dpy) if( !vaDisplayIsValid(dpy) ) { return VA_STATUS_ERROR _INVALID_DISPLAY; }
239
240 void va_TracePutSurface (
241 VADisplay dpy,
242 VASurfaceID surface,
243 void *draw, /* the target Drawable */
244 short srcx,
245 short srcy,
246 unsigned short srcw,
247 unsigned short srch,
248 short destx,
249 short desty,
250 unsigned short destw,
251 unsigned short desth,
252 VARectangle *cliprects, /* client supplied clip list */
253 unsigned int number_cliprects, /* number of clip rects in the clip list */
254 unsigned int flags /* de-interlacing flags */
255 );
256
257
258 VAStatus vaPutSurface (
259 VADisplay dpy,
260 VASurfaceID surface,
261 Drawable draw, /* X Drawable */
262 short srcx,
263 short srcy,
264 unsigned short srcw,
265 unsigned short srch,
266 short destx,
267 short desty,
268 unsigned short destw,
269 unsigned short desth,
270 VARectangle *cliprects, /* client supplied clip list */
271 unsigned int number_cliprects, /* number of clip rects in the clip list */
272 unsigned int flags /* de-interlacing flags */
273 )
274 {
275 VADriverContextP ctx;
276
277 if (fool_postp)
278 return VA_STATUS_SUCCESS;
279
280 CHECK_DISPLAY(dpy);
281 ctx = CTX(dpy);
282
283 VA_TRACE_FUNC(va_TracePutSurface, dpy, surface, (void *)draw, srcx, srcy, srcw , srch,
284 destx, desty, destw, desth,
285 cliprects, number_cliprects, flags );
286
287 return ctx->vtable->vaPutSurface( ctx, surface, (void *)draw, srcx, srcy, srcw , srch,
288 destx, desty, destw, desth,
289 cliprects, number_cliprects, flags );
290 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698