diff options
author | 2025-03-24 11:12:02 -0700 | |
---|---|---|
committer | 2025-03-24 11:12:02 -0700 | |
commit | 4a76e99c28ad5235b8cf09272c35b3d2001938f5 (patch) | |
tree | 6c0d0242f36b589c146ec7758ee618c3b3da178d | |
parent | 75bf7d5d1b83f141a3a387b0fbf87d0f0380801f (diff) | |
parent | be940c85397c9e81e4d520bd042bebae87893cdb (diff) |
Merge "Add border API to surface control" into main
-rw-r--r-- | core/java/android/view/SurfaceControl.java | 35 | ||||
-rw-r--r-- | core/java/android/window/flags/window_surfaces.aconfig | 8 | ||||
-rw-r--r-- | core/jni/android_view_SurfaceControl.cpp | 23 |
3 files changed, 66 insertions, 0 deletions
diff --git a/core/java/android/view/SurfaceControl.java b/core/java/android/view/SurfaceControl.java index f9d7a672f43a..872076b4b41c 100644 --- a/core/java/android/view/SurfaceControl.java +++ b/core/java/android/view/SurfaceControl.java @@ -47,6 +47,7 @@ import android.graphics.PixelFormat; import android.graphics.Point; import android.graphics.Rect; import android.graphics.Region; +import android.gui.BorderSettings; import android.gui.DropInputMode; import android.gui.StalledTransactionInfo; import android.gui.TrustedOverlay; @@ -261,6 +262,10 @@ public final class SurfaceControl implements Parcelable { private static native void nativeWriteTransactionToParcel(long nativeObject, Parcel out); private static native void nativeSetShadowRadius(long transactionObj, long nativeObject, float shadowRadius); + + private static native void nativeSetBorderSettings(long transactionObj, long nativeObject, + Parcel settings); + private static native void nativeSetGlobalShadowSettings(@Size(4) float[] ambientColor, @Size(4) float[] spotColor, float lightPosY, float lightPosZ, float lightRadius); private static native DisplayDecorationSupport nativeGetDisplayDecorationSupport( @@ -4133,6 +4138,36 @@ public final class SurfaceControl implements Parcelable { } /** + * Sets the outline settings on this SurfaceControl. If a shadow radius is set, + * the outline will be drawn after the shadow and before any buffers. + * The outline will be drawn on the border (outside) of the rounded rectangle + * that is used for shadow casting. I.e. for an opaque layer, + * the outline begins where shadow is visible. + * + * @hide + */ + public Transaction setBorderSettings(SurfaceControl sc, + @NonNull BorderSettings settings) { + checkPreconditions(sc); + if (SurfaceControlRegistry.sCallStackDebuggingEnabled) { + SurfaceControlRegistry.getProcessInstance().checkCallStackDebugging( + "setBorderSettings", this, sc, "settings=" + settings); + } + + if (!Flags.enableBorderSettings()) { + Log.w(TAG, "setBorderSettings was called but" + + "enable_border_settings flag is disabled"); + return this; + } + + Parcel settingsParcel = Parcel.obtain(); + settings.writeToParcel(settingsParcel, 0); + settingsParcel.setDataPosition(0); + nativeSetBorderSettings(mNativeObject, sc.mNativeObject, settingsParcel); + return this; + } + + /** * Sets the intended frame rate for this surface. Any switching of refresh rates is * most probably going to be seamless. * diff --git a/core/java/android/window/flags/window_surfaces.aconfig b/core/java/android/window/flags/window_surfaces.aconfig index 756288bdf5bf..7550a6360ee9 100644 --- a/core/java/android/window/flags/window_surfaces.aconfig +++ b/core/java/android/window/flags/window_surfaces.aconfig @@ -99,6 +99,14 @@ flag { } # ignore_corner_radius_and_shadows flag { + name: "enable_border_settings" + namespace: "window_surfaces" + description: "Enable SurfaceControl outline settings." + bug: "367464660" + is_fixed_read_only: true +} + +flag { name: "jank_api" namespace: "window_surfaces" description: "Adds the jank data listener to AttachedSurfaceControl" diff --git a/core/jni/android_view_SurfaceControl.cpp b/core/jni/android_view_SurfaceControl.cpp index a8e51a7c1fe8..f3a5575a548e 100644 --- a/core/jni/android_view_SurfaceControl.cpp +++ b/core/jni/android_view_SurfaceControl.cpp @@ -1146,6 +1146,27 @@ static void nativeSetShadowRadius(JNIEnv* env, jclass clazz, jlong transactionOb transaction->setShadowRadius(ctrl, shadowRadius); } +static void nativeSetBorderSettings(JNIEnv* env, jclass clazz, jlong transactionObj, + jlong nativeObject, jobject settingsObj) { + Parcel* settingsParcel = parcelForJavaObject(env, settingsObj); + if (settingsParcel == NULL) { + doThrowNPE(env); + return; + } + gui::BorderSettings settings; + status_t err = settings.readFromParcel(settingsParcel); + if (err != NO_ERROR) { + jniThrowException(env, "java/lang/IllegalArgumentException", + "BorderSettings parcel has wrong format"); + return; + } + + auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); + const auto ctrl = reinterpret_cast<SurfaceControl*>(nativeObject); + + transaction->setBorderSettings(ctrl, settings); +} + static void nativeSetTrustedOverlay(JNIEnv* env, jclass clazz, jlong transactionObj, jlong nativeObject, jint trustedOverlay) { auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); @@ -2570,6 +2591,8 @@ static const JNINativeMethod sSurfaceControlMethods[] = { (void*) nativeSetEdgeExtensionEffect }, {"nativeSetShadowRadius", "(JJF)V", (void*)nativeSetShadowRadius }, + {"nativeSetBorderSettings", "(JJLandroid/os/Parcel;)V", + (void*)nativeSetBorderSettings }, {"nativeSetFrameRate", "(JJFII)V", (void*)nativeSetFrameRate }, {"nativeSetDefaultFrameRateCompatibility", "(JJI)V", |