summaryrefslogtreecommitdiffstats
path: root/libs/surfaceflinger_client/Surface.cpp
diff options
context:
space:
mode:
authorJamie Gennis <jgennis@google.com>2010-07-16 15:17:59 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2010-07-16 15:17:59 -0700
commit04b953132edb5482f0aa6d992f89e7016961528c (patch)
tree279fe5e87a52047793f723f7f9d3bff2632693f0 /libs/surfaceflinger_client/Surface.cpp
parent7b8df313f714d6e8d536e0f8bbe5496fe9a6c26d (diff)
parentc8c79a654d4ae8e3a883854e19cc2df757f72d82 (diff)
downloadframeworks_base-04b953132edb5482f0aa6d992f89e7016961528c.zip
frameworks_base-04b953132edb5482f0aa6d992f89e7016961528c.tar.gz
frameworks_base-04b953132edb5482f0aa6d992f89e7016961528c.tar.bz2
am c8c79a65: Merge "Re-use existing Surface objects when reading them from parcels." into gingerbread
Merge commit 'c8c79a654d4ae8e3a883854e19cc2df757f72d82' into gingerbread-plus-aosp * commit 'c8c79a654d4ae8e3a883854e19cc2df757f72d82': Re-use existing Surface objects when reading them from parcels.
Diffstat (limited to 'libs/surfaceflinger_client/Surface.cpp')
-rw-r--r--libs/surfaceflinger_client/Surface.cpp35
1 files changed, 28 insertions, 7 deletions
diff --git a/libs/surfaceflinger_client/Surface.cpp b/libs/surfaceflinger_client/Surface.cpp
index dc6332c..1de3a4f 100644
--- a/libs/surfaceflinger_client/Surface.cpp
+++ b/libs/surfaceflinger_client/Surface.cpp
@@ -374,15 +374,36 @@ status_t Surface::writeToParcel(
}
-sp<Surface> Surface::readFromParcel(
- const Parcel& data, const sp<Surface>& other)
-{
- sp<Surface> result(other);
+
+Mutex Surface::sCachedSurfacesLock;
+DefaultKeyedVector<wp<IBinder>, wp<Surface> > Surface::sCachedSurfaces(wp<Surface>(0));
+
+sp<Surface> Surface::readFromParcel(const Parcel& data) {
+ Mutex::Autolock _l(sCachedSurfacesLock);
sp<IBinder> binder(data.readStrongBinder());
- if (other==0 || binder != other->mSurface->asBinder()) {
- result = new Surface(data, binder);
+ sp<Surface> surface = sCachedSurfaces.valueFor(binder).promote();
+ if (surface == 0) {
+ surface = new Surface(data, binder);
+ sCachedSurfaces.add(binder, surface);
+ } else {
+ LOGW("Reusing surface!");
+ }
+ if (surface->mSurface == 0) {
+ surface = 0;
+ }
+ cleanCachedSurfaces();
+ return surface;
+}
+
+// Remove the stale entries from the surface cache. This should only be called
+// with sCachedSurfacesLock held.
+void Surface::cleanCachedSurfaces() {
+ for (int i = sCachedSurfaces.size()-1; i >= 0; --i) {
+ wp<Surface> s(sCachedSurfaces.valueAt(i));
+ if (s == 0 || s.promote() == 0) {
+ sCachedSurfaces.removeItemsAt(i);
+ }
}
- return result;
}
void Surface::init()