1 /* 2 * Copyright (c) 2021-2023 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_WINDOW_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_WINDOW_H 18 19 #include <memory> 20 21 #include "base/geometry/ng/rect_t.h" 22 #include "base/mousestyle/mouse_style.h" 23 #include "base/thread/task_executor.h" 24 #include "base/utils/macros.h" 25 #include "base/utils/noncopyable.h" 26 #include "core/common/ace_page.h" 27 #include "core/common/platform_window.h" 28 29 namespace OHOS::Rosen { 30 class RSUIDirector; 31 } 32 33 namespace OHOS::Ace { 34 35 namespace NG { 36 class FrameNode; 37 } // namespace NG 38 class ACE_EXPORT Window : public std::enable_shared_from_this<Window> { 39 public: 40 Window() = default; 41 explicit Window(std::unique_ptr<PlatformWindow> platformWindow); 42 virtual ~Window() = default; 43 GetWindowId()44 uint32_t GetWindowId() const 45 { 46 return windowId_; 47 } 48 49 virtual void RequestFrame(); 50 FlushFrameRate(int32_t rate,int32_t animatorExpectedFrameRate,int32_t rateTyte)51 virtual void FlushFrameRate(int32_t rate, int32_t animatorExpectedFrameRate, int32_t rateTyte) {} 52 SetTaskExecutor(const RefPtr<TaskExecutor> & taskExecutor)53 virtual void SetTaskExecutor(const RefPtr<TaskExecutor>& taskExecutor) {} 54 SetInstanceId(int32_t instanceId)55 virtual void SetInstanceId(int32_t instanceId) {} 56 Init()57 virtual void Init() {} 58 Destroy()59 virtual void Destroy() 60 { 61 platformWindow_->Destroy(); 62 platformWindow_.reset(); 63 } 64 65 virtual void SetRootRenderNode(const RefPtr<RenderNode>& root); 66 SetRootFrameNode(const RefPtr<NG::FrameNode> & root)67 virtual void SetRootFrameNode(const RefPtr<NG::FrameNode>& root) {} 68 RecordFrameTime(uint64_t timeStamp,const std::string & name)69 virtual void RecordFrameTime(uint64_t timeStamp, const std::string& name) {} 70 FlushTasks()71 virtual void FlushTasks() {} 72 GetRSUIDirector()73 virtual std::shared_ptr<Rosen::RSUIDirector> GetRSUIDirector() const 74 { 75 return nullptr; 76 } 77 FlushAnimation(uint64_t timeStamp)78 virtual bool FlushAnimation(uint64_t timeStamp) 79 { 80 return false; 81 } 82 FlushAnimationStartTime(uint64_t timeStamp)83 virtual void FlushAnimationStartTime(uint64_t timeStamp) {} 84 FlushModifier()85 virtual void FlushModifier() {} 86 HasUIRunningAnimation()87 virtual bool HasUIRunningAnimation() 88 { 89 return false; 90 } 91 92 virtual void OnVsync(uint64_t nanoTimestamp, uint32_t frameCount); 93 94 virtual void SetVsyncCallback(AceVsyncCallback&& callback); 95 OnShow()96 virtual void OnShow() 97 { 98 onShow_ = true; 99 } 100 OnHide()101 virtual void OnHide() 102 { 103 onShow_ = false; 104 } 105 IsHide()106 bool IsHide() const 107 { 108 return !onShow_; 109 } 110 SetDensity(double density)111 void SetDensity(double density) 112 { 113 density_ = density; 114 } 115 SetGetWindowRectImpl(std::function<Rect ()> && callback)116 void SetGetWindowRectImpl(std::function<Rect()>&& callback) 117 { 118 windowRectImpl_ = std::move(callback); 119 } 120 GetCurrentWindowRect()121 virtual Rect GetCurrentWindowRect() const 122 { 123 Rect rect; 124 if (windowRectImpl_) { 125 rect = windowRectImpl_(); 126 } 127 return rect; 128 } 129 SetDrawTextAsBitmap(bool useBitmap)130 virtual void SetDrawTextAsBitmap(bool useBitmap) {} 131 GetRefreshRate()132 virtual float GetRefreshRate() const 133 { 134 return 0.0f; 135 } 136 GetLastRequestVsyncTime()137 uint64_t GetLastRequestVsyncTime() const 138 { 139 return lastRequestVsyncTime_; 140 } 141 GetLastVsyncEndTimestamp()142 int64_t GetLastVsyncEndTimestamp() const 143 { 144 return lastVsyncEndTimestamp_; 145 } 146 SetLastVsyncEndTimestamp(int64_t lastVsyncEndTimestamp)147 void SetLastVsyncEndTimestamp(int64_t lastVsyncEndTimestamp) 148 { 149 lastVsyncEndTimestamp_ = lastVsyncEndTimestamp; 150 } 151 SetKeepScreenOn(bool keepScreenOn)152 virtual void SetKeepScreenOn(bool keepScreenOn) {}; 153 GetVSyncPeriod()154 virtual int64_t GetVSyncPeriod() const 155 { 156 return 0; 157 }; 158 GetWindowName()159 virtual std::string GetWindowName() const 160 { 161 static std::string name; 162 return name; 163 }; 164 SetCursor(MouseFormat cursor)165 void SetCursor(MouseFormat cursor) 166 { 167 cursor_ = cursor; 168 } 169 GetCursor()170 MouseFormat GetCursor() const 171 { 172 return cursor_; 173 } 174 SetUserSetCursor(bool isUserSetCursor)175 void SetUserSetCursor(bool isUserSetCursor) 176 { 177 isUserSetCursor_ = isUserSetCursor; 178 } 179 IsUserSetCursor()180 bool IsUserSetCursor() const 181 { 182 return isUserSetCursor_; 183 } 184 GetCurrentRefreshRateMode()185 virtual int32_t GetCurrentRefreshRateMode() const 186 { 187 return -1; 188 } 189 GetAnimateExpectedRate()190 virtual int32_t GetAnimateExpectedRate() const 191 { 192 return 0; 193 } 194 Lock()195 virtual void Lock() {} 196 Unlock()197 virtual void Unlock() {} 198 199 virtual void SetUiDvsyncSwitch(bool dvsyncSwitch); 200 201 protected: 202 bool isRequestVsync_ = false; 203 bool onShow_ = true; 204 double density_ = 1.0; 205 MouseFormat cursor_ = MouseFormat::DEFAULT; 206 bool isUserSetCursor_ = false; 207 208 struct VsyncCallback { 209 AceVsyncCallback callback_ = nullptr; 210 int32_t containerId_ = -1; 211 }; 212 std::list<struct VsyncCallback> callbacks_; 213 214 uint64_t lastRequestVsyncTime_ = 0; 215 int64_t lastVsyncEndTimestamp_ = 0; 216 uint32_t windowId_ = 0; 217 218 private: 219 std::function<Rect()> windowRectImpl_; 220 std::unique_ptr<PlatformWindow> platformWindow_; 221 222 ACE_DISALLOW_COPY_AND_MOVE(Window); 223 }; 224 225 } // namespace OHOS::Ace 226 227 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_WINDOW_H 228