summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChad Versace <chad.versace@intel.com>2015-01-27 09:36:52 -0800
committerChad Versace <chad.versace@intel.com>2015-01-27 09:36:52 -0800
commit6866728a4d95f6640810b07a44cafdfb22c3038a (patch)
tree6eebad4e5dbe3c2ff8a2a78ea421c74c6deaa809
parenta72df8ffc5c2c2d99642a9a0311cbd96c5c5c1af (diff)
parentaa89036b413b88a0015cf92a583565df0ea30f11 (diff)
Merge branch 'chadv/waffle_window_create2' into master
* waffle_window_create2: examples/gl_basic: Update to use waffle_window_create2() tests/gl_basic: Update to use waffle_window_create2() waffle: Add public func waffle_window_create2() core: Add func wcore_attrib_list_pop() core: Add func wcore_attrib_list_copy() core: Add attrib_list param to func wcore_platform::window::create core: Add func wcore_error_bad_attribute waffle: Fix signature of wcore_platform::window::create() waffle: Fix mismatch in waffle_window_create prototype core: Add func wcore_attrib_list_from_int32 core: Add arithmetic functions that detect overflow core: Define intptr_t variants of wcore_attrib_list functions core: Define wcore_attrib_list funcs with type-generic template core: Change return type of wcore_attrib_list32_length core: Rename functions s/wcore_attrib_list/wcore_attrib_list32/ include: Deprecate waffle_attrib_list funcs include: Define macro WAFFLE_DEPRECATED_1_06
-rw-r--r--examples/gl_basic.c13
-rw-r--r--include/waffle/waffle.h36
-rw-r--r--man/waffle_attrib_list.3.xml14
-rw-r--r--man/waffle_enum.3.xml7
-rw-r--r--man/waffle_window.3.xml27
-rw-r--r--src/waffle/android/droid_window.c10
-rw-r--r--src/waffle/android/droid_window.h4
-rw-r--r--src/waffle/api/waffle_attrib_list.c8
-rw-r--r--src/waffle/api/waffle_window.c76
-rw-r--r--src/waffle/cgl/cgl_window.h5
-rw-r--r--src/waffle/cgl/cgl_window.m13
-rw-r--r--src/waffle/core/wcore_attrib_list.c237
-rw-r--r--src/waffle/core/wcore_attrib_list.h45
-rw-r--r--src/waffle/core/wcore_attrib_list_unittest.c112
-rw-r--r--src/waffle/core/wcore_config_attrs.c10
-rw-r--r--src/waffle/core/wcore_error.c8
-rw-r--r--src/waffle/core/wcore_error.h4
-rw-r--r--src/waffle/core/wcore_platform.h5
-rw-r--r--src/waffle/core/wcore_util.c24
-rw-r--r--src/waffle/core/wcore_util.h27
-rw-r--r--src/waffle/gbm/wgbm_window.c11
-rw-r--r--src/waffle/gbm/wgbm_window.h5
-rw-r--r--src/waffle/glx/glx_window.c11
-rw-r--r--src/waffle/glx/glx_window.h5
-rw-r--r--src/waffle/waffle.def.in1
-rw-r--r--src/waffle/wayland/wayland_window.c11
-rw-r--r--src/waffle/wayland/wayland_window.h5
-rw-r--r--src/waffle/wgl/wgl_window.c15
-rw-r--r--src/waffle/wgl/wgl_window.h9
-rw-r--r--src/waffle/x11/x11_window.c4
-rw-r--r--src/waffle/x11/x11_window.h4
-rw-r--r--src/waffle/xegl/xegl_window.c11
-rw-r--r--src/waffle/xegl/xegl_window.h5
-rw-r--r--tests/functional/gl_basic_test.c9
34 files changed, 616 insertions, 175 deletions
diff --git a/examples/gl_basic.c b/examples/gl_basic.c
index 69418c8..77bb1dc 100644
--- a/examples/gl_basic.c
+++ b/examples/gl_basic.c
@@ -34,7 +34,7 @@
/// each buffer swap.
#define _POSIX_C_SOURCE 199309L // glibc feature macro for nanosleep.
-#define WAFFLE_API_VERSION 0x0103
+#define WAFFLE_API_VERSION 0x0106
#define WAFFLE_API_EXPERIMENTAL
#include <getopt.h>
@@ -530,6 +530,7 @@ main(int argc, char **argv)
int32_t init_attrib_list[3];
int32_t config_attrib_list[64];
+ intptr_t window_attrib_list[5];
struct waffle_display *dpy;
struct waffle_config *config;
@@ -628,7 +629,15 @@ main(int argc, char **argv)
if (!ctx)
error_waffle();
- window = waffle_window_create(config, window_width, window_height);
+
+ i = 0;
+ window_attrib_list[i++] = WAFFLE_WINDOW_WIDTH;
+ window_attrib_list[i++] = window_width;
+ window_attrib_list[i++] = WAFFLE_WINDOW_HEIGHT;
+ window_attrib_list[i++] = window_height;
+ window_attrib_list[i++] = 0;
+
+ window = waffle_window_create2(config, window_attrib_list);
if (!window)
error_waffle();
diff --git a/include/waffle/waffle.h b/include/waffle/waffle.h
index 77885a4..80cb793 100644
--- a/include/waffle/waffle.h
+++ b/include/waffle/waffle.h
@@ -36,6 +36,20 @@
extern "C" {
#endif
+#if defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 301)
+# define WAFFLE_DEPRECATED __attribute__((deprecated))
+#elif defined(_MSC_VER)
+# define WAFFLE_DEPRECATED __declspec(deprecated)
+#else
+# define WAFFLE_DEPRECATED
+#endif
+
+#if WAFFLE_API_VERSION >= 0x0106
+# define WAFFLE_DEPRECATED_1_06 WAFFLE_DEPRECATED
+#else
+# define WAFFLE_DEPRECATED_1_06
+#endif
+
struct waffle_display;
struct waffle_config;
struct waffle_context;
@@ -151,6 +165,13 @@ enum waffle_enum {
WAFFLE_DL_OPENGL_ES1 = 0x0302,
WAFFLE_DL_OPENGL_ES2 = 0x0303,
WAFFLE_DL_OPENGL_ES3 = 0x0304,
+
+ // ------------------------------------------------------------------
+ // For waffle_window
+ // ------------------------------------------------------------------
+
+ WAFFLE_WINDOW_WIDTH = 0x0310,
+ WAFFLE_WINDOW_HEIGHT = 0x0311,
};
const char*
@@ -222,6 +243,13 @@ waffle_context_get_native(struct waffle_context *self);
// waffle_window
// ---------------------------------------------------------------------------
+#if WAFFLE_API_VERSION >= 0x0106
+struct waffle_window*
+waffle_window_create2(
+ struct waffle_config *config,
+ const intptr_t attrib_list[]);
+#endif
+
struct waffle_window*
waffle_window_create(
struct waffle_config *config,
@@ -311,23 +339,23 @@ union waffle_native_window {
// waffle_attrib_list
// ---------------------------------------------------------------------------
-int32_t
+WAFFLE_DEPRECATED_1_06 int32_t
waffle_attrib_list_length(const int32_t attrib_list[]);
-bool
+WAFFLE_DEPRECATED_1_06 bool
waffle_attrib_list_get(
const int32_t attrib_list[],
int32_t key,
int32_t *value);
-bool
+WAFFLE_DEPRECATED_1_06 bool
waffle_attrib_list_get_with_default(
const int32_t attrib_list[],
int32_t key,
int32_t *value,
int32_t default_value);
-bool
+WAFFLE_DEPRECATED_1_06 bool
waffle_attrib_list_update(
int32_t *attrib_list,
int32_t key,
diff --git a/man/waffle_attrib_list.3.xml b/man/waffle_attrib_list.3.xml
index 9b390ba..277fe26 100644
--- a/man/waffle_attrib_list.3.xml
+++ b/man/waffle_attrib_list.3.xml
@@ -44,19 +44,19 @@
<funcsynopsisinfo>#include &lt;waffle.h&gt;</funcsynopsisinfo>
<funcprototype>
- <funcdef>bool <function>waffle_attrib_list_length</function></funcdef>
+ <funcdef>DEPRECATED bool <function>waffle_attrib_list_length</function></funcdef>
<paramdef>const int32_t <parameter>attrib_list</parameter>[]</paramdef>
</funcprototype>
<funcprototype>
- <funcdef>bool <function>waffle_attrib_list_get</function></funcdef>
+ <funcdef>DEPRECATED bool <function>waffle_attrib_list_get</function></funcdef>
<paramdef>const int32_t <parameter>attrib_list</parameter>[]</paramdef>
<paramdef>int32_t <parameter>key</parameter></paramdef>
<paramdef>int32_t *<parameter>value</parameter></paramdef>
</funcprototype>
<funcprototype>
- <funcdef>bool <function>waffle_attrib_list_get_with_default</function></funcdef>
+ <funcdef>DEPRECATED bool <function>waffle_attrib_list_get_with_default</function></funcdef>
<paramdef>const int32_t <parameter>attrib_list</parameter>[]</paramdef>
<paramdef>int32_t <parameter>key</parameter></paramdef>
<paramdef>int32_t *<parameter>value</parameter></paramdef>
@@ -64,13 +64,19 @@
</funcprototype>
<funcprototype>
- <funcdef>bool <function>waffle_attrib_list_update</function></funcdef>
+ <funcdef>DEPRECATED bool <function>waffle_attrib_list_update</function></funcdef>
<paramdef>int32_t <parameter>attrib_list</parameter>[]</paramdef>
<paramdef>int32_t <parameter>key</parameter></paramdef>
<paramdef>int32_t *<parameter>value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
+
+ <refsect2>
+ <title>Deprecation</title>
+ <para>All functions above are deprecated in Waffle 1.6 and later.</para>
+ </refsect2>
+
</refsynopsisdiv>
<refsect1>
diff --git a/man/waffle_enum.3.xml b/man/waffle_enum.3.xml
index 07edd6c..4874fe7 100644
--- a/man/waffle_enum.3.xml
+++ b/man/waffle_enum.3.xml
@@ -142,6 +142,13 @@ enum waffle_enum {
WAFFLE_DL_OPENGL = 0x0301,
WAFFLE_DL_OPENGL_ES1 = 0x0302,
WAFFLE_DL_OPENGL_ES2 = 0x0303,
+
+ // ------------------------------------------------------------------
+ // For waffle_window
+ // ------------------------------------------------------------------
+
+ WAFFLE_WINDOW_WIDTH = 0x0310,
+ WAFFLE_WINDOW_HEIGHT = 0x0311,
};
]]>
</programlisting>
diff --git a/man/waffle_window.3.xml b/man/waffle_window.3.xml
index de046fa..795152a 100644
--- a/man/waffle_window.3.xml
+++ b/man/waffle_window.3.xml
@@ -56,6 +56,12 @@ struct waffle_window;
</funcprototype>
<funcprototype>
+ <funcdef>struct waffle_window* <function>waffle_window_create2</function></funcdef>
+ <paramdef>struct waffle_window *<parameter>config</parameter></paramdef>
+ <paramdef>const intptr_t <parameter>attrib_list</parameter>[]</paramdef>
+ </funcprototype>
+
+ <funcprototype>
<funcdef>bool <function>waffle_window_destroy</function></funcdef>
<paramdef>struct waffle_window *<parameter>self</parameter></paramdef>
</funcprototype>
@@ -104,6 +110,27 @@ struct waffle_window;
</varlistentry>
<varlistentry>
+ <term><function>waffle_window_create2()</function></term>
+ <listitem>
+ <para>
+ Feature test macro: <code>WAFFLE_API_VERSION >= 0x0106</code>.
+ (See <citerefentry><refentrytitle>waffle_feature_test_macros</refentrytitle><manvolnum>7</manvolnum></citerefentry>).
+ </para>
+ <para>
+ Create a window with the properties specified by
+ <parameter>config</parameter> and
+ <parameter>attrib_list</parameter>.
+
+ <parameter>attrib_list</parameter> must contain the attributes
+ <constant>WAFFLE_WINDOW_WIDTH</constant> and
+ <constant>WAFFLE_WINDOW_HEIGHT</constant>,
+ whose values must be positive
+ and no greater than <constant>INT32_MAX</constant>.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
<term><function>waffle_window_destroy()</function></term>
<listitem>
<para>
diff --git a/src/waffle/android/droid_window.c b/src/waffle/android/droid_window.c
index a9e6f9b..20a566f 100644
--- a/src/waffle/android/droid_window.c
+++ b/src/waffle/android/droid_window.c
@@ -26,6 +26,7 @@
#include <stdlib.h>
#include <string.h>
+#include "wcore_attrib_list.h"
#include "wcore_error.h"
#include "wegl_config.h"
@@ -37,14 +38,19 @@
struct wcore_window*
droid_window_create(struct wcore_platform *wc_plat,
struct wcore_config *wc_config,
- int width,
- int height)
+ int32_t width,
+ int32_t height,
+ const intptr_t attrib_list[])
{
struct droid_window *self;
struct wegl_config *config = wegl_config(wc_config);
struct droid_display *dpy = droid_display(wc_config->display);
bool ok = true;
+ if (wcore_attrib_list_length(attrib_list) > 0) {
+ wcore_error_bad_attribute(attrib_list[0]);
+ }
+
self = wcore_calloc(sizeof(*self));
if (self == NULL)
return NULL;
diff --git a/src/waffle/android/droid_window.h b/src/waffle/android/droid_window.h
index 85064cd..b4288d0 100644
--- a/src/waffle/android/droid_window.h
+++ b/src/waffle/android/droid_window.h
@@ -51,8 +51,8 @@ droid_window(struct wcore_window *wc_self)
struct wcore_window*
droid_window_create(struct wcore_platform *wc_plat,
struct wcore_config *wc_config,
- int width,
- int height);
+ int32_t width,
+ int32_t height);
bool
droid_window_destroy(struct wcore_window *wc_self);
diff --git a/src/waffle/api/waffle_attrib_list.c b/src/waffle/api/waffle_attrib_list.c
index 94327bb..8ddfa9f 100644
--- a/src/waffle/api/waffle_attrib_list.c
+++ b/src/waffle/api/waffle_attrib_list.c
@@ -33,7 +33,7 @@ waffle_attrib_list_length(const int32_t attrib_list[])
{
wcore_error_reset();
- return wcore_attrib_list_length(attrib_list);
+ return wcore_attrib_list32_length(attrib_list);
}
WAFFLE_API bool
@@ -43,7 +43,7 @@ waffle_attrib_list_get(
int32_t *value)
{
wcore_error_reset();
- return wcore_attrib_list_get(attrib_list, key, value);
+ return wcore_attrib_list32_get(attrib_list, key, value);
}
WAFFLE_API bool
@@ -54,7 +54,7 @@ waffle_attrib_list_get_with_default(
int32_t default_value)
{
wcore_error_reset();
- return wcore_attrib_list_get_with_default(attrib_list, key, value,
+ return wcore_attrib_list32_get_with_default(attrib_list, key, value,
default_value);
}
@@ -65,5 +65,5 @@ waffle_attrib_list_update(
int32_t value)
{
wcore_error_reset();
- return wcore_attrib_list_update(attrib_list, key, value);
+ return wcore_attrib_list32_update(attrib_list, key, value);
}
diff --git a/src/waffle/api/waffle_window.c b/src/waffle/api/waffle_window.c
index 81f95f8..9ab63ca 100644
--- a/src/waffle/api/waffle_window.c
+++ b/src/waffle/api/waffle_window.c
@@ -27,36 +27,96 @@
#include "api_priv.h"
+#include "wcore_attrib_list.h"
#include "wcore_config.h"
#include "wcore_error.h"
#include "wcore_platform.h"
#include "wcore_window.h"
WAFFLE_API struct waffle_window*
-waffle_window_create(
+waffle_window_create2(
struct waffle_config *config,
- int width, int height)
+ const intptr_t attrib_list[])
{
- struct wcore_window *wc_self;
+ struct wcore_window *wc_self = NULL;
struct wcore_config *wc_config = wcore_config(config);
+ intptr_t *attrib_list_filtered = NULL;
+ intptr_t width = 0, height = 0;
const struct api_object *obj_list[] = {
wc_config ? &wc_config->api : NULL,
};
- if (!api_check_entry(obj_list, 1))
- return NULL;
+ if (!api_check_entry(obj_list, 1)) {
+ goto done;
+ }
+
+ attrib_list_filtered = wcore_attrib_list_copy(attrib_list);
+
+ if (!wcore_attrib_list_pop(attrib_list_filtered,
+ WAFFLE_WINDOW_WIDTH, &width)) {
+ wcore_errorf(WAFFLE_ERROR_BAD_ATTRIBUTE,
+ "required attribute WAFFLE_WINDOW_WIDTH is missing");
+ goto done;
+ }
+
+ if (!wcore_attrib_list_pop(attrib_list_filtered,
+ WAFFLE_WINDOW_HEIGHT, &height)) {
+ wcore_errorf(WAFFLE_ERROR_BAD_ATTRIBUTE,
+ "required attribute WAFFLE_WINDOW_HEIGHT is missing");
+ goto done;
+ }
+
+ if (width <= 0) {
+ wcore_errorf(WAFFLE_ERROR_BAD_ATTRIBUTE,
+ "WAFFLE_WINDOW_WIDTH is not positive");
+ goto done;
+ } else if (width > INT32_MAX) {
+ wcore_errorf(WAFFLE_ERROR_BAD_ATTRIBUTE,
+ "WAFFLE_WINDOW_WIDTH is greater than INT32_MAX");
+ goto done;
+ }
+
+ if (height <= 0) {
+ wcore_errorf(WAFFLE_ERROR_BAD_ATTRIBUTE,
+ "WAFFLE_WINDOW_HEIGHT is not positive");
+ goto done;
+ } else if (height > INT32_MAX) {
+ wcore_errorf(WAFFLE_ERROR_BAD_ATTRIBUTE,
+ "WAFFLE_WINDOW_HEIGHT is greater than INT32_MAX");
+ goto done;
+ }
wc_self = api_platform->vtbl->window.create(api_platform,
wc_config,
- width,
- height);
- if (!wc_self)
+ (int32_t) width,
+ (int32_t) height,
+ attrib_list_filtered);
+
+done:
+ free(attrib_list_filtered);
+
+ if (!wc_self) {
return NULL;
+ }
return waffle_window(wc_self);
}
+WAFFLE_API struct waffle_window*
+waffle_window_create(
+ struct waffle_config *config,
+ int32_t width, int32_t height)
+{
+ const intptr_t attrib_list[] = {
+ WAFFLE_WINDOW_WIDTH, width,
+ WAFFLE_WINDOW_HEIGHT, height,
+ 0,
+ };
+
+ return waffle_window_create2(config, attrib_list);
+}
+
WAFFLE_API bool
waffle_window_destroy(struct waffle_window *self)
{
diff --git a/src/waffle/cgl/cgl_window.h b/src/waffle/cgl/cgl_window.h
index 4038e09..b565d58 100644
--- a/src/waffle/cgl/cgl_window.h
+++ b/src/waffle/cgl/cgl_window.h
@@ -48,8 +48,9 @@ DEFINE_CONTAINER_CAST_FUNC(cgl_window,
struct wcore_window*
cgl_window_create(struct wcore_platform *wc_plat,
struct wcore_config *wc_config,
- int width,
- int height);
+ int32_t width,
+ int32_t height,
+ const intptr_t attrib_list[]);
bool
cgl_window_destroy(struct wcore_window *wc_self);
diff --git a/src/waffle/cgl/cgl_window.m b/src/waffle/cgl/cgl_window.m
index e4711e1..5ff1ec7 100644
--- a/src/waffle/cgl/cgl_window.m
+++ b/src/waffle/cgl/cgl_window.m
@@ -26,6 +26,7 @@
#import <Cocoa/Cocoa.h>
#import <OpenGL/OpenGL.h>
+#include "wcore_attrib_list.h"
#include "wcore_error.h"
#include "cgl_config.h"
@@ -53,7 +54,7 @@ cgl_window_destroy(struct wcore_window *wc_self)
static WaffleGLView*
-cgl_window_create_gl_view(int width, int height)
+cgl_window_create_gl_view(int32_t width, int32_t height)
{
WaffleGLView *view = [[WaffleGLView alloc]
initWithFrame:NSMakeRect(0, 0, width, height)];
@@ -94,12 +95,18 @@ cgl_window_create_ns_window(NSView *view)
struct wcore_window*
cgl_window_create(struct wcore_platform *wc_plat,
struct wcore_config *wc_config,
- int width,
- int height)
+ int32_t width,
+ int32_t height,
+ const intptr_t attrib_list[])
{
struct cgl_window *self;
bool ok = true;
+ if (wcore_attrib_list_length(attrib_list) > 0) {
+ wcore_error_bad_attribute(attrib_list[0]);
+ return NULL;
+ }
+
self = wcore_calloc(sizeof(*self));
if (!self)
return NULL;
diff --git a/src/waffle/core/wcore_attrib_list.c b/src/waffle/core/wcore_attrib_list.c
index 48d4b33..985e13a 100644
--- a/src/waffle/core/wcore_attrib_list.c
+++ b/src/waffle/core/wcore_attrib_list.c
@@ -28,76 +28,219 @@
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
+#include <string.h>
-int32_t
-wcore_attrib_list_length(const int32_t attrib_list[])
-{
- const int32_t *i = attrib_list;
+#include "wcore_error.h"
+#include "wcore_util.h"
+
+#define WCORE_ATTRIB_LIST_COMMON_FUNCS(T, \
+ length_func, \
+ get_func, \
+ get_with_default_func, \
+ update_func) \
+ \
+ size_t \
+ length_func(const T attrib_list[]) \
+ { \
+ const T *i = attrib_list; \
+ \
+ if (!attrib_list) { \
+ return 0; \
+ } \
+ \
+ while (*i) { \
+ i += 2; \
+ } \
+ \
+ return (i - attrib_list) / 2; \
+ } \
+ \
+ bool \
+ get_func(const T *attrib_list, \
+ T key, \
+ T *value) \
+ { \
+ if (!attrib_list) { \
+ return false; \
+ } \
+ \
+ for (size_t i = 0; attrib_list[i] != 0; i += 2) { \
+ if (attrib_list[i] == key) { \
+ *value = attrib_list[i + 1]; \
+ return true; \
+ } \
+ } \
+ \
+ return false; \
+ } \
+ \
+ bool \
+ get_with_default_func( \
+ const T attrib_list[], \
+ T key, \
+ T *value, \
+ T default_value) \
+ { \
+ if (get_func(attrib_list, key, value)) { \
+ return true; \
+ } else { \
+ *value = default_value; \
+ return false; \
+ } \
+ } \
+ \
+ bool \
+ update_func(T *attrib_list, \
+ T key, \
+ T value) \
+ { \
+ T *i = attrib_list; \
+ \
+ if (attrib_list == NULL) { \
+ return false; \
+ } \
+ \
+ while (*i != 0 && *i != key) { \
+ i += 2; \
+ } \
+ \
+ if (*i == key) { \
+ i[1] = value; \
+ return true; \
+ } else { \
+ return false; \
+ } \
+ }
+
+WCORE_ATTRIB_LIST_COMMON_FUNCS(int32_t,
+ wcore_attrib_list32_length,
+ wcore_attrib_list32_get,
+ wcore_attrib_list32_get_with_default,
+ wcore_attrib_list32_update)
- if (attrib_list == NULL)
- return 0;
+WCORE_ATTRIB_LIST_COMMON_FUNCS(intptr_t,
+ wcore_attrib_list_length,
+ wcore_attrib_list_get,
+ wcore_attrib_list_get_with_default,
+ wcore_attrib_list_update)
- while (*i != 0)
- i += 2;
+/// Given length of attribute list, calculate its size in bytes. Return false
+/// on arithemtic overflow.
+static bool
+wcore_attrib_list_get_size(size_t *size, size_t len) {
+ bool ok;
- return (int32_t) (i - attrib_list) / 2;
+ ok = wcore_mul_size(size, 2, len);
+ ok &= wcore_iadd_size(size, 1);
+ ok &= wcore_imul_size(size, sizeof(intptr_t));
+
+ return ok;
}
-bool
-wcore_attrib_list_get(
- const int32_t *attrib_list,
- int32_t key,
- int32_t *value)
+intptr_t*
+wcore_attrib_list_from_int32(const int32_t attrib_list32[])
{
- if (attrib_list == NULL)
- return false;
+ size_t len = 0;
+ size_t size = 0;
+ intptr_t *attrib_list = NULL;
- for (int i = 0; attrib_list[i] != 0; i += 2) {
- if (attrib_list[i] != key)
- continue;
+ len = wcore_attrib_list32_length(attrib_list32);
- *value = attrib_list[i + 1];
- return true;
+ if (!wcore_attrib_list_get_size(&size, len)) {
+ // Arithmetic overflow occurred, therefore we can't allocate the
+ // memory.
+ wcore_error(WAFFLE_ERROR_BAD_ALLOC);
+ return NULL;
}
- return false;
+ attrib_list = wcore_malloc(size);
+ if (!attrib_list) {
+ return NULL;
+ }
+
+ // Copy all key/value pairs.
+ for (size_t i = 0; i < 2 * len; ++i) {
+ attrib_list[i] = attrib_list32[i];
+ }
+
+ // Add terminal null.
+ attrib_list[2 * len] = 0;
+
+ return attrib_list;
}
-bool
-wcore_attrib_list_get_with_default(
- const int32_t attrib_list[],
- int32_t key,
- int32_t *value,
- int32_t default_value)
+intptr_t*
+wcore_attrib_list_copy(const intptr_t attrib_list[])
{
- if (wcore_attrib_list_get(attrib_list, key, value)) {
- return true;
- }
- else {
- *value = default_value;
- return false;
+ intptr_t *copy = NULL;
+
+ if (attrib_list) {
+ size_t len;
+ size_t size = 0;
+
+ len = wcore_attrib_list_length(attrib_list);
+
+ if (!wcore_attrib_list_get_size(&size, len)) {
+ // Arithmetic overflow occurred, therefore we can't allocate the
+ // memory.
+ wcore_error(WAFFLE_ERROR_BAD_ALLOC);
+ return NULL;
+ }
+
+ copy = wcore_malloc(size);
+ if (!copy) {
+ return NULL;
+ }
+
+ memcpy(copy, attrib_list, size);
+ } else {
+ copy = wcore_malloc(sizeof(intptr_t));
+ if (!copy) {
+ return NULL;
+ }
+
+ copy[0] = 0;
}
+
+ return copy;
}
bool
-wcore_attrib_list_update(
- int32_t *attrib_list,
- int32_t key,
- int32_t value)
+wcore_attrib_list_pop(
+ intptr_t attrib_list[],
+ intptr_t key,
+ intptr_t *value)
{
- int32_t *i = attrib_list;
+ // Address of key in attrib_list.
+ intptr_t *key_addr = NULL;
- if (attrib_list == NULL)
- return false;
+ // Address of the terminal zero in attrib_list.
+ intptr_t *end_addr = NULL;
- while (*i != 0 && *i != key)
- i += 2;
+ if (attrib_list == NULL) {
+ return false;
+ }
- if (*i == key) {
- i[1] = value;
- return true;
+ for (intptr_t *i = attrib_list; *i != 0; i += 2) {
+ if (i[0] == key) {
+ key_addr = i;
+ *value = i[1];
+ break;
+ }
}
- else {
+
+ if (!key_addr) {
return false;
}
+
+ end_addr = key_addr + 2; // Step to next pair.
+ while (*end_addr != 0) {
+ end_addr += 2; // Step to next pair.
+ }
+
+ // Move all key/value pairs located at or above (key_addr + 2), and
+ // move the terminal null too.
+ memmove(key_addr, key_addr + 2,
+ sizeof(intptr_t) * (end_addr - key_addr - 1));
+ return true;
}
diff --git a/src/waffle/core/wcore_attrib_list.h b/src/waffle/core/wcore_attrib_list.h
index 30d2096..561fb1d 100644
--- a/src/waffle/core/wcore_attrib_list.h
+++ b/src/waffle/core/wcore_attrib_list.h
@@ -26,26 +26,63 @@
#pragma once
#include <stdbool.h>
+#include <stddef.h>
#include <stdint.h>
+#include <stdlib.h>
-int32_t
-wcore_attrib_list_length(const int32_t attrib_list[]);
+/// @brief Convert int32_t attribute list to an intptr_t attribute list.
+intptr_t*
+wcore_attrib_list_from_int32(const int32_t attrib_list[]);
+
+size_t
+wcore_attrib_list_length(const intptr_t attrib_list[]);
+
+intptr_t*
+wcore_attrib_list_copy(const intptr_t attrib_list[]);
bool
wcore_attrib_list_get(
+ const intptr_t *attrib_list,
+ intptr_t key,
+ intptr_t *value);
+
+bool
+wcore_attrib_list_get_with_default(
+ const intptr_t attrib_list[],
+ intptr_t key,
+ intptr_t *value,
+ intptr_t default_value);
+
+bool
+wcore_attrib_list_pop(
+ intptr_t attrib_list[],
+ intptr_t key,
+ intptr_t *value);
+
+bool
+wcore_attrib_list_update(
+ intptr_t *attrib_list,
+ intptr_t key,
+ intptr_t value);
+
+size_t
+wcore_attrib_list32_length(const int32_t attrib_list[]);
+
+bool
+wcore_attrib_list32_get(
const int32_t *attrib_list,
int32_t key,
int32_t *value);
bool
-wcore_attrib_list_get_with_default(
+wcore_attrib_list32_get_with_default(
const int32_t attrib_list[],
int32_t key,
int32_t *value,
int32_t default_value);
bool
-wcore_attrib_list_update(
+wcore_attrib_list32_update(
int32_t *attrib_list,
int32_t key,
int32_t value);
diff --git a/src/waffle/core/wcore_attrib_list_unittest.c b/src/waffle/core/wcore_attrib_list_unittest.c
index 4c8e371..2eb95f2 100644
--- a/src/waffle/core/wcore_attrib_list_unittest.c
+++ b/src/waffle/core/wcore_attrib_list_unittest.c
@@ -33,25 +33,25 @@
#include "wcore_attrib_list.h"
static void
-test_wcore_attrib_list_get_null(void **state) {
+test_wcore_attrib_list32_get_null(void **state) {
int32_t *attrib_list = NULL;
int32_t key = 0;
int32_t value;
- assert_false(wcore_attrib_list_get(attrib_list, key, &value));
+ assert_false(wcore_attrib_list32_get(attrib_list, key, &value));
}
static void
-test_wcore_attrib_list_get_empty(void **state) {
+test_wcore_attrib_list32_get_empty(void **state) {
int32_t attrib_list[] = { 0 };
int32_t key = 0;
int32_t value;
- assert_false(wcore_attrib_list_get(attrib_list, key, &value));
+ assert_false(wcore_attrib_list32_get(attrib_list, key, &value));
}
static void
-test_wcore_attrib_list_get_missing_value(void **state) {
+test_wcore_attrib_list32_get_missing_value(void **state) {
int32_t attrib_list[] = {
1, 11,
0,
@@ -59,11 +59,11 @@ test_wcore_attrib_list_get_missing_value(void **state) {
int32_t key = 2;
int32_t value;
- assert_false(wcore_attrib_list_get(attrib_list, key, &value));
+ assert_false(wcore_attrib_list32_get(attrib_list, key, &value));
}
static void
-test_wcore_attrib_list_get_trailing_items(void **state) {
+test_wcore_attrib_list32_get_trailing_items(void **state) {
int32_t attrib_list[] = {
1, 11,
0,
@@ -72,23 +72,23 @@ test_wcore_attrib_list_get_trailing_items(void **state) {
int32_t key = 2;
int32_t value;
- assert_false(wcore_attrib_list_get(attrib_list, key, &value));
+ assert_false(wcore_attrib_list32_get(attrib_list, key, &value));
}
static void
-test_wcore_attrib_list_get_value_not_modified_if_not_found(void **state) {
+test_wcore_attrib_list32_get_value_not_modified_if_not_found(void **state) {
int32_t attrib_list[] = {
1, 11,
0,
};
int32_t value = 17;
- assert_false(wcore_attrib_list_get(attrib_list, 2, &value));
+ assert_false(wcore_attrib_list32_get(attrib_list, 2, &value));
assert_int_equal(value, 17);
}
static void
-test_wcore_attrib_list_get_key_is_first(void **state) {
+test_wcore_attrib_list32_get_key_is_first(void **state) {
int32_t attrib_list[] = {
1, 11,
2, 22,
@@ -98,12 +98,12 @@ test_wcore_attrib_list_get_key_is_first(void **state) {
int32_t key = 1;
int32_t value;
- assert_true(wcore_attrib_list_get(attrib_list, key, &value));
+ assert_true(wcore_attrib_list32_get(attrib_list, key, &value));
assert_int_equal(value, 11);
}
static void
-test_wcore_attrib_list_get_key_is_last(void **state) {
+test_wcore_attrib_list32_get_key_is_last(void **state) {
int32_t attrib_list[] = {
1, 11,
2, 22,
@@ -113,52 +113,52 @@ test_wcore_attrib_list_get_key_is_last(void **state) {
int32_t key = 3;
int32_t value;
- assert_true(wcore_attrib_list_get(attrib_list, key, &value));
+ assert_true(wcore_attrib_list32_get(attrib_list, key, &value));
assert_int_equal(value, 33);
}
static void
-test_wcore_attrib_list_length_null(void **state) {
+test_wcore_attrib_list32_length_null(void **state) {
int32_t *attrib_list = NULL;
- assert_int_equal(wcore_attrib_list_length(attrib_list), 0);
+ assert_int_equal(wcore_attrib_list32_length(attrib_list), 0);
}
static void
-test_wcore_attrib_list_length_is_0(void **state) {
+test_wcore_attrib_list32_length_is_0(void **state) {
int32_t attrib_list[] = {0};
- assert_int_equal(wcore_attrib_list_length(attrib_list), 0);
+ assert_int_equal(wcore_attrib_list32_length(attrib_list), 0);
}
static void
-test_wcore_attrib_list_length_is_1(void **state) {
+test_wcore_attrib_list32_length_is_1(void **state) {
int32_t attrib_list[] = {
1, 1,
0,
};
- assert_int_equal(wcore_attrib_list_length(attrib_list), 1);
+ assert_int_equal(wcore_attrib_list32_length(attrib_list), 1);
}
static void
-test_wcore_attrib_list_length_is_2(void **state) {
+test_wcore_attrib_list32_length_is_2(void **state) {
int32_t attrib_list[] = {
1, 1,
2, 2,
0,
};
- assert_int_equal(wcore_attrib_list_length(attrib_list), 2);
+ assert_int_equal(wcore_attrib_list32_length(attrib_list), 2);
}
static void
-test_wcore_attrib_list_length_is_37(void **state) {
+test_wcore_attrib_list32_length_is_37(void **state) {
int32_t attrib_list[75];
memset(attrib_list, 0xff, 74 * sizeof(int32_t));
attrib_list[74] = 0;
- assert_int_equal(wcore_attrib_list_length(attrib_list), 37);
+ assert_int_equal(wcore_attrib_list32_length(attrib_list), 37);
}
static void
-test_wcore_attrib_list_length_trailing_items(void **state) {
+test_wcore_attrib_list32_length_trailing_items(void **state) {
int32_t attrib_list[] = {
1, 1,
2, 2,
@@ -169,23 +169,23 @@ test_wcore_attrib_list_length_trailing_items(void **state) {
0,
};
- assert_int_equal(wcore_attrib_list_length(attrib_list), 3);
+ assert_int_equal(wcore_attrib_list32_length(attrib_list), 3);
}
static void
-test_wcore_attrib_list_update_null(void **state) {
+test_wcore_attrib_list32_update_null(void **state) {
int32_t *attrib_list = NULL;
- assert_false(wcore_attrib_list_update(attrib_list, 7, 7));
+ assert_false(wcore_attrib_list32_update(attrib_list, 7, 7));
}
static void
-test_wcore_attrib_list_update_empty_list(void **state) {
+test_wcore_attrib_list32_update_empty_list(void **state) {
int32_t attrib_list[] = {0};
- assert_false(wcore_attrib_list_update(attrib_list, 7, 7));
+ assert_false(wcore_attrib_list32_update(attrib_list, 7, 7));
}
static void
-test_wcore_attrib_list_update_at_0(void **state) {
+test_wcore_attrib_list32_update_at_0(void **state) {
int32_t v;
int32_t attrib_list[] = {
10, 10,
@@ -194,13 +194,13 @@ test_wcore_attrib_list_update_at_0(void **state) {
0,
};
- assert_true(wcore_attrib_list_update(attrib_list, 10, 99));
- assert_true(wcore_attrib_list_get(attrib_list, 10, &v));
+ assert_true(wcore_attrib_list32_update(attrib_list, 10, 99));
+ assert_true(wcore_attrib_list32_get(attrib_list, 10, &v));
assert_int_equal(v, 99);
}
static void
-test_wcore_attrib_list_update_at_1(void **state) {
+test_wcore_attrib_list32_update_at_1(void **state) {
int32_t v;
int32_t attrib_list[] = {
10, 10,
@@ -209,13 +209,13 @@ test_wcore_attrib_list_update_at_1(void **state) {
0,
};
- assert_true(wcore_attrib_list_update(attrib_list, 20, 99));
- assert_true(wcore_attrib_list_get(attrib_list, 20, &v));
+ assert_true(wcore_attrib_list32_update(attrib_list, 20, 99));
+ assert_true(wcore_attrib_list32_get(attrib_list, 20, &v));
assert_int_equal(v, 99);
}
static void
-test_wcore_attrib_list_update_missing_key(void **state) {
+test_wcore_attrib_list32_update_missing_key(void **state) {
int32_t attrib_list[] = {
10, 10,
20, 20,
@@ -223,30 +223,30 @@ test_wcore_attrib_list_update_missing_key(void **state) {
0,
};
- assert_false(wcore_attrib_list_update(attrib_list, 50, 99));
+ assert_false(wcore_attrib_list32_update(attrib_list, 50, 99));
}
int
main(void) {
const UnitTest tests[] = {
- unit_test(test_wcore_attrib_list_get_null),
- unit_test(test_wcore_attrib_list_get_empty),
- unit_test(test_wcore_attrib_list_get_missing_value),
- unit_test(test_wcore_attrib_list_get_trailing_items),
- unit_test(test_wcore_attrib_list_get_value_not_modified_if_not_found),
- unit_test(test_wcore_attrib_list_get_key_is_first),
- unit_test(test_wcore_attrib_list_get_key_is_last),
- unit_test(test_wcore_attrib_list_length_null),
- unit_test(test_wcore_attrib_list_length_is_0),
- unit_test(test_wcore_attrib_list_length_is_1),
- unit_test(test_wcore_attrib_list_length_is_2),
- unit_test(test_wcore_attrib_list_length_is_37),
- unit_test(test_wcore_attrib_list_length_trailing_items),
- unit_test(test_wcore_attrib_list_update_null),
- unit_test(test_wcore_attrib_list_update_empty_list),
- unit_test(test_wcore_attrib_list_update_at_0),
- unit_test(test_wcore_attrib_list_update_at_1),
- unit_test(test_wcore_attrib_list_update_missing_key),
+ unit_test(test_wcore_attrib_list32_get_null),
+ unit_test(test_wcore_attrib_list32_get_empty),
+ unit_test(test_wcore_attrib_list32_get_missing_value),
+ unit_test(test_wcore_attrib_list32_get_trailing_items),
+ unit_test(test_wcore_attrib_list32_get_value_not_modified_if_not_found),
+ unit_test(test_wcore_attrib_list32_get_key_is_first),
+ unit_test(test_wcore_attrib_list32_get_key_is_last),
+ unit_test(test_wcore_attrib_list32_length_null),
+ unit_test(test_wcore_attrib_list32_length_is_0),
+ unit_test(test_wcore_attrib_list32_length_is_1),
+ unit_test(test_wcore_attrib_list32_length_is_2),
+ unit_test(test_wcore_attrib_list32_length_is_37),
+ unit_test(test_wcore_attrib_list32_length_trailing_items),
+ unit_test(test_wcore_attrib_list32_update_null),
+ unit_test(test_wcore_attrib_list32_update_empty_list),
+ unit_test(test_wcore_attrib_list32_update_at_0),
+ unit_test(test_wcore_attrib_list32_update_at_1),
+ unit_test(test_wcore_attrib_list32_update_missing_key),
};
return run_tests(tests);
diff --git a/src/waffle/core/wcore_config_attrs.c b/src/waffle/core/wcore_config_attrs.c
index dba28f7..21c62a2 100644
--- a/src/waffle/core/wcore_config_attrs.c
+++ b/src/waffle/core/wcore_config_attrs.c
@@ -84,7 +84,7 @@ parse_bool(const int32_t attrib_list[],
{
int32_t raw_value;
- wcore_attrib_list_get_with_default(attrib_list, attrib_name,
+ wcore_attrib_list32_get_with_default(attrib_list, attrib_name,
&raw_value, default_value);
if (raw_value == WAFFLE_DONT_CARE) {
@@ -108,7 +108,7 @@ parse_context_api(struct wcore_config_attrs *attrs,
{
bool found;
- found = wcore_attrib_list_get(attrib_list,
+ found = wcore_attrib_list32_get(attrib_list,
WAFFLE_CONTEXT_API, &attrs->context_api);
if (!found) {
wcore_errorf(WAFFLE_ERROR_BAD_ATTRIBUTE,
@@ -163,11 +163,11 @@ static bool
parse_context_version(struct wcore_config_attrs *attrs,
const int32_t attrib_list[])
{
- wcore_attrib_list_get_with_default(attrib_list,
+ wcore_attrib_list32_get_with_default(attrib_list,
WAFFLE_CONTEXT_MAJOR_VERSION,
&attrs->context_major_version,
attrs->context_major_version);
- wcore_attrib_list_get_with_default(attrib_list,
+ wcore_attrib_list32_get_with_default(attrib_list,
WAFFLE_CONTEXT_MINOR_VERSION,
&attrs->context_minor_version,
attrs->context_minor_version);
@@ -260,7 +260,7 @@ static bool
parse_context_profile(struct wcore_config_attrs *attrs,
const int32_t attrib_list[])
{
- wcore_attrib_list_get_with_default(attrib_list,
+ wcore_attrib_list32_get_with_default(attrib_list,
WAFFLE_CONTEXT_PROFILE,
&attrs->context_profile,
attrs->context_profile);
diff --git a/src/waffle/core/wcore_error.c b/src/waffle/core/wcore_error.c
index fdf70f8..e755ac5 100644
--- a/src/waffle/core/wcore_error.c
+++ b/src/waffle/core/wcore_error.c
@@ -24,6 +24,7 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <errno.h>
+#include <inttypes.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
@@ -170,6 +171,13 @@ wcore_error_errno(const char *format, ...)
}
void
+wcore_error_bad_attribute(intptr_t attr)
+{
+ wcore_errorf(WAFFLE_ERROR_BAD_ATTRIBUTE,
+ "bad attribute 0x%"PRIxPTR, attr);
+}
+
+void
_wcore_error_internal(const char *file, int line, const char *format, ...)
{
struct wcore_error_tinfo *t = wcore_tinfo_get()->error;
diff --git a/src/waffle/core/wcore_error.h b/src/waffle/core/wcore_error.h
index e2d3189..0a9767c 100644
--- a/src/waffle/core/wcore_error.h
+++ b/src/waffle/core/wcore_error.h
@@ -63,6 +63,10 @@ wcore_errorf(enum waffle_error error, const char *format, ...);
void
wcore_error_errno(const char *format, ...);
+/// @brief Emit WAFFLE_ERROR_BAD_ATTRIBUTE with a default error message.
+void
+wcore_error_bad_attribute(intptr_t attr);
+
/// @brief Set error to WAFFLE_INTERNAL_ERROR with source location.
#define wcore_error_internal(format, ...) \
_wcore_error_internal(__FILE__, __LINE__, format, __VA_ARGS__)
diff --git a/src/waffle/core/wcore_platform.h b/src/waffle/core/wcore_platform.h
index 77943e4..2f9b9f8 100644
--- a/src/waffle/core/wcore_platform.h
+++ b/src/waffle/core/wcore_platform.h
@@ -114,8 +114,9 @@ struct wcore_platform_vtbl {
struct wcore_window*
(*create)(struct wcore_platform *platform,
struct wcore_config *config,
- int width,
- int height);
+ int32_t width,
+ int32_t height,
+ const intptr_t attrib_list[]);
bool
(*destroy)(struct wcore_window *window);
diff --git a/src/waffle/core/wcore_util.c b/src/waffle/core/wcore_util.c
index b2dafe4..b7809a3 100644
--- a/src/waffle/core/wcore_util.c
+++ b/src/waffle/core/wcore_util.c
@@ -28,6 +28,28 @@
#include "wcore_error.h"
#include "wcore_util.h"
+bool
+wcore_add_size(size_t *res, size_t x, size_t y)
+{
+ if (x > SIZE_MAX - y) {
+ return false;
+ }
+
+ *res = x + y;
+ return true;
+}
+
+bool
+wcore_mul_size(size_t *res, size_t x, size_t y)
+{
+ if (x > SIZE_MAX / y) {
+ return false;
+ }
+
+ *res = x * y;
+ return true;
+}
+
void*
wcore_malloc(size_t size)
{
@@ -89,6 +111,8 @@ wcore_enum_to_string(int32_t e)
CASE(WAFFLE_DL_OPENGL_ES1);
CASE(WAFFLE_DL_OPENGL_ES2);
CASE(WAFFLE_DL_OPENGL_ES3);
+ CASE(WAFFLE_WINDOW_WIDTH);
+ CASE(WAFFLE_WINDOW_HEIGHT);
default: return NULL;
diff --git a/src/waffle/core/wcore_util.h b/src/waffle/core/wcore_util.h
index d2aaa27..183134f 100644
--- a/src/waffle/core/wcore_util.h
+++ b/src/waffle/core/wcore_util.h
@@ -26,6 +26,7 @@
#pragma once
#include <stddef.h>
+#include "c99_compat.h"
#define container_of(ptr, type, member) ({ \
const __typeof__(((type *)0)->member ) *__mptr = (ptr); \
@@ -49,6 +50,32 @@
return 0; \
}
+/// @brief Addition that detects arithmetic overflow.
+///
+/// If the addition would result in overflow, then return false and do not
+/// update @a res.
+bool
+wcore_add_size(size_t *res, size_t x, size_t y);
+
+/// @brief In-place variant of wcore_add_size().
+static inline bool
+wcore_iadd_size(size_t *x, size_t y) {
+ return wcore_add_size(x, *x, y);
+}
+
+/// @brief Multiplication that detects arithmetic overflow.
+///
+/// If the multiplication would result in overflow, then return false and do
+/// not update @a res.
+bool
+wcore_mul_size(size_t *res, size_t x, size_t y);
+
+/// @brief In-place variant of wcore_mul_size().
+static inline bool
+wcore_imul_size(size_t *x, size_t y) {
+ return wcore_mul_size(x, *x, y);
+}
+
/// @brief Wrapper around malloc() that emits error if allocation fails.
void*
wcore_malloc(size_t size);
diff --git a/src/waffle/gbm/wgbm_window.c b/src/waffle/gbm/wgbm_window.c
index edac449..9fbf1be 100644
--- a/src/waffle/gbm/wgbm_window.c
+++ b/src/waffle/gbm/wgbm_window.c
@@ -30,6 +30,7 @@
#include "waffle_gbm.h"
+#include "wcore_attrib_list.h"
#include "wcore_error.h"
#include "wegl_config.h"
@@ -59,8 +60,9 @@ wgbm_window_destroy(struct wcore_window *wc_self)
struct wcore_window*
wgbm_window_create(struct wcore_platform *wc_plat,
struct wcore_config *wc_config,
- int width,
- int height)
+ int32_t width,
+ int32_t height,
+ const intptr_t attrib_list[])
{
struct wgbm_display *dpy = wgbm_display(wc_config->display);
struct wgbm_platform *plat = wgbm_platform(wegl_platform(wc_plat));
@@ -68,6 +70,11 @@ wgbm_window_create(struct wcore_platform *wc_plat,
uint32_t gbm_format;
bool ok = true;
+ if (wcore_attrib_list_length(attrib_list) > 0) {
+ wcore_error_bad_attribute(attrib_list[0]);
+ return NULL;
+ }
+
self = wcore_calloc(sizeof(*self));
if (self == NULL)
return NULL;
diff --git a/src/waffle/gbm/wgbm_window.h b/src/waffle/gbm/wgbm_window.h
index 729612b..7827823 100644
--- a/src/waffle/gbm/wgbm_window.h
+++ b/src/waffle/gbm/wgbm_window.h
@@ -52,8 +52,9 @@ wgbm_window(struct wcore_window *wc_self)
struct wcore_window*
wgbm_window_create(struct wcore_platform *wc_plat,
struct wcore_config *wc_config,
- int width,
- int height);
+ int32_t width,
+ int32_t height,
+ const intptr_t attrib_list[]);
bool
wgbm_window_destroy(struct wcore_window *wc_self);
diff --git a/src/waffle/glx/glx_window.c b/src/waffle/glx/glx_window.c
index 34fa784..331bb51 100644
--- a/src/waffle/glx/glx_window.c
+++ b/src/waffle/glx/glx_window.c
@@ -27,6 +27,7 @@
#include <string.h>
#include <xcb/xcb.h>
+#include "wcore_attrib_list.h"
#include "wcore_error.h"
#include "glx_config.h"
@@ -52,14 +53,20 @@ glx_window_destroy(struct wcore_window *wc_self)
struct wcore_window*
glx_window_create(struct wcore_platform *wc_plat,
struct wcore_config *wc_config,
- int width,
- int height)
+ int32_t width,
+ int32_t height,
+ const intptr_t attrib_list[])
{
struct glx_window *self;
struct glx_display *dpy = glx_display(wc_config->display);
struct glx_config *config = glx_config(wc_config);
bool ok = true;
+ if (wcore_attrib_list_length(attrib_list) > 0) {
+ wcore_error_bad_attribute(attrib_list[0]);
+ return NULL;
+ }
+
self = wcore_calloc(sizeof(*self));
if (self == NULL)
return NULL;
diff --git a/src/waffle/glx/glx_window.h b/src/waffle/glx/glx_window.h
index 5aed497..b4fd7f9 100644
--- a/src/waffle/glx/glx_window.h
+++ b/src/waffle/glx/glx_window.h
@@ -46,8 +46,9 @@ DEFINE_CONTAINER_CAST_FUNC(glx_window,
struct wcore_window*
glx_window_create(struct wcore_platform *wc_plat,
struct wcore_config *wc_config,
- int width,
- int height);
+ int32_t width,
+ int32_t height,
+ const intptr_t attrib_list[]);
bool
glx_window_destroy(struct wcore_window *wc_self);
diff --git a/src/waffle/waffle.def.in b/src/waffle/waffle.def.in
index db8464f..ca3078a 100644
--- a/src/waffle/waffle.def.in
+++ b/src/waffle/waffle.def.in
@@ -20,6 +20,7 @@ EXPORTS
waffle_context_destroy
waffle_context_get_native
waffle_window_create
+ waffle_window_create2
waffle_window_destroy
waffle_window_show
waffle_window_swap_buffers
diff --git a/src/waffle/wayland/wayland_window.c b/src/waffle/wayland/wayland_window.c
index f32e995..4ac9c16 100644
--- a/src/waffle/wayland/wayland_window.c
+++ b/src/waffle/wayland/wayland_window.c
@@ -33,6 +33,7 @@
#include "waffle_wayland.h"
+#include "wcore_attrib_list.h"
#include "wcore_error.h"
#include "wegl_config.h"
@@ -96,13 +97,19 @@ static const struct wl_shell_surface_listener shell_surface_listener = {
struct wcore_window*
wayland_window_create(struct wcore_platform *wc_plat,
struct wcore_config *wc_config,
- int width,
- int height)
+ int32_t width,
+ int32_t height,
+ const intptr_t attrib_list[])
{
struct wayland_window *self;
struct wayland_display *dpy = wayland_display(wc_config->display);
bool ok = true;
+ if (wcore_attrib_list_length(attrib_list) > 0) {
+ wcore_error_bad_attribute(attrib_list[0]);
+ return NULL;
+ }
+
self = wcore_calloc(sizeof(*self));
if (self == NULL)
return NULL;
diff --git a/src/waffle/wayland/wayland_window.h b/src/waffle/wayland/wayland_window.h
index 933e751..11e6791 100644
--- a/src/waffle/wayland/wayland_window.h
+++ b/src/waffle/wayland/wayland_window.h
@@ -59,8 +59,9 @@ wayland_window(struct wcore_window *wc_self)
struct wcore_window*
wayland_window_create(struct wcore_platform *wc_plat,
struct wcore_config *wc_config,
- int width,
- int height);
+ int32_t width,
+ int32_t height,
+ const intptr_t attrib_list[]);
bool
wayland_window_destroy(struct wcore_window *wc_self);
diff --git a/src/waffle/wgl/wgl_window.c b/src/waffle/wgl/wgl_window.c
index 7c3932f..99dd194 100644
--- a/src/waffle/wgl/wgl_window.c
+++ b/src/waffle/wgl/wgl_window.c
@@ -25,6 +25,7 @@
#include <windows.h>
+#include "wcore_attrib_list.h"
#include "wcore_error.h"
#include "wgl_config.h"
@@ -68,14 +69,20 @@ wgl_window_priv_destroy(struct wcore_window *wc_self)
struct wcore_window*
wgl_window_create(struct wcore_platform *wc_plat,
struct wcore_config *wc_config,
- int width,
- int height)
+ int32_t width,
+ int32_t height,
+ const intptr_t attrib_list[])
{
struct wgl_config *config = wgl_config(wc_config);
bool ok;
assert(config->window);
+ if (wcore_attrib_list_length(attrib_list) > 0) {
+ wcore_error_bad_attribute(attrib_list[0]);
+ return NULL;
+ }
+
// Currently we do not allow multiple windows per config.
// Neither piglit nor the waffle examples do that yet, so just
// return NULL in case that ever changes.
@@ -95,8 +102,8 @@ wgl_window_create(struct wcore_platform *wc_plat,
struct wcore_window*
wgl_window_priv_create(struct wcore_platform *wc_plat,
struct wcore_config *wc_config,
- int width,
- int height)
+ int32_t width,
+ int32_t height)
{
struct wgl_platform *plat = wgl_platform(wc_plat);
struct wgl_window *self;
diff --git a/src/waffle/wgl/wgl_window.h b/src/waffle/wgl/wgl_window.h
index a60205d..9b11509 100644
--- a/src/waffle/wgl/wgl_window.h
+++ b/src/waffle/wgl/wgl_window.h
@@ -48,8 +48,8 @@ wgl_window(struct wcore_window *wcore)
struct wcore_window*
wgl_window_priv_create(struct wcore_platform *wc_plat,
struct wcore_config *wc_config,
- int width,
- int height);
+ int32_t width,
+ int32_t height);
bool
wgl_window_priv_destroy(struct wcore_window *wc_self);
@@ -57,8 +57,9 @@ wgl_window_priv_destroy(struct wcore_window *wc_self);
struct wcore_window*
wgl_window_create(struct wcore_platform *wc_plat,
struct wcore_config *wc_config,
- int width,
- int height);
+ int32_t width,
+ int32_t height,
+ const intptr_t attrib_list[]);
bool
wgl_window_destroy(struct wcore_window *wc_self);
diff --git a/src/waffle/x11/x11_window.c b/src/waffle/x11/x11_window.c
index b2e3631..308d4ce 100644
--- a/src/waffle/x11/x11_window.c
+++ b/src/waffle/x11/x11_window.c
@@ -70,8 +70,8 @@ bool
x11_window_init(struct x11_window *self,
struct x11_display *dpy,
xcb_visualid_t visual_id,
- int width,
- int height)
+ int32_t width,
+ int32_t height)
{
xcb_colormap_t colormap = 0;
xcb_window_t window = 0;
diff --git a/src/waffle/x11/x11_window.h b/src/waffle/x11/x11_window.h
index 812b146..262b156 100644
--- a/src/waffle/x11/x11_window.h
+++ b/src/waffle/x11/x11_window.h
@@ -40,8 +40,8 @@ bool
x11_window_init(struct x11_window *self,
struct x11_display *dpy,
xcb_visualid_t visual_id,
- int width,
- int height);
+ int32_t width,
+ int32_t height);
bool
x11_window_teardown(struct x11_window *self);
diff --git a/src/waffle/xegl/xegl_window.c b/src/waffle/xegl/xegl_window.c
index ce638b4..ab66314 100644
--- a/src/waffle/xegl/xegl_window.c
+++ b/src/waffle/xegl/xegl_window.c
@@ -28,6 +28,7 @@
#include <xcb/xcb.h>
+#include "wcore_attrib_list.h"
#include "wcore_error.h"
#include "wegl_config.h"
@@ -55,8 +56,9 @@ xegl_window_destroy(struct wcore_window *wc_self)
struct wcore_window*
xegl_window_create(struct wcore_platform *wc_plat,
struct wcore_config *wc_config,
- int width,
- int height)
+ int32_t width,
+ int32_t height,
+ const intptr_t attrib_list[])
{
struct xegl_window *self;
struct xegl_display *dpy = xegl_display(wc_config->display);
@@ -65,6 +67,11 @@ xegl_window_create(struct wcore_platform *wc_plat,
xcb_visualid_t visual;
bool ok = true;
+ if (wcore_attrib_list_length(attrib_list) > 0) {
+ wcore_error_bad_attribute(attrib_list[0]);
+ return NULL;
+ }
+
self = wcore_calloc(sizeof(*self));
if (self == NULL)
return NULL;
diff --git a/src/waffle/xegl/xegl_window.h b/src/waffle/xegl/xegl_window.h
index 1f963ba..e59c02f 100644
--- a/src/waffle/xegl/xegl_window.h
+++ b/src/waffle/xegl/xegl_window.h
@@ -56,8 +56,9 @@ xegl_window(struct wcore_window *wc_self)
struct wcore_window*
xegl_window_create(struct wcore_platform *wc_plat,
struct wcore_config *wc_config,
- int width,
- int height);
+ int32_t width,
+ int32_t height,
+ const intptr_t attrib_list[]);
bool
xegl_window_destroy(struct wcore_window *wc_self);
diff --git a/tests/functional/gl_basic_test.c b/tests/functional/gl_basic_test.c
index 0e932e3..19b0dac 100644
--- a/tests/functional/gl_basic_test.c
+++ b/tests/functional/gl_basic_test.c
@@ -216,6 +216,12 @@ gl_basic_draw__(struct gl_basic_draw_args__ args)
struct waffle_window *window = NULL;
struct waffle_context *ctx = NULL;
+ const intptr_t window_attrib_list[] = {
+ WAFFLE_WINDOW_WIDTH, WINDOW_WIDTH,
+ WAFFLE_WINDOW_HEIGHT, WINDOW_HEIGHT,
+ 0,
+ };
+
libgl = libgl_from_context_api(waffle_context_api);
i = 0;
@@ -271,8 +277,7 @@ gl_basic_draw__(struct gl_basic_draw_args__ args)
}
}
- ASSERT_TRUE(window = waffle_window_create(config,
- WINDOW_WIDTH, WINDOW_HEIGHT));
+ ASSERT_TRUE(window = waffle_window_create2(config, window_attrib_list));
ASSERT_TRUE(waffle_window_show(window));
ctx = waffle_context_create(config, NULL);