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

Commit df1982d1 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: Ic3b253a0d9d1e61121104acadc0b29af9aca1872
parent 65fb1c6d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -94,6 +94,7 @@ filegroup {
        "android/**/TouchOcclusionMode.aidl",
        "android/gui/TrustedOverlay.aidl",
        "android/gui/BorderSettings.aidl",
        "android/gui/BoxShadowSettings.aidl",
    ],
}

+7 −0
Original line number Diff line number Diff line
@@ -181,6 +181,7 @@ status_t layer_state_t::write(Parcel& output) const
    }
    SAFE_PARCEL(output.writeFloat, shadowRadius);
    SAFE_PARCEL(output.writeParcelable, borderSettings);
    SAFE_PARCEL(output.writeParcelable, boxShadowSettings);
    SAFE_PARCEL(output.writeInt32, frameRateSelectionPriority);
    SAFE_PARCEL(output.writeFloat, frameRate);
    SAFE_PARCEL(output.writeByte, frameRateCompatibility);
@@ -330,6 +331,7 @@ status_t layer_state_t::read(const Parcel& input)
    }
    SAFE_PARCEL(input.readFloat, &shadowRadius);
    SAFE_PARCEL(input.readParcelable, &borderSettings);
    SAFE_PARCEL(input.readParcelable, &boxShadowSettings);

    SAFE_PARCEL(input.readInt32, &frameRateSelectionPriority);
    SAFE_PARCEL(input.readFloat, &frameRate);
@@ -734,6 +736,10 @@ void layer_state_t::merge(const layer_state_t& other) {
        what |= eBorderSettingsChanged;
        borderSettings = other.borderSettings;
    }
    if (other.what & eBoxShadowSettingsChanged) {
        what |= eBoxShadowSettingsChanged;
        boxShadowSettings = other.boxShadowSettings;
    }
    if (other.what & eLutsChanged) {
        what |= eLutsChanged;
        luts = other.luts;
@@ -889,6 +895,7 @@ uint64_t layer_state_t::diff(const layer_state_t& other) const {
    if (other.what & eMetadataChanged) diff |= eMetadataChanged;
    CHECK_DIFF(diff, eShadowRadiusChanged, other, shadowRadius);
    CHECK_DIFF(diff, eBorderSettingsChanged, other, borderSettings);
    CHECK_DIFF(diff, eBoxShadowSettingsChanged, other, boxShadowSettings);
    CHECK_DIFF(diff, eDefaultFrameRateCompatibilityChanged, other, defaultFrameRateCompatibility);
    CHECK_DIFF(diff, eFrameRateSelectionPriority, other, frameRateSelectionPriority);
    CHECK_DIFF3(diff, eFrameRateChanged, other, frameRate, frameRateCompatibility,
+13 −0
Original line number Diff line number Diff line
@@ -2235,6 +2235,19 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setBorde
    return *this;
}

SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setBoxShadowSettings(
        const sp<SurfaceControl>& sc, gui::BoxShadowSettings settings) {
    layer_state_t* s = getLayerState(sc);
    if (!s) {
        mStatus = BAD_INDEX;
        return *this;
    }

    s->what |= layer_state_t::eBoxShadowSettingsChanged;
    s->boxShadowSettings = settings;
    return *this;
}

SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFrameRate(
        const sp<SurfaceControl>& sc, float frameRate, int8_t compatibility,
        int8_t changeFrameRateStrategy) {
+32 −0
Original line number Diff line number Diff line
/**
 * Copyright (c) 2025, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.gui;

/** @hide */
parcelable BoxShadowSettings {
    parcelable BoxShadowParams
    {
        float blurRadius;
        float spreadRadius;
        // Space is sRGB, not premultiplied, bit pattern is 0xAARRGGBB.
        int color;
        float offsetX;
        float offsetY;
    }

    BoxShadowParams []boxShadows = {};
}
+8 −2
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
#include <span>

#include <android/gui/BorderSettings.h>
#include <android/gui/BoxShadowSettings.h>
#include <android/gui/DisplayCaptureArgs.h>
#include <android/gui/IWindowInfosReportedListener.h>
#include <android/gui/LayerCaptureArgs.h>
@@ -252,6 +253,7 @@ struct layer_state_t {
        eAppContentPriorityChanged = 0x100000'00000000,
        eClientDrawnCornerRadiusChanged = 0x200000'00000000,
        eBorderSettingsChanged = 0x400000'00000000,
        eBoxShadowSettingsChanged = 0x800000'00000000,
    };

    layer_state_t();
@@ -296,7 +298,8 @@ struct layer_state_t {
            layer_state_t::eCornerRadiusChanged | layer_state_t::eDimmingEnabledChanged |
            layer_state_t::eHdrMetadataChanged | layer_state_t::eShadowRadiusChanged |
            layer_state_t::eStretchChanged | layer_state_t::ePictureProfileHandleChanged |
            layer_state_t::eAppContentPriorityChanged | layer_state_t::eBorderSettingsChanged;
            layer_state_t::eAppContentPriorityChanged | layer_state_t::eBorderSettingsChanged |
            layer_state_t::eBoxShadowSettingsChanged;

    // Changes which invalidates the layer's visible region in CE.
    static constexpr uint64_t CONTENT_DIRTY = layer_state_t::CONTENT_CHANGES |
@@ -325,7 +328,7 @@ struct layer_state_t {
    static constexpr uint64_t COMPOSITION_EFFECTS = layer_state_t::eBackgroundBlurRadiusChanged |
            layer_state_t::eBlurRegionsChanged | layer_state_t::eCornerRadiusChanged |
            layer_state_t::eShadowRadiusChanged | layer_state_t::eStretchChanged |
            layer_state_t::eBorderSettingsChanged;
            layer_state_t::eBorderSettingsChanged | layer_state_t::eBoxShadowSettingsChanged;

    bool hasValidBuffer() const;
    void sanitize(int32_t permissions);
@@ -417,6 +420,9 @@ struct layer_state_t {
    // Draws an outline around the layer.
    gui::BorderSettings borderSettings;

    // Draws a sequence of box shadows under the layer.
    gui::BoxShadowSettings boxShadowSettings;

    // Priority of the layer assigned by Window Manager.
    int32_t frameRateSelectionPriority;

Loading