Skip to content

Commit a60def9

Browse files
Wenhui YangAndroid (Google) Code Review
authored andcommitted
Merge "Skip invisible windows in input list" into main
2 parents ff7a0f4 + b09293f commit a60def9

5 files changed

Lines changed: 73 additions & 14 deletions

File tree

services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -261,20 +261,25 @@ void updateVisibility(LayerSnapshot& snapshot, bool visible) {
261261
}
262262
snapshot.isVisible = visible;
263263

264-
// TODO(b/238781169) we are ignoring this compat for now, since we will have
265-
// to remove any optimization based on visibility.
266-
267-
// For compatibility reasons we let layers which can receive input
268-
// receive input before they have actually submitted a buffer. Because
269-
// of this we use canReceiveInput instead of isVisible to check the
270-
// policy-visibility, ignoring the buffer state. However for layers with
271-
// hasInputInfo()==false we can use the real visibility state.
272-
// We are just using these layers for occlusion detection in
273-
// InputDispatcher, and obviously if they aren't visible they can't occlude
274-
// anything.
275-
const bool visibleForInput =
276-
snapshot.hasInputInfo() ? snapshot.canReceiveInput() : snapshot.isVisible;
277-
snapshot.inputInfo.setInputConfig(gui::WindowInfo::InputConfig::NOT_VISIBLE, !visibleForInput);
264+
if (FlagManager::getInstance().skip_invisible_windows_in_input()) {
265+
snapshot.inputInfo.setInputConfig(gui::WindowInfo::InputConfig::NOT_VISIBLE, !visible);
266+
} else {
267+
// TODO(b/238781169) we are ignoring this compat for now, since we will have
268+
// to remove any optimization based on visibility.
269+
270+
// For compatibility reasons we let layers which can receive input
271+
// receive input before they have actually submitted a buffer. Because
272+
// of this we use canReceiveInput instead of isVisible to check the
273+
// policy-visibility, ignoring the buffer state. However for layers with
274+
// hasInputInfo()==false we can use the real visibility state.
275+
// We are just using these layers for occlusion detection in
276+
// InputDispatcher, and obviously if they aren't visible they can't occlude
277+
// anything.
278+
const bool visibleForInput =
279+
snapshot.hasInputInfo() ? snapshot.canReceiveInput() : snapshot.isVisible;
280+
snapshot.inputInfo.setInputConfig(gui::WindowInfo::InputConfig::NOT_VISIBLE,
281+
!visibleForInput);
282+
}
278283
LLOGV(snapshot.sequence, "updating visibility %s %s", visible ? "true" : "false",
279284
snapshot.getDebugString().c_str());
280285
}
@@ -1260,6 +1265,10 @@ void LayerSnapshotBuilder::forEachInputSnapshot(const ConstVisitor& visitor) con
12601265
for (int i = mNumInterestingSnapshots - 1; i >= 0; i--) {
12611266
LayerSnapshot& snapshot = *mSnapshots[(size_t)i];
12621267
if (!snapshot.hasInputInfo()) continue;
1268+
if (FlagManager::getInstance().skip_invisible_windows_in_input() &&
1269+
snapshot.inputInfo.inputConfig.test(gui::WindowInfo::InputConfig::NOT_VISIBLE)) {
1270+
continue;
1271+
}
12631272
visitor(snapshot);
12641273
}
12651274
}

services/surfaceflinger/common/FlagManager.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ void FlagManager::dump(std::string& result) const {
159159
DUMP_READ_ONLY_FLAG(display_config_error_hal);
160160
DUMP_READ_ONLY_FLAG(connected_display_hdr);
161161
DUMP_READ_ONLY_FLAG(deprecate_frame_tracker);
162+
DUMP_READ_ONLY_FLAG(skip_invisible_windows_in_input);
162163

163164
#undef DUMP_READ_ONLY_FLAG
164165
#undef DUMP_SERVER_FLAG
@@ -266,6 +267,7 @@ FLAG_MANAGER_READ_ONLY_FLAG(true_hdr_screenshots, "debug.sf.true_hdr_screenshots
266267
FLAG_MANAGER_READ_ONLY_FLAG(display_config_error_hal, "");
267268
FLAG_MANAGER_READ_ONLY_FLAG(connected_display_hdr, "");
268269
FLAG_MANAGER_READ_ONLY_FLAG(deprecate_frame_tracker, "");
270+
FLAG_MANAGER_READ_ONLY_FLAG(skip_invisible_windows_in_input, "");
269271

270272
/// Trunk stable server flags ///
271273
FLAG_MANAGER_SERVER_FLAG(refresh_rate_overlay_on_external_display, "")

services/surfaceflinger/common/include/common/FlagManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class FlagManager {
9797
bool display_config_error_hal() const;
9898
bool connected_display_hdr() const;
9999
bool deprecate_frame_tracker() const;
100+
bool skip_invisible_windows_in_input() const;
100101

101102
protected:
102103
// overridden for unit tests

services/surfaceflinger/surfaceflinger_flags_new.aconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,17 @@ flag {
195195
}
196196
} # single_hop_screenshot
197197

198+
flag {
199+
name: "skip_invisible_windows_in_input"
200+
namespace: "window_surfaces"
201+
description: "Only send visible windows to input list"
202+
bug: "305254099"
203+
is_fixed_read_only: true
204+
metadata {
205+
purpose: PURPOSE_BUGFIX
206+
}
207+
} # skip_invisible_windows_in_input
208+
198209
flag {
199210
name: "true_hdr_screenshots"
200211
namespace: "core_graphics"

services/surfaceflinger/tests/unittests/LayerSnapshotTest.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,6 +1550,9 @@ TEST_F(LayerSnapshotTest, propagateDropInputMode) {
15501550
}
15511551

15521552
TEST_F(LayerSnapshotTest, NonVisibleLayerWithInput) {
1553+
SET_FLAG_FOR_TEST(com::android::graphics::surfaceflinger::flags::
1554+
skip_invisible_windows_in_input,
1555+
false);
15531556
LayerHierarchyTestBase::createRootLayer(3);
15541557
setColor(3, {-1._hf, -1._hf, -1._hf});
15551558
UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
@@ -1575,6 +1578,39 @@ TEST_F(LayerSnapshotTest, NonVisibleLayerWithInput) {
15751578
EXPECT_TRUE(foundInputLayer);
15761579
}
15771580

1581+
TEST_F(LayerSnapshotTest, NonVisibleLayerWithInputShouldNotBeIncluded) {
1582+
SET_FLAG_FOR_TEST(com::android::graphics::surfaceflinger::flags::
1583+
skip_invisible_windows_in_input,
1584+
true);
1585+
LayerHierarchyTestBase::createRootLayer(3);
1586+
setColor(3, {-1._hf, -1._hf, -1._hf});
1587+
UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1588+
1589+
std::vector<TransactionState> transactions;
1590+
transactions.emplace_back();
1591+
transactions.back().states.push_back({});
1592+
transactions.back().states.front().state.what = layer_state_t::eInputInfoChanged;
1593+
transactions.back().states.front().layerId = 3;
1594+
transactions.back().states.front().state.windowInfoHandle = sp<gui::WindowInfoHandle>::make();
1595+
auto inputInfo = transactions.back().states.front().state.windowInfoHandle->editInfo();
1596+
inputInfo->token = sp<BBinder>::make();
1597+
hideLayer(3);
1598+
mLifecycleManager.applyTransactions(transactions);
1599+
1600+
update(mSnapshotBuilder);
1601+
1602+
bool foundInputLayer = false;
1603+
mSnapshotBuilder.forEachInputSnapshot([&](const frontend::LayerSnapshot& snapshot) {
1604+
if (snapshot.uniqueSequence == 3) {
1605+
EXPECT_TRUE(
1606+
snapshot.inputInfo.inputConfig.test(gui::WindowInfo::InputConfig::NOT_VISIBLE));
1607+
EXPECT_FALSE(snapshot.isVisible);
1608+
foundInputLayer = true;
1609+
}
1610+
});
1611+
EXPECT_FALSE(foundInputLayer);
1612+
}
1613+
15781614
TEST_F(LayerSnapshotTest, ForEachSnapshotsWithPredicate) {
15791615
std::vector<uint32_t> visitedUniqueSequences;
15801616
mSnapshotBuilder.forEachSnapshot(

0 commit comments

Comments
 (0)