• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-2021 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 "animator/animator_manager.h"
17 
18 #include "common/task_manager.h"
19 #include "hal_tick.h"
20 
21 namespace OHOS {
GetInstance()22 AnimatorManager* AnimatorManager::GetInstance()
23 {
24     static AnimatorManager animatorManager;
25     return &animatorManager;
26 }
27 
Init()28 void AnimatorManager::Init()
29 {
30     Task::Init();
31 }
32 
Add(Animator * animator)33 void AnimatorManager::Add(Animator* animator)
34 {
35     if (animator == nullptr) {
36         return;
37     }
38 
39     ListNode<Animator*>* pos = list_.Begin();
40     while (pos != list_.End()) {
41         if (pos->data_ == animator) {
42             GRAPHIC_LOGI("do not add animator multi times");
43             return;
44         }
45         pos = pos->next_;
46     }
47 
48     list_.PushBack(animator);
49 }
50 
Remove(const Animator * animator)51 void AnimatorManager::Remove(const Animator* animator)
52 {
53     if (animator == nullptr) {
54         return;
55     }
56     ListNode<Animator*>* pos = list_.Begin();
57     while (pos != list_.End()) {
58         if (pos->data_ == animator) {
59             pos->data_ = nullptr;
60             return;
61         }
62         pos = pos->next_;
63     }
64 }
65 
AnimatorTask()66 void AnimatorManager::AnimatorTask()
67 {
68     ListNode<Animator*>* pos = list_.Begin();
69     Animator* animator = nullptr;
70 
71     while (pos != list_.End()) {
72         animator = pos->data_;
73         if (animator == nullptr) {
74             // clean up animator list
75             pos = list_.Remove(pos);
76             continue;
77         }
78         if (animator->GetState() == Animator::START) {
79             animator->Run();
80         }
81         pos = pos->next_;
82     }
83 }
84 } // namespace OHOS
85