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