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

Commit 8f65420f authored by Shuzhen Wang's avatar Shuzhen Wang
Browse files

Camera: Fixes for OutputConfiguration.getConfiguredFormat

- Add missing HAL_PIXEL_FORMAT_YCBCR_422_I case
- Clean up format override for RGB output formats.
  RGB formats are overridden to PRIVATE if they have
  HARDWARE and no SOFTWARE_READ usage flags.

Flag: com.android.internal.camera.flags.surface_format_fix
Bug: 424865503
Test: Run CameraDeviceSetupTest
Change-Id: I985a0ee428ab6b8a5f02d5b0fa7da536aac53cfc
parent 81d75a8d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -965,7 +965,7 @@ public final class OutputConfiguration implements Parcelable {
        mConfiguredSize = surfaceSize;
        mConfiguredFormat = StreamConfigurationMap.imageFormatToInternal(format);
        mConfiguredDataspace = StreamConfigurationMap.imageFormatToDataspace(format);
        mPublicFormat = format;
        mPublicFormat = SurfaceUtils.getOverrideFormat(format, usage);
        mConfiguredGenerationId = 0;
        mIsDeferredConfig = false;
        mIsShared = false;
+1 −0
Original line number Diff line number Diff line
@@ -1695,6 +1695,7 @@ public final class StreamConfigurationMap {
            case HAL_PIXEL_FORMAT_RGB_565:
            case HAL_PIXEL_FORMAT_YCBCR_422_SP:
            case HAL_PIXEL_FORMAT_YCRCB_420_SP:
            case HAL_PIXEL_FORMAT_YCBCR_422_I:
            case HAL_PIXEL_FORMAT_RAW16:
            case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
            case HAL_PIXEL_FORMAT_YCBCR_420_888:
+31 −9
Original line number Diff line number Diff line
@@ -29,6 +29,8 @@ import android.util.Range;
import android.util.Size;
import android.view.Surface;

import com.android.internal.camera.flags.Flags;

import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
@@ -42,6 +44,8 @@ public class SurfaceUtils {
    // Usage flags not yet included in HardwareBuffer
    private static final int USAGE_RENDERSCRIPT = 0x00100000;
    private static final int USAGE_HW_COMPOSER = 0x00000800;
    private static final int USAGE_HW_MASK = 0x00071F00;
    private static final int USAGE_SW_READ_MASK = 0x0000000F;

    // Image formats not yet included in PixelFormat
    private static final int BGRA_8888 = 0x5;
@@ -63,7 +67,6 @@ public class SurfaceUtils {
                | HardwareBuffer.USAGE_GPU_COLOR_OUTPUT;
        boolean previewConsumer = ((usageFlags & disallowedFlags) == 0
                && (usageFlags & allowedFlags) != 0);
        int surfaceFormat = getSurfaceFormat(surface);

        return previewConsumer;
    }
@@ -84,8 +87,6 @@ public class SurfaceUtils {
        boolean videoEncoderConsumer = ((usageFlags & disallowedFlags) == 0
                && (usageFlags & allowedFlags) != 0);

        int surfaceFormat = getSurfaceFormat(surface);

        return videoEncoderConsumer;
    }

@@ -149,14 +150,35 @@ public class SurfaceUtils {
        checkNotNull(surface);
        int surfaceType = nativeDetectSurfaceType(surface);
        if (surfaceType == BAD_VALUE) throw new IllegalArgumentException("Surface was abandoned");
        long usageFlags = nativeDetectSurfaceUsageFlags(surface);
        return getOverrideFormat(surfaceType, usageFlags);
    }

    /**
     * Get override format based on application specified format and usage flags
     *
     * If the camera override the output format, return the
     * overridden value. Otherwise, return the original value.
     *
     * @param format The format set by the application
     * @param usage The consumer usage flag of the output surface
     * @return format of the camera output
     */
    public static int getOverrideFormat(int format, long usage) {
        if (format >= PixelFormat.RGBA_8888 && format <= BGRA_8888) {
            if (!Flags.surfaceFormatFix()) {
                // Maintain existing behavior
                return ImageFormat.PRIVATE;
            }

        // TODO: remove this override since the default format should be
        // ImageFormat.PRIVATE. b/9487482
        if ((surfaceType >= PixelFormat.RGBA_8888
                && surfaceType <= BGRA_8888)) {
            surfaceType = ImageFormat.PRIVATE;
            // Only override to PRIVATE if the usage has only hardware
            // bits.
            if (((usage & USAGE_HW_MASK) != 0)
                    && ((usage & USAGE_SW_READ_MASK) == 0)) {
                return ImageFormat.PRIVATE;
            }
        return surfaceType;
        }
        return format;
    }

    /**