Kodi Development  20.0
for Binary and Script based Add-Ons
renderHelper.h
1 /*
2  * Copyright (C) 2005-2019 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 
13 #ifdef __cplusplus
14 
15 namespace kodi
16 {
17 namespace gui
18 {
19 struct ATTRIBUTE_HIDDEN IRenderHelper
20 {
21  virtual ~IRenderHelper() = default;
22  virtual bool Init() = 0;
23  virtual void Begin() = 0;
24  virtual void End() = 0;
25 }; /* class IRenderHelper */
26 } /* namespace gui */
27 } /* namespace kodi */
28 
29 #if defined(WIN32) && defined(HAS_ANGLE)
30 #include "gl/GLonDX.h"
31 #else
32 /*
33  * Default background GUI render helper class
34  */
35 namespace kodi
36 {
37 namespace gui
38 {
39 struct ATTRIBUTE_HIDDEN CRenderHelperStub : public IRenderHelper
40 {
41  bool Init() override { return true; }
42  void Begin() override {}
43  void End() override {}
44 }; /* class CRenderHelperStub */
45 
47 } /* namespace gui */
48 } /* namespace kodi */
49 #endif
50 
51 namespace kodi
52 {
53 namespace gui
54 {
55 
56 /*
57  * Create render background handler, e.g. becomes on "Windows" Angle used
58  * to emulate GL.
59  *
60  * This only be used internal and not from addon's direct.
61  *
62  * Function defines here and not in CAddonBase because of a hen and egg problem.
63  */
64 inline std::shared_ptr<IRenderHelper> ATTRIBUTE_HIDDEN GetRenderHelper()
65 {
66  using namespace ::kodi::addon;
67  if (static_cast<CAddonBase*>(CAddonBase::m_interface->addonBase)->m_renderHelper)
68  return static_cast<CAddonBase*>(CAddonBase::m_interface->addonBase)->m_renderHelper;
69 
70  std::shared_ptr<kodi::gui::IRenderHelper> renderHelper(new CRenderHelper());
71  if (!renderHelper->Init())
72  return nullptr;
73 
74  static_cast<CAddonBase*>(CAddonBase::m_interface->addonBase)->m_renderHelper =
75  renderHelper; // Hold on base for other types
76  return renderHelper;
77 }
78 
79 } /* namespace gui */
80 } /* namespace kodi */
81 
82 #endif /* __cplusplus */
Definition: renderHelper.h:40
Definition: renderHelper.h:20