[waffle] [PATCH v3 3/4] waffle: initial empty implementation of nacl backend

Tapani Pälli tapani.palli at intel.com
Sun Jan 4 23:36:13 PST 2015


Patch adds nacl platform skeleton. Only thing it does is that
it creates a container that holds the 3D context object which is
responsible for any communication required with browser.

v2: cleanups, remove unnecessary casts, use c99 initializer
    (Emil Velikov)
v3: additional code cleanups (Chad Versace)

Signed-off-by: Tapani Pälli <tapani.palli at intel.com>
---
 CMakeLists.txt                     |   2 +-
 include/waffle/waffle.h            |   1 +
 src/waffle/CMakeLists.txt          |  16 ++++-
 src/waffle/api/waffle_init.c       |  11 +++
 src/waffle/core/wcore_util.c       |   1 +
 src/waffle/nacl/nacl_config.c      |  63 +++++++++++++++++
 src/waffle/nacl/nacl_config.h      |  49 ++++++++++++++
 src/waffle/nacl/nacl_container.cpp |  66 ++++++++++++++++++
 src/waffle/nacl/nacl_container.h   |  38 +++++++++++
 src/waffle/nacl/nacl_context.c     |  65 ++++++++++++++++++
 src/waffle/nacl/nacl_context.h     |  52 ++++++++++++++
 src/waffle/nacl/nacl_display.c     |  70 +++++++++++++++++++
 src/waffle/nacl/nacl_display.h     |  52 ++++++++++++++
 src/waffle/nacl/nacl_platform.c    | 134 +++++++++++++++++++++++++++++++++++++
 src/waffle/nacl/nacl_platform.h    |  49 ++++++++++++++
 src/waffle/nacl/nacl_window.c      |  90 +++++++++++++++++++++++++
 src/waffle/nacl/nacl_window.h      |  59 ++++++++++++++++
 17 files changed, 816 insertions(+), 2 deletions(-)
 create mode 100644 src/waffle/nacl/nacl_config.c
 create mode 100644 src/waffle/nacl/nacl_config.h
 create mode 100644 src/waffle/nacl/nacl_container.cpp
 create mode 100644 src/waffle/nacl/nacl_container.h
 create mode 100644 src/waffle/nacl/nacl_context.c
 create mode 100644 src/waffle/nacl/nacl_context.h
 create mode 100644 src/waffle/nacl/nacl_display.c
 create mode 100644 src/waffle/nacl/nacl_display.h
 create mode 100644 src/waffle/nacl/nacl_platform.c
 create mode 100644 src/waffle/nacl/nacl_platform.h
 create mode 100644 src/waffle/nacl/nacl_window.c
 create mode 100644 src/waffle/nacl/nacl_window.h

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9bbe387..02e995e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -23,7 +23,7 @@
 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-project(waffle1 C)
+project(waffle1 C CXX)
 
 cmake_minimum_required(VERSION 2.8.11)
 
diff --git a/include/waffle/waffle.h b/include/waffle/waffle.h
index e04b23f..77885a4 100644
--- a/include/waffle/waffle.h
+++ b/include/waffle/waffle.h
@@ -104,6 +104,7 @@ enum waffle_enum {
         WAFFLE_PLATFORM_X11_EGL                                 = 0x0015,
         WAFFLE_PLATFORM_GBM                                     = 0x0016,
         WAFFLE_PLATFORM_WGL                                     = 0x0017,
+        WAFFLE_PLATFORM_NACL                                    = 0x0018,
 
     // ------------------------------------------------------------------
     // For waffle_config_choose()
diff --git a/src/waffle/CMakeLists.txt b/src/waffle/CMakeLists.txt
index c62b45d..ac9b415 100644
--- a/src/waffle/CMakeLists.txt
+++ b/src/waffle/CMakeLists.txt
@@ -15,6 +15,7 @@ include_directories(
     egl
     glx
     linux
+    nacl
     wayland
     wgl
     x11
@@ -180,6 +181,19 @@ if(waffle_on_windows)
         )
 endif()
 
+if(waffle_has_nacl)
+    list(APPEND waffle_sources
+        nacl/nacl_config.c
+        nacl/nacl_context.c
+        nacl/nacl_display.c
+        nacl/nacl_platform.c
+        nacl/nacl_window.c
+        )
+    list(APPEND waffle_cxx_sources
+        nacl/nacl_container.cpp
+        )
+endif()
+
 # CMake will pass to the C compiler only C sources. CMake does not recognize the
 # .m extension and ignores any such files in the source lists. To coerce CMake
 # to pass .m files to the compiler, we must lie and claim that they are
@@ -209,7 +223,7 @@ include_directories(
     ${XCB_INCLUDE_DIRS}
     )
 
-add_library(${waffle_libname} SHARED ${waffle_sources})
+add_library(${waffle_libname} SHARED ${waffle_sources} ${waffle_cxx_sources})
 
 # Debian's packaging system emits warnings if wflinfo directly links to any
 # library that it doesn't directly use. Silence the warnings by annotating
diff --git a/src/waffle/api/waffle_init.c b/src/waffle/api/waffle_init.c
index ebc6cd5..fcf8456 100644
--- a/src/waffle/api/waffle_init.c
+++ b/src/waffle/api/waffle_init.c
@@ -35,6 +35,7 @@ struct wcore_platform* wayland_platform_create(void);
 struct wcore_platform* xegl_platform_create(void);
 struct wcore_platform* wgbm_platform_create(void);
 struct wcore_platform* wgl_platform_create(void);
+struct wcore_platform* nacl_platform_create(void);
 
 static bool
 waffle_init_parse_attrib_list(
@@ -104,6 +105,12 @@ waffle_init_parse_attrib_list(
                     CASE_UNDEFINED_PLATFORM(WGL)
 #endif
 
+#ifdef WAFFLE_HAS_NACL
+                    CASE_DEFINED_PLATFORM(NACL)
+#else
+                    CASE_UNDEFINED_PLATFORM(NACL)
+#endif
+
                     default:
                         wcore_errorf(WAFFLE_ERROR_BAD_ATTRIBUTE,
                                      "WAFFLE_PLATFORM has bad value 0x%x",
@@ -164,6 +171,10 @@ waffle_init_create_platform(int32_t waffle_platform)
         case WAFFLE_PLATFORM_WGL:
             return wgl_platform_create();
 #endif
+#ifdef WAFFLE_HAS_NACL
+        case WAFFLE_PLATFORM_NACL:
+            return nacl_platform_create();
+#endif
         default:
             assert(false);
             return NULL;
diff --git a/src/waffle/core/wcore_util.c b/src/waffle/core/wcore_util.c
index deee1bf..b2dafe4 100644
--- a/src/waffle/core/wcore_util.c
+++ b/src/waffle/core/wcore_util.c
@@ -62,6 +62,7 @@ wcore_enum_to_string(int32_t e)
         CASE(WAFFLE_PLATFORM_X11_EGL);
         CASE(WAFFLE_PLATFORM_GBM);
         CASE(WAFFLE_PLATFORM_WGL);
+        CASE(WAFFLE_PLATFORM_NACL);
         CASE(WAFFLE_CONTEXT_API);
         CASE(WAFFLE_CONTEXT_OPENGL);
         CASE(WAFFLE_CONTEXT_OPENGL_ES1);
diff --git a/src/waffle/nacl/nacl_config.c b/src/waffle/nacl/nacl_config.c
new file mode 100644
index 0000000..27a75e1
--- /dev/null
+++ b/src/waffle/nacl/nacl_config.c
@@ -0,0 +1,63 @@
+// Copyright 2014 Intel Corporation
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// - Redistributions of source code must retain the above copyright notice, this
+//   list of conditions and the following disclaimer.
+//
+// - Redistributions in binary form must reproduce the above copyright notice,
+//   this list of conditions and the following disclaimer in the documentation
+//   and/or other materials provided with the distribution.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "nacl_config.h"
+
+bool
+nacl_config_destroy(struct wcore_config *wc_self)
+{
+    bool ok = true;
+
+    if (wc_self == NULL)
+        return ok;
+
+    ok &= wcore_config_teardown(wc_self);
+    free(nacl_config(wc_self));
+    return ok;
+}
+
+struct wcore_config*
+nacl_config_choose(struct wcore_platform *wc_plat,
+                  struct wcore_display *wc_dpy,
+                  const struct wcore_config_attrs *attrs)
+{
+    struct nacl_config *self;
+    bool ok = true;
+
+    self = wcore_calloc(sizeof(*self));
+    if (self == NULL)
+        return NULL;
+
+    ok = wcore_config_init(&self->wcore, wc_dpy, attrs);
+    if (!ok)
+        goto error;
+
+    return &self->wcore;
+
+error:
+    nacl_config_destroy(&self->wcore);
+    self = NULL;
+    return NULL;
+}
diff --git a/src/waffle/nacl/nacl_config.h b/src/waffle/nacl/nacl_config.h
new file mode 100644
index 0000000..3270179
--- /dev/null
+++ b/src/waffle/nacl/nacl_config.h
@@ -0,0 +1,49 @@
+// Copyright 2014 Intel Corporation
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// - Redistributions of source code must retain the above copyright notice, this
+//   list of conditions and the following disclaimer.
+//
+// - Redistributions in binary form must reproduce the above copyright notice,
+//   this list of conditions and the following disclaimer in the documentation
+//   and/or other materials provided with the distribution.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#pragma once
+
+#include "wcore_config.h"
+#include "wcore_util.h"
+
+struct wcore_config_attrs;
+struct wcore_platform;
+
+struct nacl_config {
+    struct wcore_config wcore;
+};
+
+DEFINE_CONTAINER_CAST_FUNC(nacl_config,
+                           struct nacl_config,
+                           struct wcore_config,
+                           wcore)
+
+struct wcore_config*
+nacl_config_choose(struct wcore_platform *wc_plat,
+                   struct wcore_display *wc_dpy,
+                   const struct wcore_config_attrs *attrs);
+
+bool
+nacl_config_destroy(struct wcore_config *wc_self);
diff --git a/src/waffle/nacl/nacl_container.cpp b/src/waffle/nacl/nacl_container.cpp
new file mode 100644
index 0000000..3e8073c
--- /dev/null
+++ b/src/waffle/nacl/nacl_container.cpp
@@ -0,0 +1,66 @@
+// Copyright 2014 Intel Corporation
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// - Redistributions of source code must retain the above copyright notice, this
+//   list of conditions and the following disclaimer.
+//
+// - Redistributions in binary form must reproduce the above copyright notice,
+//   this list of conditions and the following disclaimer in the documentation
+//   and/or other materials provided with the distribution.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "ppapi/cpp/graphics_3d.h"
+#include "nacl_container.h"
+
+namespace waffle {
+
+struct nacl_container {
+    pp::Graphics3D ctx;
+};
+
+static void
+nacl_container_dtor(waffle::nacl_container *nc)
+{
+    if (!nc)
+        return;
+    delete nc;
+}
+
+static nacl_container*
+nacl_container_ctor()
+{
+    nacl_container *nc = new nacl_container;
+
+    if (!nc)
+        return NULL;
+
+    return nc;
+}
+
+}; // namespace waffle ends
+
+extern "C" struct nacl_container*
+nacl_init()
+{
+    return reinterpret_cast<nacl_container*>(waffle::nacl_container_ctor());
+}
+
+extern "C" void
+nacl_teardown(nacl_container *nc)
+{
+    waffle::nacl_container_dtor(reinterpret_cast<waffle::nacl_container*>(nc));
+}
diff --git a/src/waffle/nacl/nacl_container.h b/src/waffle/nacl/nacl_container.h
new file mode 100644
index 0000000..61d935c
--- /dev/null
+++ b/src/waffle/nacl/nacl_container.h
@@ -0,0 +1,38 @@
+// Copyright 2014 Intel Corporation
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// - Redistributions of source code must retain the above copyright notice, this
+//   list of conditions and the following disclaimer.
+//
+// - Redistributions in binary form must reproduce the above copyright notice,
+//   this list of conditions and the following disclaimer in the documentation
+//   and/or other materials provided with the distribution.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifdef __cplusplus
+
+extern "C" {
+#endif
+
+struct nacl_container;
+
+struct nacl_container *nacl_init();
+void nacl_teardown(struct nacl_container *nc);
+
+#ifdef __cplusplus
+};
+#endif
diff --git a/src/waffle/nacl/nacl_context.c b/src/waffle/nacl/nacl_context.c
new file mode 100644
index 0000000..2e68a64
--- /dev/null
+++ b/src/waffle/nacl/nacl_context.c
@@ -0,0 +1,65 @@
+// Copyright 2014 Intel Corporation
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// - Redistributions of source code must retain the above copyright notice, this
+//   list of conditions and the following disclaimer.
+//
+// - Redistributions in binary form must reproduce the above copyright notice,
+//   this list of conditions and the following disclaimer in the documentation
+//   and/or other materials provided with the distribution.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "nacl_context.h"
+
+bool
+nacl_context_destroy(struct wcore_context *wc_self)
+{
+    struct nacl_context *self;
+    bool ok = true;
+
+    if (!wc_self)
+        return ok;
+
+    self = nacl_context(wc_self);
+
+    ok &= wcore_context_teardown(wc_self);
+    free(self);
+    return ok;
+}
+
+struct wcore_context*
+nacl_context_create(struct wcore_platform *wc_plat,
+                    struct wcore_config *wc_config,
+                    struct wcore_context *wc_share_ctx)
+{
+    struct nacl_context *self;
+    bool ok = true;
+
+    self = wcore_calloc(sizeof(*self));
+    if (self == NULL)
+        return NULL;
+
+    ok = wcore_context_init(&self->wcore, wc_config);
+    if (!ok)
+        goto error;
+
+    return &self->wcore;
+
+error:
+    nacl_context_destroy(&self->wcore);
+    return NULL;
+}
diff --git a/src/waffle/nacl/nacl_context.h b/src/waffle/nacl/nacl_context.h
new file mode 100644
index 0000000..bb4481a
--- /dev/null
+++ b/src/waffle/nacl/nacl_context.h
@@ -0,0 +1,52 @@
+// Copyright 2014 Intel Corporation
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// - Redistributions of source code must retain the above copyright notice, this
+//   list of conditions and the following disclaimer.
+//
+// - Redistributions in binary form must reproduce the above copyright notice,
+//   this list of conditions and the following disclaimer in the documentation
+//   and/or other materials provided with the distribution.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#pragma once
+
+#include "wcore_context.h"
+#include "wcore_util.h"
+
+#include "nacl_display.h"
+#include "nacl_platform.h"
+
+struct wcore_config;
+struct wcore_platform;
+
+struct nacl_context {
+    struct wcore_context wcore;
+};
+
+DEFINE_CONTAINER_CAST_FUNC(nacl_context,
+                           struct nacl_context,
+                           struct wcore_context,
+                           wcore)
+
+struct wcore_context*
+nacl_context_create(struct wcore_platform *wc_plat,
+                    struct wcore_config *wc_config,
+                    struct wcore_context *wc_share_ctx);
+
+bool
+nacl_context_destroy(struct wcore_context *wc_self);
diff --git a/src/waffle/nacl/nacl_display.c b/src/waffle/nacl/nacl_display.c
new file mode 100644
index 0000000..2d1162e
--- /dev/null
+++ b/src/waffle/nacl/nacl_display.c
@@ -0,0 +1,70 @@
+// Copyright 2014 Intel Corporation
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// - Redistributions of source code must retain the above copyright notice, this
+//   list of conditions and the following disclaimer.
+//
+// - Redistributions in binary form must reproduce the above copyright notice,
+//   this list of conditions and the following disclaimer in the documentation
+//   and/or other materials provided with the distribution.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "nacl_display.h"
+
+bool
+nacl_display_destroy(struct wcore_display *wc_self)
+{
+    struct nacl_display *self = nacl_display(wc_self);
+    bool ok = true;
+
+    if (!self)
+        return ok;
+
+    ok &= wcore_display_teardown(&self->wcore);
+
+    free(self);
+    return ok;
+}
+
+struct wcore_display*
+nacl_display_connect(struct wcore_platform *wc_plat,
+                     const char *name)
+{
+    struct nacl_display *self;
+    bool ok = true;
+
+    self = wcore_calloc(sizeof(*self));
+    if (self == NULL)
+        return NULL;
+
+    ok = wcore_display_init(&self->wcore, wc_plat);
+    if (!ok)
+        goto error;
+
+    return &self->wcore;
+
+error:
+    nacl_display_destroy(&self->wcore);
+    return NULL;
+}
+
+bool
+nacl_display_supports_context_api(struct wcore_display *wc_self,
+                                  int32_t context_api)
+{
+    return false;
+}
diff --git a/src/waffle/nacl/nacl_display.h b/src/waffle/nacl/nacl_display.h
new file mode 100644
index 0000000..34eee21
--- /dev/null
+++ b/src/waffle/nacl/nacl_display.h
@@ -0,0 +1,52 @@
+// Copyright 2014 Intel Corporation
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// - Redistributions of source code must retain the above copyright notice, this
+//   list of conditions and the following disclaimer.
+//
+// - Redistributions in binary form must reproduce the above copyright notice,
+//   this list of conditions and the following disclaimer in the documentation
+//   and/or other materials provided with the distribution.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#pragma once
+
+#include "wcore_display.h"
+#include "wcore_error.h"
+#include "wcore_util.h"
+
+struct wcore_platform;
+
+struct nacl_display {
+    struct wcore_display wcore;
+};
+
+DEFINE_CONTAINER_CAST_FUNC(nacl_display,
+                           struct nacl_display,
+                           struct wcore_display,
+                           wcore)
+
+struct wcore_display*
+nacl_display_connect(struct wcore_platform *wc_plat,
+                     const char *name);
+
+bool
+nacl_display_destroy(struct wcore_display *wc_self);
+
+bool
+nacl_display_supports_context_api(struct wcore_display *wc_self,
+                                  int32_t context_api);
diff --git a/src/waffle/nacl/nacl_platform.c b/src/waffle/nacl/nacl_platform.c
new file mode 100644
index 0000000..b4df9d9
--- /dev/null
+++ b/src/waffle/nacl/nacl_platform.c
@@ -0,0 +1,134 @@
+// Copyright 2014 Intel Corporation
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// - Redistributions of source code must retain the above copyright notice, this
+//   list of conditions and the following disclaimer.
+//
+// - Redistributions in binary form must reproduce the above copyright notice,
+//   this list of conditions and the following disclaimer in the documentation
+//   and/or other materials provided with the distribution.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include <dlfcn.h>
+#include <stdio.h>
+
+#include "nacl_platform.h"
+
+static const struct wcore_platform_vtbl nacl_platform_vtbl;
+
+static bool
+nacl_platform_destroy(struct wcore_platform *wc_self)
+{
+    struct nacl_platform *self = nacl_platform(wc_self);
+    bool ok = true;
+
+    if (!self)
+        return true;
+
+    ok &= wcore_platform_teardown(wc_self);
+
+    nacl_teardown(self->nacl);
+
+    free(self);
+    return ok;
+}
+
+static bool
+nacl_platform_dl_can_open(struct wcore_platform *wc_self,
+                          int32_t waffle_dl)
+{
+    return false;
+}
+
+static void*
+nacl_platform_dl_sym(struct wcore_platform *wc_self,
+                     int32_t waffle_dl,
+                     const char *name)
+{
+    return NULL;
+}
+
+static bool
+nacl_platform_make_current(struct wcore_platform *wc_self,
+                           struct wcore_display *wc_dpy,
+                           struct wcore_window *wc_window,
+                           struct wcore_context *wc_ctx)
+{
+    return false;
+}
+
+struct wcore_platform*
+nacl_platform_create(void)
+{
+    struct nacl_platform *self;
+    bool ok = true;
+
+    self = wcore_calloc(sizeof(*self));
+    if (self == NULL)
+        return NULL;
+
+    ok = wcore_platform_init(&self->wcore);
+    if (!ok)
+        goto error;
+
+    self->nacl = nacl_init();
+    if (!self->nacl)
+        goto error;
+
+    self->wcore.vtbl = &nacl_platform_vtbl;
+    return &self->wcore;
+
+error:
+    nacl_platform_destroy(&self->wcore);
+    return NULL;
+}
+
+static const struct wcore_platform_vtbl nacl_platform_vtbl = {
+    .destroy = nacl_platform_destroy,
+
+    .make_current = nacl_platform_make_current,
+    .dl_can_open = nacl_platform_dl_can_open,
+    .dl_sym = nacl_platform_dl_sym,
+
+    .display = {
+        .connect = nacl_display_connect,
+        .destroy = nacl_display_destroy,
+        .supports_context_api = nacl_display_supports_context_api,
+        .get_native = NULL,
+    },
+
+    .config = {
+        .choose = nacl_config_choose,
+        .destroy = nacl_config_destroy,
+        .get_native = NULL,
+    },
+
+    .context = {
+        .create = nacl_context_create,
+        .destroy = nacl_context_destroy,
+        .get_native = NULL,
+    },
+
+    .window = {
+        .create = nacl_window_create,
+        .destroy = nacl_window_destroy,
+        .show = nacl_window_show,
+        .swap_buffers = nacl_window_swap_buffers,
+        .resize = nacl_window_resize,
+        .get_native = NULL,
+    },
+};
diff --git a/src/waffle/nacl/nacl_platform.h b/src/waffle/nacl/nacl_platform.h
new file mode 100644
index 0000000..ba58de5
--- /dev/null
+++ b/src/waffle/nacl/nacl_platform.h
@@ -0,0 +1,49 @@
+// Copyright 2014 Intel Corporation
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// - Redistributions of source code must retain the above copyright notice, this
+//   list of conditions and the following disclaimer.
+//
+// - Redistributions in binary form must reproduce the above copyright notice,
+//   this list of conditions and the following disclaimer in the documentation
+//   and/or other materials provided with the distribution.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#pragma once
+
+#include "wcore_platform.h"
+#include "wcore_error.h"
+#include "wcore_util.h"
+
+#include "nacl_config.h"
+#include "nacl_container.h"
+#include "nacl_context.h"
+#include "nacl_display.h"
+#include "nacl_window.h"
+
+struct nacl_platform {
+    struct wcore_platform wcore;
+    struct nacl_container *nacl;
+};
+
+DEFINE_CONTAINER_CAST_FUNC(nacl_platform,
+                           struct nacl_platform,
+                           struct wcore_platform,
+                           wcore)
+
+struct wcore_platform*
+nacl_platform_create(void);
diff --git a/src/waffle/nacl/nacl_window.c b/src/waffle/nacl/nacl_window.c
new file mode 100644
index 0000000..c5ba4e0
--- /dev/null
+++ b/src/waffle/nacl/nacl_window.c
@@ -0,0 +1,90 @@
+// Copyright 2014 Intel Corporation
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// - Redistributions of source code must retain the above copyright notice, this
+//   list of conditions and the following disclaimer.
+//
+// - Redistributions in binary form must reproduce the above copyright notice,
+//   this list of conditions and the following disclaimer in the documentation
+//   and/or other materials provided with the distribution.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "wcore_error.h"
+#include "nacl_config.h"
+#include "nacl_display.h"
+#include "nacl_window.h"
+#include "nacl_platform.h"
+
+bool
+nacl_window_destroy(struct wcore_window *wc_self)
+{
+    struct nacl_window *self = nacl_window(wc_self);
+    bool ok = true;
+
+    if (!wc_self)
+        return ok;
+
+    ok &= wcore_window_teardown(wc_self);
+    free(self);
+    return ok;
+}
+
+struct wcore_window*
+nacl_window_create(struct wcore_platform *wc_plat,
+                   struct wcore_config *wc_config,
+                   int width,
+                   int height)
+{
+    struct nacl_window *self;
+    bool ok = true;
+
+    self = wcore_calloc(sizeof(*self));
+    if (self == NULL)
+        return NULL;
+
+    ok = wcore_window_init(&self->wcore, wc_config);
+    if (!ok)
+        goto error;
+
+    if (!ok)
+        goto error;
+
+    return &self->wcore;
+
+error:
+    nacl_window_destroy(&self->wcore);
+    return NULL;
+}
+
+bool
+nacl_window_show(struct wcore_window *wc_self)
+{
+    return true;
+}
+
+bool
+nacl_window_resize(struct wcore_window *wc_self,
+                   int32_t width, int32_t height)
+{
+    return false;
+}
+
+bool
+nacl_window_swap_buffers(struct wcore_window *wc_self)
+{
+    return false;
+}
diff --git a/src/waffle/nacl/nacl_window.h b/src/waffle/nacl/nacl_window.h
new file mode 100644
index 0000000..5f0906d
--- /dev/null
+++ b/src/waffle/nacl/nacl_window.h
@@ -0,0 +1,59 @@
+// Copyright 2014 Intel Corporation
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// - Redistributions of source code must retain the above copyright notice, this
+//   list of conditions and the following disclaimer.
+//
+// - Redistributions in binary form must reproduce the above copyright notice,
+//   this list of conditions and the following disclaimer in the documentation
+//   and/or other materials provided with the distribution.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#pragma once
+
+#include "wcore_window.h"
+#include "wcore_util.h"
+#include "nacl_platform.h"
+
+struct wcore_platform;
+
+struct nacl_window {
+    struct wcore_window wcore;
+};
+
+DEFINE_CONTAINER_CAST_FUNC(nacl_window,
+                           struct nacl_window,
+                           struct wcore_window,
+                           wcore)
+struct wcore_window*
+nacl_window_create(struct wcore_platform *wc_plat,
+                   struct wcore_config *wc_config,
+                   int width,
+                   int height);
+
+bool
+nacl_window_destroy(struct wcore_window *wc_self);
+
+bool
+nacl_window_show(struct wcore_window *wc_self);
+
+bool
+nacl_window_resize(struct wcore_window *wc_self,
+                  int32_t width, int32_t height);
+
+bool
+nacl_window_swap_buffers(struct wcore_window *wc_self);
-- 
1.9.3



More information about the waffle mailing list