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

Commit 3cc15a4f authored by Vishnu Nair's avatar Vishnu Nair
Browse files

[sf] add debug dump for new front end

Test: window type populated correctly in sf dump
Test: dumpsys SurfaceFlinger
Bug: 238781169
Change-Id: I86e475393c8b157496862fa34420c13fc80d681c
parent b5d886df
Loading
Loading
Loading
Loading
+26 −6
Original line number Diff line number Diff line
@@ -149,13 +149,33 @@ std::string LayerHierarchy::getDebugStringShort() const {
    return debug + "}";
}

std::string LayerHierarchy::getDebugString(const char* prefix) const {
    std::string debug = prefix + getDebugStringShort();
    for (auto& [child, childVariant] : mChildren) {
        std::string childPrefix = "  " + std::string(prefix) + " " + std::to_string(childVariant);
        debug += "\n" + child->getDebugString(childPrefix.c_str());
void LayerHierarchy::dump(std::ostream& out, const std::string& prefix,
                          LayerHierarchy::Variant variant, bool isLastChild) const {
    if (!mLayer) {
        out << " ROOT";
    } else {
        out << prefix + (isLastChild ? "└─ " : "├─ ");
        if (variant == LayerHierarchy::Variant::Relative) {
            out << "(Relative) ";
        } else if (variant == LayerHierarchy::Variant::Mirror) {
            out << "(Mirroring) " << *mLayer << "\n" + prefix + "   └─ ...";
            return;
        }
    return debug;
        out << *mLayer;
    }

    for (size_t i = 0; i < mChildren.size(); i++) {
        auto& [child, childVariant] = mChildren[i];
        if (childVariant == LayerHierarchy::Variant::Detached) continue;
        const bool lastChild = i == (mChildren.size() - 1);
        std::string childPrefix = prefix;
        if (mLayer) {
            childPrefix += (isLastChild ? "   " : "│  ");
        }
        out << "\n";
        child->dump(out, childPrefix, childVariant, lastChild);
    }
    return;
}

bool LayerHierarchy::hasRelZLoop(uint32_t& outInvalidRelativeRoot) const {
+8 −1
Original line number Diff line number Diff line
@@ -156,7 +156,12 @@ public:
    const RequestedLayerState* getLayer() const;
    const LayerHierarchy* getRelativeParent() const;
    const LayerHierarchy* getParent() const;
    std::string getDebugString(const char* prefix = "") const;
    friend std::ostream& operator<<(std::ostream& os, const LayerHierarchy& obj) {
        std::string prefix = " ";
        obj.dump(os, prefix, LayerHierarchy::Variant::Attached, /*isLastChild=*/false);
        return os;
    }

    std::string getDebugStringShort() const;
    // Traverse the hierarchy and return true if loops are found. The outInvalidRelativeRoot
    // will contain the first relative root that was visited twice in a traversal.
@@ -172,6 +177,8 @@ private:
    void updateChild(LayerHierarchy*, LayerHierarchy::Variant);
    void traverseInZOrder(const Visitor& visitor, LayerHierarchy::TraversalPath& parent) const;
    void traverse(const Visitor& visitor, LayerHierarchy::TraversalPath& parent) const;
    void dump(std::ostream& out, const std::string& prefix, LayerHierarchy::Variant variant,
              bool isLastChild) const;

    const RequestedLayerState* mLayer;
    LayerHierarchy* mParent = nullptr;
+90 −2
Original line number Diff line number Diff line
@@ -39,6 +39,63 @@ void updateSurfaceDamage(const RequestedLayerState& requested, bool hasReadyFram
    }
}

std::ostream& operator<<(std::ostream& os, const ui::Transform& transform) {
    const uint32_t type = transform.getType();
    const uint32_t orientation = transform.getOrientation();
    if (type == ui::Transform::IDENTITY) {
        return os;
    }

    if (type & ui::Transform::UNKNOWN) {
        std::string out;
        transform.dump(out, "", "");
        os << out;
        return os;
    }

    if (type & ui::Transform::ROTATE) {
        switch (orientation) {
            case ui::Transform::ROT_0:
                os << "ROT_0";
                break;
            case ui::Transform::FLIP_H:
                os << "FLIP_H";
                break;
            case ui::Transform::FLIP_V:
                os << "FLIP_V";
                break;
            case ui::Transform::ROT_90:
                os << "ROT_90";
                break;
            case ui::Transform::ROT_180:
                os << "ROT_180";
                break;
            case ui::Transform::ROT_270:
                os << "ROT_270";
                break;
            case ui::Transform::ROT_INVALID:
            default:
                os << "ROT_INVALID";
                break;
        }
    }

    if (type & ui::Transform::SCALE) {
        std::string out;
        android::base::StringAppendF(&out, " scale x=%.4f y=%.4f ", transform.getScaleX(),
                                     transform.getScaleY());
        os << out;
    }

    if (type & ui::Transform::TRANSLATE) {
        std::string out;
        android::base::StringAppendF(&out, " tx=%.4f ty=%.4f ", transform.tx(), transform.ty());
        os << out;
    }

    return os;
}

} // namespace

LayerSnapshot::LayerSnapshot(const RequestedLayerState& state,
@@ -59,6 +116,7 @@ LayerSnapshot::LayerSnapshot(const RequestedLayerState& state,
    }
    sequence = static_cast<int32_t>(state.id);
    name = state.name;
    debugName = state.debugName;
    textureName = state.textureName;
    premultipliedAlpha = state.premultipliedAlpha;
    inputInfo.name = state.name;
@@ -180,13 +238,13 @@ std::string LayerSnapshot::getIsVisibleReason() const {
    if (handleSkipScreenshotFlag & outputFilter.toInternalDisplay) return "eLayerSkipScreenshot";
    if (invalidTransform) return "invalidTransform";
    if (color.a == 0.0f && !hasBlur()) return "alpha = 0 and no blur";
    if (!hasSomethingToDraw()) return "!hasSomethingToDraw";
    if (!hasSomethingToDraw()) return "nothing to draw";

    // visible
    std::stringstream reason;
    if (sidebandStream != nullptr) reason << " sidebandStream";
    if (externalTexture != nullptr)
        reason << " buffer:" << externalTexture->getId() << " frame:" << frameNumber;
        reason << " buffer=" << externalTexture->getId() << " frame=" << frameNumber;
    if (fillsColor() || color.a > 0.0f) reason << " color{" << color << "}";
    if (drawShadows()) reason << " shadowSettings.length=" << shadowSettings.length;
    if (backgroundBlurRadius > 0) reason << " backgroundBlurRadius=" << backgroundBlurRadius;
@@ -232,6 +290,36 @@ std::string LayerSnapshot::getDebugString() const {
    return debug.str();
}

std::ostream& operator<<(std::ostream& out, const LayerSnapshot& obj) {
    out << "Layer [" << obj.path.id;
    if (obj.path.mirrorRootId != UNASSIGNED_LAYER_ID) {
        out << " mirrored from " << obj.path.mirrorRootId;
    }
    out << "] " << obj.name << "\n    " << (obj.isVisible ? "visible" : "invisible")
        << " reason=" << obj.getIsVisibleReason();

    if (!obj.geomLayerBounds.isEmpty()) {
        out << "\n    bounds={" << obj.transformedBounds.left << "," << obj.transformedBounds.top
            << "," << obj.transformedBounds.bottom << "," << obj.transformedBounds.right << "}";
    }

    if (obj.geomLayerTransform.getType() != ui::Transform::IDENTITY) {
        out << " toDisplayTransform={" << obj.geomLayerTransform << "}";
    }

    if (obj.hasInputInfo()) {
        out << "\n    input{"
            << "(" << obj.inputInfo.inputConfig.string() << ")";
        if (obj.touchCropId != UNASSIGNED_LAYER_ID) out << " touchCropId=" << obj.touchCropId;
        if (obj.inputInfo.replaceTouchableRegionWithCrop) out << " replaceTouchableRegionWithCrop";
        auto touchableRegion = obj.inputInfo.touchableRegion.getBounds();
        out << " touchableRegion={" << touchableRegion.left << "," << touchableRegion.top << ","
            << touchableRegion.bottom << "," << touchableRegion.right << "}"
            << "}";
    }
    return out;
}

FloatRect LayerSnapshot::sourceBounds() const {
    if (!externalTexture) {
        return geomLayerBounds;
+2 −1
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ struct LayerSnapshot : public compositionengine::LayerFECompositionState {
    // generated from the same layer, for example when mirroring.
    int32_t sequence;
    std::string name;
    std::string debugName;
    uint32_t textureName;
    bool contentOpaque;
    bool layerOpaqueFlagSet;
@@ -145,7 +146,7 @@ struct LayerSnapshot : public compositionengine::LayerFECompositionState {
    bool hasInputInfo() const;
    FloatRect sourceBounds() const;
    Hwc2::IComposerClient::BlendMode getBlendMode(const RequestedLayerState& requested) const;

    friend std::ostream& operator<<(std::ostream& os, const LayerSnapshot& obj);
    void merge(const RequestedLayerState& requested, bool forceUpdate, bool displayChanges,
               bool forceFullDamage, uint32_t displayRotationFlags);
};
+17 −0
Original line number Diff line number Diff line
@@ -127,6 +127,16 @@ RequestedLayerState::RequestedLayerState(const LayerCreationArgs& args)
    gameMode = gui::GameMode::Unsupported;
    requestedFrameRate = {};
    cachingHint = gui::CachingHint::Enabled;

    if (name.length() > 77) {
        std::string shortened;
        shortened.append(name, 0, 36);
        shortened.append("[...]");
        shortened.append(name, name.length() - 36);
        debugName = std::move(shortened);
    } else {
        debugName = name;
    }
}

void RequestedLayerState::merge(const ResolvedComposerState& resolvedComposerState) {
@@ -371,6 +381,13 @@ std::string RequestedLayerState::getDebugString() const {
    return debug.str();
}

std::ostream& operator<<(std::ostream& out, const RequestedLayerState& obj) {
    out << obj.debugName;
    if (obj.relativeParentId != UNASSIGNED_LAYER_ID) out << " parent=" << obj.parentId;
    if (!obj.handleAlive) out << " handleNotAlive";
    return out;
}

std::string RequestedLayerState::getDebugStringShort() const {
    return "[" + std::to_string(id) + "]" + name;
}
Loading