2 * Copyright (C) 2005-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
20 #include "ScreenSaver.h"
21 #include "settings/Settings.h"
22 #include "windowing/WindowingFactory.h"
25 #include "interfaces/python/XBPython.h"
26 #include "utils/AlarmClock.h"
28 // What sound does a python screensaver make?
29 #define PYTHON_ALARM "sssssscreensaver"
31 #define PYTHON_SCRIPT_TIMEOUT 5 // seconds
37 CScreenSaver::CScreenSaver(const char *addonID)
38 : ADDON::CAddonDll<DllScreenSaver, ScreenSaver, SCR_PROPS>(AddonProps(addonID, ADDON_UNKNOWN, "", ""))
42 bool CScreenSaver::CreateScreenSaver()
45 if (URIUtils::GetExtension(LibPath()).Equals(".py", false))
47 // Don't allow a previously-scheduled alarm to kill our new screensaver
48 g_alarmClock.Stop(PYTHON_ALARM, true);
50 if (!g_pythonParser.StopScript(LibPath()))
51 g_pythonParser.evalFile(LibPath(), AddonPtr(new CScreenSaver(Props())));
55 // pass it the screen width,height
56 // and the name of the screensaver
57 int iWidth = g_graphicsContext.GetWidth();
58 int iHeight = g_graphicsContext.GetHeight();
60 m_pInfo = new SCR_PROPS;
62 m_pInfo->device = g_Windowing.Get3DDevice();
64 m_pInfo->device = NULL;
68 m_pInfo->width = iWidth;
69 m_pInfo->height = iHeight;
70 m_pInfo->pixelRatio = g_settings.m_ResInfo[g_graphicsContext.GetVideoResolution()].fPixelRatio;
71 m_pInfo->name = strdup(Name().c_str());
72 m_pInfo->presets = strdup(CSpecialProtocol::TranslatePath(Path()).c_str());
73 m_pInfo->profile = strdup(CSpecialProtocol::TranslatePath(Profile()).c_str());
75 if (CAddonDll<DllScreenSaver, ScreenSaver, SCR_PROPS>::Create() == ADDON_STATUS_OK)
81 void CScreenSaver::Start()
83 // notify screen saver that they should start
84 if (Initialized()) m_pStruct->Start();
87 void CScreenSaver::Render()
89 // ask screensaver to render itself
90 if (Initialized()) m_pStruct->Render();
93 void CScreenSaver::GetInfo(SCR_INFO *info)
95 // get info from screensaver
96 if (Initialized()) m_pStruct->GetInfo(info);
99 void CScreenSaver::Destroy()
102 if (URIUtils::GetExtension(LibPath()).Equals(".py", false))
104 g_alarmClock.Start(PYTHON_ALARM, PYTHON_SCRIPT_TIMEOUT, "StopScript(" + LibPath() + ")", true, false);
108 // Release what was allocated in method CScreenSaver::CreateScreenSaver.
111 free((void *) m_pInfo->name);
112 free((void *) m_pInfo->presets);
113 free((void *) m_pInfo->profile);
119 CAddonDll<DllScreenSaver, ScreenSaver, SCR_PROPS>::Destroy();
122 } /*namespace ADDON*/