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

Commit 068e31b9 authored by Yiwei Zhang's avatar Yiwei Zhang
Browse files

Implement Display Layer Stats

Try to collect data for analyzing how many display controller layers we
need and what we use them for. Also part of a bug fixing for potential
memory leak of existing layer tracing work of winscope.

Test: adb shell dumpsys SurfaceFlinger --enable-layer-stats
Test: adb shell dumpsys SurfaceFlinger --disable-layer-stats
Test: adb shell dumpsys SurfaceFlinger --clear-layer-stats
Test: adb shell dumpsys SurfaceFlinger --dump-layer-stats
Bug: b/73668062
Change-Id: Ie08aa85d34db2c2c767b8e27eb5aad6f7c3fb975
Merged-In: Ie08aa85d34db2c2c767b8e27eb5aad6f7c3fb975
parent b62346a3
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -105,6 +105,7 @@ filegroup {
        "Layer.cpp",
        "Layer.cpp",
        "LayerProtoHelper.cpp",
        "LayerProtoHelper.cpp",
        "LayerRejecter.cpp",
        "LayerRejecter.cpp",
        "LayerStats.cpp",
        "LayerVector.cpp",
        "LayerVector.cpp",
        "MessageQueue.cpp",
        "MessageQueue.cpp",
        "MonitoredProducer.cpp",
        "MonitoredProducer.cpp",
+16 −0
Original line number Original line Diff line number Diff line
@@ -635,6 +635,7 @@ void Layer::setGeometry(const sp<const DisplayDevice>& displayDevice, uint32_t z
        hwcInfo.forceClientComposition = true;
        hwcInfo.forceClientComposition = true;
    } else {
    } else {
        auto transform = static_cast<HWC2::Transform>(orientation);
        auto transform = static_cast<HWC2::Transform>(orientation);
        hwcInfo.transform = transform;
        auto error = hwcLayer->setTransform(transform);
        auto error = hwcLayer->setTransform(transform);
        ALOGE_IF(error != HWC2::Error::None,
        ALOGE_IF(error != HWC2::Error::None,
                 "[%s] Failed to set transform %s: "
                 "[%s] Failed to set transform %s: "
@@ -1923,6 +1924,21 @@ void Layer::writeToProto(LayerProto* layerInfo, LayerVector::StateSet stateSet)
    layerInfo->set_app_id(state.appId);
    layerInfo->set_app_id(state.appId);
}
}


void Layer::writeToProto(LayerProto* layerInfo, int32_t hwcId) {
    writeToProto(layerInfo, LayerVector::StateSet::Drawing);

    const auto& hwcInfo = getBE().mHwcLayers.at(hwcId);

    const Rect& frame = hwcInfo.displayFrame;
    LayerProtoHelper::writeToProto(frame, layerInfo->mutable_hwc_frame());

    const FloatRect& crop = hwcInfo.sourceCrop;
    LayerProtoHelper::writeToProto(crop, layerInfo->mutable_hwc_crop());

    const int32_t transform = static_cast<int32_t>(hwcInfo.transform);
    layerInfo->set_hwc_transform(transform);
}

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


}; // namespace android
}; // namespace android
+5 −1
Original line number Original line Diff line number Diff line
@@ -113,7 +113,8 @@ public:
                layer(nullptr),
                layer(nullptr),
                forceClientComposition(false),
                forceClientComposition(false),
                compositionType(HWC2::Composition::Invalid),
                compositionType(HWC2::Composition::Invalid),
                clearClientTarget(false) {}
                clearClientTarget(false),
                transform(HWC2::Transform::None) {}


        HWComposer* hwc;
        HWComposer* hwc;
        HWC2::Layer* layer;
        HWC2::Layer* layer;
@@ -123,6 +124,7 @@ public:
        Rect displayFrame;
        Rect displayFrame;
        FloatRect sourceCrop;
        FloatRect sourceCrop;
        HWComposerBufferCache bufferCache;
        HWComposerBufferCache bufferCache;
        HWC2::Transform transform;
    };
    };


    // A layer can be attached to multiple displays when operating in mirror mode
    // A layer can be attached to multiple displays when operating in mirror mode
@@ -357,6 +359,8 @@ public:
    void writeToProto(LayerProto* layerInfo,
    void writeToProto(LayerProto* layerInfo,
                      LayerVector::StateSet stateSet = LayerVector::StateSet::Drawing);
                      LayerVector::StateSet stateSet = LayerVector::StateSet::Drawing);


    void writeToProto(LayerProto* layerInfo, int32_t hwcId);

protected:
protected:
    /*
    /*
     * onDraw - draws the surface.
     * onDraw - draws the surface.
+7 −0
Original line number Original line Diff line number Diff line
@@ -37,6 +37,13 @@ void LayerProtoHelper::writeToProto(const Rect& rect, RectProto* rectProto) {
    rectProto->set_right(rect.right);
    rectProto->set_right(rect.right);
}
}


void LayerProtoHelper::writeToProto(const FloatRect& rect, FloatRectProto* rectProto) {
    rectProto->set_left(rect.left);
    rectProto->set_top(rect.top);
    rectProto->set_bottom(rect.bottom);
    rectProto->set_right(rect.right);
}

void LayerProtoHelper::writeToProto(const half4 color, ColorProto* colorProto) {
void LayerProtoHelper::writeToProto(const half4 color, ColorProto* colorProto) {
    colorProto->set_r(color.r);
    colorProto->set_r(color.r);
    colorProto->set_g(color.g);
    colorProto->set_g(color.g);
+2 −1
Original line number Original line Diff line number Diff line
@@ -29,6 +29,7 @@ namespace surfaceflinger {
class LayerProtoHelper {
class LayerProtoHelper {
public:
public:
    static void writeToProto(const Rect& rect, RectProto* rectProto);
    static void writeToProto(const Rect& rect, RectProto* rectProto);
    static void writeToProto(const FloatRect& rect, FloatRectProto* rectProto);
    static void writeToProto(const Region& region, RegionProto* regionProto);
    static void writeToProto(const Region& region, RegionProto* regionProto);
    static void writeToProto(const half4 color, ColorProto* colorProto);
    static void writeToProto(const half4 color, ColorProto* colorProto);
    static void writeToProto(const Transform& transform, TransformProto* transformProto);
    static void writeToProto(const Transform& transform, TransformProto* transformProto);
Loading