• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 RENDER_SERVICE_CORE_PIPELINE_RS_RCD_CONFIG_H
17 #define RENDER_SERVICE_CORE_PIPELINE_RS_RCD_CONFIG_H
18 
19 #pragma once
20 #include <libxml/parser.h>
21 #include <libxml/tree.h>
22 #include <cstring>
23 #include <vector>
24 #include <iostream>
25 #include <cstdlib>
26 #include <memory>
27 #include <mutex>
28 #include <optional>
29 #include <thread>
30 #include <unordered_map>
31 
32 #include "common/rs_rect.h"
33 #include "image/bitmap.h"
34 #include "securec.h"
35 #include "platform/common/rs_log.h"
36 
37 namespace OHOS {
38 namespace Rosen {
39 namespace rs_rcd {
40 
41 const char PATH_CONFIG_FILE[] = "/sys_prod/etc/display/RoundCornerDisplay/config.xml";
42 const char PATH_CONFIG_DIR[] = "/sys_prod/etc/display/RoundCornerDisplay";
43 
44 const char NODE_ROUNDCORNERDISPLAY[] = "RoundCornerDisplay";
45 const char NODE_LCDMODEL[] = "LCDModel";
46 const char NODE_SURFACECONFIG[] = "SurfaceConfig";
47 const char NODE_TOPSURFACE[] = "TopSurface";
48 const char NODE_BOTTOMSURFACE[] = "BottomSurface";
49 const char NODE_SIDEREGIONCONFIG[] = "SideRegionConfig";
50 const char NODE_SIDEREGION[] = "SideRegion";
51 const char NODE_HARDWARECOMPOSERCONFIG[] = "HardwareComposerConfig";
52 const char NODE_HARDWARECOMPOSER[] = "HardwareComposer";
53 const char NODE_ROG[] = "ROG";
54 const char NODE_PORTRAIT[] = "Portrait";
55 const char NODE_LANDSCAPE[] = "Landscape";
56 const char NODE_PORTRAIT_SIDEREGION[] = "Portrait_sideRegion";
57 const char NODE_LANDSCAPE_SIDEREGION[] = "Landscape_sideRegion";
58 const char NODE_LAYERUP[] = "LayerUp";
59 const char NODE_LAYERDOWN[] = "LayerDown";
60 const char NODE_LAYERHIDE[] = "LayerHide";
61 const char NODE_CAMERAAUO[] = "CameraAuo";
62 
63 const char ATTR_SUPPORT[] = "Support";
64 const char ATTR_DISPLAYMODE[] = "DisplayMode";
65 const char ATTR_REGIONMODE[] = "RegionMode";
66 const char ATTR_NAME[] = "Name";
67 const char ATTR_WIDTH[] = "Width";
68 const char ATTR_HEIGHT[] = "Height";
69 const char ATTR_FILENAME[] = "Filename";
70 const char ATTR_BINFILENAME[] = "BinFilename";
71 const char ATTR_OFFSET_X[] = "OffsetX";
72 const char ATTR_OFFSET_Y[] = "OffsetY";
73 const char ATTR_BUFFERSIZE[] = "BufferSize";
74 const char ATTR_CLDWIDTH[] = "CldWidth";
75 const char ATTR_CLDHEIGHT[] = "CldHeight";
76 const char ATTR_DEFAULT[] = "default";
77 
78 struct XMLReader {
79     static bool RegexMatch(const std::string& str, const std::string& pattern);
80     static bool RegexMatchNum(std::string& str);
81     static xmlNodePtr FindNode(const xmlNodePtr& src, const std::string& index);
82     static std::string ReadAttrStr(const xmlNodePtr& src, const std::string& attr);
83     static int ReadAttrInt(const xmlNodePtr& src, const std::string& attr);
84     static float ReadAttrFloat(const xmlNodePtr& src, const std::string& attr);
85     static bool ReadAttrBool(const xmlNodePtr& src, const std::string& attr);
86 };
87 
88 struct SupportConfig {
89     bool support = false;
90     int mode = 0;
91     bool ReadXmlNode(const xmlNodePtr& ptr, const std::string& supportAttr, const std::string& modeAttr);
92 };
93 
94 struct RoundCornerLayer {
95     std::string fileName;
96     int offsetX = 0;
97     int offsetY = 0;
98     std::string binFileName;
99     int bufferSize = 0;
100     int cldWidth = 0;
101     int cldHeight = 0;
102     std::shared_ptr<Drawing::Bitmap> curBitmap = nullptr;
103     bool ReadXmlNode(const xmlNodePtr& ptr, const std::vector<std::string>& attrArray);
104 };
105 
106 struct RoundCornerHardware {
107     bool resourceChanged = false;
108     bool resourcePreparing = false;
109     RectT<uint32_t> displayRect;
110     std::shared_ptr<RoundCornerLayer> topLayer = nullptr;
111     std::shared_ptr<RoundCornerLayer> bottomLayer = nullptr;
112 };
113 
114 struct RogPortrait {
115     RoundCornerLayer layerUp;
116     RoundCornerLayer layerDown;
117     RoundCornerLayer layerHide;
118     bool ReadXmlNode(const xmlNodePtr& portraitNodePtr);
119 };
120 
121 struct RogLandscape {
122     RoundCornerLayer layerUp;
123     bool ReadXmlNode(const xmlNodePtr& landNodePtr);
124 };
125 
126 struct ROGSetting {
127     int width = 0;
128     int height = 0;
129     std::unordered_map<std::string, RogPortrait> portraitMap;
130     std::unordered_map<std::string, RogLandscape> landscapeMap;
131     bool ReadXmlNode(const xmlNodePtr& rogNodePtr);
132     bool HavePortrait(const std::string& name) const;
133     bool HaveLandscape(const std::string& name) const;
134     std::optional<RogPortrait> GetPortrait(const std::string& name) const;
135     std::optional<RogLandscape> GetLandscape(const std::string& name) const;
136 };
137 
138 struct SurfaceConfig {
139     SupportConfig topSurface;
140     SupportConfig bottomSurface;
141     bool ReadXmlNode(const xmlNodePtr& surfaceConfigNodePtr);
142 };
143 
144 struct SideRegionConfig {
145     SupportConfig sideRegion;
146     bool ReadXmlNode(const xmlNodePtr& sideRegionNodePtr);
147 };
148 
149 struct HardwareComposer {
150     bool support = false;
151     bool ReadXmlNode(const xmlNodePtr& ptr, const std::string& supportAttr);
152 };
153 
154 struct HardwareComposerConfig {
155     HardwareComposer hardwareComposer;
156     bool ReadXmlNode(const xmlNodePtr& hardwareComposerNodePtr);
157 };
158 
159 struct LCDModel {
LCDModelLCDModel160     LCDModel() {}
161     virtual ~LCDModel();
162     std::string name;
163     SurfaceConfig surfaceConfig;
164     SideRegionConfig sideRegionConfig;
165     HardwareComposerConfig hardwareConfig;
166     std::vector<ROGSetting*> rogs;
167     bool ReadXmlNode(const xmlNodePtr& lcdNodePtr);
168     SurfaceConfig GetSurfaceConfig() const;
169     SideRegionConfig GetSideRegionConfig() const;
170     HardwareComposerConfig GetHardwareComposerConfig() const;
171     ROGSetting* GetRog(const int w, const int h) const;
172 };
173 
174 struct RCDConfig {
RCDConfigRCDConfig175     RCDConfig() {}
176     virtual ~RCDConfig();
177     static void PrintLayer(const std::string& name, const rs_rcd::RoundCornerLayer& layer);
178     static void PrintParseRog(rs_rcd::ROGSetting* rog);
179     LCDModel* GetLcdModel(const std::string& name) const;
180     bool Load(const std::string& configFile);
181     bool IsDataLoaded() const;
182 private:
183     void CloseXML();
184     void Clear();
185     xmlDocPtr pDoc = nullptr;
186     xmlNodePtr pRoot = nullptr;
187     std::vector<LCDModel*> lcdModels;
188     std::mutex xmlMut;
189     bool isLoadData = false;
190 };
191 } // namespace rs_rcd
192 } // namespace Rosen
193 } // namespace OHOS
194 
195 #endif // RENDER_SERVICE_CORE_PIPELINE_RS_RCD_CONFIG_H