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

Commit 67dd7126 authored by Tianhao Yao's avatar Tianhao Yao Committed by chaviw
Browse files

Enable drawing layers' borders in SurfaceFlinger.

Provide an API on SurfaceComposerClient::Transaction for enabling
a border to be drawn for a specified hierarchy. The caller requests a
border to be drawn at a certain Layer and all its children will be
included when computing the visible region. The border will draw around
the union of all the layers' visible regions, starting from the
requested layer.

Test: go/wm-smoke
Test: LayerBorder_test
Bug: 225977175

Change-Id: I7760b51b68cdf01bb9146ec91a270a9d63927995
parent ff4b9b8d
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ layer_state_t::layer_state_t()
        fixedTransformHint(ui::Transform::ROT_INVALID),
        autoRefresh(false),
        isTrustedOverlay(false),
        borderEnabled(false),
        bufferCrop(Rect::INVALID_RECT),
        destinationFrame(Rect::INVALID_RECT),
        dropInputMode(gui::DropInputMode::NONE) {
@@ -100,7 +101,7 @@ status_t layer_state_t::write(Parcel& output) const
    SAFE_PARCEL(output.write, transparentRegion);
    SAFE_PARCEL(output.writeUint32, transform);
    SAFE_PARCEL(output.writeBool, transformToDisplayInverse);

    SAFE_PARCEL(output.writeBool, borderEnabled);
    SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(dataspace));
    SAFE_PARCEL(output.write, hdrMetadata);
    SAFE_PARCEL(output.write, surfaceDamageRegion);
@@ -200,6 +201,7 @@ status_t layer_state_t::read(const Parcel& input)
    SAFE_PARCEL(input.read, transparentRegion);
    SAFE_PARCEL(input.readUint32, &transform);
    SAFE_PARCEL(input.readBool, &transformToDisplayInverse);
    SAFE_PARCEL(input.readBool, &borderEnabled);

    uint32_t tmpUint32 = 0;
    SAFE_PARCEL(input.readUint32, &tmpUint32);
@@ -550,6 +552,10 @@ void layer_state_t::merge(const layer_state_t& other) {
        what |= eShadowRadiusChanged;
        shadowRadius = other.shadowRadius;
    }
    if (other.what & eRenderBorderChanged) {
        what |= eRenderBorderChanged;
        borderEnabled = other.borderEnabled;
    }
    if (other.what & eFrameRateSelectionPriority) {
        what |= eFrameRateSelectionPriority;
        frameRateSelectionPriority = other.frameRateSelectionPriority;
+15 −0
Original line number Diff line number Diff line
@@ -1918,6 +1918,21 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setDropI
    return *this;
}

SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::enableBorder(
        const sp<SurfaceControl>& sc, bool shouldEnable) {
    layer_state_t* s = getLayerState(sc);
    if (!s) {
        mStatus = BAD_INDEX;
        return *this;
    }

    s->what |= layer_state_t::eRenderBorderChanged;
    s->borderEnabled = shouldEnable;

    registerSurfaceControlForCallback(sc);
    return *this;
}

// ---------------------------------------------------------------------------

DisplayState& SurfaceComposerClient::Transaction::getDisplayState(const sp<IBinder>& token) {
+3 −1
Original line number Diff line number Diff line
@@ -155,7 +155,7 @@ struct layer_state_t {
        eLayerStackChanged = 0x00000080,
        eDimmingEnabledChanged = 0x00000400,
        eShadowRadiusChanged = 0x00000800,
        /* unused 0x00001000, */
        eRenderBorderChanged = 0x00001000,
        eBufferCropChanged = 0x00002000,
        eRelativeLayerChanged = 0x00004000,
        eReparent = 0x00008000,
@@ -293,6 +293,8 @@ struct layer_state_t {
    // should be trusted for input occlusion detection purposes
    bool isTrustedOverlay;

    // Flag to indicate if border needs to be enabled on the layer
    bool borderEnabled;
    // Stretch effect to be applied to this layer
    StretchEffect stretchEffect;

+2 −0
Original line number Diff line number Diff line
@@ -625,6 +625,8 @@ public:
                                         const Rect& destinationFrame);
        Transaction& setDropInputMode(const sp<SurfaceControl>& sc, gui::DropInputMode mode);

        Transaction& enableBorder(const sp<SurfaceControl>& sc, bool shouldEnable);

        status_t setDisplaySurface(const sp<IBinder>& token,
                const sp<IGraphicBufferProducer>& bufferProducer);

+33 −0
Original line number Diff line number Diff line
/*
 * Copyright 2022 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.
 */

#pragma once
#include <math/mat4.h>
#include <ui/Region.h>

namespace android {
namespace renderengine {

struct BorderRenderInfo {
    Region combinedRegion;

    bool operator==(const BorderRenderInfo& rhs) const {
        return (combinedRegion.hasSameRects(rhs.combinedRegion));
    }
};

} // namespace renderengine
} // namespace android
 No newline at end of file
Loading