1 /*
2  * Copyright (c) 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_COMPONENTS_NG_PATTERN_WINDOW_SCENE_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_WINDOW_SCENE_H
18 
19 #include "core/components_ng/pattern/window_scene/scene/window_pattern.h"
20 
21 namespace OHOS::Ace::NG {
22 class WindowScene : public WindowPattern {
23     DECLARE_ACE_TYPE(WindowScene, WindowPattern);
24 
25 public:
26     explicit WindowScene(const sptr<Rosen::Session>& session);
27     ~WindowScene() override;
28     uint32_t GetWindowPatternType() const override;
29 
30 protected:
GetContextParam()31     std::optional<RenderContext::ContextParam> GetContextParam() const override
32     {
33         return RenderContext::ContextParam { RenderContext::ContextType::EXTERNAL };
34     }
35 
HasStartingPage()36     bool HasStartingPage() override
37     {
38         return true;
39     }
40 
41     void OnAttachToFrameNode() override;
42     void OnDetachFromFrameNode(FrameNode* frameNode) override;
43     void OnMountToParentDone() override;
44     bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override;
45 
46     void OnActivation() override;
47     void OnConnect() override;
48     void OnDisconnect() override;
49     void OnLayoutFinished() override;
50     void OnDrawingCompleted() override;
51     void OnRemoveBlank() override;
52     void OnAppRemoveStartingWindow() override;
53 
54 private:
55     std::shared_ptr<Rosen::RSSurfaceNode> CreateLeashWindowNode();
56     void BufferAvailableCallback();
57     void BufferAvailableCallbackForBlank(bool fromMainThread);
58     void BufferAvailableCallbackForSnapshot();
59     void DisposeSnapshotAndBlankWindow();
60     void OnBoundsChanged(const Rosen::Vector4f& bounds);
61     bool IsWindowSizeEqual();
62     void RegisterResponseRegionCallback();
63     void RegisterFocusCallback();
64     void CleanBlankWindow();
65     void SetSubWindowBufferAvailableCallback(const std::shared_ptr<Rosen::RSSurfaceNode>& surfaceNode);
66 
67     bool destroyed_ = false;
68     OHOS::Rosen::WindowMode initWindowMode_ = OHOS::Rosen::WindowMode::WINDOW_MODE_UNDEFINED;
69     CancelableCallback<void()> deleteWindowTask_;
70     CancelableCallback<void()> removeStartingWindowTask_;
71 
72     ACE_DISALLOW_COPY_AND_MOVE(WindowScene);
73 };
74 } // namespace OHOS::Ace::NG
75 
76 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_WINDOW_SCENE_H
77