Mesa (master): wayland-egl: rework and simplify wl_egl_window initialization

Emil Velikov evelikov at kemper.freedesktop.org
Mon Oct 2 15:36:42 UTC 2017


Module: Mesa
Branch: master
Commit: 677edff5cfdefdd1433beff4787a7d7987e07bd3
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=677edff5cfdefdd1433beff4787a7d7987e07bd3

Author: Emil Velikov <emil.velikov at collabora.com>
Date:   Thu Sep 28 18:38:13 2017 +0100

wayland-egl: rework and simplify wl_egl_window initialization

Use calloc instead of malloc + explicitly zeroing the different fields.
We need special handling for the version field which is of type
const intptr_t.

As we're here document why keeping the constness is a good idea.

The wl_egl_window_resize() call is replaced with an explicit set of the
width/height.

Signed-off-by: Emil Velikov <emil.velikov at collabora.com>
Reviewed-by: Daniel Stone <daniels at collabora.com>
Reviewed-by: Miguel A. Vico <mvicomoya at nvidia.com>

---

 src/egl/wayland/wayland-egl/wayland-egl.c | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/src/egl/wayland/wayland-egl/wayland-egl.c b/src/egl/wayland/wayland-egl/wayland-egl.c
index 4501c6dc95..e7cea895ec 100644
--- a/src/egl/wayland/wayland-egl/wayland-egl.c
+++ b/src/egl/wayland/wayland-egl/wayland-egl.c
@@ -61,26 +61,32 @@ WL_EGL_EXPORT struct wl_egl_window *
 wl_egl_window_create(struct wl_surface *surface,
 		     int width, int height)
 {
-	struct wl_egl_window _INIT_ = { .version = WL_EGL_WINDOW_VERSION };
 	struct wl_egl_window *egl_window;
 
 	if (width <= 0 || height <= 0)
 		return NULL;
 
-	egl_window = malloc(sizeof *egl_window);
+	egl_window = calloc(1, sizeof *egl_window);
 	if (!egl_window)
 		return NULL;
 
-	memcpy(egl_window, &_INIT_, sizeof *egl_window);
+	/* Cast away the constness to set the version number.
+	 *
+	 * We want the const notation since it gives an explicit
+	 * feedback to the backend implementation, should it try to
+	 * change it.
+	 *
+	 * The latter in itself is not too surprising as these days APIs
+	 * tend to provide bidirectional version field.
+	 */
+	intptr_t *version = (intptr_t *)&egl_window->version;
+	*version = WL_EGL_WINDOW_VERSION;
 
 	egl_window->surface = surface;
-	egl_window->private = NULL;
-	egl_window->resize_callback = NULL;
-	egl_window->destroy_window_callback = NULL;
-	wl_egl_window_resize(egl_window, width, height, 0, 0);
-	egl_window->attached_width  = 0;
-	egl_window->attached_height = 0;
-	
+
+	egl_window->width  = width;
+	egl_window->height = height;
+
 	return egl_window;
 }
 




More information about the mesa-commit mailing list