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.
28 #include "va_backend.h"
31 #include "va_android.h"
32 #include "va_drmcommon.h"
33 #include "va_drm_utils.h"
36 #include <sys/types.h>
43 #define CHECK_SYMBOL(func) { if (!func) printf("func %s not found\n", #func); return VA_STATUS_ERROR_UNKNOWN; }
44 #define DEVICE_NAME "/dev/dri/renderD128"
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);
68 fprintf (stderr, "Cannot open '%s': %d, %s\n",
69 dev_name, errno, strerror (errno));
76 static int va_DisplayContextIsValid (
77 VADisplayContextP pDisplayContext
80 return (pDisplayContext != NULL &&
81 pDisplayContext->pDriverContext != NULL);
84 static void va_DisplayContextDestroy (
85 VADisplayContextP pDisplayContext
88 struct drm_state *drm_state;
90 if (pDisplayContext == NULL)
93 /* close the open-ed DRM fd */
94 drm_state = (struct drm_state *)pDisplayContext->pDriverContext->drm_state;
97 free(pDisplayContext->pDriverContext->drm_state);
98 free(pDisplayContext->pDriverContext);
99 free(pDisplayContext);
102 static VAStatus va_DisplayContextGetDriverName (
103 VADisplayContextP pDisplayContext,
107 VADriverContextP const ctx = pDisplayContext->pDriverContext;
108 struct drm_state * drm_state = (struct drm_state *)ctx->drm_state;
110 memset(drm_state, 0, sizeof(*drm_state));
111 drm_state->fd = open_device((char *)DEVICE_NAME);
113 if (drm_state->fd < 0) {
114 fprintf(stderr,"can't open DRM devices\n");
115 return VA_STATUS_ERROR_UNKNOWN;
117 drm_state->auth_type = VA_DRM_AUTH_CUSTOM;
119 return VA_DRM_GetDriverName(ctx, driver_name);
123 VADisplay vaGetDisplay (
124 void *native_dpy /* implementation specific */
127 VADisplay dpy = NULL;
128 VADisplayContextP pDisplayContext;
135 /* create new entry */
136 VADriverContextP pDriverContext = 0;
137 struct drm_state *drm_state = 0;
138 pDisplayContext = (VADisplayContextP)calloc(1, sizeof(*pDisplayContext));
139 pDriverContext = (VADriverContextP)calloc(1, sizeof(*pDriverContext));
140 drm_state = (struct drm_state*)calloc(1, sizeof(*drm_state));
141 if (pDisplayContext && pDriverContext && drm_state)
143 pDisplayContext->vadpy_magic = VA_DISPLAY_MAGIC;
145 pDriverContext->native_dpy = (void *)native_dpy;
146 pDriverContext->display_type = VA_DISPLAY_ANDROID;
147 pDisplayContext->pDriverContext = pDriverContext;
148 pDisplayContext->vaIsValid = va_DisplayContextIsValid;
149 pDisplayContext->vaDestroy = va_DisplayContextDestroy;
150 pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName;
151 pDriverContext->drm_state = drm_state;
152 dpy = (VADisplay)pDisplayContext;
157 free(pDisplayContext);
159 free(pDriverContext);
168 #define CTX(dpy) (((VADisplayContextP)dpy)->pDriverContext)
169 #define CHECK_DISPLAY(dpy) if( !vaDisplayIsValid(dpy) ) { return VA_STATUS_ERROR_INVALID_DISPLAY; }
173 extern int fool_postp; /* do nothing for vaPutSurface if set */
174 extern int trace_flag; /* trace vaPutSurface parameters */
176 void va_TracePutSurface (
179 void *draw, /* the target Drawable */
186 unsigned short destw,
187 unsigned short desth,
188 VARectangle *cliprects, /* client supplied clip list */
189 unsigned int number_cliprects, /* number of clip rects in the clip list */
190 unsigned int flags /* de-interlacing flags */
194 VAStatus vaPutSurface (
197 sp<ANativeWindow> draw, /* Android Native Window */
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 */
211 VADriverContextP ctx;
214 return VA_STATUS_SUCCESS;
217 return VA_STATUS_ERROR_UNKNOWN;
222 VA_TRACE_LOG(va_TracePutSurface, dpy, surface, static_cast<void*>(&draw), srcx, srcy, srcw, srch,
223 destx, desty, destw, desth,
224 cliprects, number_cliprects, flags );
226 return ctx->vtable->vaPutSurface( ctx, surface, static_cast<void*>(&draw), srcx, srcy, srcw, srch,
227 destx, desty, destw, desth,
228 cliprects, number_cliprects, flags );