Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 36f87cdf authored by Shuzhen Wang's avatar Shuzhen Wang
Browse files

Camera: Unhide OutputConfiguration getter functions

Unhide OutputConfiguration getter for configured size and format.

This makes it possible to call OutputConfiguration to get
configured sizes and formats even though the caller doesn't
create the OutputConfiguration.

Remove the unnecessary getConfiguredDataspace call because
dataspace isn't something configurable via OutputConfiguration.

Remove getSurfaceType call. It's not used.

Flag: com.android.internal.camera.flags.output_configuration_getter
Test: atest CameraDeviceTest
Bug: 419358672
Bug: 383609887
Change-Id: I907c3989fadabae590bb46802e758d080dc66782
parent 6e3b3b84
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -20714,6 +20714,8 @@ package android.hardware.camera2.params {
    method @NonNull public static java.util.List<android.hardware.camera2.params.OutputConfiguration> createInstancesForMultiResolutionOutput(@NonNull java.util.Collection<android.hardware.camera2.params.MultiResolutionStreamInfo>, int);
    method @NonNull public static java.util.List<android.hardware.camera2.params.OutputConfiguration> createInstancesForMultiResolutionOutput(@NonNull java.util.Collection<android.hardware.camera2.params.MultiResolutionStreamInfo>, int);
    method public int describeContents();
    method public int describeContents();
    method public void enableSurfaceSharing();
    method public void enableSurfaceSharing();
    method @FlaggedApi("com.android.internal.camera.flags.output_configuration_getter") public int getConfiguredFormat();
    method @FlaggedApi("com.android.internal.camera.flags.output_configuration_getter") @NonNull public android.util.Size getConfiguredSize();
    method public long getDynamicRangeProfile();
    method public long getDynamicRangeProfile();
    method public int getMaxSharedSurfaceCount();
    method public int getMaxSharedSurfaceCount();
    method public int getMirrorMode();
    method public int getMirrorMode();
+27 −35
Original line number Original line Diff line number Diff line
@@ -29,7 +29,6 @@ import android.annotation.TestApi;
import android.graphics.ColorSpace;
import android.graphics.ColorSpace;
import android.graphics.ImageFormat;
import android.graphics.ImageFormat;
import android.graphics.ImageFormat.Format;
import android.graphics.ImageFormat.Format;
import android.hardware.DataSpace.NamedDataSpace;
import android.hardware.HardwareBuffer;
import android.hardware.HardwareBuffer;
import android.hardware.HardwareBuffer.Usage;
import android.hardware.HardwareBuffer.Usage;
import android.hardware.camera2.CameraCaptureSession;
import android.hardware.camera2.CameraCaptureSession;
@@ -588,6 +587,8 @@ public final class OutputConfiguration implements Parcelable {
        mConfiguredFormat = SurfaceUtils.getSurfaceFormat(surface);
        mConfiguredFormat = SurfaceUtils.getSurfaceFormat(surface);
        mConfiguredDataspace = SurfaceUtils.getSurfaceDataspace(surface);
        mConfiguredDataspace = SurfaceUtils.getSurfaceDataspace(surface);
        mConfiguredGenerationId = surface.getGenerationId();
        mConfiguredGenerationId = surface.getGenerationId();
        mPublicFormat = StreamConfigurationMap.internalFormatAndDataspaceToImageFormat(
                mConfiguredFormat, mConfiguredDataspace);
        mIsDeferredConfig = false;
        mIsDeferredConfig = false;
        mIsShared = false;
        mIsShared = false;
        mPhysicalCameraId = null;
        mPhysicalCameraId = null;
@@ -834,6 +835,7 @@ public final class OutputConfiguration implements Parcelable {
        mMirrorModeForSurfaces = new IntArray();
        mMirrorModeForSurfaces = new IntArray();
        mRotation = ROTATION_0;
        mRotation = ROTATION_0;
        mConfiguredSize = surfaceSize;
        mConfiguredSize = surfaceSize;
        mPublicFormat = ImageFormat.PRIVATE;
        mConfiguredFormat = StreamConfigurationMap.imageFormatToInternal(ImageFormat.PRIVATE);
        mConfiguredFormat = StreamConfigurationMap.imageFormatToInternal(ImageFormat.PRIVATE);
        mConfiguredDataspace = StreamConfigurationMap.imageFormatToDataspace(ImageFormat.PRIVATE);
        mConfiguredDataspace = StreamConfigurationMap.imageFormatToDataspace(ImageFormat.PRIVATE);
        mConfiguredGenerationId = 0;
        mConfiguredGenerationId = 0;
@@ -963,6 +965,7 @@ public final class OutputConfiguration implements Parcelable {
        mConfiguredSize = surfaceSize;
        mConfiguredSize = surfaceSize;
        mConfiguredFormat = StreamConfigurationMap.imageFormatToInternal(format);
        mConfiguredFormat = StreamConfigurationMap.imageFormatToInternal(format);
        mConfiguredDataspace = StreamConfigurationMap.imageFormatToDataspace(format);
        mConfiguredDataspace = StreamConfigurationMap.imageFormatToDataspace(format);
        mPublicFormat = format;
        mConfiguredGenerationId = 0;
        mConfiguredGenerationId = 0;
        mIsDeferredConfig = false;
        mIsDeferredConfig = false;
        mIsShared = false;
        mIsShared = false;
@@ -1567,6 +1570,7 @@ public final class OutputConfiguration implements Parcelable {
        this.mSurfaceType = other.mSurfaceType;
        this.mSurfaceType = other.mSurfaceType;
        this.mConfiguredDataspace = other.mConfiguredDataspace;
        this.mConfiguredDataspace = other.mConfiguredDataspace;
        this.mConfiguredFormat = other.mConfiguredFormat;
        this.mConfiguredFormat = other.mConfiguredFormat;
        this.mPublicFormat = other.mPublicFormat;
        this.mConfiguredSize = other.mConfiguredSize;
        this.mConfiguredSize = other.mConfiguredSize;
        this.mConfiguredGenerationId = other.mConfiguredGenerationId;
        this.mConfiguredGenerationId = other.mConfiguredGenerationId;
        this.mIsDeferredConfig = other.mIsDeferredConfig;
        this.mIsDeferredConfig = other.mIsDeferredConfig;
@@ -1641,6 +1645,8 @@ public final class OutputConfiguration implements Parcelable {
            }
            }
            mConfiguredGenerationId = 0;
            mConfiguredGenerationId = 0;
        }
        }
        mPublicFormat = StreamConfigurationMap.internalFormatAndDataspaceToImageFormat(
                mConfiguredFormat, mConfiguredDataspace);
        mPhysicalCameraId = physicalCameraId;
        mPhysicalCameraId = physicalCameraId;
        mIsMultiResolution = isMultiResolutionOutput;
        mIsMultiResolution = isMultiResolutionOutput;
        mSensorPixelModesUsed = convertIntArrayToIntegerList(sensorPixelModesUsed);
        mSensorPixelModesUsed = convertIntArrayToIntegerList(sensorPixelModesUsed);
@@ -1716,28 +1722,40 @@ public final class OutputConfiguration implements Parcelable {
     * Get the configured size associated with this {@link OutputConfiguration}.
     * Get the configured size associated with this {@link OutputConfiguration}.
     *
     *
     * @return The configured size associated with this {@link OutputConfiguration}.
     * @return The configured size associated with this {@link OutputConfiguration}.
     *
     * @hide
     */
     */
    public Size getConfiguredSize() {
    @FlaggedApi(Flags.FLAG_OUTPUT_CONFIGURATION_GETTER)
    public @NonNull Size getConfiguredSize() {
        return mConfiguredSize;
        return mConfiguredSize;
    }
    }


    /**
    /**
     * Get the configured format associated with this {@link OutputConfiguration}.
     * Get the configured format associated with this {@link OutputConfiguration}.
     *
     *
     * <p>This function handles all ImageFormats and output targets supported by
     * the camera APIs, and isn't designed for all possible OS supported formats and
     * surfaces. For example, an ImageReader can be created using any combinations of
     * HardwareBuffer format and dataspace. If the combination is not supported
     * by the camera APIs, this function returns ImageFormat.UNKNOWN.</p>
     *
     * @return {@link android.graphics.ImageFormat#Format} associated with this
     * @return {@link android.graphics.ImageFormat#Format} associated with this
     *         {@link OutputConfiguration}.
     *         {@link OutputConfiguration}.
     *
     * @hide
     */
     */
    @FlaggedApi(Flags.FLAG_OUTPUT_CONFIGURATION_GETTER)
    public @Format int getConfiguredFormat() {
    public @Format int getConfiguredFormat() {
        return mConfiguredFormat;
        // The public facing configured format is the combination of internal
        // mConfiguredFormat and mConfiguredDataSpace.
        return mPublicFormat;
    }
    }


    /**
    /**
     * Get the usage flag associated with this {@link OutputConfiguration}.
     * Get the usage flag associated with this {@link OutputConfiguration}.
     *
     *
     * <p>Return the application specified usage flag if the OutputConfiguration is created
     * with an Image format.</p>
     *
     * <p>If the OutputConfiguration is created using an output surface, or using a class,
     * this function returns 0.</p>
     *
     * @return {@link HardwareBuffer#Usage} associated with this {@link OutputConfiguration}.
     * @return {@link HardwareBuffer#Usage} associated with this {@link OutputConfiguration}.
     *
     *
     * @hide
     * @hide
@@ -1746,23 +1764,6 @@ public final class OutputConfiguration implements Parcelable {
        return mUsage;
        return mUsage;
    }
    }


    /**
     * Get the surface type associated with this {@link OutputConfiguration}.
     *
     * @return The surface type associated with this {@link OutputConfiguration}.
     *
     * @see #SURFACE_TYPE_SURFACE_VIEW
     * @see #SURFACE_TYPE_SURFACE_TEXTURE
     * @see #SURFACE_TYPE_MEDIA_RECORDER
     * @see #SURFACE_TYPE_MEDIA_CODEC
     * @see #SURFACE_TYPE_IMAGE_READER
     * @see #SURFACE_TYPE_UNKNOWN
     * @hide
     */
    public int getSurfaceType() {
        return mSurfaceType;
    }

    /**
    /**
     * Get the sensor pixel modes associated with this {@link OutputConfiguration}.
     * Get the sensor pixel modes associated with this {@link OutputConfiguration}.
     *
     *
@@ -1785,17 +1786,6 @@ public final class OutputConfiguration implements Parcelable {
        return mIsShared;
        return mIsShared;
    }
    }


    /**
     * Get the dataspace associated with this {@link OutputConfiguration}.
     *
     * @return {@link Dataspace#NamedDataSpace} for this {@link OutputConfiguration}.
     *
     * @hide
     */
    public @NamedDataSpace int getConfiguredDataspace() {
        return mConfiguredDataspace;
    }

    /**
    /**
     * Get the flag indicating if this {@link OutputConfiguration} is for a multi-resolution output
     * Get the flag indicating if this {@link OutputConfiguration} is for a multi-resolution output
     * with a MultiResolutionImageReader.
     * with a MultiResolutionImageReader.
@@ -2019,6 +2009,8 @@ public final class OutputConfiguration implements Parcelable {
    private final Size mConfiguredSize;
    private final Size mConfiguredSize;
    private final int mConfiguredFormat;
    private final int mConfiguredFormat;
    private final int mConfiguredDataspace;
    private final int mConfiguredDataspace;
    // The public facing format, a combination of mConfiguredFormat and mConfiguredDataspace
    private final int mPublicFormat;
    // Surface generation ID to distinguish changes to Surface native internals
    // Surface generation ID to distinguish changes to Surface native internals
    private final int mConfiguredGenerationId;
    private final int mConfiguredGenerationId;
    // Flag indicating if this config has deferred surface.
    // Flag indicating if this config has deferred surface.
+104 −2
Original line number Original line Diff line number Diff line
@@ -1620,6 +1620,98 @@ public final class StreamConfigurationMap {
        }
        }
    }
    }


    /**
     * Convert an internal format and an internal dataspace from {@code graphics.h}
     * to a public format defined in {@code ImageFormat}.
     *
     * <p>In particular below conversion is done:</p>
     *
     * HAL_DATASPACE_DEPTH ==>
     *     HAL_PIXEL_FORMAT_BLOB ==>       ImageFormat.DEPTH_POINT_CLOUD
     *     HAL_PIXEL_FORMAT_Y16 ==>        ImageFormat.DEPTH16
     *     HAL_PIXEL_FORMAT_RAW16 ==>      ImageFormat.RAW_DEPTH
     *     HAL_PIXEL_FORMAT_RAW10 ==>      ImageFormat.RAW_DEPTH10
     *
     * HAL_PIXEL_FORMAT_BLOB ==>
     *     HAL_DATASPACE_DYNAMIC_DEPTH ==> ImageFormat.DEPTH_JPEG
     *     HAL_DATASPACE_HEIF ==>          ImageFormat.HEIC
     *     HAL_DATASPACE_JPEG_R ==>        ImageFormat.JPEG_R
     *     DATASPACE_HEIF_ULTRAHDR ==>     ImageFormat.HEIC_ULTRAHDR
     *     HAL_DATASPACE_V0_JFIF ==>       ImageFormat.JPEG
     *
     * HAL_PIXEL_FORMAT_RGBA_8888 ===>     PixelFormat.RGBA_8888
     * HAL_PIXEL_FORMAT_RGBX_8888 ===>     PixelFormat.RGBX_8888
     * HAL_PIXEL_FORMAT_RGB_888  ===>      PixelFormat.RGB_888
     * HAL_PIXEL_FORMAT_RGB_565 ==>        PixelFormat.RGB_565
     * HAL_PIXEL_FORMAT_YCBCR_422_SP ==>   ImageFormat.NV16
     * HAL_PIXEL_FORMAT_YCRCB_420_SP ===>  ImageFormat.NV21
     * HAL_PIXEL_FORMAT_YCBCR_422_I ===>   ImageFormat.YUY2
     * HAL_PIXEL_FORMAT_RAW16 ==>          ImageFormat.RAW_SENSOR
     * HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED ==> ImageFormat.PRIVATE
     * HAL_PIXEL_FORMAT_YCBCR_420_888 ==>  ImageFormat.YUV_420_888
     * HAL_PIXEL_FORMAT_RAW_OPAQUE ==>     ImageFormat.RAW_PRIVATE
     * HAL_PIXEL_FORMAT_RAW10 ==>          ImageFormat.RAW10
     * HAL_PIXEL_FORMAT_RAW12 ==>          ImageFormat.RAW12
     * HAL_PIXEL_FORMAT_YCBCR_P010 ==>     ImageFormat.YCBCR_P010
     * HAL_PIXEL_FORMAT_YCBCR_P210 ==>     ImageFormat.YCBCR_P210
     * HAL_PIXEL_FORMAT_Y8 ===>            ImageFormat.Y8
     * HAL_PIXEL_FORMAT_Y16 ===>           ImageFormat.Y16
     * HAL_PIXEL_FORMAT_FORMAT_YV12 ==>    ImageFormat.YV12
     *
     * @hide
     */
    static int internalFormatAndDataspaceToImageFormat(int internalFormat, int dataSpace) {
        // Convert all depth formats
        if (dataSpace == HAL_DATASPACE_DEPTH) {
            return depthFormatToPublic(internalFormat);
        }

        // Convert all blob formats
        if (internalFormat == HAL_PIXEL_FORMAT_BLOB) {
            if (Flags.cameraHeifGainmap()) {
                if (dataSpace == DataSpace.DATASPACE_HEIF_ULTRAHDR) {
                    return ImageFormat.HEIC_ULTRAHDR;
                }
            }

            switch (dataSpace) {
                case HAL_DATASPACE_DYNAMIC_DEPTH:
                    return ImageFormat.DEPTH_JPEG;
                case HAL_DATASPACE_HEIF:
                    return ImageFormat.HEIC;
                case HAL_DATASPACE_JPEG_R:
                    return ImageFormat.JPEG_R;
                case HAL_DATASPACE_V0_JFIF:
                default:
                    return ImageFormat.JPEG;
            }
        }

        // Remaining recognized formats that are equal between public and internal.
        switch (internalFormat) {
            case HAL_PIXEL_FORMAT_RGBA_8888:
            case HAL_PIXEL_FORMAT_RGBX_8888:
            case HAL_PIXEL_FORMAT_RGB_888:
            case HAL_PIXEL_FORMAT_RGB_565:
            case HAL_PIXEL_FORMAT_YCBCR_422_SP:
            case HAL_PIXEL_FORMAT_YCRCB_420_SP:
            case HAL_PIXEL_FORMAT_RAW16:
            case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
            case HAL_PIXEL_FORMAT_YCBCR_420_888:
            case HAL_PIXEL_FORMAT_RAW_OPAQUE:
            case HAL_PIXEL_FORMAT_RAW10:
            case HAL_PIXEL_FORMAT_RAW12:
            case HAL_PIXEL_FORMAT_YCBCR_P010:
            case HAL_PIXEL_FORMAT_YCBCR_P210:
            case HAL_PIXEL_FORMAT_Y8:
            case HAL_PIXEL_FORMAT_Y16:
            case HAL_PIXEL_FORMAT_YV12:
                return internalFormat;
            default:
                return ImageFormat.UNKNOWN;
        }
    }

    /**
    /**
     * Convert image formats from public to internal formats (in-place).
     * Convert image formats from public to internal formats (in-place).
     *
     *
@@ -2130,16 +2222,26 @@ public final class StreamConfigurationMap {
    }
    }


    // from system/core/include/system/graphics.h
    // from system/core/include/system/graphics.h
    private static final int HAL_PIXEL_FORMAT_RGBA_8888 = 0x01;
    private static final int HAL_PIXEL_FORMAT_RGBX_8888 = 0x02;
    private static final int HAL_PIXEL_FORMAT_RGB_888 = 0x03;
    private static final int HAL_PIXEL_FORMAT_RGB_565 = 0x04;
    private static final int HAL_PIXEL_FORMAT_YCBCR_422_SP = 0x10;
    private static final int HAL_PIXEL_FORMAT_YCRCB_420_SP = 0x11;
    private static final int HAL_PIXEL_FORMAT_YCBCR_422_I = 0x14;
    private static final int HAL_PIXEL_FORMAT_RAW16 = 0x20;
    private static final int HAL_PIXEL_FORMAT_RAW16 = 0x20;
    /** @hide */
    /** @hide */
    public static final int HAL_PIXEL_FORMAT_BLOB = 0x21;
    public static final int HAL_PIXEL_FORMAT_BLOB = 0x21;
    private static final int HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED = 0x22;
    private static final int HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED = 0x22;
    private static final int HAL_PIXEL_FORMAT_YCbCr_420_888 = 0x23;
    private static final int HAL_PIXEL_FORMAT_YCBCR_420_888 = 0x23;
    private static final int HAL_PIXEL_FORMAT_RAW_OPAQUE = 0x24;
    private static final int HAL_PIXEL_FORMAT_RAW_OPAQUE = 0x24;
    private static final int HAL_PIXEL_FORMAT_RAW10 = 0x25;
    private static final int HAL_PIXEL_FORMAT_RAW10 = 0x25;
    private static final int HAL_PIXEL_FORMAT_RAW12 = 0x26;
    private static final int HAL_PIXEL_FORMAT_RAW12 = 0x26;
    private static final int HAL_PIXEL_FORMAT_YCBCR_P010 = 0x36;
    private static final int HAL_PIXEL_FORMAT_YCBCR_P210 = 0x3c;
    private static final int HAL_PIXEL_FORMAT_Y8 = 0x20203859;
    private static final int HAL_PIXEL_FORMAT_Y16 = 0x20363159;
    private static final int HAL_PIXEL_FORMAT_Y16 = 0x20363159;

    private static final int HAL_PIXEL_FORMAT_YV12 = 0x32315659;


    private static final int HAL_DATASPACE_STANDARD_SHIFT = 16;
    private static final int HAL_DATASPACE_STANDARD_SHIFT = 16;
    private static final int HAL_DATASPACE_TRANSFER_SHIFT = 22;
    private static final int HAL_DATASPACE_TRANSFER_SHIFT = 22;