blob: 2b33ba17463d07ed8e6f9d9dc2adc7da4481564d [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>
21
Sundong Ahn85131bd2019-02-18 15:51:53 +090022#include <cstdlib>
Sundong Ahnd5e08f62018-12-12 20:27:28 +090023#include <tuple>
24
25#include "SurfaceFlingerProperties.h"
26
27namespace android {
28namespace sysprop {
29using namespace android::hardware::configstore;
30using namespace android::hardware::configstore::V1_0;
Sundong Ahncb20cca2019-02-22 11:57:38 +090031using android::hardware::graphics::common::V1_2::Dataspace;
32using android::hardware::graphics::common::V1_2::PixelFormat;
33using android::ui::DisplayPrimaries;
Sundong Ahnd5e08f62018-12-12 20:27:28 +090034
35int64_t vsync_event_phase_offset_ns(int64_t defaultValue) {
36 auto temp = SurfaceFlingerProperties::vsync_event_phase_offset_ns();
37 if (temp.has_value()) {
38 return *temp;
39 }
40 return getInt64<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::vsyncEventPhaseOffsetNs>(
41 defaultValue);
42}
43
44int64_t vsync_sf_event_phase_offset_ns(int64_t defaultValue) {
45 auto temp = SurfaceFlingerProperties::vsync_sf_event_phase_offset_ns();
46 if (temp.has_value()) {
47 return *temp;
48 }
49 return getInt64<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::vsyncSfEventPhaseOffsetNs>(
50 defaultValue);
51}
52
53bool use_context_priority(bool defaultValue) {
54 auto temp = SurfaceFlingerProperties::use_context_priority();
55 if (temp.has_value()) {
56 return *temp;
57 }
58 return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::useContextPriority>(
59 defaultValue);
60}
61
62int64_t max_frame_buffer_acquired_buffers(int64_t defaultValue) {
63 auto temp = SurfaceFlingerProperties::max_frame_buffer_acquired_buffers();
64 if (temp.has_value()) {
65 return *temp;
66 }
67 return getInt64<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::maxFrameBufferAcquiredBuffers>(
68 defaultValue);
69}
70
71bool has_wide_color_display(bool defaultValue) {
72 auto temp = SurfaceFlingerProperties::has_wide_color_display();
73 if (temp.has_value()) {
74 return *temp;
75 }
76 return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasWideColorDisplay>(
77 defaultValue);
78}
79
80bool running_without_sync_framework(bool defaultValue) {
81 auto temp = SurfaceFlingerProperties::running_without_sync_framework();
82 if (temp.has_value()) {
83 return !(*temp);
84 }
85 return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasSyncFramework>(defaultValue);
86}
87
88bool has_HDR_display(bool defaultValue) {
89 auto temp = SurfaceFlingerProperties::has_HDR_display();
90 if (temp.has_value()) {
91 return *temp;
92 }
93 return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasHDRDisplay>(defaultValue);
94}
95
96int64_t present_time_offset_from_vsync_ns(int64_t defaultValue) {
97 auto temp = SurfaceFlingerProperties::present_time_offset_from_vsync_ns();
98 if (temp.has_value()) {
99 return *temp;
100 }
101 return getInt64<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::presentTimeOffsetFromVSyncNs>(
102 defaultValue);
103}
104
105bool force_hwc_copy_for_virtual_displays(bool defaultValue) {
106 auto temp = SurfaceFlingerProperties::force_hwc_copy_for_virtual_displays();
107 if (temp.has_value()) {
108 return *temp;
109 }
110 return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::useHwcForRGBtoYUV>(
111 defaultValue);
112}
113
114int64_t max_virtual_display_dimension(int64_t defaultValue) {
115 auto temp = SurfaceFlingerProperties::max_virtual_display_dimension();
116 if (temp.has_value()) {
117 return *temp;
118 }
119 return getUInt64<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::maxVirtualDisplaySize>(
120 defaultValue);
121}
122
123bool use_vr_flinger(bool defaultValue) {
124 auto temp = SurfaceFlingerProperties::use_vr_flinger();
125 if (temp.has_value()) {
126 return *temp;
127 }
128 return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::useVrFlinger>(defaultValue);
129}
130
131bool start_graphics_allocator_service(bool defaultValue) {
132 auto temp = SurfaceFlingerProperties::start_graphics_allocator_service();
133 if (temp.has_value()) {
134 return *temp;
135 }
136 return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::startGraphicsAllocatorService>(
137 defaultValue);
138}
139
140SurfaceFlingerProperties::primary_display_orientation_values primary_display_orientation(
141 SurfaceFlingerProperties::primary_display_orientation_values defaultValue) {
142 auto temp = SurfaceFlingerProperties::primary_display_orientation();
143 if (temp.has_value()) {
144 return *temp;
145 }
146 auto configDefault = DisplayOrientation::ORIENTATION_0;
147 switch (defaultValue) {
148 case SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_90:
149 configDefault = DisplayOrientation::ORIENTATION_90;
150 break;
151 case SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_180:
152 configDefault = DisplayOrientation::ORIENTATION_180;
153 break;
154 case SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_270:
155 configDefault = DisplayOrientation::ORIENTATION_270;
156 break;
157 default:
158 configDefault = DisplayOrientation::ORIENTATION_0;
159 break;
160 }
161 DisplayOrientation result =
162 getDisplayOrientation<V1_1::ISurfaceFlingerConfigs,
163 &V1_1::ISurfaceFlingerConfigs::primaryDisplayOrientation>(
164 configDefault);
165 switch (result) {
166 case DisplayOrientation::ORIENTATION_90:
167 return SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_90;
168 case DisplayOrientation::ORIENTATION_180:
169 return SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_180;
170 case DisplayOrientation::ORIENTATION_270:
171 return SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_270;
172 default:
173 break;
174 }
175 return SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_0;
176}
177
178bool use_color_management(bool defaultValue) {
179 auto tmpuseColorManagement = SurfaceFlingerProperties::use_color_management();
Peiyong Lin8cabfc32019-06-14 14:25:43 -0700180 auto tmpHasHDRDisplayVal = has_HDR_display(defaultValue);
181 auto tmpHasWideColorDisplayVal = has_wide_color_display(defaultValue);
Daniel Solomon94a4df42019-03-01 16:27:39 -0800182
183 auto tmpuseColorManagementVal = tmpuseColorManagement.has_value() ? *tmpuseColorManagement :
184 defaultValue;
Daniel Solomon94a4df42019-03-01 16:27:39 -0800185
186 return tmpuseColorManagementVal || tmpHasHDRDisplayVal || tmpHasWideColorDisplayVal;
Sundong Ahnd5e08f62018-12-12 20:27:28 +0900187}
188
Sundong Ahnd5e08f62018-12-12 20:27:28 +0900189int64_t default_composition_dataspace(Dataspace defaultValue) {
190 auto temp = SurfaceFlingerProperties::default_composition_dataspace();
191 if (temp.has_value()) {
192 return *temp;
193 }
Sundong Ahnd5e08f62018-12-12 20:27:28 +0900194 return static_cast<int64_t>(defaultValue);
195}
196
197int32_t default_composition_pixel_format(PixelFormat defaultValue) {
198 auto temp = SurfaceFlingerProperties::default_composition_pixel_format();
199 if (temp.has_value()) {
200 return *temp;
201 }
Sundong Ahnd5e08f62018-12-12 20:27:28 +0900202 return static_cast<int32_t>(defaultValue);
203}
204
205int64_t wcg_composition_dataspace(Dataspace defaultValue) {
206 auto temp = SurfaceFlingerProperties::wcg_composition_dataspace();
207 if (temp.has_value()) {
208 return *temp;
209 }
Sundong Ahnd5e08f62018-12-12 20:27:28 +0900210 return static_cast<int64_t>(defaultValue);
211}
212
213int32_t wcg_composition_pixel_format(PixelFormat defaultValue) {
214 auto temp = SurfaceFlingerProperties::wcg_composition_pixel_format();
215 if (temp.has_value()) {
216 return *temp;
217 }
Sundong Ahnd5e08f62018-12-12 20:27:28 +0900218 return static_cast<int32_t>(defaultValue);
219}
220
Ady Abrahambe59c0d2019-03-05 13:01:13 -0800221int32_t set_idle_timer_ms(int32_t defaultValue) {
222 auto temp = SurfaceFlingerProperties::set_idle_timer_ms();
223 if (temp.has_value()) {
224 return *temp;
225 }
226 return defaultValue;
227}
228
Ady Abraham8532d012019-05-08 14:50:56 -0700229int32_t set_touch_timer_ms(int32_t defaultValue) {
230 auto temp = SurfaceFlingerProperties::set_touch_timer_ms();
231 if (temp.has_value()) {
232 return *temp;
233 }
234 return defaultValue;
235}
236
Ana Krulece5a06e02019-03-06 17:09:03 -0800237bool use_smart_90_for_video(bool defaultValue) {
238 auto temp = SurfaceFlingerProperties::use_smart_90_for_video();
239 if (temp.has_value()) {
240 return *temp;
241 }
242 return defaultValue;
243}
244
Peiyong Lin6a043d52019-04-01 17:18:21 -0700245bool enable_protected_contents(bool defaultValue) {
246 auto temp = SurfaceFlingerProperties::enable_protected_contents();
247 if (temp.has_value()) {
248 return *temp;
249 }
250 return defaultValue;
251}
252
Alec Mouridc28b372019-04-18 21:17:13 -0700253bool support_kernel_idle_timer(bool defaultValue) {
254 auto temp = SurfaceFlingerProperties::support_kernel_idle_timer();
255 if (temp.has_value()) {
256 return *temp;
257 }
258 return defaultValue;
259}
260
Sundong Ahn85131bd2019-02-18 15:51:53 +0900261#define DISPLAY_PRIMARY_SIZE 3
262
263constexpr float kSrgbRedX = 0.4123f;
264constexpr float kSrgbRedY = 0.2126f;
265constexpr float kSrgbRedZ = 0.0193f;
266constexpr float kSrgbGreenX = 0.3576f;
267constexpr float kSrgbGreenY = 0.7152f;
268constexpr float kSrgbGreenZ = 0.1192f;
269constexpr float kSrgbBlueX = 0.1805f;
270constexpr float kSrgbBlueY = 0.0722f;
271constexpr float kSrgbBlueZ = 0.9506f;
272constexpr float kSrgbWhiteX = 0.9505f;
273constexpr float kSrgbWhiteY = 1.0000f;
274constexpr float kSrgbWhiteZ = 1.0891f;
275
276DisplayPrimaries getDisplayNativePrimaries() {
277 auto mDisplay_primary_red = SurfaceFlingerProperties::display_primary_red();
278 auto mDisplay_primary_green = SurfaceFlingerProperties::display_primary_green();
279 auto mDisplay_primary_blue = SurfaceFlingerProperties::display_primary_blue();
280 auto mDisplay_primary_white = SurfaceFlingerProperties::display_primary_white();
281 // To avoid null point exception.
282 mDisplay_primary_red.resize(DISPLAY_PRIMARY_SIZE);
283 mDisplay_primary_green.resize(DISPLAY_PRIMARY_SIZE);
284 mDisplay_primary_blue.resize(DISPLAY_PRIMARY_SIZE);
285 mDisplay_primary_white.resize(DISPLAY_PRIMARY_SIZE);
286 DisplayPrimaries primaries =
287 {{static_cast<float>(mDisplay_primary_red[0].value_or(kSrgbRedX)),
288 static_cast<float>(mDisplay_primary_red[1].value_or(kSrgbRedY)),
289 static_cast<float>(mDisplay_primary_red[2].value_or(kSrgbRedZ))},
290 {static_cast<float>(mDisplay_primary_green[0].value_or(kSrgbGreenX)),
291 static_cast<float>(mDisplay_primary_green[1].value_or(kSrgbGreenY)),
292 static_cast<float>(mDisplay_primary_green[2].value_or(kSrgbGreenZ))},
293 {static_cast<float>(mDisplay_primary_blue[0].value_or(kSrgbBlueX)),
294 static_cast<float>(mDisplay_primary_blue[1].value_or(kSrgbBlueY)),
295 static_cast<float>(mDisplay_primary_blue[2].value_or(kSrgbBlueZ))},
296 {static_cast<float>(mDisplay_primary_white[0].value_or(kSrgbWhiteX)),
297 static_cast<float>(mDisplay_primary_white[1].value_or(kSrgbWhiteY)),
298 static_cast<float>(mDisplay_primary_white[2].value_or(kSrgbWhiteZ))}};
299
300 return primaries;
301}
302
Sundong Ahnd5e08f62018-12-12 20:27:28 +0900303} // namespace sysprop
304} // namespace android