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

Commit a9823c4e authored by Riddle Hsu's avatar Riddle Hsu Committed by Android (Google) Code Review
Browse files

Merge "Remove implementation of global transaction" into main

parents 9d36aab1 114856f8
Loading
Loading
Loading
Loading
+14 −74
Original line number Diff line number Diff line
@@ -503,9 +503,6 @@ public final class SurfaceControl implements Parcelable {
    // be dumped as additional context
    private static volatile boolean sDebugUsageAfterRelease = false;

    static GlobalTransactionWrapper sGlobalTransaction;
    static long sTransactionNestCount = 0;

    private static final NativeAllocationRegistry sRegistry =
            NativeAllocationRegistry.createMalloced(SurfaceControl.class.getClassLoader(),
                    nativeGetNativeSurfaceControlFinalizer());
@@ -1590,54 +1587,30 @@ public final class SurfaceControl implements Parcelable {
        return mNativeObject != 0;
    }

    /*
     * set surface parameters.
     * needs to be inside open/closeTransaction block
     */

    /** start a transaction
     * @hide
     */
    @UnsupportedAppUsage
    public static void openTransaction() {
        synchronized (SurfaceControl.class) {
            if (sGlobalTransaction == null) {
                sGlobalTransaction = new GlobalTransactionWrapper();
            }
            synchronized(SurfaceControl.class) {
                sTransactionNestCount++;
            }
        }
    }

    /**
     * Merge the supplied transaction in to the deprecated "global" transaction.
     * This clears the supplied transaction in an identical fashion to {@link Transaction#merge}.
     * <p>
     * This is a utility for interop with legacy-code and will go away with the Global Transaction.
     * @hide
     * @deprecated Use regular Transaction instead.
     */
    @Deprecated
    public static void mergeToGlobalTransaction(Transaction t) {
        synchronized(SurfaceControl.class) {
            sGlobalTransaction.merge(t);
        }
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.VANILLA_ICE_CREAM,
            publicAlternatives = "Use {@code SurfaceControl.Transaction} instead",
            trackingBug = 247078497)
    public static void openTransaction() {
        // TODO(b/247078497): It was used for global transaction (all usages are removed).
        //  Keep the method declaration to avoid breaking reference from legacy access.
    }

    /** end a transaction
     * @hide
     * @deprecated Use regular Transaction instead.
     */
    @UnsupportedAppUsage
    @Deprecated
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.VANILLA_ICE_CREAM,
            publicAlternatives = "Use {@code SurfaceControl.Transaction} instead",
            trackingBug = 247078497)
    public static void closeTransaction() {
        synchronized(SurfaceControl.class) {
            if (sTransactionNestCount == 0) {
                Log.e(TAG,
                        "Call to SurfaceControl.closeTransaction without matching openTransaction");
            } else if (--sTransactionNestCount > 0) {
                return;
            }
            sGlobalTransaction.applyGlobalTransaction(false);
        }
        // TODO(b/247078497): It was used for global transaction (all usages are removed).
        //  Keep the method declaration to avoid breaking reference from legacy access.
    }

    /**
@@ -4512,39 +4485,6 @@ public final class SurfaceControl implements Parcelable {
        }
    }

    /**
     * As part of eliminating usage of the global Transaction we expose
     * a SurfaceControl.getGlobalTransaction function. However calling
     * apply on this global transaction (rather than using closeTransaction)
     * would be very dangerous. So for the global transaction we use this
     * subclass of Transaction where the normal apply throws an exception.
     */
    private static class GlobalTransactionWrapper extends SurfaceControl.Transaction {
        void applyGlobalTransaction(boolean sync) {
            applyResizedSurfaces();
            notifyReparentedSurfaces();
            nativeApplyTransaction(mNativeObject, sync, /*oneWay*/ false);
        }

        @Override
        public void apply(boolean sync) {
            throw new RuntimeException("Global transaction must be applied from closeTransaction");
        }
    }

    /**
     * This is a refactoring utility function to enable lower levels of code to be refactored
     * from using the global transaction (and instead use a passed in Transaction) without
     * having to refactor the higher levels at the same time.
     * The returned global transaction can't be applied, it must be applied from closeTransaction
     * Unless you are working on removing Global Transaction usage in the WindowManager, this
     * probably isn't a good function to use.
     * @hide
     */
    public static Transaction getGlobalTransaction() {
        return sGlobalTransaction;
    }

    /**
     * @hide
     */