1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_RENDER_PARTICLE_ANIMATION_H 17 #define RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_RENDER_PARTICLE_ANIMATION_H 18 19 #include <memory> 20 21 #include "rs_particle_noise_field.h" 22 #include "rs_render_particle.h" 23 24 #include "animation/rs_render_particle_system.h" 25 #include "animation/rs_render_property_animation.h" 26 #include "common/rs_macros.h" 27 28 namespace OHOS { 29 namespace Rosen { 30 class RSB_EXPORT RSRenderParticleAnimation : public RSRenderPropertyAnimation { 31 public: 32 RSRenderParticleAnimation(AnimationId id, const PropertyId& propertyId, 33 const std::vector<std::shared_ptr<ParticleRenderParams>>& particlesRenderParams); 34 35 ~RSRenderParticleAnimation() override = default; 36 RSRenderParticleAnimation() = default; 37 38 void DumpAnimationInfo(std::string& out) const override; 39 40 bool Marshalling(Parcel& parcel) const override; 41 42 [[nodiscard]] static RSRenderParticleAnimation* Unmarshalling(Parcel& parcel); GetRenderParticle()43 const RSRenderParticleVector& GetRenderParticle() 44 { 45 return renderParticleVector_; 46 } 47 bool Animate(int64_t time, int64_t& minLeftDelayTime) override; 48 void UpdateEmitter(const std::vector<std::shared_ptr<EmitterUpdater>>& emitterUpdater); 49 void UpdateNoiseField(const std::shared_ptr<ParticleNoiseFields>& particleNoiseFields); GetParticleSystem()50 const std::shared_ptr<RSRenderParticleSystem>& GetParticleSystem() 51 { 52 return particleSystem_; 53 } 54 template <typename T> UpdateParamsIfChanged(const std::shared_ptr<T> & updaterValue,std::shared_ptr<T> & targetValue)55 void UpdateParamsIfChanged(const std::shared_ptr<T>& updaterValue, std::shared_ptr<T>& targetValue) 56 { 57 if (updaterValue && updaterValue != targetValue) { 58 targetValue = updaterValue; 59 } 60 } 61 62 protected: 63 void OnAttach() override; 64 void OnDetach() override; 65 66 private: 67 bool ParseParam(Parcel& parcel) override; 68 std::vector<std::shared_ptr<ParticleRenderParams>> particlesRenderParams_; 69 std::shared_ptr<RSRenderParticleSystem> particleSystem_; 70 RSRenderParticleVector renderParticleVector_; 71 std::shared_ptr<ParticleNoiseFields> particleNoiseFields_; 72 }; 73 } // namespace Rosen 74 } // namespace OHOS 75 76 #endif // RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_RENDER_PARTICLE_ANIMATION_H 77