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() const44 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() const73 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 HasFirstFrameAnimation()83 virtual bool HasFirstFrameAnimation() 84 { 85 return false; 86 } 87 FlushAnimationStartTime(uint64_t timeStamp)88 virtual void FlushAnimationStartTime(uint64_t timeStamp) {} 89 FlushModifier()90 virtual void FlushModifier() {} 91 HasUIRunningAnimation()92 virtual bool HasUIRunningAnimation() 93 { 94 return false; 95 } 96 97 virtual void OnVsync(uint64_t nanoTimestamp, uint32_t frameCount); 98 99 virtual void SetVsyncCallback(AceVsyncCallback&& callback); 100 OnShow()101 virtual void OnShow() 102 { 103 onShow_ = true; 104 } 105 OnHide()106 virtual void OnHide() 107 { 108 onShow_ = false; 109 } 110 IsHide() const111 bool IsHide() const 112 { 113 return !onShow_; 114 } 115 SetDensity(double density)116 void SetDensity(double density) 117 { 118 density_ = density; 119 } 120 SetGetWindowRectImpl(std::function<Rect()>&& callback)121 void SetGetWindowRectImpl(std::function<Rect()>&& callback) 122 { 123 windowRectImpl_ = std::move(callback); 124 } 125 GetCurrentWindowRect() const126 virtual Rect GetCurrentWindowRect() const 127 { 128 Rect rect; 129 if (windowRectImpl_) { 130 rect = windowRectImpl_(); 131 } 132 return rect; 133 } 134 SetDrawTextAsBitmap(bool useBitmap)135 virtual void SetDrawTextAsBitmap(bool useBitmap) {} 136 GetRefreshRate() const137 virtual float GetRefreshRate() const 138 { 139 return 0.0f; 140 } 141 GetLastRequestVsyncTime() const142 uint64_t GetLastRequestVsyncTime() const 143 { 144 return lastRequestVsyncTime_; 145 } 146 GetLastVsyncEndTimestamp() const147 int64_t GetLastVsyncEndTimestamp() const 148 { 149 return lastVsyncEndTimestamp_; 150 } 151 SetLastVsyncEndTimestamp(int64_t lastVsyncEndTimestamp)152 void SetLastVsyncEndTimestamp(int64_t lastVsyncEndTimestamp) 153 { 154 lastVsyncEndTimestamp_ = lastVsyncEndTimestamp; 155 } 156 SetKeepScreenOn(bool keepScreenOn)157 virtual void SetKeepScreenOn(bool keepScreenOn) {}; 158 GetVSyncPeriod() const159 virtual int64_t GetVSyncPeriod() const 160 { 161 return 0; 162 }; 163 GetWindowName() const164 virtual std::string GetWindowName() const 165 { 166 static std::string name; 167 return name; 168 }; 169 SetCursor(MouseFormat cursor)170 void SetCursor(MouseFormat cursor) 171 { 172 cursor_ = cursor; 173 } 174 GetCursor() const175 MouseFormat GetCursor() const 176 { 177 return cursor_; 178 } 179 SetUserSetCursor(bool isUserSetCursor)180 void SetUserSetCursor(bool isUserSetCursor) 181 { 182 isUserSetCursor_ = isUserSetCursor; 183 } 184 IsUserSetCursor() const185 bool IsUserSetCursor() const 186 { 187 return isUserSetCursor_; 188 } 189 GetCurrentRefreshRateMode() const190 virtual int32_t GetCurrentRefreshRateMode() const 191 { 192 return -1; 193 } 194 GetAnimateExpectedRate() const195 virtual int32_t GetAnimateExpectedRate() const 196 { 197 return 0; 198 } 199 Lock()200 virtual void Lock() {} 201 Unlock()202 virtual void Unlock() {} 203 204 virtual void SetUiDvsyncSwitch(bool dvsyncSwitch); 205 GetStatusBarHeight() const206 virtual uint32_t GetStatusBarHeight() const 207 { 208 return 0; 209 } 210 NotifyExtensionTimeout(int32_t errorCode)211 virtual void NotifyExtensionTimeout(int32_t errorCode) {} 212 protected: 213 bool isRequestVsync_ = false; 214 bool onShow_ = true; 215 double density_ = 1.0; 216 MouseFormat cursor_ = MouseFormat::DEFAULT; 217 bool isUserSetCursor_ = false; 218 219 struct VsyncCallback { 220 AceVsyncCallback callback_ = nullptr; 221 int32_t containerId_ = -1; 222 }; 223 std::list<struct VsyncCallback> callbacks_; 224 225 uint64_t lastRequestVsyncTime_ = 0; 226 int64_t lastVsyncEndTimestamp_ = 0; 227 uint32_t windowId_ = 0; 228 229 private: 230 std::function<Rect()> windowRectImpl_; 231 std::unique_ptr<PlatformWindow> platformWindow_; 232 233 ACE_DISALLOW_COPY_AND_MOVE(Window); 234 }; 235 236 } // namespace OHOS::Ace 237 238 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_WINDOW_H 239