From 4b4182708a6c183a52f5459d357f341ea6c99e1b Mon Sep 17 00:00:00 2001 From: Andy CrossGate Yan Date: Sun, 19 Nov 2023 23:07:03 +0800 Subject: [PATCH 5/6] Restore getPhysicalDisplayIds in SurfaceControl For convenience of accessing DynamicDisplayInfo from Settings Copy over the updated implementation from DisplayControl while we're at it This partially reverts commit e2f333728788ad88a65208a6119aed90e13e7040. Change-Id: Ie056ecaf76acbc70d73e1c26cc4542088fcda18d --- core/java/android/view/SurfaceControl.java | 8 ++++++++ core/jni/android_view_SurfaceControl.cpp | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/core/java/android/view/SurfaceControl.java b/core/java/android/view/SurfaceControl.java index eff35c0c0f03..5cc1d0817688 100644 --- a/core/java/android/view/SurfaceControl.java +++ b/core/java/android/view/SurfaceControl.java @@ -176,6 +176,7 @@ public final class SurfaceControl implements Parcelable { private static native boolean nativeClearAnimationFrameStats(); private static native boolean nativeGetAnimationFrameStats(WindowAnimationFrameStats outStats); + private static native long[] nativeGetPhysicalDisplayIds(); private static native void nativeSetDisplaySurface(long transactionObj, IBinder displayToken, long nativeSurfaceObject); private static native void nativeSetDisplayLayerStack(long transactionObj, @@ -2379,6 +2380,13 @@ public final class SurfaceControl implements Parcelable { nativeSetGameContentType(displayToken, on); } + /** + * @hide + */ + public static long[] getPhysicalDisplayIds() { + return nativeGetPhysicalDisplayIds(); + } + /** * Returns whether protected content is supported in GPU composition. * @hide diff --git a/core/jni/android_view_SurfaceControl.cpp b/core/jni/android_view_SurfaceControl.cpp index 6fec527aaa16..8c908aa3d451 100644 --- a/core/jni/android_view_SurfaceControl.cpp +++ b/core/jni/android_view_SurfaceControl.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -1075,6 +1076,21 @@ static void nativeSetDestinationFrame(JNIEnv* env, jclass clazz, jlong transacti transaction->setDestinationFrame(ctrl, crop); } +static jlongArray nativeGetPhysicalDisplayIds(JNIEnv* env, jclass clazz) { + const auto displayIds = SurfaceComposerClient::getPhysicalDisplayIds(); + ScopedLongArrayRW values(env, env->NewLongArray(displayIds.size())); + if (values.get() == nullptr) { + jniThrowException(env, "java/lang/OutOfMemoryError", nullptr); + return nullptr; + } + + for (size_t i = 0; i < displayIds.size(); ++i) { + values[i] = static_cast(displayIds[i].value); + } + + return values.getJavaArray(); +} + static jobject nativeGetDisplayedContentSamplingAttributes(JNIEnv* env, jclass clazz, jobject tokenObj) { sp token(ibinderForJavaObject(env, tokenObj)); @@ -2269,6 +2285,8 @@ static const JNINativeMethod sSurfaceControlMethods[] = { (void*)nativeSetFrameRateCategory}, {"nativeSetFrameRateSelectionStrategy", "(JJI)V", (void*)nativeSetFrameRateSelectionStrategy}, + {"nativeGetPhysicalDisplayIds", "()[J", + (void*)nativeGetPhysicalDisplayIds }, {"nativeSetDisplaySurface", "(JLandroid/os/IBinder;J)V", (void*)nativeSetDisplaySurface }, {"nativeSetDisplayLayerStack", "(JLandroid/os/IBinder;I)V", -- 2.34.1