diff options
| author | 2020-09-10 17:22:18 +0000 | |
|---|---|---|
| committer | 2020-09-10 17:22:18 +0000 | |
| commit | cdb6b16dec3a541b455be99d075004cb2f0a0cd7 (patch) | |
| tree | f7110d50445c67a337105034b1f2db3946a88fef /include/android | |
| parent | 171cac1b603e4bb83412eb596d05a500af5d7a76 (diff) | |
| parent | ac07d0f5ab16bb9e8bbbabb589d1c7d36817baa9 (diff) | |
Merge "Merge Android R"
Diffstat (limited to 'include/android')
| -rw-r--r-- | include/android/bitmap.h | 159 | ||||
| -rw-r--r-- | include/android/choreographer.h | 72 | ||||
| -rw-r--r-- | include/android/configuration.h | 122 | ||||
| -rw-r--r-- | include/android/hardware_buffer_jni.h | 19 | ||||
| -rw-r--r-- | include/android/imagedecoder.h | 538 | ||||
| -rw-r--r-- | include/android/input.h | 7 | ||||
| -rw-r--r-- | include/android/sensor.h | 16 | ||||
| -rw-r--r-- | include/android/surface_control.h | 32 | ||||
| -rw-r--r-- | include/android/thermal.h | 190 |
9 files changed, 1073 insertions, 82 deletions
diff --git a/include/android/bitmap.h b/include/android/bitmap.h index 2def64dc90..f19539913e 100644 --- a/include/android/bitmap.h +++ b/include/android/bitmap.h @@ -26,6 +26,7 @@ #ifndef ANDROID_BITMAP_H #define ANDROID_BITMAP_H +#include <stdbool.h> #include <stdint.h> #include <jni.h> @@ -60,6 +61,30 @@ enum AndroidBitmapFormat { ANDROID_BITMAP_FORMAT_RGBA_4444 = 7, /** Alpha: 8 bits. */ ANDROID_BITMAP_FORMAT_A_8 = 8, + /** Each component is stored as a half float. **/ + ANDROID_BITMAP_FORMAT_RGBA_F16 = 9, +}; + +/** Bitmap alpha format */ +enum { + /** Pixel components are premultiplied by alpha. */ + ANDROID_BITMAP_FLAGS_ALPHA_PREMUL = 0, + /** Pixels are opaque. */ + ANDROID_BITMAP_FLAGS_ALPHA_OPAQUE = 1, + /** Pixel components are independent of alpha. */ + ANDROID_BITMAP_FLAGS_ALPHA_UNPREMUL = 2, + /** Bit mask for AndroidBitmapFormat.flags to isolate the alpha. */ + ANDROID_BITMAP_FLAGS_ALPHA_MASK = 0x3, + /** Shift for AndroidBitmapFormat.flags to isolate the alpha. */ + ANDROID_BITMAP_FLAGS_ALPHA_SHIFT = 0, +}; + +enum { + /** If this bit is set in AndroidBitmapInfo.flags, the Bitmap uses the + * HARDWARE Config, and its {@link AHardwareBuffer} can be retrieved via + * {@link AndroidBitmap_getHardwareBuffer}. + */ + ANDROID_BITMAP_FLAGS_IS_HARDWARE = 1 << 31, }; /** Bitmap info, see AndroidBitmap_getInfo(). */ @@ -72,17 +97,41 @@ typedef struct { uint32_t stride; /** The bitmap pixel format. See {@link AndroidBitmapFormat} */ int32_t format; - /** Unused. */ - uint32_t flags; // 0 for now + /** Bitfield containing information about the bitmap. + * + * <p>Two bits are used to encode alpha. Use {@link ANDROID_BITMAP_FLAGS_ALPHA_MASK} + * and {@link ANDROID_BITMAP_FLAGS_ALPHA_SHIFT} to retrieve them.</p> + * + * <p>One bit is used to encode whether the Bitmap uses the HARDWARE Config. Use + * {@link ANDROID_BITMAP_FLAGS_IS_HARDWARE} to know.</p> + * + * <p>These flags were introduced in API level 30.</p> + */ + uint32_t flags; } AndroidBitmapInfo; /** - * Given a java bitmap object, fill out the AndroidBitmapInfo struct for it. + * Given a java bitmap object, fill out the {@link AndroidBitmapInfo} struct for it. * If the call fails, the info parameter will be ignored. */ int AndroidBitmap_getInfo(JNIEnv* env, jobject jbitmap, AndroidBitmapInfo* info); +#if __ANDROID_API__ >= 30 + +/** + * Given a java bitmap object, return its {@link ADataSpace}. + * + * Note that {@link ADataSpace} only exposes a few values. This may return + * {@link ADATASPACE_UNKNOWN}, even for Named ColorSpaces, if they have no + * corresponding ADataSpace. + * + * Available since API level 30. + */ +int32_t AndroidBitmap_getDataSpace(JNIEnv* env, jobject jbitmap) __INTRODUCED_IN(30); + +#endif // __ANDROID_API__ >= 30 + /** * Given a java bitmap object, attempt to lock the pixel address. * Locking will ensure that the memory for the pixels will not move @@ -103,6 +152,110 @@ int AndroidBitmap_lockPixels(JNIEnv* env, jobject jbitmap, void** addrPtr); */ int AndroidBitmap_unlockPixels(JNIEnv* env, jobject jbitmap); +#if __ANDROID_API__ >= 30 + +// Note: these values match android.graphics.Bitmap#compressFormat. + +/** + * Specifies the formats that can be compressed to with + * {@link AndroidBitmap_compress}. + */ +enum AndroidBitmapCompressFormat { + /** + * Compress to the JPEG format. quality of 0 means + * compress for the smallest size. 100 means compress for max + * visual quality. + */ + ANDROID_BITMAP_COMPRESS_FORMAT_JPEG = 0, + /** + * Compress to the PNG format. PNG is lossless, so quality is + * ignored. + */ + ANDROID_BITMAP_COMPRESS_FORMAT_PNG = 1, + /** + * Compress to the WEBP lossy format. quality of 0 means + * compress for the smallest size. 100 means compress for max + * visual quality. + */ + ANDROID_BITMAP_COMPRESS_FORMAT_WEBP_LOSSY = 3, + /** + * Compress to the WEBP lossless format. quality refers to how + * much effort to put into compression. A value of 0 means to + * compress quickly, resulting in a relatively large file size. + * 100 means to spend more time compressing, resulting in a + * smaller file. + */ + ANDROID_BITMAP_COMPRESS_FORMAT_WEBP_LOSSLESS = 4, +}; + +/** + * User-defined function for writing the output of compression. + * + * Available since API level 30. + * + * @param userContext Pointer to user-defined data passed to + * {@link AndroidBitmap_compress}. + * @param data Compressed data of |size| bytes to write. + * @param size Length in bytes of data to write. + * @return Whether the operation succeeded. + */ +typedef bool (*AndroidBitmap_CompressWriteFunc)(void* userContext, + const void* data, + size_t size) __INTRODUCED_IN(30); + +/** + * Compress |pixels| as described by |info|. + * + * Available since API level 30. + * + * @param info Description of the pixels to compress. + * @param dataspace {@link ADataSpace} describing the color space of the + * pixels. + * @param pixels Pointer to pixels to compress. + * @param format {@link AndroidBitmapCompressFormat} to compress to. + * @param quality Hint to the compressor, 0-100. The value is interpreted + * differently depending on the + * {@link AndroidBitmapCompressFormat}. + * @param userContext User-defined data which will be passed to the supplied + * {@link AndroidBitmap_CompressWriteFunc} each time it is + * called. May be null. + * @param fn Function that writes the compressed data. Will be called each time + * the compressor has compressed more data that is ready to be + * written. May be called more than once for each call to this method. + * May not be null. + * @return AndroidBitmap functions result code. + */ +int AndroidBitmap_compress(const AndroidBitmapInfo* info, + int32_t dataspace, + const void* pixels, + int32_t format, int32_t quality, + void* userContext, + AndroidBitmap_CompressWriteFunc fn) __INTRODUCED_IN(30); + +struct AHardwareBuffer; +typedef struct AHardwareBuffer AHardwareBuffer; + +/** + * Retrieve the native object associated with a HARDWARE Bitmap. + * + * Client must not modify it while a Bitmap is wrapping it. + * + * Available since API level 30. + * + * @param bitmap Handle to an android.graphics.Bitmap. + * @param outBuffer On success, is set to a pointer to the + * {@link AHardwareBuffer} associated with bitmap. This acquires + * a reference on the buffer, and the client must call + * {@link AHardwareBuffer_release} when finished with it. + * @return AndroidBitmap functions result code. + * {@link ANDROID_BITMAP_RESULT_BAD_PARAMETER} if bitmap is not a + * HARDWARE Bitmap. + */ +int AndroidBitmap_getHardwareBuffer(JNIEnv* env, jobject bitmap, + AHardwareBuffer** outBuffer) __INTRODUCED_IN(30); + +#endif // __ANDROID_API__ >= 30 + #ifdef __cplusplus } #endif diff --git a/include/android/choreographer.h b/include/android/choreographer.h index 346861f0a8..e9f559cd8e 100644 --- a/include/android/choreographer.h +++ b/include/android/choreographer.h @@ -54,6 +54,13 @@ typedef void (*AChoreographer_frameCallback)(long frameTimeNanos, void* data); */ typedef void (*AChoreographer_frameCallback64)(int64_t frameTimeNanos, void* data); +/** + * Prototype of the function that is called when the display refresh rate + * changes. It's passed the new vsync period in nanoseconds, as well as the data + * pointer provided by the application that registered a callback. + */ +typedef void (*AChoreographer_refreshRateCallback)(int64_t vsyncPeriodNanos, void* data); + #if __ANDROID_API__ >= 24 /** @@ -68,14 +75,16 @@ AChoreographer* AChoreographer_getInstance() __INTRODUCED_IN(24); * Deprecated: Use AChoreographer_postFrameCallback64 instead. */ void AChoreographer_postFrameCallback(AChoreographer* choreographer, - AChoreographer_frameCallback callback, void* data) __INTRODUCED_IN(24) __DEPRECATED_IN(29); + AChoreographer_frameCallback callback, void* data) + __INTRODUCED_IN(24) __DEPRECATED_IN(29); /** * Deprecated: Use AChoreographer_postFrameCallbackDelayed64 instead. */ void AChoreographer_postFrameCallbackDelayed(AChoreographer* choreographer, - AChoreographer_frameCallback callback, void* data, - long delayMillis) __INTRODUCED_IN(24) __DEPRECATED_IN(29); + AChoreographer_frameCallback callback, void* data, + long delayMillis) __INTRODUCED_IN(24) + __DEPRECATED_IN(29); #endif /* __ANDROID_API__ >= 24 */ @@ -87,8 +96,9 @@ void AChoreographer_postFrameCallbackDelayed(AChoreographer* choreographer, * * Available since API level 29. */ -void AChoreographer_postFrameCallback64(AChoreographer* chroreographer, - AChoreographer_frameCallback64 callback, void* data) __INTRODUCED_IN(29); +void AChoreographer_postFrameCallback64(AChoreographer* choreographer, + AChoreographer_frameCallback64 callback, void* data) + __INTRODUCED_IN(29); /** * Post a callback to be run on the frame following the specified delay. The @@ -98,10 +108,60 @@ void AChoreographer_postFrameCallback64(AChoreographer* chroreographer, * Available since API level 29. */ void AChoreographer_postFrameCallbackDelayed64(AChoreographer* choreographer, - AChoreographer_frameCallback64 callback, void* data, uint32_t delayMillis) __INTRODUCED_IN(29); + AChoreographer_frameCallback64 callback, void* data, + uint32_t delayMillis) __INTRODUCED_IN(29); #endif /* __ANDROID_API__ >= 29 */ +#if __ANDROID_API__ >= 30 + +/** + * Registers a callback to be run when the display refresh rate changes. The + * data pointer provided will be passed to the callback function when it's + * called. The same callback may be registered multiple times, provided that a + * different data pointer is provided each time. + * + * If an application registers a callback for this choreographer instance when + * no new callbacks were previously registered, that callback is guaranteed to + * be dispatched. However, if the callback and associated data pointer are + * unregistered prior to running the callback, then the callback may be silently + * dropped. + * + * This api is thread-safe. Any thread is allowed to register a new refresh + * rate callback for the choreographer instance. + * + * Note that in API level 30, this api is not guaranteed to be atomic with + * DisplayManager. That is, calling Display#getRefreshRate very soon after + * a refresh rate callback is invoked may return a stale refresh rate. If any + * Display properties would be required by this callback, then it is recommended + * to listen directly to DisplayManager.DisplayListener#onDisplayChanged events + * instead. + * + * Available since API level 30. + */ +void AChoreographer_registerRefreshRateCallback(AChoreographer* choreographer, + AChoreographer_refreshRateCallback, void* data) + __INTRODUCED_IN(30); + +/** + * Unregisters a callback to be run when the display refresh rate changes, along + * with the data pointer previously provided when registering the callback. The + * callback is only unregistered when the data pointer matches one that was + * previously registered. + * + * This api is thread-safe. Any thread is allowed to unregister an existing + * refresh rate callback for the choreographer instance. When a refresh rate + * callback and associated data pointer are unregistered, then there is a + * guarantee that when the unregistration completes that that callback will not + * be run with the data pointer passed. + * + * Available since API level 30. + */ +void AChoreographer_unregisterRefreshRateCallback(AChoreographer* choreographer, + AChoreographer_refreshRateCallback, void* data) + __INTRODUCED_IN(30); +#endif /* __ANDROID_API__ >= 30 */ + __END_DECLS #endif // ANDROID_CHOREOGRAPHER_H diff --git a/include/android/configuration.h b/include/android/configuration.h index 05f43407fb..ccf3e59066 100644 --- a/include/android/configuration.h +++ b/include/android/configuration.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 The Android Open Source Project + * Copyright (C) 2010 The Android Open Source Project. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -58,13 +58,13 @@ enum { ACONFIGURATION_ORIENTATION_ANY = 0x0000, /** * Orientation: value corresponding to the - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#OrientationQualifier">port</a> + * <a href="/guide/topics/resources/providing-resources.html#OrientationQualifier">port</a> * resource qualifier. */ ACONFIGURATION_ORIENTATION_PORT = 0x0001, /** * Orientation: value corresponding to the - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#OrientationQualifier">land</a> + * <a href="/guide/topics/resources/providing-resources.html#OrientationQualifier">land</a> * resource qualifier. */ ACONFIGURATION_ORIENTATION_LAND = 0x0002, @@ -75,7 +75,7 @@ enum { ACONFIGURATION_TOUCHSCREEN_ANY = 0x0000, /** * Touchscreen: value corresponding to the - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#TouchscreenQualifier">notouch</a> + * <a href="/guide/topics/resources/providing-resources.html#TouchscreenQualifier">notouch</a> * resource qualifier. */ ACONFIGURATION_TOUCHSCREEN_NOTOUCH = 0x0001, @@ -83,7 +83,7 @@ enum { ACONFIGURATION_TOUCHSCREEN_STYLUS = 0x0002, /** * Touchscreen: value corresponding to the - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#TouchscreenQualifier">finger</a> + * <a href="/guide/topics/resources/providing-resources.html#TouchscreenQualifier">finger</a> * resource qualifier. */ ACONFIGURATION_TOUCHSCREEN_FINGER = 0x0003, @@ -92,43 +92,43 @@ enum { ACONFIGURATION_DENSITY_DEFAULT = 0, /** * Density: value corresponding to the - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#DensityQualifier">ldpi</a> + * <a href="/guide/topics/resources/providing-resources.html#DensityQualifier">ldpi</a> * resource qualifier. */ ACONFIGURATION_DENSITY_LOW = 120, /** * Density: value corresponding to the - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#DensityQualifier">mdpi</a> + * <a href="/guide/topics/resources/providing-resources.html#DensityQualifier">mdpi</a> * resource qualifier. */ ACONFIGURATION_DENSITY_MEDIUM = 160, /** * Density: value corresponding to the - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#DensityQualifier">tvdpi</a> + * <a href="/guide/topics/resources/providing-resources.html#DensityQualifier">tvdpi</a> * resource qualifier. */ ACONFIGURATION_DENSITY_TV = 213, /** * Density: value corresponding to the - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#DensityQualifier">hdpi</a> + * <a href="/guide/topics/resources/providing-resources.html#DensityQualifier">hdpi</a> * resource qualifier. */ ACONFIGURATION_DENSITY_HIGH = 240, /** * Density: value corresponding to the - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#DensityQualifier">xhdpi</a> + * <a href="/guide/topics/resources/providing-resources.html#DensityQualifier">xhdpi</a> * resource qualifier. */ ACONFIGURATION_DENSITY_XHIGH = 320, /** * Density: value corresponding to the - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#DensityQualifier">xxhdpi</a> + * <a href="/guide/topics/resources/providing-resources.html#DensityQualifier">xxhdpi</a> * resource qualifier. */ ACONFIGURATION_DENSITY_XXHIGH = 480, /** * Density: value corresponding to the - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#DensityQualifier">xxxhdpi</a> + * <a href="/guide/topics/resources/providing-resources.html#DensityQualifier">xxxhdpi</a> * resource qualifier. */ ACONFIGURATION_DENSITY_XXXHIGH = 640, @@ -141,19 +141,19 @@ enum { ACONFIGURATION_KEYBOARD_ANY = 0x0000, /** * Keyboard: value corresponding to the - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#ImeQualifier">nokeys</a> + * <a href="/guide/topics/resources/providing-resources.html#ImeQualifier">nokeys</a> * resource qualifier. */ ACONFIGURATION_KEYBOARD_NOKEYS = 0x0001, /** * Keyboard: value corresponding to the - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#ImeQualifier">qwerty</a> + * <a href="/guide/topics/resources/providing-resources.html#ImeQualifier">qwerty</a> * resource qualifier. */ ACONFIGURATION_KEYBOARD_QWERTY = 0x0002, /** * Keyboard: value corresponding to the - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#ImeQualifier">12key</a> + * <a href="/guide/topics/resources/providing-resources.html#ImeQualifier">12key</a> * resource qualifier. */ ACONFIGURATION_KEYBOARD_12KEY = 0x0003, @@ -162,25 +162,25 @@ enum { ACONFIGURATION_NAVIGATION_ANY = 0x0000, /** * Navigation: value corresponding to the - * <a href="@@dacRoot/guide/topics/resources/providing-resources.html#NavigationQualifier">nonav</a> + * <a href="@/guide/topics/resources/providing-resources.html#NavigationQualifier">nonav</a> * resource qualifier. */ ACONFIGURATION_NAVIGATION_NONAV = 0x0001, /** * Navigation: value corresponding to the - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#NavigationQualifier">dpad</a> + * <a href="/guide/topics/resources/providing-resources.html#NavigationQualifier">dpad</a> * resource qualifier. */ ACONFIGURATION_NAVIGATION_DPAD = 0x0002, /** * Navigation: value corresponding to the - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#NavigationQualifier">trackball</a> + * <a href="/guide/topics/resources/providing-resources.html#NavigationQualifier">trackball</a> * resource qualifier. */ ACONFIGURATION_NAVIGATION_TRACKBALL = 0x0003, /** * Navigation: value corresponding to the - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#NavigationQualifier">wheel</a> + * <a href="/guide/topics/resources/providing-resources.html#NavigationQualifier">wheel</a> * resource qualifier. */ ACONFIGURATION_NAVIGATION_WHEEL = 0x0004, @@ -189,19 +189,19 @@ enum { ACONFIGURATION_KEYSHIDDEN_ANY = 0x0000, /** * Keyboard availability: value corresponding to the - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#KeyboardAvailQualifier">keysexposed</a> + * <a href="/guide/topics/resources/providing-resources.html#KeyboardAvailQualifier">keysexposed</a> * resource qualifier. */ ACONFIGURATION_KEYSHIDDEN_NO = 0x0001, /** * Keyboard availability: value corresponding to the - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#KeyboardAvailQualifier">keyshidden</a> + * <a href="/guide/topics/resources/providing-resources.html#KeyboardAvailQualifier">keyshidden</a> * resource qualifier. */ ACONFIGURATION_KEYSHIDDEN_YES = 0x0002, /** * Keyboard availability: value corresponding to the - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#KeyboardAvailQualifier">keyssoft</a> + * <a href="/guide/topics/resources/providing-resources.html#KeyboardAvailQualifier">keyssoft</a> * resource qualifier. */ ACONFIGURATION_KEYSHIDDEN_SOFT = 0x0003, @@ -210,13 +210,13 @@ enum { ACONFIGURATION_NAVHIDDEN_ANY = 0x0000, /** * Navigation availability: value corresponding to the - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#NavAvailQualifier">navexposed</a> + * <a href="/guide/topics/resources/providing-resources.html#NavAvailQualifier">navexposed</a> * resource qualifier. */ ACONFIGURATION_NAVHIDDEN_NO = 0x0001, /** * Navigation availability: value corresponding to the - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#NavAvailQualifier">navhidden</a> + * <a href="/guide/topics/resources/providing-resources.html#NavAvailQualifier">navhidden</a> * resource qualifier. */ ACONFIGURATION_NAVHIDDEN_YES = 0x0002, @@ -226,28 +226,28 @@ enum { /** * Screen size: value indicating the screen is at least * approximately 320x426 dp units, corresponding to the - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#ScreenSizeQualifier">small</a> + * <a href="/guide/topics/resources/providing-resources.html#ScreenSizeQualifier">small</a> * resource qualifier. */ ACONFIGURATION_SCREENSIZE_SMALL = 0x01, /** * Screen size: value indicating the screen is at least * approximately 320x470 dp units, corresponding to the - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#ScreenSizeQualifier">normal</a> + * <a href="/guide/topics/resources/providing-resources.html#ScreenSizeQualifier">normal</a> * resource qualifier. */ ACONFIGURATION_SCREENSIZE_NORMAL = 0x02, /** * Screen size: value indicating the screen is at least * approximately 480x640 dp units, corresponding to the - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#ScreenSizeQualifier">large</a> + * <a href="/guide/topics/resources/providing-resources.html#ScreenSizeQualifier">large</a> * resource qualifier. */ ACONFIGURATION_SCREENSIZE_LARGE = 0x03, /** * Screen size: value indicating the screen is at least * approximately 720x960 dp units, corresponding to the - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#ScreenSizeQualifier">xlarge</a> + * <a href="/guide/topics/resources/providing-resources.html#ScreenSizeQualifier">xlarge</a> * resource qualifier. */ ACONFIGURATION_SCREENSIZE_XLARGE = 0x04, @@ -256,13 +256,13 @@ enum { ACONFIGURATION_SCREENLONG_ANY = 0x00, /** * Screen layout: value that corresponds to the - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#ScreenAspectQualifier">notlong</a> + * <a href="/guide/topics/resources/providing-resources.html#ScreenAspectQualifier">notlong</a> * resource qualifier. */ ACONFIGURATION_SCREENLONG_NO = 0x1, /** * Screen layout: value that corresponds to the - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#ScreenAspectQualifier">long</a> + * <a href="/guide/topics/resources/providing-resources.html#ScreenAspectQualifier">long</a> * resource qualifier. */ ACONFIGURATION_SCREENLONG_YES = 0x2, @@ -275,13 +275,13 @@ enum { ACONFIGURATION_WIDE_COLOR_GAMUT_ANY = 0x00, /** * Wide color gamut: value that corresponds to - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#WideColorGamutQualifier">no + * <a href="/guide/topics/resources/providing-resources.html#WideColorGamutQualifier">no * nowidecg</a> resource qualifier specified. */ ACONFIGURATION_WIDE_COLOR_GAMUT_NO = 0x1, /** * Wide color gamut: value that corresponds to - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#WideColorGamutQualifier"> + * <a href="/guide/topics/resources/providing-resources.html#WideColorGamutQualifier"> * widecg</a> resource qualifier specified. */ ACONFIGURATION_WIDE_COLOR_GAMUT_YES = 0x2, @@ -290,13 +290,13 @@ enum { ACONFIGURATION_HDR_ANY = 0x00, /** * HDR: value that corresponds to - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#HDRQualifier"> + * <a href="/guide/topics/resources/providing-resources.html#HDRQualifier"> * lowdr</a> resource qualifier specified. */ ACONFIGURATION_HDR_NO = 0x1, /** * HDR: value that corresponds to - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#HDRQualifier"> + * <a href="/guide/topics/resources/providing-resources.html#HDRQualifier"> * highdr</a> resource qualifier specified. */ ACONFIGURATION_HDR_YES = 0x2, @@ -305,38 +305,38 @@ enum { ACONFIGURATION_UI_MODE_TYPE_ANY = 0x00, /** * UI mode: value that corresponds to - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#UiModeQualifier">no + * <a href="/guide/topics/resources/providing-resources.html#UiModeQualifier">no * UI mode type</a> resource qualifier specified. */ ACONFIGURATION_UI_MODE_TYPE_NORMAL = 0x01, /** * UI mode: value that corresponds to - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#UiModeQualifier">desk</a> resource qualifier specified. + * <a href="/guide/topics/resources/providing-resources.html#UiModeQualifier">desk</a> resource qualifier specified. */ ACONFIGURATION_UI_MODE_TYPE_DESK = 0x02, /** * UI mode: value that corresponds to - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#UiModeQualifier">car</a> resource qualifier specified. + * <a href="/guide/topics/resources/providing-resources.html#UiModeQualifier">car</a> resource qualifier specified. */ ACONFIGURATION_UI_MODE_TYPE_CAR = 0x03, /** * UI mode: value that corresponds to - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#UiModeQualifier">television</a> resource qualifier specified. + * <a href="/guide/topics/resources/providing-resources.html#UiModeQualifier">television</a> resource qualifier specified. */ ACONFIGURATION_UI_MODE_TYPE_TELEVISION = 0x04, /** * UI mode: value that corresponds to - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#UiModeQualifier">appliance</a> resource qualifier specified. + * <a href="/guide/topics/resources/providing-resources.html#UiModeQualifier">appliance</a> resource qualifier specified. */ ACONFIGURATION_UI_MODE_TYPE_APPLIANCE = 0x05, /** * UI mode: value that corresponds to - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#UiModeQualifier">watch</a> resource qualifier specified. + * <a href="/guide/topics/resources/providing-resources.html#UiModeQualifier">watch</a> resource qualifier specified. */ ACONFIGURATION_UI_MODE_TYPE_WATCH = 0x06, /** * UI mode: value that corresponds to - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#UiModeQualifier">vr</a> resource qualifier specified. + * <a href="/guide/topics/resources/providing-resources.html#UiModeQualifier">vr</a> resource qualifier specified. */ ACONFIGURATION_UI_MODE_TYPE_VR_HEADSET = 0x07, @@ -344,12 +344,12 @@ enum { ACONFIGURATION_UI_MODE_NIGHT_ANY = 0x00, /** * UI night mode: value that corresponds to - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#NightQualifier">notnight</a> resource qualifier specified. + * <a href="/guide/topics/resources/providing-resources.html#NightQualifier">notnight</a> resource qualifier specified. */ ACONFIGURATION_UI_MODE_NIGHT_NO = 0x1, /** * UI night mode: value that corresponds to - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#NightQualifier">night</a> resource qualifier specified. + * <a href="/guide/topics/resources/providing-resources.html#NightQualifier">night</a> resource qualifier specified. */ ACONFIGURATION_UI_MODE_NIGHT_YES = 0x2, @@ -366,78 +366,78 @@ enum { ACONFIGURATION_LAYOUTDIR_ANY = 0x00, /** * Layout direction: value that corresponds to - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#LayoutDirectionQualifier">ldltr</a> resource qualifier specified. + * <a href="/guide/topics/resources/providing-resources.html#LayoutDirectionQualifier">ldltr</a> resource qualifier specified. */ ACONFIGURATION_LAYOUTDIR_LTR = 0x01, /** * Layout direction: value that corresponds to - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#LayoutDirectionQualifier">ldrtl</a> resource qualifier specified. + * <a href="/guide/topics/resources/providing-resources.html#LayoutDirectionQualifier">ldrtl</a> resource qualifier specified. */ ACONFIGURATION_LAYOUTDIR_RTL = 0x02, /** * Bit mask for - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#MccQualifier">mcc</a> + * <a href="/guide/topics/resources/providing-resources.html#MccQualifier">mcc</a> * configuration. */ ACONFIGURATION_MCC = 0x0001, /** * Bit mask for - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#MccQualifier">mnc</a> + * <a href="/guide/topics/resources/providing-resources.html#MccQualifier">mnc</a> * configuration. */ ACONFIGURATION_MNC = 0x0002, /** * Bit mask for - * <a href="{@docRoot}guide/topics/resources/providing-resources.html#LocaleQualifier">locale</a> + * <a href="/guide/topics/resources/providing-resources.html#LocaleQualifier">locale</a> * configuration. */ ACONFIGURATION_LOCALE = 0x0004, /** * Bit mask for - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#TouchscreenQualifier">touchscreen</a> + * <a href="/guide/topics/resources/providing-resources.html#TouchscreenQualifier">touchscreen</a> * configuration. */ ACONFIGURATION_TOUCHSCREEN = 0x0008, /** * Bit mask for - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#ImeQualifier">keyboard</a> + * <a href="/guide/topics/resources/providing-resources.html#ImeQualifier">keyboard</a> * configuration. */ ACONFIGURATION_KEYBOARD = 0x0010, /** * Bit mask for - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#KeyboardAvailQualifier">keyboardHidden</a> + * <a href="/guide/topics/resources/providing-resources.html#KeyboardAvailQualifier">keyboardHidden</a> * configuration. */ ACONFIGURATION_KEYBOARD_HIDDEN = 0x0020, /** * Bit mask for - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#NavigationQualifier">navigation</a> + * <a href="/guide/topics/resources/providing-resources.html#NavigationQualifier">navigation</a> * configuration. */ ACONFIGURATION_NAVIGATION = 0x0040, /** * Bit mask for - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#OrientationQualifier">orientation</a> + * <a href="/guide/topics/resources/providing-resources.html#OrientationQualifier">orientation</a> * configuration. */ ACONFIGURATION_ORIENTATION = 0x0080, /** * Bit mask for - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#DensityQualifier">density</a> + * <a href="/guide/topics/resources/providing-resources.html#DensityQualifier">density</a> * configuration. */ ACONFIGURATION_DENSITY = 0x0100, /** * Bit mask for - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#ScreenSizeQualifier">screen size</a> + * <a href="/guide/topics/resources/providing-resources.html#ScreenSizeQualifier">screen size</a> * configuration. */ ACONFIGURATION_SCREEN_SIZE = 0x0200, /** * Bit mask for - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#VersionQualifier">platform version</a> + * <a href="/guide/topics/resources/providing-resources.html#VersionQualifier">platform version</a> * configuration. */ ACONFIGURATION_VERSION = 0x0400, @@ -447,27 +447,27 @@ enum { ACONFIGURATION_SCREEN_LAYOUT = 0x0800, /** * Bit mask for - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#UiModeQualifier">ui mode</a> + * <a href="/guide/topics/resources/providing-resources.html#UiModeQualifier">ui mode</a> * configuration. */ ACONFIGURATION_UI_MODE = 0x1000, /** * Bit mask for - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#SmallestScreenWidthQualifier">smallest screen width</a> + * <a href="/guide/topics/resources/providing-resources.html#SmallestScreenWidthQualifier">smallest screen width</a> * configuration. */ ACONFIGURATION_SMALLEST_SCREEN_SIZE = 0x2000, /** * Bit mask for - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#LayoutDirectionQualifier">layout direction</a> + * <a href="/guide/topics/resources/providing-resources.html#LayoutDirectionQualifier">layout direction</a> * configuration. */ ACONFIGURATION_LAYOUTDIR = 0x4000, ACONFIGURATION_SCREEN_ROUND = 0x8000, /** * Bit mask for - * <a href="@dacRoot/guide/topics/resources/providing-resources.html#WideColorGamutQualifier">wide color gamut</a> - * and <a href="@dacRoot/guide/topics/resources/providing-resources.html#HDRQualifier">HDR</a> configurations. + * <a href="/guide/topics/resources/providing-resources.html#WideColorGamutQualifier">wide color gamut</a> + * and <a href="/guide/topics/resources/providing-resources.html#HDRQualifier">HDR</a> configurations. */ ACONFIGURATION_COLOR_MODE = 0x10000, /** diff --git a/include/android/hardware_buffer_jni.h b/include/android/hardware_buffer_jni.h index 293e5ac469..ae208a6e75 100644 --- a/include/android/hardware_buffer_jni.h +++ b/include/android/hardware_buffer_jni.h @@ -39,9 +39,9 @@ __BEGIN_DECLS * Return the AHardwareBuffer wrapped by a Java HardwareBuffer object. * * This method does not acquire any additional reference to the AHardwareBuffer - * that is returned. To keep the AHardwareBuffer live after the Java - * HardwareBuffer object got garbage collected, be sure to use AHardwareBuffer_acquire() - * to acquire an additional reference. + * that is returned. To keep the AHardwareBuffer alive after the Java + * HardwareBuffer object is closed, explicitly or by the garbage collector, be + * sure to use AHardwareBuffer_acquire() to acquire an additional reference. * * Available since API level 26. */ @@ -50,7 +50,18 @@ AHardwareBuffer* AHardwareBuffer_fromHardwareBuffer(JNIEnv* env, /** * Return a new Java HardwareBuffer object that wraps the passed native - * AHardwareBuffer object. + * AHardwareBuffer object. The Java HardwareBuffer will acquire a reference to + * the internal buffer and manage its lifetime. For example: + * + * <pre><code> + * AHardwareBuffer* buffer; + * AHardwareBuffer_allocate(..., &buffer); // `buffer` has reference count 1 + * jobject java_result = AHardwareBuffer_toHardwareBuffer(buffer); // `buffer` has reference count 2. + * AHardwareBuffer_release(buffer); // `buffer` has reference count 1 + * return result; // The underlying buffer is kept alive by `java_result` and + * // will be set to 0 when it is closed on the Java side with + * // HardwareBuffer::close(). + * </code></pre> * * Available since API level 26. */ diff --git a/include/android/imagedecoder.h b/include/android/imagedecoder.h new file mode 100644 index 0000000000..d7e6e4118f --- /dev/null +++ b/include/android/imagedecoder.h @@ -0,0 +1,538 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @defgroup ImageDecoder + * + * Functions for converting encoded images into RGBA pixels. + * + * Similar to the Java counterpart android.graphics.ImageDecoder, it can be used + * to decode images in the following formats: + * - JPEG + * - PNG + * - GIF + * - WebP + * - BMP + * - ICO + * - WBMP + * - HEIF + * - Digital negatives (via the DNG SDK) + * <p>It has similar options for scaling, cropping, and choosing the output format. + * Unlike the Java API, which can create an android.graphics.Bitmap or + * android.graphics.drawable.Drawable object, AImageDecoder decodes directly + * into memory provided by the client. For more information, see the + * <a href="https://developer.android.com/ndk/guides/image-decoder">Image decoder</a> + * developer guide. + * @{ + */ + +/** + * @file imagedecoder.h + * @brief API for decoding images. + */ + +#ifndef ANDROID_IMAGE_DECODER_H +#define ANDROID_IMAGE_DECODER_H + +#include "bitmap.h" +#include <android/rect.h> +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +struct AAsset; + +#if __ANDROID_API__ >= 30 + +/** + * {@link AImageDecoder} functions result code. Many functions will return one of these + * to indicate success ({@link ANDROID_IMAGE_DECODER_SUCCESS}) or the reason + * for the failure. On failure, any out-parameters should be considered + * uninitialized, except where specified. + */ +enum { + /** + * Decoding was successful and complete. + */ + ANDROID_IMAGE_DECODER_SUCCESS = 0, + /** + * The input is incomplete. + */ + ANDROID_IMAGE_DECODER_INCOMPLETE = -1, + /** + * The input contained an error after decoding some lines. + */ + ANDROID_IMAGE_DECODER_ERROR = -2, + /** + * Could not convert. For example, attempting to decode an image with + * alpha to an opaque format. + */ + ANDROID_IMAGE_DECODER_INVALID_CONVERSION = -3, + /** + * The scale is invalid. It may have overflowed, or it may be incompatible + * with the current alpha setting. + */ + ANDROID_IMAGE_DECODER_INVALID_SCALE = -4, + /** + * Some other parameter is invalid. + */ + ANDROID_IMAGE_DECODER_BAD_PARAMETER = -5, + /** + * Input was invalid before decoding any pixels. + */ + ANDROID_IMAGE_DECODER_INVALID_INPUT = -6, + /** + * A seek was required and it failed. + */ + ANDROID_IMAGE_DECODER_SEEK_ERROR = -7, + /** + * Some other error. For example, an internal allocation failed. + */ + ANDROID_IMAGE_DECODER_INTERNAL_ERROR = -8, + /** + * AImageDecoder did not recognize the format. + */ + ANDROID_IMAGE_DECODER_UNSUPPORTED_FORMAT = -9 +}; + +struct AImageDecoder; + +/** + * Opaque handle for decoding images. + * + * Create using one of the following: + * - {@link AImageDecoder_createFromAAsset} + * - {@link AImageDecoder_createFromFd} + * - {@link AImageDecoder_createFromBuffer} + * + * After creation, {@link AImageDecoder_getHeaderInfo} can be used to retrieve + * information about the encoded image. Other functions, like + * {@link AImageDecoder_setTargetSize}, can be used to specify how to decode, and + * {@link AImageDecoder_decode} will decode into client provided memory. + * + * {@link AImageDecoder} objects are NOT thread-safe, and should not be shared across + * threads. + */ +typedef struct AImageDecoder AImageDecoder; + +/** + * Create a new {@link AImageDecoder} from an {@link AAsset}. + * + * Available since API level 30. + * + * @param asset {@link AAsset} containing encoded image data. Client is still + * responsible for calling {@link AAsset_close} on it, which may be + * done after deleting the returned {@link AImageDecoder}. + * @param outDecoder On success (i.e. return value is + * {@link ANDROID_IMAGE_DECODER_SUCCESS}), this will be set to + * a newly created {@link AImageDecoder}. Caller is + * responsible for calling {@link AImageDecoder_delete} on it. + * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value + * indicating the reason for the failure. + * + * Errors: + * - {@link ANDROID_IMAGE_DECODER_INCOMPLETE}: The asset was truncated before + * reading the image header. + * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: One of the parameters is + * null. + * - {@link ANDROID_IMAGE_DECODER_INVALID_INPUT}: There is an error in the + * header. + * - {@link ANDROID_IMAGE_DECODER_SEEK_ERROR}: The asset failed to seek. + * - {@link ANDROID_IMAGE_DECODER_INTERNAL_ERROR}: Some other error, like a + * failure to allocate memory. + * - {@link ANDROID_IMAGE_DECODER_UNSUPPORTED_FORMAT}: The format is not + * supported. + */ +int AImageDecoder_createFromAAsset(struct AAsset* asset, AImageDecoder** outDecoder) + __INTRODUCED_IN(30); + +/** + * Create a new {@link AImageDecoder} from a file descriptor. + * + * Available since API level 30. + * + * @param fd Seekable, readable, open file descriptor for encoded data. + * Client is still responsible for closing it, which may be done + * after deleting the returned {@link AImageDecoder}. + * @param outDecoder On success (i.e. return value is + * {@link ANDROID_IMAGE_DECODER_SUCCESS}), this will be set to + * a newly created {@link AImageDecoder}. Caller is + * responsible for calling {@link AImageDecoder_delete} on it. + * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value + * indicating the reason for the failure. + * + * Errors: + * - {@link ANDROID_IMAGE_DECODER_INCOMPLETE}: The file was truncated before + * reading the image header. + * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: The {@link AImageDecoder} is + * null, or |fd| does not represent a valid, seekable file descriptor. + * - {@link ANDROID_IMAGE_DECODER_INVALID_INPUT}: There is an error in the + * header. + * - {@link ANDROID_IMAGE_DECODER_SEEK_ERROR}: The descriptor failed to seek. + * - {@link ANDROID_IMAGE_DECODER_INTERNAL_ERROR}: Some other error, like a + * failure to allocate memory. + * - {@link ANDROID_IMAGE_DECODER_UNSUPPORTED_FORMAT}: The format is not + * supported. + */ +int AImageDecoder_createFromFd(int fd, AImageDecoder** outDecoder) __INTRODUCED_IN(30); + +/** + * Create a new AImageDecoder from a buffer. + * + * Available since API level 30. + * + * @param buffer Pointer to encoded data. Must be valid for the entire time + * the {@link AImageDecoder} is used. + * @param length Byte length of buffer. + * @param outDecoder On success (i.e. return value is + * {@link ANDROID_IMAGE_DECODER_SUCCESS}), this will be set to + * a newly created {@link AImageDecoder}. Caller is + * responsible for calling {@link AImageDecoder_delete} on it. + * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value + * indicating the reason for the failure. + * + * Errors: + * - {@link ANDROID_IMAGE_DECODER_INCOMPLETE}: The encoded image was truncated before + * reading the image header. + * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: One of the parameters is + * invalid. + * - {@link ANDROID_IMAGE_DECODER_INVALID_INPUT}: There is an error in the + * header. + * - {@link ANDROID_IMAGE_DECODER_INTERNAL_ERROR}: Some other error, like a + * failure to allocate memory. + * - {@link ANDROID_IMAGE_DECODER_UNSUPPORTED_FORMAT}: The format is not + * supported. + */ +int AImageDecoder_createFromBuffer(const void* buffer, size_t length, + AImageDecoder** outDecoder) __INTRODUCED_IN(30); + +/** + * Delete the AImageDecoder. + * + * Available since API level 30. + */ +void AImageDecoder_delete(AImageDecoder* decoder) __INTRODUCED_IN(30); + +/** + * Choose the desired output format. + * + * Available since API level 30. + * + * @param format {@link AndroidBitmapFormat} to use for the output. + * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value + * indicating the reason for the failure. On failure, the + * {@link AImageDecoder} uses the format it was already planning + * to use (either its default or a previously successful setting + * from this function). + * + * Errors: + * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: The + * {@link AImageDecoder} is null or |format| does not correspond to an + * {@link AndroidBitmapFormat}. + * - {@link ANDROID_IMAGE_DECODER_INVALID_CONVERSION}: The + * {@link AndroidBitmapFormat} is incompatible with the image. + */ +int AImageDecoder_setAndroidBitmapFormat(AImageDecoder*, + int32_t format) __INTRODUCED_IN(30); + +/** + * Specify whether the output's pixels should be unpremultiplied. + * + * By default, {@link AImageDecoder_decodeImage} will premultiply the pixels, if they have alpha. + * Pass true to this method to leave them unpremultiplied. This has no effect on an + * opaque image. + * + * Available since API level 30. + * + * @param unpremultipliedRequired Pass true to leave the pixels unpremultiplied. + * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value + * indicating the reason for the failure. + * + * Errors: + * - {@link ANDROID_IMAGE_DECODER_INVALID_CONVERSION}: Unpremultiplied is not + * possible due to an existing scale set by + * {@link AImageDecoder_setTargetSize}. + * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: The + * {@link AImageDecoder} is null. + */ +int AImageDecoder_setUnpremultipliedRequired(AImageDecoder*, + bool unpremultipliedRequired) __INTRODUCED_IN(30); + +/** + * Choose the dataspace for the output. + * + * Ignored by {@link ANDROID_BITMAP_FORMAT_A_8}, which does not support + * an {@link ADataSpace}. + * + * Available since API level 30. + * + * @param dataspace The {@link ADataSpace} to decode into. An ADataSpace + * specifies how to interpret the colors. By default, + * AImageDecoder will decode into the ADataSpace specified by + * {@link AImageDecoderHeaderInfo_getDataSpace}. If this + * parameter is set to a different ADataSpace, AImageDecoder + * will transform the output into the specified ADataSpace. + * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value + * indicating the reason for the failure. + * + * Errors: + * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: The + * {@link AImageDecoder} is null or |dataspace| does not correspond to an + * {@link ADataSpace} value. + */ +int AImageDecoder_setDataSpace(AImageDecoder*, int32_t dataspace) __INTRODUCED_IN(30); + +/** + * Specify the output size for a decoded image. + * + * Future calls to {@link AImageDecoder_decodeImage} will sample or scale the + * encoded image to reach the desired size. If a crop rect is set (via + * {@link AImageDecoder_setCrop}), it must be contained within the dimensions + * specified by width and height, and the output image will be the size of the + * crop rect. + * + * Available since API level 30. + * + * @param width Width of the output (prior to cropping). + * This will affect future calls to + * {@link AImageDecoder_getMinimumStride}, which will now return + * a value based on this width. + * @param height Height of the output (prior to cropping). + * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value + * indicating the reason for the failure. + * + * Errors: + * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: The + * {@link AImageDecoder} is null. + * - {@link ANDROID_IMAGE_DECODER_INVALID_SCALE}: |width| or |height| is <= 0, + * the size is too big, any existing crop is not contained by the new image dimensions, + * or the scale is incompatible with a previous call to + * {@link AImageDecoder_setUnpremultipliedRequired}(true). + */ +int AImageDecoder_setTargetSize(AImageDecoder*, int32_t width, int32_t height) __INTRODUCED_IN(30); + + +/** + * Compute the dimensions to use for a given sampleSize. + * + * Although AImageDecoder can scale to an arbitrary target size (see + * {@link AImageDecoder_setTargetSize}), some sizes may be more efficient than + * others. This computes the most efficient target size to use to reach a + * particular sampleSize. + * + * Available since API level 30. + * + * @param sampleSize A subsampling rate of the original image. Must be greater + * than or equal to 1. A sampleSize of 2 means to skip every + * other pixel/line, resulting in a width and height that are + * 1/2 of the original dimensions, with 1/4 the number of + * pixels. + * @param width Out parameter for the width sampled by sampleSize, and rounded + * in the direction that the decoder can do most efficiently. + * @param height Out parameter for the height sampled by sampleSize, and rounded + * in the direction that the decoder can do most efficiently. + * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value + * indicating the reason for the failure. + * + * Errors: + * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: The + * {@link AImageDecoder}, |width| or |height| is null or |sampleSize| is < 1. + */ +int AImageDecoder_computeSampledSize(const AImageDecoder*, int sampleSize, + int32_t* width, int32_t* height) __INTRODUCED_IN(30); +/** + * Specify how to crop the output after scaling (if any). + * + * Future calls to {@link AImageDecoder_decodeImage} will crop their output to + * the specified {@link ARect}. Clients will only need to allocate enough memory + * for the cropped ARect. + * + * Available since API level 30. + * + * @param crop Rectangle describing a crop of the decode. It must be contained inside of + * the (possibly scaled, by {@link AImageDecoder_setTargetSize}) + * image dimensions. This will affect future calls to + * {@link AImageDecoder_getMinimumStride}, which will now return a + * value based on the width of the crop. An empty ARect - + * specifically { 0, 0, 0, 0 } - may be used to remove the cropping + * behavior. Any other empty or unsorted ARects will result in + * returning {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}. + * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value + * indicating the reason for the failure. + * + * Errors: + * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: The + * {@link AImageDecoder} is null or the crop is not contained by the + * (possibly scaled) image dimensions. + */ +int AImageDecoder_setCrop(AImageDecoder*, ARect crop) __INTRODUCED_IN(30); + +struct AImageDecoderHeaderInfo; +/** + * Opaque handle for representing information about the encoded image. Retrieved + * using {@link AImageDecoder_getHeaderInfo} and passed to methods like + * {@link AImageDecoderHeaderInfo_getWidth} and + * {@link AImageDecoderHeaderInfo_getHeight}. + */ +typedef struct AImageDecoderHeaderInfo AImageDecoderHeaderInfo; + +/** + * Return an opaque handle for reading header info. + * + * This is owned by the {@link AImageDecoder} and will be destroyed when the + * AImageDecoder is destroyed via {@link AImageDecoder_delete}. + * + * Available since API level 30. + */ +const AImageDecoderHeaderInfo* AImageDecoder_getHeaderInfo( + const AImageDecoder*) __INTRODUCED_IN(30); + +/** + * Report the native width of the encoded image. This is also the logical + * pixel width of the output, unless {@link AImageDecoder_setTargetSize} is + * used to choose a different size or {@link AImageDecoder_setCrop} is used to + * set a crop rect. + * + * Available since API level 30. + */ +int32_t AImageDecoderHeaderInfo_getWidth(const AImageDecoderHeaderInfo*) __INTRODUCED_IN(30); + +/** + * Report the native height of the encoded image. This is also the logical + * pixel height of the output, unless {@link AImageDecoder_setTargetSize} is + * used to choose a different size or {@link AImageDecoder_setCrop} is used to + * set a crop rect. + * + * Available since API level 30. + */ +int32_t AImageDecoderHeaderInfo_getHeight(const AImageDecoderHeaderInfo*) __INTRODUCED_IN(30); + +/** + * Report the mimeType of the encoded image. + * + * Available since API level 30. + * + * @return a string literal describing the mime type. + */ +const char* AImageDecoderHeaderInfo_getMimeType( + const AImageDecoderHeaderInfo*) __INTRODUCED_IN(30); + +/** + * Report the {@link AndroidBitmapFormat} the AImageDecoder will decode to + * by default. {@link AImageDecoder} will try to choose one that is sensible + * for the image and the system. Note that this does not indicate the + * encoded format of the image. + * + * Available since API level 30. + */ +int32_t AImageDecoderHeaderInfo_getAndroidBitmapFormat( + const AImageDecoderHeaderInfo*) __INTRODUCED_IN(30); + +/** + * Report how the {@link AImageDecoder} will handle alpha by default. If the image + * contains no alpha (according to its header), this will return + * {@link ANDROID_BITMAP_FLAGS_ALPHA_OPAQUE}. If the image may contain alpha, + * this returns {@link ANDROID_BITMAP_FLAGS_ALPHA_PREMUL}, because + * {@link AImageDecoder_decodeImage} will premultiply pixels by default. + * + * Available since API level 30. + */ +int AImageDecoderHeaderInfo_getAlphaFlags( + const AImageDecoderHeaderInfo*) __INTRODUCED_IN(30); + +/** + * Report the dataspace the AImageDecoder will decode to by default. + * + * By default, {@link AImageDecoder_decodeImage} will not do any color + * conversion. + * + * Available since API level 30. + * + * @return The {@link ADataSpace} representing the way the colors + * are encoded (or {@link ADATASPACE_UNKNOWN} if there is not a + * corresponding ADataSpace). This specifies how to interpret the colors + * in the decoded image, unless {@link AImageDecoder_setDataSpace} is + * called to decode to a different ADataSpace. + * + * Note that ADataSpace only exposes a few values. This may return + * {@link ADATASPACE_UNKNOWN}, even for Named ColorSpaces, if they have + * no corresponding {@link ADataSpace}. + */ +int32_t AImageDecoderHeaderInfo_getDataSpace( + const AImageDecoderHeaderInfo*) __INTRODUCED_IN(30); + +/** + * Return the minimum stride that can be used in + * {@link AImageDecoder_decodeImage). + * + * This stride provides no padding, meaning it will be exactly equal to the + * width times the number of bytes per pixel for the {@link AndroidBitmapFormat} + * being used. + * + * If the output is scaled (via {@link AImageDecoder_setTargetSize}) and/or + * cropped (via {@link AImageDecoder_setCrop}), this takes those into account. + * + * Available since API level 30. + */ +size_t AImageDecoder_getMinimumStride(AImageDecoder*) __INTRODUCED_IN(30); + +/** + * Decode the image into pixels, using the settings of the {@link AImageDecoder}. + * + * Available since API level 30. + * + * @param decoder Opaque object representing the decoder. + * @param pixels On success, will be filled with the result + * of the decode. Must be large enough to hold |size| bytes. + * @param stride Width in bytes of a single row. Must be at least + * {@link AImageDecoder_getMinimumStride} and a multiple of the + * bytes per pixel of the {@link AndroidBitmapFormat}. + * @param size Size of the pixel buffer in bytes. Must be at least + * stride * (height - 1) + + * {@link AImageDecoder_getMinimumStride}. + * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value + * indicating the reason for the failure. + * + * Errors: + * - {@link ANDROID_IMAGE_DECODER_INCOMPLETE}: The image was truncated. A + * partial image was decoded, and undecoded lines have been initialized to all + * zeroes. + * - {@link ANDROID_IMAGE_DECODER_ERROR}: The image contained an error. A + * partial image was decoded, and undecoded lines have been initialized to all + * zeroes. + * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}: The {@link AImageDecoder} or + * |pixels| is null, the stride is not large enough or not pixel aligned, or + * |size| is not large enough. + * - {@link ANDROID_IMAGE_DECODER_SEEK_ERROR}: The asset or file descriptor + * failed to seek. + * - {@link ANDROID_IMAGE_DECODER_INTERNAL_ERROR}: Some other error, like a + * failure to allocate memory. + */ +int AImageDecoder_decodeImage(AImageDecoder* decoder, + void* pixels, size_t stride, + size_t size) __INTRODUCED_IN(30); + +#endif // __ANDROID_API__ >= 30 + +#ifdef __cplusplus +} +#endif + +#endif // ANDROID_IMAGE_DECODER_H + +/** @} */ diff --git a/include/android/input.h b/include/android/input.h index ce439c6d75..dbfd61eb05 100644 --- a/include/android/input.h +++ b/include/android/input.h @@ -158,7 +158,10 @@ enum { AINPUT_EVENT_TYPE_KEY = 1, /** Indicates that the input event is a motion event. */ - AINPUT_EVENT_TYPE_MOTION = 2 + AINPUT_EVENT_TYPE_MOTION = 2, + + /** Focus event */ + AINPUT_EVENT_TYPE_FOCUS = 3, }; /** @@ -790,6 +793,8 @@ enum { AMOTION_EVENT_TOOL_TYPE_MOUSE = 3, /** eraser */ AMOTION_EVENT_TOOL_TYPE_ERASER = 4, + /** palm */ + AMOTION_EVENT_TOOL_TYPE_PALM = 5, }; /** diff --git a/include/android/sensor.h b/include/android/sensor.h index 3ebe79fd2e..eb407794d1 100644 --- a/include/android/sensor.h +++ b/include/android/sensor.h @@ -15,6 +15,9 @@ */ /** + * Structures and functions to receive and process sensor events in + * native code. + * * @addtogroup Sensor * @{ */ @@ -42,12 +45,6 @@ * - DO NOT CHANGE THE LAYOUT OR SIZE OF STRUCTURES */ -/** - * Structures and functions to receive and process sensor events in - * native code. - * - */ - #include <android/looper.h> #include <stdbool.h> @@ -245,6 +242,13 @@ enum { * {@link ASENSOR_TYPE_ACCELEROMETER_UNCALIBRATED} */ ASENSOR_TYPE_ACCELEROMETER_UNCALIBRATED = 35, + /** + * {@link ASENSOR_TYPE_HINGE_ANGLE} + * reporting-mode: on-change + * + * The hinge angle sensor value is returned in degrees. + */ + ASENSOR_TYPE_HINGE_ANGLE = 36, }; /** diff --git a/include/android/surface_control.h b/include/android/surface_control.h index 90e565359e..cbcf6ec5c0 100644 --- a/include/android/surface_control.h +++ b/include/android/surface_control.h @@ -149,7 +149,7 @@ int64_t ASurfaceTransactionStats_getLatchTime(ASurfaceTransactionStats* surface_ /** * Returns a sync fence that signals when the transaction has been presented. * The recipient of the callback takes ownership of the fence and is responsible for closing - * it. + * it. If a device does not support present fences, a -1 will be returned. * * Available since API level 29. */ @@ -407,6 +407,36 @@ void ASurfaceTransaction_setHdrMetadata_cta861_3(ASurfaceTransaction* transactio #endif // __ANDROID_API__ >= 29 +#if __ANDROID_API__ >= 30 + +/** + * Sets the intended frame rate for |surface_control|. + * + * On devices that are capable of running the display at different refresh rates, the system may + * choose a display refresh rate to better match this surface's frame rate. Usage of this API won't + * directly affect the application's frame production pipeline. However, because the system may + * change the display refresh rate, calls to this function may result in changes to Choreographer + * callback timings, and changes to the time interval at which the system releases buffers back to + * the application. + * + * |frameRate| is the intended frame rate of this surface, in frames per second. 0 is a special + * value that indicates the app will accept the system's choice for the display frame rate, which is + * the default behavior if this function isn't called. The frameRate param does <em>not</em> need to + * be a valid refresh rate for this device's display - e.g., it's fine to pass 30fps to a device + * that can only run the display at 60fps. + * + * |compatibility| The frame rate compatibility of this surface. The compatibility value may + * influence the system's choice of display frame rate. To specify a compatibility use the + * ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_* enum. + * + * Available since API level 30. + */ +void ASurfaceTransaction_setFrameRate(ASurfaceTransaction* transaction, + ASurfaceControl* surface_control, float frameRate, + int8_t compatibility) __INTRODUCED_IN(30); + +#endif // __ANDROID_API__ >= 30 + __END_DECLS #endif // ANDROID_SURFACE_CONTROL_H diff --git a/include/android/thermal.h b/include/android/thermal.h new file mode 100644 index 0000000000..83582d6791 --- /dev/null +++ b/include/android/thermal.h @@ -0,0 +1,190 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup Thermal + * @{ + */ + +/** + * @file thermal.h + */ + +#ifndef _ANDROID_THERMAL_H +#define _ANDROID_THERMAL_H + +#include <sys/cdefs.h> + +/****************************************************************** + * + * IMPORTANT NOTICE: + * + * This file is part of Android's set of stable system headers + * exposed by the Android NDK (Native Development Kit). + * + * Third-party source AND binary code relies on the definitions + * here to be FROZEN ON ALL UPCOMING PLATFORM RELEASES. + * + * - DO NOT MODIFY ENUMS (EXCEPT IF YOU ADD NEW 32-BIT VALUES) + * - DO NOT MODIFY CONSTANTS OR FUNCTIONAL MACROS + * - DO NOT CHANGE THE SIGNATURE OF FUNCTIONS IN ANY WAY + * - DO NOT CHANGE THE LAYOUT OR SIZE OF STRUCTURES + */ + +/* + * Structures and functions to access thermal status and register/unregister + * thermal status listener in native code. + */ + +#include <stdint.h> +#include <sys/types.h> + +#if !defined(__INTRODUCED_IN) +#define __INTRODUCED_IN(30) /* Introduced in API level 30 */ +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +enum AThermalStatus { + /** Error in thermal status. */ + ATHERMAL_STATUS_ERROR = -1, + /** Not under throttling. */ + ATHERMAL_STATUS_NONE = 0, + /** Light throttling where UX is not impacted. */ + ATHERMAL_STATUS_LIGHT = 1, + /** Moderate throttling where UX is not largely impacted. */ + ATHERMAL_STATUS_MODERATE = 2, + /** Severe throttling where UX is largely impacted. */ + ATHERMAL_STATUS_SEVERE = 3, + /** Platform has done everything to reduce power. */ + ATHERMAL_STATUS_CRITICAL = 4, + /** + * Key components in platform are shutting down due to thermal condition. + * Device functionalities will be limited. + */ + ATHERMAL_STATUS_EMERGENCY = 5, + /** Need shutdown immediately. */ + ATHERMAL_STATUS_SHUTDOWN = 6, +}; + +/** + * An opaque type representing a handle to a thermal manager. + * An instance of thermal manager must be acquired prior to + * using thermal status APIs and must be released after use. + * + * <p>To use:<ul> + * <li>Create a new thermal manager instance by calling the + * {@link AThermal_acquireManager} function.</li> + * <li>Get current thermal status with + * {@link AThermal_getCurrentThermalStatus}.</li> + * <li>Register a thermal status listener with + * {@link AThermal_registerThermalStatusListener}.</li> + * <li>Unregister a thermal status listener with + * {@link AThermal_unregisterThermalStatusListener}.</li> + * <li>Release the thermal manager instance with + * {@link AThermal_releaseManager}.</li></ul></p> + * + */ +typedef struct AThermalManager AThermalManager; + +/** + * Prototype of the function that is called when thermal status changes. + * It's passed the updated thermal status as parameter, as well as the + * pointer provided by the client that registered a callback. + */ +typedef void (*AThermal_StatusCallback)(void *data, AThermalStatus status); + +#if __ANDROID_API__ >= 30 + +/** + * Acquire an instance of the thermal manager. This must be freed using + * {@link AThermal_releaseManager}. + * + * Available since API level 30. + * + * @return manager instance on success, nullptr on failure. + */ +AThermalManager* AThermal_acquireManager() __INTRODUCED_IN(30); + +/** + * Release the thermal manager pointer acquired via + * {@link AThermal_acquireManager}. + * + * Available since API level 30. + * + * @param manager The manager to be released. + */ +void AThermal_releaseManager(AThermalManager *manager) __INTRODUCED_IN(30); + +/** + * Gets the current thermal status. + * + * Available since API level 30. + * + * @param manager The manager instance to use to query the thermal status. + * Acquired via {@link AThermal_acquireManager}. + * + * @return current thermal status, ATHERMAL_STATUS_ERROR on failure. + */ +AThermalStatus AThermal_getCurrentThermalStatus(AThermalManager *manager) __INTRODUCED_IN(30); + +/** + * Register the thermal status listener for thermal status change. + * + * Available since API level 30. + * + * @param manager The manager instance to use to register. + * Acquired via {@link AThermal_acquireManager}. + * @param callback The callback function to be called when thermal status updated. + * @param data The data pointer to be passed when callback is called. + * + * @return 0 on success + * EINVAL if the listener and data pointer were previously added and not removed. + * EPERM if the required permission is not held. + * EPIPE if communication with the system service has failed. + */ +int AThermal_registerThermalStatusListener(AThermalManager *manager, + AThermal_StatusCallback callback, void *data) __INTRODUCED_IN(30); + +/** + * Unregister the thermal status listener previously resgistered. + * + * Available since API level 30. + * + * @param manager The manager instance to use to unregister. + * Acquired via {@link AThermal_acquireManager}. + * @param callback The callback function to be called when thermal status updated. + * @param data The data pointer to be passed when callback is called. + * + * @return 0 on success + * EINVAL if the listener and data pointer were not previously added. + * EPERM if the required permission is not held. + * EPIPE if communication with the system service has failed. + */ +int AThermal_unregisterThermalStatusListener(AThermalManager *manager, + AThermal_StatusCallback callback, void *data) __INTRODUCED_IN(30); + +#endif // __ANDROID_API__ >= 30 + +#ifdef __cplusplus +} +#endif + +#endif // _ANDROID_THERMAL_H + +/** @} */ |