Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d87984df authored by Vishnu Nair's avatar Vishnu Nair
Browse files

[Shadows] Add an api to draw shadows around a surface. (1/n)

Bug: 136561771
Test: go/wm-smoke

Change-Id: Ibbf87d93ec30109dae0fbb112e4e20bae5a096f2
parent 98e9bbdb
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -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.
+10 −0
Original line number Diff line number Diff line
@@ -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;",