From ffe17a14ad6c8e21baf2ff765e31b975815bef73 Mon Sep 17 00:00:00 2001 From: Chong Zhang Date: Fri, 22 May 2015 10:54:25 -0700 Subject: [PATCH] fix BufferItem flatten/unflatten alignment bug: 21370100 Change-Id: Ia3991dc591c176bdbd1d78d1804aa22777525b62 (cherry picked from commit 47f674dfeca31b29810ecb90f1277918b67c4cf8) --- include/gui/BufferItem.h | 16 ++++++++++++++-- libs/gui/BufferItem.cpp | 25 ++++++++++++------------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/include/gui/BufferItem.h b/include/gui/BufferItem.h index 000ef0e87..145efe6f6 100644 --- a/include/gui/BufferItem.h +++ b/include/gui/BufferItem.h @@ -72,7 +72,13 @@ class BufferItem : public Flattenable { // to set by queueBuffer each time this slot is queued. This value // is guaranteed to be monotonically increasing for each newly // acquired buffer. - int64_t mTimestamp; + union { + int64_t mTimestamp; + struct { + uint32_t mTimestampLo; + uint32_t mTimestampHi; + }; + }; // mIsAutoTimestamp indicates whether mTimestamp was generated // automatically when the buffer was queued. @@ -84,7 +90,13 @@ class BufferItem : public Flattenable { android_dataspace mDataSpace; // mFrameNumber is the number of the queued frame for this slot. - uint64_t mFrameNumber; + union { + uint64_t mFrameNumber; + struct { + uint32_t mFrameNumberLo; + uint32_t mFrameNumberHi; + }; + }; union { // mSlot is the slot index of this buffer (default INVALID_BUFFER_SLOT). diff --git a/libs/gui/BufferItem.cpp b/libs/gui/BufferItem.cpp index 5793d405e..8f64ae0e0 100644 --- a/libs/gui/BufferItem.cpp +++ b/libs/gui/BufferItem.cpp @@ -46,15 +46,16 @@ static void addAligned(size_t& size, T /* value */) { } size_t BufferItem::getPodSize() const { - // Must align<8> before writing these fields for this to be correct size_t size = 0; addAligned(size, mCrop); addAligned(size, mTransform); addAligned(size, mScalingMode); - addAligned(size, mTimestamp); + addAligned(size, mTimestampLo); + addAligned(size, mTimestampHi); addAligned(size, mIsAutoTimestamp); addAligned(size, mDataSpace); - addAligned(size, mFrameNumber); + addAligned(size, mFrameNumberLo); + addAligned(size, mFrameNumberHi); addAligned(size, mSlot); addAligned(size, mIsDroppable); addAligned(size, mAcquireCalled); @@ -126,9 +127,6 @@ status_t BufferItem::flatten( if (err) return err; FlattenableUtils::advance(buffer, size, mSurfaceDamage.getFlattenedSize()); - // Must align<8> so that getPodSize returns the correct value - size -= FlattenableUtils::align<8>(buffer); - // Check we still have enough space if (size < getPodSize()) { return NO_MEMORY; @@ -137,10 +135,12 @@ status_t BufferItem::flatten( writeAligned(buffer, size, mCrop); writeAligned(buffer, size, mTransform); writeAligned(buffer, size, mScalingMode); - writeAligned(buffer, size, mTimestamp); + writeAligned(buffer, size, mTimestampLo); + writeAligned(buffer, size, mTimestampHi); writeAligned(buffer, size, mIsAutoTimestamp); writeAligned(buffer, size, mDataSpace); - writeAligned(buffer, size, mFrameNumber); + writeAligned(buffer, size, mFrameNumberLo); + writeAligned(buffer, size, mFrameNumberHi); writeAligned(buffer, size, mSlot); writeAligned(buffer, size, mIsDroppable); writeAligned(buffer, size, mAcquireCalled); @@ -183,9 +183,6 @@ status_t BufferItem::unflatten( if (err) return err; FlattenableUtils::advance(buffer, size, mSurfaceDamage.getFlattenedSize()); - // Must align<8> so that getPodSize returns the correct value - size -= FlattenableUtils::align<8>(buffer); - // Check we still have enough space if (size < getPodSize()) { return NO_MEMORY; @@ -194,10 +191,12 @@ status_t BufferItem::unflatten( readAligned(buffer, size, mCrop); readAligned(buffer, size, mTransform); readAligned(buffer, size, mScalingMode); - readAligned(buffer, size, mTimestamp); + readAligned(buffer, size, mTimestampLo); + readAligned(buffer, size, mTimestampHi); readAligned(buffer, size, mIsAutoTimestamp); readAligned(buffer, size, mDataSpace); - readAligned(buffer, size, mFrameNumber); + readAligned(buffer, size, mFrameNumberLo); + readAligned(buffer, size, mFrameNumberHi); readAligned(buffer, size, mSlot); readAligned(buffer, size, mIsDroppable); readAligned(buffer, size, mAcquireCalled);