Implementation for nacl is somewhat different as for other platforms, platform needs to ensure that the previous swap has finished before issuing another one. This is done by introducing a worker thread that does buffer swaps from a work queue.
Signed-off-by: Tapani Pälli <tapani.pa...@intel.com> --- src/waffle/nacl/nacl_container.cpp | 20 +++++++++++ src/waffle/nacl/nacl_container.h | 1 + src/waffle/nacl/nacl_swap_thread.h | 72 ++++++++++++++++++++++++++++++++++++++ src/waffle/nacl/nacl_window.c | 3 +- 4 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 src/waffle/nacl/nacl_swap_thread.h diff --git a/src/waffle/nacl/nacl_container.cpp b/src/waffle/nacl/nacl_container.cpp index abd64fd..4ea3f2a 100644 --- a/src/waffle/nacl/nacl_container.cpp +++ b/src/waffle/nacl/nacl_container.cpp @@ -28,11 +28,13 @@ #include "ppapi/cpp/module.h" #include "ppapi/c/pp_errors.h" #include "nacl_container.h" +#include "nacl_swap_thread.h" namespace waffle { struct nacl_container { pp::Graphics3D ctx; + NaclSwapThread *swapper; bool (*glInitializePPAPI) (PPB_GetInterface); void (*glSetCurrentContextPPAPI) (PP_Resource); @@ -48,6 +50,7 @@ nacl_container_dtor(waffle::nacl_container *nc) nc->glSetCurrentContextPPAPI(0); nc->glTerminatePPAPI(); + delete nc->swapper; delete nc; } @@ -123,6 +126,7 @@ nacl_context_init(waffle::nacl_container *nc, struct nacl_config *cfg) return false; } + nc->swapper = new NaclSwapThread(pp_instance, nc->ctx); return true; } @@ -145,6 +149,15 @@ nacl_makecurrent(waffle::nacl_container *nc) return true; } +static bool +nacl_swapbuffers(waffle::nacl_container *nc) +{ + if (!nc) + return false; + + return nc->swapper->swap(); +} + }; // namespace waffle ends extern "C" struct nacl_container* @@ -180,3 +193,10 @@ nacl_makecurrent(nacl_container *nc) return waffle::nacl_makecurrent( reinterpret_cast<waffle::nacl_container*>(nc)); } + +extern "C" bool +nacl_swapbuffers(nacl_container *nc) +{ + return waffle::nacl_swapbuffers( + reinterpret_cast<waffle::nacl_container*>(nc)); +} diff --git a/src/waffle/nacl/nacl_container.h b/src/waffle/nacl/nacl_container.h index 5341141..35e848a 100644 --- a/src/waffle/nacl/nacl_container.h +++ b/src/waffle/nacl/nacl_container.h @@ -42,6 +42,7 @@ 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); bool nacl_makecurrent(struct nacl_container *nc); +bool nacl_swapbuffers(struct nacl_container *nc); #ifdef __cplusplus }; diff --git a/src/waffle/nacl/nacl_swap_thread.h b/src/waffle/nacl/nacl_swap_thread.h new file mode 100644 index 0000000..e735c8e --- /dev/null +++ b/src/waffle/nacl/nacl_swap_thread.h @@ -0,0 +1,72 @@ +// 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 "ppapi/cpp/instance.h" + +#include "ppapi/utility/completion_callback_factory.h" +#include "ppapi/utility/threading/simple_thread.h" + + +// Thread takes care that we do not issue another buffer +// swap before previous swap has completed. +class NaclSwapThread : public pp::SimpleThread +{ +public: + explicit NaclSwapThread(const pp::InstanceHandle& instance, + const pp::Graphics3D &_ctx) : + pp::SimpleThread(instance), + ctx(_ctx), + cbf(this) + { + Start(); + } + + ~NaclSwapThread() + { + message_loop().PostQuit(true); + } + + bool swap() + { + pp::CompletionCallback cb = + cbf.NewCallback(&NaclSwapThread::swap_buffers); + + if (message_loop().PostWork(cb) != PP_OK) + return false; + + return true; + } + +private: + + void swap_buffers(int32_t result) + { + ctx.SwapBuffers(pp::BlockUntilComplete()); + } + + pp::Graphics3D ctx; + pp::CompletionCallbackFactory<NaclSwapThread> cbf; +}; diff --git a/src/waffle/nacl/nacl_window.c b/src/waffle/nacl/nacl_window.c index eef1d1d..009e940 100644 --- a/src/waffle/nacl/nacl_window.c +++ b/src/waffle/nacl/nacl_window.c @@ -91,5 +91,6 @@ nacl_window_resize(struct wcore_window *wc_self, bool nacl_window_swap_buffers(struct wcore_window *wc_self) { - return false; + struct nacl_platform *plat = nacl_platform(wc_self->display->platform); + return nacl_swapbuffers(plat->nacl); } -- 2.1.0 _______________________________________________ waffle mailing list waffle@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/waffle