• 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 #include <refbase.h>
23 #include <screen_manager/screen_types.h>
24 #include <ui/rs_display_node.h>
25 #include <ui/rs_surface_node.h>
26 
27 #include "noncopyable.h"
28 #include "screen.h"
29 #include "screen_group.h"
30 #include "screen_group_info.h"
31 #include "screen_info.h"
32 
33 namespace OHOS::Rosen {
34 class AbstractScreenGroup;
35 class AbstractScreenController;
36 class AbstractScreen : public RefBase {
37 public:
38     AbstractScreen(sptr<AbstractScreenController>, const std::string& name, ScreenId dmsId, ScreenId rsId);
39     AbstractScreen() = delete;
40     WM_DISALLOW_COPY_AND_MOVE(AbstractScreen);
41     ~AbstractScreen();
42     sptr<SupportedScreenModes> GetActiveScreenMode() const;
43     std::vector<sptr<SupportedScreenModes>> GetAbstractScreenModes() const;
44     sptr<AbstractScreenGroup> GetGroup() const;
45     sptr<ScreenInfo> ConvertToScreenInfo() const;
46     bool SetOrientation(Orientation orientation);
47     Rotation CalcRotation(Orientation orientation) const;
48     bool SetVirtualPixelRatio(float virtualPixelRatio);
49     float GetVirtualPixelRatio() const;
50     bool SetSourceMode(ScreenSourceMode sourceMode);
51     ScreenSourceMode GetSourceMode() const;
52 
53     void UpdateRSTree(std::shared_ptr<RSSurfaceNode>& surfaceNode, bool isAdd, bool needToUpdate = true);
54     DMError AddSurfaceNode(std::shared_ptr<RSSurfaceNode>& surfaceNode, bool onTop, bool needToRecord = true);
55     DMError RemoveSurfaceNode(std::shared_ptr<RSSurfaceNode>& surfaceNode);
56     void UpdateDisplayGroupRSTree(std::shared_ptr<RSSurfaceNode>& surfaceNode, NodeId parentNodeId, bool isAdd);
57     void InitRSDisplayNode(const RSDisplayNodeConfig& config, const Point& startPoint);
58     void InitRSDefaultDisplayNode(const RSDisplayNodeConfig& config, const Point& startPoint);
59     ScreenId GetScreenGroupId() const;
60 
61     // colorspace, gamut
62     DMError GetScreenSupportedColorGamuts(std::vector<ScreenColorGamut>& colorGamuts);
63     DMError GetScreenColorGamut(ScreenColorGamut& colorGamut);
64     DMError SetScreenColorGamut(int32_t colorGamutIdx);
65     DMError GetScreenGamutMap(ScreenGamutMap& gamutMap);
66     DMError SetScreenGamutMap(ScreenGamutMap gamutMap);
67     DMError SetScreenColorTransform();
68     const std::string& GetScreenName() const;
69     void SetPhyWidth(uint32_t phyWidth);
70     void SetPhyHeight(uint32_t phyHeight);
71     uint32_t GetPhyWidth() const;
72     uint32_t GetPhyHeight() const;
73 
74     const ScreenId dmsId_;
75     const ScreenId rsId_;
76     bool isScreenGroup_ { false };
77     std::shared_ptr<RSDisplayNode> rsDisplayNode_;
78     RSDisplayNodeConfig rSDisplayNodeConfig_;
79     ScreenId groupDmsId_ { SCREEN_ID_INVALID };
80     ScreenId lastGroupDmsId_ { SCREEN_ID_INVALID };
81     ScreenType type_ { ScreenType::REAL };
82     int32_t activeIdx_ { 0 };
83     std::vector<sptr<SupportedScreenModes>> modes_ = {};
84     float virtualPixelRatio_ = { 1.0 };
85     Orientation orientation_ { Orientation::UNSPECIFIED };
86     Rotation rotation_ { Rotation::ROTATION_0 };
87     Orientation screenRequestedOrientation_ { Orientation::UNSPECIFIED };
88     // nativeSurfaceNodes_ means th node which is added/removed by interface of dms directly
89     std::vector<std::shared_ptr<RSSurfaceNode>> nativeSurfaceNodes_;
90     // appSurfaceNodes_ means th node which is added/removed by interface of wms
91     std::vector<std::shared_ptr<RSSurfaceNode>> appSurfaceNodes_;
92 
93 protected:
94     void FillScreenInfo(sptr<ScreenInfo>) const;
95     const sptr<AbstractScreenController> screenController_;
96 
97 private:
98     void SetPropertyForDisplayNode(const std::shared_ptr<RSDisplayNode>& rsDisplayNode,
99         const RSDisplayNodeConfig& config, const Point& startPoint);
100     std::string name_ { "UNKNOW" };
101     uint32_t phyWidth_ { UINT32_MAX };
102     uint32_t phyHeight_ { UINT32_MAX };
103 };
104 
105 class AbstractScreenGroup : public AbstractScreen {
106 public:
107     AbstractScreenGroup(sptr<AbstractScreenController>, ScreenId dmsId, ScreenId rsId, std::string name,
108         ScreenCombination combination);
109     AbstractScreenGroup() = delete;
110     WM_DISALLOW_COPY_AND_MOVE(AbstractScreenGroup);
111     ~AbstractScreenGroup();
112 
113     bool AddChild(sptr<AbstractScreen>& dmsScreen, Point& startPoint);
114     bool AddChildren(std::vector<sptr<AbstractScreen>>& dmsScreens, std::vector<Point>& startPoints);
115     bool RemoveChild(sptr<AbstractScreen>& dmsScreen);
116     bool RemoveDefaultScreen(const sptr<AbstractScreen>& dmsScreen);
117     bool HasChild(ScreenId childScreen) const;
118     std::vector<sptr<AbstractScreen>> GetChildren() const;
119     std::vector<Point> GetChildrenPosition() const;
120     Point GetChildPosition(ScreenId screenId) const;
121     size_t GetChildCount() const;
122     sptr<ScreenGroupInfo> ConvertToScreenGroupInfo() const;
123     ScreenCombination GetScreenCombination() const;
124 
125     ScreenCombination combination_ { ScreenCombination::SCREEN_ALONE };
126     ScreenId mirrorScreenId_ { SCREEN_ID_INVALID };
127     ScreenId defaultScreenId_ { SCREEN_ID_INVALID };
128 
129 private:
130     bool GetRSDisplayNodeConfig(sptr<AbstractScreen>& dmsScreen, struct RSDisplayNodeConfig& config);
131 
132     std::map<ScreenId, std::pair<sptr<AbstractScreen>, Point>> abstractScreenMap_;
133 };
134 } // namespace OHOS::Rosen
135 #endif // FOUNDATION_DMSERVER_ABSTRACT_SCREEN_H