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

Commit 081f39e3 authored by Wenhui Yang's avatar Wenhui Yang
Browse files

Introduce setCompositionOrder() and getCompositionOrder() apis

Android's current SurfaceView z-order APIs have limitations in
controlling the precise z-order, especially with multiple SurfaceViews.
Therefore, we need to introduce new APIs to enable better z-order
management.

Bug: 341021569
Test: SurfaceViewTest
Flag: android.view.flags.surface_view_set_composition_order
Change-Id: I73c37eb10d6121de0eb6f2a2e584e27f60ea5d2a
parent 97972948
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -52560,10 +52560,12 @@ package android.view {
    ctor public SurfaceView(android.content.Context, android.util.AttributeSet, int);
    ctor public SurfaceView(android.content.Context, android.util.AttributeSet, int, int);
    method public void applyTransactionToFrame(@NonNull android.view.SurfaceControl.Transaction);
    method @FlaggedApi("android.view.flags.surface_view_set_composition_order") public int getCompositionOrder();
    method public android.view.SurfaceHolder getHolder();
    method @Deprecated @Nullable public android.os.IBinder getHostToken();
    method public android.view.SurfaceControl getSurfaceControl();
    method public void setChildSurfacePackage(@NonNull android.view.SurfaceControlViewHost.SurfacePackage);
    method @FlaggedApi("android.view.flags.surface_view_set_composition_order") public void setCompositionOrder(int);
    method @FlaggedApi("com.android.graphics.hwui.flags.limited_hdr") public void setDesiredHdrHeadroom(@FloatRange(from=0.0f, to=10000.0) float);
    method public void setSecure(boolean);
    method public void setSurfaceLifecycle(int);
+33 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.view;

import static android.view.flags.Flags.FLAG_SURFACE_VIEW_SET_COMPOSITION_ORDER;
import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
import static android.view.WindowManagerPolicyConstants.APPLICATION_MEDIA_OVERLAY_SUBLAYER;
import static android.view.WindowManagerPolicyConstants.APPLICATION_MEDIA_SUBLAYER;
@@ -769,6 +770,36 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
        return mCornerRadius;
    }

    /**
     * Controls the composition order of the SurfaceView. A non-negative composition order
     * value indicates that the SurfaceView is composited on top of the parent window, while
     * a negative composition order indicates that the SurfaceView is behind the parent
     * window. A SurfaceView with a higher value appears above its peers with lower values.
     * For SurfaceViews with the same composition order value, their relative order is
     * undefined.
     *
     * @param compositionOrder the composition order of the surface view.
     */
    @FlaggedApi(FLAG_SURFACE_VIEW_SET_COMPOSITION_ORDER)
    public void setCompositionOrder(int compositionOrder) {
        mRequestedSubLayer = compositionOrder;
        if (mSubLayer != mRequestedSubLayer) {
            updateSurface();
        }
    }

    /**
     * Returns the composition order of the SurfaceView.
     *
     * @return composition order of the SurfaceView.
     *
     * @see #setCompositionOrder(int)
     */
    @FlaggedApi(FLAG_SURFACE_VIEW_SET_COMPOSITION_ORDER)
    public int getCompositionOrder() {
        return mRequestedSubLayer;
    }

    /**
     * Control whether the surface view's surface is placed on top of another
     * regular surface view in the window (but still behind the window itself).
@@ -1257,7 +1288,8 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
                final Transaction surfaceUpdateTransaction = new Transaction();
                if (creating) {
                    updateOpaqueFlag();
                    final String name = "SurfaceView[" + viewRoot.getTitle().toString() + "]";
                    final String name = Integer.toHexString(System.identityHashCode(this))
                            + " SurfaceView[" + viewRoot.getTitle().toString() + "]";
                    createBlastSurfaceControls(viewRoot, name, surfaceUpdateTransaction);
                } else if (mSurfaceControl == null) {
                    return;
+8 −0
Original line number Diff line number Diff line
@@ -109,3 +109,11 @@ flag {
      purpose: PURPOSE_BUGFIX
  }
}

flag {
    name: "surface_view_set_composition_order"
    namespace: "window_surfaces"
    description: "Add a SurfaceView composition order control API."
    bug: "341021569"
    is_fixed_read_only: true
}
 No newline at end of file