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

Commit 720e54cb authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes I641c1373,I6371e25a

* changes:
  SF: Remove unused globals of VSYNC sysprops
  SF: Clean up postComposition
parents b4ef6ab1 b4fa7fb7
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -136,10 +136,6 @@ void DisplayDevice::setDeviceProductInfo(std::optional<DeviceProductInfo> info)
    mDeviceProductInfo = std::move(info);
}

uint32_t DisplayDevice::getPageFlipCount() const {
    return mCompositionDisplay->getRenderSurface()->getPageFlipCount();
}

auto DisplayDevice::getInputInfo() const -> InputInfo {
    gui::DisplayInfo info;
    info.displayId = getLayerStack().id;
+0 −1
Original line number Diff line number Diff line
@@ -259,7 +259,6 @@ public:
    /* ------------------------------------------------------------------------
     * Debugging
     */
    uint32_t getPageFlipCount() const;
    std::string getDebugName() const;
    void dump(std::string& result) const;

+1 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ static_assert(SchedulerClock::is_steady);
struct Duration;

struct TimePoint : scheduler::SchedulerClock::time_point {
    constexpr TimePoint() = default;
    explicit constexpr TimePoint(const Duration&);

    // Implicit conversion from std::chrono counterpart.
+37 −47
Original line number Diff line number Diff line
@@ -2247,7 +2247,6 @@ void SurfaceFlinger::composite(nsecs_t frameTime, int64_t vsyncId)
        scheduleComposite(FrameHint::kNone);
    }

    postFrame();
    postComposition();

    const bool prevFrameHadClientComposition = mHadClientComposition;
@@ -2363,7 +2362,7 @@ ui::Rotation SurfaceFlinger::getPhysicalDisplayOrientation(DisplayId displayId,

void SurfaceFlinger::postComposition() {
    ATRACE_CALL();
    ALOGV("postComposition");
    ALOGV(__func__);

    const auto* display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()).get();

@@ -2378,18 +2377,19 @@ void SurfaceFlinger::postComposition() {
    }

    mPreviousPresentFences[1] = mPreviousPresentFences[0];
    mPreviousPresentFences[0].fence =

    auto presentFence =
            display ? getHwComposer().getPresentFence(display->getPhysicalId()) : Fence::NO_FENCE;
    mPreviousPresentFences[0].fenceTime =
            std::make_shared<FenceTime>(mPreviousPresentFences[0].fence);

    nsecs_t now = systemTime();
    auto presentFenceTime = std::make_shared<FenceTime>(presentFence);
    mPreviousPresentFences[0] = {presentFence, presentFenceTime};

    const TimePoint presentTime = scheduler::SchedulerClock::now();

    // Set presentation information before calling Layer::releasePendingBuffer, such that jank
    // information from previous' frame classification is already available when sending jank info
    // to clients, so they get jank classification as early as possible.
    mFrameTimeline->setSfPresent(/* sfPresentTime */ now, mPreviousPresentFences[0].fenceTime,
                                 glCompositionDoneFenceTime);
    mFrameTimeline->setSfPresent(presentTime.ns(), presentFenceTime, glCompositionDoneFenceTime);

    // We use the CompositionEngine::getLastFrameRefreshTimestamp() which might
    // be sampled a little later than when we started doing work for this frame,
@@ -2397,11 +2397,10 @@ void SurfaceFlinger::postComposition() {
    const TimePoint compositeTime =
            TimePoint::fromNs(mCompositionEngine->getLastFrameRefreshTimestamp());
    const Duration presentLatency =
            mPresentLatencyTracker.trackPendingFrame(compositeTime,
                                                     mPreviousPresentFences[0].fenceTime);
            mPresentLatencyTracker.trackPendingFrame(compositeTime, presentFenceTime);

    const auto& schedule = mScheduler->getVsyncSchedule();
    const TimePoint vsyncDeadline = schedule.vsyncDeadlineAfter(TimePoint::fromNs(now));
    const TimePoint vsyncDeadline = schedule.vsyncDeadlineAfter(presentTime);
    const Period vsyncPeriod = schedule.period();
    const nsecs_t vsyncPhase = mVsyncConfiguration->getCurrentConfigs().late.sfOffset;

@@ -2409,9 +2408,9 @@ void SurfaceFlinger::postComposition() {
                                            presentLatency.ns());

    for (const auto& layer: mLayersWithQueuedFrames) {
        layer->onPostComposition(display, glCompositionDoneFenceTime,
                                 mPreviousPresentFences[0].fenceTime, compositorTiming);
        layer->releasePendingBuffer(/*dequeueReadyTime*/ now);
        layer->onPostComposition(display, glCompositionDoneFenceTime, presentFenceTime,
                                 compositorTiming);
        layer->releasePendingBuffer(presentTime.ns());
    }

    std::vector<std::pair<std::shared_ptr<compositionengine::Display>, sp<HdrLayerInfoReporter>>>
@@ -2468,13 +2467,16 @@ void SurfaceFlinger::postComposition() {
    mSomeDataspaceChanged = false;
    mVisibleRegionsWereDirtyThisFrame = false;

    mTransactionCallbackInvoker.addPresentFence(mPreviousPresentFences[0].fence);
    mTransactionCallbackInvoker.addPresentFence(std::move(presentFence));
    mTransactionCallbackInvoker.sendCallbacks(false /* onCommitOnly */);
    mTransactionCallbackInvoker.clearCompletedTransactions();

    mTimeStats->incrementTotalFrames();
    mTimeStats->setPresentFenceGlobal(presentFenceTime);

    if (display && display->isInternal() && display->getPowerMode() == hal::PowerMode::ON &&
        mPreviousPresentFences[0].fenceTime->isValid()) {
        mScheduler->addPresentFence(mPreviousPresentFences[0].fenceTime);
        presentFenceTime->isValid()) {
        mScheduler->addPresentFence(std::move(presentFenceTime));
    }

    const bool isDisplayConnected =
@@ -2486,9 +2488,6 @@ void SurfaceFlinger::postComposition() {
        }
    }

    mTimeStats->incrementTotalFrames();
    mTimeStats->setPresentFenceGlobal(mPreviousPresentFences[0].fenceTime);

    const size_t sfConnections = mScheduler->getEventThreadConnectionCount(mSfConnectionHandle);
    const size_t appConnections = mScheduler->getEventThreadConnectionCount(mAppConnectionHandle);
    mTimeStats->recordDisplayEventConnectionCount(sfConnections + appConnections);
@@ -2498,20 +2497,19 @@ void SurfaceFlinger::postComposition() {
        return;
    }

    nsecs_t currentTime = systemTime();
    if (mHasPoweredOff) {
        mHasPoweredOff = false;
    } else {
        nsecs_t elapsedTime = currentTime - getBE().mLastSwapTime;
        const size_t numPeriods = static_cast<size_t>(elapsedTime / vsyncPeriod.ns());
        const Duration elapsedTime = presentTime - getBE().mLastPresentTime;
        const size_t numPeriods = static_cast<size_t>(elapsedTime.ns() / vsyncPeriod.ns());
        if (numPeriods < SurfaceFlingerBE::NUM_BUCKETS - 1) {
            getBE().mFrameBuckets[numPeriods] += elapsedTime;
            getBE().mFrameBuckets[numPeriods] += elapsedTime.ns();
        } else {
            getBE().mFrameBuckets[SurfaceFlingerBE::NUM_BUCKETS - 1] += elapsedTime;
            getBE().mFrameBuckets[SurfaceFlingerBE::NUM_BUCKETS - 1] += elapsedTime.ns();
        }
        getBE().mTotalTime += elapsedTime;
        getBE().mTotalTime += elapsedTime.ns();
    }
    getBE().mLastSwapTime = currentTime;
    getBE().mLastPresentTime = presentTime;

    // Cleanup any outstanding resources due to rendering a prior frame.
    getRenderEngine().cleanupPostRender();
@@ -2539,6 +2537,8 @@ void SurfaceFlinger::postComposition() {
        // getTotalSize returns the total number of buffers that were allocated by SurfaceFlinger
        ATRACE_INT64("Total Buffer Size", GraphicBufferAllocator::get().getTotalSize());
    }

    logFrameStats(presentTime);
}

FloatRect SurfaceFlinger::getMaxDisplayBounds() {
@@ -2571,16 +2571,6 @@ void SurfaceFlinger::computeLayerBounds() {
    }
}

void SurfaceFlinger::postFrame() {
    const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked());
    if (display && getHwComposer().isConnected(display->getPhysicalId())) {
        uint32_t flipCount = display->getPageFlipCount();
        if (flipCount % LOG_FRAME_STATS_PERIOD == 0) {
            logFrameStats();
        }
    }
}

void SurfaceFlinger::commitTransactions() {
    ATRACE_CALL();

@@ -4956,7 +4946,14 @@ void SurfaceFlinger::dumpFrameTimeline(const DumpArgs& args, std::string& result
    mFrameTimeline->parseArgs(args, result);
}

void SurfaceFlinger::logFrameStats() {
void SurfaceFlinger::logFrameStats(TimePoint now) {
    using namespace std::chrono_literals;

    static TimePoint sTimestamp = now;
    if (now - sTimestamp < 30min) return;
    sTimestamp = now;

    ATRACE_CALL();
    mDrawingState.traverse([&](Layer* layer) { layer->logFrameStats(); });
}

@@ -5560,15 +5557,8 @@ status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* r
                reply->writeInt32(0);
                reply->writeInt32(mDebugDisableHWC);
                return NO_ERROR;
            case 1013: {
                const auto display = getDefaultDisplayDevice();
                if (!display) {
            case 1013: // Unused.
                return NAME_NOT_FOUND;
                }

                reply->writeInt32(display->getPageFlipCount());
                return NO_ERROR;
            }
            case 1014: {
                Mutex::Autolock _l(mStateLock);
                // daltonize
+3 −30
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@
#include <compositionengine/OutputColorSetting.h>
#include <scheduler/Fps.h>
#include <scheduler/PresentLatencyTracker.h>
#include <scheduler/Time.h>

#include "ClientCache.h"
#include "DisplayDevice.h"
@@ -174,7 +175,7 @@ struct SurfaceFlingerBE {
    static const size_t NUM_BUCKETS = 8; // < 1-7, 7+
    nsecs_t mFrameBuckets[NUM_BUCKETS] = {};
    nsecs_t mTotalTime = 0;
    std::atomic<nsecs_t> mLastSwapTime = 0;
    TimePoint mLastPresentTime;
};

class SurfaceFlinger : public BnSurfaceComposer,
@@ -197,29 +198,6 @@ public:

    static char const* getServiceName() ANDROID_API { return "SurfaceFlinger"; }

    // This is the phase offset in nanoseconds of the software vsync event
    // relative to the vsync event reported by HWComposer.  The software vsync
    // event is when SurfaceFlinger and Choreographer-based applications run each
    // frame.
    //
    // This phase offset allows adjustment of the minimum latency from application
    // wake-up time (by Choreographer) to the time at which the resulting window
    // image is displayed.  This value may be either positive (after the HW vsync)
    // or negative (before the HW vsync). Setting it to 0 will result in a lower
    // latency bound of two vsync periods because the app and SurfaceFlinger
    // will run just after the HW vsync.  Setting it to a positive number will
    // result in the minimum latency being:
    //
    //     (2 * VSYNC_PERIOD - (vsyncPhaseOffsetNs % VSYNC_PERIOD))
    //
    // Note that reducing this latency makes it more likely for the applications
    // to not have their window content image ready in time.  When this happens
    // the latency will end up being an additional vsync period, and animations
    // will hiccup.  Therefore, this latency should be tuned somewhat
    // conservatively (or at least with awareness of the trade-off being made).
    static int64_t vsyncPhaseOffsetNs;
    static int64_t sfVsyncPhaseOffsetNs;

    // If fences from sync Framework are supported.
    static bool hasSyncFramework;

@@ -386,10 +364,6 @@ private:
    using DumpArgs = Vector<String16>;
    using Dumper = std::function<void(const DumpArgs&, bool asProto, std::string&)>;

    // This value is specified in number of frames.  Log frame stats at most
    // every half hour.
    enum { LOG_FRAME_STATS_PERIOD =  30*60*60 };

    class State {
    public:
        explicit State(LayerVector::StateSet set) : stateSet(set), layersSortedByZ(set) {}
@@ -938,7 +912,6 @@ private:
     * Compositing
     */
    void postComposition() REQUIRES(kMainThreadContext);
    void postFrame() REQUIRES(kMainThreadContext);

    /*
     * Display management
@@ -1038,7 +1011,7 @@ private:
    void clearStatsLocked(const DumpArgs& args, std::string& result);
    void dumpTimeStats(const DumpArgs& args, bool asProto, std::string& result) const;
    void dumpFrameTimeline(const DumpArgs& args, std::string& result) const;
    void logFrameStats() REQUIRES(kMainThreadContext);
    void logFrameStats(TimePoint now) REQUIRES(kMainThreadContext);

    void dumpVSync(std::string& result) const REQUIRES(mStateLock);
    void dumpStaticScreenStats(std::string& result) const;
Loading