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