libui/libgui: Fix errors in parceling
BufferItem and GraphicBuffer were not parceling correctly, which had not been noticed because the libgui tests (specifically, one that tests placing a BufferQueue in a separate process from the IGBP/C) had not been run recently. This change fixes the errors found in those classes. Change-Id: Ie224361a534a79115a3481d83ff97f21d154d4f5
This commit is contained in:
parent
ff5c1a6b67
commit
eea6d682b8
@ -39,52 +39,66 @@ BufferItem::BufferItem() :
|
||||
|
||||
BufferItem::~BufferItem() {}
|
||||
|
||||
template <typename T>
|
||||
static void addAligned(size_t& size, T /* value */) {
|
||||
size = FlattenableUtils::align<sizeof(T)>(size);
|
||||
size += sizeof(T);
|
||||
}
|
||||
|
||||
size_t BufferItem::getPodSize() const {
|
||||
size_t c = sizeof(mCrop) +
|
||||
sizeof(mTransform) +
|
||||
sizeof(mScalingMode) +
|
||||
sizeof(mTimestamp) +
|
||||
sizeof(mIsAutoTimestamp) +
|
||||
sizeof(mDataSpace) +
|
||||
sizeof(mFrameNumber) +
|
||||
sizeof(mSlot) +
|
||||
sizeof(mIsDroppable) +
|
||||
sizeof(mAcquireCalled) +
|
||||
sizeof(mTransformToDisplayInverse);
|
||||
return c;
|
||||
// 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, mIsAutoTimestamp);
|
||||
addAligned(size, mDataSpace);
|
||||
addAligned(size, mFrameNumber);
|
||||
addAligned(size, mSlot);
|
||||
addAligned(size, mIsDroppable);
|
||||
addAligned(size, mAcquireCalled);
|
||||
addAligned(size, mTransformToDisplayInverse);
|
||||
return size;
|
||||
}
|
||||
|
||||
size_t BufferItem::getFlattenedSize() const {
|
||||
size_t c = 0;
|
||||
size_t size = sizeof(uint32_t); // Flags
|
||||
if (mGraphicBuffer != 0) {
|
||||
c += mGraphicBuffer->getFlattenedSize();
|
||||
FlattenableUtils::align<4>(c);
|
||||
size += mGraphicBuffer->getFlattenedSize();
|
||||
FlattenableUtils::align<4>(size);
|
||||
}
|
||||
if (mFence != 0) {
|
||||
c += mFence->getFlattenedSize();
|
||||
FlattenableUtils::align<4>(c);
|
||||
size += mFence->getFlattenedSize();
|
||||
FlattenableUtils::align<4>(size);
|
||||
}
|
||||
c += mSurfaceDamage.getFlattenedSize();
|
||||
FlattenableUtils::align<4>(c);
|
||||
return sizeof(int32_t) + c + getPodSize();
|
||||
size += mSurfaceDamage.getFlattenedSize();
|
||||
size = FlattenableUtils::align<8>(size);
|
||||
return size + getPodSize();
|
||||
}
|
||||
|
||||
size_t BufferItem::getFdCount() const {
|
||||
size_t c = 0;
|
||||
size_t count = 0;
|
||||
if (mGraphicBuffer != 0) {
|
||||
c += mGraphicBuffer->getFdCount();
|
||||
count += mGraphicBuffer->getFdCount();
|
||||
}
|
||||
if (mFence != 0) {
|
||||
c += mFence->getFdCount();
|
||||
count += mFence->getFdCount();
|
||||
}
|
||||
return c;
|
||||
return count;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static void writeAligned(void*& buffer, size_t& size, T value) {
|
||||
size -= FlattenableUtils::align<alignof(T)>(buffer);
|
||||
FlattenableUtils::write(buffer, size, value);
|
||||
}
|
||||
|
||||
status_t BufferItem::flatten(
|
||||
void*& buffer, size_t& size, int*& fds, size_t& count) const {
|
||||
|
||||
// make sure we have enough space
|
||||
if (count < BufferItem::getFlattenedSize()) {
|
||||
if (size < BufferItem::getFlattenedSize()) {
|
||||
return NO_MEMORY;
|
||||
}
|
||||
|
||||
@ -107,35 +121,46 @@ status_t BufferItem::flatten(
|
||||
size -= FlattenableUtils::align<4>(buffer);
|
||||
flags |= 2;
|
||||
}
|
||||
|
||||
status_t err = mSurfaceDamage.flatten(buffer, size);
|
||||
if (err) return err;
|
||||
size -= FlattenableUtils::align<4>(buffer);
|
||||
FlattenableUtils::advance(buffer, size, mSurfaceDamage.getFlattenedSize());
|
||||
|
||||
// check we have enough space (in case flattening the fence/graphicbuffer lied to us)
|
||||
// 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;
|
||||
}
|
||||
|
||||
FlattenableUtils::write(buffer, size, mCrop);
|
||||
FlattenableUtils::write(buffer, size, mTransform);
|
||||
FlattenableUtils::write(buffer, size, mScalingMode);
|
||||
FlattenableUtils::write(buffer, size, mTimestamp);
|
||||
FlattenableUtils::write(buffer, size, mIsAutoTimestamp);
|
||||
FlattenableUtils::write(buffer, size, mDataSpace);
|
||||
FlattenableUtils::write(buffer, size, mFrameNumber);
|
||||
FlattenableUtils::write(buffer, size, mSlot);
|
||||
FlattenableUtils::write(buffer, size, mIsDroppable);
|
||||
FlattenableUtils::write(buffer, size, mAcquireCalled);
|
||||
FlattenableUtils::write(buffer, size, mTransformToDisplayInverse);
|
||||
writeAligned(buffer, size, mCrop);
|
||||
writeAligned(buffer, size, mTransform);
|
||||
writeAligned(buffer, size, mScalingMode);
|
||||
writeAligned(buffer, size, mTimestamp);
|
||||
writeAligned(buffer, size, mIsAutoTimestamp);
|
||||
writeAligned(buffer, size, mDataSpace);
|
||||
writeAligned(buffer, size, mFrameNumber);
|
||||
writeAligned(buffer, size, mSlot);
|
||||
writeAligned(buffer, size, mIsDroppable);
|
||||
writeAligned(buffer, size, mAcquireCalled);
|
||||
writeAligned(buffer, size, mTransformToDisplayInverse);
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static void readAligned(const void*& buffer, size_t& size, T& value) {
|
||||
size -= FlattenableUtils::align<alignof(T)>(buffer);
|
||||
FlattenableUtils::read(buffer, size, value);
|
||||
}
|
||||
|
||||
status_t BufferItem::unflatten(
|
||||
void const*& buffer, size_t& size, int const*& fds, size_t& count) {
|
||||
|
||||
if (size < sizeof(uint32_t))
|
||||
if (size < sizeof(uint32_t)) {
|
||||
return NO_MEMORY;
|
||||
}
|
||||
|
||||
uint32_t flags = 0;
|
||||
FlattenableUtils::read(buffer, size, flags);
|
||||
@ -153,26 +178,30 @@ status_t BufferItem::unflatten(
|
||||
if (err) return err;
|
||||
size -= FlattenableUtils::align<4>(buffer);
|
||||
}
|
||||
|
||||
status_t err = mSurfaceDamage.unflatten(buffer, size);
|
||||
if (err) return err;
|
||||
size -= FlattenableUtils::align<4>(buffer);
|
||||
FlattenableUtils::advance(buffer, size, mSurfaceDamage.getFlattenedSize());
|
||||
|
||||
// check we have enough space
|
||||
// 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;
|
||||
}
|
||||
|
||||
FlattenableUtils::read(buffer, size, mCrop);
|
||||
FlattenableUtils::read(buffer, size, mTransform);
|
||||
FlattenableUtils::read(buffer, size, mScalingMode);
|
||||
FlattenableUtils::read(buffer, size, mTimestamp);
|
||||
FlattenableUtils::read(buffer, size, mIsAutoTimestamp);
|
||||
FlattenableUtils::read(buffer, size, mDataSpace);
|
||||
FlattenableUtils::read(buffer, size, mFrameNumber);
|
||||
FlattenableUtils::read(buffer, size, mSlot);
|
||||
FlattenableUtils::read(buffer, size, mIsDroppable);
|
||||
FlattenableUtils::read(buffer, size, mAcquireCalled);
|
||||
FlattenableUtils::read(buffer, size, mTransformToDisplayInverse);
|
||||
readAligned(buffer, size, mCrop);
|
||||
readAligned(buffer, size, mTransform);
|
||||
readAligned(buffer, size, mScalingMode);
|
||||
readAligned(buffer, size, mTimestamp);
|
||||
readAligned(buffer, size, mIsAutoTimestamp);
|
||||
readAligned(buffer, size, mDataSpace);
|
||||
readAligned(buffer, size, mFrameNumber);
|
||||
readAligned(buffer, size, mSlot);
|
||||
readAligned(buffer, size, mIsDroppable);
|
||||
readAligned(buffer, size, mAcquireCalled);
|
||||
readAligned(buffer, size, mTransformToDisplayInverse);
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
@ -303,7 +303,7 @@ status_t GraphicBuffer::flatten(void*& buffer, size_t& size, int*& fds, size_t&
|
||||
static_cast<size_t>(handle->numInts) * sizeof(int));
|
||||
}
|
||||
|
||||
buffer = reinterpret_cast<void*>(static_cast<int*>(buffer) + sizeNeeded);
|
||||
buffer = static_cast<void*>(static_cast<uint8_t*>(buffer) + sizeNeeded);
|
||||
size -= sizeNeeded;
|
||||
if (handle) {
|
||||
fds += handle->numFds;
|
||||
@ -385,7 +385,7 @@ status_t GraphicBuffer::unflatten(
|
||||
}
|
||||
}
|
||||
|
||||
buffer = reinterpret_cast<void const*>(static_cast<int const*>(buffer) + sizeNeeded);
|
||||
buffer = static_cast<void const*>(static_cast<uint8_t const*>(buffer) + sizeNeeded);
|
||||
size -= sizeNeeded;
|
||||
fds += numFds;
|
||||
count -= numFds;
|
||||
|
Loading…
Reference in New Issue
Block a user