Kodi Development  20.0
for Binary and Script based Add-Ons
Screensaver.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "../AddonBase.h"
12 #include "../c-api/addon-instance/screensaver.h"
13 #include "../gui/renderHelper.h"
14 
15 #ifdef __cplusplus
16 namespace kodi
17 {
18 namespace addon
19 {
20 
21 //==============================================================================
193 class ATTRIBUTE_HIDDEN CInstanceScreensaver : public IAddonInstance
194 {
195 public:
196  //============================================================================
204  {
205  if (CAddonBase::m_interface->globalSingleInstance != nullptr)
206  throw std::logic_error("kodi::addon::CInstanceScreensaver: Creation of more as one in single "
207  "instance way is not allowed!");
208 
209  SetAddonStruct(CAddonBase::m_interface->firstKodiInstance);
210  CAddonBase::m_interface->globalSingleInstance = this;
211  }
212  //----------------------------------------------------------------------------
213 
214  //============================================================================
255  explicit CInstanceScreensaver(KODI_HANDLE instance, const std::string& kodiVersion = "")
257  !kodiVersion.empty() ? kodiVersion
259  {
260  if (CAddonBase::m_interface->globalSingleInstance != nullptr)
261  throw std::logic_error("kodi::addon::CInstanceScreensaver: Creation of multiple together "
262  "with single instance way is not allowed!");
263 
264  SetAddonStruct(instance);
265  }
266  //----------------------------------------------------------------------------
267 
268  //============================================================================
272  ~CInstanceScreensaver() override = default;
273  //----------------------------------------------------------------------------
274 
275  //============================================================================
281  virtual bool Start() { return true; }
282  //----------------------------------------------------------------------------
283 
284  //============================================================================
289  virtual void Stop() {}
290  //----------------------------------------------------------------------------
291 
292  //============================================================================
296  virtual void Render() {}
297  //----------------------------------------------------------------------------
298 
299  //============================================================================
305 
306  //============================================================================
330  inline kodi::HardwareContext Device() { return m_instanceData->props->device; }
331  //----------------------------------------------------------------------------
332 
333  //============================================================================
339  inline int X() { return m_instanceData->props->x; }
340  //----------------------------------------------------------------------------
341 
342  //============================================================================
348  inline int Y() { return m_instanceData->props->y; }
349  //----------------------------------------------------------------------------
350 
351  //============================================================================
357  inline int Width() { return m_instanceData->props->width; }
358  //----------------------------------------------------------------------------
359 
360  //============================================================================
366  inline int Height() { return m_instanceData->props->height; }
367  //----------------------------------------------------------------------------
368 
369  //============================================================================
376  inline float PixelRatio() { return m_instanceData->props->pixelRatio; }
377  //----------------------------------------------------------------------------
378 
379  //============================================================================
385  inline std::string Name() { return m_instanceData->props->name; }
386  //----------------------------------------------------------------------------
387 
388  //============================================================================
395  inline std::string Presets() { return m_instanceData->props->presets; }
396  //----------------------------------------------------------------------------
397 
398  //============================================================================
408  inline std::string Profile() { return m_instanceData->props->profile; }
409  //----------------------------------------------------------------------------
410 
412 
413 private:
414  void SetAddonStruct(KODI_HANDLE instance)
415  {
416  if (instance == nullptr)
417  throw std::logic_error("kodi::addon::CInstanceScreensaver: Creation with empty addon "
418  "structure not allowed, table must be given from Kodi!");
419 
420  m_instanceData = static_cast<AddonInstance_Screensaver*>(instance);
421  m_instanceData->toAddon->addonInstance = this;
422  m_instanceData->toAddon->Start = ADDON_Start;
423  m_instanceData->toAddon->Stop = ADDON_Stop;
424  m_instanceData->toAddon->Render = ADDON_Render;
425  }
426 
427  inline static bool ADDON_Start(AddonInstance_Screensaver* instance)
428  {
429  CInstanceScreensaver* thisClass =
430  static_cast<CInstanceScreensaver*>(instance->toAddon->addonInstance);
431  thisClass->m_renderHelper = kodi::gui::GetRenderHelper();
432  return thisClass->Start();
433  }
434 
435  inline static void ADDON_Stop(AddonInstance_Screensaver* instance)
436  {
437  CInstanceScreensaver* thisClass =
438  static_cast<CInstanceScreensaver*>(instance->toAddon->addonInstance);
439  thisClass->Stop();
440  thisClass->m_renderHelper = nullptr;
441  }
442 
443  inline static void ADDON_Render(AddonInstance_Screensaver* instance)
444  {
445  CInstanceScreensaver* thisClass =
446  static_cast<CInstanceScreensaver*>(instance->toAddon->addonInstance);
447 
448  if (!thisClass->m_renderHelper)
449  return;
450  thisClass->m_renderHelper->Begin();
451  thisClass->Render();
452  thisClass->m_renderHelper->End();
453  }
454 
455  /*
456  * Background render helper holds here and in addon base.
457  * In addon base also to have for the others, and stored here for the worst
458  * case where this class is independent from base and base becomes closed
459  * before.
460  *
461  * This is on Kodi with GL unused and the calls to there are empty (no work)
462  * On Kodi with Direct X where angle is present becomes this used.
463  */
464  std::shared_ptr<kodi::gui::IRenderHelper> m_renderHelper;
465  AddonInstance_Screensaver* m_instanceData;
466 };
467 
468 } /* namespace addon */
469 } /* namespace kodi */
470 #endif /* __cplusplus */
Definition: Screensaver.h:194
Definition: AddonBase.h:186
@ ADDON_INSTANCE_SCREENSAVER
PVR client instance, see kodi::addon::CInstanceScreensaver.
Definition: versions.h:235
std::string Presets()
Used to get the full path where the add-on is installed.
Definition: Screensaver.h:395
int Height()
Returns the height of the rendering window.
Definition: Screensaver.h:366
kodi::HardwareContext Device()
Device that represents the display adapter.
Definition: Screensaver.h:330
std::string Profile()
Used to get the full path to the add-on's user profile.
Definition: Screensaver.h:408
int X()
Returns the X position of the rendering window.
Definition: Screensaver.h:339
int Width()
Returns the width of the rendering window.
Definition: Screensaver.h:357
int Y()
Returns the Y position of the rendering window.
Definition: Screensaver.h:348
std::string Name()
Used to get the name of the add-on defined in addon.xml.
Definition: Screensaver.h:385
float PixelRatio()
Pixel aspect ratio (often abbreviated PAR) is a ratio that describes how the width of a pixel compare...
Definition: Screensaver.h:376
virtual void Render()
Used to indicate when the add-on should render.
Definition: Screensaver.h:296
CInstanceScreensaver()
Screensaver class constructor.
Definition: Screensaver.h:202
CInstanceScreensaver(KODI_HANDLE instance, const std::string &kodiVersion="")
Screensaver class constructor used to support multiple instance types.
Definition: Screensaver.h:255
virtual bool Start()
Used to notify the screensaver that it has been started.
Definition: Screensaver.h:281
~CInstanceScreensaver() override=default
Destructor.
virtual void Stop()
Used to inform the screensaver that the rendering control was stopped.
Definition: Screensaver.h:289
std::string ATTRIBUTE_HIDDEN GetKodiTypeVersion(int type)
To get used version inside Kodi itself about asked type.
Definition: AddonBase.h:630
Screensaver instance.
Definition: screensaver.h:68