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 "interfaces/generic/ScriptInvocationManager.h"
22 #include "settings/DisplaySettings.h"
23 #include "utils/AlarmClock.h"
24 #include "windowing/WindowingFactory.h"
26 // What sound does a python screensaver make?
27 #define SCRIPT_ALARM "sssssscreensaver"
29 #define SCRIPT_TIMEOUT 5 // seconds
34 CScreenSaver::CScreenSaver(const char *addonID)
35 : ADDON::CAddonDll<DllScreenSaver, ScreenSaver, SCR_PROPS>(AddonProps(addonID, ADDON_UNKNOWN, "", ""))
39 AddonPtr CScreenSaver::Clone() const
41 // Copy constructor is generated by compiler and calls parent copy constructor
42 return AddonPtr(new CScreenSaver(*this));
45 bool CScreenSaver::CreateScreenSaver()
47 if (CScriptInvocationManager::Get().HasLanguageInvoker(LibPath()))
49 // Don't allow a previously-scheduled alarm to kill our new screensaver
50 g_alarmClock.Stop(SCRIPT_ALARM, true);
52 if (!CScriptInvocationManager::Get().Stop(LibPath()))
53 CScriptInvocationManager::Get().Execute(LibPath(), Clone());
56 // pass it the screen width,height
57 // and the name of the screensaver
58 int iWidth = g_graphicsContext.GetWidth();
59 int iHeight = g_graphicsContext.GetHeight();
61 m_pInfo = new SCR_PROPS;
63 m_pInfo->device = g_Windowing.Get3DDevice();
65 m_pInfo->device = NULL;
69 m_pInfo->width = iWidth;
70 m_pInfo->height = iHeight;
71 m_pInfo->pixelRatio = g_graphicsContext.GetResInfo().fPixelRatio;
72 m_pInfo->name = strdup(Name().c_str());
73 m_pInfo->presets = strdup(CSpecialProtocol::TranslatePath(Path()).c_str());
74 m_pInfo->profile = strdup(CSpecialProtocol::TranslatePath(Profile()).c_str());
76 if (CAddonDll<DllScreenSaver, ScreenSaver, SCR_PROPS>::Create() == ADDON_STATUS_OK)
82 void CScreenSaver::Start()
84 // notify screen saver that they should start
85 if (Initialized()) m_pStruct->Start();
88 void CScreenSaver::Render()
90 // ask screensaver to render itself
91 if (Initialized()) m_pStruct->Render();
94 void CScreenSaver::GetInfo(SCR_INFO *info)
96 // get info from screensaver
97 if (Initialized()) m_pStruct->GetInfo(info);
100 void CScreenSaver::Destroy()
103 if (URIUtils::HasExtension(LibPath(), ".py"))
105 g_alarmClock.Start(SCRIPT_ALARM, SCRIPT_TIMEOUT, "StopScript(" + LibPath() + ")", true, false);
109 // Release what was allocated in method CScreenSaver::CreateScreenSaver.
112 free((void *) m_pInfo->name);
113 free((void *) m_pInfo->presets);
114 free((void *) m_pInfo->profile);
120 CAddonDll<DllScreenSaver, ScreenSaver, SCR_PROPS>::Destroy();
123 } /*namespace ADDON*/