SF: Introduce struct surfaceflinger::Config

This pulls out all the individual configuration constants read by
SurfaceFlinger in its constructor, and moves them to a new
surfaceflinger::Config structure which is passed to the constructor.

All the initialization is the functionally the same, a few values turned
out to not be used, so were removed (mMaxGraphicBufferProducerListSize,
mGraphicBufferProducerListSizeLogThreshold). Otherwise all properties
read for the new structure consistently use android-base/properties.h to
read them.

To keep the argument count down, the SurfaceFlinger factory argument to
the constructor was moved to be stored in the new Config structure.

As a result of the change, SurfaceFlinger now only has one constructor.
The tests were using the other constructor (passing
SurfaceFlinger::skipInitiailization) to skip over the property reads to
help ensure a hermetic configuration of SurfaceFlinger. The tests can
now instead create create a minimally configured Config structure, and
pass that the structure.

The other changes were then to switch over to using the values in the
Config structure, both internally to SurfaceFlinger, as well as in other
files including Layer.cpp and DisplayDevice.cpp. In some cases, those
changes required altering the arguments to the function being called to
obtain the values, since originally some of the values where static
member data in SurfaceFlinger.

There were similar changes required for the tests and the fuzzers, to switch over,
including how some tests mutated the configuration values so that they
overall coverage was the same.

No new tests/fuzzing was added, though it should now be easier to extend
coverage.

Test: atest libsurfaceflinger_unittest
Bug: None

Change-Id: I8dc3c2317a92b256e58ec45190e24463032c2f8e
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index fd05016..31df2df 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -63,6 +63,7 @@
 #include <scheduler/interface/ICompositor.h>
 #include <ui/FenceResult.h>
 
+#include "Client.h"
 #include "Display/PhysicalDisplay.h"
 #include "DisplayDevice.h"
 #include "DisplayHardware/HWC2.h"
@@ -81,6 +82,7 @@
 #include "Scheduler/RefreshRateSelector.h"
 #include "Scheduler/RefreshRateStats.h"
 #include "Scheduler/Scheduler.h"
+#include "SurfaceFlingerConfig.h"
 #include "SurfaceFlingerFactory.h"
 #include "ThreadContext.h"
 #include "Tracing/LayerTracing.h"
@@ -107,7 +109,6 @@
 
 #include <aidl/android/hardware/graphics/common/DisplayDecorationSupport.h>
 #include <aidl/android/hardware/graphics/composer3/RefreshRateChangedDebugData.h>
-#include "Client.h"
 
 using namespace android::surfaceflinger;
 
@@ -196,10 +197,7 @@
                        private ICompositor,
                        private scheduler::ISchedulerCallback {
 public:
-    struct SkipInitializationTag {};
-
-    SurfaceFlinger(surfaceflinger::Factory&, SkipInitializationTag) ANDROID_API;
-    explicit SurfaceFlinger(surfaceflinger::Factory&) ANDROID_API;
+    explicit SurfaceFlinger(surfaceflinger::Config&) ANDROID_API;
 
     // set main thread scheduling policy
     static status_t setSchedFifo(bool enabled) ANDROID_API;
@@ -209,51 +207,9 @@
 
     static char const* getServiceName() ANDROID_API { return "SurfaceFlinger"; }
 
-    // If fences from sync Framework are supported.
-    static bool hasSyncFramework;
-
-    // The offset in nanoseconds to use when VsyncController timestamps present fence
-    // signaling time.
-    static int64_t dispSyncPresentTimeOffset;
-
-    // Some hardware can do RGB->YUV conversion more efficiently in hardware
-    // controlled by HWC than in hardware controlled by the video encoder.
-    // This instruct VirtualDisplaySurface to use HWC for such conversion on
-    // GL composition.
-    static bool useHwcForRgbToYuv;
-
-    // Controls the number of buffers SurfaceFlinger will allocate for use in
-    // FramebufferSurface
-    static int64_t maxFrameBufferAcquiredBuffers;
-
-    // Controls the minimum acquired buffers SurfaceFlinger will suggest via
-    // ISurfaceComposer.getMaxAcquiredBufferCount().
-    static int64_t minAcquiredBuffers;
-
-    // Controls the maximum width and height in pixels that the graphics pipeline can support for
-    // GPU fallback composition. For example, 8k devices with 4k GPUs, or 4k devices with 2k GPUs.
-    static uint32_t maxGraphicsWidth;
-    static uint32_t maxGraphicsHeight;
-
     // Indicate if device wants color management on its display.
     static const constexpr bool useColorManagement = true;
 
-    static bool useContextPriority;
-
-    // The data space and pixel format that SurfaceFlinger expects hardware composer
-    // to composite efficiently. Meaning under most scenarios, hardware composer
-    // will accept layers with the data space and pixel format.
-    static ui::Dataspace defaultCompositionDataspace;
-    static ui::PixelFormat defaultCompositionPixelFormat;
-
-    // The data space and pixel format that SurfaceFlinger expects hardware composer
-    // to composite efficiently for wide color gamut surfaces. Meaning under most scenarios,
-    // hardware composer will accept layers with the data space and pixel format.
-    static ui::Dataspace wideColorGamutCompositionDataspace;
-    static ui::PixelFormat wideColorGamutCompositionPixelFormat;
-
-    static constexpr SkipInitializationTag SkipInitialization;
-
     static LatchUnsignaledConfig enableLatchUnsignaledConfig;
 
     // must be called before clients can connect
@@ -274,7 +230,8 @@
     // Schedule sampling independently from commit or composite.
     void scheduleSample();
 
-    surfaceflinger::Factory& getFactory() { return mFactory; }
+    const surfaceflinger::Config& getConfig() { return *mConfig; }
+    surfaceflinger::Factory& getFactory() { return *mConfig->factory; }
 
     // The CompositionEngine encapsulates all composition related interfaces and actions.
     compositionengine::CompositionEngine& getCompositionEngine() const;
@@ -306,10 +263,6 @@
         return mTransactionCallbackInvoker;
     }
 
-    // If set, disables reusing client composition buffers. This can be set by
-    // debug.sf.disable_client_composition_cache
-    bool mDisableClientCompositionCache = false;
-
     // Disables expensive rendering for all displays
     // This is scheduled on the main thread
     void disableExpensiveRendering();
@@ -320,17 +273,6 @@
     // run parallel to the hwc validateDisplay call and re-run if the predition is incorrect.
     bool mPredictCompositionStrategy = false;
 
-    // If true, then any layer with a SMPTE 170M transfer function is decoded using the sRGB
-    // transfer instead. This is mainly to preserve legacy behavior, where implementations treated
-    // SMPTE 170M as sRGB prior to color management being implemented, and now implementations rely
-    // on this behavior to increase contrast for some media sources.
-    bool mTreat170mAsSrgb = false;
-
-    // Allows to ignore physical orientation provided through hwc API in favour of
-    // 'ro.surface_flinger.primary_display_orientation'.
-    // TODO(b/246793311): Clean up a temporary property
-    bool mIgnoreHwcPhysicalDisplayOrientation = false;
-
     void forceFutureUpdate(int delayInMs);
     const DisplayDevice* getDisplayFromLayerStack(ui::LayerStack)
             REQUIRES(mStateLock, kMainThreadContext);
@@ -662,12 +604,6 @@
     // Keeps track of whether the kernel idle timer is currently enabled, so we don't have to
     // make calls to sys prop each time.
     bool mKernelIdleTimerEnabled = false;
-    // Show spinner with refresh rate overlay
-    bool mRefreshRateOverlaySpinner = false;
-    // Show render rate with refresh rate overlay
-    bool mRefreshRateOverlayRenderRate = false;
-    // Show render rate overlay offseted to the middle of the screen (e.g. for circular displays)
-    bool mRefreshRateOverlayShowInMiddle = false;
 
     void setDesiredActiveMode(display::DisplayModeRequest&&, bool force = false)
             REQUIRES(mStateLock);
@@ -1101,8 +1037,8 @@
      */
     const std::unordered_map<std::string, uint32_t>& getGenericLayerMetadataKeyMap() const;
 
-    static int calculateMaxAcquiredBufferCount(Fps refreshRate,
-                                               std::chrono::nanoseconds presentLatency);
+    int calculateMaxAcquiredBufferCount(Fps refreshRate,
+                                        std::chrono::nanoseconds presentLatency) const;
     int getMaxAcquiredBufferCountForRefreshRate(Fps refreshRate) const;
 
     bool isHdrLayer(const frontend::LayerSnapshot& snapshot) const;
@@ -1112,8 +1048,7 @@
     void traverseLegacyLayers(const LayerVector::Visitor& visitor) const;
 
     sp<StartPropertySetThread> mStartPropertySetThread;
-    surfaceflinger::Factory& mFactory;
-    pid_t mPid;
+    surfaceflinger::Config* const mConfig = nullptr;
     std::future<void> mRenderEnginePrimeCacheFuture;
 
     // mStateLock has conventions related to the current thread, because only
@@ -1140,12 +1075,6 @@
     float mGlobalSaturationFactor = 1.0f;
     mat4 mClientColorMatrix;
 
-    size_t mMaxGraphicBufferProducerListSize = MAX_LAYERS;
-    // If there are more GraphicBufferProducers tracked by SurfaceFlinger than
-    // this threshold, then begin logging.
-    size_t mGraphicBufferProducerListSizeLogThreshold =
-            static_cast<size_t>(0.95 * static_cast<double>(MAX_LAYERS));
-
     // protected by mStateLock (but we could use another lock)
     bool mLayersRemoved = false;
     bool mLayersAdded = false;
@@ -1155,7 +1084,6 @@
 
     // constant members (no synchronization needed for access)
     const nsecs_t mBootTime = systemTime();
-    bool mIsUserBuild = true;
 
     // Can only accessed from the main thread, these members
     // don't need synchronization
@@ -1167,7 +1095,6 @@
     // Used to ensure we omit a callback when HDR layer info listener is newly added but the
     // scene hasn't changed
     bool mAddingHDRLayerInfoListener = false;
-    bool mIgnoreHdrCameraLayers = false;
 
     // Set during transaction application stage to track if the input info or children
     // for a layer has changed.
@@ -1226,9 +1153,6 @@
     std::atomic<nsecs_t> mDebugInTransaction = 0;
     std::atomic_bool mForceFullDamage = false;
 
-    bool mLayerCachingEnabled = false;
-    bool mBackpressureGpuComposition = false;
-
     LayerTracing mLayerTracing;
     bool mLayerTracingEnabled = false;
 
@@ -1241,9 +1165,6 @@
 
     VsyncId mLastCommittedVsyncId;
 
-    // If blurs should be enabled on this device.
-    bool mSupportsBlur = false;
-
     TransactionCallbackInvoker mTransactionCallbackInvoker;
 
     // We maintain a pool of pre-generated texture names to hand out to avoid
@@ -1275,13 +1196,9 @@
     // This property can be used to force SurfaceFlinger to always pick a certain color mode.
     ui::ColorMode mForceColorMode = ui::ColorMode::NATIVE;
 
-    // Whether to enable wide color gamut (e.g. Display P3) for internal displays that support it.
-    // If false, wide color modes are filtered out for all internal displays.
-    bool mSupportsWideColor = false;
+    std::optional<ui::Dataspace> mOverrideDefaultCompositionDataspace;
+    std::optional<ui::Dataspace> mOverrideWideColorGamutCompositionDataspace;
 
-    ui::Dataspace mDefaultCompositionDataspace;
-    ui::Dataspace mWideColorGamutCompositionDataspace;
-    ui::Dataspace mColorSpaceAgnosticDataspace;
     float mDimmingRatio = -1.f;
 
     std::unique_ptr<renderengine::RenderEngine> mRenderEngine;
@@ -1295,8 +1212,6 @@
     // any mutex.
     size_t mMaxRenderTargetSize{1};
 
-    const std::string mHwcServiceName;
-
     /*
      * Scheduler
      */
@@ -1313,14 +1228,9 @@
     // below flags are set by main thread only
     bool mSetActiveModePending = false;
 
-    bool mLumaSampling = true;
     sp<RegionSamplingThread> mRegionSamplingThread;
     sp<FpsReporter> mFpsReporter;
     sp<TunnelModeEnabledReporter> mTunnelModeEnabledReporter;
-    ui::DisplayPrimaries mInternalDisplayPrimaries;
-
-    const float mEmulatedDisplayDensity;
-    const float mInternalDisplayDensity;
 
     // Should only be accessed by the main thread.
     sp<os::IInputFlinger> mInputFlinger;
@@ -1397,9 +1307,6 @@
 
     bool mPowerHintSessionEnabled;
 
-    bool mLayerLifecycleManagerEnabled = false;
-    bool mLegacyFrontEndEnabled = true;
-
     frontend::LayerLifecycleManager mLayerLifecycleManager;
     frontend::LayerHierarchyBuilder mLayerHierarchyBuilder{{}};
     frontend::LayerSnapshotBuilder mLayerSnapshotBuilder;