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