| Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 1 |  | 
|  | 2 | #include <sysprop/SurfaceFlingerProperties.sysprop.h> | 
|  | 3 |  | 
|  | 4 | #include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h> | 
|  | 5 | #include <android/hardware/configstore/1.1/ISurfaceFlingerConfigs.h> | 
|  | 6 | #include <android/hardware/configstore/1.1/types.h> | 
|  | 7 | #include <android/hardware/configstore/1.2/ISurfaceFlingerConfigs.h> | 
|  | 8 | #include <configstore/Utils.h> | 
|  | 9 |  | 
|  | 10 | #include <tuple> | 
|  | 11 |  | 
|  | 12 | #include "SurfaceFlingerProperties.h" | 
|  | 13 |  | 
|  | 14 | namespace android { | 
|  | 15 | namespace sysprop { | 
|  | 16 | using namespace android::hardware::configstore; | 
|  | 17 | using namespace android::hardware::configstore::V1_0; | 
| Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 18 | using ::android::hardware::graphics::common::V1_2::Dataspace; | 
| Kevin DuBois | 73d0f48 | 2019-01-25 11:18:03 -0800 | [diff] [blame] | 19 | using ::android::hardware::graphics::common::V1_2::PixelFormat; | 
| Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 20 |  | 
|  | 21 | int64_t vsync_event_phase_offset_ns(int64_t defaultValue) { | 
|  | 22 | auto temp = SurfaceFlingerProperties::vsync_event_phase_offset_ns(); | 
|  | 23 | if (temp.has_value()) { | 
|  | 24 | return *temp; | 
|  | 25 | } | 
|  | 26 | return getInt64<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::vsyncEventPhaseOffsetNs>( | 
|  | 27 | defaultValue); | 
|  | 28 | } | 
|  | 29 |  | 
|  | 30 | int64_t vsync_sf_event_phase_offset_ns(int64_t defaultValue) { | 
|  | 31 | auto temp = SurfaceFlingerProperties::vsync_sf_event_phase_offset_ns(); | 
|  | 32 | if (temp.has_value()) { | 
|  | 33 | return *temp; | 
|  | 34 | } | 
|  | 35 | return getInt64<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::vsyncSfEventPhaseOffsetNs>( | 
|  | 36 | defaultValue); | 
|  | 37 | } | 
|  | 38 |  | 
|  | 39 | bool use_context_priority(bool defaultValue) { | 
|  | 40 | auto temp = SurfaceFlingerProperties::use_context_priority(); | 
|  | 41 | if (temp.has_value()) { | 
|  | 42 | return *temp; | 
|  | 43 | } | 
|  | 44 | return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::useContextPriority>( | 
|  | 45 | defaultValue); | 
|  | 46 | } | 
|  | 47 |  | 
|  | 48 | int64_t max_frame_buffer_acquired_buffers(int64_t defaultValue) { | 
|  | 49 | auto temp = SurfaceFlingerProperties::max_frame_buffer_acquired_buffers(); | 
|  | 50 | if (temp.has_value()) { | 
|  | 51 | return *temp; | 
|  | 52 | } | 
|  | 53 | return getInt64<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::maxFrameBufferAcquiredBuffers>( | 
|  | 54 | defaultValue); | 
|  | 55 | } | 
|  | 56 |  | 
|  | 57 | bool has_wide_color_display(bool defaultValue) { | 
|  | 58 | auto temp = SurfaceFlingerProperties::has_wide_color_display(); | 
|  | 59 | if (temp.has_value()) { | 
|  | 60 | return *temp; | 
|  | 61 | } | 
|  | 62 | return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasWideColorDisplay>( | 
|  | 63 | defaultValue); | 
|  | 64 | } | 
|  | 65 |  | 
|  | 66 | bool running_without_sync_framework(bool defaultValue) { | 
|  | 67 | auto temp = SurfaceFlingerProperties::running_without_sync_framework(); | 
|  | 68 | if (temp.has_value()) { | 
|  | 69 | return !(*temp); | 
|  | 70 | } | 
|  | 71 | return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasSyncFramework>(defaultValue); | 
|  | 72 | } | 
|  | 73 |  | 
|  | 74 | bool has_HDR_display(bool defaultValue) { | 
|  | 75 | auto temp = SurfaceFlingerProperties::has_HDR_display(); | 
|  | 76 | if (temp.has_value()) { | 
|  | 77 | return *temp; | 
|  | 78 | } | 
|  | 79 | return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasHDRDisplay>(defaultValue); | 
|  | 80 | } | 
|  | 81 |  | 
|  | 82 | int64_t present_time_offset_from_vsync_ns(int64_t defaultValue) { | 
|  | 83 | auto temp = SurfaceFlingerProperties::present_time_offset_from_vsync_ns(); | 
|  | 84 | if (temp.has_value()) { | 
|  | 85 | return *temp; | 
|  | 86 | } | 
|  | 87 | return getInt64<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::presentTimeOffsetFromVSyncNs>( | 
|  | 88 | defaultValue); | 
|  | 89 | } | 
|  | 90 |  | 
|  | 91 | bool force_hwc_copy_for_virtual_displays(bool defaultValue) { | 
|  | 92 | auto temp = SurfaceFlingerProperties::force_hwc_copy_for_virtual_displays(); | 
|  | 93 | if (temp.has_value()) { | 
|  | 94 | return *temp; | 
|  | 95 | } | 
|  | 96 | return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::useHwcForRGBtoYUV>( | 
|  | 97 | defaultValue); | 
|  | 98 | } | 
|  | 99 |  | 
|  | 100 | int64_t max_virtual_display_dimension(int64_t defaultValue) { | 
|  | 101 | auto temp = SurfaceFlingerProperties::max_virtual_display_dimension(); | 
|  | 102 | if (temp.has_value()) { | 
|  | 103 | return *temp; | 
|  | 104 | } | 
|  | 105 | return getUInt64<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::maxVirtualDisplaySize>( | 
|  | 106 | defaultValue); | 
|  | 107 | } | 
|  | 108 |  | 
|  | 109 | bool use_vr_flinger(bool defaultValue) { | 
|  | 110 | auto temp = SurfaceFlingerProperties::use_vr_flinger(); | 
|  | 111 | if (temp.has_value()) { | 
|  | 112 | return *temp; | 
|  | 113 | } | 
|  | 114 | return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::useVrFlinger>(defaultValue); | 
|  | 115 | } | 
|  | 116 |  | 
|  | 117 | bool start_graphics_allocator_service(bool defaultValue) { | 
|  | 118 | auto temp = SurfaceFlingerProperties::start_graphics_allocator_service(); | 
|  | 119 | if (temp.has_value()) { | 
|  | 120 | return *temp; | 
|  | 121 | } | 
|  | 122 | return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::startGraphicsAllocatorService>( | 
|  | 123 | defaultValue); | 
|  | 124 | } | 
|  | 125 |  | 
|  | 126 | SurfaceFlingerProperties::primary_display_orientation_values primary_display_orientation( | 
|  | 127 | SurfaceFlingerProperties::primary_display_orientation_values defaultValue) { | 
|  | 128 | auto temp = SurfaceFlingerProperties::primary_display_orientation(); | 
|  | 129 | if (temp.has_value()) { | 
|  | 130 | return *temp; | 
|  | 131 | } | 
|  | 132 | auto configDefault = DisplayOrientation::ORIENTATION_0; | 
|  | 133 | switch (defaultValue) { | 
|  | 134 | case SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_90: | 
|  | 135 | configDefault = DisplayOrientation::ORIENTATION_90; | 
|  | 136 | break; | 
|  | 137 | case SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_180: | 
|  | 138 | configDefault = DisplayOrientation::ORIENTATION_180; | 
|  | 139 | break; | 
|  | 140 | case SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_270: | 
|  | 141 | configDefault = DisplayOrientation::ORIENTATION_270; | 
|  | 142 | break; | 
|  | 143 | default: | 
|  | 144 | configDefault = DisplayOrientation::ORIENTATION_0; | 
|  | 145 | break; | 
|  | 146 | } | 
|  | 147 | DisplayOrientation result = | 
|  | 148 | getDisplayOrientation<V1_1::ISurfaceFlingerConfigs, | 
|  | 149 | &V1_1::ISurfaceFlingerConfigs::primaryDisplayOrientation>( | 
|  | 150 | configDefault); | 
|  | 151 | switch (result) { | 
|  | 152 | case DisplayOrientation::ORIENTATION_90: | 
|  | 153 | return SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_90; | 
|  | 154 | case DisplayOrientation::ORIENTATION_180: | 
|  | 155 | return SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_180; | 
|  | 156 | case DisplayOrientation::ORIENTATION_270: | 
|  | 157 | return SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_270; | 
|  | 158 | default: | 
|  | 159 | break; | 
|  | 160 | } | 
|  | 161 | return SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_0; | 
|  | 162 | } | 
|  | 163 |  | 
|  | 164 | bool use_color_management(bool defaultValue) { | 
|  | 165 | auto tmpuseColorManagement = SurfaceFlingerProperties::use_color_management(); | 
|  | 166 | auto tmpHasHDRDisplay = SurfaceFlingerProperties::has_HDR_display(); | 
|  | 167 | auto tmpHasWideColorDisplay = SurfaceFlingerProperties::has_wide_color_display(); | 
|  | 168 | if (tmpuseColorManagement.has_value() && tmpHasHDRDisplay.has_value() && | 
|  | 169 | tmpHasWideColorDisplay.has_value()) { | 
|  | 170 | return *tmpuseColorManagement || *tmpHasHDRDisplay || *tmpHasWideColorDisplay; | 
|  | 171 | } | 
|  | 172 | auto surfaceFlingerConfigsServiceV1_2 = ISurfaceFlingerConfigs::getService(); | 
|  | 173 | if (surfaceFlingerConfigsServiceV1_2) { | 
|  | 174 | return getBool<V1_2::ISurfaceFlingerConfigs, | 
|  | 175 | &V1_2::ISurfaceFlingerConfigs::useColorManagement>(defaultValue); | 
|  | 176 | } | 
|  | 177 | return defaultValue; | 
|  | 178 | } | 
|  | 179 |  | 
|  | 180 | auto getCompositionPreference(sp<V1_2::ISurfaceFlingerConfigs> configsServiceV1_2) { | 
|  | 181 | Dataspace defaultCompositionDataspace = Dataspace::V0_SRGB; | 
|  | 182 | PixelFormat defaultCompositionPixelFormat = PixelFormat::RGBA_8888; | 
|  | 183 | Dataspace wideColorGamutCompositionDataspace = Dataspace::V0_SRGB; | 
|  | 184 | PixelFormat wideColorGamutCompositionPixelFormat = PixelFormat::RGBA_8888; | 
|  | 185 | configsServiceV1_2->getCompositionPreference( | 
|  | 186 | [&](auto tmpDefaultDataspace, auto tmpDefaultPixelFormat, | 
|  | 187 | auto tmpWideColorGamutDataspace, auto tmpWideColorGamutPixelFormat) { | 
|  | 188 | defaultCompositionDataspace = tmpDefaultDataspace; | 
|  | 189 | defaultCompositionPixelFormat = tmpDefaultPixelFormat; | 
|  | 190 | wideColorGamutCompositionDataspace = tmpWideColorGamutDataspace; | 
|  | 191 | wideColorGamutCompositionPixelFormat = tmpWideColorGamutPixelFormat; | 
|  | 192 | }); | 
|  | 193 | return std::tuple(defaultCompositionDataspace, defaultCompositionPixelFormat, | 
|  | 194 | wideColorGamutCompositionDataspace, wideColorGamutCompositionPixelFormat); | 
|  | 195 | } | 
|  | 196 |  | 
|  | 197 | int64_t default_composition_dataspace(Dataspace defaultValue) { | 
|  | 198 | auto temp = SurfaceFlingerProperties::default_composition_dataspace(); | 
|  | 199 | if (temp.has_value()) { | 
|  | 200 | return *temp; | 
|  | 201 | } | 
|  | 202 | auto configsServiceV1_2 = V1_2::ISurfaceFlingerConfigs::getService(); | 
|  | 203 | if (configsServiceV1_2) { | 
|  | 204 | return static_cast<int64_t>(get<0>(getCompositionPreference(configsServiceV1_2))); | 
|  | 205 | } | 
|  | 206 | return static_cast<int64_t>(defaultValue); | 
|  | 207 | } | 
|  | 208 |  | 
|  | 209 | int32_t default_composition_pixel_format(PixelFormat defaultValue) { | 
|  | 210 | auto temp = SurfaceFlingerProperties::default_composition_pixel_format(); | 
|  | 211 | if (temp.has_value()) { | 
|  | 212 | return *temp; | 
|  | 213 | } | 
|  | 214 | auto configsServiceV1_2 = V1_2::ISurfaceFlingerConfigs::getService(); | 
|  | 215 | if (configsServiceV1_2) { | 
|  | 216 | return static_cast<int32_t>(get<1>(getCompositionPreference(configsServiceV1_2))); | 
|  | 217 | } | 
|  | 218 | return static_cast<int32_t>(defaultValue); | 
|  | 219 | } | 
|  | 220 |  | 
|  | 221 | int64_t wcg_composition_dataspace(Dataspace defaultValue) { | 
|  | 222 | auto temp = SurfaceFlingerProperties::wcg_composition_dataspace(); | 
|  | 223 | if (temp.has_value()) { | 
|  | 224 | return *temp; | 
|  | 225 | } | 
|  | 226 | auto configsServiceV1_2 = V1_2::ISurfaceFlingerConfigs::getService(); | 
|  | 227 | if (configsServiceV1_2) { | 
|  | 228 | return static_cast<int64_t>(get<2>(getCompositionPreference(configsServiceV1_2))); | 
|  | 229 | } | 
|  | 230 | return static_cast<int64_t>(defaultValue); | 
|  | 231 | } | 
|  | 232 |  | 
|  | 233 | int32_t wcg_composition_pixel_format(PixelFormat defaultValue) { | 
|  | 234 | auto temp = SurfaceFlingerProperties::wcg_composition_pixel_format(); | 
|  | 235 | if (temp.has_value()) { | 
|  | 236 | return *temp; | 
|  | 237 | } | 
|  | 238 | auto configsServiceV1_2 = V1_2::ISurfaceFlingerConfigs::getService(); | 
|  | 239 | if (configsServiceV1_2) { | 
|  | 240 | return static_cast<int32_t>(get<3>(getCompositionPreference(configsServiceV1_2))); | 
|  | 241 | } | 
|  | 242 | return static_cast<int32_t>(defaultValue); | 
|  | 243 | } | 
|  | 244 |  | 
|  | 245 | } // namespace sysprop | 
|  | 246 | } // namespace android |