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

Commit e8a7ab25 authored by Patrick Williams's avatar Patrick Williams
Browse files

Improve updateInputFlinger performance

This change improves the performance of the WindowInfosListenerInvoker work done on SurfaceFlinger's background executor thread. The primary optimization made is not sending a WindowInfosReportedListener with every call to WindowInfosListener.onWindowInfosChanged. Instead, we send a new interface, WindowInfosPublisher, and a unique listener id to listeners when they're added.  Listeners call WindowInfosPublisher.ackWindowInfosReceived with their id after processing each update.

From traces taken during development, the new code is a major improvement, taking about 15% of the time spent previously on SurfaceFlinger's background thread for sending window infos. Performance with this change seems roughly in line with the performance in T.

Bug: 290377931
Test: atest WindowInfosListenerTest
Test: atest WindowInfosListenerInvokerTest
Test: manually killing system server and checking valid state on restart
Change-Id: Ib39ba935727df0bc1ab4030bcfe8301de7e64805
(cherry picked from commit acd2258a)
parent 96d0d965
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -73,6 +73,7 @@ filegroup {
        "android/gui/FocusRequest.aidl",
        "android/gui/InputApplicationInfo.aidl",
        "android/gui/IWindowInfosListener.aidl",
        "android/gui/IWindowInfosPublisher.aidl",
        "android/gui/IWindowInfosReportedListener.aidl",
        "android/gui/WindowInfo.aidl",
        "android/gui/WindowInfosUpdate.aidl",
@@ -90,6 +91,7 @@ cc_library_static {
        "android/gui/FocusRequest.aidl",
        "android/gui/InputApplicationInfo.aidl",
        "android/gui/IWindowInfosListener.aidl",
        "android/gui/IWindowInfosPublisher.aidl",
        "android/gui/IWindowInfosReportedListener.aidl",
        "android/gui/WindowInfosUpdate.aidl",
        "android/gui/WindowInfo.aidl",
@@ -136,6 +138,7 @@ aidl_library {
        "android/gui/FocusRequest.aidl",
        "android/gui/InputApplicationInfo.aidl",
        "android/gui/IWindowInfosListener.aidl",
        "android/gui/IWindowInfosPublisher.aidl",
        "android/gui/IWindowInfosReportedListener.aidl",
        "android/gui/WindowInfo.aidl",
        "android/gui/WindowInfosUpdate.aidl",
+12 −8
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@
namespace android {

using gui::DisplayInfo;
using gui::IWindowInfosReportedListener;
using gui::WindowInfo;
using gui::WindowInfosListener;
using gui::aidl_utils::statusTFromBinderStatus;
@@ -40,8 +39,13 @@ status_t WindowInfosListenerReporter::addWindowInfosListener(
    {
        std::scoped_lock lock(mListenersMutex);
        if (mWindowInfosListeners.empty()) {
            binder::Status s = surfaceComposer->addWindowInfosListener(this);
            gui::WindowInfosListenerInfo listenerInfo;
            binder::Status s = surfaceComposer->addWindowInfosListener(this, &listenerInfo);
            status = statusTFromBinderStatus(s);
            if (status == OK) {
                mWindowInfosPublisher = std::move(listenerInfo.windowInfosPublisher);
                mListenerId = listenerInfo.listenerId;
            }
        }

        if (status == OK) {
@@ -85,8 +89,7 @@ status_t WindowInfosListenerReporter::removeWindowInfosListener(
}

binder::Status WindowInfosListenerReporter::onWindowInfosChanged(
        const gui::WindowInfosUpdate& update,
        const sp<IWindowInfosReportedListener>& windowInfosReportedListener) {
        const gui::WindowInfosUpdate& update) {
    std::unordered_set<sp<WindowInfosListener>, gui::SpHash<WindowInfosListener>>
            windowInfosListeners;

@@ -104,9 +107,7 @@ binder::Status WindowInfosListenerReporter::onWindowInfosChanged(
        listener->onWindowInfosChanged(update);
    }

    if (windowInfosReportedListener) {
        windowInfosReportedListener->onWindowInfosReported();
    }
    mWindowInfosPublisher->ackWindowInfosReceived(update.vsyncId, mListenerId);

    return binder::Status::ok();
}
@@ -114,7 +115,10 @@ binder::Status WindowInfosListenerReporter::onWindowInfosChanged(
void WindowInfosListenerReporter::reconnect(const sp<gui::ISurfaceComposer>& composerService) {
    std::scoped_lock lock(mListenersMutex);
    if (!mWindowInfosListeners.empty()) {
        composerService->addWindowInfosListener(this);
        gui::WindowInfosListenerInfo listenerInfo;
        composerService->addWindowInfosListener(this, &listenerInfo);
        mWindowInfosPublisher = std::move(listenerInfo.windowInfosPublisher);
        mListenerId = listenerInfo.listenerId;
    }
}

+3 −1
Original line number Diff line number Diff line
@@ -40,12 +40,14 @@ import android.gui.IScreenCaptureListener;
import android.gui.ISurfaceComposerClient;
import android.gui.ITunnelModeEnabledListener;
import android.gui.IWindowInfosListener;
import android.gui.IWindowInfosPublisher;
import android.gui.LayerCaptureArgs;
import android.gui.LayerDebugInfo;
import android.gui.OverlayProperties;
import android.gui.PullAtomData;
import android.gui.ARect;
import android.gui.StaticDisplayInfo;
import android.gui.WindowInfosListenerInfo;

/** @hide */
interface ISurfaceComposer {
@@ -500,7 +502,7 @@ interface ISurfaceComposer {
     */
    int getMaxAcquiredBufferCount();

    void addWindowInfosListener(IWindowInfosListener windowInfosListener);
    WindowInfosListenerInfo addWindowInfosListener(IWindowInfosListener windowInfosListener);

    void removeWindowInfosListener(IWindowInfosListener windowInfosListener);

+25 −0
Original line number Diff line number Diff line
/**
 * Copyright (c) 2023, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.gui;

import android.gui.IWindowInfosPublisher;

/** @hide */
parcelable WindowInfosListenerInfo {
    long listenerId;
    IWindowInfosPublisher windowInfosPublisher;
}
 No newline at end of file
+1 −3
Original line number Diff line number Diff line
@@ -16,11 +16,9 @@

package android.gui;

import android.gui.IWindowInfosReportedListener;
import android.gui.WindowInfosUpdate;

/** @hide */
oneway interface IWindowInfosListener {
    void onWindowInfosChanged(
        in WindowInfosUpdate update, in @nullable IWindowInfosReportedListener windowInfosReportedListener);
    void onWindowInfosChanged(in WindowInfosUpdate update);
}
Loading