2 * Copyright (c) 2007 Intel Corporation. All Rights Reserved.
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:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
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.
27 #include "va_backend.h"
28 #include "va_android.h"
29 #include "x11/va_dricommon.h"
35 #include <sys/types.h>
41 #define CHECK_SYMBOL(func) { if (!func) printf("func %s not found\n", #func); return VA_STATUS_ERROR_UNKNOWN; }
42 #define DEVICE_NAME "/dev/dri/card0"
44 static VADisplayContextP pDisplayContexts = NULL;
46 static int open_device (char *dev_name)
51 if (-1 == stat (dev_name, &st))
53 printf ("Cannot identify '%s': %d, %s\n",
54 dev_name, errno, strerror (errno));
58 if (!S_ISCHR (st.st_mode))
60 printf ("%s is no device\n", dev_name);
64 fd = open (dev_name, O_RDWR /* required */ | O_NONBLOCK, 0);
68 fprintf (stderr, "Cannot open '%s': %d, %s\n",
69 dev_name, errno, strerror (errno));
76 static int va_DisplayContextIsValid (
77 VADisplayContextP pDisplayContext
83 static void va_DisplayContextDestroy (
84 VADisplayContextP pDisplayContext
87 VADisplayContextP *ctx = &pDisplayContexts;
89 /* Throw away pDisplayContext */
92 if (*ctx == pDisplayContext)
94 *ctx = pDisplayContext->pNext;
95 pDisplayContext->pNext = NULL;
98 ctx = &((*ctx)->pNext);
100 free(pDisplayContext->pDriverContext);
101 free(pDisplayContext);
105 static VAStatus va_DisplayContextGetDriverName (
106 VADisplayContextP pDisplayContext,
110 char *driver_name_env;
112 unsigned int verndor_id;
113 unsigned int device_id;
114 char driver_name[64];
116 { 0x8086, 0x4100, "psb" },
122 *driver_name = strdup(devices[0].driver_name);
124 return VA_STATUS_SUCCESS;
128 VADisplay vaGetDisplay (
129 Display *native_dpy /* implementation specific */
132 VADisplay dpy = NULL;
133 VADisplayContextP pDisplayContext = pDisplayContexts;
138 while (pDisplayContext)
140 if (pDisplayContext->pDriverContext &&
141 pDisplayContext->pDriverContext->native_dpy == (void *)native_dpy)
143 dpy = (VADisplay)pDisplayContext;
146 pDisplayContext = pDisplayContext->pNext;
152 /* create new entry */
153 VADriverContextP pDriverContext;
154 struct dri_state *dri_state;
156 pDisplayContext = (VADisplayContextP)calloc(1, sizeof(*pDisplayContext));
157 pDriverContext = (VADriverContextP)calloc(1, sizeof(*pDriverContext));
158 dri_state = (struct dri_state*)calloc(1, sizeof(*dri_state));
160 /* assgin necessary dri_state struct variable */
161 dri_state->driConnectedFlag = VA_DRI2;
162 dri_state->fd = open_device(DEVICE_NAME);
163 dri_state->createDrawable = NULL;
164 dri_state->destroyDrawable = NULL;
165 dri_state->swapBuffer = NULL;
166 dri_state->getRenderingBuffer = NULL;
167 dri_state->close = NULL;
169 if (pDisplayContext && pDriverContext && dri_state)
171 pDisplayContext->vadpy_magic = VA_DISPLAY_MAGIC;
173 pDriverContext->native_dpy = (void *)native_dpy;
174 pDisplayContext->pNext = pDisplayContexts;
175 pDisplayContext->pDriverContext = pDriverContext;
176 pDisplayContext->vaIsValid = va_DisplayContextIsValid;
177 pDisplayContext->vaDestroy = va_DisplayContextDestroy;
178 pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName;
179 pDisplayContexts = pDisplayContext;
180 pDriverContext->dri_state = dri_state;
181 dpy = (VADisplay)pDisplayContext;
186 free(pDisplayContext);
188 free(pDriverContext);
197 #define CTX(dpy) (((VADisplayContextP)dpy)->pDriverContext)
198 #define CHECK_DISPLAY(dpy) if( !vaDisplayIsValid(dpy) ) { return VA_STATUS_ERROR_INVALID_DISPLAY; }
200 static int vaDisplayIsValid(VADisplay dpy)
202 VADisplayContextP pDisplayContext = (VADisplayContextP)dpy;
203 return pDisplayContext && (pDisplayContext->vadpy_magic == VA_DISPLAY_MAGIC) && pDisplayContext->vaIsValid(pDisplayContext);
206 VAStatus vaPutSurface (
209 //Surface *draw, /* Android Surface/Window */
217 unsigned short destw,
218 unsigned short desth,
219 VARectangle *cliprects, /* client supplied clip list */
220 unsigned int number_cliprects, /* number of clip rects in the clip list */
221 unsigned int flags /* de-interlacing flags */
224 VADriverContextP ctx;
229 return ctx->vtable.vaPutSurface( ctx, surface, draw, srcx, srcy, srcw, srch,
230 destx, desty, destw, desth,
231 cliprects, number_cliprects, flags );