From 9e98140a17e2e76a177112d993e307396f028a2c Mon Sep 17 00:00:00 2001 From: Pablo Gamito Date: Wed, 1 Sep 2021 15:24:32 +0000 Subject: [PATCH 1/3] Expose SurfaceControl's native mLayerId property to Java Expose the layerId so that we can dump it in WindowManager proto traces. This is to allow us to link windows to their respective layer accurately and consistently from the trace data. This enables Flicker as a Service (go/wm-fass) to tag and assocaite animations across the WindowManager trace and SurfaceFlinger trace and allows us to better display and associate errors across both WM and SF hierarchy views in Winscope. Test: N/A Bug: 197712697 Change-Id: Ic11f33b8dc3e134d6c19ac68bfe03f801af04d06 --- core/java/android/view/SurfaceControl.java | 14 ++++++++++++-- core/jni/android_view_SurfaceControl.cpp | 8 ++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/core/java/android/view/SurfaceControl.java b/core/java/android/view/SurfaceControl.java index d6186d71331e1..2c1a83f44cc13 100644 --- a/core/java/android/view/SurfaceControl.java +++ b/core/java/android/view/SurfaceControl.java @@ -239,6 +239,7 @@ public final class SurfaceControl implements Parcelable { private static native int nativeGetGPUContextPriority(); private static native void nativeSetTransformHint(long nativeObject, int transformHint); private static native int nativeGetTransformHint(long nativeObject); + private static native int nativeGetLayerId(long nativeObject); @Nullable @GuardedBy("mLock") @@ -354,8 +355,6 @@ public final class SurfaceControl implements Parcelable { @GuardedBy("mLock") private int mHeight; - private int mTransformHint; - private WeakReference mLocalOwnerView; static GlobalTransactionWrapper sGlobalTransaction; @@ -3652,4 +3651,15 @@ public final class SurfaceControl implements Parcelable { public void setTransformHint(@Surface.Rotation int transformHint) { nativeSetTransformHint(mNativeObject, transformHint); } + + /** + * @hide + */ + public int getLayerId() { + if (mNativeObject != 0) { + return nativeGetLayerId(mNativeObject); + } + + return -1; + } } diff --git a/core/jni/android_view_SurfaceControl.cpp b/core/jni/android_view_SurfaceControl.cpp index b9233a087c333..eeb6ce5375476 100644 --- a/core/jni/android_view_SurfaceControl.cpp +++ b/core/jni/android_view_SurfaceControl.cpp @@ -1815,6 +1815,12 @@ static jint nativeGetTransformHint(JNIEnv* env, jclass clazz, jlong nativeSurfac return toRotationInt(ui::Transform::toRotation((transformHintRotationFlags))); } +static jint nativeGetLayerId(JNIEnv* env, jclass clazz, jlong nativeSurfaceControl) { + sp surface(reinterpret_cast(nativeSurfaceControl)); + + return surface->getLayerId(); +} + // ---------------------------------------------------------------------------- static const JNINativeMethod sSurfaceControlMethods[] = { @@ -2010,6 +2016,8 @@ static const JNINativeMethod sSurfaceControlMethods[] = { (void*)nativeGetTransformHint }, {"nativeSetTrustedOverlay", "(JJZ)V", (void*)nativeSetTrustedOverlay }, + {"nativeGetLayerId", "(J)I", + (void*)nativeGetLayerId }, // clang-format on }; From 120ee45bd05755f5325ba33b706f2c1e431122dc Mon Sep 17 00:00:00 2001 From: Pablo Gamito Date: Wed, 1 Sep 2021 15:25:42 +0000 Subject: [PATCH 2/3] Dump SurfaceControl's layerId to proto Test: Data appears in Winscope Bug: 197712697 Change-Id: Ida47f5506a56b19902fcaafc644d1df34ce6c4a3 --- core/java/android/view/SurfaceControl.java | 2 ++ core/proto/android/view/surfacecontrol.proto | 1 + 2 files changed, 3 insertions(+) diff --git a/core/java/android/view/SurfaceControl.java b/core/java/android/view/SurfaceControl.java index 2c1a83f44cc13..9972eba7ea207 100644 --- a/core/java/android/view/SurfaceControl.java +++ b/core/java/android/view/SurfaceControl.java @@ -23,6 +23,7 @@ import static android.graphics.Matrix.MSKEW_Y; import static android.graphics.Matrix.MTRANS_X; import static android.graphics.Matrix.MTRANS_Y; import static android.view.SurfaceControlProto.HASH_CODE; +import static android.view.SurfaceControlProto.LAYER_ID; import static android.view.SurfaceControlProto.NAME; import android.annotation.FloatRange; @@ -1537,6 +1538,7 @@ public final class SurfaceControl implements Parcelable { final long token = proto.start(fieldId); proto.write(HASH_CODE, System.identityHashCode(this)); proto.write(NAME, mName); + proto.write(LAYER_ID, getLayerId()); proto.end(token); } diff --git a/core/proto/android/view/surfacecontrol.proto b/core/proto/android/view/surfacecontrol.proto index cbb243ba7872f..5a5f035412b2c 100644 --- a/core/proto/android/view/surfacecontrol.proto +++ b/core/proto/android/view/surfacecontrol.proto @@ -29,4 +29,5 @@ message SurfaceControlProto { optional int32 hash_code = 1; optional string name = 2 [ (android.privacy).dest = DEST_EXPLICIT ]; + optional int32 layerId = 3; } From afaa2fedf06b1ceb864699df6b936ec76e585a8e Mon Sep 17 00:00:00 2001 From: Pablo Gamito Date: Wed, 1 Sep 2021 15:26:50 +0000 Subject: [PATCH 3/3] Dump WindowContainer SurfaceControls to proto Test: Data appears in Winscope Bug: 197712697 Change-Id: I5a2704f4e910529d81698768a6e657e4f823d829 --- core/proto/android/server/windowmanagerservice.proto | 1 + services/core/java/com/android/server/wm/WindowContainer.java | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/core/proto/android/server/windowmanagerservice.proto b/core/proto/android/server/windowmanagerservice.proto index 0121bff3e7ef0..4af9d75682bbd 100644 --- a/core/proto/android/server/windowmanagerservice.proto +++ b/core/proto/android/server/windowmanagerservice.proto @@ -480,6 +480,7 @@ message WindowContainerProto { optional SurfaceAnimatorProto surface_animator = 4; repeated WindowContainerChildProto children = 5; optional IdentifierProto identifier = 6; + optional .android.view.SurfaceControlProto surface_control = 7; } /* represents a generic child of a WindowContainer */ diff --git a/services/core/java/com/android/server/wm/WindowContainer.java b/services/core/java/com/android/server/wm/WindowContainer.java index b6c8e13bb74f2..59d5ccfdbe092 100644 --- a/services/core/java/com/android/server/wm/WindowContainer.java +++ b/services/core/java/com/android/server/wm/WindowContainer.java @@ -51,6 +51,7 @@ import static com.android.server.wm.WindowContainerProto.CONFIGURATION_CONTAINER import static com.android.server.wm.WindowContainerProto.IDENTIFIER; import static com.android.server.wm.WindowContainerProto.ORIENTATION; import static com.android.server.wm.WindowContainerProto.SURFACE_ANIMATOR; +import static com.android.server.wm.WindowContainerProto.SURFACE_CONTROL; import static com.android.server.wm.WindowContainerProto.VISIBLE; import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM; import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; @@ -2393,6 +2394,9 @@ class WindowContainer extends ConfigurationContainer< if (mSurfaceAnimator.isAnimating()) { mSurfaceAnimator.dumpDebug(proto, SURFACE_ANIMATOR); } + if (mSurfaceControl != null) { + mSurfaceControl.dumpDebug(proto, SURFACE_CONTROL); + } // add children to proto for (int i = 0; i < getChildCount(); i++) {