summaryrefslogtreecommitdiffstats
path: root/xbmc/addons/kodi-addon-dev-kit/include/kodi/gui/controls/Rendering.h
blob: 7cc9b247d93cbcf48e5c6075108f40944b55ea4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*
 *  Copyright (C) 2005-2018 Team Kodi
 *  This file is part of Kodi - https://kodi.tv
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 *  See LICENSES/README.md for more information.
 */

#pragma once

#include "../../AddonBase.h"
#include "../Window.h"
#include "../renderHelper.h"

namespace kodi
{
namespace gui
{
namespace controls
{

//============================================================================
///
/// \defgroup cpp_kodi_gui_controls_CRendering Control Rendering
/// \ingroup cpp_kodi_gui
/// @brief \cpp_class{ kodi::gui::controls::CRendering }
/// **Window control for rendering own parts**
///
/// This rendering control is used  when own parts are needed.  You  have  the
/// control  over them  to render direct  OpenGL or  DirectX  content  to  the
/// screen set by the size of them.
///
/// Alternative  can be  the virtual  functions from t his been ignored if the
/// callbacks are  defined  by the  \ref CRendering_SetIndependentCallbacks function  and
/// class is used as single and not as a parent class.
///
/// It has the header \ref Rendering.h "#include <kodi/gui/controls/Rendering.h>"
/// be included to enjoy it.
///
/// Here you find the needed skin part for a \ref Addon_Rendering_control "rendering control"
///
/// @note The  call of  the control is only  possible  from  the corresponding
/// window as its class and identification number is required.
///

//============================================================================
///
/// \defgroup cpp_kodi_gui_controls_CRendering_Defs Definitions, structures and enumerators
/// \ingroup cpp_kodi_gui_controls_CRendering
/// @brief **Library definition values**
///

class ATTRIBUTE_HIDDEN CRendering : public CAddonGUIControlBase
{
public:
  //==========================================================================
  ///
  /// \ingroup cpp_kodi_gui_controls_CRendering
  /// @brief Construct a new control
  ///
  /// @param[in] window               related window control class
  /// @param[in] controlId            Used skin xml control id
  ///
  CRendering(CWindow* window, int controlId) : CAddonGUIControlBase(window)
  {
    m_controlHandle = m_interface->kodi_gui->window->get_control_render_addon(
        m_interface->kodiBase, m_Window->GetControlHandle(), controlId);
    if (m_controlHandle)
      m_interface->kodi_gui->control_rendering->set_callbacks(m_interface->kodiBase,
                                                              m_controlHandle, this, OnCreateCB,
                                                              OnRenderCB, OnStopCB, OnDirtyCB);
    else
      kodi::Log(ADDON_LOG_FATAL, "kodi::gui::controls::%s can't create control class from Kodi !!!",
                __FUNCTION__);
  }
  //--------------------------------------------------------------------------

  //==========================================================================
  ///
  /// \ingroup cpp_kodi_gui_controls_CRendering
  /// @brief Destructor
  ///
  ~CRendering() override
  {
    m_interface->kodi_gui->control_rendering->destroy(m_interface->kodiBase, m_controlHandle);
  }
  //--------------------------------------------------------------------------

  //==========================================================================
  ///
  /// \ingroup cpp_kodi_gui_controls_CRendering
  /// @brief To create rendering control on Add-on
  ///
  /// Function  creates the  needed rendering  control for Kodi  which becomes
  /// handled and processed from Add-on
  ///
  /// @note This is  callback  function  from Kodi  to  Add-on and  not to use
  /// for calls from add-on to this function.
  ///
  /// @param[in] x                    Horizontal position
  /// @param[in] y                    Vertical position
  /// @param[in] w                    Width of control
  /// @param[in] h                    Height of control
  /// @param[in] device               The device to use.  For OpenGL  is empty
  ///                                 on Direct X is the needed device send.
  /// @return                         Add-on needs to return true if successed,
  ///                                 otherwise false.
  ///
  virtual bool Create(int x, int y, int w, int h, void* device) { return false; }
  //--------------------------------------------------------------------------

  //==========================================================================
  ///
  /// \ingroup cpp_kodi_gui_controls_CRendering
  /// @brief Render process call from Kodi
  ///
  /// @note This  is callback  function from  Kodi to  Add-on  and not  to use
  /// for calls from add-on to this function.
  ///
  virtual void Render() {}
  //--------------------------------------------------------------------------

  //==========================================================================
  ///
  /// \ingroup cpp_kodi_gui_controls_CRendering
  /// @brief Call from Kodi to stop rendering process
  ///
  /// @note This  is callback  function from  Kodi to  Add-on  and not  to use
  /// for calls from add-on to this function.
  ///
  virtual void Stop() {}
  //--------------------------------------------------------------------------

  //==========================================================================
  ///
  /// \ingroup cpp_kodi_gui_controls_CRendering
  /// @brief Call from Kodi where add-on  becomes asked about  dirty rendering
  /// region.
  ///
  /// @note This  is callback  function from  Kodi to  Add-on  and not  to use
  /// for calls from add-on to this function.
  ///
  virtual bool Dirty() { return false; }
  //--------------------------------------------------------------------------

  //==========================================================================
  ///
  /// \ingroup cpp_kodi_gui_controls_CRendering
  /// \anchor CRendering_SetIndependentCallbacks
  /// @brief If the  class is used  independent (with "new CRendering")
  /// and not as  parent (with "cCLASS_own : CRendering") from own must
  /// be the callback from Kodi to add-on overdriven with own functions!
  ///
  void SetIndependentCallbacks(
      GUIHANDLE cbhdl,
      bool (*CBCreate)(GUIHANDLE cbhdl, int x, int y, int w, int h, void* device),
      void (*CBRender)(GUIHANDLE cbhdl),
      void (*CBStop)(GUIHANDLE cbhdl),
      bool (*CBDirty)(GUIHANDLE cbhdl))
  {
    if (!cbhdl || !CBCreate || !CBRender || !CBStop || !CBDirty)
    {
      kodi::Log(ADDON_LOG_ERROR, "kodi::gui::controls::%s called with nullptr !!!", __FUNCTION__);
      return;
    }

    m_interface->kodi_gui->control_rendering->set_callbacks(
        m_interface->kodiBase, m_controlHandle, cbhdl, CBCreate, CBRender, CBStop, CBDirty);
  }
  //--------------------------------------------------------------------------

private:
  /*
   * Defined callback functions from Kodi to add-on, for use in parent / child system
   * (is private)!
   */
  static bool OnCreateCB(void* cbhdl, int x, int y, int w, int h, void* device)
  {
    static_cast<CRendering*>(cbhdl)->m_renderHelper = kodi::gui::GetRenderHelper();
    return static_cast<CRendering*>(cbhdl)->Create(x, y, w, h, device);
  }

  static void OnRenderCB(void* cbhdl)
  {
    if (!static_cast<CRendering*>(cbhdl)->m_renderHelper)
      return;
    static_cast<CRendering*>(cbhdl)->m_renderHelper->Begin();
    static_cast<CRendering*>(cbhdl)->Render();
    static_cast<CRendering*>(cbhdl)->m_renderHelper->End();
  }

  static void OnStopCB(void* cbhdl)
  {
    static_cast<CRendering*>(cbhdl)->Stop();
    static_cast<CRendering*>(cbhdl)->m_renderHelper = nullptr;
  }

  static bool OnDirtyCB(void* cbhdl) { return static_cast<CRendering*>(cbhdl)->Dirty(); }

  std::shared_ptr<kodi::gui::IRenderHelper> m_renderHelper;
};

} /* namespace controls */
} /* namespace gui */
} /* namespace kodi */