Skip to content

Commit 969e7ea

Browse files
Treehugger RobotAndroid (Google) Code Review
authored andcommitted
Merge changes I60d42f38,I25857739 into main
* changes: Ensure Choreographer is held as sp<> in SurfaceControl. Harden construction sites of android::StrongPointer in frameworks/native
2 parents 4b52779 + 9045666 commit 969e7ea

File tree

12 files changed

+15
-15
lines changed

12 files changed

+15
-15
lines changed

cmds/flatland/GLHelper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ bool GLHelper::createWindowSurface(uint32_t w, uint32_t h,
241241
status_t err;
242242

243243
if (mSurfaceComposerClient == nullptr) {
244-
mSurfaceComposerClient = new SurfaceComposerClient;
244+
mSurfaceComposerClient = sp<SurfaceComposerClient>::make();
245245
}
246246
err = mSurfaceComposerClient->initCheck();
247247
if (err != NO_ERROR) {

libs/gui/SurfaceControl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ const std::string& SurfaceControl::getName() const {
194194
return mName;
195195
}
196196

197-
std::shared_ptr<Choreographer> SurfaceControl::getChoreographer() {
197+
sp<Choreographer> SurfaceControl::getChoreographer() {
198198
if (mChoreographer) {
199199
return mChoreographer;
200200
}
@@ -203,7 +203,7 @@ std::shared_ptr<Choreographer> SurfaceControl::getChoreographer() {
203203
ALOGE("%s: No looper prepared for thread", __func__);
204204
return nullptr;
205205
}
206-
mChoreographer = std::make_shared<Choreographer>(looper, getHandle());
206+
mChoreographer = sp<Choreographer>::make(looper, getHandle());
207207
status_t result = mChoreographer->initialize();
208208
if (result != OK) {
209209
ALOGE("Failed to initialize choreographer");

libs/gui/include/gui/SurfaceControl.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include <android/gui/ISurfaceComposerClient.h>
2828

29+
#include <gui/Choreographer.h>
2930
#include <ui/FrameStats.h>
3031
#include <ui/PixelFormat.h>
3132
#include <ui/Region.h>
@@ -36,7 +37,6 @@ namespace android {
3637

3738
// ---------------------------------------------------------------------------
3839

39-
class Choreographer;
4040
class IGraphicBufferProducer;
4141
class Surface;
4242
class SurfaceComposerClient;
@@ -82,7 +82,7 @@ class SurfaceControl : public RefBase
8282
const std::string& getName() const;
8383

8484
// TODO(b/267195698): Consider renaming.
85-
std::shared_ptr<Choreographer> getChoreographer();
85+
sp<Choreographer> getChoreographer();
8686

8787
sp<IGraphicBufferProducer> getIGraphicBufferProducer();
8888

@@ -134,7 +134,7 @@ class SurfaceControl : public RefBase
134134
PixelFormat mFormat = PIXEL_FORMAT_NONE;
135135
uint32_t mCreateFlags = 0;
136136
uint64_t mFallbackFrameNumber = 100;
137-
std::shared_ptr<Choreographer> mChoreographer;
137+
sp<Choreographer> mChoreographer;
138138
};
139139

140140
}; // namespace android

libs/gui/tests/BLASTBufferQueue_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ class BLASTBufferQueueTest : public ::testing::Test {
201201
protected:
202202
void SetUp() {
203203
mComposer = ComposerService::getComposerService();
204-
mClient = new SurfaceComposerClient();
204+
mClient = sp<SurfaceComposerClient>::make();
205205
const auto ids = SurfaceComposerClient::getPhysicalDisplayIds();
206206
ASSERT_FALSE(ids.empty());
207207
// display 0 is picked as this test is not much display depedent

libs/gui/tests/DisplayedContentSampling_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static constexpr uint32_t INVALID_MASK = 0x10;
3030
class DisplayedContentSamplingTest : public ::testing::Test {
3131
protected:
3232
void SetUp() {
33-
mComposerClient = new SurfaceComposerClient;
33+
mComposerClient = sp<SurfaceComposerClient>::make();
3434
ASSERT_EQ(OK, mComposerClient->initCheck());
3535
const auto ids = SurfaceComposerClient::getPhysicalDisplayIds();
3636
ASSERT_FALSE(ids.empty());

libs/gui/tests/EndToEndNativeInputTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ class InputSurfacesTest : public ::testing::Test {
398398
InputSurfacesTest() { ProcessState::self()->startThreadPool(); }
399399

400400
void SetUp() {
401-
mComposerClient = new SurfaceComposerClient;
401+
mComposerClient = sp<SurfaceComposerClient>::make();
402402
ASSERT_EQ(NO_ERROR, mComposerClient->initCheck());
403403
const auto ids = SurfaceComposerClient::getPhysicalDisplayIds();
404404
ASSERT_FALSE(ids.empty());

libs/gui/tests/GLTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void GLTest::SetUp() {
5656
}
5757

5858
if (mDisplaySecs > 0) {
59-
mComposerClient = new SurfaceComposerClient;
59+
mComposerClient = sp<SurfaceComposerClient>::make();
6060
ASSERT_EQ(NO_ERROR, mComposerClient->initCheck());
6161

6262
mSurfaceControl = mComposerClient->createSurface(

libs/gui/tests/RegionSampling_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ struct RegionSamplingTest : ::testing::Test {
180180
}
181181

182182
void SetUp() override {
183-
mSurfaceComposerClient = new SurfaceComposerClient;
183+
mSurfaceComposerClient = sp<SurfaceComposerClient>::make();
184184
ASSERT_EQ(NO_ERROR, mSurfaceComposerClient->initCheck());
185185

186186
mBackgroundLayer =

libs/gui/tests/SamplingDemo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace android {
3636
class Button : public gui::BnRegionSamplingListener {
3737
public:
3838
Button(const char* name, const Rect& samplingArea) {
39-
sp<SurfaceComposerClient> client = new SurfaceComposerClient;
39+
sp<SurfaceComposerClient> client = sp<SurfaceComposerClient>::make();
4040

4141
mButton = client->createSurface(String8(name), 0, 0, PIXEL_FORMAT_RGBA_8888,
4242
ISurfaceComposerClient::eFXSurfaceEffect);

libs/gui/tests/Surface_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class SurfaceTest : public ::testing::Test {
134134
}
135135

136136
virtual void SetUp() {
137-
mComposerClient = new SurfaceComposerClient;
137+
mComposerClient = sp<SurfaceComposerClient>::make();
138138
ASSERT_EQ(NO_ERROR, mComposerClient->initCheck());
139139

140140
// TODO(brianderson): The following sometimes fails and is a source of

0 commit comments

Comments
 (0)