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

Commit b0f30164 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Force snapshot update when requested transform changes from invalid to valid" into main

parents 2c710c3d 91282082
Loading
Loading
Loading
Loading
+9 −0
Original line number Original line Diff line number Diff line
@@ -150,6 +150,7 @@ RequestedLayerState::RequestedLayerState(const LayerCreationArgs& args)
}
}


void RequestedLayerState::merge(const ResolvedComposerState& resolvedComposerState) {
void RequestedLayerState::merge(const ResolvedComposerState& resolvedComposerState) {
    bool transformWasValid = transformIsValid;
    const uint32_t oldFlags = flags;
    const uint32_t oldFlags = flags;
    const half oldAlpha = color.a;
    const half oldAlpha = color.a;
    const bool hadBuffer = externalTexture != nullptr;
    const bool hadBuffer = externalTexture != nullptr;
@@ -357,6 +358,14 @@ void RequestedLayerState::merge(const ResolvedComposerState& resolvedComposerSta
        clientDrawnCornerRadius = clientState.clientDrawnCornerRadius;
        clientDrawnCornerRadius = clientState.clientDrawnCornerRadius;
        changes |= RequestedLayerState::Changes::Geometry;
        changes |= RequestedLayerState::Changes::Geometry;
    }
    }

    // We can't just check requestedTransform here because LayerSnapshotBuilder uses
    // getTransform which reads destinationFrame or buffer dimensions.
    // Display rotation does not affect validity so just use ROT_0.
    transformIsValid = LayerSnapshot::isTransformValid(getTransform(ui::Transform::ROT_0));
    if (!transformWasValid && transformIsValid) {
        changes |= RequestedLayerState::Changes::Visibility;
    }
}
}


ui::Size RequestedLayerState::getUnrotatedBufferSize(uint32_t displayRotationFlags) const {
ui::Size RequestedLayerState::getUnrotatedBufferSize(uint32_t displayRotationFlags) const {
+1 −0
Original line number Original line Diff line number Diff line
@@ -115,6 +115,7 @@ struct RequestedLayerState : layer_state_t {
    const gui::Pid ownerPid;
    const gui::Pid ownerPid;
    bool dataspaceRequested;
    bool dataspaceRequested;
    bool hasColorTransform;
    bool hasColorTransform;
    bool transformIsValid = true;
    bool premultipliedAlpha{true};
    bool premultipliedAlpha{true};
    // This layer can be a cursor on some displays.
    // This layer can be a cursor on some displays.
    bool potentialCursor{false};
    bool potentialCursor{false};
+41 −0
Original line number Original line Diff line number Diff line
@@ -90,5 +90,46 @@ static void updateClientStatesNoChanges(benchmark::State& state) {
}
}
BENCHMARK(updateClientStatesNoChanges);
BENCHMARK(updateClientStatesNoChanges);


static void propagateManyHiddenChildren(benchmark::State& state) {
    LayerLifecycleManager lifecycleManager;
    LayerLifecycleManagerHelper helper(lifecycleManager);

    helper.createRootLayer(0);
    for (uint32_t i = 1; i < 50; ++i) {
        helper.createLayer(i, i - 1);
    }

    helper.hideLayer(0);

    LayerHierarchyBuilder hierarchyBuilder;
    DisplayInfo info;
    info.info.logicalHeight = 100;
    info.info.logicalWidth = 100;
    DisplayInfos displayInfos;
    displayInfos.emplace_or_replace(ui::LayerStack::fromValue(1), info);
    ShadowSettings globalShadowSettings;

    LayerSnapshotBuilder snapshotBuilder;

    int i = 1;
    for (auto _ : state) {
        i++;
        helper.setAlpha(0, (1 + (i % 255)) / 255.0f);

        if (lifecycleManager.getGlobalChanges().test(RequestedLayerState::Changes::Hierarchy)) {
            hierarchyBuilder.update(lifecycleManager);
        }
        LayerSnapshotBuilder::Args args{.root = hierarchyBuilder.getHierarchy(),
                                        .layerLifecycleManager = lifecycleManager,
                                        .displays = displayInfos,
                                        .globalShadowSettings = globalShadowSettings,
                                        .supportedLayerGenericMetadata = {},
                                        .genericLayerMetadataKeyMap = {}};
        snapshotBuilder.update(args);
        lifecycleManager.commitChanges();
    }
}
BENCHMARK(propagateManyHiddenChildren);

} // namespace
} // namespace
} // namespace android::surfaceflinger
} // namespace android::surfaceflinger
+34 −0
Original line number Original line Diff line number Diff line
@@ -261,6 +261,40 @@ TEST_F(LayerSnapshotTest, AlphaInheritedByChildren) {
    EXPECT_EQ(getSnapshot(1221)->alpha, 0.25f);
    EXPECT_EQ(getSnapshot(1221)->alpha, 0.25f);
}
}


TEST_F(LayerSnapshotTest, AlphaInheritedByChildWhenParentIsHiddenByInvalidTransform) {
    setMatrix(1, 0, 0, 0, 0);
    update(mSnapshotBuilder);
    mLifecycleManager.commitChanges();

    setAlpha(1, 0.5);
    update(mSnapshotBuilder);
    mLifecycleManager.commitChanges();

    setMatrix(1, 1, 0, 0, 1);
    update(mSnapshotBuilder);
    mLifecycleManager.commitChanges();

    EXPECT_EQ(getSnapshot(1)->alpha, 0.5f);
    EXPECT_EQ(getSnapshot(11)->alpha, 0.5f);
}

TEST_F(LayerSnapshotTest, AlphaInheritedByChildWhenParentIsHidden) {
    hideLayer(1);
    update(mSnapshotBuilder);
    mLifecycleManager.commitChanges();

    setAlpha(1, 0.5);
    update(mSnapshotBuilder);
    mLifecycleManager.commitChanges();

    showLayer(1);
    update(mSnapshotBuilder);
    mLifecycleManager.commitChanges();

    EXPECT_EQ(getSnapshot(1)->alpha, 0.5f);
    EXPECT_EQ(getSnapshot(11)->alpha, 0.5f);
}

// Change states
// Change states
TEST_F(LayerSnapshotTest, UpdateClearsPreviousChangeStates) {
TEST_F(LayerSnapshotTest, UpdateClearsPreviousChangeStates) {
    setCrop(1, Rect(1, 2, 3, 4));
    setCrop(1, Rect(1, 2, 3, 4));