From ffca21f2743a7b367fa212799c6e2fea6190dd5d Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 3 Mar 2015 16:53:59 +0100 Subject: initial commit for kodi master --- xbmc/addons/ScreenSaver.cpp | 125 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 xbmc/addons/ScreenSaver.cpp (limited to 'xbmc/addons/ScreenSaver.cpp') diff --git a/xbmc/addons/ScreenSaver.cpp b/xbmc/addons/ScreenSaver.cpp new file mode 100644 index 0000000..ef345f5 --- /dev/null +++ b/xbmc/addons/ScreenSaver.cpp @@ -0,0 +1,125 @@ +/* + * Copyright (C) 2005-2013 Team XBMC + * http://xbmc.org + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, see + * . + * + */ +#include "ScreenSaver.h" +#include "guilib/GraphicContext.h" +#include "interfaces/generic/ScriptInvocationManager.h" +#include "settings/DisplaySettings.h" +#include "utils/AlarmClock.h" +#include "windowing/WindowingFactory.h" + +// What sound does a python screensaver make? +#define SCRIPT_ALARM "sssssscreensaver" + +#define SCRIPT_TIMEOUT 5 // seconds + +namespace ADDON +{ + + CScreenSaver::CScreenSaver(const char *addonID) + : ADDON::CAddonDll(AddonProps(addonID, ADDON_UNKNOWN, "", "")) + { + } + +AddonPtr CScreenSaver::Clone() const +{ + // Copy constructor is generated by compiler and calls parent copy constructor + return AddonPtr(new CScreenSaver(*this)); +} + +bool CScreenSaver::CreateScreenSaver() +{ + if (CScriptInvocationManager::Get().HasLanguageInvoker(LibPath())) + { + // Don't allow a previously-scheduled alarm to kill our new screensaver + g_alarmClock.Stop(SCRIPT_ALARM, true); + + if (!CScriptInvocationManager::Get().Stop(LibPath())) + CScriptInvocationManager::Get().ExecuteAsync(LibPath(), Clone()); + return true; + } + // pass it the screen width,height + // and the name of the screensaver + int iWidth = g_graphicsContext.GetWidth(); + int iHeight = g_graphicsContext.GetHeight(); + + m_pInfo = new SCR_PROPS; +#ifdef HAS_DX + m_pInfo->device = g_Windowing.Get3DDevice(); +#else + m_pInfo->device = NULL; +#endif + m_pInfo->x = 0; + m_pInfo->y = 0; + m_pInfo->width = iWidth; + m_pInfo->height = iHeight; + m_pInfo->pixelRatio = g_graphicsContext.GetResInfo().fPixelRatio; + m_pInfo->name = strdup(Name().c_str()); + m_pInfo->presets = strdup(CSpecialProtocol::TranslatePath(Path()).c_str()); + m_pInfo->profile = strdup(CSpecialProtocol::TranslatePath(Profile()).c_str()); + + if (CAddonDll::Create() == ADDON_STATUS_OK) + return true; + + return false; +} + +void CScreenSaver::Start() +{ + // notify screen saver that they should start + if (Initialized()) m_pStruct->Start(); +} + +void CScreenSaver::Render() +{ + // ask screensaver to render itself + if (Initialized()) m_pStruct->Render(); +} + +void CScreenSaver::GetInfo(SCR_INFO *info) +{ + // get info from screensaver + if (Initialized()) m_pStruct->GetInfo(info); +} + +void CScreenSaver::Destroy() +{ +#ifdef HAS_PYTHON + if (URIUtils::HasExtension(LibPath(), ".py")) + { + g_alarmClock.Start(SCRIPT_ALARM, SCRIPT_TIMEOUT, "StopScript(" + LibPath() + ")", true, false); + return; + } +#endif + // Release what was allocated in method CScreenSaver::CreateScreenSaver. + if (m_pInfo) + { + free((void *) m_pInfo->name); + free((void *) m_pInfo->presets); + free((void *) m_pInfo->profile); + + delete m_pInfo; + m_pInfo = NULL; + } + + CAddonDll::Destroy(); +} + +} /*namespace ADDON*/ + -- cgit v1.2.3