OSDN Git Service

Add new BRC mode AVBR
[android-x86/hardware-intel-common-libva.git] / va / x11 / va_x11.c
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_internal.h"
30 #include "va_trace.h"
31 #include "va_fool.h"
32 #include "va_x11.h"
33 #include "va_dri2.h"
34 #include "va_dricommon.h"
35 #include "va_nvctrl.h"
36 #include "va_fglrx.h"
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <stdarg.h>
40 #include <string.h>
41 #include <unistd.h>
42 #include <sys/types.h>
43 #include <sys/stat.h>
44 #include <fcntl.h>
45 #include <errno.h>
46
47 static int va_DisplayContextIsValid (
48     VADisplayContextP pDisplayContext
49 )
50 {
51     return (pDisplayContext != NULL && 
52             pDisplayContext->pDriverContext != NULL);
53 }
54
55 static void va_DisplayContextDestroy (
56     VADisplayContextP pDisplayContext
57 )
58 {
59     VADriverContextP ctx;
60     struct dri_state *dri_state;
61
62     if (pDisplayContext == NULL)
63         return;
64
65     ctx = pDisplayContext->pDriverContext;
66     dri_state = ctx->drm_state;
67
68     if (dri_state && dri_state->close)
69         dri_state->close(ctx);
70
71     free(pDisplayContext->pDriverContext->drm_state);
72     free(pDisplayContext->pDriverContext);
73     free(pDisplayContext);
74 }
75
76
77 static VAStatus va_DRI2GetDriverName (
78     VADisplayContextP pDisplayContext,
79     char **driver_name
80 )
81 {
82     VADriverContextP ctx = pDisplayContext->pDriverContext;
83
84     if (!va_isDRI2Connected(ctx, driver_name))
85         return VA_STATUS_ERROR_UNKNOWN;
86
87     return VA_STATUS_SUCCESS;
88 }
89
90 static VAStatus va_NVCTRL_GetDriverName (
91     VADisplayContextP pDisplayContext,
92     char **driver_name
93 )
94 {
95     VADriverContextP ctx = pDisplayContext->pDriverContext;
96     int direct_capable, driver_major, driver_minor, driver_patch;
97     Bool result;
98
99     result = VA_NVCTRLQueryDirectRenderingCapable(ctx->native_dpy, ctx->x11_screen,
100                                                   &direct_capable);
101     if (!result || !direct_capable)
102         return VA_STATUS_ERROR_UNKNOWN;
103
104     result = VA_NVCTRLGetClientDriverName(ctx->native_dpy, ctx->x11_screen,
105                                           &driver_major, &driver_minor,
106                                           &driver_patch, driver_name);
107     if (!result)
108         return VA_STATUS_ERROR_UNKNOWN;
109
110     return VA_STATUS_SUCCESS;
111 }
112
113 static VAStatus va_FGLRX_GetDriverName (
114     VADisplayContextP pDisplayContext,
115     char **driver_name
116 )
117 {
118     VADriverContextP ctx = pDisplayContext->pDriverContext;
119     int driver_major, driver_minor, driver_patch;
120     Bool result;
121
122     result = VA_FGLRXGetClientDriverName(ctx->native_dpy, ctx->x11_screen,
123                                          &driver_major, &driver_minor,
124                                          &driver_patch, driver_name);
125     if (!result)
126         return VA_STATUS_ERROR_UNKNOWN;
127
128     return VA_STATUS_SUCCESS;
129 }
130
131 static VAStatus va_DisplayContextGetDriverName (
132     VADisplayContextP pDisplayContext,
133     char **driver_name
134 )
135 {
136     VAStatus vaStatus;
137
138     if (driver_name)
139         *driver_name = NULL;
140     else
141         return VA_STATUS_ERROR_UNKNOWN;
142     
143     vaStatus = va_DRI2GetDriverName(pDisplayContext, driver_name);
144     if (vaStatus != VA_STATUS_SUCCESS)
145         vaStatus = va_NVCTRL_GetDriverName(pDisplayContext, driver_name);
146     if (vaStatus != VA_STATUS_SUCCESS)
147         vaStatus = va_FGLRX_GetDriverName(pDisplayContext, driver_name);
148     return vaStatus;
149 }
150
151
152 VADisplay vaGetDisplay (
153     Display *native_dpy /* implementation specific */
154 )
155 {
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;
191 }
192
193
194 void va_TracePutSurface (
195     VADisplay dpy,
196     VASurfaceID surface,
197     void *draw, /* the target Drawable */
198     short srcx,
199     short srcy,
200     unsigned short srcw,
201     unsigned short srch,
202     short destx,
203     short desty,
204     unsigned short destw,
205     unsigned short desth,
206     VARectangle *cliprects, /* client supplied clip list */
207     unsigned int number_cliprects, /* number of clip rects in the clip list */
208     unsigned int flags /* de-interlacing flags */
209 );
210
211
212 VAStatus vaPutSurface (
213     VADisplay dpy,
214     VASurfaceID surface,
215     Drawable draw, /* X Drawable */
216     short srcx,
217     short srcy,
218     unsigned short srcw,
219     unsigned short srch,
220     short destx,
221     short desty,
222     unsigned short destw,
223     unsigned short desth,
224     VARectangle *cliprects, /* client supplied clip list */
225     unsigned int number_cliprects, /* number of clip rects in the clip list */
226     unsigned int flags /* de-interlacing flags */
227 )
228 {
229   VADriverContextP ctx;
230
231   if (va_fool_postp)
232       return VA_STATUS_SUCCESS;
233
234   CHECK_DISPLAY(dpy);
235   ctx = CTX(dpy);
236   
237   VA_TRACE_LOG(va_TracePutSurface, dpy, surface, (void *)draw, srcx, srcy, srcw, srch,
238                destx, desty, destw, desth,
239                cliprects, number_cliprects, flags );
240   
241   return ctx->vtable->vaPutSurface( ctx, surface, (void *)draw, srcx, srcy, srcw, srch,
242                                    destx, desty, destw, desth,
243                                    cliprects, number_cliprects, flags );
244 }