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

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

Merge "Improve the VSYNC api a bit."

parents 7498cd96 478ae5eb
Loading
Loading
Loading
Loading
+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);
}
+14 −5
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@

#include "SurfaceFlinger.h"
#include "DisplayEventConnection.h"
#include "EventThread.h"

// ---------------------------------------------------------------------------

@@ -33,30 +34,38 @@ namespace android {
// ---------------------------------------------------------------------------

DisplayEventConnection::DisplayEventConnection(
        const sp<SurfaceFlinger>& flinger)
    : mFlinger(flinger), mChannel(new BitTube())
        const sp<EventThread>& eventThread)
    : mEventThread(eventThread), mChannel(new BitTube())
{
}

DisplayEventConnection::~DisplayEventConnection() {
    mFlinger->cleanupDisplayEventConnection(this);
    mEventThread->unregisterDisplayEventConnection(this);
}

void DisplayEventConnection::onFirstRef() {
    // nothing to do here for now.
    // NOTE: mEventThread doesn't hold a strong reference on us
    mEventThread->registerDisplayEventConnection(this);
}

sp<BitTube> DisplayEventConnection::getDataChannel() const {
    return mChannel;
}

void DisplayEventConnection::setVsyncRate(uint32_t count) {
    mEventThread->setVsyncRate(count, this);
}

void DisplayEventConnection::requestNextVsync() {
    mEventThread->requestNextVsync(this);
}

status_t DisplayEventConnection::postEvent(const DisplayEventReceiver::Event& event)
{
    ssize_t size = mChannel->write(&event, sizeof(DisplayEventReceiver::Event));
    return size < 0 ? status_t(size) : status_t(NO_ERROR);
}


// ---------------------------------------------------------------------------

}; // namespace android
Loading