blob: e15eae8c36ed1fb4881cddee29ccb9337d68face [file] [log] [blame]
Peiyong Lin6a043d52019-04-01 17:18:21 -07001/*
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 Ahnd5e08f62018-12-12 20:27:28 +090016
Sundong Ahnd5e08f62018-12-12 20:27:28 +090017#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 Ahnd5e08f62018-12-12 20:27:28 +090020#include <configstore/Utils.h>
Ady Abraham48da0702020-02-04 15:59:25 -080021#include <utils/Log.h>
Sundong Ahnd5e08f62018-12-12 20:27:28 +090022
Ana Krulec3f6a2062020-01-23 15:48:01 -080023#include <log/log.h>
Sundong Ahn85131bd2019-02-18 15:51:53 +090024#include <cstdlib>
Sundong Ahnd5e08f62018-12-12 20:27:28 +090025#include <tuple>
26
27#include "SurfaceFlingerProperties.h"
28
29namespace android {
30namespace sysprop {
31using namespace android::hardware::configstore;
32using namespace android::hardware::configstore::V1_0;
Sundong Ahncb20cca2019-02-22 11:57:38 +090033using android::hardware::graphics::common::V1_2::Dataspace;
34using android::hardware::graphics::common::V1_2::PixelFormat;
35using android::ui::DisplayPrimaries;
Sundong Ahnd5e08f62018-12-12 20:27:28 +090036
Vishnu Nair8c8db542021-09-17 19:51:45 -070037// Keep logic in sync with WindowManagerService functions that query SurfaceFlinger properties.
38// Consider exposing properties via ISurfaceComposer instead.
Sundong Ahnd5e08f62018-12-12 20:27:28 +090039int64_t vsync_event_phase_offset_ns(int64_t defaultValue) {
40 auto temp = SurfaceFlingerProperties::vsync_event_phase_offset_ns();
41 if (temp.has_value()) {
42 return *temp;
43 }
44 return getInt64<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::vsyncEventPhaseOffsetNs>(
45 defaultValue);
46}
47
48int64_t vsync_sf_event_phase_offset_ns(int64_t defaultValue) {
49 auto temp = SurfaceFlingerProperties::vsync_sf_event_phase_offset_ns();
50 if (temp.has_value()) {
51 return *temp;
52 }
53 return getInt64<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::vsyncSfEventPhaseOffsetNs>(
54 defaultValue);
55}
56
57bool use_context_priority(bool defaultValue) {
58 auto temp = SurfaceFlingerProperties::use_context_priority();
59 if (temp.has_value()) {
60 return *temp;
61 }
62 return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::useContextPriority>(
63 defaultValue);
64}
65
66int64_t max_frame_buffer_acquired_buffers(int64_t defaultValue) {
67 auto temp = SurfaceFlingerProperties::max_frame_buffer_acquired_buffers();
68 if (temp.has_value()) {
69 return *temp;
70 }
71 return getInt64<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::maxFrameBufferAcquiredBuffers>(
72 defaultValue);
73}
74
Brian Lindahla13f2d52020-03-05 11:54:17 +010075int32_t max_graphics_width(int32_t defaultValue) {
76 auto temp = SurfaceFlingerProperties::max_graphics_width();
77 if (temp.has_value()) {
78 return *temp;
79 }
80 return defaultValue;
81}
82
83int32_t max_graphics_height(int32_t defaultValue) {
84 auto temp = SurfaceFlingerProperties::max_graphics_height();
85 if (temp.has_value()) {
86 return *temp;
87 }
88 return defaultValue;
89}
90
Sundong Ahnd5e08f62018-12-12 20:27:28 +090091bool has_wide_color_display(bool defaultValue) {
92 auto temp = SurfaceFlingerProperties::has_wide_color_display();
93 if (temp.has_value()) {
94 return *temp;
95 }
96 return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasWideColorDisplay>(
97 defaultValue);
98}
99
100bool running_without_sync_framework(bool defaultValue) {
101 auto temp = SurfaceFlingerProperties::running_without_sync_framework();
102 if (temp.has_value()) {
103 return !(*temp);
104 }
105 return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasSyncFramework>(defaultValue);
106}
107
108bool has_HDR_display(bool defaultValue) {
109 auto temp = SurfaceFlingerProperties::has_HDR_display();
110 if (temp.has_value()) {
111 return *temp;
112 }
113 return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasHDRDisplay>(defaultValue);
114}
115
116int64_t present_time_offset_from_vsync_ns(int64_t defaultValue) {
117 auto temp = SurfaceFlingerProperties::present_time_offset_from_vsync_ns();
118 if (temp.has_value()) {
119 return *temp;
120 }
121 return getInt64<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::presentTimeOffsetFromVSyncNs>(
122 defaultValue);
123}
124
125bool force_hwc_copy_for_virtual_displays(bool defaultValue) {
126 auto temp = SurfaceFlingerProperties::force_hwc_copy_for_virtual_displays();
127 if (temp.has_value()) {
128 return *temp;
129 }
130 return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::useHwcForRGBtoYUV>(
131 defaultValue);
132}
133
134int64_t max_virtual_display_dimension(int64_t defaultValue) {
135 auto temp = SurfaceFlingerProperties::max_virtual_display_dimension();
136 if (temp.has_value()) {
137 return *temp;
138 }
139 return getUInt64<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::maxVirtualDisplaySize>(
140 defaultValue);
141}
142
143bool use_vr_flinger(bool defaultValue) {
144 auto temp = SurfaceFlingerProperties::use_vr_flinger();
145 if (temp.has_value()) {
146 return *temp;
147 }
148 return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::useVrFlinger>(defaultValue);
149}
150
151bool start_graphics_allocator_service(bool defaultValue) {
152 auto temp = SurfaceFlingerProperties::start_graphics_allocator_service();
153 if (temp.has_value()) {
154 return *temp;
155 }
156 return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::startGraphicsAllocatorService>(
157 defaultValue);
158}
159
160SurfaceFlingerProperties::primary_display_orientation_values primary_display_orientation(
161 SurfaceFlingerProperties::primary_display_orientation_values defaultValue) {
162 auto temp = SurfaceFlingerProperties::primary_display_orientation();
163 if (temp.has_value()) {
164 return *temp;
165 }
166 auto configDefault = DisplayOrientation::ORIENTATION_0;
167 switch (defaultValue) {
168 case SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_90:
169 configDefault = DisplayOrientation::ORIENTATION_90;
170 break;
171 case SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_180:
172 configDefault = DisplayOrientation::ORIENTATION_180;
173 break;
174 case SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_270:
175 configDefault = DisplayOrientation::ORIENTATION_270;
176 break;
177 default:
178 configDefault = DisplayOrientation::ORIENTATION_0;
179 break;
180 }
181 DisplayOrientation result =
182 getDisplayOrientation<V1_1::ISurfaceFlingerConfigs,
183 &V1_1::ISurfaceFlingerConfigs::primaryDisplayOrientation>(
184 configDefault);
185 switch (result) {
186 case DisplayOrientation::ORIENTATION_90:
187 return SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_90;
188 case DisplayOrientation::ORIENTATION_180:
189 return SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_180;
190 case DisplayOrientation::ORIENTATION_270:
191 return SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_270;
192 default:
193 break;
194 }
195 return SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_0;
196}
197
198bool use_color_management(bool defaultValue) {
199 auto tmpuseColorManagement = SurfaceFlingerProperties::use_color_management();
Peiyong Lin8cabfc32019-06-14 14:25:43 -0700200 auto tmpHasHDRDisplayVal = has_HDR_display(defaultValue);
201 auto tmpHasWideColorDisplayVal = has_wide_color_display(defaultValue);
Daniel Solomon94a4df42019-03-01 16:27:39 -0800202
203 auto tmpuseColorManagementVal = tmpuseColorManagement.has_value() ? *tmpuseColorManagement :
204 defaultValue;
Daniel Solomon94a4df42019-03-01 16:27:39 -0800205
206 return tmpuseColorManagementVal || tmpHasHDRDisplayVal || tmpHasWideColorDisplayVal;
Sundong Ahnd5e08f62018-12-12 20:27:28 +0900207}
208
Sundong Ahnd5e08f62018-12-12 20:27:28 +0900209int64_t default_composition_dataspace(Dataspace defaultValue) {
210 auto temp = SurfaceFlingerProperties::default_composition_dataspace();
211 if (temp.has_value()) {
212 return *temp;
213 }
Sundong Ahnd5e08f62018-12-12 20:27:28 +0900214 return static_cast<int64_t>(defaultValue);
215}
216
217int32_t default_composition_pixel_format(PixelFormat defaultValue) {
218 auto temp = SurfaceFlingerProperties::default_composition_pixel_format();
219 if (temp.has_value()) {
220 return *temp;
221 }
Sundong Ahnd5e08f62018-12-12 20:27:28 +0900222 return static_cast<int32_t>(defaultValue);
223}
224
225int64_t wcg_composition_dataspace(Dataspace defaultValue) {
226 auto temp = SurfaceFlingerProperties::wcg_composition_dataspace();
227 if (temp.has_value()) {
228 return *temp;
229 }
Sundong Ahnd5e08f62018-12-12 20:27:28 +0900230 return static_cast<int64_t>(defaultValue);
231}
232
233int32_t wcg_composition_pixel_format(PixelFormat defaultValue) {
234 auto temp = SurfaceFlingerProperties::wcg_composition_pixel_format();
235 if (temp.has_value()) {
236 return *temp;
237 }
Sundong Ahnd5e08f62018-12-12 20:27:28 +0900238 return static_cast<int32_t>(defaultValue);
239}
240
Yichi Chenda901bf2019-06-28 14:58:27 +0800241int64_t color_space_agnostic_dataspace(Dataspace defaultValue) {
242 auto temp = SurfaceFlingerProperties::color_space_agnostic_dataspace();
243 if (temp.has_value()) {
244 return *temp;
245 }
246 return static_cast<int64_t>(defaultValue);
247}
248
Ana Krulec10e02052020-02-04 17:16:10 +0000249bool refresh_rate_switching(bool defaultValue) {
Ana Krulec3f6a2062020-01-23 15:48:01 -0800250#pragma clang diagnostic push
251#pragma clang diagnostic ignored "-Wdeprecated-declarations"
Ana Krulec10e02052020-02-04 17:16:10 +0000252 auto temp = SurfaceFlingerProperties::refresh_rate_switching();
Ana Krulec3f6a2062020-01-23 15:48:01 -0800253#pragma clang diagnostic pop
Ana Krulec10e02052020-02-04 17:16:10 +0000254 if (temp.has_value()) {
Ana Krulec3f6a2062020-01-23 15:48:01 -0800255 ALOGW("Using deprecated refresh_rate_switching sysprop. Value: %d", *temp);
Ana Krulec10e02052020-02-04 17:16:10 +0000256 return *temp;
257 }
258 return defaultValue;
259}
260
Ady Abrahambe59c0d2019-03-05 13:01:13 -0800261int32_t set_idle_timer_ms(int32_t defaultValue) {
262 auto temp = SurfaceFlingerProperties::set_idle_timer_ms();
263 if (temp.has_value()) {
264 return *temp;
265 }
266 return defaultValue;
267}
268
Ady Abraham8532d012019-05-08 14:50:56 -0700269int32_t set_touch_timer_ms(int32_t defaultValue) {
270 auto temp = SurfaceFlingerProperties::set_touch_timer_ms();
271 if (temp.has_value()) {
272 return *temp;
273 }
274 return defaultValue;
275}
276
Ady Abraham6fe2c172019-07-12 12:37:57 -0700277int32_t set_display_power_timer_ms(int32_t defaultValue) {
278 auto temp = SurfaceFlingerProperties::set_display_power_timer_ms();
279 if (temp.has_value()) {
280 return *temp;
281 }
282 return defaultValue;
283}
284
Ady Abraham48da0702020-02-04 15:59:25 -0800285bool use_content_detection_for_refresh_rate(bool defaultValue) {
286#pragma clang diagnostic push
287#pragma clang diagnostic ignored "-Wdeprecated-declarations"
288 auto smart_90_deprecated = SurfaceFlingerProperties::use_smart_90_for_video();
289#pragma clang diagnostic pop
290 if (smart_90_deprecated.has_value()) {
291 ALOGW("Using deprecated use_smart_90_for_video sysprop. Value: %d", *smart_90_deprecated);
292 return *smart_90_deprecated;
293 }
294
295 auto temp = SurfaceFlingerProperties::use_content_detection_for_refresh_rate();
Ana Krulece5a06e02019-03-06 17:09:03 -0800296 if (temp.has_value()) {
297 return *temp;
298 }
299 return defaultValue;
300}
301
Peiyong Lin6a043d52019-04-01 17:18:21 -0700302bool enable_protected_contents(bool defaultValue) {
303 auto temp = SurfaceFlingerProperties::enable_protected_contents();
304 if (temp.has_value()) {
305 return *temp;
306 }
307 return defaultValue;
308}
309
Alec Mouridc28b372019-04-18 21:17:13 -0700310bool support_kernel_idle_timer(bool defaultValue) {
311 auto temp = SurfaceFlingerProperties::support_kernel_idle_timer();
312 if (temp.has_value()) {
313 return *temp;
314 }
315 return defaultValue;
316}
317
Ana Krulec3803b8d2020-02-03 16:35:46 -0800318bool use_frame_rate_api(bool defaultValue) {
319 auto temp = SurfaceFlingerProperties::use_frame_rate_api();
320 if (temp.has_value()) {
321 return *temp;
322 }
323 return defaultValue;
324}
325
John Reckac09e452021-04-07 16:35:37 -0400326bool enable_sdr_dimming(bool defaultValue) {
327 return SurfaceFlingerProperties::enable_sdr_dimming().value_or(defaultValue);
328}
329
Dan Stoza030fbc12020-02-19 15:32:01 -0800330int32_t display_update_imminent_timeout_ms(int32_t defaultValue) {
331 auto temp = SurfaceFlingerProperties::display_update_imminent_timeout_ms();
332 if (temp.has_value()) {
333 return *temp;
334 }
335 return defaultValue;
336}
337
Sundong Ahn85131bd2019-02-18 15:51:53 +0900338#define DISPLAY_PRIMARY_SIZE 3
339
340constexpr float kSrgbRedX = 0.4123f;
341constexpr float kSrgbRedY = 0.2126f;
342constexpr float kSrgbRedZ = 0.0193f;
343constexpr float kSrgbGreenX = 0.3576f;
344constexpr float kSrgbGreenY = 0.7152f;
345constexpr float kSrgbGreenZ = 0.1192f;
346constexpr float kSrgbBlueX = 0.1805f;
347constexpr float kSrgbBlueY = 0.0722f;
348constexpr float kSrgbBlueZ = 0.9506f;
349constexpr float kSrgbWhiteX = 0.9505f;
350constexpr float kSrgbWhiteY = 1.0000f;
351constexpr float kSrgbWhiteZ = 1.0891f;
352
353DisplayPrimaries getDisplayNativePrimaries() {
354 auto mDisplay_primary_red = SurfaceFlingerProperties::display_primary_red();
355 auto mDisplay_primary_green = SurfaceFlingerProperties::display_primary_green();
356 auto mDisplay_primary_blue = SurfaceFlingerProperties::display_primary_blue();
357 auto mDisplay_primary_white = SurfaceFlingerProperties::display_primary_white();
358 // To avoid null point exception.
359 mDisplay_primary_red.resize(DISPLAY_PRIMARY_SIZE);
360 mDisplay_primary_green.resize(DISPLAY_PRIMARY_SIZE);
361 mDisplay_primary_blue.resize(DISPLAY_PRIMARY_SIZE);
362 mDisplay_primary_white.resize(DISPLAY_PRIMARY_SIZE);
363 DisplayPrimaries primaries =
364 {{static_cast<float>(mDisplay_primary_red[0].value_or(kSrgbRedX)),
365 static_cast<float>(mDisplay_primary_red[1].value_or(kSrgbRedY)),
366 static_cast<float>(mDisplay_primary_red[2].value_or(kSrgbRedZ))},
367 {static_cast<float>(mDisplay_primary_green[0].value_or(kSrgbGreenX)),
368 static_cast<float>(mDisplay_primary_green[1].value_or(kSrgbGreenY)),
369 static_cast<float>(mDisplay_primary_green[2].value_or(kSrgbGreenZ))},
370 {static_cast<float>(mDisplay_primary_blue[0].value_or(kSrgbBlueX)),
371 static_cast<float>(mDisplay_primary_blue[1].value_or(kSrgbBlueY)),
372 static_cast<float>(mDisplay_primary_blue[2].value_or(kSrgbBlueZ))},
373 {static_cast<float>(mDisplay_primary_white[0].value_or(kSrgbWhiteX)),
374 static_cast<float>(mDisplay_primary_white[1].value_or(kSrgbWhiteY)),
375 static_cast<float>(mDisplay_primary_white[2].value_or(kSrgbWhiteZ))}};
376
377 return primaries;
378}
379
Marin Shalamanovf8c63722020-10-06 13:11:21 +0200380bool update_device_product_info_on_hotplug_reconnect(bool defaultValue) {
381 return SurfaceFlingerProperties::update_device_product_info_on_hotplug_reconnect().value_or(
382 defaultValue);
383}
384
Ady Abraham4899ff82021-01-06 13:53:29 -0800385bool enable_frame_rate_override(bool defaultValue) {
386 return SurfaceFlingerProperties::enable_frame_rate_override().value_or(defaultValue);
387}
388
Ady Abraham9c87def2021-02-18 11:25:28 -0800389bool enable_layer_caching(bool defaultValue) {
390 return SurfaceFlingerProperties::enable_layer_caching().value_or(defaultValue);
391}
392
Sundong Ahnd5e08f62018-12-12 20:27:28 +0900393} // namespace sysprop
394} // namespace android