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

Commit b09293f0 authored by Wenhui Yang's avatar Wenhui Yang
Browse files

Skip invisible windows in input list

To reduce traffic sent over binder and the number of copied objects in native code, we decide to remove windows from WindowInfosListener that are not visible because input doesn't need to know about the windows that aren't visible, and invisible windows don't affect the operation of other windows.

Fixes: 305254099
Test: adb shell su root dumpsys SurfaceFlinger
Test: atest LayerSnapshotTest
Flag: EXEMPT bugfix
Change-Id: I1ccc29565ee92277a703d16c07fd1141d6df6862
parent 28c8e155
Loading
Loading
Loading
Loading
+23 −14
Original line number Diff line number Diff line
@@ -261,6 +261,9 @@ void updateVisibility(LayerSnapshot& snapshot, bool visible) {
    }
    snapshot.isVisible = visible;

    if (FlagManager::getInstance().skip_invisible_windows_in_input()) {
        snapshot.inputInfo.setInputConfig(gui::WindowInfo::InputConfig::NOT_VISIBLE, !visible);
    } else {
        // TODO(b/238781169) we are ignoring this compat for now, since we will have
        // to remove any optimization based on visibility.

@@ -274,7 +277,9 @@ void updateVisibility(LayerSnapshot& snapshot, bool visible) {
        // anything.
        const bool visibleForInput =
                snapshot.hasInputInfo() ? snapshot.canReceiveInput() : snapshot.isVisible;
    snapshot.inputInfo.setInputConfig(gui::WindowInfo::InputConfig::NOT_VISIBLE, !visibleForInput);
        snapshot.inputInfo.setInputConfig(gui::WindowInfo::InputConfig::NOT_VISIBLE,
                                          !visibleForInput);
    }
    LLOGV(snapshot.sequence, "updating visibility %s %s", visible ? "true" : "false",
          snapshot.getDebugString().c_str());
}
@@ -1260,6 +1265,10 @@ void LayerSnapshotBuilder::forEachInputSnapshot(const ConstVisitor& visitor) con
    for (int i = mNumInterestingSnapshots - 1; i >= 0; i--) {
        LayerSnapshot& snapshot = *mSnapshots[(size_t)i];
        if (!snapshot.hasInputInfo()) continue;
        if (FlagManager::getInstance().skip_invisible_windows_in_input() &&
            snapshot.inputInfo.inputConfig.test(gui::WindowInfo::InputConfig::NOT_VISIBLE)) {
            continue;
        }
        visitor(snapshot);
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -159,6 +159,7 @@ void FlagManager::dump(std::string& result) const {
    DUMP_READ_ONLY_FLAG(display_config_error_hal);
    DUMP_READ_ONLY_FLAG(connected_display_hdr);
    DUMP_READ_ONLY_FLAG(deprecate_frame_tracker);
    DUMP_READ_ONLY_FLAG(skip_invisible_windows_in_input);

#undef DUMP_READ_ONLY_FLAG
#undef DUMP_SERVER_FLAG
@@ -266,6 +267,7 @@ FLAG_MANAGER_READ_ONLY_FLAG(true_hdr_screenshots, "debug.sf.true_hdr_screenshots
FLAG_MANAGER_READ_ONLY_FLAG(display_config_error_hal, "");
FLAG_MANAGER_READ_ONLY_FLAG(connected_display_hdr, "");
FLAG_MANAGER_READ_ONLY_FLAG(deprecate_frame_tracker, "");
FLAG_MANAGER_READ_ONLY_FLAG(skip_invisible_windows_in_input, "");

/// Trunk stable server flags ///
FLAG_MANAGER_SERVER_FLAG(refresh_rate_overlay_on_external_display, "")
+1 −0
Original line number Diff line number Diff line
@@ -97,6 +97,7 @@ public:
    bool display_config_error_hal() const;
    bool connected_display_hdr() const;
    bool deprecate_frame_tracker() const;
    bool skip_invisible_windows_in_input() const;

protected:
    // overridden for unit tests
+11 −0
Original line number Diff line number Diff line
@@ -195,6 +195,17 @@ flag {
  }
 } # single_hop_screenshot

flag {
  name: "skip_invisible_windows_in_input"
  namespace: "window_surfaces"
  description: "Only send visible windows to input list"
  bug: "305254099"
  is_fixed_read_only: true
  metadata {
    purpose: PURPOSE_BUGFIX
  }
 } # skip_invisible_windows_in_input

flag {
  name: "true_hdr_screenshots"
  namespace: "core_graphics"
+36 −0
Original line number Diff line number Diff line
@@ -1551,6 +1551,9 @@ TEST_F(LayerSnapshotTest, propagateDropInputMode) {
}

TEST_F(LayerSnapshotTest, NonVisibleLayerWithInput) {
    SET_FLAG_FOR_TEST(com::android::graphics::surfaceflinger::flags::
                              skip_invisible_windows_in_input,
                      false);
    LayerHierarchyTestBase::createRootLayer(3);
    setColor(3, {-1._hf, -1._hf, -1._hf});
    UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
@@ -1576,6 +1579,39 @@ TEST_F(LayerSnapshotTest, NonVisibleLayerWithInput) {
    EXPECT_TRUE(foundInputLayer);
}

TEST_F(LayerSnapshotTest, NonVisibleLayerWithInputShouldNotBeIncluded) {
    SET_FLAG_FOR_TEST(com::android::graphics::surfaceflinger::flags::
                              skip_invisible_windows_in_input,
                      true);
    LayerHierarchyTestBase::createRootLayer(3);
    setColor(3, {-1._hf, -1._hf, -1._hf});
    UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);

    std::vector<TransactionState> transactions;
    transactions.emplace_back();
    transactions.back().states.push_back({});
    transactions.back().states.front().state.what = layer_state_t::eInputInfoChanged;
    transactions.back().states.front().layerId = 3;
    transactions.back().states.front().state.windowInfoHandle = sp<gui::WindowInfoHandle>::make();
    auto inputInfo = transactions.back().states.front().state.windowInfoHandle->editInfo();
    inputInfo->token = sp<BBinder>::make();
    hideLayer(3);
    mLifecycleManager.applyTransactions(transactions);

    update(mSnapshotBuilder);

    bool foundInputLayer = false;
    mSnapshotBuilder.forEachInputSnapshot([&](const frontend::LayerSnapshot& snapshot) {
        if (snapshot.uniqueSequence == 3) {
            EXPECT_TRUE(
                    snapshot.inputInfo.inputConfig.test(gui::WindowInfo::InputConfig::NOT_VISIBLE));
            EXPECT_FALSE(snapshot.isVisible);
            foundInputLayer = true;
        }
    });
    EXPECT_FALSE(foundInputLayer);
}

TEST_F(LayerSnapshotTest, ForEachSnapshotsWithPredicate) {
    std::vector<uint32_t> visitedUniqueSequences;
    mSnapshotBuilder.forEachSnapshot(