st/egl: Add native_surface::present callback.
[mesa.git] / src / gallium / state_trackers / egl / fbdev / native_fbdev.c
index d70b7c6eb965f3014ce070cca3275a3c48a6e55c..728dba3ff49f9ca8b864aca559dca5befbf509b2 100644 (file)
@@ -137,6 +137,32 @@ fbdev_surface_swap_buffers(struct native_surface *nsurf)
    return ret;
 }
 
+static boolean
+fbdev_surface_present(struct native_surface *nsurf,
+                      enum native_attachment natt,
+                      boolean preserve,
+                      uint swap_interval)
+{
+   boolean ret;
+
+   if (preserve || swap_interval)
+      return FALSE;
+
+   switch (natt) {
+   case NATIVE_ATTACHMENT_FRONT_LEFT:
+      ret = fbdev_surface_flush_frontbuffer(nsurf);
+      break;
+   case NATIVE_ATTACHMENT_BACK_LEFT:
+      ret = fbdev_surface_swap_buffers(nsurf);
+      break;
+   default:
+      ret = FALSE;
+      break;
+   }
+
+   return ret;
+}
+
 static void
 fbdev_surface_wait(struct native_surface *nsurf)
 {
@@ -183,6 +209,7 @@ fbdev_display_create_scanout_surface(struct native_display *ndpy,
    fbsurf->base.destroy = fbdev_surface_destroy;
    fbsurf->base.swap_buffers = fbdev_surface_swap_buffers;
    fbsurf->base.flush_frontbuffer = fbdev_surface_flush_frontbuffer;
+   fbsurf->base.present = fbdev_surface_present;
    fbsurf->base.validate = fbdev_surface_validate;
    fbsurf->base.wait = fbdev_surface_wait;
 
@@ -279,6 +306,9 @@ fbdev_display_get_param(struct native_display *ndpy,
    int val;
 
    switch (param) {
+   case NATIVE_PARAM_USE_NATIVE_BUFFER:
+   case NATIVE_PARAM_PRESERVE_BUFFER:
+   case NATIVE_PARAM_MAX_SWAP_INTERVAL:
    default:
       val = 0;
       break;
@@ -386,8 +416,10 @@ fbdev_display_init(struct native_display *ndpy)
       return FALSE;
 
    ws = fbdev_create_sw_winsys(fbdpy->fd, fbdpy->config.color_format);
-   if (ws)
-      fbdpy->base.screen = native_create_sw_screen(ws);
+   if (ws) {
+      fbdpy->base.screen =
+         fbdpy->event_handler->new_sw_screen(&fbdpy->base, ws);
+   }
 
    if (fbdpy->base.screen) {
       if (!fbdpy->base.screen->is_format_supported(fbdpy->base.screen,
@@ -402,7 +434,8 @@ fbdev_display_init(struct native_display *ndpy)
 }
 
 static struct native_display *
-fbdev_display_create(int fd, struct native_event_handler *event_handler)
+fbdev_display_create(int fd, struct native_event_handler *event_handler,
+                     void *user_data)
 {
    struct fbdev_display *fbdpy;
 
@@ -412,6 +445,7 @@ fbdev_display_create(int fd, struct native_event_handler *event_handler)
 
    fbdpy->fd = fd;
    fbdpy->event_handler = event_handler;
+   fbdpy->base.user_data = user_data;
 
    if (!fbdev_display_init(&fbdpy->base)) {
       FREE(fbdpy);
@@ -427,44 +461,37 @@ fbdev_display_create(int fd, struct native_event_handler *event_handler)
    return &fbdpy->base;
 }
 
-struct native_probe *
-native_create_probe(EGLNativeDisplayType 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(EGLNativeDisplayType dpy,
-                      struct native_event_handler *event_handler)
+static struct native_display *
+native_create_display(void *dpy, struct native_event_handler *event_handler,
+                      void *user_data)
 {
    struct native_display *ndpy;
    int fd;
 
    /* well, this makes fd 0 being ignored */
-   if (dpy == EGL_DEFAULT_DISPLAY) {
+   if (!dpy) {
       fd = open("/dev/fb0", O_RDWR);
    }
    else {
-      fd = dup((int) pointer_to_intptr((void *) dpy));
+      fd = dup((int) pointer_to_intptr(dpy));
    }
    if (fd < 0)
       return NULL;
 
-   ndpy = fbdev_display_create(fd, event_handler);
+   ndpy = fbdev_display_create(fd, event_handler, user_data);
    if (!ndpy)
       close(fd);
 
    return ndpy;
 }
+
+static const struct native_platform fbdev_platform = {
+   "FBDEV", /* name */
+   native_create_display
+};
+
+const struct native_platform *
+native_get_fbdev_platform(void)
+{
+   return &fbdev_platform;
+}