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

Commit 756b7891 authored by Dominik Laskowski's avatar Dominik Laskowski
Browse files

SF: Move MessageQueue to Scheduler

...as a first step in removing the ISchedulerCallback::scheduleComposite
roundtrip, and extracting scheduling logic from SF::{commit,composite}.

Bug: 185535769
Test: libsurfaceflinger_unittest
Change-Id: I7fb38a1dd7b917e5639b9d58a0d44b32983b689e
parent 33ff59aa
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -117,8 +117,8 @@ private:
    }
};

Scheduler::Scheduler(ISchedulerCallback& callback, Options options)
      : mOptions(options), mSchedulerCallback(callback) {}
Scheduler::Scheduler(ICompositor& compositor, ISchedulerCallback& callback, Options options)
      : impl::MessageQueue(compositor), mOptions(options), mSchedulerCallback(callback) {}

void Scheduler::startTimers() {
    using namespace sysprop;
@@ -148,6 +148,12 @@ Scheduler::~Scheduler() {
    mRefreshRateConfigs.reset();
}

void Scheduler::run() {
    while (true) {
        waitMessage();
    }
}

void Scheduler::createVsyncSchedule(bool supportKernelTimer) {
    auto clock = std::make_unique<scheduler::SystemClock>();
    auto tracker = createVSyncTracker();
+25 −3
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@

#include <atomic>
#include <functional>
#include <future>
#include <memory>
#include <mutex>
#include <optional>
@@ -32,6 +33,7 @@

#include "EventThread.h"
#include "LayerHistory.h"
#include "MessageQueue.h"
#include "OneShotTimer.h"
#include "RefreshRateConfigs.h"
#include "SchedulerUtils.h"
@@ -70,21 +72,41 @@ protected:
    ~ISchedulerCallback() = default;
};

class Scheduler {
class Scheduler : impl::MessageQueue {
    using Impl = impl::MessageQueue;

public:
    using RefreshRate = scheduler::RefreshRateConfigs::RefreshRate;
    using ModeEvent = scheduler::RefreshRateConfigEvent;

    struct Options {
        // Whether to use content detection at all.
        bool useContentDetection = false;
        bool useContentDetection;
    };

    Scheduler(ISchedulerCallback&, Options);
    Scheduler(ICompositor&, ISchedulerCallback&, Options);
    ~Scheduler();

    void createVsyncSchedule(bool supportKernelIdleTimer);
    void startTimers();
    void run();

    using Impl::initVsync;
    using Impl::setInjector;

    using Impl::getScheduledFrameTime;
    using Impl::setDuration;

    using Impl::scheduleCommit;
    using Impl::scheduleComposite;

    // Schedule an asynchronous or synchronous task on the main thread.
    template <typename F, typename T = std::invoke_result_t<F>>
    [[nodiscard]] std::future<T> schedule(F&& f) {
        auto [task, future] = makeTask(std::move(f));
        postMessage(std::move(task));
        return std::move(future);
    }

    using ConnectionHandle = scheduler::ConnectionHandle;
    ConnectionHandle createConnection(const char* connectionName, frametimeline::TokenManager*,
+144 −134

File changed.

Preview size limit exceeded, changes collapsed.

+1 −11
Original line number Diff line number Diff line
@@ -56,7 +56,6 @@
#include "Fps.h"
#include "FrameTracker.h"
#include "LayerVector.h"
#include "Scheduler/MessageQueue.h"
#include "Scheduler/RefreshRateConfigs.h"
#include "Scheduler/RefreshRateStats.h"
#include "Scheduler/Scheduler.h"
@@ -265,10 +264,6 @@ public:
    SurfaceFlingerBE& getBE() { return mBE; }
    const SurfaceFlingerBE& getBE() const { return mBE; }

    // Schedule an asynchronous or synchronous task on the main thread.
    template <typename F, typename T = std::invoke_result_t<F>>
    [[nodiscard]] std::future<T> schedule(F&&);

    // Schedule commit of transactions on the main thread ahead of the next VSYNC.
    void scheduleCommit(FrameHint);
    // As above, but also force composite regardless if transactions were committed.
@@ -1206,14 +1201,9 @@ private:

    TransactionCallbackInvoker mTransactionCallbackInvoker;

    // these are thread safe
    std::unique_ptr<MessageQueue> mEventQueue;
    // Thread-safe.
    FrameTracker mAnimFrameTracker;

    // protected by mDestroyedLayerLock;
    mutable Mutex mDestroyedLayerLock;
    Vector<Layer const *> mDestroyedLayers;

    // We maintain a pool of pre-generated texture names to hand out to avoid
    // layer creation needing to run on the main thread (which it would
    // otherwise need to do to access RenderEngine).
+0 −5

File changed.

Preview size limit exceeded, changes collapsed.

Loading