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