[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / particle-system / particle-modifier.h
1 #ifndef DALI_TOOLKIT_PARTICLE_SYSTEM_PARTICLE_MODIFIER_H
2 #define DALI_TOOLKIT_PARTICLE_SYSTEM_PARTICLE_MODIFIER_H
3 /*
4  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 // INTERNAL INCLUDES
21 #include <dali-toolkit/public-api/particle-system/particle-types.h>
22
23 // EXTERNAL INCLUDES
24 #include <dali/public-api/object/base-handle.h>
25 #include <dali/public-api/signals/callback.h>
26 #include <memory>
27
28 namespace Dali::Toolkit::ParticleSystem::Internal
29 {
30 class ParticleModifier;
31 }
32
33 namespace Dali::Toolkit::ParticleSystem
34 {
35 class ParticleEmitter;
36
37 class ParticleList;
38
39 class DALI_TOOLKIT_API ParticleModifierInterface
40 {
41 public:
42   /**
43    * @brief Destructor
44    */
45   virtual ~ParticleModifierInterface() = default;
46
47   /**
48    * @brief Update function to update the modifier to alter the behavior of particles.
49    * @param[in] particleList       List of particles
50    * @param[in] firstParticleIndex Index of the first particle
51    * @param[in] particleCount      Number of particles
52    */
53   virtual void Update(ParticleList& particleList, uint32_t firstParticleIndex, uint32_t particleCount) = 0;
54
55   /**
56    * @brief Will be called to check whether modifier supports multi-threading
57    *
58    * If modifier supports multi-threading then Update() function will be called
59    * providing partial range of particles to process.
60    *
61    * It is important to make sure, the batch of particles has no dependencies
62    * on particles from outside the batch. If this is the case, the function
63    * must return false and single threaded process will proceed.
64    *
65    * @return True if modifier supports multi-threading
66    */
67   virtual bool IsMultiThreaded()
68   {
69     return false;
70   }
71 };
72
73 /**
74  * @class ParticleModifier
75  *
76  * @brief ParticleModifer allows altering particle behaviour during simulation.
77  *
78  * Multiple modifiers can be used in the modifier stack.
79  *
80  * Output of previous modifier becomes an input of the next one.
81  *
82  */
83 class DALI_TOOLKIT_API ParticleModifier : public Dali::BaseHandle
84 {
85 public:
86   /**
87    * @brief Constructor
88    */
89   ParticleModifier() = default;
90
91   /**
92    * @brief Destructor
93    */
94   ~ParticleModifier() = default;
95
96   /**
97    * @brief Creates new modifier with given functor object.
98    * The modifier takes over the ownership over the functor object.
99    *
100    * @param[in] modifierUpdater Functor for the modifier
101    * @return New ParticleModifier object
102    */
103   static ParticleModifier New(std::unique_ptr<ParticleModifierInterface>&& modifierUpdater);
104
105   /**
106    * @brief Creates new modifier with given class and construction arguments
107    *
108    * @return New ParticleModifier object
109    */
110   template<class T, class... Args>
111   static ParticleModifier New(Args... args)
112   {
113     return New(std::move(std::make_unique<T>(args...)));
114   }
115   /**
116    * @brief Returns associated particle modifier callback
117    *
118    * @return Valid reference to associated callback
119    */
120   ParticleModifierInterface& GetModifierCallback();
121
122   /**
123    * @brief Downcasts a handle to ParticleModifier handle.
124    *
125    * If handle points to an ParticleModifier object, the downcast produces valid handle.
126    * If not, the returned handle is left uninitialized.
127    *
128    * @param[in] handle to An object
129    * @return handle to a ParticleModifier object or an uninitialized handle
130    */
131   static ParticleModifier DownCast(BaseHandle handle);
132
133 private:
134   /// @cond internal
135   /**
136    * @brief This constructor is used by ParticleModifier::New() methods.
137    *
138    * @param [in] impl A pointer to a newly allocated implementation
139    */
140   ParticleModifier(Internal::ParticleModifier* impl);
141   /// @endcond
142 };
143
144 } // namespace Dali::Toolkit::ParticleSystem
145
146 #endif