Re-use existing Surface objects when reading them from parcels.
This change adds a process-global cache of previously deserialized Surface objects so that if a Surface object wrapping the same ISurface gets received again the same Surface can be used. This is important because the 'tail' pointer in the SharedBufferClient is stored only on the client side, and needs to be the same for all the Surface objects wrapping an ISurface instance. This solves the problem by making there only be one Surface object wrapping an ISurface per process. Change-Id: I4bf0b8787885c56277622fca053022d2bb638902
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <utils/KeyedVector.h>
|
||||
#include <utils/RefBase.h>
|
||||
#include <utils/threads.h>
|
||||
|
||||
@@ -147,8 +148,7 @@ public:
|
||||
static status_t writeToParcel(
|
||||
const sp<Surface>& control, Parcel* parcel);
|
||||
|
||||
static sp<Surface> readFromParcel(
|
||||
const Parcel& data, const sp<Surface>& other);
|
||||
static sp<Surface> readFromParcel(const Parcel& data);
|
||||
|
||||
static bool isValid(const sp<Surface>& surface) {
|
||||
return (surface != 0) && surface->isValid();
|
||||
@@ -244,6 +244,8 @@ private:
|
||||
uint32_t *pWidth, uint32_t *pHeight,
|
||||
uint32_t *pFormat, uint32_t *pUsage) const;
|
||||
|
||||
static void cleanCachedSurfaces();
|
||||
|
||||
class BufferInfo {
|
||||
uint32_t mWidth;
|
||||
uint32_t mHeight;
|
||||
@@ -298,6 +300,10 @@ private:
|
||||
// Inherently thread-safe
|
||||
mutable Mutex mSurfaceLock;
|
||||
mutable Mutex mApiLock;
|
||||
|
||||
// A cache of Surface objects that have been deserialized into this process.
|
||||
static Mutex sCachedSurfacesLock;
|
||||
static DefaultKeyedVector<wp<IBinder>, wp<Surface> > sCachedSurfaces;
|
||||
};
|
||||
|
||||
}; // namespace android
|
||||
|
||||
Reference in New Issue
Block a user