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

Commit 534a9ba1 authored by Emilian Peev's avatar Emilian Peev
Browse files

ImageWriter: Convert Blob native format to respective public value

The result of the surface format query is the underlying native pixel
format which in some cases might be different from the public advertised
value. The native allocation estimation expects the public ImageFormat
so the queried format must be converted where necessary.

Bug: 170900000
Test: atest
cts/tests/camera/src/android/hardware/camera2/cts/ImageWriter.java#testWriterReaderBlobFormats

Change-Id: If509c112f9caf2f0d00f165200f5a8559896121d
parent 3f08df9f
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -1917,9 +1917,18 @@ public final class StreamConfigurationMap {
            (3 << HAL_DATASPACE_TRANSFER_SHIFT) |
            (1 << HAL_DATASPACE_RANGE_SHIFT);

    private static final int HAL_DATASPACE_DEPTH = 0x1000;
    private static final int HAL_DATASPACE_DYNAMIC_DEPTH = 0x1002;
    private static final int HAL_DATASPACE_HEIF = 0x1003;
    /**
     * @hide
     */
    public static final int HAL_DATASPACE_DEPTH = 0x1000;
    /**
     * @hide
     */
    public static final int HAL_DATASPACE_DYNAMIC_DEPTH = 0x1002;
    /**
     * @hide
     */
    public static final int HAL_DATASPACE_HEIF = 0x1003;
    private static final long DURATION_20FPS_NS = 50000000L;
    /**
     * @see #getDurations(int, int)
+20 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.graphics.ImageFormat;
import android.graphics.ImageFormat.Format;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.hardware.camera2.params.StreamConfigurationMap;
import android.hardware.camera2.utils.SurfaceUtils;
import android.hardware.HardwareBuffer;
import android.os.Handler;
@@ -202,6 +203,25 @@ public class ImageWriter implements AutoCloseable {
        if (format == ImageFormat.UNKNOWN) {
            format = SurfaceUtils.getSurfaceFormat(surface);
        }
        // Several public formats use the same native HAL_PIXEL_FORMAT_BLOB. The native
        // allocation estimation sequence depends on the public formats values. To avoid
        // possible errors, convert where necessary.
        if (format == StreamConfigurationMap.HAL_PIXEL_FORMAT_BLOB) {
            int surfaceDataspace = SurfaceUtils.getSurfaceDataspace(surface);
            switch (surfaceDataspace) {
                case StreamConfigurationMap.HAL_DATASPACE_DEPTH:
                    format = ImageFormat.DEPTH_POINT_CLOUD;
                    break;
                case StreamConfigurationMap.HAL_DATASPACE_DYNAMIC_DEPTH:
                    format = ImageFormat.DEPTH_JPEG;
                    break;
                case StreamConfigurationMap.HAL_DATASPACE_HEIF:
                    format = ImageFormat.HEIC;
                    break;
                default:
                    format = ImageFormat.JPEG;
            }
        }
        // Estimate the native buffer allocation size and register it so it gets accounted for
        // during GC. Note that this doesn't include the buffers required by the buffer queue
        // itself and the buffers requested by the producer.