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