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

Commit d8ca4fc8 authored by Vishnu Nair's avatar Vishnu Nair Committed by Android (Google) Code Review
Browse files

Merge changes I24cdcd3a,I4132e7a7 into main

* changes:
  Remove legacy layer mirroring
  Remove legacy layer hierarchy
parents 406e859b 620fefda
Loading
Loading
Loading
Loading
+1 −16
Original line number Diff line number Diff line
@@ -22,28 +22,13 @@
#include "RequestedLayerState.h"
#include "TransactionState.h"

namespace android {
struct LayerCreatedState {
    LayerCreatedState(const wp<Layer>& layer, const wp<Layer>& parent, bool addToRoot)
          : layer(layer), initialParent(parent), addToRoot(addToRoot) {}
    wp<Layer> layer;
    // Indicates the initial parent of the created layer, only used for creating layer in
    // SurfaceFlinger. If nullptr, it may add the created layer into the current root layers.
    wp<Layer> initialParent;
    // Indicates whether the layer getting created should be added at root if there's no parent
    // and has permission ACCESS_SURFACE_FLINGER. If set to false and no parent, the layer will
    // be added offscreen.
    bool addToRoot;
};
} // namespace android

namespace android::surfaceflinger::frontend {

// Atomic set of changes affecting layer state. These changes are queued in binder threads and
// applied every vsync.
struct Update {
    std::vector<TransactionState> transactions;
    std::vector<LayerCreatedState> layerCreatedStates;
    std::vector<sp<Layer>> legacyLayers;
    std::vector<std::unique_ptr<frontend::RequestedLayerState>> newLayers;
    std::vector<LayerCreationArgs> layerCreationArgs;
    std::vector<std::pair<uint32_t, std::string /* debugName */>> destroyedHandles;
+0 −585

File changed.

Preview size limit exceeded, changes collapsed.

+0 −121
Original line number Diff line number Diff line
@@ -250,8 +250,6 @@ public:
    // true if this layer is visible, false otherwise
    virtual bool isVisible() const;

    virtual sp<Layer> createClone();

    // Set a 2x2 transformation matrix on the layer. This transform
    // will be applied after parent transforms, but before any final
    // producer specified transform.
@@ -297,7 +295,6 @@ public:

    virtual bool setMetadata(const LayerMetadata& data);
    virtual void setChildrenDrawingParent(const sp<Layer>&);
    virtual bool reparent(const sp<IBinder>& newParentHandle) REQUIRES(mFlinger->mStateLock);
    virtual bool setColorTransform(const mat4& matrix);
    virtual mat4 getColorTransform() const;
    virtual bool hasColorTransform() const;
@@ -326,8 +323,6 @@ public:
                           gui::GameMode gameMode);
    bool setTransactionCompletedListeners(const std::vector<sp<CallbackHandle>>& /*handles*/,
                                          bool willPresent);
    virtual bool setBackgroundColor(const half3& color, float alpha, ui::Dataspace dataspace)
            REQUIRES(mFlinger->mStateLock);
    virtual bool setColorSpaceAgnostic(const bool agnostic);
    virtual bool setDimmingEnabled(const bool dimmingEnabled);
    virtual bool setFixedTransformHint(ui::Transform::RotationFlags fixedTransformHint);
@@ -426,7 +421,6 @@ public:

    // from graphics API
    static ui::Dataspace translateDataspace(ui::Dataspace dataspace);
    void updateCloneBufferInfo();
    uint64_t mPreviousFrameNumber = 0;

    void onCompositionPresented(const DisplayDevice*,
@@ -638,8 +632,6 @@ public:
        return {getLayerStack(), isInternalDisplayOverlay()};
    }

    bool isRemovedFromCurrentState() const;

    perfetto::protos::LayerProto* writeToProto(perfetto::protos::LayersProto& layersProto,
                                               uint32_t traceFlags);
    void writeCompositionStateToProto(perfetto::protos::LayerProto* layerProto,
@@ -657,8 +649,6 @@ public:

    gui::WindowInfo::Type getWindowType() const { return mWindowType; }

    bool updateMirrorInfo(const std::deque<Layer*>& cloneRootsPendingUpdates);

    /*
     * doTransaction - process the transaction. This is a good place to figure
     * out which attributes of the surface have changed.
@@ -671,22 +661,6 @@ public:
     */
    void removeRelativeZ(const std::vector<Layer*>& layersInTree);

    /*
     * Remove from current state and mark for removal.
     */
    void removeFromCurrentState() REQUIRES(mFlinger->mStateLock);

    /*
     * called with the state lock from a binder thread when the layer is
     * removed from the current list to the pending removal list
     */
    void onRemovedFromCurrentState() REQUIRES(mFlinger->mStateLock);

    /*
     * Called when the layer is added back to the current state list.
     */
    void addToCurrentState();

    inline const State& getDrawingState() const { return mDrawingState; }
    inline State& getDrawingState() { return mDrawingState; }

@@ -715,57 +689,9 @@ public:
    // is ready to acquire a buffer.
    ui::Transform::RotationFlags getFixedTransformHint() 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, const LayerVector::Visitor&);
    void traverseInReverseZOrder(LayerVector::StateSet, const LayerVector::Visitor&);
    void traverseInZOrder(LayerVector::StateSet, const LayerVector::Visitor&);
    void traverseChildren(const LayerVector::Visitor&);

    /**
     * Traverse only children in z order, ignoring relative layers that are not children of the
     * parent.
     */
    void traverseChildrenInZOrder(LayerVector::StateSet, const LayerVector::Visitor&);

    size_t getDescendantCount() const;
    size_t getChildrenCount() const { return mDrawingChildren.size(); }
    bool isHandleAlive() const { return mHandleAlive; }
    bool onHandleDestroyed() { return mHandleAlive = false; }

    // ONLY CALL THIS FROM THE LAYER DTOR!
    // See b/141111965.  We need to add current children to offscreen layers in
    // the layer dtor so as not to dangle layers.  Since the layer has not
    // committed its transaction when the layer is destroyed, we must add
    // current children.  This is safe in the dtor as we will no longer update
    // the current state, but should not be called anywhere else!
    LayerVector& getCurrentChildren() { return mCurrentChildren; }

    void addChild(const sp<Layer>&);
    // Returns index if removed, or negative value otherwise
    // for symmetry with Vector::remove
    ssize_t removeChild(const sp<Layer>& layer);
    sp<Layer> getParent() const { return mCurrentParent.promote(); }

    // Should be called with the surfaceflinger statelock held
    bool isAtRoot() const { return mIsAtRoot; }
    void setIsAtRoot(bool isAtRoot) { mIsAtRoot = isAtRoot; }

    bool hasParent() const { return getParent() != nullptr; }
    Rect getScreenBounds(bool reduceTransparentRegion = true) const;
    bool setChildLayer(const sp<Layer>& childLayer, int32_t z);
    bool setChildRelativeLayer(const sp<Layer>& childLayer,
            const sp<IBinder>& relativeToHandle, int32_t relativeZ);

    // Copy the current list of children to the drawing state. Called by
    // SurfaceFlinger to complete a transaction.
    void commitChildList();
    int32_t getZ(LayerVector::StateSet) const;

    /**
@@ -823,15 +749,6 @@ public:

    int32_t getOwnerAppId() { return mOwnerAppId; }

    // This layer is not a clone, but it's the parent to the cloned hierarchy. The
    // variable mClonedChild represents the top layer that will be cloned so this
    // layer will be the parent of mClonedChild.
    // The layers in the cloned hierarchy will match the lifetime of the real layers. That is
    // if the real layer is destroyed, then the clone layer will also be destroyed.
    sp<Layer> mClonedChild;
    bool mHadClonedChild = false;
    void setClonedChild(const sp<Layer>& mClonedChild);

    mutable bool contentDirty{false};
    Region surfaceDamageRegion;

@@ -855,7 +772,6 @@ public:
    }

    bool setStretchEffect(const StretchEffect& effect);
    StretchEffect getStretchEffect() const;

    bool setBufferCrop(const Rect& /* bufferCrop */);
    bool setDestinationFrame(const Rect& /* destinationFrame */);
@@ -877,10 +793,6 @@ public:
    // CompositionEngine to create a single path for composing layers.
    void updateSnapshot(bool updateGeometry);
    void updateChildrenSnapshots(bool updateGeometry);
    sp<Layer> getClonedFrom() const {
        return mClonedFrom != nullptr ? mClonedFrom.promote() : nullptr;
    }
    bool isClone() { return mClonedFrom != nullptr; }

    bool willPresentCurrentTransaction() const;

@@ -946,16 +858,6 @@ protected:
    void preparePerFrameEffectsCompositionState();
    void gatherBufferInfo();

    bool isClonedFromAlive() { return getClonedFrom() != nullptr; }

    void cloneDrawingState(const Layer* from);
    void updateClonedDrawingState(std::map<sp<Layer>, sp<Layer>>& clonedLayersMap);
    void updateClonedChildren(const sp<Layer>& mirrorRoot,
                              std::map<sp<Layer>, sp<Layer>>& clonedLayersMap);
    void updateClonedRelatives(const std::map<sp<Layer>, sp<Layer>>& clonedLayersMap);
    void addChildToDrawing(const sp<Layer>&);
    void updateClonedInputInfo(const std::map<sp<Layer>, sp<Layer>>& clonedLayersMap);

    void prepareBasicGeometryCompositionState();
    void prepareGeometryCompositionState();
    void prepareCursorCompositionState();
@@ -1086,19 +988,6 @@ private:
            const DisplayDevice&) const;
    aidl::android::hardware::graphics::composer3::Composition getCompositionType(
            const compositionengine::OutputLayer*) const;
    /**
     * Returns an unsorted vector of all layers that are part of this tree.
     * That includes the current layer and all its descendants.
     */
    std::vector<Layer*> getLayersInTree(LayerVector::StateSet);
    /**
     * Traverses layers that are part of this tree in the correct z order.
     * layersInTree must be sorted before calling this method.
     */
    void traverseChildrenInZOrderInner(const std::vector<Layer*>& layersInTree,
                                       LayerVector::StateSet, const LayerVector::Visitor&);
    LayerVector makeChildrenTraversalList(LayerVector::StateSet,
                                          const std::vector<Layer*>& layersInTree);

    bool propagateFrameRateForLayerTree(FrameRate parentFrameRate, bool overrideChildren,
                                        bool* transactionNeeded);
@@ -1107,10 +996,6 @@ private:
    gui::DropInputMode getDropInputMode() const;
    void handleDropInputMode(gui::WindowInfo& info) const;

    // Find the root of the cloned hierarchy, this means the first non cloned parent.
    // This will return null if first non cloned parent is not found.
    sp<Layer> getClonedRoot();

    // Finds the top most layer in the hierarchy. This will find the root Layer where the parent is
    // null.
    sp<Layer> getRootLayer();
@@ -1185,12 +1070,6 @@ private:

    bool mGetHandleCalled = false;

    // The current layer is a clone of mClonedFrom. This means that this layer will update it's
    // properties based on mClonedFrom. When mClonedFrom latches a new buffer for BufferLayers,
    // this layer will update it's buffer. When mClonedFrom updates it's drawing state, children,
    // and relatives, this layer will update as well.
    wp<Layer> mClonedFrom;

    // The inherited shadow radius after taking into account the layer hierarchy. This is the
    // final shadow radius for this layer. If a shadow is specified for a layer, then effective
    // shadow radius is the set shadow radius, otherwise its the parent's shadow radius.
+0 −29
Original line number Diff line number Diff line
@@ -61,35 +61,6 @@ int LayerVector::do_compare(const void* lhs, const void* rhs) const
    return (l->sequence > r->sequence) ? 1 : -1;
}

void LayerVector::traverseInZOrder(StateSet stateSet, const Visitor& visitor) const {
    for (size_t i = 0; i < size(); i++) {
        const auto& layer = (*this)[i];
        auto& state = layer->getDrawingState();
        if (state.isRelativeOf) {
            continue;
        }
        layer->traverseInZOrder(stateSet, visitor);
    }
}

void LayerVector::traverseInReverseZOrder(StateSet stateSet, const Visitor& visitor) const {
    for (auto i = static_cast<int64_t>(size()) - 1; i >= 0; i--) {
        const auto& layer = (*this)[i];
        auto& state = layer->getDrawingState();
        if (state.isRelativeOf) {
            continue;
        }
        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 −4
Original line number Diff line number Diff line
@@ -46,11 +46,8 @@ public:

    // Sorts layer by layer-stack, Z order, and finally creation order (sequence).
    int do_compare(const void* lhs, const void* rhs) const override;

    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;
};
Loading