Camera2: Consolidate the overriding of PRIVATE format

We had overriding of PRIVATE format scattered at multiple places.
Consolidate them into one place.

Test: Camera preview/capture, and camcorder recording
Change-Id: I098ce93bba2000760a20c0297fcf0cb9d8c6caab
This commit is contained in:
Shuzhen Wang
2016-12-07 14:46:30 -08:00
parent f3fc930c3c
commit 71e6d62d23
3 changed files with 11 additions and 18 deletions

View File

@@ -348,9 +348,7 @@ public class LegacyCameraDevice implements AutoCloseable {
Size[] sizes = streamConfigurations.getOutputSizes(surfaceType);
if (sizes == null) {
// WAR: Override default format to IMPLEMENTATION_DEFINED for b/9487482
if ((surfaceType >= LegacyMetadataMapper.HAL_PIXEL_FORMAT_RGBA_8888 &&
surfaceType <= LegacyMetadataMapper.HAL_PIXEL_FORMAT_BGRA_8888)) {
if (surfaceType == ImageFormat.PRIVATE) {
// YUV_420_888 is always present in LEGACY for all
// IMPLEMENTATION_DEFINED output sizes, and is publicly visible in the
@@ -649,7 +647,16 @@ public class LegacyCameraDevice implements AutoCloseable {
*/
public static int detectSurfaceType(Surface surface) throws BufferQueueAbandonedException {
checkNotNull(surface);
return LegacyExceptionUtils.throwOnError(nativeDetectSurfaceType(surface));
int surfaceType = nativeDetectSurfaceType(surface);
// TODO: remove this override since the default format should be
// ImageFormat.PRIVATE. b/9487482
if ((surfaceType >= LegacyMetadataMapper.HAL_PIXEL_FORMAT_RGBA_8888 &&
surfaceType <= LegacyMetadataMapper.HAL_PIXEL_FORMAT_BGRA_8888)) {
surfaceType = ImageFormat.PRIVATE;
}
return LegacyExceptionUtils.throwOnError(surfaceType);
}
/**

View File

@@ -408,12 +408,6 @@ public final class StreamConfigurationMap {
// See if consumer is flexible.
boolean isFlexible = SurfaceUtils.isFlexibleConsumer(surface);
// Override RGB formats to IMPLEMENTATION_DEFINED, b/9487482
if ((surfaceFormat >= LegacyMetadataMapper.HAL_PIXEL_FORMAT_RGBA_8888 &&
surfaceFormat <= LegacyMetadataMapper.HAL_PIXEL_FORMAT_BGRA_8888)) {
surfaceFormat = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;
}
StreamConfiguration[] configs =
surfaceDataspace != HAL_DATASPACE_DEPTH ? mConfigurations : mDepthConfigurations;
for (StreamConfiguration config : configs) {

View File

@@ -118,15 +118,7 @@ public class SurfaceUtils {
* @param surface The high speed output surface to be checked.
*/
private static void checkHighSpeedSurfaceFormat(Surface surface) {
// TODO: remove this override since the default format should be
// ImageFormat.PRIVATE. b/9487482
final int HAL_FORMAT_RGB_START = 1; // HAL_PIXEL_FORMAT_RGBA_8888 from graphics.h
final int HAL_FORMAT_RGB_END = 5; // HAL_PIXEL_FORMAT_BGRA_8888 from graphics.h
int surfaceFormat = SurfaceUtils.getSurfaceFormat(surface);
if (surfaceFormat >= HAL_FORMAT_RGB_START &&
surfaceFormat <= HAL_FORMAT_RGB_END) {
surfaceFormat = ImageFormat.PRIVATE;
}
if (surfaceFormat != ImageFormat.PRIVATE) {
throw new IllegalArgumentException("Surface format(" + surfaceFormat + ") is not"