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

Tapani Pälli tapani.palli at intel.com
Mon Feb 2 23:14:51 PST 2015



On 02/03/2015 01:28 AM, Chad Versace wrote:
> On 01/22/2015 11:59 PM, Tapani Pälli wrote:
>> Signed-off-by: Tapani Pälli <tapani.palli at intel.com>

8<

>> +
>> +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;
> }

Yep, works fine. I will change this and the other functions. I think the 
check for cpp_nc can be also be removed as the container will always be 
there and cast result would be undefined behaviour if it would fail.

>> 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")
>
>>   }

OK, I will add errors codes here.

>>   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;
>>
>
>


More information about the waffle mailing list