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

Commit 38c6856b authored by Chavi Weingarten's avatar Chavi Weingarten Committed by Android (Google) Code Review
Browse files

Merge "Ensure currentState is copied to drawingState for offscreen layers" into qt-dev

parents bf48d1ab 74d90ad5
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -130,7 +130,7 @@ Layer::~Layer() {
    }

    mFrameTracker.logAndResetStats(mName);
    mFlinger->onLayerDestroyed();
    mFlinger->onLayerDestroyed(this);
}

// ---------------------------------------------------------------------------
+30 −1
Original line number Diff line number Diff line
@@ -2944,6 +2944,13 @@ void SurfaceFlinger::commitTransaction()
            if (l->isRemovedFromCurrentState()) {
                latchAndReleaseBuffer(l);
            }

            // If the layer has been removed and has no parent, then it will not be reachable
            // when traversing layers on screen. Add the layer to the offscreenLayers set to
            // ensure we can copy its current to drawing state.
            if (!l->getParent()) {
                mOffscreenLayers.emplace(l.get());
            }
        }
        mLayersPendingRemoval.clear();
    }
@@ -2957,7 +2964,17 @@ void SurfaceFlinger::commitTransaction()
        // clear the "changed" flags in current state
        mCurrentState.colorMatrixChanged = false;

        mDrawingState.traverseInZOrder([](Layer* layer) { layer->commitChildList(); });
        mDrawingState.traverseInZOrder([&](Layer* layer) {
            layer->commitChildList();

            // 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();
    });

    mTransactionPending = false;
@@ -2985,6 +3002,18 @@ void SurfaceFlinger::withTracingLock(std::function<void()> lockedOperation) {
    }
}

void SurfaceFlinger::commitOffscreenLayers() {
    for (Layer* offscreenLayer : mOffscreenLayers) {
        offscreenLayer->traverseInZOrder(LayerVector::StateSet::Drawing, [](Layer* layer) {
            uint32_t trFlags = layer->getTransactionFlags(eTransactionNeeded);
            if (!trFlags) return;

            layer->doTransaction(0);
            layer->commitChildList();
        });
    }
}

void SurfaceFlinger::computeVisibleRegions(const sp<const DisplayDevice>& displayDevice,
                                           Region& outDirtyRegion, Region& outOpaqueRegion) {
    ATRACE_CALL();
+11 −1
Original line number Diff line number Diff line
@@ -308,7 +308,10 @@ public:
        const sp<IGraphicBufferProducer>& bufferProducer) const;

    inline void onLayerCreated() { mNumLayers++; }
    inline void onLayerDestroyed() { mNumLayers--; }
    inline void onLayerDestroyed(Layer* layer) {
        mNumLayers--;
        mOffscreenLayers.erase(layer);
    }

    TransactionCompletedThread& getTransactionCompletedThread() {
        return mTransactionCompletedThread;
@@ -563,6 +566,7 @@ private:
    uint32_t setTransactionFlags(uint32_t flags, Scheduler::TransactionStart transactionStart);
    void latchAndReleaseBuffer(const sp<Layer>& layer);
    void commitTransaction() REQUIRES(mStateLock);
    void commitOffscreenLayers();
    bool containsAnyInvalidClientState(const Vector<ComposerState>& states);
    bool transactionIsReadyToBeApplied(int64_t desiredPresentTime,
                                       const Vector<ComposerState>& states);
@@ -1152,6 +1156,12 @@ private:

    // Flag used to set override allowed display configs from backdoor
    bool mDebugDisplayConfigSetByBackdoor = false;

    // A set of layers that have no parent so they are not drawn on screen.
    // Should only be accessed by the main thread.
    // The Layer pointer is removed from the set when the destructor is called so there shouldn't
    // be any issues with a raw pointer referencing an invalid object.
    std::unordered_set<Layer*> mOffscreenLayers;
};

} // namespace android