blob: f3352a5a24d803301aaaf279f921e7cc2e4fa55f [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
73bool has_wide_color_display(bool defaultValue) {
74 auto temp = SurfaceFlingerProperties::has_wide_color_display();
75 if (temp.has_value()) {
76 return *temp;
77 }
78 return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasWideColorDisplay>(
79 defaultValue);
80}
81
82bool running_without_sync_framework(bool defaultValue) {
83 auto temp = SurfaceFlingerProperties::running_without_sync_framework();
84 if (temp.has_value()) {
85 return !(*temp);
86 }
87 return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasSyncFramework>(defaultValue);
88}
89
90bool has_HDR_display(bool defaultValue) {
91 auto temp = SurfaceFlingerProperties::has_HDR_display();
92 if (temp.has_value()) {
93 return *temp;
94 }
95 return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasHDRDisplay>(defaultValue);
96}
97
98int64_t present_time_offset_from_vsync_ns(int64_t defaultValue) {
99 auto temp = SurfaceFlingerProperties::present_time_offset_from_vsync_ns();
100 if (temp.has_value()) {
101 return *temp;
102 }
103 return getInt64<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::presentTimeOffsetFromVSyncNs>(
104 defaultValue);
105}
106
107bool force_hwc_copy_for_virtual_displays(bool defaultValue) {
108 auto temp = SurfaceFlingerProperties::force_hwc_copy_for_virtual_displays();
109 if (temp.has_value()) {
110 return *temp;
111 }
112 return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::useHwcForRGBtoYUV>(
113 defaultValue);
114}
115
116int64_t max_virtual_display_dimension(int64_t defaultValue) {
117 auto temp = SurfaceFlingerProperties::max_virtual_display_dimension();
118 if (temp.has_value()) {
119 return *temp;
120 }
121 return getUInt64<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::maxVirtualDisplaySize>(
122 defaultValue);
123}
124
125bool use_vr_flinger(bool defaultValue) {
126 auto temp = SurfaceFlingerProperties::use_vr_flinger();
127 if (temp.has_value()) {
128 return *temp;
129 }
130 return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::useVrFlinger>(defaultValue);
131}
132
133bool start_graphics_allocator_service(bool defaultValue) {
134 auto temp = SurfaceFlingerProperties::start_graphics_allocator_service();
135 if (temp.has_value()) {
136 return *temp;
137 }
138 return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::startGraphicsAllocatorService>(
139 defaultValue);
140}
141
142SurfaceFlingerProperties::primary_display_orientation_values primary_display_orientation(
143 SurfaceFlingerProperties::primary_display_orientation_values defaultValue) {
144 auto temp = SurfaceFlingerProperties::primary_display_orientation();
145 if (temp.has_value()) {
146 return *temp;
147 }
148 auto configDefault = DisplayOrientation::ORIENTATION_0;
149 switch (defaultValue) {
150 case SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_90:
151 configDefault = DisplayOrientation::ORIENTATION_90;
152 break;
153 case SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_180:
154 configDefault = DisplayOrientation::ORIENTATION_180;
155 break;
156 case SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_270:
157 configDefault = DisplayOrientation::ORIENTATION_270;
158 break;
159 default:
160 configDefault = DisplayOrientation::ORIENTATION_0;
161 break;
162 }
163 DisplayOrientation result =
164 getDisplayOrientation<V1_1::ISurfaceFlingerConfigs,
165 &V1_1::ISurfaceFlingerConfigs::primaryDisplayOrientation>(
166 configDefault);
167 switch (result) {
168 case DisplayOrientation::ORIENTATION_90:
169 return SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_90;
170 case DisplayOrientation::ORIENTATION_180:
171 return SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_180;
172 case DisplayOrientation::ORIENTATION_270:
173 return SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_270;
174 default:
175 break;
176 }
177 return SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_0;
178}
179
180bool use_color_management(bool defaultValue) {
181 auto tmpuseColorManagement = SurfaceFlingerProperties::use_color_management();
Peiyong Lin8cabfc32019-06-14 14:25:43 -0700182 auto tmpHasHDRDisplayVal = has_HDR_display(defaultValue);
183 auto tmpHasWideColorDisplayVal = has_wide_color_display(defaultValue);
Daniel Solomon94a4df42019-03-01 16:27:39 -0800184
185 auto tmpuseColorManagementVal = tmpuseColorManagement.has_value() ? *tmpuseColorManagement :
186 defaultValue;
Daniel Solomon94a4df42019-03-01 16:27:39 -0800187
188 return tmpuseColorManagementVal || tmpHasHDRDisplayVal || tmpHasWideColorDisplayVal;
Sundong Ahnd5e08f62018-12-12 20:27:28 +0900189}
190
Sundong Ahnd5e08f62018-12-12 20:27:28 +0900191int64_t default_composition_dataspace(Dataspace defaultValue) {
192 auto temp = SurfaceFlingerProperties::default_composition_dataspace();
193 if (temp.has_value()) {
194 return *temp;
195 }
Sundong Ahnd5e08f62018-12-12 20:27:28 +0900196 return static_cast<int64_t>(defaultValue);
197}
198
199int32_t default_composition_pixel_format(PixelFormat defaultValue) {
200 auto temp = SurfaceFlingerProperties::default_composition_pixel_format();
201 if (temp.has_value()) {
202 return *temp;
203 }
Sundong Ahnd5e08f62018-12-12 20:27:28 +0900204 return static_cast<int32_t>(defaultValue);
205}
206
207int64_t wcg_composition_dataspace(Dataspace defaultValue) {
208 auto temp = SurfaceFlingerProperties::wcg_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 wcg_composition_pixel_format(PixelFormat defaultValue) {
216 auto temp = SurfaceFlingerProperties::wcg_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
Yichi Chenda901bf2019-06-28 14:58:27 +0800223int64_t color_space_agnostic_dataspace(Dataspace defaultValue) {
224 auto temp = SurfaceFlingerProperties::color_space_agnostic_dataspace();
225 if (temp.has_value()) {
226 return *temp;
227 }
228 return static_cast<int64_t>(defaultValue);
229}
230
Ana Krulec10e02052020-02-04 17:16:10 +0000231bool refresh_rate_switching(bool defaultValue) {
Ana Krulec3f6a2062020-01-23 15:48:01 -0800232#pragma clang diagnostic push
233#pragma clang diagnostic ignored "-Wdeprecated-declarations"
Ana Krulec10e02052020-02-04 17:16:10 +0000234 auto temp = SurfaceFlingerProperties::refresh_rate_switching();
Ana Krulec3f6a2062020-01-23 15:48:01 -0800235#pragma clang diagnostic pop
Ana Krulec10e02052020-02-04 17:16:10 +0000236 if (temp.has_value()) {
Ana Krulec3f6a2062020-01-23 15:48:01 -0800237 ALOGW("Using deprecated refresh_rate_switching sysprop. Value: %d", *temp);
Ana Krulec10e02052020-02-04 17:16:10 +0000238 return *temp;
239 }
240 return defaultValue;
241}
242
Ady Abrahambe59c0d2019-03-05 13:01:13 -0800243int32_t set_idle_timer_ms(int32_t defaultValue) {
244 auto temp = SurfaceFlingerProperties::set_idle_timer_ms();
245 if (temp.has_value()) {
246 return *temp;
247 }
248 return defaultValue;
249}
250
Ady Abraham8532d012019-05-08 14:50:56 -0700251int32_t set_touch_timer_ms(int32_t defaultValue) {
252 auto temp = SurfaceFlingerProperties::set_touch_timer_ms();
253 if (temp.has_value()) {
254 return *temp;
255 }
256 return defaultValue;
257}
258
Ady Abraham6fe2c172019-07-12 12:37:57 -0700259int32_t set_display_power_timer_ms(int32_t defaultValue) {
260 auto temp = SurfaceFlingerProperties::set_display_power_timer_ms();
261 if (temp.has_value()) {
262 return *temp;
263 }
264 return defaultValue;
265}
266
Ady Abraham48da0702020-02-04 15:59:25 -0800267bool use_content_detection_for_refresh_rate(bool defaultValue) {
268#pragma clang diagnostic push
269#pragma clang diagnostic ignored "-Wdeprecated-declarations"
270 auto smart_90_deprecated = SurfaceFlingerProperties::use_smart_90_for_video();
271#pragma clang diagnostic pop
272 if (smart_90_deprecated.has_value()) {
273 ALOGW("Using deprecated use_smart_90_for_video sysprop. Value: %d", *smart_90_deprecated);
274 return *smart_90_deprecated;
275 }
276
277 auto temp = SurfaceFlingerProperties::use_content_detection_for_refresh_rate();
Ana Krulece5a06e02019-03-06 17:09:03 -0800278 if (temp.has_value()) {
279 return *temp;
280 }
281 return defaultValue;
282}
283
Peiyong Lin6a043d52019-04-01 17:18:21 -0700284bool enable_protected_contents(bool defaultValue) {
285 auto temp = SurfaceFlingerProperties::enable_protected_contents();
286 if (temp.has_value()) {
287 return *temp;
288 }
289 return defaultValue;
290}
291
Alec Mouridc28b372019-04-18 21:17:13 -0700292bool support_kernel_idle_timer(bool defaultValue) {
293 auto temp = SurfaceFlingerProperties::support_kernel_idle_timer();
294 if (temp.has_value()) {
295 return *temp;
296 }
297 return defaultValue;
298}
299
Ana Krulec3803b8d2020-02-03 16:35:46 -0800300bool use_frame_rate_api(bool defaultValue) {
301 auto temp = SurfaceFlingerProperties::use_frame_rate_api();
302 if (temp.has_value()) {
303 return *temp;
304 }
305 return defaultValue;
306}
307
Dan Stoza030fbc12020-02-19 15:32:01 -0800308int32_t display_update_imminent_timeout_ms(int32_t defaultValue) {
309 auto temp = SurfaceFlingerProperties::display_update_imminent_timeout_ms();
310 if (temp.has_value()) {
311 return *temp;
312 }
313 return defaultValue;
314}
315
Sundong Ahn85131bd2019-02-18 15:51:53 +0900316#define DISPLAY_PRIMARY_SIZE 3
317
318constexpr float kSrgbRedX = 0.4123f;
319constexpr float kSrgbRedY = 0.2126f;
320constexpr float kSrgbRedZ = 0.0193f;
321constexpr float kSrgbGreenX = 0.3576f;
322constexpr float kSrgbGreenY = 0.7152f;
323constexpr float kSrgbGreenZ = 0.1192f;
324constexpr float kSrgbBlueX = 0.1805f;
325constexpr float kSrgbBlueY = 0.0722f;
326constexpr float kSrgbBlueZ = 0.9506f;
327constexpr float kSrgbWhiteX = 0.9505f;
328constexpr float kSrgbWhiteY = 1.0000f;
329constexpr float kSrgbWhiteZ = 1.0891f;
330
331DisplayPrimaries getDisplayNativePrimaries() {
332 auto mDisplay_primary_red = SurfaceFlingerProperties::display_primary_red();
333 auto mDisplay_primary_green = SurfaceFlingerProperties::display_primary_green();
334 auto mDisplay_primary_blue = SurfaceFlingerProperties::display_primary_blue();
335 auto mDisplay_primary_white = SurfaceFlingerProperties::display_primary_white();
336 // To avoid null point exception.
337 mDisplay_primary_red.resize(DISPLAY_PRIMARY_SIZE);
338 mDisplay_primary_green.resize(DISPLAY_PRIMARY_SIZE);
339 mDisplay_primary_blue.resize(DISPLAY_PRIMARY_SIZE);
340 mDisplay_primary_white.resize(DISPLAY_PRIMARY_SIZE);
341 DisplayPrimaries primaries =
342 {{static_cast<float>(mDisplay_primary_red[0].value_or(kSrgbRedX)),
343 static_cast<float>(mDisplay_primary_red[1].value_or(kSrgbRedY)),
344 static_cast<float>(mDisplay_primary_red[2].value_or(kSrgbRedZ))},
345 {static_cast<float>(mDisplay_primary_green[0].value_or(kSrgbGreenX)),
346 static_cast<float>(mDisplay_primary_green[1].value_or(kSrgbGreenY)),
347 static_cast<float>(mDisplay_primary_green[2].value_or(kSrgbGreenZ))},
348 {static_cast<float>(mDisplay_primary_blue[0].value_or(kSrgbBlueX)),
349 static_cast<float>(mDisplay_primary_blue[1].value_or(kSrgbBlueY)),
350 static_cast<float>(mDisplay_primary_blue[2].value_or(kSrgbBlueZ))},
351 {static_cast<float>(mDisplay_primary_white[0].value_or(kSrgbWhiteX)),
352 static_cast<float>(mDisplay_primary_white[1].value_or(kSrgbWhiteY)),
353 static_cast<float>(mDisplay_primary_white[2].value_or(kSrgbWhiteZ))}};
354
355 return primaries;
356}
357
Sundong Ahnd5e08f62018-12-12 20:27:28 +0900358} // namespace sysprop
359} // namespace android