1 
2 /*
3  * Copyright (c) 2022 Huawei Device Co., Ltd.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "modifier/rs_modifier.h"
18 
19 #include "modifier/rs_modifier_manager.h"
20 #include "modifier/rs_modifier_manager_map.h"
21 #include "platform/common/rs_log.h"
22 
23 namespace OHOS {
24 namespace Rosen {
AttachProperty(const std::shared_ptr<RSPropertyBase> & property)25 void RSModifier::AttachProperty(const std::shared_ptr<RSPropertyBase>& property)
26 {
27     if (property != nullptr) {
28         property->target_ = property_->target_;
29         property->SetIsCustom(true);
30         property->AttachModifier(shared_from_this());
31         property->MarkModifierDirty();
32     }
33 }
34 
SetDirty(const bool isDirty)35 void RSModifier::SetDirty(const bool isDirty)
36 {
37     if (!isDirty) {
38         isDirty_ = isDirty;
39         return;
40     }
41 
42     if (isDirty_) {
43         return;
44     }
45     isDirty_ = isDirty;
46     auto modifierManager = RSModifierManagerMap::Instance()->GetModifierManager(gettid());
47     if (modifierManager == nullptr) {
48         ROSEN_LOGE("Modifier manager is null while mark modifier dirty Id: %{public}" PRIu64 "!", GetPropertyId());
49         return;
50     }
51 
52     modifierManager->AddModifier(shared_from_this());
53 }
54 
ResetRSNodeExtendModifierDirty()55 void RSModifier::ResetRSNodeExtendModifierDirty()
56 {
57     auto target = property_->target_.lock();
58     if (target == nullptr) {
59         return;
60     }
61 
62     target->ResetExtendModifierDirty();
63 }
64 } // namespace Rosen
65 } // namespace OHOS
66