[waffle] [PATCH 15/17] waffle: Add public func waffle_window_create2() (v2)

Chad Versace chad.versace at intel.com
Sun Jan 4 14:03:08 PST 2015


Today, waffle_window() has only two parameters: width and height.

Frank Henigman wants to extend Waffle's GBM backend with the ability to
post window contents to the display. Multiple methods exist for posting
content to the screen with the drm API, and that method should be
configurable per waffle_window. Therefore, we need to be able to pass
additional attributes to waffle_window_create().

It would also be nice to specify at time of creation that the
waffle_window should be full screen. Again, we need to pass additional
attributes to waffle_window_create().

The new function waffle_window_create2() is conceptually equivalent to
the original waffle_window_create() with the addition of an attrib_list
parameter.  The only supported attributes are currently
WAFFLE_WINDOW_WIDTH and WAFFLE_WINDOW_HEIGHT.

See the manpage changes for more details.

Signed-off-by: Chad Versace <chad.versace at intel.com>
---

v2:
    - Implement old function (waffle_window_create) by calling the new function
      (waffle_window_create2). [fjhenigman]

 include/waffle/waffle.h        | 14 ++++++++
 man/waffle_enum.3.xml          |  7 ++++
 man/waffle_window.3.xml        | 27 +++++++++++++++
 src/waffle/api/waffle_window.c | 77 +++++++++++++++++++++++++++++++++++++-----
 src/waffle/core/wcore_util.c   |  2 ++
 5 files changed, 118 insertions(+), 9 deletions(-)

diff --git a/include/waffle/waffle.h b/include/waffle/waffle.h
index c242910..cff421f 100644
--- a/include/waffle/waffle.h
+++ b/include/waffle/waffle.h
@@ -162,6 +162,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*
@@ -233,6 +240,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,
diff --git a/man/waffle_enum.3.xml b/man/waffle_enum.3.xml
index a96bd20..ee5f236 100644
--- a/man/waffle_enum.3.xml
+++ b/man/waffle_enum.3.xml
@@ -141,6 +141,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/api/waffle_window.c b/src/waffle/api/waffle_window.c
index 34ecc4a..9ab63ca 100644
--- a/src/waffle/api/waffle_window.c
+++ b/src/waffle/api/waffle_window.c
@@ -27,37 +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,
-        int32_t width, int32_t 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,
-                                                NULL /*attrib_list*/);
-    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/core/wcore_util.c b/src/waffle/core/wcore_util.c
index fe4ac30..ffa0465 100644
--- a/src/waffle/core/wcore_util.c
+++ b/src/waffle/core/wcore_util.c
@@ -110,6 +110,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;
 
-- 
2.2.0



More information about the waffle mailing list