Merge "Fix the issue in ImageWriter Builder class." into tm-dev
This commit is contained in:
@@ -108,7 +108,6 @@ public class ImageWriter implements AutoCloseable {
|
|||||||
private long mUsage = HardwareBuffer.USAGE_CPU_WRITE_OFTEN;
|
private long mUsage = HardwareBuffer.USAGE_CPU_WRITE_OFTEN;
|
||||||
private @HardwareBuffer.Format int mHardwareBufferFormat;
|
private @HardwareBuffer.Format int mHardwareBufferFormat;
|
||||||
private @NamedDataSpace int mDataSpace;
|
private @NamedDataSpace int mDataSpace;
|
||||||
private boolean mUseLegacyImageFormat;
|
|
||||||
|
|
||||||
// Field below is used by native code, do not access or modify.
|
// Field below is used by native code, do not access or modify.
|
||||||
private int mWriterFormat;
|
private int mWriterFormat;
|
||||||
@@ -257,7 +256,6 @@ public class ImageWriter implements AutoCloseable {
|
|||||||
+ ", maxImages: " + maxImages);
|
+ ", maxImages: " + maxImages);
|
||||||
}
|
}
|
||||||
|
|
||||||
mUseLegacyImageFormat = useLegacyImageFormat;
|
|
||||||
// Note that the underlying BufferQueue is working in synchronous mode
|
// Note that the underlying BufferQueue is working in synchronous mode
|
||||||
// to avoid dropping any buffers.
|
// to avoid dropping any buffers.
|
||||||
mNativeContext = nativeInit(new WeakReference<>(this), surface, maxImages, width, height,
|
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) {
|
int hardwareBufferFormat, int dataSpace, int width, int height, long usage) {
|
||||||
mMaxImages = maxImages;
|
mMaxImages = maxImages;
|
||||||
mUsage = usage;
|
mUsage = usage;
|
||||||
mHardwareBufferFormat = hardwareBufferFormat;
|
int imageFormat;
|
||||||
mDataSpace = dataSpace;
|
// if useSurfaceImageFormatInfo is true, imageFormat will be set to UNKNOWN
|
||||||
int publicFormat = PublicFormatUtils.getPublicFormat(hardwareBufferFormat, dataSpace);
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
initializeImageWriter(surface, maxImages, useSurfaceImageFormatInfo, false,
|
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 @HardwareBuffer.Format int mHardwareBufferFormat = HardwareBuffer.RGBA_8888;
|
||||||
private @NamedDataSpace int mDataSpace = DataSpace.DATASPACE_UNKNOWN;
|
private @NamedDataSpace int mDataSpace = DataSpace.DATASPACE_UNKNOWN;
|
||||||
private boolean mUseSurfaceImageFormatInfo = true;
|
private boolean mUseSurfaceImageFormatInfo = true;
|
||||||
// set this as true temporarily now as a workaround to get correct format
|
private boolean mUseLegacyImageFormat = false;
|
||||||
// when using surface format by default without overriding the image format
|
|
||||||
// in the builder pattern
|
|
||||||
private boolean mUseLegacyImageFormat = true;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new builder for {@link ImageWriter}.
|
* 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.
|
* @param surface The destination Surface this writer produces Image data into.
|
||||||
*
|
*
|
||||||
* @throws IllegalArgumentException if the surface is already abandoned.
|
* @throws IllegalArgumentException if the surface is already abandoned.
|
||||||
*/
|
*/
|
||||||
public Builder(@NonNull Surface surface) {
|
public Builder(@NonNull Surface surface) {
|
||||||
mSurface = 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;
|
mWidth = writer.mWidth;
|
||||||
mHeight = writer.mHeight;
|
mHeight = writer.mHeight;
|
||||||
mDataSpace = writer.mDataSpace;
|
mDataSpace = writer.mDataSpace;
|
||||||
|
|
||||||
if (!mOwner.mUseLegacyImageFormat) {
|
|
||||||
mFormat = PublicFormatUtils.getPublicFormat(
|
|
||||||
mOwner.mHardwareBufferFormat, mDataSpace);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1083,7 +1075,7 @@ public class ImageWriter implements AutoCloseable {
|
|||||||
public int getFormat() {
|
public int getFormat() {
|
||||||
throwISEIfImageIsInvalid();
|
throwISEIfImageIsInvalid();
|
||||||
|
|
||||||
if (mOwner.mUseLegacyImageFormat && mFormat == -1) {
|
if (mFormat == -1) {
|
||||||
mFormat = nativeGetFormat(mDataSpace);
|
mFormat = nativeGetFormat(mDataSpace);
|
||||||
}
|
}
|
||||||
return mFormat;
|
return mFormat;
|
||||||
|
|||||||
Reference in New Issue
Block a user