Skip to content

Commit f6dc853

Browse files
author
Anton Ivanov
committed
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
1 parent 1a25e57 commit f6dc853

4 files changed

Lines changed: 8 additions & 8 deletions

File tree

libs/gui/Choreographer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ namespace android {
6969

7070
Choreographer::Context Choreographer::gChoreographers;
7171

72-
static thread_local Choreographer* gChoreographer;
72+
static thread_local sp<Choreographer> gChoreographer;
7373

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

89-
Choreographer* Choreographer::getForThread() {
89+
sp<Choreographer> Choreographer::getForThread() {
9090
if (gChoreographer == nullptr) {
9191
sp<Looper> looper = Looper::getForThread();
9292
if (!looper.get()) {
9393
ALOGW("No looper prepared for thread");
9494
return nullptr;
9595
}
96-
gChoreographer = new Choreographer(looper);
96+
gChoreographer = sp<Choreographer>::make(looper);
9797
status_t result = gChoreographer->initialize();
9898
if (result != OK) {
9999
ALOGW("Failed to initialize");
100100
return nullptr;
101101
}
102102
}
103-
return gChoreographer;
103+
return gChoreographer.get();
104104
}
105105

106106
Choreographer::Choreographer(const sp<Looper>& looper, const sp<IBinder>& layerHandle)

libs/gui/include/gui/Choreographer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class Choreographer : public DisplayEventDispatcher, public MessageHandler {
103103
virtual void handleMessage(const Message& message) override;
104104

105105
static void initJVM(JNIEnv* env);
106-
static Choreographer* getForThread();
106+
static sp<Choreographer> getForThread();
107107
static void signalRefreshRateCallbacks(nsecs_t vsyncPeriod) EXCLUDES(gChoreographers.lock);
108108
static int64_t getStartTimeNanosForVsyncId(AVsyncId vsyncId) EXCLUDES(gChoreographers.lock);
109109
virtual ~Choreographer() override EXCLUDES(gChoreographers.lock);

libs/gui/tests/Choreographer_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static void vsyncCallback(const AChoreographerFrameCallbackData* callbackData, v
5050

5151
TEST_F(ChoreographerTest, InputCallbackBeforeAnimation) {
5252
sp<Looper> looper = Looper::prepare(0);
53-
Choreographer* choreographer = Choreographer::getForThread();
53+
sp<Choreographer> choreographer = Choreographer::getForThread();
5454
VsyncCallback animationCb;
5555
choreographer->postFrameCallbackDelayed(nullptr, nullptr, vsyncCallback, &animationCb, 0,
5656
CALLBACK_ANIMATION);
@@ -83,4 +83,4 @@ TEST_F(ChoreographerTest, InputCallbackBeforeAnimation) {
8383
animationCb.frameTime.count());
8484
}
8585

86-
} // namespace android
86+
} // namespace android

libs/nativedisplay/AChoreographer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ static inline AChoreographer* Choreographer_to_AChoreographer(Choreographer* cho
142142
}
143143

144144
AChoreographer* AChoreographer_getInstance() {
145-
return Choreographer_to_AChoreographer(Choreographer::getForThread());
145+
return Choreographer_to_AChoreographer(Choreographer::getForThread().get());
146146
}
147147

148148
void AChoreographer_postFrameCallback(AChoreographer* choreographer,

0 commit comments

Comments
 (0)