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 "pipeline/rs_render_node.h"
21 #include "platform/common/rs_log.h"
22 #include "rs_profiler.h"
23
24 namespace OHOS {
25 namespace Rosen {
26
OnChange() const27 void RSRenderPropertyBase::OnChange() const
28 {
29 if (auto node = node_.lock()) {
30 node->SetDirty();
31 node->AddDirtyType(modifierType_);
32 if (modifierType_ < RSModifierType::BOUNDS || modifierType_ > RSModifierType::TRANSLATE_Z ||
33 modifierType_ == RSModifierType::POSITION_Z) {
34 node->MarkNonGeometryChanged();
35 }
36 if (modifierType_ > RSModifierType::EXTENDED) {
37 node->SetContentDirty();
38 }
39 if (modifierType_ == RSModifierType::POSITION_Z) {
40 node->MarkParentNeedRegenerateChildren();
41 }
42 }
43 }
44
UpdatePropertyUnit(RSModifierType type)45 void RSRenderPropertyBase::UpdatePropertyUnit(RSModifierType type)
46 {
47 switch (type) {
48 case RSModifierType::FRAME:
49 case RSModifierType::TRANSLATE:
50 SetPropertyUnit(RSPropertyUnit::PIXEL_POSITION);
51 break;
52 case RSModifierType::SCALE:
53 SetPropertyUnit(RSPropertyUnit::RATIO_SCALE);
54 break;
55 case RSModifierType::ROTATION_X:
56 case RSModifierType::ROTATION_Y:
57 case RSModifierType::ROTATION:
58 SetPropertyUnit(RSPropertyUnit::ANGLE_ROTATION);
59 break;
60 default:
61 SetPropertyUnit(RSPropertyUnit::UNKNOWN);
62 break;
63 }
64 }
65
Marshalling(Parcel & parcel,const std::shared_ptr<RSRenderPropertyBase> & val)66 bool RSRenderPropertyBase::Marshalling(Parcel& parcel, const std::shared_ptr<RSRenderPropertyBase>& val)
67 {
68 if (val == nullptr) {
69 if (!parcel.WriteUint16(static_cast<int16_t>(RSModifierType::INVALID))) {
70 ROSEN_LOGE("RSRenderPropertyBase::Marshalling WriteUint16 1 failed");
71 return false;
72 }
73 return true;
74 }
75 RSRenderPropertyType type = val->GetPropertyType();
76 if (!(parcel.WriteInt16(static_cast<int16_t>(type)))) {
77 ROSEN_LOGE("RSRenderPropertyBase::Marshalling WriteUint16 2 failed");
78 return false;
79 }
80 RSPropertyUnit unit = val->GetPropertyUnit();
81 if (!(parcel.WriteInt16(static_cast<int16_t>(unit)))) {
82 ROSEN_LOGE("RSRenderPropertyBase::Marshalling WriteUint16 3 failed");
83 return false;
84 }
85 switch (type) {
86 case RSRenderPropertyType::PROPERTY_FLOAT: {
87 auto property = std::static_pointer_cast<RSRenderAnimatableProperty<float>>(val);
88 if (property == nullptr) {
89 return false;
90 }
91 bool flag = parcel.WriteUint64(property->GetId()) &&
92 RSMarshallingHelper::Marshalling(parcel, property->Get());
93 if (!flag) {
94 ROSEN_LOGE("RSRenderPropertyBase::Marshalling PROPERTY_FLOAT failed");
95 }
96 return flag;
97 }
98 case RSRenderPropertyType::PROPERTY_COLOR: {
99 auto property = std::static_pointer_cast<RSRenderAnimatableProperty<Color>>(val);
100 if (property == nullptr) {
101 return false;
102 }
103 bool flag = parcel.WriteUint64(property->GetId()) &&
104 RSMarshallingHelper::Marshalling(parcel, property->Get());
105 if (!flag) {
106 ROSEN_LOGE("RSRenderPropertyBase::Marshalling PROPERTY_COLOR failed");
107 }
108 return flag;
109 }
110 case RSRenderPropertyType::PROPERTY_MATRIX3F: {
111 auto property = std::static_pointer_cast<RSRenderAnimatableProperty<Matrix3f>>(val);
112 if (property == nullptr) {
113 return false;
114 }
115 bool flag = parcel.WriteUint64(property->GetId()) &&
116 RSMarshallingHelper::Marshalling(parcel, property->Get());
117 if (!flag) {
118 ROSEN_LOGE("RSRenderPropertyBase::Marshalling PROPERTY_MATRIX3F failed");
119 }
120 return flag;
121 }
122 case RSRenderPropertyType::PROPERTY_QUATERNION: {
123 auto property = std::static_pointer_cast<RSRenderAnimatableProperty<Quaternion>>(val);
124 if (property == nullptr) {
125 return false;
126 }
127 bool flag = parcel.WriteUint64(property->GetId()) &&
128 RSMarshallingHelper::Marshalling(parcel, property->Get());
129 if (!flag) {
130 ROSEN_LOGE("RSRenderPropertyBase::Marshalling PROPERTY_QUATERNION failed");
131 }
132 return flag;
133 }
134 case RSRenderPropertyType::PROPERTY_FILTER: {
135 auto property = std::static_pointer_cast<RSRenderAnimatableProperty<std::shared_ptr<RSFilter>>>(val);
136 if (property == nullptr) {
137 return false;
138 }
139 bool flag = parcel.WriteUint64(property->GetId()) &&
140 RSMarshallingHelper::Marshalling(parcel, property->Get());
141 if (!flag) {
142 ROSEN_LOGE("RSRenderPropertyBase::Marshalling PROPERTY_FILTER failed");
143 }
144 return flag;
145 }
146 case RSRenderPropertyType::PROPERTY_VECTOR2F: {
147 auto property = std::static_pointer_cast<RSRenderAnimatableProperty<Vector2f>>(val);
148 if (property == nullptr) {
149 return false;
150 }
151 bool flag = parcel.WriteUint64(property->GetId()) &&
152 RSMarshallingHelper::Marshalling(parcel, property->Get());
153 if (!flag) {
154 ROSEN_LOGE("RSRenderPropertyBase::Marshalling PROPERTY_VECTOR2F failed");
155 }
156 return flag;
157 }
158 case RSRenderPropertyType::PROPERTY_VECTOR4F: {
159 auto property = std::static_pointer_cast<RSRenderAnimatableProperty<Vector4f>>(val);
160 if (property == nullptr) {
161 return false;
162 }
163 bool flag = parcel.WriteUint64(property->GetId()) &&
164 RSMarshallingHelper::Marshalling(parcel, property->Get());
165 if (!flag) {
166 ROSEN_LOGE("RSRenderPropertyBase::Marshalling PROPERTY_VECTOR4F failed");
167 }
168 return flag;
169 }
170 case RSRenderPropertyType::PROPERTY_VECTOR4_COLOR: {
171 auto property = std::static_pointer_cast<RSRenderAnimatableProperty<Vector4<Color>>>(val);
172 if (property == nullptr) {
173 return false;
174 }
175 bool flag = parcel.WriteUint64(property->GetId()) &&
176 RSMarshallingHelper::Marshalling(parcel, property->Get());
177 if (!flag) {
178 ROSEN_LOGE("RSRenderPropertyBase::Marshalling PROPERTY_VECTOR4_COLOR failed");
179 }
180 return flag;
181 }
182 case RSRenderPropertyType::PROPERTY_RRECT: {
183 auto property = std::static_pointer_cast<RSRenderAnimatableProperty<RRect>>(val);
184 if (property == nullptr) {
185 return false;
186 }
187 bool flag = parcel.WriteUint64(property->GetId()) &&
188 RSMarshallingHelper::Marshalling(parcel, property->Get());
189 if (!flag) {
190 ROSEN_LOGE("RSRenderPropertyBase::Marshalling PROPERTY_RRECT failed");
191 }
192 return flag;
193 }
194 default: {
195 return false;
196 }
197 }
198 return true;
199 }
200
Unmarshalling(Parcel & parcel,std::shared_ptr<RSRenderPropertyBase> & val)201 bool RSRenderPropertyBase::Unmarshalling(Parcel& parcel, std::shared_ptr<RSRenderPropertyBase>& val)
202 {
203 int16_t typeId = 0;
204 if (!parcel.ReadInt16(typeId)) {
205 ROSEN_LOGE("RSRenderPropertyBase::Unmarshalling ReadInt16 1 failed");
206 return false;
207 }
208 RSRenderPropertyType type = static_cast<RSRenderPropertyType>(typeId);
209 if (type == RSRenderPropertyType::INVALID) {
210 val.reset();
211 return true;
212 }
213 int16_t unitId = 0;
214 if (!parcel.ReadInt16(unitId)) {
215 ROSEN_LOGE("RSRenderPropertyBase::Unmarshalling ReadInt16 2 failed");
216 return false;
217 }
218 RSPropertyUnit unit = static_cast<RSPropertyUnit>(unitId);
219 PropertyId id = 0;
220 if (!parcel.ReadUint64(id)) {
221 ROSEN_LOGE("RSRenderPropertyBase::Unmarshalling ReadInt16 3 failed");
222 return false;
223 }
224 RS_PROFILER_PATCH_NODE_ID(parcel, id);
225 switch (type) {
226 case RSRenderPropertyType::PROPERTY_FLOAT: {
227 float value;
228 if (!RSMarshallingHelper::Unmarshalling(parcel, value)) {
229 return false;
230 }
231 val.reset(new RSRenderAnimatableProperty<float>(value, id, type, unit));
232 break;
233 }
234 case RSRenderPropertyType::PROPERTY_COLOR: {
235 Color value;
236 if (!RSMarshallingHelper::Unmarshalling(parcel, value)) {
237 return false;
238 }
239 val.reset(new RSRenderAnimatableProperty<Color>(value, id, type, unit));
240 break;
241 }
242 case RSRenderPropertyType::PROPERTY_MATRIX3F: {
243 Matrix3f value;
244 if (!RSMarshallingHelper::Unmarshalling(parcel, value)) {
245 return false;
246 }
247 val.reset(new RSRenderAnimatableProperty<Matrix3f>(value, id, type, unit));
248 break;
249 }
250 case RSRenderPropertyType::PROPERTY_QUATERNION: {
251 Quaternion value;
252 if (!RSMarshallingHelper::Unmarshalling(parcel, value)) {
253 return false;
254 }
255 val.reset(new RSRenderAnimatableProperty<Quaternion>(value, id, type, unit));
256 break;
257 }
258 case RSRenderPropertyType::PROPERTY_FILTER: {
259 std::shared_ptr<RSFilter> value;
260 if (!RSMarshallingHelper::Unmarshalling(parcel, value)) {
261 return false;
262 }
263 val.reset(new RSRenderAnimatableProperty<std::shared_ptr<RSFilter>>(value, id, type, unit));
264 break;
265 }
266 case RSRenderPropertyType::PROPERTY_VECTOR2F: {
267 Vector2f value;
268 if (!RSMarshallingHelper::Unmarshalling(parcel, value)) {
269 return false;
270 }
271 val.reset(new RSRenderAnimatableProperty<Vector2f>(value, id, type, unit));
272 break;
273 }
274 case RSRenderPropertyType::PROPERTY_VECTOR4F: {
275 Vector4f value;
276 if (!RSMarshallingHelper::Unmarshalling(parcel, value)) {
277 return false;
278 }
279 val.reset(new RSRenderAnimatableProperty<Vector4f>(value, id, type, unit));
280 break;
281 }
282 case RSRenderPropertyType::PROPERTY_VECTOR4_COLOR: {
283 Vector4<Color> value;
284 if (!RSMarshallingHelper::Unmarshalling(parcel, value)) {
285 return false;
286 }
287 val.reset(new RSRenderAnimatableProperty<Vector4<Color>>(value, id, type, unit));
288 break;
289 }
290 case RSRenderPropertyType::PROPERTY_RRECT: {
291 RRect value;
292 if (!RSMarshallingHelper::Unmarshalling(parcel, value)) {
293 return false;
294 }
295 val.reset(new RSRenderAnimatableProperty<RRect>(value, id, type, unit));
296 break;
297 }
298 default: {
299 return false;
300 }
301 }
302 return val != nullptr;
303 }
304
305 template<>
ToFloat() const306 float RSRenderAnimatableProperty<float>::ToFloat() const
307 {
308 return std::fabs(RSRenderProperty<float>::stagingValue_);
309 }
310
311 template<>
ToFloat() const312 float RSRenderAnimatableProperty<Vector4f>::ToFloat() const
313 {
314 return RSRenderProperty<Vector4f>::stagingValue_.GetLength();
315 }
316
317 template<>
ToFloat() const318 float RSRenderAnimatableProperty<Quaternion>::ToFloat() const
319 {
320 return RSRenderProperty<Quaternion>::stagingValue_.GetLength();
321 }
322
323 template<>
ToFloat() const324 float RSRenderAnimatableProperty<Vector2f>::ToFloat() const
325 {
326 return RSRenderProperty<Vector2f>::stagingValue_.GetLength();
327 }
328
operator +=(const std::shared_ptr<RSRenderPropertyBase> & a,const std::shared_ptr<const RSRenderPropertyBase> & b)329 std::shared_ptr<RSRenderPropertyBase> operator+=(
330 const std::shared_ptr<RSRenderPropertyBase>& a, const std::shared_ptr<const RSRenderPropertyBase>& b)
331 {
332 if (a == nullptr) {
333 return {};
334 }
335
336 return a->Add(b);
337 }
338
operator -=(const std::shared_ptr<RSRenderPropertyBase> & a,const std::shared_ptr<const RSRenderPropertyBase> & b)339 std::shared_ptr<RSRenderPropertyBase> operator-=(
340 const std::shared_ptr<RSRenderPropertyBase>& a, const std::shared_ptr<const RSRenderPropertyBase>& b)
341 {
342 if (a == nullptr) {
343 return {};
344 }
345
346 return a->Minus(b);
347 }
348
operator *=(const std::shared_ptr<RSRenderPropertyBase> & value,const float scale)349 std::shared_ptr<RSRenderPropertyBase> operator*=(const std::shared_ptr<RSRenderPropertyBase>& value, const float scale)
350 {
351 if (value == nullptr) {
352 return {};
353 }
354
355 return value->Multiply(scale);
356 }
357
operator +(const std::shared_ptr<const RSRenderPropertyBase> & a,const std::shared_ptr<const RSRenderPropertyBase> & b)358 std::shared_ptr<RSRenderPropertyBase> operator+(
359 const std::shared_ptr<const RSRenderPropertyBase>& a, const std::shared_ptr<const RSRenderPropertyBase>& b)
360 {
361 if (a == nullptr) {
362 return {};
363 }
364
365 auto clone = a->Clone();
366 if (clone == nullptr) {
367 return {};
368 }
369 return clone->Add(b);
370 }
371
operator -(const std::shared_ptr<const RSRenderPropertyBase> & a,const std::shared_ptr<const RSRenderPropertyBase> & b)372 std::shared_ptr<RSRenderPropertyBase> operator-(
373 const std::shared_ptr<const RSRenderPropertyBase>& a, const std::shared_ptr<const RSRenderPropertyBase>& b)
374 {
375 if (a == nullptr) {
376 return {};
377 }
378
379 auto clone = a->Clone();
380 if (clone == nullptr) {
381 return {};
382 }
383 return clone->Minus(b);
384 }
385
operator *(const std::shared_ptr<const RSRenderPropertyBase> & value,const float scale)386 std::shared_ptr<RSRenderPropertyBase> operator*(
387 const std::shared_ptr<const RSRenderPropertyBase>& value, const float scale)
388 {
389 if (value == nullptr) {
390 return {};
391 }
392
393 auto clone = value->Clone();
394 if (clone == nullptr) {
395 return {};
396 }
397
398 return clone->Multiply(scale);
399 }
400
operator ==(const std::shared_ptr<const RSRenderPropertyBase> & a,const std::shared_ptr<const RSRenderPropertyBase> & b)401 bool operator==(
402 const std::shared_ptr<const RSRenderPropertyBase>& a, const std::shared_ptr<const RSRenderPropertyBase>& b)
403 {
404 if (a == nullptr) {
405 return {};
406 }
407
408 return a->IsEqual(b);
409 }
410
operator !=(const std::shared_ptr<const RSRenderPropertyBase> & a,const std::shared_ptr<const RSRenderPropertyBase> & b)411 bool operator!=(
412 const std::shared_ptr<const RSRenderPropertyBase>& a, const std::shared_ptr<const RSRenderPropertyBase>& b)
413 {
414 if (a == nullptr) {
415 return {};
416 }
417
418 return !a->IsEqual(b);
419 }
420
421 template<>
Dump(std::string & out) const422 void RSRenderProperty<bool>::Dump(std::string& out) const
423 {
424 out += "[" + std::string(Get() ? "true" : "false") + "]";
425 }
426
427 template<>
Dump(std::string & out) const428 void RSRenderProperty<int>::Dump(std::string& out) const
429 {
430 out += "[" + std::to_string(Get()) + "]";
431 }
432
433 template<>
Dump(std::string & out) const434 void RSRenderProperty<float>::Dump(std::string& out) const
435 {
436 std::stringstream ss;
437 ss << "[" << std::fixed << std::setprecision(1) << Get() << "]";
438 out += ss.str();
439 }
440
441 template<>
Dump(std::string & out) const442 void RSRenderProperty<Vector4<uint32_t>>::Dump(std::string& out) const
443 {
444 Vector4 v4 = Get();
445 switch (modifierType_) {
446 case RSModifierType::BORDER_STYLE:
447 case RSModifierType::OUTLINE_STYLE: {
448 out += "[left:" + std::to_string(v4.x_);
449 out += " top:" + std::to_string(v4.y_);
450 out += " right:" + std::to_string(v4.z_);
451 out += " bottom:" + std::to_string(v4.w_) + "]";
452 break;
453 }
454 default: {
455 out += "[x:" + std::to_string(v4.x_) + " y:";
456 out += std::to_string(v4.y_) + " z:";
457 out += std::to_string(v4.z_) + " w:";
458 out += std::to_string(v4.w_) + "]";
459 break;
460 }
461 }
462 }
463
464 template<>
Dump(std::string & out) const465 void RSRenderProperty<Vector4f>::Dump(std::string& out) const
466 {
467 Vector4f v4f = Get();
468 std::stringstream ss;
469 ss << std::fixed << std::setprecision(1);
470 switch (modifierType_) {
471 case RSModifierType::BORDER_WIDTH:
472 case RSModifierType::BORDER_DASH_WIDTH:
473 case RSModifierType::BORDER_DASH_GAP:
474 case RSModifierType::OUTLINE_WIDTH:
475 case RSModifierType::OUTLINE_DASH_WIDTH:
476 case RSModifierType::OUTLINE_DASH_GAP: {
477 ss << "[left:" << v4f.x_ << " top:" << v4f.y_ << " right:" << v4f.z_ << " bottom:" << v4f.w_ << + "]";
478 break;
479 }
480 case RSModifierType::CORNER_RADIUS:
481 case RSModifierType::OUTLINE_RADIUS: {
482 ss << "[topLeft:" << v4f.x_ << " topRight:" << v4f.y_ \
483 << " bottomRight:" << v4f.z_ << " bottomLeft:" << v4f.w_ << + "]";
484 break;
485 }
486 case RSModifierType::BOUNDS: {
487 ss << "[x:" << v4f.x_ << " y:" << v4f.y_ << " width:" << v4f.z_ << " height:" << v4f.w_ << + "]";
488 break;
489 }
490 default: {
491 ss << "[x:" << v4f.x_ << " y:" << v4f.y_ << " z:" << v4f.z_ << " w:" << v4f.w_ << + "]";
492 break;
493 }
494 }
495 out += ss.str();
496 }
497
498 template<>
Dump(std::string & out) const499 void RSRenderProperty<Quaternion>::Dump(std::string& out) const
500 {
501 Quaternion q = Get();
502 std::stringstream ss;
503 ss << std::fixed << std::setprecision(1);
504 ss << "[x:" << q.x_ << " y:" << q.y_ << " z:" << q.z_ << " w:" << q.w_ << + "]";
505 out += ss.str();
506 }
507
508 template<>
Dump(std::string & out) const509 void RSRenderProperty<Vector2f>::Dump(std::string& out) const
510 {
511 Vector2f v2f = Get();
512 std::stringstream ss;
513 ss << std::fixed << std::setprecision(1) << "[x:" << v2f.x_ << " y:" << v2f.y_ << "]";
514 out += ss.str();
515 }
516
517 template<>
Dump(std::string & out) const518 void RSRenderProperty<Matrix3f>::Dump(std::string& out) const
519 {
520 }
521
522 template<>
Dump(std::string & out) const523 void RSRenderProperty<Color>::Dump(std::string& out) const
524 {
525 Get().Dump(out);
526 }
527
528 template<>
Dump(std::string & out) const529 void RSRenderProperty<std::shared_ptr<RSFilter>>::Dump(std::string& out) const
530 {
531 auto filter = Get();
532 out += "[";
533 if (filter != nullptr && filter->IsValid()) {
534 out += filter->GetDescription();
535 }
536 out += "]";
537 }
538
539 template<>
Dump(std::string & out) const540 void RSRenderProperty<Vector4<Color>>::Dump(std::string& out) const
541 {
542 Vector4<Color> v4Color = Get();
543 out += "[left";
544 v4Color.x_.Dump(out);
545 out += " top";
546 v4Color.y_.Dump(out);
547 out += " right";
548 v4Color.z_.Dump(out);
549 out += " bottom";
550 v4Color.w_.Dump(out);
551 out += ']';
552 }
553
554 template<>
Dump(std::string & out) const555 void RSRenderProperty<RRect>::Dump(std::string& out) const
556 {
557 const auto& rrect = stagingValue_;
558 out += "[rect:[x:";
559 out += std::to_string(rrect.rect_.left_) + " y:";
560 out += std::to_string(rrect.rect_.top_) + " width:";
561 out += std::to_string(rrect.rect_.width_) + " height:";
562 out += std::to_string(rrect.rect_.height_) + "]";
563 out += " radius:[[";
564 out += std::to_string(rrect.radius_[0][0]) + " " + std::to_string(rrect.radius_[0][1]) + "] [";
565 out += std::to_string(rrect.radius_[1][0]) + " " + std::to_string(rrect.radius_[1][1]) + "] [";
566 out += std::to_string(rrect.radius_[2][0]) + " " + std::to_string(rrect.radius_[2][1]) + "] ["; // 2 is vector index
567 out += std::to_string(rrect.radius_[3][0]) + " " + std::to_string(rrect.radius_[3][1]) + "]"; // 3 is vector index
568 out += "]";
569 }
570
571 template<>
Dump(std::string & out) const572 void RSRenderProperty<Drawing::DrawCmdListPtr>::Dump(std::string& out) const
573 {
574 auto propertyData = Get();
575 if (propertyData != nullptr) {
576 out += "drawCmdList[";
577 propertyData->Dump(out);
578 out += ']';
579 }
580 }
581
582 template<>
GetSize() const583 size_t RSRenderProperty<Drawing::DrawCmdListPtr>::GetSize() const
584 {
585 auto propertyData = Get();
586 size_t size = sizeof(*this);
587 if (propertyData != nullptr) {
588 size += propertyData->GetSize();
589 }
590 return size;
591 }
592
593 template<>
Dump(std::string & out) const594 void RSRenderProperty<ForegroundColorStrategyType>::Dump(std::string& out) const
595 {
596 out += std::to_string(static_cast<int>(Get()));
597 }
598
599 template<>
Dump(std::string & out) const600 void RSRenderProperty<SkMatrix>::Dump(std::string& out) const
601 {
602 Get().dump(out, 0);
603 }
604
605 template<>
Dump(std::string & out) const606 void RSRenderProperty<std::shared_ptr<RSLinearGradientBlurPara>>::Dump(std::string& out) const
607 {
608 auto property = Get();
609 if (property != nullptr) {
610 property->Dump(out);
611 }
612 }
613
614 template<>
Dump(std::string & out) const615 void RSRenderProperty<std::shared_ptr<MotionBlurParam>>::Dump(std::string& out) const
616 {
617 auto property = Get();
618 if (property != nullptr) {
619 property->Dump(out);
620 }
621 }
622
623 template<>
Dump(std::string & out) const624 void RSRenderProperty<std::shared_ptr<RSMagnifierParams>>::Dump(std::string& out) const
625 {
626 auto property = Get();
627 if (property != nullptr) {
628 property->Dump(out);
629 }
630 }
631
632 template<>
Dump(std::string & out) const633 void RSRenderProperty<std::vector<std::shared_ptr<EmitterUpdater>>>::Dump(std::string& out) const
634 {
635 auto property = Get();
636 out += '[';
637 bool found = false;
638 for (auto& eu : property) {
639 if (eu != nullptr) {
640 found = true;
641 out += "emitterUpdater";
642 eu->Dump(out);
643 out += ' ';
644 }
645 }
646 if (found) {
647 out.pop_back();
648 }
649 out += ']';
650 }
651
652 template<>
Dump(std::string & out) const653 void RSRenderProperty<std::shared_ptr<ParticleNoiseFields>>::Dump(std::string& out) const
654 {
655 auto property = Get();
656 if (property != nullptr) {
657 property->Dump(out);
658 }
659 }
660
661 template<>
Dump(std::string & out) const662 void RSRenderProperty<std::shared_ptr<RSMask>>::Dump(std::string& out) const
663 {
664 auto property = Get();
665 if (property != nullptr) {
666 property->Dump(out);
667 }
668 }
669
670 template<>
Dump(std::string & out) const671 void RSRenderProperty<std::shared_ptr<RSShader>>::Dump(std::string& out) const
672 {
673 if (!Get() || !Get()->GetDrawingShader()) {
674 out += "[null]";
675 return;
676 }
677 out += "[";
678 out += std::to_string(static_cast<int>(Get()->GetDrawingShader()->GetType()));
679 out += "]";
680 }
681
682 template<>
Dump(std::string & out) const683 void RSRenderProperty<std::shared_ptr<RSImage>>::Dump(std::string& out) const
684 {
685 if (!Get()) {
686 out += "[null]";
687 return;
688 }
689 std::string info;
690 Get()->dump(info, 0);
691 info.erase(std::remove_if(info.begin(), info.end(), [](auto c) { return c == '\t' || c == '\n'; }),
692 info.end());
693 out += "[\"" + info + "\"]";
694 }
695
696 template<>
Dump(std::string & out) const697 void RSRenderProperty<std::shared_ptr<RSPath>>::Dump(std::string& out) const
698 {
699 if (!Get()) {
700 out += "[null]";
701 return;
702 }
703 const auto& path = Get()->GetDrawingPath();
704 const auto bounds = path.GetBounds();
705 out += "[length:";
706 out += std::to_string(path.GetLength(false)) + " bounds[x:";
707 out += std::to_string(bounds.GetLeft()) + " y:";
708 out += std::to_string(bounds.GetTop()) + " width:";
709 out += std::to_string(bounds.GetWidth()) + " height:";
710 out += std::to_string(bounds.GetHeight()) + "] valid:";
711 out += std::string(path.IsValid() ? "true" : "false");
712 out += "]";
713 }
714
715 template<>
Dump(std::string & out) const716 void RSRenderProperty<Gravity>::Dump(std::string& out) const
717 {
718 out += "[";
719 out += std::to_string(static_cast<int>(Get()));
720 out += "]";
721 }
722
723 template<>
Dump(std::string & out) const724 void RSRenderProperty<Drawing::Matrix>::Dump(std::string& out) const
725 {
726 out += "[";
727 Drawing::Matrix::Buffer buffer;
728 Get().GetAll(buffer);
729 for (auto v: buffer) {
730 out += std::to_string(v) + " ";
731 }
732 out.pop_back();
733 out += "]";
734 }
735
736 template<>
IsNearEqual(const std::shared_ptr<RSRenderPropertyBase> & value,float zeroThreshold) const737 bool RSRenderAnimatableProperty<float>::IsNearEqual(
738 const std::shared_ptr<RSRenderPropertyBase>& value, float zeroThreshold) const
739 {
740 auto animatableProperty = std::static_pointer_cast<const RSRenderAnimatableProperty<float>>(value);
741 if (animatableProperty != nullptr) {
742 return fabs(RSRenderProperty<float>::stagingValue_ - animatableProperty->stagingValue_) <= zeroThreshold;
743 }
744 ROSEN_LOGE("RSRenderAnimatableProperty<float>::IsNearEqual: the value of the comparison is a null pointer!");
745 return true;
746 }
747
748 template<>
IsNearEqual(const std::shared_ptr<RSRenderPropertyBase> & value,float zeroThreshold) const749 bool RSRenderAnimatableProperty<Vector2f>::IsNearEqual(
750 const std::shared_ptr<RSRenderPropertyBase>& value, float zeroThreshold) const
751 {
752 auto animatableProperty = std::static_pointer_cast<const RSRenderAnimatableProperty<Vector2f>>(value);
753 if (animatableProperty != nullptr) {
754 return RSRenderProperty<Vector2f>::stagingValue_.IsNearEqual(animatableProperty->Get(), zeroThreshold);
755 }
756 ROSEN_LOGE("RSRenderAnimatableProperty<Vector2f>::IsNearEqual: the value of the comparison is a null pointer!");
757 return true;
758 }
759
760 template<>
IsNearEqual(const std::shared_ptr<RSRenderPropertyBase> & value,float zeroThreshold) const761 bool RSRenderAnimatableProperty<Quaternion>::IsNearEqual(
762 const std::shared_ptr<RSRenderPropertyBase>& value, float zeroThreshold) const
763 {
764 auto animatableProperty = std::static_pointer_cast<const RSRenderAnimatableProperty<Quaternion>>(value);
765 if (animatableProperty != nullptr) {
766 return RSRenderProperty<Quaternion>::stagingValue_.IsNearEqual(animatableProperty->Get(), zeroThreshold);
767 }
768 ROSEN_LOGE("RSRenderAnimatableProperty<Quaternion>::IsNearEqual: the value of the comparison is a null pointer!");
769 return true;
770 }
771
772 template<>
IsNearEqual(const std::shared_ptr<RSRenderPropertyBase> & value,float zeroThreshold) const773 bool RSRenderAnimatableProperty<Vector4f>::IsNearEqual(
774 const std::shared_ptr<RSRenderPropertyBase>& value, float zeroThreshold) const
775 {
776 auto animatableProperty = std::static_pointer_cast<const RSRenderAnimatableProperty<Vector4f>>(value);
777 if (animatableProperty != nullptr) {
778 return RSRenderProperty<Vector4f>::stagingValue_.IsNearEqual(animatableProperty->Get(), zeroThreshold);
779 }
780 ROSEN_LOGE("RSRenderAnimatableProperty<Vector4f>::IsNearEqual: the value of the comparison is a null pointer!");
781 return true;
782 }
783
784 template<>
IsNearEqual(const std::shared_ptr<RSRenderPropertyBase> & value,float zeroThreshold) const785 bool RSRenderAnimatableProperty<Matrix3f>::IsNearEqual(
786 const std::shared_ptr<RSRenderPropertyBase>& value, float zeroThreshold) const
787 {
788 auto animatableProperty = std::static_pointer_cast<const RSRenderAnimatableProperty<Matrix3f>>(value);
789 if (animatableProperty != nullptr) {
790 return RSRenderProperty<Matrix3f>::stagingValue_.IsNearEqual(animatableProperty->Get(), zeroThreshold);
791 }
792 ROSEN_LOGE("RSRenderAnimatableProperty<Matrix3f>::IsNearEqual: the value of the comparison is a null pointer!");
793 return true;
794 }
795
796 template<>
IsNearEqual(const std::shared_ptr<RSRenderPropertyBase> & value,float zeroThreshold) const797 bool RSRenderAnimatableProperty<Color>::IsNearEqual(
798 const std::shared_ptr<RSRenderPropertyBase>& value, float zeroThreshold) const
799 {
800 auto animatableProperty = std::static_pointer_cast<const RSRenderAnimatableProperty<Color>>(value);
801 if (animatableProperty != nullptr) {
802 return RSRenderProperty<Color>::stagingValue_.IsNearEqual(
803 animatableProperty->Get(), static_cast<int16_t>(zeroThreshold));
804 }
805 ROSEN_LOGE("RSRenderAnimatableProperty<Color>::IsNearEqual: the value of the comparison is a null pointer!");
806 return true;
807 }
808
809 template<>
IsNearEqual(const std::shared_ptr<RSRenderPropertyBase> & value,float zeroThreshold) const810 bool RSRenderAnimatableProperty<std::shared_ptr<RSFilter>>::IsNearEqual(
811 const std::shared_ptr<RSRenderPropertyBase>& value, float zeroThreshold) const
812 {
813 auto animatableProperty =
814 std::static_pointer_cast<const RSRenderAnimatableProperty<std::shared_ptr<RSFilter>>>(value);
815 if (animatableProperty == nullptr) {
816 return true;
817 }
818
819 auto filter = RSRenderProperty<std::shared_ptr<RSFilter>>::stagingValue_;
820 auto otherFilter = animatableProperty->Get();
821 if ((filter != nullptr) && (otherFilter != nullptr)) {
822 return filter->IsNearEqual(otherFilter, zeroThreshold);
823 } else if ((filter == nullptr) && (otherFilter == nullptr)) {
824 ROSEN_LOGE("RSRenderAnimatableProperty<std::shared_ptr<RSFilter>>::IsNearEqual: "
825 "both values compared are null Pointers!");
826 return true;
827 } else if (filter == nullptr) {
828 ROSEN_LOGE(
829 "RSRenderAnimatableProperty<std::shared_ptr<RSFilter>>::IsNearEqual: the staging value is a null pointer!");
830 return otherFilter->IsNearZero(zeroThreshold);
831 } else {
832 ROSEN_LOGE("RSRenderAnimatableProperty<std::shared_ptr<RSFilter>>::IsNearEqual: "
833 "the value of the comparison is a null pointer!");
834 return filter->IsNearZero(zeroThreshold);
835 }
836 }
837
838 template<>
IsNearEqual(const std::shared_ptr<RSRenderPropertyBase> & value,float zeroThreshold) const839 bool RSRenderAnimatableProperty<Vector4<Color>>::IsNearEqual(
840 const std::shared_ptr<RSRenderPropertyBase>& value, float zeroThreshold) const
841 {
842 auto animatableProperty = std::static_pointer_cast<const RSRenderAnimatableProperty<Vector4<Color>>>(value);
843 if (animatableProperty != nullptr) {
844 auto thisData = RSRenderProperty<Vector4<Color>>::stagingValue_.data_;
845 auto otherValue = animatableProperty->Get();
846 auto& otherData = otherValue.data_;
847 int16_t threshold = static_cast<int16_t>(zeroThreshold);
848 return thisData[0].IsNearEqual(otherData[0], threshold) && thisData[1].IsNearEqual(otherData[1], threshold) &&
849 thisData[2].IsNearEqual(otherData[2], threshold) && thisData[3].IsNearEqual(otherData[3], threshold);
850 }
851 ROSEN_LOGE(
852 "RSRenderAnimatableProperty<Vector4<Color>>::IsNearEqual: the value of the comparison is a null pointer!");
853 return true;
854 }
855
856 template<>
IsNearEqual(const std::shared_ptr<RSRenderPropertyBase> & value,float zeroThreshold) const857 bool RSRenderAnimatableProperty<RRect>::IsNearEqual(
858 const std::shared_ptr<RSRenderPropertyBase>& value, float zeroThreshold) const
859 {
860 auto animatableProperty = std::static_pointer_cast<const RSRenderAnimatableProperty<RRect>>(value);
861 if (animatableProperty != nullptr) {
862 return RSRenderProperty<RRect>::stagingValue_.IsNearEqual(animatableProperty->Get(), zeroThreshold);
863 }
864 ROSEN_LOGE("RSRenderAnimatableProperty<RRect>::IsNearEqual: the value of the comparison is a null pointer!");
865 return true;
866 }
867
868 template<>
IsEqual(const std::shared_ptr<const RSRenderPropertyBase> & value) const869 bool RSRenderAnimatableProperty<std::shared_ptr<RSFilter>>::IsEqual(
870 const std::shared_ptr<const RSRenderPropertyBase>& value) const
871 {
872 auto animatableProperty =
873 std::static_pointer_cast<const RSRenderAnimatableProperty<std::shared_ptr<RSFilter>>>(value);
874 if (animatableProperty == nullptr) {
875 return true;
876 }
877
878 auto filter = RSRenderProperty<std::shared_ptr<RSFilter>>::stagingValue_;
879 auto otherFilter = animatableProperty->Get();
880 if ((filter != nullptr) && (otherFilter != nullptr)) {
881 return filter->IsEqual(otherFilter);
882 } else if ((filter == nullptr) && (otherFilter == nullptr)) {
883 ROSEN_LOGE("RSRenderAnimatableProperty<std::shared_ptr<RSFilter>>::IsEqual: "
884 "both values compared are null Pointers!");
885 return true;
886 } else if (filter == nullptr) {
887 ROSEN_LOGE(
888 "RSRenderAnimatableProperty<std::shared_ptr<RSFilter>>::IsEqual: the staging value is a null pointer!");
889 return otherFilter->IsEqualZero();
890 } else {
891 ROSEN_LOGE("RSRenderAnimatableProperty<std::shared_ptr<RSFilter>>::IsEqual: "
892 "the value of the comparison is a null pointer!");
893 return filter->IsEqualZero();
894 }
895 }
896
897 template class RSRenderProperty<bool>;
898 template class RSRenderProperty<int>;
899 template class RSRenderProperty<float>;
900 template class RSRenderProperty<Vector4<uint32_t>>;
901 template class RSRenderProperty<Vector4f>;
902 template class RSRenderProperty<Quaternion>;
903 template class RSRenderProperty<Vector2f>;
904 template class RSRenderProperty<Matrix3f>;
905 template class RSRenderProperty<Color>;
906 template class RSRenderProperty<std::shared_ptr<RSFilter>>;
907 template class RSRenderProperty<Vector4<Color>>;
908 template class RSRenderProperty<RRect>;
909 template class RSRenderProperty<Drawing::DrawCmdListPtr>;
910 template class RSRenderProperty<ForegroundColorStrategyType>;
911 template class RSRenderProperty<SkMatrix>;
912 template class RSRenderProperty<std::shared_ptr<RSShader>>;
913 template class RSRenderProperty<std::shared_ptr<RSImage>>;
914 template class RSRenderProperty<std::shared_ptr<RSPath>>;
915 template class RSRenderProperty<Gravity>;
916 template class RSRenderProperty<Drawing::Matrix>;
917 template class RSRenderProperty<std::shared_ptr<RSLinearGradientBlurPara>>;
918 template class RSRenderProperty<std::shared_ptr<MotionBlurParam>>;
919 template class RSRenderProperty<std::shared_ptr<RSMagnifierParams>>;
920 template class RSRenderProperty<std::vector<std::shared_ptr<EmitterUpdater>>>;
921 template class RSRenderProperty<std::shared_ptr<ParticleNoiseFields>>;
922 template class RSRenderProperty<std::shared_ptr<RSMask>>;
923
924 template class RSRenderAnimatableProperty<float>;
925 template class RSRenderAnimatableProperty<Vector4f>;
926 template class RSRenderAnimatableProperty<Quaternion>;
927 template class RSRenderAnimatableProperty<Vector2f>;
928 template class RSRenderAnimatableProperty<Matrix3f>;
929 template class RSRenderAnimatableProperty<Color>;
930 template class RSRenderAnimatableProperty<std::shared_ptr<RSFilter>>;
931 template class RSRenderAnimatableProperty<Vector4<Color>>;
932 template class RSRenderAnimatableProperty<RRect>;
933 } // namespace Rosen
934 } // namespace OHOS
935