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

Commit 922e1b9b authored by Huihong Luo's avatar Huihong Luo Committed by Android (Google) Code Review
Browse files

Merge "Migrate display related methods to AIDL" into tm-dev

parents 6451714a b5cb7c15
Loading
Loading
Loading
Loading
+0 −116
Original line number Diff line number Diff line
@@ -226,81 +226,6 @@ public:
        return result;
    }

    sp<IBinder> createDisplay(const String8& displayName, bool secure) override {
        Parcel data, reply;
        data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
        status_t status = data.writeString8(displayName);
        if (status) {
            return nullptr;
        }
        status = data.writeBool(secure);
        if (status) {
            return nullptr;
        }

        status = remote()->transact(BnSurfaceComposer::CREATE_DISPLAY, data, &reply);
        if (status) {
            return nullptr;
        }
        sp<IBinder> display;
        status = reply.readNullableStrongBinder(&display);
        if (status) {
            return nullptr;
        }
        return display;
    }

    void destroyDisplay(const sp<IBinder>& display) override {
        Parcel data, reply;
        data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
        data.writeStrongBinder(display);
        remote()->transact(BnSurfaceComposer::DESTROY_DISPLAY, data, &reply);
    }

    std::vector<PhysicalDisplayId> getPhysicalDisplayIds() const override {
        Parcel data, reply;
        data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
        if (remote()->transact(BnSurfaceComposer::GET_PHYSICAL_DISPLAY_IDS, data, &reply) ==
            NO_ERROR) {
            std::vector<uint64_t> rawIds;
            if (reply.readUint64Vector(&rawIds) == NO_ERROR) {
                std::vector<PhysicalDisplayId> displayIds;
                displayIds.reserve(rawIds.size());

                for (const uint64_t rawId : rawIds) {
                    if (const auto id = DisplayId::fromValue<PhysicalDisplayId>(rawId)) {
                        displayIds.push_back(*id);
                    }
                }
                return displayIds;
            }
        }

        return {};
    }

    status_t getPrimaryPhysicalDisplayId(PhysicalDisplayId* displayId) const override {
        Parcel data, reply;
        SAFE_PARCEL(data.writeInterfaceToken, ISurfaceComposer::getInterfaceDescriptor());
        SAFE_PARCEL(remote()->transact, BnSurfaceComposer::GET_PRIMARY_PHYSICAL_DISPLAY_ID, data,
                    &reply);
        uint64_t rawId;
        SAFE_PARCEL(reply.readUint64, &rawId);
        if (const auto id = DisplayId::fromValue<PhysicalDisplayId>(rawId)) {
            *displayId = *id;
            return NO_ERROR;
        }
        return NAME_NOT_FOUND;
    }

    sp<IBinder> getPhysicalDisplayToken(PhysicalDisplayId displayId) const override {
        Parcel data, reply;
        data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
        data.writeUint64(displayId.value);
        remote()->transact(BnSurfaceComposer::GET_PHYSICAL_DISPLAY_TOKEN, data, &reply);
        return reply.readStrongBinder();
    }

    void setPowerMode(const sp<IBinder>& display, int mode) override {
        Parcel data, reply;
        data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
@@ -1467,29 +1392,6 @@ status_t BnSurfaceComposer::onTransact(
            reply->writeStrongBinder(IInterface::asBinder(connection));
            return NO_ERROR;
        }
        case CREATE_DISPLAY: {
            CHECK_INTERFACE(ISurfaceComposer, data, reply);
            String8 displayName;
            SAFE_PARCEL(data.readString8, &displayName);
            bool secure = false;
            SAFE_PARCEL(data.readBool, &secure);
            sp<IBinder> display = createDisplay(displayName, secure);
            SAFE_PARCEL(reply->writeStrongBinder, display);
            return NO_ERROR;
        }
        case DESTROY_DISPLAY: {
            CHECK_INTERFACE(ISurfaceComposer, data, reply);
            sp<IBinder> display = data.readStrongBinder();
            destroyDisplay(display);
            return NO_ERROR;
        }
        case GET_PHYSICAL_DISPLAY_TOKEN: {
            CHECK_INTERFACE(ISurfaceComposer, data, reply);
            const auto id = DisplayId::fromValue<PhysicalDisplayId>(data.readUint64());
            if (!id) return BAD_VALUE;
            reply->writeStrongBinder(getPhysicalDisplayToken(*id));
            return NO_ERROR;
        }
        case GET_DISPLAY_STATE: {
            CHECK_INTERFACE(ISurfaceComposer, data, reply);
            ui::DisplayState state;
@@ -1826,24 +1728,6 @@ status_t BnSurfaceComposer::onTransact(
            }
            return error;
        }
        case GET_PHYSICAL_DISPLAY_IDS: {
            CHECK_INTERFACE(ISurfaceComposer, data, reply);
            std::vector<PhysicalDisplayId> ids = getPhysicalDisplayIds();
            std::vector<uint64_t> rawIds(ids.size());
            std::transform(ids.begin(), ids.end(), rawIds.begin(),
                           [](PhysicalDisplayId id) { return id.value; });
            return reply->writeUint64Vector(rawIds);
        }
        case GET_PRIMARY_PHYSICAL_DISPLAY_ID: {
            CHECK_INTERFACE(ISurfaceComposer, data, reply);
            PhysicalDisplayId id;
            status_t result = getPrimaryPhysicalDisplayId(&id);
            if (result != NO_ERROR) {
                ALOGE("getPrimaryPhysicalDisplayId: Failed to get id");
                return result;
            }
            return reply->writeUint64(id.value);
        }
        case ADD_REGION_SAMPLING_LISTENER: {
            CHECK_INTERFACE(ISurfaceComposer, data, reply);
            Rect samplingArea;
+3 −2
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@
#include <gui/ISurfaceComposer.h>
#include <gui/LayerState.h>
#include <private/gui/ComposerService.h>
#include <private/gui/ComposerServiceAIDL.h>

namespace android {

@@ -343,7 +344,7 @@ status_t Surface::getFrameTimestamps(uint64_t frameNumber,
status_t Surface::getWideColorSupport(bool* supported) {
    ATRACE_CALL();

    const sp<IBinder> display = composerService()->getInternalDisplayToken();
    const sp<IBinder> display = ComposerServiceAIDL::getInstance().getInternalDisplayToken();
    if (display == nullptr) {
        return NAME_NOT_FOUND;
    }
@@ -356,7 +357,7 @@ status_t Surface::getWideColorSupport(bool* supported) {
status_t Surface::getHdrSupport(bool* supported) {
    ATRACE_CALL();

    const sp<IBinder> display = composerService()->getInternalDisplayToken();
    const sp<IBinder> display = ComposerServiceAIDL::getInstance().getInternalDisplayToken();
    if (display == nullptr) {
        return NAME_NOT_FOUND;
    }
+35 −8
Original line number Diff line number Diff line
@@ -1022,32 +1022,59 @@ status_t SurfaceComposerClient::Transaction::apply(bool synchronous, bool oneWay
// ---------------------------------------------------------------------------

sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName, bool secure) {
    return ComposerService::getComposerService()->createDisplay(displayName,
            secure);
    sp<IBinder> display = nullptr;
    binder::Status status =
            ComposerServiceAIDL::getComposerService()->createDisplay(std::string(
                                                                             displayName.string()),
                                                                     secure, &display);
    return status.isOk() ? display : nullptr;
}

void SurfaceComposerClient::destroyDisplay(const sp<IBinder>& display) {
    return ComposerService::getComposerService()->destroyDisplay(display);
    ComposerServiceAIDL::getComposerService()->destroyDisplay(display);
}

std::vector<PhysicalDisplayId> SurfaceComposerClient::getPhysicalDisplayIds() {
    return ComposerService::getComposerService()->getPhysicalDisplayIds();
    std::vector<int64_t> displayIds;
    std::vector<PhysicalDisplayId> physicalDisplayIds;
    binder::Status status =
            ComposerServiceAIDL::getComposerService()->getPhysicalDisplayIds(&displayIds);
    if (status.isOk()) {
        physicalDisplayIds.reserve(displayIds.size());
        for (auto item : displayIds) {
            auto id = DisplayId::fromValue<PhysicalDisplayId>(static_cast<uint64_t>(item));
            physicalDisplayIds.push_back(*id);
        }
    }
    return physicalDisplayIds;
}

status_t SurfaceComposerClient::getPrimaryPhysicalDisplayId(PhysicalDisplayId* id) {
    return ComposerService::getComposerService()->getPrimaryPhysicalDisplayId(id);
    int64_t displayId;
    binder::Status status =
            ComposerServiceAIDL::getComposerService()->getPrimaryPhysicalDisplayId(&displayId);
    if (status.isOk()) {
        *id = *DisplayId::fromValue<PhysicalDisplayId>(static_cast<uint64_t>(displayId));
    }
    return status.transactionError();
}

std::optional<PhysicalDisplayId> SurfaceComposerClient::getInternalDisplayId() {
    return ComposerService::getComposerService()->getInternalDisplayId();
    ComposerServiceAIDL& instance = ComposerServiceAIDL::getInstance();
    return instance.getInternalDisplayId();
}

sp<IBinder> SurfaceComposerClient::getPhysicalDisplayToken(PhysicalDisplayId displayId) {
    return ComposerService::getComposerService()->getPhysicalDisplayToken(displayId);
    sp<IBinder> display = nullptr;
    binder::Status status =
            ComposerServiceAIDL::getComposerService()->getPhysicalDisplayToken(displayId.value,
                                                                               &display);
    return status.isOk() ? display : nullptr;
}

sp<IBinder> SurfaceComposerClient::getInternalDisplayToken() {
    return ComposerService::getComposerService()->getInternalDisplayToken();
    ComposerServiceAIDL& instance = ComposerServiceAIDL::getInstance();
    return instance.getInternalDisplayToken();
}

void SurfaceComposerClient::Transaction::setAnimationTransaction() {
+22 −0
Original line number Diff line number Diff line
@@ -22,6 +22,28 @@ import android.gui.IScreenCaptureListener;

/** @hide */
interface ISurfaceComposer {

    /* create a virtual display
     * requires ACCESS_SURFACE_FLINGER permission.
     */
    @nullable IBinder createDisplay(@utf8InCpp String displayName, boolean secure);

    /* destroy a virtual display
     * requires ACCESS_SURFACE_FLINGER permission.
     */
    void destroyDisplay(IBinder display);

    /* get stable IDs for connected physical displays.
     */
    long[] getPhysicalDisplayIds();

    long getPrimaryPhysicalDisplayId();

    /* get token for a physical display given its stable ID obtained via getPhysicalDisplayIds or a
     * DisplayEventReceiver hotplug event.
     */
    @nullable IBinder getPhysicalDisplayToken(long displayId);

    /**
     * Capture the specified screen. This requires READ_FRAME_BUFFER
     * permission.  This function will fail if there is a secure window on
+5 −39
Original line number Diff line number Diff line
@@ -138,40 +138,6 @@ public:
            VsyncSource vsyncSource = eVsyncSourceApp,
            EventRegistrationFlags eventRegistration = {}) = 0;

    /* create a virtual display
     * requires ACCESS_SURFACE_FLINGER permission.
     */
    virtual sp<IBinder> createDisplay(const String8& displayName,
            bool secure) = 0;

    /* destroy a virtual display
     * requires ACCESS_SURFACE_FLINGER permission.
     */
    virtual void destroyDisplay(const sp<IBinder>& display) = 0;

    /* get stable IDs for connected physical displays.
     */
    virtual std::vector<PhysicalDisplayId> getPhysicalDisplayIds() const = 0;

    virtual status_t getPrimaryPhysicalDisplayId(PhysicalDisplayId*) const = 0;

    // TODO(b/74619554): Remove this stopgap once the framework is display-agnostic.
    std::optional<PhysicalDisplayId> getInternalDisplayId() const {
        const auto displayIds = getPhysicalDisplayIds();
        return displayIds.empty() ? std::nullopt : std::make_optional(displayIds.front());
    }

    /* get token for a physical display given its stable ID obtained via getPhysicalDisplayIds or a
     * DisplayEventReceiver hotplug event.
     */
    virtual sp<IBinder> getPhysicalDisplayToken(PhysicalDisplayId displayId) const = 0;

    // TODO(b/74619554): Remove this stopgap once the framework is display-agnostic.
    sp<IBinder> getInternalDisplayToken() const {
        const auto displayId = getInternalDisplayId();
        return displayId ? getPhysicalDisplayToken(*displayId) : nullptr;
    }

    /* open/close transactions. requires ACCESS_SURFACE_FLINGER permission */
    virtual status_t setTransactionState(
            const FrameTimelineInfo& frameTimelineInfo, const Vector<ComposerState>& state,
@@ -597,9 +563,9 @@ public:
        CREATE_CONNECTION,
        GET_STATIC_DISPLAY_INFO,
        CREATE_DISPLAY_EVENT_CONNECTION,
        CREATE_DISPLAY,
        DESTROY_DISPLAY,
        GET_PHYSICAL_DISPLAY_TOKEN,
        CREATE_DISPLAY,             // Deprecated. Autogenerated by .aidl now.
        DESTROY_DISPLAY,            // Deprecated. Autogenerated by .aidl now.
        GET_PHYSICAL_DISPLAY_TOKEN, // Deprecated. Autogenerated by .aidl now.
        SET_TRANSACTION_STATE,
        AUTHENTICATE_SURFACE,
        GET_SUPPORTED_FRAME_TIMESTAMPS,
@@ -627,7 +593,7 @@ public:
        GET_PROTECTED_CONTENT_SUPPORT,
        IS_WIDE_COLOR_DISPLAY,
        GET_DISPLAY_NATIVE_PRIMARIES,
        GET_PHYSICAL_DISPLAY_IDS,
        GET_PHYSICAL_DISPLAY_IDS, // Deprecated. Autogenerated by .aidl now.
        ADD_REGION_SAMPLING_LISTENER,
        REMOVE_REGION_SAMPLING_LISTENER,
        SET_DESIRED_DISPLAY_MODE_SPECS,
@@ -659,7 +625,7 @@ public:
        REMOVE_TUNNEL_MODE_ENABLED_LISTENER,
        ADD_WINDOW_INFOS_LISTENER,
        REMOVE_WINDOW_INFOS_LISTENER,
        GET_PRIMARY_PHYSICAL_DISPLAY_ID,
        GET_PRIMARY_PHYSICAL_DISPLAY_ID, // Deprecated. Autogenerated by .aidl now.
        GET_DISPLAY_DECORATION_SUPPORT,
        GET_BOOT_DISPLAY_MODE_SUPPORT,
        SET_BOOT_DISPLAY_MODE,
Loading