Commit b072d9ee authored by Chad Versace's avatar Chad Versace

waffle: Fix waffle_*_get_native functions

This patch fixes all waffle_*_get_native functions for glx, x11_egl, and
wayland. The functions never did work because I incorrectly implemented
them like this:

    union waffle_native_display*
    glx_display_get_native(...)
    {
        struct waffle_glx_display *n_dpy = malloc(sizeof(*n_dpy));
        [fill n_dpy];
        return (union waffle_native_display*) n_dpy;
    }

That implementation would have been correct if the union were defined as:

    union waffle_native_display {
        struct waffle_glx_display glx;
        ...
    };

Instead, the union is defined as:

    union waffle_native_display {
        struct waffle_glx_display *glx;
        ...
    };

Therefore, the correct implementation looks like this, modulo error
checking:

    union waffle_native_display*
    glx_display_get_native(...)
    {
        union waffle_native_display *n_dpy = malloc(sizeof(*n_dpy));
        n_dpy->glx = malloc(sizeof(*n_dpy->glx));
        [fill n_dpy->glx];
        return n_dpy;
    }
Signed-off-by: default avatarChad Versace <chad.versace@linux.intel.com>
parent d1c3e0cd
......@@ -29,6 +29,8 @@
#include <stdbool.h>
#include <stdlib.h>
#include "waffle_config.h"
#include "waffle/api/api_object.h"
#include "wcore_display.h"
......
......@@ -29,6 +29,8 @@
#include <stdbool.h>
#include <stdlib.h>
#include "waffle_context.h"
#include "waffle/api/api_object.h"
#include "wcore_config.h"
......
......@@ -29,6 +29,8 @@
#include <stdlib.h>
#include <stdint.h>
#include "waffle_display.h"
#include "waffle/api/api_object.h"
#include "wcore_util.h"
......
......@@ -59,3 +59,21 @@ wcore_malloc(size_t size);
/// easy to use incorrectly.
void*
wcore_calloc(size_t size);
/// @brief Create one of `union waffle_native_*`.
///
/// The example below allocates n_dpy and n_dpy->glx, then sets both
/// variables.
///
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.c}
/// union waffle_native_display *n_dpy;
/// WCORE_CREATE_NATIVE_UNION(n_dpy, glx);
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
///
#define WCORE_CREATE_NATIVE_UNION(union_var, union_member) \
do { \
union_var = wcore_malloc(sizeof(*union_var) + \
sizeof(*union_var->union_member)); \
if (union_var) \
union_var->union_member = (void*) (union_var + 1); \
} while (0)
......@@ -28,6 +28,8 @@
#include <stdbool.h>
#include <stdlib.h>
#include "waffle_window.h"
#include "wcore_config.h"
#include "wcore_util.h"
......
......@@ -222,16 +222,16 @@ glx_config_get_native(struct wcore_config *wc_self)
{
struct glx_config *self = glx_config(wc_self);
struct glx_display *dpy = glx_display(wc_self->display);
struct waffle_glx_config *n_config;
union waffle_native_config *n_config;
n_config = wcore_malloc(sizeof(*n_config));
if (n_config == NULL)
WCORE_CREATE_NATIVE_UNION(n_config, glx);
if (!n_config)
return NULL;
n_config->xlib_display = dpy->x11.xlib;
n_config->glx_fbconfig = self->glx_fbconfig;
n_config->glx->xlib_display = dpy->x11.xlib;
n_config->glx->glx_fbconfig = self->glx_fbconfig;
return (union waffle_native_config*) n_config;
return n_config;
}
static const struct wcore_config_vtbl glx_config_wcore_vtbl = {
......
......@@ -187,16 +187,16 @@ glx_context_get_native(struct wcore_context *wc_self)
{
struct glx_context *self = glx_context(wc_self);
struct glx_display *dpy = glx_display(wc_self->display);
struct waffle_glx_context *n_ctx;
union waffle_native_context *n_ctx;
n_ctx = wcore_malloc(sizeof(*n_ctx));
if (n_ctx == NULL)
WCORE_CREATE_NATIVE_UNION(n_ctx, glx);
if (!n_ctx)
return NULL;
n_ctx->xlib_display = dpy->x11.xlib;
n_ctx->glx_context = self->glx;
n_ctx->glx->xlib_display = dpy->x11.xlib;
n_ctx->glx->glx_context = self->glx;
return (union waffle_native_context*) n_ctx;
return n_ctx;
}
static const struct wcore_context_vtbl glx_context_wcore_vtbl = {
......
......@@ -128,15 +128,15 @@ static union waffle_native_display*
glx_display_get_native(struct wcore_display *wc_self)
{
struct glx_display *self = glx_display(wc_self);
struct waffle_glx_display *n_dpy;
union waffle_native_display *n_dpy;
n_dpy = wcore_malloc(sizeof(*n_dpy));
if (n_dpy == NULL)
WCORE_CREATE_NATIVE_UNION(n_dpy, glx);
if (!n_dpy)
return NULL;
n_dpy->xlib_display = self->x11.xlib;
n_dpy->glx->xlib_display = self->x11.xlib;
return (union waffle_native_display*) n_dpy;
return n_dpy;
}
static const struct wcore_display_vtbl glx_display_wcore_vtbl = {
......
......@@ -30,6 +30,8 @@
#include <xcb/xcb.h>
#undef linux
#include "waffle_glx.h"
#include "waffle/core/wcore_platform.h"
#include "waffle/core/wcore_util.h"
......
......@@ -106,16 +106,16 @@ glx_window_get_native(struct wcore_window *wc_self)
{
struct glx_window *self = glx_window(wc_self);
struct glx_display *dpy = glx_display(wc_self->display);
struct waffle_glx_window *n_window;
union waffle_native_window *n_window;
n_window = wcore_malloc(sizeof(*n_window));
if (n_window == NULL)
WCORE_CREATE_NATIVE_UNION(n_window, glx);
if (!n_window)
return NULL;
n_window->xlib_display = dpy->x11.xlib;
n_window->xlib_window = self->x11.xcb;
n_window->glx->xlib_display = dpy->x11.xlib;
n_window->glx->xlib_window = self->x11.xcb;
return (union waffle_native_window*) n_window;
return n_window;
}
static const struct wcore_window_vtbl glx_window_wcore_vtbl = {
......
......@@ -91,16 +91,16 @@ wayland_config_get_native(struct wcore_config *wc_self)
{
struct wayland_config *self = wayland_config(wc_self);
struct wayland_display *dpy = wayland_display(wc_self->display);
struct waffle_wayland_config *n_config;
union waffle_native_config *n_config;
n_config = wcore_malloc(sizeof(*n_config));
if (n_config == NULL)
WCORE_CREATE_NATIVE_UNION(n_config, wayland);
if (!n_config)
return NULL;
wayland_display_fill_native(dpy, &n_config->display);
n_config->egl_config = self->egl;
wayland_display_fill_native(dpy, &n_config->wayland->display);
n_config->wayland->egl_config = self->egl;
return (union waffle_native_config*) n_config;
return n_config;
}
static const struct wcore_config_vtbl wayland_config_wcore_vtbl = {
......
......@@ -96,16 +96,16 @@ wayland_context_get_native(struct wcore_context *wc_self)
{
struct wayland_context *self = wayland_context(wc_self);
struct wayland_display *dpy = wayland_display(wc_self->display);
struct waffle_wayland_context *n_ctx;
union waffle_native_context *n_ctx;
n_ctx = wcore_malloc(sizeof(*n_ctx));
if (n_ctx == NULL)
WCORE_CREATE_NATIVE_UNION(n_ctx, wayland);
if (!n_ctx)
return NULL;
wayland_display_fill_native(dpy, &n_ctx->display);
n_ctx->egl_context = self->egl;
wayland_display_fill_native(dpy, &n_ctx->wayland->display);
n_ctx->wayland->egl_context = self->egl;
return (union waffle_native_context*) n_ctx;
return n_ctx;
}
static const struct wcore_context_vtbl wayland_context_wcore_vtbl = {
......
......@@ -136,15 +136,15 @@ static union waffle_native_display*
wayland_display_get_native(struct wcore_display *wc_self)
{
struct wayland_display *self = wayland_display(wc_self);
struct waffle_wayland_display *n_dpy;
union waffle_native_display *n_dpy;
n_dpy = wcore_malloc(sizeof(*n_dpy));
if (n_dpy == NULL)
WCORE_CREATE_NATIVE_UNION(n_dpy, wayland);
if (!n_dpy)
return NULL;
wayland_display_fill_native(self, n_dpy);
wayland_display_fill_native(self, n_dpy->wayland);
return (union waffle_native_display*) n_dpy;
return n_dpy;
}
static const struct wcore_display_vtbl wayland_display_wcore_vtbl = {
......
......@@ -30,6 +30,8 @@
#undef linux
#include "waffle_wayland.h"
#include "waffle/core/wcore_platform.h"
#include "waffle/core/wcore_util.h"
......
......@@ -160,19 +160,19 @@ wayland_window_get_native(struct wcore_window *wc_self)
{
struct wayland_window *self = wayland_window(wc_self);
struct wayland_display *dpy = wayland_display(wc_self->display);
struct waffle_wayland_window *n_window;
union waffle_native_window *n_window;
n_window = wcore_malloc(sizeof(*n_window));
if (n_window == NULL)
WCORE_CREATE_NATIVE_UNION(n_window, wayland);
if (!n_window)
return NULL;
wayland_display_fill_native(dpy, &n_window->display);
n_window->wl_surface = self->wl_surface;
n_window->wl_shell_surface = self->wl_shell_surface;
n_window->wl_window = self->wl_window;
n_window->egl_surface = self->egl;
wayland_display_fill_native(dpy, &n_window->wayland->display);
n_window->wayland->wl_surface = self->wl_surface;
n_window->wayland->wl_shell_surface = self->wl_shell_surface;
n_window->wayland->wl_window = self->wl_window;
n_window->wayland->egl_surface = self->egl;
return (union waffle_native_window*) n_window;
return n_window;
}
static const struct wcore_window_vtbl wayland_window_wcore_vtbl = {
......
......@@ -98,16 +98,16 @@ xegl_config_get_native(struct wcore_config *wc_self)
{
struct xegl_config *self = xegl_config(wc_self);
struct xegl_display *dpy = xegl_display(wc_self->display);
struct waffle_x11_egl_config *n_config;
union waffle_native_config *n_config;
n_config = wcore_malloc(sizeof(*n_config));
if (n_config == NULL)
WCORE_CREATE_NATIVE_UNION(n_config, x11_egl);
if (!n_config)
return NULL;
xegl_display_fill_native(dpy, &n_config->display);
n_config->egl_config = self->egl;
xegl_display_fill_native(dpy, &n_config->x11_egl->display);
n_config->x11_egl->egl_config = self->egl;
return (union waffle_native_config*) n_config;
return n_config;
}
static const struct wcore_config_vtbl xegl_config_wcore_vtbl = {
......
......@@ -94,16 +94,16 @@ xegl_context_get_native(struct wcore_context *wc_self)
{
struct xegl_context *self = xegl_context(wc_self);
struct xegl_display *dpy = xegl_display(wc_self->display);
struct waffle_x11_egl_context *n_ctx;
union waffle_native_context *n_ctx;
n_ctx = wcore_malloc(sizeof(*n_ctx));
if (n_ctx == NULL)
WCORE_CREATE_NATIVE_UNION(n_ctx, x11_egl);
if (!n_ctx)
return NULL;
xegl_display_fill_native(dpy, &n_ctx->display);
n_ctx->egl_context = self->egl;
xegl_display_fill_native(dpy, &n_ctx->x11_egl->display);
n_ctx->x11_egl->egl_context = self->egl;
return (union waffle_native_context*) n_ctx;
return n_ctx;
}
static const struct wcore_context_vtbl xegl_context_wcore_vtbl = {
......
......@@ -103,15 +103,14 @@ static union waffle_native_display*
xegl_display_get_native(struct wcore_display *wc_self)
{
struct xegl_display *self = xegl_display(wc_self);
struct waffle_x11_egl_display *n_dpy;
union waffle_native_display *n_dpy;
n_dpy = wcore_malloc(sizeof(*n_dpy));
if (n_dpy == NULL)
WCORE_CREATE_NATIVE_UNION(n_dpy, x11_egl);
if (!n_dpy)
return NULL;
xegl_display_fill_native(self, n_dpy);
return (union waffle_native_display*) n_dpy;
xegl_display_fill_native(self, n_dpy->x11_egl);
return n_dpy;
}
static const struct wcore_display_vtbl xegl_display_wcore_vtbl = {
......
......@@ -29,6 +29,8 @@
#include <stdlib.h>
#undef linux
#include "waffle_x11_egl.h"
#include "waffle/core/wcore_platform.h"
#include "waffle/core/wcore_util.h"
......
......@@ -118,17 +118,17 @@ xegl_window_get_native(struct wcore_window *wc_self)
{
struct xegl_window *self = xegl_window(wc_self);
struct xegl_display *dpy = xegl_display(wc_self->display);
struct waffle_x11_egl_window *n_window;
union waffle_native_window *n_window;
n_window = wcore_malloc(sizeof(*n_window));
if (n_window == NULL)
WCORE_CREATE_NATIVE_UNION(n_window, x11_egl);
if (!n_window)
return NULL;
xegl_display_fill_native(dpy, &n_window->display);
n_window->xlib_window = self->x11.xcb;
n_window->egl_surface = self->egl;
xegl_display_fill_native(dpy, &n_window->x11_egl->display);
n_window->x11_egl->xlib_window = self->x11.xcb;
n_window->x11_egl->egl_surface = self->egl;
return (union waffle_native_window*) n_window;
return n_window;
}
static const struct wcore_window_vtbl xegl_window_wcore_vtbl = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment