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

Commit 4a46ee57 authored by Mathias Agopian's avatar Mathias Agopian Committed by Android (Google) Code Review
Browse files

Merge "Improve the VSYNC api a bit."

parents 7554c57c 6779df2c
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -107,6 +107,12 @@ status_t NativeDisplayEventReceiver::scheduleVsync() {
            return status_t(n);
        }

        status_t status = mReceiver.requestNextVsync();
        if (status) {
            LOGW("Failed to request next vsync, status=%d", status);
            return status;
        }

        if (!mFdCallbackRegistered) {
            int rc = mLooper->addFd(mReceiver.getFd(), 0, ALOOPER_EVENT_INPUT,
                    handleReceiveCallback, this);
+14 −0
Original line number Diff line number Diff line
@@ -94,6 +94,20 @@ public:
     */
    ssize_t getEvents(Event* events, size_t count);

    /*
     * setVsyncRate() sets the Event::VSync delivery rate. A value of
     * 1 returns every Event::VSync. A value of 2 returns every other event,
     * etc... a value of 0 returns no event unless  requestNextVsync() has
     * been called.
     */
    status_t setVsyncRate(uint32_t count);

    /*
     * requestNextVsync() schedules the next Event::VSync. It has no effect
     * if the vsync rate is > 0.
     */
    status_t requestNextVsync();

private:
    sp<IDisplayEventConnection> mEventConnection;
    sp<BitTube> mDataChannel;
+18 −0
Original line number Diff line number Diff line
@@ -33,9 +33,27 @@ class BitTube;
class IDisplayEventConnection : public IInterface
{
public:

    DECLARE_META_INTERFACE(DisplayEventConnection);

    /*
     * getDataChannel() returns a BitTube where to receive the events from
     */
    virtual sp<BitTube> getDataChannel() const = 0;

    /*
     * setVsyncRate() sets the vsync event delivery rate. A value of
     * 1 returns every vsync events. A value of 2 returns every other events,
     * etc... a value of 0 returns no event unless  requestNextVsync() has
     * been called.
     */
    virtual void setVsyncRate(uint32_t count) = 0;

    /*
     * requestNextVsync() schedules the next vsync event. It has no effect
     * if the vsync rate is > 0.
     */
    virtual void requestNextVsync() = 0;    // asynchronous
};

// ----------------------------------------------------------------------------
+20 −0
Original line number Diff line number Diff line
@@ -58,6 +58,26 @@ int DisplayEventReceiver::getFd() const {
    return mDataChannel->getFd();
}

status_t DisplayEventReceiver::setVsyncRate(uint32_t count) {
    if (int32_t(count) < 0)
        return BAD_VALUE;

    if (mEventConnection != NULL) {
        mEventConnection->setVsyncRate(count);
        return NO_ERROR;
    }
    return NO_INIT;
}

status_t DisplayEventReceiver::requestNextVsync() {
    if (mEventConnection != NULL) {
        mEventConnection->requestNextVsync();
        return NO_ERROR;
    }
    return NO_INIT;
}


ssize_t DisplayEventReceiver::getEvents(DisplayEventReceiver::Event* events,
        size_t count) {
    ssize_t size = mDataChannel->read(events, sizeof(events[0])*count);
+25 −0
Original line number Diff line number Diff line
@@ -32,6 +32,8 @@ namespace android {

enum {
    GET_DATA_CHANNEL = IBinder::FIRST_CALL_TRANSACTION,
    SET_VSYNC_RATE,
    REQUEST_NEXT_VSYNC
};

class BpDisplayEventConnection : public BpInterface<IDisplayEventConnection>
@@ -49,6 +51,19 @@ public:
        remote()->transact(GET_DATA_CHANNEL, data, &reply);
        return new BitTube(reply);
    }

    virtual void setVsyncRate(uint32_t count) {
        Parcel data, reply;
        data.writeInterfaceToken(IDisplayEventConnection::getInterfaceDescriptor());
        data.writeInt32(count);
        remote()->transact(SET_VSYNC_RATE, data, &reply);
    }

    virtual void requestNextVsync() {
        Parcel data, reply;
        data.writeInterfaceToken(IDisplayEventConnection::getInterfaceDescriptor());
        remote()->transact(REQUEST_NEXT_VSYNC, data, &reply, IBinder::FLAG_ONEWAY);
    }
};

IMPLEMENT_META_INTERFACE(DisplayEventConnection, "android.gui.DisplayEventConnection");
@@ -65,6 +80,16 @@ status_t BnDisplayEventConnection::onTransact(
            channel->writeToParcel(reply);
            return NO_ERROR;
        } break;
        case SET_VSYNC_RATE: {
            CHECK_INTERFACE(IDisplayEventConnection, data, reply);
            setVsyncRate(data.readInt32());
            return NO_ERROR;
        } break;
        case REQUEST_NEXT_VSYNC: {
            CHECK_INTERFACE(IDisplayEventConnection, data, reply);
            requestNextVsync();
            return NO_ERROR;
        } break;
    }
    return BBinder::onTransact(code, data, reply, flags);
}
Loading