diff options
author | 2017-05-22 14:21:00 -0700 | |
---|---|---|
committer | 2017-05-26 15:16:36 -0700 | |
commit | cb496acbe593326e8d5d563847067d02b2df40ec (patch) | |
tree | be669654542a7fe19d85d17d89e092b1880ccb3e | |
parent | 177759a90584489b1b77cdaf3818ebdb79b1b9bf (diff) |
use 64-bits usage bits almost everywhere
Revert "Revert "use 64-bits usage bits almost everywhere""
This reverts commit 1671de0068de40f57288628d4b757a1c84962a62.
Test: manual, build
Bug: 33350696
Bug: 38466700
Change-Id: Ia2f51b97137dba754b1938dfb1e235f4babc8a88
27 files changed, 189 insertions, 195 deletions
diff --git a/include/gui/BufferQueueConsumer.h b/include/gui/BufferQueueConsumer.h index f194bdf758..d108120777 100644 --- a/include/gui/BufferQueueConsumer.h +++ b/include/gui/BufferQueueConsumer.h @@ -121,13 +121,12 @@ public: // GraphicBuffers of a defaultDataSpace if no data space is specified // in queueBuffer. // The initial default is HAL_DATASPACE_UNKNOWN - virtual status_t setDefaultBufferDataSpace( - android_dataspace defaultDataSpace); + virtual status_t setDefaultBufferDataSpace(android_dataspace defaultDataSpace); // 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. - virtual status_t setConsumerUsageBits(uint32_t usage); + virtual status_t setConsumerUsageBits(uint64_t usage) override; // setConsumerIsProtected will turn on an internal bit that indicates whether // the consumer can handle protected gralloc buffers (i.e. with diff --git a/include/gui/BufferQueueCore.h b/include/gui/BufferQueueCore.h index dd8b992ce1..537c957746 100644 --- a/include/gui/BufferQueueCore.h +++ b/include/gui/BufferQueueCore.h @@ -170,7 +170,7 @@ private: // mConsumerUsageBits contains flags that the consumer wants for // GraphicBuffers. - uint32_t mConsumerUsageBits; + uint64_t mConsumerUsageBits; // mConsumerIsProtected indicates the consumer is ready to handle protected // buffer. diff --git a/include/gui/BufferQueueProducer.h b/include/gui/BufferQueueProducer.h index 87bc8008e1..0f8917aa6d 100644 --- a/include/gui/BufferQueueProducer.h +++ b/include/gui/BufferQueueProducer.h @@ -80,9 +80,9 @@ public: // // In both cases, the producer will need to call requestBuffer to get a // GraphicBuffer handle for the returned slot. - status_t dequeueBuffer(int *outSlot, sp<Fence>* outFence, + virtual status_t dequeueBuffer(int *outSlot, sp<Fence>* outFence, uint32_t width, uint32_t height, PixelFormat format, - uint32_t usage, FrameEventHistoryDelta* outTimestamps) override; + uint64_t usage, FrameEventHistoryDelta* outTimestamps) override; // See IGraphicBufferProducer::detachBuffer virtual status_t detachBuffer(int slot); @@ -152,7 +152,7 @@ public: // See IGraphicBufferProducer::allocateBuffers virtual void allocateBuffers(uint32_t width, uint32_t height, - PixelFormat format, uint32_t usage); + PixelFormat format, uint64_t usage) override; // See IGraphicBufferProducer::allowAllocation virtual status_t allowAllocation(bool allow); diff --git a/include/gui/IGraphicBufferConsumer.h b/include/gui/IGraphicBufferConsumer.h index 57cce16d10..90de1140e9 100644 --- a/include/gui/IGraphicBufferConsumer.h +++ b/include/gui/IGraphicBufferConsumer.h @@ -241,7 +241,7 @@ public: // 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; + virtual status_t setConsumerUsageBits(uint64_t usage) = 0; // setConsumerIsProtected will turn on an internal bit that indicates whether // the consumer can handle protected gralloc buffers (i.e. with diff --git a/include/gui/IGraphicBufferProducer.h b/include/gui/IGraphicBufferProducer.h index 925080663e..6d16e7426c 100644 --- a/include/gui/IGraphicBufferProducer.h +++ b/include/gui/IGraphicBufferProducer.h @@ -195,7 +195,7 @@ public: // All other negative values are an unknown error returned downstream // from the graphics allocator (typically errno). virtual status_t dequeueBuffer(int* slot, sp<Fence>* fence, uint32_t w, - uint32_t h, PixelFormat format, uint32_t usage, + uint32_t h, PixelFormat format, uint64_t usage, FrameEventHistoryDelta* outTimestamps) = 0; // detachBuffer attempts to remove all ownership of the buffer in the given @@ -517,7 +517,7 @@ public: // dequeueBuffer. If there are already the maximum number of buffers // allocated, this function has no effect. virtual void allocateBuffers(uint32_t width, uint32_t height, - PixelFormat format, uint32_t usage) = 0; + PixelFormat format, uint64_t usage) = 0; // Sets whether dequeueBuffer is allowed to allocate new buffers. // diff --git a/include/gui/Surface.h b/include/gui/Surface.h index c8c6e99c10..c836543b16 100644 --- a/include/gui/Surface.h +++ b/include/gui/Surface.h @@ -204,8 +204,8 @@ private: int dispatchSetBuffersStickyTransform(va_list args); int dispatchSetBuffersTimestamp(va_list args); int dispatchSetCrop(va_list args); - int dispatchSetPostTransformCrop(va_list args); int dispatchSetUsage(va_list args); + int dispatchSetUsage64(va_list args); int dispatchLock(va_list args); int dispatchUnlockAndPost(va_list args); int dispatchSetSidebandStream(va_list args); @@ -239,7 +239,7 @@ protected: virtual int setBuffersTimestamp(int64_t timestamp); virtual int setBuffersDataSpace(android_dataspace dataSpace); virtual int setCrop(Rect const* rect); - virtual int setUsage(uint32_t reqUsage); + virtual int setUsage(uint64_t reqUsage); virtual void setSurfaceDamage(android_native_rect_t* rects, size_t numRects); public: @@ -318,7 +318,7 @@ protected: // mReqUsage is the set of buffer usage flags that will be requested // at the next deuque operation. It is initialized to 0. - uint32_t mReqUsage; + uint64_t mReqUsage; // mTimestamp is the timestamp that will be used for the next buffer queue // operation. It defaults to NATIVE_WINDOW_TIMESTAMP_AUTO, which means that diff --git a/include/gui/bufferqueue/1.0/H2BGraphicBufferProducer.h b/include/gui/bufferqueue/1.0/H2BGraphicBufferProducer.h index 93c452a0d6..c3a9d443ec 100644 --- a/include/gui/bufferqueue/1.0/H2BGraphicBufferProducer.h +++ b/include/gui/bufferqueue/1.0/H2BGraphicBufferProducer.h @@ -65,7 +65,7 @@ struct H2BGraphicBufferProducer : public ::android::H2BConverter< status_t setMaxDequeuedBufferCount(int maxDequeuedBuffers) override; status_t setAsyncMode(bool async) override; status_t dequeueBuffer(int* slot, sp<Fence>* fence, uint32_t w, - uint32_t h, ::android::PixelFormat format, uint32_t usage, + uint32_t h, ::android::PixelFormat format, uint64_t usage, FrameEventHistoryDelta* outTimestamps) override; status_t detachBuffer(int slot) override; status_t detachNextBuffer(sp<GraphicBuffer>* outBuffer, sp<Fence>* outFence) @@ -83,7 +83,7 @@ struct H2BGraphicBufferProducer : public ::android::H2BConverter< override; status_t setSidebandStream(const sp<NativeHandle>& stream) override; void allocateBuffers(uint32_t width, uint32_t height, - ::android::PixelFormat format, uint32_t usage) override; + ::android::PixelFormat format, uint64_t usage) override; status_t allowAllocation(bool allow) override; status_t setGenerationNumber(uint32_t generationNumber) override; String8 getConsumerName() const override; diff --git a/libs/gui/BufferQueueConsumer.cpp b/libs/gui/BufferQueueConsumer.cpp index be754c25fc..168d35555f 100644 --- a/libs/gui/BufferQueueConsumer.cpp +++ b/libs/gui/BufferQueueConsumer.cpp @@ -703,9 +703,9 @@ status_t BufferQueueConsumer::setDefaultBufferDataSpace( return NO_ERROR; } -status_t BufferQueueConsumer::setConsumerUsageBits(uint32_t usage) { +status_t BufferQueueConsumer::setConsumerUsageBits(uint64_t usage) { ATRACE_CALL(); - BQ_LOGV("setConsumerUsageBits: %#x", usage); + BQ_LOGV("setConsumerUsageBits: %#" PRIx64, usage); Mutex::Autolock lock(mCore->mMutex); mCore->mConsumerUsageBits = usage; return NO_ERROR; diff --git a/libs/gui/BufferQueueProducer.cpp b/libs/gui/BufferQueueProducer.cpp index 7510069963..b39ecc5856 100644 --- a/libs/gui/BufferQueueProducer.cpp +++ b/libs/gui/BufferQueueProducer.cpp @@ -349,7 +349,7 @@ status_t BufferQueueProducer::waitForFreeSlotThenRelock(FreeSlotCaller caller, status_t BufferQueueProducer::dequeueBuffer(int *outSlot, sp<android::Fence> *outFence, uint32_t width, uint32_t height, - PixelFormat format, uint32_t usage, + PixelFormat format, uint64_t usage, FrameEventHistoryDelta* outTimestamps) { ATRACE_CALL(); { // Autolock scope @@ -367,8 +367,7 @@ status_t BufferQueueProducer::dequeueBuffer(int *outSlot, } } // Autolock scope - BQ_LOGV("dequeueBuffer: w=%u h=%u format=%#x, usage=%#x", width, height, - format, usage); + BQ_LOGV("dequeueBuffer: w=%u h=%u format=%#x, usage=%#" PRIx64, width, height, format, usage); if ((width && !height) || (!width && height)) { BQ_LOGE("dequeueBuffer: invalid size: w=%u h=%u", width, height); @@ -418,11 +417,9 @@ status_t BufferQueueProducer::dequeueBuffer(int *outSlot, // buffer. If this buffer would require reallocation to meet the // requested attributes, we free it and attempt to get another one. if (!mCore->mAllowAllocation) { - if (buffer->needsReallocation(width, height, format, - BQ_LAYER_COUNT, usage)) { + if (buffer->needsReallocation(width, height, format, BQ_LAYER_COUNT, usage)) { if (mCore->mSharedBufferSlot == found) { - BQ_LOGE("dequeueBuffer: cannot re-allocate a shared" - "buffer"); + BQ_LOGE("dequeueBuffer: cannot re-allocate a sharedbuffer"); return BAD_VALUE; } mCore->mFreeSlots.insert(found); @@ -435,8 +432,7 @@ status_t BufferQueueProducer::dequeueBuffer(int *outSlot, const sp<GraphicBuffer>& buffer(mSlots[found].mGraphicBuffer); if (mCore->mSharedBufferSlot == found && - buffer->needsReallocation(width, height, format, - BQ_LAYER_COUNT, usage)) { + buffer->needsReallocation(width, height, format, BQ_LAYER_COUNT, usage)) { BQ_LOGE("dequeueBuffer: cannot re-allocate a shared" "buffer"); @@ -470,8 +466,7 @@ status_t BufferQueueProducer::dequeueBuffer(int *outSlot, } else { // We add 1 because that will be the frame number when this buffer // is queued - mCore->mBufferAge = - mCore->mFrameCounter + 1 - mSlots[found].mFrameNumber; + mCore->mBufferAge = mCore->mFrameCounter + 1 - mSlots[found].mFrameNumber; } BQ_LOGV("dequeueBuffer: setting buffer age to %" PRIu64, @@ -1313,14 +1308,14 @@ status_t BufferQueueProducer::setSidebandStream(const sp<NativeHandle>& stream) } void BufferQueueProducer::allocateBuffers(uint32_t width, uint32_t height, - PixelFormat format, uint32_t usage) { + PixelFormat format, uint64_t usage) { ATRACE_CALL(); while (true) { size_t newBufferCount = 0; uint32_t allocWidth = 0; uint32_t allocHeight = 0; PixelFormat allocFormat = PIXEL_FORMAT_UNKNOWN; - uint32_t allocUsage = 0; + uint64_t allocUsage = 0; { // Autolock scope Mutex::Autolock lock(mCore->mMutex); mCore->waitWhileAllocatingLocked(); @@ -1354,7 +1349,7 @@ void BufferQueueProducer::allocateBuffers(uint32_t width, uint32_t height, if (result != NO_ERROR) { BQ_LOGE("allocateBuffers: failed to allocate buffer (%u x %u, format" - " %u, usage %u)", width, height, format, usage); + " %u, usage %#" PRIx64 ")", width, height, format, usage); Mutex::Autolock lock(mCore->mMutex); mCore->mIsAllocating = false; mCore->mIsAllocatingCondition.broadcast(); @@ -1369,7 +1364,7 @@ void BufferQueueProducer::allocateBuffers(uint32_t width, uint32_t height, uint32_t checkHeight = height > 0 ? height : mCore->mDefaultHeight; PixelFormat checkFormat = format != 0 ? format : mCore->mDefaultBufferFormat; - uint32_t checkUsage = usage | mCore->mConsumerUsageBits; + uint64_t checkUsage = usage | mCore->mConsumerUsageBits; if (checkWidth != allocWidth || checkHeight != allocHeight || checkFormat != allocFormat || checkUsage != allocUsage) { // Something changed while we released the lock. Retry. diff --git a/libs/gui/GLConsumer.cpp b/libs/gui/GLConsumer.cpp index c654f083b3..34c9d7805a 100644 --- a/libs/gui/GLConsumer.cpp +++ b/libs/gui/GLConsumer.cpp @@ -21,6 +21,8 @@ #define GL_GLEXT_PROTOTYPES #define EGL_EGLEXT_PROTOTYPES +#include <inttypes.h> + #include <EGL/egl.h> #include <EGL/eglext.h> #include <GLES2/gl2.h> @@ -1219,7 +1221,7 @@ status_t GLConsumer::EglImage::createIfNeeded(EGLDisplay eglDisplay, mEglDisplay = EGL_NO_DISPLAY; mCropRect.makeInvalid(); const sp<GraphicBuffer>& buffer = mGraphicBuffer; - ALOGE("Failed to create image. size=%ux%u st=%u usage=0x%x fmt=%d", + ALOGE("Failed to create image. size=%ux%u st=%u usage=%#" PRIx64 " fmt=%d", buffer->getWidth(), buffer->getHeight(), buffer->getStride(), buffer->getUsage(), buffer->getPixelFormat()); return UNKNOWN_ERROR; diff --git a/libs/gui/IGraphicBufferConsumer.cpp b/libs/gui/IGraphicBufferConsumer.cpp index a573bee651..c705d3926d 100644 --- a/libs/gui/IGraphicBufferConsumer.cpp +++ b/libs/gui/IGraphicBufferConsumer.cpp @@ -132,7 +132,7 @@ public: return callRemote<Signature>(Tag::SET_DEFAULT_BUFFER_DATA_SPACE, defaultDataSpace); } - status_t setConsumerUsageBits(uint32_t usage) override { + status_t setConsumerUsageBits(uint64_t usage) override { using Signature = decltype(&IGraphicBufferConsumer::setConsumerUsageBits); return callRemote<Signature>(Tag::SET_CONSUMER_USAGE_BITS, usage); } diff --git a/libs/gui/IGraphicBufferProducer.cpp b/libs/gui/IGraphicBufferProducer.cpp index 8481b502a0..1b0fe06810 100644 --- a/libs/gui/IGraphicBufferProducer.cpp +++ b/libs/gui/IGraphicBufferProducer.cpp @@ -125,7 +125,7 @@ public: } virtual status_t dequeueBuffer(int *buf, sp<Fence>* fence, uint32_t width, - uint32_t height, PixelFormat format, uint32_t usage, + uint32_t height, PixelFormat format, uint64_t usage, FrameEventHistoryDelta* outTimestamps) { Parcel data, reply; bool getFrameTimestamps = (outTimestamps != nullptr); @@ -134,7 +134,7 @@ public: data.writeUint32(width); data.writeUint32(height); data.writeInt32(static_cast<int32_t>(format)); - data.writeUint32(usage); + data.writeUint64(usage); data.writeBool(getFrameTimestamps); status_t result = remote()->transact(DEQUEUE_BUFFER, data, &reply); @@ -333,13 +333,13 @@ public: } virtual void allocateBuffers(uint32_t width, uint32_t height, - PixelFormat format, uint32_t usage) { + PixelFormat format, uint64_t usage) { Parcel data, reply; data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); data.writeUint32(width); data.writeUint32(height); data.writeInt32(static_cast<int32_t>(format)); - data.writeUint32(usage); + data.writeUint64(usage); status_t result = remote()->transact(ALLOCATE_BUFFERS, data, &reply); if (result != NO_ERROR) { ALOGE("allocateBuffers failed to transact: %d", result); @@ -517,7 +517,7 @@ public: } status_t dequeueBuffer(int* slot, sp<Fence>* fence, uint32_t w, uint32_t h, - PixelFormat format, uint32_t usage, + PixelFormat format, uint64_t usage, FrameEventHistoryDelta* outTimestamps) override { return mBase->dequeueBuffer( slot, fence, w, h, format, usage, outTimestamps); @@ -569,7 +569,7 @@ public: } void allocateBuffers(uint32_t width, uint32_t height, - PixelFormat format, uint32_t usage) override { + PixelFormat format, uint64_t usage) override { return mBase->allocateBuffers(width, height, format, usage); } @@ -654,7 +654,7 @@ status_t BnGraphicBufferProducer::onTransact( uint32_t width = data.readUint32(); uint32_t height = data.readUint32(); PixelFormat format = static_cast<PixelFormat>(data.readInt32()); - uint32_t usage = data.readUint32(); + uint64_t usage = data.readUint64(); bool getTimestamps = data.readBool(); int buf = 0; @@ -777,7 +777,7 @@ status_t BnGraphicBufferProducer::onTransact( uint32_t width = data.readUint32(); uint32_t height = data.readUint32(); PixelFormat format = static_cast<PixelFormat>(data.readInt32()); - uint32_t usage = data.readUint32(); + uint64_t usage = data.readUint64(); allocateBuffers(width, height, format, usage); return NO_ERROR; } diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp index 83ebbe8d14..d471dbf047 100644 --- a/libs/gui/Surface.cpp +++ b/libs/gui/Surface.cpp @@ -20,6 +20,8 @@ #include <gui/Surface.h> +#include <inttypes.h> + #include <android/native_window.h> #include <utils/Log.h> @@ -471,7 +473,7 @@ int Surface::dequeueBuffer(android_native_buffer_t** buffer, int* fenceFd) { uint32_t reqWidth; uint32_t reqHeight; PixelFormat reqFormat; - uint32_t reqUsage; + uint64_t reqUsage; bool enableFrameTimestamps; { @@ -511,8 +513,8 @@ int Surface::dequeueBuffer(android_native_buffer_t** buffer, int* fenceFd) { if (result < 0) { ALOGV("dequeueBuffer: IGraphicBufferProducer::dequeueBuffer" - "(%d, %d, %d, %d) failed: %d", reqWidth, reqHeight, reqFormat, - reqUsage, result); + "(%d, %d, %d, %#" PRIx64 ") failed: %d", + reqWidth, reqHeight, reqFormat, reqUsage, result); return result; } @@ -959,6 +961,9 @@ int Surface::perform(int operation, va_list args) case NATIVE_WINDOW_GET_HDR_SUPPORT: res = dispatchGetHdrSupport(args); break; + case NATIVE_WINDOW_SET_USAGE64: + res = dispatchSetUsage64(args); + break; default: res = NAME_NOT_FOUND; break; @@ -977,8 +982,13 @@ int Surface::dispatchDisconnect(va_list args) { } int Surface::dispatchSetUsage(va_list args) { - int usage = va_arg(args, int); - return setUsage(static_cast<uint32_t>(usage)); + uint64_t usage = va_arg(args, uint32_t); + return setUsage(usage); +} + +int Surface::dispatchSetUsage64(va_list args) { + uint64_t usage = va_arg(args, uint64_t); + return setUsage(usage); } int Surface::dispatchSetCrop(va_list args) { @@ -1256,8 +1266,7 @@ int Surface::attachBuffer(ANativeWindowBuffer* buffer) uint32_t priorGeneration = graphicBuffer->mGenerationNumber; graphicBuffer->mGenerationNumber = mGenerationNumber; int32_t attachedSlot = -1; - status_t result = mGraphicBufferProducer->attachBuffer( - &attachedSlot, graphicBuffer); + status_t result = mGraphicBufferProducer->attachBuffer(&attachedSlot, graphicBuffer); if (result != NO_ERROR) { ALOGE("attachBuffer: IGraphicBufferProducer call failed (%d)", result); graphicBuffer->mGenerationNumber = priorGeneration; @@ -1271,7 +1280,7 @@ int Surface::attachBuffer(ANativeWindowBuffer* buffer) return NO_ERROR; } -int Surface::setUsage(uint32_t reqUsage) +int Surface::setUsage(uint64_t reqUsage) { ALOGV("Surface::setUsage"); Mutex::Autolock lock(mMutex); diff --git a/libs/gui/bufferqueue/1.0/H2BGraphicBufferProducer.cpp b/libs/gui/bufferqueue/1.0/H2BGraphicBufferProducer.cpp index fda5b945da..7c0552e0dc 100644 --- a/libs/gui/bufferqueue/1.0/H2BGraphicBufferProducer.cpp +++ b/libs/gui/bufferqueue/1.0/H2BGraphicBufferProducer.cpp @@ -125,7 +125,7 @@ inline void wrapAs(AnwBuffer* t, GraphicBuffer const& l) { t->attr.stride = l.getStride(); t->attr.format = static_cast<PixelFormat>(l.getPixelFormat()); t->attr.layerCount = l.getLayerCount(); - t->attr.usage = l.getUsage(); + t->attr.usage = uint32_t(l.getUsage()); // FIXME: need 64-bits usage version t->attr.id = l.getId(); t->attr.generationNumber = l.getGenerationNumber(); t->nativeHandle = hidl_handle(l.handle); @@ -988,14 +988,15 @@ status_t H2BGraphicBufferProducer::setAsyncMode(bool async) { return toStatusT(mBase->setAsyncMode(async)); } +// FIXME: usage bits truncated -- needs a 64-bits usage version status_t H2BGraphicBufferProducer::dequeueBuffer( int* slot, sp<Fence>* fence, uint32_t w, uint32_t h, ::android::PixelFormat format, - uint32_t usage, FrameEventHistoryDelta* outTimestamps) { + uint64_t usage, FrameEventHistoryDelta* outTimestamps) { *fence = new Fence(); status_t fnStatus; status_t transStatus = toStatusT(mBase->dequeueBuffer( - w, h, static_cast<PixelFormat>(format), usage, + w, h, static_cast<PixelFormat>(format), uint32_t(usage), outTimestamps != nullptr, [&fnStatus, slot, fence, outTimestamps] ( Status status, @@ -1144,10 +1145,11 @@ status_t H2BGraphicBufferProducer::setSidebandStream( return toStatusT(mBase->setSidebandStream(stream == nullptr ? nullptr : stream->handle())); } +// FIXME: usage bits truncated -- needs a 64-bits usage version void H2BGraphicBufferProducer::allocateBuffers(uint32_t width, uint32_t height, - ::android::PixelFormat format, uint32_t usage) { + ::android::PixelFormat format, uint64_t usage) { mBase->allocateBuffers( - width, height, static_cast<PixelFormat>(format), usage); + width, height, static_cast<PixelFormat>(format), uint32_t(usage)); } status_t H2BGraphicBufferProducer::allowAllocation(bool allow) { diff --git a/libs/gui/tests/Malicious.cpp b/libs/gui/tests/Malicious.cpp index 7ecf08cdb0..6bc3ccf53d 100644 --- a/libs/gui/tests/Malicious.cpp +++ b/libs/gui/tests/Malicious.cpp @@ -38,7 +38,7 @@ public: } status_t setAsyncMode(bool async) override { return mProducer->setAsyncMode(async); } status_t dequeueBuffer(int* slot, sp<Fence>* fence, uint32_t w, uint32_t h, PixelFormat format, - uint32_t usage, FrameEventHistoryDelta* outTimestamps) override { + uint64_t usage, FrameEventHistoryDelta* outTimestamps) override { return mProducer->dequeueBuffer(slot, fence, w, h, format, usage, outTimestamps); } status_t detachBuffer(int slot) override { return mProducer->detachBuffer(slot); } @@ -67,7 +67,7 @@ public: return mProducer->setSidebandStream(stream); } void allocateBuffers(uint32_t width, uint32_t height, PixelFormat format, - uint32_t usage) override { + uint64_t usage) override { mProducer->allocateBuffers(width, height, format, usage); } status_t allowAllocation(bool allow) override { return mProducer->allowAllocation(allow); } @@ -105,7 +105,7 @@ public: // Override dequeueBuffer, optionally corrupting the returned slot number status_t dequeueBuffer(int* buf, sp<Fence>* fence, uint32_t width, uint32_t height, - PixelFormat format, uint32_t usage, + PixelFormat format, uint64_t usage, FrameEventHistoryDelta* outTimestamps) override { EXPECT_EQ(BUFFER_NEEDS_REALLOCATION, mProducer->dequeueBuffer(buf, fence, width, height, format, usage, diff --git a/libs/nativebase/include/nativebase/nativebase.h b/libs/nativebase/include/nativebase/nativebase.h index 90afb3f637..7ecdfbd745 100644 --- a/libs/nativebase/include/nativebase/nativebase.h +++ b/libs/nativebase/include/nativebase/nativebase.h @@ -88,14 +88,18 @@ typedef struct ANativeWindowBuffer int height; int stride; int format; - int usage; + int usage_deprecated; uintptr_t layerCount; void* reserved[1]; const native_handle_t* handle; + uint64_t usage; - void* reserved_proc[8]; + // we needed extra space for storing the 64-bits usage flags + // the number of slots to use from reserved_proc depends on the + // architecture. + void* reserved_proc[8 - (sizeof(uint64_t) / sizeof(void*))]; } ANativeWindowBuffer_t; typedef struct ANativeWindowBuffer ANativeWindowBuffer; diff --git a/libs/nativewindow/ANativeWindow.cpp b/libs/nativewindow/ANativeWindow.cpp index 9224df604a..c6994c30b4 100644 --- a/libs/nativewindow/ANativeWindow.cpp +++ b/libs/nativewindow/ANativeWindow.cpp @@ -190,8 +190,7 @@ int ANativeWindow_cancelBuffer(ANativeWindow* window, ANativeWindowBuffer* buffe } int ANativeWindow_setUsage(ANativeWindow* window, uint64_t usage) { - usage = AHardwareBuffer_convertToGrallocUsageBits(usage); - return native_window_set_usage(window, (uint32_t)usage); // FIXME: we need a 64-bits version + return native_window_set_usage(window, usage); } int ANativeWindow_setBufferCount(ANativeWindow* window, size_t bufferCount) { diff --git a/libs/nativewindow/include/system/window.h b/libs/nativewindow/include/system/window.h index 6429c52f61..3df97a1b4a 100644 --- a/libs/nativewindow/include/system/window.h +++ b/libs/nativewindow/include/system/window.h @@ -193,36 +193,37 @@ enum { */ enum { // clang-format off - NATIVE_WINDOW_SET_USAGE = 0, - NATIVE_WINDOW_CONNECT = 1, /* deprecated */ - NATIVE_WINDOW_DISCONNECT = 2, /* deprecated */ - NATIVE_WINDOW_SET_CROP = 3, /* private */ - NATIVE_WINDOW_SET_BUFFER_COUNT = 4, - NATIVE_WINDOW_SET_BUFFERS_GEOMETRY = 5, /* deprecated */ - NATIVE_WINDOW_SET_BUFFERS_TRANSFORM = 6, - NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP = 7, - NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS = 8, - NATIVE_WINDOW_SET_BUFFERS_FORMAT = 9, - NATIVE_WINDOW_SET_SCALING_MODE = 10, /* private */ - NATIVE_WINDOW_LOCK = 11, /* private */ - NATIVE_WINDOW_UNLOCK_AND_POST = 12, /* private */ - NATIVE_WINDOW_API_CONNECT = 13, /* private */ - NATIVE_WINDOW_API_DISCONNECT = 14, /* private */ - NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS = 15, /* private */ - NATIVE_WINDOW_SET_POST_TRANSFORM_CROP = 16, /* private */ - NATIVE_WINDOW_SET_BUFFERS_STICKY_TRANSFORM = 17,/* private */ - NATIVE_WINDOW_SET_SIDEBAND_STREAM = 18, - NATIVE_WINDOW_SET_BUFFERS_DATASPACE = 19, - NATIVE_WINDOW_SET_SURFACE_DAMAGE = 20, /* private */ - NATIVE_WINDOW_SET_SHARED_BUFFER_MODE = 21, - NATIVE_WINDOW_SET_AUTO_REFRESH = 22, - NATIVE_WINDOW_GET_REFRESH_CYCLE_DURATION= 23, - NATIVE_WINDOW_GET_NEXT_FRAME_ID = 24, - NATIVE_WINDOW_ENABLE_FRAME_TIMESTAMPS = 25, - NATIVE_WINDOW_GET_COMPOSITOR_TIMING = 26, - NATIVE_WINDOW_GET_FRAME_TIMESTAMPS = 27, - NATIVE_WINDOW_GET_WIDE_COLOR_SUPPORT = 28, - NATIVE_WINDOW_GET_HDR_SUPPORT = 29, + NATIVE_WINDOW_SET_USAGE = 0, /* deprecated */ + NATIVE_WINDOW_CONNECT = 1, /* deprecated */ + NATIVE_WINDOW_DISCONNECT = 2, /* deprecated */ + NATIVE_WINDOW_SET_CROP = 3, /* private */ + NATIVE_WINDOW_SET_BUFFER_COUNT = 4, + NATIVE_WINDOW_SET_BUFFERS_GEOMETRY = 5, /* deprecated */ + NATIVE_WINDOW_SET_BUFFERS_TRANSFORM = 6, + NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP = 7, + NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS = 8, + NATIVE_WINDOW_SET_BUFFERS_FORMAT = 9, + NATIVE_WINDOW_SET_SCALING_MODE = 10, /* private */ + NATIVE_WINDOW_LOCK = 11, /* private */ + NATIVE_WINDOW_UNLOCK_AND_POST = 12, /* private */ + NATIVE_WINDOW_API_CONNECT = 13, /* private */ + NATIVE_WINDOW_API_DISCONNECT = 14, /* private */ + NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS = 15, /* private */ + NATIVE_WINDOW_SET_POST_TRANSFORM_CROP = 16, /* deprecated, unimplemented */ + NATIVE_WINDOW_SET_BUFFERS_STICKY_TRANSFORM = 17, /* private */ + NATIVE_WINDOW_SET_SIDEBAND_STREAM = 18, + NATIVE_WINDOW_SET_BUFFERS_DATASPACE = 19, + NATIVE_WINDOW_SET_SURFACE_DAMAGE = 20, /* private */ + NATIVE_WINDOW_SET_SHARED_BUFFER_MODE = 21, + NATIVE_WINDOW_SET_AUTO_REFRESH = 22, + NATIVE_WINDOW_GET_REFRESH_CYCLE_DURATION = 23, + NATIVE_WINDOW_GET_NEXT_FRAME_ID = 24, + NATIVE_WINDOW_ENABLE_FRAME_TIMESTAMPS = 25, + NATIVE_WINDOW_GET_COMPOSITOR_TIMING = 26, + NATIVE_WINDOW_GET_FRAME_TIMESTAMPS = 27, + NATIVE_WINDOW_GET_WIDE_COLOR_SUPPORT = 28, + NATIVE_WINDOW_GET_HDR_SUPPORT = 29, + NATIVE_WINDOW_SET_USAGE64 = 30, // clang-format on }; @@ -533,20 +534,18 @@ struct ANativeWindow typedef struct ANativeWindow android_native_window_t __deprecated; /* - * native_window_set_usage(..., usage) + * native_window_set_usage64(..., usage) * Sets the intended usage flags for the next buffers * acquired with (*lockBuffer)() and on. - * By default (if this function is never called), a usage of - * GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE - * is assumed. + * + * Valid usage flags are defined in android/hardware_buffer.h + * All AHARDWAREBUFFER_USAGE_* flags can be specified as needed. + * * Calling this function will usually cause following buffers to be * reallocated. */ - -static inline int native_window_set_usage( - struct ANativeWindow* window, int usage) -{ - return window->perform(window, NATIVE_WINDOW_SET_USAGE, usage); +static inline int native_window_set_usage(struct ANativeWindow* window, uint64_t usage) { + return window->perform(window, NATIVE_WINDOW_SET_USAGE64, usage); } /* deprecated. Always returns 0. Don't call. */ @@ -589,45 +588,6 @@ static inline int native_window_set_crop( } /* - * native_window_set_post_transform_crop(..., crop) - * Sets which region of the next queued buffers needs to be considered. - * Depending on the scaling mode, a buffer's crop region is scaled and/or - * cropped to match the surface's size. This function sets the crop in - * post-transformed pixel coordinates. - * - * The specified crop region applies to all buffers queued after it is called. - * - * If 'crop' is NULL, subsequently queued buffers won't be cropped. - * - * An error is returned if for instance the crop region is invalid, out of the - * buffer's bound or if the window is invalid. - */ -static inline int native_window_set_post_transform_crop( - struct ANativeWindow* window, - android_native_rect_t const * crop) -{ - return window->perform(window, NATIVE_WINDOW_SET_POST_TRANSFORM_CROP, crop); -} - -/* - * native_window_set_active_rect(..., active_rect) - * - * This function is deprecated and will be removed soon. For now it simply - * sets the post-transform crop for compatibility while multi-project commits - * get checked. - */ -static inline int native_window_set_active_rect( - struct ANativeWindow* window, - android_native_rect_t const * active_rect) __deprecated; - -static inline int native_window_set_active_rect( - struct ANativeWindow* window, - android_native_rect_t const * active_rect) -{ - return native_window_set_post_transform_crop(window, active_rect); -} - -/* * native_window_set_buffer_count(..., count) * Sets the number of buffers associated with this native window. */ diff --git a/libs/ui/GraphicBuffer.cpp b/libs/ui/GraphicBuffer.cpp index ee85c9bad9..c8805000a4 100644 --- a/libs/ui/GraphicBuffer.cpp +++ b/libs/ui/GraphicBuffer.cpp @@ -51,6 +51,7 @@ GraphicBuffer::GraphicBuffer() height = stride = format = + usage_deprecated = 0; usage = 0; layerCount = 0; handle = NULL; @@ -59,14 +60,12 @@ GraphicBuffer::GraphicBuffer() // deprecated GraphicBuffer::GraphicBuffer(uint32_t inWidth, uint32_t inHeight, PixelFormat inFormat, uint32_t inUsage, std::string requestorName) - : GraphicBuffer(inWidth, inHeight, inFormat, 1, static_cast<uint64_t>(inUsage), - requestorName) + : GraphicBuffer(inWidth, inHeight, inFormat, 1, static_cast<uint64_t>(inUsage), requestorName) { } GraphicBuffer::GraphicBuffer(uint32_t inWidth, uint32_t inHeight, - PixelFormat inFormat, uint32_t inLayerCount, uint64_t usage, - std::string requestorName) + PixelFormat inFormat, uint32_t inLayerCount, uint64_t usage, std::string requestorName) : GraphicBuffer() { mInitCheck = initWithSize(inWidth, inHeight, inFormat, inLayerCount, @@ -139,7 +138,7 @@ status_t GraphicBuffer::reallocate(uint32_t inWidth, uint32_t inHeight, static_cast<int>(inHeight) == height && inFormat == format && inLayerCount == layerCount && - static_cast<int>(inUsage) == usage) + inUsage == usage) return NO_ERROR; if (handle) { @@ -147,8 +146,7 @@ status_t GraphicBuffer::reallocate(uint32_t inWidth, uint32_t inHeight, allocator.free(handle); handle = 0; } - return initWithSize(inWidth, inHeight, inFormat, inLayerCount, - inUsage, "[Reallocation]"); + return initWithSize(inWidth, inHeight, inFormat, inLayerCount, inUsage, "[Reallocation]"); } bool GraphicBuffer::needsReallocation(uint32_t inWidth, uint32_t inHeight, @@ -158,7 +156,7 @@ bool GraphicBuffer::needsReallocation(uint32_t inWidth, uint32_t inHeight, if (static_cast<int>(inHeight) != height) return true; if (inFormat != format) return true; if (inLayerCount != layerCount) return true; - if ((static_cast<uint32_t>(usage) & inUsage) != inUsage) return true; + if ((usage & inUsage) != inUsage) return true; return false; } @@ -176,7 +174,8 @@ status_t GraphicBuffer::initWithSize(uint32_t inWidth, uint32_t inHeight, height = static_cast<int>(inHeight); format = inFormat; layerCount = inLayerCount; - usage = static_cast<int>(inUsage); + usage = inUsage; + usage_deprecated = int(usage); stride = static_cast<int>(outStride); } return err; @@ -191,7 +190,8 @@ status_t GraphicBuffer::initWithHandle(const native_handle_t* handle, ANativeWindowBuffer::height = static_cast<int>(height); ANativeWindowBuffer::stride = static_cast<int>(stride); ANativeWindowBuffer::format = format; - ANativeWindowBuffer::usage = static_cast<int>(usage); + ANativeWindowBuffer::usage = usage; + ANativeWindowBuffer::usage_deprecated = int(usage); ANativeWindowBuffer::layerCount = layerCount; @@ -312,8 +312,7 @@ status_t GraphicBuffer::lockAsyncYCbCr(uint32_t inUsage, const Rect& rect, width, height); return BAD_VALUE; } - status_t res = getBufferMapper().lockAsyncYCbCr(handle, inUsage, rect, - ycbcr, fenceFd); + status_t res = getBufferMapper().lockAsyncYCbCr(handle, inUsage, rect, ycbcr, fenceFd); return res; } @@ -324,7 +323,7 @@ status_t GraphicBuffer::unlockAsync(int *fenceFd) } size_t GraphicBuffer::getFlattenedSize() const { - return static_cast<size_t>(12 + (handle ? handle->numInts : 0)) * sizeof(int); + return static_cast<size_t>(13 + (handle ? handle->numInts : 0)) * sizeof(int); } size_t GraphicBuffer::getFdCount() const { @@ -339,25 +338,25 @@ status_t GraphicBuffer::flatten(void*& buffer, size_t& size, int*& fds, size_t& if (count < fdCountNeeded) return NO_MEMORY; int32_t* buf = static_cast<int32_t*>(buffer); - buf[0] = 'GBFR'; + buf[0] = 'GB01'; buf[1] = width; buf[2] = height; buf[3] = stride; buf[4] = format; buf[5] = static_cast<int32_t>(layerCount); - buf[6] = usage; + buf[6] = int(usage); // low 32-bits buf[7] = static_cast<int32_t>(mId >> 32); buf[8] = static_cast<int32_t>(mId & 0xFFFFFFFFull); buf[9] = static_cast<int32_t>(mGenerationNumber); buf[10] = 0; buf[11] = 0; + buf[12] = int(usage >> 32); // high 32-bits if (handle) { buf[10] = handle->numFds; buf[11] = handle->numInts; - memcpy(fds, handle->data, - static_cast<size_t>(handle->numFds) * sizeof(int)); - memcpy(&buf[12], handle->data + handle->numFds, + memcpy(fds, handle->data, static_cast<size_t>(handle->numFds) * sizeof(int)); + memcpy(buf + 13, handle->data + handle->numFds, static_cast<size_t>(handle->numInts) * sizeof(int)); } @@ -373,10 +372,21 @@ status_t GraphicBuffer::flatten(void*& buffer, size_t& size, int*& fds, size_t& status_t GraphicBuffer::unflatten( void const*& buffer, size_t& size, int const*& fds, size_t& count) { - if (size < 12 * sizeof(int)) return NO_MEMORY; int const* buf = static_cast<int const*>(buffer); - if (buf[0] != 'GBFR') return BAD_TYPE; + + // NOTE: it turns out that some media code generates a flattened GraphicBuffer manually!!!!! + // see H2BGraphicBufferProducer.cpp + uint32_t flattenWordCount = 0; + if (buf[0] == 'GB01') { + // new version with 64-bits usage bits + flattenWordCount = 13; + } else if (buf[0] == 'GBFR') { + // old version, when usage bits were 32-bits + flattenWordCount = 12; + } else { + return BAD_TYPE; + } const size_t numFds = static_cast<size_t>(buf[10]); const size_t numInts = static_cast<size_t>(buf[11]); @@ -386,15 +396,16 @@ status_t GraphicBuffer::unflatten( // chosen to be high enough to not cause issues and low enough to prevent // overflow problems. const size_t maxNumber = 4096; - if (numFds >= maxNumber || numInts >= (maxNumber - 12)) { - width = height = stride = format = layerCount = usage = 0; + if (numFds >= maxNumber || numInts >= (maxNumber - flattenWordCount)) { + width = height = stride = format = usage_deprecated = 0; + layerCount = 0; + usage = 0; handle = NULL; - ALOGE("unflatten: numFds or numInts is too large: %zd, %zd", - numFds, numInts); + ALOGE("unflatten: numFds or numInts is too large: %zd, %zd", numFds, numInts); return BAD_VALUE; } - const size_t sizeNeeded = (12 + numInts) * sizeof(int); + const size_t sizeNeeded = (flattenWordCount + numInts) * sizeof(int); if (size < sizeNeeded) return NO_MEMORY; size_t fdCountNeeded = numFds; @@ -411,20 +422,29 @@ status_t GraphicBuffer::unflatten( stride = buf[3]; format = buf[4]; layerCount = static_cast<uintptr_t>(buf[5]); - usage = buf[6]; + usage_deprecated = buf[6]; + if (flattenWordCount == 13) { + usage = (uint64_t(buf[12]) << 32) | uint32_t(buf[6]); + } else { + usage = uint64_t(usage_deprecated); + } native_handle* h = native_handle_create( static_cast<int>(numFds), static_cast<int>(numInts)); if (!h) { - width = height = stride = format = layerCount = usage = 0; + width = height = stride = format = usage_deprecated = 0; + layerCount = 0; + usage = 0; handle = NULL; ALOGE("unflatten: native_handle_create failed"); return NO_MEMORY; } memcpy(h->data, fds, numFds * sizeof(int)); - memcpy(h->data + numFds, &buf[12], numInts * sizeof(int)); + memcpy(h->data + numFds, buf + flattenWordCount, numInts * sizeof(int)); handle = h; } else { - width = height = stride = format = layerCount = usage = 0; + width = height = stride = format = usage_deprecated = 0; + layerCount = 0; + usage = 0; handle = NULL; } @@ -439,10 +459,11 @@ status_t GraphicBuffer::unflatten( buffer_handle_t importedHandle; status_t err = mBufferMapper.importBuffer(handle, &importedHandle); if (err != NO_ERROR) { - width = height = stride = format = layerCount = usage = 0; + width = height = stride = format = usage_deprecated = 0; + layerCount = 0; + usage = 0; handle = NULL; - ALOGE("unflatten: registerBuffer failed: %s (%d)", - strerror(-err), err); + ALOGE("unflatten: registerBuffer failed: %s (%d)", strerror(-err), err); return err; } diff --git a/libs/ui/include/ui/GraphicBuffer.h b/libs/ui/include/ui/GraphicBuffer.h index 9a5aa6937a..95c2d2272e 100644 --- a/libs/ui/include/ui/GraphicBuffer.h +++ b/libs/ui/include/ui/GraphicBuffer.h @@ -141,7 +141,7 @@ public: uint32_t getWidth() const { return static_cast<uint32_t>(width); } uint32_t getHeight() const { return static_cast<uint32_t>(height); } uint32_t getStride() const { return static_cast<uint32_t>(stride); } - uint32_t getUsage() const { return static_cast<uint32_t>(usage); } + uint64_t getUsage() const { return usage; } PixelFormat getPixelFormat() const { return format; } uint32_t getLayerCount() const { return static_cast<uint32_t>(layerCount); } Rect getBounds() const { return Rect(width, height); } diff --git a/libs/vr/libbufferhubqueue/buffer_hub_queue_producer.cpp b/libs/vr/libbufferhubqueue/buffer_hub_queue_producer.cpp index 7dd076af61..fca5eca0d1 100644 --- a/libs/vr/libbufferhubqueue/buffer_hub_queue_producer.cpp +++ b/libs/vr/libbufferhubqueue/buffer_hub_queue_producer.cpp @@ -131,9 +131,9 @@ status_t BufferHubQueueProducer::setAsyncMode(bool async) { status_t BufferHubQueueProducer::dequeueBuffer( int* out_slot, sp<Fence>* out_fence, uint32_t width, uint32_t height, - PixelFormat format, uint32_t usage, + PixelFormat format, uint64_t usage, FrameEventHistoryDelta* /* out_timestamps */) { - ALOGD_IF(TRACE, "dequeueBuffer: w=%u, h=%u, format=%d, usage=%u", width, + ALOGD_IF(TRACE, "dequeueBuffer: w=%u, h=%u, format=%d, usage=%llu", width, height, format, usage); status_t ret; @@ -532,7 +532,7 @@ status_t BufferHubQueueProducer::setSidebandStream( void BufferHubQueueProducer::allocateBuffers(uint32_t /* width */, uint32_t /* height */, PixelFormat /* format */, - uint32_t /* usage */) { + uint64_t /* usage */) { // TODO(jwcai) |allocateBuffers| aims to preallocate up to the maximum number // of buffers permitted by the current BufferQueue configuration (aka // |max_buffer_count_|). diff --git a/libs/vr/libbufferhubqueue/include/private/dvr/buffer_hub_queue_producer.h b/libs/vr/libbufferhubqueue/include/private/dvr/buffer_hub_queue_producer.h index 7890176f04..638a56caef 100644 --- a/libs/vr/libbufferhubqueue/include/private/dvr/buffer_hub_queue_producer.h +++ b/libs/vr/libbufferhubqueue/include/private/dvr/buffer_hub_queue_producer.h @@ -42,7 +42,7 @@ class BufferHubQueueProducer : public BnGraphicBufferProducer { // See |IGraphicBufferProducer::dequeueBuffer| status_t dequeueBuffer(int* out_slot, sp<Fence>* out_fence, uint32_t width, - uint32_t height, PixelFormat format, uint32_t usage, + uint32_t height, PixelFormat format, uint64_t usage, FrameEventHistoryDelta* outTimestamps) override; // See |IGraphicBufferProducer::detachBuffer| @@ -80,7 +80,7 @@ class BufferHubQueueProducer : public BnGraphicBufferProducer { // See |IGraphicBufferProducer::allocateBuffers| void allocateBuffers(uint32_t width, uint32_t height, PixelFormat format, - uint32_t usage) override; + uint64_t usage) override; // See |IGraphicBufferProducer::allowAllocation| status_t allowAllocation(bool allow) override; diff --git a/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.cpp b/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.cpp index 6e843d9f33..c129ae546c 100644 --- a/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.cpp +++ b/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.cpp @@ -16,6 +16,9 @@ // #define LOG_NDEBUG 0 #include "VirtualDisplaySurface.h" + +#include <inttypes.h> + #include "HWComposer.h" #include "SurfaceFlinger.h" @@ -339,7 +342,7 @@ status_t VirtualDisplaySurface::setAsyncMode(bool async) { } status_t VirtualDisplaySurface::dequeueBuffer(Source source, - PixelFormat format, uint32_t usage, int* sslot, sp<Fence>* fence) { + PixelFormat format, uint64_t usage, int* sslot, sp<Fence>* fence) { LOG_FATAL_IF(mDisplayId < 0, "mDisplayId=%d but should not be < 0.", mDisplayId); status_t result = mSource[source]->dequeueBuffer(sslot, fence, @@ -372,7 +375,7 @@ status_t VirtualDisplaySurface::dequeueBuffer(Source source, mSource[source]->cancelBuffer(*sslot, *fence); return result; } - VDS_LOGV("dequeueBuffer(%s): buffers[%d]=%p fmt=%d usage=%#x", + VDS_LOGV("dequeueBuffer(%s): buffers[%d]=%p fmt=%d usage=%#" PRIx64, dbgSourceStr(source), pslot, mProducerBuffers[pslot].get(), mProducerBuffers[pslot]->getPixelFormat(), mProducerBuffers[pslot]->getUsage()); @@ -382,7 +385,7 @@ status_t VirtualDisplaySurface::dequeueBuffer(Source source, } status_t VirtualDisplaySurface::dequeueBuffer(int* pslot, sp<Fence>* fence, - uint32_t w, uint32_t h, PixelFormat format, uint32_t usage, + uint32_t w, uint32_t h, PixelFormat format, uint64_t usage, FrameEventHistoryDelta* outTimestamps) { if (mDisplayId < 0) { return mSource[SOURCE_SINK]->dequeueBuffer( @@ -393,7 +396,7 @@ status_t VirtualDisplaySurface::dequeueBuffer(int* pslot, sp<Fence>* fence, "Unexpected dequeueBuffer() in %s state", dbgStateStr()); mDbgState = DBG_STATE_GLES; - VDS_LOGV("dequeueBuffer %dx%d fmt=%d usage=%#x", w, h, format, usage); + VDS_LOGV("dequeueBuffer %dx%d fmt=%d usage=%#" PRIx64, w, h, format, usage); status_t result = NO_ERROR; Source source = fbSourceForCompositionType(mCompositionType); @@ -423,8 +426,8 @@ status_t VirtualDisplaySurface::dequeueBuffer(int* pslot, sp<Fence>* fence, (w != 0 && w != mSinkBufferWidth) || (h != 0 && h != mSinkBufferHeight)) { VDS_LOGV("dequeueBuffer: dequeueing new output buffer: " - "want %dx%d fmt=%d use=%#x, " - "have %dx%d fmt=%d use=%#x", + "want %dx%d fmt=%d use=%#" PRIx64 ", " + "have %dx%d fmt=%d use=%#" PRIx64, w, h, format, usage, mSinkBufferWidth, mSinkBufferHeight, buf->getPixelFormat(), buf->getUsage()); @@ -575,7 +578,7 @@ status_t VirtualDisplaySurface::setSidebandStream(const sp<NativeHandle>& /*stre } void VirtualDisplaySurface::allocateBuffers(uint32_t /* width */, - uint32_t /* height */, PixelFormat /* format */, uint32_t /* usage */) { + uint32_t /* height */, PixelFormat /* format */, uint64_t /* usage */) { // TODO: Should we actually allocate buffers for a virtual display? } diff --git a/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.h b/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.h index 5c0e084fb9..7f8b39b62b 100644 --- a/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.h +++ b/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.h @@ -105,7 +105,7 @@ private: virtual status_t setMaxDequeuedBufferCount(int maxDequeuedBuffers); virtual status_t setAsyncMode(bool async); virtual status_t dequeueBuffer(int* pslot, sp<Fence>* fence, uint32_t w, - uint32_t h, PixelFormat format, uint32_t usage, + uint32_t h, PixelFormat format, uint64_t usage, FrameEventHistoryDelta *outTimestamps); virtual status_t detachBuffer(int slot); virtual status_t detachNextBuffer(sp<GraphicBuffer>* outBuffer, @@ -120,7 +120,7 @@ private: virtual status_t disconnect(int api, DisconnectMode mode); virtual status_t setSidebandStream(const sp<NativeHandle>& stream); virtual void allocateBuffers(uint32_t width, uint32_t height, - PixelFormat format, uint32_t usage); + PixelFormat format, uint64_t usage); virtual status_t allowAllocation(bool allow); virtual status_t setGenerationNumber(uint32_t generationNumber); virtual String8 getConsumerName() const override; @@ -135,7 +135,7 @@ private: // Utility methods // static Source fbSourceForCompositionType(CompositionType type); - status_t dequeueBuffer(Source source, PixelFormat format, uint32_t usage, + status_t dequeueBuffer(Source source, PixelFormat format, uint64_t usage, int* sslot, sp<Fence>* fence); void updateQueueBufferOutput(QueueBufferOutput&& qbo); void resetPerFrameState(); @@ -168,7 +168,7 @@ private: // the composition type changes or the GLES driver starts requesting // different usage/format, we'll get a new buffer. uint32_t mOutputFormat; - uint32_t mOutputUsage; + uint64_t mOutputUsage; // Since we present a single producer interface to the GLES driver, but // are internally muxing between the sink and scratch producers, we have diff --git a/services/surfaceflinger/MonitoredProducer.cpp b/services/surfaceflinger/MonitoredProducer.cpp index 2ba1b338dd..e717632c0f 100644 --- a/services/surfaceflinger/MonitoredProducer.cpp +++ b/services/surfaceflinger/MonitoredProducer.cpp @@ -69,7 +69,7 @@ status_t MonitoredProducer::setAsyncMode(bool async) { } status_t MonitoredProducer::dequeueBuffer(int* slot, sp<Fence>* fence, - uint32_t w, uint32_t h, PixelFormat format, uint32_t usage, + uint32_t w, uint32_t h, PixelFormat format, uint64_t usage, FrameEventHistoryDelta* outTimestamps) { return mProducer->dequeueBuffer( slot, fence, w, h, format, usage, outTimestamps); @@ -116,7 +116,7 @@ status_t MonitoredProducer::setSidebandStream(const sp<NativeHandle>& stream) { } void MonitoredProducer::allocateBuffers(uint32_t width, uint32_t height, - PixelFormat format, uint32_t usage) { + PixelFormat format, uint64_t usage) { mProducer->allocateBuffers(width, height, format, usage); } diff --git a/services/surfaceflinger/MonitoredProducer.h b/services/surfaceflinger/MonitoredProducer.h index a3ec29d711..58b9bc4e2e 100644 --- a/services/surfaceflinger/MonitoredProducer.h +++ b/services/surfaceflinger/MonitoredProducer.h @@ -40,7 +40,7 @@ public: virtual status_t setMaxDequeuedBufferCount(int maxDequeuedBuffers); virtual status_t setAsyncMode(bool async); virtual status_t dequeueBuffer(int* slot, sp<Fence>* fence, uint32_t w, - uint32_t h, PixelFormat format, uint32_t usage, + uint32_t h, PixelFormat format, uint64_t usage, FrameEventHistoryDelta* outTimestamps); virtual status_t detachBuffer(int slot); virtual status_t detachNextBuffer(sp<GraphicBuffer>* outBuffer, @@ -56,7 +56,7 @@ public: virtual status_t disconnect(int api, DisconnectMode mode); virtual status_t setSidebandStream(const sp<NativeHandle>& stream); virtual void allocateBuffers(uint32_t width, uint32_t height, - PixelFormat format, uint32_t usage); + PixelFormat format, uint64_t usage); virtual status_t allowAllocation(bool allow); virtual status_t setGenerationNumber(uint32_t generationNumber); virtual String8 getConsumerName() const override; diff --git a/vulkan/libvulkan/swapchain.cpp b/vulkan/libvulkan/swapchain.cpp index cb893aa912..ded9549b27 100644 --- a/vulkan/libvulkan/swapchain.cpp +++ b/vulkan/libvulkan/swapchain.cpp @@ -1015,7 +1015,7 @@ VkResult CreateSwapchainKHR(VkDevice device, return VK_ERROR_SURFACE_LOST_KHR; } } - err = native_window_set_usage(surface.window.get(), gralloc_usage); + err = native_window_set_usage(surface.window.get(), uint64_t(gralloc_usage)); if (err != 0) { // TODO(jessehall): Improve error reporting. Can we enumerate possible // errors and translate them to valid Vulkan result codes? @@ -1092,7 +1092,7 @@ VkResult CreateSwapchainKHR(VkDevice device, image_native_buffer.handle = img.buffer->handle; image_native_buffer.stride = img.buffer->stride; image_native_buffer.format = img.buffer->format; - image_native_buffer.usage = img.buffer->usage; + image_native_buffer.usage = int(img.buffer->usage); // TODO: Adjust once ANativeWindowBuffer supports gralloc1-style usage. // For now, this is the same translation Gralloc1On0Adapter does. image_native_buffer.usage2.consumer = |