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 #include "frameworks/bridge/declarative_frontend/jsview/js_effect_component.h"
17 
18 #include "bridge/declarative_frontend/jsview/models/effect_component_model_impl.h"
19 #include "core/components_ng/pattern/effect_component/effect_component_model_ng.h"
20 #include "frameworks/bridge/declarative_frontend/jsview/js_utils.h"
21 
22 namespace OHOS::Ace {
23 std::unique_ptr<EffectComponentModel> EffectComponentModel::instance_ = nullptr;
24 std::mutex EffectComponentModel::mutex_;
25 
GetInstance()26 EffectComponentModel* EffectComponentModel::GetInstance()
27 {
28     if (!instance_) {
29         std::lock_guard<std::mutex> lock(mutex_);
30         if (!instance_) {
31 #ifdef NG_BUILD
32             instance_.reset(new NG::EffectComponentModelNG());
33 #else
34             if (Container::IsCurrentUseNewPipeline()) {
35                 instance_.reset(new NG::EffectComponentModelNG());
36             } else {
37                 // empty implementation
38                 instance_.reset(new Framework::EffectComponentModelImpl());
39             }
40 #endif
41         }
42     }
43     return instance_.get();
44 }
45 } // namespace OHOS::Ace
46 
47 namespace OHOS::Ace::Framework {
Create()48 void JSEffectComponent::Create()
49 {
50     EffectComponentModel::GetInstance()->Create();
51 }
52 
JSBind(BindingTarget globalObj)53 void JSEffectComponent::JSBind(BindingTarget globalObj)
54 {
55     JSClass<JSEffectComponent>::Declare("EffectComponent");
56     MethodOptions opt = MethodOptions::NONE;
57     JSClass<JSEffectComponent>::StaticMethod("create", &JSEffectComponent::Create, opt);
58 
59     JSClass<JSEffectComponent>::InheritAndBind<JSViewAbstract>(globalObj);
60 }
61 } // namespace OHOS::Ace::Framework
62