[videodb] Remove nested transaction when saving state after stopping PVR playback
[xbmc.git] / xbmc / windows / GUIWindowScreensaver.cpp
blob75d2194d38c2731e3e913f496ae312f134f0d1f8
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "GUIWindowScreensaver.h"
11 #include "GUIPassword.h"
12 #include "GUIUserMessages.h"
13 #include "ServiceBroker.h"
14 #include "addons/AddonManager.h"
15 #include "addons/ScreenSaver.h"
16 #include "addons/addoninfo/AddonType.h"
17 #include "application/ApplicationComponents.h"
18 #include "application/ApplicationPowerHandling.h"
19 #include "guilib/GUIComponent.h"
20 #include "guilib/GUITexture.h"
21 #include "guilib/GUIWindowManager.h"
22 #include "settings/Settings.h"
23 #include "settings/SettingsComponent.h"
25 using namespace KODI;
27 CGUIWindowScreensaver::CGUIWindowScreensaver()
28 : CGUIDialog(WINDOW_SCREENSAVER, "", DialogModalityType::MODELESS)
30 m_renderOrder = RENDER_ORDER_WINDOW_SCREENSAVER;
33 void CGUIWindowScreensaver::Process(unsigned int currentTime, CDirtyRegionList& regions)
35 MarkDirtyRegion();
36 CGUIWindow::Process(currentTime, regions);
37 const auto& context = CServiceBroker::GetWinSystem()->GetGfxContext();
38 m_renderRegion.SetRect(0, 0, static_cast<float>(context.GetWidth()),
39 static_cast<float>(context.GetHeight()));
42 void CGUIWindowScreensaver::Render()
44 // FIXME/TODO: Screensaver addons should make the screen black instead
45 // keeping this just for compatibility reasons since it's now a dialog.
46 CGUITexture::DrawQuad(m_renderRegion, UTILS::COLOR::BLACK);
48 if (m_addon)
50 auto& context = CServiceBroker::GetWinSystem()->GetGfxContext();
52 context.CaptureStateBlock();
53 m_addon->Render();
54 context.ApplyStateBlock();
55 return;
58 CGUIDialog::Render();
61 void CGUIWindowScreensaver::OnInitWindow()
63 CGUIDialog::OnInitWindow();
64 m_visible = true;
67 void CGUIWindowScreensaver::UpdateVisibility()
69 auto& components = CServiceBroker::GetAppComponents();
70 const auto appPower = components.GetComponent<CApplicationPowerHandling>();
71 if (!appPower->IsInScreenSaver() && m_visible)
73 m_visible = false;
74 Close();
78 bool CGUIWindowScreensaver::OnMessage(CGUIMessage& message)
80 switch (message.GetMessage())
82 case GUI_MSG_WINDOW_DEINIT:
84 if (m_addon)
86 m_addon->Stop();
87 m_addon.reset();
90 CServiceBroker::GetWinSystem()->GetGfxContext().ApplyStateBlock();
92 break;
94 case GUI_MSG_WINDOW_INIT:
96 CGUIWindow::OnMessage(message);
98 CServiceBroker::GetWinSystem()->GetGfxContext().CaptureStateBlock();
100 const std::string addon = CServiceBroker::GetSettingsComponent()->GetSettings()->GetString(
101 CSettings::SETTING_SCREENSAVER_MODE);
102 const ADDON::AddonInfoPtr addonBase =
103 CServiceBroker::GetAddonMgr().GetAddonInfo(addon, ADDON::AddonType::SCREENSAVER);
104 if (!addonBase)
105 return false;
106 m_addon = std::make_unique<KODI::ADDONS::CScreenSaver>(addonBase);
107 return m_addon->Start();
110 case GUI_MSG_CHECK_LOCK:
112 auto& components = CServiceBroker::GetAppComponents();
113 const auto appPower = components.GetComponent<CApplicationPowerHandling>();
114 if (!g_passwordManager.IsProfileLockUnlocked())
116 appPower->SetScreenSaverLockFailed();
117 return false;
119 appPower->SetScreenSaverUnlocked();
120 return true;
124 return CGUIWindow::OnMessage(message);