Merge "Rename getSurfaceTransformHint API and switch to using NDK transform constants" into sc-v2-dev am: 492bdf0074

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15937682

Change-Id: I65045ca90bfa16c885af4c5fde86e4af592d8633
This commit is contained in:
TreeHugger Robot
2021-10-12 00:50:11 +00:00
committed by Automerger Merge Worker
5 changed files with 118 additions and 38 deletions

View File

@@ -46938,15 +46938,15 @@ package android.view {
} }
@UiThread public interface AttachedSurfaceControl { @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 public boolean applyTransactionOnDraw(@NonNull android.view.SurfaceControl.Transaction);
method @Nullable public android.view.SurfaceControl.Transaction buildReparentTransaction(@NonNull android.view.SurfaceControl); method @Nullable public android.view.SurfaceControl.Transaction buildReparentTransaction(@NonNull android.view.SurfaceControl);
method public default int getSurfaceTransformHint(); method public default int getBufferTransformHint();
method public default void removeOnSurfaceTransformHintChangedListener(@NonNull android.view.AttachedSurfaceControl.OnSurfaceTransformHintChangedListener); method public default void removeOnBufferTransformHintChangedListener(@NonNull android.view.AttachedSurfaceControl.OnBufferTransformHintChangedListener);
} }
@UiThread public static interface AttachedSurfaceControl.OnSurfaceTransformHintChangedListener { @UiThread public static interface AttachedSurfaceControl.OnBufferTransformHintChangedListener {
method public void onSurfaceTransformHintChanged(int); method public void onBufferTransformHintChanged(int);
} }
public final class Choreographer { public final class Choreographer {
@@ -48436,6 +48436,12 @@ package android.view {
method public void readFromParcel(android.os.Parcel); method public void readFromParcel(android.os.Parcel);
method public void release(); method public void release();
method public void writeToParcel(android.os.Parcel, int); 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; field @NonNull public static final android.os.Parcelable.Creator<android.view.SurfaceControl> CREATOR;
} }

View File

@@ -18,6 +18,7 @@ package android.view;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.annotation.UiThread; import android.annotation.UiThread;
import android.hardware.HardwareBuffer;
/** /**
* Provides an interface to the root-Surface of a View Hierarchy or Window. This * 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 * 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 * SurfaceView Surface, the buffer producer will already have access to the transform hint and
* no additional work is needed. * no additional work is needed.
*
* @see HardwareBuffer
*/ */
default @Surface.Rotation int getSurfaceTransformHint() { default @SurfaceControl.BufferTransform int getBufferTransformHint() {
return Surface.ROTATION_0; return SurfaceControl.BUFFER_TRANSFORM_IDENTITY;
} }
/** /**
* Surface transform hint change listener. * Buffer transform hint change listener.
* @see #getSurfaceTransformHint * @see #getBufferTransformHint
*/ */
@UiThread @UiThread
interface OnSurfaceTransformHintChangedListener { interface OnBufferTransformHintChangedListener {
/** /**
* @param hint new surface transform hint * @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. * the transform hint changes.
* *
* @see #getSurfaceTransformHint * @see #getBufferTransformHint
* @see #removeOnSurfaceTransformHintChangedListener * @see #removeOnBufferTransformHintChangedListener
*/ */
default void addOnSurfaceTransformHintChangedListener( default void addOnBufferTransformHintChangedListener(
@NonNull OnSurfaceTransformHintChangedListener listener) { @NonNull OnBufferTransformHintChangedListener listener) {
} }
/** /**
* Unregisters a surface transform hint changed listener. * Unregisters a {@link OnBufferTransformHintChangedListener}.
* *
* @see #addOnSurfaceTransformHintChangedListener * @see #addOnBufferTransformHintChangedListener
*/ */
default void removeOnSurfaceTransformHintChangedListener( default void removeOnBufferTransformHintChangedListener(
@NonNull OnSurfaceTransformHintChangedListener listener) { @NonNull OnBufferTransformHintChangedListener listener) {
} }
} }

View File

@@ -245,6 +245,76 @@ public final class SurfaceControl implements Parcelable {
private static native int nativeGetTransformHint(long nativeObject); private static native int nativeGetTransformHint(long nativeObject);
private static native int nativeGetLayerId(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 @Nullable
@GuardedBy("mLock") @GuardedBy("mLock")
private ArrayList<OnReparentListener> mReparentListeners; private ArrayList<OnReparentListener> mReparentListeners;

View File

@@ -1104,7 +1104,7 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
|| mWindowSpaceTop != mLocation[1]; || mWindowSpaceTop != mLocation[1];
final boolean layoutSizeChanged = getWidth() != mScreenRect.width() final boolean layoutSizeChanged = getWidth() != mScreenRect.width()
|| getHeight() != mScreenRect.height(); || getHeight() != mScreenRect.height();
final boolean hintChanged = (viewRoot.getSurfaceTransformHint() != mTransformHint) final boolean hintChanged = (viewRoot.getBufferTransformHint() != mTransformHint)
&& mRequestedVisible; && mRequestedVisible;
if (creating || formatChanged || sizeChanged || visibleChanged || if (creating || formatChanged || sizeChanged || visibleChanged ||
@@ -1130,7 +1130,7 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
mSurfaceHeight = myHeight; mSurfaceHeight = myHeight;
mFormat = mRequestedFormat; mFormat = mRequestedFormat;
mLastWindowVisibility = mWindowVisibility; mLastWindowVisibility = mWindowVisibility;
mTransformHint = viewRoot.getSurfaceTransformHint(); mTransformHint = viewRoot.getBufferTransformHint();
mScreenRect.left = mWindowSpaceLeft; mScreenRect.left = mWindowSpaceLeft;
mScreenRect.top = mWindowSpaceTop; mScreenRect.top = mWindowSpaceTop;
@@ -1362,7 +1362,7 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
if (mBlastBufferQueue != null) { if (mBlastBufferQueue != null) {
mBlastBufferQueue.destroy(); mBlastBufferQueue.destroy();
} }
mTransformHint = viewRoot.getSurfaceTransformHint(); mTransformHint = viewRoot.getBufferTransformHint();
mBlastSurfaceControl.setTransformHint(mTransformHint); mBlastSurfaceControl.setTransformHint(mTransformHint);
mBlastBufferQueue = new BLASTBufferQueue(name, mBlastSurfaceControl, mSurfaceWidth, mBlastBufferQueue = new BLASTBufferQueue(name, mBlastSurfaceControl, mSurfaceWidth,
mSurfaceHeight, mFormat); mSurfaceHeight, mFormat);

View File

@@ -312,7 +312,7 @@ public final class ViewRootImpl implements ViewParent,
static final ArrayList<Runnable> sFirstDrawHandlers = new ArrayList<>(); static final ArrayList<Runnable> sFirstDrawHandlers = new ArrayList<>();
static boolean sFirstDrawComplete = false; static boolean sFirstDrawComplete = false;
private ArrayList<OnSurfaceTransformHintChangedListener> mTransformHintListeners = private ArrayList<OnBufferTransformHintChangedListener> mTransformHintListeners =
new ArrayList<>(); new ArrayList<>();
private @Surface.Rotation int mPreviousTransformHint = Surface.ROTATION_0; private @Surface.Rotation int mPreviousTransformHint = Surface.ROTATION_0;
/** /**
@@ -7872,7 +7872,8 @@ public final class ViewRootImpl implements ViewParent,
int transformHint = mSurfaceControl.getTransformHint(); int transformHint = mSurfaceControl.getTransformHint();
if (mPreviousTransformHint != transformHint) { if (mPreviousTransformHint != transformHint) {
mPreviousTransformHint = transformHint; mPreviousTransformHint = transformHint;
dispatchTransformHintChanged(transformHint); dispatchTransformHintChanged(
SurfaceControl.rotationToBufferTransform(transformHint));
} }
} else { } else {
destroySurface(); destroySurface();
@@ -10499,38 +10500,38 @@ public final class ViewRootImpl implements ViewParent,
} }
@Override @Override
public @Surface.Rotation int getSurfaceTransformHint() { public @SurfaceControl.BufferTransform int getBufferTransformHint() {
return mSurfaceControl.getTransformHint(); return SurfaceControl.rotationToBufferTransform(mSurfaceControl.getTransformHint());
} }
@Override @Override
public void addOnSurfaceTransformHintChangedListener( public void addOnBufferTransformHintChangedListener(
OnSurfaceTransformHintChangedListener listener) { OnBufferTransformHintChangedListener listener) {
Objects.requireNonNull(listener); Objects.requireNonNull(listener);
if (mTransformHintListeners.contains(listener)) { if (mTransformHintListeners.contains(listener)) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"attempt to call addOnSurfaceTransformHintChangedListener() " "attempt to call addOnBufferTransformHintChangedListener() "
+ "with a previously registered listener"); + "with a previously registered listener");
} }
mTransformHintListeners.add(listener); mTransformHintListeners.add(listener);
} }
@Override @Override
public void removeOnSurfaceTransformHintChangedListener( public void removeOnBufferTransformHintChangedListener(
OnSurfaceTransformHintChangedListener listener) { OnBufferTransformHintChangedListener listener) {
Objects.requireNonNull(listener); Objects.requireNonNull(listener);
mTransformHintListeners.remove(listener); mTransformHintListeners.remove(listener);
} }
private void dispatchTransformHintChanged(@Surface.Rotation int hint) { private void dispatchTransformHintChanged(@SurfaceControl.BufferTransform int hint) {
if (mTransformHintListeners.isEmpty()) { if (mTransformHintListeners.isEmpty()) {
return; return;
} }
ArrayList<OnSurfaceTransformHintChangedListener> listeners = ArrayList<OnBufferTransformHintChangedListener> listeners =
(ArrayList<OnSurfaceTransformHintChangedListener>) mTransformHintListeners.clone(); (ArrayList<OnBufferTransformHintChangedListener>) mTransformHintListeners.clone();
for (int i = 0; i < listeners.size(); i++) { for (int i = 0; i < listeners.size(); i++) {
OnSurfaceTransformHintChangedListener listener = listeners.get(i); OnBufferTransformHintChangedListener listener = listeners.get(i);
listener.onSurfaceTransformHintChanged(hint); listener.onBufferTransformHintChanged(hint);
} }
} }
} }