1 /*
2  * Copyright (c) 2024 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 #ifndef FRAMEWORKS_BOOTANIMATION_INCLUDE_BOOT_ANIMATION_OPERATION_H
17 #define FRAMEWORKS_BOOTANIMATION_INCLUDE_BOOT_ANIMATION_OPERATION_H
18 
19 #include <condition_variable>
20 #include <mutex>
21 #include <thread>
22 
23 #include "boot_animation_config.h"
24 #include "boot_compile_progress.h"
25 #include "boot_player.h"
26 #include "event_handler.h"
27 #ifdef NEW_RENDER_CONTEXT
28 #include "render_context_factory.h"
29 #include "rs_surface_factory.h"
30 #endif
31 #include <render_context/render_context.h>
32 #include <ui/rs_display_node.h>
33 #include <ui/rs_surface_extractor.h>
34 #include "util.h"
35 
36 namespace OHOS {
37 class BootAnimationOperation {
38 public:
39     BootAnimationOperation() = default;
40 
41     virtual ~BootAnimationOperation();
42 
43     void Init(const BootAnimationConfig& config, int32_t width, int32_t height, int32_t duration);
44 
45     void SetSoundEnable(bool isEnabled);
46 
47     std::thread& GetThread();
48 
49 private:
50     void StartEventHandler(const BootAnimationConfig& config);
51     bool IsBootVideoEnabled(const BootAnimationConfig& config);
52     bool InitRsDisplayNode();
53     bool InitRsSurfaceNode(int32_t degree);
54     bool InitRsSurface();
55     void PlayVideo(const std::string& path);
56     void PlayPicture(const std::string& path);
57     void PlaySound(const std::string& path);
58     void StopBootAnimation();
59 
60 private:
61     bool isSoundEnabled_ = true;
62     int32_t windowWidth_;
63     int32_t windowHeight_;
64     int32_t duration_;
65     Rosen::ScreenId currentScreenId_;
66     OHOS::BootAnimationCallback callback_;
67 
68     std::mutex eventMutex_;
69     std::thread eventThread_;
70     std::condition_variable eventCon_;
71 
72 #ifdef NEW_RENDER_CONTEXT
73     std::shared_ptr<OHOS::Rosen::RSRenderSurface> rsSurface_;
74 #endif
75     std::shared_ptr<OHOS::Rosen::RSSurface> rsSurface_;
76     std::shared_ptr<OHOS::Rosen::RSDisplayNode> rsDisplayNode_;
77     std::shared_ptr<OHOS::Rosen::RSSurfaceNode> rsSurfaceNode_;
78 
79     std::shared_ptr<OHOS::AppExecFwk::EventRunner> runner_;
80     std::shared_ptr<OHOS::AppExecFwk::EventHandler> mainHandler_;
81 
82     std::shared_ptr<BootPlayer> picPlayer_;
83     std::shared_ptr<BootPlayer> soundPlayer_;
84     std::shared_ptr<BootPlayer> videoPlayer_;
85 };
86 } // namespace OHOS
87 
88 #endif // FRAMEWORKS_BOOTANIMATION_INCLUDE_BOOT_ANIMATION_OPERATION_H
89