• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "text_effect.h"
17 
18 namespace OHOS::Rosen {
19 
GetInstance()20 TextEffectFactoryCreator& TextEffectFactoryCreator::GetInstance()
21 {
22     static TextEffectFactoryCreator instance;
23     return instance;
24 }
25 
RegisterFactory(TextEffectStrategy strategy,std::shared_ptr<TextEffectFactory> factory)26 bool TextEffectFactoryCreator::RegisterFactory(TextEffectStrategy strategy,
27     std::shared_ptr<TextEffectFactory> factory)
28 {
29     if (factory == nullptr) {
30         return false;
31     }
32     std::unique_lock<std::shared_mutex> lock(mutex_);
33     if (factoryTable_.find(strategy) != factoryTable_.end()) {
34         return false;
35     }
36     factoryTable_.emplace(strategy, factory);
37     return true;
38 }
39 
UnregisterFactory(TextEffectStrategy strategy)40 void TextEffectFactoryCreator::UnregisterFactory(TextEffectStrategy strategy)
41 {
42     std::unique_lock<std::shared_mutex> lock(mutex_);
43     factoryTable_.erase(strategy);
44 }
45 
CreateTextEffect(TextEffectStrategy strategy)46 std::shared_ptr<TextEffect> TextEffectFactoryCreator::CreateTextEffect(TextEffectStrategy strategy)
47 {
48     std::shared_lock<std::shared_mutex> lock(mutex_);
49     auto iter = factoryTable_.find(strategy);
50     if (iter == factoryTable_.end()) {
51         return nullptr;
52     }
53     return iter->second->CreateTextEffect();
54 }
55 } // namespace OHOS::Rosen