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

Commit f6dc8535 authored by Anton Ivanov's avatar Anton Ivanov
Browse files

Construct Choreographer with sp<>::make().

The instance consructed in this way is passed to call sites expecting
sp<>, so it must be constructed as such.

Bug: 393217449
Test: presubmit
Flag: EXEMPT_refactor
Change-Id: I34d5be7c6abf5b37472a79be80ac10cd07dd731c
parent 1a25e57a
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@ namespace android {

Choreographer::Context Choreographer::gChoreographers;

static thread_local Choreographer* gChoreographer;
static thread_local sp<Choreographer> gChoreographer;

void Choreographer::initJVM(JNIEnv* env) {
    env->GetJavaVM(&gJni.jvm);
@@ -86,21 +86,21 @@ void Choreographer::initJVM(JNIEnv* env) {
                             "()V");
}

Choreographer* Choreographer::getForThread() {
sp<Choreographer> Choreographer::getForThread() {
    if (gChoreographer == nullptr) {
        sp<Looper> looper = Looper::getForThread();
        if (!looper.get()) {
            ALOGW("No looper prepared for thread");
            return nullptr;
        }
        gChoreographer = new Choreographer(looper);
        gChoreographer = sp<Choreographer>::make(looper);
        status_t result = gChoreographer->initialize();
        if (result != OK) {
            ALOGW("Failed to initialize");
            return nullptr;
        }
    }
    return gChoreographer;
    return gChoreographer.get();
}

Choreographer::Choreographer(const sp<Looper>& looper, const sp<IBinder>& layerHandle)
+1 −1
Original line number Diff line number Diff line
@@ -103,7 +103,7 @@ public:
    virtual void handleMessage(const Message& message) override;

    static void initJVM(JNIEnv* env);
    static Choreographer* getForThread();
    static sp<Choreographer> getForThread();
    static void signalRefreshRateCallbacks(nsecs_t vsyncPeriod) EXCLUDES(gChoreographers.lock);
    static int64_t getStartTimeNanosForVsyncId(AVsyncId vsyncId) EXCLUDES(gChoreographers.lock);
    virtual ~Choreographer() override EXCLUDES(gChoreographers.lock);
+2 −2
Original line number Diff line number Diff line
@@ -50,7 +50,7 @@ static void vsyncCallback(const AChoreographerFrameCallbackData* callbackData, v

TEST_F(ChoreographerTest, InputCallbackBeforeAnimation) {
    sp<Looper> looper = Looper::prepare(0);
    Choreographer* choreographer = Choreographer::getForThread();
    sp<Choreographer> choreographer = Choreographer::getForThread();
    VsyncCallback animationCb;
    choreographer->postFrameCallbackDelayed(nullptr, nullptr, vsyncCallback, &animationCb, 0,
                                            CALLBACK_ANIMATION);
+1 −1
Original line number Diff line number Diff line
@@ -142,7 +142,7 @@ static inline AChoreographer* Choreographer_to_AChoreographer(Choreographer* cho
}

AChoreographer* AChoreographer_getInstance() {
    return Choreographer_to_AChoreographer(Choreographer::getForThread());
    return Choreographer_to_AChoreographer(Choreographer::getForThread().get());
}

void AChoreographer_postFrameCallback(AChoreographer* choreographer,