~ubuntu-branches/ubuntu/natty/libva/natty

« back to all changes in this revision

Viewing changes to src/x11/va_x11.c

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler, Artur Rona, Reinhard Tartler
  • Date: 2011-02-13 19:01:16 UTC
  • mfrom: (3.2.2 sid)
  • Revision ID: james.westby@ubuntu.com-20110213190116-wy9fqh71nmomiacl
Tags: 1.0.8-3
[ Artur Rona ]
* Update library dependencies to fix FTBFS properly.

[ Reinhard Tartler ]
* Disable i965 driver on hurd-i386, Closes: #613102

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 "va_x11.h"
30
 
#include "va_dri.h"
31
 
#include "va_dri2.h"
32
 
#include "va_dricommon.h"
33
 
#include "va_nvctrl.h"
34
 
#include <stdio.h>
35
 
#include <stdarg.h>
36
 
#include <string.h>
37
 
#include <unistd.h>
38
 
#include <sys/types.h>
39
 
#include <sys/stat.h>
40
 
#include <fcntl.h>
41
 
#include <errno.h>
42
 
 
43
 
static VADisplayContextP pDisplayContexts = NULL;
44
 
 
45
 
static int va_DisplayContextIsValid (
46
 
    VADisplayContextP pDisplayContext
47
 
)
48
 
{
49
 
    VADisplayContextP ctx = pDisplayContexts;
50
 
 
51
 
    while (ctx)
52
 
    {
53
 
        if (ctx == pDisplayContext && pDisplayContext->pDriverContext)
54
 
            return 1;
55
 
        ctx = ctx->pNext;
56
 
    }
57
 
    return 0;
58
 
}
59
 
 
60
 
static void va_DisplayContextDestroy (
61
 
    VADisplayContextP pDisplayContext
62
 
)
63
 
{
64
 
    VADisplayContextP *ctx = &pDisplayContexts;
65
 
 
66
 
    /* Throw away pDisplayContext */
67
 
    while (*ctx)
68
 
    {
69
 
        if (*ctx == pDisplayContext)
70
 
        {
71
 
            *ctx = pDisplayContext->pNext;
72
 
            pDisplayContext->pNext = NULL;
73
 
            break;
74
 
        }
75
 
        ctx = &((*ctx)->pNext);
76
 
    }
77
 
    free(pDisplayContext->pDriverContext->dri_state);
78
 
    free(pDisplayContext->pDriverContext);
79
 
    free(pDisplayContext);
80
 
}
81
 
 
82
 
 
83
 
static VAStatus va_DRI2GetDriverName (
84
 
    VADisplayContextP pDisplayContext,
85
 
    char **driver_name
86
 
)
87
 
{
88
 
    VADriverContextP ctx = pDisplayContext->pDriverContext;
89
 
 
90
 
    if (!isDRI2Connected(ctx, driver_name))
91
 
        return VA_STATUS_ERROR_UNKNOWN;
92
 
 
93
 
    return VA_STATUS_SUCCESS;
94
 
}
95
 
 
96
 
static VAStatus va_DRIGetDriverName (
97
 
    VADisplayContextP pDisplayContext,
98
 
    char **driver_name
99
 
)
100
 
{
101
 
    VADriverContextP ctx = pDisplayContext->pDriverContext;
102
 
 
103
 
    if (!isDRI1Connected(ctx, driver_name))
104
 
        return VA_STATUS_ERROR_UNKNOWN;
105
 
 
106
 
    return VA_STATUS_SUCCESS;
107
 
}
108
 
 
109
 
static VAStatus va_NVCTRL_GetDriverName (
110
 
    VADisplayContextP pDisplayContext,
111
 
    char **driver_name
112
 
)
113
 
{
114
 
    VADriverContextP ctx = pDisplayContext->pDriverContext;
115
 
    int direct_capable, driver_major, driver_minor, driver_patch;
116
 
    Bool result;
117
 
 
118
 
    result = VA_NVCTRLQueryDirectRenderingCapable(ctx->x11_dpy, ctx->x11_screen,
119
 
                                                  &direct_capable);
120
 
    if (!result || !direct_capable)
121
 
        return VA_STATUS_ERROR_UNKNOWN;
122
 
 
123
 
    result = VA_NVCTRLGetClientDriverName(ctx->x11_dpy, ctx->x11_screen,
124
 
                                          &driver_major, &driver_minor,
125
 
                                          &driver_patch, driver_name);
126
 
    if (!result)
127
 
        return VA_STATUS_ERROR_UNKNOWN;
128
 
 
129
 
    return VA_STATUS_SUCCESS;
130
 
}
131
 
 
132
 
static VAStatus va_DisplayContextGetDriverName (
133
 
    VADisplayContextP pDisplayContext,
134
 
    char **driver_name
135
 
)
136
 
{
137
 
    VAStatus vaStatus;
138
 
    char *driver_name_env;
139
 
 
140
 
    if (driver_name)
141
 
        *driver_name = NULL;
142
 
 
143
 
    if ((driver_name_env = getenv("LIBVA_DRIVER_NAME")) != NULL
144
 
        && geteuid() == getuid())
145
 
    {
146
 
        /* don't allow setuid apps to use LIBVA_DRIVER_NAME */
147
 
        *driver_name = strdup(driver_name_env);
148
 
        return VA_STATUS_SUCCESS;
149
 
    }
150
 
 
151
 
    vaStatus = va_DRI2GetDriverName(pDisplayContext, driver_name);
152
 
    if (vaStatus != VA_STATUS_SUCCESS)
153
 
        vaStatus = va_DRIGetDriverName(pDisplayContext, driver_name);
154
 
    if (vaStatus != VA_STATUS_SUCCESS)
155
 
        vaStatus = va_NVCTRL_GetDriverName(pDisplayContext, driver_name);
156
 
   
157
 
    return vaStatus;
158
 
}
159
 
 
160
 
 
161
 
VADisplay vaGetDisplay (
162
 
    Display *native_dpy /* implementation specific */
163
 
)
164
 
{
165
 
  VADisplay dpy = NULL;
166
 
  VADisplayContextP pDisplayContext = pDisplayContexts;
167
 
 
168
 
  if (!native_dpy)
169
 
      return NULL;
170
 
 
171
 
  while (pDisplayContext)
172
 
  {
173
 
      if (pDisplayContext->pDriverContext &&
174
 
          pDisplayContext->pDriverContext->x11_dpy == native_dpy)
175
 
      {
176
 
          dpy = (VADisplay)pDisplayContext;
177
 
          break;
178
 
      }
179
 
      pDisplayContext = pDisplayContext->pNext;
180
 
  }
181
 
 
182
 
  if (!dpy)
183
 
  {
184
 
      /* create new entry */
185
 
      VADriverContextP pDriverContext;
186
 
      struct dri_state *dri_state;
187
 
      pDisplayContext = calloc(1, sizeof(*pDisplayContext));
188
 
      pDriverContext  = calloc(1, sizeof(*pDriverContext));
189
 
      dri_state       = calloc(1, sizeof(*dri_state));
190
 
      if (pDisplayContext && pDriverContext && dri_state)
191
 
      {
192
 
          pDisplayContext->vadpy_magic = VA_DISPLAY_MAGIC;          
193
 
 
194
 
          pDriverContext->x11_dpy          = native_dpy;
195
 
          pDisplayContext->pNext           = pDisplayContexts;
196
 
          pDisplayContext->pDriverContext  = pDriverContext;
197
 
          pDisplayContext->vaIsValid       = va_DisplayContextIsValid;
198
 
          pDisplayContext->vaDestroy       = va_DisplayContextDestroy;
199
 
          pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName;
200
 
          pDisplayContexts                 = pDisplayContext;
201
 
          pDriverContext->dri_state        = dri_state;
202
 
          dpy                              = (VADisplay)pDisplayContext;
203
 
      }
204
 
      else
205
 
      {
206
 
          if (pDisplayContext)
207
 
              free(pDisplayContext);
208
 
          if (pDriverContext)
209
 
              free(pDriverContext);
210
 
          if (dri_state)
211
 
              free(dri_state);
212
 
      }
213
 
  }
214
 
  
215
 
  return dpy;
216
 
}