DirectRendering:
[platform/core/uifw/dali-core.git] / dali / public-api / signals / render-callback.h
1 #ifndef DALI_RENDER_CALLBACK_H
2 #define DALI_RENDER_CALLBACK_H
3
4 /*
5  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/math/matrix.h>
23 #include <dali/public-api/math/vector2.h>
24 #include <dali/public-api/signals/callback.h>
25
26 // EXTERNAL INCLUDES
27 #include <memory>
28
29 namespace Dali
30 {
31 /**
32  * @class RenderCallbackInput
33  *
34  * This structure contains data to be passed into the RenderCallback
35  * functor.
36  *
37  * RenderCallbackInput inherits from Graphics::NativeDrawInput
38  *
39  * @SINCE_2_1.14
40  */
41 struct RenderCallbackInput
42 {
43   Matrix mvp;
44   Matrix projection;
45   Size   size;
46 };
47
48 /**
49  * @class DrawableCallback
50  *
51  * The class wraps CallbackBase object ensuring its type-safe assignment
52  *
53  * @SINCE_2_1.14
54  */
55 class RenderCallback
56 {
57 public:
58   /**
59    * Templated member function type
60    */
61   template<class T>
62   using FuncType = bool (T::*)(const RenderCallbackInput&);
63
64   /**
65    * @brief Constructor of RenderCallback
66    *
67    * @param[in] object Object to invoke
68    * @param[in] func Member function to invoke
69    *
70    * @SINCE_2_1.14
71    */
72   template<class T>
73   RenderCallback(T* object, FuncType<T> func)
74   : mCallback(MakeCallback(object, func))
75   {
76   }
77
78   /**
79    * @brief Creates new instance of RenderCallback
80    *
81    * @SINCE_2_1.14
82    * @param[in] object Object to invoke
83    * @param[in] func Member function to invoke
84    * @return Unique pointer to the RenderCallback instance
85    */
86   template<class T>
87   static std::unique_ptr<RenderCallback> New(T* object, FuncType<T> func)
88   {
89     return std::make_unique<RenderCallback>(object, func);
90   }
91
92   /**
93    * @brief Explicit cast operator
94    *
95    * @SINCE_2_1.14
96    * @return casts RenderCallback to CallbackBase object
97    */
98   explicit operator CallbackBase*()
99   {
100     return mCallback.get();
101   }
102
103   /**
104    * @brief Explicit cast operator
105    *
106    * @SINCE_2_1.14
107    * @return casts RenderCallback to CallbackBase object
108    */
109   explicit operator CallbackBase&()
110   {
111     return *mCallback;
112   }
113
114 private:
115   std::unique_ptr<CallbackBase> mCallback; //< Callback base object
116 };
117 } // namespace Dali
118
119 #endif // DALI_RENDER_CALLBACK_H