From 5c2a840de8897f380199833bc9a05caa3fae624a Mon Sep 17 00:00:00 2001 From: Jayant Chowdhary Date: Tue, 20 Jul 2021 15:45:08 -0700 Subject: [PATCH] camera2: Add fwk-only tags for SCALER_CROP_REGION and metering regions. Default sensor mode capture requests would have their scaler crop regions set to the default active / pre-correction array coordinate system. Cameraserver needs to correct this for max res sensor pixel mode CaptureRequests. In order to facilitate the correction, we add fwk-only CaptureRequest tags which are set when camera clients set SCALER_CROP_REGION / metering regions. Bug: 194143991 Test: CTS Change-Id: I66393a1e6310f149138be4799f20ced377b11eb4 Signed-off-by: Jayant Chowdhary --- .../hardware/camera2/CaptureRequest.java | 60 +++++++++++++++++ .../camera2/impl/CameraMetadataNative.java | 65 +++++++++++++++++++ 2 files changed, 125 insertions(+) diff --git a/core/java/android/hardware/camera2/CaptureRequest.java b/core/java/android/hardware/camera2/CaptureRequest.java index 906256d701970..53c3021a7fa23 100644 --- a/core/java/android/hardware/camera2/CaptureRequest.java +++ b/core/java/android/hardware/camera2/CaptureRequest.java @@ -2307,6 +2307,51 @@ public final class CaptureRequest extends CameraMetadata> public static final Key CONTROL_ZOOM_RATIO = new Key("android.control.zoomRatio", float.class); + /** + *

Framework-only private key which informs camera fwk that the AF regions has been set + * by the client and those regions need not be corrected when {@link CaptureRequest#SENSOR_PIXEL_MODE android.sensor.pixelMode} is + * set to MAXIMUM_RESOLUTION.

+ *

This must be set to TRUE by the camera2 java fwk when the camera client sets + * {@link CaptureRequest#CONTROL_AF_REGIONS android.control.afRegions}.

+ *

Optional - The value for this key may be {@code null} on some devices.

+ * + * @see CaptureRequest#CONTROL_AF_REGIONS + * @see CaptureRequest#SENSOR_PIXEL_MODE + * @hide + */ + public static final Key CONTROL_AF_REGIONS_SET = + new Key("android.control.afRegionsSet", boolean.class); + + /** + *

Framework-only private key which informs camera fwk that the AE regions has been set + * by the client and those regions need not be corrected when {@link CaptureRequest#SENSOR_PIXEL_MODE android.sensor.pixelMode} is + * set to MAXIMUM_RESOLUTION.

+ *

This must be set to TRUE by the camera2 java fwk when the camera client sets + * {@link CaptureRequest#CONTROL_AE_REGIONS android.control.aeRegions}.

+ *

Optional - The value for this key may be {@code null} on some devices.

+ * + * @see CaptureRequest#CONTROL_AE_REGIONS + * @see CaptureRequest#SENSOR_PIXEL_MODE + * @hide + */ + public static final Key CONTROL_AE_REGIONS_SET = + new Key("android.control.aeRegionsSet", boolean.class); + + /** + *

Framework-only private key which informs camera fwk that the AF regions has been set + * by the client and those regions need not be corrected when {@link CaptureRequest#SENSOR_PIXEL_MODE android.sensor.pixelMode} is + * set to MAXIMUM_RESOLUTION.

+ *

This must be set to TRUE by the camera2 java fwk when the camera client sets + * {@link CaptureRequest#CONTROL_AWB_REGIONS android.control.awbRegions}.

+ *

Optional - The value for this key may be {@code null} on some devices.

+ * + * @see CaptureRequest#CONTROL_AWB_REGIONS + * @see CaptureRequest#SENSOR_PIXEL_MODE + * @hide + */ + public static final Key CONTROL_AWB_REGIONS_SET = + new Key("android.control.awbRegionsSet", boolean.class); + /** *

Operation mode for edge * enhancement.

@@ -3046,6 +3091,21 @@ public final class CaptureRequest extends CameraMetadata> public static final Key SCALER_ROTATE_AND_CROP = new Key("android.scaler.rotateAndCrop", int.class); + /** + *

Framework-only private key which informs camera fwk that the scaler crop region + * ({@link CaptureRequest#SCALER_CROP_REGION android.scaler.cropRegion}) has been set by the client and it need + * not be corrected when {@link CaptureRequest#SENSOR_PIXEL_MODE android.sensor.pixelMode} is set to MAXIMUM_RESOLUTION.

+ *

This must be set to TRUE by the camera2 java fwk when the camera client sets + * {@link CaptureRequest#SCALER_CROP_REGION android.scaler.cropRegion}.

+ *

Optional - The value for this key may be {@code null} on some devices.

+ * + * @see CaptureRequest#SCALER_CROP_REGION + * @see CaptureRequest#SENSOR_PIXEL_MODE + * @hide + */ + public static final Key SCALER_CROP_REGION_SET = + new Key("android.scaler.cropRegionSet", boolean.class); + /** *

Duration each pixel is exposed to * light.

diff --git a/core/java/android/hardware/camera2/impl/CameraMetadataNative.java b/core/java/android/hardware/camera2/impl/CameraMetadataNative.java index 2e841f50e84dd..4928af20e877d 100644 --- a/core/java/android/hardware/camera2/impl/CameraMetadataNative.java +++ b/core/java/android/hardware/camera2/impl/CameraMetadataNative.java @@ -53,6 +53,7 @@ import android.hardware.camera2.params.Capability; import android.hardware.camera2.params.Face; import android.hardware.camera2.params.HighSpeedVideoConfiguration; import android.hardware.camera2.params.LensShadingMap; +import android.hardware.camera2.params.MeteringRectangle; import android.hardware.camera2.params.MandatoryStreamCombination; import android.hardware.camera2.params.MultiResolutionStreamConfigurationMap; import android.hardware.camera2.params.OisSample; @@ -1708,6 +1709,34 @@ public class CameraMetadataNative implements Parcelable { metadata.setGpsLocation((Location) value); } }); + sSetCommandMap.put(CaptureRequest.SCALER_CROP_REGION.getNativeKey(), + new SetCommand() { + @Override + public void setValue(CameraMetadataNative metadata, T value) { + metadata.setScalerCropRegion((Rect) value); + } + }); + sSetCommandMap.put(CaptureRequest.CONTROL_AWB_REGIONS.getNativeKey(), + new SetCommand() { + @Override + public void setValue(CameraMetadataNative metadata, T value) { + metadata.setAWBRegions((MeteringRectangle[]) value); + } + }); + sSetCommandMap.put(CaptureRequest.CONTROL_AF_REGIONS.getNativeKey(), + new SetCommand() { + @Override + public void setValue(CameraMetadataNative metadata, T value) { + metadata.setAFRegions((MeteringRectangle[]) value); + } + }); + sSetCommandMap.put(CaptureRequest.CONTROL_AE_REGIONS.getNativeKey(), + new SetCommand() { + @Override + public void setValue(CameraMetadataNative metadata, T value) { + metadata.setAERegions((MeteringRectangle[]) value); + } + }); } private boolean setAvailableFormats(int[] value) { @@ -1777,6 +1806,42 @@ public class CameraMetadataNative implements Parcelable { return true; } + private boolean setScalerCropRegion(Rect cropRegion) { + if (cropRegion == null) { + return false; + } + setBase(CaptureRequest.SCALER_CROP_REGION_SET, true); + setBase(CaptureRequest.SCALER_CROP_REGION, cropRegion); + return true; + } + + private boolean setAFRegions(MeteringRectangle[] afRegions) { + if (afRegions == null) { + return false; + } + setBase(CaptureRequest.CONTROL_AF_REGIONS_SET, true); + setBase(CaptureRequest.CONTROL_AF_REGIONS, afRegions); + return true; + } + + private boolean setAERegions(MeteringRectangle[] aeRegions) { + if (aeRegions == null) { + return false; + } + setBase(CaptureRequest.CONTROL_AE_REGIONS_SET, true); + setBase(CaptureRequest.CONTROL_AE_REGIONS, aeRegions); + return true; + } + + private boolean setAWBRegions(MeteringRectangle[] awbRegions) { + if (awbRegions == null) { + return false; + } + setBase(CaptureRequest.CONTROL_AWB_REGIONS_SET, true); + setBase(CaptureRequest.CONTROL_AWB_REGIONS, awbRegions); + return true; + } + private void updateNativeAllocation() { long currentBufferSize = nativeGetBufferSize(mMetadataPtr);