From ac977e6de0cdebddebc2db0efd8cbec94c2bc996 Mon Sep 17 00:00:00 2001 From: Adithya Srinivasan Date: Fri, 21 May 2021 22:50:56 +0000 Subject: SF - plumbing game mode for metrics (Part 1) This change adds a game mode in the Layer metadata that gets updated every time a game app comes to the foreground. The gameMode is then set on the Layer based on the metadata and reparenting. The game mode will then be updated in TimeStats as a dimension (Part 2, in a separate CL later). Bug: 186025682 Test: libsurfaceflinger_unittest:GameModeTest Change-Id: I09deffc01d1b318cc08d0475611289dec055c190 --- services/surfaceflinger/Layer.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'services/surfaceflinger/Layer.cpp') diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp index a7c870483b..d78a8223c4 100644 --- a/services/surfaceflinger/Layer.cpp +++ b/services/surfaceflinger/Layer.cpp @@ -1651,12 +1651,25 @@ size_t Layer::getChildrenCount() const { return count; } +void Layer::setGameModeForTree(int parentGameMode) { + int gameMode = parentGameMode; + auto& currentState = getCurrentState(); + if (currentState.metadata.has(METADATA_GAME_MODE)) { + gameMode = currentState.metadata.getInt32(METADATA_GAME_MODE, 0); + } + setGameMode(gameMode); + for (const sp& child : mCurrentChildren) { + child->setGameModeForTree(gameMode); + } +} + void Layer::addChild(const sp& layer) { mChildrenChanged = true; setTransactionFlags(eTransactionNeeded); mCurrentChildren.add(layer); layer->setParent(this); + layer->setGameModeForTree(mGameMode); updateTreeHasFrameRateVote(); } @@ -1668,6 +1681,7 @@ ssize_t Layer::removeChild(const sp& layer) { const auto removeResult = mCurrentChildren.remove(layer); updateTreeHasFrameRateVote(); + layer->setGameModeForTree(0); layer->updateTreeHasFrameRateVote(); return removeResult; -- cgit v1.2.3-59-g8ed1b