From 1d0359c5a8e19a3ad0bb3e0d8265c32bab6f0d4d Mon Sep 17 00:00:00 2001 From: Dan Stoza Date: Wed, 5 Apr 2017 16:23:19 -0700 Subject: libgui: Format IGraphicBufferConsumer Applies the framework default .clang-format and does a bit of tidying up (cleaning up and reflowing comments to 100 characters, reordering includes, etc.). Test: libgui_tests + manual testing Change-Id: I6a4c6149282661ad1bf92571597d22123c3ba93c --- include/gui/IGraphicBufferConsumer.h | 270 +++++++++++++++-------------------- 1 file changed, 116 insertions(+), 154 deletions(-) (limited to 'include/gui') diff --git a/include/gui/IGraphicBufferConsumer.h b/include/gui/IGraphicBufferConsumer.h index 60b7d24b59..bd838bc95a 100644 --- a/include/gui/IGraphicBufferConsumer.h +++ b/include/gui/IGraphicBufferConsumer.h @@ -14,27 +14,20 @@ * limitations under the License. */ -#ifndef ANDROID_GUI_IGRAPHICBUFFERCONSUMER_H -#define ANDROID_GUI_IGRAPHICBUFFERCONSUMER_H +#pragma once -#include -#include - -#include -#include -#include +#include #include -#include - -#include - #include #include +#include + +#include + namespace android { -// ---------------------------------------------------------------------------- class BufferItem; class Fence; @@ -43,11 +36,12 @@ class IConsumerListener; class NativeHandle; class IGraphicBufferConsumer : public IInterface { - public: + DECLARE_META_INTERFACE(GraphicBufferConsumer) + enum { - // Returned by releaseBuffer, after which the consumer must - // free any references to the just-released buffer that it might have. + // Returned by releaseBuffer, after which the consumer must free any references to the + // just-released buffer that it might have. STALE_BUFFER_SLOT = 1, // Returned by dequeueBuffer if there are no pending buffers available. NO_BUFFER_AVAILABLE, @@ -55,88 +49,79 @@ public: PRESENT_LATER, }; - // acquireBuffer attempts to acquire ownership of the next pending buffer in - // the BufferQueue. If no buffer is pending then it returns - // NO_BUFFER_AVAILABLE. If a buffer is successfully acquired, the - // information about the buffer is returned in BufferItem. + // acquireBuffer attempts to acquire ownership of the next pending buffer in the BufferQueue. + // If no buffer is pending then it returns NO_BUFFER_AVAILABLE. If a buffer is successfully + // acquired, the information about the buffer is returned in BufferItem. // - // If the buffer returned had previously been - // acquired then the BufferItem::mGraphicBuffer field of buffer is set to - // NULL and it is assumed that the consumer still holds a reference to the + // If the buffer returned had previously been acquired then the BufferItem::mGraphicBuffer field + // of buffer is set to NULL and it is assumed that the consumer still holds a reference to the // buffer. // - // If presentWhen is non-zero, it indicates the time when the buffer will - // be displayed on screen. If the buffer's timestamp is farther in the - // future, the buffer won't be acquired, and PRESENT_LATER will be - // returned. The presentation time is in nanoseconds, and the time base + // If presentWhen is non-zero, it indicates the time when the buffer will be displayed on + // screen. If the buffer's timestamp is farther in the future, the buffer won't be acquired, and + // PRESENT_LATER will be returned. The presentation time is in nanoseconds, and the time base // is CLOCK_MONOTONIC. // - // If maxFrameNumber is non-zero, it indicates that acquireBuffer should - // only return a buffer with a frame number less than or equal to - // maxFrameNumber. If no such frame is available (such as when a buffer has - // been replaced but the consumer has not received the onFrameReplaced - // callback), then PRESENT_LATER will be returned. + // If maxFrameNumber is non-zero, it indicates that acquireBuffer should only return a buffer + // with a frame number less than or equal to maxFrameNumber. If no such frame is available + // (such as when a buffer has been replaced but the consumer has not received the + // onFrameReplaced callback), then PRESENT_LATER will be returned. // // Return of NO_ERROR means the operation completed as normal. // - // Return of a positive value means the operation could not be completed - // at this time, but the user should try again later: + // Return of a positive value means the operation could not be completed at this time, but the + // user should try again later: // * NO_BUFFER_AVAILABLE - no buffer is pending (nothing queued by producer) // * PRESENT_LATER - the buffer's timestamp is farther in the future // // Return of a negative value means an error has occurred: // * INVALID_OPERATION - too many buffers have been acquired virtual status_t acquireBuffer(BufferItem* buffer, nsecs_t presentWhen, - uint64_t maxFrameNumber = 0) = 0; + uint64_t maxFrameNumber = 0) = 0; - // detachBuffer attempts to remove all ownership of the buffer in the given - // slot from the buffer queue. If this call succeeds, the slot will be - // freed, and there will be no way to obtain the buffer from this interface. - // The freed slot will remain unallocated until either it is selected to - // hold a freshly allocated buffer in dequeueBuffer or a buffer is attached - // to the slot. The buffer must have already been acquired. + // detachBuffer attempts to remove all ownership of the buffer in the given slot from the buffer + // queue. If this call succeeds, the slot will be freed, and there will be no way to obtain the + // buffer from this interface. The freed slot will remain unallocated until either it is + // selected to hold a freshly allocated buffer in dequeueBuffer or a buffer is attached to the + // slot. The buffer must have already been acquired. // // Return of a value other than NO_ERROR means an error has occurred: - // * BAD_VALUE - the given slot number is invalid, either because it is - // out of the range [0, NUM_BUFFER_SLOTS) or because the slot - // it refers to is not currently acquired. + // * BAD_VALUE - the given slot number is invalid, either because it is out of the range + // [0, NUM_BUFFER_SLOTS) or because the slot it refers to is not + // currently acquired. virtual status_t detachBuffer(int slot) = 0; - // attachBuffer attempts to transfer ownership of a buffer to the buffer - // queue. If this call succeeds, it will be as if this buffer was acquired - // from the returned slot number. As such, this call will fail if attaching - // this buffer would cause too many buffers to be simultaneously acquired. + // attachBuffer attempts to transfer ownership of a buffer to the BufferQueue. If this call + // succeeds, it will be as if this buffer was acquired from the returned slot number. As such, + // this call will fail if attaching this buffer would cause too many buffers to be + // simultaneously acquired. // - // If the buffer is successfully attached, its frameNumber is initialized - // to 0. This must be passed into the releaseBuffer call or else the buffer - // will be deallocated as stale. + // If the buffer is successfully attached, its frameNumber is initialized to 0. This must be + // passed into the releaseBuffer call or else the buffer will be deallocated as stale. // // Return of a value other than NO_ERROR means an error has occurred: - // * BAD_VALUE - outSlot or buffer were NULL, or the generation number of - // the buffer did not match the buffer queue. - // * INVALID_OPERATION - cannot attach the buffer because it would cause too - // many buffers to be acquired. + // * BAD_VALUE - outSlot or buffer were NULL, or the generation number of the buffer did not + // match the BufferQueue. + // * INVALID_OPERATION - cannot attach the buffer because it would cause too many buffers + // to be acquired. // * NO_MEMORY - no free slots available - virtual status_t attachBuffer(int *outSlot, - const sp& buffer) = 0; + virtual status_t attachBuffer(int* outSlot, const sp& buffer) = 0; - // releaseBuffer releases a buffer slot from the consumer back to the - // BufferQueue. This may be done while the buffer's contents are still - // being accessed. The fence will signal when the buffer is no longer - // in use. frameNumber is used to indentify the exact buffer returned. + // releaseBuffer releases a buffer slot from the consumer back to the BufferQueue. This may be + // done while the buffer's contents are still being accessed. The fence will signal when the + // buffer is no longer in use. frameNumber is used to identify the exact buffer returned. // - // If releaseBuffer returns STALE_BUFFER_SLOT, then the consumer must free - // any references to the just-released buffer that it might have, as if it - // had received a onBuffersReleased() call with a mask set for the released - // buffer. + // If releaseBuffer returns STALE_BUFFER_SLOT, then the consumer must free any references to the + // just-released buffer that it might have, as if it had received a onBuffersReleased() call + // with a mask set for the released buffer. // - // Note that the dependencies on EGL will be removed once we switch to using - // the Android HW Sync HAL. + // Note that the dependencies on EGL will be removed once we switch to using the Android HW + // Sync HAL. // // Return of NO_ERROR means the operation completed as normal. // - // Return of a positive value means the operation could not be completed - // at this time, but the user should try again later: + // Return of a positive value means the operation could not be completed at this time, but the + // user should try again later: // * STALE_BUFFER_SLOT - see above (second paragraph) // // Return of a negative value means an error has occurred: @@ -144,122 +129,111 @@ public: // * the buffer slot was invalid // * the fence was NULL // * the buffer slot specified is not in the acquired state - virtual status_t releaseBuffer(int buf, uint64_t frameNumber, - EGLDisplay display, EGLSyncKHR fence, - const sp& releaseFence) = 0; + virtual status_t releaseBuffer(int buf, uint64_t frameNumber, EGLDisplay display, + EGLSyncKHR fence, const sp& releaseFence) = 0; - // consumerConnect connects a consumer to the BufferQueue. Only one - // consumer may be connected, and when that consumer disconnects the - // BufferQueue is placed into the "abandoned" state, causing most - // interactions with the BufferQueue by the producer to fail. - // controlledByApp indicates whether the consumer is controlled by - // the application. + // consumerConnect connects a consumer to the BufferQueue. Only one consumer may be connected, + // and when that consumer disconnects the BufferQueue is placed into the "abandoned" state, + // causing most interactions with the BufferQueue by the producer to fail. controlledByApp + // indicates whether the consumer is controlled by the application. // // consumer may not be NULL. // // Return of a value other than NO_ERROR means an error has occurred: - // * NO_INIT - the buffer queue has been abandoned + // * NO_INIT - the BufferQueue has been abandoned // * BAD_VALUE - a NULL consumer was provided - virtual status_t consumerConnect(const sp& consumer, bool controlledByApp) = 0; + virtual status_t consumerConnect(const sp& consumer, + bool controlledByApp) = 0; - // consumerDisconnect disconnects a consumer from the BufferQueue. All - // buffers will be freed and the BufferQueue is placed in the "abandoned" - // state, causing most interactions with the BufferQueue by the producer to - // fail. + // consumerDisconnect disconnects a consumer from the BufferQueue. All buffers will be freed and + // the BufferQueue is placed in the "abandoned" state, causing most interactions with the + // BufferQueue by the producer to fail. // // Return of a value other than NO_ERROR means an error has occurred: // * BAD_VALUE - no consumer is currently connected virtual status_t consumerDisconnect() = 0; - // getReleasedBuffers sets the value pointed to by slotMask to a bit set. - // Each bit index with a 1 corresponds to a released buffer slot with that - // index value. In particular, a released buffer is one that has - // been released by the BufferQueue but have not yet been released by the consumer. + // getReleasedBuffers sets the value pointed to by slotMask to a bit set. Each bit index with a + // 1 corresponds to a released buffer slot with that index value. In particular, a released + // buffer is one that has been released by the BufferQueue but has not yet been released by + // the consumer. // // This should be called from the onBuffersReleased() callback. // // Return of a value other than NO_ERROR means an error has occurred: - // * NO_INIT - the buffer queue has been abandoned. + // * NO_INIT - the BufferQueue has been abandoned. virtual status_t getReleasedBuffers(uint64_t* slotMask) = 0; - // setDefaultBufferSize is used to set the size of buffers returned by - // dequeueBuffer when a width and height of zero is requested. Default - // is 1x1. + // setDefaultBufferSize is used to set the size of buffers returned by dequeueBuffer when a + // width and height of zero is requested. Default is 1x1. // // Return of a value other than NO_ERROR means an error has occurred: // * BAD_VALUE - either w or h was zero virtual status_t setDefaultBufferSize(uint32_t w, uint32_t h) = 0; - // setMaxBufferCount sets the maximum value for the number of buffers used - // in the buffer queue (the initial default is NUM_BUFFER_SLOTS). If a call - // to setMaxAcquiredBufferCount (by the consumer), or a call to setAsyncMode - // or setMaxDequeuedBufferCount (by the producer), would cause this value to - // be exceeded then that call will fail. This call will fail if a producer + // setMaxBufferCount sets the maximum value for the number of buffers used in the BufferQueue + // (the initial default is NUM_BUFFER_SLOTS). If a call to setMaxAcquiredBufferCount (by the + // consumer), or a call to setAsyncMode or setMaxDequeuedBufferCount (by the producer), would + // cause this value to be exceeded then that call will fail. This call will fail if a producer // is connected to the BufferQueue. // - // The count must be between 1 and NUM_BUFFER_SLOTS, inclusive. The count - // cannot be less than maxAcquiredBufferCount. + // The count must be between 1 and NUM_BUFFER_SLOTS, inclusive. The count cannot be less than + // maxAcquiredBufferCount. // // Return of a value other than NO_ERROR means an error has occurred: // * BAD_VALUE - one of the below conditions occurred: - // * bufferCount was out of range (see above). - // * failure to adjust the number of available slots. + // * bufferCount was out of range (see above). + // * failure to adjust the number of available slots. // * INVALID_OPERATION - attempting to call this after a producer connected. virtual status_t setMaxBufferCount(int bufferCount) = 0; - // setMaxAcquiredBufferCount sets the maximum number of buffers that can - // be acquired by the consumer at one time (default 1). If this method - // succeeds, any new buffer slots will be both unallocated and owned by the - // BufferQueue object (i.e. they are not owned by the producer or consumer). - // Calling this may also cause some buffer slots to be emptied. + // setMaxAcquiredBufferCount sets the maximum number of buffers that can be acquired by the + // consumer at one time (default 1). If this method succeeds, any new buffer slots will be both + // unallocated and owned by the BufferQueue object (i.e. they are not owned by the producer or + // consumer). Calling this may also cause some buffer slots to be emptied. // - // This function should not be called with a value of maxAcquiredBuffers - // that is less than the number of currently acquired buffer slots. Doing so - // will result in a BAD_VALUE error. + // This function should not be called with a value of maxAcquiredBuffers that is less than the + // number of currently acquired buffer slots. Doing so will result in a BAD_VALUE error. // - // maxAcquiredBuffers must be (inclusive) between 1 and - // MAX_MAX_ACQUIRED_BUFFERS. It also cannot cause the maxBufferCount value - // to be exceeded. + // maxAcquiredBuffers must be (inclusive) between 1 and MAX_MAX_ACQUIRED_BUFFERS. It also cannot + // cause the maxBufferCount value to be exceeded. // // Return of a value other than NO_ERROR means an error has occurred: - // * NO_INIT - the buffer queue has been abandoned + // * NO_INIT - the BufferQueue has been abandoned // * BAD_VALUE - one of the below conditions occurred: - // * maxAcquiredBuffers was out of range (see above). - // * failure to adjust the number of available slots. - // * client would have more than the requested number of - // acquired buffers after this call + // * maxAcquiredBuffers was out of range (see above). + // * failure to adjust the number of available slots. + // * client would have more than the requested number of acquired buffers after + // this call // * INVALID_OPERATION - attempting to call this after a producer connected. virtual status_t setMaxAcquiredBufferCount(int maxAcquiredBuffers) = 0; // setConsumerName sets the name used in logging virtual void setConsumerName(const String8& name) = 0; - // setDefaultBufferFormat allows the BufferQueue to create - // GraphicBuffers of a defaultFormat if no format is specified - // in dequeueBuffer. - // The initial default is PIXEL_FORMAT_RGBA_8888. + // setDefaultBufferFormat allows the BufferQueue to create GraphicBuffers of a defaultFormat if + // no format is specified in dequeueBuffer. The initial default is PIXEL_FORMAT_RGBA_8888. // // Return of a value other than NO_ERROR means an unknown error has occurred. virtual status_t setDefaultBufferFormat(PixelFormat defaultFormat) = 0; - // setDefaultBufferDataSpace is a request to the producer to provide buffers - // of the indicated dataSpace. The producer may ignore this request. - // The initial default is HAL_DATASPACE_UNKNOWN. + // setDefaultBufferDataSpace is a request to the producer to provide buffers of the indicated + // dataSpace. The producer may ignore this request. The initial default is + // HAL_DATASPACE_UNKNOWN. // // Return of a value other than NO_ERROR means an unknown error has occurred. - virtual status_t setDefaultBufferDataSpace( - android_dataspace defaultDataSpace) = 0; + virtual status_t setDefaultBufferDataSpace(android_dataspace defaultDataSpace) = 0; - // setConsumerUsageBits will turn on additional usage bits for dequeueBuffer. - // These are merged with the bits passed to dequeueBuffer. The values are - // enumerated in gralloc.h, e.g. GRALLOC_USAGE_HW_RENDER; the default is 0. + // setConsumerUsageBits will turn on additional usage bits for dequeueBuffer. These are merged + // with the bits passed to dequeueBuffer. The values are enumerated in gralloc.h, + // e.g. GRALLOC_USAGE_HW_RENDER; the default is 0. // // Return of a value other than NO_ERROR means an unknown error has occurred. virtual status_t setConsumerUsageBits(uint32_t usage) = 0; - // setTransformHint bakes in rotation to buffers so overlays can be used. - // The values are enumerated in window.h, e.g. - // NATIVE_WINDOW_TRANSFORM_ROT_90. The default is 0 (no transform). + // setTransformHint bakes in rotation to buffers so overlays can be used. The values are + // enumerated in window.h, e.g. NATIVE_WINDOW_TRANSFORM_ROT_90. The default is 0 + // (no transform). // // Return of a value other than NO_ERROR means an unknown error has occurred. virtual status_t setTransformHint(uint32_t hint) = 0; @@ -267,36 +241,24 @@ public: // Retrieve the sideband buffer stream, if any. virtual sp getSidebandStream() const = 0; - // Retrieves any stored segments of the occupancy history of this - // BufferQueue and clears them. Optionally closes out the pending segment if - // forceFlush is true. + // Retrieves any stored segments of the occupancy history of this BufferQueue and clears them. + // Optionally closes out the pending segment if forceFlush is true. virtual status_t getOccupancyHistory(bool forceFlush, - std::vector* outHistory) = 0; + std::vector* outHistory) = 0; - // discardFreeBuffers releases all currently-free buffers held by the queue, - // in order to reduce the memory consumption of the queue to the minimum - // possible without discarding data. + // discardFreeBuffers releases all currently-free buffers held by the BufferQueue, in order to + // reduce the memory consumption of the BufferQueue to the minimum possible without + // discarding data. virtual status_t discardFreeBuffers() = 0; // dump state into a string virtual void dumpState(String8& result, const char* prefix) const = 0; - -public: - DECLARE_META_INTERFACE(GraphicBufferConsumer) }; -// ---------------------------------------------------------------------------- - -class BnGraphicBufferConsumer : public BnInterface -{ +class BnGraphicBufferConsumer : public BnInterface { public: - virtual status_t onTransact( uint32_t code, - const Parcel& data, - Parcel* reply, - uint32_t flags = 0); + status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply, + uint32_t flags = 0) override; }; -// ---------------------------------------------------------------------------- -}; // namespace android - -#endif // ANDROID_GUI_IGRAPHICBUFFERCONSUMER_H +} // namespace android -- cgit v1.2.3-59-g8ed1b From 0c9a1ed91f8e19887ac43eff5af16e59878c8226 Mon Sep 17 00:00:00 2001 From: Dan Stoza Date: Thu, 6 Apr 2017 15:10:21 -0700 Subject: libgui: Normalize IGraphicBufferConsumer methods This change modifies IGraphicBufferConsumer such that all synchronous methods return a status_t and, as such, all outputs are returned by output parameter rather than return value. It also eliminates the use of a const char* parameter that SafeInterface can't handle. Test: m -j + libgui_tests + manual testing Change-Id: I9bb0e2892492d5e0a3f660bf228834b9ed014539 --- include/gui/BufferQueueConsumer.h | 6 ++--- include/gui/BufferQueueCore.h | 2 +- include/gui/IGraphicBufferConsumer.h | 13 ++++++++--- libs/gui/BufferQueueConsumer.cpp | 18 +++++++++------ libs/gui/BufferQueueCore.cpp | 18 +++++++-------- libs/gui/ConsumerBase.cpp | 4 +++- libs/gui/IGraphicBufferConsumer.cpp | 26 ++++++++++++---------- libs/gui/tests/BufferQueue_test.cpp | 2 +- services/surfaceflinger/SurfaceFlingerConsumer.cpp | 4 +++- 9 files changed, 55 insertions(+), 38 deletions(-) (limited to 'include/gui') diff --git a/include/gui/BufferQueueConsumer.h b/include/gui/BufferQueueConsumer.h index da574ec7d2..1e22d2823a 100644 --- a/include/gui/BufferQueueConsumer.h +++ b/include/gui/BufferQueueConsumer.h @@ -110,7 +110,7 @@ public: virtual status_t setMaxAcquiredBufferCount(int maxAcquiredBuffers); // setConsumerName sets the name used in logging - virtual void setConsumerName(const String8& name); + status_t setConsumerName(const String8& name) override; // setDefaultBufferFormat allows the BufferQueue to create // GraphicBuffers of a defaultFormat if no format is specified @@ -135,7 +135,7 @@ public: virtual status_t setTransformHint(uint32_t hint); // Retrieve the sideband buffer stream, if any. - virtual sp getSidebandStream() const; + status_t getSidebandStream(sp* outStream) const override; // See IGraphicBufferConsumer::getOccupancyHistory virtual status_t getOccupancyHistory(bool forceFlush, @@ -145,7 +145,7 @@ public: virtual status_t discardFreeBuffers() override; // dump our state in a String - virtual void dumpState(String8& result, const char* prefix) const; + status_t dumpState(const String8& prefix, String8* outResult) const override; // Functions required for backwards compatibility. // These will be modified/renamed in IGraphicBufferConsumer and will be diff --git a/include/gui/BufferQueueCore.h b/include/gui/BufferQueueCore.h index b1c730a587..91463401f0 100644 --- a/include/gui/BufferQueueCore.h +++ b/include/gui/BufferQueueCore.h @@ -86,7 +86,7 @@ public: private: // Dump our state in a string - void dumpState(String8& result, const char* prefix) const; + void dumpState(const String8& prefix, String8* outResult) const; // getMinUndequeuedBufferCountLocked returns the minimum number of buffers // that must remain in a state other than DEQUEUED. The async parameter diff --git a/include/gui/IGraphicBufferConsumer.h b/include/gui/IGraphicBufferConsumer.h index bd838bc95a..4f6d9fbd90 100644 --- a/include/gui/IGraphicBufferConsumer.h +++ b/include/gui/IGraphicBufferConsumer.h @@ -209,7 +209,7 @@ public: virtual status_t setMaxAcquiredBufferCount(int maxAcquiredBuffers) = 0; // setConsumerName sets the name used in logging - virtual void setConsumerName(const String8& name) = 0; + virtual status_t setConsumerName(const String8& name) = 0; // setDefaultBufferFormat allows the BufferQueue to create GraphicBuffers of a defaultFormat if // no format is specified in dequeueBuffer. The initial default is PIXEL_FORMAT_RGBA_8888. @@ -239,7 +239,7 @@ public: virtual status_t setTransformHint(uint32_t hint) = 0; // Retrieve the sideband buffer stream, if any. - virtual sp getSidebandStream() const = 0; + virtual status_t getSidebandStream(sp* outStream) const = 0; // Retrieves any stored segments of the occupancy history of this BufferQueue and clears them. // Optionally closes out the pending segment if forceFlush is true. @@ -252,7 +252,14 @@ public: virtual status_t discardFreeBuffers() = 0; // dump state into a string - virtual void dumpState(String8& result, const char* prefix) const = 0; + virtual status_t dumpState(const String8& prefix, String8* outResult) const = 0; + + // Provide backwards source compatibility + void dumpState(String8& result, const char* prefix) { + String8 returned; + dumpState(String8(prefix), &returned); + result.append(returned); + } }; class BnGraphicBufferConsumer : public BnInterface { diff --git a/libs/gui/BufferQueueConsumer.cpp b/libs/gui/BufferQueueConsumer.cpp index d66aa1acf5..cd8e696d8d 100644 --- a/libs/gui/BufferQueueConsumer.cpp +++ b/libs/gui/BufferQueueConsumer.cpp @@ -675,12 +675,13 @@ status_t BufferQueueConsumer::setMaxAcquiredBufferCount( return NO_ERROR; } -void BufferQueueConsumer::setConsumerName(const String8& name) { +status_t BufferQueueConsumer::setConsumerName(const String8& name) { ATRACE_CALL(); BQ_LOGV("setConsumerName: '%s'", name.string()); Mutex::Autolock lock(mCore->mMutex); mCore->mConsumerName = name; mConsumerName = name; + return NO_ERROR; } status_t BufferQueueConsumer::setDefaultBufferFormat(PixelFormat defaultFormat) { @@ -716,9 +717,10 @@ status_t BufferQueueConsumer::setTransformHint(uint32_t hint) { return NO_ERROR; } -sp BufferQueueConsumer::getSidebandStream() const { +status_t BufferQueueConsumer::getSidebandStream(sp* outStream) const { Mutex::Autolock lock(mCore->mMutex); - return mCore->mSidebandStream; + *outStream = mCore->mSidebandStream; + return NO_ERROR; } status_t BufferQueueConsumer::getOccupancyHistory(bool forceFlush, @@ -734,20 +736,22 @@ status_t BufferQueueConsumer::discardFreeBuffers() { return NO_ERROR; } -void BufferQueueConsumer::dumpState(String8& result, const char* prefix) const { +status_t BufferQueueConsumer::dumpState(const String8& prefix, String8* outResult) const { const IPCThreadState* ipc = IPCThreadState::self(); const pid_t pid = ipc->getCallingPid(); const uid_t uid = ipc->getCallingUid(); if ((uid != AID_SHELL) && !PermissionCache::checkPermission(String16( "android.permission.DUMP"), pid, uid)) { - result.appendFormat("Permission Denial: can't dump BufferQueueConsumer " + outResult->appendFormat("Permission Denial: can't dump BufferQueueConsumer " "from pid=%d, uid=%d\n", pid, uid); android_errorWriteWithInfoLog(0x534e4554, "27046057", static_cast(uid), NULL, 0); - } else { - mCore->dumpState(result, prefix); + return PERMISSION_DENIED; } + + mCore->dumpState(prefix, outResult); + return NO_ERROR; } } // namespace android diff --git a/libs/gui/BufferQueueCore.cpp b/libs/gui/BufferQueueCore.cpp index d653db817f..566af90d8e 100644 --- a/libs/gui/BufferQueueCore.cpp +++ b/libs/gui/BufferQueueCore.cpp @@ -133,7 +133,7 @@ BufferQueueCore::BufferQueueCore(const sp& allocator) : BufferQueueCore::~BufferQueueCore() {} -void BufferQueueCore::dumpState(String8& result, const char* prefix) const { +void BufferQueueCore::dumpState(const String8& prefix, String8* outResult) const { Mutex::Autolock lock(mMutex); String8 fifo; @@ -148,10 +148,10 @@ void BufferQueueCore::dumpState(String8& result, const char* prefix) const { ++current; } - result.appendFormat("%s-BufferQueue mMaxAcquiredBufferCount=%d, " + outResult->appendFormat("%s-BufferQueue mMaxAcquiredBufferCount=%d, " "mMaxDequeuedBufferCount=%d, mDequeueBufferCannotBlock=%d " "mAsyncMode=%d, default-size=[%dx%d], default-format=%d, " - "transform-hint=%02x, FIFO(%zu)={%s}\n", prefix, + "transform-hint=%02x, FIFO(%zu)={%s}\n", prefix.string(), mMaxAcquiredBufferCount, mMaxDequeuedBufferCount, mDequeueBufferCannotBlock, mAsyncMode, mDefaultWidth, mDefaultHeight, mDefaultBufferFormat, mTransformHint, mQueue.size(), @@ -161,28 +161,28 @@ void BufferQueueCore::dumpState(String8& result, const char* prefix) const { const sp& buffer(mSlots[s].mGraphicBuffer); // A dequeued buffer might be null if it's still being allocated if (buffer.get()) { - result.appendFormat("%s%s[%02d:%p] state=%-8s, %p " - "[%4ux%4u:%4u,%3X]\n", prefix, + outResult->appendFormat("%s%s[%02d:%p] state=%-8s, %p " + "[%4ux%4u:%4u,%3X]\n", prefix.string(), (mSlots[s].mBufferState.isAcquired()) ? ">" : " ", s, buffer.get(), mSlots[s].mBufferState.string(), buffer->handle, buffer->width, buffer->height, buffer->stride, buffer->format); } else { - result.appendFormat("%s [%02d:%p] state=%-8s\n", prefix, s, + outResult->appendFormat("%s [%02d:%p] state=%-8s\n", prefix.string(), s, buffer.get(), mSlots[s].mBufferState.string()); } } for (int s : mFreeBuffers) { const sp& buffer(mSlots[s].mGraphicBuffer); - result.appendFormat("%s [%02d:%p] state=%-8s, %p [%4ux%4u:%4u,%3X]\n", - prefix, s, buffer.get(), mSlots[s].mBufferState.string(), + outResult->appendFormat("%s [%02d:%p] state=%-8s, %p [%4ux%4u:%4u,%3X]\n", + prefix.string(), s, buffer.get(), mSlots[s].mBufferState.string(), buffer->handle, buffer->width, buffer->height, buffer->stride, buffer->format); } for (int s : mFreeSlots) { const sp& buffer(mSlots[s].mGraphicBuffer); - result.appendFormat("%s [%02d:%p] state=%-8s\n", prefix, s, + outResult->appendFormat("%s [%02d:%p] state=%-8s\n", prefix.string(), s, buffer.get(), mSlots[s].mBufferState.string()); } } diff --git a/libs/gui/ConsumerBase.cpp b/libs/gui/ConsumerBase.cpp index d4e4dc3616..1783561928 100644 --- a/libs/gui/ConsumerBase.cpp +++ b/libs/gui/ConsumerBase.cpp @@ -270,7 +270,9 @@ void ConsumerBase::dumpLocked(String8& result, const char* prefix) const { result.appendFormat("%smAbandoned=%d\n", prefix, int(mAbandoned)); if (!mAbandoned) { - mConsumer->dumpState(result, prefix); + String8 consumerState; + mConsumer->dumpState(String8(prefix), &consumerState); + result.append(consumerState); } } diff --git a/libs/gui/IGraphicBufferConsumer.cpp b/libs/gui/IGraphicBufferConsumer.cpp index 4771033188..befca11d36 100644 --- a/libs/gui/IGraphicBufferConsumer.cpp +++ b/libs/gui/IGraphicBufferConsumer.cpp @@ -187,11 +187,11 @@ public: return reply.readInt32(); } - virtual void setConsumerName(const String8& name) { + virtual status_t setConsumerName(const String8& name) { Parcel data, reply; data.writeInterfaceToken(IGraphicBufferConsumer::getInterfaceDescriptor()); data.writeString8(name); - remote()->transact(SET_CONSUMER_NAME, data, &reply); + return remote()->transact(SET_CONSUMER_NAME, data, &reply); } virtual status_t setDefaultBufferFormat(PixelFormat defaultFormat) { @@ -238,18 +238,20 @@ public: return reply.readInt32(); } - virtual sp getSidebandStream() const { + virtual status_t getSidebandStream(sp* outStream) const { Parcel data, reply; status_t err; data.writeInterfaceToken(IGraphicBufferConsumer::getInterfaceDescriptor()); if ((err = remote()->transact(GET_SIDEBAND_STREAM, data, &reply)) != NO_ERROR) { - return NULL; + *outStream = nullptr; + return err; } sp stream; if (reply.readInt32()) { stream = NativeHandle::create(reply.readNativeHandle(), true); } - return stream; + *outStream = std::move(stream); + return NO_ERROR; } virtual status_t getOccupancyHistory(bool forceFlush, @@ -291,13 +293,12 @@ public: return result; } - virtual void dumpState(String8& result, const char* prefix) const { + virtual status_t dumpState(const String8& prefix, String8* outResult) const { Parcel data, reply; data.writeInterfaceToken(IGraphicBufferConsumer::getInterfaceDescriptor()); - data.writeString8(result); - data.writeString8(String8(prefix ? prefix : "")); + data.writeString8(prefix); remote()->transact(DUMP, data, &reply); - reply.readString8(); + return reply.readString8(outResult); } }; @@ -432,7 +433,8 @@ status_t BnGraphicBufferConsumer::onTransact(uint32_t code, const Parcel& data, } case GET_SIDEBAND_STREAM: { CHECK_INTERFACE(IGraphicBufferConsumer, data, reply); - sp stream = getSidebandStream(); + sp stream; + getSidebandStream(&stream); reply->writeInt32(static_cast(stream != NULL)); if (stream != NULL) { reply->writeNativeHandle(stream->handle()); @@ -466,9 +468,9 @@ status_t BnGraphicBufferConsumer::onTransact(uint32_t code, const Parcel& data, } case DUMP: { CHECK_INTERFACE(IGraphicBufferConsumer, data, reply); - String8 result = data.readString8(); String8 prefix = data.readString8(); - static_cast(this)->dumpState(result, prefix); + String8 result; + static_cast(this)->dumpState(prefix, &result); reply->writeString8(result); return NO_ERROR; } diff --git a/libs/gui/tests/BufferQueue_test.cpp b/libs/gui/tests/BufferQueue_test.cpp index 55e6fbf851..893c0a6fc8 100644 --- a/libs/gui/tests/BufferQueue_test.cpp +++ b/libs/gui/tests/BufferQueue_test.cpp @@ -1057,7 +1057,7 @@ TEST_F(BufferQueueTest, TestDiscardFreeBuffers) { // Check no free buffers in dump String8 dumpString; - mConsumer->dumpState(dumpString, nullptr); + mConsumer->dumpState(String8{}, &dumpString); // Parse the dump to ensure that all buffer slots that are FREE also // have a null GraphicBuffer diff --git a/services/surfaceflinger/SurfaceFlingerConsumer.cpp b/services/surfaceflinger/SurfaceFlingerConsumer.cpp index 1d2b485164..9babeef87f 100644 --- a/services/surfaceflinger/SurfaceFlingerConsumer.cpp +++ b/services/surfaceflinger/SurfaceFlingerConsumer.cpp @@ -139,7 +139,9 @@ const Region& SurfaceFlingerConsumer::getSurfaceDamage() const { } sp SurfaceFlingerConsumer::getSidebandStream() const { - return mConsumer->getSidebandStream(); + sp stream; + mConsumer->getSidebandStream(&stream); + return stream; } // We need to determine the time when a buffer acquired now will be -- cgit v1.2.3-59-g8ed1b From 4b5fbdb107cf25bf0cad040a63cf51399ce9215b Mon Sep 17 00:00:00 2001 From: Dan Stoza Date: Mon, 10 Apr 2017 13:41:53 -0700 Subject: libgui: Make IGraphicBufferConsumer a SafeInterface Converts IGraphicBufferConsumer to be a SafeInterface such that all parceling/unparceling is done automatically. Test: libgui_tests + manual testing Change-Id: Ica5f5f5c3e6b5735f0f1327a50cefe8f3f6f0feb --- include/gui/IGraphicBufferConsumer.h | 17 +- libs/gui/IGraphicBufferConsumer.cpp | 495 +++++++++-------------------------- 2 files changed, 134 insertions(+), 378 deletions(-) (limited to 'include/gui') diff --git a/include/gui/IGraphicBufferConsumer.h b/include/gui/IGraphicBufferConsumer.h index 4f6d9fbd90..63254ed5b0 100644 --- a/include/gui/IGraphicBufferConsumer.h +++ b/include/gui/IGraphicBufferConsumer.h @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -132,6 +133,17 @@ public: virtual status_t releaseBuffer(int buf, uint64_t frameNumber, EGLDisplay display, EGLSyncKHR fence, const sp& releaseFence) = 0; + status_t releaseHelper(int buf, uint64_t frameNumber, const sp& releaseFence) { + return releaseBuffer(buf, frameNumber, EGL_NO_DISPLAY, EGL_NO_SYNC_KHR, releaseFence); + } + // This is explicitly *not* the actual signature of IGBC::releaseBuffer, but: + // 1) We have no easy way to send the EGL objects across Binder + // 2) This has always been broken, probably because + // 3) IGBC is rarely remoted + // For now, we will choose to bury our heads in the sand and ignore this problem until such time + // as we can finally finish converting away from EGL sync to native Android sync + using ReleaseBuffer = decltype(&IGraphicBufferConsumer::releaseHelper); + // consumerConnect connects a consumer to the BufferQueue. Only one consumer may be connected, // and when that consumer disconnects the BufferQueue is placed into the "abandoned" state, // causing most interactions with the BufferQueue by the producer to fail. controlledByApp @@ -262,8 +274,11 @@ public: } }; -class BnGraphicBufferConsumer : public BnInterface { +class BnGraphicBufferConsumer : public SafeBnInterface { public: + BnGraphicBufferConsumer() + : SafeBnInterface("BnGraphicBufferConsumer") {} + status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags = 0) override; }; diff --git a/libs/gui/IGraphicBufferConsumer.cpp b/libs/gui/IGraphicBufferConsumer.cpp index befca11d36..568c318f0e 100644 --- a/libs/gui/IGraphicBufferConsumer.cpp +++ b/libs/gui/IGraphicBufferConsumer.cpp @@ -29,7 +29,9 @@ namespace android { -enum { +namespace { // Anonymous namespace + +enum class Tag : uint32_t { ACQUIRE_BUFFER = IBinder::FIRST_CALL_TRANSACTION, DETACH_BUFFER, ATTACH_BUFFER, @@ -48,257 +50,116 @@ enum { GET_SIDEBAND_STREAM, GET_OCCUPANCY_HISTORY, DISCARD_FREE_BUFFERS, - DUMP, + DUMP_STATE, + LAST = DUMP_STATE, }; -class BpGraphicBufferConsumer : public BpInterface { +} // Anonymous namespace + +class BpGraphicBufferConsumer : public SafeBpInterface { public: explicit BpGraphicBufferConsumer(const sp& impl) - : BpInterface(impl) {} - - virtual ~BpGraphicBufferConsumer(); - - virtual status_t acquireBuffer(BufferItem* buffer, nsecs_t presentWhen, - uint64_t maxFrameNumber) { - Parcel data, reply; - data.writeInterfaceToken(IGraphicBufferConsumer::getInterfaceDescriptor()); - data.writeInt64(presentWhen); - data.writeUint64(maxFrameNumber); - status_t result = remote()->transact(ACQUIRE_BUFFER, data, &reply); - if (result != NO_ERROR) { - return result; - } - result = reply.read(*buffer); - if (result != NO_ERROR) { - return result; - } - return reply.readInt32(); + : SafeBpInterface(impl, "BpGraphicBufferConsumer") {} + + ~BpGraphicBufferConsumer() override; + + status_t acquireBuffer(BufferItem* buffer, nsecs_t presentWhen, + uint64_t maxFrameNumber) override { + using Signature = decltype(&IGraphicBufferConsumer::acquireBuffer); + return callRemote(Tag::ACQUIRE_BUFFER, buffer, presentWhen, maxFrameNumber); } - virtual status_t detachBuffer(int slot) { - Parcel data, reply; - data.writeInterfaceToken(IGraphicBufferConsumer::getInterfaceDescriptor()); - data.writeInt32(slot); - status_t result = remote()->transact(DETACH_BUFFER, data, &reply); - if (result != NO_ERROR) { - return result; - } - result = reply.readInt32(); - return result; + status_t detachBuffer(int slot) override { + using Signature = decltype(&IGraphicBufferConsumer::detachBuffer); + return callRemote(Tag::DETACH_BUFFER, slot); } - virtual status_t attachBuffer(int* slot, const sp& buffer) { - Parcel data, reply; - data.writeInterfaceToken(IGraphicBufferConsumer::getInterfaceDescriptor()); - data.write(*buffer.get()); - status_t result = remote()->transact(ATTACH_BUFFER, data, &reply); - if (result != NO_ERROR) { - return result; - } - *slot = reply.readInt32(); - result = reply.readInt32(); - return result; + status_t attachBuffer(int* slot, const sp& buffer) override { + using Signature = decltype(&IGraphicBufferConsumer::attachBuffer); + return callRemote(Tag::ATTACH_BUFFER, slot, buffer); } - virtual status_t releaseBuffer(int buf, uint64_t frameNumber, - EGLDisplay display __attribute__((unused)), - EGLSyncKHR fence __attribute__((unused)), - const sp& releaseFence) { - Parcel data, reply; - data.writeInterfaceToken(IGraphicBufferConsumer::getInterfaceDescriptor()); - data.writeInt32(buf); - data.writeInt64(static_cast(frameNumber)); - data.write(*releaseFence); - status_t result = remote()->transact(RELEASE_BUFFER, data, &reply); - if (result != NO_ERROR) { - return result; - } - return reply.readInt32(); + status_t releaseBuffer(int buf, uint64_t frameNumber, + EGLDisplay display __attribute__((unused)), + EGLSyncKHR fence __attribute__((unused)), + const sp& releaseFence) override { + return callRemote(Tag::RELEASE_BUFFER, buf, frameNumber, releaseFence); } - virtual status_t consumerConnect(const sp& consumer, bool controlledByApp) { - Parcel data, reply; - data.writeInterfaceToken(IGraphicBufferConsumer::getInterfaceDescriptor()); - data.writeStrongBinder(IInterface::asBinder(consumer)); - data.writeInt32(controlledByApp); - status_t result = remote()->transact(CONSUMER_CONNECT, data, &reply); - if (result != NO_ERROR) { - return result; - } - return reply.readInt32(); + status_t consumerConnect(const sp& consumer, bool controlledByApp) override { + using Signature = decltype(&IGraphicBufferConsumer::consumerConnect); + return callRemote(Tag::CONSUMER_CONNECT, consumer, controlledByApp); } - virtual status_t consumerDisconnect() { - Parcel data, reply; - data.writeInterfaceToken(IGraphicBufferConsumer::getInterfaceDescriptor()); - status_t result = remote()->transact(CONSUMER_DISCONNECT, data, &reply); - if (result != NO_ERROR) { - return result; - } - return reply.readInt32(); + status_t consumerDisconnect() override { + return callRemote( + Tag::CONSUMER_DISCONNECT); } - virtual status_t getReleasedBuffers(uint64_t* slotMask) { - Parcel data, reply; - if (slotMask == NULL) { - ALOGE("getReleasedBuffers: slotMask must not be NULL"); - return BAD_VALUE; - } - data.writeInterfaceToken(IGraphicBufferConsumer::getInterfaceDescriptor()); - status_t result = remote()->transact(GET_RELEASED_BUFFERS, data, &reply); - if (result != NO_ERROR) { - return result; - } - *slotMask = static_cast(reply.readInt64()); - return reply.readInt32(); + status_t getReleasedBuffers(uint64_t* slotMask) override { + using Signature = decltype(&IGraphicBufferConsumer::getReleasedBuffers); + return callRemote(Tag::GET_RELEASED_BUFFERS, slotMask); } - virtual status_t setDefaultBufferSize(uint32_t width, uint32_t height) { - Parcel data, reply; - data.writeInterfaceToken(IGraphicBufferConsumer::getInterfaceDescriptor()); - data.writeUint32(width); - data.writeUint32(height); - status_t result = remote()->transact(SET_DEFAULT_BUFFER_SIZE, data, &reply); - if (result != NO_ERROR) { - return result; - } - return reply.readInt32(); + status_t setDefaultBufferSize(uint32_t width, uint32_t height) override { + using Signature = decltype(&IGraphicBufferConsumer::setDefaultBufferSize); + return callRemote(Tag::SET_DEFAULT_BUFFER_SIZE, width, height); } - virtual status_t setMaxBufferCount(int bufferCount) { - Parcel data, reply; - data.writeInterfaceToken(IGraphicBufferConsumer::getInterfaceDescriptor()); - data.writeInt32(bufferCount); - status_t result = remote()->transact(SET_MAX_BUFFER_COUNT, data, &reply); - if (result != NO_ERROR) { - return result; - } - return reply.readInt32(); + status_t setMaxBufferCount(int bufferCount) override { + using Signature = decltype(&IGraphicBufferConsumer::setMaxBufferCount); + return callRemote(Tag::SET_MAX_BUFFER_COUNT, bufferCount); } - virtual status_t setMaxAcquiredBufferCount(int maxAcquiredBuffers) { - Parcel data, reply; - data.writeInterfaceToken(IGraphicBufferConsumer::getInterfaceDescriptor()); - data.writeInt32(maxAcquiredBuffers); - status_t result = remote()->transact(SET_MAX_ACQUIRED_BUFFER_COUNT, data, &reply); - if (result != NO_ERROR) { - return result; - } - return reply.readInt32(); + status_t setMaxAcquiredBufferCount(int maxAcquiredBuffers) override { + using Signature = decltype(&IGraphicBufferConsumer::setMaxAcquiredBufferCount); + return callRemote(Tag::SET_MAX_ACQUIRED_BUFFER_COUNT, maxAcquiredBuffers); } - virtual status_t setConsumerName(const String8& name) { - Parcel data, reply; - data.writeInterfaceToken(IGraphicBufferConsumer::getInterfaceDescriptor()); - data.writeString8(name); - return remote()->transact(SET_CONSUMER_NAME, data, &reply); + status_t setConsumerName(const String8& name) override { + using Signature = decltype(&IGraphicBufferConsumer::setConsumerName); + return callRemote(Tag::SET_CONSUMER_NAME, name); } - virtual status_t setDefaultBufferFormat(PixelFormat defaultFormat) { - Parcel data, reply; - data.writeInterfaceToken(IGraphicBufferConsumer::getInterfaceDescriptor()); - data.writeInt32(static_cast(defaultFormat)); - status_t result = remote()->transact(SET_DEFAULT_BUFFER_FORMAT, data, &reply); - if (result != NO_ERROR) { - return result; - } - return reply.readInt32(); + status_t setDefaultBufferFormat(PixelFormat defaultFormat) override { + using Signature = decltype(&IGraphicBufferConsumer::setDefaultBufferFormat); + return callRemote(Tag::SET_DEFAULT_BUFFER_FORMAT, defaultFormat); } - virtual status_t setDefaultBufferDataSpace(android_dataspace defaultDataSpace) { - Parcel data, reply; - data.writeInterfaceToken(IGraphicBufferConsumer::getInterfaceDescriptor()); - data.writeInt32(static_cast(defaultDataSpace)); - status_t result = remote()->transact(SET_DEFAULT_BUFFER_DATA_SPACE, data, &reply); - if (result != NO_ERROR) { - return result; - } - return reply.readInt32(); + status_t setDefaultBufferDataSpace(android_dataspace defaultDataSpace) override { + using Signature = decltype(&IGraphicBufferConsumer::setDefaultBufferDataSpace); + return callRemote(Tag::SET_DEFAULT_BUFFER_DATA_SPACE, defaultDataSpace); } - virtual status_t setConsumerUsageBits(uint32_t usage) { - Parcel data, reply; - data.writeInterfaceToken(IGraphicBufferConsumer::getInterfaceDescriptor()); - data.writeUint32(usage); - status_t result = remote()->transact(SET_CONSUMER_USAGE_BITS, data, &reply); - if (result != NO_ERROR) { - return result; - } - return reply.readInt32(); + status_t setConsumerUsageBits(uint32_t usage) override { + using Signature = decltype(&IGraphicBufferConsumer::setConsumerUsageBits); + return callRemote(Tag::SET_CONSUMER_USAGE_BITS, usage); } - virtual status_t setTransformHint(uint32_t hint) { - Parcel data, reply; - data.writeInterfaceToken(IGraphicBufferConsumer::getInterfaceDescriptor()); - data.writeUint32(hint); - status_t result = remote()->transact(SET_TRANSFORM_HINT, data, &reply); - if (result != NO_ERROR) { - return result; - } - return reply.readInt32(); + status_t setTransformHint(uint32_t hint) override { + using Signature = decltype(&IGraphicBufferConsumer::setTransformHint); + return callRemote(Tag::SET_TRANSFORM_HINT, hint); } - virtual status_t getSidebandStream(sp* outStream) const { - Parcel data, reply; - status_t err; - data.writeInterfaceToken(IGraphicBufferConsumer::getInterfaceDescriptor()); - if ((err = remote()->transact(GET_SIDEBAND_STREAM, data, &reply)) != NO_ERROR) { - *outStream = nullptr; - return err; - } - sp stream; - if (reply.readInt32()) { - stream = NativeHandle::create(reply.readNativeHandle(), true); - } - *outStream = std::move(stream); - return NO_ERROR; + status_t getSidebandStream(sp* outStream) const override { + using Signature = decltype(&IGraphicBufferConsumer::getSidebandStream); + return callRemote(Tag::GET_SIDEBAND_STREAM, outStream); } - virtual status_t getOccupancyHistory(bool forceFlush, - std::vector* outHistory) { - Parcel data, reply; - data.writeInterfaceToken(IGraphicBufferConsumer::getInterfaceDescriptor()); - status_t error = data.writeBool(forceFlush); - if (error != NO_ERROR) { - return error; - } - error = remote()->transact(GET_OCCUPANCY_HISTORY, data, &reply); - if (error != NO_ERROR) { - return error; - } - error = reply.readParcelableVector(outHistory); - if (error != NO_ERROR) { - return error; - } - status_t result = NO_ERROR; - error = reply.readInt32(&result); - if (error != NO_ERROR) { - return error; - } - return result; + status_t getOccupancyHistory(bool forceFlush, + std::vector* outHistory) override { + using Signature = decltype(&IGraphicBufferConsumer::getOccupancyHistory); + return callRemote(Tag::GET_OCCUPANCY_HISTORY, forceFlush, outHistory); } - virtual status_t discardFreeBuffers() { - Parcel data, reply; - data.writeInterfaceToken(IGraphicBufferConsumer::getInterfaceDescriptor()); - status_t error = remote()->transact(DISCARD_FREE_BUFFERS, data, &reply); - if (error != NO_ERROR) { - return error; - } - int32_t result = NO_ERROR; - error = reply.readInt32(&result); - if (error != NO_ERROR) { - return error; - } - return result; + status_t discardFreeBuffers() override { + return callRemote( + Tag::DISCARD_FREE_BUFFERS); } - virtual status_t dumpState(const String8& prefix, String8* outResult) const { - Parcel data, reply; - data.writeInterfaceToken(IGraphicBufferConsumer::getInterfaceDescriptor()); - data.writeString8(prefix); - remote()->transact(DUMP, data, &reply); - return reply.readString8(outResult); + status_t dumpState(const String8& prefix, String8* outResult) const override { + using Signature = status_t (IGraphicBufferConsumer::*)(const String8&, String8*) const; + return callRemote(Tag::DUMP_STATE, prefix, outResult); } }; @@ -308,174 +169,54 @@ BpGraphicBufferConsumer::~BpGraphicBufferConsumer() = default; IMPLEMENT_META_INTERFACE(GraphicBufferConsumer, "android.gui.IGraphicBufferConsumer"); -// ---------------------------------------------------------------------- - status_t BnGraphicBufferConsumer::onTransact(uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) { - switch (code) { - case ACQUIRE_BUFFER: { - CHECK_INTERFACE(IGraphicBufferConsumer, data, reply); - BufferItem item; - int64_t presentWhen = data.readInt64(); - uint64_t maxFrameNumber = data.readUint64(); - status_t result = acquireBuffer(&item, presentWhen, maxFrameNumber); - status_t err = reply->write(item); - if (err) return err; - reply->writeInt32(result); - return NO_ERROR; - } - case DETACH_BUFFER: { - CHECK_INTERFACE(IGraphicBufferConsumer, data, reply); - int slot = data.readInt32(); - int result = detachBuffer(slot); - reply->writeInt32(result); - return NO_ERROR; - } - case ATTACH_BUFFER: { - CHECK_INTERFACE(IGraphicBufferConsumer, data, reply); - sp buffer = new GraphicBuffer(); - data.read(*buffer.get()); - int slot = -1; - int result = attachBuffer(&slot, buffer); - reply->writeInt32(slot); - reply->writeInt32(result); - return NO_ERROR; - } - case RELEASE_BUFFER: { - CHECK_INTERFACE(IGraphicBufferConsumer, data, reply); - int buf = data.readInt32(); - uint64_t frameNumber = static_cast(data.readInt64()); - sp releaseFence = new Fence(); - status_t err = data.read(*releaseFence); - if (err) return err; - status_t result = - releaseBuffer(buf, frameNumber, EGL_NO_DISPLAY, EGL_NO_SYNC_KHR, releaseFence); - reply->writeInt32(result); - return NO_ERROR; - } - case CONSUMER_CONNECT: { - CHECK_INTERFACE(IGraphicBufferConsumer, data, reply); - sp consumer = - IConsumerListener::asInterface(data.readStrongBinder()); - bool controlledByApp = data.readInt32(); - status_t result = consumerConnect(consumer, controlledByApp); - reply->writeInt32(result); - return NO_ERROR; - } - case CONSUMER_DISCONNECT: { - CHECK_INTERFACE(IGraphicBufferConsumer, data, reply); - status_t result = consumerDisconnect(); - reply->writeInt32(result); - return NO_ERROR; - } - case GET_RELEASED_BUFFERS: { - CHECK_INTERFACE(IGraphicBufferConsumer, data, reply); - uint64_t slotMask = 0; - status_t result = getReleasedBuffers(&slotMask); - reply->writeInt64(static_cast(slotMask)); - reply->writeInt32(result); - return NO_ERROR; - } - case SET_DEFAULT_BUFFER_SIZE: { - CHECK_INTERFACE(IGraphicBufferConsumer, data, reply); - uint32_t width = data.readUint32(); - uint32_t height = data.readUint32(); - status_t result = setDefaultBufferSize(width, height); - reply->writeInt32(result); - return NO_ERROR; - } - case SET_MAX_BUFFER_COUNT: { - CHECK_INTERFACE(IGraphicBufferConsumer, data, reply); - int bufferCount = data.readInt32(); - status_t result = setMaxBufferCount(bufferCount); - reply->writeInt32(result); - return NO_ERROR; - } - case SET_MAX_ACQUIRED_BUFFER_COUNT: { - CHECK_INTERFACE(IGraphicBufferConsumer, data, reply); - int maxAcquiredBuffers = data.readInt32(); - status_t result = setMaxAcquiredBufferCount(maxAcquiredBuffers); - reply->writeInt32(result); - return NO_ERROR; - } - case SET_CONSUMER_NAME: { - CHECK_INTERFACE(IGraphicBufferConsumer, data, reply); - setConsumerName(data.readString8()); - return NO_ERROR; - } - case SET_DEFAULT_BUFFER_FORMAT: { - CHECK_INTERFACE(IGraphicBufferConsumer, data, reply); - PixelFormat defaultFormat = static_cast(data.readInt32()); - status_t result = setDefaultBufferFormat(defaultFormat); - reply->writeInt32(result); - return NO_ERROR; - } - case SET_DEFAULT_BUFFER_DATA_SPACE: { - CHECK_INTERFACE(IGraphicBufferConsumer, data, reply); - android_dataspace defaultDataSpace = static_cast(data.readInt32()); - status_t result = setDefaultBufferDataSpace(defaultDataSpace); - reply->writeInt32(result); - return NO_ERROR; - } - case SET_CONSUMER_USAGE_BITS: { - CHECK_INTERFACE(IGraphicBufferConsumer, data, reply); - uint32_t usage = data.readUint32(); - status_t result = setConsumerUsageBits(usage); - reply->writeInt32(result); - return NO_ERROR; - } - case SET_TRANSFORM_HINT: { - CHECK_INTERFACE(IGraphicBufferConsumer, data, reply); - uint32_t hint = data.readUint32(); - status_t result = setTransformHint(hint); - reply->writeInt32(result); - return NO_ERROR; - } - case GET_SIDEBAND_STREAM: { - CHECK_INTERFACE(IGraphicBufferConsumer, data, reply); - sp stream; - getSidebandStream(&stream); - reply->writeInt32(static_cast(stream != NULL)); - if (stream != NULL) { - reply->writeNativeHandle(stream->handle()); - } - return NO_ERROR; - } - case GET_OCCUPANCY_HISTORY: { - CHECK_INTERFACE(IGraphicBufferConsumer, data, reply); - bool forceFlush = false; - status_t error = data.readBool(&forceFlush); - if (error != NO_ERROR) { - return error; - } - std::vector history; - status_t result = getOccupancyHistory(forceFlush, &history); - error = reply->writeParcelableVector(history); - if (error != NO_ERROR) { - return error; - } - error = reply->writeInt32(result); - if (error != NO_ERROR) { - return error; - } - return NO_ERROR; - } - case DISCARD_FREE_BUFFERS: { - CHECK_INTERFACE(IGraphicBufferConsumer, data, reply); - status_t result = discardFreeBuffers(); - status_t error = reply->writeInt32(result); - return error; - } - case DUMP: { - CHECK_INTERFACE(IGraphicBufferConsumer, data, reply); - String8 prefix = data.readString8(); - String8 result; - static_cast(this)->dumpState(prefix, &result); - reply->writeString8(result); - return NO_ERROR; + if (code < IBinder::FIRST_CALL_TRANSACTION || code > static_cast(Tag::LAST)) { + return BBinder::onTransact(code, data, reply, flags); + } + auto tag = static_cast(code); + switch (tag) { + case Tag::ACQUIRE_BUFFER: + return callLocal(data, reply, &IGraphicBufferConsumer::acquireBuffer); + case Tag::DETACH_BUFFER: + return callLocal(data, reply, &IGraphicBufferConsumer::detachBuffer); + case Tag::ATTACH_BUFFER: + return callLocal(data, reply, &IGraphicBufferConsumer::attachBuffer); + case Tag::RELEASE_BUFFER: + return callLocal(data, reply, &IGraphicBufferConsumer::releaseHelper); + case Tag::CONSUMER_CONNECT: + return callLocal(data, reply, &IGraphicBufferConsumer::consumerConnect); + case Tag::CONSUMER_DISCONNECT: + return callLocal(data, reply, &IGraphicBufferConsumer::consumerDisconnect); + case Tag::GET_RELEASED_BUFFERS: + return callLocal(data, reply, &IGraphicBufferConsumer::getReleasedBuffers); + case Tag::SET_DEFAULT_BUFFER_SIZE: + return callLocal(data, reply, &IGraphicBufferConsumer::setDefaultBufferSize); + case Tag::SET_MAX_BUFFER_COUNT: + return callLocal(data, reply, &IGraphicBufferConsumer::setMaxBufferCount); + case Tag::SET_MAX_ACQUIRED_BUFFER_COUNT: + return callLocal(data, reply, &IGraphicBufferConsumer::setMaxAcquiredBufferCount); + case Tag::SET_CONSUMER_NAME: + return callLocal(data, reply, &IGraphicBufferConsumer::setConsumerName); + case Tag::SET_DEFAULT_BUFFER_FORMAT: + return callLocal(data, reply, &IGraphicBufferConsumer::setDefaultBufferFormat); + case Tag::SET_DEFAULT_BUFFER_DATA_SPACE: + return callLocal(data, reply, &IGraphicBufferConsumer::setDefaultBufferDataSpace); + case Tag::SET_CONSUMER_USAGE_BITS: + return callLocal(data, reply, &IGraphicBufferConsumer::setConsumerUsageBits); + case Tag::SET_TRANSFORM_HINT: + return callLocal(data, reply, &IGraphicBufferConsumer::setTransformHint); + case Tag::GET_SIDEBAND_STREAM: + return callLocal(data, reply, &IGraphicBufferConsumer::getSidebandStream); + case Tag::GET_OCCUPANCY_HISTORY: + return callLocal(data, reply, &IGraphicBufferConsumer::getOccupancyHistory); + case Tag::DISCARD_FREE_BUFFERS: + return callLocal(data, reply, &IGraphicBufferConsumer::discardFreeBuffers); + case Tag::DUMP_STATE: { + using Signature = status_t (IGraphicBufferConsumer::*)(const String8&, String8*) const; + return callLocal(data, reply, &IGraphicBufferConsumer::dumpState); } } - return BBinder::onTransact(code, data, reply, flags); } -}; // namespace android +} // namespace android -- cgit v1.2.3-59-g8ed1b