From 6c64b56cc80522c323a39d03d7fb2369350e2470 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 13 Jun 2013 15:37:13 +0200 Subject: [PATCH 1/2] Platform: redirect debug output to JS console in NaClApplication. --- src/Platform/NaClApplication.cpp | 20 ++++++++++++++++++++ src/Platform/NaClApplication.h | 17 +++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/Platform/NaClApplication.cpp b/src/Platform/NaClApplication.cpp index 40906b7df..c00ee9df5 100644 --- a/src/Platform/NaClApplication.cpp +++ b/src/Platform/NaClApplication.cpp @@ -27,16 +27,35 @@ #include #include #include +#include #include "Context.h" namespace Magnum { namespace Platform { +struct NaClApplication::ConsoleDebugOutput { + explicit ConsoleDebugOutput(pp::Instance* instance); + + Utility::NaClConsoleStreamBuffer debugBuffer, warningBuffer, errorBuffer; + std::ostream debugOutput, warningOutput, errorOutput; +}; + +NaClApplication::ConsoleDebugOutput::ConsoleDebugOutput(pp::Instance* instance): debugBuffer(instance, Utility::NaClConsoleStreamBuffer::LogLevel::Log), warningBuffer(instance, Utility::NaClConsoleStreamBuffer::LogLevel::Warning), errorBuffer(instance, Utility::NaClConsoleStreamBuffer::LogLevel::Error), debugOutput(&debugBuffer), warningOutput(&warningBuffer), errorOutput(&errorBuffer) { + /* Inform about this change on standard output */ + Debug() << "Platform::NaClApplication: redirecting Debug, Warning and Error output to JavaScript console"; + + Debug::setOutput(&debugOutput); + Warning::setOutput(&warningOutput); + Error::setOutput(&errorOutput); +} + NaClApplication::NaClApplication(const Arguments& arguments): Instance(arguments), Graphics3DClient(this), MouseLock(this), c(nullptr) { + debugOutput = new ConsoleDebugOutput(this); createContext(new Configuration); } NaClApplication::NaClApplication(const Arguments& arguments, Configuration* configuration): Instance(arguments), Graphics3DClient(this), MouseLock(this), graphics(nullptr), fullscreen(nullptr), c(nullptr) { + debugOutput = new ConsoleDebugOutput(this); if(configuration) createContext(configuration); } @@ -95,6 +114,7 @@ NaClApplication::~NaClApplication() { delete c; delete fullscreen; delete graphics; + delete debugOutput; } bool NaClApplication::isFullscreen() { diff --git a/src/Platform/NaClApplication.h b/src/Platform/NaClApplication.h index 09772f9a8..289b12f0c 100644 --- a/src/Platform/NaClApplication.h +++ b/src/Platform/NaClApplication.h @@ -70,6 +70,19 @@ MAGNUM_NACLAPPLICATION_MAIN(MyApplication) If no other application header is included this class is also aliased to `Platform::Application` and the macro is aliased to `MAGNUM_APPLICATION_MAIN()` to simplify porting. + +@section NaClApplication-html HTML markup and NMF file + +You need to provide HTML markup containing `<embed>` pointing to `*.nmf` +file describing the application. + +@todoc Document this better, add "bootstrap" examples + +@subsection NaClApplication-html-console Redirecting output to Chrome's JavaScript console + +The application redirects @ref Debug, @ref Warning and @ref Error output to +JavaScript console. See also @ref Corrade::Utility::NaClConsoleStreamBuffer for +more information. */ class NaClApplication: public pp::Instance, public pp::Graphics3DClient, public pp::MouseLock { public: @@ -210,6 +223,8 @@ class NaClApplication: public pp::Instance, public pp::Graphics3DClient, public /*@}*/ private: + struct ConsoleDebugOutput; + enum class Flag: UnsignedByte { ViewportUpdated = 1 << 0, SwapInProgress = 1 << 1, @@ -241,6 +256,8 @@ class NaClApplication: public pp::Instance, public pp::Graphics3DClient, public Vector2i viewportSize; Flags flags; + ConsoleDebugOutput* debugOutput; + CORRADE_ENUMSET_FRIEND_OPERATORS(Flags) }; From 902b368207002ba1bdb79e609ada370bc78e5f9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 13 Jun 2013 15:37:42 +0200 Subject: [PATCH 2/2] Platform: fixed copypaste error. --- src/Platform/NaClApplication.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Platform/NaClApplication.h b/src/Platform/NaClApplication.h index 289b12f0c..ed33f57b2 100644 --- a/src/Platform/NaClApplication.h +++ b/src/Platform/NaClApplication.h @@ -61,7 +61,7 @@ You need to implement at least drawEvent() and viewportEvent() to be able to draw on the screen. The subclass must be then registered to NaCl API using MAGNUM_NACLAPPLICATION_MAIN() macro. @code -class MyApplication: public Magnum::Platform::Sdl2Application { +class MyApplication: public Magnum::Platform::NaClApplication { // implement required methods... }; MAGNUM_NACLAPPLICATION_MAIN(MyApplication)