Expose a property in display plugins to determine if the device is visble to the user

This commit is contained in:
Brad Davis 2016-03-10 16:58:11 -08:00
parent bbc298f1e4
commit 87c9961aa8
8 changed files with 34 additions and 10 deletions

View file

@ -29,24 +29,26 @@ protected:
using TextureEscrow = GLEscrow<gpu::TexturePointer>; using TextureEscrow = GLEscrow<gpu::TexturePointer>;
public: public:
OpenGLDisplayPlugin(); OpenGLDisplayPlugin();
virtual void activate() override; void activate() override;
virtual void deactivate() override; void deactivate() override;
virtual void stop() override; void stop() override;
virtual bool eventFilter(QObject* receiver, QEvent* event) override; bool eventFilter(QObject* receiver, QEvent* event) override;
bool isDisplayVisible() const override { return true; }
virtual void submitSceneTexture(uint32_t frameIndex, const gpu::TexturePointer& sceneTexture) override;
virtual void submitOverlayTexture(const gpu::TexturePointer& overlayTexture) override;
virtual float presentRate() override;
virtual glm::uvec2 getRecommendedRenderSize() const override { void submitSceneTexture(uint32_t frameIndex, const gpu::TexturePointer& sceneTexture) override;
void submitOverlayTexture(const gpu::TexturePointer& overlayTexture) override;
float presentRate() override;
glm::uvec2 getRecommendedRenderSize() const override {
return getSurfacePixels(); return getSurfacePixels();
} }
virtual glm::uvec2 getRecommendedUiSize() const override { glm::uvec2 getRecommendedUiSize() const override {
return getSurfaceSize(); return getSurfaceSize();
} }
virtual QImage getScreenshot() const override; QImage getScreenshot() const override;
protected: protected:
#if THREADED_PRESENT #if THREADED_PRESENT

View file

@ -22,12 +22,16 @@ public:
glm::uvec2 getRecommendedUiSize() const override final; glm::uvec2 getRecommendedUiSize() const override final;
glm::uvec2 getRecommendedRenderSize() const override final { return _renderTargetSize; } glm::uvec2 getRecommendedRenderSize() const override final { return _renderTargetSize; }
void setEyeRenderPose(uint32_t frameIndex, Eye eye, const glm::mat4& pose) override final; void setEyeRenderPose(uint32_t frameIndex, Eye eye, const glm::mat4& pose) override final;
bool isDisplayVisible() const override { return isHmdMounted(); }
void activate() override; void activate() override;
void deactivate() override; void deactivate() override;
protected: protected:
virtual void hmdPresent() = 0; virtual void hmdPresent() = 0;
virtual bool isHmdMounted() const = 0;
void compositeOverlay() override; void compositeOverlay() override;
void compositePointer() override; void compositePointer() override;
void internalPresent() override; void internalPresent() override;

View file

@ -65,6 +65,12 @@ public:
virtual bool isThrottled() const { return false; } virtual bool isThrottled() const { return false; }
virtual float getTargetFrameRate() { return 0.0f; } virtual float getTargetFrameRate() { return 0.0f; }
/// Returns a boolean value indicating whether the display is currently visible
/// to the user. For monitor displays, false might indicate that a screensaver,
/// or power-save mode is active. For HMDs it may reflect a sensor indicating
/// whether the HMD is being worn
virtual bool isDisplayVisible() const { return false; }
// Rendering support // Rendering support
// Stop requesting renders, but don't do full deactivation // Stop requesting renders, but don't do full deactivation

View file

@ -17,6 +17,7 @@ public:
protected: protected:
void hmdPresent() override {} void hmdPresent() override {}
bool isHmdMounted() const override { return true; }
private: private:
static const QString NAME; static const QString NAME;

View file

@ -24,6 +24,8 @@ public:
protected: protected:
void hmdPresent() override; void hmdPresent() override;
// FIXME update with Oculus API call once it's available in the SDK
bool isHmdMounted() const override { return true; }
void customizeContext() override; void customizeContext() override;
void uncustomizeContext() override; void uncustomizeContext() override;
void updateFrameData() override; void updateFrameData() override;

View file

@ -35,6 +35,7 @@ public:
protected: protected:
virtual void customizeContext() override; virtual void customizeContext() override;
void hmdPresent() override {} void hmdPresent() override {}
bool isHmdMounted() const override { return true; }
#if 0 #if 0
virtual void uncustomizeContext() override; virtual void uncustomizeContext() override;
virtual void internalPresent() override; virtual void internalPresent() override;

View file

@ -139,4 +139,10 @@ void OpenVrDisplayPlugin::hmdPresent() {
vr::TrackedDevicePose_t currentTrackedDevicePose[vr::k_unMaxTrackedDeviceCount]; vr::TrackedDevicePose_t currentTrackedDevicePose[vr::k_unMaxTrackedDeviceCount];
_compositor->WaitGetPoses(currentTrackedDevicePose, vr::k_unMaxTrackedDeviceCount, nullptr, 0); _compositor->WaitGetPoses(currentTrackedDevicePose, vr::k_unMaxTrackedDeviceCount, nullptr, 0);
_hmdActivityLevel = _system->GetTrackedDeviceActivityLevel(vr::k_unTrackedDeviceIndex_Hmd);
} }
bool OpenVrDisplayPlugin::isHmdMounted() const {
return _hmdActivityLevel == vr::k_EDeviceActivityLevel_UserInteraction;
}

View file

@ -33,9 +33,11 @@ public:
protected: protected:
void hmdPresent() override; void hmdPresent() override;
bool isHmdMounted() const override;
private: private:
vr::IVRSystem* _system { nullptr }; vr::IVRSystem* _system { nullptr };
std::atomic<vr::EDeviceActivityLevel> _hmdActivityLevel { vr::k_EDeviceActivityLevel_Unknown };
static const QString NAME; static const QString NAME;
mutable Mutex _poseMutex; mutable Mutex _poseMutex;
}; };