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/utils/macros.h" 22 #include "base/utils/noncopyable.h" 23 #include "core/common/ace_page.h" 24 #include "core/common/platform_window.h" 25 26 namespace OHOS::Ace { 27 28 namespace NG { 29 class FrameNode; 30 } // namespace NG 31 class ACE_EXPORT Window { 32 public: 33 Window() = default; 34 explicit Window(std::unique_ptr<PlatformWindow> platformWindow); 35 virtual ~Window() = default; 36 37 virtual void RequestFrame(); 38 Destroy()39 virtual void Destroy() 40 { 41 platformWindow_->Destroy(); 42 platformWindow_.reset(); 43 } 44 45 virtual void SetRootRenderNode(const RefPtr<RenderNode>& root); 46 SetRootFrameNode(const RefPtr<NG::FrameNode> & root)47 virtual void SetRootFrameNode(const RefPtr<NG::FrameNode>& root) {} 48 RecordFrameTime(uint64_t timeStamp,const std::string & name)49 virtual void RecordFrameTime(uint64_t timeStamp, const std::string& name) {} 50 FlushTasks()51 virtual void FlushTasks() {} 52 FlushCustomAnimation(uint64_t timeStamp)53 virtual bool FlushCustomAnimation(uint64_t timeStamp) 54 { 55 return false; 56 }; 57 58 void OnVsync(uint64_t nanoTimestamp, uint32_t frameCount); 59 60 virtual void SetVsyncCallback(AceVsyncCallback&& callback); 61 OnShow()62 virtual void OnShow() 63 { 64 onShow_ = true; 65 } 66 OnHide()67 virtual void OnHide() 68 { 69 onShow_ = false; 70 } 71 IsHide()72 bool IsHide() const 73 { 74 return !onShow_; 75 } 76 SetDensity(double density)77 void SetDensity(double density) 78 { 79 density_ = density; 80 } 81 SetGetWindowRectImpl(std::function<Rect ()> && callback)82 void SetGetWindowRectImpl(std::function<Rect()>&& callback) 83 { 84 windowRectImpl_ = std::move(callback); 85 } 86 GetCurrentWindowRect()87 Rect GetCurrentWindowRect() const 88 { 89 Rect rect; 90 if (windowRectImpl_) { 91 rect = windowRectImpl_(); 92 } 93 return rect; 94 } 95 SetDrawTextAsBitmap(bool useBitmap)96 virtual void SetDrawTextAsBitmap(bool useBitmap) {} 97 98 protected: 99 bool isRequestVsync_ = false; 100 bool onShow_ = true; 101 double density_ = 1.0; 102 103 struct VsyncCallback { 104 AceVsyncCallback callback_ = nullptr; 105 int32_t containerId_ = -1; 106 }; 107 std::list<struct VsyncCallback> callbacks_; 108 109 private: 110 std::function<Rect()> windowRectImpl_; 111 std::unique_ptr<PlatformWindow> platformWindow_; 112 113 ACE_DISALLOW_COPY_AND_MOVE(Window); 114 }; 115 116 } // namespace OHOS::Ace 117 118 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_WINDOW_H 119