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