From f66a4e20c19d55005854bbee312947ec16e287e3 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Thu, 17 Jun 2010 23:21:43 +0800 Subject: 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. --- src/gallium/state_trackers/egl/common/egl_g3d.c | 47 +++++++++++++++------- src/gallium/state_trackers/egl/common/egl_g3d.h | 1 + src/gallium/state_trackers/egl/common/native.h | 26 ++++++++++-- .../state_trackers/egl/common/native_probe.h | 16 -------- .../state_trackers/egl/fbdev/native_fbdev.c | 33 +++++++-------- src/gallium/state_trackers/egl/gdi/native_gdi.c | 33 +++++++-------- src/gallium/state_trackers/egl/kms/native_kms.c | 43 +++++++++++--------- src/gallium/state_trackers/egl/x11/native_x11.c | 45 ++++++++++++++------- 8 files changed, 137 insertions(+), 107 deletions(-) (limited to 'src') diff --git a/src/gallium/state_trackers/egl/common/egl_g3d.c b/src/gallium/state_trackers/egl/common/egl_g3d.c index b4ca861efe..6b54ee365c 100644 --- a/src/gallium/state_trackers/egl/common/egl_g3d.c +++ b/src/gallium/state_trackers/egl/common/egl_g3d.c @@ -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. */ -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); } /** @@ -460,10 +479,15 @@ egl_g3d_initialize(_EGLDriver *drv, _EGLDisplay *dpy, { 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"); @@ -471,7 +495,8 @@ egl_g3d_initialize(_EGLDriver *drv, _EGLDisplay *dpy, } 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)"); @@ -543,12 +568,10 @@ egl_g3d_get_proc_address(_EGLDriver *drv, const char *procname) 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: @@ -582,12 +605,8 @@ egl_g3d_unload(_EGLDriver *drv) _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; @@ -597,7 +616,7 @@ _eglMain(const char *args) 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; diff --git a/src/gallium/state_trackers/egl/common/egl_g3d.h b/src/gallium/state_trackers/egl/common/egl_g3d.h index d516d8fe03..26043169ff 100644 --- a/src/gallium/state_trackers/egl/common/egl_g3d.h +++ b/src/gallium/state_trackers/egl/common/egl_g3d.h @@ -47,6 +47,7 @@ struct egl_g3d_driver { struct st_api *stapis[ST_API_COUNT]; EGLint api_mask; + const struct native_platform *platform; EGLint probe_key; }; diff --git a/src/gallium/state_trackers/egl/common/native.h b/src/gallium/state_trackers/egl/common/native.h index 494becb61f..941adfc03f 100644 --- a/src/gallium/state_trackers/egl/common/native.h +++ b/src/gallium/state_trackers/egl/common/native.h @@ -207,10 +207,28 @@ native_attachment_mask_test(uint mask, enum native_attachment att) 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_ */ diff --git a/src/gallium/state_trackers/egl/common/native_probe.h b/src/gallium/state_trackers/egl/common/native_probe.h index 539c4aa70d..c0b7f2a1ff 100644 --- a/src/gallium/state_trackers/egl/common/native_probe.h +++ b/src/gallium/state_trackers/egl/common/native_probe.h @@ -49,20 +49,4 @@ struct native_probe { 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_ */ diff --git a/src/gallium/state_trackers/egl/fbdev/native_fbdev.c b/src/gallium/state_trackers/egl/fbdev/native_fbdev.c index 399c1251ef..ffd32fa46e 100644 --- a/src/gallium/state_trackers/egl/fbdev/native_fbdev.c +++ b/src/gallium/state_trackers/egl/fbdev/native_fbdev.c @@ -427,25 +427,7 @@ fbdev_display_create(int fd, struct native_event_handler *event_handler) 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; @@ -467,3 +449,16 @@ native_create_display(void *dpy, struct native_event_handler *event_handler) 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; +} diff --git a/src/gallium/state_trackers/egl/gdi/native_gdi.c b/src/gallium/state_trackers/egl/gdi/native_gdi.c index 56f190de00..ba4ddff232 100644 --- a/src/gallium/state_trackers/egl/gdi/native_gdi.c +++ b/src/gallium/state_trackers/egl/gdi/native_gdi.c @@ -366,25 +366,7 @@ gdi_create_display(HDC hDC, struct pipe_screen *screen, 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; @@ -403,3 +385,16 @@ native_create_display(void *dpy, struct native_event_handler *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; +} diff --git a/src/gallium/state_trackers/egl/kms/native_kms.c b/src/gallium/state_trackers/egl/kms/native_kms.c index 09a08f32b3..8ee80996a4 100644 --- a/src/gallium/state_trackers/egl/kms/native_kms.c +++ b/src/gallium/state_trackers/egl/kms/native_kms.c @@ -768,37 +768,40 @@ kms_create_display(int fd, struct native_event_handler *event_handler) 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; } diff --git a/src/gallium/state_trackers/egl/x11/native_x11.c b/src/gallium/state_trackers/egl/x11/native_x11.c index 6f1e599873..6c0201c26f 100644 --- a/src/gallium/state_trackers/egl/x11/native_x11.c +++ b/src/gallium/state_trackers/egl/x11/native_x11.c @@ -44,8 +44,8 @@ x11_probe_destroy(struct native_probe *nprobe) 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; @@ -89,8 +89,8 @@ native_create_probe(void *dpy) 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; @@ -106,17 +106,7 @@ native_get_probe_result(struct native_probe *nprobe) 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; @@ -139,3 +129,28 @@ native_create_display(void *dpy, struct native_event_handler *event_handler) 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; +} -- cgit v1.2.3