[waffle] [PATCH 4/4] gbm: implement window_resize

Emil Velikov emil.l.velikov at gmail.com
Mon May 16 10:48:10 UTC 2016


From: Emil Velikov <emil.velikov at collabora.com>

Reuse the existing init/teardown functions to create a new window and
nuke the old one on success.

Note: as we need the original config, we keep a reference to it in
struct wcore_config. Ideally there will be a generic way to query it.

Signed-off-by: Emil Velikov <emil.velikov at collabora.com>
---
 src/waffle/gbm/wgbm_platform.c |  1 +
 src/waffle/gbm/wgbm_window.c   | 43 ++++++++++++++++++++++++++++++++++++++++++
 src/waffle/gbm/wgbm_window.h   |  5 +++++
 3 files changed, 49 insertions(+)

diff --git a/src/waffle/gbm/wgbm_platform.c b/src/waffle/gbm/wgbm_platform.c
index 5e36534..f4147af 100644
--- a/src/waffle/gbm/wgbm_platform.c
+++ b/src/waffle/gbm/wgbm_platform.c
@@ -210,6 +210,7 @@ static const struct wcore_platform_vtbl wgbm_platform_vtbl = {
         .destroy = wgbm_window_destroy,
         .show = wgbm_window_show,
         .swap_buffers = wgbm_window_swap_buffers,
+        .resize = wgbm_window_resize,
         .get_native = wgbm_window_get_native,
     },
 };
diff --git a/src/waffle/gbm/wgbm_window.c b/src/waffle/gbm/wgbm_window.c
index 12ae197..d9dcba0 100644
--- a/src/waffle/gbm/wgbm_window.c
+++ b/src/waffle/gbm/wgbm_window.c
@@ -32,8 +32,10 @@
 
 #include "wcore_attrib_list.h"
 #include "wcore_error.h"
+#include "wcore_tinfo.h"
 
 #include "wegl_config.h"
+#include "wegl_util.h"
 
 #include "wgbm_config.h"
 #include "wgbm_display.h"
@@ -92,6 +94,7 @@ wgbm_window_init(struct wgbm_window *self,
     if (!ok)
         return false;
 
+    self->wc_config = wc_config;
     return true;
 }
 
@@ -155,6 +158,46 @@ wgbm_window_swap_buffers(struct wcore_window *wc_self)
     return true;
 }
 
+bool
+wgbm_window_resize(struct wcore_window *wc_self,
+                   int32_t width, int32_t height)
+{
+    struct wcore_display *wc_dpy = wc_self->display;
+    struct wcore_platform *wc_plat = wc_self->display->platform;
+    struct wgbm_window *self = wgbm_window(wc_self);
+    struct wgbm_window backup_self;
+    struct wcore_context *wc_ctx;
+    struct wcore_tinfo *tinfo;
+    bool ok = true;
+
+    // Backup the old window/surface so that we can restore it upon failure.
+    backup_self = *self;
+
+    ok = wgbm_window_init(self, wc_plat, self->wc_config, width, height);
+    if (!ok)
+        goto error;
+
+    tinfo = wcore_tinfo_get();
+    wc_ctx = tinfo->current_context;
+
+    // XXX: Can/should we use waffle_make_current() here ?
+    ok = wegl_make_current(wc_plat, wc_dpy, wc_self, wc_ctx);
+    if (!ok)
+        goto error;
+
+    // We don't need to set current_display or current_window
+    tinfo->current_context = wc_ctx;
+
+    // Everything went fine, so teardown the old window.
+    wgbm_window_teardown(&backup_self);
+    return true;
+
+error:
+    // Nuke the new window and restore the old one.
+    wgbm_window_teardown(self);
+    *self = backup_self;
+    return false;
+}
 
 union waffle_native_window*
 wgbm_window_get_native(struct wcore_window *wc_self)
diff --git a/src/waffle/gbm/wgbm_window.h b/src/waffle/gbm/wgbm_window.h
index 7827823..d4015a0 100644
--- a/src/waffle/gbm/wgbm_window.h
+++ b/src/waffle/gbm/wgbm_window.h
@@ -35,6 +35,7 @@ struct gbm_surface;
 struct wgbm_window {
     struct gbm_surface *gbm_surface;
     struct wegl_window wegl;
+    struct wcore_config *wc_config;
 };
 
 static inline struct wgbm_window*
@@ -65,5 +66,9 @@ wgbm_window_show(struct wcore_window *wc_self);
 bool
 wgbm_window_swap_buffers(struct wcore_window *wc_self);
 
+bool
+wgbm_window_resize(struct wcore_window *wc_self,
+                   int32_t width, int32_t height);
+
 union waffle_native_window*
 wgbm_window_get_native(struct wcore_window *wc_self);
-- 
2.6.2



More information about the waffle mailing list