diff options
author | Mathias Agopian <mathias@google.com> | 2010-02-11 17:30:52 -0800 |
---|---|---|
committer | Mathias Agopian <mathias@google.com> | 2010-02-21 23:27:25 -0800 |
commit | c86727f5805f28fbd25da141c50fb6843f364f3a (patch) | |
tree | 395806614f40b9aac7306a9e951305167fb8abe1 /include | |
parent | 08d13c3cbb0b250b84ca861edb462060556aead9 (diff) | |
download | frameworks_base-c86727f5805f28fbd25da141c50fb6843f364f3a.zip frameworks_base-c86727f5805f28fbd25da141c50fb6843f364f3a.tar.gz frameworks_base-c86727f5805f28fbd25da141c50fb6843f364f3a.tar.bz2 |
remove a dependency of GraphicBuffer (libui) on Parcel (libbinder).
Add a Flattenable interface to libutils which can be used to flatten
an object into bytestream + filedescriptor stream.
Parcel is modified to handle Flattenable. And GraphicBuffer implements
Flattenable.
Except for the overlay classes libui is now independent of libbinder.
Diffstat (limited to 'include')
-rw-r--r-- | include/binder/Parcel.h | 4 | ||||
-rw-r--r-- | include/ui/GraphicBuffer.h | 17 | ||||
-rw-r--r-- | include/utils/Flattenable.h | 62 |
3 files changed, 77 insertions, 6 deletions
diff --git a/include/binder/Parcel.h b/include/binder/Parcel.h index ba6c711..66c34b2 100644 --- a/include/binder/Parcel.h +++ b/include/binder/Parcel.h @@ -30,6 +30,7 @@ class IBinder; class ProcessState; class String8; class TextOutput; +class Flattenable; struct flat_binder_object; // defined in support_p/binder_module.h @@ -81,6 +82,7 @@ public: status_t writeString16(const char16_t* str, size_t len); status_t writeStrongBinder(const sp<IBinder>& val); status_t writeWeakBinder(const wp<IBinder>& val); + status_t write(const Flattenable& val); // Place a native_handle into the parcel (the native_handle's file- // descriptors are dup'ed, so it is safe to delete the native_handle @@ -119,7 +121,7 @@ public: const char16_t* readString16Inplace(size_t* outLen) const; sp<IBinder> readStrongBinder() const; wp<IBinder> readWeakBinder() const; - + status_t read(Flattenable& val) const; // Retrieve native_handle from the parcel. This returns a copy of the // parcel's native_handle (the caller takes ownership). The caller diff --git a/include/ui/GraphicBuffer.h b/include/ui/GraphicBuffer.h index b9c491b..e72b6b3 100644 --- a/include/ui/GraphicBuffer.h +++ b/include/ui/GraphicBuffer.h @@ -23,6 +23,7 @@ #include <ui/android_native_buffer.h> #include <ui/PixelFormat.h> #include <ui/Rect.h> +#include <utils/Flattenable.h> #include <pixelflinger/pixelflinger.h> struct android_native_buffer_t; @@ -30,7 +31,6 @@ struct android_native_buffer_t; namespace android { class GraphicBufferMapper; -class Parcel; // =========================================================================== // GraphicBuffer @@ -40,7 +40,7 @@ class GraphicBuffer : public EGLNativeBase< android_native_buffer_t, GraphicBuffer, - LightRefBase<GraphicBuffer> > + LightRefBase<GraphicBuffer> >, public Flattenable { public: @@ -97,7 +97,6 @@ public: uint32_t getVerticalStride() const; protected: - GraphicBuffer(const Parcel& reply); virtual ~GraphicBuffer(); enum { @@ -122,8 +121,16 @@ private: status_t initSize(uint32_t w, uint32_t h, PixelFormat format, uint32_t usage); - static status_t writeToParcel(Parcel* reply, - android_native_buffer_t const* buffer); + void free_handle(); + + // Flattenable interface + size_t getFlattenedSize() const; + size_t getFdCount() const; + status_t flatten(void* buffer, size_t size, + int fds[], size_t count) const; + status_t unflatten(void const* buffer, size_t size, + int fds[], size_t count); + GraphicBufferMapper& mBufferMapper; ssize_t mInitCheck; diff --git a/include/utils/Flattenable.h b/include/utils/Flattenable.h new file mode 100644 index 0000000..852be3b --- /dev/null +++ b/include/utils/Flattenable.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_UTILS_FLATTENABLE_H +#define ANDROID_UTILS_FLATTENABLE_H + + +#include <stdint.h> +#include <sys/types.h> +#include <utils/Errors.h> + +namespace android { + +class Flattenable +{ +public: + // size in bytes of the flattened object + virtual size_t getFlattenedSize() const = 0; + + // number of file descriptors to flatten + virtual size_t getFdCount() const = 0; + + // flattens the object into buffer. + // size should be at least of getFlattenedSize() + // file descriptors are written in the fds[] array but ownership is + // not transfered (ie: they must be dupped by the caller of + // flatten() if needed). + virtual status_t flatten(void* buffer, size_t size, + int fds[], size_t count) const = 0; + + // unflattens the object from buffer. + // size should be equal to the value of getFlattenedSize() when the + // object was flattened. + // unflattened file descriptors are found in the fds[] array and + // don't need to be dupped(). ie: the caller of unflatten doesn't + // keep ownership. If a fd is not retained by unflatten() it must be + // explicitly closed. + virtual status_t unflatten(void const* buffer, size_t size, + int fds[], size_t count) = 0; + +protected: + virtual ~Flattenable() = 0; + +}; + +}; // namespace android + + +#endif /* ANDROID_UTILS_FLATTENABLE_H */ |