diff options
| author | Mathias Agopian <mathias@google.com> | 2013-03-13 16:07:57 -0700 |
|---|---|---|
| committer | Mathias Agopian <mathias@google.com> | 2013-03-13 16:07:57 -0700 |
| commit | c3b9cd635163ae48a9151fc6e1650388c5d716be (patch) | |
| tree | 2fab8ff4a21209bf886740d837572993f9eec8d6 | |
| parent | 2530b32de5c609fc6738b292baaf540e4ac10cd7 (diff) | |
| download | frameworks_base-c3b9cd635163ae48a9151fc6e1650388c5d716be.zip frameworks_base-c3b9cd635163ae48a9151fc6e1650388c5d716be.tar.gz frameworks_base-c3b9cd635163ae48a9151fc6e1650388c5d716be.tar.bz2 | |
Try to keep the same native Surface object when reading a parcel
If the IGraphicBufferProducers are the same, it's really the same
window, so we keep the same native object.
Bug: 8322406
Change-Id: I96d55a90e6656a05d4e32ae22945226c350b5747
| -rw-r--r-- | core/jni/android_view_Surface.cpp | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/core/jni/android_view_Surface.cpp b/core/jni/android_view_Surface.cpp index 9c78abe..41146bf 100644 --- a/core/jni/android_view_Surface.cpp +++ b/core/jni/android_view_Surface.cpp @@ -332,19 +332,32 @@ static jint nativeReadFromParcel(JNIEnv* env, jclass clazz, doThrowNPE(env); return 0; } + sp<Surface> self(reinterpret_cast<Surface *>(nativeObject)); - if (self != NULL) { - self->decStrong(&sRefBaseOwner); + sp<IBinder> binder(parcel->readStrongBinder()); + + // update the Surface only if the underlying IGraphicBufferProducer + // has changed. + if (self != NULL + && (self->getIGraphicBufferProducer()->asBinder() == binder)) { + // same IGraphicBufferProducer, return ourselves + return int(self.get()); } sp<Surface> sur; - sp<IGraphicBufferProducer> gbp( - interface_cast<IGraphicBufferProducer>(parcel->readStrongBinder())); + sp<IGraphicBufferProducer> gbp(interface_cast<IGraphicBufferProducer>(binder)); if (gbp != NULL) { + // we have a new IGraphicBufferProducer, create a new Surface for it sur = new Surface(gbp); + // and keep a reference before passing to java sur->incStrong(&sRefBaseOwner); } + if (self != NULL) { + // and loose the java reference to ourselves + self->decStrong(&sRefBaseOwner); + } + return int(sur.get()); } |
