• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #include "host/commands/cvd/parser/instance/cf_boot_configs.h"
17 
18 #include <android-base/logging.h>
19 #include <android-base/strings.h>
20 #include <google/protobuf/text_format.h>
21 
22 #include "launch_cvd.pb.h"
23 
24 #include "common/libs/utils/base64.h"
25 #include "host/commands/assemble_cvd/flags_defaults.h"
26 #include "host/commands/cvd/parser/cf_configs_common.h"
27 #include "host/libs/config/cuttlefish_config.h"
28 
29 namespace cuttlefish {
30 
InitGraphicsConfigs(Json::Value & instances)31 void InitGraphicsConfigs(Json::Value& instances) {
32   InitIntConfigSubGroupVector(instances, "graphics", "displays", "width",
33                               CF_DEFAULTS_DISPLAY_WIDTH);
34   InitIntConfigSubGroupVector(instances, "graphics", "displays", "height",
35                               CF_DEFAULTS_DISPLAY_HEIGHT);
36   InitIntConfigSubGroupVector(instances, "graphics", "displays", "dpi",
37                               CF_DEFAULTS_DISPLAY_DPI);
38   InitIntConfigSubGroupVector(instances, "graphics", "displays",
39                               "refresh_rate_hertz",
40                               CF_DEFAULTS_DISPLAY_REFRESH_RATE);
41 }
42 
GenerateDisplayFlag(const Json::Value & instances_json)43 std::string GenerateDisplayFlag(const Json::Value& instances_json) {
44   using google::protobuf::TextFormat;
45   cuttlefish::InstancesDisplays all_instances_displays;
46 
47   int num_instances = instances_json.size();
48   for (int i = 0; i < num_instances; i++) {
49     auto* instance = all_instances_displays.add_instances();
50     int num_displays = instances_json[i]["graphics"]["displays"].size();
51     for (int j = 0; j < num_displays; j++) {
52       Json::Value display_json = instances_json[i]["graphics"]["displays"][j];
53       auto* display = instance->add_displays();
54       display->set_width(display_json["width"].asInt());
55       display->set_height(display_json["height"].asInt());
56       display->set_dpi(display_json["dpi"].asInt());
57       display->set_refresh_rate_hertz(
58           display_json["refresh_rate_hertz"].asInt());
59     }
60   }
61 
62   std::string bin_output;
63   if (!all_instances_displays.SerializeToString(&bin_output)) {
64     LOG(ERROR) << "Failed to convert display proto to binary string ";
65     return std::string();
66   }
67 
68   std::string base64_output;
69   if (!cuttlefish::EncodeBase64((void*)bin_output.c_str(), bin_output.size(),
70                                 &base64_output)) {
71     LOG(ERROR) << "Failed to apply EncodeBase64 to binary string ";
72     return std::string();
73   }
74   return "--displays_binproto=" + base64_output;
75 }
76 
GenerateGraphicsFlags(const Json::Value & instances)77 std::vector<std::string> GenerateGraphicsFlags(const Json::Value& instances) {
78   std::vector<std::string> result;
79   result.emplace_back(GenerateDisplayFlag(instances));
80   return result;
81 }
82 
83 }  // namespace cuttlefish
84