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

Commit 19949581 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Use new traversal function when order doesn't matter"

parents 09384dcb 844fa677
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -1804,6 +1804,15 @@ void Layer::traverseInReverseZOrder(LayerVector::StateSet stateSet,
    }
}

void Layer::traverse(LayerVector::StateSet state, const LayerVector::Visitor& visitor) {
    visitor(this);
    const LayerVector& children =
            state == LayerVector::StateSet::Drawing ? mDrawingChildren : mCurrentChildren;
    for (const sp<Layer>& child : children) {
        child->traverse(state, visitor);
    }
}

LayerVector Layer::makeChildrenTraversalList(LayerVector::StateSet stateSet,
                                             const std::vector<Layer*>& layersInTree) {
    LOG_ALWAYS_FATAL_IF(stateSet == LayerVector::StateSet::Invalid,
+9 −0
Original line number Diff line number Diff line
@@ -679,6 +679,15 @@ public:

    renderengine::ShadowSettings getShadowSettings(const Rect& viewport) const;

    /**
     * Traverse this layer and it's hierarchy of children directly. Unlike traverseInZOrder
     * which will not emit children who have relativeZOrder to another layer, this method
     * just directly emits all children. It also emits them in no particular order.
     * So this method is not suitable for graphical operations, as it doesn't represent
     * the scene state, but it's also more efficient than traverseInZOrder and so useful for
     * book-keeping.
     */
    void traverse(LayerVector::StateSet stateSet, const LayerVector::Visitor& visitor);
    void traverseInReverseZOrder(LayerVector::StateSet stateSet,
                                 const LayerVector::Visitor& visitor);
    void traverseInZOrder(LayerVector::StateSet stateSet, const LayerVector::Visitor& visitor);
+8 −0
Original line number Diff line number Diff line
@@ -86,6 +86,14 @@ void LayerVector::traverseInReverseZOrder(StateSet stateSet, const Visitor& visi
        layer->traverseInReverseZOrder(stateSet, visitor);
     }
}

void LayerVector::traverse(const Visitor& visitor) const {
    for (auto i = static_cast<int64_t>(size()) - 1; i >= 0; i--) {
        const auto& layer = (*this)[i];
        layer->traverse(mStateSet, visitor);
    }
}

} // namespace android

// TODO(b/129481165): remove the #pragma below and fix conversion issues
+1 −1
Original line number Diff line number Diff line
@@ -50,7 +50,7 @@ public:
    using Visitor = std::function<void(Layer*)>;
    void traverseInReverseZOrder(StateSet stateSet, const Visitor& visitor) const;
    void traverseInZOrder(StateSet stateSet, const Visitor& visitor) const;

    void traverse(const Visitor& visitor) const;
private:
    const StateSet mStateSet;
};
+18 −14
Original line number Diff line number Diff line
@@ -2059,7 +2059,7 @@ void SurfaceFlinger::postComposition()
        compositorTiming = getBE().mCompositorTiming;
    }

    mDrawingState.traverseInZOrder([&](Layer* layer) {
    mDrawingState.traverse([&](Layer* layer) {
        bool frameLatched = layer->onPostComposition(displayDevice, glCompositionDoneFenceTime,
                                                     presentFenceTime, compositorTiming);
        if (frameLatched) {
@@ -2496,7 +2496,7 @@ void SurfaceFlinger::handleTransactionLocked(uint32_t transactionFlags)
    const nsecs_t expectedPresentTime = mExpectedPresentTime.load();

    // Notify all layers of available frames
    mCurrentState.traverseInZOrder([expectedPresentTime](Layer* layer) {
    mCurrentState.traverse([expectedPresentTime](Layer* layer) {
        layer->notifyAvailableFrames(expectedPresentTime);
    });

@@ -2506,7 +2506,7 @@ void SurfaceFlinger::handleTransactionLocked(uint32_t transactionFlags)
     */

    if ((transactionFlags & eTraversalNeeded) || mTraversalNeededMainThread) {
        mCurrentState.traverseInZOrder([&](Layer* layer) {
        mCurrentState.traverse([&](Layer* layer) {
            uint32_t trFlags = layer->getTransactionFlags(eTransactionNeeded);
            if (!trFlags) return;

@@ -2553,7 +2553,7 @@ void SurfaceFlinger::handleTransactionLocked(uint32_t transactionFlags)
        sp<const DisplayDevice> hintDisplay;
        uint32_t currentlayerStack = 0;
        bool first = true;
        mCurrentState.traverseInZOrder([&](Layer* layer) {
        mCurrentState.traverse([&](Layer* layer) {
            // NOTE: we rely on the fact that layers are sorted by
            // layerStack first (so we don't have to traverse the list
            // of displays for every layer).
@@ -2781,7 +2781,7 @@ void SurfaceFlinger::commitTransactionLocked() {
    // clear the "changed" flags in current state
    mCurrentState.colorMatrixChanged = false;

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

        // If the layer can be reached when traversing mDrawingState, then the layer is no
@@ -2792,7 +2792,7 @@ void SurfaceFlinger::commitTransactionLocked() {
    });

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

void SurfaceFlinger::withTracingLock(std::function<void()> lockedOperation) {
@@ -2817,7 +2817,7 @@ void SurfaceFlinger::withTracingLock(std::function<void()> lockedOperation) {

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

@@ -2858,7 +2858,7 @@ bool SurfaceFlinger::handlePageFlip()
    // 3.) Layer 1 is latched.
    // Display is now waiting on Layer 1's frame, which is behind layer 0's
    // second frame. But layer 0's second frame could be waiting on display.
    mDrawingState.traverseInZOrder([&](Layer* layer) {
    mDrawingState.traverse([&](Layer* layer) {
        if (layer->hasReadyFrame()) {
            frameQueued = true;
            if (layer->shouldPresentNow(expectedPresentTime)) {
@@ -2876,7 +2876,7 @@ bool SurfaceFlinger::handlePageFlip()
    // be shown on screen. Therefore, we need to latch and release buffers of offscreen
    // layers to ensure dequeueBuffer doesn't block indefinitely.
    for (Layer* offscreenLayer : mOffscreenLayers) {
        offscreenLayer->traverseInZOrder(LayerVector::StateSet::Drawing,
        offscreenLayer->traverse(LayerVector::StateSet::Drawing,
                                         [&](Layer* l) { l->latchAndReleaseBuffer(); });
    }

@@ -2911,7 +2911,7 @@ bool SurfaceFlinger::handlePageFlip()
        mBootStage = BootStage::BOOTANIMATION;
    }

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

    // Only continue with the refresh if there is actually new work to do
    return !mLayersWithQueuedFrames.empty() && newDataLatched;
@@ -3733,7 +3733,7 @@ std::string SurfaceFlinger::getUniqueLayerName(const char* name) {
    bool matchFound = true;
    while (matchFound) {
        matchFound = false;
        mCurrentState.traverseInZOrder([&](Layer* layer) {
        mCurrentState.traverse([&](Layer* layer) {
            if (layer->getName() == uniqueName) {
                matchFound = true;
                uniqueName = base::StringPrintf("%s#%u", name, ++dupeCounter);
@@ -4104,7 +4104,7 @@ void SurfaceFlinger::clearStatsLocked(const DumpArgs& args, std::string&) {
    const bool clearAll = args.size() < 2;
    const auto name = clearAll ? String8() : String8(args[1]);

    mCurrentState.traverseInZOrder([&](Layer* layer) {
    mCurrentState.traverse([&](Layer* layer) {
        if (clearAll || layer->getName() == name.string()) {
            layer->clearFrameStats();
        }
@@ -4120,7 +4120,7 @@ void SurfaceFlinger::dumpTimeStats(const DumpArgs& args, bool asProto, std::stri
// This should only be called from the main thread.  Otherwise it would need
// the lock and should use mCurrentState rather than mDrawingState.
void SurfaceFlinger::logFrameStats() {
    mDrawingState.traverseInZOrder([&](Layer* layer) {
    mDrawingState.traverse([&](Layer* layer) {
        layer->logFrameStats();
    });

@@ -4355,7 +4355,7 @@ void SurfaceFlinger::dumpOffscreenLayers(std::string& result) {
    result.append("Offscreen Layers:\n");
    postMessageSync(new LambdaMessage([&]() {
        for (Layer* offscreenLayer : mOffscreenLayers) {
            offscreenLayer->traverseInZOrder(LayerVector::StateSet::Drawing, [&](Layer* layer) {
            offscreenLayer->traverse(LayerVector::StateSet::Drawing, [&](Layer* layer) {
                layer->dumpCallingUidPid(result);
            });
        }
@@ -5588,6 +5588,10 @@ void SurfaceFlinger::setInputWindowsFinished() {

// ---------------------------------------------------------------------------

void SurfaceFlinger::State::traverse(const LayerVector::Visitor& visitor) const {
    layersSortedByZ.traverse(visitor);
}

void SurfaceFlinger::State::traverseInZOrder(const LayerVector::Visitor& visitor) const {
    layersSortedByZ.traverseInZOrder(stateSet, visitor);
}
Loading