blob: cb9a6c0daa7934501cf4ef970ee3fd44f6ff6cee [file] [log] [blame]
Sundong Ahnd5e08f62018-12-12 20:27:28 +09001
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 Ahnd5e08f62018-12-12 20:27:28 +09007#include <configstore/Utils.h>
8
Sundong Ahn85131bd2019-02-18 15:51:53 +09009#include <cstdlib>
Sundong Ahnd5e08f62018-12-12 20:27:28 +090010#include <tuple>
11
12#include "SurfaceFlingerProperties.h"
13
14namespace android {
15namespace sysprop {
16using namespace android::hardware::configstore;
17using namespace android::hardware::configstore::V1_0;
Sundong Ahncb20cca2019-02-22 11:57:38 +090018using android::hardware::graphics::common::V1_2::Dataspace;
19using android::hardware::graphics::common::V1_2::PixelFormat;
20using android::ui::DisplayPrimaries;
Sundong Ahnd5e08f62018-12-12 20:27:28 +090021
22int64_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
31int64_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
40bool 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
49int64_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
58bool 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
67bool 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
75bool 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
83int64_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
92bool 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
101int64_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
110bool 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
118bool 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
127SurfaceFlingerProperties::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
165bool 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();
Daniel Solomon94a4df42019-03-01 16:27:39 -0800169
170 auto tmpuseColorManagementVal = tmpuseColorManagement.has_value() ? *tmpuseColorManagement :
171 defaultValue;
172 auto tmpHasHDRDisplayVal = tmpHasHDRDisplay.has_value() ? *tmpHasHDRDisplay :
173 defaultValue;
174 auto tmpHasWideColorDisplayVal = tmpHasWideColorDisplay.has_value() ? *tmpHasWideColorDisplay :
175 defaultValue;
176
177 return tmpuseColorManagementVal || tmpHasHDRDisplayVal || tmpHasWideColorDisplayVal;
Sundong Ahnd5e08f62018-12-12 20:27:28 +0900178}
179
Sundong Ahnd5e08f62018-12-12 20:27:28 +0900180int64_t default_composition_dataspace(Dataspace defaultValue) {
181 auto temp = SurfaceFlingerProperties::default_composition_dataspace();
182 if (temp.has_value()) {
183 return *temp;
184 }
Sundong Ahnd5e08f62018-12-12 20:27:28 +0900185 return static_cast<int64_t>(defaultValue);
186}
187
188int32_t default_composition_pixel_format(PixelFormat defaultValue) {
189 auto temp = SurfaceFlingerProperties::default_composition_pixel_format();
190 if (temp.has_value()) {
191 return *temp;
192 }
Sundong Ahnd5e08f62018-12-12 20:27:28 +0900193 return static_cast<int32_t>(defaultValue);
194}
195
196int64_t wcg_composition_dataspace(Dataspace defaultValue) {
197 auto temp = SurfaceFlingerProperties::wcg_composition_dataspace();
198 if (temp.has_value()) {
199 return *temp;
200 }
Sundong Ahnd5e08f62018-12-12 20:27:28 +0900201 return static_cast<int64_t>(defaultValue);
202}
203
204int32_t wcg_composition_pixel_format(PixelFormat defaultValue) {
205 auto temp = SurfaceFlingerProperties::wcg_composition_pixel_format();
206 if (temp.has_value()) {
207 return *temp;
208 }
Sundong Ahnd5e08f62018-12-12 20:27:28 +0900209 return static_cast<int32_t>(defaultValue);
210}
211
Sundong Ahn85131bd2019-02-18 15:51:53 +0900212#define DISPLAY_PRIMARY_SIZE 3
213
214constexpr float kSrgbRedX = 0.4123f;
215constexpr float kSrgbRedY = 0.2126f;
216constexpr float kSrgbRedZ = 0.0193f;
217constexpr float kSrgbGreenX = 0.3576f;
218constexpr float kSrgbGreenY = 0.7152f;
219constexpr float kSrgbGreenZ = 0.1192f;
220constexpr float kSrgbBlueX = 0.1805f;
221constexpr float kSrgbBlueY = 0.0722f;
222constexpr float kSrgbBlueZ = 0.9506f;
223constexpr float kSrgbWhiteX = 0.9505f;
224constexpr float kSrgbWhiteY = 1.0000f;
225constexpr float kSrgbWhiteZ = 1.0891f;
226
227DisplayPrimaries getDisplayNativePrimaries() {
228 auto mDisplay_primary_red = SurfaceFlingerProperties::display_primary_red();
229 auto mDisplay_primary_green = SurfaceFlingerProperties::display_primary_green();
230 auto mDisplay_primary_blue = SurfaceFlingerProperties::display_primary_blue();
231 auto mDisplay_primary_white = SurfaceFlingerProperties::display_primary_white();
232 // To avoid null point exception.
233 mDisplay_primary_red.resize(DISPLAY_PRIMARY_SIZE);
234 mDisplay_primary_green.resize(DISPLAY_PRIMARY_SIZE);
235 mDisplay_primary_blue.resize(DISPLAY_PRIMARY_SIZE);
236 mDisplay_primary_white.resize(DISPLAY_PRIMARY_SIZE);
237 DisplayPrimaries primaries =
238 {{static_cast<float>(mDisplay_primary_red[0].value_or(kSrgbRedX)),
239 static_cast<float>(mDisplay_primary_red[1].value_or(kSrgbRedY)),
240 static_cast<float>(mDisplay_primary_red[2].value_or(kSrgbRedZ))},
241 {static_cast<float>(mDisplay_primary_green[0].value_or(kSrgbGreenX)),
242 static_cast<float>(mDisplay_primary_green[1].value_or(kSrgbGreenY)),
243 static_cast<float>(mDisplay_primary_green[2].value_or(kSrgbGreenZ))},
244 {static_cast<float>(mDisplay_primary_blue[0].value_or(kSrgbBlueX)),
245 static_cast<float>(mDisplay_primary_blue[1].value_or(kSrgbBlueY)),
246 static_cast<float>(mDisplay_primary_blue[2].value_or(kSrgbBlueZ))},
247 {static_cast<float>(mDisplay_primary_white[0].value_or(kSrgbWhiteX)),
248 static_cast<float>(mDisplay_primary_white[1].value_or(kSrgbWhiteY)),
249 static_cast<float>(mDisplay_primary_white[2].value_or(kSrgbWhiteZ))}};
250
251 return primaries;
252}
253
Sundong Ahnd5e08f62018-12-12 20:27:28 +0900254} // namespace sysprop
255} // namespace android