Commit 46696e98 authored by Chad Versace's avatar Chad Versace

core: Aggregate all object vtbl's into wcore_platform_vtbl

Functions have always been dispatched at the granularity of platform, not
of object. Having each object possess a vtbl is unnecessary and just
overcomplicates things. Virtual dispatch in C is messy business, and we
should keep it as simple as possible.

This patch moves the vtbl for each of wcore_display, wcore_config,
wcore_context, and wcore_window into the vtbl of wcore_platform.
Signed-off-by: default avatarChad Versace <chad.versace@linux.intel.com>
parent f89a8f09
......@@ -37,8 +37,6 @@
#include "droid_display.h"
#include "droid_surfaceflingerlink.h"
static const struct wcore_config_vtbl droid_config_wcore_vtbl;
struct wcore_config*
droid_config_choose(struct wcore_platform *wc_plat,
struct wcore_display *wc_dpy,
......@@ -74,7 +72,6 @@ droid_config_choose(struct wcore_platform *wc_plat,
}
self->waffle_context_api = attrs->context_api;
self->wcore.vtbl = &droid_config_wcore_vtbl;
return &self->wcore;
error:
......@@ -102,8 +99,3 @@ droid_config_get_native(struct wcore_config *wc_self)
wcore_error(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM);
return NULL;
}
static const struct wcore_config_vtbl droid_config_wcore_vtbl = {
.destroy = droid_config_destroy,
.get_native = droid_config_get_native,
};
......@@ -34,8 +34,6 @@
#include "droid_priv_egl.h"
#include "droid_surfaceflingerlink.h"
static const struct wcore_context_vtbl droid_context_wcore_vtbl;
struct wcore_context*
droid_context_create(struct wcore_platform *wc_plat,
struct wcore_config *wc_config,
......@@ -64,7 +62,6 @@ droid_context_create(struct wcore_platform *wc_plat,
if (!self->egl)
goto error;
self->wcore.vtbl = &droid_context_wcore_vtbl;
return &self->wcore;
error:
......@@ -96,8 +93,3 @@ droid_context_get_native(struct wcore_context *wc_self)
wcore_error(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM);
return NULL;
}
static const struct wcore_context_vtbl droid_context_wcore_vtbl = {
.destroy = droid_context_destroy,
.get_native = droid_context_get_native,
};
......@@ -35,8 +35,6 @@
#include "droid_priv_egl.h"
#include "droid_surfaceflingerlink.h"
static const struct wcore_display_vtbl droid_display_wcore_vtbl;
struct wcore_display*
droid_display_connect(struct wcore_platform *wc_plat,
const char *name)
......@@ -62,7 +60,6 @@ droid_display_connect(struct wcore_platform *wc_plat,
if (!self->egl)
goto error;
self->wcore.vtbl = &droid_display_wcore_vtbl;
return &self->wcore;
error:
......@@ -103,9 +100,3 @@ droid_display_supports_context_api(
{
return egl_supports_context_api(wc_self->platform, context_api);
}
static const struct wcore_display_vtbl droid_display_wcore_vtbl = {
.destroy = droid_display_disconnect,
.get_native = droid_display_get_native,
.supports_context_api = droid_display_supports_context_api,
};
......@@ -37,7 +37,7 @@
#include "droid_priv_egl.h"
#include "droid_window.h"
static const struct wcore_platform_vtbl droid_platform_wcore_vtbl;
static const struct wcore_platform_vtbl droid_platform_vtbl;
static bool
droid_platform_destroy(struct wcore_platform *wc_self)
......@@ -74,7 +74,7 @@ droid_platform_create(void)
if (!self->linux)
goto error;
self->wcore.vtbl = &droid_platform_wcore_vtbl;
self->wcore.vtbl = &droid_platform_vtbl;
return &self->wcore;
error:
......@@ -120,14 +120,38 @@ droid_dl_sym(
waffle_dl, name);
}
static const struct wcore_platform_vtbl droid_platform_wcore_vtbl = {
static const struct wcore_platform_vtbl droid_platform_vtbl = {
.destroy = droid_platform_destroy,
.connect_to_display = droid_display_connect,
.choose_config = droid_config_choose,
.create_context = droid_context_create,
.create_window = droid_window_create,
.make_current = droid_make_current,
.get_proc_address = droid_get_proc_address,
.dl_can_open = droid_dl_can_open,
.dl_sym = droid_dl_sym,
.display = {
.connect = droid_display_connect,
.destroy = droid_display_disconnect,
.supports_context_api = droid_display_supports_context_api,
.get_native = droid_display_get_native,
},
.config = {
.choose = droid_config_choose,
.destroy = droid_config_destroy,
.get_native = droid_config_get_native,
},
.context = {
.create = droid_context_create,
.destroy = droid_context_destroy,
.get_native = droid_context_get_native,
},
.window = {
.create = droid_window_create,
.destroy = droid_window_destroy,
.show = droid_window_show,
.swap_buffers = droid_window_swap_buffers,
.get_native = droid_window_get_native,
},
};
......@@ -35,8 +35,6 @@
#include "droid_display.h"
#include "droid_surfaceflingerlink.h"
static const struct wcore_window_vtbl droid_window_wcore_vtbl;
struct wcore_window*
droid_window_create(struct wcore_platform *wc_plat,
struct wcore_config *wc_config,
......@@ -67,7 +65,6 @@ droid_window_create(struct wcore_platform *wc_plat,
if (!self->egl)
goto error;
self->wcore.vtbl = &droid_window_wcore_vtbl;
return &self->wcore;
error:
......@@ -127,10 +124,3 @@ droid_window_swap_buffers(struct wcore_window *wc_self)
return egl_swap_buffers(dpy->egl, self->egl);
}
static const struct wcore_window_vtbl droid_window_wcore_vtbl = {
.destroy = droid_window_destroy,
.get_native = droid_window_get_native,
.show = droid_window_show,
.swap_buffers = droid_window_swap_buffers,
};
......@@ -60,9 +60,7 @@ waffle_config_choose(
if (!ok)
return NULL;
wc_self = api_platform->vtbl->choose_config(api_platform,
wc_dpy,
&attrs);
wc_self = api_platform->vtbl->config.choose(api_platform, wc_dpy, &attrs);
if (!wc_self)
return NULL;
......@@ -81,7 +79,7 @@ waffle_config_destroy(struct waffle_config *self)
if (!api_check_entry(obj_list, 1))
return false;
return wc_self->vtbl->destroy(wc_self);
return api_platform->vtbl->config.destroy(wc_self);
}
union waffle_native_config*
......@@ -96,7 +94,7 @@ waffle_config_get_native(struct waffle_config *self)
if (!api_check_entry(obj_list, 1))
return NULL;
return wc_self->vtbl->get_native(wc_self);
return api_platform->vtbl->config.get_native(wc_self);
}
/// @}
......@@ -56,7 +56,7 @@ waffle_context_create(
if (!api_check_entry(obj_list, len))
return NULL;
wc_self = api_platform->vtbl->create_context(api_platform,
wc_self = api_platform->vtbl->context.create(api_platform,
wc_config,
wc_shared_ctx);
if (!wc_self)
......@@ -77,7 +77,7 @@ waffle_context_destroy(struct waffle_context *self)
if (!api_check_entry(obj_list, 1))
return false;
return wc_self->vtbl->destroy(wc_self);
return api_platform->vtbl->context.destroy(wc_self);
}
union waffle_native_context*
......@@ -92,7 +92,7 @@ waffle_context_get_native(struct waffle_context *self)
if (!api_check_entry(obj_list, 1))
return NULL;
return wc_self->vtbl->get_native(wc_self);
return api_platform->vtbl->context.get_native(wc_self);
}
/// @}
......@@ -48,7 +48,7 @@ waffle_display_connect(const char *name)
if (!api_check_entry(NULL, 0))
return NULL;
wc_self = api_platform->vtbl->connect_to_display(api_platform, name);
wc_self = api_platform->vtbl->display.connect(api_platform, name);
if (!wc_self)
return NULL;
......@@ -67,7 +67,7 @@ waffle_display_disconnect(struct waffle_display *self)
if (!api_check_entry(obj_list, 1))
return false;
return wc_self->vtbl->destroy(wc_self);
return api_platform->vtbl->display.destroy(wc_self);
}
bool
......@@ -95,7 +95,8 @@ waffle_display_supports_context_api(
return false;
}
return wc_self->vtbl->supports_context_api(wc_self, context_api);
return api_platform->vtbl->display.supports_context_api(wc_self,
context_api);
}
union waffle_native_display*
......@@ -110,7 +111,7 @@ waffle_display_get_native(struct waffle_display *self)
if (!api_check_entry(obj_list, 1))
return NULL;
return wc_self->vtbl->get_native(wc_self);
return api_platform->vtbl->display.get_native(wc_self);
}
/// @}
......@@ -53,7 +53,7 @@ waffle_window_create(
if (!api_check_entry(obj_list, 1))
return NULL;
wc_self = api_platform->vtbl->create_window(api_platform,
wc_self = api_platform->vtbl->window.create(api_platform,
wc_config,
width,
height);
......@@ -75,7 +75,7 @@ waffle_window_destroy(struct waffle_window *self)
if (!api_check_entry(obj_list, 1))
return false;
return wc_self->vtbl->destroy(wc_self);
return api_platform->vtbl->window.destroy(wc_self);
}
bool
......@@ -90,7 +90,7 @@ waffle_window_show(struct waffle_window *self)
if (!api_check_entry(obj_list, 1))
return false;
return wc_self->vtbl->show(wc_self);
return api_platform->vtbl->window.show(wc_self);
}
bool
......@@ -105,7 +105,7 @@ waffle_window_swap_buffers(struct waffle_window *self)
if (!api_check_entry(obj_list, 1))
return false;
return wc_self->vtbl->swap_buffers(wc_self);
return api_platform->vtbl->window.swap_buffers(wc_self);
}
union waffle_native_window*
......@@ -120,7 +120,7 @@ waffle_window_get_native(struct waffle_window *self)
if (!api_check_entry(obj_list, 1))
return NULL;
return wc_self->vtbl->get_native(wc_self);
return api_platform->vtbl->window.get_native(wc_self);
}
/// @}
......@@ -35,8 +35,6 @@
#include "cgl_config.h"
#include "cgl_error.h"
static const struct wcore_config_vtbl cgl_config_wcore_vtbl;
bool
cgl_config_destroy(struct wcore_config *wc_self)
{
......@@ -186,7 +184,6 @@ cgl_config_choose(struct wcore_platform *wc_plat,
goto error;
}
self->wcore.vtbl = &cgl_config_wcore_vtbl;
return &self->wcore;
error:
......@@ -200,8 +197,3 @@ cgl_config_get_native(struct wcore_config *wc_self)
wcore_error(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM);
return NULL;
}
static const struct wcore_config_vtbl cgl_config_wcore_vtbl = {
.destroy = cgl_config_destroy,
.get_native = cgl_config_get_native,
};
......@@ -33,8 +33,6 @@
#include "cgl_context.h"
#include "cgl_error.h"
static const struct wcore_context_vtbl cgl_context_wcore_vtbl;
bool
cgl_context_destroy(struct wcore_context *wc_self)
{
......@@ -93,7 +91,6 @@ cgl_context_create(struct wcore_platform *wc_plat,
// The NSOpenGLContext now owns the CGLContext.
CGLReleaseContext(cgl_self);
self->wcore.vtbl = &cgl_context_wcore_vtbl;
return &self->wcore;
fail:
......@@ -107,8 +104,3 @@ cgl_context_get_native(struct wcore_context *wc_self)
wcore_error(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM);
return NULL;
}
static const struct wcore_context_vtbl cgl_context_wcore_vtbl = {
.destroy = cgl_context_destroy,
.get_native = cgl_context_get_native,
};
......@@ -31,8 +31,6 @@
#include "cgl_display.h"
static const struct wcore_display_vtbl cgl_display_wcore_vtbl;
bool
cgl_display_destroy(struct wcore_display *wc_self)
{
......@@ -65,7 +63,6 @@ cgl_display_connect(struct wcore_platform *wc_plat,
if (!ok)
goto error;
self->wcore.vtbl = &cgl_display_wcore_vtbl;
return &self->wcore;
error:
......@@ -97,9 +94,3 @@ cgl_display_get_native(struct wcore_display *wc_self)
wcore_error(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM);
return NULL;
}
static const struct wcore_display_vtbl cgl_display_wcore_vtbl = {
.destroy = cgl_display_destroy,
.get_native = cgl_display_get_native,
.supports_context_api = cgl_display_supports_context_api,
};
......@@ -35,7 +35,7 @@
#include "cgl_window.h"
static const struct wcore_platform_vtbl cgl_platform_wcore_vtbl;
static const struct wcore_platform_vtbl cgl_platform_vtbl;
static bool
cgl_platform_destroy(struct wcore_platform *wc_self)
......@@ -70,7 +70,7 @@ cgl_platform_create(void)
if (!ok)
goto error;
self->wcore.vtbl = &cgl_platform_wcore_vtbl;
self->wcore.vtbl = &cgl_platform_vtbl;
return &self->wcore;
error:
......@@ -109,14 +109,38 @@ cgl_platform_get_proc_address(struct wcore_platform *wc_self,
return NULL;
}
static const struct wcore_platform_vtbl cgl_platform_wcore_vtbl = {
static const struct wcore_platform_vtbl cgl_platform_vtbl = {
.destroy = cgl_platform_destroy,
.connect_to_display = cgl_display_connect,
.choose_config = cgl_config_choose,
.create_context = cgl_context_create,
.create_window = cgl_window_create,
.make_current = cgl_platform_make_current,
.get_proc_address = cgl_platform_get_proc_address,
.dl_can_open = cgl_dl_can_open,
.dl_sym = cgl_dl_sym,
.display = {
.connect = cgl_display_connect,
.destroy = cgl_display_destroy,
.supports_context_api = cgl_display_supports_context_api,
.get_native = cgl_display_get_native,
},
.config = {
.choose = cgl_config_choose,
.destroy = cgl_config_destroy,
.get_native = cgl_config_get_native,
},
.context = {
.create = cgl_context_create,
.destroy = cgl_context_destroy,
.get_native = cgl_context_get_native,
},
.window = {
.create = cgl_window_create,
.destroy = cgl_window_destroy,
.show = cgl_window_show,
.swap_buffers = cgl_window_swap_buffers,
.get_native = cgl_window_get_native,
},
};
......@@ -31,8 +31,6 @@
#include "cgl_config.h"
#include "cgl_window.h"
static const struct wcore_window_vtbl cgl_window_wcore_vtbl;
bool
cgl_window_destroy(struct wcore_window *wc_self)
{
......@@ -119,7 +117,6 @@ cgl_window_create(struct wcore_platform *wc_plat,
if (!self->ns_window)
goto error;
self->wcore.vtbl = &cgl_window_wcore_vtbl;
return &self->wcore;
error:
......@@ -148,10 +145,3 @@ cgl_window_get_native(struct wcore_window *wc_self)
wcore_error(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM);
return NULL;
}
static const struct wcore_window_vtbl cgl_window_wcore_vtbl = {
.destroy = cgl_window_destroy,
.get_native = cgl_window_get_native,
.show = cgl_window_show,
.swap_buffers = cgl_window_swap_buffers,
};
......@@ -39,17 +39,7 @@
struct wcore_config;
union waffle_native_config;
struct wcore_config_vtbl {
bool
(*destroy)(struct wcore_config *self);
union waffle_native_config*
(*get_native)(struct wcore_config *self);
};
struct wcore_config {
const struct wcore_config_vtbl *vtbl;
struct waffle_config {} wfl;
struct api_object api;
......
......@@ -40,14 +40,6 @@ struct wcore_context;
struct wcore_display;
union waffle_native_context;
struct wcore_context_vtbl {
bool
(*destroy)(struct wcore_context *self);
union waffle_native_context*
(*get_native)(struct wcore_context *self);
};
struct wcore_context {
const struct wcore_context_vtbl *vtbl;
......
......@@ -39,22 +39,7 @@ struct wcore_display;
struct wcore_platform;
union waffle_native_display;
struct wcore_display_vtbl {
bool
(*destroy)(struct wcore_display *self);
bool
(*supports_context_api)(
struct wcore_display *self,
int32_t context_api);
union waffle_native_display*
(*get_native)(struct wcore_display *self);
};
struct wcore_display {
const struct wcore_display_vtbl *vtbl;
struct waffle_display {} wfl;
struct api_object api;
......
......@@ -40,30 +40,6 @@ struct wcore_platform_vtbl {
bool
(*destroy)(struct wcore_platform *self);
struct wcore_display*
(*connect_to_display)(
struct wcore_platform *self,
const char *name);
struct wcore_config*
(*choose_config)(
struct wcore_platform *self,
struct wcore_display *dpy,
const struct wcore_config_attrs *attrs);
struct wcore_context*
(*create_context)(
struct wcore_platform *self,
struct wcore_config *config,
struct wcore_context *share_ctx);
struct wcore_window*
(*create_window)(
struct wcore_platform *self,
struct wcore_config *config,
int width,
int height);
bool
(*make_current)(
struct wcore_platform *self,
......@@ -86,6 +62,68 @@ struct wcore_platform_vtbl {
struct wcore_platform *self,
int32_t waffle_dl,
const char *symbol);
struct wcore_display_vtbl {
struct wcore_display*
(*connect)(struct wcore_platform *platform,
const char *name);
bool
(*destroy)(struct wcore_display *self);
bool
(*supports_context_api)(
struct wcore_display *display,
int32_t context_api);
union waffle_native_display*
(*get_native)(struct wcore_display *display);
} display;
struct wcore_config_vtbl {
struct wcore_config*
(*choose)(struct wcore_platform *platform,
struct wcore_display *display,
const struct wcore_config_attrs *attrs);
bool
(*destroy)(struct wcore_config *config);
union waffle_native_config*
(*get_native)(struct wcore_config *config);
} config;
struct wcore_context_vtbl {
struct wcore_context*
(*create)(struct wcore_platform *platform,
struct wcore_config *config,
struct wcore_context *share_ctx);
bool
(*destroy)(struct wcore_context *ctx);
union waffle_native_context*
(*get_native)(struct wcore_context *ctx);
} context;
struct wcore_window_vtbl {
struct wcore_window*
(*create)(struct wcore_platform *platform,
struct wcore_config *config,
int width,
int height);
bool
(*destroy)(struct wcore_window *window);
bool
(*show)(struct wcore_window *window);
bool
(*swap_buffers)(struct wcore_window *window);
union waffle_native_window*
(*get_native)(struct wcore_window *window);
} window;
};
struct wcore_platform {
......
......@@ -36,23 +36,7 @@
struct wcore_window;
union waffle_native_window;
struct wcore_window_vtbl {
bool
(*destroy)(struct wcore_window *self);
bool
(*show)(struct wcore_window *self);
bool
(*swap_buffers)(struct wcore_window *self);
union waffle_native_window*
(*get_native)(struct wcore_window *self);
};
struct wcore_window {
const struct wcore_window_vtbl *vtbl;
struct waffle_window {} wfl;
struct api_object api;
......
......@@ -38,8 +38,6 @@
#include "wgbm_platform.h"
#include "wgbm_priv_egl.h"
static const struct wcore_config_vtbl wgbm_config_wcore_vtbl;
bool
wgbm_config_destroy(struct wcore_config *wc_self)
{
......@@ -103,7 +101,6 @@ wgbm_config_choose(struct wcore_platform *wc_plat,
goto error;
self->waffle_context_api = attrs->context_api;
self->wcore.vtbl = &wgbm_config_wcore_vtbl;
return &self->wcore;
error:
......@@ -127,8 +124,3 @@ wgbm_config_get_native(struct wcore_config *wc_self)
return n_config;
}
static const struct wcore_config_vtbl wgbm_config_wcore_vtbl = {
.destroy = wgbm_config_destroy,
.get_native = wgbm_config_get_native,
};
......@@ -35,8 +35,6 @@
#include "wgbm_display.h"
#include "wgbm_priv_egl.h"
static const struct wcore_context_vtbl wgbm_context_wcore_vtbl;
bool
wgbm_context_destroy(struct wcore_context *wc_self)
{
......@@ -83,7 +81,6 @@ wgbm_context_create(struct wcore_platform *wc_plat,
if (!self->egl)
goto error;
self->wcore.vtbl = &wgbm_context_wcore_vtbl;
return &self->wcore;
error:
......@@ -107,8 +104,3 @@ wgbm_context_get_native(struct wcore_context *wc_self)
return n_ctx;
}
static const struct wcore_context_vtbl wgbm_context_wcore_vtbl = {
.destroy = wgbm_context_destroy,
.get_native = wgbm_context_get_native,
};
......@@ -43,8 +43,6 @@
#include "wgbm_platform.h"
#include "wgbm_priv_egl.h"
static const struct wcore_display_vtbl wgbm_display_wcore_vtbl;
bool
wgbm_display_destroy(struct wcore_display *wc_self)
{
......@@ -136,7 +134,6 @@ wgbm_display_connect(struct wcore_platform *wc_plat,
if (!self->egl)
goto error;
self->wcore.vtbl = &wgbm_display_wcore_vtbl;
return &self->wcore;
error:
......@@ -174,9 +171,3 @@ wgbm_display_get_native(struct wcore_display *wc_self)
return n_dpy;
}
static const struct wcore_display_vtbl wgbm_display_wcore_vtbl = {
.destroy = wgbm_display_destroy,
.get_native = wgbm_display_get_native,
.supports_context_api = wgbm_display_supports_context_api,
};
......@@ -38,7 +38,7 @@
#include "wgbm_priv_egl.h"
#include "wgbm_window.h"
static const struct wcore_platform_vtbl wgbm_platform_wcore_vtbl;
static const struct wcore_platform_vtbl wgbm_platform_vtbl;
static bool
wgbm_platform_destroy(struct wcore_platform *wc_self)
......@@ -79,7 +79,7 @@ wgbm_platform_create(void)
setenv("EGL_PLATFORM", "drm", true);