• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

hardware/intel/libva


Commit MetaInfo

修訂239eba1354a8d15cdffbe998c1b5ff86a54d24eb (tree)
時間2012-09-28 17:56:07
作者Haitao Huang <haitao.huang@inte...>
CommiterGwenole Beauchesne

Log Message

android: use common DRM driver detection code.

Change the driver used for android. Libva has to load the correct
driver and retain the vendor and device id's.

This change is to re-use common drm utils code for driver name
detection. Also removed non-android code in android specific files
and unneeded files in android directory.

Change-Id: I2893d8fcadfbf911e7c0b421a4e90d5aeb0d619e
Signed-off-by: Daniel Charles <daniel.charles@intel.com> (change driver)
Signed-off-by: Haitao Huang <haitao.huang@intel.com> (update using drm util)
Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com> (add missing headers)

Change Summary

差異

--- a/va/Android.mk
+++ b/va/Android.mk
@@ -89,14 +89,16 @@ LOCAL_GENERATED_SOURCES += $(GEN)
8989 include $(CLEAR_VARS)
9090
9191 LOCAL_SRC_FILES := \
92- android/va_android.cpp
92+ android/va_android.cpp \
93+ drm/va_drm_utils.c
9394
9495 LOCAL_CFLAGS += \
9596 -DANDROID -DLOG_TAG=\"libva-android\"
9697
9798 LOCAL_C_INCLUDES += \
9899 $(TARGET_OUT_HEADERS)/libva \
99- $(LOCAL_PATH)/x11
100+ $(TARGET_OUT_HEADERS)/libdrm \
101+ $(LOCAL_PATH)/drm
100102
101103 LOCAL_COPY_HEADERS_TO := libva/va
102104
@@ -105,7 +107,7 @@ LOCAL_COPY_HEADERS := va_android.h
105107 LOCAL_MODULE_TAGS := optional
106108 LOCAL_MODULE := libva-android
107109
108-LOCAL_SHARED_LIBRARIES := libva
110+LOCAL_SHARED_LIBRARIES := libva libdrm
109111
110112 include $(BUILD_SHARED_LIBRARY)
111113
--- a/va/android/drmtest.c
+++ /dev/null
@@ -1,139 +0,0 @@
1-/*
2- * Copyright © 2007 Intel Corporation
3- *
4- * Permission is hereby granted, free of charge, to any person obtaining a
5- * copy of this software and associated documentation files (the "Software"),
6- * to deal in the Software without restriction, including without limitation
7- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8- * and/or sell copies of the Software, and to permit persons to whom the
9- * Software is furnished to do so, subject to the following conditions:
10- *
11- * The above copyright notice and this permission notice (including the next
12- * paragraph) shall be included in all copies or substantial portions of the
13- * Software.
14- *
15- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21- * IN THE SOFTWARE.
22- *
23- * Authors:
24- * Eric Anholt <eric@anholt.net>
25- *
26- */
27-
28-#include <string.h>
29-#include <fcntl.h>
30-#include <fnmatch.h>
31-#include <sys/stat.h>
32-#include <sys/ioctl.h>
33-#include "drmtest.h"
34-
35-#define LIBUDEV_I_KNOW_THE_API_IS_SUBJECT_TO_CHANGE
36-#include <libudev.h>
37-
38-static int is_master(int fd)
39-{
40- drm_client_t client;
41- int ret;
42-
43- /* Check that we're the only opener and authed. */
44- client.idx = 0;
45- ret = ioctl(fd, DRM_IOCTL_GET_CLIENT, &client);
46- assert (ret == 0);
47- if (!client.auth)
48- return 0;
49- client.idx = 1;
50- ret = ioctl(fd, DRM_IOCTL_GET_CLIENT, &client);
51- if (ret != -1 || errno != EINVAL)
52- return 0;
53-
54- return 1;
55-}
56-
57-/** Open the first DRM device matching the criteria */
58-int drm_open_matching(const char *pci_glob, int flags, int *vendor_id, int *device_id)
59-{
60- struct udev *udev;
61- struct udev_enumerate *e;
62- struct udev_device *device, *parent;
63- struct udev_list_entry *entry;
64- const char *pci_id, *path;
65- char *tmp;
66- int fd;
67-
68- *vendor_id = 0;
69- *device_id = 0;
70-
71- udev = udev_new();
72- if (udev == NULL) {
73- fprintf(stderr, "failed to initialize udev context\n");
74- return -1;
75- //abort();
76- }
77-
78- fd = -1;
79- e = udev_enumerate_new(udev);
80- udev_enumerate_add_match_subsystem(e, "drm");
81- udev_enumerate_scan_devices(e);
82- udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) {
83- path = udev_list_entry_get_name(entry);
84- device = udev_device_new_from_syspath(udev, path);
85- parent = udev_device_get_parent(device);
86- /* Filter out KMS output devices. */
87- if (strcmp(udev_device_get_subsystem(parent), "pci") != 0)
88- continue;
89- pci_id = udev_device_get_property_value(parent, "PCI_ID");
90- if (fnmatch(pci_glob, pci_id, 0) != 0)
91- continue;
92- fd = open(udev_device_get_devnode(device), O_RDWR);
93- if (fd < 0)
94- continue;
95- if ((flags & DRM_TEST_MASTER) && !is_master(fd)) {
96- close(fd);
97- fd = -1;
98- continue;
99- }
100-
101- break;
102- }
103- udev_enumerate_unref(e);
104- udev_unref(udev);
105-
106- *vendor_id = (int) strtol(pci_id, &tmp, 16);
107- *device_id = (int) strtol((tmp+1), NULL, 16);
108-
109- return fd;
110-}
111-
112-int drm_open_any(int *vendor_id, int *device_id)
113-{
114- int fd = drm_open_matching("*:*", 0, vendor_id, device_id);
115-
116- if (fd < 0) {
117- fprintf(stderr, "failed to open any drm device\n");
118- //abort();
119- }
120-
121- return fd;
122-}
123-
124-/**
125- * Open the first DRM device we can find where we end up being the master.
126- */
127-int drm_open_any_master(void)
128-{
129- int vendor_id, device_id;
130- int fd = drm_open_matching("*:*", DRM_TEST_MASTER, &vendor_id, &device_id);
131-
132- if (fd < 0) {
133- fprintf(stderr, "failed to open any drm device\n");
134- abort();
135- }
136-
137- return fd;
138-
139-}
--- a/va/android/drmtest.h
+++ /dev/null
@@ -1,40 +0,0 @@
1-/*
2- * Copyright © 2007 Intel Corporation
3- *
4- * Permission is hereby granted, free of charge, to any person obtaining a
5- * copy of this software and associated documentation files (the "Software"),
6- * to deal in the Software without restriction, including without limitation
7- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8- * and/or sell copies of the Software, and to permit persons to whom the
9- * Software is furnished to do so, subject to the following conditions:
10- *
11- * The above copyright notice and this permission notice (including the next
12- * paragraph) shall be included in all copies or substantial portions of the
13- * Software.
14- *
15- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21- * IN THE SOFTWARE.
22- *
23- * Authors:
24- * Eric Anholt <eric@anholt.net>
25- *
26- */
27-
28-#include <stdio.h>
29-#include <stdlib.h>
30-#include <unistd.h>
31-#include <assert.h>
32-#include <errno.h>
33-
34-#include "xf86drm.h"
35-
36-#define DRM_TEST_MASTER 0x01
37-
38-int drm_open_any(int *vendor_id, int *device_id);
39-int drm_open_any_master(void);
40-int drm_open_matching(const char *pci_glob, int flags, int *vendor_id, int *device_id);
--- a/va/android/va_android.cpp
+++ b/va/android/va_android.cpp
@@ -23,29 +23,25 @@
2323 */
2424
2525 #define _GNU_SOURCE 1
26+#include "sysdeps.h"
2627 #include "va.h"
2728 #include "va_backend.h"
2829 #include "va_trace.h"
2930 #include "va_fool.h"
3031 #include "va_android.h"
31-#include "va_dricommon.h" /* needs some helper functions from this file */
32-#include <stdio.h>
33-#include <stdlib.h>
32+#include "va_drmcommon.h"
33+#include "va_drm_utils.h"
3434 #include <stdarg.h>
35-#include <string.h>
3635 #include <unistd.h>
3736 #include <sys/types.h>
3837 #include <sys/stat.h>
3938 #include <fcntl.h>
4039 #include <dlfcn.h>
4140 #include <errno.h>
42-#ifndef ANDROID
43-#include <libudev.h>
44-#include "drmtest.h"
45-#endif
41+
4642
4743 #define CHECK_SYMBOL(func) { if (!func) printf("func %s not found\n", #func); return VA_STATUS_ERROR_UNKNOWN; }
48-#define DEVICE_NAME "/dev/card0"
44+#define DEVICE_NAME "/dev/dri/card0"
4945
5046 static int open_device (char *dev_name)
5147 {
@@ -89,114 +85,40 @@ static void va_DisplayContextDestroy (
8985 VADisplayContextP pDisplayContext
9086 )
9187 {
92- struct dri_state *dri_state;
88+ struct drm_state *drm_state;
9389
9490 if (pDisplayContext == NULL)
9591 return;
9692
9793 /* close the open-ed DRM fd */
98- dri_state = (struct dri_state *)pDisplayContext->pDriverContext->drm_state;
99- close(dri_state->base.fd);
94+ drm_state = (struct drm_state *)pDisplayContext->pDriverContext->drm_state;
95+ close(drm_state->fd);
10096
10197 free(pDisplayContext->pDriverContext->drm_state);
10298 free(pDisplayContext->pDriverContext);
10399 free(pDisplayContext);
104100 }
105101
106-#ifdef ANDROID
107102 static VAStatus va_DisplayContextGetDriverName (
108103 VADisplayContextP pDisplayContext,
109104 char **driver_name
110105 )
111106 {
112- VADriverContextP ctx = pDisplayContext->pDriverContext;
113- struct dri_state *dri_state = (struct dri_state *)ctx->drm_state;
114- char *driver_name_env;
115- int vendor_id, device_id;
116-
117- struct {
118- int vendor_id;
119- int device_id;
120- char driver_name[64];
121- } devices[] = {
122- { 0x8086, 0x4100, "pvr" },
123- { 0x8086, 0x0130, "pvr" },
124- { 0x0, 0x0, "\0" },
125- };
126-
127- memset(dri_state, 0, sizeof(*dri_state));
128- dri_state->base.fd = open_device((char *)DEVICE_NAME);
129-
130- if (dri_state->base.fd < 0) {
131- fprintf(stderr,"can't open DRM devices\n");
132- return VA_STATUS_ERROR_UNKNOWN;
133- }
107+ VADriverContextP const ctx = pDisplayContext->pDriverContext;
108+ struct drm_state * drm_state = (struct drm_state *)ctx->drm_state;
134109
135- /* TBD: other vendor driver names */
136- vendor_id = devices[0].vendor_id;
137- device_id = devices[0].device_id;
138- *driver_name = strdup(devices[0].driver_name);
139-
140- dri_state->base.auth_type = VA_DUMMY;
110+ memset(drm_state, 0, sizeof(*drm_state));
111+ drm_state->fd = open_device((char *)DEVICE_NAME);
141112
142- return VA_STATUS_SUCCESS;
143-}
144-#else
145-static VAStatus va_DisplayContextGetDriverName (
146- VADisplayContextP pDisplayContext,
147- char **driver_name
148-)
149-{
150- VADriverContextP ctx = pDisplayContext->pDriverContext;
151- struct dri_state *dri_state = (struct dri_state *)ctx->drm_state;
152- char *driver_name_env;
153- int vendor_id, device_id;
154- int i = 0;
155-
156- struct {
157- int vendor_id;
158- int device_id;
159- char driver_name[64];
160- } devices[] = {
161- { 0x8086, 0x4100, "pvr" },
162- { 0x8086, 0x0130, "pvr" },
163- { 0x0, 0x0, "\0" },
164- };
165-
166- memset(dri_state, 0, sizeof(*dri_state));
167- dri_state->base.fd = drm_open_any(&vendor_id, &device_id);
168-
169- if (dri_state->base.fd < 0) {
113+ if (drm_state->fd < 0) {
170114 fprintf(stderr,"can't open DRM devices\n");
171115 return VA_STATUS_ERROR_UNKNOWN;
172116 }
173-
174- /* TBD: other vendor driver names */
175-
176- while (devices[i].device_id != 0) {
177- if ((devices[i].vendor_id == vendor_id) &&
178- (devices[i].device_id == device_id))
179- break;
180- i++;
181- }
117+ drm_state->auth_type = VA_DRM_AUTH_CUSTOM;
182118
183- if (devices[i].device_id != 0)
184- *driver_name = strdup(devices[i].driver_name);
185- else {
186- fprintf(stderr,"device (0x%04x:0x%04x) is not supported\n",
187- vendor_id, device_id);
188-
189- return VA_STATUS_ERROR_UNKNOWN;
190- }
191-
192- printf("DRM device is opened, loading driver %s for device 0x%04x:0x%04x\n",
193- driver_name, vendor_id, device_id);
194-
195- dri_state->base.auth_type = VA_DUMMY;
196-
197- return VA_STATUS_SUCCESS;
119+ return VA_DRM_GetDriverName(ctx, driver_name);
198120 }
199-#endif
121+
200122
201123 VADisplay vaGetDisplay (
202124 void *native_dpy /* implementation specific */
@@ -211,12 +133,12 @@ VADisplay vaGetDisplay (
211133 if (!dpy)
212134 {
213135 /* create new entry */
214- VADriverContextP pDriverContext;
215- struct dri_state *dri_state;
136+ VADriverContextP pDriverContext = 0;
137+ struct drm_state *drm_state = 0;
216138 pDisplayContext = (VADisplayContextP)calloc(1, sizeof(*pDisplayContext));
217139 pDriverContext = (VADriverContextP)calloc(1, sizeof(*pDriverContext));
218- dri_state = (struct dri_state*)calloc(1, sizeof(*dri_state));
219- if (pDisplayContext && pDriverContext && dri_state)
140+ drm_state = (struct drm_state*)calloc(1, sizeof(*drm_state));
141+ if (pDisplayContext && pDriverContext && drm_state)
220142 {
221143 pDisplayContext->vadpy_magic = VA_DISPLAY_MAGIC;
222144
@@ -226,7 +148,7 @@ VADisplay vaGetDisplay (
226148 pDisplayContext->vaIsValid = va_DisplayContextIsValid;
227149 pDisplayContext->vaDestroy = va_DisplayContextDestroy;
228150 pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName;
229- pDriverContext->drm_state = dri_state;
151+ pDriverContext->drm_state = drm_state;
230152 dpy = (VADisplay)pDisplayContext;
231153 }
232154 else
@@ -235,8 +157,8 @@ VADisplay vaGetDisplay (
235157 free(pDisplayContext);
236158 if (pDriverContext)
237159 free(pDriverContext);
238- if (dri_state)
239- free(dri_state);
160+ if (drm_state)
161+ free(drm_state);
240162 }
241163 }
242164
@@ -247,7 +169,6 @@ VADisplay vaGetDisplay (
247169 #define CHECK_DISPLAY(dpy) if( !vaDisplayIsValid(dpy) ) { return VA_STATUS_ERROR_INVALID_DISPLAY; }
248170
249171
250-#ifdef ANDROID
251172 extern "C" {
252173 extern int fool_postp; /* do nothing for vaPutSurface if set */
253174 extern int trace_flag; /* trace vaPutSurface parameters */
@@ -306,4 +227,3 @@ VAStatus vaPutSurface (
306227 destx, desty, destw, desth,
307228 cliprects, number_cliprects, flags );
308229 }
309-#endif