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

Commit d8339d96 authored by Dan Stoza's avatar Dan Stoza
Browse files

libgui: Format IConsumerListener

Applies the framework default .clang-format and does a bit of tidying
up (reflowing comments to 100 characters, reordering includes, etc.).

Test: libgui_tests + manual testing
Change-Id: I324493551bca5a6c6a011cbe773021236e11e992
parent df614ae8
Loading
Loading
Loading
Loading
+37 −57
Original line number Diff line number Diff line
@@ -17,25 +17,23 @@
#ifndef ANDROID_GUI_ICONSUMERLISTENER_H
#define ANDROID_GUI_ICONSUMERLISTENER_H

#include <stdint.h>
#include <sys/types.h>
#include <gui/FrameTimestamps.h>

#include <binder/IInterface.h>

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

#include <binder/IInterface.h>

#include <gui/FrameTimestamps.h>
#include <stdint.h>
#include <sys/types.h>

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

class BufferItem;

// ConsumerListener is the interface through which the BufferQueue notifies
// the consumer of events that the consumer may wish to react to.  Because
// the consumer will generally have a mutex that is locked during calls from
// the consumer to the BufferQueue, these calls from the BufferQueue to the
// ConsumerListener is the interface through which the BufferQueue notifies the consumer of events
// that the consumer may wish to react to. Because the consumer will generally have a mutex that is
// locked during calls from the consumer to the BufferQueue, these calls from the BufferQueue to the
// consumer *MUST* be called only when the BufferQueue mutex is NOT locked.

class ConsumerListener : public virtual RefBase {
@@ -46,71 +44,53 @@ public:
    // onDisconnect is called when a producer disconnects from the BufferQueue.
    virtual void onDisconnect() {} /* Asynchronous */

    // onFrameAvailable is called from queueBuffer each time an additional
    // frame becomes available for consumption. This means that frames that
    // are queued while in asynchronous mode only trigger the callback if no
    // previous frames are pending. Frames queued while in synchronous mode
    // always trigger the callback. The item passed to the callback will contain
    // all of the information about the queued frame except for its
    // GraphicBuffer pointer, which will always be null (except if the consumer
    // is SurfaceFlinger).
    // onFrameAvailable is called from queueBuffer each time an additional frame becomes available
    // for consumption. This means that frames that are queued while in asynchronous mode only
    // trigger the callback if no previous frames are pending. Frames queued while in synchronous
    // mode always trigger the callback. The item passed to the callback will contain all of the
    // information about the queued frame except for its GraphicBuffer pointer, which will always be
    // null (except if the consumer is SurfaceFlinger).
    //
    // This is called without any lock held and can be called concurrently
    // by multiple threads.
    // This is called without any lock held and can be called concurrently by multiple threads.
    virtual void onFrameAvailable(const BufferItem& item) = 0; /* Asynchronous */

    // onFrameReplaced is called from queueBuffer if the frame being queued is
    // replacing an existing slot in the queue. Any call to queueBuffer that
    // doesn't call onFrameAvailable will call this callback instead. The item
    // passed to the callback will contain all of the information about the
    // queued frame except for its GraphicBuffer pointer, which will always be
    // null.
    // onFrameReplaced is called from queueBuffer if the frame being queued is replacing an existing
    // slot in the queue. Any call to queueBuffer that doesn't call onFrameAvailable will call this
    // callback instead. The item passed to the callback will contain all of the information about
    // the queued frame except for its GraphicBuffer pointer, which will always be null.
    //
    // This is called without any lock held and can be called concurrently
    // by multiple threads.
    // This is called without any lock held and can be called concurrently by multiple threads.
    virtual void onFrameReplaced(const BufferItem& /* item */) {} /* Asynchronous */

    // onBuffersReleased is called to notify the buffer consumer that the
    // BufferQueue has released its references to one or more GraphicBuffers
    // contained in its slots.  The buffer consumer should then call
    // BufferQueue::getReleasedBuffers to retrieve the list of buffers
    // onBuffersReleased is called to notify the buffer consumer that the BufferQueue has released
    // its references to one or more GraphicBuffers contained in its slots. The buffer consumer
    // should then call BufferQueue::getReleasedBuffers to retrieve the list of buffers.
    //
    // This is called without any lock held and can be called concurrently
    // by multiple threads.
    // This is called without any lock held and can be called concurrently by multiple threads.
    virtual void onBuffersReleased() = 0; /* Asynchronous */

    // onSidebandStreamChanged is called to notify the buffer consumer that the
    // BufferQueue's sideband buffer stream has changed. This is called when a
    // stream is first attached and when it is either detached or replaced by a
    // different stream.
    // onSidebandStreamChanged is called to notify the buffer consumer that the BufferQueue's
    // sideband buffer stream has changed. This is called when a stream is first attached and when
    // it is either detached or replaced by a different stream.
    virtual void onSidebandStreamChanged() = 0; /* Asynchronous */

    // Notifies the consumer of any new producer-side timestamps and
    // returns the combined frame history that hasn't already been retrieved.
    virtual void addAndGetFrameTimestamps(
            const NewFrameEventsEntry* /*newTimestamps*/,
    // Notifies the consumer of any new producer-side timestamps and returns the combined frame
    // history that hasn't already been retrieved.
    virtual void addAndGetFrameTimestamps(const NewFrameEventsEntry* /*newTimestamps*/,
                                          FrameEventHistoryDelta* /*outDelta*/) {}
};


class IConsumerListener : public ConsumerListener, public IInterface
{
class IConsumerListener : public ConsumerListener, public IInterface {
public:
    DECLARE_META_INTERFACE(ConsumerListener)
};

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

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

// ----------------------------------------------------------------------------
}; // namespace android
} // namespace android

#endif // ANDROID_GUI_ICONSUMERLISTENER_H
+21 −26
Original line number Diff line number Diff line
@@ -14,18 +14,17 @@
 * limitations under the License.
 */

#include <stdint.h>
#include <sys/types.h>
#include <gui/IConsumerListener.h>

#include <gui/BufferItem.h>

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

#include <gui/IConsumerListener.h>
#include <gui/BufferItem.h>
#include <stdint.h>
#include <sys/types.h>

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

enum {
    ON_DISCONNECT = IBinder::FIRST_CALL_TRANSACTION,
@@ -35,12 +34,9 @@ enum {
    GET_FRAME_TIMESTAMPS
};

class BpConsumerListener : public BpInterface<IConsumerListener>
{
class BpConsumerListener : public BpInterface<IConsumerListener> {
public:
    explicit BpConsumerListener(const sp<IBinder>& impl)
        : BpInterface<IConsumerListener>(impl) {
    }
    explicit BpConsumerListener(const sp<IBinder>& impl) : BpInterface<IConsumerListener>(impl) {}

    virtual ~BpConsumerListener();

@@ -70,42 +66,41 @@ public:
    }
};

// Out-of-line virtual method definition to trigger vtable emission in this
// translation unit (see clang warning -Wweak-vtables)
// Out-of-line virtual method definition to trigger vtable emission in this translation unit (see
// clang warning -Wweak-vtables)
BpConsumerListener::~BpConsumerListener() {}

IMPLEMENT_META_INTERFACE(ConsumerListener, "android.gui.IConsumerListener");

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

status_t BnConsumerListener::onTransact(
    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
{
status_t BnConsumerListener::onTransact(uint32_t code, const Parcel& data, Parcel* reply,
                                        uint32_t flags) {
    switch (code) {
        case ON_DISCONNECT: {
            CHECK_INTERFACE(IConsumerListener, data, reply);
            onDisconnect();
            return NO_ERROR; }
            return NO_ERROR;
        }
        case ON_FRAME_AVAILABLE: {
            CHECK_INTERFACE(IConsumerListener, data, reply);
            BufferItem item;
            data.read(item);
            onFrameAvailable(item);
            return NO_ERROR; }
            return NO_ERROR;
        }
        case ON_BUFFER_RELEASED: {
            CHECK_INTERFACE(IConsumerListener, data, reply);
            onBuffersReleased();
            return NO_ERROR; }
            return NO_ERROR;
        }
        case ON_SIDEBAND_STREAM_CHANGED: {
            CHECK_INTERFACE(IConsumerListener, data, reply);
            onSidebandStreamChanged();
            return NO_ERROR; }
            return NO_ERROR;
        }
    }
    return BBinder::onTransact(code, data, reply, flags);
}

ConsumerListener::~ConsumerListener() = default;

// ---------------------------------------------------------------------------
}; // namespace android
// ---------------------------------------------------------------------------
} // namespace android