1 /*
2 * Copyright (c) 2022 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 "frame_msg_mgr.h"
17
18 namespace OHOS {
19 namespace RME {
20 DEFINE_RMELOG_INTELLISENSE("ueaClient-FrameMsgMgr");
21 IMPLEMENT_SINGLE_INSTANCE(FrameMsgMgr);
22
FrameMsgMgr()23 FrameMsgMgr::FrameMsgMgr()
24 : sceneType(SceneEvent::SLIDE), rmeScene(nullptr)
25 {
26 FrameMapKeyToFunc();
27 }
28
~FrameMsgMgr()29 FrameMsgMgr::~FrameMsgMgr()
30 {
31 if (rmeScene != nullptr) {
32 delete rmeScene;
33 }
34 }
35
Init()36 bool FrameMsgMgr::Init()
37 {
38 if (rmeScene == nullptr) {
39 rmeScene = new RmeSceneSched();
40 }
41 if (!rmeScene->Init()) {
42 RME_LOGE("[Init]:inited failed!");
43 return false;
44 }
45 RME_LOGI("[Init]:inited success!");
46 return true;
47 }
48
EventUpdate(FrameEvent event)49 void FrameMsgMgr::EventUpdate(FrameEvent event)
50 {
51 switch (event) {
52 case FrameEvent::EVENT_SET_PARAM:
53 SetSchedParam();
54 break;
55 default:
56 HandleFrameMsgKey(event);
57 break;
58 }
59 }
60
HandleFrameMsgKey(FrameEvent event)61 bool FrameMsgMgr::HandleFrameMsgKey(FrameEvent event)
62 {
63 std::map<FrameEvent, PHandle>::iterator iter = m_frameMsgKeyToFunc.find(event);
64 if (m_frameMsgKeyToFunc.end() == iter) {
65 RME_LOGE("[HandleFrameMsgKey]: search frameEvent:%{public}d failed!",
66 static_cast<int>(event));
67 return false;
68 }
69 PHandle pFunction = iter->second;
70 (this->*pFunction)();
71 return true;
72 }
73
FrameMapKeyToFunc()74 void FrameMsgMgr::FrameMapKeyToFunc()
75 {
76 m_frameMsgKeyToFunc[FrameEvent::EVENT_BEGIN_FRAME] = &FrameMsgMgr::HandleBeginFrame;
77 m_frameMsgKeyToFunc[FrameEvent::EVENT_FLUSH_ANIMATION_START] = &FrameMsgMgr::BeginFlushAnimation;
78 m_frameMsgKeyToFunc[FrameEvent::EVENT_FLUSH_ANIMATION_END] = &FrameMsgMgr::EndFlushAnimation;
79 m_frameMsgKeyToFunc[FrameEvent::EVENT_FLUSH_BUILD_START] = &FrameMsgMgr::BeginFlushBuild;
80 m_frameMsgKeyToFunc[FrameEvent::EVENT_FLUSH_BUILD_END] = &FrameMsgMgr::EndFlushBuild;
81 m_frameMsgKeyToFunc[FrameEvent::EVENT_FLUSH_LAYOUT_START] = &FrameMsgMgr::BeginFlushLayout;
82 m_frameMsgKeyToFunc[FrameEvent::EVENT_FLUSH_LAYOUT_END] = &FrameMsgMgr::EndFlushLayout;
83 m_frameMsgKeyToFunc[FrameEvent::EVENT_FLUSH_RENDER_START] = &FrameMsgMgr::BeginFlushRender;
84 m_frameMsgKeyToFunc[FrameEvent::EVENT_FLUSH_RENDER_END] = &FrameMsgMgr::EndFlushRender;
85 m_frameMsgKeyToFunc[FrameEvent::EVENT_FLUSH_RENDER_FINISH_START] = &FrameMsgMgr::BeginFlushRenderFinish;
86 m_frameMsgKeyToFunc[FrameEvent::EVENT_FLUSH_RENDER_FINISH_END] = &FrameMsgMgr::EndFlushRenderFinish;
87 m_frameMsgKeyToFunc[FrameEvent::EVENT_PROCESS_POST_FLUSH_START] = &FrameMsgMgr::BeginProcessPostFlush;
88 m_frameMsgKeyToFunc[FrameEvent::EVENT_PROCESS_COMMANDS_START] = &FrameMsgMgr::ProcessCommandsStart;
89 m_frameMsgKeyToFunc[FrameEvent::EVENT_ANIMATE_START] = &FrameMsgMgr::AnimateStart;
90 m_frameMsgKeyToFunc[FrameEvent::EVENT_RENDER_START] = &FrameMsgMgr::RenderStart;
91 m_frameMsgKeyToFunc[FrameEvent::EVENT_SEND_COMMANDS_START] = &FrameMsgMgr::SendCommandsStart;
92 m_frameMsgKeyToFunc[FrameEvent::EVENT_END_FRAME] = &FrameMsgMgr::HandleEndFrame;
93 }
94
GetSceneHandler() const95 FrameSceneSched *FrameMsgMgr::GetSceneHandler() const
96 {
97 if (sceneType == SceneEvent::SCENE_INVALID) {
98 RME_LOGE("[GetSceneHandler]:get nullptr sceneType %{public}d,", static_cast<int>(sceneType));
99 return nullptr;
100 }
101 return rmeScene;
102 }
103
UpdateScene(SceneEvent scene)104 void FrameMsgMgr::UpdateScene(SceneEvent scene)
105 {
106 if (scene < SceneEvent::SCENE_INVALID || scene >= SceneEvent::SCENE_MAX) {
107 scene = SceneEvent::SCENE_INVALID;
108 }
109 sceneType = scene;
110 }
111
HandleBeginFrame()112 void FrameMsgMgr::HandleBeginFrame()
113 {
114 RME_LOGI("[HandleBeginFrame]:start");
115 FrameSceneSched *scene = GetSceneHandler();
116 if (scene == nullptr) {
117 RME_LOGE("[HandleBeginFrame]:scene nullptr");
118 return;
119 }
120 scene->HandleBeginFrame();
121 }
122
BeginFlushAnimation()123 void FrameMsgMgr::BeginFlushAnimation()
124 {
125 FrameSceneSched *scene = GetSceneHandler();
126 if (scene == nullptr) {
127 RME_LOGE("[BeginFlushAnimation]:scene nullptr");
128 return;
129 }
130 scene->BeginFlushAnimation();
131 }
132
EndFlushAnimation()133 void FrameMsgMgr::EndFlushAnimation()
134 {
135 FrameSceneSched *scene = GetSceneHandler();
136 if (scene == nullptr) {
137 RME_LOGE("[EndFlushAnimation]:scene nullptr");
138 return;
139 }
140 scene->EndFlushAnimation();
141 }
142
BeginFlushBuild()143 void FrameMsgMgr::BeginFlushBuild()
144 {
145 FrameSceneSched *scene = GetSceneHandler();
146 if (scene == nullptr) {
147 RME_LOGE("[BeginFlushBuild]:scene nullptr");
148 return;
149 }
150 scene->BeginFlushBuild();
151 }
152
EndFlushBuild()153 void FrameMsgMgr::EndFlushBuild()
154 {
155 FrameSceneSched *scene = GetSceneHandler();
156 if (scene == nullptr) {
157 RME_LOGE("[EndFlushBuild]:scene nullptr");
158 return;
159 }
160 scene->EndFlushBuild();
161 }
162
BeginFlushLayout()163 void FrameMsgMgr::BeginFlushLayout()
164 {
165 FrameSceneSched *scene = GetSceneHandler();
166 if (scene == nullptr) {
167 RME_LOGE("[BeginFlushLayout]:scene nullptr");
168 return;
169 }
170 scene->BeginFlushLayout();
171 }
172
EndFlushLayout()173 void FrameMsgMgr::EndFlushLayout()
174 {
175 FrameSceneSched *scene = GetSceneHandler();
176 if (scene == nullptr) {
177 RME_LOGE("[EndFlushLayout]:scene nullptr");
178 return;
179 }
180 scene->EndFlushLayout();
181 }
182
BeginFlushRender()183 void FrameMsgMgr::BeginFlushRender()
184 {
185 FrameSceneSched *scene = GetSceneHandler();
186 if (scene == nullptr) {
187 RME_LOGE("[BeginFlushRender]:scene nullptr");
188 return;
189 }
190 scene->BeginFlushRender();
191 }
192
EndFlushRender()193 void FrameMsgMgr::EndFlushRender()
194 {
195 FrameSceneSched *scene = GetSceneHandler();
196 if (scene == nullptr) {
197 RME_LOGE("[EndFlushRender]:scene nullptr");
198 return;
199 }
200 scene->EndFlushRender();
201 }
202
BeginFlushRenderFinish()203 void FrameMsgMgr::BeginFlushRenderFinish()
204 {
205 FrameSceneSched *scene = GetSceneHandler();
206 if (scene == nullptr) {
207 RME_LOGE("[BeginFlushRenderFinish]:scene nullptr");
208 return;
209 }
210 scene->BeginFlushRenderFinish();
211 }
212
EndFlushRenderFinish()213 void FrameMsgMgr::EndFlushRenderFinish()
214 {
215 FrameSceneSched *scene = GetSceneHandler();
216 if (scene == nullptr) {
217 RME_LOGE("[EndFlushRenderFinish]:scene nullptr");
218 return;
219 }
220 scene->EndFlushRenderFinish();
221 }
222
BeginProcessPostFlush()223 void FrameMsgMgr::BeginProcessPostFlush()
224 {
225 FrameSceneSched *scene = GetSceneHandler();
226 if (scene == nullptr) {
227 RME_LOGE("[BeginProcessPostFlush]:scene nullptr");
228 return;
229 }
230 scene->BeginProcessPostFlush();
231 }
232
ProcessCommandsStart()233 void FrameMsgMgr::ProcessCommandsStart()
234 {
235 FrameSceneSched *scene = GetSceneHandler();
236 if (scene == nullptr) {
237 RME_LOGE("[ProcessCommandsStart]:scene nullptr");
238 return;
239 }
240 scene->ProcessCommandsStart();
241 }
242
AnimateStart()243 void FrameMsgMgr::AnimateStart()
244 {
245 FrameSceneSched *scene = GetSceneHandler();
246 if (scene == nullptr) {
247 RME_LOGE("[AnimateStart]:scene nullptr");
248 return;
249 }
250 scene->AnimateStart();
251 }
252
RenderStart()253 void FrameMsgMgr::RenderStart()
254 {
255 FrameSceneSched *scene = GetSceneHandler();
256 if (scene == nullptr) {
257 RME_LOGE("[RenderStart]:scene nullptr");
258 return;
259 }
260 scene->RenderStart();
261 }
262
SendCommandsStart()263 void FrameMsgMgr::SendCommandsStart()
264 {
265 FrameSceneSched *scene = GetSceneHandler();
266 if (scene == nullptr) {
267 RME_LOGE("[SendCommandsStart]:scene nullptr");
268 return;
269 }
270 scene->SendCommandsStart();
271 }
272
HandleEndFrame()273 void FrameMsgMgr::HandleEndFrame()
274 {
275 FrameSceneSched *scene = GetSceneHandler();
276 if (scene == nullptr) {
277 RME_LOGE("[HandleEndFrame]:scene nullptr");
278 return;
279 }
280 scene->HandleEndFrame();
281 }
282
SetSchedParam()283 void FrameMsgMgr::SetSchedParam()
284 {
285 RME_LOGI("[SetSchedParam]: set default sched param!");
286 }
287 } // namespace RME
288 } // namespace OHOS
289