• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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_DMSERVER_ABSTRACT_SCREEN_H
17 #define FOUNDATION_DMSERVER_ABSTRACT_SCREEN_H
18 
19 
20 #include <vector>
21 #include <map>
22 
23 #include <refbase.h>
24 #include <screen_manager/screen_types.h>
25 #include <ui/rs_display_node.h>
26 #include <ui/rs_surface_node.h>
27 #include <ui/rs_ui_context.h>
28 #include <ui/rs_ui_director.h>
29 
30 #include "display_info.h"
31 #include "noncopyable.h"
32 #include "screen.h"
33 #include "screen_group.h"
34 #include "screen_group_info.h"
35 #include "screen_info.h"
36 
37 namespace OHOS::Rosen {
38 class AbstractScreenGroup;
39 class AbstractScreenController;
40 class AbstractScreen : public RefBase {
41 public:
42     AbstractScreen(sptr<AbstractScreenController>, const std::string& name, ScreenId dmsId, ScreenId rsId);
43     AbstractScreen() = delete;
44     WM_DISALLOW_COPY_AND_MOVE(AbstractScreen);
45     ~AbstractScreen();
46     sptr<SupportedScreenModes> GetActiveScreenMode() const;
47     std::vector<sptr<SupportedScreenModes>> GetAbstractScreenModes() const;
48     sptr<AbstractScreenGroup> GetGroup() const;
49     sptr<ScreenInfo> ConvertToScreenInfo() const;
50     bool SetOrientation(Orientation orientation);
51     Rotation CalcRotation(Orientation orientation) const;
52     bool SetVirtualPixelRatio(float virtualPixelRatio);
53     float GetVirtualPixelRatio() const;
54     bool SetSourceMode(ScreenSourceMode sourceMode);
55     ScreenSourceMode GetSourceMode() const;
56     DisplaySourceMode GetDisplaySourceMode() const;
57 
58     void UpdateRSTree(std::shared_ptr<RSSurfaceNode>& surfaceNode, bool isAdd, bool needToUpdate = true);
59     DMError AddSurfaceNode(std::shared_ptr<RSSurfaceNode>& surfaceNode, bool onTop, bool needToRecord = true);
60     DMError RemoveSurfaceNode(std::shared_ptr<RSSurfaceNode>& surfaceNode);
61     void UpdateDisplayGroupRSTree(
62         std::shared_ptr<RSSurfaceNode>& surfaceNode, std::shared_ptr<RSDisplayNode>& parentNode, bool isAdd);
63     void InitRSDisplayNode(const RSDisplayNodeConfig& config, const Point& startPoint);
64     void InitRSDefaultDisplayNode(const RSDisplayNodeConfig& config, const Point& startPoint);
65     void UpdateRSDisplayNode(Point startPoint, const sptr<AbstractScreen>& absScreen);
66     ScreenId GetScreenGroupId() const;
67     sptr<DisplayInfo> ConvertScreenInfoToDisplayInfo(const sptr<ScreenInfo>& info) const;
68     void FillDisplayInfoByScreenInfo(sptr<DisplayInfo> displayInfo, const sptr<ScreenInfo>& info) const;
69 
70     // colorspace, gamut
71     DMError GetScreenSupportedColorGamuts(std::vector<ScreenColorGamut>& colorGamuts);
72     DMError GetScreenColorGamut(ScreenColorGamut& colorGamut);
73     DMError SetScreenColorGamut(int32_t colorGamutIdx);
74     DMError GetScreenGamutMap(ScreenGamutMap& gamutMap);
75     DMError SetScreenGamutMap(ScreenGamutMap gamutMap);
76     DMError SetScreenColorTransform();
77     const std::string& GetScreenName() const;
78     void SetPhyWidth(uint32_t phyWidth);
79     void SetPhyHeight(uint32_t phyHeight);
80     uint32_t GetPhyWidth() const;
81     uint32_t GetPhyHeight() const;
82 
83     /*
84      * RS Client Multi Instance
85      */
86     std::shared_ptr<RSUIContext> GetRSUIContext() const;
87 
88     const ScreenId dmsId_;
89     const ScreenId rsId_;
90     bool isScreenGroup_ { false };
91     std::shared_ptr<RSDisplayNode> rsDisplayNode_;
92     RSDisplayNodeConfig rSDisplayNodeConfig_;
93     Point startPoint_{};
94     ScreenId groupDmsId_ { SCREEN_ID_INVALID };
95     ScreenId lastGroupDmsId_ { SCREEN_ID_INVALID };
96     ScreenType type_ { ScreenType::REAL };
97     int32_t activeIdx_ { 0 };
98     std::vector<sptr<SupportedScreenModes>> modes_ = {};
99     float virtualPixelRatio_ = { 1.0 };
100     Orientation orientation_ { Orientation::UNSPECIFIED };
101     Rotation rotation_ { Rotation::ROTATION_0 };
102     Orientation screenRequestedOrientation_ { Orientation::UNSPECIFIED };
103     // nativeSurfaceNodes_ means th node which is added/removed by interface of dms directly
104     std::vector<std::shared_ptr<RSSurfaceNode>> nativeSurfaceNodes_;
105     // appSurfaceNodes_ means th node which is added/removed by interface of wms
106     std::vector<std::shared_ptr<RSSurfaceNode>> appSurfaceNodes_;
107 
108 protected:
109     void FillScreenInfo(sptr<ScreenInfo>) const;
110     const sptr<AbstractScreenController> screenController_;
111 
112 private:
113     void SetPropertyForDisplayNode(const std::shared_ptr<RSDisplayNode>& rsDisplayNode,
114         const RSDisplayNodeConfig& config, const Point& startPoint);
115     std::string name_ { "UNKNOWN" };
116     uint32_t phyWidth_ { UINT32_MAX };
117     uint32_t phyHeight_ { UINT32_MAX };
118     mutable std::recursive_mutex mutex_;
119 
120     /*
121      * RS Client Multi Instance
122      */
123     std::shared_ptr<RSUIDirector> rsUIDirector_;
124 };
125 
126 class AbstractScreenGroup : public AbstractScreen {
127 public:
128     AbstractScreenGroup(sptr<AbstractScreenController>, ScreenId dmsId, ScreenId rsId, std::string name,
129         ScreenCombination combination);
130     AbstractScreenGroup() = delete;
131     WM_DISALLOW_COPY_AND_MOVE(AbstractScreenGroup);
132     ~AbstractScreenGroup();
133 
134     bool AddChild(sptr<AbstractScreen>& dmsScreen, Point& startPoint);
135     bool AddChildren(std::vector<sptr<AbstractScreen>>& dmsScreens, std::vector<Point>& startPoints);
136     bool RemoveChild(sptr<AbstractScreen>& dmsScreen);
137     bool RemoveDefaultScreen(const sptr<AbstractScreen>& dmsScreen);
138     bool HasChild(ScreenId childScreen) const;
139     std::vector<sptr<AbstractScreen>> GetChildren() const;
140     std::vector<Point> GetChildrenPosition() const;
141     Point GetChildPosition(ScreenId screenId) const;
142     size_t GetChildCount() const;
143     sptr<ScreenGroupInfo> ConvertToScreenGroupInfo() const;
144     ScreenCombination GetScreenCombination() const;
145 
146     ScreenCombination combination_ { ScreenCombination::SCREEN_ALONE };
147     ScreenId mirrorScreenId_ { SCREEN_ID_INVALID };
148     ScreenId defaultScreenId_ { SCREEN_ID_INVALID };
149 
150 private:
151     bool GetRSDisplayNodeConfig(sptr<AbstractScreen>& dmsScreen, struct RSDisplayNodeConfig& config);
152 
153     std::map<ScreenId, sptr<AbstractScreen>> screenMap_;
154     mutable std::mutex screenMapMutex_;
155 };
156 } // namespace OHOS::Rosen
157 #endif // FOUNDATION_DMSERVER_ABSTRACT_SCREEN_H
158