Peiyong Lin | 6a043d5 | 2019-04-01 17:18:21 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 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 | */ |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 16 | |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 17 | #include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h> |
| 18 | #include <android/hardware/configstore/1.1/ISurfaceFlingerConfigs.h> |
| 19 | #include <android/hardware/configstore/1.1/types.h> |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 20 | #include <configstore/Utils.h> |
Ady Abraham | 48da070 | 2020-02-04 15:59:25 -0800 | [diff] [blame] | 21 | #include <utils/Log.h> |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 22 | |
Ana Krulec | 3f6a206 | 2020-01-23 15:48:01 -0800 | [diff] [blame] | 23 | #include <log/log.h> |
Sundong Ahn | 85131bd | 2019-02-18 15:51:53 +0900 | [diff] [blame] | 24 | #include <cstdlib> |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 25 | #include <tuple> |
| 26 | |
| 27 | #include "SurfaceFlingerProperties.h" |
| 28 | |
| 29 | namespace android { |
| 30 | namespace sysprop { |
| 31 | using namespace android::hardware::configstore; |
| 32 | using namespace android::hardware::configstore::V1_0; |
Sundong Ahn | cb20cca | 2019-02-22 11:57:38 +0900 | [diff] [blame] | 33 | using android::hardware::graphics::common::V1_2::Dataspace; |
| 34 | using android::hardware::graphics::common::V1_2::PixelFormat; |
| 35 | using android::ui::DisplayPrimaries; |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 36 | |
| 37 | int64_t vsync_event_phase_offset_ns(int64_t defaultValue) { |
| 38 | auto temp = SurfaceFlingerProperties::vsync_event_phase_offset_ns(); |
| 39 | if (temp.has_value()) { |
| 40 | return *temp; |
| 41 | } |
| 42 | return getInt64<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::vsyncEventPhaseOffsetNs>( |
| 43 | defaultValue); |
| 44 | } |
| 45 | |
| 46 | int64_t vsync_sf_event_phase_offset_ns(int64_t defaultValue) { |
| 47 | auto temp = SurfaceFlingerProperties::vsync_sf_event_phase_offset_ns(); |
| 48 | if (temp.has_value()) { |
| 49 | return *temp; |
| 50 | } |
| 51 | return getInt64<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::vsyncSfEventPhaseOffsetNs>( |
| 52 | defaultValue); |
| 53 | } |
| 54 | |
| 55 | bool use_context_priority(bool defaultValue) { |
| 56 | auto temp = SurfaceFlingerProperties::use_context_priority(); |
| 57 | if (temp.has_value()) { |
| 58 | return *temp; |
| 59 | } |
| 60 | return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::useContextPriority>( |
| 61 | defaultValue); |
| 62 | } |
| 63 | |
| 64 | int64_t max_frame_buffer_acquired_buffers(int64_t defaultValue) { |
| 65 | auto temp = SurfaceFlingerProperties::max_frame_buffer_acquired_buffers(); |
| 66 | if (temp.has_value()) { |
| 67 | return *temp; |
| 68 | } |
| 69 | return getInt64<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::maxFrameBufferAcquiredBuffers>( |
| 70 | defaultValue); |
| 71 | } |
| 72 | |
| 73 | bool has_wide_color_display(bool defaultValue) { |
| 74 | auto temp = SurfaceFlingerProperties::has_wide_color_display(); |
| 75 | if (temp.has_value()) { |
| 76 | return *temp; |
| 77 | } |
| 78 | return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasWideColorDisplay>( |
| 79 | defaultValue); |
| 80 | } |
| 81 | |
| 82 | bool running_without_sync_framework(bool defaultValue) { |
| 83 | auto temp = SurfaceFlingerProperties::running_without_sync_framework(); |
| 84 | if (temp.has_value()) { |
| 85 | return !(*temp); |
| 86 | } |
| 87 | return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasSyncFramework>(defaultValue); |
| 88 | } |
| 89 | |
| 90 | bool has_HDR_display(bool defaultValue) { |
| 91 | auto temp = SurfaceFlingerProperties::has_HDR_display(); |
| 92 | if (temp.has_value()) { |
| 93 | return *temp; |
| 94 | } |
| 95 | return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasHDRDisplay>(defaultValue); |
| 96 | } |
| 97 | |
| 98 | int64_t present_time_offset_from_vsync_ns(int64_t defaultValue) { |
| 99 | auto temp = SurfaceFlingerProperties::present_time_offset_from_vsync_ns(); |
| 100 | if (temp.has_value()) { |
| 101 | return *temp; |
| 102 | } |
| 103 | return getInt64<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::presentTimeOffsetFromVSyncNs>( |
| 104 | defaultValue); |
| 105 | } |
| 106 | |
| 107 | bool force_hwc_copy_for_virtual_displays(bool defaultValue) { |
| 108 | auto temp = SurfaceFlingerProperties::force_hwc_copy_for_virtual_displays(); |
| 109 | if (temp.has_value()) { |
| 110 | return *temp; |
| 111 | } |
| 112 | return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::useHwcForRGBtoYUV>( |
| 113 | defaultValue); |
| 114 | } |
| 115 | |
| 116 | int64_t max_virtual_display_dimension(int64_t defaultValue) { |
| 117 | auto temp = SurfaceFlingerProperties::max_virtual_display_dimension(); |
| 118 | if (temp.has_value()) { |
| 119 | return *temp; |
| 120 | } |
| 121 | return getUInt64<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::maxVirtualDisplaySize>( |
| 122 | defaultValue); |
| 123 | } |
| 124 | |
| 125 | bool use_vr_flinger(bool defaultValue) { |
| 126 | auto temp = SurfaceFlingerProperties::use_vr_flinger(); |
| 127 | if (temp.has_value()) { |
| 128 | return *temp; |
| 129 | } |
| 130 | return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::useVrFlinger>(defaultValue); |
| 131 | } |
| 132 | |
| 133 | bool start_graphics_allocator_service(bool defaultValue) { |
| 134 | auto temp = SurfaceFlingerProperties::start_graphics_allocator_service(); |
| 135 | if (temp.has_value()) { |
| 136 | return *temp; |
| 137 | } |
| 138 | return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::startGraphicsAllocatorService>( |
| 139 | defaultValue); |
| 140 | } |
| 141 | |
| 142 | SurfaceFlingerProperties::primary_display_orientation_values primary_display_orientation( |
| 143 | SurfaceFlingerProperties::primary_display_orientation_values defaultValue) { |
| 144 | auto temp = SurfaceFlingerProperties::primary_display_orientation(); |
| 145 | if (temp.has_value()) { |
| 146 | return *temp; |
| 147 | } |
| 148 | auto configDefault = DisplayOrientation::ORIENTATION_0; |
| 149 | switch (defaultValue) { |
| 150 | case SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_90: |
| 151 | configDefault = DisplayOrientation::ORIENTATION_90; |
| 152 | break; |
| 153 | case SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_180: |
| 154 | configDefault = DisplayOrientation::ORIENTATION_180; |
| 155 | break; |
| 156 | case SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_270: |
| 157 | configDefault = DisplayOrientation::ORIENTATION_270; |
| 158 | break; |
| 159 | default: |
| 160 | configDefault = DisplayOrientation::ORIENTATION_0; |
| 161 | break; |
| 162 | } |
| 163 | DisplayOrientation result = |
| 164 | getDisplayOrientation<V1_1::ISurfaceFlingerConfigs, |
| 165 | &V1_1::ISurfaceFlingerConfigs::primaryDisplayOrientation>( |
| 166 | configDefault); |
| 167 | switch (result) { |
| 168 | case DisplayOrientation::ORIENTATION_90: |
| 169 | return SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_90; |
| 170 | case DisplayOrientation::ORIENTATION_180: |
| 171 | return SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_180; |
| 172 | case DisplayOrientation::ORIENTATION_270: |
| 173 | return SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_270; |
| 174 | default: |
| 175 | break; |
| 176 | } |
| 177 | return SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_0; |
| 178 | } |
| 179 | |
| 180 | bool use_color_management(bool defaultValue) { |
| 181 | auto tmpuseColorManagement = SurfaceFlingerProperties::use_color_management(); |
Peiyong Lin | 8cabfc3 | 2019-06-14 14:25:43 -0700 | [diff] [blame] | 182 | auto tmpHasHDRDisplayVal = has_HDR_display(defaultValue); |
| 183 | auto tmpHasWideColorDisplayVal = has_wide_color_display(defaultValue); |
Daniel Solomon | 94a4df4 | 2019-03-01 16:27:39 -0800 | [diff] [blame] | 184 | |
| 185 | auto tmpuseColorManagementVal = tmpuseColorManagement.has_value() ? *tmpuseColorManagement : |
| 186 | defaultValue; |
Daniel Solomon | 94a4df4 | 2019-03-01 16:27:39 -0800 | [diff] [blame] | 187 | |
| 188 | return tmpuseColorManagementVal || tmpHasHDRDisplayVal || tmpHasWideColorDisplayVal; |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 189 | } |
| 190 | |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 191 | int64_t default_composition_dataspace(Dataspace defaultValue) { |
| 192 | auto temp = SurfaceFlingerProperties::default_composition_dataspace(); |
| 193 | if (temp.has_value()) { |
| 194 | return *temp; |
| 195 | } |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 196 | return static_cast<int64_t>(defaultValue); |
| 197 | } |
| 198 | |
| 199 | int32_t default_composition_pixel_format(PixelFormat defaultValue) { |
| 200 | auto temp = SurfaceFlingerProperties::default_composition_pixel_format(); |
| 201 | if (temp.has_value()) { |
| 202 | return *temp; |
| 203 | } |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 204 | return static_cast<int32_t>(defaultValue); |
| 205 | } |
| 206 | |
| 207 | int64_t wcg_composition_dataspace(Dataspace defaultValue) { |
| 208 | auto temp = SurfaceFlingerProperties::wcg_composition_dataspace(); |
| 209 | if (temp.has_value()) { |
| 210 | return *temp; |
| 211 | } |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 212 | return static_cast<int64_t>(defaultValue); |
| 213 | } |
| 214 | |
| 215 | int32_t wcg_composition_pixel_format(PixelFormat defaultValue) { |
| 216 | auto temp = SurfaceFlingerProperties::wcg_composition_pixel_format(); |
| 217 | if (temp.has_value()) { |
| 218 | return *temp; |
| 219 | } |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 220 | return static_cast<int32_t>(defaultValue); |
| 221 | } |
| 222 | |
Yichi Chen | da901bf | 2019-06-28 14:58:27 +0800 | [diff] [blame] | 223 | int64_t color_space_agnostic_dataspace(Dataspace defaultValue) { |
| 224 | auto temp = SurfaceFlingerProperties::color_space_agnostic_dataspace(); |
| 225 | if (temp.has_value()) { |
| 226 | return *temp; |
| 227 | } |
| 228 | return static_cast<int64_t>(defaultValue); |
| 229 | } |
| 230 | |
Ana Krulec | 10e0205 | 2020-02-04 17:16:10 +0000 | [diff] [blame] | 231 | bool refresh_rate_switching(bool defaultValue) { |
Ana Krulec | 3f6a206 | 2020-01-23 15:48:01 -0800 | [diff] [blame] | 232 | #pragma clang diagnostic push |
| 233 | #pragma clang diagnostic ignored "-Wdeprecated-declarations" |
Ana Krulec | 10e0205 | 2020-02-04 17:16:10 +0000 | [diff] [blame] | 234 | auto temp = SurfaceFlingerProperties::refresh_rate_switching(); |
Ana Krulec | 3f6a206 | 2020-01-23 15:48:01 -0800 | [diff] [blame] | 235 | #pragma clang diagnostic pop |
Ana Krulec | 10e0205 | 2020-02-04 17:16:10 +0000 | [diff] [blame] | 236 | if (temp.has_value()) { |
Ana Krulec | 3f6a206 | 2020-01-23 15:48:01 -0800 | [diff] [blame] | 237 | ALOGW("Using deprecated refresh_rate_switching sysprop. Value: %d", *temp); |
Ana Krulec | 10e0205 | 2020-02-04 17:16:10 +0000 | [diff] [blame] | 238 | return *temp; |
| 239 | } |
| 240 | return defaultValue; |
| 241 | } |
| 242 | |
Ady Abraham | be59c0d | 2019-03-05 13:01:13 -0800 | [diff] [blame] | 243 | int32_t set_idle_timer_ms(int32_t defaultValue) { |
| 244 | auto temp = SurfaceFlingerProperties::set_idle_timer_ms(); |
| 245 | if (temp.has_value()) { |
| 246 | return *temp; |
| 247 | } |
| 248 | return defaultValue; |
| 249 | } |
| 250 | |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 251 | int32_t set_touch_timer_ms(int32_t defaultValue) { |
| 252 | auto temp = SurfaceFlingerProperties::set_touch_timer_ms(); |
| 253 | if (temp.has_value()) { |
| 254 | return *temp; |
| 255 | } |
| 256 | return defaultValue; |
| 257 | } |
| 258 | |
Ady Abraham | 6fe2c17 | 2019-07-12 12:37:57 -0700 | [diff] [blame] | 259 | int32_t set_display_power_timer_ms(int32_t defaultValue) { |
| 260 | auto temp = SurfaceFlingerProperties::set_display_power_timer_ms(); |
| 261 | if (temp.has_value()) { |
| 262 | return *temp; |
| 263 | } |
| 264 | return defaultValue; |
| 265 | } |
| 266 | |
Ady Abraham | 48da070 | 2020-02-04 15:59:25 -0800 | [diff] [blame] | 267 | bool use_content_detection_for_refresh_rate(bool defaultValue) { |
| 268 | #pragma clang diagnostic push |
| 269 | #pragma clang diagnostic ignored "-Wdeprecated-declarations" |
| 270 | auto smart_90_deprecated = SurfaceFlingerProperties::use_smart_90_for_video(); |
| 271 | #pragma clang diagnostic pop |
| 272 | if (smart_90_deprecated.has_value()) { |
| 273 | ALOGW("Using deprecated use_smart_90_for_video sysprop. Value: %d", *smart_90_deprecated); |
| 274 | return *smart_90_deprecated; |
| 275 | } |
| 276 | |
| 277 | auto temp = SurfaceFlingerProperties::use_content_detection_for_refresh_rate(); |
Ana Krulec | e5a06e0 | 2019-03-06 17:09:03 -0800 | [diff] [blame] | 278 | if (temp.has_value()) { |
| 279 | return *temp; |
| 280 | } |
| 281 | return defaultValue; |
| 282 | } |
| 283 | |
Peiyong Lin | 6a043d5 | 2019-04-01 17:18:21 -0700 | [diff] [blame] | 284 | bool enable_protected_contents(bool defaultValue) { |
| 285 | auto temp = SurfaceFlingerProperties::enable_protected_contents(); |
| 286 | if (temp.has_value()) { |
| 287 | return *temp; |
| 288 | } |
| 289 | return defaultValue; |
| 290 | } |
| 291 | |
Alec Mouri | dc28b37 | 2019-04-18 21:17:13 -0700 | [diff] [blame] | 292 | bool support_kernel_idle_timer(bool defaultValue) { |
| 293 | auto temp = SurfaceFlingerProperties::support_kernel_idle_timer(); |
| 294 | if (temp.has_value()) { |
| 295 | return *temp; |
| 296 | } |
| 297 | return defaultValue; |
| 298 | } |
| 299 | |
Ana Krulec | 3803b8d | 2020-02-03 16:35:46 -0800 | [diff] [blame] | 300 | bool use_frame_rate_api(bool defaultValue) { |
| 301 | auto temp = SurfaceFlingerProperties::use_frame_rate_api(); |
| 302 | if (temp.has_value()) { |
| 303 | return *temp; |
| 304 | } |
| 305 | return defaultValue; |
| 306 | } |
| 307 | |
Dan Stoza | 030fbc1 | 2020-02-19 15:32:01 -0800 | [diff] [blame^] | 308 | int32_t display_update_imminent_timeout_ms(int32_t defaultValue) { |
| 309 | auto temp = SurfaceFlingerProperties::display_update_imminent_timeout_ms(); |
| 310 | if (temp.has_value()) { |
| 311 | return *temp; |
| 312 | } |
| 313 | return defaultValue; |
| 314 | } |
| 315 | |
Sundong Ahn | 85131bd | 2019-02-18 15:51:53 +0900 | [diff] [blame] | 316 | #define DISPLAY_PRIMARY_SIZE 3 |
| 317 | |
| 318 | constexpr float kSrgbRedX = 0.4123f; |
| 319 | constexpr float kSrgbRedY = 0.2126f; |
| 320 | constexpr float kSrgbRedZ = 0.0193f; |
| 321 | constexpr float kSrgbGreenX = 0.3576f; |
| 322 | constexpr float kSrgbGreenY = 0.7152f; |
| 323 | constexpr float kSrgbGreenZ = 0.1192f; |
| 324 | constexpr float kSrgbBlueX = 0.1805f; |
| 325 | constexpr float kSrgbBlueY = 0.0722f; |
| 326 | constexpr float kSrgbBlueZ = 0.9506f; |
| 327 | constexpr float kSrgbWhiteX = 0.9505f; |
| 328 | constexpr float kSrgbWhiteY = 1.0000f; |
| 329 | constexpr float kSrgbWhiteZ = 1.0891f; |
| 330 | |
| 331 | DisplayPrimaries getDisplayNativePrimaries() { |
| 332 | auto mDisplay_primary_red = SurfaceFlingerProperties::display_primary_red(); |
| 333 | auto mDisplay_primary_green = SurfaceFlingerProperties::display_primary_green(); |
| 334 | auto mDisplay_primary_blue = SurfaceFlingerProperties::display_primary_blue(); |
| 335 | auto mDisplay_primary_white = SurfaceFlingerProperties::display_primary_white(); |
| 336 | // To avoid null point exception. |
| 337 | mDisplay_primary_red.resize(DISPLAY_PRIMARY_SIZE); |
| 338 | mDisplay_primary_green.resize(DISPLAY_PRIMARY_SIZE); |
| 339 | mDisplay_primary_blue.resize(DISPLAY_PRIMARY_SIZE); |
| 340 | mDisplay_primary_white.resize(DISPLAY_PRIMARY_SIZE); |
| 341 | DisplayPrimaries primaries = |
| 342 | {{static_cast<float>(mDisplay_primary_red[0].value_or(kSrgbRedX)), |
| 343 | static_cast<float>(mDisplay_primary_red[1].value_or(kSrgbRedY)), |
| 344 | static_cast<float>(mDisplay_primary_red[2].value_or(kSrgbRedZ))}, |
| 345 | {static_cast<float>(mDisplay_primary_green[0].value_or(kSrgbGreenX)), |
| 346 | static_cast<float>(mDisplay_primary_green[1].value_or(kSrgbGreenY)), |
| 347 | static_cast<float>(mDisplay_primary_green[2].value_or(kSrgbGreenZ))}, |
| 348 | {static_cast<float>(mDisplay_primary_blue[0].value_or(kSrgbBlueX)), |
| 349 | static_cast<float>(mDisplay_primary_blue[1].value_or(kSrgbBlueY)), |
| 350 | static_cast<float>(mDisplay_primary_blue[2].value_or(kSrgbBlueZ))}, |
| 351 | {static_cast<float>(mDisplay_primary_white[0].value_or(kSrgbWhiteX)), |
| 352 | static_cast<float>(mDisplay_primary_white[1].value_or(kSrgbWhiteY)), |
| 353 | static_cast<float>(mDisplay_primary_white[2].value_or(kSrgbWhiteZ))}}; |
| 354 | |
| 355 | return primaries; |
| 356 | } |
| 357 | |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 358 | } // namespace sysprop |
| 359 | } // namespace android |