Make it possible to pass state-tracker-specific data to the init_screen function, and even open the door for device-specific state-tracker screen initialization. Signed-off-by: Thomas Hellstrom <thellstrom-at-vmware-dot-com>tags/mesa_7_5_rc1
@@ -10,13 +10,30 @@ struct pipe_buffer; | |||
struct pipe_context; | |||
struct pipe_texture; | |||
enum drm_create_screen_mode { | |||
DRM_CREATE_NORMAL = 0, | |||
DRM_CREATE_DRI1, | |||
DRM_CREATE_DRIVER = 1024, | |||
DRM_CREATE_MAX | |||
}; | |||
/** | |||
* Modes other than DRM_CREATE_NORMAL derive from this struct. | |||
*/ | |||
/*@{*/ | |||
struct drm_create_screen_arg { | |||
enum drm_create_screen_mode mode; | |||
}; | |||
/*@}*/ | |||
struct drm_api | |||
{ | |||
/** | |||
* Special buffer functions | |||
*/ | |||
/*@{*/ | |||
struct pipe_screen* (*create_screen)(int drmFB, int pciID); | |||
struct pipe_screen* (*create_screen)(int drm_fd, | |||
struct drm_create_screen_arg *arg); | |||
struct pipe_context* (*create_context)(struct pipe_screen *screen); | |||
/*@}*/ | |||
@@ -67,37 +67,6 @@ static const __DRIextension *dri_screen_extensions[] = { | |||
NULL | |||
}; | |||
static void | |||
dri_get_drm_minor(struct dri_screen *screen) | |||
{ | |||
/* TODO get the real minor */ | |||
screen->minor = 0; | |||
} | |||
static void | |||
dri_get_device_id(struct dri_screen *screen) | |||
{ | |||
char path[512]; | |||
FILE *file; | |||
/* | |||
* There must be a better way to get the deviceID. | |||
* XXX this only works on Linux. | |||
*/ | |||
snprintf(path, sizeof(path), "/sys/class/drm/card%d/device/device", screen->minor); | |||
file = fopen(path, "r"); | |||
if (!file) { | |||
return; | |||
} | |||
fgets(path, sizeof(path), file); | |||
sscanf(path, "%x", &screen->deviceID); | |||
fclose(file); | |||
} | |||
static const __DRIconfig ** | |||
dri_fill_in_modes(__DRIscreenPrivate *psp, | |||
unsigned pixel_bits, unsigned depth_bits, | |||
@@ -212,13 +181,11 @@ dri_init_screen2(__DRIscreenPrivate *sPriv) | |||
screen->sPriv = sPriv; | |||
screen->fd = sPriv->fd; | |||
dri_get_drm_minor(screen); | |||
dri_get_device_id(screen); | |||
sPriv->private = (void *) screen; | |||
sPriv->extensions = dri_screen_extensions; | |||
screen->pipe_screen = drm_api_hooks.create_screen(screen->fd, screen->deviceID); | |||
screen->pipe_screen = drm_api_hooks.create_screen(screen->fd, NULL); | |||
if (!screen->pipe_screen) { | |||
debug_printf("%s: failed to create pipe_screen\n", __FUNCTION__); | |||
goto fail; |
@@ -54,9 +54,7 @@ struct dri_screen | |||
struct dri_context *dummyContext; | |||
/* drm */ | |||
int deviceID; | |||
int fd; | |||
int minor; | |||
/* gallium */ | |||
struct pipe_winsys *pipe_winsys; |
@@ -146,7 +146,7 @@ drm_initialize(_EGLDriver *drv, EGLDisplay dpy, EGLint *major, EGLint *minor) | |||
dev->drmFD = fd; | |||
drm_get_device_id(dev); | |||
dev->screen = drm_api_hooks.create_screen(dev->drmFD, dev->deviceID); | |||
dev->screen = drm_api_hooks.create_screen(dev->drmFD, NULL); | |||
if (!dev->screen) | |||
goto err_screen; | |||
dev->winsys = dev->screen->winsys; |
@@ -476,7 +476,7 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) | |||
} | |||
if (!ms->screen) { | |||
ms->screen = drm_api_hooks.create_screen(ms->fd, ms->PciInfo->device_id); | |||
ms->screen = drm_api_hooks.create_screen(ms->fd, NULL); | |||
if (!ms->screen) { | |||
FatalError("Could not init pipe_screen\n"); |
@@ -8,7 +8,8 @@ | |||
#include "intel_be_device.h" | |||
struct pipe_screen *intel_be_create_screen(int drmFD, int pciID); | |||
struct pipe_screen *intel_be_create_screen(int drmFD, | |||
struct drm_create_screen_arg *arg); | |||
struct pipe_context *intel_be_create_context(struct pipe_screen *screen); | |||
#endif |
@@ -14,6 +14,7 @@ | |||
#include "softpipe/sp_winsys.h" | |||
#include "intel_be_api.h" | |||
#include <stdio.h> | |||
/* | |||
* Buffer | |||
@@ -290,11 +291,42 @@ intel_be_init_device(struct intel_be_device *dev, int fd, unsigned id) | |||
return true; | |||
} | |||
static void | |||
intel_be_get_device_id(unsigned int *device_id) | |||
{ | |||
char path[512]; | |||
FILE *file; | |||
/* | |||
* FIXME: Fix this up to use a drm ioctl or whatever. | |||
*/ | |||
snprintf(path, sizeof(path), "/sys/class/drm/card0/device/device"); | |||
file = fopen(path, "r"); | |||
if (!file) { | |||
return; | |||
} | |||
fgets(path, sizeof(path), file); | |||
sscanf(path, "%x", device_id); | |||
fclose(file); | |||
} | |||
struct pipe_screen * | |||
intel_be_create_screen(int drmFD, int deviceID) | |||
intel_be_create_screen(int drmFD, struct drm_create_screen_arg *arg) | |||
{ | |||
struct intel_be_device *dev; | |||
struct pipe_screen *screen; | |||
unsigned int deviceID; | |||
if (arg != NULL) { | |||
switch(arg->mode) { | |||
case DRM_CREATE_NORMAL: | |||
break; | |||
default: | |||
return NULL; | |||
} | |||
} | |||
/* Allocate the private area */ | |||
dev = malloc(sizeof(*dev)); | |||
@@ -302,6 +334,7 @@ intel_be_create_screen(int drmFD, int deviceID) | |||
return NULL; | |||
memset(dev, 0, sizeof(*dev)); | |||
intel_be_get_device_id(&deviceID); | |||
intel_be_init_device(dev, drmFD, deviceID); | |||
if (dev->softpipe) { |
@@ -267,7 +267,7 @@ nouveau_screen_create(__DRIscreenPrivate *psp) | |||
nouveau_device_open_existing(&nv_screen->device, 0, psp->fd, 0); | |||
nv_screen->pscreen = drm_api_hooks.create_screen(psp->fd, 0); | |||
nv_screen->pscreen = drm_api_hooks.create_screen(psp->fd, NULL); | |||
if (!nv_screen->pscreen) { | |||
FREE(nv_screen); | |||
return NULL; |
@@ -8,7 +8,7 @@ | |||
#include "nouveau_bo.h" | |||
static struct pipe_screen * | |||
nouveau_drm_create_screen(int fd, int pciid) | |||
nouveau_drm_create_screen(int fd, struct drm_create_screen_arg *arg) | |||
{ | |||
struct pipe_winsys *ws; | |||
struct nouveau_winsys *nvws; |
@@ -31,7 +31,8 @@ | |||
#include "radeon_drm.h" | |||
/* Create a pipe_screen. */ | |||
struct pipe_screen* radeon_create_screen(int drmFB, int pciID) | |||
struct pipe_screen* radeon_create_screen(int drmFB, | |||
struct drm_create_screen_arg *arg ) | |||
{ | |||
struct radeon_winsys* winsys = radeon_pipe_winsys(drmFB); | |||
@@ -40,7 +40,8 @@ | |||
#include "radeon_r300.h" | |||
#include "radeon_winsys_softpipe.h" | |||
struct pipe_screen* radeon_create_screen(int drmFB, int pciID); | |||
struct pipe_screen* radeon_create_screen(int drmFB, | |||
struct drm_create_screen_arg *arg); | |||
struct pipe_context* radeon_create_context(struct pipe_screen* screen); | |||