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

Commit 68634d30 authored by John Reck's avatar John Reck
Browse files

Make ViewRootImpl#destroyHardwareResources thread-safe

Fixes: 25148144
Test: none
Change-Id: Ie719c5dd8bd7424c9dd2858d338c6cfc5c032d4f
parent ab5938c3
Loading
Loading
Loading
Loading
+16 −3
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import static android.view.WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY;

import android.Manifest;
import android.animation.LayoutTransition;
import android.annotation.AnyThread;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UnsupportedAppUsage;
@@ -1041,10 +1042,22 @@ public final class ViewRootImpl implements ViewParent,
        return mHeight;
    }

    /**
     * Destroys hardware rendering resources for this ViewRootImpl
     *
     * May be called on any thread
     */
    @AnyThread
    void destroyHardwareResources() {
        if (mAttachInfo.mThreadedRenderer != null) {
            mAttachInfo.mThreadedRenderer.destroyHardwareResources(mView);
            mAttachInfo.mThreadedRenderer.destroy();
        final ThreadedRenderer renderer = mAttachInfo.mThreadedRenderer;
        if (renderer != null) {
            // This is called by WindowManagerGlobal which may or may not be on the right thread
            if (Looper.myLooper() != mAttachInfo.mHandler.getLooper()) {
                mAttachInfo.mHandler.postAtFrontOfQueue(this::destroyHardwareResources);
                return;
            }
            renderer.destroyHardwareResources(mView);
            renderer.destroy();
        }
    }