diff options
author | 2017-03-31 16:30:42 -0700 | |
---|---|---|
committer | 2017-04-06 11:42:52 -0700 | |
commit | 27c8115510cebda13cbe24fd4caa946ea9c5003c (patch) | |
tree | 1f905493d9c2122f921ee78b3c18b24e70222b79 | |
parent | 1e438d2c9ce366ef98452ed6e50699196433bf2c (diff) |
libgui: Format BitTube and move into gui namespace
Reformats BitTube using the framework default .clang-format and moves
it into the android::gui namespace.
Test: m -j + manual testing
Change-Id: I5ea748b809f37c2ec4dcfb41e7b84daf7a084368
-rw-r--r-- | include/gui/DisplayEventReceiver.h | 11 | ||||
-rw-r--r-- | include/gui/IDisplayEventConnection.h | 4 | ||||
-rw-r--r-- | libs/gui/BitTube.cpp | 93 | ||||
-rw-r--r-- | libs/gui/DisplayEventReceiver.cpp | 8 | ||||
-rw-r--r-- | libs/gui/IDisplayEventConnection.cpp | 6 | ||||
-rw-r--r-- | libs/gui/include/private/gui/BitTube.h | 38 | ||||
-rw-r--r-- | services/surfaceflinger/EventThread.cpp | 4 | ||||
-rw-r--r-- | services/surfaceflinger/EventThread.h | 4 | ||||
-rw-r--r-- | services/surfaceflinger/MessageQueue.h | 2 |
9 files changed, 74 insertions, 96 deletions
diff --git a/include/gui/DisplayEventReceiver.h b/include/gui/DisplayEventReceiver.h index cb9b373392..6d1ab5d2d8 100644 --- a/include/gui/DisplayEventReceiver.h +++ b/include/gui/DisplayEventReceiver.h @@ -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,14 +111,14 @@ 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, + static ssize_t getEvents(const sp<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, + static ssize_t sendEvents(const sp<gui::BitTube>& dataChannel, Event const* events, size_t count); /* @@ -134,7 +137,7 @@ public: private: sp<IDisplayEventConnection> mEventConnection; - sp<BitTube> mDataChannel; + sp<gui::BitTube> mDataChannel; }; // ---------------------------------------------------------------------------- diff --git a/include/gui/IDisplayEventConnection.h b/include/gui/IDisplayEventConnection.h index ebebfbe57e..21b53fe7e4 100644 --- a/include/gui/IDisplayEventConnection.h +++ b/include/gui/IDisplayEventConnection.h @@ -25,7 +25,9 @@ namespace android { +namespace gui { class BitTube; +} // namespace gui class IDisplayEventConnection : public IInterface { public: @@ -34,7 +36,7 @@ public: /* * getDataChannel() returns a BitTube where to receive the events from */ - virtual status_t getDataChannel(sp<BitTube>* outChannel) const = 0; + virtual status_t getDataChannel(sp<gui::BitTube>* outChannel) const = 0; /* * setVsyncRate() sets the vsync event delivery rate. A value of 1 returns every vsync event. diff --git a/libs/gui/BitTube.cpp b/libs/gui/BitTube.cpp index 51a8d67118..63f594bf8b 100644 --- a/libs/gui/BitTube.cpp +++ b/libs/gui/BitTube.cpp @@ -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,33 @@ #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) -{ +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) : mSendFd(-1), mReceiveFd(-1) { init(bufsize, bufsize); } -BitTube::BitTube(const Parcel& data) - : mSendFd(-1), mReceiveFd(-1) -{ +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)); + ALOGE("BitTube(Parcel): can't dup filedescriptor (%s)", strerror(-mReceiveFd)); } } -BitTube::~BitTube() -{ - if (mSendFd >= 0) - close(mSendFd); +BitTube::~BitTube() { + if (mSendFd >= 0) close(mSendFd); - if (mReceiveFd >= 0) - close(mReceiveFd); + if (mReceiveFd >= 0) close(mReceiveFd); } void BitTube::init(size_t rcvbuf, size_t sndbuf) { @@ -74,7 +62,7 @@ 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); @@ -87,26 +75,22 @@ void BitTube::init(size_t rcvbuf, size_t sndbuf) { } } -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) -{ +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,25 +100,22 @@ 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); @@ -142,36 +123,34 @@ status_t BitTube::writeToParcel(Parcel* reply) const return result; } - -ssize_t BitTube::sendObjects(const sp<BitTube>& tube, - void const* events, size_t count, size_t objSize) -{ +ssize_t BitTube::sendObjects(const sp<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); + 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!)", - count, objSize, size); + "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); + // 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(const sp<BitTube>& tube, void* events, size_t count, size_t objSize) { 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 LOG_ALWAYS_FATAL_IF((size >= 0) && (size % static_cast<ssize_t>(objSize)), - "BitTube::recvObjects(count=%zu, size=%zu), res=%zd (partial events were received!)", - count, objSize, size); + "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); + // 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 diff --git a/libs/gui/DisplayEventReceiver.cpp b/libs/gui/DisplayEventReceiver.cpp index 16b06e9a6e..a3ae68c565 100644 --- a/libs/gui/DisplayEventReceiver.cpp +++ b/libs/gui/DisplayEventReceiver.cpp @@ -83,16 +83,16 @@ ssize_t DisplayEventReceiver::getEvents(DisplayEventReceiver::Event* events, return DisplayEventReceiver::getEvents(mDataChannel, events, count); } -ssize_t DisplayEventReceiver::getEvents(const sp<BitTube>& dataChannel, +ssize_t DisplayEventReceiver::getEvents(const sp<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(const sp<gui::BitTube>& dataChannel, Event const* events, size_t count) { - return BitTube::sendObjects(dataChannel, events, count); + return gui::BitTube::sendObjects(dataChannel, events, count); } // --------------------------------------------------------------------------- diff --git a/libs/gui/IDisplayEventConnection.cpp b/libs/gui/IDisplayEventConnection.cpp index 2de2f8a2f4..d3ee39c16f 100644 --- a/libs/gui/IDisplayEventConnection.cpp +++ b/libs/gui/IDisplayEventConnection.cpp @@ -31,11 +31,11 @@ public: ~BpDisplayEventConnection() override; - status_t getDataChannel(sp<BitTube>* outChannel) const override { + status_t getDataChannel(sp<gui::BitTube>* outChannel) const override { Parcel data, reply; data.writeInterfaceToken(IDisplayEventConnection::getInterfaceDescriptor()); remote()->transact(GET_DATA_CHANNEL, data, &reply); - *outChannel = new BitTube(reply); + *outChannel = new gui::BitTube(reply); return NO_ERROR; } @@ -65,7 +65,7 @@ status_t BnDisplayEventConnection::onTransact(uint32_t code, const Parcel& data, switch (code) { case GET_DATA_CHANNEL: { CHECK_INTERFACE(IDisplayEventConnection, data, reply); - sp<BitTube> channel; + sp<gui::BitTube> channel; getDataChannel(&channel); channel->writeToParcel(reply); return NO_ERROR; diff --git a/libs/gui/include/private/gui/BitTube.h b/libs/gui/include/private/gui/BitTube.h index 9d65fad228..1a77e63be2 100644 --- a/libs/gui/include/private/gui/BitTube.h +++ b/libs/gui/include/private/gui/BitTube.h @@ -14,8 +14,7 @@ * limitations under the License. */ -#ifndef ANDROID_GUI_SENSOR_CHANNEL_H -#define ANDROID_GUI_SENSOR_CHANNEL_H +#pragma once #include <stdint.h> #include <sys/types.h> @@ -25,13 +24,13 @@ #include <utils/RefBase.h> namespace android { -// ---------------------------------------------------------------------------- + class Parcel; -class BitTube : public RefBase -{ -public: +namespace gui { +class BitTube : public RefBase { +public: // creates a BitTube with a default (4KB) send buffer BitTube(); @@ -52,16 +51,14 @@ public: // send objects (sized blobs). All objects are guaranteed to be written or the call fails. template <typename T> - static ssize_t sendObjects(const sp<BitTube>& tube, - T const* events, size_t count) { + static ssize_t sendObjects(const sp<BitTube>& tube, T const* events, size_t count) { return sendObjects(tube, events, count, sizeof(T)); } - // receive objects (sized blobs). If the receiving buffer isn't large enough, - // excess messages are silently discarded. + // receive objects (sized blobs). If the receiving buffer isn't large enough, excess messages + // are silently discarded. template <typename T> - static ssize_t recvObjects(const sp<BitTube>& tube, - T* events, size_t count) { + static ssize_t recvObjects(const sp<BitTube>& tube, T* events, size_t count) { return recvObjects(tube, events, count, sizeof(T)); } @@ -74,21 +71,18 @@ private: // send a message. The write is guaranteed to send the whole message or fail. ssize_t write(void const* vaddr, size_t size); - // receive a message. the passed buffer must be at least as large as the - // write call used to send the message, excess data is silently discarded. + // receive a message. the passed buffer must be at least as large as the write call used to send + // the message, excess data is silently discarded. ssize_t read(void* vaddr, size_t size); int mSendFd; mutable int mReceiveFd; - static ssize_t sendObjects(const sp<BitTube>& tube, - void const* events, size_t count, size_t objSize); + static ssize_t sendObjects(const sp<BitTube>& tube, void const* events, size_t count, + size_t objSize); - static ssize_t recvObjects(const sp<BitTube>& tube, - void* events, size_t count, size_t objSize); + static ssize_t recvObjects(const sp<BitTube>& tube, void* events, size_t count, size_t objSize); }; -// ---------------------------------------------------------------------------- -}; // namespace android - -#endif // ANDROID_GUI_SENSOR_CHANNEL_H +} // namespace gui +} // namespace android diff --git a/services/surfaceflinger/EventThread.cpp b/services/surfaceflinger/EventThread.cpp index 463e60c08b..7e0506b00e 100644 --- a/services/surfaceflinger/EventThread.cpp +++ b/services/surfaceflinger/EventThread.cpp @@ -389,7 +389,7 @@ void EventThread::dump(String8& result) const { EventThread::Connection::Connection( const sp<EventThread>& eventThread) - : count(-1), mEventThread(eventThread), mChannel(new BitTube()) + : count(-1), mEventThread(eventThread), mChannel(new gui::BitTube()) { } @@ -403,7 +403,7 @@ void EventThread::Connection::onFirstRef() { mEventThread->registerDisplayEventConnection(this); } -status_t EventThread::Connection::getDataChannel(sp<BitTube>* outChannel) const { +status_t EventThread::Connection::getDataChannel(sp<gui::BitTube>* outChannel) const { *outChannel = mChannel; return NO_ERROR; } diff --git a/services/surfaceflinger/EventThread.h b/services/surfaceflinger/EventThread.h index c0b5532562..3e057493dd 100644 --- a/services/surfaceflinger/EventThread.h +++ b/services/surfaceflinger/EventThread.h @@ -68,11 +68,11 @@ class EventThread : public Thread, private VSyncSource::Callback { private: virtual ~Connection(); virtual void onFirstRef(); - status_t getDataChannel(sp<BitTube>* outChannel) const override; + status_t getDataChannel(sp<gui::BitTube>* outChannel) const override; status_t setVsyncRate(uint32_t count) override; void requestNextVsync() override; // asynchronous sp<EventThread> const mEventThread; - sp<BitTube> const mChannel; + sp<gui::BitTube> const mChannel; }; public: diff --git a/services/surfaceflinger/MessageQueue.h b/services/surfaceflinger/MessageQueue.h index aed0aa90f2..2bb5fa6580 100644 --- a/services/surfaceflinger/MessageQueue.h +++ b/services/surfaceflinger/MessageQueue.h @@ -81,7 +81,7 @@ class MessageQueue { sp<Looper> mLooper; sp<EventThread> mEventThread; sp<IDisplayEventConnection> mEvents; - sp<BitTube> mEventTube; + sp<gui::BitTube> mEventTube; sp<Handler> mHandler; |