summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Anton Ivanov <aii@google.com> 2025-03-03 11:38:32 -0800
committer Android (Google) Code Review <android-gerrit@google.com> 2025-03-03 11:38:32 -0800
commitc9eb89a948b1a5f707715ba59aa26e25c0bdb8c2 (patch)
tree0574ed75b803e176ddd5e69abfcd2295a494fa3b
parentd86e469813603cc42d8cd9cf380bbc1cfaa12539 (diff)
parenta4c448d5f17cbf3e24755dabb9b06509960274ec (diff)
Merge "Harden construction sites of android::Surface." into main
-rw-r--r--cmds/bootanimation/BootAnimation.cpp2
-rw-r--r--core/jni/android_media_ImageWriter.cpp2
-rw-r--r--core/jni/android_view_Surface.cpp8
-rw-r--r--core/jni/android_view_SurfaceSession.cpp8
-rw-r--r--core/jni/android_view_TextureView.cpp2
-rw-r--r--core/jni/com_google_android_gles_jni_EGLImpl.cpp2
-rw-r--r--native/android/surface_control.cpp2
7 files changed, 13 insertions, 13 deletions
diff --git a/cmds/bootanimation/BootAnimation.cpp b/cmds/bootanimation/BootAnimation.cpp
index 844e52c3ecf2..b0070c5faa36 100644
--- a/cmds/bootanimation/BootAnimation.cpp
+++ b/cmds/bootanimation/BootAnimation.cpp
@@ -207,7 +207,7 @@ BootAnimation::BootAnimation(sp<Callbacks> callbacks)
: Thread(false), mLooper(new Looper(false)), mClockEnabled(true), mTimeIsAccurate(false),
mTimeFormat12Hour(false), mTimeCheckThread(nullptr), mCallbacks(callbacks) {
ATRACE_CALL();
- mSession = new SurfaceComposerClient();
+ mSession = sp<SurfaceComposerClient>::make();
std::string powerCtl = android::base::GetProperty("sys.powerctl", "");
if (powerCtl.empty()) {
diff --git a/core/jni/android_media_ImageWriter.cpp b/core/jni/android_media_ImageWriter.cpp
index 1357dd842ff1..8e58922bd9df 100644
--- a/core/jni/android_media_ImageWriter.cpp
+++ b/core/jni/android_media_ImageWriter.cpp
@@ -399,7 +399,7 @@ static jlong ImageWriter_init(JNIEnv* env, jobject thiz, jobject weakThiz, jobje
}
sp<JNIImageWriterContext> ctx(new JNIImageWriterContext(env, weakThiz, clazz));
- sp<Surface> producer = new Surface(bufferProducer, /*controlledByApp*/false);
+ sp<Surface> producer = sp<Surface>::make(bufferProducer, /*controlledByApp*/ false);
ctx->setProducer(producer);
/**
* NATIVE_WINDOW_API_CPU isn't a good choice here, as it makes the bufferQueue not connectable
diff --git a/core/jni/android_view_Surface.cpp b/core/jni/android_view_Surface.cpp
index 312c2067d396..783daec82b9e 100644
--- a/core/jni/android_view_Surface.cpp
+++ b/core/jni/android_view_Surface.cpp
@@ -139,7 +139,7 @@ jobject android_view_Surface_createFromIGraphicBufferProducer(JNIEnv* env,
return NULL;
}
- sp<Surface> surface(new Surface(bufferProducer, true));
+ sp<Surface> surface = sp<Surface>::make(bufferProducer, true);
return android_view_Surface_createFromSurface(env, surface);
}
@@ -161,7 +161,7 @@ static jlong nativeCreateFromSurfaceTexture(JNIEnv* env, jclass clazz,
return 0;
}
- sp<Surface> surface(new Surface(producer, true));
+ sp<Surface> surface = sp<Surface>::make(producer, true);
if (surface == NULL) {
jniThrowException(env, OutOfResourcesException, NULL);
return 0;
@@ -358,8 +358,8 @@ static jlong nativeReadFromParcel(JNIEnv* env, jclass clazz,
sp<Surface> sur;
if (surfaceShim.graphicBufferProducer != nullptr) {
// we have a new IGraphicBufferProducer, create a new Surface for it
- sur = new Surface(surfaceShim.graphicBufferProducer, true,
- surfaceShim.surfaceControlHandle);
+ sur = sp<Surface>::make(surfaceShim.graphicBufferProducer, true,
+ surfaceShim.surfaceControlHandle);
// and keep a reference before passing to java
sur->incStrong(&sRefBaseOwner);
}
diff --git a/core/jni/android_view_SurfaceSession.cpp b/core/jni/android_view_SurfaceSession.cpp
index 6ad109e80752..4f2ab09252c8 100644
--- a/core/jni/android_view_SurfaceSession.cpp
+++ b/core/jni/android_view_SurfaceSession.cpp
@@ -42,14 +42,14 @@ sp<SurfaceComposerClient> android_view_SurfaceSession_getClient(
static jlong nativeCreate(JNIEnv* env, jclass clazz) {
- SurfaceComposerClient* client = new SurfaceComposerClient();
- client->incStrong((void*)nativeCreate);
- return reinterpret_cast<jlong>(client);
+ // Will be deleted via decStrong() in nativeDestroy.
+ auto client = sp<SurfaceComposerClient>::make();
+ return reinterpret_cast<jlong>(client.release());
}
static void nativeDestroy(JNIEnv* env, jclass clazz, jlong ptr) {
SurfaceComposerClient* client = reinterpret_cast<SurfaceComposerClient*>(ptr);
- client->decStrong((void*)nativeCreate);
+ client->decStrong((void*)client);
}
static const JNINativeMethod gMethods[] = {
diff --git a/core/jni/android_view_TextureView.cpp b/core/jni/android_view_TextureView.cpp
index 21fe1f020b29..f71878ccff08 100644
--- a/core/jni/android_view_TextureView.cpp
+++ b/core/jni/android_view_TextureView.cpp
@@ -85,7 +85,7 @@ static void android_view_TextureView_createNativeWindow(JNIEnv* env, jobject tex
jobject surface) {
sp<IGraphicBufferProducer> producer(SurfaceTexture_getProducer(env, surface));
- sp<ANativeWindow> window = new Surface(producer, true);
+ sp<ANativeWindow> window = sp<Surface>::make(producer, true);
window->incStrong((void*)android_view_TextureView_createNativeWindow);
SET_LONG(textureView, gTextureViewClassInfo.nativeWindow, jlong(window.get()));
diff --git a/core/jni/com_google_android_gles_jni_EGLImpl.cpp b/core/jni/com_google_android_gles_jni_EGLImpl.cpp
index 75330be2624d..1b3b14da49d5 100644
--- a/core/jni/com_google_android_gles_jni_EGLImpl.cpp
+++ b/core/jni/com_google_android_gles_jni_EGLImpl.cpp
@@ -300,7 +300,7 @@ not_valid_surface:
}
sp<IGraphicBufferProducer> producer(SurfaceTexture_getProducer(_env, native_window));
- window = new Surface(producer, true);
+ window = sp<Surface>::make(producer, true);
if (window == NULL)
goto not_valid_surface;
diff --git a/native/android/surface_control.cpp b/native/android/surface_control.cpp
index 275972495206..f6dc41ed128a 100644
--- a/native/android/surface_control.cpp
+++ b/native/android/surface_control.cpp
@@ -89,7 +89,7 @@ ASurfaceControl* ASurfaceControl_createFromWindow(ANativeWindow* window, const c
CHECK_NOT_NULL(window);
CHECK_NOT_NULL(debug_name);
- sp<SurfaceComposerClient> client = new SurfaceComposerClient();
+ sp<SurfaceComposerClient> client = sp<SurfaceComposerClient>::make();
if (client->initCheck() != NO_ERROR) {
return nullptr;
}