diff options
author | 2013-07-29 21:24:40 -0700 | |
---|---|---|
committer | 2013-07-30 21:19:13 -0700 | |
commit | e142428a9c8b9d2380032cd4d7b55ee440fe8770 (patch) | |
tree | 7c55a190ef023bc7aba348d040211901448c13d3 /libs/ui/Fence.cpp | |
parent | 1d76781b7aa19611c4045fdf6b848af6c6094e0b (diff) |
Make Flattenable not virtual
Fallout from the Flattenable change, update all its uses.
Additionnaly, fix/tighten size checks when (un)flatten()ing
things.
Removed the assumption by some flattenables (e.g.: Fence)
that the size passed to them would be exact (it can
and will be larger in some cases)
The code in Parcel is a bit complicated so that we don't
have to expose the full implementation (and also to
keep the code smallish).
Change-Id: I0bf1c8aca2a3128491b4f45510bc46667e566dde
Diffstat (limited to 'libs/ui/Fence.cpp')
-rw-r--r-- | libs/ui/Fence.cpp | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/libs/ui/Fence.cpp b/libs/ui/Fence.cpp index 464ee86c87..93ec0ce611 100644 --- a/libs/ui/Fence.cpp +++ b/libs/ui/Fence.cpp @@ -127,37 +127,49 @@ nsecs_t Fence::getSignalTime() const { } size_t Fence::getFlattenedSize() const { - return 0; + return 1; } size_t Fence::getFdCount() const { return isValid() ? 1 : 0; } -status_t Fence::flatten(void* buffer, size_t size, int fds[], - size_t count) const { - if (size != getFlattenedSize() || count != getFdCount()) { - return BAD_VALUE; +status_t Fence::flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const { + if (size < getFlattenedSize() || count < getFdCount()) { + return NO_MEMORY; } - + FlattenableUtils::write(buffer, size, getFdCount()); if (isValid()) { - fds[0] = mFenceFd; + *fds++ = mFenceFd; + count--; } return NO_ERROR; } -status_t Fence::unflatten(void const* buffer, size_t size, int fds[], - size_t count) { - if (size != 0 || (count != 0 && count != 1)) { - return BAD_VALUE; - } +status_t Fence::unflatten(void const*& buffer, size_t& size, int const*& fds, size_t& count) { if (mFenceFd != -1) { // Don't unflatten if we already have a valid fd. return INVALID_OPERATION; } - if (count == 1) { - mFenceFd = fds[0]; + if (size < 1) { + return NO_MEMORY; + } + + size_t numFds; + FlattenableUtils::read(buffer, size, numFds); + + if (numFds > 1) { + return BAD_VALUE; + } + + if (count < numFds) { + return NO_MEMORY; + } + + if (numFds) { + mFenceFd = *fds++; + count--; } return NO_ERROR; |