diff --git a/src/Platform/NaClApplication.cpp b/src/Platform/NaClApplication.cpp index 1d0b5583e..a57aae744 100644 --- a/src/Platform/NaClApplication.cpp +++ b/src/Platform/NaClApplication.cpp @@ -16,6 +16,7 @@ #include "NaClApplication.h" #include +#include #include #include "Context.h" @@ -44,6 +45,8 @@ NaClApplication::NaClApplication(PP_Instance instance, const Math::Vector2pp_resource()); c = new Context; @@ -58,10 +61,44 @@ NaClApplication::NaClApplication(PP_Instance instance, const Math::Vector2IsFullscreen(); +} + +bool NaClApplication::setFullscreen(bool enabled) { + /* Given fullscreen mode already set or switching to it is in progress, done */ + if(isFullscreen() == enabled || ((flags & Flag::FullscreenSwitchInProgress) && (flags & Flag::WillBeFullscreen) == enabled)) + return true; + + /* Switch to opposite fullscreen mode is in progress, can't revert it back */ + if((flags & Flag::FullscreenSwitchInProgress) && (flags & Flag::WillBeFullscreen) != enabled) + return false; + + /* Set fullscreen */ + if(!fullscreen->SetFullscreen(enabled)) + return false; + + /* Set flags */ + flags |= Flag::FullscreenSwitchInProgress; + enabled ? flags |= Flag::WillBeFullscreen : flags &= ~Flag::WillBeFullscreen; + return true; +} + void NaClApplication::DidChangeView(const pp::View& view) { + /* Fullscreen switch in progress */ + if(flags & Flag::FullscreenSwitchInProgress) { + /* Done, remove the progress flag */ + if(isFullscreen() == bool(flags & Flag::WillBeFullscreen)) + flags &= ~Flag::FullscreenSwitchInProgress; + + /* Don't process anything during the switch */ + else return; + } + Math::Vector2 size(view.GetRect().width(), view.GetRect().height()); /* Canvas resized */ @@ -81,6 +118,9 @@ void NaClApplication::DidChangeView(const pp::View& view) { } bool NaClApplication::HandleInputEvent(const pp::InputEvent& event) { + /* Don't handle anything during switch from/to fullscreen */ + if(flags & Flag::FullscreenSwitchInProgress) return false; + Flags tmpFlags = flags; switch(event.GetType()) { diff --git a/src/Platform/NaClApplication.h b/src/Platform/NaClApplication.h index 901e928a2..d634924f7 100644 --- a/src/Platform/NaClApplication.h +++ b/src/Platform/NaClApplication.h @@ -34,6 +34,7 @@ namespace pp { class Graphics3D; + class Fullscreen; } namespace Magnum { @@ -78,6 +79,19 @@ class NaClApplication: public pp::Instance, public pp::Graphics3DClient { ~NaClApplication(); + /** @brief Whether the application runs fullscreen */ + bool isFullscreen(); + + /** + * @brief Set fullscreen + * @return `False` if switch to opposite mode is in progress or if the + * switch is not possible, `true` otherwise. + * + * The switch is done asynchronously, during the switch no event + * processing is done. + */ + bool setFullscreen(bool enabled); + protected: /** @{ @name Drawing functions */ @@ -153,7 +167,9 @@ class NaClApplication: public pp::Instance, public pp::Graphics3DClient { enum class Flag: std::uint8_t { ViewportUpdated = 1 << 0, SwapInProgress = 1 << 1, - Redraw = 1 << 2 + Redraw = 1 << 2, + FullscreenSwitchInProgress = 1 << 3, + WillBeFullscreen = 1 << 4 }; typedef Corrade::Containers::EnumSet Flags; @@ -168,6 +184,7 @@ class NaClApplication: public pp::Instance, public pp::Graphics3DClient { static void swapCallback(void* applicationInstance, std::int32_t); pp::Graphics3D* graphics; + pp::Fullscreen* fullscreen; Context* c; Math::Vector2 viewportSize; Flags flags;