1 /*
2 * Copyright 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
17 #include "Common.h"
18
19 #include <android-base/properties.h>
20
21 namespace aidl::android::hardware::graphics::composer3::impl {
22
IsAutoDevice()23 bool IsAutoDevice() {
24 // gcar_emu_x86_64, sdk_car_md_x86_64, cf_x86_64_auto, cf_x86_64_only_auto_md
25 const std::string product_name = ::android::base::GetProperty("ro.product.name", "");
26 return product_name.find("car_") != std::string::npos ||
27 product_name.find("_auto") != std::string::npos;
28 }
29
IsCuttlefish()30 bool IsCuttlefish() { return ::android::base::GetProperty("ro.product.board", "") == "cutf"; }
31
IsCuttlefishFoldable()32 bool IsCuttlefishFoldable() {
33 return IsCuttlefish() && ::android::base::GetProperty("ro.product.name", "").find("foldable") !=
34 std::string::npos;
35 }
36
IsInNoOpCompositionMode()37 bool IsInNoOpCompositionMode() {
38 const std::string mode = ::android::base::GetProperty("ro.vendor.hwcomposer.mode", "");
39 DEBUG_LOG("%s: sysprop ro.vendor.hwcomposer.mode is %s", __FUNCTION__, mode.c_str());
40 return mode == "noop";
41 }
42
IsInClientCompositionMode()43 bool IsInClientCompositionMode() {
44 const std::string mode = ::android::base::GetProperty("ro.vendor.hwcomposer.mode", "");
45 DEBUG_LOG("%s: sysprop ro.vendor.hwcomposer.mode is %s", __FUNCTION__, mode.c_str());
46 return mode == "client";
47 }
48
IsInGem5DisplayFinderMode()49 bool IsInGem5DisplayFinderMode() {
50 const std::string mode =
51 ::android::base::GetProperty("ro.vendor.hwcomposer.display_finder_mode", "");
52 DEBUG_LOG("%s: sysprop ro.vendor.hwcomposer.display_finder_mode is %s", __FUNCTION__,
53 mode.c_str());
54 return mode == "gem5";
55 }
56
IsInNoOpDisplayFinderMode()57 bool IsInNoOpDisplayFinderMode() {
58 const std::string mode =
59 ::android::base::GetProperty("ro.vendor.hwcomposer.display_finder_mode", "");
60 DEBUG_LOG("%s: sysprop ro.vendor.hwcomposer.display_finder_mode is %s", __FUNCTION__,
61 mode.c_str());
62 return mode == "noop";
63 }
64
IsInDrmDisplayFinderMode()65 bool IsInDrmDisplayFinderMode() {
66 const std::string mode =
67 ::android::base::GetProperty("ro.vendor.hwcomposer.display_finder_mode", "");
68 DEBUG_LOG("%s: sysprop ro.vendor.hwcomposer.display_finder_mode is %s", __FUNCTION__,
69 mode.c_str());
70 return mode == "drm";
71 }
72
toString(HWC3::Error error)73 std::string toString(HWC3::Error error) {
74 switch (error) {
75 case HWC3::Error::None:
76 return "None";
77 case HWC3::Error::BadConfig:
78 return "BadConfig";
79 case HWC3::Error::BadDisplay:
80 return "BadDisplay";
81 case HWC3::Error::BadLayer:
82 return "BadLayer";
83 case HWC3::Error::BadParameter:
84 return "BadParameter";
85 case HWC3::Error::NoResources:
86 return "NoResources";
87 case HWC3::Error::NotValidated:
88 return "NotValidated";
89 case HWC3::Error::Unsupported:
90 return "Unsupported";
91 case HWC3::Error::SeamlessNotAllowed:
92 return "SeamlessNotAllowed";
93 }
94 }
95
96 } // namespace aidl::android::hardware::graphics::composer3::impl
97