summaryrefslogtreecommitdiffstats
path: root/xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/Screensaver.h
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2020-10-19 00:52:24 +0200
committermanuel <manuel@mausz.at>2020-10-19 00:52:24 +0200
commitbe933ef2241d79558f91796cc5b3a161f72ebf9c (patch)
treefe3ab2f130e20c99001f2d7a81d610c78c96a3f4 /xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/Screensaver.h
parent5f8335c1e49ce108ef3481863833c98efa00411b (diff)
downloadkodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.tar.gz
kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.tar.bz2
kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.zip
sync with upstream
Diffstat (limited to 'xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/Screensaver.h')
-rw-r--r--xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/Screensaver.h470
1 files changed, 470 insertions, 0 deletions
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/Screensaver.h b/xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/Screensaver.h
new file mode 100644
index 0000000..4902fcb
--- /dev/null
+++ b/xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/Screensaver.h
@@ -0,0 +1,470 @@
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//==============================================================================
22/// @addtogroup cpp_kodi_addon_screensaver
23/// @brief \cpp_class{ kodi::addon::CInstanceScreensaver }
24/// **Screensaver add-on instance**
25///
26/// A screensaver is a Kodi addon that fills the screen with moving images or
27/// patterns when the computer is not in use. Initially designed to prevent
28/// phosphor burn-in on CRT and plasma computer monitors (hence the name),
29/// screensavers are now used primarily for entertainment, security or to
30/// display system status information.
31///
32/// Include the header @ref Screensaver.h "#include <kodi/addon-instance/ScreenSaver.h>"
33/// to use this class.
34///
35/// This interface allows the creating of screensavers for Kodi, based upon
36/// **DirectX** or/and **OpenGL** rendering with `C++` code.
37///
38/// The interface is small and easy usable. It has three functions:
39///
40/// * <b><c>Start()</c></b> - Called on creation
41/// * <b><c>Render()</c></b> - Called at render time
42/// * <b><c>Stop()</c></b> - Called when the screensaver has no work
43///
44/// Additionally, there are several \ref cpp_kodi_addon_screensaver_CB "other functions"
45/// available in which the child class can ask about the current hardware,
46/// including the device, display and several other parts.
47///
48/// ----------------------------------------------------------------------------
49///
50/// Here is an example of what the <b>`addon.xml.in`</b> would look like for an
51/// screensaver addon:
52///
53/// ~~~~~~~~~~~~~{.xml}
54/// <?xml version="1.0" encoding="UTF-8"?>
55/// <addon
56/// id="screensaver.myspecialnamefor"
57/// version="1.0.0"
58/// name="My special screensaver addon"
59/// provider-name="Your Name">
60/// <requires>@ADDON_DEPENDS@</requires>
61/// <extension
62/// point="xbmc.ui.screensaver"
63/// library_@PLATFORM@="@LIBRARY_FILENAME@"/>
64/// <extension point="xbmc.addon.metadata">
65/// <summary lang="en_GB">My screensaver addon</summary>
66/// <description lang="en_GB">My screensaver addon description</description>
67/// <platform>@PLATFORM@</platform>
68/// </extension>
69/// </addon>
70/// ~~~~~~~~~~~~~
71///
72/// Description to screensaver related addon.xml values:
73/// | Name | Description
74/// |:------------------------------|----------------------------------------
75/// | <b>`point`</b> | Addon type specification<br>At all addon types and for this kind always <b>"xbmc.ui.screensaver"</b>.
76/// | <b>`library_@PLATFORM@`</b> | Sets the used library name, which is automatically set by cmake at addon build.
77///
78/// @remark For more detailed description of the <b>`addon.xml`</b>, see also https://kodi.wiki/view/Addon.xml.
79///
80///
81/// --------------------------------------------------------------------------
82///
83/// **Here is an example of the minimum required code to start a screensaver:**
84/// ~~~~~~~~~~~~~{.cpp}
85/// #include <kodi/addon-instance/Screensaver.h>
86///
87/// class CMyScreenSaver : public kodi::addon::CAddonBase,
88/// public kodi::addon::CInstanceScreensaver
89/// {
90/// public:
91/// CMyScreenSaver();
92///
93/// bool Start() override;
94/// void Render() override;
95/// };
96///
97/// CMyScreenSaver::CMyScreenSaver()
98/// {
99/// ...
100/// }
101///
102/// bool CMyScreenSaver::Start()
103/// {
104/// ...
105/// return true;
106/// }
107///
108/// void CMyScreenSaver::Render()
109/// {
110/// ...
111/// }
112///
113/// ADDONCREATOR(CMyScreenSaver)
114/// ~~~~~~~~~~~~~
115///
116///
117/// --------------------------------------------------------------------------
118///
119///
120/// **Here is another example where the screensaver is used together with
121/// other instance types:**
122///
123/// ~~~~~~~~~~~~~{.cpp}
124/// #include <kodi/addon-instance/Screensaver.h>
125///
126/// class CMyScreenSaver : public kodi::addon::CInstanceScreensaver
127/// {
128/// public:
129/// CMyScreenSaver(KODI_HANDLE instance, const std::string& version);
130///
131/// bool Start() override;
132/// void Render() override;
133/// };
134///
135/// CMyScreenSaver::CMyScreenSaver(KODI_HANDLE instance, const std::string& version)
136/// : CInstanceScreensaver(instance, version)
137/// {
138/// ...
139/// }
140///
141/// bool CMyScreenSaver::Start()
142/// {
143/// ...
144/// return true;
145/// }
146///
147/// void CMyScreenSaver::Render()
148/// {
149/// ...
150/// }
151///
152///
153/// //----------------------------------------------------------------------
154///
155/// class CMyAddon : public kodi::addon::CAddonBase
156/// {
157/// public:
158/// CMyAddon() = default;
159/// ADDON_STATUS CreateInstance(int instanceType,
160/// const std::string& instanceID,
161/// KODI_HANDLE instance,
162/// const std::string& version,
163/// KODI_HANDLE& addonInstance) override;
164/// };
165///
166/// // If you use only one instance in your add-on, can be instanceType and
167/// // instanceID ignored
168/// ADDON_STATUS CMyAddon::CreateInstance(int instanceType,
169/// const std::string& instanceID,
170/// KODI_HANDLE instance,
171/// const std::string& version,
172/// KODI_HANDLE& addonInstance)
173/// {
174/// if (instanceType == ADDON_INSTANCE_SCREENSAVER)
175/// {
176/// kodi::Log(ADDON_LOG_INFO, "Creating my Screensaver");
177/// addonInstance = new CMyScreenSaver(instance, version);
178/// return ADDON_STATUS_OK;
179/// }
180/// else if (...)
181/// {
182/// ...
183/// }
184/// return ADDON_STATUS_UNKNOWN;
185/// }
186///
187/// ADDONCREATOR(CMyAddon)
188/// ~~~~~~~~~~~~~
189///
190/// The destruction of the example class `CMyScreenSaver` is called from
191/// Kodi's header. Manually deleting the add-on instance is not required.
192///
193class ATTRIBUTE_HIDDEN CInstanceScreensaver : public IAddonInstance
194{
195public:
196 //============================================================================
197 /// @ingroup cpp_kodi_addon_screensaver
198 /// @brief Screensaver class constructor.
199 ///
200 /// Used by an add-on that only supports screensavers.
201 ///
202 CInstanceScreensaver()
203 : IAddonInstance(ADDON_INSTANCE_SCREENSAVER, GetKodiTypeVersion(ADDON_INSTANCE_SCREENSAVER))
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 //============================================================================
215 /// @ingroup cpp_kodi_addon_screensaver
216 /// @brief Screensaver class constructor used to support multiple instance
217 /// types.
218 ///
219 /// @param[in] instance The instance value given to
220 /// <b>`kodi::addon::CAddonBase::CreateInstance(...)`</b>.
221 /// @param[in] kodiVersion [opt] Version used in Kodi for this instance, to
222 /// allow compatibility to older Kodi versions.
223 ///
224 /// @note Recommended to set <b>`kodiVersion`</b>.
225 ///
226 ///
227 /// --------------------------------------------------------------------------
228 ///
229 /// **Here's example about the use of this:**
230 /// ~~~~~~~~~~~~~{.cpp}
231 /// class CMyScreenSaver : public kodi::addon::CInstanceScreensaver
232 /// {
233 /// public:
234 /// CMyScreenSaver(KODI_HANDLE instance, const std::string& kodiVersion)
235 /// : kodi::addon::CInstanceScreensaver(instance, kodiVersion)
236 /// {
237 /// ...
238 /// }
239 ///
240 /// ...
241 /// };
242 ///
243 /// ADDON_STATUS CMyAddon::CreateInstance(int instanceType,
244 /// const std::string& instanceID,
245 /// KODI_HANDLE instance,
246 /// const std::string& version,
247 /// KODI_HANDLE& addonInstance)
248 /// {
249 /// kodi::Log(ADDON_LOG_INFO, "Creating my screensaver");
250 /// addonInstance = new CMyScreenSaver(instance, version);
251 /// return ADDON_STATUS_OK;
252 /// }
253 /// ~~~~~~~~~~~~~
254 ///
255 explicit CInstanceScreensaver(KODI_HANDLE instance, const std::string& kodiVersion = "")
256 : IAddonInstance(ADDON_INSTANCE_SCREENSAVER,
257 !kodiVersion.empty() ? kodiVersion
258 : GetKodiTypeVersion(ADDON_INSTANCE_SCREENSAVER))
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 //============================================================================
269 /// @ingroup cpp_kodi_addon_screensaver
270 /// @brief Destructor.
271 ///
272 ~CInstanceScreensaver() override = default;
273 //----------------------------------------------------------------------------
274
275 //============================================================================
276 /// @ingroup cpp_kodi_addon_screensaver
277 /// @brief Used to notify the screensaver that it has been started.
278 ///
279 /// @return true if the screensaver was started successfully, false otherwise
280 ///
281 virtual bool Start() { return true; }
282 //----------------------------------------------------------------------------
283
284 //============================================================================
285 /// @ingroup cpp_kodi_addon_screensaver
286 /// @brief Used to inform the screensaver that the rendering control was
287 /// stopped.
288 ///
289 virtual void Stop() {}
290 //----------------------------------------------------------------------------
291
292 //============================================================================
293 /// @ingroup cpp_kodi_addon_screensaver
294 /// @brief Used to indicate when the add-on should render
295 ///
296 virtual void Render() {}
297 //----------------------------------------------------------------------------
298
299 //============================================================================
300 /// @defgroup cpp_kodi_addon_screensaver_CB Information functions
301 /// @ingroup cpp_kodi_addon_screensaver
302 /// @brief **To get info about the device, display and several other parts**
303 ///
304 ///@{
305
306 //============================================================================
307 /// @ingroup cpp_kodi_addon_screensaver_CB
308 /// @brief Device that represents the display adapter.
309 ///
310 /// @return A pointer to the device
311 ///
312 /// @note This is only available on **DirectX**, It us unused (`nullptr`) on
313 /// **OpenGL**
314 ///
315 /// This value can also be becomed by @ref kodi::gui::GetHWContext() and is
316 /// recommended to use.
317 ///
318 ///-------------------------------------------------------------------------
319 ///
320 /// **Example:**
321 /// ~~~~~~~~~~~~~{.cpp}
322 /// #include <d3d11_1.h>
323 /// ..
324 /// // Note: Device() there is used inside addon child class about
325 /// // kodi::addon::CInstanceVisualization
326 /// ID3D11DeviceContext1* context = static_cast<ID3D11DeviceContext1*>(kodi::addon::CInstanceVisualization::Device());
327 /// ..
328 /// ~~~~~~~~~~~~~
329 ///
330 inline kodi::HardwareContext Device() { return m_instanceData->props->device; }
331 //----------------------------------------------------------------------------
332
333 //============================================================================
334 /// @ingroup cpp_kodi_addon_screensaver_CB
335 /// @brief Returns the X position of the rendering window.
336 ///
337 /// @return The X position, in pixels
338 ///
339 inline int X() { return m_instanceData->props->x; }
340 //----------------------------------------------------------------------------
341
342 //============================================================================
343 /// @ingroup cpp_kodi_addon_screensaver_CB
344 /// @brief Returns the Y position of the rendering window.
345 ///
346 /// @return The Y position, in pixels
347 ///
348 inline int Y() { return m_instanceData->props->y; }
349 //----------------------------------------------------------------------------
350
351 //============================================================================
352 /// @ingroup cpp_kodi_addon_screensaver_CB
353 /// @brief Returns the width of the rendering window.
354 ///
355 /// @return The width, in pixels
356 ///
357 inline int Width() { return m_instanceData->props->width; }
358 //----------------------------------------------------------------------------
359
360 //============================================================================
361 /// @ingroup cpp_kodi_addon_screensaver_CB
362 /// @brief Returns the height of the rendering window.
363 ///
364 /// @return The height, in pixels
365 ///
366 inline int Height() { return m_instanceData->props->height; }
367 //----------------------------------------------------------------------------
368
369 //============================================================================
370 /// @ingroup cpp_kodi_addon_screensaver_CB
371 /// @brief Pixel aspect ratio (often abbreviated PAR) is a ratio that
372 /// describes how the width of a pixel compares to the height of that pixel.
373 ///
374 /// @return The pixel aspect ratio used by the display
375 ///
376 inline float PixelRatio() { return m_instanceData->props->pixelRatio; }
377 //----------------------------------------------------------------------------
378
379 //============================================================================
380 /// @ingroup cpp_kodi_addon_screensaver_CB
381 /// @brief Used to get the name of the add-on defined in `addon.xml`.
382 ///
383 /// @return The add-on name
384 ///
385 inline std::string Name() { return m_instanceData->props->name; }
386 //----------------------------------------------------------------------------
387
388 //============================================================================
389 ///
390 /// @ingroup cpp_kodi_addon_screensaver_CB
391 /// @brief Used to get the full path where the add-on is installed.
392 ///
393 /// @return The add-on installation path
394 ///
395 inline std::string Presets() { return m_instanceData->props->presets; }
396 //----------------------------------------------------------------------------
397
398 //============================================================================
399 /// @ingroup cpp_kodi_addon_screensaver_CB
400 /// @brief Used to get the full path to the add-on's user profile.
401 ///
402 /// @note The trailing folder (consisting of the add-on's ID) is not created
403 /// by default. If it is needed, you must call kodi::vfs::CreateDirectory()
404 /// to create the folder.
405 ///
406 /// @return Path to the user profile
407 ///
408 inline std::string Profile() { return m_instanceData->props->profile; }
409 //----------------------------------------------------------------------------
410
411 ///@}
412
413private:
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 */