[waffle] [PATCH v2 5/8] nacl: add implementation for window create and resize

Tapani Pälli tapani.palli at intel.com
Mon Feb 9 05:24:46 PST 2015


v2: cleanup + throw error if resize fails (Chad Versace)

Signed-off-by: Tapani Pälli <tapani.palli at intel.com>
---
 src/waffle/nacl/nacl_container.cpp | 27 +++++++++++++++++++++++++++
 src/waffle/nacl/nacl_container.h   |  1 +
 src/waffle/nacl/nacl_window.c      |  9 ++++++---
 src/waffle/nacl/nacl_window.h      |  1 +
 4 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/src/waffle/nacl/nacl_container.cpp b/src/waffle/nacl/nacl_container.cpp
index e4bf07a..5dd44a8 100644
--- a/src/waffle/nacl/nacl_container.cpp
+++ b/src/waffle/nacl/nacl_container.cpp
@@ -26,6 +26,7 @@
 #include "ppapi/cpp/graphics_3d.h"
 #include "ppapi/cpp/instance.h"
 #include "ppapi/cpp/module.h"
+#include "ppapi/c/pp_errors.h"
 #include "nacl_container.h"
 
 namespace waffle {
@@ -154,3 +155,29 @@ nacl_context_fini(struct nacl_container *nc)
     cpp_nc->glSetCurrentContextPPAPI(0);
     cpp_nc->glTerminatePPAPI();
 }
+
+extern "C" bool
+nacl_resize(struct nacl_container *nc, int32_t width, int32_t height)
+{
+    waffle::nacl_container *cpp_nc =
+        reinterpret_cast<waffle::nacl_container*>(nc);
+
+    int32_t error = cpp_nc->ctx->ResizeBuffers(width, height);
+
+    if (error == PP_OK)
+       return true;
+
+    switch (error) {
+        case PP_ERROR_BADRESOURCE:
+            wcore_errorf(WAFFLE_ERROR_FATAL, "Invalid NaCl 3D context.");
+            break;
+        case PP_ERROR_BADARGUMENT:
+            wcore_errorf(WAFFLE_ERROR_BAD_PARAMETER,
+                         "Invalid values given for resize (w %d h %d)",
+                         width, height);
+            break;
+        default:
+            wcore_errorf(WAFFLE_ERROR_UNKNOWN, "NaCl resize failed.");
+    }
+    return false;
+}
diff --git a/src/waffle/nacl/nacl_container.h b/src/waffle/nacl/nacl_container.h
index af08116..d1cb11d 100644
--- a/src/waffle/nacl/nacl_container.h
+++ b/src/waffle/nacl/nacl_container.h
@@ -40,6 +40,7 @@ struct nacl_container;
 struct nacl_container *nacl_init();
 void nacl_teardown(struct nacl_container *nc);
 bool nacl_context_init(struct nacl_container *nc, struct nacl_config *cfg);
+bool nacl_resize(struct nacl_container *nc, int32_t width, int32_t height);
 void nacl_context_fini(struct nacl_container *nc);
 
 #ifdef __cplusplus
diff --git a/src/waffle/nacl/nacl_window.c b/src/waffle/nacl/nacl_window.c
index 3596327..7b7121f 100644
--- a/src/waffle/nacl/nacl_window.c
+++ b/src/waffle/nacl/nacl_window.c
@@ -53,6 +53,7 @@ nacl_window_create(struct wcore_platform *wc_plat,
 
 {
     struct nacl_window *self;
+    struct nacl_platform *nplat = nacl_platform(wc_plat);
     bool ok = true;
 
     if (wcore_attrib_list_length(attrib_list) > 0) {
@@ -68,8 +69,9 @@ nacl_window_create(struct wcore_platform *wc_plat,
     if (!ok)
         goto error;
 
-    if (!ok)
-        goto error;
+    // Set requested dimensions for the backing surface.
+    if (!nacl_resize(nplat->nacl, width, height))
+         goto error;
 
     return &self->wcore;
 
@@ -88,7 +90,8 @@ bool
 nacl_window_resize(struct wcore_window *wc_self,
                    int32_t width, int32_t height)
 {
-    return false;
+    struct nacl_platform *plat = nacl_platform(wc_self->display->platform);
+    return nacl_resize(plat->nacl, width, height);
 }
 
 bool
diff --git a/src/waffle/nacl/nacl_window.h b/src/waffle/nacl/nacl_window.h
index 48567b1..d3465f3 100644
--- a/src/waffle/nacl/nacl_window.h
+++ b/src/waffle/nacl/nacl_window.h
@@ -27,6 +27,7 @@
 
 #include "wcore_window.h"
 #include "wcore_util.h"
+#include "nacl_container.h"
 #include "nacl_platform.h"
 
 struct wcore_platform;
-- 
2.1.0



More information about the waffle mailing list