CameraService: Implement SCALER_ROTATE_AND_CROP_AUTO, part 1
When an app sets SCALER_ROTATE_AND_CROP to AUTO, the camera service
needs to select the right ROTATE_AND_CROP mode given the application
UI state at the moment, received from the window manager.
In addition, some of the metadata in the active array coordinate
system needs to be converted to/from the cropped+rotated coordinate
system to ensure roundtripping UI information works as before.
Also ensure that the available rotate and crop metadata field is
always available, with a value of NONE if nothing else.
This commit adds support for doing the coordinate transforms and
overriding AUTO to a concrete value; it does not wire up a connection
to another system service to receive the correct override value, but
does add a command to set the override value for all current camera
clients.
Test: New CTS tests pass, unit tests for RotateAndCropMapper pass
Bug: 134631897
Change-Id: Icc45530e2cfbaf838a1e4d04e4fd2aef8122e8e1
diff --git a/services/camera/libcameraservice/device3/Camera3Device.h b/services/camera/libcameraservice/device3/Camera3Device.h
index 7279baf..0764320 100644
--- a/services/camera/libcameraservice/device3/Camera3Device.h
+++ b/services/camera/libcameraservice/device3/Camera3Device.h
@@ -48,6 +48,7 @@
#include "device3/Camera3BufferManager.h"
#include "device3/DistortionMapper.h"
#include "device3/ZoomRatioMapper.h"
+#include "device3/RotateAndCropMapper.h"
#include "device3/InFlightRequest.h"
#include "device3/Camera3OutputInterface.h"
#include "device3/Camera3OfflineSession.h"
@@ -222,6 +223,15 @@
std::vector<sp<camera3::Camera3StreamInterface>> getAllStreams() override;
/**
+ * Set the current behavior for the ROTATE_AND_CROP control when in AUTO.
+ *
+ * The value must be one of the ROTATE_AND_CROP_* values besides AUTO,
+ * and defaults to NONE.
+ */
+ status_t setRotateAndCropAutoBehavior(
+ camera_metadata_enum_android_scaler_rotate_and_crop_t rotateAndCropValue);
+
+ /**
* Helper functions to map between framework and HIDL values
*/
static hardware::graphics::common::V1_0::PixelFormat mapToPixelFormat(int frameworkFormat);
@@ -501,6 +511,10 @@
int mBatchSize;
// Whether this request is from a repeating or repeating burst.
bool mRepeating;
+ // Whether this request has ROTATE_AND_CROP_AUTO set, so needs both
+ // overriding of ROTATE_AND_CROP value and adjustment of coordinates
+ // in several other controls in both the request and the result
+ bool mRotateAndCropAuto;
};
typedef List<sp<CaptureRequest> > RequestList;
@@ -824,6 +838,9 @@
/*out*/sp<hardware::camera::device::V3_6::ICameraOfflineSession>* offlineSession,
/*out*/camera3::BufferRecords* bufferRecords);
+ status_t setRotateAndCropAutoBehavior(
+ camera_metadata_enum_android_scaler_rotate_and_crop_t rotateAndCropValue);
+
protected:
virtual bool threadLoop();
@@ -840,7 +857,10 @@
// HAL workaround: Make sure a trigger ID always exists if
// a trigger does
- status_t addDummyTriggerIds(const sp<CaptureRequest> &request);
+ status_t addDummyTriggerIds(const sp<CaptureRequest> &request);
+
+ // Override rotate_and_crop control if needed; returns true if the current value was changed
+ bool overrideAutoRotateAndCrop(const sp<CaptureRequest> &request);
static const nsecs_t kRequestTimeout = 50e6; // 50 ms
@@ -962,6 +982,7 @@
TriggerMap mTriggerReplacedMap;
uint32_t mCurrentAfTriggerId;
uint32_t mCurrentPreCaptureTriggerId;
+ camera_metadata_enum_android_scaler_rotate_and_crop_t mRotateAndCropOverride;
int64_t mRepeatingLastFrameNumber;
@@ -993,8 +1014,8 @@
status_t registerInFlight(uint32_t frameNumber,
int32_t numBuffers, CaptureResultExtras resultExtras, bool hasInput,
bool callback, nsecs_t maxExpectedDuration, std::set<String8>& physicalCameraIds,
- bool isStillCapture, bool isZslCapture, const std::set<std::string>& cameraIdsWithZoom,
- const SurfaceMap& outputSurfaces);
+ bool isStillCapture, bool isZslCapture, bool rotateAndCropAuto,
+ const std::set<std::string>& cameraIdsWithZoom, const SurfaceMap& outputSurfaces);
/**
* Tracking for idle detection
@@ -1113,6 +1134,11 @@
*/
std::unordered_map<std::string, camera3::ZoomRatioMapper> mZoomRatioMappers;
+ /**
+ * RotateAndCrop mapper support
+ */
+ std::unordered_map<std::string, camera3::RotateAndCropMapper> mRotateAndCropMappers;
+
// Debug tracker for metadata tag value changes
// - Enabled with the -m <taglist> option to dumpsys, such as
// dumpsys -m android.control.aeState,android.control.aeMode