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"
29 #include "va_internal.h"
32 #include "va_android.h"
33 #include "va_drmcommon.h"
34 #include "va_drm_utils.h"
37 #include <sys/types.h>
44 #define CHECK_SYMBOL(func) { if (!func) printf("func %s not found\n", #func); return VA_STATUS_ERROR_UNKNOWN; }
45 #define DEVICE_NAME "/dev/dri/renderD128"
47 static int open_device (char *dev_name)
52 if (-1 == stat (dev_name, &st))
54 printf ("Cannot identify '%s': %d, %s\n",
55 dev_name, errno, strerror (errno));
59 if (!S_ISCHR (st.st_mode))
61 printf ("%s is no device\n", dev_name);
65 fd = open (dev_name, O_RDWR);
69 fprintf (stderr, "Cannot open '%s': %d, %s\n",
70 dev_name, errno, strerror (errno));
77 static int va_DisplayContextIsValid (
78 VADisplayContextP pDisplayContext
81 return (pDisplayContext != NULL &&
82 pDisplayContext->pDriverContext != NULL);
85 static void va_DisplayContextDestroy (
86 VADisplayContextP pDisplayContext
89 struct drm_state *drm_state;
91 if (pDisplayContext == NULL)
94 /* close the open-ed DRM fd */
95 drm_state = (struct drm_state *)pDisplayContext->pDriverContext->drm_state;
98 free(pDisplayContext->pDriverContext->drm_state);
99 free(pDisplayContext->pDriverContext);
100 free(pDisplayContext);
103 static VAStatus va_DisplayContextGetDriverName (
104 VADisplayContextP pDisplayContext,
108 VADriverContextP const ctx = pDisplayContext->pDriverContext;
109 struct drm_state * drm_state = (struct drm_state *)ctx->drm_state;
111 memset(drm_state, 0, sizeof(*drm_state));
112 drm_state->fd = open_device((char *)DEVICE_NAME);
114 if (drm_state->fd < 0) {
115 fprintf(stderr,"can't open DRM devices\n");
116 return VA_STATUS_ERROR_UNKNOWN;
118 drm_state->auth_type = VA_DRM_AUTH_CUSTOM;
120 return VA_DRM_GetDriverName(ctx, driver_name);
124 VADisplay vaGetDisplay (
125 void *native_dpy /* implementation specific */
128 VADisplayContextP pDisplayContext;
129 VADriverContextP pDriverContext;
130 struct drm_state *drm_state;
135 pDisplayContext = va_newDisplayContext();
136 if (!pDisplayContext)
139 pDisplayContext->vaIsValid = va_DisplayContextIsValid;
140 pDisplayContext->vaDestroy = va_DisplayContextDestroy;
141 pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName;
143 pDriverContext = va_newDriverContext(pDisplayContext);
144 if (!pDriverContext) {
145 free(pDisplayContext);
149 pDriverContext->native_dpy = (void *)native_dpy;
150 pDriverContext->display_type = VA_DISPLAY_ANDROID
152 drm_state = calloc(1, sizeof(*drm_state));
154 free(pDisplayContext);
155 free(pDriverContext);
159 pDriverContext->drm_state = drm_state;
161 return (VADisplay)pDisplayContext;