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

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

Merge "[sf] Use layer id as snapshot ids" into udc-dev

parents 7ec5b1d9 150065b4
Loading
Loading
Loading
Loading
+5 −6
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
namespace android::surfaceflinger {

std::atomic<uint32_t> LayerCreationArgs::sSequence{1};
std::atomic<uint32_t> LayerCreationArgs::sInternalSequence{1};

uint32_t LayerCreationArgs::getInternalLayerId(uint32_t id) {
    return id | INTERNAL_LAYER_PREFIX;
@@ -48,13 +49,11 @@ LayerCreationArgs::LayerCreationArgs(SurfaceFlinger* flinger, sp<Client> client,
                metadata.getInt32(gui::METADATA_OWNER_UID, static_cast<int32_t>(ownerUid)));
    }

    if (id) {
        sequence = *id;
    if (internalLayer) {
            sequence = getInternalLayerId(*id);
        } else {
        sequence = getInternalLayerId(sInternalSequence++);
    } else if (id) {
        sequence = *id;
        sSequence = *id + 1;
        }
    } else {
        sequence = sSequence++;
        if (sequence >= INTERNAL_LAYER_PREFIX) {
+1 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ namespace android::surfaceflinger {

struct LayerCreationArgs {
    static std::atomic<uint32_t> sSequence;
    static std::atomic<uint32_t> sInternalSequence;
    static uint32_t getInternalLayerId(uint32_t id);
    static LayerCreationArgs fromOtherArgs(const LayerCreationArgs& other);

+9 −13
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ void LayerLifecycleManager::addLayers(std::vector<std::unique_ptr<RequestedLayer
            LOG_ALWAYS_FATAL("Duplicate layer id %d found. Existing layer: %s", layer.id,
                             it->second.owner.getDebugString().c_str());
        }

        mAddedLayers.push_back(newLayer.get());
        layer.parentId = linkLayer(layer.parentId, layer.id);
        layer.relativeParentId = linkLayer(layer.relativeParentId, layer.id);
        if (layer.layerStackToMirror != ui::INVALID_LAYER_STACK) {
@@ -258,23 +258,19 @@ void LayerLifecycleManager::applyTransactions(const std::vector<TransactionState
}

void LayerLifecycleManager::commitChanges() {
    for (auto& layer : mLayers) {
        if (layer->changes.test(RequestedLayerState::Changes::Created)) {
            for (auto listener : mListeners) {
    for (auto layer : mAddedLayers) {
        for (auto& listener : mListeners) {
            listener->onLayerAdded(*layer);
        }
    }
    mAddedLayers.clear();

    for (auto& layer : mLayers) {
        layer->clearChanges();
    }

    for (auto& destroyedLayer : mDestroyedLayers) {
        if (destroyedLayer->changes.test(RequestedLayerState::Changes::Created)) {
            for (auto listener : mListeners) {
                listener->onLayerAdded(*destroyedLayer);
            }
        }

        for (auto listener : mListeners) {
        for (auto& listener : mListeners) {
            listener->onLayerDestroyed(*destroyedLayer);
        }
    }
+3 −0
Original line number Diff line number Diff line
@@ -108,6 +108,9 @@ private:
    std::vector<std::unique_ptr<RequestedLayerState>> mLayers;
    // Layers pending destruction. Layers will be destroyed once changes are committed.
    std::vector<std::unique_ptr<RequestedLayerState>> mDestroyedLayers;
    // Keeps track of all the layers that were added in order. Changes will be cleared once
    // committed.
    std::vector<RequestedLayerState*> mAddedLayers;
};

} // namespace android::surfaceflinger::frontend
+6 −2
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ using namespace ftl::flag_operators;
LayerSnapshot::LayerSnapshot(const RequestedLayerState& state,
                             const LayerHierarchy::TraversalPath& path)
      : path(path) {
    static uint32_t sUniqueSequenceId = 0;
    // Provide a unique id for all snapshots.
    // A front end layer can generate multiple snapshots if its mirrored.
    // Additionally, if the layer is not reachable, we may choose to destroy
@@ -35,7 +34,12 @@ LayerSnapshot::LayerSnapshot(const RequestedLayerState& state,
    // change. The consumer shouldn't tie any lifetimes to this unique id but
    // register a LayerLifecycleManager::ILifecycleListener or get a list of
    // destroyed layers from LayerLifecycleManager.
    uniqueSequence = sUniqueSequenceId++;
    if (path.isClone()) {
        uniqueSequence =
                LayerCreationArgs::getInternalLayerId(LayerCreationArgs::sInternalSequence++);
    } else {
        uniqueSequence = state.id;
    }
    sequence = static_cast<int32_t>(state.id);
    name = state.name;
    textureName = state.textureName;
Loading