Skip to content

Commit 61566cc

Browse files
author
Dianne Hackborn
committed
Fix issue #5614559: Registering surface error in...
...Background Replacement on Stingray This is how I should have done it in the first place. We get the new surface from the window manager, and then just copy it in to the constant Surface object we have for the holder. Change-Id: I537a9e413829a18f689dfb46687014676b27156e
1 parent f57c138 commit 61566cc

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

core/java/android/view/Surface.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,24 @@ private Surface(Parcel source) throws OutOfResourcesException {
282282
/**
283283
* Copy another surface to this one. This surface now holds a reference
284284
* to the same data as the original surface, and is -not- the owner.
285+
* This is for use by the window manager when returning a window surface
286+
* back from a client, converting it from the representation being managed
287+
* by the window manager to the representation the client uses to draw
288+
* in to it.
285289
* @hide
286290
*/
287291
public native void copyFrom(Surface o);
288-
292+
293+
/**
294+
* Transfer the native state from 'o' to this surface, releasing it
295+
* from 'o'. This is for use in the client side for drawing into a
296+
* surface; not guaranteed to work on the window manager side.
297+
* This is for use by the client to move the underlying surface from
298+
* one Surface object to another, in particular in SurfaceFlinger.
299+
* @hide.
300+
*/
301+
public native void transferFrom(Surface o);
302+
289303
/** @hide */
290304
public int getGenerationId() {
291305
return mSurfaceGenerationId;

core/java/android/view/SurfaceView.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ public class SurfaceView extends View {
8888
final int[] mLocation = new int[2];
8989

9090
final ReentrantLock mSurfaceLock = new ReentrantLock();
91-
Surface mSurface = new Surface(); // Current surface in use
92-
Surface mNewSurface = new Surface(); // New surface we are switching to
91+
final Surface mSurface = new Surface(); // Current surface in use
92+
final Surface mNewSurface = new Surface(); // New surface we are switching to
9393
boolean mDrawingStopped = true;
9494

9595
final WindowManager.LayoutParams mLayout
@@ -519,10 +519,7 @@ private void updateWindow(boolean force, boolean redrawNeeded) {
519519
}
520520
}
521521

522-
Surface tmpSurface = mSurface;
523-
mSurface = mNewSurface;
524-
mNewSurface = tmpSurface;
525-
mNewSurface.release();
522+
mSurface.transferFrom(mNewSurface);
526523

527524
if (visible) {
528525
if (!mSurfaceCreated && (surfaceChanged || visibleChanged)) {

core/jni/android_view_Surface.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,25 @@ static void Surface_copyFrom(
752752
}
753753
}
754754

755+
static void Surface_transferFrom(
756+
JNIEnv* env, jobject clazz, jobject other)
757+
{
758+
if (clazz == other)
759+
return;
760+
761+
if (other == NULL) {
762+
doThrowNPE(env);
763+
return;
764+
}
765+
766+
sp<SurfaceControl> control(getSurfaceControl(env, other));
767+
sp<Surface> surface(Surface_getSurface(env, other));
768+
setSurfaceControl(env, clazz, control);
769+
setSurface(env, clazz, surface);
770+
setSurfaceControl(env, other, 0);
771+
setSurface(env, other, 0);
772+
}
773+
755774
static void Surface_readFromParcel(
756775
JNIEnv* env, jobject clazz, jobject argParcel)
757776
{
@@ -820,6 +839,7 @@ static JNINativeMethod gSurfaceMethods[] = {
820839
{"destroy", "()V", (void*)Surface_destroy },
821840
{"release", "()V", (void*)Surface_release },
822841
{"copyFrom", "(Landroid/view/Surface;)V", (void*)Surface_copyFrom },
842+
{"transferFrom", "(Landroid/view/Surface;)V", (void*)Surface_transferFrom },
823843
{"isValid", "()Z", (void*)Surface_isValid },
824844
{"lockCanvasNative", "(Landroid/graphics/Rect;)Landroid/graphics/Canvas;", (void*)Surface_lockCanvas },
825845
{"unlockCanvasAndPost", "(Landroid/graphics/Canvas;)V", (void*)Surface_unlockCanvasAndPost },

0 commit comments

Comments
 (0)