diff options
author | noelallen@chromium.org <noelallen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-24 19:30:41 +0000 |
---|---|---|
committer | noelallen@chromium.org <noelallen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-24 19:30:41 +0000 |
commit | a97cac0d9372c411c9832a1cc5c7452bda387efa (patch) | |
tree | 23a308b104826d6343dca20c38bd929f1069a40f | |
parent | 9f9cb33460ef5de2cc854feb9e20162df541a4bd (diff) | |
download | chromium_src-a97cac0d9372c411c9832a1cc5c7452bda387efa.zip chromium_src-a97cac0d9372c411c9832a1cc5c7452bda387efa.tar.gz chromium_src-a97cac0d9372c411c9832a1cc5c7452bda387efa.tar.bz2 |
Add 2D instance to ppapi_main library.
Adds functionality for 2D applications.
Move common render, build context functions to instance.
Move mouselock and fullscreen to instance
This cleanup is required to re-create the Demo apps
BUG=164959
Review URL: https://codereview.chromium.org/13907006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@196202 0039d316-1c4b-4281-b951-d872f2087c98
10 files changed, 328 insertions, 168 deletions
diff --git a/native_client_sdk/src/examples/hello_world_instance3d/example.dsc b/native_client_sdk/src/examples/hello_world_instance3d/example.dsc index 4180cad..2c2d881 100644 --- a/native_client_sdk/src/examples/hello_world_instance3d/example.dsc +++ b/native_client_sdk/src/examples/hello_world_instance3d/example.dsc @@ -9,7 +9,8 @@ '-I../../src', '-I../../src/ppapi/lib/gl' ], - 'LIBS': ['ppapi_main', 'nacl_io', 'ppapi_gles2', 'ppapi_cpp', 'ppapi', + 'DEPS': ['ppapi_main', 'nacl_io'], + 'LIBS': ['ppapi_gles2', 'ppapi_cpp', 'ppapi', 'pthread'] } ], diff --git a/native_client_sdk/src/examples/hello_world_instance3d/hello_world.cc b/native_client_sdk/src/examples/hello_world_instance3d/hello_world.cc index 9a86d94..6aea13f 100644 --- a/native_client_sdk/src/examples/hello_world_instance3d/hello_world.cc +++ b/native_client_sdk/src/examples/hello_world_instance3d/hello_world.cc @@ -210,7 +210,7 @@ void ProcessEvent(PPAPIEvent* event) { } } -void PPAPIRender(uint32_t width, uint32_t height) { +void PPAPIRender(PP_Resource ctx, uint32_t width, uint32_t height) { if (!g_Ready) { if (g_Loaded) { InitProgram(); diff --git a/native_client_sdk/src/libraries/ppapi_main/library.dsc b/native_client_sdk/src/libraries/ppapi_main/library.dsc index 3386c5a..366fde4 100644 --- a/native_client_sdk/src/libraries/ppapi_main/library.dsc +++ b/native_client_sdk/src/libraries/ppapi_main/library.dsc @@ -6,6 +6,7 @@ 'TYPE' : 'lib', 'SOURCES' : [ "ppapi_instance.cc", + "ppapi_instance2d.cc", "ppapi_instance3d.cc", "ppapi_main.cc", "ppapi_queue.cc", @@ -17,6 +18,7 @@ 'FILES': [ "ppapi_event.h", "ppapi_instance.h", + "ppapi_instance2d.h", "ppapi_instance3d.h", "ppapi_main.h", "ppapi_queue.h", diff --git a/native_client_sdk/src/libraries/ppapi_main/ppapi_instance.cc b/native_client_sdk/src/libraries/ppapi_main/ppapi_instance.cc index b9b5132..2816c74 100644 --- a/native_client_sdk/src/libraries/ppapi_main/ppapi_instance.cc +++ b/native_client_sdk/src/libraries/ppapi_main/ppapi_instance.cc @@ -40,31 +40,67 @@ struct StartInfo { const char** argv_; }; -void* PPAPIInstance::StartMain(void *info) { - StartInfo* si = static_cast<StartInfo*>(info); - si->inst_->main_loop_.AttachToCurrentThread(); - if (NULL != info) { - ppapi_main(si->argc_, si->argv_); +// +// The starting point for 'main'. We create this thread to hide the real +// main pepper thread which must never be blocked. +// +void* PPAPIInstance::MainThreadThunk(void *info) { + StartInfo* si = static_cast<StartInfo*>(info); + int ret = si->inst_->MainThread(si->argc_, si->argv_); - for (uint32_t i = 0; i < si->argc_; i++) { - delete[] si->argv_[i]; - } - delete[] si->argv_; - delete si; - } - else { - const char *argv[] = { "NEXE", NULL }; - ppapi_main(1, argv); + printf("Main thread returned with %d.\n", ret); + for (uint32_t i = 0; i < si->argc_; i++) { + delete[] si->argv_[i]; } + delete[] si->argv_; + delete si; + + return NULL; +} + +// +// Enabled with pm_use_main=False this creates a second thread where we +// send all input, view change, buffer swap, etc... messages. This allows us +// avoid blocking the main pepper thread which would otherwise recieves these +// messages, and may need to lock to act on them. +// +void *PPAPIInstance::EventThreadThunk(void *this_ptr) { + PPAPIInstance *pInst = static_cast<PPAPIInstance*>(this_ptr); + return pInst->EventThread(); +} + + +// +// The default implementation supports running a 'C' main. +// +int PPAPIInstance::MainThread(int argc, const char *argv[]) { + return ppapi_main(argc, argv); +} + +// +// The default implementation just waits to processes forwarded events. +// +void* PPAPIInstance::EventThread() { + render_loop_.AttachToCurrentThread(); + render_loop_.Run(); + printf("Event thread exiting.\n"); return NULL; } + PPAPIInstance::PPAPIInstance(PP_Instance instance, const char *args[]) : pp::Instance(instance), main_loop_(this), - has_focus_(false) { + has_focus_(false), + fullscreen_(this), + is_context_bound_(false), + callback_factory_(this), + use_main_thread_(true), + render_loop_(this) { + + // Place PPAPI_MAIN_USE arguments into properties map while (*args) { std::string key = *args++; std::string val = *args++; @@ -77,20 +113,28 @@ PPAPIInstance::PPAPIInstance(PP_Instance instance, const char *args[]) PP_INPUTEVENT_CLASS_TOUCH); } -PPAPIInstance::~PPAPIInstance() { -} +PPAPIInstance::~PPAPIInstance() {} + bool PPAPIInstance::Init(uint32_t arg, const char* argn[], const char* argv[]) { StartInfo* si = new StartInfo; + si->inst_ = this; si->argc_ = 1; si->argv_ = new const char *[arg*2+1]; si->argv_[0] = NULL; + // Process arguments passed into Module INIT from JavaScript for (uint32_t i=0; i < arg; i++) { + if (argv[i]) { + printf("ARG %s=%s\n", argn[i], argv[i]); + } else { + printf("ARG %s\n", argn[i]); + } + // If we start with PM prefix set the instance argument map if (0 == strncmp(argn[i], "pm_", 3)) { std::string key = argn[i]; @@ -128,9 +172,10 @@ bool PPAPIInstance::Init(uint32_t arg, si->argv_[0] = name; } + if (ProcessProperties()) { pthread_t main_thread; - int ret = pthread_create(&main_thread, NULL, StartMain, + int ret = pthread_create(&main_thread, NULL, MainThreadThunk, static_cast<void*>(si)); return ret == 0; } @@ -152,13 +197,13 @@ bool PPAPIInstance::ProcessProperties() { const char* stderr_path = GetProperty("pm_stderr", "/dev/console3"); const char* queue_size = GetProperty("pm_queue_size", "1024"); - // Force a minimum size of 4 + // Build the event Queue with a minimum size of 4 uint32_t queue_size_int = atoi(queue_size); if (queue_size_int < 4) queue_size_int = 4; event_queue_.SetSize(queue_size_int); + // Enable NaCl IO to map STDIN, STDOUT, and STDERR nacl_io_init_ppapi(PPAPI_GetInstanceId(), PPAPI_GetInterface); - int fd0 = open(stdin_path, O_RDONLY); dup2(fd0, 0); @@ -170,11 +215,23 @@ bool PPAPIInstance::ProcessProperties() { setvbuf(stderr, NULL, _IOLBF, 0); setvbuf(stdout, NULL, _IOLBF, 0); + + const char *use_main_str = GetProperty("pm_use_main", "true"); + use_main_thread_ = !strcasecmp(use_main_str, "true"); + + // Create seperate thread for processing events. + printf("Events on main thread = %s.\n", use_main_str); + if (!use_main_thread_) { + pthread_t event_thread; + int ret = pthread_create(&event_thread, NULL, EventThreadThunk, + static_cast<void*>(this)); + return ret == 0; + } return true; } -void PPAPIInstance::HandleMessage(const pp::Var& message) {} - +void PPAPIInstance::HandleMessage(const pp::Var& message) { +} bool PPAPIInstance::HandleInputEvent(const pp::InputEvent& event) { PPAPIEvent* event_ptr; @@ -266,9 +323,53 @@ void PPAPIInstance::ReleaseInputEvent(PPAPIEvent* event) { event_queue_.ReleaseTopMessage(event); } -void PPAPIInstance::DidChangeView(const pp::View&) { +void PPAPIInstance::DidChangeView(const pp::View& view) { + pp::Size new_size = view.GetRect().size(); + printf("View changed: %dx%d\n", new_size.width(), new_size.height()); + + // Build or update the 3D context when the view changes. + if (use_main_thread_) { + // If using the main thread, update the context immediately + BuildContext(0, new_size); + } else { + // If using a seperate thread, then post the message so we can build the + // context on the correct thread. + render_loop_.PostWork(callback_factory_.NewCallback( + &PPAPIInstance::BuildContext, new_size)); + } } void PPAPIInstance::DidChangeFocus(bool focus) { has_focus_ = focus; } + +bool PPAPIInstance::ToggleFullscreen() { + // Ignore switch if in transition + if (!is_context_bound_) + return false; + + if (fullscreen_.IsFullscreen()) { + if (!fullscreen_.SetFullscreen(false)) { + printf("Could not leave fullscreen mode\n"); + return false; + } + } else { + if (!fullscreen_.SetFullscreen(true)) { + printf("Could not enter fullscreen mode\n"); + return false; + } + } + return true; +} + +// The default implementation calls the 'C' render function. +void PPAPIInstance::Render(PP_Resource ctx, uint32_t width, uint32_t height) { +} + +void PPAPIInstance::Flushed(int32_t result) { +} + +void PPAPIInstance::BuildContext(int32_t result, const pp::Size& new_size) { + size_ = new_size; + printf("Resized: %dx%d.\n", size_.width(), size_.height()); +} diff --git a/native_client_sdk/src/libraries/ppapi_main/ppapi_instance.h b/native_client_sdk/src/libraries/ppapi_main/ppapi_instance.h index 47be29b..1172cd8 100644 --- a/native_client_sdk/src/libraries/ppapi_main/ppapi_instance.h +++ b/native_client_sdk/src/libraries/ppapi_main/ppapi_instance.h @@ -11,10 +11,14 @@ #include "ppapi/cpp/fullscreen.h" #include "ppapi/cpp/instance.h" #include "ppapi/cpp/message_loop.h" +#include "ppapi/cpp/mouse_lock.h" + +#include "ppapi/utility/completion_callback_factory.h" #include "ppapi_main/ppapi_event.h" #include "ppapi_main/ppapi_queue.h" + typedef std::map<std::string, std::string> PropertyMap_t; class PPAPIInstance : public pp::Instance { @@ -22,6 +26,10 @@ class PPAPIInstance : public pp::Instance { PPAPIInstance(PP_Instance instance, const char *args[]); virtual ~PPAPIInstance(); + // + // Callback functions triggered by Pepepr + // + // Called by the browser when the NaCl module is loaded and all ready to go. virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]); @@ -37,30 +45,61 @@ class PPAPIInstance : public pp::Instance { // Called by the browser to handle incoming input events. virtual bool HandleInputEvent(const pp::InputEvent& event); - // Accessors for the PPAPIQueue object. Use Acquire to fetch the top - // event if one is available, then release when done. Events must be - // acquired and released one at a time. + // Called when the graphics flush completes + virtual void Flushed(int result); + + // Called when we need to rebuild the Graphics device context. This usually + // happens as a result of DidChangeView. + virtual void BuildContext(int32_t result, const pp::Size& new_size); + + // Called with the current graphics context, current size and width, when + // the application is ready to render, either due to a newly build + // Context, or a successful Flush of the previous frame. + virtual void Render(PP_Resource ctx, uint32_t width, uint32_t height); + + // + // Thread entry points + // + virtual int MainThread(int argc, const char* argv[]); + virtual void* EventThread(); + + // + // Request API + // + bool ToggleFullscreen(); virtual PPAPIEvent* AcquireInputEvent(); virtual void ReleaseInputEvent(PPAPIEvent* event); - static PPAPIInstance* GetInstance(); protected: - // Called to launch ppapi_main - static void* StartMain(void *start_info); + // Called to run ppapi_main. + static void* MainThreadThunk(void *start_info); + + // Called if message processing and rendering happens off the main thread. + static void* EventThreadThunk(void *this_ptr); // Called by Init to processes default and embed tag arguments prior to // launching the 'ppapi_main' thread. virtual bool ProcessProperties(); - // Returns value based on KEY or default + // Returns value based on KEY or default. const char* GetProperty(const char* key, const char* def = NULL); - private: + protected: pp::MessageLoop main_loop_; + pp::Fullscreen fullscreen_; + pp::MessageLoop render_loop_; + pp::CompletionCallbackFactory<PPAPIInstance> callback_factory_; + PropertyMap_t properties_; PPAPIQueue event_queue_; + + pp::Size size_; bool has_focus_; + bool is_context_bound_; + bool was_fullscreen_; + bool mouse_locked_; + bool use_main_thread_; }; diff --git a/native_client_sdk/src/libraries/ppapi_main/ppapi_instance2d.cc b/native_client_sdk/src/libraries/ppapi_main/ppapi_instance2d.cc new file mode 100644 index 0000000..f6e54be --- /dev/null +++ b/native_client_sdk/src/libraries/ppapi_main/ppapi_instance2d.cc @@ -0,0 +1,87 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include <stdio.h> + +#include "ppapi/cpp/graphics_2d.h" +#include "ppapi/cpp/message_loop.h" +#include "ppapi/cpp/size.h" +#include "ppapi/cpp/var.h" + +#include "ppapi/utility/completion_callback_factory.h" + +#include "ppapi_main/ppapi_instance2d.h" +#include "ppapi_main/ppapi_main.h" + + +void* PPAPI_CreateInstance2D(PP_Instance inst, const char *args[]) { + return static_cast<void*>(new PPAPIInstance2D(inst, args)); +} + + +PPAPIInstance2D* PPAPIInstance2D::GetInstance2D() { + return static_cast<PPAPIInstance2D*>(PPAPI_GetInstanceObject()); +} + + +void PPAPIInstance2D::Flushed(int result) { + if (result != 0) { + printf("Flush result=%d.\n", result); + } + + if (is_context_bound_) { + Render(device_context_.pp_resource(), size_.width(), size_.height()); + + int result; + result = device_context_.Flush(callback_factory_.NewCallback( + &PPAPIInstance::Flushed)); + if (result == PP_OK_COMPLETIONPENDING) return; + printf("Failed Flush with %d.\n", result); + } + + // Failed to draw, so add a callback for the future. This could + // an application choice or the browser dealing with an event such as + // fullscreen toggle. We add a delay of 100ms (to prevent burnning CPU + // in cases where the context will not be available for a while. + pp::MessageLoop::GetCurrent().PostWork(callback_factory_.NewCallback( + &PPAPIInstance::Flushed), 100); +} + +void PPAPIInstance2D::BuildContext(int32_t result, const pp::Size& new_size) { + printf("Building context.\n"); + + size_ = new_size; + device_context_ = pp::Graphics2D(this, size_ ,true); + printf("Got Context!\n"); + + is_context_bound_ = BindGraphics(device_context_); + printf("Context is bound=%d\n", is_context_bound_); + + if (is_context_bound_) { + PPAPIBuildContext(size_.width(), size_.height()); + device_context_.Flush(callback_factory_.NewCallback( + &PPAPIInstance::Flushed)); + } else { + fprintf(stderr, "Failed to bind context for %dx%d.\n", size_.width(), + size_.height()); + } +} + +// The default implementation calls the 'C' render function. +void PPAPIInstance2D::Render(PP_Resource ctx, uint32_t width, + uint32_t height) { + PPAPIRender(ctx, width, height); +} + +PPAPIInstance2D::PPAPIInstance2D(PP_Instance instance, const char *args[]) + : PPAPIInstance(instance, args) { +} + + +PPAPIInstance2D::~PPAPIInstance2D() { + if (is_context_bound_) { + is_context_bound_ = false; + // Cleanup code? + } +} diff --git a/native_client_sdk/src/libraries/ppapi_main/ppapi_instance2d.h b/native_client_sdk/src/libraries/ppapi_main/ppapi_instance2d.h new file mode 100644 index 0000000..ac600c2 --- /dev/null +++ b/native_client_sdk/src/libraries/ppapi_main/ppapi_instance2d.h @@ -0,0 +1,36 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_MAIN_PPAPI_INSTANCE2D_H_ +#define PPAPI_MAIN_PPAPI_INSTANCE2D_H_ + +#include "ppapi/c/pp_instance.h" + +#include "ppapi/cpp/graphics_2d.h" +#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/size.h" + +#include "ppapi_main/ppapi_instance.h" + + +class PPAPIInstance2D : public PPAPIInstance { + public: + PPAPIInstance2D(PP_Instance instance, const char *args[]); + virtual ~PPAPIInstance2D(); + + // Called when we need to rebuild the context + virtual void BuildContext(int32_t result, const pp::Size& new_size); + + // Called whenever a swap takes place + virtual void Flushed(int result); + + virtual void Render(PP_Resource ctx, uint32_t width, uint32_t height); + static PPAPIInstance2D* GetInstance2D(); + + protected: + pp::Graphics2D device_context_; +}; + + +#endif // PPAPI_MAIN_PPAPI_INSTANCE2D_H_ diff --git a/native_client_sdk/src/libraries/ppapi_main/ppapi_instance3d.cc b/native_client_sdk/src/libraries/ppapi_main/ppapi_instance3d.cc index 60fa1d2..3ff74a69 100644 --- a/native_client_sdk/src/libraries/ppapi_main/ppapi_instance3d.cc +++ b/native_client_sdk/src/libraries/ppapi_main/ppapi_instance3d.cc @@ -2,30 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <fcntl.h> -#include <pthread.h> #include <stdio.h> -#include <string.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> -#include <cstdlib> -#include <cstring> -#include <map> -#include <string> -#include <vector> - -#include "nacl_io/nacl_io.h" - -#include "ppapi/cpp/fullscreen.h" #include "ppapi/cpp/graphics_3d.h" -#include "ppapi/cpp/input_event.h" -#include "ppapi/cpp/message_loop.h" -#include "ppapi/cpp/mouse_lock.h" -#include "ppapi/cpp/rect.h" #include "ppapi/cpp/size.h" -#include "ppapi/cpp/var.h" #include "ppapi/lib/gl/gles2/gl2ext_ppapi.h" #include "ppapi/lib/gl/include/GLES2/gl2.h" @@ -37,9 +17,6 @@ #include "ppapi_main/ppapi_main.h" -static const uint32_t kReturnKeyCode = 13; - - void* PPAPI_CreateInstance3D(PP_Instance inst, const char *args[]) { return static_cast<void*>(new PPAPIInstance3D(inst, args)); } @@ -75,32 +52,27 @@ PPAPIInstance3D* PPAPIInstance3D::GetInstance3D() { return static_cast<PPAPIInstance3D*>(PPAPI_GetInstanceObject()); } - -void *PPAPIInstance3D::RenderLoop(void *this_ptr) { - PPAPIInstance3D *pInst = static_cast<PPAPIInstance3D*>(this_ptr); - pInst->render_loop_.AttachToCurrentThread(); - pInst->render_loop_.Run(); - return NULL; -} - - -void PPAPIInstance3D::Swapped(int result) { +void PPAPIInstance3D::Flushed(int result) { if (result != 0) { printf("Swapped result=%d.\n", result); } if (is_context_bound_) { - PPAPIRender(size_.width(), size_.height()); + Render(device_context_.pp_resource(), size_.width(), size_.height()); + int result; result = device_context_.SwapBuffers(callback_factory_.NewCallback( - &PPAPIInstance3D::Swapped)); + &PPAPIInstance::Flushed)); if (result == PP_OK_COMPLETIONPENDING) return; printf("Failed swap with %d.\n", result); } - // Failed to draw, so add a callback for the future. + // Failed to draw, so add a callback for the future. This could + // an application choice or the browser dealing with an event such as + // fullscreen toggle. We add a delay of 100ms (to prevent burnning CPU + // in cases where the context will not be available for a while. pp::MessageLoop::GetCurrent().PostWork(callback_factory_.NewCallback( - &PPAPIInstance3D::Swapped), 100); + &PPAPIInstance::Flushed), 100); } void PPAPIInstance3D::BuildContext(int32_t result, const pp::Size& new_size) { @@ -146,22 +118,21 @@ void PPAPIInstance3D::BuildContext(int32_t result, const pp::Size& new_size) { if (is_context_bound_) { PPAPIBuildContext(size_.width(), size_.height()); device_context_.SwapBuffers(callback_factory_.NewCallback( - &PPAPIInstance3D::Swapped)); + &PPAPIInstance::Flushed)); } else { fprintf(stderr, "Failed to bind context for %dx%d.\n", size_.width(), size_.height()); } } +// The default implementation calls the 'C' render function. +void PPAPIInstance3D::Render(PP_Resource ctx, uint32_t width, + uint32_t height) { + PPAPIRender(ctx, width, height); +} + PPAPIInstance3D::PPAPIInstance3D(PP_Instance instance, const char *args[]) - : PPAPIInstance(instance, args), - mouse_locked_(false), - callback_factory_(this), - fullscreen_(this), - is_context_bound_(false), - was_fullscreen_(false), - render_loop_(this), - main_thread_3d_(true) { + : PPAPIInstance(instance, args) { glInitializePPAPI(pp::Module::Get()->get_browser_interface()); } @@ -172,61 +143,3 @@ PPAPIInstance3D::~PPAPIInstance3D() { // Cleanup code? } } - -bool PPAPIInstance3D::Init(uint32_t arg, - const char* argn[], - const char* argv[]) { - if (!PPAPIInstance::Init(arg, argn, argv)) { - return false; - } - - for (uint32_t a=0; a < arg; a++) { - printf("%s=%s\n", argn[a], argv[a]); - } - - const char *use_main = GetProperty("pm_main3d", "true"); - main_thread_3d_ = !strcasecmp(use_main, "true"); - printf("Using 3D on main thread = %s.\n", use_main); - if (!main_thread_3d_) { - pthread_t render_thread; - int ret = pthread_create(&render_thread, NULL, RenderLoop, - static_cast<void*>(this)); - return ret == 0; - } - return true; -} - -void PPAPIInstance3D::DidChangeView(const pp::View& view) { - pp::Size new_size = view.GetRect().size(); - printf("View changed: %dx%d\n", new_size.width(), new_size.height()); - - // Build or update the 3D context when the view changes. - if (main_thread_3d_) { - // If using the main thread, update the context immediately - BuildContext(0, new_size); - } else { - // If using a seperate thread, then post the message so we can build the - // context on the correct thread. - render_loop_.PostWork(callback_factory_.NewCallback( - &PPAPIInstance3D::BuildContext, new_size)); - } -} - -bool PPAPIInstance3D::ToggleFullscreen() { - // Ignore switch if in transition - if (!is_context_bound_) - return false; - - if (fullscreen_.IsFullscreen()) { - if (!fullscreen_.SetFullscreen(false)) { - printf("Could not leave fullscreen mode\n"); - return false; - } - } else { - if (!fullscreen_.SetFullscreen(true)) { - printf("Could not enter fullscreen mode\n"); - return false; - } - } - return true; -} diff --git a/native_client_sdk/src/libraries/ppapi_main/ppapi_instance3d.h b/native_client_sdk/src/libraries/ppapi_main/ppapi_instance3d.h index 8c392809..410b952 100644 --- a/native_client_sdk/src/libraries/ppapi_main/ppapi_instance3d.h +++ b/native_client_sdk/src/libraries/ppapi_main/ppapi_instance3d.h @@ -8,13 +8,11 @@ #include <map> #include "ppapi/c/pp_instance.h" -#include "ppapi/cpp/fullscreen.h" +#include "ppapi/c/pp_resource.h" + #include "ppapi/cpp/graphics_3d.h" -#include "ppapi/cpp/input_event.h" #include "ppapi/cpp/instance.h" -#include "ppapi/cpp/message_loop.h" -#include "ppapi/cpp/mouse_lock.h" -#include "ppapi/utility/completion_callback_factory.h" +#include "ppapi/cpp/size.h" #include "ppapi_main/ppapi_instance.h" @@ -24,35 +22,18 @@ class PPAPIInstance3D : public PPAPIInstance { PPAPIInstance3D(PP_Instance instance, const char *args[]); virtual ~PPAPIInstance3D(); - // Called during initialization - virtual bool Init(uint32_t arg, const char* argn[], const char* argv[]); - - // Called whenever the in-browser window changes size. - virtual void DidChangeView(const pp::View& view); - // Called when we need to rebuild the context virtual void BuildContext(int32_t result, const pp::Size& new_size); // Called whenever a swap takes place - virtual void Swapped(int result); - - // Toggle in and out of Fullscreen mode - virtual bool ToggleFullscreen(); + virtual void Flushed(int result); + virtual void Render(PP_Resource ctx, uint32_t width, uint32_t height); static PPAPIInstance3D* GetInstance3D(); protected: - static void *RenderLoop(void *this_ptr); - - pp::CompletionCallbackFactory<PPAPIInstance3D> callback_factory_; - pp::Fullscreen fullscreen_; pp::Graphics3D device_context_; - pp::Size size_; - pp::MessageLoop render_loop_; - bool is_context_bound_; - bool was_fullscreen_; - bool mouse_locked_; - bool main_thread_3d_; + }; diff --git a/native_client_sdk/src/libraries/ppapi_main/ppapi_main.h b/native_client_sdk/src/libraries/ppapi_main/ppapi_main.h index 9bfe5b5..2f2c4e3 100644 --- a/native_client_sdk/src/libraries/ppapi_main/ppapi_main.h +++ b/native_client_sdk/src/libraries/ppapi_main/ppapi_main.h @@ -33,20 +33,20 @@ void* PPAPI_CreateInstance3D(PP_Instance inst, const char *args[]); PPAPIEvent* PPAPI_AcquireEvent(); void PPAPI_ReleaseEvent(PPAPIEvent* event); - -// Functions for 3D instances +// Functions for Graphic Instances int32_t *PPAPIGet3DAttribs(uint32_t width, uint32_t height); void PPAPIBuildContext(uint32_t width, uint32_t height); -void PPAPIRender(uint32_t width, uint32_t height); +void PPAPIRender(PP_Resource ctx, uint32_t width, uint32_t height); + EXTERN_C_END #define PPAPI_MAIN_DEFAULT_ARGS NULL, NULL -#define PPAPI_MAIN_USE(factory, ...) \ -void* UserCreateInstance(PP_Instance inst) { \ +#define PPAPI_MAIN_USE(factory, ...) \ +void* UserCreateInstance(PP_Instance inst) { \ static const char *params[] = { __VA_ARGS__ }; \ - return factory(inst, params); \ + return factory(inst, params); \ } #define PPAPI_MAIN_WITH_DEFAULT_ARGS \ |