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

Commit f1833853 authored by Dominik Laskowski's avatar Dominik Laskowski
Browse files

SF: Remove layer stack lookup for screencap

GPU virtual displays now have IDs, so the (ambiguous) fallback is no
longer necessary.

Remove PhysicalDisplayId constructor from uint64_t to enforce error
checking at compile time when upcasting or deserializing.

Bug: 162612135
Bug: 182939859
Test: screencap -d <id>
Test: DisplayId_test
Change-Id: I68fa0835cbc915975c7fa40c7d544d9491db9fa2
parent 7b9bf4cb
Loading
Loading
Loading
Loading
+19 −11
Original line number Diff line number Diff line
@@ -123,11 +123,11 @@ public:
        return remote()->transact(BnSurfaceComposer::CAPTURE_DISPLAY, data, &reply);
    }

    status_t captureDisplay(uint64_t displayOrLayerStack,
    status_t captureDisplay(DisplayId displayId,
                            const sp<IScreenCaptureListener>& captureListener) override {
        Parcel data, reply;
        data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
        SAFE_PARCEL(data.writeUint64, displayOrLayerStack);
        SAFE_PARCEL(data.writeUint64, displayId.value);
        SAFE_PARCEL(data.writeStrongBinder, IInterface::asBinder(captureListener));

        return remote()->transact(BnSurfaceComposer::CAPTURE_DISPLAY_BY_ID, data, &reply);
@@ -281,9 +281,14 @@ public:
            NO_ERROR) {
            std::vector<uint64_t> rawIds;
            if (reply.readUint64Vector(&rawIds) == NO_ERROR) {
                std::vector<PhysicalDisplayId> displayIds(rawIds.size());
                std::transform(rawIds.begin(), rawIds.end(), displayIds.begin(),
                               [](uint64_t rawId) { return PhysicalDisplayId(rawId); });
                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;
            }
        }
@@ -1296,12 +1301,15 @@ status_t BnSurfaceComposer::onTransact(
        }
        case CAPTURE_DISPLAY_BY_ID: {
            CHECK_INTERFACE(ISurfaceComposer, data, reply);
            uint64_t displayOrLayerStack = 0;
            uint64_t value;
            SAFE_PARCEL(data.readUint64, &value);
            const auto id = DisplayId::fromValue(value);
            if (!id) return BAD_VALUE;

            sp<IScreenCaptureListener> captureListener;
            SAFE_PARCEL(data.readUint64, &displayOrLayerStack);
            SAFE_PARCEL(data.readStrongBinder, &captureListener);

            return captureDisplay(displayOrLayerStack, captureListener);
            return captureDisplay(*id, captureListener);
        }
        case CAPTURE_LAYERS: {
            CHECK_INTERFACE(ISurfaceComposer, data, reply);
@@ -1368,9 +1376,9 @@ status_t BnSurfaceComposer::onTransact(
        }
        case GET_PHYSICAL_DISPLAY_TOKEN: {
            CHECK_INTERFACE(ISurfaceComposer, data, reply);
            PhysicalDisplayId displayId(data.readUint64());
            sp<IBinder> display = getPhysicalDisplayToken(displayId);
            reply->writeStrongBinder(display);
            const auto id = DisplayId::fromValue<PhysicalDisplayId>(data.readUint64());
            if (!id) return BAD_VALUE;
            reply->writeStrongBinder(getPhysicalDisplayToken(*id));
            return NO_ERROR;
        }
        case GET_DISPLAY_STATE: {
+2 −2
Original line number Diff line number Diff line
@@ -2098,12 +2098,12 @@ status_t ScreenshotClient::captureDisplay(const DisplayCaptureArgs& captureArgs,
    return s->captureDisplay(captureArgs, captureListener);
}

status_t ScreenshotClient::captureDisplay(uint64_t displayOrLayerStack,
status_t ScreenshotClient::captureDisplay(DisplayId displayId,
                                          const sp<IScreenCaptureListener>& captureListener) {
    sp<ISurfaceComposer> s(ComposerService::getComposerService());
    if (s == nullptr) return NO_INIT;

    return s->captureDisplay(displayOrLayerStack, captureListener);
    return s->captureDisplay(displayId, captureListener);
}

status_t ScreenshotClient::captureLayers(const LayerCaptureArgs& captureArgs,
+9 −11
Original line number Diff line number Diff line
@@ -114,6 +114,11 @@ public:

    using EventRegistrationFlags = Flags<EventRegistration>;

    template <typename T>
    struct SpHash {
        size_t operator()(const sp<T>& k) const { return std::hash<T*>()(k.get()); }
    };

    /*
     * Create a connection with SurfaceFlinger.
     */
@@ -237,24 +242,17 @@ public:
     * The subregion can be optionally rotated.  It will also be scaled to
     * match the size of the output buffer.
     */
    virtual status_t captureDisplay(const DisplayCaptureArgs& args,
                                    const sp<IScreenCaptureListener>& captureListener) = 0;
    virtual status_t captureDisplay(const DisplayCaptureArgs&,
                                    const sp<IScreenCaptureListener>&) = 0;

    virtual status_t captureDisplay(uint64_t displayOrLayerStack,
                                    const sp<IScreenCaptureListener>& captureListener) = 0;

    template <class AA>
    struct SpHash {
        size_t operator()(const sp<AA>& k) const { return std::hash<AA*>()(k.get()); }
    };
    virtual status_t captureDisplay(DisplayId, const sp<IScreenCaptureListener>&) = 0;

    /**
     * Capture a subtree of the layer hierarchy, potentially ignoring the root node.
     * This requires READ_FRAME_BUFFER permission. This function will fail if there
     * is a secure window on screen
     */
    virtual status_t captureLayers(const LayerCaptureArgs& args,
                                   const sp<IScreenCaptureListener>& captureListener) = 0;
    virtual status_t captureLayers(const LayerCaptureArgs&, const sp<IScreenCaptureListener>&) = 0;

    /* Clears the frame statistics for animations.
     *
+3 −6
Original line number Diff line number Diff line
@@ -608,12 +608,9 @@ private:

class ScreenshotClient {
public:
    static status_t captureDisplay(const DisplayCaptureArgs& captureArgs,
                                   const sp<IScreenCaptureListener>& captureListener);
    static status_t captureDisplay(uint64_t displayOrLayerStack,
                                   const sp<IScreenCaptureListener>& captureListener);
    static status_t captureLayers(const LayerCaptureArgs& captureArgs,
                                  const sp<IScreenCaptureListener>& captureListener);
    static status_t captureDisplay(const DisplayCaptureArgs&, const sp<IScreenCaptureListener>&);
    static status_t captureDisplay(DisplayId, const sp<IScreenCaptureListener>&);
    static status_t captureLayers(const LayerCaptureArgs&, const sp<IScreenCaptureListener>&);
};

// ---------------------------------------------------------------------------
+7 −9
Original line number Diff line number Diff line
@@ -752,21 +752,19 @@ public:
    }
    status_t setActiveColorMode(const sp<IBinder>& /*display*/,
        ColorMode /*colorMode*/) override { return NO_ERROR; }
    status_t captureDisplay(const DisplayCaptureArgs& /* captureArgs */,
                            const sp<IScreenCaptureListener>& /* captureListener */) override {
        return NO_ERROR;
    }
    void setAutoLowLatencyMode(const sp<IBinder>& /*display*/, bool /*on*/) override {}
    void setGameContentType(const sp<IBinder>& /*display*/, bool /*on*/) override {}
    status_t captureDisplay(uint64_t /*displayOrLayerStack*/,
                            const sp<IScreenCaptureListener>& /* captureListener */) override {

    status_t captureDisplay(const DisplayCaptureArgs&, const sp<IScreenCaptureListener>&) override {
        return NO_ERROR;
    }
    virtual status_t captureLayers(
            const LayerCaptureArgs& /* captureArgs */,
            const sp<IScreenCaptureListener>& /* captureListener */) override {
    status_t captureDisplay(DisplayId, const sp<IScreenCaptureListener>&) override {
        return NO_ERROR;
    }
    status_t captureLayers(const LayerCaptureArgs&, const sp<IScreenCaptureListener>&) override {
        return NO_ERROR;
    }

    status_t clearAnimationFrameStats() override { return NO_ERROR; }
    status_t getAnimationFrameStats(FrameStats* /*outStats*/) const override {
        return NO_ERROR;
Loading