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

Commit 1c3cd770 authored by Marin Shalamanov's avatar Marin Shalamanov Committed by Android (Google) Code Review
Browse files

Merge changes Id05d2eac,I3d8bcbf8 into sc-dev

* changes:
  SF: Add DisplayDevice::initiateModeChange
  SF: Store display modes in DisplayDevice
parents 52bf7808 12c9e5af
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -96,7 +96,7 @@ public:
    MOCK_CONST_METHOD1(isVsyncPeriodSwitchSupported, bool(PhysicalDisplayId));
    MOCK_CONST_METHOD1(getDisplayVsyncPeriod, nsecs_t(PhysicalDisplayId));
    MOCK_METHOD4(setActiveModeWithConstraints,
                 status_t(PhysicalDisplayId, DisplayModeId,
                 status_t(PhysicalDisplayId, hal::HWConfigId,
                          const hal::VsyncPeriodChangeConstraints&,
                          hal::VsyncPeriodChangeTimeline*));
    MOCK_METHOD2(setAutoLowLatencyMode, status_t(PhysicalDisplayId, bool));
+50 −11
Original line number Diff line number Diff line
@@ -51,17 +51,22 @@ using android::base::StringAppendF;
ui::Transform::RotationFlags DisplayDevice::sPrimaryDisplayRotationFlags = ui::Transform::ROT_0;

DisplayDeviceCreationArgs::DisplayDeviceCreationArgs(
        const sp<SurfaceFlinger>& flinger, const wp<IBinder>& displayToken,
        const sp<SurfaceFlinger>& flinger, HWComposer& hwComposer, const wp<IBinder>& displayToken,
        std::shared_ptr<compositionengine::Display> compositionDisplay)
      : flinger(flinger), displayToken(displayToken), compositionDisplay(compositionDisplay) {}
      : flinger(flinger),
        hwComposer(hwComposer),
        displayToken(displayToken),
        compositionDisplay(compositionDisplay) {}

DisplayDevice::DisplayDevice(DisplayDeviceCreationArgs& args)
      : mFlinger(args.flinger),
        mHwComposer(args.hwComposer),
        mDisplayToken(args.displayToken),
        mSequenceId(args.sequenceId),
        mConnectionType(args.connectionType),
        mCompositionDisplay{args.compositionDisplay},
        mPhysicalOrientation(args.physicalOrientation),
        mSupportedModes(std::move(args.supportedModes)),
        mIsPrimary(args.isPrimary) {
    mCompositionDisplay->editState().isSecure = args.isSecure;
    mCompositionDisplay->createRenderSurface(
@@ -139,12 +144,39 @@ bool DisplayDevice::isPoweredOn() const {
    return mPowerMode != hal::PowerMode::OFF;
}

void DisplayDevice::setActiveMode(DisplayModeId mode) {
    mActiveMode = mode;
void DisplayDevice::setActiveMode(DisplayModeId id) {
    LOG_FATAL_IF(id.value() >= mSupportedModes.size(),
                 "Cannot set active mode which is not supported.");
    mActiveModeId = id;
}

DisplayModeId DisplayDevice::getActiveMode() const {
    return mActiveMode;
status_t DisplayDevice::initiateModeChange(DisplayModeId modeId,
                                           const hal::VsyncPeriodChangeConstraints& constraints,
                                           hal::VsyncPeriodChangeTimeline* outTimeline) const {
    const auto mode = getMode(modeId);
    if (!mode) {
        ALOGE("Trying to initiate a mode change to invalid mode %s on display %s",
              std::to_string(modeId.value()).c_str(), to_string(getId()).c_str());
        return BAD_VALUE;
    }
    return mHwComposer.setActiveModeWithConstraints(getPhysicalId(), mode->getHwcId(), constraints,
                                                    outTimeline);
}

const DisplayModePtr& DisplayDevice::getActiveMode() const {
    return mSupportedModes[mActiveModeId.value()];
}

const DisplayModes& DisplayDevice::getSupportedModes() const {
    return mSupportedModes;
}

DisplayModePtr DisplayDevice::getMode(DisplayModeId modeId) const {
    const auto id = modeId.value();
    if (id < mSupportedModes.size()) {
        return mSupportedModes[id];
    }
    return nullptr;
}

ui::Dataspace DisplayDevice::getCompositionDataSpace() const {
@@ -206,17 +238,24 @@ std::string DisplayDevice::getDebugName() const {

void DisplayDevice::dump(std::string& result) const {
    StringAppendF(&result, "+ %s\n", getDebugName().c_str());
    StringAppendF(&result, "   powerMode=%s (%d)\n", to_string(mPowerMode).c_str(),
                  static_cast<int32_t>(mPowerMode));
    StringAppendF(&result, "   activeMode=%s\n", to_string(*getActiveMode()).c_str());

    result.append("   supportedModes=\n");

    for (const auto& mode : mSupportedModes) {
        result.append("     ");
    StringAppendF(&result, "powerMode=%s (%d), ", to_string(mPowerMode).c_str(),
                  static_cast<int32_t>(mPowerMode));
    StringAppendF(&result, "activeConfig=%zu, ", mActiveMode.value());
        result.append(to_string(*mode));
        result.append("\n");
    }
    StringAppendF(&result, "   deviceProductInfo=");
    if (mDeviceProductInfo) {
        mDeviceProductInfo->dump(result);
    } else {
        result.append("{}");
    }
    result.append("\n");
    getCompositionDisplay()->dump(result);
}

+24 −5
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@
#include <ui/HdrCapabilities.h>
#include <ui/Region.h>
#include <ui/Transform.h>
#include <utils/Errors.h>
#include <utils/Mutex.h>
#include <utils/RefBase.h>
#include <utils/Timers.h>
@@ -157,10 +158,23 @@ public:
    ui::Dataspace getCompositionDataSpace() const;

    /* ------------------------------------------------------------------------
     * Display active config management.
     * Display mode management.
     */
    DisplayModeId getActiveMode() const;
    void setActiveMode(DisplayModeId mode);
    const DisplayModePtr& getActiveMode() const;
    void setActiveMode(DisplayModeId);
    status_t initiateModeChange(DisplayModeId modeId,
                                const hal::VsyncPeriodChangeConstraints& constraints,
                                hal::VsyncPeriodChangeTimeline* outTimeline) const;

    // Return the immutable list of supported display modes. The HWC may report different modes
    // after a hotplug reconnect event, in which case the DisplayDevice object will be recreated.
    // Hotplug reconnects are common for external displays.
    const DisplayModes& getSupportedModes() const;

    // Returns nullptr if the given mode ID is not supported. A previously
    // supported mode may be no longer supported for some devices like TVs and
    // set-top boxes after a hotplug reconnect.
    DisplayModePtr getMode(DisplayModeId) const;

    // release HWC resources (if any) for removable displays
    void disconnect();
@@ -174,6 +188,7 @@ public:

private:
    const sp<SurfaceFlinger> mFlinger;
    HWComposer& mHwComposer;
    const wp<IBinder> mDisplayToken;
    const int32_t mSequenceId;
    const std::optional<DisplayConnectionType> mConnectionType;
@@ -189,7 +204,8 @@ private:

    hardware::graphics::composer::hal::PowerMode mPowerMode =
            hardware::graphics::composer::hal::PowerMode::OFF;
    DisplayModeId mActiveMode;
    DisplayModeId mActiveModeId;
    const DisplayModes mSupportedModes;

    // TODO(b/74619554): Remove special cases for primary display.
    const bool mIsPrimary;
@@ -229,9 +245,11 @@ private:
struct DisplayDeviceCreationArgs {
    // We use a constructor to ensure some of the values are set, without
    // assuming a default value.
    DisplayDeviceCreationArgs(const sp<SurfaceFlinger>&, const wp<IBinder>& displayToken,
    DisplayDeviceCreationArgs(const sp<SurfaceFlinger>&, HWComposer& hwComposer,
                              const wp<IBinder>& displayToken,
                              std::shared_ptr<compositionengine::Display>);
    const sp<SurfaceFlinger> flinger;
    HWComposer& hwComposer;
    const wp<IBinder> displayToken;
    const std::shared_ptr<compositionengine::Display> compositionDisplay;

@@ -248,6 +266,7 @@ struct DisplayDeviceCreationArgs {
    hardware::graphics::composer::hal::PowerMode initialPowerMode{
            hardware::graphics::composer::hal::PowerMode::ON};
    bool isPrimary{false};
    DisplayModes supportedModes;
};

} // namespace android
+14 −3
Original line number Diff line number Diff line
@@ -17,8 +17,10 @@
#pragma once

#include "DisplayHardware/Hal.h"
#include "Fps.h"
#include "Scheduler/StrongTyping.h"

#include <android-base/stringprintf.h>
#include <android/configuration.h>
#include <utils/Timers.h>

@@ -61,7 +63,7 @@ public:
        }

        Builder& setVsyncPeriod(int32_t vsyncPeriod) {
            mDisplayMode->mVsyncPeriod = vsyncPeriod;
            mDisplayMode->mFps = Fps::fromPeriodNsecs(vsyncPeriod);
            return *this;
        }

@@ -111,7 +113,8 @@ public:

    int32_t getWidth() const { return mWidth; }
    int32_t getHeight() const { return mHeight; }
    nsecs_t getVsyncPeriod() const { return mVsyncPeriod; }
    Fps getFps() const { return mFps; }
    nsecs_t getVsyncPeriod() const { return mFps.getPeriodNsecs(); }
    float getDpiX() const { return mDpiX; }
    float getDpiY() const { return mDpiY; }
    int32_t getConfigGroup() const { return mConfigGroup; }
@@ -124,10 +127,18 @@ private:

    int32_t mWidth = -1;
    int32_t mHeight = -1;
    nsecs_t mVsyncPeriod = -1;
    Fps mFps;
    float mDpiX = -1;
    float mDpiY = -1;
    int32_t mConfigGroup = -1;
};

inline std::string to_string(const DisplayMode& mode) {
    return base::StringPrintf("{id=%zu, hwcId=%d, width=%d, height=%d, refreshRate=%s, "
                              "dpiX=%.2f, dpiY=%.2f, configGroup=%d}",
                              mode.getId().value(), mode.getHwcId(), mode.getWidth(),
                              mode.getHeight(), to_string(mode.getFps()).c_str(), mode.getDpiX(),
                              mode.getDpiY(), mode.getConfigGroup());
}

} // namespace android
 No newline at end of file
+4 −10
Original line number Diff line number Diff line
@@ -674,19 +674,13 @@ status_t HWComposer::setPowerMode(PhysicalDisplayId displayId, hal::PowerMode mo
}

status_t HWComposer::setActiveModeWithConstraints(
        PhysicalDisplayId displayId, DisplayModeId modeId,
        PhysicalDisplayId displayId, hal::HWConfigId hwcModeId,
        const hal::VsyncPeriodChangeConstraints& constraints,
        hal::VsyncPeriodChangeTimeline* outTimeline) {
    RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);

    auto& displayData = mDisplayData[displayId];
    if (modeId.value() >= displayData.modes.size()) {
        LOG_DISPLAY_ERROR(displayId, ("Invalid mode " + std::to_string(modeId.value())).c_str());
        return BAD_INDEX;
    }

    const auto hwcConfigId = displayData.modes[modeId.value()]->getHwcId();
    auto error = displayData.hwcDisplay->setActiveConfigWithConstraints(hwcConfigId, constraints,
    auto error = mDisplayData[displayId].hwcDisplay->setActiveConfigWithConstraints(hwcModeId,
                                                                                    constraints,
                                                                                    outTimeline);
    RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
    return NO_ERROR;
Loading