[waffle] [PATCH 4/7] nacl: add implementation for window create and resize

Chad Versace chad.versace at intel.com
Mon Feb 2 15:28:09 PST 2015


On 01/22/2015 11:59 PM, Tapani Pälli wrote:
> Signed-off-by: Tapani Pälli <tapani.palli at intel.com>
> ---
>  src/waffle/nacl/nacl_container.cpp | 18 ++++++++++++++++++
>  src/waffle/nacl/nacl_container.h   |  1 +
>  src/waffle/nacl/nacl_window.c      |  7 ++++++-
>  src/waffle/nacl/nacl_window.h      |  1 +
>  4 files changed, 26 insertions(+), 1 deletion(-)
> 
> diff --git a/src/waffle/nacl/nacl_container.cpp b/src/waffle/nacl/nacl_container.cpp
> index e352da9..bca39eb 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 {
> @@ -125,6 +126,15 @@ nacl_context_init(waffle::nacl_container *nc, struct nacl_config *cfg)
>      return true;
>  }
>  
> +static bool
> +nacl_resize(struct nacl_container *nc, int32_t width, int32_t height)
> +{
> +    if (!nc || nc->ctx.ResizeBuffers(width, height) != PP_OK)
> +        return false;
> +
> +    return true;
> +}
> +
>  }; // namespace waffle ends
>  
>  extern "C" struct nacl_container*
> @@ -145,3 +155,11 @@ nacl_context_init(struct nacl_container *nc, struct nacl_config *cfg)
>      return waffle::nacl_context_init(
>                     reinterpret_cast<waffle::nacl_container*>(nc), cfg);
>  }
> +
> +extern "C" bool
> +nacl_resize(struct nacl_container *nc, int32_t width, int32_t height)
> +{
> +    return waffle::nacl_resize(
> +                   reinterpret_cast<waffle::nacl_container*>(nc),
> +                   width, height);
> +}

It's legal to make C++ calls inside `extern C` fuctions. So, I think you can
remove waffle::nacl_resize() and just do everything inside the C nacl_resize().
This should probably work:

extern "C" bool
nacl_resize(struct nacl_container *nc, int32_t width, int32_t height)
{
    waffle::nacl_container *cpp_nc = reinterpreet_cast<waffle::nacl_container*>(nc);
    
    if (!cpp_nc || cpp_nc->ctx.ResizeBuffers(width, height) != PP_OK)
        return false;

    return true;
}

> diff --git a/src/waffle/nacl/nacl_container.h b/src/waffle/nacl/nacl_container.h
> index 81472cc..f3ede41 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);
>  
>  #ifdef __cplusplus
>  };
> diff --git a/src/waffle/nacl/nacl_window.c b/src/waffle/nacl/nacl_window.c
> index c5ba4e0..eef1d1d 100644
> --- a/src/waffle/nacl/nacl_window.c
> +++ b/src/waffle/nacl/nacl_window.c
> @@ -50,12 +50,16 @@ nacl_window_create(struct wcore_platform *wc_plat,
>                     int height)
>  {
>      struct nacl_window *self;
> +    struct nacl_platform *nplat = nacl_platform(wc_plat);
>      bool ok = true;
>  
>      self = wcore_calloc(sizeof(*self));
>      if (self == NULL)
>          return NULL;
>  
> +    // Set requested dimensions for the backing surface.
> +    nacl_resize(nplat->nacl, width, height);
> +
>      ok = wcore_window_init(&self->wcore, wc_config);
>      if (!ok)
>          goto error;
> @@ -80,7 +84,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);

When this function returns false, it needs to emit an error explaining why.
If it's difficult to discover why, then it's always acceptable to emit the
error like this
    wcore_error(WAFFLE_ERROR_UNKNOWN)
or like this
    wcore_errorf(WAFFLE_ERROR_UNKNOWN, "pp::Graphics3D::ResizeBuffers failed")

>  }
>  
>  bool
> diff --git a/src/waffle/nacl/nacl_window.h b/src/waffle/nacl/nacl_window.h
> index 5f0906d..9bbbb29 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;
> 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 884 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freedesktop.org/archives/waffle/attachments/20150202/862c22b7/attachment.sig>


More information about the waffle mailing list