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