summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2019-02-22 00:27:43 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2019-02-22 00:27:43 +0000
commit432b9640a667be9fff16d9e2253ade1be32ed33e (patch)
tree5d500da563060e75d4f8f45a8fe820fabb1b0685
parent7a81c02723306c6f77b5240b2460dae5fe6f3b29 (diff)
parente7c158f1148ddd774e33a33ff3db216726b04f5c (diff)
Merge "Add annotations for ImageReader/ImageWriter factory methods"
-rw-r--r--api/current.txt8
-rw-r--r--graphics/java/android/graphics/ImageFormat.java40
-rw-r--r--media/java/android/media/ImageReader.java18
-rw-r--r--media/java/android/media/ImageWriter.java9
4 files changed, 64 insertions, 11 deletions
diff --git a/api/current.txt b/api/current.txt
index 0d67dcb35f8c..4ef524363f39 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -24014,8 +24014,8 @@ package android.media {
method public int getMaxImages();
method public android.view.Surface getSurface();
method public int getWidth();
- method public static android.media.ImageReader newInstance(int, int, int, int);
- method public static android.media.ImageReader newInstance(int, int, int, int, long);
+ method @NonNull public static android.media.ImageReader newInstance(@IntRange(from=1) int, @IntRange(from=1) int, int, @IntRange(from=1) int);
+ method @NonNull public static android.media.ImageReader newInstance(@IntRange(from=1) int, @IntRange(from=1) int, int, @IntRange(from=1) int, long);
method public void setOnImageAvailableListener(android.media.ImageReader.OnImageAvailableListener, android.os.Handler);
}
@@ -24028,8 +24028,8 @@ package android.media {
method public android.media.Image dequeueInputImage();
method public int getFormat();
method public int getMaxImages();
- method public static android.media.ImageWriter newInstance(android.view.Surface, int);
- method public static android.media.ImageWriter newInstance(android.view.Surface, int, int);
+ method @NonNull public static android.media.ImageWriter newInstance(@NonNull android.view.Surface, @IntRange(from=1) int);
+ method @NonNull public static android.media.ImageWriter newInstance(@NonNull android.view.Surface, @IntRange(from=1) int, int);
method public void queueInputImage(android.media.Image);
method public void setOnImageReleasedListener(android.media.ImageWriter.OnImageReleasedListener, android.os.Handler);
}
diff --git a/graphics/java/android/graphics/ImageFormat.java b/graphics/java/android/graphics/ImageFormat.java
index 62647741dcfa..15d855e9560c 100644
--- a/graphics/java/android/graphics/ImageFormat.java
+++ b/graphics/java/android/graphics/ImageFormat.java
@@ -16,7 +16,43 @@
package android.graphics;
+import android.annotation.IntDef;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
public class ImageFormat {
+ /** @hide */
+ @Retention(RetentionPolicy.SOURCE)
+ @IntDef(value = {
+ UNKNOWN,
+ RGB_565,
+ YV12,
+ Y8,
+ Y16,
+ NV16,
+ NV21,
+ YUY2,
+ JPEG,
+ DEPTH_JPEG,
+ YUV_420_888,
+ YUV_422_888,
+ YUV_444_888,
+ FLEX_RGB_888,
+ FLEX_RGBA_8888,
+ RAW_SENSOR,
+ RAW_PRIVATE,
+ RAW10,
+ RAW12,
+ DEPTH16,
+ DEPTH_POINT_CLOUD,
+ RAW_DEPTH,
+ PRIVATE,
+ HEIC
+ })
+ public @interface Format {
+ }
+
/*
* these constants are chosen to be binary compatible with their previous
* location in PixelFormat.java
@@ -731,7 +767,7 @@ public class ImageFormat {
* @return the number of bits per pixel of the given format or -1 if the
* format doesn't exist or is not supported.
*/
- public static int getBitsPerPixel(int format) {
+ public static int getBitsPerPixel(@Format int format) {
switch (format) {
case RGB_565:
return 16;
@@ -781,7 +817,7 @@ public class ImageFormat {
*
* @hide
*/
- public static boolean isPublicFormat(int format) {
+ public static boolean isPublicFormat(@Format int format) {
switch (format) {
case RGB_565:
case NV16:
diff --git a/media/java/android/media/ImageReader.java b/media/java/android/media/ImageReader.java
index 6116429ae561..ba87f2bbffb5 100644
--- a/media/java/android/media/ImageReader.java
+++ b/media/java/android/media/ImageReader.java
@@ -16,8 +16,12 @@
package android.media;
+import android.annotation.IntRange;
+import android.annotation.NonNull;
import android.graphics.ImageFormat;
+import android.graphics.ImageFormat.Format;
import android.hardware.HardwareBuffer;
+import android.hardware.HardwareBuffer.Usage;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
@@ -120,7 +124,11 @@ public class ImageReader implements AutoCloseable {
* Must be greater than 0.
* @see Image
*/
- public static ImageReader newInstance(int width, int height, int format, int maxImages) {
+ public static @NonNull ImageReader newInstance(
+ @IntRange(from = 1) int width,
+ @IntRange(from = 1) int height,
+ @Format int format,
+ @IntRange(from = 1) int maxImages) {
// If the format is private don't default to USAGE_CPU_READ_OFTEN since it may not
// work, and is inscrutable anyway
return new ImageReader(width, height, format, maxImages,
@@ -210,8 +218,12 @@ public class ImageReader implements AutoCloseable {
* @see Image
* @see HardwareBuffer
*/
- public static ImageReader newInstance(int width, int height, int format, int maxImages,
- long usage) {
+ public static @NonNull ImageReader newInstance(
+ @IntRange(from = 1) int width,
+ @IntRange(from = 1) int height,
+ @Format int format,
+ @IntRange(from = 1) int maxImages,
+ @Usage long usage) {
// TODO: Check this - can't do it just yet because format support is different
// Unify formats! The only reliable way to validate usage is to just try it and see.
diff --git a/media/java/android/media/ImageWriter.java b/media/java/android/media/ImageWriter.java
index dd09afc3ddb0..f813d1b68419 100644
--- a/media/java/android/media/ImageWriter.java
+++ b/media/java/android/media/ImageWriter.java
@@ -16,7 +16,10 @@
package android.media;
+import android.annotation.IntRange;
+import android.annotation.NonNull;
import android.graphics.ImageFormat;
+import android.graphics.ImageFormat.Format;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.hardware.camera2.utils.SurfaceUtils;
@@ -124,7 +127,8 @@ public class ImageWriter implements AutoCloseable {
* {@link #dequeueInputImage()}.
* @return a new ImageWriter instance.
*/
- public static ImageWriter newInstance(Surface surface, int maxImages) {
+ public static @NonNull ImageWriter newInstance(@NonNull Surface surface,
+ @IntRange(from = 1) int maxImages) {
return new ImageWriter(surface, maxImages, ImageFormat.UNKNOWN);
}
@@ -169,7 +173,8 @@ public class ImageWriter implements AutoCloseable {
*
* @return a new ImageWriter instance.
*/
- public static ImageWriter newInstance(Surface surface, int maxImages, int format) {
+ public static @NonNull ImageWriter newInstance(@NonNull Surface surface,
+ @IntRange(from = 1) int maxImages, @Format int format) {
if (!ImageFormat.isPublicFormat(format) && !PixelFormat.isPublicFormat(format)) {
throw new IllegalArgumentException("Invalid format is specified: " + format);
}