1 /*
2 * Copyright (c) 2022-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 #include "modifier/rs_render_property.h"
17
18 #include <iomanip>
19
20 #include "rs_profiler.h"
21
22 #include "effect/rs_render_filter_base.h"
23 #include "effect/rs_render_mask_base.h"
24 #include "effect/rs_render_shader_base.h"
25 #include "modifier_ng/rs_render_modifier_ng.h"
26 #include "pipeline/rs_render_node.h"
27 #include "platform/common/rs_log.h"
28
29 namespace OHOS {
30 namespace Rosen {
31
Attach(RSRenderNode & node,std::weak_ptr<ModifierNG::RSRenderModifier> modifier)32 void RSRenderPropertyBase::Attach(RSRenderNode& node, std::weak_ptr<ModifierNG::RSRenderModifier> modifier)
33 {
34 node_ = node.weak_from_this();
35 modifier_ = modifier;
36 node.RegisterProperty(shared_from_this());
37 OnChange();
38 OnAttach(node, modifier);
39 }
40
Detach()41 void RSRenderPropertyBase::Detach()
42 {
43 if (auto node = node_.lock()) {
44 node->UnregisterProperty(id_);
45 }
46 OnDetach();
47 modifier_.reset();
48 node_.reset();
49 }
50
OnChange() const51 void RSRenderPropertyBase::OnChange() const
52 {
53 if (auto modifier = modifier_.lock()) {
54 modifier->SetDirty();
55 }
56 }
57
UpdatePropertyUnitNG(ModifierNG::RSPropertyType propertyType)58 void RSRenderPropertyBase::UpdatePropertyUnitNG(ModifierNG::RSPropertyType propertyType)
59 {
60 switch (propertyType) {
61 case ModifierNG::RSPropertyType::FRAME:
62 case ModifierNG::RSPropertyType::TRANSLATE:
63 SetPropertyUnit(RSPropertyUnit::PIXEL_POSITION);
64 break;
65 case ModifierNG::RSPropertyType::SCALE:
66 SetPropertyUnit(RSPropertyUnit::RATIO_SCALE);
67 break;
68 case ModifierNG::RSPropertyType::ROTATION_X:
69 case ModifierNG::RSPropertyType::ROTATION_Y:
70 case ModifierNG::RSPropertyType::ROTATION:
71 SetPropertyUnit(RSPropertyUnit::ANGLE_ROTATION);
72 break;
73 default:
74 SetPropertyUnit(RSPropertyUnit::UNKNOWN);
75 break;
76 }
77 }
78
Unmarshalling(Parcel & parcel,std::shared_ptr<RSRenderPropertyBase> & val)79 bool RSRenderPropertyBase::Unmarshalling(Parcel& parcel, std::shared_ptr<RSRenderPropertyBase>& val)
80 {
81 val.reset();
82 RSPropertyType type = RSPropertyType::INVALID;
83 if (!RSMarshallingHelper::Unmarshalling(parcel, type)) {
84 ROSEN_LOGE("RSRenderPropertyBase::Unmarshalling: unmarshalling type failed");
85 return false;
86 }
87 // If the type is RSPropertyType::INVALID, the property will be unmarshalled as a null pointer.
88 if (type == RSPropertyType::INVALID) {
89 return true;
90 }
91 bool isAnimatable = false;
92 if (!RSMarshallingHelper::Unmarshalling(parcel, isAnimatable)) {
93 ROSEN_LOGE("RSRenderPropertyBase::Unmarshalling: unmarshalling isAnimatable failed");
94 return false;
95 }
96 uint16_t key = static_cast<uint16_t>(isAnimatable) << 8 | static_cast<uint16_t>(type);
97 auto it = UnmarshallingFuncs_.find(key);
98 if (it == UnmarshallingFuncs_.end()) {
99 ROSEN_LOGE("RSRenderPropertyBase::Unmarshalling: no unmarshalling function for type %d, isAnimatable %d",
100 static_cast<int>(type), isAnimatable);
101 return false;
102 }
103 return (it->second)(parcel, val);
104 }
105
106 template<>
ToFloat() const107 float RSRenderAnimatableProperty<float>::ToFloat() const
108 {
109 return std::fabs(RSRenderProperty<float>::stagingValue_);
110 }
111
112 template<>
ToFloat() const113 float RSRenderAnimatableProperty<Vector4f>::ToFloat() const
114 {
115 return RSRenderProperty<Vector4f>::stagingValue_.GetLength();
116 }
117
118 template<>
ToFloat() const119 float RSRenderAnimatableProperty<Quaternion>::ToFloat() const
120 {
121 return RSRenderProperty<Quaternion>::stagingValue_.GetLength();
122 }
123
124 template<>
ToFloat() const125 float RSRenderAnimatableProperty<Vector2f>::ToFloat() const
126 {
127 return RSRenderProperty<Vector2f>::stagingValue_.GetLength();
128 }
129
130 template<>
ToFloat() const131 float RSRenderAnimatableProperty<Vector3f>::ToFloat() const
132 {
133 return RSRenderProperty<Vector3f>::stagingValue_.GetLength();
134 }
135
operator +=(const std::shared_ptr<RSRenderPropertyBase> & a,const std::shared_ptr<const RSRenderPropertyBase> & b)136 std::shared_ptr<RSRenderPropertyBase> operator+=(
137 const std::shared_ptr<RSRenderPropertyBase>& a, const std::shared_ptr<const RSRenderPropertyBase>& b)
138 {
139 if (a == nullptr) {
140 return {};
141 }
142
143 return a->Add(b);
144 }
145
operator -=(const std::shared_ptr<RSRenderPropertyBase> & a,const std::shared_ptr<const RSRenderPropertyBase> & b)146 std::shared_ptr<RSRenderPropertyBase> operator-=(
147 const std::shared_ptr<RSRenderPropertyBase>& a, const std::shared_ptr<const RSRenderPropertyBase>& b)
148 {
149 if (a == nullptr) {
150 return {};
151 }
152
153 return a->Minus(b);
154 }
155
operator *=(const std::shared_ptr<RSRenderPropertyBase> & value,const float scale)156 std::shared_ptr<RSRenderPropertyBase> operator*=(const std::shared_ptr<RSRenderPropertyBase>& value, const float scale)
157 {
158 if (value == nullptr) {
159 return {};
160 }
161
162 return value->Multiply(scale);
163 }
164
operator +(const std::shared_ptr<const RSRenderPropertyBase> & a,const std::shared_ptr<const RSRenderPropertyBase> & b)165 std::shared_ptr<RSRenderPropertyBase> operator+(
166 const std::shared_ptr<const RSRenderPropertyBase>& a, const std::shared_ptr<const RSRenderPropertyBase>& b)
167 {
168 if (a == nullptr) {
169 return {};
170 }
171
172 auto clone = a->Clone();
173 if (clone == nullptr) {
174 return {};
175 }
176 return clone->Add(b);
177 }
178
operator -(const std::shared_ptr<const RSRenderPropertyBase> & a,const std::shared_ptr<const RSRenderPropertyBase> & b)179 std::shared_ptr<RSRenderPropertyBase> operator-(
180 const std::shared_ptr<const RSRenderPropertyBase>& a, const std::shared_ptr<const RSRenderPropertyBase>& b)
181 {
182 if (a == nullptr) {
183 return {};
184 }
185
186 auto clone = a->Clone();
187 if (clone == nullptr) {
188 return {};
189 }
190 return clone->Minus(b);
191 }
192
operator *(const std::shared_ptr<const RSRenderPropertyBase> & value,const float scale)193 std::shared_ptr<RSRenderPropertyBase> operator*(
194 const std::shared_ptr<const RSRenderPropertyBase>& value, const float scale)
195 {
196 if (value == nullptr) {
197 return {};
198 }
199
200 auto clone = value->Clone();
201 if (clone == nullptr) {
202 return {};
203 }
204
205 return clone->Multiply(scale);
206 }
207
operator ==(const std::shared_ptr<const RSRenderPropertyBase> & a,const std::shared_ptr<const RSRenderPropertyBase> & b)208 bool operator==(
209 const std::shared_ptr<const RSRenderPropertyBase>& a, const std::shared_ptr<const RSRenderPropertyBase>& b)
210 {
211 if (a == nullptr) {
212 return {};
213 }
214
215 return a->IsEqual(b);
216 }
217
operator !=(const std::shared_ptr<const RSRenderPropertyBase> & a,const std::shared_ptr<const RSRenderPropertyBase> & b)218 bool operator!=(
219 const std::shared_ptr<const RSRenderPropertyBase>& a, const std::shared_ptr<const RSRenderPropertyBase>& b)
220 {
221 if (a == nullptr) {
222 return {};
223 }
224
225 return !a->IsEqual(b);
226 }
227
228 template<typename T>
OnUnmarshalling(Parcel & parcel,std::shared_ptr<RSRenderPropertyBase> & val)229 bool RSRenderProperty<T>::OnUnmarshalling(Parcel& parcel, std::shared_ptr<RSRenderPropertyBase>& val)
230 {
231 auto ret = new RSRenderProperty<T>();
232 if (ret == nullptr) {
233 ROSEN_LOGE("%s Creating property failed", __PRETTY_FUNCTION__);
234 return false;
235 }
236 if (!RSMarshallingHelper::UnmarshallingPidPlusId(parcel, ret->id_) ||
237 !RSMarshallingHelper::Unmarshalling(parcel, ret->stagingValue_)) {
238 ROSEN_LOGE("%s Unmarshalling failed", __PRETTY_FUNCTION__);
239 delete ret;
240 return false;
241 }
242 val.reset(ret);
243 return true;
244 }
245
246 template<typename T>
OnUnmarshalling(Parcel & parcel,std::shared_ptr<RSRenderPropertyBase> & val)247 bool RSRenderAnimatableProperty<T>::OnUnmarshalling(Parcel& parcel, std::shared_ptr<RSRenderPropertyBase>& val)
248 {
249 auto ret = new RSRenderAnimatableProperty<T>();
250 if (ret == nullptr) {
251 ROSEN_LOGE("%s Creating property failed", __PRETTY_FUNCTION__);
252 return false;
253 }
254 if (!RSMarshallingHelper::UnmarshallingPidPlusId(parcel, ret->id_) ||
255 !RSMarshallingHelper::Unmarshalling(parcel, ret->stagingValue_) ||
256 !RSMarshallingHelper::Unmarshalling(parcel, ret->unit_)) {
257 ROSEN_LOGE("%s Unmarshalling failed", __PRETTY_FUNCTION__);
258 delete ret;
259 return false;
260 }
261 val.reset(ret);
262 return true;
263 }
264
265 template<>
Dump(std::string & out) const266 void RSRenderProperty<bool>::Dump(std::string& out) const
267 {
268 out += "[" + std::string(Get() ? "true" : "false") + "]";
269 }
270
271 template<>
Dump(std::string & out) const272 void RSRenderProperty<int>::Dump(std::string& out) const
273 {
274 out += "[" + std::to_string(Get()) + "]";
275 }
276
277 template<>
Dump(std::string & out) const278 void RSRenderProperty<float>::Dump(std::string& out) const
279 {
280 std::stringstream ss;
281 ss << "[" << std::fixed << std::setprecision(1) << Get() << "]";
282 out += ss.str();
283 }
284
285 template<>
Dump(std::string & out) const286 void RSRenderProperty<Quaternion>::Dump(std::string& out) const
287 {
288 Quaternion q = Get();
289 std::stringstream ss;
290 ss << std::fixed << std::setprecision(1);
291 ss << "[x:" << q.x_ << " y:" << q.y_ << " z:" << q.z_ << " w:" << q.w_ << +"]";
292 out += ss.str();
293 }
294
295 template<>
Dump(std::string & out) const296 void RSRenderProperty<Vector2f>::Dump(std::string& out) const
297 {
298 Vector2f v2f = Get();
299 std::stringstream ss;
300 ss << std::fixed << std::setprecision(1) << "[x:" << v2f.x_ << " y:" << v2f.y_ << "]";
301 out += ss.str();
302 }
303
304 template<>
Dump(std::string & out) const305 void RSRenderProperty<Vector3f>::Dump(std::string& out) const
306 {
307 Vector3f v3f = Get();
308 std::stringstream ss;
309 ss << std::fixed << std::setprecision(1) << "[x:" << v3f.x_ << " y:" << v3f.y_ << " z:" << v3f.z_ << "]";
310 out += ss.str();
311 }
312
313 template<>
Dump(std::string & out) const314 void RSRenderProperty<Color>::Dump(std::string& out) const
315 {
316 Get().Dump(out);
317 }
318
319 template<>
Dump(std::string & out) const320 void RSRenderProperty<Vector4<Color>>::Dump(std::string& out) const
321 {
322 Vector4<Color> v4Color = Get();
323 out += "[left";
324 v4Color.x_.Dump(out);
325 out += " top";
326 v4Color.y_.Dump(out);
327 out += " right";
328 v4Color.z_.Dump(out);
329 out += " bottom";
330 v4Color.w_.Dump(out);
331 out += ']';
332 }
333
334 template<>
Dump(std::string & out) const335 void RSRenderProperty<RRect>::Dump(std::string& out) const
336 {
337 const auto& rrect = stagingValue_;
338 out += "[rect:[x:";
339 out += std::to_string(rrect.rect_.left_) + " y:";
340 out += std::to_string(rrect.rect_.top_) + " width:";
341 out += std::to_string(rrect.rect_.width_) + " height:";
342 out += std::to_string(rrect.rect_.height_) + "]";
343 out += " radius:[[";
344 out += std::to_string(rrect.radius_[0][0]) + " " + std::to_string(rrect.radius_[0][1]) + "] [";
345 out += std::to_string(rrect.radius_[1][0]) + " " + std::to_string(rrect.radius_[1][1]) + "] [";
346 out += std::to_string(rrect.radius_[2][0]) + " " + std::to_string(rrect.radius_[2][1]) + "] ["; // 2 is vector index
347 out += std::to_string(rrect.radius_[3][0]) + " " + std::to_string(rrect.radius_[3][1]) + "]"; // 3 is vector index
348 out += "]";
349 }
350
351 template<>
Dump(std::string & out) const352 void RSRenderProperty<Drawing::DrawCmdListPtr>::Dump(std::string& out) const
353 {
354 auto propertyData = Get();
355 if (propertyData != nullptr) {
356 out += "drawCmdList[";
357 propertyData->Dump(out);
358 out += ']';
359 }
360 }
361
362 template<>
GetSize() const363 size_t RSRenderProperty<Drawing::DrawCmdListPtr>::GetSize() const
364 {
365 auto propertyData = Get();
366 size_t size = sizeof(*this);
367 if (propertyData != nullptr) {
368 size += propertyData->GetSize();
369 }
370 return size;
371 }
372
373 template<>
Dump(std::string & out) const374 void RSRenderProperty<ForegroundColorStrategyType>::Dump(std::string& out) const
375 {
376 out += std::to_string(static_cast<int>(Get()));
377 }
378
379 template<>
Dump(std::string & out) const380 void RSRenderProperty<SkMatrix>::Dump(std::string& out) const
381 {
382 #ifdef TODO_M133_SKIA
383 (void)out; // todo : Intrusive modification of the waiting turn
384 #else
385 Get().dump(out, 0);
386 #endif
387 }
388
389 template<>
Dump(std::string & out) const390 void RSRenderProperty<std::shared_ptr<RSLinearGradientBlurPara>>::Dump(std::string& out) const
391 {
392 auto property = Get();
393 if (property != nullptr) {
394 property->Dump(out);
395 }
396 }
397
398 template<>
Dump(std::string & out) const399 void RSRenderProperty<std::shared_ptr<MotionBlurParam>>::Dump(std::string& out) const
400 {
401 auto property = Get();
402 if (property != nullptr) {
403 property->Dump(out);
404 }
405 }
406
407 template<>
Dump(std::string & out) const408 void RSRenderProperty<std::shared_ptr<RSMagnifierParams>>::Dump(std::string& out) const
409 {
410 auto property = Get();
411 if (property != nullptr) {
412 property->Dump(out);
413 }
414 }
415
416 template<>
Dump(std::string & out) const417 void RSRenderProperty<std::vector<std::shared_ptr<EmitterUpdater>>>::Dump(std::string& out) const
418 {
419 auto property = Get();
420 out += '[';
421 bool found = false;
422 for (auto& eu : property) {
423 if (eu != nullptr) {
424 found = true;
425 out += "emitterUpdater";
426 eu->Dump(out);
427 out += ' ';
428 }
429 }
430 if (found) {
431 out.pop_back();
432 }
433 out += ']';
434 }
435
436 template<>
Dump(std::string & out) const437 void RSRenderProperty<std::shared_ptr<ParticleNoiseFields>>::Dump(std::string& out) const
438 {
439 auto property = Get();
440 if (property != nullptr) {
441 property->Dump(out);
442 }
443 }
444
445 template<>
Dump(std::string & out) const446 void RSRenderProperty<std::shared_ptr<RSMask>>::Dump(std::string& out) const
447 {
448 auto property = Get();
449 if (property != nullptr) {
450 property->Dump(out);
451 }
452 }
453
454 template<>
Dump(std::string & out) const455 void RSRenderProperty<std::shared_ptr<RSShader>>::Dump(std::string& out) const
456 {
457 if (!Get() || !Get()->GetDrawingShader()) {
458 out += "[null]";
459 return;
460 }
461 out += "[";
462 out += std::to_string(static_cast<int>(Get()->GetDrawingShader()->GetType()));
463 out += "]";
464 }
465
466 template<>
Dump(std::string & out) const467 void RSRenderProperty<std::shared_ptr<RSNGRenderFilterBase>>::Dump(std::string& out) const
468 {
469 if (auto property = Get()) {
470 property->Dump(out);
471 return;
472 }
473 out += "[null]";
474 }
475
476 template<>
Dump(std::string & out) const477 void RSRenderProperty<std::shared_ptr<RSNGRenderShaderBase>>::Dump(std::string& out) const
478 {
479 if (auto property = Get()) {
480 property->Dump(out);
481 return;
482 }
483 out += "[null]";
484 }
485
486 template<>
Dump(std::string & out) const487 void RSRenderProperty<std::shared_ptr<RSNGRenderMaskBase>>::Dump(std::string& out) const
488 {
489 if (auto property = Get()) {
490 property->Dump(out);
491 return;
492 }
493 out += "[null]";
494 }
495
496 template<>
Dump(std::string & out) const497 void RSRenderProperty<std::shared_ptr<RSImage>>::Dump(std::string& out) const
498 {
499 if (!Get()) {
500 out += "[null]";
501 return;
502 }
503 std::string info;
504 Get()->Dump(info, 0);
505 info.erase(std::remove_if(info.begin(), info.end(), [](auto c) { return c == '\t' || c == '\n'; }), info.end());
506 out += "[\"" + info + "\"]";
507 }
508
509 template<>
Dump(std::string & out) const510 void RSRenderProperty<std::shared_ptr<RSPath>>::Dump(std::string& out) const
511 {
512 if (!Get()) {
513 out += "[null]";
514 return;
515 }
516 const auto& path = Get()->GetDrawingPath();
517 const auto bounds = path.GetBounds();
518 out += "[length:";
519 out += std::to_string(path.GetLength(false)) + " bounds[x:";
520 out += std::to_string(bounds.GetLeft()) + " y:";
521 out += std::to_string(bounds.GetTop()) + " width:";
522 out += std::to_string(bounds.GetWidth()) + " height:";
523 out += std::to_string(bounds.GetHeight()) + "] valid:";
524 out += std::string(path.IsValid() ? "true" : "false");
525 out += "]";
526 }
527
528 template<>
Dump(std::string & out) const529 void RSRenderProperty<Gravity>::Dump(std::string& out) const
530 {
531 out += "[";
532 out += std::to_string(static_cast<int>(Get()));
533 out += "]";
534 }
535
536 template<>
Dump(std::string & out) const537 void RSRenderProperty<Drawing::Matrix>::Dump(std::string& out) const
538 {
539 out += "[";
540 Drawing::Matrix::Buffer buffer;
541 Get().GetAll(buffer);
542 for (const auto& v : buffer) {
543 out += std::to_string(v) + " ";
544 }
545 out.pop_back();
546 out += "]";
547 }
548
549 template<>
IsNearEqual(const std::shared_ptr<RSRenderPropertyBase> & value,float zeroThreshold) const550 bool RSRenderAnimatableProperty<float>::IsNearEqual(
551 const std::shared_ptr<RSRenderPropertyBase>& value, float zeroThreshold) const
552 {
553 auto animatableProperty = std::static_pointer_cast<const RSRenderAnimatableProperty<float>>(value);
554 if (animatableProperty != nullptr) {
555 return fabs(RSRenderProperty<float>::stagingValue_ - animatableProperty->stagingValue_) <= zeroThreshold;
556 }
557 ROSEN_LOGE("RSRenderAnimatableProperty<float>::IsNearEqual: the value of the comparison is a null pointer!");
558 return true;
559 }
560
561 template<>
IsNearEqual(const std::shared_ptr<RSRenderPropertyBase> & value,float zeroThreshold) const562 bool RSRenderAnimatableProperty<Vector2f>::IsNearEqual(
563 const std::shared_ptr<RSRenderPropertyBase>& value, float zeroThreshold) const
564 {
565 auto animatableProperty = std::static_pointer_cast<const RSRenderAnimatableProperty<Vector2f>>(value);
566 if (animatableProperty != nullptr) {
567 return RSRenderProperty<Vector2f>::stagingValue_.IsNearEqual(animatableProperty->Get(), zeroThreshold);
568 }
569 ROSEN_LOGE("RSRenderAnimatableProperty<Vector2f>::IsNearEqual: the value of the comparison is a null pointer!");
570 return true;
571 }
572
573 template<>
IsNearEqual(const std::shared_ptr<RSRenderPropertyBase> & value,float zeroThreshold) const574 bool RSRenderAnimatableProperty<Vector3f>::IsNearEqual(
575 const std::shared_ptr<RSRenderPropertyBase>& value, float zeroThreshold) const
576 {
577 auto animatableProperty = std::static_pointer_cast<const RSRenderAnimatableProperty<Vector3f>>(value);
578 if (animatableProperty != nullptr) {
579 return RSRenderProperty<Vector3f>::stagingValue_.IsNearEqual(animatableProperty->Get(), zeroThreshold);
580 }
581 ROSEN_LOGE("RSRenderAnimatableProperty<Vector3f>::IsNearEqual: the value of the comparison is a null pointer!");
582 return true;
583 }
584
585 template<>
IsNearEqual(const std::shared_ptr<RSRenderPropertyBase> & value,float zeroThreshold) const586 bool RSRenderAnimatableProperty<Quaternion>::IsNearEqual(
587 const std::shared_ptr<RSRenderPropertyBase>& value, float zeroThreshold) const
588 {
589 auto animatableProperty = std::static_pointer_cast<const RSRenderAnimatableProperty<Quaternion>>(value);
590 if (animatableProperty != nullptr) {
591 return RSRenderProperty<Quaternion>::stagingValue_.IsNearEqual(animatableProperty->Get(), zeroThreshold);
592 }
593 ROSEN_LOGE("RSRenderAnimatableProperty<Quaternion>::IsNearEqual: the value of the comparison is a null pointer!");
594 return true;
595 }
596
597 template<>
IsNearEqual(const std::shared_ptr<RSRenderPropertyBase> & value,float zeroThreshold) const598 bool RSRenderAnimatableProperty<Vector4f>::IsNearEqual(
599 const std::shared_ptr<RSRenderPropertyBase>& value, float zeroThreshold) const
600 {
601 auto animatableProperty = std::static_pointer_cast<const RSRenderAnimatableProperty<Vector4f>>(value);
602 if (animatableProperty != nullptr) {
603 return RSRenderProperty<Vector4f>::stagingValue_.IsNearEqual(animatableProperty->Get(), zeroThreshold);
604 }
605 ROSEN_LOGE("RSRenderAnimatableProperty<Vector4f>::IsNearEqual: the value of the comparison is a null pointer!");
606 return true;
607 }
608
609 template<>
IsNearEqual(const std::shared_ptr<RSRenderPropertyBase> & value,float zeroThreshold) const610 bool RSRenderAnimatableProperty<Matrix3f>::IsNearEqual(
611 const std::shared_ptr<RSRenderPropertyBase>& value, float zeroThreshold) const
612 {
613 auto animatableProperty = std::static_pointer_cast<const RSRenderAnimatableProperty<Matrix3f>>(value);
614 if (animatableProperty != nullptr) {
615 return RSRenderProperty<Matrix3f>::stagingValue_.IsNearEqual(animatableProperty->Get(), zeroThreshold);
616 }
617 ROSEN_LOGE("RSRenderAnimatableProperty<Matrix3f>::IsNearEqual: the value of the comparison is a null pointer!");
618 return true;
619 }
620
621 template<>
IsNearEqual(const std::shared_ptr<RSRenderPropertyBase> & value,float zeroThreshold) const622 bool RSRenderAnimatableProperty<Color>::IsNearEqual(
623 const std::shared_ptr<RSRenderPropertyBase>& value, float zeroThreshold) const
624 {
625 auto animatableProperty = std::static_pointer_cast<const RSRenderAnimatableProperty<Color>>(value);
626 if (animatableProperty != nullptr) {
627 return RSRenderProperty<Color>::stagingValue_.IsNearEqual(
628 animatableProperty->Get(), static_cast<int16_t>(zeroThreshold));
629 }
630 ROSEN_LOGE("RSRenderAnimatableProperty<Color>::IsNearEqual: the value of the comparison is a null pointer!");
631 return true;
632 }
633
634 template<>
IsNearEqual(const std::shared_ptr<RSRenderPropertyBase> & value,float zeroThreshold) const635 bool RSRenderAnimatableProperty<Vector4<Color>>::IsNearEqual(
636 const std::shared_ptr<RSRenderPropertyBase>& value, float zeroThreshold) const
637 {
638 auto animatableProperty = std::static_pointer_cast<const RSRenderAnimatableProperty<Vector4<Color>>>(value);
639 if (animatableProperty != nullptr) {
640 auto thisData = RSRenderProperty<Vector4<Color>>::stagingValue_.data_;
641 auto otherValue = animatableProperty->Get();
642 auto& otherData = otherValue.data_;
643 int16_t threshold = static_cast<int16_t>(zeroThreshold);
644 return thisData[0].IsNearEqual(otherData[0], threshold) && thisData[1].IsNearEqual(otherData[1], threshold) &&
645 thisData[2].IsNearEqual(otherData[2], threshold) && thisData[3].IsNearEqual(otherData[3], threshold);
646 }
647 ROSEN_LOGE(
648 "RSRenderAnimatableProperty<Vector4<Color>>::IsNearEqual: the value of the comparison is a null pointer!");
649 return true;
650 }
651
652 template<>
IsNearEqual(const std::shared_ptr<RSRenderPropertyBase> & value,float zeroThreshold) const653 bool RSRenderAnimatableProperty<RRect>::IsNearEqual(
654 const std::shared_ptr<RSRenderPropertyBase>& value, float zeroThreshold) const
655 {
656 auto animatableProperty = std::static_pointer_cast<const RSRenderAnimatableProperty<RRect>>(value);
657 if (animatableProperty != nullptr) {
658 return RSRenderProperty<RRect>::stagingValue_.IsNearEqual(animatableProperty->Get(), zeroThreshold);
659 }
660 ROSEN_LOGE("RSRenderAnimatableProperty<RRect>::IsNearEqual: the value of the comparison is a null pointer!");
661 return true;
662 }
663
664 template<>
OnAttach(RSRenderNode & node,std::weak_ptr<ModifierNG::RSRenderModifier> modifier)665 void RSRenderProperty<std::shared_ptr<RSNGRenderFilterBase>>::OnAttach(RSRenderNode& node,
666 std::weak_ptr<ModifierNG::RSRenderModifier> modifier)
667 {
668 if (stagingValue_) {
669 stagingValue_->Attach(node, modifier);
670 }
671 }
672
673 template<>
OnDetach()674 void RSRenderProperty<std::shared_ptr<RSNGRenderFilterBase>>::OnDetach()
675 {
676 if (stagingValue_) {
677 stagingValue_->Detach();
678 }
679 }
680
681 template<>
Set(const std::shared_ptr<RSNGRenderFilterBase> & value,PropertyUpdateType type)682 void RSRenderProperty<std::shared_ptr<RSNGRenderFilterBase>>::Set(
683 const std::shared_ptr<RSNGRenderFilterBase>& value, PropertyUpdateType type)
684 {
685 if (value == stagingValue_) {
686 return;
687 }
688 // PLANNING: node_ is only used in this function, find alternative way detach/attach values, and remove the node_
689 // member variable.
690 auto node = node_.lock();
691 if (node && stagingValue_) {
692 stagingValue_->Detach();
693 }
694 stagingValue_ = value;
695 if (node && value) {
696 value->Attach(*node, modifier_.lock());
697 }
698 OnChange();
699 }
700
701 template<>
OnAttach(RSRenderNode & node,std::weak_ptr<ModifierNG::RSRenderModifier> modifier)702 void RSRenderProperty<std::shared_ptr<RSNGRenderShaderBase>>::OnAttach(RSRenderNode& node,
703 std::weak_ptr<ModifierNG::RSRenderModifier> modifier)
704 {
705 if (stagingValue_) {
706 stagingValue_->Attach(node, modifier);
707 }
708 }
709
710 template<>
OnDetach()711 void RSRenderProperty<std::shared_ptr<RSNGRenderShaderBase>>::OnDetach()
712 {
713 if (stagingValue_) {
714 stagingValue_->Detach();
715 }
716 }
717
718 template<>
Set(const std::shared_ptr<RSNGRenderShaderBase> & value,PropertyUpdateType type)719 void RSRenderProperty<std::shared_ptr<RSNGRenderShaderBase>>::Set(
720 const std::shared_ptr<RSNGRenderShaderBase>& value, PropertyUpdateType type)
721 {
722 if (value == stagingValue_) {
723 return;
724 }
725 // PLANNING: node_ is only used in this function, find alternative way detach/attach values, and remove the node_
726 // member variable.
727 auto node = node_.lock();
728 if (node && stagingValue_) {
729 stagingValue_->Detach();
730 }
731 stagingValue_ = value;
732 if (node && value) {
733 value->Attach(*node, modifier_.lock());
734 }
735 OnChange();
736 }
737
738 template<>
OnAttach(RSRenderNode & node,std::weak_ptr<ModifierNG::RSRenderModifier> modifier)739 void RSRenderProperty<std::shared_ptr<RSNGRenderMaskBase>>::OnAttach(RSRenderNode& node,
740 std::weak_ptr<ModifierNG::RSRenderModifier> modifier)
741 {
742 if (stagingValue_) {
743 stagingValue_->Attach(node, modifier);
744 }
745 }
746
747 template<>
OnDetach()748 void RSRenderProperty<std::shared_ptr<RSNGRenderMaskBase>>::OnDetach()
749 {
750 if (stagingValue_) {
751 stagingValue_->Detach();
752 }
753 }
754
755 template<>
Set(const std::shared_ptr<RSNGRenderMaskBase> & value,PropertyUpdateType type)756 void RSRenderProperty<std::shared_ptr<RSNGRenderMaskBase>>::Set(
757 const std::shared_ptr<RSNGRenderMaskBase>& value, PropertyUpdateType type)
758 {
759 if (value == stagingValue_) {
760 return;
761 }
762 // PLANNING: node_ is only used in this function, find alternative way detach/attach values, and remove the node_
763 // member variable.
764 auto node = node_.lock();
765 if (node && stagingValue_) {
766 stagingValue_->Detach();
767 }
768 stagingValue_ = value;
769 if (node && value) {
770 value->Attach(*node, modifier_.lock());
771 }
772 OnChange();
773 }
774
775 #define DECLARE_PROPERTY(T, TYPE_ENUM) template class RSRenderProperty<T>
776 #define DECLARE_ANIMATABLE_PROPERTY(T, TYPE_ENUM) \
777 template class RSRenderAnimatableProperty<T>; \
778 template class RSRenderProperty<T>
779
780 #include "modifier/rs_property_def.in"
781
782 #undef DECLARE_PROPERTY
783 #undef DECLARE_ANIMATABLE_PROPERTY
784
785 } // namespace Rosen
786 } // namespace OHOS
787