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

Commit 867be37f authored by Robert Carr's avatar Robert Carr Committed by Rob Carr
Browse files

Optimize offscreen layer management

Now that we manage reparenting on the main thread, we can directly
manipulate the offscreen layers list rather than updating it
in a later traversal.

Bug: 186200583
Test: Existing tests pass
Change-Id: I9b101544c272b60d2d93d09b3cc6074098181cf3
parent e89521f7
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -254,6 +254,7 @@ void Layer::addToCurrentState() {
    if (mRemovedFromDrawingState) {
        mRemovedFromDrawingState = false;
        mFlinger->mScheduler->registerLayer(this);
        mFlinger->removeFromOffscreenLayers(this);
    }

    for (const auto& child : mCurrentChildren) {
+6 −13
Original line number Diff line number Diff line
@@ -3253,17 +3253,6 @@ void SurfaceFlinger::commitTransactionLocked() {
        }
    }

    // TODO(b/163019109): See if this traversal is needed at all...
    if (!mOffscreenLayers.empty()) {
        mDrawingState.traverse([&](Layer* layer) {
            // If the layer can be reached when traversing mDrawingState, then the layer is no
            // longer offscreen. Remove the layer from the offscreenLayer set.
            if (mOffscreenLayers.count(layer)) {
                mOffscreenLayers.erase(layer);
            }
        });
    }

    commitOffscreenLayers();
    mDrawingState.traverse([&](Layer* layer) { layer->updateMirrorInfo(); });
}
@@ -6622,7 +6611,7 @@ void SurfaceFlinger::onLayerFirstRef(Layer* layer) {

void SurfaceFlinger::onLayerDestroyed(Layer* layer) {
    mNumLayers--;
    removeFromOffscreenLayers(layer);
    removeHierarchyFromOffscreenLayers(layer);
    if (!layer->isRemovedFromCurrentState()) {
        mScheduler->deregisterLayer(layer);
    }
@@ -6635,13 +6624,17 @@ void SurfaceFlinger::onLayerDestroyed(Layer* layer) {
// from dangling children layers such that they are not reachable from the
// Drawing state nor the offscreen layer list
// See b/141111965
void SurfaceFlinger::removeFromOffscreenLayers(Layer* layer) {
void SurfaceFlinger::removeHierarchyFromOffscreenLayers(Layer* layer) {
    for (auto& child : layer->getCurrentChildren()) {
        mOffscreenLayers.emplace(child.get());
    }
    mOffscreenLayers.erase(layer);
}

void SurfaceFlinger::removeFromOffscreenLayers(Layer* layer) {
    mOffscreenLayers.erase(layer);
}

status_t SurfaceFlinger::setGlobalShadowSettings(const half4& ambientColor, const half4& spotColor,
                                                 float lightPosY, float lightPosZ,
                                                 float lightRadius) {
+1 −0
Original line number Diff line number Diff line
@@ -313,6 +313,7 @@ public:
    void onLayerFirstRef(Layer*);
    void onLayerDestroyed(Layer*);

    void removeHierarchyFromOffscreenLayers(Layer* layer);
    void removeFromOffscreenLayers(Layer* layer);

    TransactionCallbackInvoker& getTransactionCallbackInvoker() {