Fixed an issue where the fallback screensaver would not fade in correctly.

This commit is contained in:
Leon Styhre 2021-03-18 20:07:07 +01:00
parent 5f727f8c00
commit 60ee29f2ea
4 changed files with 31 additions and 38 deletions

View file

@ -44,6 +44,7 @@ SystemScreensaver::SystemScreensaver(
mMediaSwapTime(0),
mTriggerNextGame(false),
mHasMediaFiles(false),
mFallbackScreensaver(false),
mOpacity(0.0f),
mDimValue(1.0),
mRectangleFadeIn(50),
@ -70,11 +71,17 @@ bool SystemScreensaver::isScreensaverActive()
return (mState != STATE_INACTIVE);
}
bool SystemScreensaver::isFallbackScreensaver()
{
return mFallbackScreensaver;
}
void SystemScreensaver::startScreensaver(bool generateMediaList)
{
std::string path = "";
std::string screensaverType = Settings::getInstance()->getString("ScreensaverType");
mHasMediaFiles = false;
mFallbackScreensaver = false;
mOpacity = 0.0f;
// Keep a reference to the default fonts, so they don't keep getting destroyed/recreated.
@ -253,6 +260,7 @@ void SystemScreensaver::goToGame()
void SystemScreensaver::renderScreensaver()
{
std::string screensaverType = Settings::getInstance()->getString("ScreensaverType");
if (mVideoScreensaver && screensaverType == "video") {
// Render a black background below the video.
Renderer::setMatrix(Transform4x4f::Identity());
@ -309,20 +317,10 @@ void SystemScreensaver::renderScreensaver()
}
}
else {
// If there are no images, fade in a black screen.
#if defined(USE_OPENGL_21)
Renderer::shaderParameters blackParameters;
blackParameters.fragmentDimValue = mDimValue;
Renderer::shaderPostprocessing(Renderer::SHADER_DIM, blackParameters);
#else
Renderer::drawRect(0.0f, 0.0f, Renderer::getScreenWidth(),
Renderer::getScreenHeight(), 0x000000FF, 0x000000FF, mDimValue);
#endif
if (mDimValue > 0.0)
mDimValue = Math::clamp(mDimValue - 0.045f, 0.0f, 1.0f);
mFallbackScreensaver = true;
}
}
if (Settings::getInstance()->getString("ScreensaverType") == "video") {
else if (Settings::getInstance()->getString("ScreensaverType") == "video") {
if (mHasMediaFiles) {
#if defined(USE_OPENGL_21)
Renderer::shaderParameters videoParameters;
@ -370,20 +368,23 @@ void SystemScreensaver::renderScreensaver()
}
}
else {
// If there are no videos, fade in a black screen.
#if defined(USE_OPENGL_21)
Renderer::shaderParameters blackParameters;
blackParameters.fragmentDimValue = mDimValue;
Renderer::shaderPostprocessing(Renderer::SHADER_DIM, blackParameters);
#else
Renderer::drawRect(0.0f, 0.0f, Renderer::getScreenWidth(),
Renderer::getScreenHeight(), 0x000000FF, 0x000000FF, mDimValue);
#endif
if (mDimValue > 0.0)
mDimValue = Math::clamp(mDimValue - 0.045f, 0.0f, 1.0f);
mFallbackScreensaver = true;
}
}
if (mFallbackScreensaver ||
Settings::getInstance()->getString("ScreensaverType") == "black") {
#if defined(USE_OPENGL_21)
Renderer::shaderParameters blackParameters;
blackParameters.fragmentDimValue = mDimValue;
Renderer::shaderPostprocessing(Renderer::SHADER_DIM, blackParameters);
if (mDimValue > 0.0)
mDimValue = Math::clamp(mDimValue - 0.045f, 0.0f, 1.0f);
#else
Renderer::drawRect(0.0f, 0.0f, Renderer::getScreenWidth(),
Renderer::getScreenHeight(), 0x000000FF, 0x000000FF);
#endif
}
else if (Settings::getInstance()->getString("ScreensaverType") == "dim") {
#if defined(USE_OPENGL_21)
Renderer::shaderParameters dimParameters;
@ -400,18 +401,6 @@ void SystemScreensaver::renderScreensaver()
Renderer::getScreenHeight(), 0x000000A0, 0x000000A0);
#endif
}
else if (Settings::getInstance()->getString("ScreensaverType") == "black") {
#if defined(USE_OPENGL_21)
Renderer::shaderParameters blackParameters;
blackParameters.fragmentDimValue = mDimValue;
Renderer::shaderPostprocessing(Renderer::SHADER_DIM, blackParameters);
if (mDimValue > 0.0)
mDimValue = Math::clamp(mDimValue - 0.045f, 0.0f, 1.0f);
#else
Renderer::drawRect(0.0f, 0.0f, Renderer::getScreenWidth(),
Renderer::getScreenHeight(), 0x000000FF, 0x000000FF);
#endif
}
}
}

View file

@ -24,6 +24,7 @@ public:
virtual bool allowSleep();
virtual bool isScreensaverActive();
virtual bool isFallbackScreensaver();
virtual void startScreensaver(bool generateMediaList);
virtual void stopScreensaver();
@ -72,6 +73,7 @@ private:
int mMediaSwapTime;
bool mTriggerNextGame;
bool mHasMediaFiles;
bool mFallbackScreensaver;
float mOpacity;
float mDimValue;
unsigned char mRectangleFadeIn;

View file

@ -312,9 +312,10 @@ void Window::render()
}
// Don't render the system view or gamelist view if the video or slideshow screensaver
// is running.
if (!(mRenderScreensaver && (Settings::getInstance()->getString("ScreensaverType") ==
"video" || Settings::getInstance()->getString("ScreensaverType") == "slideshow")))
// is running, unless the fallback screensaver is active due to lack of images or videos.
if ((mRenderScreensaver && mScreensaver->isFallbackScreensaver()) ||
(!(mRenderScreensaver && (Settings::getInstance()->getString("ScreensaverType") ==
"video" || Settings::getInstance()->getString("ScreensaverType") == "slideshow"))))
bottom->render(transform);
if (bottom != top) {

View file

@ -35,6 +35,7 @@ public:
public:
virtual bool allowSleep() = 0;
virtual bool isScreensaverActive() = 0;
virtual bool isFallbackScreensaver() = 0;
virtual void startScreensaver(bool generateMediaList) = 0;
virtual void stopScreensaver() = 0;