• 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/thread/task_executor.h"
23 #include "base/utils/macros.h"
24 #include "base/utils/noncopyable.h"
25 #include "core/common/ace_page.h"
26 #include "core/common/platform_window.h"
27 
28 namespace OHOS::Rosen {
29 class RSUIDirector;
30 }
31 
32 namespace OHOS::Ace {
33 
34 namespace NG {
35 class FrameNode;
36 } // namespace NG
37 class ACE_EXPORT Window {
38 public:
39     Window() = default;
40     explicit Window(std::unique_ptr<PlatformWindow> platformWindow);
41     virtual ~Window() = default;
42 
GetWindowId()43     uint32_t GetWindowId() const
44     {
45         return windowId_;
46     }
47 
48     virtual void RequestFrame();
49 
SetTaskExecutor(const RefPtr<TaskExecutor> & taskExecutor)50     virtual void SetTaskExecutor(const RefPtr<TaskExecutor>& taskExecutor) {}
51 
SetInstanceId(int32_t instanceId)52     virtual void SetInstanceId(int32_t instanceId) {}
53 
Init()54     virtual void Init() {}
55 
Destroy()56     virtual void Destroy()
57     {
58         platformWindow_->Destroy();
59         platformWindow_.reset();
60     }
61 
62     virtual void SetRootRenderNode(const RefPtr<RenderNode>& root);
63 
SetRootFrameNode(const RefPtr<NG::FrameNode> & root)64     virtual void SetRootFrameNode(const RefPtr<NG::FrameNode>& root) {}
65 
RecordFrameTime(uint64_t timeStamp,const std::string & name)66     virtual void RecordFrameTime(uint64_t timeStamp, const std::string& name) {}
67 
FlushTasks()68     virtual void FlushTasks() {}
69 
FlushCustomAnimation(uint64_t timeStamp)70     virtual bool FlushCustomAnimation(uint64_t timeStamp)
71     {
72         return false;
73     }
74 
GetRSUIDirector()75     virtual std::shared_ptr<Rosen::RSUIDirector> GetRSUIDirector() const
76     {
77         return nullptr;
78     }
79 
80     void OnVsync(uint64_t nanoTimestamp, uint32_t frameCount);
81 
82     virtual void SetVsyncCallback(AceVsyncCallback&& callback);
83 
OnShow()84     virtual void OnShow()
85     {
86         onShow_ = true;
87     }
88 
OnHide()89     virtual void OnHide()
90     {
91         onShow_ = false;
92     }
93 
IsHide()94     bool IsHide() const
95     {
96         return !onShow_;
97     }
98 
SetDensity(double density)99     void SetDensity(double density)
100     {
101         density_ = density;
102     }
103 
SetGetWindowRectImpl(std::function<Rect ()> && callback)104     void SetGetWindowRectImpl(std::function<Rect()>&& callback)
105     {
106         windowRectImpl_ = std::move(callback);
107     }
108 
GetCurrentWindowRect()109     virtual Rect GetCurrentWindowRect() const
110     {
111         Rect rect;
112         if (windowRectImpl_) {
113             rect = windowRectImpl_();
114         }
115         return rect;
116     }
117 
SetDrawTextAsBitmap(bool useBitmap)118     virtual void SetDrawTextAsBitmap(bool useBitmap) {}
119 
GetRefreshRate()120     virtual float GetRefreshRate() const
121     {
122         return 0.0f;
123     }
124 
GetLastRequestVsyncTime()125     uint64_t GetLastRequestVsyncTime() const
126     {
127         return lastRequestVsyncTime_;
128     }
129 
SetKeepScreenOn(bool keepScreenOn)130     virtual void SetKeepScreenOn(bool keepScreenOn) {};
131 
132 protected:
133     bool isRequestVsync_ = false;
134     bool onShow_ = true;
135     double density_ = 1.0;
136 
137     struct VsyncCallback {
138         AceVsyncCallback callback_ = nullptr;
139         int32_t containerId_ = -1;
140     };
141     std::list<struct VsyncCallback> callbacks_;
142 
143     uint64_t lastRequestVsyncTime_ = 0;
144     uint32_t windowId_ = 0;
145 
146 private:
147     std::function<Rect()> windowRectImpl_;
148     std::unique_ptr<PlatformWindow> platformWindow_;
149 
150     ACE_DISALLOW_COPY_AND_MOVE(Window);
151 };
152 
153 } // namespace OHOS::Ace
154 
155 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_WINDOW_H
156