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

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

Merge changes I6618561d,If9479cd9,I3e13894e into pi-dev

* changes:
  SF: Test coverage for EventControlThread
  SF: Test coverage for EventThread
  SF: Test coverage for setPowerModeInternal
parents 4863737d 117510d0
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -26,8 +26,6 @@

namespace android {

class SurfaceFlinger;

class EventControlThread {
public:
    virtual ~EventControlThread();
+10 −8
Original line number Diff line number Diff line
@@ -26,14 +26,12 @@
#include <cutils/sched_policy.h>

#include <gui/DisplayEventReceiver.h>
#include <gui/IDisplayEventConnection.h>

#include <utils/Errors.h>
#include <utils/String8.h>
#include <utils/Trace.h>

#include "EventThread.h"
#include "SurfaceFlinger.h"

using namespace std::chrono_literals;

@@ -47,9 +45,11 @@ EventThread::~EventThread() = default;

namespace impl {

EventThread::EventThread(VSyncSource* src, SurfaceFlinger& flinger, bool interceptVSyncs,
                         const char* threadName)
      : mVSyncSource(src), mFlinger(flinger), mInterceptVSyncs(interceptVSyncs) {
EventThread::EventThread(VSyncSource* src, ResyncWithRateLimitCallback resyncWithRateLimitCallback,
                         InterceptVSyncsCallback interceptVSyncsCallback, const char* threadName)
      : mVSyncSource(src),
        mResyncWithRateLimitCallback(resyncWithRateLimitCallback),
        mInterceptVSyncsCallback(interceptVSyncsCallback) {
    for (auto& event : mVSyncEvent) {
        event.header.type = DisplayEventReceiver::DISPLAY_EVENT_VSYNC;
        event.header.id = 0;
@@ -118,7 +118,9 @@ void EventThread::setVsyncRate(uint32_t count, const sp<EventThread::Connection>
void EventThread::requestNextVsync(const sp<EventThread::Connection>& connection) {
    std::lock_guard<std::mutex> lock(mMutex);

    mFlinger.resyncWithRateLimit();
    if (mResyncWithRateLimitCallback) {
        mResyncWithRateLimitCallback();
    }

    if (connection->count < 0) {
        connection->count = 0;
@@ -216,8 +218,8 @@ Vector<sp<EventThread::Connection> > EventThread::waitForEventLocked(
            timestamp = mVSyncEvent[i].header.timestamp;
            if (timestamp) {
                // we have a vsync event to dispatch
                if (mInterceptVSyncs) {
                    mFlinger.mInterceptor->saveVSyncEvent(timestamp);
                if (mInterceptVSyncsCallback) {
                    mInterceptVSyncsCallback(timestamp);
                }
                *event = mVSyncEvent[i];
                mVSyncEvent[i].header.timestamp = 0;
+14 −8
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@
namespace android {
// ---------------------------------------------------------------------------

class EventThreadTest;
class SurfaceFlinger;
class String8;

@@ -82,7 +83,9 @@ class EventThread : public android::EventThread, private VSyncSource::Callback {
    class Connection : public BnDisplayEventConnection {
    public:
        explicit Connection(EventThread* eventThread);
        status_t postEvent(const DisplayEventReceiver::Event& event);
        virtual ~Connection();

        virtual status_t postEvent(const DisplayEventReceiver::Event& event);

        // count >= 1 : continuous event. count is the vsync rate
        // count == 0 : one-shot event that has not fired
@@ -90,7 +93,6 @@ class EventThread : public android::EventThread, private VSyncSource::Callback {
        int32_t count;

    private:
        virtual ~Connection();
        virtual void onFirstRef();
        status_t stealReceiveChannel(gui::BitTube* outChannel) override;
        status_t setVsyncRate(uint32_t count) override;
@@ -100,8 +102,11 @@ class EventThread : public android::EventThread, private VSyncSource::Callback {
    };

public:
    EventThread(VSyncSource* src, SurfaceFlinger& flinger, bool interceptVSyncs,
                const char* threadName);
    using ResyncWithRateLimitCallback = std::function<void()>;
    using InterceptVSyncsCallback = std::function<void(nsecs_t)>;

    EventThread(VSyncSource* src, ResyncWithRateLimitCallback resyncWithRateLimitCallback,
                InterceptVSyncsCallback interceptVSyncsCallback, const char* threadName);
    ~EventThread();

    sp<BnDisplayEventConnection> createEventConnection() const override;
@@ -124,6 +129,8 @@ public:
    void setPhaseOffset(nsecs_t phaseOffset) override;

private:
    friend EventThreadTest;

    void threadMain();
    Vector<sp<EventThread::Connection>> waitForEventLocked(std::unique_lock<std::mutex>* lock,
                                                           DisplayEventReceiver::Event* event)
@@ -137,8 +144,9 @@ private:
    void onVSyncEvent(nsecs_t timestamp) override;

    // constants
    VSyncSource* mVSyncSource GUARDED_BY(mMutex) = nullptr;
    SurfaceFlinger& mFlinger;
    VSyncSource* const mVSyncSource GUARDED_BY(mMutex) = nullptr;
    const ResyncWithRateLimitCallback mResyncWithRateLimitCallback;
    const InterceptVSyncsCallback mInterceptVSyncsCallback;

    std::thread mThread;
    mutable std::mutex mMutex;
@@ -155,8 +163,6 @@ private:

    // for debugging
    bool mDebugVsyncEnabled GUARDED_BY(mMutex) = false;

    const bool mInterceptVSyncs = false;
};

// ---------------------------------------------------------------------------
+15 −6
Original line number Diff line number Diff line
@@ -635,13 +635,20 @@ void SurfaceFlinger::init() {
    mEventThreadSource =
            std::make_unique<DispSyncSource>(&mPrimaryDispSync, SurfaceFlinger::vsyncPhaseOffsetNs,
                                             true, "app");
    mEventThread = std::make_unique<impl::EventThread>(mEventThreadSource.get(), *this, false,
    mEventThread = std::make_unique<impl::EventThread>(mEventThreadSource.get(),
                                                       [this]() { resyncWithRateLimit(); },
                                                       impl::EventThread::InterceptVSyncsCallback(),
                                                       "appEventThread");
    mSfEventThreadSource =
            std::make_unique<DispSyncSource>(&mPrimaryDispSync,
                                             SurfaceFlinger::sfVsyncPhaseOffsetNs, true, "sf");

    mSFEventThread = std::make_unique<impl::EventThread>(mSfEventThreadSource.get(), *this, true,
    mSFEventThread =
            std::make_unique<impl::EventThread>(mSfEventThreadSource.get(),
                                                [this]() { resyncWithRateLimit(); },
                                                [this](nsecs_t timestamp) {
                                                    mInterceptor->saveVSyncEvent(timestamp);
                                                },
                                                "sfEventThread");
    mEventQueue->setEventThread(mSFEventThread.get());
    mVsyncModulator.setEventThread(mSFEventThread.get());
@@ -1131,8 +1138,10 @@ status_t SurfaceFlinger::enableVSyncInjections(bool enable) {
            ALOGV("VSync Injections enabled");
            if (mVSyncInjector.get() == nullptr) {
                mVSyncInjector = std::make_unique<InjectVSyncSource>();
                mInjectorEventThread =
                        std::make_unique<impl::EventThread>(mVSyncInjector.get(), *this, false,
                mInjectorEventThread = std::make_unique<
                        impl::EventThread>(mVSyncInjector.get(),
                                           [this]() { resyncWithRateLimit(); },
                                           impl::EventThread::InterceptVSyncsCallback(),
                                           "injEventThread");
            }
            mEventQueue->setEventThread(mInjectorEventThread.get());
+2 −0
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ cc_test {
    srcs: [
        ":libsurfaceflinger_sources",
        "DisplayTransactionTest.cpp",
        "EventControlThreadTest.cpp",
        "EventThreadTest.cpp",
        "mock/DisplayHardware/MockComposer.cpp",
        "mock/DisplayHardware/MockDisplaySurface.cpp",
        "mock/gui/MockGraphicBufferConsumer.cpp",
Loading