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/GraphicBuffer.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/GraphicBuffer.cpp')
-rw-r--r-- | libs/ui/GraphicBuffer.cpp | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/libs/ui/GraphicBuffer.cpp b/libs/ui/GraphicBuffer.cpp index 580788d0e9..1f273e264e 100644 --- a/libs/ui/GraphicBuffer.cpp +++ b/libs/ui/GraphicBuffer.cpp @@ -209,9 +209,7 @@ size_t GraphicBuffer::getFdCount() const { return handle ? handle->numFds : 0; } -status_t GraphicBuffer::flatten(void* buffer, size_t size, - int fds[], size_t count) const -{ +status_t GraphicBuffer::flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const { size_t sizeNeeded = GraphicBuffer::getFlattenedSize(); if (size < sizeNeeded) return NO_MEMORY; @@ -236,12 +234,16 @@ status_t GraphicBuffer::flatten(void* buffer, size_t size, memcpy(&buf[8], h->data + h->numFds, h->numInts*sizeof(int)); } + buffer = reinterpret_cast<void*>(static_cast<int*>(buffer) + sizeNeeded); + size -= sizeNeeded; + fds += handle->numFds; + count -= handle->numFds; + return NO_ERROR; } -status_t GraphicBuffer::unflatten(void const* buffer, size_t size, - int fds[], size_t count) -{ +status_t GraphicBuffer::unflatten( + void const*& buffer, size_t& size, int const*& fds, size_t& count) { if (size < 8*sizeof(int)) return NO_MEMORY; int const* buf = static_cast<int const*>(buffer); @@ -287,6 +289,11 @@ status_t GraphicBuffer::unflatten(void const* buffer, size_t size, } } + buffer = reinterpret_cast<void const*>(static_cast<int const*>(buffer) + sizeNeeded); + size -= sizeNeeded; + fds += numFds; + count -= numFds; + return NO_ERROR; } |