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

Commit 98041835 authored by Dominik Laskowski's avatar Dominik Laskowski
Browse files

SF: Clean up Scheduler

Remove dynamic allocation for Scheduler::{Connection,ConnectionHandle},
as well as ref-counting for the latter. Also, remove dead code and make
members private.

Bug: 130554049
Test: libsurfaceflinger_unittest
Change-Id: Ibb9dc8d4cb66451a4172c852a36032bbc0a54411
parent 13db07b6
Loading
Loading
Loading
Loading
+10 −13
Original line number Diff line number Diff line
@@ -21,15 +21,18 @@

#include "RegionSamplingThread.h"

#include <compositionengine/Display.h>
#include <compositionengine/impl/OutputCompositionState.h>
#include <cutils/properties.h>
#include <gui/IRegionSamplingListener.h>
#include <ui/DisplayStatInfo.h>
#include <utils/Trace.h>

#include <string>

#include <compositionengine/Display.h>
#include <compositionengine/impl/OutputCompositionState.h>
#include "DisplayDevice.h"
#include "Layer.h"
#include "Scheduler/DispSync.h"
#include "SurfaceFlinger.h"

namespace android {
@@ -105,9 +108,8 @@ struct SamplingOffsetCallback : DispSync::Callback {
        if (mVsyncListening) return;

        mPhaseIntervalSetting = Phase::ZERO;
        mScheduler.withPrimaryDispSync([this](android::DispSync& sync) {
            sync.addEventListener("SamplingThreadDispSyncListener", 0, this, mLastCallbackTime);
        });
        mScheduler.getPrimaryDispSync().addEventListener("SamplingThreadDispSyncListener", 0, this,
                                                         mLastCallbackTime);
        mVsyncListening = true;
    }

@@ -120,9 +122,7 @@ private:
    void stopVsyncListenerLocked() /*REQUIRES(mMutex)*/ {
        if (!mVsyncListening) return;

        mScheduler.withPrimaryDispSync([this](android::DispSync& sync) {
            sync.removeEventListener(this, &mLastCallbackTime);
        });
        mScheduler.getPrimaryDispSync().removeEventListener(this, &mLastCallbackTime);
        mVsyncListening = false;
    }

@@ -132,16 +132,13 @@ private:
        if (mPhaseIntervalSetting == Phase::ZERO) {
            ATRACE_INT(lumaSamplingStepTag, static_cast<int>(samplingStep::waitForSamplePhase));
            mPhaseIntervalSetting = Phase::SAMPLING;
            mScheduler.withPrimaryDispSync([this](android::DispSync& sync) {
                sync.changePhaseOffset(this, mTargetSamplingOffset.count());
            });
            mScheduler.getPrimaryDispSync().changePhaseOffset(this, mTargetSamplingOffset.count());
            return;
        }

        if (mPhaseIntervalSetting == Phase::SAMPLING) {
            mPhaseIntervalSetting = Phase::ZERO;
            mScheduler.withPrimaryDispSync(
                    [this](android::DispSync& sync) { sync.changePhaseOffset(this, 0); });
            mScheduler.getPrimaryDispSync().changePhaseOffset(this, 0);
            stopVsyncListenerLocked();
            lock.unlock();
            mRegionSamplingThread.notifySamplingOffset();
+8 −11
Original line number Diff line number Diff line
@@ -462,22 +462,14 @@ private:
    TracedOrdinal<bool> mParity;
};

DispSync::DispSync(const char* name) : mName(name), mRefreshSkipCount(0) {
DispSync::DispSync(const char* name, bool hasSyncFramework)
      : mName(name), mIgnorePresentFences(!hasSyncFramework) {
    // This flag offers the ability to turn on systrace logging from the shell.
    char value[PROPERTY_VALUE_MAX];
    property_get("debug.sf.dispsync_trace_detailed_info", value, "0");
    mTraceDetailedInfo = atoi(value);
    mThread = new DispSyncThread(name, mTraceDetailedInfo);
}

DispSync::~DispSync() {
    mThread->stop();
    mThread->requestExitAndWait();
}

void DispSync::init(bool hasSyncFramework, int64_t dispSyncPresentTimeOffset) {
    mIgnorePresentFences = !hasSyncFramework;
    mPresentTimeOffset = dispSyncPresentTimeOffset;
    mThread = new DispSyncThread(name, mTraceDetailedInfo);
    mThread->run("DispSync", PRIORITY_URGENT_DISPLAY + PRIORITY_MORE_FAVORABLE);

    // set DispSync to SCHED_FIFO to minimize jitter
@@ -495,6 +487,11 @@ void DispSync::init(bool hasSyncFramework, int64_t dispSyncPresentTimeOffset) {
    }
}

DispSync::~DispSync() {
    mThread->stop();
    mThread->requestExitAndWait();
}

void DispSync::reset() {
    Mutex::Autolock lock(mMutex);
    resetLocked();
+3 −8
Original line number Diff line number Diff line
@@ -88,11 +88,10 @@ class DispSyncThread;
// needed.
class DispSync : public android::DispSync {
public:
    explicit DispSync(const char* name);
    // hasSyncFramework specifies whether the platform supports present fences.
    DispSync(const char* name, bool hasSyncFramework);
    ~DispSync() override;

    void init(bool hasSyncFramework, int64_t dispSyncPresentTimeOffset);

    // reset clears the resync samples and error value.
    void reset() override;

@@ -252,7 +251,7 @@ private:
    std::shared_ptr<FenceTime> mPresentFences[NUM_PRESENT_SAMPLES]{FenceTime::NO_FENCE};
    size_t mPresentSampleOffset;

    int mRefreshSkipCount;
    int mRefreshSkipCount = 0;

    // mThread is the thread from which all the callbacks are called.
    sp<DispSyncThread> mThread;
@@ -260,10 +259,6 @@ private:
    // mMutex is used to protect access to all member variables.
    mutable Mutex mMutex;

    // This is the offset from the present fence timestamps to the corresponding
    // vsync event.
    int64_t mPresentTimeOffset;

    // Ignore present (retire) fences if the device doesn't have support for the
    // sync framework
    bool mIgnorePresentFences;
+1 −1
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ EventControlThread::~EventControlThread() = default;
namespace impl {

EventControlThread::EventControlThread(EventControlThread::SetVSyncEnabledFunction function)
      : mSetVSyncEnabled(function) {
      : mSetVSyncEnabled(std::move(function)) {
    pthread_setname_np(mThread.native_handle(), "EventControlThread");

    pid_t tid = pthread_gettid_np(mThread.native_handle());
+2 −0
Original line number Diff line number Diff line
@@ -39,6 +39,8 @@ public:
                 const TimeoutCallback& timeoutCallback);
    ~OneShotTimer();

    const Interval& interval() const { return mInterval; }

    // Initializes and turns on the idle timer.
    void start();
    // Stops the idle timer and any held resources.
Loading