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

Commit e5cceea2 authored by Marin Shalamanov's avatar Marin Shalamanov
Browse files

SF: Store DeviceProductInfo in DisplayDevice

When a new display is connected we query the display
identification data, parse the EDID and store it in
DisplayDevice for future use. This saves an unnecessary IPC
to HWC when SurfaceFlinger::getDisplayInfo() is called.

Bug: 149075047
Test: 1. flash a device
      2. boot a device connected to a display
      3. Check for sensible DeviceProductInfo:
         adb shell dumpsys SurfaceFlinger | grep deviceProductInfo
         adb shell dumpsys display | grep deviceProductInfo
      4. reboot without a display
      5. Check that  DeviceProductInfo is empty / null in
         adb shell dumpsys SurfaceFlinger | grep deviceProductInfo
         adb shell dumpsys display | grep deviceProductInfo
Change-Id: I35b6b3869eb740dd90913c9d3095fdc591b5ba3c
parent cf5f4059
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
@@ -16,13 +16,17 @@

#include <ui/DeviceProductInfo.h>

#include <android-base/stringprintf.h>
#include <ui/FlattenableHelpers.h>
#include <utils/Log.h>

#define RETURN_IF_ERROR(op) \
    if (const status_t status = (op); status != OK) return status;

namespace android {

using base::StringAppendF;

size_t DeviceProductInfo::getFlattenedSize() const {
    return FlattenableHelpers::getFlattenedSize(name) +
            FlattenableHelpers::getFlattenedSize(manufacturerPnpId) +
@@ -52,4 +56,32 @@ status_t DeviceProductInfo::unflatten(void const* buffer, size_t size) {
    return OK;
}

void DeviceProductInfo::dump(std::string& result) const {
    StringAppendF(&result, "{name=%s, ", name.c_str());
    StringAppendF(&result, "manufacturerPnpId=%s, ", manufacturerPnpId.data());
    StringAppendF(&result, "productId=%s, ", productId.c_str());

    if (const auto* model = std::get_if<ModelYear>(&manufactureOrModelDate)) {
        StringAppendF(&result, "modelYear=%u, ", model->year);
    } else if (const auto* manufactureWeekAndYear =
                       std::get_if<ManufactureWeekAndYear>(&manufactureOrModelDate)) {
        StringAppendF(&result, "manufactureWeek=%u, ", manufactureWeekAndYear->week);
        StringAppendF(&result, "manufactureYear=%d, ", manufactureWeekAndYear->year);
    } else if (const auto* manufactureYear =
                       std::get_if<ManufactureYear>(&manufactureOrModelDate)) {
        StringAppendF(&result, "manufactureYear=%d, ", manufactureYear->year);
    } else {
        ALOGE("Unknown alternative for variant DeviceProductInfo::ManufactureOrModelDate");
    }

    result.append("relativeAddress=[");
    for (size_t i = 0; i < relativeAddress.size(); i++) {
        if (i != 0) {
            result.append(", ");
        }
        StringAppendF(&result, "%u", relativeAddress[i]);
    }
    result.append("]}");
}

} // namespace android
+2 −0
Original line number Diff line number Diff line
@@ -68,6 +68,8 @@ struct DeviceProductInfo : LightFlattenable<DeviceProductInfo> {
    size_t getFlattenedSize() const;
    status_t flatten(void* buffer, size_t size) const;
    status_t unflatten(void const* buffer, size_t size);

    void dump(std::string& result) const;
};

} // namespace android
+10 −0
Original line number Diff line number Diff line
@@ -116,6 +116,10 @@ void DisplayDevice::setDisplayName(const std::string& displayName) {
    }
}

void DisplayDevice::setDeviceProductInfo(std::optional<DeviceProductInfo> info) {
    mDeviceProductInfo = std::move(info);
}

uint32_t DisplayDevice::getPageFlipCount() const {
    return mCompositionDisplay->getRenderSurface()->getPageFlipCount();
}
@@ -267,6 +271,12 @@ void DisplayDevice::dump(std::string& result) const {
    StringAppendF(&result, "powerMode=%s (%d), ", to_string(mPowerMode).c_str(),
                  static_cast<int32_t>(mPowerMode));
    StringAppendF(&result, "activeConfig=%d, ", mActiveConfig.value());
    StringAppendF(&result, "deviceProductInfo=");
    if (mDeviceProductInfo) {
        mDeviceProductInfo->dump(result);
    } else {
        result.append("{}");
    }
    getCompositionDisplay()->dump(result);
}

+7 −0
Original line number Diff line number Diff line
@@ -132,6 +132,11 @@ public:
    void setDisplayName(const std::string& displayName);
    const std::string& getDisplayName() const { return mDisplayName; }

    void setDeviceProductInfo(std::optional<DeviceProductInfo> info);
    const std::optional<DeviceProductInfo>& getDeviceProductInfo() const {
        return mDeviceProductInfo;
    }

    /* ------------------------------------------------------------------------
     * Display power mode management.
     */
@@ -178,6 +183,8 @@ private:

    // TODO(b/74619554): Remove special cases for primary display.
    const bool mIsPrimary;

    std::optional<DeviceProductInfo> mDeviceProductInfo;
};

struct DisplayDeviceState {
+4 −8
Original line number Diff line number Diff line
@@ -836,7 +836,7 @@ status_t SurfaceFlinger::getDisplayInfo(const sp<IBinder>& displayToken, Display
    }

    info->secure = display->isSecure();
    info->deviceProductInfo = getDeviceProductInfoLocked(*display);
    info->deviceProductInfo = display->getDeviceProductInfo();

    return NO_ERROR;
}
@@ -1310,13 +1310,8 @@ status_t SurfaceFlinger::getHdrCapabilities(const sp<IBinder>& displayToken,
}

std::optional<DeviceProductInfo> SurfaceFlinger::getDeviceProductInfoLocked(
        const DisplayDevice& display) const {
    // TODO(b/149075047): Populate DeviceProductInfo on hotplug and store it in DisplayDevice to
    // avoid repetitive HAL IPC and EDID parsing.
    const auto displayId = display.getId();
    LOG_FATAL_IF(!displayId);

    const auto hwcDisplayId = getHwComposer().fromPhysicalDisplayId(*displayId);
        DisplayId displayId) const {
    const auto hwcDisplayId = getHwComposer().fromPhysicalDisplayId(displayId);
    LOG_FATAL_IF(!hwcDisplayId);

    uint8_t port;
@@ -2544,6 +2539,7 @@ sp<DisplayDevice> SurfaceFlinger::setupNewDisplayDeviceInternal(
        LOG_ALWAYS_FATAL_IF(!displayId);
        auto activeConfigId = HwcConfigIndexType(getHwComposer().getActiveConfigIndex(*displayId));
        display->setActiveConfig(activeConfigId);
        display->setDeviceProductInfo(getDeviceProductInfoLocked(*displayId));
    }

    display->setLayerStack(state.layerStack);
Loading