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