Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 32818e22 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Convert to sysprop as API"

parents 57ba2f19 d5e08f6c
Loading
Loading
Loading
Loading
+28 −1
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ cc_defaults {
        "libinput",
        "libutils",
        "libutilscallstack",
        "libSurfaceFlingerProperties",
    ],
    static_libs: [
        "libcompositionengine",
@@ -221,7 +222,10 @@ cc_binary {
    defaults: ["libsurfaceflinger_binary"],
    init_rc: ["surfaceflinger.rc"],
    srcs: [":surfaceflinger_binary_sources"],
    shared_libs: ["libsurfaceflinger"],
    shared_libs: [
        "libsurfaceflinger",
        "libSurfaceFlingerProperties",
    ],
}

cc_library_shared {
@@ -247,3 +251,26 @@ subdirs = [
    "TimeStats/timestatsproto",
    "tests",
]

cc_library_shared {
    name: "libSurfaceFlingerProperties",
    srcs: [
        "SurfaceFlingerProperties.cpp",
        "sysprop/*.sysprop",
    ],
    shared_libs: [
        "android.hardware.configstore-utils",
        "android.hardware.configstore@1.0",
        "android.hardware.configstore@1.1",
        "android.hardware.configstore@1.2",
        "libhidlbase",
        "libhidltransport",
        "libhwbinder",
        "libutils",
    ],
    export_shared_lib_headers: [
        "libhidlbase",
        "libhidltransport",
        "libhwbinder",
    ],
}
+4 −6
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@
#include <android/hardware/configstore/1.1/ISurfaceFlingerConfigs.h>
#include <android/hardware/configstore/1.2/ISurfaceFlingerConfigs.h>
#include <configstore/Utils.h>

#include <cutils/properties.h>
#include <gui/ISurfaceComposer.h>
#include <ui/DisplayStatInfo.h>
@@ -42,11 +41,13 @@
#include "IdleTimer.h"
#include "InjectVSyncSource.h"
#include "SchedulerUtils.h"
#include "SurfaceFlingerProperties.h"

namespace android {

using namespace android::hardware::configstore;
using namespace android::hardware::configstore::V1_0;
using namespace android::sysprop;

#define RETURN_VALUE_IF_INVALID(value) \
    if (handle == nullptr || mConnections.count(handle->id) == 0) return value
@@ -56,11 +57,8 @@ using namespace android::hardware::configstore::V1_0;
std::atomic<int64_t> Scheduler::sNextId = 0;

Scheduler::Scheduler(impl::EventControlThread::SetVSyncEnabledFunction function)
      : mHasSyncFramework(
                getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasSyncFramework>(true)),
        mDispSyncPresentTimeOffset(
                getInt64<ISurfaceFlingerConfigs,
                         &ISurfaceFlingerConfigs::presentTimeOffsetFromVSyncNs>(0)),
      : mHasSyncFramework(running_without_sync_framework(true)),
        mDispSyncPresentTimeOffset(present_time_offset_from_vsync_ns(0)),
        mPrimaryHWVsyncEnabled(false),
        mHWVsyncAvailable(false) {
    // Note: We create a local temporary with the real DispSync implementation
+1 −1
Original line number Diff line number Diff line
@@ -149,7 +149,7 @@ private:

    // The offset in nanoseconds to use, when DispSync timestamps present fence
    // signaling time.
    const nsecs_t mDispSyncPresentTimeOffset;
    nsecs_t mDispSyncPresentTimeOffset;

    // Each connection has it's own ID. This variable keeps track of the count.
    static std::atomic<int64_t> sNextId;
+32 −47
Original line number Diff line number Diff line
@@ -112,11 +112,13 @@
#include <configstore/Utils.h>

#include <layerproto/LayerProtoParser.h>
#include "SurfaceFlingerProperties.h"

namespace android {

using namespace android::hardware::configstore;
using namespace android::hardware::configstore::V1_0;
using namespace android::sysprop;
using base::StringAppendF;
using ui::ColorMode;
using ui::Dataspace;
@@ -282,67 +284,50 @@ SurfaceFlinger::SurfaceFlinger(surfaceflinger::Factory& factory)
      : SurfaceFlinger(factory, SkipInitialization) {
    ALOGI("SurfaceFlinger is starting");

    vsyncPhaseOffsetNs = getInt64< ISurfaceFlingerConfigs,
            &ISurfaceFlingerConfigs::vsyncEventPhaseOffsetNs>(1000000);
    vsyncPhaseOffsetNs = vsync_event_phase_offset_ns(1000000);

    sfVsyncPhaseOffsetNs = getInt64< ISurfaceFlingerConfigs,
            &ISurfaceFlingerConfigs::vsyncSfEventPhaseOffsetNs>(1000000);
    sfVsyncPhaseOffsetNs = vsync_sf_event_phase_offset_ns(1000000);

    hasSyncFramework = getBool< ISurfaceFlingerConfigs,
            &ISurfaceFlingerConfigs::hasSyncFramework>(true);
    hasSyncFramework = running_without_sync_framework(true);

    dispSyncPresentTimeOffset = getInt64< ISurfaceFlingerConfigs,
            &ISurfaceFlingerConfigs::presentTimeOffsetFromVSyncNs>(0);
    dispSyncPresentTimeOffset = present_time_offset_from_vsync_ns(0);

    useHwcForRgbToYuv = getBool< ISurfaceFlingerConfigs,
            &ISurfaceFlingerConfigs::useHwcForRGBtoYUV>(false);
    useHwcForRgbToYuv = force_hwc_copy_for_virtual_displays(false);

    maxVirtualDisplaySize = getUInt64<ISurfaceFlingerConfigs,
            &ISurfaceFlingerConfigs::maxVirtualDisplaySize>(0);
    maxVirtualDisplaySize = max_virtual_display_dimension(0);

    // Vr flinger is only enabled on Daydream ready devices.
    useVrFlinger = getBool< ISurfaceFlingerConfigs,
            &ISurfaceFlingerConfigs::useVrFlinger>(false);

    maxFrameBufferAcquiredBuffers = getInt64< ISurfaceFlingerConfigs,
            &ISurfaceFlingerConfigs::maxFrameBufferAcquiredBuffers>(2);

    hasWideColorDisplay =
            getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasWideColorDisplay>(false);
    useColorManagement =
            getBool<V1_2::ISurfaceFlingerConfigs,
                    &V1_2::ISurfaceFlingerConfigs::useColorManagement>(false);

    auto surfaceFlingerConfigsServiceV1_2 = V1_2::ISurfaceFlingerConfigs::getService();
    if (surfaceFlingerConfigsServiceV1_2) {
        surfaceFlingerConfigsServiceV1_2->getCompositionPreference(
                [&](auto tmpDefaultDataspace, auto tmpDefaultPixelFormat,
                    auto tmpWideColorGamutDataspace, auto tmpWideColorGamutPixelFormat) {
                    defaultCompositionDataspace = tmpDefaultDataspace;
                    defaultCompositionPixelFormat = tmpDefaultPixelFormat;
                    wideColorGamutCompositionDataspace = tmpWideColorGamutDataspace;
                    wideColorGamutCompositionPixelFormat = tmpWideColorGamutPixelFormat;
                });
    }
    mDefaultCompositionDataspace = defaultCompositionDataspace;
    mWideColorGamutCompositionDataspace = wideColorGamutCompositionDataspace;
    useVrFlinger = use_vr_flinger(false);

    maxFrameBufferAcquiredBuffers = max_frame_buffer_acquired_buffers(2);

    hasWideColorDisplay = has_wide_color_display(false);

    useColorManagement = use_color_management(false);

    useContextPriority = getBool<ISurfaceFlingerConfigs,
                                 &ISurfaceFlingerConfigs::useContextPriority>(true);
    mDefaultCompositionDataspace =
            static_cast<ui::Dataspace>(default_composition_dataspace(Dataspace::V0_SRGB));
    mWideColorGamutCompositionDataspace =
            static_cast<ui::Dataspace>(wcg_composition_dataspace(Dataspace::V0_SRGB));
    defaultCompositionDataspace = mDefaultCompositionDataspace;
    wideColorGamutCompositionDataspace = mWideColorGamutCompositionDataspace;
    defaultCompositionPixelFormat = static_cast<ui::PixelFormat>(
            default_composition_pixel_format(ui::PixelFormat::RGBA_8888));
    wideColorGamutCompositionPixelFormat =
            static_cast<ui::PixelFormat>(wcg_composition_pixel_format(ui::PixelFormat::RGBA_8888));

    V1_1::DisplayOrientation primaryDisplayOrientation =
        getDisplayOrientation<V1_1::ISurfaceFlingerConfigs,
                              &V1_1::ISurfaceFlingerConfigs::primaryDisplayOrientation>(
            V1_1::DisplayOrientation::ORIENTATION_0);
    useContextPriority = use_context_priority(true);

    switch (primaryDisplayOrientation) {
        case V1_1::DisplayOrientation::ORIENTATION_90:
    auto tmpPrimaryDisplayOrientation = primary_display_orientation(
            SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_0);
    switch (tmpPrimaryDisplayOrientation) {
        case SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_90:
            SurfaceFlinger::primaryDisplayOrientation = DisplayState::eOrientation90;
            break;
        case V1_1::DisplayOrientation::ORIENTATION_180:
        case SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_180:
            SurfaceFlinger::primaryDisplayOrientation = DisplayState::eOrientation180;
            break;
        case V1_1::DisplayOrientation::ORIENTATION_270:
        case SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_270:
            SurfaceFlinger::primaryDisplayOrientation = DisplayState::eOrientation270;
            break;
        default:
+246 −0
Original line number Diff line number Diff line

#include <sysprop/SurfaceFlingerProperties.sysprop.h>

#include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h>
#include <android/hardware/configstore/1.1/ISurfaceFlingerConfigs.h>
#include <android/hardware/configstore/1.1/types.h>
#include <android/hardware/configstore/1.2/ISurfaceFlingerConfigs.h>
#include <configstore/Utils.h>

#include <tuple>

#include "SurfaceFlingerProperties.h"

namespace android {
namespace sysprop {
using namespace android::hardware::configstore;
using namespace android::hardware::configstore::V1_0;
using ::android::hardware::graphics::common::V1_1::PixelFormat;
using ::android::hardware::graphics::common::V1_2::Dataspace;

int64_t vsync_event_phase_offset_ns(int64_t defaultValue) {
    auto temp = SurfaceFlingerProperties::vsync_event_phase_offset_ns();
    if (temp.has_value()) {
        return *temp;
    }
    return getInt64<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::vsyncEventPhaseOffsetNs>(
            defaultValue);
}

int64_t vsync_sf_event_phase_offset_ns(int64_t defaultValue) {
    auto temp = SurfaceFlingerProperties::vsync_sf_event_phase_offset_ns();
    if (temp.has_value()) {
        return *temp;
    }
    return getInt64<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::vsyncSfEventPhaseOffsetNs>(
            defaultValue);
}

bool use_context_priority(bool defaultValue) {
    auto temp = SurfaceFlingerProperties::use_context_priority();
    if (temp.has_value()) {
        return *temp;
    }
    return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::useContextPriority>(
            defaultValue);
}

int64_t max_frame_buffer_acquired_buffers(int64_t defaultValue) {
    auto temp = SurfaceFlingerProperties::max_frame_buffer_acquired_buffers();
    if (temp.has_value()) {
        return *temp;
    }
    return getInt64<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::maxFrameBufferAcquiredBuffers>(
            defaultValue);
}

bool has_wide_color_display(bool defaultValue) {
    auto temp = SurfaceFlingerProperties::has_wide_color_display();
    if (temp.has_value()) {
        return *temp;
    }
    return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasWideColorDisplay>(
            defaultValue);
}

bool running_without_sync_framework(bool defaultValue) {
    auto temp = SurfaceFlingerProperties::running_without_sync_framework();
    if (temp.has_value()) {
        return !(*temp);
    }
    return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasSyncFramework>(defaultValue);
}

bool has_HDR_display(bool defaultValue) {
    auto temp = SurfaceFlingerProperties::has_HDR_display();
    if (temp.has_value()) {
        return *temp;
    }
    return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasHDRDisplay>(defaultValue);
}

int64_t present_time_offset_from_vsync_ns(int64_t defaultValue) {
    auto temp = SurfaceFlingerProperties::present_time_offset_from_vsync_ns();
    if (temp.has_value()) {
        return *temp;
    }
    return getInt64<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::presentTimeOffsetFromVSyncNs>(
            defaultValue);
}

bool force_hwc_copy_for_virtual_displays(bool defaultValue) {
    auto temp = SurfaceFlingerProperties::force_hwc_copy_for_virtual_displays();
    if (temp.has_value()) {
        return *temp;
    }
    return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::useHwcForRGBtoYUV>(
            defaultValue);
}

int64_t max_virtual_display_dimension(int64_t defaultValue) {
    auto temp = SurfaceFlingerProperties::max_virtual_display_dimension();
    if (temp.has_value()) {
        return *temp;
    }
    return getUInt64<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::maxVirtualDisplaySize>(
            defaultValue);
}

bool use_vr_flinger(bool defaultValue) {
    auto temp = SurfaceFlingerProperties::use_vr_flinger();
    if (temp.has_value()) {
        return *temp;
    }
    return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::useVrFlinger>(defaultValue);
}

bool start_graphics_allocator_service(bool defaultValue) {
    auto temp = SurfaceFlingerProperties::start_graphics_allocator_service();
    if (temp.has_value()) {
        return *temp;
    }
    return getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::startGraphicsAllocatorService>(
            defaultValue);
}

SurfaceFlingerProperties::primary_display_orientation_values primary_display_orientation(
        SurfaceFlingerProperties::primary_display_orientation_values defaultValue) {
    auto temp = SurfaceFlingerProperties::primary_display_orientation();
    if (temp.has_value()) {
        return *temp;
    }
    auto configDefault = DisplayOrientation::ORIENTATION_0;
    switch (defaultValue) {
        case SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_90:
            configDefault = DisplayOrientation::ORIENTATION_90;
            break;
        case SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_180:
            configDefault = DisplayOrientation::ORIENTATION_180;
            break;
        case SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_270:
            configDefault = DisplayOrientation::ORIENTATION_270;
            break;
        default:
            configDefault = DisplayOrientation::ORIENTATION_0;
            break;
    }
    DisplayOrientation result =
            getDisplayOrientation<V1_1::ISurfaceFlingerConfigs,
                                  &V1_1::ISurfaceFlingerConfigs::primaryDisplayOrientation>(
                    configDefault);
    switch (result) {
        case DisplayOrientation::ORIENTATION_90:
            return SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_90;
        case DisplayOrientation::ORIENTATION_180:
            return SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_180;
        case DisplayOrientation::ORIENTATION_270:
            return SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_270;
        default:
            break;
    }
    return SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_0;
}

bool use_color_management(bool defaultValue) {
    auto tmpuseColorManagement = SurfaceFlingerProperties::use_color_management();
    auto tmpHasHDRDisplay = SurfaceFlingerProperties::has_HDR_display();
    auto tmpHasWideColorDisplay = SurfaceFlingerProperties::has_wide_color_display();
    if (tmpuseColorManagement.has_value() && tmpHasHDRDisplay.has_value() &&
        tmpHasWideColorDisplay.has_value()) {
        return *tmpuseColorManagement || *tmpHasHDRDisplay || *tmpHasWideColorDisplay;
    }
    auto surfaceFlingerConfigsServiceV1_2 = ISurfaceFlingerConfigs::getService();
    if (surfaceFlingerConfigsServiceV1_2) {
        return getBool<V1_2::ISurfaceFlingerConfigs,
                       &V1_2::ISurfaceFlingerConfigs::useColorManagement>(defaultValue);
    }
    return defaultValue;
}

auto getCompositionPreference(sp<V1_2::ISurfaceFlingerConfigs> configsServiceV1_2) {
    Dataspace defaultCompositionDataspace = Dataspace::V0_SRGB;
    PixelFormat defaultCompositionPixelFormat = PixelFormat::RGBA_8888;
    Dataspace wideColorGamutCompositionDataspace = Dataspace::V0_SRGB;
    PixelFormat wideColorGamutCompositionPixelFormat = PixelFormat::RGBA_8888;
    configsServiceV1_2->getCompositionPreference(
            [&](auto tmpDefaultDataspace, auto tmpDefaultPixelFormat,
                auto tmpWideColorGamutDataspace, auto tmpWideColorGamutPixelFormat) {
                defaultCompositionDataspace = tmpDefaultDataspace;
                defaultCompositionPixelFormat = tmpDefaultPixelFormat;
                wideColorGamutCompositionDataspace = tmpWideColorGamutDataspace;
                wideColorGamutCompositionPixelFormat = tmpWideColorGamutPixelFormat;
            });
    return std::tuple(defaultCompositionDataspace, defaultCompositionPixelFormat,
                      wideColorGamutCompositionDataspace, wideColorGamutCompositionPixelFormat);
}

int64_t default_composition_dataspace(Dataspace defaultValue) {
    auto temp = SurfaceFlingerProperties::default_composition_dataspace();
    if (temp.has_value()) {
        return *temp;
    }
    auto configsServiceV1_2 = V1_2::ISurfaceFlingerConfigs::getService();
    if (configsServiceV1_2) {
        return static_cast<int64_t>(get<0>(getCompositionPreference(configsServiceV1_2)));
    }
    return static_cast<int64_t>(defaultValue);
}

int32_t default_composition_pixel_format(PixelFormat defaultValue) {
    auto temp = SurfaceFlingerProperties::default_composition_pixel_format();
    if (temp.has_value()) {
        return *temp;
    }
    auto configsServiceV1_2 = V1_2::ISurfaceFlingerConfigs::getService();
    if (configsServiceV1_2) {
        return static_cast<int32_t>(get<1>(getCompositionPreference(configsServiceV1_2)));
    }
    return static_cast<int32_t>(defaultValue);
}

int64_t wcg_composition_dataspace(Dataspace defaultValue) {
    auto temp = SurfaceFlingerProperties::wcg_composition_dataspace();
    if (temp.has_value()) {
        return *temp;
    }
    auto configsServiceV1_2 = V1_2::ISurfaceFlingerConfigs::getService();
    if (configsServiceV1_2) {
        return static_cast<int64_t>(get<2>(getCompositionPreference(configsServiceV1_2)));
    }
    return static_cast<int64_t>(defaultValue);
}

int32_t wcg_composition_pixel_format(PixelFormat defaultValue) {
    auto temp = SurfaceFlingerProperties::wcg_composition_pixel_format();
    if (temp.has_value()) {
        return *temp;
    }
    auto configsServiceV1_2 = V1_2::ISurfaceFlingerConfigs::getService();
    if (configsServiceV1_2) {
        return static_cast<int32_t>(get<3>(getCompositionPreference(configsServiceV1_2)));
    }
    return static_cast<int32_t>(defaultValue);
}

} // namespace sysprop
} // namespace android
Loading