hardware/intel/common/libva
修订版 | 341716afee65acdd549bb6e84a7101e9803cfe00 (tree) |
---|---|
时间 | 2010-03-31 15:23:36 |
作者 | Austin Yuan <shengquan.yuan@gmai...> |
Commiter | Austin Yuan |
Initial android backend
Signed-off-by: Austin Yuan <shengquan.yuan@gmail.com>
@@ -0,0 +1,163 @@ | ||
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 "config.h" | |
27 | +#include "va.h" | |
28 | +#include "va_backend.h" | |
29 | +#include <stdio.h> | |
30 | +#include <stdlib.h> | |
31 | +#include <stdarg.h> | |
32 | +#include <string.h> | |
33 | +#include <unistd.h> | |
34 | +#include <sys/types.h> | |
35 | +#include <sys/stat.h> | |
36 | +#include <fcntl.h> | |
37 | +#include <errno.h> | |
38 | + | |
39 | +static VADisplayContextP pDisplayContexts = NULL; | |
40 | + | |
41 | +static int va_DisplayContextIsValid ( | |
42 | + VADisplayContextP pDisplayContext | |
43 | +) | |
44 | +{ | |
45 | + VADisplayContextP ctx = pDisplayContexts; | |
46 | + | |
47 | + while (ctx) | |
48 | + { | |
49 | + if (ctx == pDisplayContext && pDisplayContext->pDriverContext) | |
50 | + return 1; | |
51 | + ctx = ctx->pNext; | |
52 | + } | |
53 | + return 0; | |
54 | +} | |
55 | + | |
56 | +static void va_DisplayContextDestroy ( | |
57 | + VADisplayContextP pDisplayContext | |
58 | +) | |
59 | +{ | |
60 | + VADisplayContextP *ctx = &pDisplayContexts; | |
61 | + | |
62 | + /* Throw away pDisplayContext */ | |
63 | + while (*ctx) | |
64 | + { | |
65 | + if (*ctx == pDisplayContext) | |
66 | + { | |
67 | + *ctx = pDisplayContext->pNext; | |
68 | + pDisplayContext->pNext = NULL; | |
69 | + break; | |
70 | + } | |
71 | + ctx = &((*ctx)->pNext); | |
72 | + } | |
73 | + free(pDisplayContext->pDriverContext->dri_state); | |
74 | + free(pDisplayContext->pDriverContext); | |
75 | + free(pDisplayContext); | |
76 | +} | |
77 | + | |
78 | + | |
79 | +static VAStatus va_DisplayContextGetDriverName ( | |
80 | + VADisplayContextP pDisplayContext, | |
81 | + char **driver_name | |
82 | +) | |
83 | +{ | |
84 | + VAStatus vaStatus VA_STATUS_SUCCESS; | |
85 | + char *driver_name_env; | |
86 | + struct { | |
87 | + unsigned int verndor_id; | |
88 | + unsigned int device_id; | |
89 | + char driver_name[64]; | |
90 | + } devices[] = { | |
91 | + { 0x8086, 0x4100, "pvr" }, | |
92 | + }; | |
93 | + | |
94 | + if (driver_name) | |
95 | + *driver_name = NULL; | |
96 | + | |
97 | + if ((driver_name_env = getenv("LIBVA_DRIVER_NAME")) != NULL | |
98 | + && geteuid() == getuid()) | |
99 | + { | |
100 | + /* don't allow setuid apps to use LIBVA_DRIVER_NAME */ | |
101 | + *driver_name = strdup(driver_name_env); | |
102 | + return VA_STATUS_SUCCESS; | |
103 | + } | |
104 | + | |
105 | + *driver_name = strdup(devices[0].driver_name); | |
106 | + | |
107 | + return vaStatus; | |
108 | +} | |
109 | + | |
110 | + | |
111 | +VADisplay vaGetDisplay ( | |
112 | + Display *native_dpy /* implementation specific */ | |
113 | +) | |
114 | +{ | |
115 | + VADisplay dpy = NULL; | |
116 | + VADisplayContextP pDisplayContext = pDisplayContexts; | |
117 | + | |
118 | + if (!native_dpy) | |
119 | + return NULL; | |
120 | + | |
121 | + while (pDisplayContext) | |
122 | + { | |
123 | + if (pDisplayContext->pDriverContext && | |
124 | + pDisplayContext->pDriverContext->native_dpy == (void *)native_dpy) | |
125 | + { | |
126 | + dpy = (VADisplay)pDisplayContext; | |
127 | + break; | |
128 | + } | |
129 | + pDisplayContext = pDisplayContext->pNext; | |
130 | + } | |
131 | + | |
132 | + if (!dpy) | |
133 | + { | |
134 | + /* create new entry */ | |
135 | + VADriverContextP pDriverContext; | |
136 | + struct dri_state *dri_state; | |
137 | + pDisplayContext = calloc(1, sizeof(*pDisplayContext)); | |
138 | + pDriverContext = calloc(1, sizeof(*pDriverContext)); | |
139 | + if (pDisplayContext && pDriverContext && dri_state) | |
140 | + { | |
141 | + pDisplayContext->vadpy_magic = VA_DISPLAY_MAGIC; | |
142 | + | |
143 | + pDriverContext->native_dpy = (void *)native_dpy; | |
144 | + pDisplayContext->pNext = pDisplayContexts; | |
145 | + pDisplayContext->pDriverContext = pDriverContext; | |
146 | + pDisplayContext->vaIsValid = va_DisplayContextIsValid; | |
147 | + pDisplayContext->vaDestroy = va_DisplayContextDestroy; | |
148 | + pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName; | |
149 | + pDisplayContexts = pDisplayContext; | |
150 | + pDriverContext->dri_state = dri_state; | |
151 | + dpy = (VADisplay)pDisplayContext; | |
152 | + } | |
153 | + else | |
154 | + { | |
155 | + if (pDisplayContext) | |
156 | + free(pDisplayContext); | |
157 | + if (pDriverContext) | |
158 | + free(pDriverContext); | |
159 | + } | |
160 | + } | |
161 | + | |
162 | + return dpy; | |
163 | +} |
@@ -739,32 +739,6 @@ VAStatus vaQuerySurfaceStatus ( | ||
739 | 739 | return ctx->vtable.vaQuerySurfaceStatus( ctx, render_target, status ); |
740 | 740 | } |
741 | 741 | |
742 | -VAStatus vaPutSurface ( | |
743 | - VADisplay dpy, | |
744 | - VASurfaceID surface, | |
745 | - Drawable draw, /* X Drawable */ | |
746 | - short srcx, | |
747 | - short srcy, | |
748 | - unsigned short srcw, | |
749 | - unsigned short srch, | |
750 | - short destx, | |
751 | - short desty, | |
752 | - unsigned short destw, | |
753 | - unsigned short desth, | |
754 | - VARectangle *cliprects, /* client supplied clip list */ | |
755 | - unsigned int number_cliprects, /* number of clip rects in the clip list */ | |
756 | - unsigned int flags /* de-interlacing flags */ | |
757 | -) | |
758 | -{ | |
759 | - VADriverContextP ctx; | |
760 | - CHECK_DISPLAY(dpy); | |
761 | - ctx = CTX(dpy); | |
762 | - | |
763 | - return ctx->vtable.vaPutSurface( ctx, surface, draw, srcx, srcy, srcw, srch, | |
764 | - destx, desty, destw, desth, | |
765 | - cliprects, number_cliprects, flags ); | |
766 | -} | |
767 | - | |
768 | 742 | /* Get maximum number of image formats supported by the implementation */ |
769 | 743 | int vaMaxNumImageFormats ( |
770 | 744 | VADisplay dpy |
@@ -0,0 +1,46 @@ | ||
1 | +#ifndef _VA_ANDROID_H_ | |
2 | +#define _VA_ANDROID_H_ | |
3 | + | |
4 | +#include <va/va.h> | |
5 | + | |
6 | +#ifdef __cplusplus | |
7 | +extern "C" { | |
8 | +#endif | |
9 | + | |
10 | +/* | |
11 | + * Returns a suitable VADisplay for VA API | |
12 | + */ | |
13 | +VADisplay vaGetDisplay ( | |
14 | + void *dpy | |
15 | +); | |
16 | + | |
17 | +/* | |
18 | + * Output rendering | |
19 | + * Following is the rendering interface for X windows, | |
20 | + * to get the decode output surface to a X drawable | |
21 | + * It basically performs a de-interlacing (if needed), | |
22 | + * color space conversion and scaling to the destination | |
23 | + * rectangle | |
24 | + */ | |
25 | +VAStatus vaPutSurface ( | |
26 | + VADisplay dpy, | |
27 | + VASurfaceID surface, | |
28 | + Surface *draw, /* Android Window/Surface */ | |
29 | + short srcx, | |
30 | + short srcy, | |
31 | + unsigned short srcw, | |
32 | + unsigned short srch, | |
33 | + short destx, | |
34 | + short desty, | |
35 | + unsigned short destw, | |
36 | + unsigned short desth, | |
37 | + VARectangle *cliprects, /* client supplied destination clip list */ | |
38 | + unsigned int number_cliprects, /* number of clip rects in the clip list */ | |
39 | + unsigned int flags /* PutSurface flags */ | |
40 | +); | |
41 | + | |
42 | +#ifdef __cplusplus | |
43 | +} | |
44 | +#endif | |
45 | + | |
46 | +#endif /* _VA_ANDROID_H_ */ |
@@ -28,6 +28,7 @@ | ||
28 | 28 | |
29 | 29 | #include <assert.h> |
30 | 30 | #include <stdarg.h> |
31 | +#include <stdlib.h> | |
31 | 32 | #include <stdio.h> |
32 | 33 | #include <string.h> |
33 | 34 | #include <dlfcn.h> |
@@ -49,7 +50,7 @@ static unsigned int trace_height; | ||
49 | 50 | |
50 | 51 | int va_TraceInit(void) |
51 | 52 | { |
52 | - trace_file = getenv("LIBVA_TRACE"); | |
53 | + trace_file = (const char *)getenv("LIBVA_TRACE"); | |
53 | 54 | if (trace_file) { |
54 | 55 | trace_fp = fopen(trace_file, "w"); |
55 | 56 | if (trace_fp) |
@@ -1109,5 +1110,5 @@ int va_TraceEndPicture( | ||
1109 | 1110 | tmp = UV_data + i * chroma_u_stride; |
1110 | 1111 | } |
1111 | 1112 | } |
1112 | - free(buffer); | |
1113 | + free((void *)buffer); | |
1113 | 1114 | } |
@@ -215,3 +215,29 @@ VADisplay vaGetDisplay ( | ||
215 | 215 | |
216 | 216 | return dpy; |
217 | 217 | } |
218 | + | |
219 | +VAStatus vaPutSurface ( | |
220 | + VADisplay dpy, | |
221 | + VASurfaceID surface, | |
222 | + Drawable draw, /* X Drawable */ | |
223 | + short srcx, | |
224 | + short srcy, | |
225 | + unsigned short srcw, | |
226 | + unsigned short srch, | |
227 | + short destx, | |
228 | + short desty, | |
229 | + unsigned short destw, | |
230 | + unsigned short desth, | |
231 | + VARectangle *cliprects, /* client supplied clip list */ | |
232 | + unsigned int number_cliprects, /* number of clip rects in the clip list */ | |
233 | + unsigned int flags /* de-interlacing flags */ | |
234 | +) | |
235 | +{ | |
236 | + VADriverContextP ctx; | |
237 | + CHECK_DISPLAY(dpy); | |
238 | + ctx = CTX(dpy); | |
239 | + | |
240 | + return ctx->vtable.vaPutSurface( ctx, surface, draw, srcx, srcy, srcw, srch, | |
241 | + destx, desty, destw, desth, | |
242 | + cliprects, number_cliprects, flags ); | |
243 | +} |