blob: 0b25a4462d43f886639c59f4c990bda01949d566 [file] [log] [blame]
Lloyd Pique8117c1a2023-05-24 15:12:15 -07001/*
2 * Copyright 2023 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 <cstdlib>
18
19#include <SurfaceFlingerProperties.h>
20#include <SurfaceFlingerProperties.sysprop.h>
21#include <android-base/properties.h>
22#include <android/configuration.h>
23
24#include "SurfaceFlingerConfig.h"
25
26namespace android::surfaceflinger {
27
28using namespace std::string_literals;
29
30namespace {
31
32// TODO(b/141333600): Consolidate with DisplayMode::Builder::getDefaultDensity.
33constexpr float FALLBACK_DENSITY = ACONFIGURATION_DENSITY_TV;
34
35float getDensityFromProperty(const std::string& key, bool required) {
36 std::string value = base::GetProperty(key, ""s);
37 const float density = static_cast<float>(std::atof(value.c_str()));
38 if (density == 0.f && required) {
39 ALOGE("%s must be defined as a build property", key.c_str());
40 return FALLBACK_DENSITY;
41 }
42 return density;
43}
44
45} // namespace
46
47Config::Config() = default;
48
49Config Config::makeDefault(Factory* factory) {
50 Config cfg{};
51
52 // Note: The values set here will affect tests.
53 // To keep tests hermetic, do not set values here based on runtime values.
54
55 cfg.factory = factory;
56 cfg.hwcServiceName = "default"s;
57 cfg.pid = getpid(); // Exception to the hermetic rules. Allow the pid to be cached.
58
59 return cfg;
60}
61
62Config Config::makeProduction(Factory* factory) {
63 Config cfg = makeDefault(factory);
64
65 cfg.hwcServiceName = base::GetProperty("debug.sf.hwc_service_name"s, "default"s);
66
67 cfg.emulatedDisplayDensity = getDensityFromProperty("qemu.sf.lcd_density"s, false),
68 cfg.internalDisplayDensity =
69 getDensityFromProperty("ro.sf.lcd_density"s, cfg.emulatedDisplayDensity == 0.f),
70
71 cfg.hasSyncFramework = sysprop::running_without_sync_framework(cfg.hasSyncFramework);
72 cfg.dispSyncPresentTimeOffset =
73 sysprop::present_time_offset_from_vsync_ns(cfg.dispSyncPresentTimeOffset);
74 cfg.useHwcForRgbToYuv = sysprop::force_hwc_copy_for_virtual_displays(cfg.useHwcForRgbToYuv);
75 cfg.maxFrameBufferAcquiredBuffers =
76 sysprop::max_frame_buffer_acquired_buffers(cfg.maxFrameBufferAcquiredBuffers);
77 cfg.minAcquiredBuffers = sysprop::SurfaceFlingerProperties::min_acquired_buffers().value_or(
78 cfg.minAcquiredBuffers);
79
80 cfg.maxGraphicsWidth = std::max(static_cast<uint32_t>(sysprop::max_graphics_width(
81 static_cast<int32_t>(cfg.maxGraphicsWidth))),
82 0u);
83 cfg.maxGraphicsHeight = std::max(static_cast<uint32_t>(sysprop::max_graphics_height(
84 static_cast<int32_t>(cfg.maxGraphicsHeight))),
85 0u);
86
87 cfg.supportsWideColor = sysprop::has_wide_color_display(cfg.supportsWideColor);
88
89 cfg.defaultCompositionDataspace = static_cast<ui::Dataspace>(
90 sysprop::default_composition_dataspace(cfg.defaultCompositionDataspace));
91 cfg.defaultCompositionPixelFormat = static_cast<ui::PixelFormat>(
92 sysprop::default_composition_pixel_format(cfg.defaultCompositionPixelFormat));
93
94 cfg.wideColorGamutCompositionDataspace =
95 static_cast<ui::Dataspace>(sysprop::wcg_composition_dataspace(
96 cfg.supportsWideColor ? ui::Dataspace::DISPLAY_P3 : ui::Dataspace::V0_SRGB));
97 cfg.wideColorGamutCompositionPixelFormat = static_cast<ui::PixelFormat>(
98 sysprop::wcg_composition_pixel_format(cfg.wideColorGamutCompositionPixelFormat));
99
100 cfg.colorSpaceAgnosticDataspace = static_cast<ui::Dataspace>(
101 sysprop::color_space_agnostic_dataspace(cfg.colorSpaceAgnosticDataspace));
102
103 cfg.internalDisplayPrimaries = sysprop::getDisplayNativePrimaries();
104
105 cfg.layerCachingEnabled =
106 base::GetBoolProperty("debug.sf.enable_layer_caching"s,
107 android::sysprop::SurfaceFlingerProperties::enable_layer_caching()
108 .value_or(cfg.layerCachingEnabled));
109 cfg.useContextPriority = sysprop::use_context_priority(cfg.useContextPriority);
110
111 cfg.isUserBuild = "user"s == base::GetProperty("ro.build.type"s, "user"s);
112
113 cfg.backpressureGpuComposition = base::GetBoolProperty("debug.sf.enable_gl_backpressure"s,
114 cfg.backpressureGpuComposition);
115 cfg.supportsBlur =
116 base::GetBoolProperty("ro.surface_flinger.supports_background_blur"s, cfg.supportsBlur);
117
118 cfg.lumaSampling = base::GetBoolProperty("debug.sf.luma_sampling"s, cfg.lumaSampling);
119
120 cfg.disableClientCompositionCache =
121 base::GetBoolProperty("debug.sf.disable_client_composition_cache"s,
122 cfg.disableClientCompositionCache);
123
124 cfg.predictCompositionStrategy =
125 base::GetBoolProperty("debug.sf.predict_hwc_composition_strategy"s,
126 cfg.predictCompositionStrategy);
127
128 cfg.treat170mAsSrgb =
129 base::GetBoolProperty("debug.sf.treat_170m_as_sRGB"s, cfg.treat170mAsSrgb);
130
131 cfg.ignoreHwcPhysicalDisplayOrientation =
132 base::GetBoolProperty("debug.sf.ignore_hwc_physical_display_orientation"s,
133 cfg.ignoreHwcPhysicalDisplayOrientation);
134
135 cfg.trebleTestingOverride =
136 base::GetBoolProperty("debug.sf.treble_testing_override"s, cfg.trebleTestingOverride);
137
138 // TODO (b/270966065) Update the HWC based refresh rate overlay to support spinner
139 cfg.refreshRateOverlay.showSpinner =
140 base::GetBoolProperty("debug.sf.show_refresh_rate_overlay_spinner"s,
141 cfg.refreshRateOverlay.showSpinner);
142 cfg.refreshRateOverlay.showRenderRate =
143 base::GetBoolProperty("debug.sf.show_refresh_rate_overlay_render_rate"s,
144 cfg.refreshRateOverlay.showRenderRate);
145 cfg.refreshRateOverlay.showInMiddle =
146 base::GetBoolProperty("debug.sf.show_refresh_rate_overlay_in_middle"s,
147 cfg.refreshRateOverlay.showInMiddle);
148
149 cfg.ignoreHdrCameraLayers = sysprop::ignore_hdr_camera_layers(cfg.ignoreHdrCameraLayers);
150
151 cfg.enableTransactionTracing = base::GetBoolProperty("debug.sf.enable_transaction_tracing"s,
152 cfg.enableTransactionTracing);
153 cfg.layerLifecycleManagerEnabled =
154 base::GetBoolProperty("persist.debug.sf.enable_layer_lifecycle_manager"s,
155 cfg.layerLifecycleManagerEnabled);
156 cfg.legacyFrontEndEnabled = !cfg.layerLifecycleManagerEnabled ||
157 base::GetBoolProperty("persist.debug.sf.enable_legacy_frontend"s, false);
158
159 return cfg;
160}
161
162} // namespace android::surfaceflinger