Remove some usage of IGBPs in the ICamera.
This change removes the usage of IGBPs in ICamera and the surrounding
code where reasonable. This is part of a refactor outline at go/warren-buffers.
BYPASS_IGBP_IGBC_API_REASON: this CL is part of the migration.
Bug: 342197849
Test: atest android.hardware.cts.CameraTest
Flag: com.android.graphics.libgui.flags.wb_libcameraservice
Change-Id: I06fbf42e6a249f3b30266ac5b3dad0bdbc4f585a
diff --git a/camera/Camera.cpp b/camera/Camera.cpp
index d90f7c9..0bc735f 100644
--- a/camera/Camera.cpp
+++ b/camera/Camera.cpp
@@ -99,23 +99,21 @@
return c->unlock();
}
-// pass the buffered IGraphicBufferProducer to the camera service
-status_t Camera::setPreviewTarget(const sp<IGraphicBufferProducer>& bufferProducer)
-{
- ALOGV("setPreviewTarget(%p)", bufferProducer.get());
- sp <::android::hardware::ICamera> c = mCamera;
+// pass the Surface to the camera service
+status_t Camera::setPreviewTarget(const sp<SurfaceType>& target) {
+ ALOGV("setPreviewTarget(%p)", target.get());
+ sp<::android::hardware::ICamera> c = mCamera;
if (c == 0) return NO_INIT;
- ALOGD_IF(bufferProducer == 0, "app passed NULL surface");
- return c->setPreviewTarget(bufferProducer);
+ ALOGD_IF(target == 0, "app passed NULL surface");
+ return c->setPreviewTarget(target);
}
-status_t Camera::setVideoTarget(const sp<IGraphicBufferProducer>& bufferProducer)
-{
- ALOGV("setVideoTarget(%p)", bufferProducer.get());
- sp <::android::hardware::ICamera> c = mCamera;
+status_t Camera::setVideoTarget(const sp<SurfaceType>& target) {
+ ALOGV("setVideoTarget(%p)", target.get());
+ sp<::android::hardware::ICamera> c = mCamera;
if (c == 0) return NO_INIT;
- ALOGD_IF(bufferProducer == 0, "app passed NULL video surface");
- return c->setVideoTarget(bufferProducer);
+ ALOGD_IF(target == 0, "app passed NULL video surface");
+ return c->setVideoTarget(target);
}
// start preview mode
@@ -272,12 +270,10 @@
c->setPreviewCallbackFlag(flag);
}
-status_t Camera::setPreviewCallbackTarget(
- const sp<IGraphicBufferProducer>& callbackProducer)
-{
- sp <::android::hardware::ICamera> c = mCamera;
+status_t Camera::setPreviewCallbackTarget(const sp<SurfaceType>& target) {
+ sp<::android::hardware::ICamera> c = mCamera;
if (c == 0) return NO_INIT;
- return c->setPreviewCallbackTarget(callbackProducer);
+ return c->setPreviewCallbackTarget(target);
}
status_t Camera::setAudioRestriction(int32_t mode)
diff --git a/camera/ICamera.cpp b/camera/ICamera.cpp
index b83edf7..0b811d2 100644
--- a/camera/ICamera.cpp
+++ b/camera/ICamera.cpp
@@ -17,16 +17,16 @@
//#define LOG_NDEBUG 0
#define LOG_TAG "ICamera"
-#include <utils/Log.h>
-#include <stdint.h>
-#include <sys/types.h>
-#include <binder/Parcel.h>
-#include <camera/CameraUtils.h>
#include <android/hardware/ICamera.h>
#include <android/hardware/ICameraClient.h>
-#include <gui/IGraphicBufferProducer.h>
+#include <binder/Parcel.h>
+#include <camera/CameraUtils.h>
#include <gui/Surface.h>
+#include <gui/view/Surface.h>
#include <media/hardware/HardwareAPI.h>
+#include <stdint.h>
+#include <sys/types.h>
+#include <utils/Log.h>
namespace android {
namespace hardware {
@@ -34,8 +34,14 @@
enum {
DISCONNECT = IBinder::FIRST_CALL_TRANSACTION,
SET_PREVIEW_TARGET,
+#if WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
+ SET_PREVIEW_TARGET_SURFACE,
+#endif
SET_PREVIEW_CALLBACK_FLAG,
SET_PREVIEW_CALLBACK_TARGET,
+#if WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
+ SET_PREVIEW_CALLBACK_TARGET_SURFACE,
+#endif
START_PREVIEW,
STOP_PREVIEW,
AUTO_FOCUS,
@@ -54,6 +60,9 @@
RELEASE_RECORDING_FRAME,
SET_VIDEO_BUFFER_MODE,
SET_VIDEO_BUFFER_TARGET,
+#if WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
+ SET_VIDEO_BUFFER_TARGET_SURFACE,
+#endif
RELEASE_RECORDING_FRAME_HANDLE,
RELEASE_RECORDING_FRAME_HANDLE_BATCH,
SET_AUDIO_RESTRICTION,
@@ -79,15 +88,20 @@
return binder::Status::ok();
}
- // pass the buffered IGraphicBufferProducer to the camera service
- status_t setPreviewTarget(const sp<IGraphicBufferProducer>& bufferProducer)
- {
+ // pass the Surface to the camera service
+ status_t setPreviewTarget(const sp<SurfaceType>& target) {
ALOGV("setPreviewTarget");
Parcel data, reply;
data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
- sp<IBinder> b(IInterface::asBinder(bufferProducer));
+#if WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
+ view::Surface viewSurfaceProducer = view::Surface::fromSurface(target);
+ data.writeParcelable(viewSurfaceProducer);
+ remote()->transact(SET_PREVIEW_TARGET_SURFACE, data, &reply);
+#else
+ sp<IBinder> b(IInterface::asBinder(target));
data.writeStrongBinder(b);
remote()->transact(SET_PREVIEW_TARGET, data, &reply);
+#endif
return reply.readInt32();
}
@@ -102,15 +116,19 @@
remote()->transact(SET_PREVIEW_CALLBACK_FLAG, data, &reply);
}
- status_t setPreviewCallbackTarget(
- const sp<IGraphicBufferProducer>& callbackProducer)
- {
+ status_t setPreviewCallbackTarget(const sp<SurfaceType>& target) {
ALOGV("setPreviewCallbackTarget");
Parcel data, reply;
data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
- sp<IBinder> b(IInterface::asBinder(callbackProducer));
+#if WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
+ view::Surface viewCallbackProducer = view::Surface::fromSurface(target);
+ data.writeParcelable(viewCallbackProducer);
+ remote()->transact(SET_PREVIEW_CALLBACK_TARGET_SURFACE, data, &reply);
+#else
+ sp<IBinder> b(IInterface::asBinder(target));
data.writeStrongBinder(b);
remote()->transact(SET_PREVIEW_CALLBACK_TARGET, data, &reply);
+#endif
return reply.readInt32();
}
@@ -326,14 +344,19 @@
return reply.readInt32();
}
- status_t setVideoTarget(const sp<IGraphicBufferProducer>& bufferProducer)
- {
+ status_t setVideoTarget(const sp<SurfaceType>& target) {
ALOGV("setVideoTarget");
Parcel data, reply;
data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
- sp<IBinder> b(IInterface::asBinder(bufferProducer));
+#if WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
+ view::Surface viewSurfaceProducer = view::Surface::fromSurface(target);
+ data.writeParcelable(viewSurfaceProducer);
+ remote()->transact(SET_VIDEO_BUFFER_TARGET_SURFACE, data, &reply);
+#else
+ sp<IBinder> b(IInterface::asBinder(target));
data.writeStrongBinder(b);
remote()->transact(SET_VIDEO_BUFFER_TARGET, data, &reply);
+#endif
return reply.readInt32();
}
};
@@ -358,9 +381,25 @@
CHECK_INTERFACE(ICamera, data, reply);
sp<IGraphicBufferProducer> st =
interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
+#if WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
+ sp<Surface> sp = new Surface(st);
+ reply->writeInt32(setPreviewTarget(sp));
+#else
+ reply->writeInt32(setPreviewTarget(st));
+#endif
+ return NO_ERROR;
+ } break;
+#if WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
+ case SET_PREVIEW_TARGET_SURFACE: {
+ ALOGV("SET_PREVIEW_TARGET_SURFACE");
+ CHECK_INTERFACE(ICamera, data, reply);
+ view::Surface viewSurface;
+ data.readParcelable(&viewSurface);
+ sp<Surface> st = viewSurface.toSurface();
reply->writeInt32(setPreviewTarget(st));
return NO_ERROR;
} break;
+#endif
case SET_PREVIEW_CALLBACK_FLAG: {
ALOGV("SET_PREVIEW_CALLBACK_TYPE");
CHECK_INTERFACE(ICamera, data, reply);
@@ -373,9 +412,25 @@
CHECK_INTERFACE(ICamera, data, reply);
sp<IGraphicBufferProducer> cp =
interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
+#if WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
+ sp<Surface> sp = new Surface(cp);
+ reply->writeInt32(setPreviewCallbackTarget(sp));
+#else
+ reply->writeInt32(setPreviewCallbackTarget(cp));
+#endif
+ return NO_ERROR;
+ }
+#if WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
+ case SET_PREVIEW_CALLBACK_TARGET_SURFACE: {
+ ALOGV("SET_PREVIEW_CALLBACK_TARGET_SURFACE");
+ CHECK_INTERFACE(ICamera, data, reply);
+ view::Surface viewSurface;
+ data.readParcelable(&viewSurface);
+ sp<Surface> cp = viewSurface.toSurface();
reply->writeInt32(setPreviewCallbackTarget(cp));
return NO_ERROR;
}
+#endif
case START_PREVIEW: {
ALOGV("START_PREVIEW");
CHECK_INTERFACE(ICamera, data, reply);
@@ -508,9 +563,25 @@
CHECK_INTERFACE(ICamera, data, reply);
sp<IGraphicBufferProducer> st =
interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
+#if WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
+ sp<Surface> sp = new Surface(st);
+ reply->writeInt32(setVideoTarget(sp));
+#else
reply->writeInt32(setVideoTarget(st));
+#endif
return NO_ERROR;
} break;
+#if WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
+ case SET_VIDEO_BUFFER_TARGET_SURFACE: {
+ ALOGV("SET_VIDEO_BUFFER_TARGET_SURFACE");
+ CHECK_INTERFACE(ICamera, data, reply);
+ view::Surface viewSurface;
+ data.readParcelable(&viewSurface);
+ sp<Surface> cp = viewSurface.toSurface();
+ reply->writeInt32(setVideoTarget(cp));
+ return NO_ERROR;
+ } break;
+#endif
case SET_AUDIO_RESTRICTION: {
CHECK_INTERFACE(ICamera, data, reply);
int32_t mode = data.readInt32();
diff --git a/camera/include/camera/Camera.h b/camera/include/camera/Camera.h
index 646b139..fa84b4e 100644
--- a/camera/include/camera/Camera.h
+++ b/camera/include/camera/Camera.h
@@ -21,13 +21,18 @@
#include <android/hardware/ICameraService.h>
-#include <gui/IGraphicBufferProducer.h>
-#include <system/camera.h>
+#include <camera/CameraBase.h>
+#include <camera/CameraUtils.h>
#include <camera/ICameraRecordingProxy.h>
#include <camera/android/hardware/ICamera.h>
#include <camera/android/hardware/ICameraClient.h>
-#include <camera/CameraBase.h>
-#include <camera/CameraUtils.h>
+#include <gui/Flags.h>
+#if WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
+#include <gui/Surface.h>
+#else
+#include <gui/IGraphicBufferProducer.h>
+#endif
+#include <system/camera.h>
namespace android {
@@ -91,8 +96,8 @@
status_t lock();
status_t unlock();
- // pass the buffered IGraphicBufferProducer to the camera service
- status_t setPreviewTarget(const sp<IGraphicBufferProducer>& bufferProducer);
+ // pass the SurfaceType to the camera service
+ status_t setPreviewTarget(const sp<SurfaceType>& target);
// start preview mode, must call setPreviewTarget first
status_t startPreview();
@@ -148,7 +153,7 @@
// Set the video buffer producer for camera to use in VIDEO_BUFFER_MODE_BUFFER_QUEUE
// mode.
- status_t setVideoTarget(const sp<IGraphicBufferProducer>& bufferProducer);
+ status_t setVideoTarget(const sp<SurfaceType>& target);
void setListener(const sp<CameraListener>& listener);
@@ -158,8 +163,7 @@
// disabled by calling it with CAMERA_FRAME_CALLBACK_FLAG_NOOP, and
// Target by calling it with a NULL interface.
void setPreviewCallbackFlags(int preview_callback_flag);
- status_t setPreviewCallbackTarget(
- const sp<IGraphicBufferProducer>& callbackProducer);
+ status_t setPreviewCallbackTarget(const sp<SurfaceType>& target);
sp<ICameraRecordingProxy> getRecordingProxy();
diff --git a/camera/include/camera/android/hardware/ICamera.h b/camera/include/camera/android/hardware/ICamera.h
index ec19e5d..eb887fb 100644
--- a/camera/include/camera/android/hardware/ICamera.h
+++ b/camera/include/camera/android/hardware/ICamera.h
@@ -22,6 +22,7 @@
#include <binder/Parcel.h>
#include <binder/IMemory.h>
#include <binder/Status.h>
+#include <gui/Flags.h>
#include <utils/String8.h>
namespace android {
@@ -61,9 +62,8 @@
// allow other processes to use this ICamera interface
virtual status_t unlock() = 0;
- // pass the buffered IGraphicBufferProducer to the camera service
- virtual status_t setPreviewTarget(
- const sp<IGraphicBufferProducer>& bufferProducer) = 0;
+ // pass the SurfaceType to the camera service
+ virtual status_t setPreviewTarget(const sp<SurfaceType>& bufferProducer) = 0;
// set the preview callback flag to affect how the received frames from
// preview are handled. Enabling preview callback flags disables any active
@@ -73,8 +73,7 @@
// of preview callback buffers. Passing a valid interface here disables any
// active preview callbacks set by setPreviewCallbackFlag(). Passing NULL
// disables the use of the callback target.
- virtual status_t setPreviewCallbackTarget(
- const sp<IGraphicBufferProducer>& callbackProducer) = 0;
+ virtual status_t setPreviewCallbackTarget(const sp<SurfaceType>& callbackProducer) = 0;
// start preview mode, must call setPreviewTarget first
virtual status_t startPreview() = 0;
@@ -138,8 +137,7 @@
virtual status_t setVideoBufferMode(int32_t videoBufferMode) = 0;
// Set the video buffer producer for camera to use in VIDEO_BUFFER_MODE_BUFFER_QUEUE mode.
- virtual status_t setVideoTarget(
- const sp<IGraphicBufferProducer>& bufferProducer) = 0;
+ virtual status_t setVideoTarget(const sp<SurfaceType>& bufferProducer) = 0;
// Set the audio restriction mode
virtual status_t setAudioRestriction(int32_t mode) = 0;
diff --git a/camera/tests/CameraZSLTests.cpp b/camera/tests/CameraZSLTests.cpp
index 2740d09..b06f9b4 100644
--- a/camera/tests/CameraZSLTests.cpp
+++ b/camera/tests/CameraZSLTests.cpp
@@ -20,17 +20,18 @@
#include <gtest/gtest.h>
#include <android/content/AttributionSourceState.h>
+#include <android/hardware/ICameraService.h>
#include <binder/ProcessState.h>
-#include <utils/Errors.h>
-#include <utils/Log.h>
-#include <gui/Surface.h>
-#include <gui/SurfaceComposerClient.h>
-#include <camera/CameraParameters.h>
-#include <camera/CameraMetadata.h>
#include <camera/Camera.h>
+#include <camera/CameraMetadata.h>
+#include <camera/CameraParameters.h>
#include <camera/CameraUtils.h>
#include <camera/StringUtils.h>
-#include <android/hardware/ICameraService.h>
+#include <gui/Flags.h>
+#include <gui/Surface.h>
+#include <gui/SurfaceComposerClient.h>
+#include <utils/Errors.h>
+#include <utils/Log.h>
using namespace android;
using namespace android::hardware;
@@ -276,8 +277,11 @@
previewSurface = surfaceControl->getSurface();
ASSERT_TRUE(previewSurface != NULL);
- ASSERT_EQ(NO_ERROR, cameraDevice->setPreviewTarget(
- previewSurface->getIGraphicBufferProducer()));
+ ASSERT_EQ(NO_ERROR, cameraDevice->setPreviewTarget(previewSurface
+#if !WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
+ ->getIGraphicBufferProducer()
+#endif
+ ));
cameraDevice->setPreviewCallbackFlag(
CAMERA_FRAME_CALLBACK_FLAG_CAMCORDER);
diff --git a/camera/tests/fuzzer/camera_fuzzer.cpp b/camera/tests/fuzzer/camera_fuzzer.cpp
index f46d246..f976fe1 100644
--- a/camera/tests/fuzzer/camera_fuzzer.cpp
+++ b/camera/tests/fuzzer/camera_fuzzer.cpp
@@ -20,6 +20,7 @@
#include <android/content/AttributionSourceState.h>
#include <binder/MemoryDealer.h>
#include <fuzzer/FuzzedDataProvider.h>
+#include <gui/Flags.h>
#include <gui/Surface.h>
#include <gui/SurfaceComposerClient.h>
#include "camera2common.h"
@@ -210,7 +211,11 @@
auto callCameraAPIs = mFDP->PickValueInArray<const std::function<void()>>({
[&]() {
if (surfaceControl) {
- mCamera->setPreviewTarget(surface->getIGraphicBufferProducer());
+ mCamera->setPreviewTarget(surface
+#if !WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
+ ->getIGraphicBufferProducer()
+#endif
+ );
}
},
[&]() {
@@ -267,7 +272,11 @@
},
[&]() {
if (surfaceControl) {
- mCamera->setVideoTarget(surface->getIGraphicBufferProducer());
+ mCamera->setVideoTarget(surface
+#if !WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
+ ->getIGraphicBufferProducer()
+#endif
+ );
}
},
[&]() {
@@ -283,7 +292,11 @@
},
[&]() {
if (surfaceControl) {
- mCamera->setPreviewCallbackTarget(surface->getIGraphicBufferProducer());
+ mCamera->setPreviewCallbackTarget(surface
+#if !WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
+ ->getIGraphicBufferProducer()
+#endif
+ );
}
},
[&]() { mCamera->getRecordingProxy(); },