1 /*
2 * Copyright (c) 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 #include "pipeline/rs_uni_render_judgement.h"
17
18 #include <fstream>
19
20 #include "platform/common/rs_log.h"
21
22 namespace OHOS {
23 namespace Rosen {
24 namespace {
25 const std::string CONFIG_PATH = "/etc/";
26 const std::string UNIRENDER_CONFIG_FILE_NAME = "unirender.config";
27 const std::string UNI_RENDER_DISABLED_TAG = "DISABLED";
28 const std::string UNI_RENDER_ENABLED_FOR_ALL_TAG = "ENABLED_FOR_ALL";
29 const std::string UNI_RENDER_DYNAMIC_SWITCH_TAG = "DYNAMIC_SWITCH";
30 }
31
32 // used by render server
GetUniRenderEnabledType()33 UniRenderEnabledType RSUniRenderJudgement::GetUniRenderEnabledType()
34 {
35 return uniRenderEnabledType_;
36 }
37
IsUniRender()38 bool RSUniRenderJudgement::IsUniRender()
39 {
40 return RSUniRenderJudgement::GetUniRenderEnabledType() != UniRenderEnabledType::UNI_RENDER_DISABLED;
41 }
42
InitUniRenderConfig()43 void RSUniRenderJudgement::InitUniRenderConfig()
44 {
45 InitUniRenderWithConfigFile();
46 RS_LOGD("Init RenderService UniRender Type:%d", uniRenderEnabledType_);
47 }
48
SafeGetLine(std::ifstream & configFile,std::string & line)49 std::ifstream& RSUniRenderJudgement::SafeGetLine(std::ifstream &configFile, std::string &line)
50 {
51 std::string myline;
52 std::getline(configFile, myline);
53 if (myline.size() && myline[myline.size() - 1] == '\r') {
54 line = myline.substr(0, myline.size() - 1);
55 } else {
56 line = myline;
57 }
58 return configFile;
59 }
60
InitUniRenderWithConfigFile()61 void RSUniRenderJudgement::InitUniRenderWithConfigFile()
62 {
63 // open config file
64 std::string configFilePath = CONFIG_PATH + UNIRENDER_CONFIG_FILE_NAME;
65 std::ifstream configFile = std::ifstream(configFilePath.c_str());
66 std::string line;
67 // first line, init uniRenderEnabledType_
68 if (!configFile.is_open() || !SafeGetLine(configFile, line) || line.empty()) { // default case
69 #ifdef RS_ENABLE_UNI_RENDER
70 uniRenderEnabledType_ = UniRenderEnabledType::UNI_RENDER_DYNAMIC_SWITCH;
71 #else
72 uniRenderEnabledType_ = UniRenderEnabledType::UNI_RENDER_DISABLED;
73 #endif
74 } else if (line == UNI_RENDER_DISABLED_TAG) {
75 uniRenderEnabledType_ = UniRenderEnabledType::UNI_RENDER_DISABLED;
76 } else if (line == UNI_RENDER_ENABLED_FOR_ALL_TAG) {
77 uniRenderEnabledType_ = UniRenderEnabledType::UNI_RENDER_ENABLED_FOR_ALL;
78 } else if (line == UNI_RENDER_DYNAMIC_SWITCH_TAG) {
79 uniRenderEnabledType_ = UniRenderEnabledType::UNI_RENDER_DYNAMIC_SWITCH;
80 }
81 configFile.close();
82 }
83 } // namespace Rosen
84 } // namespace OHOS
85