summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/view/SurfaceControl.java25
-rw-r--r--core/jni/android_view_SurfaceControl.cpp10
2 files changed, 35 insertions, 0 deletions
diff --git a/core/java/android/view/SurfaceControl.java b/core/java/android/view/SurfaceControl.java
index 8dd475e0c306..b815c641ff25 100644
--- a/core/java/android/view/SurfaceControl.java
+++ b/core/java/android/view/SurfaceControl.java
@@ -196,6 +196,8 @@ public final class SurfaceControl implements Parcelable {
float brightness);
private static native long nativeReadTransactionFromParcel(Parcel in);
private static native void nativeWriteTransactionToParcel(long nativeObject, Parcel out);
+ private static native void nativeSetShadowRadius(long transactionObj, long nativeObject,
+ float shadowRadius);
private final CloseGuard mCloseGuard = CloseGuard.get();
private String mName;
@@ -2545,6 +2547,29 @@ public final class SurfaceControl implements Parcelable {
return this;
}
+ /**
+ * Draws shadows of length {@code shadowRadius} around the surface {@link SurfaceControl}.
+ * If the length is 0.0f then the shadows will not be drawn.
+ *
+ * Shadows are drawn around the screen bounds, these are the post transformed cropped
+ * bounds. They can draw over their parent bounds and will be occluded by layers with a
+ * higher z-order. The shadows will respect the surface's corner radius if the
+ * rounded corner bounds (transformed source bounds) are within the screen bounds.
+ *
+ * A shadow will only be drawn on buffer and color layers. If the radius is applied on a
+ * container layer, it will be passed down the hierarchy to be applied on buffer and color
+ * layers but not its children. A scenario where this is useful is when SystemUI animates
+ * a task by controlling a leash to it, can draw a shadow around the app surface by
+ * setting a shadow on the leash. This is similar to how rounded corners are set.
+ *
+ * @hide
+ */
+ public Transaction setShadowRadius(SurfaceControl sc, float shadowRadius) {
+ sc.checkNotReleased();
+ nativeSetShadowRadius(mNativeObject, sc.mNativeObject, shadowRadius);
+ return this;
+ }
+
/**
* Merge the other transaction into this transaction, clearing the
* other transaction as if it had been applied.
diff --git a/core/jni/android_view_SurfaceControl.cpp b/core/jni/android_view_SurfaceControl.cpp
index d5cd278063c0..c807e90d5ad4 100644
--- a/core/jni/android_view_SurfaceControl.cpp
+++ b/core/jni/android_view_SurfaceControl.cpp
@@ -545,6 +545,14 @@ static void nativeSetLayerStack(JNIEnv* env, jclass clazz, jlong transactionObj,
transaction->setLayerStack(ctrl, layerStack);
}
+static void nativeSetShadowRadius(JNIEnv* env, jclass clazz, jlong transactionObj,
+ jlong nativeObject, jfloat shadowRadius) {
+ auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
+
+ const auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
+ transaction->setShadowRadius(ctrl, shadowRadius);
+}
+
static jlongArray nativeGetPhysicalDisplayIds(JNIEnv* env, jclass clazz) {
const auto displayIds = SurfaceComposerClient::getPhysicalDisplayIds();
jlongArray array = env->NewLongArray(displayIds.size());
@@ -1308,6 +1316,8 @@ static const JNINativeMethod sSurfaceControlMethods[] = {
(void*)nativeSetCornerRadius },
{"nativeSetLayerStack", "(JJI)V",
(void*)nativeSetLayerStack },
+ {"nativeSetShadowRadius", "(JJF)V",
+ (void*)nativeSetShadowRadius },
{"nativeGetPhysicalDisplayIds", "()[J",
(void*)nativeGetPhysicalDisplayIds },
{"nativeGetPhysicalDisplayToken", "(J)Landroid/os/IBinder;",