summaryrefslogtreecommitdiffstats
path: root/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/Rendering.h
diff options
context:
space:
mode:
Diffstat (limited to 'xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/Rendering.h')
-rw-r--r--xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/Rendering.h217
1 files changed, 217 insertions, 0 deletions
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/Rendering.h b/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/Rendering.h
new file mode 100644
index 0000000..7f5feef
--- /dev/null
+++ b/xbmc/addons/kodi-dev-kit/include/kodi/gui/controls/Rendering.h
@@ -0,0 +1,217 @@
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 "../../c-api/gui/controls/rendering.h"
12#include "../Window.h"
13#include "../renderHelper.h"
14
15#ifdef __cplusplus
16
17namespace kodi
18{
19namespace gui
20{
21namespace controls
22{
23
24//============================================================================
25/// @defgroup cpp_kodi_gui_windows_controls_CRendering Control Rendering
26/// @ingroup cpp_kodi_gui_windows_controls
27/// @brief @cpp_class{ kodi::gui::controls::CRendering }
28/// **Window control for rendering own parts**\n
29/// This rendering control is used when own parts are needed.
30///
31/// You have the control over them to render direct OpenGL or DirectX content
32/// to the screen set by the size of them.
33///
34/// Alternative can be the virtual functions from t his been ignored if the
35/// callbacks are defined by the @ref CRendering_SetIndependentCallbacks
36/// function and class is used as single and not as a parent class.
37///
38/// It has the header @ref Rendering.h "#include <kodi/gui/controls/Rendering.h>"
39/// be included to enjoy it.
40///
41/// Here you find the needed skin part for a @ref Addon_Rendering_control "rendering control".
42///
43/// @note The call of the control is only possible from the corresponding
44/// window as its class and identification number is required.
45///
46class ATTRIBUTE_HIDDEN CRendering : public CAddonGUIControlBase
47{
48public:
49 //==========================================================================
50 /// @ingroup cpp_kodi_gui_windows_controls_CRendering
51 /// @brief Construct a new control.
52 ///
53 /// @param[in] window Related window control class
54 /// @param[in] controlId Used skin xml control id
55 ///
56 CRendering(CWindow* window, int controlId) : CAddonGUIControlBase(window)
57 {
58 m_controlHandle = m_interface->kodi_gui->window->get_control_render_addon(
59 m_interface->kodiBase, m_Window->GetControlHandle(), controlId);
60 if (m_controlHandle)
61 m_interface->kodi_gui->control_rendering->set_callbacks(m_interface->kodiBase,
62 m_controlHandle, this, OnCreateCB,
63 OnRenderCB, OnStopCB, OnDirtyCB);
64 else
65 kodi::Log(ADDON_LOG_FATAL, "kodi::gui::controls::%s can't create control class from Kodi !!!",
66 __FUNCTION__);
67 }
68 //--------------------------------------------------------------------------
69
70 //==========================================================================
71 /// @ingroup cpp_kodi_gui_windows_controls_CRendering
72 /// @brief Destructor.
73 ///
74 ~CRendering() override
75 {
76 m_interface->kodi_gui->control_rendering->destroy(m_interface->kodiBase, m_controlHandle);
77 }
78 //--------------------------------------------------------------------------
79
80 //==========================================================================
81 /// @ingroup cpp_kodi_gui_windows_controls_CRendering
82 /// @brief To create rendering control on Add-on.
83 ///
84 /// Function creates the needed rendering control for Kodi which becomes
85 /// handled and processed from Add-on
86 ///
87 /// @note This is callback function from Kodi to Add-on and not to use
88 /// for calls from add-on to this function.
89 ///
90 /// @param[in] x Horizontal position
91 /// @param[in] y Vertical position
92 /// @param[in] w Width of control
93 /// @param[in] h Height of control
94 /// @param[in] device The device to use. For OpenGL is empty on Direct X is
95 /// the needed device send.
96 /// @return Add-on needs to return true if successed, otherwise false.
97 ///
98 /// @note The @ref kodi::HardwareContext is basically a simple pointer which
99 /// has to be changed to the desired format at the corresponding places using
100 /// <b>`static_cast<...>(...)`</b>.
101 ///
102 virtual bool Create(int x, int y, int w, int h, kodi::HardwareContext device) { return false; }
103 //--------------------------------------------------------------------------
104
105 //==========================================================================
106 /// @ingroup cpp_kodi_gui_windows_controls_CRendering
107 /// @brief Render process call from Kodi.
108 ///
109 /// @note This is callback function from Kodi to Add-on and not to use for
110 /// calls from add-on to this function.
111 ///
112 virtual void Render() {}
113 //--------------------------------------------------------------------------
114
115 //==========================================================================
116 /// @ingroup cpp_kodi_gui_windows_controls_CRendering
117 /// @brief Call from Kodi to stop rendering process.
118 ///
119 /// @note This is callback function from Kodi to Add-on and not to use
120 /// for calls from add-on to this function.
121 ///
122 virtual void Stop() {}
123 //--------------------------------------------------------------------------
124
125 //==========================================================================
126 /// @ingroup cpp_kodi_gui_windows_controls_CRendering
127 /// @brief Call from Kodi where add-on becomes asked about dirty rendering
128 /// region.
129 ///
130 /// @note This is callback function from Kodi to Add-on and not to use
131 /// for calls from add-on to this function.
132 ///
133 /// @return True if a render region is dirty and need rendering.
134 ///
135 virtual bool Dirty() { return false; }
136 //--------------------------------------------------------------------------
137
138 //==========================================================================
139 /// @ingroup cpp_kodi_gui_windows_controls_CRendering
140 /// @anchor CRendering_SetIndependentCallbacks
141 /// @brief If the class is used independent (with "new CRendering")
142 /// and not as parent (with "cCLASS_own : CRendering") from own must
143 /// be the callback from Kodi to add-on overdriven with own functions!
144 ///
145 /// @param[in] cbhdl Addon related class point where becomes given as value on
146 /// related functions.
147 /// @param[in] CBCreate External creation function pointer, see also @ref Create
148 /// about related values
149 /// @param[in] CBRender External render function pointer, see also @ref Render
150 /// about related values
151 /// @param[in] CBStop External stop function pointer, see also @ref Stop
152 /// about related values
153 /// @param[in] CBDirty External dirty function pointer, see also @ref Dirty
154 /// about related values
155 ///
156 void SetIndependentCallbacks(kodi::gui::ClientHandle cbhdl,
157 bool (*CBCreate)(kodi::gui::ClientHandle cbhdl,
158 int x,
159 int y,
160 int w,
161 int h,
162 kodi::HardwareContext device),
163 void (*CBRender)(kodi::gui::ClientHandle cbhdl),
164 void (*CBStop)(kodi::gui::ClientHandle cbhdl),
165 bool (*CBDirty)(kodi::gui::ClientHandle cbhdl))
166 {
167 if (!cbhdl || !CBCreate || !CBRender || !CBStop || !CBDirty)
168 {
169 kodi::Log(ADDON_LOG_ERROR, "kodi::gui::controls::%s called with nullptr !!!", __FUNCTION__);
170 return;
171 }
172
173 m_interface->kodi_gui->control_rendering->set_callbacks(
174 m_interface->kodiBase, m_controlHandle, cbhdl, CBCreate, CBRender, CBStop, CBDirty);
175 }
176 //--------------------------------------------------------------------------
177
178private:
179 /*
180 * Defined callback functions from Kodi to add-on, for use in parent / child system
181 * (is private)!
182 */
183 static bool OnCreateCB(
184 KODI_GUI_CLIENT_HANDLE cbhdl, int x, int y, int w, int h, ADDON_HARDWARE_CONTEXT device)
185 {
186 static_cast<CRendering*>(cbhdl)->m_renderHelper = kodi::gui::GetRenderHelper();
187 return static_cast<CRendering*>(cbhdl)->Create(x, y, w, h, device);
188 }
189
190 static void OnRenderCB(KODI_GUI_CLIENT_HANDLE cbhdl)
191 {
192 if (!static_cast<CRendering*>(cbhdl)->m_renderHelper)
193 return;
194 static_cast<CRendering*>(cbhdl)->m_renderHelper->Begin();
195 static_cast<CRendering*>(cbhdl)->Render();
196 static_cast<CRendering*>(cbhdl)->m_renderHelper->End();
197 }
198
199 static void OnStopCB(KODI_GUI_CLIENT_HANDLE cbhdl)
200 {
201 static_cast<CRendering*>(cbhdl)->Stop();
202 static_cast<CRendering*>(cbhdl)->m_renderHelper = nullptr;
203 }
204
205 static bool OnDirtyCB(KODI_GUI_CLIENT_HANDLE cbhdl)
206 {
207 return static_cast<CRendering*>(cbhdl)->Dirty();
208 }
209
210 std::shared_ptr<kodi::gui::IRenderHelper> m_renderHelper;
211};
212
213} /* namespace controls */
214} /* namespace gui */
215} /* namespace kodi */
216
217#endif /* __cplusplus */