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

Commit ac977e6d authored by Adithya Srinivasan's avatar Adithya Srinivasan
Browse files

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
parent f1804968
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -26,4 +26,5 @@ enum LayerMetadataKey {
    METADATA_ACCESSIBILITY_ID = 5,
    METADATA_ACCESSIBILITY_ID = 5,
    METADATA_OWNER_PID = 6,
    METADATA_OWNER_PID = 6,
    METADATA_DEQUEUE_TIME = 7,
    METADATA_DEQUEUE_TIME = 7,
    METADATA_GAME_MODE = 8,
}
}
+2 −0
Original line number Original line Diff line number Diff line
@@ -136,6 +136,8 @@ std::string LayerMetadata::itemToString(uint32_t key, const char* separator) con
            return StringPrintf("ownerPID%s%d", separator, getInt32(key, 0));
            return StringPrintf("ownerPID%s%d", separator, getInt32(key, 0));
        case view::LayerMetadataKey::METADATA_DEQUEUE_TIME:
        case view::LayerMetadataKey::METADATA_DEQUEUE_TIME:
            return StringPrintf("dequeueTime%s%" PRId64, separator, *getInt64(key));
            return StringPrintf("dequeueTime%s%" PRId64, separator, *getInt64(key));
        case view::LayerMetadataKey::METADATA_GAME_MODE:
            return StringPrintf("gameMode%s%d", separator, getInt32(key, 0));
        default:
        default:
            return StringPrintf("%d%s%dbytes", key, separator,
            return StringPrintf("%d%s%dbytes", key, separator,
                                static_cast<int>(mMap.at(key).size()));
                                static_cast<int>(mMap.at(key).size()));
+2 −1
Original line number Original line Diff line number Diff line
@@ -29,7 +29,8 @@ enum {
    METADATA_MOUSE_CURSOR = 4,
    METADATA_MOUSE_CURSOR = 4,
    METADATA_ACCESSIBILITY_ID = 5,
    METADATA_ACCESSIBILITY_ID = 5,
    METADATA_OWNER_PID = 6,
    METADATA_OWNER_PID = 6,
    METADATA_DEQUEUE_TIME = 7
    METADATA_DEQUEUE_TIME = 7,
    METADATA_GAME_MODE = 8
};
};


struct LayerMetadata : public Parcelable {
struct LayerMetadata : public Parcelable {
+14 −0
Original line number Original line Diff line number Diff line
@@ -1651,12 +1651,25 @@ size_t Layer::getChildrenCount() const {
    return count;
    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<Layer>& child : mCurrentChildren) {
        child->setGameModeForTree(gameMode);
    }
}

void Layer::addChild(const sp<Layer>& layer) {
void Layer::addChild(const sp<Layer>& layer) {
    mChildrenChanged = true;
    mChildrenChanged = true;
    setTransactionFlags(eTransactionNeeded);
    setTransactionFlags(eTransactionNeeded);


    mCurrentChildren.add(layer);
    mCurrentChildren.add(layer);
    layer->setParent(this);
    layer->setParent(this);
    layer->setGameModeForTree(mGameMode);
    updateTreeHasFrameRateVote();
    updateTreeHasFrameRateVote();
}
}


@@ -1668,6 +1681,7 @@ ssize_t Layer::removeChild(const sp<Layer>& layer) {
    const auto removeResult = mCurrentChildren.remove(layer);
    const auto removeResult = mCurrentChildren.remove(layer);


    updateTreeHasFrameRateVote();
    updateTreeHasFrameRateVote();
    layer->setGameModeForTree(0);
    layer->updateTreeHasFrameRateVote();
    layer->updateTreeHasFrameRateVote();


    return removeResult;
    return removeResult;
+11 −0
Original line number Original line Diff line number Diff line
@@ -847,6 +847,13 @@ public:
     */
     */
    bool hasInputInfo() const;
    bool hasInputInfo() const;


    // Sets the parent's gameMode for this layer and all its children. Parent's gameMode is applied
    // only to layers that do not have the GAME_MODE_METADATA set by WMShell. Any layer(along with
    // its children) that has the metadata set will use the gameMode from the metadata.
    void setGameModeForTree(int parentGameMode);
    void setGameMode(int gameMode) { mGameMode = gameMode; };
    int getGameMode() const { return mGameMode; }

    virtual uid_t getOwnerUid() const { return mOwnerUid; }
    virtual uid_t getOwnerUid() const { return mOwnerUid; }


    pid_t getOwnerPid() { return mOwnerPid; }
    pid_t getOwnerPid() { return mOwnerPid; }
@@ -1089,6 +1096,10 @@ private:
    // shadow radius is the set shadow radius, otherwise its the parent's shadow radius.
    // shadow radius is the set shadow radius, otherwise its the parent's shadow radius.
    float mEffectiveShadowRadius = 0.f;
    float mEffectiveShadowRadius = 0.f;


    // Game mode for the layer. Set by WindowManagerShell, game mode is used in
    // metrics(SurfaceFlingerStats).
    int mGameMode = 0;

    // A list of regions on this layer that should have blurs.
    // A list of regions on this layer that should have blurs.
    const std::vector<BlurRegion> getBlurRegions() const;
    const std::vector<BlurRegion> getBlurRegions() const;
};
};
Loading