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

Commit 3643f74c authored by Dan Stoza's avatar Dan Stoza Committed by android-build-merger
Browse files

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

am: 42b54696

Change-Id: Ifc5e39570cbe69eb26820ba8abc482fbe5744306
parents 0730b35b 42b54696
Loading
Loading
Loading
Loading
+7 −6
Original line number Diff line number Diff line
@@ -32,9 +32,12 @@ namespace android {

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

class BitTube;
class IDisplayEventConnection;

namespace gui {
class BitTube;
} // namespace gui

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

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

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

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

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

#ifndef ANDROID_GUI_IDISPLAY_EVENT_CONNECTION_H
#define ANDROID_GUI_IDISPLAY_EVENT_CONNECTION_H
#pragma once

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

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

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

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

namespace gui {
class BitTube;
} // namespace gui

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

    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
     * 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.
     * setVsyncRate() sets the vsync event delivery rate. A value of 1 returns every vsync event.
     * A value of 2 returns every other event, etc. A value of 0 returns no event unless
     * requestNextVsync() has 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
     * if the vsync rate is > 0.
     * requestNextVsync() schedules the next vsync event. It has no effect if the vsync rate is > 0.
     */
    virtual void requestNextVsync() = 0;    // asynchronous
    virtual void requestNextVsync() = 0; // Asynchronous
};

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

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

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

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

    export_include_dirs: [
        "include",
    ],
}

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

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

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

#include <binder/Parcel.h>


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

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


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

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

BitTube::BitTube(const Parcel& data)
    : 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);
BitTube::BitTube(DefaultSizeType) : BitTube(DEFAULT_SOCKET_BUFFER_SIZE) {}

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

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;
        setsockopt(sockets[0], SOL_SOCKET, SO_RCVBUF, &rcvbuf, sizeof(rcvbuf));
        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[1], SOL_SOCKET, SO_RCVBUF, &size, sizeof(size));
        fcntl(sockets[0], F_SETFL, O_NONBLOCK);
        fcntl(sockets[1], F_SETFL, O_NONBLOCK);
        mReceiveFd = sockets[0];
        mSendFd = sockets[1];
        mReceiveFd.reset(sockets[0]);
        mSendFd.reset(sockets[1]);
    } else {
        mReceiveFd = -errno;
        ALOGE("BitTube: pipe creation failed (%s)", strerror(-mReceiveFd));
        mReceiveFd.reset();
        ALOGE("BitTube: pipe creation failed (%s)", strerror(errno));
    }
}

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

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

int BitTube::getSendFd() const
{
int BitTube::getSendFd() const {
    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;
    do {
        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;
}

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

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

    status_t result = reply->writeDupFileDescriptor(mReceiveFd);
    close(mReceiveFd);
    mReceiveFd = -1;
    mReceiveFd.reset();
    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,
        void const* events, size_t count, size_t objSize)
{
ssize_t BitTube::sendObjects(BitTube* tube, void const* events, size_t count, size_t objSize) {
    const char* vaddr = reinterpret_cast<const char*>(events);
    ssize_t size = tube->write(vaddr, count * objSize);

    // should never happen because of SOCK_SEQPACKET
    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);

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

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

    // should never happen because of SOCK_SEQPACKET
    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);

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

// ----------------------------------------------------------------------------
}; // namespace android
} // namespace gui
} // namespace android
+7 −6
Original line number Diff line number Diff line
@@ -37,7 +37,8 @@ DisplayEventReceiver::DisplayEventReceiver() {
    if (sf != NULL) {
        mEventConnection = sf->createDisplayEventConnection();
        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,
        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)
{
    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)
{
    return BitTube::sendObjects(dataChannel, events, count);
    return gui::BitTube::sendObjects(dataChannel, events, count);
}

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