Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 1 | |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 2 | #include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h> |
| 3 | #include <android/hardware/configstore/1.1/ISurfaceFlingerConfigs.h> |
| 4 | #include <android/hardware/configstore/1.1/types.h> |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 5 | #include <configstore/Utils.h> |
| 6 | |
Sundong Ahn | 85131bd | 2019-02-18 15:51:53 +0900 | [diff] [blame] | 7 | #include <cstdlib> |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 8 | #include <tuple> |
| 9 | |
| 10 | #include "SurfaceFlingerProperties.h" |
| 11 | |
| 12 | namespace android { |
| 13 | namespace sysprop { |
| 14 | using namespace android::hardware::configstore; |
| 15 | using namespace android::hardware::configstore::V1_0; |
Sundong Ahn | cb20cca | 2019-02-22 11:57:38 +0900 | [diff] [blame] | 16 | using android::hardware::graphics::common::V1_2::Dataspace; |
| 17 | using android::hardware::graphics::common::V1_2::PixelFormat; |
| 18 | using android::ui::DisplayPrimaries; |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 19 | |
| 20 | int64_t vsync_event_phase_offset_ns(int64_t defaultValue) { |
| 21 | auto temp = SurfaceFlingerProperties::vsync_event_phase_offset_ns(); |
| 22 | if (temp.has_value()) { |
| 23 | return *temp; |
| 24 | } |
| 25 | return getInt64<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::vsyncEventPhaseOffsetNs>( |
| 26 | defaultValue); |
| 27 | } |
| 28 | |
| 29 | int64_t vsync_sf_event_phase_offset_ns(int64_t defaultValue) { |
| 30 | auto temp = SurfaceFlingerProperties::vsync_sf_event_phase_offset_ns(); |
| 31 | if (temp.has_value()) { |
| 32 | return *temp; |
| 33 | } |
| 34 | return getInt64<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::vsyncSfEventPhaseOffsetNs>( |
| 35 | defaultValue); |
| 36 | } |
| 37 | |
| 38 | bool use_context_priority(bool defaultValue) { |
| 39 | auto temp = SurfaceFlingerProperties::use_context_priority(); |
| 40 | if (temp.has_value()) { |
| 41 | return *temp; |
| 42 | } |
| 43 | return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::useContextPriority>( |
| 44 | defaultValue); |
| 45 | } |
| 46 | |
| 47 | int64_t max_frame_buffer_acquired_buffers(int64_t defaultValue) { |
| 48 | auto temp = SurfaceFlingerProperties::max_frame_buffer_acquired_buffers(); |
| 49 | if (temp.has_value()) { |
| 50 | return *temp; |
| 51 | } |
| 52 | return getInt64<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::maxFrameBufferAcquiredBuffers>( |
| 53 | defaultValue); |
| 54 | } |
| 55 | |
| 56 | bool has_wide_color_display(bool defaultValue) { |
| 57 | auto temp = SurfaceFlingerProperties::has_wide_color_display(); |
| 58 | if (temp.has_value()) { |
| 59 | return *temp; |
| 60 | } |
| 61 | return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasWideColorDisplay>( |
| 62 | defaultValue); |
| 63 | } |
| 64 | |
| 65 | bool running_without_sync_framework(bool defaultValue) { |
| 66 | auto temp = SurfaceFlingerProperties::running_without_sync_framework(); |
| 67 | if (temp.has_value()) { |
| 68 | return !(*temp); |
| 69 | } |
| 70 | return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasSyncFramework>(defaultValue); |
| 71 | } |
| 72 | |
| 73 | bool has_HDR_display(bool defaultValue) { |
| 74 | auto temp = SurfaceFlingerProperties::has_HDR_display(); |
| 75 | if (temp.has_value()) { |
| 76 | return *temp; |
| 77 | } |
| 78 | return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasHDRDisplay>(defaultValue); |
| 79 | } |
| 80 | |
| 81 | int64_t present_time_offset_from_vsync_ns(int64_t defaultValue) { |
| 82 | auto temp = SurfaceFlingerProperties::present_time_offset_from_vsync_ns(); |
| 83 | if (temp.has_value()) { |
| 84 | return *temp; |
| 85 | } |
| 86 | return getInt64<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::presentTimeOffsetFromVSyncNs>( |
| 87 | defaultValue); |
| 88 | } |
| 89 | |
| 90 | bool force_hwc_copy_for_virtual_displays(bool defaultValue) { |
| 91 | auto temp = SurfaceFlingerProperties::force_hwc_copy_for_virtual_displays(); |
| 92 | if (temp.has_value()) { |
| 93 | return *temp; |
| 94 | } |
| 95 | return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::useHwcForRGBtoYUV>( |
| 96 | defaultValue); |
| 97 | } |
| 98 | |
| 99 | int64_t max_virtual_display_dimension(int64_t defaultValue) { |
| 100 | auto temp = SurfaceFlingerProperties::max_virtual_display_dimension(); |
| 101 | if (temp.has_value()) { |
| 102 | return *temp; |
| 103 | } |
| 104 | return getUInt64<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::maxVirtualDisplaySize>( |
| 105 | defaultValue); |
| 106 | } |
| 107 | |
| 108 | bool use_vr_flinger(bool defaultValue) { |
| 109 | auto temp = SurfaceFlingerProperties::use_vr_flinger(); |
| 110 | if (temp.has_value()) { |
| 111 | return *temp; |
| 112 | } |
| 113 | return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::useVrFlinger>(defaultValue); |
| 114 | } |
| 115 | |
| 116 | bool start_graphics_allocator_service(bool defaultValue) { |
| 117 | auto temp = SurfaceFlingerProperties::start_graphics_allocator_service(); |
| 118 | if (temp.has_value()) { |
| 119 | return *temp; |
| 120 | } |
| 121 | return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::startGraphicsAllocatorService>( |
| 122 | defaultValue); |
| 123 | } |
| 124 | |
| 125 | SurfaceFlingerProperties::primary_display_orientation_values primary_display_orientation( |
| 126 | SurfaceFlingerProperties::primary_display_orientation_values defaultValue) { |
| 127 | auto temp = SurfaceFlingerProperties::primary_display_orientation(); |
| 128 | if (temp.has_value()) { |
| 129 | return *temp; |
| 130 | } |
| 131 | auto configDefault = DisplayOrientation::ORIENTATION_0; |
| 132 | switch (defaultValue) { |
| 133 | case SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_90: |
| 134 | configDefault = DisplayOrientation::ORIENTATION_90; |
| 135 | break; |
| 136 | case SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_180: |
| 137 | configDefault = DisplayOrientation::ORIENTATION_180; |
| 138 | break; |
| 139 | case SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_270: |
| 140 | configDefault = DisplayOrientation::ORIENTATION_270; |
| 141 | break; |
| 142 | default: |
| 143 | configDefault = DisplayOrientation::ORIENTATION_0; |
| 144 | break; |
| 145 | } |
| 146 | DisplayOrientation result = |
| 147 | getDisplayOrientation<V1_1::ISurfaceFlingerConfigs, |
| 148 | &V1_1::ISurfaceFlingerConfigs::primaryDisplayOrientation>( |
| 149 | configDefault); |
| 150 | switch (result) { |
| 151 | case DisplayOrientation::ORIENTATION_90: |
| 152 | return SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_90; |
| 153 | case DisplayOrientation::ORIENTATION_180: |
| 154 | return SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_180; |
| 155 | case DisplayOrientation::ORIENTATION_270: |
| 156 | return SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_270; |
| 157 | default: |
| 158 | break; |
| 159 | } |
| 160 | return SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_0; |
| 161 | } |
| 162 | |
| 163 | bool use_color_management(bool defaultValue) { |
| 164 | auto tmpuseColorManagement = SurfaceFlingerProperties::use_color_management(); |
| 165 | auto tmpHasHDRDisplay = SurfaceFlingerProperties::has_HDR_display(); |
| 166 | auto tmpHasWideColorDisplay = SurfaceFlingerProperties::has_wide_color_display(); |
Daniel Solomon | 94a4df4 | 2019-03-01 16:27:39 -0800 | [diff] [blame] | 167 | |
| 168 | auto tmpuseColorManagementVal = tmpuseColorManagement.has_value() ? *tmpuseColorManagement : |
| 169 | defaultValue; |
| 170 | auto tmpHasHDRDisplayVal = tmpHasHDRDisplay.has_value() ? *tmpHasHDRDisplay : |
| 171 | defaultValue; |
| 172 | auto tmpHasWideColorDisplayVal = tmpHasWideColorDisplay.has_value() ? *tmpHasWideColorDisplay : |
| 173 | defaultValue; |
| 174 | |
| 175 | return tmpuseColorManagementVal || tmpHasHDRDisplayVal || tmpHasWideColorDisplayVal; |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 176 | } |
| 177 | |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 178 | int64_t default_composition_dataspace(Dataspace defaultValue) { |
| 179 | auto temp = SurfaceFlingerProperties::default_composition_dataspace(); |
| 180 | if (temp.has_value()) { |
| 181 | return *temp; |
| 182 | } |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 183 | return static_cast<int64_t>(defaultValue); |
| 184 | } |
| 185 | |
| 186 | int32_t default_composition_pixel_format(PixelFormat defaultValue) { |
| 187 | auto temp = SurfaceFlingerProperties::default_composition_pixel_format(); |
| 188 | if (temp.has_value()) { |
| 189 | return *temp; |
| 190 | } |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 191 | return static_cast<int32_t>(defaultValue); |
| 192 | } |
| 193 | |
| 194 | int64_t wcg_composition_dataspace(Dataspace defaultValue) { |
| 195 | auto temp = SurfaceFlingerProperties::wcg_composition_dataspace(); |
| 196 | if (temp.has_value()) { |
| 197 | return *temp; |
| 198 | } |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 199 | return static_cast<int64_t>(defaultValue); |
| 200 | } |
| 201 | |
| 202 | int32_t wcg_composition_pixel_format(PixelFormat defaultValue) { |
| 203 | auto temp = SurfaceFlingerProperties::wcg_composition_pixel_format(); |
| 204 | if (temp.has_value()) { |
| 205 | return *temp; |
| 206 | } |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 207 | return static_cast<int32_t>(defaultValue); |
| 208 | } |
| 209 | |
Ady Abraham | be59c0d | 2019-03-05 13:01:13 -0800 | [diff] [blame] | 210 | int32_t set_idle_timer_ms(int32_t defaultValue) { |
| 211 | auto temp = SurfaceFlingerProperties::set_idle_timer_ms(); |
| 212 | if (temp.has_value()) { |
| 213 | return *temp; |
| 214 | } |
| 215 | return defaultValue; |
| 216 | } |
| 217 | |
Ana Krulec | e5a06e0 | 2019-03-06 17:09:03 -0800 | [diff] [blame] | 218 | bool use_smart_90_for_video(bool defaultValue) { |
| 219 | auto temp = SurfaceFlingerProperties::use_smart_90_for_video(); |
| 220 | if (temp.has_value()) { |
| 221 | return *temp; |
| 222 | } |
| 223 | return defaultValue; |
| 224 | } |
| 225 | |
Sundong Ahn | 85131bd | 2019-02-18 15:51:53 +0900 | [diff] [blame] | 226 | #define DISPLAY_PRIMARY_SIZE 3 |
| 227 | |
| 228 | constexpr float kSrgbRedX = 0.4123f; |
| 229 | constexpr float kSrgbRedY = 0.2126f; |
| 230 | constexpr float kSrgbRedZ = 0.0193f; |
| 231 | constexpr float kSrgbGreenX = 0.3576f; |
| 232 | constexpr float kSrgbGreenY = 0.7152f; |
| 233 | constexpr float kSrgbGreenZ = 0.1192f; |
| 234 | constexpr float kSrgbBlueX = 0.1805f; |
| 235 | constexpr float kSrgbBlueY = 0.0722f; |
| 236 | constexpr float kSrgbBlueZ = 0.9506f; |
| 237 | constexpr float kSrgbWhiteX = 0.9505f; |
| 238 | constexpr float kSrgbWhiteY = 1.0000f; |
| 239 | constexpr float kSrgbWhiteZ = 1.0891f; |
| 240 | |
| 241 | DisplayPrimaries getDisplayNativePrimaries() { |
| 242 | auto mDisplay_primary_red = SurfaceFlingerProperties::display_primary_red(); |
| 243 | auto mDisplay_primary_green = SurfaceFlingerProperties::display_primary_green(); |
| 244 | auto mDisplay_primary_blue = SurfaceFlingerProperties::display_primary_blue(); |
| 245 | auto mDisplay_primary_white = SurfaceFlingerProperties::display_primary_white(); |
| 246 | // To avoid null point exception. |
| 247 | mDisplay_primary_red.resize(DISPLAY_PRIMARY_SIZE); |
| 248 | mDisplay_primary_green.resize(DISPLAY_PRIMARY_SIZE); |
| 249 | mDisplay_primary_blue.resize(DISPLAY_PRIMARY_SIZE); |
| 250 | mDisplay_primary_white.resize(DISPLAY_PRIMARY_SIZE); |
| 251 | DisplayPrimaries primaries = |
| 252 | {{static_cast<float>(mDisplay_primary_red[0].value_or(kSrgbRedX)), |
| 253 | static_cast<float>(mDisplay_primary_red[1].value_or(kSrgbRedY)), |
| 254 | static_cast<float>(mDisplay_primary_red[2].value_or(kSrgbRedZ))}, |
| 255 | {static_cast<float>(mDisplay_primary_green[0].value_or(kSrgbGreenX)), |
| 256 | static_cast<float>(mDisplay_primary_green[1].value_or(kSrgbGreenY)), |
| 257 | static_cast<float>(mDisplay_primary_green[2].value_or(kSrgbGreenZ))}, |
| 258 | {static_cast<float>(mDisplay_primary_blue[0].value_or(kSrgbBlueX)), |
| 259 | static_cast<float>(mDisplay_primary_blue[1].value_or(kSrgbBlueY)), |
| 260 | static_cast<float>(mDisplay_primary_blue[2].value_or(kSrgbBlueZ))}, |
| 261 | {static_cast<float>(mDisplay_primary_white[0].value_or(kSrgbWhiteX)), |
| 262 | static_cast<float>(mDisplay_primary_white[1].value_or(kSrgbWhiteY)), |
| 263 | static_cast<float>(mDisplay_primary_white[2].value_or(kSrgbWhiteZ))}}; |
| 264 | |
| 265 | return primaries; |
| 266 | } |
| 267 | |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 268 | } // namespace sysprop |
| 269 | } // namespace android |