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

Commit 42b54696 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes I2f531131,Ibaaca2a1,Ib0cba4c7,I5ea748b8,I046e3f07, ... into oc-dev

* changes:
  libgui: Make IDisplayEventConn... a SafeInterface
  libgui: Remove RefBase from BitTube
  libgui: Make BitTube Parcelable and use unique_fd
  libgui: Format BitTube and move into gui namespace
  libgui: Move BitTube out of system include dir
  libgui: Normalize IDisplayEventConnection methods
  libgui: Format IDisplayEventConnection
parents 0005f132 2d191c30
Loading
Loading
Loading
Loading
+7 −6
Original line number Original line Diff line number Diff line
@@ -32,9 +32,12 @@ namespace android {


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


class BitTube;
class IDisplayEventConnection;
class IDisplayEventConnection;


namespace gui {
class BitTube;
} // namespace gui

static inline constexpr uint32_t fourcc(char c1, char c2, char c3, char c4) {
static inline constexpr uint32_t fourcc(char c1, char c2, char c3, char c4) {
    return static_cast<uint32_t>(c1) << 24 |
    return static_cast<uint32_t>(c1) << 24 |
        static_cast<uint32_t>(c2) << 16 |
        static_cast<uint32_t>(c2) << 16 |
@@ -108,15 +111,13 @@ public:
     * should be destroyed and getEvents() shouldn't be called again.
     * should be destroyed and getEvents() shouldn't be called again.
     */
     */
    ssize_t getEvents(Event* events, size_t count);
    ssize_t getEvents(Event* events, size_t count);
    static ssize_t getEvents(const sp<BitTube>& dataChannel,
    static ssize_t getEvents(gui::BitTube* dataChannel, Event* events, size_t count);
            Event* events, size_t count);


    /*
    /*
     * sendEvents write events to the queue and returns how many events were
     * sendEvents write events to the queue and returns how many events were
     * written.
     * written.
     */
     */
    static ssize_t sendEvents(const sp<BitTube>& dataChannel,
    static ssize_t sendEvents(gui::BitTube* dataChannel, Event const* events, size_t count);
            Event const* events, size_t count);


    /*
    /*
     * setVsyncRate() sets the Event::VSync delivery rate. A value of
     * setVsyncRate() sets the Event::VSync delivery rate. A value of
@@ -134,7 +135,7 @@ public:


private:
private:
    sp<IDisplayEventConnection> mEventConnection;
    sp<IDisplayEventConnection> mEventConnection;
    sp<BitTube> mDataChannel;
    std::unique_ptr<gui::BitTube> mDataChannel;
};
};


// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
+24 −32
Original line number Original line Diff line number Diff line
@@ -14,60 +14,52 @@
 * limitations under the License.
 * limitations under the License.
 */
 */


#ifndef ANDROID_GUI_IDISPLAY_EVENT_CONNECTION_H
#pragma once
#define ANDROID_GUI_IDISPLAY_EVENT_CONNECTION_H


#include <stdint.h>
#include <binder/IInterface.h>
#include <sys/types.h>
#include <binder/SafeInterface.h>


#include <utils/Errors.h>
#include <utils/Errors.h>
#include <utils/RefBase.h>


#include <binder/IInterface.h>
#include <cstdint>


namespace android {
namespace android {
// ----------------------------------------------------------------------------


namespace gui {
class BitTube;
class BitTube;
} // namespace gui


class IDisplayEventConnection : public IInterface
class IDisplayEventConnection : public IInterface {
{
public:
public:

    DECLARE_META_INTERFACE(DisplayEventConnection)
    DECLARE_META_INTERFACE(DisplayEventConnection)


    /*
    /*
     * getDataChannel() returns a BitTube where to receive the events from
     * stealReceiveChannel() returns a BitTube to receive events from. Only the receive file
     * descriptor of outChannel will be initialized, and this effectively "steals" the receive
     * channel from the remote end (such that the remote end can only use its send channel).
     */
     */
    virtual sp<BitTube> getDataChannel() const = 0;
    virtual status_t stealReceiveChannel(gui::BitTube* outChannel) = 0;


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


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


// ----------------------------------------------------------------------------
class BnDisplayEventConnection : public SafeBnInterface<IDisplayEventConnection> {

class BnDisplayEventConnection : public BnInterface<IDisplayEventConnection>
{
public:
public:
    virtual status_t    onTransact( uint32_t code,
    BnDisplayEventConnection()
                                    const Parcel& data,
          : SafeBnInterface<IDisplayEventConnection>("BnDisplayEventConnection") {}
                                    Parcel* reply,
                                    uint32_t flags = 0);
};


// ----------------------------------------------------------------------------
    status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply,
}; // namespace android
                        uint32_t flags = 0) override;
};


#endif // ANDROID_GUI_IDISPLAY_EVENT_CONNECTION_H
} // namespace android
+4 −0
Original line number Original line Diff line number Diff line
@@ -126,6 +126,10 @@ cc_library_shared {
        "android.hidl.token@1.0-utils",
        "android.hidl.token@1.0-utils",
        "android.hardware.graphics.bufferqueue@1.0",
        "android.hardware.graphics.bufferqueue@1.0",
    ],
    ],

    export_include_dirs: [
        "include",
    ],
}
}


subdirs = ["tests"]
subdirs = ["tests"]
+55 −71
Original line number Original line Diff line number Diff line
@@ -17,8 +17,8 @@
#include <private/gui/BitTube.h>
#include <private/gui/BitTube.h>


#include <stdint.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/socket.h>
#include <sys/types.h>


#include <fcntl.h>
#include <fcntl.h>
#include <unistd.h>
#include <unistd.h>
@@ -27,45 +27,21 @@


#include <binder/Parcel.h>
#include <binder/Parcel.h>



namespace android {
namespace android {
// ----------------------------------------------------------------------------
namespace gui {


// Socket buffer size.  The default is typically about 128KB, which is much larger than
// Socket buffer size.  The default is typically about 128KB, which is much larger than we really
// we really need.  So we make it smaller.
// need. So we make it smaller.
static const size_t DEFAULT_SOCKET_BUFFER_SIZE = 4 * 1024;
static const size_t DEFAULT_SOCKET_BUFFER_SIZE = 4 * 1024;



BitTube::BitTube(size_t bufsize) {
BitTube::BitTube()
    : mSendFd(-1), mReceiveFd(-1)
{
    init(DEFAULT_SOCKET_BUFFER_SIZE, DEFAULT_SOCKET_BUFFER_SIZE);
}

BitTube::BitTube(size_t bufsize)
    : mSendFd(-1), mReceiveFd(-1)
{
    init(bufsize, bufsize);
    init(bufsize, bufsize);
}
}


BitTube::BitTube(const Parcel& data)
BitTube::BitTube(DefaultSizeType) : BitTube(DEFAULT_SOCKET_BUFFER_SIZE) {}
    : mSendFd(-1), mReceiveFd(-1)
{
    mReceiveFd = dup(data.readFileDescriptor());
    if (mReceiveFd < 0) {
        mReceiveFd = -errno;
        ALOGE("BitTube(Parcel): can't dup filedescriptor (%s)",
                strerror(-mReceiveFd));
    }
}

BitTube::~BitTube()
{
    if (mSendFd >= 0)
        close(mSendFd);


    if (mReceiveFd >= 0)
BitTube::BitTube(const Parcel& data) {
        close(mReceiveFd);
    readFromParcel(&data);
}
}


void BitTube::init(size_t rcvbuf, size_t sndbuf) {
void BitTube::init(size_t rcvbuf, size_t sndbuf) {
@@ -74,39 +50,43 @@ void BitTube::init(size_t rcvbuf, size_t sndbuf) {
        size_t size = DEFAULT_SOCKET_BUFFER_SIZE;
        size_t size = DEFAULT_SOCKET_BUFFER_SIZE;
        setsockopt(sockets[0], SOL_SOCKET, SO_RCVBUF, &rcvbuf, sizeof(rcvbuf));
        setsockopt(sockets[0], SOL_SOCKET, SO_RCVBUF, &rcvbuf, sizeof(rcvbuf));
        setsockopt(sockets[1], SOL_SOCKET, SO_SNDBUF, &sndbuf, sizeof(sndbuf));
        setsockopt(sockets[1], SOL_SOCKET, SO_SNDBUF, &sndbuf, sizeof(sndbuf));
        // sine we don't use the "return channel", we keep it small...
        // since we don't use the "return channel", we keep it small...
        setsockopt(sockets[0], SOL_SOCKET, SO_SNDBUF, &size, sizeof(size));
        setsockopt(sockets[0], SOL_SOCKET, SO_SNDBUF, &size, sizeof(size));
        setsockopt(sockets[1], SOL_SOCKET, SO_RCVBUF, &size, sizeof(size));
        setsockopt(sockets[1], SOL_SOCKET, SO_RCVBUF, &size, sizeof(size));
        fcntl(sockets[0], F_SETFL, O_NONBLOCK);
        fcntl(sockets[0], F_SETFL, O_NONBLOCK);
        fcntl(sockets[1], F_SETFL, O_NONBLOCK);
        fcntl(sockets[1], F_SETFL, O_NONBLOCK);
        mReceiveFd = sockets[0];
        mReceiveFd.reset(sockets[0]);
        mSendFd = sockets[1];
        mSendFd.reset(sockets[1]);
    } else {
    } else {
        mReceiveFd = -errno;
        mReceiveFd.reset();
        ALOGE("BitTube: pipe creation failed (%s)", strerror(-mReceiveFd));
        ALOGE("BitTube: pipe creation failed (%s)", strerror(errno));
    }
    }
}
}


status_t BitTube::initCheck() const
status_t BitTube::initCheck() const {
{
    if (mReceiveFd < 0) {
    if (mReceiveFd < 0) {
        return status_t(mReceiveFd);
        return status_t(mReceiveFd);
    }
    }
    return NO_ERROR;
    return NO_ERROR;
}
}


int BitTube::getFd() const
int BitTube::getFd() const {
{
    return mReceiveFd;
    return mReceiveFd;
}
}


int BitTube::getSendFd() const
int BitTube::getSendFd() const {
{
    return mSendFd;
    return mSendFd;
}
}


ssize_t BitTube::write(void const* vaddr, size_t size)
base::unique_fd BitTube::moveReceiveFd() {
{
    return std::move(mReceiveFd);
}

void BitTube::setReceiveFd(base::unique_fd&& receiveFd) {
    mReceiveFd = std::move(receiveFd);
}

ssize_t BitTube::write(void const* vaddr, size_t size) {
    ssize_t err, len;
    ssize_t err, len;
    do {
    do {
        len = ::send(mSendFd, vaddr, size, MSG_DONTWAIT | MSG_NOSIGNAL);
        len = ::send(mSendFd, vaddr, size, MSG_DONTWAIT | MSG_NOSIGNAL);
@@ -116,62 +96,66 @@ ssize_t BitTube::write(void const* vaddr, size_t size)
    return err == 0 ? len : -err;
    return err == 0 ? len : -err;
}
}


ssize_t BitTube::read(void* vaddr, size_t size)
ssize_t BitTube::read(void* vaddr, size_t size) {
{
    ssize_t err, len;
    ssize_t err, len;
    do {
    do {
        len = ::recv(mReceiveFd, vaddr, size, MSG_DONTWAIT);
        len = ::recv(mReceiveFd, vaddr, size, MSG_DONTWAIT);
        err = len < 0 ? errno : 0;
        err = len < 0 ? errno : 0;
    } while (err == EINTR);
    } while (err == EINTR);
    if (err == EAGAIN || err == EWOULDBLOCK) {
    if (err == EAGAIN || err == EWOULDBLOCK) {
        // EAGAIN means that we have non-blocking I/O but there was
        // EAGAIN means that we have non-blocking I/O but there was no data to be read. Nothing the
        // no data to be read. Nothing the client should care about.
        // client should care about.
        return 0;
        return 0;
    }
    }
    return err == 0 ? len : -err;
    return err == 0 ? len : -err;
}
}


status_t BitTube::writeToParcel(Parcel* reply) const
status_t BitTube::writeToParcel(Parcel* reply) const {
{
    if (mReceiveFd < 0) return -EINVAL;
    if (mReceiveFd < 0)
        return -EINVAL;


    status_t result = reply->writeDupFileDescriptor(mReceiveFd);
    status_t result = reply->writeDupFileDescriptor(mReceiveFd);
    close(mReceiveFd);
    mReceiveFd.reset();
    mReceiveFd = -1;
    return result;
    return result;
}
}


status_t BitTube::readFromParcel(const Parcel* parcel) {
    mReceiveFd.reset(dup(parcel->readFileDescriptor()));
    if (mReceiveFd < 0) {
        mReceiveFd.reset();
        int error = errno;
        ALOGE("BitTube::readFromParcel: can't dup file descriptor (%s)", strerror(error));
        return -error;
    }
    return NO_ERROR;
}


ssize_t BitTube::sendObjects(const sp<BitTube>& tube,
ssize_t BitTube::sendObjects(BitTube* tube, void const* events, size_t count, size_t objSize) {
        void const* events, size_t count, size_t objSize)
{
    const char* vaddr = reinterpret_cast<const char*>(events);
    const char* vaddr = reinterpret_cast<const char*>(events);
    ssize_t size = tube->write(vaddr, count * objSize);
    ssize_t size = tube->write(vaddr, count * objSize);


    // should never happen because of SOCK_SEQPACKET
    // should never happen because of SOCK_SEQPACKET
    LOG_ALWAYS_FATAL_IF((size >= 0) && (size % static_cast<ssize_t>(objSize)),
    LOG_ALWAYS_FATAL_IF((size >= 0) && (size % static_cast<ssize_t>(objSize)),
            "BitTube::sendObjects(count=%zu, size=%zu), res=%zd (partial events were sent!)",
                        "BitTube::sendObjects(count=%zu, size=%zu), res=%zd (partial events were "
                        "sent!)",
                        count, objSize, size);
                        count, objSize, size);


    // ALOGE_IF(size<0, "error %d sending %d events", size, count);
    // ALOGE_IF(size<0, "error %d sending %d events", size, count);
    return size < 0 ? size : size / static_cast<ssize_t>(objSize);
    return size < 0 ? size : size / static_cast<ssize_t>(objSize);
}
}


ssize_t BitTube::recvObjects(const sp<BitTube>& tube,
ssize_t BitTube::recvObjects(BitTube* tube, void* events, size_t count, size_t objSize) {
        void* events, size_t count, size_t objSize)
{
    char* vaddr = reinterpret_cast<char*>(events);
    char* vaddr = reinterpret_cast<char*>(events);
    ssize_t size = tube->read(vaddr, count * objSize);
    ssize_t size = tube->read(vaddr, count * objSize);


    // should never happen because of SOCK_SEQPACKET
    // should never happen because of SOCK_SEQPACKET
    LOG_ALWAYS_FATAL_IF((size >= 0) && (size % static_cast<ssize_t>(objSize)),
    LOG_ALWAYS_FATAL_IF((size >= 0) && (size % static_cast<ssize_t>(objSize)),
            "BitTube::recvObjects(count=%zu, size=%zu), res=%zd (partial events were received!)",
                        "BitTube::recvObjects(count=%zu, size=%zu), res=%zd (partial events were "
                        "received!)",
                        count, objSize, size);
                        count, objSize, size);


    // ALOGE_IF(size<0, "error %d receiving %d events", size, count);
    // ALOGE_IF(size<0, "error %d receiving %d events", size, count);
    return size < 0 ? size : size / static_cast<ssize_t>(objSize);
    return size < 0 ? size : size / static_cast<ssize_t>(objSize);
}
}


// ----------------------------------------------------------------------------
} // namespace gui
}; // namespace android
} // namespace android
+7 −6
Original line number Original line Diff line number Diff line
@@ -37,7 +37,8 @@ DisplayEventReceiver::DisplayEventReceiver() {
    if (sf != NULL) {
    if (sf != NULL) {
        mEventConnection = sf->createDisplayEventConnection();
        mEventConnection = sf->createDisplayEventConnection();
        if (mEventConnection != NULL) {
        if (mEventConnection != NULL) {
            mDataChannel = mEventConnection->getDataChannel();
            mDataChannel = std::make_unique<gui::BitTube>();
            mEventConnection->stealReceiveChannel(mDataChannel.get());
        }
        }
    }
    }
}
}
@@ -80,19 +81,19 @@ status_t DisplayEventReceiver::requestNextVsync() {


ssize_t DisplayEventReceiver::getEvents(DisplayEventReceiver::Event* events,
ssize_t DisplayEventReceiver::getEvents(DisplayEventReceiver::Event* events,
        size_t count) {
        size_t count) {
    return DisplayEventReceiver::getEvents(mDataChannel, events, count);
    return DisplayEventReceiver::getEvents(mDataChannel.get(), events, count);
}
}


ssize_t DisplayEventReceiver::getEvents(const sp<BitTube>& dataChannel,
ssize_t DisplayEventReceiver::getEvents(gui::BitTube* dataChannel,
        Event* events, size_t count)
        Event* events, size_t count)
{
{
    return BitTube::recvObjects(dataChannel, events, count);
    return gui::BitTube::recvObjects(dataChannel, events, count);
}
}


ssize_t DisplayEventReceiver::sendEvents(const sp<BitTube>& dataChannel,
ssize_t DisplayEventReceiver::sendEvents(gui::BitTube* dataChannel,
        Event const* events, size_t count)
        Event const* events, size_t count)
{
{
    return BitTube::sendObjects(dataChannel, events, count);
    return gui::BitTube::sendObjects(dataChannel, events, count);
}
}


// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
Loading