mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-08 17:48:10 +02:00
st/egl: Introduce native_platform.
Move native_get_name, native_create_probe, native_get_probe_result, and native_create_display into struct native_platform, and add native_get_platform to get a handle to the struct.
This commit is contained in:
parent
f9574c5f89
commit
f66a4e20c1
8 changed files with 143 additions and 113 deletions
|
|
@ -63,25 +63,44 @@ egl_g3d_init_st(_EGLDriver *drv)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the probe object of the display.
|
* Get the native platform.
|
||||||
|
*/
|
||||||
|
static const struct native_platform *
|
||||||
|
egl_g3d_get_platform(_EGLDriver *drv)
|
||||||
|
{
|
||||||
|
struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
|
||||||
|
|
||||||
|
if (!gdrv->platform)
|
||||||
|
gdrv->platform = native_get_platform();
|
||||||
|
|
||||||
|
return gdrv->platform;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the probe result of the display.
|
||||||
*
|
*
|
||||||
* Note that this function may be called before the display is initialized.
|
* Note that this function may be called before the display is initialized.
|
||||||
*/
|
*/
|
||||||
static struct native_probe *
|
static enum native_probe_result
|
||||||
egl_g3d_get_probe(_EGLDriver *drv, _EGLDisplay *dpy)
|
egl_g3d_get_probe_result(_EGLDriver *drv, _EGLDisplay *dpy)
|
||||||
{
|
{
|
||||||
struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
|
struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
|
||||||
struct native_probe *nprobe;
|
struct native_probe *nprobe;
|
||||||
|
const struct native_platform *nplat;
|
||||||
|
|
||||||
|
nplat = egl_g3d_get_platform(drv);
|
||||||
|
if (!nplat || !nplat->create_probe)
|
||||||
|
return NATIVE_PROBE_UNKNOWN;
|
||||||
|
|
||||||
nprobe = (struct native_probe *) _eglGetProbeCache(gdrv->probe_key);
|
nprobe = (struct native_probe *) _eglGetProbeCache(gdrv->probe_key);
|
||||||
if (!nprobe || nprobe->display != dpy->PlatformDisplay) {
|
if (!nprobe || nprobe->display != dpy->PlatformDisplay) {
|
||||||
if (nprobe)
|
if (nprobe)
|
||||||
nprobe->destroy(nprobe);
|
nprobe->destroy(nprobe);
|
||||||
nprobe = native_create_probe(dpy->PlatformDisplay);
|
nprobe = nplat->create_probe(dpy->PlatformDisplay);
|
||||||
_eglSetProbeCache(gdrv->probe_key, (void *) nprobe);
|
_eglSetProbeCache(gdrv->probe_key, (void *) nprobe);
|
||||||
}
|
}
|
||||||
|
|
||||||
return nprobe;
|
return nplat->get_probe_result(nprobe);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -460,10 +479,15 @@ egl_g3d_initialize(_EGLDriver *drv, _EGLDisplay *dpy,
|
||||||
{
|
{
|
||||||
struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
|
struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
|
||||||
struct egl_g3d_display *gdpy;
|
struct egl_g3d_display *gdpy;
|
||||||
|
const struct native_platform *nplat;
|
||||||
|
|
||||||
/* the probe object is unlikely to be needed again */
|
/* the probe object is unlikely to be needed again */
|
||||||
egl_g3d_destroy_probe(drv, dpy);
|
egl_g3d_destroy_probe(drv, dpy);
|
||||||
|
|
||||||
|
nplat = egl_g3d_get_platform(drv);
|
||||||
|
if (!nplat)
|
||||||
|
return EGL_FALSE;
|
||||||
|
|
||||||
gdpy = CALLOC_STRUCT(egl_g3d_display);
|
gdpy = CALLOC_STRUCT(egl_g3d_display);
|
||||||
if (!gdpy) {
|
if (!gdpy) {
|
||||||
_eglError(EGL_BAD_ALLOC, "eglInitialize");
|
_eglError(EGL_BAD_ALLOC, "eglInitialize");
|
||||||
|
|
@ -471,7 +495,8 @@ egl_g3d_initialize(_EGLDriver *drv, _EGLDisplay *dpy,
|
||||||
}
|
}
|
||||||
dpy->DriverData = gdpy;
|
dpy->DriverData = gdpy;
|
||||||
|
|
||||||
gdpy->native = native_create_display(dpy->PlatformDisplay,
|
_eglLog(_EGL_INFO, "use %s for display %p", nplat->name, dpy->PlatformDisplay);
|
||||||
|
gdpy->native = nplat->create_display(dpy->PlatformDisplay,
|
||||||
&egl_g3d_native_event_handler);
|
&egl_g3d_native_event_handler);
|
||||||
if (!gdpy->native) {
|
if (!gdpy->native) {
|
||||||
_eglError(EGL_NOT_INITIALIZED, "eglInitialize(no usable display)");
|
_eglError(EGL_NOT_INITIALIZED, "eglInitialize(no usable display)");
|
||||||
|
|
@ -543,12 +568,10 @@ egl_g3d_get_proc_address(_EGLDriver *drv, const char *procname)
|
||||||
static EGLint
|
static EGLint
|
||||||
egl_g3d_probe(_EGLDriver *drv, _EGLDisplay *dpy)
|
egl_g3d_probe(_EGLDriver *drv, _EGLDisplay *dpy)
|
||||||
{
|
{
|
||||||
struct native_probe *nprobe;
|
|
||||||
enum native_probe_result res;
|
enum native_probe_result res;
|
||||||
EGLint score;
|
EGLint score;
|
||||||
|
|
||||||
nprobe = egl_g3d_get_probe(drv, dpy);
|
res = egl_g3d_get_probe_result(drv, dpy);
|
||||||
res = native_get_probe_result(nprobe);
|
|
||||||
|
|
||||||
switch (res) {
|
switch (res) {
|
||||||
case NATIVE_PROBE_UNKNOWN:
|
case NATIVE_PROBE_UNKNOWN:
|
||||||
|
|
@ -582,12 +605,8 @@ egl_g3d_unload(_EGLDriver *drv)
|
||||||
_EGLDriver *
|
_EGLDriver *
|
||||||
_eglMain(const char *args)
|
_eglMain(const char *args)
|
||||||
{
|
{
|
||||||
static char driver_name[64];
|
|
||||||
struct egl_g3d_driver *gdrv;
|
struct egl_g3d_driver *gdrv;
|
||||||
|
|
||||||
util_snprintf(driver_name, sizeof(driver_name),
|
|
||||||
"Gallium/%s", native_get_name());
|
|
||||||
|
|
||||||
gdrv = CALLOC_STRUCT(egl_g3d_driver);
|
gdrv = CALLOC_STRUCT(egl_g3d_driver);
|
||||||
if (!gdrv)
|
if (!gdrv)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -597,7 +616,7 @@ _eglMain(const char *args)
|
||||||
gdrv->base.API.Terminate = egl_g3d_terminate;
|
gdrv->base.API.Terminate = egl_g3d_terminate;
|
||||||
gdrv->base.API.GetProcAddress = egl_g3d_get_proc_address;
|
gdrv->base.API.GetProcAddress = egl_g3d_get_proc_address;
|
||||||
|
|
||||||
gdrv->base.Name = driver_name;
|
gdrv->base.Name = "Gallium";
|
||||||
gdrv->base.Probe = egl_g3d_probe;
|
gdrv->base.Probe = egl_g3d_probe;
|
||||||
gdrv->base.Unload = egl_g3d_unload;
|
gdrv->base.Unload = egl_g3d_unload;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,7 @@ struct egl_g3d_driver {
|
||||||
struct st_api *stapis[ST_API_COUNT];
|
struct st_api *stapis[ST_API_COUNT];
|
||||||
EGLint api_mask;
|
EGLint api_mask;
|
||||||
|
|
||||||
|
const struct native_platform *platform;
|
||||||
EGLint probe_key;
|
EGLint probe_key;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -207,10 +207,28 @@ native_attachment_mask_test(uint mask, enum native_attachment att)
|
||||||
return !!(mask & (1 << att));
|
return !!(mask & (1 << att));
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
struct native_platform {
|
||||||
native_get_name(void);
|
const char *name;
|
||||||
|
|
||||||
struct native_display *
|
/**
|
||||||
native_create_display(void *dpy, struct native_event_handler *handler);
|
* Return a probe object for the given display.
|
||||||
|
*
|
||||||
|
* Note that the returned object may be cached and used by different native
|
||||||
|
* display modules. It allows fast probing when multiple modules probe the
|
||||||
|
* same display.
|
||||||
|
*/
|
||||||
|
struct native_probe *(*create_probe)(void *dpy);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Probe the probe object.
|
||||||
|
*/
|
||||||
|
enum native_probe_result (*get_probe_result)(struct native_probe *nprobe);
|
||||||
|
|
||||||
|
struct native_display *(*create_display)(void *dpy,
|
||||||
|
struct native_event_handler *handler);
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct native_platform *
|
||||||
|
native_get_platform(void);
|
||||||
|
|
||||||
#endif /* _NATIVE_H_ */
|
#endif /* _NATIVE_H_ */
|
||||||
|
|
|
||||||
|
|
@ -49,20 +49,4 @@ struct native_probe {
|
||||||
void (*destroy)(struct native_probe *nprobe);
|
void (*destroy)(struct native_probe *nprobe);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a probe object for the given display.
|
|
||||||
*
|
|
||||||
* Note that the returned object may be cached and used by different native
|
|
||||||
* display modules. It allows fast probing when multiple modules probe the
|
|
||||||
* same display.
|
|
||||||
*/
|
|
||||||
struct native_probe *
|
|
||||||
native_create_probe(void *dpy);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Probe the probe object.
|
|
||||||
*/
|
|
||||||
enum native_probe_result
|
|
||||||
native_get_probe_result(struct native_probe *nprobe);
|
|
||||||
|
|
||||||
#endif /* _NATIVE_PROBE_H_ */
|
#endif /* _NATIVE_PROBE_H_ */
|
||||||
|
|
|
||||||
|
|
@ -427,25 +427,7 @@ fbdev_display_create(int fd, struct native_event_handler *event_handler)
|
||||||
return &fbdpy->base;
|
return &fbdpy->base;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct native_probe *
|
static struct native_display *
|
||||||
native_create_probe(void *dpy)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum native_probe_result
|
|
||||||
native_get_probe_result(struct native_probe *nprobe)
|
|
||||||
{
|
|
||||||
return NATIVE_PROBE_UNKNOWN;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *
|
|
||||||
native_get_name(void)
|
|
||||||
{
|
|
||||||
return "FBDEV";
|
|
||||||
}
|
|
||||||
|
|
||||||
struct native_display *
|
|
||||||
native_create_display(void *dpy, struct native_event_handler *event_handler)
|
native_create_display(void *dpy, struct native_event_handler *event_handler)
|
||||||
{
|
{
|
||||||
struct native_display *ndpy;
|
struct native_display *ndpy;
|
||||||
|
|
@ -467,3 +449,16 @@ native_create_display(void *dpy, struct native_event_handler *event_handler)
|
||||||
|
|
||||||
return ndpy;
|
return ndpy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const struct native_platform fbdev_platform = {
|
||||||
|
"FBDEV", /* name */
|
||||||
|
NULL, /* create_probe */
|
||||||
|
NULL, /* get_probe_result */
|
||||||
|
native_create_display
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct native_platform *
|
||||||
|
native_get_platform(void)
|
||||||
|
{
|
||||||
|
return &fbdev_platform;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -366,25 +366,7 @@ gdi_create_display(HDC hDC, struct pipe_screen *screen,
|
||||||
return &gdpy->base;
|
return &gdpy->base;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct native_probe *
|
static struct native_display *
|
||||||
native_create_probe(void *dpy)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum native_probe_result
|
|
||||||
native_get_probe_result(struct native_probe *nprobe)
|
|
||||||
{
|
|
||||||
return NATIVE_PROBE_UNKNOWN;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *
|
|
||||||
native_get_name(void)
|
|
||||||
{
|
|
||||||
return "GDI";
|
|
||||||
}
|
|
||||||
|
|
||||||
struct native_display *
|
|
||||||
native_create_display(void *dpy, struct native_event_handler *event_handler)
|
native_create_display(void *dpy, struct native_event_handler *event_handler)
|
||||||
{
|
{
|
||||||
struct sw_winsys *winsys;
|
struct sw_winsys *winsys;
|
||||||
|
|
@ -403,3 +385,16 @@ native_create_display(void *dpy, struct native_event_handler *event_handler)
|
||||||
|
|
||||||
return gdi_create_display((HDC) dpy, screen, event_handler);
|
return gdi_create_display((HDC) dpy, screen, event_handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const struct native_platform gdi_platform = {
|
||||||
|
"GDI", /* name */
|
||||||
|
NULL, /* create_probe */
|
||||||
|
NULL, /* get_probe_result */
|
||||||
|
native_create_display
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct native_platform *
|
||||||
|
native_get_platform(void)
|
||||||
|
{
|
||||||
|
return &gdi_platform;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -768,37 +768,40 @@ kms_create_display(int fd, struct native_event_handler *event_handler)
|
||||||
return &kdpy->base;
|
return &kdpy->base;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct native_probe *
|
static struct native_display *
|
||||||
native_create_probe(void *dpy)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum native_probe_result
|
|
||||||
native_get_probe_result(struct native_probe *nprobe)
|
|
||||||
{
|
|
||||||
return NATIVE_PROBE_UNKNOWN;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *
|
|
||||||
native_get_name(void)
|
|
||||||
{
|
|
||||||
static char kms_name[32];
|
|
||||||
|
|
||||||
|
|
||||||
util_snprintf(kms_name, sizeof(kms_name), "KMS/%s", driver_descriptor.name);
|
|
||||||
|
|
||||||
return kms_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct native_display *
|
|
||||||
native_create_display(void *dpy, struct native_event_handler *event_handler)
|
native_create_display(void *dpy, struct native_event_handler *event_handler)
|
||||||
{
|
{
|
||||||
struct native_display *ndpy = NULL;
|
struct native_display *ndpy;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
fd = (dpy != EGL_DEFAULT_DISPLAY) ? (int) pointer_to_intptr((void *) dpy) : -1;
|
/* well, this makes fd 0 being ignored */
|
||||||
|
fd = (dpy) ? (int) pointer_to_intptr(dpy) : -1;
|
||||||
ndpy = kms_create_display(fd, event_handler);
|
ndpy = kms_create_display(fd, event_handler);
|
||||||
|
|
||||||
return ndpy;
|
return ndpy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
kms_init_platform(struct native_platform *nplat)
|
||||||
|
{
|
||||||
|
static char kms_name[32];
|
||||||
|
|
||||||
|
if (nplat->name)
|
||||||
|
return;
|
||||||
|
|
||||||
|
util_snprintf(kms_name, sizeof(kms_name), "KMS/%s", driver_descriptor.name);
|
||||||
|
|
||||||
|
nplat->name = kms_name;
|
||||||
|
nplat->create_probe = NULL;
|
||||||
|
nplat->get_probe_result = NULL;
|
||||||
|
nplat->create_display = native_create_display;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct native_platform kms_platform;
|
||||||
|
|
||||||
|
const struct native_platform *
|
||||||
|
native_get_platform(void)
|
||||||
|
{
|
||||||
|
kms_init_platform(&kms_platform);
|
||||||
|
return &kms_platform;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,8 +44,8 @@ x11_probe_destroy(struct native_probe *nprobe)
|
||||||
FREE(nprobe);
|
FREE(nprobe);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct native_probe *
|
static struct native_probe *
|
||||||
native_create_probe(void *dpy)
|
x11_create_probe(void *dpy)
|
||||||
{
|
{
|
||||||
struct native_probe *nprobe;
|
struct native_probe *nprobe;
|
||||||
struct x11_screen *xscr;
|
struct x11_screen *xscr;
|
||||||
|
|
@ -89,8 +89,8 @@ native_create_probe(void *dpy)
|
||||||
return nprobe;
|
return nprobe;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum native_probe_result
|
static enum native_probe_result
|
||||||
native_get_probe_result(struct native_probe *nprobe)
|
x11_get_probe_result(struct native_probe *nprobe)
|
||||||
{
|
{
|
||||||
if (!nprobe || nprobe->magic != X11_PROBE_MAGIC)
|
if (!nprobe || nprobe->magic != X11_PROBE_MAGIC)
|
||||||
return NATIVE_PROBE_UNKNOWN;
|
return NATIVE_PROBE_UNKNOWN;
|
||||||
|
|
@ -106,17 +106,7 @@ native_get_probe_result(struct native_probe *nprobe)
|
||||||
return NATIVE_PROBE_EXACT;
|
return NATIVE_PROBE_EXACT;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
static struct native_display *
|
||||||
native_get_name(void)
|
|
||||||
{
|
|
||||||
static char x11_name[32];
|
|
||||||
|
|
||||||
util_snprintf(x11_name, sizeof(x11_name), "X11/%s", driver_descriptor.name);
|
|
||||||
|
|
||||||
return x11_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct native_display *
|
|
||||||
native_create_display(void *dpy, struct native_event_handler *event_handler)
|
native_create_display(void *dpy, struct native_event_handler *event_handler)
|
||||||
{
|
{
|
||||||
struct native_display *ndpy = NULL;
|
struct native_display *ndpy = NULL;
|
||||||
|
|
@ -139,3 +129,28 @@ native_create_display(void *dpy, struct native_event_handler *event_handler)
|
||||||
|
|
||||||
return ndpy;
|
return ndpy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
x11_init_platform(struct native_platform *nplat)
|
||||||
|
{
|
||||||
|
static char x11_name[32];
|
||||||
|
|
||||||
|
if (nplat->name)
|
||||||
|
return;
|
||||||
|
|
||||||
|
util_snprintf(x11_name, sizeof(x11_name), "X11/%s", driver_descriptor.name);
|
||||||
|
|
||||||
|
nplat->name = x11_name;
|
||||||
|
nplat->create_probe = x11_create_probe;
|
||||||
|
nplat->get_probe_result = x11_get_probe_result;
|
||||||
|
nplat->create_display = native_create_display;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct native_platform x11_platform;
|
||||||
|
|
||||||
|
const struct native_platform *
|
||||||
|
native_get_platform(void)
|
||||||
|
{
|
||||||
|
x11_init_platform(&x11_platform);
|
||||||
|
return &x11_platform;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue