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

Commit 114856f8 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Remove implementation of global transaction

Since I67e4e58aced78a2f36163178a64ca55d3c77e6f3, the methods of
global transaction have no effective use case anymore.

Keep the empty method openTransaction and closeTransaction because
scrcpy might still use reflection to check the methods. However, it is
safe to make these 2 method no-op because setDisplaySurface,
setDisplayProjection, and setDisplayLayerStack no longer use global
transaction. See [1] and [2].

[1]: I859743cb8b10c0352a30280a610b13a4f44f34dc
[2]: I8ea8b26f4f5f8e7675a8a9fcf06c7f10cfa9e196

Bug: 159103089
Test: presubmit
Change-Id: If38dfbe77d0be12bceb5e75600f486a53c9cd2c6
parent cf01f294
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());
@@ -1576,54 +1573,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.
    }

    /**
@@ -4498,39 +4471,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
     */