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 #ifndef RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_RENDER_PARTICLE_H 16 #define RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_RENDER_PARTICLE_H 17 18 #include <memory> 19 #include <sys/types.h> 20 #include <utility> 21 #include <vector> 22 23 #include "pixel_map.h" 24 25 #include "animation/rs_interpolator.h" 26 #include "common/rs_color.h" 27 #include "common/rs_color_palette.h" 28 #include "common/rs_macros.h" 29 #include "common/rs_vector2.h" 30 #include "render/rs_image.h" 31 32 namespace OHOS { 33 namespace Rosen { 34 enum class ParticleUpdator: uint32_t {NONE = 0, RANDOM, CURVE}; 35 36 enum class ShapeType: uint32_t {RECT = 0, CIRCLE, ELLIPSE, ANNULUS}; 37 38 enum class ParticleType: uint32_t {POINTS = 0, IMAGES}; 39 40 enum class DistributionType: uint32_t {UNIFORM = 0, GAUSSIAN}; 41 42 template<typename T> 43 struct Range { 44 T start_, end_; RangeRange45 Range() : start_(), end_() {} RangeRange46 Range(T a, T b) : start_(a), end_(b) {} 47 WidthRange48 T Width() const 49 { 50 return end_ - start_; 51 } 52 }; 53 54 template<typename T> 55 class RSB_EXPORT ChangeInOverLife { 56 public: 57 T fromValue_; 58 T toValue_; 59 int startMillis_ { 0 }; 60 int endMillis_ { 0 }; 61 std::shared_ptr<RSInterpolator> interpolator_ = nullptr; ChangeInOverLife()62 ChangeInOverLife() : fromValue_(), toValue_(), startMillis_(), endMillis_(), interpolator_() {} ChangeInOverLife(const T & fromValue,const T & toValue,const int & startMillis,const int & endMillis,std::shared_ptr<RSInterpolator> interpolator)63 ChangeInOverLife(const T& fromValue, const T& toValue, const int& startMillis, const int& endMillis, 64 std::shared_ptr<RSInterpolator> interpolator) 65 : fromValue_(fromValue), toValue_(toValue), startMillis_(startMillis), endMillis_(endMillis), 66 interpolator_(std::move(interpolator)) 67 {} 68 ChangeInOverLife(const ChangeInOverLife& change) = default; 69 ChangeInOverLife& operator=(const ChangeInOverLife& change) = default; 70 ~ChangeInOverLife() = default; 71 }; 72 73 template<typename T> 74 class RSB_EXPORT RenderParticleParaType { 75 public: 76 Range<T> val_; 77 ParticleUpdator updator_; 78 Range<float> random_; 79 std::vector<std::shared_ptr<ChangeInOverLife<T>>> valChangeOverLife_; RenderParticleParaType(const Range<T> & val,const ParticleUpdator & updator,const Range<float> & random,const std::vector<std::shared_ptr<ChangeInOverLife<T>>> & valChangeOverLife)80 RenderParticleParaType(const Range<T>& val, const ParticleUpdator& updator, const Range<float>& random, 81 const std::vector<std::shared_ptr<ChangeInOverLife<T>>>& valChangeOverLife) 82 : val_(val), updator_(updator), random_(random), valChangeOverLife_(valChangeOverLife) 83 {} RenderParticleParaType()84 RenderParticleParaType() : val_(), updator_(ParticleUpdator::NONE), random_() {} 85 RenderParticleParaType(const RenderParticleParaType& paraType) = default; 86 RenderParticleParaType& operator=(const RenderParticleParaType& paraType) = default; 87 ~RenderParticleParaType() = default; 88 }; 89 90 class RSB_EXPORT Shape { 91 public: 92 ShapeType type_; 93 Shape() = default; Shape(const ShapeType & type)94 Shape(const ShapeType& type) : type_(type) {} 95 virtual void CalculatePosition(float& positionX, float& positionY) = 0; GetShapeType()96 virtual ShapeType GetShapeType() const 97 { 98 return type_; 99 } 100 101 virtual ~Shape() = default; 102 103 protected: 104 Shape(const Shape& shape) = default; 105 Shape& operator=(const Shape& shape) = default; 106 Shape(Shape&&) = default; 107 Shape& operator=(Shape&&) = default; 108 }; 109 110 class RSB_EXPORT AnnulusRegion : public Shape { 111 public: 112 Vector2f center_ { Vector2f() }; 113 float innerRadius_ { 0.0 }; 114 float outerRadius_ { 0.0 }; 115 float startAngle_ { 0.0 }; 116 float endAngle_ { 0.0 }; 117 AnnulusRegion()118 AnnulusRegion() 119 : Shape(ShapeType::ANNULUS), center_(), innerRadius_(), outerRadius_(), startAngle_(), endAngle_() 120 {} AnnulusRegion(const Vector2f & center,const float & innerRadius,const float & outerRadius,const float & startAngle,const float & endAngle)121 AnnulusRegion(const Vector2f& center, const float& innerRadius, const float& outerRadius, 122 const float & startAngle, const float& endAngle) 123 : Shape(ShapeType::ANNULUS), center_(center), innerRadius_(innerRadius), outerRadius_(outerRadius), 124 startAngle_(startAngle), endAngle_(endAngle) 125 {} 126 AnnulusRegion(const AnnulusRegion& region) = default; 127 AnnulusRegion& operator=(const AnnulusRegion& region) = default; 128 void CalculatePosition(float& positionX, float& positionY); GetShapeType()129 ShapeType GetShapeType() const 130 { 131 return ShapeType::ANNULUS; 132 } 133 134 ~AnnulusRegion() = default; 135 }; 136 137 class RSB_EXPORT EmitterConfig { 138 public: 139 int emitRate_ { 0 }; 140 ShapeType emitShape_; 141 Vector2f position_; 142 Vector2f emitSize_; 143 int32_t particleCount_ { 0 }; 144 Range<int64_t> lifeTime_; 145 ParticleType type_; 146 float radius_ { 0.0 }; 147 std::shared_ptr<RSImage> image_; 148 Vector2f imageSize_; 149 std::shared_ptr<Shape> shape_; 150 EmitterConfig()151 EmitterConfig() 152 : emitRate_(), emitShape_(ShapeType::RECT), position_(), emitSize_(), particleCount_(), lifeTime_(), 153 type_(ParticleType::POINTS), radius_(), image_(), imageSize_(), shape_() 154 {} EmitterConfig(const int & emitRate,const ShapeType & emitShape,const Vector2f & position,const Vector2f & emitSize,const int32_t & particleCount,const Range<int64_t> & lifeTime,const ParticleType & type,const float & radius,const std::shared_ptr<RSImage> & image,const Vector2f & imageSize)155 EmitterConfig(const int& emitRate, const ShapeType& emitShape, const Vector2f& position, const Vector2f& emitSize, 156 const int32_t& particleCount, const Range<int64_t>& lifeTime, const ParticleType& type, const float& radius, 157 const std::shared_ptr<RSImage>& image, const Vector2f& imageSize) 158 : emitRate_(emitRate), emitShape_(emitShape), position_(position), emitSize_(emitSize), 159 particleCount_(particleCount), lifeTime_(lifeTime), type_(type), radius_(radius), image_(std::move(image)), 160 imageSize_(imageSize) 161 { 162 if (image_ != nullptr) { 163 if (const auto& pixelMap = image_->GetPixelMap()) { 164 image_->SetDstRect(RectF(position_.x_, position_.y_, static_cast<float>(pixelMap->GetWidth()), 165 static_cast<float>(pixelMap->GetHeight()))); 166 } else if (image_->GetImage()) { 167 auto drawImage = image_->GetImage(); 168 image_->SetDstRect(RectF(position_.x_, position_.y_, static_cast<float>(drawImage->GetWidth()), 169 static_cast<float>(drawImage->GetHeight()))); 170 } 171 } 172 } 173 EmitterConfig(const EmitterConfig& config) = default; 174 EmitterConfig& operator=(const EmitterConfig& config) = default; 175 ~EmitterConfig() = default; 176 177 void SetConfigShape(const std::shared_ptr<Shape>& shape); 178 }; 179 180 class RSB_EXPORT EmitterUpdater { 181 public: 182 uint32_t emitterIndex_ { 0 }; 183 std::optional<Vector2f> position_; 184 std::optional<Vector2f> emitSize_; 185 std::optional<int> emitRate_; 186 std::shared_ptr<Shape> shape_; 187 188 explicit EmitterUpdater( 189 uint32_t emitterIndex, 190 const std::optional<Vector2f>& position = std::nullopt, 191 const std::optional<Vector2f>& emitSize = std::nullopt, 192 const std::optional<int>& emitRate = std::nullopt) emitterIndex_(emitterIndex)193 : emitterIndex_(emitterIndex), position_(position), emitSize_(emitSize), emitRate_(emitRate) 194 {} 195 EmitterUpdater(const EmitterUpdater& config) = default; 196 EmitterUpdater& operator=(const EmitterUpdater& config) = default; 197 ~EmitterUpdater() = default; 198 199 void Dump(std::string& out) const; 200 void SetShape(const std::shared_ptr<Shape>& shape); 201 }; 202 203 class RSB_EXPORT ParticleVelocity { 204 public: 205 Range<float> velocityValue_; 206 Range<float> velocityAngle_; 207 ParticleVelocity()208 ParticleVelocity() : velocityValue_(), velocityAngle_() {} ParticleVelocity(const Range<float> & velocityValue,const Range<float> & velocityAngle)209 ParticleVelocity(const Range<float>& velocityValue, const Range<float>& velocityAngle) 210 : velocityValue_(velocityValue), velocityAngle_(velocityAngle) 211 {} 212 ParticleVelocity(const ParticleVelocity& velocity) = default; 213 ParticleVelocity& operator=(const ParticleVelocity& velocity) = default; 214 ~ParticleVelocity() = default; 215 }; 216 217 class RSB_EXPORT RenderParticleAcceleration { 218 public: 219 RenderParticleParaType<float> accelerationValue_; 220 RenderParticleParaType<float> accelerationAngle_; 221 222 RenderParticleAcceleration() = default; RenderParticleAcceleration(const RenderParticleParaType<float> & accelerationValue,const RenderParticleParaType<float> & accelerationAngle)223 RenderParticleAcceleration( 224 const RenderParticleParaType<float>& accelerationValue, const RenderParticleParaType<float>& accelerationAngle) 225 : accelerationValue_(accelerationValue), accelerationAngle_(accelerationAngle) 226 {} 227 RenderParticleAcceleration(const RenderParticleAcceleration& acceleration) = default; 228 RenderParticleAcceleration& operator=(const RenderParticleAcceleration& acceleration) = default; 229 ~RenderParticleAcceleration() = default; 230 }; 231 232 class RSB_EXPORT RenderParticleColorParaType { 233 public: 234 Range<Color> colorVal_; 235 DistributionType distribution_; 236 ParticleUpdator updator_; 237 Range<float> redRandom_; 238 Range<float> greenRandom_; 239 Range<float> blueRandom_; 240 Range<float> alphaRandom_; 241 242 std::vector<std::shared_ptr<ChangeInOverLife<Color>>> valChangeOverLife_; RenderParticleColorParaType(const Range<Color> & colorVal,const DistributionType & distribution,const ParticleUpdator & updator,const Range<float> & redRandom,const Range<float> & greenRandom,const Range<float> & blueRandom,const Range<float> & alphaRandom,std::vector<std::shared_ptr<ChangeInOverLife<Color>>> valChangeOverLife)243 RenderParticleColorParaType(const Range<Color>& colorVal, const DistributionType& distribution, 244 const ParticleUpdator& updator, const Range<float>& redRandom, const Range<float>& greenRandom, 245 const Range<float>& blueRandom, const Range<float>& alphaRandom, 246 std::vector<std::shared_ptr<ChangeInOverLife<Color>>> valChangeOverLife) 247 : colorVal_(colorVal), distribution_(distribution), updator_(updator), redRandom_(redRandom), 248 greenRandom_(greenRandom), blueRandom_(blueRandom), alphaRandom_(alphaRandom), 249 valChangeOverLife_(std::move(valChangeOverLife)) 250 {} RenderParticleColorParaType()251 RenderParticleColorParaType() 252 : colorVal_(), distribution_(DistributionType::UNIFORM), updator_(ParticleUpdator::NONE), redRandom_(), 253 greenRandom_(), blueRandom_(), alphaRandom_() 254 {} 255 RenderParticleColorParaType(const RenderParticleColorParaType& color) = default; 256 RenderParticleColorParaType& operator=(const RenderParticleColorParaType& color) = default; 257 ~RenderParticleColorParaType() = default; 258 }; 259 260 class RSB_EXPORT ParticleRenderParams { 261 public: 262 EmitterConfig emitterConfig_; 263 ParticleVelocity velocity_; 264 RenderParticleAcceleration acceleration_; 265 RenderParticleColorParaType color_; 266 RenderParticleParaType<float> opacity_; 267 RenderParticleParaType<float> scale_; 268 RenderParticleParaType<float> spin_; ParticleRenderParams(const EmitterConfig & emitterConfig,const ParticleVelocity & velocity,const RenderParticleAcceleration & acceleration,const RenderParticleColorParaType & color,const RenderParticleParaType<float> & opacity,const RenderParticleParaType<float> & scale,const RenderParticleParaType<float> & spin)269 explicit ParticleRenderParams(const EmitterConfig& emitterConfig, const ParticleVelocity& velocity, 270 const RenderParticleAcceleration& acceleration, const RenderParticleColorParaType& color, 271 const RenderParticleParaType<float>& opacity, const RenderParticleParaType<float>& scale, 272 const RenderParticleParaType<float>& spin) 273 : emitterConfig_(emitterConfig), velocity_(velocity), acceleration_(acceleration), color_(color), 274 opacity_(opacity), scale_(scale), spin_(spin) 275 {} ParticleRenderParams()276 ParticleRenderParams() : emitterConfig_(), velocity_(), acceleration_(), color_(), opacity_(), scale_(), spin_() {}; 277 ParticleRenderParams(const ParticleRenderParams& params) = default; 278 ParticleRenderParams& operator=(const ParticleRenderParams& params) = default; 279 ~ParticleRenderParams() = default; 280 281 int GetEmitRate() const; 282 const ShapeType& GetEmitShape() const; 283 const Vector2f& GetEmitPosition() const; 284 const Vector2f& GetEmitSize() const; 285 int32_t GetParticleCount() const; 286 int64_t GetLifeTimeStartValue() const; 287 int64_t GetLifeTimeEndValue() const; 288 const ParticleType& GetParticleType() const; 289 float GetParticleRadius() const; 290 const std::shared_ptr<RSImage>& GetParticleImage(); 291 const Vector2f& GetImageSize() const; 292 const std::shared_ptr<Shape>& GetShape() const; 293 294 float GetVelocityStartValue() const; 295 float GetVelocityEndValue() const; 296 float GetVelocityStartAngle() const; 297 float GetVelocityEndAngle() const; 298 299 float GetAccelerationStartValue() const; 300 float GetAccelerationEndValue() const; 301 float GetAccelerationStartAngle() const; 302 float GetAccelerationEndAngle() const; 303 const ParticleUpdator& GetAccelerationValueUpdator(); 304 const ParticleUpdator& GetAccelerationAngleUpdator(); 305 float GetAccelRandomValueStart() const; 306 float GetAccelRandomValueEnd() const; 307 float GetAccelRandomAngleStart() const; 308 float GetAccelRandomAngleEnd() const; 309 310 const Color& GetColorStartValue(); 311 const Color& GetColorEndValue(); 312 const DistributionType& GetColorDistribution(); 313 const ParticleUpdator& GetColorUpdator(); 314 float GetRedRandomStart() const; 315 float GetRedRandomEnd() const; 316 float GetGreenRandomStart() const; 317 float GetGreenRandomEnd() const; 318 float GetBlueRandomStart() const; 319 float GetBlueRandomEnd() const; 320 float GetAlphaRandomStart() const; 321 float GetAlphaRandomEnd() const; 322 323 float GetOpacityStartValue(); 324 float GetOpacityEndValue(); 325 const ParticleUpdator& GetOpacityUpdator(); 326 float GetOpacityRandomStart() const; 327 float GetOpacityRandomEnd() const; 328 329 float GetScaleStartValue(); 330 float GetScaleEndValue(); 331 const ParticleUpdator& GetScaleUpdator(); 332 float GetScaleRandomStart() const; 333 float GetScaleRandomEnd() const; 334 335 float GetSpinStartValue(); 336 float GetSpinEndValue(); 337 const ParticleUpdator& GetSpinUpdator(); 338 339 const std::vector<std::shared_ptr<ChangeInOverLife<float>>>& GetAcceValChangeOverLife(); 340 const std::vector<std::shared_ptr<ChangeInOverLife<float>>>& GetAcceAngChangeOverLife(); 341 const std::vector<std::shared_ptr<ChangeInOverLife<float>>>& GetOpacityChangeOverLife(); 342 const std::vector<std::shared_ptr<ChangeInOverLife<float>>>& GetScaleChangeOverLife(); 343 const std::vector<std::shared_ptr<ChangeInOverLife<float>>>& GetSpinChangeOverLife(); 344 const std::vector<std::shared_ptr<ChangeInOverLife<Color>>>& GetColorChangeOverLife(); 345 346 float GetSpinRandomStart() const; 347 float GetSpinRandomEnd() const; 348 size_t GetImageIndex() const; 349 350 void SetEmitConfig(const EmitterConfig& emitConfig); 351 void SetParticleVelocity(const ParticleVelocity& velocity); 352 void SetParticleAcceleration(const RenderParticleAcceleration& acceleration); 353 void SetParticleColor(const RenderParticleColorParaType& color); 354 void SetParticleOpacity(const RenderParticleParaType<float>& opacity); 355 void SetParticleScale(const RenderParticleParaType<float>& scale); 356 void SetParticleSpin(const RenderParticleParaType<float>& spin); 357 void SetImageIndex(size_t imageIndex); 358 359 private: 360 size_t imageIndex_ = 0; 361 }; 362 363 class RSB_EXPORT RSRenderParticle { 364 public: 365 explicit RSRenderParticle(const std::shared_ptr<ParticleRenderParams>& particleParams); 366 RSRenderParticle() = default; 367 ~RSRenderParticle() = default; 368 // Set methods 369 void SetPosition(const Vector2f& position); 370 void SetVelocity(const Vector2f& velocity); 371 void SetAcceleration(const Vector2f& acceleration); 372 void SetSpin(const float& spin); 373 void SetOpacity(const float& opacity); 374 void SetColor(const Color& color); 375 void SetScale(const float& scale); 376 void SetRadius(const float& radius); 377 void SetImage(const std::shared_ptr<RSImage>& image); 378 void SetImageSize(const Vector2f& imageSize); 379 void SetParticleType(const ParticleType& particleType); 380 void SetActiveTime(const int64_t& activeTime); 381 void SetAccelerationValue(float accelerationValue); 382 void SetAccelerationAngle(float accelerationAngle); 383 void SetRedF(float redF); 384 void SetGreenF(float greenF); 385 void SetBlueF(float blueF); 386 void SetAlphaF(float alphaF); 387 388 // Get methods 389 const Vector2f& GetPosition(); 390 const Vector2f& GetVelocity(); 391 const Vector2f& GetAcceleration(); 392 float GetSpin(); 393 float GetOpacity(); 394 const Color& GetColor(); 395 float GetScale(); 396 float GetRadius(); 397 float GetAccelerationValue(); 398 float GetAccelerationAngle(); 399 float GetRedSpeed(); 400 float GetGreenSpeed(); 401 float GetBlueSpeed(); 402 float GetAlphaSpeed(); 403 float GetOpacitySpeed(); 404 float GetScaleSpeed(); 405 float GetSpinSpeed(); 406 float GetAccelerationValueSpeed(); 407 float GetAccelerationAngleSpeed(); 408 float GetRedF(); 409 float GetGreenF(); 410 float GetBlueF(); 411 float GetAlphaF(); 412 const std::shared_ptr<RSImage>& GetImage(); 413 const Vector2f& GetImageSize(); 414 const ParticleType& GetParticleType(); 415 int64_t GetActiveTime(); 416 const std::shared_ptr<ParticleRenderParams>& GetParticleRenderParams(); 417 418 size_t GetImageIndex() const; 419 420 // Other methods 421 void InitProperty(); 422 bool IsAlive() const; 423 void SetIsDead(); 424 static float GetRandomValue(float min, float max); 425 void SetColor(); 426 int GenerateColorComponent(double mean, double stddev); 427 Vector2f CalculateParticlePosition(const ShapeType& emitShape, const Vector2f& position, const Vector2f& emitSize, 428 const std::shared_ptr<Shape>& shape); 429 std::shared_ptr<ParticleRenderParams> particleParams_; 430 431 bool operator==(const RSRenderParticle& rhs) 432 { 433 return (position_ == rhs.position_) && (velocity_ == rhs.velocity_) && (acceleration_ == rhs.acceleration_) && 434 (scale_ == rhs.scale_) && (spin_ == rhs.spin_) && (opacity_ == rhs.opacity_) && (color_ == rhs.color_) && 435 (radius_ == rhs.radius_) && (particleType_ == rhs.particleType_) && (activeTime_ == rhs.activeTime_) && 436 (lifeTime_ == rhs.lifeTime_) && (imageSize_ == rhs.imageSize_) && (imageIndex_ == rhs.imageIndex_); 437 } 438 Lerp(const Color & start,const Color & end,float t)439 static Color Lerp(const Color& start, const Color& end, float t) 440 { 441 Color result; 442 result.SetRed(start.GetRed() + static_cast<int>(std::round((end.GetRed() - start.GetRed()) * t))); 443 result.SetGreen(start.GetGreen() + static_cast<int>(std::round((end.GetGreen() - start.GetGreen()) * t))); 444 result.SetBlue(start.GetBlue() + static_cast<int>(std::round((end.GetBlue() - start.GetBlue()) * t))); 445 result.SetAlpha(start.GetAlpha() + static_cast<int>(std::round((end.GetAlpha() - start.GetAlpha()) * t))); 446 return result; 447 } 448 449 private: 450 Vector2f position_ = {0.f, 0.f}; 451 Vector2f velocity_ = {0.f, 0.f}; 452 Vector2f acceleration_ = {0.f, 0.f}; 453 float scale_ = 1.f; 454 float spin_ = 0.f; 455 float opacity_ = 1.f; 456 Color color_ = RgbPalette::White(); 457 float radius_ = 0.f; 458 std::shared_ptr<RSImage> image_; 459 Vector2f imageSize_; 460 ParticleType particleType_ = ParticleType::POINTS; 461 int64_t activeTime_ = 0; 462 int64_t lifeTime_ = 0; 463 bool dead_ = false; 464 float accelerationValue_ = 0.f; 465 float accelerationAngle_ = 0.f; 466 float redSpeed_ = 0.f; 467 float greenSpeed_ = 0.f; 468 float blueSpeed_ = 0.f; 469 float alphaSpeed_ = 0.f; 470 float opacitySpeed_ = 0.f; 471 float scaleSpeed_ = 0.f; 472 float spinSpeed_ = 0.f; 473 float accelerationValueSpeed_ = 0.f; 474 float accelerationAngleSpeed_ = 0.f; 475 float redF_ = 0.f; 476 float greenF_ = 0.f; 477 float blueF_ = 0.f; 478 float alphaF_ = 0.f; 479 size_t imageIndex_ = 0; 480 }; 481 482 class RSB_EXPORT RSRenderParticleVector { 483 public: RSRenderParticleVector(std::vector<std::shared_ptr<RSRenderParticle>> && renderParticleVector,std::vector<std::shared_ptr<RSImage>> imageVector)484 explicit RSRenderParticleVector(std::vector<std::shared_ptr<RSRenderParticle>>&& renderParticleVector, 485 std::vector<std::shared_ptr<RSImage>> imageVector) 486 : renderParticleVector_(std::move(renderParticleVector)), imageVector_(std::move(imageVector)) 487 {} 488 RSRenderParticleVector() = default; 489 ~RSRenderParticleVector() = default; RSRenderParticleVector(const RSRenderParticleVector & other)490 RSRenderParticleVector(const RSRenderParticleVector& other) 491 : renderParticleVector_(other.renderParticleVector_), imageVector_(other.imageVector_) 492 {} 493 494 RSRenderParticleVector& operator=(const RSRenderParticleVector& other) 495 { 496 if (this != &other) { 497 renderParticleVector_ = other.renderParticleVector_; 498 imageVector_ = other.imageVector_; 499 } 500 return *this; 501 } 502 GetParticleSize()503 int GetParticleSize() const 504 { 505 return renderParticleVector_.size(); 506 } 507 GetParticleVector()508 const std::vector<std::shared_ptr<RSRenderParticle>>& GetParticleVector() const 509 { 510 return renderParticleVector_; 511 } 512 GetParticleImageVector()513 const std::vector<std::shared_ptr<RSImage>>& GetParticleImageVector() const 514 { 515 return imageVector_; 516 } 517 GetParticleImageCount()518 size_t GetParticleImageCount() const 519 { 520 return imageVector_.size(); 521 } 522 523 bool operator==(const RSRenderParticleVector& rhs) const 524 { 525 bool equal = false; 526 if (this->renderParticleVector_.size() != rhs.renderParticleVector_.size() || 527 this->imageVector_.size() != rhs.imageVector_.size()) { 528 return false; 529 } 530 if (this->renderParticleVector_.size() == 0 && this->imageVector_.size() == 0) { 531 return true; 532 } 533 for (size_t i = 0; i < this->renderParticleVector_.size(); i++) { 534 equal = equal && (this->renderParticleVector_[i] == rhs.renderParticleVector_[i]) && 535 (*(this->renderParticleVector_[i]) == *(rhs.renderParticleVector_[i])); 536 } 537 for (size_t i = 0; i < this->imageVector_.size(); i++) { 538 equal = equal && (this->imageVector_[i] == rhs.imageVector_[i]) && 539 ((*(this->imageVector_[i])).IsEqual(*(rhs.imageVector_[i]))); 540 } 541 return equal; 542 } 543 544 friend class RSRenderParticleAnimation; 545 546 private: 547 std::vector<std::shared_ptr<RSRenderParticle>> renderParticleVector_; 548 std::vector<std::shared_ptr<RSImage>> imageVector_; 549 }; 550 } // namespace Rosen 551 } // namespace OHOS 552 553 #endif // RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_RENDER_PARTICLE_H 554