diff options
author | Mathias Agopian <mathias@google.com> | 2012-08-12 19:37:16 -0700 |
---|---|---|
committer | Mathias Agopian <mathias@google.com> | 2012-08-13 02:46:05 -0700 |
commit | 8683fca395d01734ec7946e9f0595ec5d7b754c6 (patch) | |
tree | fe3f6b92245be46902760c129e395c94589b9895 /libs/gui | |
parent | e57f292595bec48f65c8088b00ff6beea01217e9 (diff) | |
download | frameworks_native-8683fca395d01734ec7946e9f0595ec5d7b754c6.zip frameworks_native-8683fca395d01734ec7946e9f0595ec5d7b754c6.tar.gz frameworks_native-8683fca395d01734ec7946e9f0595ec5d7b754c6.tar.bz2 |
improve [un]marshalling of non-binder objects
this change introduces a new class LightFlattenable<> which is
a protocol to flatten simple objects that don't require
binders or file descriptors; the benefit of this protocol is that
it doesn't require the objects to have a virtual table and give us
a consitant way of doing this.
we also introduce an implementation of this protocol for
POD structures, LightFlattenablePod<>.
Parcel has been update to handle this protocol automatically.
Sensor, Rect, Point and Region now use this new protocol.
Change-Id: Icb3ce7fa1d785249eb666f39c2129f2fc143ea4a
Diffstat (limited to 'libs/gui')
-rw-r--r-- | libs/gui/ISensorServer.cpp | 4 | ||||
-rw-r--r-- | libs/gui/LayerState.cpp | 22 | ||||
-rw-r--r-- | libs/gui/Sensor.cpp | 18 |
3 files changed, 11 insertions, 33 deletions
diff --git a/libs/gui/ISensorServer.cpp b/libs/gui/ISensorServer.cpp index 7111092..0b76f37 100644 --- a/libs/gui/ISensorServer.cpp +++ b/libs/gui/ISensorServer.cpp @@ -55,7 +55,7 @@ public: int32_t n = reply.readInt32(); v.setCapacity(n); while (n--) { - reply.read(static_cast<Flattenable&>(s)); + reply.read(s); v.add(s); } return v; @@ -84,7 +84,7 @@ status_t BnSensorServer::onTransact( size_t n = v.size(); reply->writeInt32(n); for (size_t i=0 ; i<n ; i++) { - reply->write(static_cast<const Flattenable&>(v[i])); + reply->write(v[i]); } return NO_ERROR; } break; diff --git a/libs/gui/LayerState.cpp b/libs/gui/LayerState.cpp index 07f62c4..e2604f8 100644 --- a/libs/gui/LayerState.cpp +++ b/libs/gui/LayerState.cpp @@ -26,14 +26,7 @@ status_t layer_state_t::write(Parcel& output) const { status_t err; - size_t len = transparentRegion.write(NULL, 0); - err = output.writeInt32(len); - if (err < NO_ERROR) return err; - - void* buf = output.writeInplace(len); - if (buf == NULL) return NO_MEMORY; - - err = transparentRegion.write(buf, len); + err = output.write(transparentRegion); if (err < NO_ERROR) return err; // NOTE: regions are at the end of the structure @@ -46,11 +39,8 @@ status_t layer_state_t::write(Parcel& output) const status_t layer_state_t::read(const Parcel& input) { status_t err; - size_t len = input.readInt32(); - void const* buf = input.readInplace(len); - if (buf == NULL) return NO_MEMORY; - err = transparentRegion.read(buf); + err = input.read(transparentRegion); if (err < NO_ERROR) return err; // NOTE: regions are at the end of the structure @@ -77,8 +67,8 @@ status_t DisplayState::write(Parcel& output) const { output.writeInt32(what); output.writeInt32(layerStack); output.writeInt32(orientation); - memcpy(output.writeInplace(sizeof(Rect)), &viewport, sizeof(Rect)); - memcpy(output.writeInplace(sizeof(Rect)), &frame, sizeof(Rect)); + output.write(viewport); + output.write(frame); return NO_ERROR; } @@ -88,8 +78,8 @@ status_t DisplayState::read(const Parcel& input) { what = input.readInt32(); layerStack = input.readInt32(); orientation = input.readInt32(); - memcpy(&viewport, input.readInplace(sizeof(Rect)), sizeof(Rect)); - memcpy(&frame, input.readInplace(sizeof(Rect)), sizeof(Rect)); + input.read(viewport); + input.read(frame); return NO_ERROR; } diff --git a/libs/gui/Sensor.cpp b/libs/gui/Sensor.cpp index 5cc76b4..c52a88f 100644 --- a/libs/gui/Sensor.cpp +++ b/libs/gui/Sensor.cpp @@ -98,7 +98,7 @@ int32_t Sensor::getVersion() const { return mVersion; } -size_t Sensor::getFlattenedSize() const +size_t Sensor::getSize() const { return sizeof(int32_t) + ((mName.length() + 3) & ~3) + sizeof(int32_t) + ((mVendor.length() + 3) & ~3) + @@ -107,11 +107,6 @@ size_t Sensor::getFlattenedSize() const sizeof(int32_t); } -size_t Sensor::getFdCount() const -{ - return 0; -} - static inline size_t write(void* buffer, size_t offset, const String8& value) { memcpy(static_cast<char*>(buffer) + offset, value.string(), value.length()); @@ -130,12 +125,8 @@ size_t write(void* buffer, size_t offset, int32_t value) { return sizeof(int32_t); } -status_t Sensor::flatten(void* buffer, size_t size, - int fds[], size_t count) const +status_t Sensor::flatten(void* buffer) const { - if (size < Sensor::getFlattenedSize()) - return -ENOMEM; - size_t offset = 0; offset += write(buffer, offset, int32_t(mName.length())); offset += write(buffer, offset, mName); @@ -149,7 +140,6 @@ status_t Sensor::flatten(void* buffer, size_t size, offset += write(buffer, offset, mResolution); offset += write(buffer, offset, mPower); offset += write(buffer, offset, mMinDelay); - return NO_ERROR; } @@ -171,8 +161,7 @@ size_t read(void const* buffer, size_t offset, int32_t* value) { return sizeof(int32_t); } -status_t Sensor::unflatten(void const* buffer, size_t size, - int fds[], size_t count) +status_t Sensor::unflatten(void const* buffer, size_t size) { int32_t len; size_t offset = 0; @@ -188,7 +177,6 @@ status_t Sensor::unflatten(void const* buffer, size_t size, offset += read(buffer, offset, &mResolution); offset += read(buffer, offset, &mPower); offset += read(buffer, offset, &mMinDelay); - return NO_ERROR; } |