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

Commit d65a475f authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

SF: Clean up input info loop

Remove the need to loop through all displays for each layer by caching
the necessary display info beforehand.

Bug: 188939842
Test: presubmit
Change-Id: I80d5d09855756011fa1ce8efed841120cf0aab18
parent 1728b211
Loading
Loading
Loading
Loading
+17 −31
Original line number Diff line number Diff line
@@ -3044,7 +3044,9 @@ void SurfaceFlinger::updateInputFlinger() {
void SurfaceFlinger::notifyWindowInfos() {
    std::vector<WindowInfo> windowInfos;
    std::vector<DisplayInfo> displayInfos;
    std::unordered_map<uint32_t /*layerStackId*/, const ui::Transform> displayTransforms;
    std::unordered_map<uint32_t /*layerStackId*/,
                       std::pair<bool /* isSecure */, const ui::Transform>>
            inputDisplayDetails;

    for (const auto& [_, display] : ON_MAIN_THREAD(mDisplays)) {
        if (!display->receivesInput()) {
@@ -3052,7 +3054,8 @@ void SurfaceFlinger::notifyWindowInfos() {
        }
        const uint32_t layerStackId = display->getLayerStack().id;
        const auto& [info, transform] = display->getInputInfo();
        const auto& [it, emplaced] = displayTransforms.try_emplace(layerStackId, transform);
        const auto& [it, emplaced] =
                inputDisplayDetails.try_emplace(layerStackId, display->isSecure(), transform);
        if (!emplaced) {
            ALOGE("Multiple displays claim to accept input for the same layer stack: %u",
                  layerStackId);
@@ -3064,19 +3067,21 @@ void SurfaceFlinger::notifyWindowInfos() {
    mDrawingState.traverseInReverseZOrder([&](Layer* layer) {
        if (!layer->needsInputInfo()) return;

        const DisplayDevice* display = ON_MAIN_THREAD(getDisplayWithInputByLayer(layer)).get();
        bool isSecure = true;
        ui::Transform displayTransform = ui::Transform();

        if (display != nullptr) {
            // When calculating the screen bounds we ignore the transparent region since it may
            // result in an unwanted offset.
            const auto it = displayTransforms.find(display->getLayerStack().id);
            if (it != displayTransforms.end()) {
                displayTransform = it->second;
            }
        const uint32_t layerStackId = layer->getLayerStack().id;
        const auto it = inputDisplayDetails.find(layerStackId);
        if (it != inputDisplayDetails.end()) {
            const auto& [secure, transform] = it->second;
            isSecure = secure;
            displayTransform = transform;
        } else {
            ALOGE("No input-enabled display found for layer `%s` on layer stack id: %d",
                  layer->getDebugName(), layerStackId);
        }
        const bool displayIsSecure = !display || display->isSecure();
        windowInfos.push_back(layer->fillInputInfo(displayTransform, displayIsSecure));

        windowInfos.push_back(layer->fillInputInfo(displayTransform, isSecure));
    });
    mWindowInfosListenerInvoker->windowInfosChanged(windowInfos, displayInfos,
                                                    mInputWindowCommands.syncInputWindows);
@@ -4517,25 +4522,6 @@ void SurfaceFlinger::initializeDisplays() {
    static_cast<void>(schedule([this]() MAIN_THREAD { onInitializeDisplays(); }));
}

sp<DisplayDevice> SurfaceFlinger::getDisplayWithInputByLayer(Layer* layer) const {
    const auto filter = layer->getOutputFilter();
    sp<DisplayDevice> inputDisplay;

    for (const auto& [_, display] : mDisplays) {
        if (!display->receivesInput() || !display->getCompositionDisplay()->includesLayer(filter)) {
            continue;
        }
        // Don't return immediately so that we can log duplicates.
        if (inputDisplay) {
            ALOGE("Multiple displays claim to accept input for the same layer stack: %u",
                  filter.layerStack.id);
            continue;
        }
        inputDisplay = display;
    }
    return inputDisplay;
}

void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, hal::PowerMode mode) {
    if (display->isVirtual()) {
        ALOGE("%s: Invalid operation on virtual display", __FUNCTION__);
+0 −2
Original line number Diff line number Diff line
@@ -897,8 +897,6 @@ private:
    // region of all screens presenting this layer stack.
    void invalidateLayerStack(const sp<const Layer>& layer, const Region& dirty);

    sp<DisplayDevice> getDisplayWithInputByLayer(Layer* layer) const REQUIRES(mStateLock);

    bool isDisplayActiveLocked(const sp<const DisplayDevice>& display) const REQUIRES(mStateLock) {
        return display->getDisplayToken() == mActiveDisplayToken;
    }