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

Commit a8f0924e authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "SF: Remove display lookup in SurfaceTracing" into rvc-dev am: 0a434239 am: eba39bef

Change-Id: I5a83d29ed9d8f65df8bb5eb85bced9d49544dae5
parents f484f116 eba39bef
Loading
Loading
Loading
Loading
+31 −50
Original line number Original line Diff line number Diff line
@@ -169,19 +169,22 @@ bool isWideColorMode(const ColorMode colorMode) {


#pragma clang diagnostic pop
#pragma clang diagnostic pop


class ConditionalLock {
template <typename Mutex>
public:
struct ConditionalLockGuard {
    ConditionalLock(Mutex& mutex, bool lock) : mMutex(mutex), mLocked(lock) {
    ConditionalLockGuard(Mutex& mutex, bool lock) : mutex(mutex), lock(lock) {
        if (lock) {
        if (lock) mutex.lock();
            mMutex.lock();
    }
    }

    ~ConditionalLockGuard() {
        if (lock) mutex.unlock();
    }
    }
    ~ConditionalLock() { if (mLocked) mMutex.unlock(); }

private:
    Mutex& mutex;
    Mutex& mMutex;
    const bool lock;
    bool mLocked;
};
};


using ConditionalLock = ConditionalLockGuard<Mutex>;

// TODO(b/141333600): Consolidate with HWC2::Display::Config::Builder::getDefaultDensity.
// TODO(b/141333600): Consolidate with HWC2::Display::Config::Builder::getDefaultDensity.
constexpr float FALLBACK_DENSITY = ACONFIGURATION_DENSITY_TV / 160.f;
constexpr float FALLBACK_DENSITY = ACONFIGURATION_DENSITY_TV / 160.f;


@@ -1953,8 +1956,15 @@ void SurfaceFlinger::onMessageReceived(int32_t what) NO_THREAD_SAFETY_ANALYSIS {
            // potentially trigger a display handoff.
            // potentially trigger a display handoff.
            updateVrFlinger();
            updateVrFlinger();


            if (mTracingEnabledChanged) {
                mTracingEnabled = mTracing.isEnabled();
                mTracingEnabledChanged = false;
            }

            bool refreshNeeded;
            bool refreshNeeded;
            withTracingLock([&]() {
            {
                ConditionalLockGuard<std::mutex> lock(mTracingLock, mTracingEnabled);

                refreshNeeded = handleMessageTransaction();
                refreshNeeded = handleMessageTransaction();
                refreshNeeded |= handleMessageInvalidate();
                refreshNeeded |= handleMessageInvalidate();
                if (mTracingEnabled) {
                if (mTracingEnabled) {
@@ -1964,7 +1974,7 @@ void SurfaceFlinger::onMessageReceived(int32_t what) NO_THREAD_SAFETY_ANALYSIS {
                        mTracing.notifyLocked("visibleRegionsDirty");
                        mTracing.notifyLocked("visibleRegionsDirty");
                    }
                    }
                }
                }
            });
            }


            // Layers need to get updated (in the previous line) before we can use them for
            // Layers need to get updated (in the previous line) before we can use them for
            // choosing the refresh rate.
            // choosing the refresh rate.
@@ -3037,26 +3047,6 @@ void SurfaceFlinger::commitTransactionLocked() {
    mDrawingState.traverse([&](Layer* layer) { layer->updateMirrorInfo(); });
    mDrawingState.traverse([&](Layer* layer) { layer->updateMirrorInfo(); });
}
}


void SurfaceFlinger::withTracingLock(std::function<void()> lockedOperation) {
    if (mTracingEnabledChanged) {
        mTracingEnabled = mTracing.isEnabled();
        mTracingEnabledChanged = false;
    }

    // Synchronize with Tracing thread
    std::unique_lock<std::mutex> lock;
    if (mTracingEnabled) {
        lock = std::unique_lock<std::mutex>(mDrawingStateLock);
    }

    lockedOperation();

    // Synchronize with Tracing thread
    if (mTracingEnabled) {
        lock.unlock();
    }
}

void SurfaceFlinger::commitOffscreenLayers() {
void SurfaceFlinger::commitOffscreenLayers() {
    for (Layer* offscreenLayer : mOffscreenLayers) {
    for (Layer* offscreenLayer : mOffscreenLayers) {
        offscreenLayer->traverse(LayerVector::StateSet::Drawing, [](Layer* layer) {
        offscreenLayer->traverse(LayerVector::StateSet::Drawing, [](Layer* layer) {
@@ -4563,11 +4553,13 @@ void SurfaceFlinger::dumpWideColorInfo(std::string& result) const {
    result.append("\n");
    result.append("\n");
}
}


LayersProto SurfaceFlinger::dumpDrawingStateProto(
LayersProto SurfaceFlinger::dumpDrawingStateProto(uint32_t traceFlags) const {
        uint32_t traceFlags, const sp<const DisplayDevice>& displayDevice) const {
    // If context is SurfaceTracing thread, mTracingLock blocks display transactions on main thread.
    const auto display = getDefaultDisplayDeviceLocked();

    LayersProto layersProto;
    LayersProto layersProto;
    for (const sp<Layer>& layer : mDrawingState.layersSortedByZ) {
    for (const sp<Layer>& layer : mDrawingState.layersSortedByZ) {
        layer->writeToProto(layersProto, traceFlags, displayDevice);
        layer->writeToProto(layersProto, traceFlags, display);
    }
    }


    return layersProto;
    return layersProto;
@@ -4599,10 +4591,7 @@ void SurfaceFlinger::dumpOffscreenLayersProto(LayersProto& layersProto, uint32_t


LayersProto SurfaceFlinger::dumpProtoFromMainThread(uint32_t traceFlags) {
LayersProto SurfaceFlinger::dumpProtoFromMainThread(uint32_t traceFlags) {
    LayersProto layersProto;
    LayersProto layersProto;
    postMessageSync(new LambdaMessage([&]() {
    postMessageSync(new LambdaMessage([&] { layersProto = dumpDrawingStateProto(traceFlags); }));
        const auto& displayDevice = getDefaultDisplayDeviceLocked();
        layersProto = dumpDrawingStateProto(traceFlags, displayDevice);
    }));
    return layersProto;
    return layersProto;
}
}


@@ -5129,20 +5118,12 @@ status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* r
                n = data.readInt32();
                n = data.readInt32();
                if (n) {
                if (n) {
                    ALOGD("LayerTracing enabled");
                    ALOGD("LayerTracing enabled");
                    Mutex::Autolock lock(mStateLock);
                    mTracingEnabledChanged = mTracing.enable();
                    mTracingEnabledChanged = true;
                    mTracing.enable();
                    reply->writeInt32(NO_ERROR);
                    reply->writeInt32(NO_ERROR);
                } else {
                } else {
                    ALOGD("LayerTracing disabled");
                    ALOGD("LayerTracing disabled");
                    bool writeFile = false;
                    mTracingEnabledChanged = mTracing.disable();
                    {
                    if (mTracingEnabledChanged) {
                        Mutex::Autolock lock(mStateLock);
                        mTracingEnabledChanged = true;
                        writeFile = mTracing.disable();
                    }

                    if (writeFile) {
                        reply->writeInt32(mTracing.writeToFile());
                        reply->writeInt32(mTracing.writeToFile());
                    } else {
                    } else {
                        reply->writeInt32(NO_ERROR);
                        reply->writeInt32(NO_ERROR);
+5 −7
Original line number Original line Diff line number Diff line
@@ -929,8 +929,7 @@ private:
    void dumpDisplayIdentificationData(std::string& result) const;
    void dumpDisplayIdentificationData(std::string& result) const;
    void dumpRawDisplayIdentificationData(const DumpArgs&, std::string& result) const;
    void dumpRawDisplayIdentificationData(const DumpArgs&, std::string& result) const;
    void dumpWideColorInfo(std::string& result) const;
    void dumpWideColorInfo(std::string& result) const;
    LayersProto dumpDrawingStateProto(uint32_t traceFlags = SurfaceTracing::TRACE_ALL,
    LayersProto dumpDrawingStateProto(uint32_t traceFlags) const;
                                      const sp<const DisplayDevice>& displayDevice = nullptr) const;
    void dumpOffscreenLayersProto(LayersProto& layersProto,
    void dumpOffscreenLayersProto(LayersProto& layersProto,
                                  uint32_t traceFlags = SurfaceTracing::TRACE_ALL) const;
                                  uint32_t traceFlags = SurfaceTracing::TRACE_ALL) const;
    // Dumps state from HW Composer
    // Dumps state from HW Composer
@@ -938,7 +937,6 @@ private:
    LayersProto dumpProtoFromMainThread(uint32_t traceFlags = SurfaceTracing::TRACE_ALL)
    LayersProto dumpProtoFromMainThread(uint32_t traceFlags = SurfaceTracing::TRACE_ALL)
            EXCLUDES(mStateLock);
            EXCLUDES(mStateLock);
    void dumpOffscreenLayers(std::string& result) EXCLUDES(mStateLock);
    void dumpOffscreenLayers(std::string& result) EXCLUDES(mStateLock);
    void withTracingLock(std::function<void()> operation) REQUIRES(mStateLock);


    bool isLayerTripleBufferingDisabled() const {
    bool isLayerTripleBufferingDisabled() const {
        return this->mLayerTripleBufferingDisabled;
        return this->mLayerTripleBufferingDisabled;
@@ -980,9 +978,6 @@ private:
    SortedVector<sp<Layer>> mLayersPendingRemoval;
    SortedVector<sp<Layer>> mLayersPendingRemoval;
    bool mTraversalNeededMainThread = false;
    bool mTraversalNeededMainThread = false;


    // guards access to the mDrawing state if tracing is enabled.
    mutable std::mutex mDrawingStateLock;

    // global color transform states
    // global color transform states
    Daltonizer mDaltonizer;
    Daltonizer mDaltonizer;
    float mGlobalSaturationFactor = 1.0f;
    float mGlobalSaturationFactor = 1.0f;
@@ -1057,10 +1052,13 @@ private:
    bool mPropagateBackpressure = true;
    bool mPropagateBackpressure = true;
    bool mPropagateBackpressureClientComposition = false;
    bool mPropagateBackpressureClientComposition = false;
    std::unique_ptr<SurfaceInterceptor> mInterceptor;
    std::unique_ptr<SurfaceInterceptor> mInterceptor;

    SurfaceTracing mTracing{*this};
    SurfaceTracing mTracing{*this};
    std::mutex mTracingLock;
    bool mTracingEnabled = false;
    bool mTracingEnabled = false;
    bool mAddCompositionStateToTrace = false;
    bool mAddCompositionStateToTrace = false;
    bool mTracingEnabledChanged GUARDED_BY(mStateLock) = false;
    std::atomic<bool> mTracingEnabledChanged = false;

    const std::shared_ptr<TimeStats> mTimeStats;
    const std::shared_ptr<TimeStats> mTimeStats;
    const std::unique_ptr<FrameTracer> mFrameTracer;
    const std::unique_ptr<FrameTracer> mFrameTracer;
    bool mUseHwcVirtualDisplays = false;
    bool mUseHwcVirtualDisplays = false;
+9 −10
Original line number Original line Diff line number Diff line
@@ -33,7 +33,7 @@
namespace android {
namespace android {


SurfaceTracing::SurfaceTracing(SurfaceFlinger& flinger)
SurfaceTracing::SurfaceTracing(SurfaceFlinger& flinger)
      : mFlinger(flinger), mSfLock(flinger.mDrawingStateLock) {}
      : mFlinger(flinger), mSfLock(flinger.mTracingLock) {}


void SurfaceTracing::mainLoop() {
void SurfaceTracing::mainLoop() {
    bool enabled = addFirstEntry();
    bool enabled = addFirstEntry();
@@ -44,21 +44,19 @@ void SurfaceTracing::mainLoop() {
}
}


bool SurfaceTracing::addFirstEntry() {
bool SurfaceTracing::addFirstEntry() {
    const auto displayDevice = mFlinger.getDefaultDisplayDevice();
    LayersTraceProto entry;
    LayersTraceProto entry;
    {
    {
        std::scoped_lock lock(mSfLock);
        std::scoped_lock lock(mSfLock);
        entry = traceLayersLocked("tracing.enable", displayDevice);
        entry = traceLayersLocked("tracing.enable");
    }
    }
    return addTraceToBuffer(entry);
    return addTraceToBuffer(entry);
}
}


LayersTraceProto SurfaceTracing::traceWhenNotified() {
LayersTraceProto SurfaceTracing::traceWhenNotified() {
    const auto displayDevice = mFlinger.getDefaultDisplayDevice();
    std::unique_lock<std::mutex> lock(mSfLock);
    std::unique_lock<std::mutex> lock(mSfLock);
    mCanStartTrace.wait(lock);
    mCanStartTrace.wait(lock);
    android::base::ScopedLockAssertion assumeLock(mSfLock);
    android::base::ScopedLockAssertion assumeLock(mSfLock);
    LayersTraceProto entry = traceLayersLocked(mWhere, displayDevice);
    LayersTraceProto entry = traceLayersLocked(mWhere);
    mTracingInProgress = false;
    mTracingInProgress = false;
    mMissedTraceEntries = 0;
    mMissedTraceEntries = 0;
    lock.unlock();
    lock.unlock();
@@ -126,15 +124,17 @@ void SurfaceTracing::LayersTraceBuffer::flush(LayersTraceFileProto* fileProto) {
    }
    }
}
}


void SurfaceTracing::enable() {
bool SurfaceTracing::enable() {
    std::scoped_lock lock(mTraceLock);
    std::scoped_lock lock(mTraceLock);


    if (mEnabled) {
    if (mEnabled) {
        return;
        return false;
    }
    }

    mBuffer.reset(mBufferSize);
    mBuffer.reset(mBufferSize);
    mEnabled = true;
    mEnabled = true;
    mThread = std::thread(&SurfaceTracing::mainLoop, this);
    mThread = std::thread(&SurfaceTracing::mainLoop, this);
    return true;
}
}


status_t SurfaceTracing::writeToFile() {
status_t SurfaceTracing::writeToFile() {
@@ -176,14 +176,13 @@ void SurfaceTracing::setTraceFlags(uint32_t flags) {
    mTraceFlags = flags;
    mTraceFlags = flags;
}
}


LayersTraceProto SurfaceTracing::traceLayersLocked(const char* where,
LayersTraceProto SurfaceTracing::traceLayersLocked(const char* where) {
                                                   const sp<const DisplayDevice>& displayDevice) {
    ATRACE_CALL();
    ATRACE_CALL();


    LayersTraceProto entry;
    LayersTraceProto entry;
    entry.set_elapsed_realtime_nanos(elapsedRealtimeNano());
    entry.set_elapsed_realtime_nanos(elapsedRealtimeNano());
    entry.set_where(where);
    entry.set_where(where);
    LayersProto layers(mFlinger.dumpDrawingStateProto(mTraceFlags, displayDevice));
    LayersProto layers(mFlinger.dumpDrawingStateProto(mTraceFlags));


    if (flagIsSetLocked(SurfaceTracing::TRACE_EXTRA)) {
    if (flagIsSetLocked(SurfaceTracing::TRACE_EXTRA)) {
        mFlinger.dumpOffscreenLayersProto(layers);
        mFlinger.dumpOffscreenLayersProto(layers);
+2 −6
Original line number Original line Diff line number Diff line
@@ -27,8 +27,6 @@
#include <queue>
#include <queue>
#include <thread>
#include <thread>


#include "DisplayDevice.h"

using namespace android::surfaceflinger;
using namespace android::surfaceflinger;


namespace android {
namespace android {
@@ -44,7 +42,7 @@ constexpr auto operator""_MB(unsigned long long const num) {
class SurfaceTracing {
class SurfaceTracing {
public:
public:
    explicit SurfaceTracing(SurfaceFlinger& flinger);
    explicit SurfaceTracing(SurfaceFlinger& flinger);
    void enable();
    bool enable();
    bool disable();
    bool disable();
    status_t writeToFile();
    status_t writeToFile();
    bool isEnabled() const;
    bool isEnabled() const;
@@ -92,9 +90,7 @@ private:
    void mainLoop();
    void mainLoop();
    bool addFirstEntry();
    bool addFirstEntry();
    LayersTraceProto traceWhenNotified();
    LayersTraceProto traceWhenNotified();
    LayersTraceProto traceLayersLocked(const char* where,
    LayersTraceProto traceLayersLocked(const char* where) REQUIRES(mSfLock);
                                       const sp<const DisplayDevice>& displayDevice)
            REQUIRES(mSfLock);


    // Returns true if trace is enabled.
    // Returns true if trace is enabled.
    bool addTraceToBuffer(LayersTraceProto& entry);
    bool addTraceToBuffer(LayersTraceProto& entry);