Browse Source

NaClApplication: fullscreen switching support.

pull/7/head
Vladimír Vondruš 14 years ago
parent
commit
97383b8a62
  1. 40
      src/Platform/NaClApplication.cpp
  2. 19
      src/Platform/NaClApplication.h

40
src/Platform/NaClApplication.cpp

@ -16,6 +16,7 @@
#include "NaClApplication.h"
#include <ppapi/cpp/graphics_3d.h>
#include <ppapi/cpp/fullscreen.h>
#include <ppapi/cpp/completion_callback.h>
#include "Context.h"
@ -44,6 +45,8 @@ NaClApplication::NaClApplication(PP_Instance instance, const Math::Vector2<GLsiz
exit(1);
}
fullscreen = new pp::Fullscreen(this);
glSetCurrentContextPPAPI(graphics->pp_resource());
c = new Context;
@ -58,10 +61,44 @@ NaClApplication::NaClApplication(PP_Instance instance, const Math::Vector2<GLsiz
NaClApplication::~NaClApplication() {
delete c;
delete fullscreen;
delete graphics;
}
bool NaClApplication::isFullscreen() {
return fullscreen->IsFullscreen();
}
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<GLsizei> 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()) {

19
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<Flag, std::uint8_t> 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<GLsizei> viewportSize;
Flags flags;

Loading…
Cancel
Save