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

Commit 521e363a authored by Rob Carr's avatar Rob Carr
Browse files

InsetController: Release leashes from RenderThread

We handle changes to the leashes from the UI thread, but use
the same SurfaceControl wrapper object from the RenderThread with
SyncRtSurfaceTransactionApplier. This means that at the time
we release a SurfaceControl from the UI thread we might have already
scheduled a SyncRtSurfaceTransactionApplier to use it, and actually
that could be in the process of running, leading to racy access and
crashes. To fix this we release the SurfaceControl from the RenderThread
so that it happens behind all existing operations.

Bug: 151086678
Test: Existing tests pass.
Change-Id: I2308d1c64f3f368c32587f99ddfb9e05955f821f
parent 91b4f26c
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -992,4 +992,23 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
        }
        return mViewRoot.mWindowAttributes.insetsFlags.behavior;
    }

    /**
     * At the time we receive new leashes (e.g. InsetsSourceConsumer is processing
     * setControl) we need to release the old leash. But we may have already scheduled
     * a SyncRtSurfaceTransaction applier to use it from the RenderThread. To avoid
     * synchronization issues we also release from the RenderThread so this release
     * happens after any existing items on the work queue.
     */
    public void releaseSurfaceControlFromRt(SurfaceControl sc) {
        if (mViewRoot.mView != null && mViewRoot.mView.isHardwareAccelerated()) {
            mViewRoot.registerRtFrameCallback(frame -> {
                  sc.release();
            });
            // Make sure a frame gets scheduled.
            mViewRoot.mView.invalidate();
        } else {
              sc.release();
        }
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -117,7 +117,7 @@ public class InsetsSourceConsumer {
            }
        }
        if (lastControl != null) {
            lastControl.release();
            lastControl.release(mController);
        }
    }

+2 −2
Original line number Diff line number Diff line
@@ -94,9 +94,9 @@ public class InsetsSourceControl implements Parcelable {
        dest.writeParcelable(mSurfacePosition, 0 /* flags*/);
    }

    public void release() {
    public void release(InsetsController controller) {
        if (mLeash != null) {
            mLeash.release();
            controller.releaseSurfaceControlFromRt(mLeash);
        }
    }