Kodi Development 22.0
for Binary and Script based Add-Ons
 
Loading...
Searching...
No Matches
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
16namespace kodi
17{
18namespace addon
19{
20
21//==============================================================================
187class ATTR_DLL_LOCAL CInstanceScreensaver : public IAddonInstance
188{
189public:
190 //============================================================================
197 : IAddonInstance(IInstanceInfo(CPrivateBase::m_interface->firstKodiInstance))
198 {
199 if (CPrivateBase::m_interface->globalSingleInstance != nullptr)
200 throw std::logic_error("kodi::addon::CInstanceScreensaver: Creation of more as one in single "
201 "instance way is not allowed!");
202
203 SetAddonStruct(CPrivateBase::m_interface->firstKodiInstance);
204 CPrivateBase::m_interface->globalSingleInstance = this;
205 }
206 //----------------------------------------------------------------------------
207
208 //============================================================================
249 explicit CInstanceScreensaver(const IInstanceInfo& instance) : IAddonInstance(instance)
250 {
251 if (CPrivateBase::m_interface->globalSingleInstance != nullptr)
252 throw std::logic_error("kodi::addon::CInstanceScreensaver: Creation of multiple together "
253 "with single instance way is not allowed!");
254
255 SetAddonStruct(instance);
256 }
257 //----------------------------------------------------------------------------
258
259 //============================================================================
263 ~CInstanceScreensaver() override = default;
264 //----------------------------------------------------------------------------
265
266 //============================================================================
272 virtual bool Start() { return true; }
273 //----------------------------------------------------------------------------
274
275 //============================================================================
280 virtual void Stop() {}
281 //----------------------------------------------------------------------------
282
283 //============================================================================
287 virtual void Render() {}
288 //----------------------------------------------------------------------------
289
290 //============================================================================
296
297 //============================================================================
321 inline kodi::HardwareContext Device() { return m_props.device; }
322 //----------------------------------------------------------------------------
323
324 //============================================================================
330 inline int X() { return m_props.x; }
331 //----------------------------------------------------------------------------
332
333 //============================================================================
339 inline int Y() { return m_props.y; }
340 //----------------------------------------------------------------------------
341
342 //============================================================================
348 inline int Width() { return m_props.width; }
349 //----------------------------------------------------------------------------
350
351 //============================================================================
357 inline int Height() { return m_props.height; }
358 //----------------------------------------------------------------------------
359
360 //============================================================================
367 inline float PixelRatio() { return m_props.pixelRatio; }
368 //----------------------------------------------------------------------------
369
371
372private:
373 void SetAddonStruct(KODI_ADDON_INSTANCE_STRUCT* instance)
374 {
375 instance->hdl = this;
376 instance->screensaver->toAddon->start = ADDON_start;
377 instance->screensaver->toAddon->stop = ADDON_stop;
378 instance->screensaver->toAddon->render = ADDON_render;
379
380 instance->screensaver->toKodi->get_properties(instance->info->kodi, &m_props);
381 }
382
383 inline static bool ADDON_start(const KODI_ADDON_SCREENSAVER_HDL hdl)
384 {
385 CInstanceScreensaver* thisClass = static_cast<CInstanceScreensaver*>(hdl);
386 thisClass->m_renderHelper = kodi::gui::GetRenderHelper();
387 return thisClass->Start();
388 }
389
390 inline static void ADDON_stop(const KODI_ADDON_SCREENSAVER_HDL hdl)
391 {
392 CInstanceScreensaver* thisClass = static_cast<CInstanceScreensaver*>(hdl);
393 thisClass->Stop();
394 thisClass->m_renderHelper = nullptr;
395 }
396
397 inline static void ADDON_render(const KODI_ADDON_SCREENSAVER_HDL hdl)
398 {
399 CInstanceScreensaver* thisClass = static_cast<CInstanceScreensaver*>(hdl);
400
401 if (!thisClass->m_renderHelper)
402 return;
403 thisClass->m_renderHelper->Begin();
404 thisClass->Render();
405 thisClass->m_renderHelper->End();
406 }
407
408 /*
409 * Background render helper holds here and in addon base.
410 * In addon base also to have for the others, and stored here for the worst
411 * case where this class is independent from base and base becomes closed
412 * before.
413 *
414 * This is on Kodi with GL unused and the calls to there are empty (no work)
415 * On Kodi with Direct X where angle is present becomes this used.
416 */
417 std::shared_ptr<kodi::gui::IRenderHelper> m_renderHelper;
418
419 KODI_ADDON_SCREENSAVER_PROPS m_props = {};
420};
421
422} /* namespace addon */
423} /* namespace kodi */
424#endif /* __cplusplus */
Definition Screensaver.h:188
Definition AddonBase.h:565
Definition AddonBase.h:498
int Height()
Returns the height of the rendering window.
Definition Screensaver.h:357
kodi::HardwareContext Device()
Device that represents the display adapter.
Definition Screensaver.h:321
int X()
Returns the X position of the rendering window.
Definition Screensaver.h:330
int Width()
Returns the width of the rendering window.
Definition Screensaver.h:348
int Y()
Returns the Y position of the rendering window.
Definition Screensaver.h:339
float PixelRatio()
Pixel aspect ratio (often abbreviated PAR) is a ratio that describes how the width of a pixel compare...
Definition Screensaver.h:367
virtual void Render()
Used to indicate when the add-on should render.
Definition Screensaver.h:287
CInstanceScreensaver()
Screensaver class constructor.
Definition Screensaver.h:196
virtual bool Start()
Used to notify the screensaver that it has been started.
Definition Screensaver.h:272
~CInstanceScreensaver() override=default
Destructor.
CInstanceScreensaver(const IInstanceInfo &instance)
Screensaver class constructor used to support multiple instance types.
Definition Screensaver.h:249
virtual void Stop()
Used to inform the screensaver that the rendering control was stopped.
Definition Screensaver.h:280
Definition addon_base.h:268
Definition screensaver.h:22
Internal used structure to have stored C API data above and available for everything below.
Definition AddonBase.h:73