1 /* 2 * Copyright (c) 2022-2025 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 OHOS_ROSEN_STARTING_WINDOW_H 17 #define OHOS_ROSEN_STARTING_WINDOW_H 18 19 #include <bundlemgr/launcher_service.h> 20 #include <refbase.h> 21 #include <resource_manager.h> 22 23 #include "ability_info.h" 24 #include "animation_config.h" 25 #include "bundle_info.h" 26 #include "image_source.h" 27 #include "pixel_map.h" 28 #include "surface_draw.h" 29 #include "window_node.h" 30 #include "window_root.h" 31 #include "window_transition_info.h" 32 #include "wm_common.h" 33 34 namespace OHOS { 35 namespace Rosen { 36 struct ResInfoShowState { 37 uint32_t frameIdx = 0; 38 uint32_t frameCount = 0; 39 std::vector<int32_t> delay; 40 std::chrono::steady_clock::time_point next; 41 }; 42 struct StartingWindowShowInfo { 43 wptr<WindowNode> node; 44 Rect rect; 45 std::shared_ptr<Rosen::StartingWindowPageDrawInfo> info; 46 float vpRatio; 47 std::array<ResInfoShowState, size_t(StartWindowResType::Count)> resStates {}; 48 std::array<uint32_t, size_t(StartWindowResType::Count)> frameIndex {}; 49 }; 50 class StartingWindow : public RefBase { 51 public: 52 StartingWindow() = delete; 53 ~StartingWindow() = default; 54 55 static sptr<WindowNode> CreateWindowNode(const sptr<WindowTransitionInfo>& info, uint32_t winId); 56 static void HandleClientWindowCreate(sptr<WindowNode>& node, sptr<IWindow>& window, 57 uint32_t& windowId, const std::shared_ptr<RSSurfaceNode>& surfaceNode, sptr<WindowProperty>& property, 58 int32_t pid, int32_t uid); 59 static WMError DrawStartingWindow(sptr<WindowNode>& node, std::shared_ptr<Media::PixelMap> pixelMap, 60 uint32_t bkgColor, bool isColdStart); 61 static void AddNodeOnRSTree(sptr<WindowNode>& node, bool isMultiDisplay); 62 static void ReleaseStartWinSurfaceNode(sptr<WindowNode>& node); 63 static void SetDefaultWindowMode(WindowMode defaultMode); 64 static void SetAnimationConfig(AnimationConfig config); 65 static bool transAnimateEnable_; 66 static WindowUIType windowUIType_; 67 68 private: 69 static WMError CreateLeashAndStartingSurfaceNode(sptr<WindowNode>& node); 70 static WMError SetStartingWindowAnimation(wptr<WindowNode> weak); 71 static void ChangePropertyByApiVersion(const sptr<WindowTransitionInfo>& info, 72 const Orientation orientation, sptr<WindowProperty>& property); 73 static std::recursive_mutex mutex_; 74 static WindowMode defaultMode_; 75 static AnimationConfig animationConfig_; 76 static bool IsWindowFollowParent(WindowType type); 77 static sptr<WindowProperty> InitializeWindowProperty(const sptr<WindowTransitionInfo>& info, uint32_t winId); 78 static void UpdateRSTree(sptr<WindowNode>& node, bool isMultiDisplay); 79 static sptr<AppExecFwk::IBundleMgr> GetBundleManager(); 80 static std::shared_ptr<AppExecFwk::AbilityInfo> GetAbilityInfoFromBMS(const sptr<WindowNode>& node, 81 const sptr<AppExecFwk::IBundleMgr>& bundleMgr); 82 static std::shared_ptr<Global::Resource::ResourceManager> CreateResourceManager( 83 const std::shared_ptr<AppExecFwk::AbilityInfo>& abilityInfo); 84 static std::shared_ptr<Rosen::ResourceInfo> GetPixelMapListInfo(uint32_t mediaDataId, 85 const std::shared_ptr<Global::Resource::ResourceManager>& resourceMgr, 86 const std::shared_ptr<AppExecFwk::AbilityInfo>& abilityInfo); 87 static std::shared_ptr<Rosen::StartingWindowPageDrawInfo> GetCustomStartingWindowInfo( 88 const sptr<WindowNode>& node, const sptr<AppExecFwk::IBundleMgr>& bundleMgr); 89 static std::shared_ptr<Rosen::StartingWindowPageDrawInfo> DoGetCustomStartingWindowInfo( 90 const std::shared_ptr<AppExecFwk::AbilityInfo>& abilityInfo, 91 const std::shared_ptr<Global::Resource::ResourceManager>& resourceMgr); 92 static WMError DrawStartingWindow(const std::shared_ptr<Rosen::StartingWindowPageDrawInfo>& info, 93 const sptr<WindowNode>& node, const Rect& rect); 94 static void RegisterStartingWindowShowInfo(const sptr<WindowNode>& node, const Rect& rect, 95 const std::shared_ptr<Rosen::StartingWindowPageDrawInfo>& info, float vpRatio); 96 static void UnRegisterStartingWindowShowInfo(); 97 static void UpdateWindowShowInfo(StartingWindowShowInfo& startingWindowShowInfo, bool& needRedraw); 98 static void DrawStartingWindowShowInfo(); 99 static StartingWindowShowInfo startingWindowShowInfo_; 100 static std::atomic<bool> startingWindowShowRunning_; 101 static std::thread startingWindowShowThread_; 102 static std::mutex firstFrameMutex_; 103 static std::condition_variable firstFrameCondition_; 104 static std::atomic<bool> firstFrameCompleted_; 105 }; 106 } // Rosen 107 } // OHOS 108 #endif // OHOS_ROSEN_STARTING_WINDOW_H