diff options
author | 2019-02-19 15:52:08 -0800 | |
---|---|---|
committer | 2019-02-20 10:48:04 -0800 | |
commit | e7c158f1148ddd774e33a33ff3db216726b04f5c (patch) | |
tree | afdbee9e88dcb4724792cfb93932575ece92fb48 | |
parent | fee9bcf89b89ace5a096b247c015d28cb0e342b5 (diff) |
Add annotations for ImageReader/ImageWriter factory methods
Test: make update-api && make
Bug: 124766727
Change-Id: I7f7c5afd013370ab6e42c28b96b3cfa93e8dc615
-rw-r--r-- | api/current.txt | 8 | ||||
-rw-r--r-- | graphics/java/android/graphics/ImageFormat.java | 40 | ||||
-rw-r--r-- | media/java/android/media/ImageReader.java | 18 | ||||
-rw-r--r-- | media/java/android/media/ImageWriter.java | 9 |
4 files changed, 64 insertions, 11 deletions
diff --git a/api/current.txt b/api/current.txt index d11b6a4c6525..1624cec16730 100644 --- a/api/current.txt +++ b/api/current.txt @@ -23963,8 +23963,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); } @@ -23977,8 +23977,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); } |