• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
InitArkUI_X()59     virtual void InitArkUI_X() {}
60 
Destroy()61     virtual void Destroy()
62     {
63         platformWindow_->Destroy();
64         platformWindow_.reset();
65     }
66 
67     virtual void SetRootRenderNode(const RefPtr<RenderNode>& root);
68 
SetRootFrameNode(const RefPtr<NG::FrameNode> & root)69     virtual void SetRootFrameNode(const RefPtr<NG::FrameNode>& root) {}
70 
RecordFrameTime(uint64_t timeStamp,const std::string & name)71     virtual void RecordFrameTime(uint64_t timeStamp, const std::string& name) {}
72 
FlushTasks()73     virtual void FlushTasks() {}
74 
GetRSUIDirector()75     virtual std::shared_ptr<Rosen::RSUIDirector> GetRSUIDirector() const
76     {
77         return nullptr;
78     }
79 
FlushLayoutSize(int32_t width,int32_t height)80     virtual void FlushLayoutSize(int32_t width, int32_t height) {}
81 
FlushAnimation(uint64_t timeStamp)82     virtual bool FlushAnimation(uint64_t timeStamp)
83     {
84         return false;
85     }
86 
HasFirstFrameAnimation()87     virtual bool HasFirstFrameAnimation()
88     {
89         return false;
90     }
91 
FlushAnimationStartTime(uint64_t timeStamp)92     virtual void FlushAnimationStartTime(uint64_t timeStamp) {}
93 
FlushModifier()94     virtual void FlushModifier() {}
95 
HasUIRunningAnimation()96     virtual bool HasUIRunningAnimation()
97     {
98         return false;
99     }
100 
101     virtual void OnVsync(uint64_t nanoTimestamp, uint32_t frameCount);
102 
103     virtual void SetVsyncCallback(AceVsyncCallback&& callback);
104 
OnShow()105     virtual void OnShow()
106     {
107         onShow_ = true;
108     }
109 
OnHide()110     virtual void OnHide()
111     {
112         onShow_ = false;
113     }
114 
IsHide()115     bool IsHide() const
116     {
117         return !onShow_;
118     }
119 
SetDensity(double density)120     void SetDensity(double density)
121     {
122         density_ = density;
123     }
124 
SetGetWindowRectImpl(std::function<Rect ()> && callback)125     void SetGetWindowRectImpl(std::function<Rect()>&& callback)
126     {
127         windowRectImpl_ = std::move(callback);
128     }
129 
GetCurrentWindowRect()130     virtual Rect GetCurrentWindowRect() const
131     {
132         Rect rect;
133         if (windowRectImpl_) {
134             rect = windowRectImpl_();
135         }
136         return rect;
137     }
138 
SetDrawTextAsBitmap(bool useBitmap)139     virtual void SetDrawTextAsBitmap(bool useBitmap) {}
140 
GetRefreshRate()141     virtual float GetRefreshRate() const
142     {
143         return 0.0f;
144     }
145 
GetLastRequestVsyncTime()146     uint64_t GetLastRequestVsyncTime() const
147     {
148         return lastRequestVsyncTime_;
149     }
150 
GetLastVsyncEndTimestamp()151     int64_t GetLastVsyncEndTimestamp() const
152     {
153         return lastVsyncEndTimestamp_;
154     }
155 
SetLastVsyncEndTimestamp(int64_t lastVsyncEndTimestamp)156     void SetLastVsyncEndTimestamp(int64_t lastVsyncEndTimestamp)
157     {
158         lastVsyncEndTimestamp_ = lastVsyncEndTimestamp;
159     }
160 
SetKeepScreenOn(bool keepScreenOn)161     virtual void SetKeepScreenOn(bool keepScreenOn) {};
162 
GetVSyncPeriod()163     virtual int64_t GetVSyncPeriod() const
164     {
165         return 0;
166     };
167 
GetWindowName()168     virtual std::string GetWindowName() const
169     {
170         static std::string name;
171         return name;
172     };
173 
SetCursor(MouseFormat cursor)174     void SetCursor(MouseFormat cursor)
175     {
176         cursor_ = cursor;
177     }
178 
GetCursor()179     MouseFormat GetCursor() const
180     {
181         return cursor_;
182     }
183 
SetUserSetCursor(bool isUserSetCursor)184     void SetUserSetCursor(bool isUserSetCursor)
185     {
186         isUserSetCursor_ = isUserSetCursor;
187     }
188 
IsUserSetCursor()189     bool IsUserSetCursor() const
190     {
191         return isUserSetCursor_;
192     }
193 
GetCurrentRefreshRateMode()194     virtual int32_t GetCurrentRefreshRateMode() const
195     {
196         return -1;
197     }
198 
GetAnimateExpectedRate()199     virtual int32_t GetAnimateExpectedRate() const
200     {
201         return 0;
202     }
203 
Lock()204     virtual void Lock() {}
205 
Unlock()206     virtual void Unlock() {}
207 
208     virtual void SetUiDvsyncSwitch(bool dvsyncSwitch);
209 
GetStatusBarHeight()210     virtual uint32_t GetStatusBarHeight() const
211     {
212         return 0;
213     }
214 
GetIsRequestVsync()215     virtual bool GetIsRequestVsync()
216     {
217         return false;
218     }
219 
NotifyExtensionTimeout(int32_t errorCode)220     virtual void NotifyExtensionTimeout(int32_t errorCode) {}
221 
GetIsRequestFrame()222     virtual bool GetIsRequestFrame()
223     {
224         return false;
225     }
226 protected:
227     bool isRequestVsync_ = false;
228     bool onShow_ = true;
229     double density_ = 1.0;
230     MouseFormat cursor_ = MouseFormat::DEFAULT;
231     bool isUserSetCursor_ = false;
232 
233     struct VsyncCallback {
234         AceVsyncCallback callback_ = nullptr;
235         int32_t containerId_ = -1;
236     };
237     std::list<struct VsyncCallback> callbacks_;
238 
239     uint64_t lastRequestVsyncTime_ = 0;
240     int64_t lastVsyncEndTimestamp_ = 0;
241     uint32_t windowId_ = 0;
242 
243 private:
244     std::function<Rect()> windowRectImpl_;
245     std::unique_ptr<PlatformWindow> platformWindow_;
246 
247     ACE_DISALLOW_COPY_AND_MOVE(Window);
248 };
249 
250 } // namespace OHOS::Ace
251 
252 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_WINDOW_H
253