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

Commit 492bdf00 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Rename getSurfaceTransformHint API and switch to using NDK transform...

Merge "Rename getSurfaceTransformHint API and switch to using NDK transform constants" into sc-v2-dev
parents af816a74 8eb0c64c
Loading
Loading
Loading
Loading
+11 −5
Original line number Diff line number Diff line
@@ -46912,15 +46912,15 @@ package android.view {
  }
  @UiThread public interface AttachedSurfaceControl {
    method public default void addOnSurfaceTransformHintChangedListener(@NonNull android.view.AttachedSurfaceControl.OnSurfaceTransformHintChangedListener);
    method public default void addOnBufferTransformHintChangedListener(@NonNull android.view.AttachedSurfaceControl.OnBufferTransformHintChangedListener);
    method public boolean applyTransactionOnDraw(@NonNull android.view.SurfaceControl.Transaction);
    method @Nullable public android.view.SurfaceControl.Transaction buildReparentTransaction(@NonNull android.view.SurfaceControl);
    method public default int getSurfaceTransformHint();
    method public default void removeOnSurfaceTransformHintChangedListener(@NonNull android.view.AttachedSurfaceControl.OnSurfaceTransformHintChangedListener);
    method public default int getBufferTransformHint();
    method public default void removeOnBufferTransformHintChangedListener(@NonNull android.view.AttachedSurfaceControl.OnBufferTransformHintChangedListener);
  }
  @UiThread public static interface AttachedSurfaceControl.OnSurfaceTransformHintChangedListener {
    method public void onSurfaceTransformHintChanged(int);
  @UiThread public static interface AttachedSurfaceControl.OnBufferTransformHintChangedListener {
    method public void onBufferTransformHintChanged(int);
  }
  public final class Choreographer {
@@ -48410,6 +48410,12 @@ package android.view {
    method public void readFromParcel(android.os.Parcel);
    method public void release();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final int BUFFER_TRANSFORM_IDENTITY = 0; // 0x0
    field public static final int BUFFER_TRANSFORM_MIRROR_HORIZONTAL = 1; // 0x1
    field public static final int BUFFER_TRANSFORM_MIRROR_VERTICAL = 2; // 0x2
    field public static final int BUFFER_TRANSFORM_ROTATE_180 = 3; // 0x3
    field public static final int BUFFER_TRANSFORM_ROTATE_270 = 7; // 0x7
    field public static final int BUFFER_TRANSFORM_ROTATE_90 = 4; // 0x4
    field @NonNull public static final android.os.Parcelable.Creator<android.view.SurfaceControl> CREATOR;
  }
+19 −16
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.view;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UiThread;
import android.hardware.HardwareBuffer;

/**
 * Provides an interface to the root-Surface of a View Hierarchy or Window. This
@@ -84,41 +85,43 @@ public interface AttachedSurfaceControl {
     * Note, when using ANativeWindow APIs in conjunction with a NativeActivity Surface or
     * SurfaceView Surface, the buffer producer will already have access to the transform hint and
     * no additional work is needed.
     *
     * @see HardwareBuffer
     */
    default @Surface.Rotation int getSurfaceTransformHint() {
        return Surface.ROTATION_0;
    default @SurfaceControl.BufferTransform int getBufferTransformHint() {
        return SurfaceControl.BUFFER_TRANSFORM_IDENTITY;
    }

    /**
     * Surface transform hint change listener.
     * @see #getSurfaceTransformHint
     * Buffer transform hint change listener.
     * @see #getBufferTransformHint
     */
    @UiThread
    interface OnSurfaceTransformHintChangedListener {
    interface OnBufferTransformHintChangedListener {
        /**
         * @param hint new surface transform hint
         * @see #getSurfaceTransformHint
         * @see #getBufferTransformHint
         */
        void onSurfaceTransformHintChanged(@Surface.Rotation int hint);
        void onBufferTransformHintChanged(@SurfaceControl.BufferTransform int hint);
    }

    /**
     * Registers a surface transform hint changed listener to receive notifications about when
     * Registers a {@link OnBufferTransformHintChangedListener} to receive notifications about when
     * the transform hint changes.
     *
     * @see #getSurfaceTransformHint
     * @see #removeOnSurfaceTransformHintChangedListener
     * @see #getBufferTransformHint
     * @see #removeOnBufferTransformHintChangedListener
     */
    default void addOnSurfaceTransformHintChangedListener(
            @NonNull OnSurfaceTransformHintChangedListener listener) {
    default void addOnBufferTransformHintChangedListener(
            @NonNull OnBufferTransformHintChangedListener listener) {
    }

    /**
     * Unregisters a surface transform hint changed listener.
     * Unregisters a {@link OnBufferTransformHintChangedListener}.
     *
     * @see #addOnSurfaceTransformHintChangedListener
     * @see #addOnBufferTransformHintChangedListener
     */
    default void removeOnSurfaceTransformHintChangedListener(
            @NonNull OnSurfaceTransformHintChangedListener listener) {
    default void removeOnBufferTransformHintChangedListener(
            @NonNull OnBufferTransformHintChangedListener listener) {
    }
}
+70 −0
Original line number Diff line number Diff line
@@ -245,6 +245,76 @@ public final class SurfaceControl implements Parcelable {
    private static native int nativeGetTransformHint(long nativeObject);
    private static native int nativeGetLayerId(long nativeObject);

    /**
     * Transforms that can be applied to buffers as they are displayed to a window.
     *
     * Supported transforms are any combination of horizontal mirror, vertical mirror, and
     * clock-wise 90 degree rotation, in that order. Rotations of 180 and 270 degrees are made up
     * of those basic transforms.
     * Mirrors {@code ANativeWindowTransform} definitions.
     * @hide
     */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef(prefix = {"BUFFER_TRANSFORM_"},
            value = {BUFFER_TRANSFORM_IDENTITY, BUFFER_TRANSFORM_MIRROR_HORIZONTAL,
                    BUFFER_TRANSFORM_MIRROR_VERTICAL, BUFFER_TRANSFORM_ROTATE_90,
                    BUFFER_TRANSFORM_ROTATE_180, BUFFER_TRANSFORM_ROTATE_270,
                    BUFFER_TRANSFORM_MIRROR_HORIZONTAL | BUFFER_TRANSFORM_ROTATE_90,
                    BUFFER_TRANSFORM_MIRROR_VERTICAL | BUFFER_TRANSFORM_ROTATE_90})
    public @interface BufferTransform {
    }

    /**
     * Identity transform.
     *
     * These transforms that can be applied to buffers as they are displayed to a window.
     * @see HardwareBuffer
     *
     * Supported transforms are any combination of horizontal mirror, vertical mirror, and
     * clock-wise 90 degree rotation, in that order. Rotations of 180 and 270 degrees are
     * made up of those basic transforms.
     */
    public static final int BUFFER_TRANSFORM_IDENTITY = 0x00;
    /**
     * Mirror horizontally. Can be combined with {@link #BUFFER_TRANSFORM_MIRROR_VERTICAL}
     * and {@link #BUFFER_TRANSFORM_ROTATE_90}.
     */
    public static final int BUFFER_TRANSFORM_MIRROR_HORIZONTAL = 0x01;
    /**
     * Mirror vertically. Can be combined with {@link #BUFFER_TRANSFORM_MIRROR_HORIZONTAL}
     * and {@link #BUFFER_TRANSFORM_ROTATE_90}.
     */
    public static final int BUFFER_TRANSFORM_MIRROR_VERTICAL = 0x02;
    /**
     * Rotate 90 degrees clock-wise. Can be combined with {@link
     * #BUFFER_TRANSFORM_MIRROR_HORIZONTAL} and {@link #BUFFER_TRANSFORM_MIRROR_VERTICAL}.
     */
    public static final int BUFFER_TRANSFORM_ROTATE_90 = 0x04;
    /**
     * Rotate 180 degrees clock-wise. Cannot be combined with other transforms.
     */
    public static final int BUFFER_TRANSFORM_ROTATE_180 =
            BUFFER_TRANSFORM_MIRROR_HORIZONTAL | BUFFER_TRANSFORM_MIRROR_VERTICAL;
    /**
     * Rotate 270 degrees clock-wise. Cannot be combined with other transforms.
     */
    public static final int BUFFER_TRANSFORM_ROTATE_270 =
            BUFFER_TRANSFORM_ROTATE_180 | BUFFER_TRANSFORM_ROTATE_90;

    /**
     * @hide
     */
    public static @BufferTransform int rotationToBufferTransform(@Surface.Rotation int rotation) {
        switch (rotation) {
            case Surface.ROTATION_0: return BUFFER_TRANSFORM_IDENTITY;
            case Surface.ROTATION_90: return BUFFER_TRANSFORM_ROTATE_90;
            case Surface.ROTATION_180: return BUFFER_TRANSFORM_ROTATE_180;
            case Surface.ROTATION_270: return BUFFER_TRANSFORM_ROTATE_270;
        }
        Log.e(TAG, "Trying to convert unknown rotation=" + rotation);
        return BUFFER_TRANSFORM_IDENTITY;
    }

    @Nullable
    @GuardedBy("mLock")
    private ArrayList<OnReparentListener> mReparentListeners;
+3 −3
Original line number Diff line number Diff line
@@ -1104,7 +1104,7 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
            || mWindowSpaceTop != mLocation[1];
        final boolean layoutSizeChanged = getWidth() != mScreenRect.width()
            || getHeight() != mScreenRect.height();
        final boolean hintChanged = (viewRoot.getSurfaceTransformHint() != mTransformHint)
        final boolean hintChanged = (viewRoot.getBufferTransformHint() != mTransformHint)
                && mRequestedVisible;

        if (creating || formatChanged || sizeChanged || visibleChanged ||
@@ -1130,7 +1130,7 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
                mSurfaceHeight = myHeight;
                mFormat = mRequestedFormat;
                mLastWindowVisibility = mWindowVisibility;
                mTransformHint = viewRoot.getSurfaceTransformHint();
                mTransformHint = viewRoot.getBufferTransformHint();

                mScreenRect.left = mWindowSpaceLeft;
                mScreenRect.top = mWindowSpaceTop;
@@ -1362,7 +1362,7 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
        if (mBlastBufferQueue != null) {
            mBlastBufferQueue.destroy();
        }
        mTransformHint = viewRoot.getSurfaceTransformHint();
        mTransformHint = viewRoot.getBufferTransformHint();
        mBlastSurfaceControl.setTransformHint(mTransformHint);
        mBlastBufferQueue = new BLASTBufferQueue(name, mBlastSurfaceControl, mSurfaceWidth,
                mSurfaceHeight, mFormat);
+15 −14
Original line number Diff line number Diff line
@@ -312,7 +312,7 @@ public final class ViewRootImpl implements ViewParent,
    static final ArrayList<Runnable> sFirstDrawHandlers = new ArrayList<>();
    static boolean sFirstDrawComplete = false;

    private ArrayList<OnSurfaceTransformHintChangedListener> mTransformHintListeners =
    private ArrayList<OnBufferTransformHintChangedListener> mTransformHintListeners =
            new ArrayList<>();
    private @Surface.Rotation int mPreviousTransformHint = Surface.ROTATION_0;
    /**
@@ -7872,7 +7872,8 @@ public final class ViewRootImpl implements ViewParent,
            int transformHint = mSurfaceControl.getTransformHint();
            if (mPreviousTransformHint != transformHint) {
                mPreviousTransformHint = transformHint;
                dispatchTransformHintChanged(transformHint);
                dispatchTransformHintChanged(
                        SurfaceControl.rotationToBufferTransform(transformHint));
            }
        } else {
            destroySurface();
@@ -10499,38 +10500,38 @@ public final class ViewRootImpl implements ViewParent,
    }

    @Override
    public @Surface.Rotation int getSurfaceTransformHint() {
        return mSurfaceControl.getTransformHint();
    public @SurfaceControl.BufferTransform int getBufferTransformHint() {
        return SurfaceControl.rotationToBufferTransform(mSurfaceControl.getTransformHint());
    }

    @Override
    public void addOnSurfaceTransformHintChangedListener(
            OnSurfaceTransformHintChangedListener listener) {
    public void addOnBufferTransformHintChangedListener(
            OnBufferTransformHintChangedListener listener) {
        Objects.requireNonNull(listener);
        if (mTransformHintListeners.contains(listener)) {
            throw new IllegalArgumentException(
                    "attempt to call addOnSurfaceTransformHintChangedListener() "
                    "attempt to call addOnBufferTransformHintChangedListener() "
                            + "with a previously registered listener");
        }
        mTransformHintListeners.add(listener);
    }

    @Override
    public void removeOnSurfaceTransformHintChangedListener(
            OnSurfaceTransformHintChangedListener listener) {
    public void removeOnBufferTransformHintChangedListener(
            OnBufferTransformHintChangedListener listener) {
        Objects.requireNonNull(listener);
        mTransformHintListeners.remove(listener);
    }

    private void dispatchTransformHintChanged(@Surface.Rotation int hint) {
    private void dispatchTransformHintChanged(@SurfaceControl.BufferTransform int hint) {
        if (mTransformHintListeners.isEmpty()) {
            return;
        }
        ArrayList<OnSurfaceTransformHintChangedListener> listeners =
                (ArrayList<OnSurfaceTransformHintChangedListener>) mTransformHintListeners.clone();
        ArrayList<OnBufferTransformHintChangedListener> listeners =
                (ArrayList<OnBufferTransformHintChangedListener>) mTransformHintListeners.clone();
        for (int i = 0; i < listeners.size(); i++) {
            OnSurfaceTransformHintChangedListener listener = listeners.get(i);
            listener.onSurfaceTransformHintChanged(hint);
            OnBufferTransformHintChangedListener listener = listeners.get(i);
            listener.onBufferTransformHintChanged(hint);
        }
    }
}