• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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  */
16 
17 #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>
20 #include <configstore/Utils.h>
21 #include <utils/Log.h>
22 
23 #include <log/log.h>
24 #include <cstdlib>
25 #include <tuple>
26 
27 #include "SurfaceFlingerProperties.h"
28 
29 namespace android {
30 namespace sysprop {
31 using namespace android::hardware::configstore;
32 using namespace android::hardware::configstore::V1_0;
33 using android::hardware::graphics::common::V1_2::Dataspace;
34 using android::hardware::graphics::common::V1_2::PixelFormat;
35 using android::ui::DisplayPrimaries;
36 
vsync_event_phase_offset_ns(int64_t defaultValue)37 int64_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 
vsync_sf_event_phase_offset_ns(int64_t defaultValue)46 int64_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 
use_context_priority(bool defaultValue)55 bool 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 
max_frame_buffer_acquired_buffers(int64_t defaultValue)64 int64_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 
max_graphics_width(int32_t defaultValue)73 int32_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 
max_graphics_height(int32_t defaultValue)81 int32_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 
has_wide_color_display(bool defaultValue)89 bool 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 
running_without_sync_framework(bool defaultValue)98 bool 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 
has_HDR_display(bool defaultValue)106 bool 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 
present_time_offset_from_vsync_ns(int64_t defaultValue)114 int64_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 
force_hwc_copy_for_virtual_displays(bool defaultValue)123 bool 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 
max_virtual_display_dimension(int64_t defaultValue)132 int64_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 
use_vr_flinger(bool defaultValue)141 bool 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 
start_graphics_allocator_service(bool defaultValue)149 bool 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 
primary_display_orientation(SurfaceFlingerProperties::primary_display_orientation_values defaultValue)158 SurfaceFlingerProperties::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 
use_color_management(bool defaultValue)196 bool use_color_management(bool defaultValue) {
197     auto tmpuseColorManagement = SurfaceFlingerProperties::use_color_management();
198     auto tmpHasHDRDisplayVal = has_HDR_display(defaultValue);
199     auto tmpHasWideColorDisplayVal = has_wide_color_display(defaultValue);
200 
201     auto tmpuseColorManagementVal = tmpuseColorManagement.has_value() ? *tmpuseColorManagement :
202         defaultValue;
203 
204     return tmpuseColorManagementVal || tmpHasHDRDisplayVal || tmpHasWideColorDisplayVal;
205 }
206 
default_composition_dataspace(Dataspace defaultValue)207 int64_t default_composition_dataspace(Dataspace defaultValue) {
208     auto temp = SurfaceFlingerProperties::default_composition_dataspace();
209     if (temp.has_value()) {
210         return *temp;
211     }
212     return static_cast<int64_t>(defaultValue);
213 }
214 
default_composition_pixel_format(PixelFormat defaultValue)215 int32_t default_composition_pixel_format(PixelFormat defaultValue) {
216     auto temp = SurfaceFlingerProperties::default_composition_pixel_format();
217     if (temp.has_value()) {
218         return *temp;
219     }
220     return static_cast<int32_t>(defaultValue);
221 }
222 
wcg_composition_dataspace(Dataspace defaultValue)223 int64_t wcg_composition_dataspace(Dataspace defaultValue) {
224     auto temp = SurfaceFlingerProperties::wcg_composition_dataspace();
225     if (temp.has_value()) {
226         return *temp;
227     }
228     return static_cast<int64_t>(defaultValue);
229 }
230 
wcg_composition_pixel_format(PixelFormat defaultValue)231 int32_t wcg_composition_pixel_format(PixelFormat defaultValue) {
232     auto temp = SurfaceFlingerProperties::wcg_composition_pixel_format();
233     if (temp.has_value()) {
234         return *temp;
235     }
236     return static_cast<int32_t>(defaultValue);
237 }
238 
color_space_agnostic_dataspace(Dataspace defaultValue)239 int64_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 
refresh_rate_switching(bool defaultValue)247 bool refresh_rate_switching(bool defaultValue) {
248 #pragma clang diagnostic push
249 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
250     auto temp = SurfaceFlingerProperties::refresh_rate_switching();
251 #pragma clang diagnostic pop
252     if (temp.has_value()) {
253         ALOGW("Using deprecated refresh_rate_switching sysprop. Value: %d", *temp);
254         return *temp;
255     }
256     return defaultValue;
257 }
258 
set_idle_timer_ms(int32_t defaultValue)259 int32_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 
set_touch_timer_ms(int32_t defaultValue)267 int32_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 
set_display_power_timer_ms(int32_t defaultValue)275 int32_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 
use_content_detection_for_refresh_rate(bool defaultValue)283 bool 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();
294     if (temp.has_value()) {
295         return *temp;
296     }
297     return defaultValue;
298 }
299 
enable_protected_contents(bool defaultValue)300 bool 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 
support_kernel_idle_timer(bool defaultValue)308 bool 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 
use_frame_rate_api(bool defaultValue)316 bool 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 
enable_sdr_dimming(bool defaultValue)324 bool enable_sdr_dimming(bool defaultValue) {
325     return SurfaceFlingerProperties::enable_sdr_dimming().value_or(defaultValue);
326 }
327 
display_update_imminent_timeout_ms(int32_t defaultValue)328 int32_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 
336 #define DISPLAY_PRIMARY_SIZE 3
337 
338 constexpr float kSrgbRedX = 0.4123f;
339 constexpr float kSrgbRedY = 0.2126f;
340 constexpr float kSrgbRedZ = 0.0193f;
341 constexpr float kSrgbGreenX = 0.3576f;
342 constexpr float kSrgbGreenY = 0.7152f;
343 constexpr float kSrgbGreenZ = 0.1192f;
344 constexpr float kSrgbBlueX = 0.1805f;
345 constexpr float kSrgbBlueY = 0.0722f;
346 constexpr float kSrgbBlueZ = 0.9506f;
347 constexpr float kSrgbWhiteX = 0.9505f;
348 constexpr float kSrgbWhiteY = 1.0000f;
349 constexpr float kSrgbWhiteZ = 1.0891f;
350 
getDisplayNativePrimaries()351 DisplayPrimaries 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 
update_device_product_info_on_hotplug_reconnect(bool defaultValue)378 bool 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 
enable_frame_rate_override(bool defaultValue)383 bool enable_frame_rate_override(bool defaultValue) {
384     return SurfaceFlingerProperties::enable_frame_rate_override().value_or(defaultValue);
385 }
386 
enable_layer_caching(bool defaultValue)387 bool enable_layer_caching(bool defaultValue) {
388     return SurfaceFlingerProperties::enable_layer_caching().value_or(defaultValue);
389 }
390 
391 } // namespace sysprop
392 } // namespace android
393