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

Commit 9e6cc5ac authored by YCairn Overturf's avatar YCairn Overturf
Browse files

Add box shadow API to surface control

See go/sf-box-shadows-api for more details.

Bug: b/367464660
Flag: com.android.window.flags.enable_box_shadow_settings
Test: atest SurfaceFlinger_test
Change-Id: I1ae0120060cb783799cf5421fc4ca41144c74412
parent af19c584
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.Region;
import android.gui.BorderSettings;
import android.gui.BoxShadowSettings;
import android.gui.DropInputMode;
import android.gui.StalledTransactionInfo;
import android.gui.TrustedOverlay;
@@ -263,6 +264,9 @@ public final class SurfaceControl implements Parcelable {
    private static native void nativeSetShadowRadius(long transactionObj, long nativeObject,
            float shadowRadius);

    private static native void nativeSetBoxShadowSettings(long transactionObj, long nativeObject,
            Parcel settings);

    private static native void nativeSetBorderSettings(long transactionObj, long nativeObject,
            Parcel settings);

@@ -4138,6 +4142,36 @@ public final class SurfaceControl implements Parcelable {
                        "setShadowRadius", this, sc, "radius=" + shadowRadius);
            }
            nativeSetShadowRadius(mNativeObject, sc.mNativeObject, shadowRadius);


            return this;
        }

        /**
         * Sets the box shadow settings on this SurfaceControl. If any box shadows are set,
         * the box shadows will be immediately drawn after the elevation shadow and before
         * any outline. The box shadow will use the same bounds as elevation shadows.
         *
         * @hide
         */
        public Transaction setBoxShadowSettings(SurfaceControl sc,
                @NonNull BoxShadowSettings settings) {
            checkPreconditions(sc);
            if (SurfaceControlRegistry.sCallStackDebuggingEnabled) {
                SurfaceControlRegistry.getProcessInstance().checkCallStackDebugging(
                        "setBoxShadowSettings", this, sc, "settings=" + settings);
            }

            if (!Flags.enableBoxShadowSettings()) {
                Log.w(TAG, "setBoxShadowSettings was called but"
                            + "enable_box_shadow_settings flag is disabled");
                return this;
            }

            Parcel settingsParcel = Parcel.obtain();
            settings.writeToParcel(settingsParcel, 0);
            settingsParcel.setDataPosition(0);
            nativeSetBoxShadowSettings(mNativeObject, sc.mNativeObject, settingsParcel);
            return this;
        }

+8 −0
Original line number Diff line number Diff line
@@ -106,6 +106,14 @@ flag {
  is_fixed_read_only: true
}

flag {
  name: "enable_box_shadow_settings"
  namespace: "window_surfaces"
  description: "Enable SurfaceControl box shadow settings."
  bug: "367464660"
  is_fixed_read_only: true
}

flag {
    name: "jank_api"
    namespace: "window_surfaces"
+23 −0
Original line number Diff line number Diff line
@@ -1146,6 +1146,27 @@ static void nativeSetShadowRadius(JNIEnv* env, jclass clazz, jlong transactionOb
    transaction->setShadowRadius(ctrl, shadowRadius);
}

static void nativeSetBoxShadowSettings(JNIEnv* env, jclass clazz, jlong transactionObj,
                                       jlong nativeObject, jobject settingsObj) {
    Parcel* settingsParcel = parcelForJavaObject(env, settingsObj);
    if (settingsParcel == NULL) {
        doThrowNPE(env);
        return;
    }
    gui::BoxShadowSettings settings;
    status_t err = settings.readFromParcel(settingsParcel);
    if (err != NO_ERROR) {
        jniThrowException(env, "java/lang/IllegalArgumentException",
                          "BoxShadowSettings parcel has wrong format");
        return;
    }

    auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
    const auto ctrl = reinterpret_cast<SurfaceControl*>(nativeObject);

    transaction->setBoxShadowSettings(ctrl, settings);
}

static void nativeSetBorderSettings(JNIEnv* env, jclass clazz, jlong transactionObj,
                                    jlong nativeObject, jobject settingsObj) {
    Parcel* settingsParcel = parcelForJavaObject(env, settingsObj);
@@ -2591,6 +2612,8 @@ static const JNINativeMethod sSurfaceControlMethods[] = {
            (void*) nativeSetEdgeExtensionEffect },
    {"nativeSetShadowRadius", "(JJF)V",
            (void*)nativeSetShadowRadius },
    {"nativeSetBoxShadowSettings", "(JJLandroid/os/Parcel;)V",
            (void*)nativeSetBoxShadowSettings },
    {"nativeSetBorderSettings", "(JJLandroid/os/Parcel;)V",
            (void*)nativeSetBorderSettings },
    {"nativeSetFrameRate", "(JJFII)V",