Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 61566cc1 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

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
parent f57c1388
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -282,10 +282,24 @@ public class Surface implements Parcelable {
    /**
     * Copy another surface to this one.  This surface now holds a reference
     * to the same data as the original surface, and is -not- the owner.
     * This is for use by the window manager when returning a window surface
     * back from a client, converting it from the representation being managed
     * by the window manager to the representation the client uses to draw
     * in to it.
     * @hide
     */
    public native void copyFrom(Surface o);

    /**
     * Transfer the native state from 'o' to this surface, releasing it
     * from 'o'.  This is for use in the client side for drawing into a
     * surface; not guaranteed to work on the window manager side.
     * This is for use by the client to move the underlying surface from
     * one Surface object to another, in particular in SurfaceFlinger.
     * @hide.
     */
    public native void transferFrom(Surface o);

    /** @hide */
    public int getGenerationId() {
        return mSurfaceGenerationId;
+3 −6
Original line number Diff line number Diff line
@@ -88,8 +88,8 @@ public class SurfaceView extends View {
    final int[] mLocation = new int[2];
    
    final ReentrantLock mSurfaceLock = new ReentrantLock();
    Surface mSurface = new Surface();       // Current surface in use
    Surface mNewSurface = new Surface();    // New surface we are switching to
    final Surface mSurface = new Surface();       // Current surface in use
    final Surface mNewSurface = new Surface();    // New surface we are switching to
    boolean mDrawingStopped = true;

    final WindowManager.LayoutParams mLayout
@@ -519,10 +519,7 @@ public class SurfaceView extends View {
                        }
                    }

                    Surface tmpSurface = mSurface;
                    mSurface = mNewSurface;
                    mNewSurface = tmpSurface;
                    mNewSurface.release();
                    mSurface.transferFrom(mNewSurface);

                    if (visible) {
                        if (!mSurfaceCreated && (surfaceChanged || visibleChanged)) {
+20 −0
Original line number Diff line number Diff line
@@ -752,6 +752,25 @@ static void Surface_copyFrom(
    }
}

static void Surface_transferFrom(
        JNIEnv* env, jobject clazz, jobject other)
{
    if (clazz == other)
        return;

    if (other == NULL) {
        doThrowNPE(env);
        return;
    }

    sp<SurfaceControl> control(getSurfaceControl(env, other));
    sp<Surface> surface(Surface_getSurface(env, other));
    setSurfaceControl(env, clazz, control);
    setSurface(env, clazz, surface);
    setSurfaceControl(env, other, 0);
    setSurface(env, other, 0);
}

static void Surface_readFromParcel(
        JNIEnv* env, jobject clazz, jobject argParcel)
{
@@ -820,6 +839,7 @@ static JNINativeMethod gSurfaceMethods[] = {
    {"destroy",             "()V",  (void*)Surface_destroy },
    {"release",             "()V",  (void*)Surface_release },
    {"copyFrom",            "(Landroid/view/Surface;)V",  (void*)Surface_copyFrom },
    {"transferFrom",        "(Landroid/view/Surface;)V",  (void*)Surface_transferFrom },
    {"isValid",             "()Z",  (void*)Surface_isValid },
    {"lockCanvasNative",    "(Landroid/graphics/Rect;)Landroid/graphics/Canvas;",  (void*)Surface_lockCanvas },
    {"unlockCanvasAndPost", "(Landroid/graphics/Canvas;)V", (void*)Surface_unlockCanvasAndPost },