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

Commit 7da4d886 authored by Sally Qi's avatar Sally Qi
Browse files

Fix the issue in ImageWriter Builder class.

- Builder.mUseLegacyImageFormat is set to false by default. Fix the
  mismatch format result.

Bug: 215717202
Test: android.hardware.cts.DataSpaceTest,
android.hardware.camera2.cts.ImageWriterTest,android.hardware.camera2.cts.ImageReaderTest

Change-Id: I69639cfcd7b486d7dc464d549c8a110cbb2ae89f
Merged-In: I69639cfcd7b486d7dc464d549c8a110cbb2ae89f
parent ed033ac4
Loading
Loading
Loading
Loading
+15 −23
Original line number Diff line number Diff line
@@ -108,7 +108,6 @@ public class ImageWriter implements AutoCloseable {
    private long mUsage = HardwareBuffer.USAGE_CPU_WRITE_OFTEN;
    private @HardwareBuffer.Format int mHardwareBufferFormat;
    private @NamedDataSpace int mDataSpace;
    private boolean mUseLegacyImageFormat;

    // Field below is used by native code, do not access or modify.
    private int mWriterFormat;
@@ -257,7 +256,6 @@ public class ImageWriter implements AutoCloseable {
                + ", maxImages: " + maxImages);
        }

        mUseLegacyImageFormat = useLegacyImageFormat;
        // Note that the underlying BufferQueue is working in synchronous mode
        // to avoid dropping any buffers.
        mNativeContext = nativeInit(new WeakReference<>(this), surface, maxImages, width, height,
@@ -334,12 +332,21 @@ public class ImageWriter implements AutoCloseable {
            int hardwareBufferFormat, int dataSpace, int width, int height, long usage) {
        mMaxImages = maxImages;
        mUsage = usage;
        int imageFormat;
        // if useSurfaceImageFormatInfo is true, imageFormat will be set to UNKNOWN
        // and retrieve corresponding hardwareBufferFormat and dataSpace here.
        if (useSurfaceImageFormatInfo) {
            imageFormat = ImageFormat.UNKNOWN;
            mHardwareBufferFormat = PublicFormatUtils.getHalFormat(imageFormat);
            mDataSpace = PublicFormatUtils.getHalDataspace(imageFormat);
        } else {
            imageFormat = PublicFormatUtils.getPublicFormat(hardwareBufferFormat, dataSpace);
            mHardwareBufferFormat = hardwareBufferFormat;
            mDataSpace = dataSpace;
        int publicFormat = PublicFormatUtils.getPublicFormat(hardwareBufferFormat, dataSpace);
        }

        initializeImageWriter(surface, maxImages, useSurfaceImageFormatInfo, false,
                publicFormat, hardwareBufferFormat, dataSpace, width, height, usage);
                imageFormat, hardwareBufferFormat, dataSpace, width, height, usage);
    }

    /**
@@ -884,27 +891,17 @@ public class ImageWriter implements AutoCloseable {
        private @HardwareBuffer.Format int mHardwareBufferFormat = HardwareBuffer.RGBA_8888;
        private @NamedDataSpace int mDataSpace = DataSpace.DATASPACE_UNKNOWN;
        private boolean mUseSurfaceImageFormatInfo = true;
        // set this as true temporarily now as a workaround to get correct format
        // when using surface format by default without overriding the image format
        // in the builder pattern
        private boolean mUseLegacyImageFormat = true;
        private boolean mUseLegacyImageFormat = false;

        /**
         * Constructs a new builder for {@link ImageWriter}.
         *
         * <p>Uses {@code surface} input parameter to retrieve image format, hal format
         * and hal dataspace value for default. </p>
         *
         * @param surface The destination Surface this writer produces Image data into.
         *
         * @throws IllegalArgumentException if the surface is already abandoned.
         */
        public Builder(@NonNull Surface surface) {
            mSurface = surface;
            // retrieve format from surface
            mImageFormat = SurfaceUtils.getSurfaceFormat(surface);
            mDataSpace = SurfaceUtils.getSurfaceDataspace(surface);
            mHardwareBufferFormat = PublicFormatUtils.getHalFormat(mImageFormat);
        }

        /**
@@ -1058,11 +1055,6 @@ public class ImageWriter implements AutoCloseable {
            mWidth = writer.mWidth;
            mHeight = writer.mHeight;
            mDataSpace = writer.mDataSpace;

            if (!mOwner.mUseLegacyImageFormat) {
                mFormat = PublicFormatUtils.getPublicFormat(
                    mOwner.mHardwareBufferFormat, mDataSpace);
            }
        }

        @Override
@@ -1083,7 +1075,7 @@ public class ImageWriter implements AutoCloseable {
        public int getFormat() {
            throwISEIfImageIsInvalid();

            if (mOwner.mUseLegacyImageFormat && mFormat == -1) {
            if (mFormat == -1) {
                mFormat = nativeGetFormat(mDataSpace);
            }
            return mFormat;