blob: 688606f0dae1ac2f9b6fd67eae0f2258236da63b [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
Sundong Ahn85131bd2019-02-18 15:51:53 +090023#include <cstdlib>
Sundong Ahnd5e08f62018-12-12 20:27:28 +090024#include <tuple>
25
26#include "SurfaceFlingerProperties.h"
27
28namespace android {
29namespace sysprop {
30using namespace android::hardware::configstore;
31using namespace android::hardware::configstore::V1_0;
Sundong Ahncb20cca2019-02-22 11:57:38 +090032using android::hardware::graphics::common::V1_2::Dataspace;
33using android::hardware::graphics::common::V1_2::PixelFormat;
34using android::ui::DisplayPrimaries;
Sundong Ahnd5e08f62018-12-12 20:27:28 +090035
36int64_t vsync_event_phase_offset_ns(int64_t defaultValue) {
37 auto temp = SurfaceFlingerProperties::vsync_event_phase_offset_ns();
38 if (temp.has_value()) {
39 return *temp;
40 }
41 return getInt64<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::vsyncEventPhaseOffsetNs>(
42 defaultValue);
43}
44
45int64_t vsync_sf_event_phase_offset_ns(int64_t defaultValue) {
46 auto temp = SurfaceFlingerProperties::vsync_sf_event_phase_offset_ns();
47 if (temp.has_value()) {
48 return *temp;
49 }
50 return getInt64<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::vsyncSfEventPhaseOffsetNs>(
51 defaultValue);
52}
53
54bool use_context_priority(bool defaultValue) {
55 auto temp = SurfaceFlingerProperties::use_context_priority();
56 if (temp.has_value()) {
57 return *temp;
58 }
59 return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::useContextPriority>(
60 defaultValue);
61}
62
63int64_t max_frame_buffer_acquired_buffers(int64_t defaultValue) {
64 auto temp = SurfaceFlingerProperties::max_frame_buffer_acquired_buffers();
65 if (temp.has_value()) {
66 return *temp;
67 }
68 return getInt64<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::maxFrameBufferAcquiredBuffers>(
69 defaultValue);
70}
71
72bool has_wide_color_display(bool defaultValue) {
73 auto temp = SurfaceFlingerProperties::has_wide_color_display();
74 if (temp.has_value()) {
75 return *temp;
76 }
77 return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasWideColorDisplay>(
78 defaultValue);
79}
80
81bool running_without_sync_framework(bool defaultValue) {
82 auto temp = SurfaceFlingerProperties::running_without_sync_framework();
83 if (temp.has_value()) {
84 return !(*temp);
85 }
86 return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasSyncFramework>(defaultValue);
87}
88
89bool has_HDR_display(bool defaultValue) {
90 auto temp = SurfaceFlingerProperties::has_HDR_display();
91 if (temp.has_value()) {
92 return *temp;
93 }
94 return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasHDRDisplay>(defaultValue);
95}
96
97int64_t present_time_offset_from_vsync_ns(int64_t defaultValue) {
98 auto temp = SurfaceFlingerProperties::present_time_offset_from_vsync_ns();
99 if (temp.has_value()) {
100 return *temp;
101 }
102 return getInt64<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::presentTimeOffsetFromVSyncNs>(
103 defaultValue);
104}
105
106bool force_hwc_copy_for_virtual_displays(bool defaultValue) {
107 auto temp = SurfaceFlingerProperties::force_hwc_copy_for_virtual_displays();
108 if (temp.has_value()) {
109 return *temp;
110 }
111 return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::useHwcForRGBtoYUV>(
112 defaultValue);
113}
114
115int64_t max_virtual_display_dimension(int64_t defaultValue) {
116 auto temp = SurfaceFlingerProperties::max_virtual_display_dimension();
117 if (temp.has_value()) {
118 return *temp;
119 }
120 return getUInt64<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::maxVirtualDisplaySize>(
121 defaultValue);
122}
123
124bool use_vr_flinger(bool defaultValue) {
125 auto temp = SurfaceFlingerProperties::use_vr_flinger();
126 if (temp.has_value()) {
127 return *temp;
128 }
129 return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::useVrFlinger>(defaultValue);
130}
131
132bool start_graphics_allocator_service(bool defaultValue) {
133 auto temp = SurfaceFlingerProperties::start_graphics_allocator_service();
134 if (temp.has_value()) {
135 return *temp;
136 }
137 return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::startGraphicsAllocatorService>(
138 defaultValue);
139}
140
141SurfaceFlingerProperties::primary_display_orientation_values primary_display_orientation(
142 SurfaceFlingerProperties::primary_display_orientation_values defaultValue) {
143 auto temp = SurfaceFlingerProperties::primary_display_orientation();
144 if (temp.has_value()) {
145 return *temp;
146 }
147 auto configDefault = DisplayOrientation::ORIENTATION_0;
148 switch (defaultValue) {
149 case SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_90:
150 configDefault = DisplayOrientation::ORIENTATION_90;
151 break;
152 case SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_180:
153 configDefault = DisplayOrientation::ORIENTATION_180;
154 break;
155 case SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_270:
156 configDefault = DisplayOrientation::ORIENTATION_270;
157 break;
158 default:
159 configDefault = DisplayOrientation::ORIENTATION_0;
160 break;
161 }
162 DisplayOrientation result =
163 getDisplayOrientation<V1_1::ISurfaceFlingerConfigs,
164 &V1_1::ISurfaceFlingerConfigs::primaryDisplayOrientation>(
165 configDefault);
166 switch (result) {
167 case DisplayOrientation::ORIENTATION_90:
168 return SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_90;
169 case DisplayOrientation::ORIENTATION_180:
170 return SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_180;
171 case DisplayOrientation::ORIENTATION_270:
172 return SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_270;
173 default:
174 break;
175 }
176 return SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_0;
177}
178
179bool use_color_management(bool defaultValue) {
180 auto tmpuseColorManagement = SurfaceFlingerProperties::use_color_management();
Peiyong Lin8cabfc32019-06-14 14:25:43 -0700181 auto tmpHasHDRDisplayVal = has_HDR_display(defaultValue);
182 auto tmpHasWideColorDisplayVal = has_wide_color_display(defaultValue);
Daniel Solomon94a4df42019-03-01 16:27:39 -0800183
184 auto tmpuseColorManagementVal = tmpuseColorManagement.has_value() ? *tmpuseColorManagement :
185 defaultValue;
Daniel Solomon94a4df42019-03-01 16:27:39 -0800186
187 return tmpuseColorManagementVal || tmpHasHDRDisplayVal || tmpHasWideColorDisplayVal;
Sundong Ahnd5e08f62018-12-12 20:27:28 +0900188}
189
Sundong Ahnd5e08f62018-12-12 20:27:28 +0900190int64_t default_composition_dataspace(Dataspace defaultValue) {
191 auto temp = SurfaceFlingerProperties::default_composition_dataspace();
192 if (temp.has_value()) {
193 return *temp;
194 }
Sundong Ahnd5e08f62018-12-12 20:27:28 +0900195 return static_cast<int64_t>(defaultValue);
196}
197
198int32_t default_composition_pixel_format(PixelFormat defaultValue) {
199 auto temp = SurfaceFlingerProperties::default_composition_pixel_format();
200 if (temp.has_value()) {
201 return *temp;
202 }
Sundong Ahnd5e08f62018-12-12 20:27:28 +0900203 return static_cast<int32_t>(defaultValue);
204}
205
206int64_t wcg_composition_dataspace(Dataspace defaultValue) {
207 auto temp = SurfaceFlingerProperties::wcg_composition_dataspace();
208 if (temp.has_value()) {
209 return *temp;
210 }
Sundong Ahnd5e08f62018-12-12 20:27:28 +0900211 return static_cast<int64_t>(defaultValue);
212}
213
214int32_t wcg_composition_pixel_format(PixelFormat defaultValue) {
215 auto temp = SurfaceFlingerProperties::wcg_composition_pixel_format();
216 if (temp.has_value()) {
217 return *temp;
218 }
Sundong Ahnd5e08f62018-12-12 20:27:28 +0900219 return static_cast<int32_t>(defaultValue);
220}
221
Yichi Chenda901bf2019-06-28 14:58:27 +0800222int64_t color_space_agnostic_dataspace(Dataspace defaultValue) {
223 auto temp = SurfaceFlingerProperties::color_space_agnostic_dataspace();
224 if (temp.has_value()) {
225 return *temp;
226 }
227 return static_cast<int64_t>(defaultValue);
228}
229
Ana Krulec10e02052020-02-04 17:16:10 +0000230bool refresh_rate_switching(bool defaultValue) {
231 auto temp = SurfaceFlingerProperties::refresh_rate_switching();
232 if (temp.has_value()) {
233 return *temp;
234 }
235 return defaultValue;
236}
237
Ady Abrahambe59c0d2019-03-05 13:01:13 -0800238int32_t set_idle_timer_ms(int32_t defaultValue) {
239 auto temp = SurfaceFlingerProperties::set_idle_timer_ms();
240 if (temp.has_value()) {
241 return *temp;
242 }
243 return defaultValue;
244}
245
Ady Abraham8532d012019-05-08 14:50:56 -0700246int32_t set_touch_timer_ms(int32_t defaultValue) {
247 auto temp = SurfaceFlingerProperties::set_touch_timer_ms();
248 if (temp.has_value()) {
249 return *temp;
250 }
251 return defaultValue;
252}
253
Ady Abraham6fe2c172019-07-12 12:37:57 -0700254int32_t set_display_power_timer_ms(int32_t defaultValue) {
255 auto temp = SurfaceFlingerProperties::set_display_power_timer_ms();
256 if (temp.has_value()) {
257 return *temp;
258 }
259 return defaultValue;
260}
261
Ady Abraham48da0702020-02-04 15:59:25 -0800262bool use_content_detection_for_refresh_rate(bool defaultValue) {
263#pragma clang diagnostic push
264#pragma clang diagnostic ignored "-Wdeprecated-declarations"
265 auto smart_90_deprecated = SurfaceFlingerProperties::use_smart_90_for_video();
266#pragma clang diagnostic pop
267 if (smart_90_deprecated.has_value()) {
268 ALOGW("Using deprecated use_smart_90_for_video sysprop. Value: %d", *smart_90_deprecated);
269 return *smart_90_deprecated;
270 }
271
272 auto temp = SurfaceFlingerProperties::use_content_detection_for_refresh_rate();
Ana Krulece5a06e02019-03-06 17:09:03 -0800273 if (temp.has_value()) {
274 return *temp;
275 }
276 return defaultValue;
277}
278
Peiyong Lin6a043d52019-04-01 17:18:21 -0700279bool enable_protected_contents(bool defaultValue) {
280 auto temp = SurfaceFlingerProperties::enable_protected_contents();
281 if (temp.has_value()) {
282 return *temp;
283 }
284 return defaultValue;
285}
286
Alec Mouridc28b372019-04-18 21:17:13 -0700287bool support_kernel_idle_timer(bool defaultValue) {
288 auto temp = SurfaceFlingerProperties::support_kernel_idle_timer();
289 if (temp.has_value()) {
290 return *temp;
291 }
292 return defaultValue;
293}
294
Sundong Ahn85131bd2019-02-18 15:51:53 +0900295#define DISPLAY_PRIMARY_SIZE 3
296
297constexpr float kSrgbRedX = 0.4123f;
298constexpr float kSrgbRedY = 0.2126f;
299constexpr float kSrgbRedZ = 0.0193f;
300constexpr float kSrgbGreenX = 0.3576f;
301constexpr float kSrgbGreenY = 0.7152f;
302constexpr float kSrgbGreenZ = 0.1192f;
303constexpr float kSrgbBlueX = 0.1805f;
304constexpr float kSrgbBlueY = 0.0722f;
305constexpr float kSrgbBlueZ = 0.9506f;
306constexpr float kSrgbWhiteX = 0.9505f;
307constexpr float kSrgbWhiteY = 1.0000f;
308constexpr float kSrgbWhiteZ = 1.0891f;
309
310DisplayPrimaries getDisplayNativePrimaries() {
311 auto mDisplay_primary_red = SurfaceFlingerProperties::display_primary_red();
312 auto mDisplay_primary_green = SurfaceFlingerProperties::display_primary_green();
313 auto mDisplay_primary_blue = SurfaceFlingerProperties::display_primary_blue();
314 auto mDisplay_primary_white = SurfaceFlingerProperties::display_primary_white();
315 // To avoid null point exception.
316 mDisplay_primary_red.resize(DISPLAY_PRIMARY_SIZE);
317 mDisplay_primary_green.resize(DISPLAY_PRIMARY_SIZE);
318 mDisplay_primary_blue.resize(DISPLAY_PRIMARY_SIZE);
319 mDisplay_primary_white.resize(DISPLAY_PRIMARY_SIZE);
320 DisplayPrimaries primaries =
321 {{static_cast<float>(mDisplay_primary_red[0].value_or(kSrgbRedX)),
322 static_cast<float>(mDisplay_primary_red[1].value_or(kSrgbRedY)),
323 static_cast<float>(mDisplay_primary_red[2].value_or(kSrgbRedZ))},
324 {static_cast<float>(mDisplay_primary_green[0].value_or(kSrgbGreenX)),
325 static_cast<float>(mDisplay_primary_green[1].value_or(kSrgbGreenY)),
326 static_cast<float>(mDisplay_primary_green[2].value_or(kSrgbGreenZ))},
327 {static_cast<float>(mDisplay_primary_blue[0].value_or(kSrgbBlueX)),
328 static_cast<float>(mDisplay_primary_blue[1].value_or(kSrgbBlueY)),
329 static_cast<float>(mDisplay_primary_blue[2].value_or(kSrgbBlueZ))},
330 {static_cast<float>(mDisplay_primary_white[0].value_or(kSrgbWhiteX)),
331 static_cast<float>(mDisplay_primary_white[1].value_or(kSrgbWhiteY)),
332 static_cast<float>(mDisplay_primary_white[2].value_or(kSrgbWhiteZ))}};
333
334 return primaries;
335}
336
Sundong Ahnd5e08f62018-12-12 20:27:28 +0900337} // namespace sysprop
338} // namespace android