blob: 4a69c8f0c3b3f2e468cdf132f61b761dede75f96 [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
37int64_t vsync_event_phase_offset_ns(int64_t defaultValue) {
38 auto temp = SurfaceFlingerProperties::vsync_event_phase_offset_ns();
39 if (temp.has_value()) {
40 return *temp;
41 }
42 return getInt64<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::vsyncEventPhaseOffsetNs>(
43 defaultValue);
44}
45
46int64_t vsync_sf_event_phase_offset_ns(int64_t defaultValue) {
47 auto temp = SurfaceFlingerProperties::vsync_sf_event_phase_offset_ns();
48 if (temp.has_value()) {
49 return *temp;
50 }
51 return getInt64<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::vsyncSfEventPhaseOffsetNs>(
52 defaultValue);
53}
54
55bool use_context_priority(bool defaultValue) {
56 auto temp = SurfaceFlingerProperties::use_context_priority();
57 if (temp.has_value()) {
58 return *temp;
59 }
60 return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::useContextPriority>(
61 defaultValue);
62}
63
64int64_t max_frame_buffer_acquired_buffers(int64_t defaultValue) {
65 auto temp = SurfaceFlingerProperties::max_frame_buffer_acquired_buffers();
66 if (temp.has_value()) {
67 return *temp;
68 }
69 return getInt64<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::maxFrameBufferAcquiredBuffers>(
70 defaultValue);
71}
72
Brian Lindahla13f2d52020-03-05 11:54:17 +010073int32_t max_graphics_width(int32_t defaultValue) {
74 auto temp = SurfaceFlingerProperties::max_graphics_width();
75 if (temp.has_value()) {
76 return *temp;
77 }
78 return defaultValue;
79}
80
81int32_t max_graphics_height(int32_t defaultValue) {
82 auto temp = SurfaceFlingerProperties::max_graphics_height();
83 if (temp.has_value()) {
84 return *temp;
85 }
86 return defaultValue;
87}
88
Sundong Ahnd5e08f62018-12-12 20:27:28 +090089bool has_wide_color_display(bool defaultValue) {
90 auto temp = SurfaceFlingerProperties::has_wide_color_display();
91 if (temp.has_value()) {
92 return *temp;
93 }
94 return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasWideColorDisplay>(
95 defaultValue);
96}
97
98bool running_without_sync_framework(bool defaultValue) {
99 auto temp = SurfaceFlingerProperties::running_without_sync_framework();
100 if (temp.has_value()) {
101 return !(*temp);
102 }
103 return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasSyncFramework>(defaultValue);
104}
105
106bool has_HDR_display(bool defaultValue) {
107 auto temp = SurfaceFlingerProperties::has_HDR_display();
108 if (temp.has_value()) {
109 return *temp;
110 }
111 return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasHDRDisplay>(defaultValue);
112}
113
114int64_t present_time_offset_from_vsync_ns(int64_t defaultValue) {
115 auto temp = SurfaceFlingerProperties::present_time_offset_from_vsync_ns();
116 if (temp.has_value()) {
117 return *temp;
118 }
119 return getInt64<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::presentTimeOffsetFromVSyncNs>(
120 defaultValue);
121}
122
123bool force_hwc_copy_for_virtual_displays(bool defaultValue) {
124 auto temp = SurfaceFlingerProperties::force_hwc_copy_for_virtual_displays();
125 if (temp.has_value()) {
126 return *temp;
127 }
128 return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::useHwcForRGBtoYUV>(
129 defaultValue);
130}
131
132int64_t max_virtual_display_dimension(int64_t defaultValue) {
133 auto temp = SurfaceFlingerProperties::max_virtual_display_dimension();
134 if (temp.has_value()) {
135 return *temp;
136 }
137 return getUInt64<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::maxVirtualDisplaySize>(
138 defaultValue);
139}
140
141bool use_vr_flinger(bool defaultValue) {
142 auto temp = SurfaceFlingerProperties::use_vr_flinger();
143 if (temp.has_value()) {
144 return *temp;
145 }
146 return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::useVrFlinger>(defaultValue);
147}
148
149bool start_graphics_allocator_service(bool defaultValue) {
150 auto temp = SurfaceFlingerProperties::start_graphics_allocator_service();
151 if (temp.has_value()) {
152 return *temp;
153 }
154 return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::startGraphicsAllocatorService>(
155 defaultValue);
156}
157
158SurfaceFlingerProperties::primary_display_orientation_values primary_display_orientation(
159 SurfaceFlingerProperties::primary_display_orientation_values defaultValue) {
160 auto temp = SurfaceFlingerProperties::primary_display_orientation();
161 if (temp.has_value()) {
162 return *temp;
163 }
164 auto configDefault = DisplayOrientation::ORIENTATION_0;
165 switch (defaultValue) {
166 case SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_90:
167 configDefault = DisplayOrientation::ORIENTATION_90;
168 break;
169 case SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_180:
170 configDefault = DisplayOrientation::ORIENTATION_180;
171 break;
172 case SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_270:
173 configDefault = DisplayOrientation::ORIENTATION_270;
174 break;
175 default:
176 configDefault = DisplayOrientation::ORIENTATION_0;
177 break;
178 }
179 DisplayOrientation result =
180 getDisplayOrientation<V1_1::ISurfaceFlingerConfigs,
181 &V1_1::ISurfaceFlingerConfigs::primaryDisplayOrientation>(
182 configDefault);
183 switch (result) {
184 case DisplayOrientation::ORIENTATION_90:
185 return SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_90;
186 case DisplayOrientation::ORIENTATION_180:
187 return SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_180;
188 case DisplayOrientation::ORIENTATION_270:
189 return SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_270;
190 default:
191 break;
192 }
193 return SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_0;
194}
195
196bool use_color_management(bool defaultValue) {
197 auto tmpuseColorManagement = SurfaceFlingerProperties::use_color_management();
Peiyong Lin8cabfc32019-06-14 14:25:43 -0700198 auto tmpHasHDRDisplayVal = has_HDR_display(defaultValue);
199 auto tmpHasWideColorDisplayVal = has_wide_color_display(defaultValue);
Daniel Solomon94a4df42019-03-01 16:27:39 -0800200
201 auto tmpuseColorManagementVal = tmpuseColorManagement.has_value() ? *tmpuseColorManagement :
202 defaultValue;
Daniel Solomon94a4df42019-03-01 16:27:39 -0800203
204 return tmpuseColorManagementVal || tmpHasHDRDisplayVal || tmpHasWideColorDisplayVal;
Sundong Ahnd5e08f62018-12-12 20:27:28 +0900205}
206
Sundong Ahnd5e08f62018-12-12 20:27:28 +0900207int64_t default_composition_dataspace(Dataspace defaultValue) {
208 auto temp = SurfaceFlingerProperties::default_composition_dataspace();
209 if (temp.has_value()) {
210 return *temp;
211 }
Sundong Ahnd5e08f62018-12-12 20:27:28 +0900212 return static_cast<int64_t>(defaultValue);
213}
214
215int32_t default_composition_pixel_format(PixelFormat defaultValue) {
216 auto temp = SurfaceFlingerProperties::default_composition_pixel_format();
217 if (temp.has_value()) {
218 return *temp;
219 }
Sundong Ahnd5e08f62018-12-12 20:27:28 +0900220 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 }
Sundong Ahnd5e08f62018-12-12 20:27:28 +0900228 return static_cast<int64_t>(defaultValue);
229}
230
231int32_t wcg_composition_pixel_format(PixelFormat defaultValue) {
232 auto temp = SurfaceFlingerProperties::wcg_composition_pixel_format();
233 if (temp.has_value()) {
234 return *temp;
235 }
Sundong Ahnd5e08f62018-12-12 20:27:28 +0900236 return static_cast<int32_t>(defaultValue);
237}
238
Yichi Chenda901bf2019-06-28 14:58:27 +0800239int64_t color_space_agnostic_dataspace(Dataspace defaultValue) {
240 auto temp = SurfaceFlingerProperties::color_space_agnostic_dataspace();
241 if (temp.has_value()) {
242 return *temp;
243 }
244 return static_cast<int64_t>(defaultValue);
245}
246
Ana Krulec10e02052020-02-04 17:16:10 +0000247bool refresh_rate_switching(bool defaultValue) {
Ana Krulec3f6a2062020-01-23 15:48:01 -0800248#pragma clang diagnostic push
249#pragma clang diagnostic ignored "-Wdeprecated-declarations"
Ana Krulec10e02052020-02-04 17:16:10 +0000250 auto temp = SurfaceFlingerProperties::refresh_rate_switching();
Ana Krulec3f6a2062020-01-23 15:48:01 -0800251#pragma clang diagnostic pop
Ana Krulec10e02052020-02-04 17:16:10 +0000252 if (temp.has_value()) {
Ana Krulec3f6a2062020-01-23 15:48:01 -0800253 ALOGW("Using deprecated refresh_rate_switching sysprop. Value: %d", *temp);
Ana Krulec10e02052020-02-04 17:16:10 +0000254 return *temp;
255 }
256 return defaultValue;
257}
258
Ady Abrahambe59c0d2019-03-05 13:01:13 -0800259int32_t set_idle_timer_ms(int32_t defaultValue) {
260 auto temp = SurfaceFlingerProperties::set_idle_timer_ms();
261 if (temp.has_value()) {
262 return *temp;
263 }
264 return defaultValue;
265}
266
Ady Abraham8532d012019-05-08 14:50:56 -0700267int32_t set_touch_timer_ms(int32_t defaultValue) {
268 auto temp = SurfaceFlingerProperties::set_touch_timer_ms();
269 if (temp.has_value()) {
270 return *temp;
271 }
272 return defaultValue;
273}
274
Ady Abraham6fe2c172019-07-12 12:37:57 -0700275int32_t set_display_power_timer_ms(int32_t defaultValue) {
276 auto temp = SurfaceFlingerProperties::set_display_power_timer_ms();
277 if (temp.has_value()) {
278 return *temp;
279 }
280 return defaultValue;
281}
282
Ady Abraham48da0702020-02-04 15:59:25 -0800283bool use_content_detection_for_refresh_rate(bool defaultValue) {
284#pragma clang diagnostic push
285#pragma clang diagnostic ignored "-Wdeprecated-declarations"
286 auto smart_90_deprecated = SurfaceFlingerProperties::use_smart_90_for_video();
287#pragma clang diagnostic pop
288 if (smart_90_deprecated.has_value()) {
289 ALOGW("Using deprecated use_smart_90_for_video sysprop. Value: %d", *smart_90_deprecated);
290 return *smart_90_deprecated;
291 }
292
293 auto temp = SurfaceFlingerProperties::use_content_detection_for_refresh_rate();
Ana Krulece5a06e02019-03-06 17:09:03 -0800294 if (temp.has_value()) {
295 return *temp;
296 }
297 return defaultValue;
298}
299
Peiyong Lin6a043d52019-04-01 17:18:21 -0700300bool enable_protected_contents(bool defaultValue) {
301 auto temp = SurfaceFlingerProperties::enable_protected_contents();
302 if (temp.has_value()) {
303 return *temp;
304 }
305 return defaultValue;
306}
307
Alec Mouridc28b372019-04-18 21:17:13 -0700308bool support_kernel_idle_timer(bool defaultValue) {
309 auto temp = SurfaceFlingerProperties::support_kernel_idle_timer();
310 if (temp.has_value()) {
311 return *temp;
312 }
313 return defaultValue;
314}
315
Ana Krulec3803b8d2020-02-03 16:35:46 -0800316bool use_frame_rate_api(bool defaultValue) {
317 auto temp = SurfaceFlingerProperties::use_frame_rate_api();
318 if (temp.has_value()) {
319 return *temp;
320 }
321 return defaultValue;
322}
323
John Reckac09e452021-04-07 16:35:37 -0400324bool enable_sdr_dimming(bool defaultValue) {
325 return SurfaceFlingerProperties::enable_sdr_dimming().value_or(defaultValue);
326}
327
Dan Stoza030fbc12020-02-19 15:32:01 -0800328int32_t display_update_imminent_timeout_ms(int32_t defaultValue) {
329 auto temp = SurfaceFlingerProperties::display_update_imminent_timeout_ms();
330 if (temp.has_value()) {
331 return *temp;
332 }
333 return defaultValue;
334}
335
Sundong Ahn85131bd2019-02-18 15:51:53 +0900336#define DISPLAY_PRIMARY_SIZE 3
337
338constexpr float kSrgbRedX = 0.4123f;
339constexpr float kSrgbRedY = 0.2126f;
340constexpr float kSrgbRedZ = 0.0193f;
341constexpr float kSrgbGreenX = 0.3576f;
342constexpr float kSrgbGreenY = 0.7152f;
343constexpr float kSrgbGreenZ = 0.1192f;
344constexpr float kSrgbBlueX = 0.1805f;
345constexpr float kSrgbBlueY = 0.0722f;
346constexpr float kSrgbBlueZ = 0.9506f;
347constexpr float kSrgbWhiteX = 0.9505f;
348constexpr float kSrgbWhiteY = 1.0000f;
349constexpr float kSrgbWhiteZ = 1.0891f;
350
351DisplayPrimaries getDisplayNativePrimaries() {
352 auto mDisplay_primary_red = SurfaceFlingerProperties::display_primary_red();
353 auto mDisplay_primary_green = SurfaceFlingerProperties::display_primary_green();
354 auto mDisplay_primary_blue = SurfaceFlingerProperties::display_primary_blue();
355 auto mDisplay_primary_white = SurfaceFlingerProperties::display_primary_white();
356 // To avoid null point exception.
357 mDisplay_primary_red.resize(DISPLAY_PRIMARY_SIZE);
358 mDisplay_primary_green.resize(DISPLAY_PRIMARY_SIZE);
359 mDisplay_primary_blue.resize(DISPLAY_PRIMARY_SIZE);
360 mDisplay_primary_white.resize(DISPLAY_PRIMARY_SIZE);
361 DisplayPrimaries primaries =
362 {{static_cast<float>(mDisplay_primary_red[0].value_or(kSrgbRedX)),
363 static_cast<float>(mDisplay_primary_red[1].value_or(kSrgbRedY)),
364 static_cast<float>(mDisplay_primary_red[2].value_or(kSrgbRedZ))},
365 {static_cast<float>(mDisplay_primary_green[0].value_or(kSrgbGreenX)),
366 static_cast<float>(mDisplay_primary_green[1].value_or(kSrgbGreenY)),
367 static_cast<float>(mDisplay_primary_green[2].value_or(kSrgbGreenZ))},
368 {static_cast<float>(mDisplay_primary_blue[0].value_or(kSrgbBlueX)),
369 static_cast<float>(mDisplay_primary_blue[1].value_or(kSrgbBlueY)),
370 static_cast<float>(mDisplay_primary_blue[2].value_or(kSrgbBlueZ))},
371 {static_cast<float>(mDisplay_primary_white[0].value_or(kSrgbWhiteX)),
372 static_cast<float>(mDisplay_primary_white[1].value_or(kSrgbWhiteY)),
373 static_cast<float>(mDisplay_primary_white[2].value_or(kSrgbWhiteZ))}};
374
375 return primaries;
376}
377
Marin Shalamanovf8c63722020-10-06 13:11:21 +0200378bool update_device_product_info_on_hotplug_reconnect(bool defaultValue) {
379 return SurfaceFlingerProperties::update_device_product_info_on_hotplug_reconnect().value_or(
380 defaultValue);
381}
382
Ady Abraham4899ff82021-01-06 13:53:29 -0800383bool enable_frame_rate_override(bool defaultValue) {
384 return SurfaceFlingerProperties::enable_frame_rate_override().value_or(defaultValue);
385}
386
Ady Abraham9c87def2021-02-18 11:25:28 -0800387bool enable_layer_caching(bool defaultValue) {
388 return SurfaceFlingerProperties::enable_layer_caching().value_or(defaultValue);
389}
390
Sundong Ahnd5e08f62018-12-12 20:27:28 +0900391} // namespace sysprop
392} // namespace android