}
/**
- * 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.
*/
-static struct native_probe *
-egl_g3d_get_probe(_EGLDriver *drv, _EGLDisplay *dpy)
+static enum native_probe_result
+egl_g3d_get_probe_result(_EGLDriver *drv, _EGLDisplay *dpy)
{
struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
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);
if (!nprobe || nprobe->display != dpy->PlatformDisplay) {
if (nprobe)
nprobe->destroy(nprobe);
- nprobe = native_create_probe(dpy->PlatformDisplay);
+ nprobe = nplat->create_probe(dpy->PlatformDisplay);
_eglSetProbeCache(gdrv->probe_key, (void *) nprobe);
}
- return nprobe;
+ return nplat->get_probe_result(nprobe);
}
/**
{
struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
struct egl_g3d_display *gdpy;
+ const struct native_platform *nplat;
/* the probe object is unlikely to be needed again */
egl_g3d_destroy_probe(drv, dpy);
+ nplat = egl_g3d_get_platform(drv);
+ if (!nplat)
+ return EGL_FALSE;
+
gdpy = CALLOC_STRUCT(egl_g3d_display);
if (!gdpy) {
_eglError(EGL_BAD_ALLOC, "eglInitialize");
}
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);
if (!gdpy->native) {
_eglError(EGL_NOT_INITIALIZED, "eglInitialize(no usable display)");
static EGLint
egl_g3d_probe(_EGLDriver *drv, _EGLDisplay *dpy)
{
- struct native_probe *nprobe;
enum native_probe_result res;
EGLint score;
- nprobe = egl_g3d_get_probe(drv, dpy);
- res = native_get_probe_result(nprobe);
+ res = egl_g3d_get_probe_result(drv, dpy);
switch (res) {
case NATIVE_PROBE_UNKNOWN:
_EGLDriver *
_eglMain(const char *args)
{
- static char driver_name[64];
struct egl_g3d_driver *gdrv;
- util_snprintf(driver_name, sizeof(driver_name),
- "Gallium/%s", native_get_name());
-
gdrv = CALLOC_STRUCT(egl_g3d_driver);
if (!gdrv)
return NULL;
gdrv->base.API.Terminate = egl_g3d_terminate;
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.Unload = egl_g3d_unload;
struct st_api *stapis[ST_API_COUNT];
EGLint api_mask;
+ const struct native_platform *platform;
EGLint probe_key;
};
return !!(mask & (1 << att));
}
-const char *
-native_get_name(void);
+struct native_platform {
+ 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_ */
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_ */
return &fbdpy->base;
}
-struct native_probe *
-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 *
+static struct native_display *
native_create_display(void *dpy, struct native_event_handler *event_handler)
{
struct native_display *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;
+}
return &gdpy->base;
}
-struct native_probe *
-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 *
+static struct native_display *
native_create_display(void *dpy, struct native_event_handler *event_handler)
{
struct sw_winsys *winsys;
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;
+}
return &kdpy->base;
}
-struct native_probe *
-native_create_probe(void *dpy)
+static struct native_display *
+native_create_display(void *dpy, struct native_event_handler *event_handler)
{
- return NULL;
-}
+ struct native_display *ndpy;
+ int fd;
-enum native_probe_result
-native_get_probe_result(struct native_probe *nprobe)
-{
- return NATIVE_PROBE_UNKNOWN;
+ /* well, this makes fd 0 being ignored */
+ fd = (dpy) ? (int) pointer_to_intptr(dpy) : -1;
+ ndpy = kms_create_display(fd, event_handler);
+
+ return ndpy;
}
-const char *
-native_get_name(void)
+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);
- return kms_name;
+ nplat->name = kms_name;
+ nplat->create_probe = NULL;
+ nplat->get_probe_result = NULL;
+ nplat->create_display = native_create_display;
}
-struct native_display *
-native_create_display(void *dpy, struct native_event_handler *event_handler)
-{
- struct native_display *ndpy = NULL;
- int fd;
-
- fd = (dpy != EGL_DEFAULT_DISPLAY) ? (int) pointer_to_intptr((void *) dpy) : -1;
- ndpy = kms_create_display(fd, event_handler);
+static struct native_platform kms_platform;
- return ndpy;
+const struct native_platform *
+native_get_platform(void)
+{
+ kms_init_platform(&kms_platform);
+ return &kms_platform;
}
FREE(nprobe);
}
-struct native_probe *
-native_create_probe(void *dpy)
+static struct native_probe *
+x11_create_probe(void *dpy)
{
struct native_probe *nprobe;
struct x11_screen *xscr;
return nprobe;
}
-enum native_probe_result
-native_get_probe_result(struct native_probe *nprobe)
+static enum native_probe_result
+x11_get_probe_result(struct native_probe *nprobe)
{
if (!nprobe || nprobe->magic != X11_PROBE_MAGIC)
return NATIVE_PROBE_UNKNOWN;
return NATIVE_PROBE_EXACT;
}
-const char *
-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 *
+static struct native_display *
native_create_display(void *dpy, struct native_event_handler *event_handler)
{
struct native_display *ndpy = NULL;
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;
+}