1 #ifndef DALI_RENDER_CALLBACK_H
2 #define DALI_RENDER_CALLBACK_H
5 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/public-api/math/matrix.h>
23 #include <dali/public-api/math/rect.h>
24 #include <dali/public-api/math/vector2.h>
25 #include <dali/public-api/rendering/texture.h>
26 #include <dali/public-api/signals/callback.h>
37 * @class RenderCallbackInput
39 * This structure contains data to be passed into the RenderCallback
42 * RenderCallbackInput inherits from Graphics::NativeDrawInput
46 struct DALI_CORE_API RenderCallbackInput
51 Rect<int32_t> clippingBox;
52 std::vector<uint32_t> textureBindings;
54 std::any eglContext; ///< Storage for EGL Context
58 * @class RenderCallback
60 * RenderCallback is used by the direct rendering feature and allows injecting
61 * custom render code (using native API such as GL directly) into the DALi
62 * rendering stream. The RenderCallback will be executed within own context (unless
63 * native API is context-less) to maintain state separation from DALi render state.
65 * The class wraps CallbackBase object ensuring its type-safe assignment
69 class DALI_CORE_API RenderCallback
73 * Templated member function type
76 using FuncType = bool (T::*)(const RenderCallbackInput&);
79 * @brief Constructor of RenderCallback
81 * @param[in] object Object to invoke
82 * @param[in] func Member function to invoke
87 RenderCallback(T* object, FuncType<T> func)
88 : mCallback(MakeCallback(object, func))
93 * @brief Creates new instance of RenderCallback
96 * @param[in] object Object to invoke
97 * @param[in] func Member function to invoke
98 * @return Unique pointer to the RenderCallback instance
101 static std::unique_ptr<RenderCallback> New(T* object, FuncType<T> func)
103 return std::make_unique<RenderCallback>(object, func);
107 * @brief Explicit cast operator
110 * @return casts RenderCallback to CallbackBase object
112 explicit operator CallbackBase*()
114 return mCallback.get();
118 * @brief Binds DALi textures to the callback
120 * The textures that are bound to the callback will be passed upon
121 * callback execution providing native handles (like GL name) so they
122 * can be used alongside with custom GL code.
124 * Binding texture does not affect lifecycle and it's up to the client-side
125 * to make sure the resource is alive when used inside the callback.
127 * @param[in] textures List of DALi textures to be bound to the callback
130 void BindTextureResources(std::vector<Dali::Texture> textures)
132 mTextureResources = std::move(textures);
136 * @brief Returns list of DALi textures bound to the callback
138 * @return list of textures
140 [[nodiscard]] const std::vector<Dali::Texture>& GetTextureResources() const
142 return mTextureResources;
145 * @brief Explicit cast operator
148 * @return casts RenderCallback to CallbackBase object
150 explicit operator CallbackBase&()
156 * @brief Returns input data passed to the callback upon execution
158 * The input data will be filled by the DALi and Graphics backend
159 * providing DALi rendering related data (such as clipping box) as well as
160 * Graphics native API related data (like EGLContext for GL).
163 * @return Valid RenderCallbackInput structure
165 RenderCallbackInput& GetRenderCallbackInput()
167 return mRenderCallbackInput;
171 std::unique_ptr<CallbackBase> mCallback; //< Callback base object
172 RenderCallbackInput mRenderCallbackInput;
174 std::vector<Dali::Texture> mTextureResources{};
178 #endif // DALI_RENDER_CALLBACK_H