From 183c44ce4db3f30912a6233f3567ee7990de6063 Mon Sep 17 00:00:00 2001 From: Marissa Wall Date: Mon, 8 Apr 2019 12:58:50 -0700 Subject: ASurfaceControl: support framebuffer devices There are Android devices that use a hwc2onfbadapter that allows them to ship framebuffer devices but still pass VTS and appear to the system as if they have hwc2.x*. Unfortunately, these devices do not support a present fence. This patch updates the documentation to let developers know that not all devices will return a present fence. Test: ASurfaceControlTest Bug: 129880031 Change-Id: I81dd21dc088b1d2d73d1bdb9c46216ef2e171063 --- include/android/surface_control.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/android') diff --git a/include/android/surface_control.h b/include/android/surface_control.h index ef2ad9998c..abb8368069 100644 --- a/include/android/surface_control.h +++ b/include/android/surface_control.h @@ -130,7 +130,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. */ int ASurfaceTransactionStats_getPresentFenceFd(ASurfaceTransactionStats* surface_transaction_stats) __INTRODUCED_IN(29); -- cgit v1.2.3-59-g8ed1b From e4a1cabd61895eeda1968eabeb19b9c5ad74b430 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Fri, 14 Jun 2019 14:01:20 -0700 Subject: Fix bad doxygen tags in font headers. Test: Compared to other NDK headers. Bug: None Change-Id: If2ff22d1502ec8541e57aa26a5a42461abf9fdc7 --- include/android/font.h | 2 +- include/android/font_matcher.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'include/android') diff --git a/include/android/font.h b/include/android/font.h index 435a573f51..8001ee1938 100644 --- a/include/android/font.h +++ b/include/android/font.h @@ -16,7 +16,7 @@ /** * @addtogroup Font - * { + * @{ */ /** diff --git a/include/android/font_matcher.h b/include/android/font_matcher.h index e286a4c812..0b8f892b9b 100644 --- a/include/android/font_matcher.h +++ b/include/android/font_matcher.h @@ -16,7 +16,7 @@ /** * @addtogroup Font - * { + * @{ */ /** -- cgit v1.2.3-59-g8ed1b From 12abc195bac9feedcc1447855c878f9b31a9e7c8 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Tue, 18 Jun 2019 15:13:05 -0700 Subject: Fix another doxygen issue. Test: Eyeballs Bug: None Change-Id: I0eb5c82498a532c88eb13fa72b41c720c6d8537e --- include/android/system_fonts.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/android') diff --git a/include/android/system_fonts.h b/include/android/system_fonts.h index dde9055c7a..f0485a1871 100644 --- a/include/android/system_fonts.h +++ b/include/android/system_fonts.h @@ -16,7 +16,7 @@ /** * @addtogroup Font - * { + * @{ */ /** -- cgit v1.2.3-59-g8ed1b From 20e67fa8a171f7899c754bb7663f5e534d64c322 Mon Sep 17 00:00:00 2001 From: Dillon Cower Date: Tue, 30 Jul 2019 15:39:54 -0700 Subject: Fix typo: chroreographer -> choreographer. --- include/android/choreographer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/android') diff --git a/include/android/choreographer.h b/include/android/choreographer.h index 44883cc498..1b589bca72 100644 --- a/include/android/choreographer.h +++ b/include/android/choreographer.h @@ -83,7 +83,7 @@ void AChoreographer_postFrameCallbackDelayed(AChoreographer* choreographer, * Power a callback to be run on the next frame. The data pointer provided will * be passed to the callback function when it's called. */ -void AChoreographer_postFrameCallback64(AChoreographer* chroreographer, +void AChoreographer_postFrameCallback64(AChoreographer* choreographer, AChoreographer_frameCallback64 callback, void* data) __INTRODUCED_IN(29); /** -- cgit v1.2.3-59-g8ed1b From f73f5f2b3b9da9e09cc76cf72323aaf2926a5b04 Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Mon, 12 Aug 2019 13:43:55 -0400 Subject: Add RGBA_F16 to the AndroidBitmapFormat (NDK) Bug: 135133301 Test: Id904c8cb4b22505635744ab271a639ace24ddbab Update AndroidBitmapFormat to keep up with Bitmap.Config. Change-Id: I3c17faf174b109b7c31c2eb5d1249bc881923b10 --- include/android/bitmap.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include/android') diff --git a/include/android/bitmap.h b/include/android/bitmap.h index 2def64dc90..6fba0ac9ca 100644 --- a/include/android/bitmap.h +++ b/include/android/bitmap.h @@ -60,6 +60,8 @@ 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 info, see AndroidBitmap_getInfo(). */ -- cgit v1.2.3-59-g8ed1b From 0dd622ef5da2207ae4af7819ba2d20151e49e9e9 Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Fri, 23 Aug 2019 15:44:21 -0400 Subject: Add alpha to AndroidBitmapInfo Bug: 135133301 Test: If8859321c1b7e5149029f931e4d11ec6eeeb260a Change-Id: I3577602444837b703fcbf6498bd00e1ee1c97e09 --- include/android/bitmap.h | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'include/android') diff --git a/include/android/bitmap.h b/include/android/bitmap.h index 6fba0ac9ca..01cf2f88ea 100644 --- a/include/android/bitmap.h +++ b/include/android/bitmap.h @@ -64,6 +64,20 @@ enum AndroidBitmapFormat { 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, +}; + /** Bitmap info, see AndroidBitmap_getInfo(). */ typedef struct { /** The bitmap width in pixels. */ @@ -74,8 +88,9 @@ typedef struct { uint32_t stride; /** The bitmap pixel format. See {@link AndroidBitmapFormat} */ int32_t format; - /** Unused. */ - uint32_t flags; // 0 for now + /** Two bits are used to encode alpha. Use ANDROID_BITMAP_FLAGS_ALPHA_MASK + * and ANDROID_BITMAP_FLAGS_ALPHA_SHIFT to retrieve them. */ + uint32_t flags; } AndroidBitmapInfo; /** -- cgit v1.2.3-59-g8ed1b From 3d70e532faeb9b8b2971b8643b824bacfa896047 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Tue, 29 Oct 2019 08:59:39 -0700 Subject: Add "Available since" text to all android/ headers. Also fix a few missing/incorrect annotations. Bug: http://b/143470841 Test: treehugger Change-Id: I1d9ec8350df03df7d80f1cc2334eef45deec30ec --- include/android/choreographer.h | 6 ++ include/android/configuration.h | 18 ++-- include/android/font.h | 18 ++++ include/android/font_matcher.h | 14 ++- include/android/hardware_buffer_jni.h | 4 + include/android/input.h | 16 +-- include/android/multinetwork.h | 11 ++ include/android/native_window_jni.h | 2 + include/android/sensor.h | 43 ++++++-- include/android/surface_control.h | 59 ++++++++++- include/android/surface_texture.h | 15 +++ include/android/surface_texture_jni.h | 8 +- include/android/system_fonts.h | 6 ++ include/android/trace.h | 8 +- .../ndk/include_ndk/android/binder_auto_utils.h | 2 +- .../ndk/include_ndk/android/binder_ibinder.h | 68 +++++++++++-- .../ndk/include_ndk/android/binder_ibinder_jni.h | 8 +- .../binder/ndk/include_ndk/android/binder_parcel.h | 111 ++++++++++++++++++++- .../binder/ndk/include_ndk/android/binder_status.h | 28 +++++- .../nativewindow/include/android/hardware_buffer.h | 22 ++++ libs/nativewindow/include/android/native_window.h | 7 ++ 21 files changed, 427 insertions(+), 47 deletions(-) (limited to 'include/android') diff --git a/include/android/choreographer.h b/include/android/choreographer.h index 1b589bca72..0d97e8c066 100644 --- a/include/android/choreographer.h +++ b/include/android/choreographer.h @@ -59,6 +59,8 @@ typedef void (*AChoreographer_frameCallback64)(int64_t frameTimeNanos, void* dat /** * Get the AChoreographer instance for the current thread. This must be called * on an ALooper thread. + * + * Available since API level 24. */ AChoreographer* AChoreographer_getInstance() __INTRODUCED_IN(24); @@ -82,6 +84,8 @@ void AChoreographer_postFrameCallbackDelayed(AChoreographer* choreographer, /** * Power a callback to be run on the next frame. The data pointer provided will * be passed to the callback function when it's called. + * + * Available since API level 29. */ void AChoreographer_postFrameCallback64(AChoreographer* choreographer, AChoreographer_frameCallback64 callback, void* data) __INTRODUCED_IN(29); @@ -90,6 +94,8 @@ void AChoreographer_postFrameCallback64(AChoreographer* choreographer, * Post a callback to be run on the frame following the specified delay. The * data pointer provided will be passed to the callback function when it's * called. + * + * Available since API level 29. */ void AChoreographer_postFrameCallbackDelayed64(AChoreographer* choreographer, AChoreographer_frameCallback64 callback, void* data, uint32_t delayMillis) __INTRODUCED_IN(29); diff --git a/include/android/configuration.h b/include/android/configuration.h index ef6c5a2f81..331072238b 100644 --- a/include/android/configuration.h +++ b/include/android/configuration.h @@ -675,50 +675,52 @@ int32_t AConfiguration_getUiModeNight(AConfiguration* config); */ void AConfiguration_setUiModeNight(AConfiguration* config, int32_t uiModeNight); -#if __ANDROID_API__ >= 13 /** * Return the current configuration screen width in dp units, or * ACONFIGURATION_SCREEN_WIDTH_DP_ANY if not set. */ -int32_t AConfiguration_getScreenWidthDp(AConfiguration* config) __INTRODUCED_IN(13); +int32_t AConfiguration_getScreenWidthDp(AConfiguration* config); /** * Set the configuration's current screen width in dp units. */ -void AConfiguration_setScreenWidthDp(AConfiguration* config, int32_t value) __INTRODUCED_IN(13); +void AConfiguration_setScreenWidthDp(AConfiguration* config, int32_t value); /** * Return the current configuration screen height in dp units, or * ACONFIGURATION_SCREEN_HEIGHT_DP_ANY if not set. */ -int32_t AConfiguration_getScreenHeightDp(AConfiguration* config) __INTRODUCED_IN(13); +int32_t AConfiguration_getScreenHeightDp(AConfiguration* config); /** * Set the configuration's current screen width in dp units. */ -void AConfiguration_setScreenHeightDp(AConfiguration* config, int32_t value) __INTRODUCED_IN(13); +void AConfiguration_setScreenHeightDp(AConfiguration* config, int32_t value); /** * Return the configuration's smallest screen width in dp units, or * ACONFIGURATION_SMALLEST_SCREEN_WIDTH_DP_ANY if not set. */ -int32_t AConfiguration_getSmallestScreenWidthDp(AConfiguration* config) __INTRODUCED_IN(13); +int32_t AConfiguration_getSmallestScreenWidthDp(AConfiguration* config); /** * Set the configuration's smallest screen width in dp units. */ -void AConfiguration_setSmallestScreenWidthDp(AConfiguration* config, int32_t value) __INTRODUCED_IN(13); -#endif /* __ANDROID_API__ >= 13 */ +void AConfiguration_setSmallestScreenWidthDp(AConfiguration* config, int32_t value); #if __ANDROID_API__ >= 17 /** * Return the configuration's layout direction, or * ACONFIGURATION_LAYOUTDIR_ANY if not set. + * + * Available since API level 17. */ int32_t AConfiguration_getLayoutDirection(AConfiguration* config) __INTRODUCED_IN(17); /** * Set the configuration's layout direction. + * + * Available since API level 17. */ void AConfiguration_setLayoutDirection(AConfiguration* config, int32_t value) __INTRODUCED_IN(17); #endif /* __ANDROID_API__ >= 17 */ diff --git a/include/android/font.h b/include/android/font.h index 8001ee1938..1618096d69 100644 --- a/include/android/font.h +++ b/include/android/font.h @@ -96,6 +96,8 @@ struct AFont; /** * Close an AFont. * + * Available since API level 29. + * * \param font a font returned by ASystemFontIterator_next or AFontMatchert_match. * Do nothing if NULL is passed. */ @@ -116,6 +118,8 @@ void AFont_close(AFont* _Nullable font) __INTRODUCED_IN(29); * The font file returned is guaranteed to be opend with O_RDONLY. * Note that the returned pointer is valid until AFont_close() is called for the given font. * + * Available since API level 29. + * * \param font a font object. Passing NULL is not allowed. * \return a string of the font file path. */ @@ -184,6 +188,8 @@ const char* _Nonnull AFont_getFontFilePath(const AFont* _Nonnull font) __INTRODU * * For more information about font weight, read [OpenType usWeightClass](https://docs.microsoft.com/en-us/typography/opentype/spec/os2#usweightclass) * + * Available since API level 29. + * * \param font a font object. Passing NULL is not allowed. * \return a positive integer less than or equal to {@link ASYSTEM_FONT_MAX_WEIGHT} is returned. */ @@ -192,6 +198,8 @@ uint16_t AFont_getWeight(const AFont* _Nonnull font) __INTRODUCED_IN(29); /** * Return true if the current font is italic, otherwise returns false. * + * Available since API level 29. + * * \param font a font object. Passing NULL is not allowed. * \return true if italic, otherwise false. */ @@ -204,6 +212,8 @@ bool AFont_isItalic(const AFont* _Nonnull font) __INTRODUCED_IN(29); * * Note that the returned pointer is valid until AFont_close() is called. * + * Available since API level 29. + * * \param font a font object. Passing NULL is not allowed. * \return a IETF BCP47 compliant language tag or nullptr if not available. */ @@ -216,6 +226,8 @@ const char* _Nullable AFont_getLocale(const AFont* _Nonnull font) __INTRODUCED_I * returns a non-negative value as an font offset in the collection. This * always returns 0 if the target font file is a regular font. * + * Available since API level 29. + * * \param font a font object. Passing NULL is not allowed. * \return a font collection index. */ @@ -247,6 +259,8 @@ size_t AFont_getCollectionIndex(const AFont* _Nonnull font) __INTRODUCED_IN(29); * * For more information about font variation settings, read [Font Variations Table](https://docs.microsoft.com/en-us/typography/opentype/spec/fvar) * + * Available since API level 29. + * * \param font a font object. Passing NULL is not allowed. * \return a number of font variation settings. */ @@ -258,6 +272,8 @@ size_t AFont_getAxisCount(const AFont* _Nonnull font) __INTRODUCED_IN(29); * * See AFont_getAxisCount for more details. * + * Available since API level 29. + * * \param font a font object. Passing NULL is not allowed. * \param axisIndex an index to the font variation settings. Passing value larger than or * equal to {@link AFont_getAxisCount} is not allowed. @@ -271,6 +287,8 @@ uint32_t AFont_getAxisTag(const AFont* _Nonnull font, uint32_t axisIndex) * * See AFont_getAxisCount for more details. * + * Available since API level 29. + * * \param font a font object. Passing NULL is not allowed. * \param axisIndex an index to the font variation settings. Passing value larger than or * equal to {@link ASYstemFont_getAxisCount} is not allwed. diff --git a/include/android/font_matcher.h b/include/android/font_matcher.h index 0b8f892b9b..d4bd892bf6 100644 --- a/include/android/font_matcher.h +++ b/include/android/font_matcher.h @@ -130,13 +130,17 @@ struct AFontMatcher; */ /** - * Creates a new AFontMatcher object + * Creates a new AFontMatcher object. + * + * Available since API level 29. */ AFontMatcher* _Nonnull AFontMatcher_create() __INTRODUCED_IN(29); /** * Destroy the matcher object. * + * Available since API level 29. + * * \param matcher a matcher object. Passing NULL is not allowed. */ void AFontMatcher_destroy(AFontMatcher* _Nonnull matcher) __INTRODUCED_IN(29); @@ -147,6 +151,8 @@ void AFontMatcher_destroy(AFontMatcher* _Nonnull matcher) __INTRODUCED_IN(29); * If this function is not called, the matcher performs with {@link ASYSTEM_FONT_WEIGHT_NORMAL} * with non-italic style. * + * Available since API level 29. + * * \param matcher a matcher object. Passing NULL is not allowed. * \param weight a font weight value. Only from 0 to 1000 value is valid * \param italic true if italic, otherwise false. @@ -161,6 +167,8 @@ void AFontMatcher_setStyle( * * If this function is not called, the matcher performs with empty locale list. * + * Available since API level 29. + * * \param matcher a matcher object. Passing NULL is not allowed. * \param languageTags a null character terminated comma separated IETF BCP47 compliant language * tags. @@ -174,6 +182,8 @@ void AFontMatcher_setLocales( * * If this function is not called, the matcher performs with {@link AFAMILY_VARIANT_DEFAULT}. * + * Available since API level 29. + * * \param matcher a matcher object. Passing NULL is not allowed. * \param familyVariant Must be one of {@link AFAMILY_VARIANT_DEFAULT}, * {@link AFAMILY_VARIANT_COMPACT} or {@link AFAMILY_VARIANT_ELEGANT} is valid. @@ -190,6 +200,8 @@ void AFontMatcher_setFamilyVariant( * Even if no font can render the given text, this function will return a non-null result for * drawing Tofu character. * + * Available since API level 29. + * * \param matcher a matcher object. Passing NULL is not allowed. * \param familyName a null character terminated font family name * \param text a UTF-16 encoded text buffer to be rendered. Do not pass empty string. diff --git a/include/android/hardware_buffer_jni.h b/include/android/hardware_buffer_jni.h index aedf36903d..293e5ac469 100644 --- a/include/android/hardware_buffer_jni.h +++ b/include/android/hardware_buffer_jni.h @@ -42,6 +42,8 @@ __BEGIN_DECLS * 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. + * + * Available since API level 26. */ AHardwareBuffer* AHardwareBuffer_fromHardwareBuffer(JNIEnv* env, jobject hardwareBufferObj) __INTRODUCED_IN(26); @@ -49,6 +51,8 @@ AHardwareBuffer* AHardwareBuffer_fromHardwareBuffer(JNIEnv* env, /** * Return a new Java HardwareBuffer object that wraps the passed native * AHardwareBuffer object. + * + * Available since API level 26. */ jobject AHardwareBuffer_toHardwareBuffer(JNIEnv* env, AHardwareBuffer* hardwareBuffer) __INTRODUCED_IN(26); diff --git a/include/android/input.h b/include/android/input.h index cfade6c806..ce439c6d75 100644 --- a/include/android/input.h +++ b/include/android/input.h @@ -986,10 +986,8 @@ int32_t AMotionEvent_getFlags(const AInputEvent* motion_event); */ int32_t AMotionEvent_getMetaState(const AInputEvent* motion_event); -#if __ANDROID_API__ >= 14 /** Get the button state of all buttons that are pressed. */ -int32_t AMotionEvent_getButtonState(const AInputEvent* motion_event) __INTRODUCED_IN(14); -#endif +int32_t AMotionEvent_getButtonState(const AInputEvent* motion_event); /** * Get a bitfield indicating which edges, if any, were touched by this motion event. @@ -1054,14 +1052,12 @@ size_t AMotionEvent_getPointerCount(const AInputEvent* motion_event); */ int32_t AMotionEvent_getPointerId(const AInputEvent* motion_event, size_t pointer_index); -#if __ANDROID_API__ >= 14 /** * Get the tool type of a pointer for the given pointer index. * The tool type indicates the type of tool used to make contact such as a * finger or stylus, if known. */ -int32_t AMotionEvent_getToolType(const AInputEvent* motion_event, size_t pointer_index) __INTRODUCED_IN(14); -#endif +int32_t AMotionEvent_getToolType(const AInputEvent* motion_event, size_t pointer_index); /** * Get the original raw X coordinate of this event. @@ -1151,11 +1147,9 @@ float AMotionEvent_getToolMinor(const AInputEvent* motion_event, size_t pointer_ */ float AMotionEvent_getOrientation(const AInputEvent* motion_event, size_t pointer_index); -#if __ANDROID_API__ >= 13 /** Get the value of the request axis for the given pointer index. */ float AMotionEvent_getAxisValue(const AInputEvent* motion_event, - int32_t axis, size_t pointer_index) __INTRODUCED_IN(13); -#endif + int32_t axis, size_t pointer_index); /** * Get the number of historical points in this event. These are movements that @@ -1286,14 +1280,12 @@ float AMotionEvent_getHistoricalToolMinor(const AInputEvent* motion_event, size_ float AMotionEvent_getHistoricalOrientation(const AInputEvent* motion_event, size_t pointer_index, size_t history_index); -#if __ANDROID_API__ >= 13 /** * Get the historical value of the request axis for the given pointer index * that occurred between this event and the previous motion event. */ float AMotionEvent_getHistoricalAxisValue(const AInputEvent* motion_event, - int32_t axis, size_t pointer_index, size_t history_index) __INTRODUCED_IN(13); -#endif + int32_t axis, size_t pointer_index, size_t history_index); struct AInputQueue; diff --git a/include/android/multinetwork.h b/include/android/multinetwork.h index d31d1f122f..59b1deb595 100644 --- a/include/android/multinetwork.h +++ b/include/android/multinetwork.h @@ -69,6 +69,7 @@ typedef uint64_t net_handle_t; * * This is the equivalent of: [android.net.Network#bindSocket()](https://developer.android.com/reference/android/net/Network.html#bindSocket(java.net.Socket)) * + * Available since API level 23. */ int android_setsocknetwork(net_handle_t network, int fd) __INTRODUCED_IN(23); @@ -86,6 +87,7 @@ int android_setsocknetwork(net_handle_t network, int fd) __INTRODUCED_IN(23); * * This is the equivalent of: [android.net.ConnectivityManager#setProcessDefaultNetwork()](https://developer.android.com/reference/android/net/ConnectivityManager.html#setProcessDefaultNetwork(android.net.Network)) * + * Available since API level 23. */ int android_setprocnetwork(net_handle_t network) __INTRODUCED_IN(23); @@ -103,6 +105,7 @@ int android_setprocnetwork(net_handle_t network) __INTRODUCED_IN(23); * * This is the equivalent of: [android.net.Network#getAllByName()](https://developer.android.com/reference/android/net/Network.html#getAllByName(java.lang.String)) * + * Available since API level 23. */ int android_getaddrinfofornetwork(net_handle_t network, const char *node, const char *service, @@ -144,6 +147,8 @@ enum ResNsendFlags : uint32_t { * * Returns a file descriptor to watch for read events, or a negative * POSIX error code (see errno.h) if an immediate error occurs. + * + * Available since API level 29. */ int android_res_nquery(net_handle_t network, const char *dname, int ns_class, int ns_type, uint32_t flags) __INTRODUCED_IN(29); @@ -155,6 +160,8 @@ int android_res_nquery(net_handle_t network, * * Returns a file descriptor to watch for read events, or a negative * POSIX error code (see errno.h) if an immediate error occurs. + * + * Available since API level 29. */ int android_res_nsend(net_handle_t network, const uint8_t *msg, size_t msglen, uint32_t flags) __INTRODUCED_IN(29); @@ -163,6 +170,8 @@ int android_res_nsend(net_handle_t network, * Read a result for the query associated with the |fd| descriptor. * Closes |fd| before returning. * + * Available since 29. + * * Returns: * < 0: negative POSIX error code (see errno.h for possible values). |rcode| is not set. * >= 0: length of |answer|. |rcode| is the resolver return code (e.g., ns_r_nxdomain) @@ -173,6 +182,8 @@ int android_res_nresult(int fd, /** * Attempts to cancel the in-progress query associated with the |nsend_fd| * descriptor. + * + * Available since API level 29. */ void android_res_cancel(int nsend_fd) __INTRODUCED_IN(29); diff --git a/include/android/native_window_jni.h b/include/android/native_window_jni.h index 0c196b9671..3a77ffe86b 100644 --- a/include/android/native_window_jni.h +++ b/include/android/native_window_jni.h @@ -51,6 +51,8 @@ ANativeWindow* ANativeWindow_fromSurface(JNIEnv* env, jobject surface); * the ANativeWindow; maintains it through general Java object's life cycle; * and will automatically release the reference when the Java object gets garbage * collected. + * + * Available since API level 26. */ jobject ANativeWindow_toSurface(JNIEnv* env, ANativeWindow* window) __INTRODUCED_IN(26); #endif diff --git a/include/android/sensor.h b/include/android/sensor.h index e9d5c16d0d..3ebe79fd2e 100644 --- a/include/android/sensor.h +++ b/include/android/sensor.h @@ -564,6 +564,7 @@ ASensorManager* ASensorManager_getInstance(); * * ASensorManager* sensorManager = ASensorManager_getInstanceForPackage("foo.bar.baz"); * + * Available since API level 26. */ ASensorManager* ASensorManager_getInstanceForPackage(const char* packageName) __INTRODUCED_IN(26); #endif @@ -583,6 +584,8 @@ ASensor const* ASensorManager_getDefaultSensor(ASensorManager* manager, int type /** * Returns the default sensor with the given type and wakeUp properties or NULL if no sensor * of this type and wakeUp properties exists. + * + * Available since API level 21. */ ASensor const* ASensorManager_getDefaultSensorEx(ASensorManager* manager, int type, bool wakeUp) __INTRODUCED_IN(21); #endif @@ -609,6 +612,8 @@ int ASensorManager_destroyEventQueue(ASensorManager* manager, ASensorEventQueue* * Create a direct channel of {@link ASENSOR_DIRECT_CHANNEL_TYPE_SHARED_MEMORY} to be used * for configuring sensor direct report. * + * Available since API level 26. + * * \param manager the {@link ASensorManager} instance obtained from * {@link ASensorManager_getInstanceForPackage}. * \param fd file descriptor representing a shared memory created by @@ -627,6 +632,8 @@ int ASensorManager_createSharedMemoryDirectChannel(ASensorManager* manager, int * Create a direct channel of {@link ASENSOR_DIRECT_CHANNEL_TYPE_HARDWARE_BUFFER} type to be used * for configuring sensor direct report. * + * Available since API level 26. + * * \param manager the {@link ASensorManager} instance obtained from * {@link ASensorManager_getInstanceForPackage}. * \param buffer {@link AHardwareBuffer} instance created by {@link AHardwareBuffer_allocate}. @@ -646,6 +653,8 @@ int ASensorManager_createHardwareBufferDirectChannel( * The buffer used for creating direct channel does not get destroyed with * {@link ASensorManager_destroy} and has to be close or released separately. * + * Available since API level 26. + * * \param manager the {@link ASensorManager} instance obtained from * {@link ASensorManager_getInstanceForPackage}. * \param channelId channel id (a positive integer) returned from @@ -678,6 +687,8 @@ void ASensorManager_destroyDirectChannel(ASensorManager* manager, int channelId) * * ASensorManager_configureDirectReport(manager, sensor, channel_id, ASENSOR_DIRECT_RATE_FAST); * + * Available since API level 26. + * * \param manager the {@link ASensorManager} instance obtained from * {@link ASensorManager_getInstanceForPackage}. * \param sensor a {@link ASensor} to denote which sensor to be operate. It can be NULL if rate @@ -780,7 +791,7 @@ int ASensorEventQueue_hasEvents(ASensorEventQueue* queue); */ ssize_t ASensorEventQueue_getEvents(ASensorEventQueue* queue, ASensorEvent* events, size_t count); -#if __ANDROID_API__ >= __ANDROID_API_Q__ +#if __ANDROID_API__ >= 29 /** * Request that {@link ASENSOR_TYPE_ADDITIONAL_INFO} events to be delivered on * the given {@link ASensorEventQueue}. @@ -796,13 +807,15 @@ ssize_t ASensorEventQueue_getEvents(ASensorEventQueue* queue, ASensorEvent* even * {@link AAdditionalInfoEvent#type}, as new values may be defined in the future * and may delivered to the client. * + * Available since API level 29. + * * \param queue {@link ASensorEventQueue} to configure * \param enable true to request {@link ASENSOR_TYPE_ADDITIONAL_INFO} events, * false to stop receiving events * \return 0 on success or a negative error code on failure */ -int ASensorEventQueue_requestAdditionalInfoEvents(ASensorEventQueue* queue, bool enable); -#endif /* __ANDROID_API__ >= __ANDRDOID_API_Q__ */ +int ASensorEventQueue_requestAdditionalInfoEvents(ASensorEventQueue* queue, bool enable) __INTRODUCED_IN(29); +#endif /* __ANDROID_API__ >= 29 */ /*****************************************************************************/ @@ -837,26 +850,36 @@ int ASensor_getMinDelay(ASensor const* sensor); /** * Returns the maximum size of batches for this sensor. Batches will often be * smaller, as the hardware fifo might be used for other sensors. + * + * Available since API level 21. */ int ASensor_getFifoMaxEventCount(ASensor const* sensor) __INTRODUCED_IN(21); /** * Returns the hardware batch fifo size reserved to this sensor. + * + * Available since API level 21. */ int ASensor_getFifoReservedEventCount(ASensor const* sensor) __INTRODUCED_IN(21); /** * Returns this sensor's string type. + * + * Available since API level 21. */ const char* ASensor_getStringType(ASensor const* sensor) __INTRODUCED_IN(21); /** * Returns the reporting mode for this sensor. One of AREPORTING_MODE_* constants. + * + * Available since API level 21. */ int ASensor_getReportingMode(ASensor const* sensor) __INTRODUCED_IN(21); /** * Returns true if this is a wake up sensor, false otherwise. + * + * Available since API level 21. */ bool ASensor_isWakeUpSensor(ASensor const* sensor) __INTRODUCED_IN(21); #endif /* __ANDROID_API__ >= 21 */ @@ -865,6 +888,8 @@ bool ASensor_isWakeUpSensor(ASensor const* sensor) __INTRODUCED_IN(21); /** * Test if sensor supports a certain type of direct channel. * + * Available since API level 26. + * * \param sensor a {@link ASensor} to denote the sensor to be checked. * \param channelType Channel type constant, either * {@ASENSOR_DIRECT_CHANNEL_TYPE_SHARED_MEMORY} @@ -874,7 +899,9 @@ bool ASensor_isWakeUpSensor(ASensor const* sensor) __INTRODUCED_IN(21); bool ASensor_isDirectChannelTypeSupported(ASensor const* sensor, int channelType) __INTRODUCED_IN(26); /** - * Get the highest direct rate level that a sensor support. + * Get the highest direct rate level that a sensor supports. + * + * Available since API level 26. * * \param sensor a {@link ASensor} to denote the sensor to be checked. * @@ -885,7 +912,7 @@ bool ASensor_isDirectChannelTypeSupported(ASensor const* sensor, int channelType int ASensor_getHighestDirectReportRateLevel(ASensor const* sensor) __INTRODUCED_IN(26); #endif /* __ANDROID_API__ >= 26 */ -#if __ANDROID_API__ >= __ANDROID_API_Q__ +#if __ANDROID_API__ >= 29 /** * Returns the sensor's handle. * @@ -899,9 +926,11 @@ int ASensor_getHighestDirectReportRateLevel(ASensor const* sensor) __INTRODUCED_ * It is important to note that the value returned by {@link ASensor_getHandle} is not the same as * the value returned by the Java API {@link android.hardware.Sensor#getId} and no mapping exists * between the values. + * + * Available since API level 29. */ -int ASensor_getHandle(ASensor const* sensor) __INTRODUCED_IN(__ANDROID_API_Q__); -#endif /* __ANDROID_API__ >= ANDROID_API_Q__ */ +int ASensor_getHandle(ASensor const* sensor) __INTRODUCED_IN(29); +#endif /* __ANDROID_API__ >= 29 */ #ifdef __cplusplus }; diff --git a/include/android/surface_control.h b/include/android/surface_control.h index abb8368069..31abb6622e 100644 --- a/include/android/surface_control.h +++ b/include/android/surface_control.h @@ -46,7 +46,7 @@ struct ASurfaceControl; */ typedef struct ASurfaceControl ASurfaceControl; -/* +/** * Creates an ASurfaceControl with either ANativeWindow or an ASurfaceControl as its parent. * |debug_name| is a debug name associated with this surface. It can be used to * identify this surface in the SurfaceFlinger's layer tree. It must not be @@ -54,10 +54,17 @@ typedef struct ASurfaceControl ASurfaceControl; * * The caller takes ownership of the ASurfaceControl returned and must release it * using ASurfaceControl_release below. + * + * Available since API level 29. */ ASurfaceControl* ASurfaceControl_createFromWindow(ANativeWindow* parent, const char* debug_name) __INTRODUCED_IN(29); +/** + * See ASurfaceControl_createFromWindow. + * + * Available since API level 29. + */ ASurfaceControl* ASurfaceControl_create(ASurfaceControl* parent, const char* debug_name) __INTRODUCED_IN(29); @@ -65,6 +72,8 @@ ASurfaceControl* ASurfaceControl_create(ASurfaceControl* parent, const char* deb * Releases the |surface_control| object. After releasing the ASurfaceControl the caller no longer * has ownership of the AsurfaceControl. The surface and it's children may remain on display as long * as their parent remains on display. + * + * Available since API level 29. */ void ASurfaceControl_release(ASurfaceControl* surface_control) __INTRODUCED_IN(29); @@ -79,11 +88,15 @@ typedef struct ASurfaceTransaction ASurfaceTransaction; /** * The caller takes ownership of the transaction and must release it using * ASurfaceControl_delete below. + * + * Available since API level 29. */ ASurfaceTransaction* ASurfaceTransaction_create() __INTRODUCED_IN(29); /** * Destroys the |transaction| object. + * + * Available since API level 29. */ void ASurfaceTransaction_delete(ASurfaceTransaction* transaction) __INTRODUCED_IN(29); @@ -93,6 +106,8 @@ void ASurfaceTransaction_delete(ASurfaceTransaction* transaction) __INTRODUCED_I * Note that the transaction is guaranteed to be applied atomically. The * transactions which are applied on the same thread are also guaranteed to be * applied in order. + * + * Available since API level 29. */ void ASurfaceTransaction_apply(ASurfaceTransaction* transaction) __INTRODUCED_IN(29); @@ -116,6 +131,8 @@ typedef struct ASurfaceTransactionStats ASurfaceTransactionStats; * * THREADING * The transaction completed callback can be invoked on any thread. + * + * Available since API level 29. */ typedef void (*ASurfaceTransaction_OnComplete)(void* context, ASurfaceTransactionStats* stats) __INTRODUCED_IN(29); @@ -123,6 +140,8 @@ typedef void (*ASurfaceTransaction_OnComplete)(void* context, ASurfaceTransactio /** * Returns the timestamp of when the frame was latched by the framework. Once a frame is * latched by the framework, it is presented at the following hardware vsync. + * + * Available since API level 29. */ int64_t ASurfaceTransactionStats_getLatchTime(ASurfaceTransactionStats* surface_transaction_stats) __INTRODUCED_IN(29); @@ -131,6 +150,8 @@ 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. If a device does not support present fences, a -1 will be returned. + * + * Available since API level 29. */ int ASurfaceTransactionStats_getPresentFenceFd(ASurfaceTransactionStats* surface_transaction_stats) __INTRODUCED_IN(29); @@ -141,6 +162,8 @@ int ASurfaceTransactionStats_getPresentFenceFd(ASurfaceTransactionStats* surface * When the client is done using the array, it must release it by calling * ASurfaceTransactionStats_releaseASurfaceControls. * + * Available since API level 29. + * * |outASurfaceControlsSize| returns the size of the ASurfaceControls array. */ void ASurfaceTransactionStats_getASurfaceControls(ASurfaceTransactionStats* surface_transaction_stats, @@ -150,6 +173,8 @@ void ASurfaceTransactionStats_getASurfaceControls(ASurfaceTransactionStats* surf /** * Releases the array of ASurfaceControls that were returned by * ASurfaceTransactionStats_getASurfaceControls. + * + * Available since API level 29. */ void ASurfaceTransactionStats_releaseASurfaceControls(ASurfaceControl** surface_controls) __INTRODUCED_IN(29); @@ -158,6 +183,8 @@ void ASurfaceTransactionStats_releaseASurfaceControls(ASurfaceControl** surface_ * Returns the timestamp of when the CURRENT buffer was acquired. A buffer is considered * acquired when its acquire_fence_fd has signaled. A buffer cannot be latched or presented until * it is acquired. If no acquire_fence_fd was provided, this timestamp will be set to -1. + * + * Available since API level 29. */ int64_t ASurfaceTransactionStats_getAcquireTime(ASurfaceTransactionStats* surface_transaction_stats, ASurfaceControl* surface_control) @@ -180,6 +207,8 @@ int64_t ASurfaceTransactionStats_getAcquireTime(ASurfaceTransactionStats* surfac * * The client must ensure that all pending refs on a buffer are released before attempting to reuse * this buffer, otherwise synchronization errors may occur. + * + * Available since API level 29. */ int ASurfaceTransactionStats_getPreviousReleaseFenceFd( ASurfaceTransactionStats* surface_transaction_stats, @@ -190,6 +219,8 @@ int ASurfaceTransactionStats_getPreviousReleaseFenceFd( * Sets the callback that will be invoked when the updates from this transaction * are presented. For details on the callback semantics and data, see the * comments on the ASurfaceTransaction_OnComplete declaration above. + * + * Available since API level 29. */ void ASurfaceTransaction_setOnComplete(ASurfaceTransaction* transaction, void* context, ASurfaceTransaction_OnComplete func) __INTRODUCED_IN(29); @@ -199,6 +230,8 @@ void ASurfaceTransaction_setOnComplete(ASurfaceTransaction* transaction, void* c * Any children of the* reparented |surface_control| will remain children of the |surface_control|. * * The |new_parent| can be null. Surface controls with a null parent do not appear on the display. + * + * Available since API level 29. */ void ASurfaceTransaction_reparent(ASurfaceTransaction* transaction, ASurfaceControl* surface_control, ASurfaceControl* new_parent) @@ -213,6 +246,8 @@ enum { * Updates the visibility of |surface_control|. If show is set to * ASURFACE_TRANSACTION_VISIBILITY_HIDE, the |surface_control| and all surfaces in its subtree will * be hidden. + * + * Available since API level 29. */ void ASurfaceTransaction_setVisibility(ASurfaceTransaction* transaction, ASurfaceControl* surface_control, int8_t visibility) @@ -224,6 +259,8 @@ void ASurfaceTransaction_setVisibility(ASurfaceTransaction* transaction, * the same z order is undefined. * * Z orders may be from MIN_INT32 to MAX_INT32. A layer's default z order index is 0. + * + * Available since API level 29. */ void ASurfaceTransaction_setZOrder(ASurfaceTransaction* transaction, ASurfaceControl* surface_control, int32_t z_order) @@ -236,6 +273,8 @@ void ASurfaceTransaction_setZOrder(ASurfaceTransaction* transaction, * * The frameworks takes ownership of the |acquire_fence_fd| passed and is responsible * for closing it. + * + * Available since API level 29. */ void ASurfaceTransaction_setBuffer(ASurfaceTransaction* transaction, ASurfaceControl* surface_control, AHardwareBuffer* buffer, @@ -246,6 +285,8 @@ void ASurfaceTransaction_setBuffer(ASurfaceTransaction* transaction, * ASurfaceControl visible in transparent regions of the surface. Colors |r|, |g|, * and |b| must be within the range that is valid for |dataspace|. |dataspace| and |alpha| * will be the dataspace and alpha set for the background color layer. + * + * Available since API level 29. */ void ASurfaceTransaction_setColor(ASurfaceTransaction* transaction, ASurfaceControl* surface_control, float r, float g, float b, @@ -264,6 +305,8 @@ void ASurfaceTransaction_setColor(ASurfaceTransaction* transaction, * |transform| the transform applied after the source rect is applied to the buffer. This parameter * should be set to 0 for no transform. To specify a transfrom use the NATIVE_WINDOW_TRANSFORM_* * enum. + * + * Available since API level 29. */ void ASurfaceTransaction_setGeometry(ASurfaceTransaction* transaction, ASurfaceControl* surface_control, const ARect& source, @@ -281,6 +324,8 @@ enum { * Updates whether the content for the buffer associated with this surface is * completely opaque. If true, every pixel of content inside the buffer must be * opaque or visual errors can occur. + * + * Available since API level 29. */ void ASurfaceTransaction_setBufferTransparency(ASurfaceTransaction* transaction, ASurfaceControl* surface_control, @@ -290,6 +335,8 @@ void ASurfaceTransaction_setBufferTransparency(ASurfaceTransaction* transaction, /** * Updates the region for the content on this surface updated in this * transaction. If unspecified, the complete surface is assumed to be damaged. + * + * Available since API level 29. */ void ASurfaceTransaction_setDamageRegion(ASurfaceTransaction* transaction, ASurfaceControl* surface_control, const ARect rects[], @@ -304,6 +351,8 @@ void ASurfaceTransaction_setDamageRegion(ASurfaceTransaction* transaction, * * If an earlier transaction has a desired present time of x, and a later transaction has a desired * present time that is before x, the later transaction will not preempt the earlier transaction. + * + * Available since API level 29. */ void ASurfaceTransaction_setDesiredPresentTime(ASurfaceTransaction* transaction, int64_t desiredPresentTime) __INTRODUCED_IN(29); @@ -312,6 +361,8 @@ void ASurfaceTransaction_setDesiredPresentTime(ASurfaceTransaction* transaction, * Sets the alpha for the buffer. It uses a premultiplied blending. * * The |alpha| must be between 0.0 and 1.0. + * + * Available since API level 29. */ void ASurfaceTransaction_setBufferAlpha(ASurfaceTransaction* transaction, ASurfaceControl* surface_control, float alpha) @@ -321,6 +372,8 @@ void ASurfaceTransaction_setBufferAlpha(ASurfaceTransaction* transaction, * Sets the data space of the surface_control's buffers. * * If no data space is set, the surface control defaults to ADATASPACE_SRGB. + * + * Available since API level 29. */ void ASurfaceTransaction_setBufferDataSpace(ASurfaceTransaction* transaction, ASurfaceControl* surface_control, ADataSpace data_space) @@ -331,6 +384,8 @@ void ASurfaceTransaction_setBufferDataSpace(ASurfaceTransaction* transaction, * * When |metadata| is set to null, the framework does not use any smpte2086 metadata when rendering * the surface's buffer. + * + * Available since API level 29. */ void ASurfaceTransaction_setHdrMetadata_smpte2086(ASurfaceTransaction* transaction, ASurfaceControl* surface_control, @@ -342,6 +397,8 @@ void ASurfaceTransaction_setHdrMetadata_smpte2086(ASurfaceTransaction* transacti * * When |metadata| is set to null, the framework does not use any cta861.3 metadata when rendering * the surface's buffer. + * + * Available since API level 29. */ void ASurfaceTransaction_setHdrMetadata_cta861_3(ASurfaceTransaction* transaction, ASurfaceControl* surface_control, diff --git a/include/android/surface_texture.h b/include/android/surface_texture.h index 540d23a4c7..dde7eaa0b6 100644 --- a/include/android/surface_texture.h +++ b/include/android/surface_texture.h @@ -65,6 +65,9 @@ typedef struct ASurfaceTexture ASurfaceTexture; * Release the reference to the native ASurfaceTexture acquired with * ASurfaceTexture_fromSurfaceTexture(). * Failing to do so will result in leaked memory and graphic resources. + * + * Available since API level 28. + * * \param st A ASurfaceTexture reference acquired with ASurfaceTexture_fromSurfaceTexture() */ void ASurfaceTexture_release(ASurfaceTexture* st) __INTRODUCED_IN(28); @@ -73,6 +76,8 @@ void ASurfaceTexture_release(ASurfaceTexture* st) __INTRODUCED_IN(28); * Returns a reference to an ANativeWindow (i.e. the Producer) for this SurfaceTexture. * This is equivalent to Java's: Surface sur = new Surface(surfaceTexture); * + * Available since API level 28. + * * \param st A ASurfaceTexture reference acquired with ASurfaceTexture_fromSurfaceTexture() * @return A reference to an ANativeWindow. This reference MUST BE released when no longer needed * using ANativeWindow_release(). Failing to do so will result in leaked resources. nullptr is @@ -90,6 +95,8 @@ ANativeWindow* ASurfaceTexture_acquireANativeWindow(ASurfaceTexture* st) __INTRO * contexts. Note, however, that the image contents are only accessible from one OpenGL ES * context at a time. * + * Available since API level 28. + * * \param st A ASurfaceTexture reference acquired with ASurfaceTexture_fromSurfaceTexture() * \param texName The name of the OpenGL ES texture that will be created. This texture name * must be unusued in the OpenGL ES context that is current on the calling thread. @@ -108,6 +115,8 @@ int ASurfaceTexture_attachToGLContext(ASurfaceTexture* st, uint32_t texName) __I * contexts. Note, however, that the image contents are only accessible from one OpenGL ES * context at a time. * + * Available since API level 28. + * * \param st A ASurfaceTexture reference acquired with ASurfaceTexture_fromSurfaceTexture() * \return 0 on success, negative posix error code otherwise (see ) */ @@ -118,6 +127,8 @@ int ASurfaceTexture_detachFromGLContext(ASurfaceTexture* st) __INTRODUCED_IN(28) * called while the OpenGL ES context that owns the texture is current on the calling thread. * It will implicitly bind its texture to the GL_TEXTURE_EXTERNAL_OES texture target. * + * Available since API level 28. + * * \param st A ASurfaceTexture reference acquired with ASurfaceTexture_fromSurfaceTexture() * \return 0 on success, negative posix error code otherwise (see ) */ @@ -135,6 +146,8 @@ int ASurfaceTexture_updateTexImage(ASurfaceTexture* st) __INTRODUCED_IN(28); * The matrix is stored in column-major order so that it may be passed directly to OpenGL ES via * the glLoadMatrixf or glUniformMatrix4fv functions. * + * Available since API level 28. + * * \param st A ASurfaceTexture reference acquired with ASurfaceTexture_fromSurfaceTexture() * \param mtx the array into which the 4x4 matrix will be stored. The array must have exactly * 16 elements. @@ -156,6 +169,8 @@ void ASurfaceTexture_getTransformMatrix(ASurfaceTexture* st, float mtx[16]) __IN * For EGL/Vulkan producers, this timestamp is the desired present time set with the * EGL_ANDROID_presentation_time or VK_GOOGLE_display_timing extensions * + * Available since API level 28. + * * \param st A ASurfaceTexture reference acquired with ASurfaceTexture_fromSurfaceTexture() */ int64_t ASurfaceTexture_getTimestamp(ASurfaceTexture* st) __INTRODUCED_IN(28); diff --git a/include/android/surface_texture_jni.h b/include/android/surface_texture_jni.h index b0e1edd590..2266d541f6 100644 --- a/include/android/surface_texture_jni.h +++ b/include/android/surface_texture_jni.h @@ -32,6 +32,8 @@ __BEGIN_DECLS +#if __ANDROID_API__ >= 28 + /** * Get a reference to the native ASurfaceTexture from the corresponding java object. * @@ -40,13 +42,17 @@ __BEGIN_DECLS * properly once the Java object gets finalized. * However, this will not result in program termination. * + * Available since API level 28. + * * \param env JNI environment * \param surfacetexture Instance of Java SurfaceTexture object * \return native ASurfaceTexture reference or nullptr if the java object is not a SurfaceTexture. * The returned reference MUST BE released when it's no longer needed using * ASurfaceTexture_release(). */ -ASurfaceTexture* ASurfaceTexture_fromSurfaceTexture(JNIEnv* env, jobject surfacetexture); +ASurfaceTexture* ASurfaceTexture_fromSurfaceTexture(JNIEnv* env, jobject surfacetexture) __INTRODUCED_IN(28); + +#endif __END_DECLS diff --git a/include/android/system_fonts.h b/include/android/system_fonts.h index f0485a1871..6fd7d2c0ab 100644 --- a/include/android/system_fonts.h +++ b/include/android/system_fonts.h @@ -102,6 +102,8 @@ struct ASystemFontIterator; * * Use ASystemFont_close() to close the iterator. * + * Available since API level 29. + * * \return a pointer for a newly allocated iterator, nullptr on failure. */ ASystemFontIterator* _Nullable ASystemFontIterator_open() __INTRODUCED_IN(29); @@ -109,6 +111,8 @@ ASystemFontIterator* _Nullable ASystemFontIterator_open() __INTRODUCED_IN(29); /** * Close an opened system font iterator, freeing any related resources. * + * Available since API level 29. + * * \param iterator a pointer of an iterator for the system fonts. Do nothing if NULL is passed. */ void ASystemFontIterator_close(ASystemFontIterator* _Nullable iterator) __INTRODUCED_IN(29); @@ -116,6 +120,8 @@ void ASystemFontIterator_close(ASystemFontIterator* _Nullable iterator) __INTROD /** * Move to the next system font. * + * Available since API level 29. + * * \param iterator an iterator for the system fonts. Passing NULL is not allowed. * \return a font. If no more font is available, returns nullptr. You need to release the returned * font by ASystemFont_close when it is no longer needed. diff --git a/include/android/trace.h b/include/android/trace.h index bb7ff28f79..d59690ab2e 100644 --- a/include/android/trace.h +++ b/include/android/trace.h @@ -74,7 +74,7 @@ void ATrace_endSection() __INTRODUCED_IN(23); #endif /* __ANDROID_API__ >= 23 */ -#if __ANDROID_API__ >= __ANDROID_API_Q__ +#if __ANDROID_API__ >= 29 /** * Writes a trace message to indicate that a given section of code has @@ -83,6 +83,8 @@ void ATrace_endSection() __INTRODUCED_IN(23); * asynchronous events do not need to be nested. The name and cookie used to * begin an event must be used to end it. * + * Available since API level 29. + * * \param sectionName The method name to appear in the trace. * \param cookie Unique identifier for distinguishing simultaneous events */ @@ -93,6 +95,8 @@ void ATrace_beginAsyncSection(const char* sectionName, int32_t cookie) __INTRODU * Must be called exactly once for each call to {@link ATrace_beginAsyncSection} * using the same name and cookie. * + * Available since API level 29. + * * \param methodName The method name to appear in the trace. * \param cookie Unique identifier for distinguishing simultaneous events */ @@ -101,6 +105,8 @@ void ATrace_endAsyncSection(const char* sectionName, int32_t cookie) __INTRODUCE /** * Writes trace message to indicate the value of a given counter. * + * Available since API level 29. + * * \param counterName The counter name to appear in the trace. * \param counterValue The counter value. */ diff --git a/libs/binder/ndk/include_ndk/android/binder_auto_utils.h b/libs/binder/ndk/include_ndk/android/binder_auto_utils.h index dc3c8d2e3a..dc891caab4 100644 --- a/libs/binder/ndk/include_ndk/android/binder_auto_utils.h +++ b/libs/binder/ndk/include_ndk/android/binder_auto_utils.h @@ -21,7 +21,7 @@ /** * @file binder_auto_utils.h - * @brief These objects provide a more C++-like thin interface to the . + * @brief These objects provide a more C++-like thin interface to the binder. */ #pragma once diff --git a/libs/binder/ndk/include_ndk/android/binder_ibinder.h b/libs/binder/ndk/include_ndk/android/binder_ibinder.h index 160739b044..4d5c044232 100644 --- a/libs/binder/ndk/include_ndk/android/binder_ibinder.h +++ b/libs/binder/ndk/include_ndk/android/binder_ibinder.h @@ -34,7 +34,7 @@ #include __BEGIN_DECLS -#if __ANDROID_API__ >= __ANDROID_API_Q__ +#if __ANDROID_API__ >= 29 // Also see TF_* in kernel's binder.h typedef uint32_t binder_flags_t; @@ -165,6 +165,8 @@ typedef binder_status_t (*AIBinder_Class_onTransact)(AIBinder* binder, transacti * * None of these parameters can be null. * + * Available since API level 29. + * * \param interfaceDescriptor this is a unique identifier for the class. This is used internally for * sanity checks on transactions. * \param onCreate see AIBinder_Class_onCreate. @@ -199,6 +201,8 @@ typedef binder_status_t (*AIBinder_onDump)(AIBinder* binder, int fd, const char* * If this isn't set, nothing will be dumped when dump is called (for instance with * android.os.Binder#dump). Must be called before any instance of the class is created. * + * Available since API level 29. + * * \param dump function to call when an instance of this binder class is being dumped. */ void AIBinder_Class_setOnDump(AIBinder_Class* clazz, AIBinder_onDump onDump) __INTRODUCED_IN(29); @@ -220,6 +224,8 @@ void AIBinder_Class_setOnDump(AIBinder_Class* clazz, AIBinder_onDump onDump) __I * these two objects are actually equal using the AIBinder pointer alone (which they should be able * to do). Also see the suggested memory ownership model suggested above. * + * Available since API level 29. + * * \param clazz the type of the object to be created. * \param args the args to pass to AIBinder_onCreate for that class. * @@ -231,6 +237,8 @@ __attribute__((warn_unused_result)) AIBinder* AIBinder_new(const AIBinder_Class* /** * If this is hosted in a process other than the current one. * + * Available since API level 29. + * * \param binder the binder being queried. * * \return true if the AIBinder represents an object in another process. @@ -244,6 +252,8 @@ bool AIBinder_isRemote(const AIBinder* binder) __INTRODUCED_IN(29); * updated as the result of a transaction made using AIBinder_transact, but it will also be updated * based on the results of bookkeeping or other transactions made internally. * + * Available since API level 29. + * * \param binder the binder being queried. * * \return true if the binder is alive. @@ -255,6 +265,8 @@ bool AIBinder_isAlive(const AIBinder* binder) __INTRODUCED_IN(29); * return. Usually this is used to make sure that a binder is alive, as a placeholder call, or as a * sanity check. * + * Available since API level 29. + * * \param binder the binder being queried. * * \return STATUS_OK if the ping succeeds. @@ -264,7 +276,9 @@ binder_status_t AIBinder_ping(AIBinder* binder) __INTRODUCED_IN(29); /** * Built-in transaction for all binder objects. This dumps information about a given binder. * - * See also AIBinder_Class_setOnDump, AIBinder_onDump + * See also AIBinder_Class_setOnDump, AIBinder_onDump. + * + * Available since API level 29. * * \param binder the binder to dump information about * \param fd where information should be dumped to @@ -287,6 +301,8 @@ binder_status_t AIBinder_dump(AIBinder* binder, int fd, const char** args, uint3 * * If binder is local, this will return STATUS_INVALID_OPERATION. * + * Available since API level 29. + * * \param binder the binder object you want to receive death notifications from. * \param recipient the callback that will receive notifications when/if the binder dies. * \param cookie the value that will be passed to the death recipient on death. @@ -306,6 +322,8 @@ binder_status_t AIBinder_linkToDeath(AIBinder* binder, AIBinder_DeathRecipient* * If the binder dies, it will automatically unlink. If the binder is deleted, it will be * automatically unlinked. * + * Available since API level 29. + * * \param binder the binder object to remove a previously linked death recipient from. * \param recipient the callback to remove. * \param cookie the cookie used to link to death. @@ -322,9 +340,11 @@ binder_status_t AIBinder_unlinkToDeath(AIBinder* binder, AIBinder_DeathRecipient * This can be used with higher-level system services to determine the caller's identity and check * permissions. * + * Available since API level 29. + * * \return calling uid or the current process's UID if this thread isn't processing a transaction. */ -uid_t AIBinder_getCallingUid(); +uid_t AIBinder_getCallingUid() __INTRODUCED_IN(29); /** * This returns the calling PID assuming that this thread is called from a thread that is processing @@ -335,14 +355,18 @@ uid_t AIBinder_getCallingUid(); * calling process dies and is replaced with another process with elevated permissions and the same * PID. * + * Available since API level 29. + * * \return calling pid or the current process's PID if this thread isn't processing a transaction. * If the transaction being processed is a oneway transaction, then this method will return 0. */ -pid_t AIBinder_getCallingPid(); +pid_t AIBinder_getCallingPid() __INTRODUCED_IN(29); /** * This can only be called if a strong reference to this object already exists in process. * + * Available since API level 29. + * * \param binder the binder object to add a refcount to. */ void AIBinder_incStrong(AIBinder* binder) __INTRODUCED_IN(29); @@ -350,6 +374,8 @@ void AIBinder_incStrong(AIBinder* binder) __INTRODUCED_IN(29); /** * This will delete the object and call onDestroy once the refcount reaches zero. * + * Available since API level 29. + * * \param binder the binder object to remove a refcount from. */ void AIBinder_decStrong(AIBinder* binder) __INTRODUCED_IN(29); @@ -357,6 +383,8 @@ void AIBinder_decStrong(AIBinder* binder) __INTRODUCED_IN(29); /** * For debugging only! * + * Available since API level 29. + * * \param binder the binder object to retrieve the refcount of. * * \return the number of strong-refs on this binder in this process. If binder is null, this will be @@ -373,6 +401,8 @@ int32_t AIBinder_debugGetRefCount(AIBinder* binder) __INTRODUCED_IN(29); * This returns true if the class association succeeds. If it fails, no change is made to the * binder object. * + * Available since API level 29. + * * \param binder the object to attach the class to. * \param clazz the clazz to attach to binder. * @@ -383,6 +413,8 @@ bool AIBinder_associateClass(AIBinder* binder, const AIBinder_Class* clazz) __IN /** * Returns the class that this binder was constructed with or associated with. * + * Available since API level 29. + * * \param binder the object that is being queried. * * \return the class that this binder is associated with. If this binder wasn't created with @@ -394,6 +426,8 @@ const AIBinder_Class* AIBinder_getClass(AIBinder* binder) __INTRODUCED_IN(29); * Value returned by onCreate for a local binder. For stateless classes (if onCreate returns * null), this also returns null. For a remote binder, this will always return null. * + * Available since API level 29. + * * \param binder the object that is being queried. * * \return the userdata returned from AIBinder_onCreate when this object was created. This may be @@ -422,6 +456,8 @@ void* AIBinder_getUserData(AIBinder* binder) __INTRODUCED_IN(29); * AIBinder_transact. Alternatively, if there is an error while filling out the parcel, it can be * deleted with AParcel_delete. * + * Available since API level 29. + * * \param binder the binder object to start a transaction on. * \param in out parameter for input data to the transaction. * @@ -442,6 +478,8 @@ binder_status_t AIBinder_prepareTransaction(AIBinder* binder, AParcel** in) __IN * This does not affect the ownership of binder. The out parcel's ownership is passed to the caller * and must be released with AParcel_delete when finished reading. * + * Available since API level 29. + * * \param binder the binder object to transact on. * \param code the implementation-specific code representing which transaction should be taken. * \param in the implementation-specific input data to this transaction. @@ -459,6 +497,8 @@ binder_status_t AIBinder_transact(AIBinder* binder, transaction_code_t code, APa * This does not take any ownership of the input binder, but it can be used to retrieve it if * something else in some process still holds a reference to it. * + * Available since API level 29. + * * \param binder object to create a weak pointer to. * * \return object representing a weak pointer to binder (or null if binder is null). @@ -469,6 +509,8 @@ __attribute__((warn_unused_result)) AIBinder_Weak* AIBinder_Weak_new(AIBinder* b /** * Deletes the weak reference. This will have no impact on the lifetime of the binder. * + * Available since API level 29. + * * \param weakBinder object created with AIBinder_Weak_new. */ void AIBinder_Weak_delete(AIBinder_Weak* weakBinder) __INTRODUCED_IN(29); @@ -477,6 +519,8 @@ void AIBinder_Weak_delete(AIBinder_Weak* weakBinder) __INTRODUCED_IN(29); * If promotion succeeds, result will have one strong refcount added to it. Otherwise, this returns * null. * + * Available since API level 29. + * * \param weakBinder weak pointer to attempt retrieving the original object from. * * \return an AIBinder object with one refcount given to the caller or null. @@ -487,6 +531,8 @@ __attribute__((warn_unused_result)) AIBinder* AIBinder_Weak_promote(AIBinder_Wea /** * This function is executed on death receipt. See AIBinder_linkToDeath/AIBinder_unlinkToDeath. * + * Available since API level 29. + * * \param cookie the cookie passed to AIBinder_linkToDeath. */ typedef void (*AIBinder_DeathRecipient_onBinderDied)(void* cookie) __INTRODUCED_IN(29); @@ -494,6 +540,8 @@ typedef void (*AIBinder_DeathRecipient_onBinderDied)(void* cookie) __INTRODUCED_ /** * Creates a new binder death recipient. This can be attached to multiple different binder objects. * + * Available since API level 29. + * * \param onBinderDied the callback to call when this death recipient is invoked. * * \return the newly constructed object (or null if onBinderDied is null). @@ -505,19 +553,23 @@ __attribute__((warn_unused_result)) AIBinder_DeathRecipient* AIBinder_DeathRecip * Deletes a binder death recipient. It is not necessary to call AIBinder_unlinkToDeath before * calling this as these will all be automatically unlinked. * + * Available since API level 29. + * * \param recipient the binder to delete (previously created with AIBinder_DeathRecipient_new). */ void AIBinder_DeathRecipient_delete(AIBinder_DeathRecipient* recipient) __INTRODUCED_IN(29); -#endif //__ANDROID_API__ >= __ANDROID_API_Q__ +#endif //__ANDROID_API__ >= 29 -#if __ANDROID_API__ >= __ANDROID_API_R__ +#if __ANDROID_API__ >= 30 /** * Gets the extension registered with AIBinder_setExtension. * * See AIBinder_setExtension. * + * Available since API level 30. + * * \param binder the object to get the extension of. * \param outExt the returned extension object. Will be null if there is no extension set or * non-null with one strong ref count. @@ -570,6 +622,8 @@ binder_status_t AIBinder_getExtension(AIBinder* binder, AIBinder** outExt) __INT * // if bar is null, then there is no extension or a different * // type of extension * + * Available since API level 30. + * * \param binder the object to get the extension on. Must be local. * \param ext the extension to set (binder will hold a strong reference to this) * @@ -578,7 +632,7 @@ binder_status_t AIBinder_getExtension(AIBinder* binder, AIBinder** outExt) __INT */ binder_status_t AIBinder_setExtension(AIBinder* binder, AIBinder* ext) __INTRODUCED_IN(30); -#endif //__ANDROID_API__ >= __ANDROID_API_R__ +#endif //__ANDROID_API__ >= 30 __END_DECLS diff --git a/libs/binder/ndk/include_ndk/android/binder_ibinder_jni.h b/libs/binder/ndk/include_ndk/android/binder_ibinder_jni.h index 124f36c55b..be3029c3ff 100644 --- a/libs/binder/ndk/include_ndk/android/binder_ibinder_jni.h +++ b/libs/binder/ndk/include_ndk/android/binder_ibinder_jni.h @@ -31,7 +31,7 @@ #include __BEGIN_DECLS -#if __ANDROID_API__ >= __ANDROID_API_Q__ +#if __ANDROID_API__ >= 29 /** * Converts an android.os.IBinder object into an AIBinder* object. @@ -40,6 +40,8 @@ __BEGIN_DECLS * AIBinder object, the original object is returned. The returned object has one refcount * associated with it, and so this should be accompanied with an AIBinder_decStrong call. * + * Available since API level 29. + * * \param env Java environment. * \param binder android.os.IBinder java object. * @@ -55,6 +57,8 @@ __attribute__((warn_unused_result)) AIBinder* AIBinder_fromJavaBinder(JNIEnv* en * If either env or the binder is null, null is returned. If this binder object was originally an * IBinder object, the original java object will be returned. * + * Available since API level 29. + * * \param env Java environment. * \param binder the object to convert. * @@ -63,7 +67,7 @@ __attribute__((warn_unused_result)) AIBinder* AIBinder_fromJavaBinder(JNIEnv* en __attribute__((warn_unused_result)) jobject AIBinder_toJavaBinder(JNIEnv* env, AIBinder* binder) __INTRODUCED_IN(29); -#endif //__ANDROID_API__ >= __ANDROID_API_Q__ +#endif //__ANDROID_API__ >= 29 __END_DECLS /** @} */ diff --git a/libs/binder/ndk/include_ndk/android/binder_parcel.h b/libs/binder/ndk/include_ndk/android/binder_parcel.h index 8c4170754a..86b75b8c61 100644 --- a/libs/binder/ndk/include_ndk/android/binder_parcel.h +++ b/libs/binder/ndk/include_ndk/android/binder_parcel.h @@ -35,7 +35,7 @@ struct AIBinder; typedef struct AIBinder AIBinder; __BEGIN_DECLS -#if __ANDROID_API__ >= __ANDROID_API_Q__ +#if __ANDROID_API__ >= 29 /** * This object represents a package of data that can be sent between processes. When transacting, an @@ -49,6 +49,8 @@ typedef struct AParcel AParcel; /** * Cleans up a parcel. * + * Available since API level 29. + * * \param parcel A parcel returned by AIBinder_prepareTransaction or AIBinder_transact when a * transaction is being aborted. */ @@ -57,6 +59,8 @@ void AParcel_delete(AParcel* parcel) __INTRODUCED_IN(29); /** * Sets the position within the parcel. * + * Available since API level 29. + * * \param parcel The parcel of which to set the position. * \param position Position of the parcel to set. This must be a value returned by * AParcel_getDataPosition. Positions are constant for a given parcel between processes. @@ -69,6 +73,8 @@ binder_status_t AParcel_setDataPosition(const AParcel* parcel, int32_t position) /** * Gets the current position within the parcel. * + * Available since API level 29. + * * \param parcel The parcel of which to get the position. * * \return The size of the parcel. This will always be greater than 0. The values returned by this @@ -389,6 +395,8 @@ typedef bool (*AParcel_byteArrayAllocator)(void* arrayData, int32_t length, int8 * Writes an AIBinder to the next location in a non-null parcel. Can be null. This does not take any * refcounts of ownership of the binder from the client. * + * Available since API level 29. + * * \param parcel the parcel to write to. * \param binder the value to write to the parcel. * @@ -400,6 +408,8 @@ binder_status_t AParcel_writeStrongBinder(AParcel* parcel, AIBinder* binder) __I * Reads an AIBinder from the next location in a non-null parcel. One strong ref-count of ownership * is passed to the caller of this function. * + * Available since API level 29. + * * \param parcel the parcel to read from. * \param binder the out parameter for what is read from the parcel. This may be null. * @@ -414,12 +424,14 @@ binder_status_t AParcel_readStrongBinder(const AParcel* parcel, AIBinder** binde * * This corresponds to the SDK's android.os.ParcelFileDescriptor. * + * Available since API level 29. + * * \param parcel the parcel to write to. * \param fd the value to write to the parcel (-1 to represent a null ParcelFileDescriptor). * * \return STATUS_OK on successful write. */ -binder_status_t AParcel_writeParcelFileDescriptor(AParcel* parcel, int fd); +binder_status_t AParcel_writeParcelFileDescriptor(AParcel* parcel, int fd) __INTRODUCED_IN(29); /** * Reads an int from the next location in a non-null parcel. @@ -428,13 +440,16 @@ binder_status_t AParcel_writeParcelFileDescriptor(AParcel* parcel, int fd); * * This corresponds to the SDK's android.os.ParcelFileDescriptor. * + * Available since API level 29. + * * \param parcel the parcel to read from. * \param fd the out parameter for what is read from the parcel (or -1 to represent a null * ParcelFileDescriptor) * * \return STATUS_OK on successful write. */ -binder_status_t AParcel_readParcelFileDescriptor(const AParcel* parcel, int* fd); +binder_status_t AParcel_readParcelFileDescriptor(const AParcel* parcel, int* fd) + __INTRODUCED_IN(29); /** * Writes an AStatus object to the next location in a non-null parcel. @@ -445,6 +460,8 @@ binder_status_t AParcel_readParcelFileDescriptor(const AParcel* parcel, int* fd) * this happens or if writing the status object itself fails, the return value from this function * should be propagated to the client, and AParcel_readStatusHeader shouldn't be called. * + * Available since API level 29. + * * \param parcel the parcel to write to. * \param status the value to write to the parcel. * @@ -457,6 +474,8 @@ binder_status_t AParcel_writeStatusHeader(AParcel* parcel, const AStatus* status * Reads an AStatus from the next location in a non-null parcel. Ownership is passed to the caller * of this function. * + * Available since API level 29. + * * \param parcel the parcel to read from. * \param status the out parameter for what is read from the parcel. * @@ -470,6 +489,8 @@ binder_status_t AParcel_readStatusHeader(const AParcel* parcel, AStatus** status * * If length is -1, and string is nullptr, this will write a 'null' string to the parcel. * + * Available since API level 29. + * * \param parcel the parcel to write to. * \param string the null-terminated string to write to the parcel, at least of size 'length'. * \param length the length of the string to be written. @@ -487,6 +508,8 @@ binder_status_t AParcel_writeString(AParcel* parcel, const char* string, int32_t * the output buffer from this read. If there is a 'null' string on the binder buffer, the allocator * will be called with length -1. * + * Available since API level 29. + * * \param parcel the parcel to read from. * \param stringData some external representation of a string. * \param allocator allocator that will be called once the size of the string is known. @@ -504,6 +527,8 @@ binder_status_t AParcel_readString(const AParcel* parcel, void* stringData, * returned from this function will be used to fill out the data from the parcel. If length is -1, * this will write a 'null' string array to the binder buffer. * + * Available since API level 29. + * * \param parcel the parcel to write to. * \param arrayData some external representation of an array. * \param length the length of the array to be written. @@ -526,6 +551,8 @@ binder_status_t AParcel_writeStringArray(AParcel* parcel, const void* arrayData, * the contents of the string that is read. If the string array being read is 'null', this will * instead just pass -1 to AParcel_stringArrayAllocator. * + * Available since API level 29. + * * \param parcel the parcel to read from. * \param arrayData some external representation of an array. * \param allocator the callback that will be called with arrayData once the size of the output @@ -543,6 +570,8 @@ binder_status_t AParcel_readStringArray(const AParcel* parcel, void* arrayData, /** * Writes an array of parcelables (user-defined types) to the next location in a non-null parcel. * + * Available since API level 29. + * * \param parcel the parcel to write to. * \param arrayData an array of size 'length' (or null if length is -1, may be null if length is 0). * \param length the length of arrayData or -1 if this represents a null array. @@ -562,6 +591,8 @@ binder_status_t AParcel_writeParcelableArray(AParcel* parcel, const void* arrayD * length is greater than zero, elementReader will be called for every index to read the * corresponding parcelable. * + * Available since API level 29. + * * \param parcel the parcel to read from. * \param arrayData some external representation of an array. * \param allocator the callback that will be called to allocate the array. @@ -578,6 +609,8 @@ binder_status_t AParcel_readParcelableArray(const AParcel* parcel, void* arrayDa /** * Writes int32_t value to the next location in a non-null parcel. * + * Available since API level 29. + * * \param parcel the parcel to write to. * \param value the value to write to the parcel. * @@ -588,6 +621,8 @@ binder_status_t AParcel_writeInt32(AParcel* parcel, int32_t value) __INTRODUCED_ /** * Writes uint32_t value to the next location in a non-null parcel. * + * Available since API level 29. + * * \param parcel the parcel to write to. * \param value the value to write to the parcel. * @@ -598,6 +633,8 @@ binder_status_t AParcel_writeUint32(AParcel* parcel, uint32_t value) __INTRODUCE /** * Writes int64_t value to the next location in a non-null parcel. * + * Available since API level 29. + * * \param parcel the parcel to write to. * \param value the value to write to the parcel. * @@ -608,6 +645,8 @@ binder_status_t AParcel_writeInt64(AParcel* parcel, int64_t value) __INTRODUCED_ /** * Writes uint64_t value to the next location in a non-null parcel. * + * Available since API level 29. + * * \param parcel the parcel to write to. * \param value the value to write to the parcel. * @@ -618,6 +657,8 @@ binder_status_t AParcel_writeUint64(AParcel* parcel, uint64_t value) __INTRODUCE /** * Writes float value to the next location in a non-null parcel. * + * Available since API level 29. + * * \param parcel the parcel to write to. * \param value the value to write to the parcel. * @@ -628,6 +669,8 @@ binder_status_t AParcel_writeFloat(AParcel* parcel, float value) __INTRODUCED_IN /** * Writes double value to the next location in a non-null parcel. * + * Available since API level 29. + * * \param parcel the parcel to write to. * \param value the value to write to the parcel. * @@ -638,6 +681,8 @@ binder_status_t AParcel_writeDouble(AParcel* parcel, double value) __INTRODUCED_ /** * Writes bool value to the next location in a non-null parcel. * + * Available since API level 29. + * * \param parcel the parcel to write to. * \param value the value to write to the parcel. * @@ -648,6 +693,8 @@ binder_status_t AParcel_writeBool(AParcel* parcel, bool value) __INTRODUCED_IN(2 /** * Writes char16_t value to the next location in a non-null parcel. * + * Available since API level 29. + * * \param parcel the parcel to write to. * \param value the value to write to the parcel. * @@ -658,6 +705,8 @@ binder_status_t AParcel_writeChar(AParcel* parcel, char16_t value) __INTRODUCED_ /** * Writes int8_t value to the next location in a non-null parcel. * + * Available since API level 29. + * * \param parcel the parcel to write to. * \param value the value to write to the parcel. * @@ -668,6 +717,8 @@ binder_status_t AParcel_writeByte(AParcel* parcel, int8_t value) __INTRODUCED_IN /** * Reads into int32_t value from the next location in a non-null parcel. * + * Available since API level 29. + * * \param parcel the parcel to read from. * \param value the value to read from the parcel. * @@ -678,6 +729,8 @@ binder_status_t AParcel_readInt32(const AParcel* parcel, int32_t* value) __INTRO /** * Reads into uint32_t value from the next location in a non-null parcel. * + * Available since API level 29. + * * \param parcel the parcel to read from. * \param value the value to read from the parcel. * @@ -688,6 +741,8 @@ binder_status_t AParcel_readUint32(const AParcel* parcel, uint32_t* value) __INT /** * Reads into int64_t value from the next location in a non-null parcel. * + * Available since API level 29. + * * \param parcel the parcel to read from. * \param value the value to read from the parcel. * @@ -698,6 +753,8 @@ binder_status_t AParcel_readInt64(const AParcel* parcel, int64_t* value) __INTRO /** * Reads into uint64_t value from the next location in a non-null parcel. * + * Available since API level 29. + * * \param parcel the parcel to read from. * \param value the value to read from the parcel. * @@ -708,6 +765,8 @@ binder_status_t AParcel_readUint64(const AParcel* parcel, uint64_t* value) __INT /** * Reads into float value from the next location in a non-null parcel. * + * Available since API level 29. + * * \param parcel the parcel to read from. * \param value the value to read from the parcel. * @@ -718,6 +777,8 @@ binder_status_t AParcel_readFloat(const AParcel* parcel, float* value) __INTRODU /** * Reads into double value from the next location in a non-null parcel. * + * Available since API level 29. + * * \param parcel the parcel to read from. * \param value the value to read from the parcel. * @@ -728,6 +789,8 @@ binder_status_t AParcel_readDouble(const AParcel* parcel, double* value) __INTRO /** * Reads into bool value from the next location in a non-null parcel. * + * Available since API level 29. + * * \param parcel the parcel to read from. * \param value the value to read from the parcel. * @@ -738,6 +801,8 @@ binder_status_t AParcel_readBool(const AParcel* parcel, bool* value) __INTRODUCE /** * Reads into char16_t value from the next location in a non-null parcel. * + * Available since API level 29. + * * \param parcel the parcel to read from. * \param value the value to read from the parcel. * @@ -748,6 +813,8 @@ binder_status_t AParcel_readChar(const AParcel* parcel, char16_t* value) __INTRO /** * Reads into int8_t value from the next location in a non-null parcel. * + * Available since API level 29. + * * \param parcel the parcel to read from. * \param value the value to read from the parcel. * @@ -758,6 +825,8 @@ binder_status_t AParcel_readByte(const AParcel* parcel, int8_t* value) __INTRODU /** * Writes an array of int32_t to the next location in a non-null parcel. * + * Available since API level 29. + * * \param parcel the parcel to write to. * \param arrayData an array of size 'length' (or null if length is -1, may be null if length is 0). * \param length the length of arrayData or -1 if this represents a null array. @@ -770,6 +839,8 @@ binder_status_t AParcel_writeInt32Array(AParcel* parcel, const int32_t* arrayDat /** * Writes an array of uint32_t to the next location in a non-null parcel. * + * Available since API level 29. + * * \param parcel the parcel to write to. * \param arrayData an array of size 'length' (or null if length is -1, may be null if length is 0). * \param length the length of arrayData or -1 if this represents a null array. @@ -782,6 +853,8 @@ binder_status_t AParcel_writeUint32Array(AParcel* parcel, const uint32_t* arrayD /** * Writes an array of int64_t to the next location in a non-null parcel. * + * Available since API level 29. + * * \param parcel the parcel to write to. * \param arrayData an array of size 'length' (or null if length is -1, may be null if length is 0). * \param length the length of arrayData or -1 if this represents a null array. @@ -794,6 +867,8 @@ binder_status_t AParcel_writeInt64Array(AParcel* parcel, const int64_t* arrayDat /** * Writes an array of uint64_t to the next location in a non-null parcel. * + * Available since API level 29. + * * \param parcel the parcel to write to. * \param arrayData an array of size 'length' (or null if length is -1, may be null if length is 0). * \param length the length of arrayData or -1 if this represents a null array. @@ -806,6 +881,8 @@ binder_status_t AParcel_writeUint64Array(AParcel* parcel, const uint64_t* arrayD /** * Writes an array of float to the next location in a non-null parcel. * + * Available since API level 29. + * * \param parcel the parcel to write to. * \param arrayData an array of size 'length' (or null if length is -1, may be null if length is 0). * \param length the length of arrayData or -1 if this represents a null array. @@ -818,6 +895,8 @@ binder_status_t AParcel_writeFloatArray(AParcel* parcel, const float* arrayData, /** * Writes an array of double to the next location in a non-null parcel. * + * Available since API level 29. + * * \param parcel the parcel to write to. * \param arrayData an array of size 'length' (or null if length is -1, may be null if length is 0). * \param length the length of arrayData or -1 if this represents a null array. @@ -833,6 +912,8 @@ binder_status_t AParcel_writeDoubleArray(AParcel* parcel, const double* arrayDat * getter(arrayData, i) will be called for each i in [0, length) in order to get the underlying * values to write to the parcel. * + * Available since API level 29. + * * \param parcel the parcel to write to. * \param arrayData some external representation of an array. * \param length the length of arrayData (or -1 if this represents a null array). @@ -846,6 +927,8 @@ binder_status_t AParcel_writeBoolArray(AParcel* parcel, const void* arrayData, i /** * Writes an array of char16_t to the next location in a non-null parcel. * + * Available since API level 29. + * * \param parcel the parcel to write to. * \param arrayData an array of size 'length' (or null if length is -1, may be null if length is 0). * \param length the length of arrayData or -1 if this represents a null array. @@ -858,6 +941,8 @@ binder_status_t AParcel_writeCharArray(AParcel* parcel, const char16_t* arrayDat /** * Writes an array of int8_t to the next location in a non-null parcel. * + * Available since API level 29. + * * \param parcel the parcel to write to. * \param arrayData an array of size 'length' (or null if length is -1, may be null if length is 0). * \param length the length of arrayData or -1 if this represents a null array. @@ -874,6 +959,8 @@ binder_status_t AParcel_writeByteArray(AParcel* parcel, const int8_t* arrayData, * length is greater than zero, the buffer returned by the allocator will be filled with the * corresponding data * + * Available since API level 29. + * * \param parcel the parcel to read from. * \param arrayData some external representation of an array. * \param allocator the callback that will be called to allocate the array. @@ -890,6 +977,8 @@ binder_status_t AParcel_readInt32Array(const AParcel* parcel, void* arrayData, * length is greater than zero, the buffer returned by the allocator will be filled with the * corresponding data * + * Available since API level 29. + * * \param parcel the parcel to read from. * \param arrayData some external representation of an array. * \param allocator the callback that will be called to allocate the array. @@ -906,6 +995,8 @@ binder_status_t AParcel_readUint32Array(const AParcel* parcel, void* arrayData, * length is greater than zero, the buffer returned by the allocator will be filled with the * corresponding data * + * Available since API level 29. + * * \param parcel the parcel to read from. * \param arrayData some external representation of an array. * \param allocator the callback that will be called to allocate the array. @@ -922,6 +1013,8 @@ binder_status_t AParcel_readInt64Array(const AParcel* parcel, void* arrayData, * length is greater than zero, the buffer returned by the allocator will be filled with the * corresponding data * + * Available since API level 29. + * * \param parcel the parcel to read from. * \param arrayData some external representation of an array. * \param allocator the callback that will be called to allocate the array. @@ -938,6 +1031,8 @@ binder_status_t AParcel_readUint64Array(const AParcel* parcel, void* arrayData, * length is greater than zero, the buffer returned by the allocator will be filled with the * corresponding data * + * Available since API level 29. + * * \param parcel the parcel to read from. * \param arrayData some external representation of an array. * \param allocator the callback that will be called to allocate the array. @@ -954,6 +1049,8 @@ binder_status_t AParcel_readFloatArray(const AParcel* parcel, void* arrayData, * length is greater than zero, the buffer returned by the allocator will be filled with the * corresponding data * + * Available since API level 29. + * * \param parcel the parcel to read from. * \param arrayData some external representation of an array. * \param allocator the callback that will be called to allocate the array. @@ -969,6 +1066,8 @@ binder_status_t AParcel_readDoubleArray(const AParcel* parcel, void* arrayData, * First, allocator will be called with the length of the array. Then, for every i in [0, length), * setter(arrayData, i, x) will be called where x is the value at the associated index. * + * Available since API level 29. + * * \param parcel the parcel to read from. * \param arrayData some external representation of an array. * \param allocator the callback that will be called to allocate the array. @@ -988,6 +1087,8 @@ binder_status_t AParcel_readBoolArray(const AParcel* parcel, void* arrayData, * length is greater than zero, the buffer returned by the allocator will be filled with the * corresponding data * + * Available since API level 29. + * * \param parcel the parcel to read from. * \param arrayData some external representation of an array. * \param allocator the callback that will be called to allocate the array. @@ -1004,6 +1105,8 @@ binder_status_t AParcel_readCharArray(const AParcel* parcel, void* arrayData, * length is greater than zero, the buffer returned by the allocator will be filled with the * corresponding data * + * Available since API level 29. + * * \param parcel the parcel to read from. * \param arrayData some external representation of an array. * \param allocator the callback that will be called to allocate the array. @@ -1015,7 +1118,7 @@ binder_status_t AParcel_readByteArray(const AParcel* parcel, void* arrayData, // @END-PRIMITIVE-READ-WRITE -#endif //__ANDROID_API__ >= __ANDROID_API_Q__ +#endif //__ANDROID_API__ >= 29 __END_DECLS /** @} */ diff --git a/libs/binder/ndk/include_ndk/android/binder_status.h b/libs/binder/ndk/include_ndk/android/binder_status.h index 2671b9b6fc..78d70f87ba 100644 --- a/libs/binder/ndk/include_ndk/android/binder_status.h +++ b/libs/binder/ndk/include_ndk/android/binder_status.h @@ -30,7 +30,7 @@ #include __BEGIN_DECLS -#if __ANDROID_API__ >= __ANDROID_API_Q__ +#if __ANDROID_API__ >= 29 enum { STATUS_OK = 0, @@ -105,6 +105,8 @@ typedef struct AStatus AStatus; /** * New status which is considered a success. * + * Available since API level 29. + * * \return a newly constructed status object that the caller owns. */ __attribute__((warn_unused_result)) AStatus* AStatus_newOk() __INTRODUCED_IN(29); @@ -112,6 +114,8 @@ __attribute__((warn_unused_result)) AStatus* AStatus_newOk() __INTRODUCED_IN(29) /** * New status with exception code. * + * Available since API level 29. + * * \param exception the code that this status should represent. If this is EX_NONE, then this * constructs an non-error status object. * @@ -123,6 +127,8 @@ __attribute__((warn_unused_result)) AStatus* AStatus_fromExceptionCode(binder_ex /** * New status with exception code and message. * + * Available since API level 29. + * * \param exception the code that this status should represent. If this is EX_NONE, then this * constructs an non-error status object. * \param message the error message to associate with this status object. @@ -137,6 +143,8 @@ __attribute__((warn_unused_result)) AStatus* AStatus_fromExceptionCodeWithMessag * * This is considered to be EX_TRANSACTION_FAILED with extra information. * + * Available since API level 29. + * * \param serviceSpecific an implementation defined error code. * * \return a newly constructed status object that the caller owns. @@ -149,6 +157,8 @@ __attribute__((warn_unused_result)) AStatus* AStatus_fromServiceSpecificError( * * This is considered to be EX_TRANSACTION_FAILED with extra information. * + * Available since API level 29. + * * \param serviceSpecific an implementation defined error code. * \param message the error message to associate with this status object. * @@ -162,6 +172,8 @@ __attribute__((warn_unused_result)) AStatus* AStatus_fromServiceSpecificErrorWit * is returned by an API on AIBinder or AParcel, and that is to be returned from a method returning * an AStatus instance. * + * Available since API level 29. + * * \param a low-level error to associate with this status object. * * \return a newly constructed status object that the caller owns. @@ -173,6 +185,8 @@ __attribute__((warn_unused_result)) AStatus* AStatus_fromStatus(binder_status_t * Whether this object represents a successful transaction. If this function returns true, then * AStatus_getExceptionCode will return EX_NONE. * + * Available since API level 29. + * * \param status the status being queried. * * \return whether the status represents a successful transaction. For more details, see below. @@ -182,6 +196,8 @@ bool AStatus_isOk(const AStatus* status) __INTRODUCED_IN(29); /** * The exception that this status object represents. * + * Available since API level 29. + * * \param status the status being queried. * * \return the exception code that this object represents. @@ -194,6 +210,8 @@ binder_exception_t AStatus_getExceptionCode(const AStatus* status) __INTRODUCED_ * 0, the status object may still represent a different exception or status. To find out if this * transaction as a whole is okay, use AStatus_isOk instead. * + * Available since API level 29. + * * \param status the status being queried. * * \return the service-specific error code if the exception code is EX_SERVICE_SPECIFIC or 0. @@ -206,6 +224,8 @@ int32_t AStatus_getServiceSpecificError(const AStatus* status) __INTRODUCED_IN(2 * object may represent a different exception or a service specific error. To find out if this * transaction as a whole is okay, use AStatus_isOk instead. * + * Available since API level 29. + * * \param status the status being queried. * * \return the status code if the exception code is EX_TRANSACTION_FAILED or 0. @@ -218,6 +238,8 @@ binder_status_t AStatus_getStatus(const AStatus* status) __INTRODUCED_IN(29); * * The returned string has the lifetime of the status object passed into this function. * + * Available since API level 29. + * * \param status the status being queried. * * \return the message associated with this error. @@ -227,11 +249,13 @@ const char* AStatus_getMessage(const AStatus* status) __INTRODUCED_IN(29); /** * Deletes memory associated with the status instance. * + * Available since API level 29. + * * \param status the status to delete, returned from AStatus_newOk or one of the AStatus_from* APIs. */ void AStatus_delete(AStatus* status) __INTRODUCED_IN(29); -#endif //__ANDROID_API__ >= __ANDROID_API_Q__ +#endif //__ANDROID_API__ >= 29 __END_DECLS /** @} */ diff --git a/libs/nativewindow/include/android/hardware_buffer.h b/libs/nativewindow/include/android/hardware_buffer.h index da959e36d2..ae5e47ba97 100644 --- a/libs/nativewindow/include/android/hardware_buffer.h +++ b/libs/nativewindow/include/android/hardware_buffer.h @@ -342,6 +342,8 @@ typedef struct AHardwareBuffer AHardwareBuffer; * not compatible with its usage flags, the results are undefined and * may include program termination. * + * Available since API level 26. + * * \return 0 on success, or an error number of the allocation fails for * any reason. The returned buffer has a reference count of 1. */ @@ -352,18 +354,24 @@ int AHardwareBuffer_allocate(const AHardwareBuffer_Desc* desc, * * This prevents the object from being deleted until the last reference * is removed. + * + * Available since API level 26. */ void AHardwareBuffer_acquire(AHardwareBuffer* buffer) __INTRODUCED_IN(26); /** * Remove a reference that was previously acquired with * AHardwareBuffer_acquire() or AHardwareBuffer_allocate(). + * + * Available since API level 26. */ void AHardwareBuffer_release(AHardwareBuffer* buffer) __INTRODUCED_IN(26); /** * Return a description of the AHardwareBuffer in the passed * AHardwareBuffer_Desc struct. + * + * Available since API level 26. */ void AHardwareBuffer_describe(const AHardwareBuffer* buffer, AHardwareBuffer_Desc* outDesc) __INTRODUCED_IN(26); @@ -413,6 +421,8 @@ void AHardwareBuffer_describe(const AHardwareBuffer* buffer, * simultaneously, and the contents of the buffer behave like shared * memory. * + * Available since API level 26. + * * \return 0 on success. -EINVAL if \a buffer is NULL, the usage flags * are not a combination of AHARDWAREBUFFER_USAGE_CPU_*, or the buffer * has more than one layer. Error number if the lock fails for any other @@ -441,6 +451,8 @@ int AHardwareBuffer_lock(AHardwareBuffer* buffer, uint64_t usage, * * See the AHardwareBuffer_lock documentation for all other locking semantics. * + * Available since API level 29. + * * \return 0 on success. -EINVAL if \a buffer is NULL, the usage flags * are not a combination of AHARDWAREBUFFER_USAGE_CPU_*, or the buffer * has more than one layer. Error number if the lock fails for any other @@ -462,6 +474,8 @@ int AHardwareBuffer_lockPlanes(AHardwareBuffer* buffer, uint64_t usage, * completed before the function returned and no further operations are * necessary. * + * Available since API level 26. + * * \return 0 on success. -EINVAL if \a buffer is NULL. Error number if * the unlock fails for any reason. */ @@ -470,6 +484,8 @@ int AHardwareBuffer_unlock(AHardwareBuffer* buffer, int32_t* fence) __INTRODUCED /** * Send the AHardwareBuffer to an AF_UNIX socket. * + * Available since API level 26. + * * \return 0 on success, -EINVAL if \a buffer is NULL, or an error * number if the operation fails for any reason. */ @@ -478,6 +494,8 @@ int AHardwareBuffer_sendHandleToUnixSocket(const AHardwareBuffer* buffer, int so /** * Receive an AHardwareBuffer from an AF_UNIX socket. * + * Available since API level 26. + * * \return 0 on success, -EINVAL if \a outBuffer is NULL, or an error * number if the operation fails for any reason. */ @@ -501,6 +519,8 @@ int AHardwareBuffer_recvHandleFromUnixSocket(int socketFd, AHardwareBuffer** out * some implementations have implementation-defined limits on texture * size and layer count. * + * Available since API level 29. + * * \return 1 if the format and usage flag combination is allocatable, * 0 otherwise. */ @@ -514,6 +534,8 @@ int AHardwareBuffer_isSupported(const AHardwareBuffer_Desc* desc) __INTRODUCED_I * of the locked buffer. If the bytes per pixel or bytes per stride are unknown * or variable, or if the underlying mapper implementation does not support returning * additional information, then this call will fail with INVALID_OPERATION + * + * Available since API level 29. */ int AHardwareBuffer_lockAndGetInfo(AHardwareBuffer* buffer, uint64_t usage, int32_t fence, const ARect* rect, void** outVirtualAddress, diff --git a/libs/nativewindow/include/android/native_window.h b/libs/nativewindow/include/android/native_window.h index 6730596ec7..3e436e3b07 100644 --- a/libs/nativewindow/include/android/native_window.h +++ b/libs/nativewindow/include/android/native_window.h @@ -189,6 +189,8 @@ int32_t ANativeWindow_unlockAndPost(ANativeWindow* window); /** * Set a transform that will be applied to future buffers posted to the window. * + * Available since API level 26. + * * \param transform combination of {@link ANativeWindowTransform} flags * \return 0 for success, or -EINVAL if \p transform is invalid */ @@ -208,6 +210,8 @@ int32_t ANativeWindow_setBuffersTransform(ANativeWindow* window, int32_t transfo * measurement data instead of color images. The default dataSpace is 0, * ADATASPACE_UNKNOWN, unless it has been overridden by the producer. * + * Available since API level 28. + * * \param dataSpace data space of all buffers queued after this call. * \return 0 for success, -EINVAL if window is invalid or the dataspace is not * supported. @@ -216,6 +220,9 @@ int32_t ANativeWindow_setBuffersDataSpace(ANativeWindow* window, int32_t dataSpa /** * Get the dataspace of the buffers in window. + * + * Available since API level 28. + * * \return the dataspace of buffers in window, ADATASPACE_UNKNOWN is returned if * dataspace is unknown, or -EINVAL if window is invalid. */ -- cgit v1.2.3-59-g8ed1b From cc4452292052758a6f2df841b80d9059ba164ec5 Mon Sep 17 00:00:00 2001 From: Alec Mouri Date: Tue, 22 Oct 2019 10:19:17 -0700 Subject: [AChoreographer] Split source files out from libandroid. This change is prework for allowing HWUI to depend on AChoreographer so that the dependency on DisplayEventReceiver is decoupled. AChoreographer needs to be split out from libandroid, as libandroid transitively depends on libhwui causing a circular dependency otherwise. Bug: 136262896 Test: builds Change-Id: Id60f9801cd82314065d82462e2a4286a3cb91e98 --- include/android/choreographer.h | 109 ---------- libs/nativedisplay/AChoreographer.cpp | 225 +++++++++++++++++++++ libs/nativedisplay/Android.bp | 10 + libs/nativedisplay/MODULE_LICENSE_APACHE2 | 0 libs/nativedisplay/NOTICE | 190 +++++++++++++++++ libs/nativedisplay/include/android/choreographer.h | 109 ++++++++++ libs/nativedisplay/libnativedisplay.map.txt | 10 + 7 files changed, 544 insertions(+), 109 deletions(-) delete mode 100644 include/android/choreographer.h create mode 100644 libs/nativedisplay/AChoreographer.cpp create mode 100644 libs/nativedisplay/MODULE_LICENSE_APACHE2 create mode 100644 libs/nativedisplay/NOTICE create mode 100644 libs/nativedisplay/include/android/choreographer.h create mode 100644 libs/nativedisplay/libnativedisplay.map.txt (limited to 'include/android') diff --git a/include/android/choreographer.h b/include/android/choreographer.h deleted file mode 100644 index 0d97e8c066..0000000000 --- a/include/android/choreographer.h +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (C) 2015 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 Choreographer - * @{ - */ - -/** - * @file choreographer.h - */ - -#ifndef ANDROID_CHOREOGRAPHER_H -#define ANDROID_CHOREOGRAPHER_H - -#include -#include - -__BEGIN_DECLS - -struct AChoreographer; -typedef struct AChoreographer AChoreographer; - -/** - * Prototype of the function that is called when a new frame is being rendered. - * It's passed the time that the frame is being rendered as nanoseconds in the - * CLOCK_MONOTONIC time base, as well as the data pointer provided by the - * application that registered a callback. All callbacks that run as part of - * rendering a frame will observe the same frame time, so it should be used - * whenever events need to be synchronized (e.g. animations). - */ -typedef void (*AChoreographer_frameCallback)(long frameTimeNanos, void* data); - -/** - * Prototype of the function that is called when a new frame is being rendered. - * It's passed the time that the frame is being rendered as nanoseconds in the - * CLOCK_MONOTONIC time base, as well as the data pointer provided by the - * application that registered a callback. All callbacks that run as part of - * rendering a frame will observe the same frame time, so it should be used - * whenever events need to be synchronized (e.g. animations). - */ -typedef void (*AChoreographer_frameCallback64)(int64_t frameTimeNanos, void* data); - -#if __ANDROID_API__ >= 24 - -/** - * Get the AChoreographer instance for the current thread. This must be called - * on an ALooper thread. - * - * Available since API level 24. - */ -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); - -/** - * Deprecated: Use AChoreographer_postFrameCallbackDelayed64 instead. - */ -void AChoreographer_postFrameCallbackDelayed(AChoreographer* choreographer, - AChoreographer_frameCallback callback, void* data, - long delayMillis) __INTRODUCED_IN(24) __DEPRECATED_IN(29); - -#endif /* __ANDROID_API__ >= 24 */ - -#if __ANDROID_API__ >= 29 - -/** - * Power a callback to be run on the next frame. The data pointer provided will - * be passed to the callback function when it's called. - * - * Available since API level 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 - * data pointer provided will be passed to the callback function when it's - * called. - * - * Available since API level 29. - */ -void AChoreographer_postFrameCallbackDelayed64(AChoreographer* choreographer, - AChoreographer_frameCallback64 callback, void* data, uint32_t delayMillis) __INTRODUCED_IN(29); - -#endif /* __ANDROID_API__ >= 29 */ - -__END_DECLS - -#endif // ANDROID_CHOREOGRAPHER_H - -/** @} */ diff --git a/libs/nativedisplay/AChoreographer.cpp b/libs/nativedisplay/AChoreographer.cpp new file mode 100644 index 0000000000..63e073405f --- /dev/null +++ b/libs/nativedisplay/AChoreographer.cpp @@ -0,0 +1,225 @@ +/* + * Copyright (C) 2015 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. + */ + +#define LOG_TAG "Choreographer" +//#define LOG_NDEBUG 0 + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +namespace android { + +static inline const char* toString(bool value) { + return value ? "true" : "false"; +} + +struct FrameCallback { + AChoreographer_frameCallback callback; + AChoreographer_frameCallback64 callback64; + void* data; + nsecs_t dueTime; + + inline bool operator<(const FrameCallback& rhs) const { + // Note that this is intentionally flipped because we want callbacks due sooner to be at + // the head of the queue + return dueTime > rhs.dueTime; + } +}; + + +class Choreographer : public DisplayEventDispatcher, public MessageHandler { +public: + void postFrameCallbackDelayed(AChoreographer_frameCallback cb, + AChoreographer_frameCallback64 cb64, void* data, nsecs_t delay); + + enum { + MSG_SCHEDULE_CALLBACKS = 0, + MSG_SCHEDULE_VSYNC = 1 + }; + virtual void handleMessage(const Message& message) override; + + static Choreographer* getForThread(); + +protected: + virtual ~Choreographer() = default; + +private: + explicit Choreographer(const sp& looper); + Choreographer(const Choreographer&) = delete; + + void dispatchVsync(nsecs_t timestamp, PhysicalDisplayId displayId, uint32_t count) override; + void dispatchHotplug(nsecs_t timestamp, PhysicalDisplayId displayId, bool connected) override; + void dispatchConfigChanged(nsecs_t timestamp, PhysicalDisplayId displayId, + int32_t configId) override; + + void scheduleCallbacks(); + + // Protected by mLock + std::priority_queue mCallbacks; + + mutable Mutex mLock; + + const sp mLooper; + const std::thread::id mThreadId; +}; + + +static thread_local Choreographer* gChoreographer; +Choreographer* Choreographer::getForThread() { + if (gChoreographer == nullptr) { + sp looper = Looper::getForThread(); + if (!looper.get()) { + ALOGW("No looper prepared for thread"); + return nullptr; + } + gChoreographer = new Choreographer(looper); + status_t result = gChoreographer->initialize(); + if (result != OK) { + ALOGW("Failed to initialize"); + return nullptr; + } + } + return gChoreographer; +} + +Choreographer::Choreographer(const sp& looper) : + DisplayEventDispatcher(looper), mLooper(looper), mThreadId(std::this_thread::get_id()) { +} + +void Choreographer::postFrameCallbackDelayed( + AChoreographer_frameCallback cb, AChoreographer_frameCallback64 cb64, void* data, nsecs_t delay) { + nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC); + FrameCallback callback{cb, cb64, data, now + delay}; + { + AutoMutex _l{mLock}; + mCallbacks.push(callback); + } + if (callback.dueTime <= now) { + if (std::this_thread::get_id() != mThreadId) { + Message m{MSG_SCHEDULE_VSYNC}; + mLooper->sendMessage(this, m); + } else { + scheduleVsync(); + } + } else { + Message m{MSG_SCHEDULE_CALLBACKS}; + mLooper->sendMessageDelayed(delay, this, m); + } +} + +void Choreographer::scheduleCallbacks() { + AutoMutex _{mLock}; + nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC); + if (mCallbacks.top().dueTime <= now) { + ALOGV("choreographer %p ~ scheduling vsync", this); + scheduleVsync(); + return; + } +} + +// TODO(b/74619554): The PhysicalDisplayId is ignored because SF only emits VSYNC events for the +// internal display and DisplayEventReceiver::requestNextVsync only allows requesting VSYNC for +// the internal display implicitly. +void Choreographer::dispatchVsync(nsecs_t timestamp, PhysicalDisplayId, uint32_t) { + std::vector callbacks{}; + { + AutoMutex _l{mLock}; + nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC); + while (!mCallbacks.empty() && mCallbacks.top().dueTime < now) { + callbacks.push_back(mCallbacks.top()); + mCallbacks.pop(); + } + } + for (const auto& cb : callbacks) { + if (cb.callback64 != nullptr) { + cb.callback64(timestamp, cb.data); + } else if (cb.callback != nullptr) { + cb.callback(timestamp, cb.data); + } + } +} + +void Choreographer::dispatchHotplug(nsecs_t, PhysicalDisplayId displayId, bool connected) { + ALOGV("choreographer %p ~ received hotplug event (displayId=%" + ANDROID_PHYSICAL_DISPLAY_ID_FORMAT ", connected=%s), ignoring.", + this, displayId, toString(connected)); +} + +void Choreographer::dispatchConfigChanged(nsecs_t, PhysicalDisplayId displayId, + int32_t configId) { + ALOGV("choreographer %p ~ received config changed event (displayId=%" + ANDROID_PHYSICAL_DISPLAY_ID_FORMAT ", configId=%s), ignoring.", + this, displayId, toString(configId)); +} + +void Choreographer::handleMessage(const Message& message) { + switch (message.what) { + case MSG_SCHEDULE_CALLBACKS: + scheduleCallbacks(); + break; + case MSG_SCHEDULE_VSYNC: + scheduleVsync(); + break; + } +} + +} + +/* Glue for the NDK interface */ + +using android::Choreographer; + +static inline Choreographer* AChoreographer_to_Choreographer(AChoreographer* choreographer) { + return reinterpret_cast(choreographer); +} + +static inline AChoreographer* Choreographer_to_AChoreographer(Choreographer* choreographer) { + return reinterpret_cast(choreographer); +} + +AChoreographer* AChoreographer_getInstance() { + return Choreographer_to_AChoreographer(Choreographer::getForThread()); +} + +void AChoreographer_postFrameCallback(AChoreographer* choreographer, + AChoreographer_frameCallback callback, void* data) { + AChoreographer_to_Choreographer(choreographer)->postFrameCallbackDelayed( + callback, nullptr, data, 0); +} +void AChoreographer_postFrameCallbackDelayed(AChoreographer* choreographer, + AChoreographer_frameCallback callback, void* data, long delayMillis) { + AChoreographer_to_Choreographer(choreographer)->postFrameCallbackDelayed( + callback, nullptr, data, ms2ns(delayMillis)); +} +void AChoreographer_postFrameCallback64(AChoreographer* choreographer, + AChoreographer_frameCallback64 callback, void* data) { + AChoreographer_to_Choreographer(choreographer)->postFrameCallbackDelayed( + nullptr, callback, data, 0); +} +void AChoreographer_postFrameCallbackDelayed64(AChoreographer* choreographer, + AChoreographer_frameCallback64 callback, void* data, uint32_t delayMillis) { + AChoreographer_to_Choreographer(choreographer)->postFrameCallbackDelayed( + nullptr, callback, data, ms2ns(delayMillis)); +} diff --git a/libs/nativedisplay/Android.bp b/libs/nativedisplay/Android.bp index 66ebdfd6f8..45b935ac08 100644 --- a/libs/nativedisplay/Android.bp +++ b/libs/nativedisplay/Android.bp @@ -12,6 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. +ndk_headers { + name: "libachoreographer_ndk_headers", + from: "include/android", + to: "android", + srcs: ["include/android/*.h"], + license: "NOTICE", +} + cc_library_headers { name: "libnativedisplay_headers", export_include_dirs: ["include"], @@ -33,10 +41,12 @@ cc_library { ], srcs: [ + "AChoreographer.cpp", "ADisplay.cpp", ], shared_libs: [ + "libandroidfw", "libgui", "liblog", "libui", diff --git a/libs/nativedisplay/MODULE_LICENSE_APACHE2 b/libs/nativedisplay/MODULE_LICENSE_APACHE2 new file mode 100644 index 0000000000..e69de29bb2 diff --git a/libs/nativedisplay/NOTICE b/libs/nativedisplay/NOTICE new file mode 100644 index 0000000000..c5b1efa7aa --- /dev/null +++ b/libs/nativedisplay/NOTICE @@ -0,0 +1,190 @@ + + Copyright (c) 2005-2008, 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. + + 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. + + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + diff --git a/libs/nativedisplay/include/android/choreographer.h b/libs/nativedisplay/include/android/choreographer.h new file mode 100644 index 0000000000..0d97e8c066 --- /dev/null +++ b/libs/nativedisplay/include/android/choreographer.h @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2015 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 Choreographer + * @{ + */ + +/** + * @file choreographer.h + */ + +#ifndef ANDROID_CHOREOGRAPHER_H +#define ANDROID_CHOREOGRAPHER_H + +#include +#include + +__BEGIN_DECLS + +struct AChoreographer; +typedef struct AChoreographer AChoreographer; + +/** + * Prototype of the function that is called when a new frame is being rendered. + * It's passed the time that the frame is being rendered as nanoseconds in the + * CLOCK_MONOTONIC time base, as well as the data pointer provided by the + * application that registered a callback. All callbacks that run as part of + * rendering a frame will observe the same frame time, so it should be used + * whenever events need to be synchronized (e.g. animations). + */ +typedef void (*AChoreographer_frameCallback)(long frameTimeNanos, void* data); + +/** + * Prototype of the function that is called when a new frame is being rendered. + * It's passed the time that the frame is being rendered as nanoseconds in the + * CLOCK_MONOTONIC time base, as well as the data pointer provided by the + * application that registered a callback. All callbacks that run as part of + * rendering a frame will observe the same frame time, so it should be used + * whenever events need to be synchronized (e.g. animations). + */ +typedef void (*AChoreographer_frameCallback64)(int64_t frameTimeNanos, void* data); + +#if __ANDROID_API__ >= 24 + +/** + * Get the AChoreographer instance for the current thread. This must be called + * on an ALooper thread. + * + * Available since API level 24. + */ +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); + +/** + * Deprecated: Use AChoreographer_postFrameCallbackDelayed64 instead. + */ +void AChoreographer_postFrameCallbackDelayed(AChoreographer* choreographer, + AChoreographer_frameCallback callback, void* data, + long delayMillis) __INTRODUCED_IN(24) __DEPRECATED_IN(29); + +#endif /* __ANDROID_API__ >= 24 */ + +#if __ANDROID_API__ >= 29 + +/** + * Power a callback to be run on the next frame. The data pointer provided will + * be passed to the callback function when it's called. + * + * Available since API level 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 + * data pointer provided will be passed to the callback function when it's + * called. + * + * Available since API level 29. + */ +void AChoreographer_postFrameCallbackDelayed64(AChoreographer* choreographer, + AChoreographer_frameCallback64 callback, void* data, uint32_t delayMillis) __INTRODUCED_IN(29); + +#endif /* __ANDROID_API__ >= 29 */ + +__END_DECLS + +#endif // ANDROID_CHOREOGRAPHER_H + +/** @} */ diff --git a/libs/nativedisplay/libnativedisplay.map.txt b/libs/nativedisplay/libnativedisplay.map.txt new file mode 100644 index 0000000000..3b29c18fc3 --- /dev/null +++ b/libs/nativedisplay/libnativedisplay.map.txt @@ -0,0 +1,10 @@ +LIBNATIVEDISPLAY { + global: + AChoreographer_getInstance; # apex # introduced=30 + AChoreographer_postFrameCallback; # apex # introduced=30 + AChoreographer_postFrameCallbackDelayed; # apex # introduced=30 + AChoreographer_postFrameCallback64; # apex # introduced=30 + AChoreographer_postFrameCallbackDelayed64; # apex # introduced=30 + local: + *; +}; -- cgit v1.2.3-59-g8ed1b From 7feb2eaf82d88bd4d903f43776860015806274ce Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Mon, 25 Nov 2019 15:11:23 -0800 Subject: Add FocusEvent and InputMessage::Type::FOCUS FocusEvents will be consumed by InputConsumer on the app side. They will be used to notify app that focus has been gained / lost. They will also carry information about the current state of touch mode. Also add a new type of InputMessage with type FOCUS. This new data structure will be used to pass focus events to the apps from input across the socket. Bug: 70668286 Test: presubmit Change-Id: I88582c64ee41ecb49623b9b7f5c149eafa694788 --- include/android/input.h | 5 +- include/input/Input.h | 29 ++++++++++ include/input/InputTransport.h | 34 ++++++++--- libs/input/Input.cpp | 45 +++++++++++++++ libs/input/InputTransport.cpp | 67 +++++++++++++++++----- .../input/tests/InputPublisherAndConsumer_test.cpp | 43 ++++++++++++++ libs/input/tests/StructLayout_test.cpp | 5 ++ .../inputflinger/dispatcher/InputDispatcher.cpp | 2 +- .../inputflinger/tests/InputDispatcher_test.cpp | 4 +- 9 files changed, 209 insertions(+), 25 deletions(-) (limited to 'include/android') diff --git a/include/android/input.h b/include/android/input.h index ce439c6d75..f51cd79504 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, }; /** diff --git a/include/input/Input.h b/include/input/Input.h index a7e706ed18..f8718479f9 100644 --- a/include/input/Input.h +++ b/include/input/Input.h @@ -167,6 +167,8 @@ namespace android { class Parcel; #endif +const char* inputEventTypeToString(int32_t type); + /* * Flags that flow alongside events in the input dispatch system to help with certain * policy decisions such as waking from device sleep. @@ -686,6 +688,28 @@ protected: Vector mSamplePointerCoords; }; +/* + * Focus events. + */ +class FocusEvent : public InputEvent { +public: + virtual ~FocusEvent() {} + + virtual int32_t getType() const override { return AINPUT_EVENT_TYPE_FOCUS; } + + inline bool getHasFocus() const { return mHasFocus; } + + inline bool getInTouchMode() const { return mInTouchMode; } + + void initialize(bool hasFocus, bool inTouchMode); + + void initialize(const FocusEvent& from); + +protected: + bool mHasFocus; + bool mInTouchMode; +}; + /* * Input event factory. */ @@ -698,6 +722,7 @@ public: virtual KeyEvent* createKeyEvent() = 0; virtual MotionEvent* createMotionEvent() = 0; + virtual FocusEvent* createFocusEvent() = 0; }; /* @@ -711,10 +736,12 @@ public: virtual KeyEvent* createKeyEvent() override { return &mKeyEvent; } virtual MotionEvent* createMotionEvent() override { return &mMotionEvent; } + virtual FocusEvent* createFocusEvent() override { return &mFocusEvent; } private: KeyEvent mKeyEvent; MotionEvent mMotionEvent; + FocusEvent mFocusEvent; }; /* @@ -727,6 +754,7 @@ public: virtual KeyEvent* createKeyEvent() override; virtual MotionEvent* createMotionEvent() override; + virtual FocusEvent* createFocusEvent() override; void recycle(InputEvent* event); @@ -735,6 +763,7 @@ private: std::queue> mKeyEventPool; std::queue> mMotionEventPool; + std::queue> mFocusEventPool; }; } // namespace android diff --git a/include/input/InputTransport.h b/include/input/InputTransport.h index d39ee250a5..ae47438ac8 100644 --- a/include/input/InputTransport.h +++ b/include/input/InputTransport.h @@ -64,6 +64,7 @@ struct InputMessage { KEY, MOTION, FINISHED, + FOCUS, }; struct Header { @@ -92,9 +93,7 @@ struct InputMessage { uint32_t empty2; nsecs_t downTime __attribute__((aligned(8))); - inline size_t size() const { - return sizeof(Key); - } + inline size_t size() const { return sizeof(Key); } } key; struct Motion { @@ -110,7 +109,7 @@ struct InputMessage { int32_t metaState; int32_t buttonState; MotionClassification classification; // base type: uint8_t - uint8_t empty2[3]; + uint8_t empty2[3]; // 3 bytes to fill gap created by classification int32_t edgeFlags; nsecs_t downTime __attribute__((aligned(8))); float xOffset; @@ -148,10 +147,17 @@ struct InputMessage { uint32_t seq; uint32_t handled; // actually a bool, but we must maintain 8-byte alignment - inline size_t size() const { - return sizeof(Finished); - } + inline size_t size() const { return sizeof(Finished); } } finished; + + struct Focus { + uint32_t seq; + // The following two fields take up 4 bytes total + uint16_t hasFocus; // actually a bool + uint16_t inTouchMode; // actually a bool, but we must maintain 8-byte alignment + + inline size_t size() const { return sizeof(Focus); } + } focus; } __attribute__((aligned(8))) body; bool isValid(size_t actualSize) const; @@ -294,6 +300,15 @@ public: uint32_t pointerCount, const PointerProperties* pointerProperties, const PointerCoords* pointerCoords); + /* Publishes a focus event to the input channel. + * + * Returns OK on success. + * Returns WOULD_BLOCK if the channel is full. + * Returns DEAD_OBJECT if the channel's peer has been closed. + * Other errors probably indicate that the channel is broken. + */ + status_t publishFocusEvent(uint32_t seq, bool hasFocus, bool inTouchMode); + /* Receives the finished signal from the consumer in reply to the original dispatch signal. * If a signal was received, returns the message sequence number, * and whether the consumer handled the message. @@ -349,8 +364,8 @@ public: * Returns NO_MEMORY if the event could not be created. * Other errors probably indicate that the channel is broken. */ - status_t consume(InputEventFactoryInterface* factory, bool consumeBatches, - nsecs_t frameTime, uint32_t* outSeq, InputEvent** outEvent); + status_t consume(InputEventFactoryInterface* factory, bool consumeBatches, nsecs_t frameTime, + uint32_t* outSeq, InputEvent** outEvent); /* Sends a finished signal to the publisher to inform it that the message * with the specified sequence number has finished being process and whether @@ -521,6 +536,7 @@ private: static void rewriteMessage(TouchState& state, InputMessage& msg); static void initializeKeyEvent(KeyEvent* event, const InputMessage* msg); static void initializeMotionEvent(MotionEvent* event, const InputMessage* msg); + static void initializeFocusEvent(FocusEvent* event, const InputMessage* msg); static void addSample(MotionEvent* event, const InputMessage* msg); static bool canAddSample(const Batch& batch, const InputMessage* msg); static ssize_t findSampleNoLaterThan(const Batch& batch, nsecs_t time); diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp index c7303efd13..8ccbc7f650 100644 --- a/libs/input/Input.cpp +++ b/libs/input/Input.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #ifdef __ANDROID__ @@ -41,6 +42,21 @@ const char* motionClassificationToString(MotionClassification classification) { // --- InputEvent --- +const char* inputEventTypeToString(int32_t type) { + switch (type) { + case AINPUT_EVENT_TYPE_KEY: { + return "KEY"; + } + case AINPUT_EVENT_TYPE_MOTION: { + return "MOTION"; + } + case AINPUT_EVENT_TYPE_FOCUS: { + return "FOCUS"; + } + } + return "UNKNOWN"; +} + void InputEvent::initialize(int32_t deviceId, int32_t source, int32_t displayId) { mDeviceId = deviceId; mSource = source; @@ -587,6 +603,20 @@ int32_t MotionEvent::getAxisFromLabel(const char* label) { return getAxisByLabel(label); } +// --- FocusEvent --- + +void FocusEvent::initialize(bool hasFocus, bool inTouchMode) { + InputEvent::initialize(ReservedInputDeviceId::VIRTUAL_KEYBOARD_ID, AINPUT_SOURCE_UNKNOWN, + ADISPLAY_ID_NONE); + mHasFocus = hasFocus; + mInTouchMode = inTouchMode; +} + +void FocusEvent::initialize(const FocusEvent& from) { + InputEvent::initialize(from); + mHasFocus = from.mHasFocus; + mInTouchMode = from.mInTouchMode; +} // --- PooledInputEventFactory --- @@ -615,6 +645,15 @@ MotionEvent* PooledInputEventFactory::createMotionEvent() { return event; } +FocusEvent* PooledInputEventFactory::createFocusEvent() { + if (mFocusEventPool.empty()) { + return new FocusEvent(); + } + FocusEvent* event = mFocusEventPool.front().release(); + mFocusEventPool.pop(); + return event; +} + void PooledInputEventFactory::recycle(InputEvent* event) { switch (event->getType()) { case AINPUT_EVENT_TYPE_KEY: @@ -629,6 +668,12 @@ void PooledInputEventFactory::recycle(InputEvent* event) { return; } break; + case AINPUT_EVENT_TYPE_FOCUS: + if (mFocusEventPool.size() < mMaxPoolSize) { + mFocusEventPool.push(std::unique_ptr(static_cast(event))); + return; + } + break; } delete event; } diff --git a/libs/input/InputTransport.cpp b/libs/input/InputTransport.cpp index b7937dc95e..200e1f39d9 100644 --- a/libs/input/InputTransport.cpp +++ b/libs/input/InputTransport.cpp @@ -103,6 +103,8 @@ bool InputMessage::isValid(size_t actualSize) const { return body.motion.pointerCount > 0 && body.motion.pointerCount <= MAX_POINTERS; case Type::FINISHED: return true; + case Type::FOCUS: + return true; } } return false; @@ -116,6 +118,8 @@ size_t InputMessage::size() const { return sizeof(Header) + body.motion.size(); case Type::FINISHED: return sizeof(Header) + body.finished.size(); + case Type::FOCUS: + return sizeof(Header) + body.focus.size(); } return sizeof(Header); } @@ -220,6 +224,12 @@ void InputMessage::getSanitizedCopy(InputMessage* msg) const { msg->body.finished.handled = body.finished.handled; break; } + case InputMessage::Type::FOCUS: { + msg->body.focus.seq = body.focus.seq; + msg->body.focus.hasFocus = body.focus.hasFocus; + msg->body.focus.inTouchMode = body.focus.inTouchMode; + break; + } } } @@ -529,6 +539,23 @@ status_t InputPublisher::publishMotionEvent( return mChannel->sendMessage(&msg); } +status_t InputPublisher::publishFocusEvent(uint32_t seq, bool hasFocus, bool inTouchMode) { + if (ATRACE_ENABLED()) { + std::string message = + StringPrintf("publishFocusEvent(inputChannel=%s, hasFocus=%s, inTouchMode=%s)", + mChannel->getName().c_str(), toString(hasFocus), + toString(inTouchMode)); + ATRACE_NAME(message.c_str()); + } + + InputMessage msg; + msg.header.type = InputMessage::Type::FOCUS; + msg.body.focus.seq = seq; + msg.body.focus.hasFocus = hasFocus ? 1 : 0; + msg.body.focus.inTouchMode = inTouchMode ? 1 : 0; + return mChannel->sendMessage(&msg); +} + status_t InputPublisher::receiveFinishedSignal(uint32_t* outSeq, bool* outHandled) { if (DEBUG_TRANSPORT_ACTIONS) { ALOGD("channel '%s' publisher ~ receiveFinishedSignal", mChannel->getName().c_str()); @@ -565,8 +592,8 @@ bool InputConsumer::isTouchResamplingEnabled() { return property_get_bool(PROPERTY_RESAMPLING_ENABLED, true); } -status_t InputConsumer::consume(InputEventFactoryInterface* factory, - bool consumeBatches, nsecs_t frameTime, uint32_t* outSeq, InputEvent** outEvent) { +status_t InputConsumer::consume(InputEventFactoryInterface* factory, bool consumeBatches, + nsecs_t frameTime, uint32_t* outSeq, InputEvent** outEvent) { if (DEBUG_TRANSPORT_ACTIONS) { ALOGD("channel '%s' consumer ~ consume: consumeBatches=%s, frameTime=%" PRId64, mChannel->getName().c_str(), toString(consumeBatches), frameTime); @@ -669,19 +696,19 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory, break; } - MotionEvent* motionEvent = factory->createMotionEvent(); - if (! motionEvent) return NO_MEMORY; + MotionEvent* motionEvent = factory->createMotionEvent(); + if (!motionEvent) return NO_MEMORY; - updateTouchState(mMsg); - initializeMotionEvent(motionEvent, &mMsg); - *outSeq = mMsg.body.motion.seq; - *outEvent = motionEvent; + updateTouchState(mMsg); + initializeMotionEvent(motionEvent, &mMsg); + *outSeq = mMsg.body.motion.seq; + *outEvent = motionEvent; - if (DEBUG_TRANSPORT_ACTIONS) { - ALOGD("channel '%s' consumer ~ consumed motion event, seq=%u", - mChannel->getName().c_str(), *outSeq); - } - break; + if (DEBUG_TRANSPORT_ACTIONS) { + ALOGD("channel '%s' consumer ~ consumed motion event, seq=%u", + mChannel->getName().c_str(), *outSeq); + } + break; } case InputMessage::Type::FINISHED: { @@ -689,6 +716,16 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory, "InputConsumer!"); break; } + + case InputMessage::Type::FOCUS: { + FocusEvent* focusEvent = factory->createFocusEvent(); + if (!focusEvent) return NO_MEMORY; + + initializeFocusEvent(focusEvent, &mMsg); + *outSeq = mMsg.body.focus.seq; + *outEvent = focusEvent; + break; + } } } return OK; @@ -1113,6 +1150,10 @@ void InputConsumer::initializeKeyEvent(KeyEvent* event, const InputMessage* msg) msg->body.key.eventTime); } +void InputConsumer::initializeFocusEvent(FocusEvent* event, const InputMessage* msg) { + event->initialize(msg->body.focus.hasFocus == 1, msg->body.focus.inTouchMode == 1); +} + void InputConsumer::initializeMotionEvent(MotionEvent* event, const InputMessage* msg) { uint32_t pointerCount = msg->body.motion.pointerCount; PointerProperties pointerProperties[pointerCount]; diff --git a/libs/input/tests/InputPublisherAndConsumer_test.cpp b/libs/input/tests/InputPublisherAndConsumer_test.cpp index a362f3281d..2fc77e97a0 100644 --- a/libs/input/tests/InputPublisherAndConsumer_test.cpp +++ b/libs/input/tests/InputPublisherAndConsumer_test.cpp @@ -60,6 +60,7 @@ protected: void PublishAndConsumeKeyEvent(); void PublishAndConsumeMotionEvent(); + void PublishAndConsumeFocusEvent(); }; TEST_F(InputPublisherAndConsumerTest, GetChannel_ReturnsTheChannel) { @@ -256,6 +257,43 @@ void InputPublisherAndConsumerTest::PublishAndConsumeMotionEvent() { << "publisher receiveFinishedSignal should have set handled to consumer's reply"; } +void InputPublisherAndConsumerTest::PublishAndConsumeFocusEvent() { + status_t status; + + constexpr uint32_t seq = 15; + constexpr bool hasFocus = true; + constexpr bool inTouchMode = true; + + status = mPublisher->publishFocusEvent(seq, hasFocus, inTouchMode); + ASSERT_EQ(OK, status) << "publisher publishKeyEvent should return OK"; + + uint32_t consumeSeq; + InputEvent* event; + status = mConsumer->consume(&mEventFactory, true /*consumeBatches*/, -1, &consumeSeq, &event); + ASSERT_EQ(OK, status) << "consumer consume should return OK"; + + ASSERT_TRUE(event != nullptr) << "consumer should have returned non-NULL event"; + ASSERT_EQ(AINPUT_EVENT_TYPE_FOCUS, event->getType()) + << "consumer should have returned a focus event"; + + FocusEvent* focusEvent = static_cast(event); + EXPECT_EQ(seq, consumeSeq); + EXPECT_EQ(hasFocus, focusEvent->getHasFocus()); + EXPECT_EQ(inTouchMode, focusEvent->getInTouchMode()); + + status = mConsumer->sendFinishedSignal(seq, true); + ASSERT_EQ(OK, status) << "consumer sendFinishedSignal should return OK"; + + uint32_t finishedSeq = 0; + bool handled = false; + status = mPublisher->receiveFinishedSignal(&finishedSeq, &handled); + ASSERT_EQ(OK, status) << "publisher receiveFinishedSignal should return OK"; + ASSERT_EQ(seq, finishedSeq) + << "publisher receiveFinishedSignal should have returned the original sequence number"; + ASSERT_TRUE(handled) + << "publisher receiveFinishedSignal should have set handled to consumer's reply"; +} + TEST_F(InputPublisherAndConsumerTest, PublishKeyEvent_EndToEnd) { ASSERT_NO_FATAL_FAILURE(PublishAndConsumeKeyEvent()); } @@ -264,6 +302,10 @@ TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_EndToEnd) { ASSERT_NO_FATAL_FAILURE(PublishAndConsumeMotionEvent()); } +TEST_F(InputPublisherAndConsumerTest, PublishFocusEvent_EndToEnd) { + ASSERT_NO_FATAL_FAILURE(PublishAndConsumeFocusEvent()); +} + TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_WhenSequenceNumberIsZero_ReturnsError) { status_t status; const size_t pointerCount = 1; @@ -322,6 +364,7 @@ TEST_F(InputPublisherAndConsumerTest, PublishMultipleEvents_EndToEnd) { ASSERT_NO_FATAL_FAILURE(PublishAndConsumeMotionEvent()); ASSERT_NO_FATAL_FAILURE(PublishAndConsumeKeyEvent()); ASSERT_NO_FATAL_FAILURE(PublishAndConsumeMotionEvent()); + ASSERT_NO_FATAL_FAILURE(PublishAndConsumeFocusEvent()); ASSERT_NO_FATAL_FAILURE(PublishAndConsumeMotionEvent()); ASSERT_NO_FATAL_FAILURE(PublishAndConsumeKeyEvent()); } diff --git a/libs/input/tests/StructLayout_test.cpp b/libs/input/tests/StructLayout_test.cpp index 0fb6cfc204..9ab0dba08d 100644 --- a/libs/input/tests/StructLayout_test.cpp +++ b/libs/input/tests/StructLayout_test.cpp @@ -69,6 +69,10 @@ void TestInputMessageAlignment() { CHECK_OFFSET(InputMessage::Body::Motion, pointerCount, 88); CHECK_OFFSET(InputMessage::Body::Motion, pointers, 96); + CHECK_OFFSET(InputMessage::Body::Focus, seq, 0); + CHECK_OFFSET(InputMessage::Body::Focus, hasFocus, 4); + CHECK_OFFSET(InputMessage::Body::Focus, inTouchMode, 6); + CHECK_OFFSET(InputMessage::Body::Finished, seq, 0); CHECK_OFFSET(InputMessage::Body::Finished, handled, 4); } @@ -87,6 +91,7 @@ void TestBodySize() { offsetof(InputMessage::Body::Motion, pointers) + sizeof(InputMessage::Body::Motion::Pointer) * MAX_POINTERS); static_assert(sizeof(InputMessage::Body::Finished) == 8); + static_assert(sizeof(InputMessage::Body::Focus) == 8); } } // namespace android diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp index 746908ba40..9c0e08e297 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.cpp +++ b/services/inputflinger/dispatcher/InputDispatcher.cpp @@ -3036,7 +3036,7 @@ int32_t InputDispatcher::injectInputEvent(const InputEvent* event, int32_t injec } default: - ALOGW("Cannot inject event of type %d", event->getType()); + ALOGW("Cannot inject %s events", inputEventTypeToString(event->getType())); return INPUT_EVENT_INJECTION_FAILED; } diff --git a/services/inputflinger/tests/InputDispatcher_test.cpp b/services/inputflinger/tests/InputDispatcher_test.cpp index ebce47f1e7..4f282611d5 100644 --- a/services/inputflinger/tests/InputDispatcher_test.cpp +++ b/services/inputflinger/tests/InputDispatcher_test.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -410,7 +411,8 @@ public: ASSERT_NE(nullptr, event) << mName.c_str() << ": consumer should have returned non-NULL event."; ASSERT_EQ(expectedEventType, event->getType()) - << mName.c_str() << ": event type should match."; + << mName.c_str() << "expected " << inputEventTypeToString(expectedEventType) + << " event, got " << inputEventTypeToString(event->getType()) << " event"; EXPECT_EQ(expectedDisplayId, event->getDisplayId()); -- cgit v1.2.3-59-g8ed1b From 06c97753112bb7a03d6e58c3774b2e44d19d7681 Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Tue, 3 Sep 2019 09:52:43 -0400 Subject: Add AndroidBitmap_getDataSpace Bug:135133301 Test: I7a5fcb726fba0c832bbb86a424d7534a7cfa35b6 This supplements AndroidBitmap_getInfo, allowing NDK clients to know how to interpret the colors in an android.graphics.Bitmap. Change-Id: Ia46dfb39d0f2708ce873343ec74bcc52e7bccd3a --- include/android/bitmap.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'include/android') diff --git a/include/android/bitmap.h b/include/android/bitmap.h index 01cf2f88ea..41718b2904 100644 --- a/include/android/bitmap.h +++ b/include/android/bitmap.h @@ -100,6 +100,19 @@ typedef struct { int AndroidBitmap_getInfo(JNIEnv* env, jobject jbitmap, AndroidBitmapInfo* info); +#if __ANDROID_API__ >= 30 + +/** + * Given a java bitmap object, return its ADataSpace. + * + * Note that ADataSpace only exposes a few values. This may return + * ADATASPACE_UNKNOWN, even for Named ColorSpaces, if they have no + * corresponding ADataSpace. + */ +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 -- cgit v1.2.3-59-g8ed1b From 2f98494d4d689a9484942435e4101114daadd91f Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Fri, 22 Nov 2019 17:02:23 -0500 Subject: Add NDK Apis for image decoding Bug: 135133301 Test: Ib84462ea5fa8a7779eaa44494775e182e52ecaca Change-Id: I8fd341c538f6b0d96f7abed77d58b003a3aefd12 --- include/android/imagedecoder.h | 299 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 299 insertions(+) create mode 100644 include/android/imagedecoder.h (limited to 'include/android') diff --git a/include/android/imagedecoder.h b/include/android/imagedecoder.h new file mode 100644 index 0000000000..50daabaaff --- /dev/null +++ b/include/android/imagedecoder.h @@ -0,0 +1,299 @@ +/* + * 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. + */ + +/** + * @addtogroup ImageDecoder + * @{ + */ + +/** + * @file imageDecoder.h + */ + +#ifndef ANDROID_IMAGE_DECODER_H +#define ANDROID_IMAGE_DECODER_H + +#include "bitmap.h" + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct AAsset; +struct ARect; + +#if __ANDROID_API__ >= 30 + +/** AImageDecoder functions result code. */ +enum { + // Decoding was successful and complete. + ANDROID_IMAGE_DECODER_SUCCESS = 0, + // The input was incomplete. In decodeImage, this means a partial + // image was decoded. Undecoded lines are all zeroes. + // In AImageDecoder_create*, no AImageDecoder was created. + ANDROID_IMAGE_DECODER_INCOMPLETE = -1, + // The input contained an error after decoding some lines. Similar to + // INCOMPLETE, above. + ANDROID_IMAGE_DECODER_ERROR = -2, + // Could not convert, e.g. 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 was bad (e.g. pixels) + ANDROID_IMAGE_DECODER_BAD_PARAMETER = -5, + // Input was invalid i.e. broken before decoding any pixels. + ANDROID_IMAGE_DECODER_INVALID_INPUT = -6, + // A seek was required, and failed. + ANDROID_IMAGE_DECODER_SEEK_ERROR = -7, + // Some other error (e.g. OOM) + ANDROID_IMAGE_DECODER_INTERNAL_ERROR = -8, + // We 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} + */ +typedef struct AImageDecoder AImageDecoder; + +/** + * Create a new AImageDecoder from an AAsset. + * + * @param asset {@link AAsset} containing encoded image data. Client is still + * responsible for calling {@link AAsset_close} on it. + * @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 reason for the failure. + */ +int AImageDecoder_createFromAAsset(AAsset* asset, AImageDecoder** outDecoder) __INTRODUCED_IN(30); + +/** + * Create a new AImageDecoder from a file descriptor. + * + * @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 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 reason for the failure. + */ +int AImageDecoder_createFromFd(int fd, AImageDecoder** outDecoder) __INTRODUCED_IN(30); + +/** + * Create a new AImageDecoder from a buffer. + * + * @param buffer Pointer to encoded data. Must be valid for the entire time + * the 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 reason for the failure. + */ +int AImageDecoder_createFromBuffer(const void* buffer, size_t length, + AImageDecoder** outDecoder) __INTRODUCED_IN(30); + +/** + * Delete the AImageDecoder. + */ +void AImageDecoder_delete(AImageDecoder* decoder) __INTRODUCED_IN(30); + +/** + * Choose the desired output format. + * + * @param format AndroidBitmapFormat to use + * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} if the format is compatible + * with the image and {@link ANDROID_IMAGE_DECODER_INVALID_CONVERSION} + * otherwise. In the latter case, the AImageDecoder uses the + * format it was already planning to use (either its default + * or a previously successful setting from this function). + */ +int AImageDecoder_setAndroidBitmapFormat(AImageDecoder*, + int32_t format) __INTRODUCED_IN(30); + +/* + * Choose the desired output format. + * + * Must be one of: + * {@link ANDROID_BITMAP_FLAGS_ALPHA_PREMUL} + * {@link ANDROID_BITMAP_FLAGS_ALPHA_OPAQUE} + * {@link ANDROID_BITMAP_FLAGS_ALPHA_UNPREMUL} + * + * Note: An OPAQUE image may be set to any of them. + * A non-OPAQUE image may not be set to OPAQUE + * + * @return - {@link ANDROID_IMAGE_DECODER_SUCCESS} on success + * - {@link ANDROID_IMAGE_DECODER_INVALID_CONVERSION} if the conversion + * is not possible + * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER} for bad parameters + */ +int AImageDecoder_setAlphaFlags(AImageDecoder*, int alphaFlags) __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. + * + * @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 + * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER} if the AImageDecoder + * pointer is null, width or height is <= 0, or any existing crop is + * not contained by the image dimensions. + */ +int AImageDecoder_setTargetSize(AImageDecoder*, int width, int 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. + * + * @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 ANDROID_IMAGE_DECODER_BAD_PARAMETER. + * @return - {@link ANDROID_IMAGE_DECODER_SUCCESS} on success + * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER} if the AImageDecoder + * pointer is null or the crop is not contained by the image + * dimensions. + */ +int AImageDecoder_setCrop(AImageDecoder*, ARect crop) __INTRODUCED_IN(30); + +/** + * Opaque handle for reading header info. + */ +struct AImageDecoderHeaderInfo; +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}. + */ +const AImageDecoderHeaderInfo* AImageDecoder_getHeaderInfo( + const AImageDecoder*) __INTRODUCED_IN(30); + +/** + * Report the native width of the encoded image. + */ +int32_t AImageDecoderHeaderInfo_getWidth(const AImageDecoderHeaderInfo*) __INTRODUCED_IN(30); + +/** + * Report the native height of the encoded image. + */ +int32_t AImageDecoderHeaderInfo_getHeight(const AImageDecoderHeaderInfo*) __INTRODUCED_IN(30); + +/** + * Report the mimeType of the encoded image. + * + * @return a string literal describing the mime type. + */ +const char* AImageDecoderHeaderInfo_getMimeType( + const AImageDecoderHeaderInfo*) __INTRODUCED_IN(30); + +/** + * Report whether the encoded image represents an animation. + */ +bool AImageDecoderHeaderInfo_isAnimated( + const AImageDecoderHeaderInfo*) __INTRODUCED_IN(30); + +/** + * Report the AndroidBitmapFormat the AImageDecoder will decode to + * by default. 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. + */ +AndroidBitmapFormat AImageDecoderHeaderInfo_getAndroidBitmapFormat( + const AImageDecoderHeaderInfo*) __INTRODUCED_IN(30); + +/** + * Report how the 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}. + * + * For animated images only the opacity of the first frame is reported. + */ +int AImageDecoderHeaderInfo_getAlphaFlags( + const AImageDecoderHeaderInfo*) __INTRODUCED_IN(30); + +/** + * Return the minimum stride that can be used, taking the specified + * (or default) (possibly scaled) width, crop rect and + * {@link AndroidBitmapFormat} into account. + */ +size_t AImageDecoder_getMinimumStride(AImageDecoder*) __INTRODUCED_IN(30); + +/** + * Decode the image into pixels, using the settings of the AImageDecoder. + * + * @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 fit |size| bytes. + * @param stride Width in bytes of a single row. Must be at least + * {@link AImageDecoder_getMinimumStride}. + * @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 an error code + * from the same enum describing the failure. + */ +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 + +/** @} */ -- cgit v1.2.3-59-g8ed1b From a2a087942db377c3d643ed2949c5bf9668460a26 Mon Sep 17 00:00:00 2001 From: Kweku Adams Date: Fri, 10 Jan 2020 17:25:25 +0000 Subject: Revert "Add AndroidBitmap_getDataSpace" Revert "Test AndroidBitmap_getDataSpace" Revert submission 9940762-_getDataSpace Reason for revert: Breaks build: http://screen/kBMYHusKiOV.png Reverted Changes: Ie05a45da3: Implement AndroidBitmap_getDataSpace I7a5fcb726: Test AndroidBitmap_getDataSpace Ia46dfb39d: Add AndroidBitmap_getDataSpace Change-Id: Ie6c9065f515442f3ea59d3930208deffb9a3bd2a --- include/android/bitmap.h | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'include/android') diff --git a/include/android/bitmap.h b/include/android/bitmap.h index 41718b2904..01cf2f88ea 100644 --- a/include/android/bitmap.h +++ b/include/android/bitmap.h @@ -100,19 +100,6 @@ typedef struct { int AndroidBitmap_getInfo(JNIEnv* env, jobject jbitmap, AndroidBitmapInfo* info); -#if __ANDROID_API__ >= 30 - -/** - * Given a java bitmap object, return its ADataSpace. - * - * Note that ADataSpace only exposes a few values. This may return - * ADATASPACE_UNKNOWN, even for Named ColorSpaces, if they have no - * corresponding ADataSpace. - */ -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 -- cgit v1.2.3-59-g8ed1b From 3dd6455a54bb94c4059519fe9370ec3ecf33dc92 Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Fri, 10 Jan 2020 13:41:44 -0500 Subject: Reland "Add AndroidBitmap_getDataSpace" Originally reviewed in Ia46dfb39d0f2708ce873343ec74bcc52e7bccd3a (and reverted in Ie6c9065f515442f3ea59d3930208deffb9a3bd2a) Bug:135133301 Test: I7a5fcb726fba0c832bbb86a424d7534a7cfa35b6 This supplements AndroidBitmap_getInfo, allowing NDK clients to know how to interpret the colors in an android.graphics.Bitmap. Change-Id: If822af556ac5ee6d412bf31afb9d07de6dd777eb --- include/android/bitmap.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'include/android') diff --git a/include/android/bitmap.h b/include/android/bitmap.h index 01cf2f88ea..41718b2904 100644 --- a/include/android/bitmap.h +++ b/include/android/bitmap.h @@ -100,6 +100,19 @@ typedef struct { int AndroidBitmap_getInfo(JNIEnv* env, jobject jbitmap, AndroidBitmapInfo* info); +#if __ANDROID_API__ >= 30 + +/** + * Given a java bitmap object, return its ADataSpace. + * + * Note that ADataSpace only exposes a few values. This may return + * ADATASPACE_UNKNOWN, even for Named ColorSpaces, if they have no + * corresponding ADataSpace. + */ +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 -- cgit v1.2.3-59-g8ed1b From 7f2d5b668c1bd20688cd6f394045a88c403c02c4 Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Fri, 13 Dec 2019 14:57:07 -0500 Subject: Add NDK Bitmap compression Bug: 135133301 Test: Ifbcb41388a48afc64bb22623bb7e981b288b2457 Add an enum and a method for compression. Change-Id: I81954dba9045f59e3e12012e7df4a14ef20c55ed --- include/android/bitmap.h | 79 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) (limited to 'include/android') diff --git a/include/android/bitmap.h b/include/android/bitmap.h index 41718b2904..d920a90846 100644 --- a/include/android/bitmap.h +++ b/include/android/bitmap.h @@ -26,6 +26,7 @@ #ifndef ANDROID_BITMAP_H #define ANDROID_BITMAP_H +#include #include #include @@ -133,6 +134,84 @@ 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. + * + * @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_compress_write_fn)(void* userContext, + const void* data, + size_t size) __INTRODUCED_IN(30); + +/** + * Compress |pixels| as described by |info|. + * + * @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_compress_write_fn} each time it is + * called. May be null. + * @parm 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_compress_write_fn fn) __INTRODUCED_IN(30); + +#endif // __ANDROID_API__ >= 30 + #ifdef __cplusplus } #endif -- cgit v1.2.3-59-g8ed1b From 1be112f2af35ea040d0203c765f7e229ba793a08 Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Wed, 15 Jan 2020 04:26:44 -0500 Subject: Rename setAlphaFlags to setUnpremultipliedRequired Bug: 135133301 Test: I48e49ee08ab1954eddf62ecae87942aeb128c10d There is never any reason to request OPAQUE. If the image is already opaque, using PREMUL or UNPREMUL has no effect. If the image is not opaque, the requesting OPAQUE is an error. This behavior is not helpful. In addition, this matches the Java API for android.graphics.ImageDecoder. Lastly, the old API was confusing for animated images. It is possible for the first frame to be opaque, while a later frame is not. Requesting OPAQUE seems reasonable for this image, until decoding the non-opaque frame, at which point the inconsistency shows. Having a setting of unpremul or not makes it obvious what will happen for the later frame. Change-Id: I3381582e27894e1072db9b8635f3762b801f5d69 --- include/android/imagedecoder.h | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'include/android') diff --git a/include/android/imagedecoder.h b/include/android/imagedecoder.h index 50daabaaff..4b6446c33d 100644 --- a/include/android/imagedecoder.h +++ b/include/android/imagedecoder.h @@ -143,23 +143,20 @@ void AImageDecoder_delete(AImageDecoder* decoder) __INTRODUCED_IN(30); int AImageDecoder_setAndroidBitmapFormat(AImageDecoder*, int32_t format) __INTRODUCED_IN(30); -/* - * Choose the desired output format. - * - * Must be one of: - * {@link ANDROID_BITMAP_FLAGS_ALPHA_PREMUL} - * {@link ANDROID_BITMAP_FLAGS_ALPHA_OPAQUE} - * {@link ANDROID_BITMAP_FLAGS_ALPHA_UNPREMUL} +/** + * Specify whether the output's pixels should be unpremultiplied. * - * Note: An OPAQUE image may be set to any of them. - * A non-OPAQUE image may not be set to OPAQUE + * By default, the decoder will premultiply the pixels, if they have alpha. Pass + * false to this method to leave them unpremultiplied. This has no effect on an + * opaque image. * + * @param required Pass true to leave the pixels unpremultiplied. * @return - {@link ANDROID_IMAGE_DECODER_SUCCESS} on success * - {@link ANDROID_IMAGE_DECODER_INVALID_CONVERSION} if the conversion * is not possible * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER} for bad parameters */ -int AImageDecoder_setAlphaFlags(AImageDecoder*, int alphaFlags) __INTRODUCED_IN(30); +int AImageDecoder_setUnpremultipliedRequired(AImageDecoder*, bool required) __INTRODUCED_IN(30); /** * Specify the output size for a decoded image. -- cgit v1.2.3-59-g8ed1b From 421eb1c2edc0f69d80cb9182a6d5a970501f8699 Mon Sep 17 00:00:00 2001 From: Arthur Hung Date: Thu, 16 Jan 2020 00:09:42 +0800 Subject: Touch cancellation handling Cancel motion event that are accidental touches when a user is holding the device and a touch stream is in progress. - Process MT_TOOL_PALM and cancel touch when sent from firmware. Bug: 117933934 Test: atest inputflinger_tests Test: atest InputProcessTest Change-Id: I80ba8b462572e5214dd1073ef0568886f71e21c9 --- include/android/input.h | 2 + .../reader/mapper/MultiTouchInputMapper.cpp | 10 +++ services/inputflinger/tests/InputReader_test.cpp | 91 ++++++++++++++++++++++ 3 files changed, 103 insertions(+) (limited to 'include/android') diff --git a/include/android/input.h b/include/android/input.h index f51cd79504..dbfd61eb05 100644 --- a/include/android/input.h +++ b/include/android/input.h @@ -793,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/services/inputflinger/reader/mapper/MultiTouchInputMapper.cpp b/services/inputflinger/reader/mapper/MultiTouchInputMapper.cpp index c567c8bf80..f42ddcf461 100644 --- a/services/inputflinger/reader/mapper/MultiTouchInputMapper.cpp +++ b/services/inputflinger/reader/mapper/MultiTouchInputMapper.cpp @@ -209,6 +209,8 @@ int32_t MultiTouchMotionAccumulator::Slot::getToolType() const { return AMOTION_EVENT_TOOL_TYPE_FINGER; case MT_TOOL_PEN: return AMOTION_EVENT_TOOL_TYPE_STYLUS; + case MT_TOOL_PALM: + return AMOTION_EVENT_TOOL_TYPE_PALM; } } return AMOTION_EVENT_TOOL_TYPE_UNKNOWN; @@ -247,6 +249,14 @@ void MultiTouchInputMapper::syncTouch(nsecs_t when, RawState* outState) { continue; } + if (inSlot->getToolType() == AMOTION_EVENT_TOOL_TYPE_PALM) { + if (!mCurrentMotionAborted) { + ALOGI("Canceling touch gesture from device %s because the palm event was detected", + getDeviceName().c_str()); + cancelTouch(when); + } + } + if (outCount >= MAX_POINTERS) { #if DEBUG_POINTERS ALOGD("MultiTouch device %s emitted more than maximum of %d pointers; " diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp index 1fc8217df8..a9d7793a17 100644 --- a/services/inputflinger/tests/InputReader_test.cpp +++ b/services/inputflinger/tests/InputReader_test.cpp @@ -6798,4 +6798,95 @@ TEST_F(MultiTouchInputMapperTest, Viewports_SurfaceRange) { ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled()); } +TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleSingleTouch) { + MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice); + addConfigurationProperty("touch.deviceType", "touchScreen"); + prepareDisplay(DISPLAY_ORIENTATION_0); + prepareAxes(POSITION | ID | SLOT | TOOL_TYPE); + addMapperAndConfigure(mapper); + + NotifyMotionArgs motionArgs; + + constexpr int32_t x1 = 100, y1 = 200, x2 = 120, y2 = 220, x3 = 140, y3 = 240; + // finger down + processId(mapper, 1); + processPosition(mapper, x1, y1); + processSync(mapper); + ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); + ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); + ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + + // finger move + processId(mapper, 1); + processPosition(mapper, x2, y2); + processSync(mapper); + ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); + ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); + ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + + // finger up. + processId(mapper, -1); + processSync(mapper); + ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); + ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action); + ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + + // new finger down + processId(mapper, 1); + processPosition(mapper, x3, y3); + processSync(mapper); + ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); + ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); + ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); +} + +/** + * Test touch should be canceled when received the MT_TOOL_PALM event, and the following MOVE and + * UP events should be ignored. + */ +TEST_F(MultiTouchInputMapperTest, Process_ShouldHandlePalmToolType) { + MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice); + addConfigurationProperty("touch.deviceType", "touchScreen"); + prepareDisplay(DISPLAY_ORIENTATION_0); + prepareAxes(POSITION | ID | SLOT | TOOL_TYPE); + addMapperAndConfigure(mapper); + + NotifyMotionArgs motionArgs; + + // default tool type is finger + constexpr int32_t x1 = 100, y1 = 200, x2 = 120, y2 = 220, x3 = 140, y3 = 240; + processId(mapper, 1); + processPosition(mapper, x1, y1); + processSync(mapper); + ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); + ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); + ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + + // Tool changed to MT_TOOL_PALM expect sending the cancel event. + processToolType(mapper, MT_TOOL_PALM); + processSync(mapper); + ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); + ASSERT_EQ(AMOTION_EVENT_ACTION_CANCEL, motionArgs.action); + + // Ignore the following MOVE and UP events if had detect a palm event. + processId(mapper, 1); + processPosition(mapper, x2, y2); + processSync(mapper); + ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled()); + + // finger up. + processId(mapper, -1); + processSync(mapper); + ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled()); + + // new finger down + processToolType(mapper, MT_TOOL_FINGER); + processId(mapper, 1); + processPosition(mapper, x3, y3); + processSync(mapper); + ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); + ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); + ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); +} + } // namespace android -- cgit v1.2.3-59-g8ed1b From f27256b956d6a48ce8d74aaab36617a41d00cee2 Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Sun, 19 Jan 2020 21:13:04 -0500 Subject: Add AImageDecoder_computeSampledSize Bug: 135133301 Test: If9ed79d8dcf1169369ba454723f4ac8d26427b7b This allows an NDK client to find an efficient target size to use. Change-Id: Iabc3db1547d4863f9aa0324bc438d994eadeef01 --- include/android/imagedecoder.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'include/android') diff --git a/include/android/imagedecoder.h b/include/android/imagedecoder.h index 4b6446c33d..c9fde0d3b7 100644 --- a/include/android/imagedecoder.h +++ b/include/android/imagedecoder.h @@ -179,6 +179,28 @@ int AImageDecoder_setUnpremultipliedRequired(AImageDecoder*, bool required) __IN */ int AImageDecoder_setTargetSize(AImageDecoder*, int width, int 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. + * + * @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 + * direction that the decoder can do most efficiently. + * @param height Out parameter for the height sampled by sampleSize, and rounded + * direction that the decoder can do most efficiently. + * @return ANDROID_IMAGE_DECODER result code. + */ +int AImageDecoder_computeSampledSize(const AImageDecoder*, int sampleSize, + int* width, int* height) __INTRODUCED_IN(30); /** * Specify how to crop the output after scaling (if any). * -- cgit v1.2.3-59-g8ed1b From d4672a8091fcf52175c8307caea60366ed784650 Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Sun, 19 Jan 2020 19:25:41 -0500 Subject: Add NDK methods for HARDWARE Bitmaps Bug: 135133301 Test: I2c1e58c41e49c72fb4bdbc64989da103885d34bf Add a flag for AndroidBitmapInfo.flags that represents whether the Bitmap has Config.HARDWARE. Add a method for retrieving the AHardwareBuffer if it is a HARDWARE Bitmap. Change-Id: I69b78491bc29e770d863aa01752e8c923298afb3 --- include/android/bitmap.h | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'include/android') diff --git a/include/android/bitmap.h b/include/android/bitmap.h index d920a90846..5e03c6c5aa 100644 --- a/include/android/bitmap.h +++ b/include/android/bitmap.h @@ -79,6 +79,14 @@ enum { ANDROID_BITMAP_FLAGS_ALPHA_SHIFT = 0, }; +enum { + /** If this bit is set in AndroidBitmapInfo.flags, the Bitmap uses the + * HARDWARE Config, and its AHardwareBuffer can be retrieved via + * AndroidBitmap_getHardwareBuffer. + */ + ANDROID_BITMAP_FLAGS_IS_HARDWARE = 1 << 31, +}; + /** Bitmap info, see AndroidBitmap_getInfo(). */ typedef struct { /** The bitmap width in pixels. */ @@ -90,7 +98,9 @@ typedef struct { /** The bitmap pixel format. See {@link AndroidBitmapFormat} */ int32_t format; /** Two bits are used to encode alpha. Use ANDROID_BITMAP_FLAGS_ALPHA_MASK - * and ANDROID_BITMAP_FLAGS_ALPHA_SHIFT to retrieve them. */ + * and ANDROID_BITMAP_FLAGS_ALPHA_SHIFT to retrieve them. One bit is used + * to encode whether the Bitmap uses the HARDWARE Config. Use + * ANDROID_BITMAP_FLAGS_IS_HARDWARE to know.*/ uint32_t flags; } AndroidBitmapInfo; @@ -210,6 +220,25 @@ int AndroidBitmap_compress(const AndroidBitmapInfo* info, void* userContext, AndroidBitmap_compress_write_fn fn) __INTRODUCED_IN(30); +struct AHardwareBuffer; + +/** + * Retrieve the native object associated with a HARDWARE Bitmap. + * + * Client must not modify it while a Bitmap is wrapping it. + * + * @param bitmap Handle to an android.graphics.Bitmap. + * @param outBuffer On success, is set to a pointer to the + * AHardwareBuffer associated with bitmap. This acquires + * a reference on the buffer, and the client must call + * AHardwareBuffer_release when finished with it. + * @return AndroidBitmap functions result code. + * 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 -- cgit v1.2.3-59-g8ed1b From 20d480ce9c6bfdd54d2b1e5e34306744968a4f37 Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Wed, 15 Jan 2020 15:32:59 -0500 Subject: Add AImageDecoder HeaderInfo_get/_setDataSpace Bug: 135133301 Test: Iffe659e50078139188c3325545624640ae177cc2 Default to ADATASPACE_UNKNOWN for images that do not have a matching ADataSpace. This matches the behavior of android.graphics.ImageDecoder and BitmapFactory, which would use an "Unknown" ColorSpace for the same images. It also means that a client who knows the true underlying profile information to treat it as if it came from that profile. Further, it means that if we add more ADataSpace values in the future, the decode will be unchanged. A client can still choose to use a known ADataSpace using _setDataSpace. Change-Id: Id3ecf3bab17e4905fb2b75410ec756233d600c97 --- include/android/imagedecoder.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'include/android') diff --git a/include/android/imagedecoder.h b/include/android/imagedecoder.h index 4b6446c33d..68401ea5a2 100644 --- a/include/android/imagedecoder.h +++ b/include/android/imagedecoder.h @@ -158,6 +158,25 @@ int AImageDecoder_setAndroidBitmapFormat(AImageDecoder*, */ int AImageDecoder_setUnpremultipliedRequired(AImageDecoder*, bool required) __INTRODUCED_IN(30); +/** + * Choose the dataspace for the output. + * + * Not supported for {@link ANDROID_BITMAP_FORMAT_A_8}, which does not support + * an ADataSpace. + * + * @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 + * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER} for a null + * AImageDecoder or an integer that does not correspond to an + * ADataSpace value. + */ +int AImageDecoder_setDataSpace(AImageDecoder*, int32_t dataspace) __INTRODUCED_IN(30); + /** * Specify the output size for a decoded image. * @@ -260,6 +279,25 @@ AndroidBitmapFormat AImageDecoderHeaderInfo_getAndroidBitmapFormat( int AImageDecoderHeaderInfo_getAlphaFlags( const AImageDecoderHeaderInfo*) __INTRODUCED_IN(30); +/** + * Report the dataspace the AImageDecoder will decode to by default. + * AImageDecoder will try to choose one that is sensible for the + * image and the system. Note that this may not exactly match the ICC + * profile (or other color information) stored in the encoded image. + * + * @return The {@link ADataSpace} most closely representing the way the colors + * are encoded (or {@link ADATASPACE_UNKNOWN} if there is not an + * approximate 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 + * ADATASPACE_UNKNOWN, even for Named ColorSpaces, if they have no + * corresponding ADataSpace. + */ +int32_t AImageDecoderHeaderInfo_getDataSpace( + const AImageDecoderHeaderInfo*) __INTRODUCED_IN(30); + /** * Return the minimum stride that can be used, taking the specified * (or default) (possibly scaled) width, crop rect and -- cgit v1.2.3-59-g8ed1b From c04a63ec68d8bb0491b291b6402206c137479d5c Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Wed, 22 Jan 2020 11:52:48 -0500 Subject: Rename callback for AndroidBitmap_compress Bug: 135133301 Test: No change in behavior, no new tests Rename from AndroidBitmap_compress_write_fn to AndroidBitmap_CompressWriteFunc to better fit in with media callbacks, as suggested in feedback. Change-Id: Id5d039761054cf8e7fb906624a277714c21156de --- include/android/bitmap.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'include/android') diff --git a/include/android/bitmap.h b/include/android/bitmap.h index d920a90846..f169d811ec 100644 --- a/include/android/bitmap.h +++ b/include/android/bitmap.h @@ -179,7 +179,7 @@ enum AndroidBitmapCompressFormat { * @param size Length in bytes of data to write. * @return Whether the operation succeeded. */ -typedef bool (*AndroidBitmap_compress_write_fn)(void* userContext, +typedef bool (*AndroidBitmap_CompressWriteFunc)(void* userContext, const void* data, size_t size) __INTRODUCED_IN(30); @@ -195,7 +195,7 @@ typedef bool (*AndroidBitmap_compress_write_fn)(void* userContext, * differently depending on the * {@link AndroidBitmapCompressFormat}. * @param userContext User-defined data which will be passed to the supplied - * {@link AndroidBitmap_compress_write_fn} each time it is + * {@link AndroidBitmap_CompressWriteFunc} each time it is * called. May be null. * @parm fn Function that writes the compressed data. Will be called each time * the compressor has compressed more data that is ready to be @@ -208,7 +208,7 @@ int AndroidBitmap_compress(const AndroidBitmapInfo* info, const void* pixels, int32_t format, int32_t quality, void* userContext, - AndroidBitmap_compress_write_fn fn) __INTRODUCED_IN(30); + AndroidBitmap_CompressWriteFunc fn) __INTRODUCED_IN(30); #endif // __ANDROID_API__ >= 30 -- cgit v1.2.3-59-g8ed1b From fdb1fc8fcb8c9cc780f35f7af720ccb267afef1f Mon Sep 17 00:00:00 2001 From: Anthony Stange Date: Thu, 16 Jan 2020 15:02:48 -0500 Subject: Add hinge angle sensor type to sensor NDK Bug: 144139857 Test: N/A Change-Id: Id809a8f65b31143759978702d18e6ac944d62ac3 --- include/android/sensor.h | 4 ++++ libs/sensor/Sensor.cpp | 4 ++++ libs/sensor/SensorManager.cpp | 2 +- services/sensorservice/SensorServiceUtils.cpp | 1 + 4 files changed, 10 insertions(+), 1 deletion(-) (limited to 'include/android') diff --git a/include/android/sensor.h b/include/android/sensor.h index 3ebe79fd2e..12c00ad8a2 100644 --- a/include/android/sensor.h +++ b/include/android/sensor.h @@ -245,6 +245,10 @@ enum { * {@link ASENSOR_TYPE_ACCELEROMETER_UNCALIBRATED} */ ASENSOR_TYPE_ACCELEROMETER_UNCALIBRATED = 35, + /** + * {@link ASENSOR_TYPE_HINGE_ANGLE} + */ + ASENSOR_TYPE_HINGE_ANGLE = 36, }; /** diff --git a/libs/sensor/Sensor.cpp b/libs/sensor/Sensor.cpp index abc910302c..9d817ae0bd 100644 --- a/libs/sensor/Sensor.cpp +++ b/libs/sensor/Sensor.cpp @@ -268,6 +268,10 @@ Sensor::Sensor(struct sensor_t const& hwSensor, const uuid_t& uuid, int halVersi mStringType = SENSOR_STRING_TYPE_ACCELEROMETER_UNCALIBRATED; mFlags |= SENSOR_FLAG_CONTINUOUS_MODE; break; + case SENSOR_TYPE_HINGE_ANGLE: + mStringType = SENSOR_STRING_TYPE_HINGE_ANGLE; + mFlags |= SENSOR_FLAG_ON_CHANGE_MODE; + break; default: // Only pipe the stringType, requiredPermission and flags for custom sensors. if (halVersion > SENSORS_DEVICE_API_VERSION_1_0 && hwSensor.stringType) { diff --git a/libs/sensor/SensorManager.cpp b/libs/sensor/SensorManager.cpp index bf8b9f73fe..a4a5d135c0 100644 --- a/libs/sensor/SensorManager.cpp +++ b/libs/sensor/SensorManager.cpp @@ -209,7 +209,7 @@ Sensor const* SensorManager::getDefaultSensor(int type) type == SENSOR_TYPE_TILT_DETECTOR || type == SENSOR_TYPE_WAKE_GESTURE || type == SENSOR_TYPE_GLANCE_GESTURE || type == SENSOR_TYPE_PICK_UP_GESTURE || type == SENSOR_TYPE_WRIST_TILT_GESTURE || - type == SENSOR_TYPE_LOW_LATENCY_OFFBODY_DETECT) { + type == SENSOR_TYPE_LOW_LATENCY_OFFBODY_DETECT || type == SENSOR_TYPE_HINGE_ANGLE) { wakeUpSensor = true; } // For now we just return the first sensor of that type we find. diff --git a/services/sensorservice/SensorServiceUtils.cpp b/services/sensorservice/SensorServiceUtils.cpp index 34cd8ddd7b..fdd56b364d 100644 --- a/services/sensorservice/SensorServiceUtils.cpp +++ b/services/sensorservice/SensorServiceUtils.cpp @@ -55,6 +55,7 @@ size_t eventSizeBySensorType(int type) { case SENSOR_TYPE_MOTION_DETECT: case SENSOR_TYPE_HEART_BEAT: case SENSOR_TYPE_LOW_LATENCY_OFFBODY_DETECT: + case SENSOR_TYPE_HINGE_ANGLE: return 1; default: -- cgit v1.2.3-59-g8ed1b From 6d88a487b0fe7f72314f81e81c9786005032afa3 Mon Sep 17 00:00:00 2001 From: Steven Thomas Date: Mon, 2 Dec 2019 22:00:47 -0800 Subject: Add setFrameRate() api setFrameRate() is a new api in Android 11 that will enable apps to specify their intended frame rate. Bug: 143912624 Bug: 137287430 Test: Added a new CTS test - android.graphics.cts.SetFrameRateTest. Change-Id: I0150055fbffd37f2d644829e9dadbfc517045d8e --- include/android/surface_control.h | 27 +++++++++++++++++++ libs/nativewindow/ANativeWindow.cpp | 7 +++++ libs/nativewindow/include/android/native_window.h | 33 +++++++++++++++++++++++ libs/nativewindow/libnativewindow.map.txt | 1 + 4 files changed, 68 insertions(+) (limited to 'include/android') diff --git a/include/android/surface_control.h b/include/android/surface_control.h index 31abb6622e..157b4242fe 100644 --- a/include/android/surface_control.h +++ b/include/android/surface_control.h @@ -407,6 +407,33 @@ 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. 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 *not* 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. + * + * Available since API level 30. + */ +void ASurfaceTransaction_setFrameRate(ASurfaceTransaction* transaction, + ASurfaceControl* surface_control, + float frameRate) + __INTRODUCED_IN(30); + +#endif // __ANDROID_API__ >= 30 + __END_DECLS #endif // ANDROID_SURFACE_CONTROL_H diff --git a/libs/nativewindow/ANativeWindow.cpp b/libs/nativewindow/ANativeWindow.cpp index 842af18c8c..a60bc4dad3 100644 --- a/libs/nativewindow/ANativeWindow.cpp +++ b/libs/nativewindow/ANativeWindow.cpp @@ -158,6 +158,13 @@ int32_t ANativeWindow_getBuffersDataSpace(ANativeWindow* window) { return query(window, NATIVE_WINDOW_DATASPACE); } +int32_t ANativeWindow_setFrameRate(ANativeWindow* window, float frameRate) { + if (!window || !query(window, NATIVE_WINDOW_IS_VALID) || frameRate < 0) { + return -EINVAL; + } + return native_window_set_frame_rate(window, frameRate); +} + /************************************************************************************************** * vndk-stable **************************************************************************************************/ diff --git a/libs/nativewindow/include/android/native_window.h b/libs/nativewindow/include/android/native_window.h index 3e436e3b07..0637db390d 100644 --- a/libs/nativewindow/include/android/native_window.h +++ b/libs/nativewindow/include/android/native_window.h @@ -230,6 +230,39 @@ int32_t ANativeWindow_getBuffersDataSpace(ANativeWindow* window) __INTRODUCED_IN #endif // __ANDROID_API__ >= 28 +#if __ANDROID_API__ >= 30 + +/** + * Sets the intended frame rate for this window. + * + * 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 + * window's frame rate. Usage of this API won't introduce frame rate throttling, + * or affect other aspects of 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. + * + * Note that this only has an effect for windows presented on the display. If + * this ANativeWindow is consumed by something other than the system compositor, + * e.g. a media codec, this call has no effect. + * + * Available since API level 30. + * + * \param frameRate The intended frame rate of this window. 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 *not* 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. + * + * \return 0 for success, -EINVAL if the window or frame rate are invalid. + */ +int32_t ANativeWindow_setFrameRate(ANativeWindow* window, float frameRate) __INTRODUCED_IN(30); + +#endif // __ANDROID_API__ >= 30 + #ifdef __cplusplus }; #endif diff --git a/libs/nativewindow/libnativewindow.map.txt b/libs/nativewindow/libnativewindow.map.txt index f59e8f0546..3002da29e7 100644 --- a/libs/nativewindow/libnativewindow.map.txt +++ b/libs/nativewindow/libnativewindow.map.txt @@ -43,6 +43,7 @@ LIBNATIVEWINDOW { ANativeWindow_setDequeueTimeout; # apex # introduced=30 ANativeWindow_setSharedBufferMode; # llndk ANativeWindow_setSwapInterval; # llndk + ANativeWindow_setFrameRate; # introduced=30 ANativeWindow_setUsage; # llndk ANativeWindow_unlockAndPost; local: -- cgit v1.2.3-59-g8ed1b From 59262f93650e4fa7205c64680045faa52f4da5fa Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Wed, 22 Jan 2020 17:29:06 -0500 Subject: Update decodeImage to account for alignment Bug: 147749998 Test: I902de3410c45a21cf27b48a02cdc5d514b7ada60 Document that the stride must be pixel-aligned. Change-Id: Ifbd667298f542f249092ae8eca744b4ed65afaee --- include/android/imagedecoder.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include/android') diff --git a/include/android/imagedecoder.h b/include/android/imagedecoder.h index 469b088c89..c9a041e2ef 100644 --- a/include/android/imagedecoder.h +++ b/include/android/imagedecoder.h @@ -337,7 +337,8 @@ size_t AImageDecoder_getMinimumStride(AImageDecoder*) __INTRODUCED_IN(30); * {@link AImageDecoder_getMinimumStride}. * @param size Size of the pixel buffer in bytes. Must be at least * stride * (height - 1) + - * {@link AImageDecoder_getMinimumStride}. + * {@link AImageDecoder_getMinimumStride}. Must also be a multiple + * of the bytes per pixel of the {@link AndroidBitmapFormat}. * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success, or an error code * from the same enum describing the failure. */ -- cgit v1.2.3-59-g8ed1b From 5d0445cc3e16af2e49ae87580ecc420be54b4608 Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Thu, 23 Jan 2020 09:43:43 -0500 Subject: Clean up imagedecoder header file Bug: 135133301 Test: Ibf7c0e563feeb08ce6dbabb5e86ddb385c9dff54 Remove AImageDecoderHeaderInfo_isAnimated. We are punting animation support to S, so there is no reason to report whether the image is animated. Use int32_t for width and height. We already return these for AImageDecoderHeaderInfo_getWidth/getHeight, so use the same type for AImageDecoder_setTargetSize/computeSampledSize. Use int32_t for AImageDecoderHeaderInfo_getAndroidBitmapFormat. This matches the convention for what to return when the value is logically an enum. Change-Id: I93df851dd9fee2eb8d097e2158fb95003a0474db --- include/android/imagedecoder.h | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'include/android') diff --git a/include/android/imagedecoder.h b/include/android/imagedecoder.h index 469b088c89..31efa65cbe 100644 --- a/include/android/imagedecoder.h +++ b/include/android/imagedecoder.h @@ -133,7 +133,7 @@ void AImageDecoder_delete(AImageDecoder* decoder) __INTRODUCED_IN(30); /** * Choose the desired output format. * - * @param format AndroidBitmapFormat to use + * @param format {@link AndroidBitmapFormat} to use for the output. * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} if the format is compatible * with the image and {@link ANDROID_IMAGE_DECODER_INVALID_CONVERSION} * otherwise. In the latter case, the AImageDecoder uses the @@ -196,7 +196,7 @@ int AImageDecoder_setDataSpace(AImageDecoder*, int32_t dataspace) __INTRODUCED_I * pointer is null, width or height is <= 0, or any existing crop is * not contained by the image dimensions. */ -int AImageDecoder_setTargetSize(AImageDecoder*, int width, int height) __INTRODUCED_IN(30); +int AImageDecoder_setTargetSize(AImageDecoder*, int32_t width, int32_t height) __INTRODUCED_IN(30); /** @@ -219,7 +219,7 @@ int AImageDecoder_setTargetSize(AImageDecoder*, int width, int height) __INTRODU * @return ANDROID_IMAGE_DECODER result code. */ int AImageDecoder_computeSampledSize(const AImageDecoder*, int sampleSize, - int* width, int* height) __INTRODUCED_IN(30); + int32_t* width, int32_t* height) __INTRODUCED_IN(30); /** * Specify how to crop the output after scaling (if any). * @@ -276,18 +276,12 @@ const char* AImageDecoderHeaderInfo_getMimeType( const AImageDecoderHeaderInfo*) __INTRODUCED_IN(30); /** - * Report whether the encoded image represents an animation. - */ -bool AImageDecoderHeaderInfo_isAnimated( - const AImageDecoderHeaderInfo*) __INTRODUCED_IN(30); - -/** - * Report the AndroidBitmapFormat the AImageDecoder will decode to + * Report the {@link AndroidBitmapFormat} the AImageDecoder will decode to * by default. 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. */ -AndroidBitmapFormat AImageDecoderHeaderInfo_getAndroidBitmapFormat( +int32_t AImageDecoderHeaderInfo_getAndroidBitmapFormat( const AImageDecoderHeaderInfo*) __INTRODUCED_IN(30); /** -- cgit v1.2.3-59-g8ed1b From 9bb0f07ac583e56123c9c223ee93cca64c1e8493 Mon Sep 17 00:00:00 2001 From: Steven Thomas Date: Thu, 23 Jan 2020 16:37:13 -0800 Subject: Clarify frame rate as frames per second Bug: 137287430 Test: n/a Change-Id: Icf1ad4c5b9551d3690af2329290d5cc30c8016b0 --- include/android/surface_control.h | 10 +++++----- libs/nativewindow/include/android/native_window.h | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'include/android') diff --git a/include/android/surface_control.h b/include/android/surface_control.h index 157b4242fe..eeb8330efd 100644 --- a/include/android/surface_control.h +++ b/include/android/surface_control.h @@ -419,11 +419,11 @@ void ASurfaceTransaction_setHdrMetadata_cta861_3(ASurfaceTransaction* transactio * 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. 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 *not* 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. + * |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 *not* 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. * * Available since API level 30. */ diff --git a/libs/nativewindow/include/android/native_window.h b/libs/nativewindow/include/android/native_window.h index 0637db390d..262aee3501 100644 --- a/libs/nativewindow/include/android/native_window.h +++ b/libs/nativewindow/include/android/native_window.h @@ -250,12 +250,12 @@ int32_t ANativeWindow_getBuffersDataSpace(ANativeWindow* window) __INTRODUCED_IN * * Available since API level 30. * - * \param frameRate The intended frame rate of this window. 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 *not* 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. + * \param frameRate The intended frame rate of this window, 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 *not* 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. * * \return 0 for success, -EINVAL if the window or frame rate are invalid. */ -- cgit v1.2.3-59-g8ed1b From a9f397b562df067d27888789954c539f6c0fa624 Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Mon, 27 Jan 2020 12:42:56 -0500 Subject: Update imagedecoder.h to build as a C file Bug: 135133301 Test: build as a C file AAsset is a forward-declared struct, so it needs to be declared in parameters as a struct in order to compile as a C file. In addition, include rect.h explicitly for documentation purposes. This also means that ARect as a parameter does not need to be declared as "struct ARect". Change-Id: I30c5176010ec3b5b0405f0b383654a7cfca65b62 --- include/android/imagedecoder.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'include/android') diff --git a/include/android/imagedecoder.h b/include/android/imagedecoder.h index 469b088c89..cabd626c35 100644 --- a/include/android/imagedecoder.h +++ b/include/android/imagedecoder.h @@ -27,7 +27,7 @@ #define ANDROID_IMAGE_DECODER_H #include "bitmap.h" - +#include #include #ifdef __cplusplus @@ -35,7 +35,6 @@ extern "C" { #endif struct AAsset; -struct ARect; #if __ANDROID_API__ >= 30 @@ -92,7 +91,8 @@ typedef struct AImageDecoder AImageDecoder; * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or a value * indicating reason for the failure. */ -int AImageDecoder_createFromAAsset(AAsset* asset, AImageDecoder** outDecoder) __INTRODUCED_IN(30); +int AImageDecoder_createFromAAsset(struct AAsset* asset, AImageDecoder** outDecoder) + __INTRODUCED_IN(30); /** * Create a new AImageDecoder from a file descriptor. -- cgit v1.2.3-59-g8ed1b From 97fea5f41c5da1765889660a881f5d7b655de544 Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Thu, 30 Jan 2020 12:18:20 -0500 Subject: Update imagedecoder documentation Bug: 147839368 Test: No change in behavior Update documentation in response to feedback and after reviewing https://android.devsite.corp.google.com/ndk/reference/group/image-decoder.html#group___image_decoder_1ga8c3a19f8ae30a936a17b3879f849ea60 - Use @defgroup instead of @addtogroup, since this is the only file for this group. - Add a top-level description, including supported formats - Describe the ANDROID_IMAGE_DECODER result enum, and use proper format for the individual values so they will be added to the documentation page. - for createFromAAsset, specify that the AAsset can be closed *after* deleting the AImageDecoder, as we do in createFromFd - reformat some return lines to look more consistent - Remove reference to animated images - Move comment describing AImageDecoderHeaderInfo to before the typedef, so it will be included in the documentation, and expand the comment - More thorough description for getWidth/getHeight - Move comment describing limitation on stride to stride (it had been on the description for size) - Clarify various comments, fix links, etc. Change-Id: I26482ea8373081ee8d47455f7028f2bb6ec6a58e --- include/android/imagedecoder.h | 196 +++++++++++++++++++++++++++-------------- 1 file changed, 129 insertions(+), 67 deletions(-) (limited to 'include/android') diff --git a/include/android/imagedecoder.h b/include/android/imagedecoder.h index 0d943b7800..6e5da52cb5 100644 --- a/include/android/imagedecoder.h +++ b/include/android/imagedecoder.h @@ -15,12 +15,24 @@ */ /** - * @addtogroup ImageDecoder + * @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 like PNG, JPEG, GIF, WEBP and HEIF. 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 + * Image decoder + * developer guide. * @{ */ /** - * @file imageDecoder.h + * @file imagedecoder.h + * @brief API for decoding images. */ #ifndef ANDROID_IMAGE_DECODER_H @@ -38,32 +50,54 @@ struct AAsset; #if __ANDROID_API__ >= 30 -/** AImageDecoder functions result code. */ +/** + * {@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. + /** + * Decoding was successful and complete. + */ ANDROID_IMAGE_DECODER_SUCCESS = 0, - // The input was incomplete. In decodeImage, this means a partial - // image was decoded. Undecoded lines are all zeroes. - // In AImageDecoder_create*, no AImageDecoder was created. + /** + * The input was incomplete. + */ ANDROID_IMAGE_DECODER_INCOMPLETE = -1, - // The input contained an error after decoding some lines. Similar to - // INCOMPLETE, above. + /** + * The input contained an error after decoding some lines. + */ ANDROID_IMAGE_DECODER_ERROR = -2, - // Could not convert, e.g. attempting to decode an image with - // alpha to an opaque format. + /** + * 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. + /** + * 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 was bad (e.g. pixels) + /** + * Some other parameter was bad. + */ ANDROID_IMAGE_DECODER_BAD_PARAMETER = -5, - // Input was invalid i.e. broken before decoding any pixels. + /** + * Input was invalid before decoding any pixels. + */ ANDROID_IMAGE_DECODER_INVALID_INPUT = -6, - // A seek was required, and failed. + /** + * A seek was required and it failed. + */ ANDROID_IMAGE_DECODER_SEEK_ERROR = -7, - // Some other error (e.g. OOM) + /** + * Some other error. For example, an internal allocation failed. + */ ANDROID_IMAGE_DECODER_INTERNAL_ERROR = -8, - // We did not recognize the format + /** + * AImageDecoder did not recognize the format. + */ ANDROID_IMAGE_DECODER_UNSUPPORTED_FORMAT = -9 }; @@ -76,36 +110,45 @@ struct AImageDecoder; * - {@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 AImageDecoder from an AAsset. + * Create a new {@link AImageDecoder} from an {@link AAsset}. * * @param asset {@link AAsset} containing encoded image data. Client is still - * responsible for calling {@link AAsset_close} on it. + * 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 reason for the failure. + * indicating the reason for the failure. */ int AImageDecoder_createFromAAsset(struct AAsset* asset, AImageDecoder** outDecoder) __INTRODUCED_IN(30); /** - * Create a new AImageDecoder from a file descriptor. + * Create a new {@link AImageDecoder} from a file descriptor. * * @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 AImageDecoder. + * 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 reason for the failure. + * indicating the reason for the failure. */ int AImageDecoder_createFromFd(int fd, AImageDecoder** outDecoder) __INTRODUCED_IN(30); @@ -113,7 +156,7 @@ int AImageDecoder_createFromFd(int fd, AImageDecoder** outDecoder) __INTRODUCED_ * Create a new AImageDecoder from a buffer. * * @param buffer Pointer to encoded data. Must be valid for the entire time - * the AImageDecoder is used. + * 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 @@ -136,7 +179,7 @@ void AImageDecoder_delete(AImageDecoder* decoder) __INTRODUCED_IN(30); * @param format {@link AndroidBitmapFormat} to use for the output. * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} if the format is compatible * with the image and {@link ANDROID_IMAGE_DECODER_INVALID_CONVERSION} - * otherwise. In the latter case, the AImageDecoder uses the + * otherwise. In the latter case, the {@link AImageDecoder} uses the * format it was already planning to use (either its default * or a previously successful setting from this function). */ @@ -146,23 +189,25 @@ int AImageDecoder_setAndroidBitmapFormat(AImageDecoder*, /** * Specify whether the output's pixels should be unpremultiplied. * - * By default, the decoder will premultiply the pixels, if they have alpha. Pass - * false to this method to leave them unpremultiplied. This has no effect on an + * 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. * - * @param required Pass true to leave the pixels unpremultiplied. - * @return - {@link ANDROID_IMAGE_DECODER_SUCCESS} on success + * @param unpremultipliedRequired Pass true to leave the pixels unpremultiplied. + * @return an enum describing whether the call succeeded. + * - {@link ANDROID_IMAGE_DECODER_SUCCESS} on success * - {@link ANDROID_IMAGE_DECODER_INVALID_CONVERSION} if the conversion * is not possible * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER} for bad parameters */ -int AImageDecoder_setUnpremultipliedRequired(AImageDecoder*, bool required) __INTRODUCED_IN(30); +int AImageDecoder_setUnpremultipliedRequired(AImageDecoder*, + bool unpremultipliedRequired) __INTRODUCED_IN(30); /** * Choose the dataspace for the output. * - * Not supported for {@link ANDROID_BITMAP_FORMAT_A_8}, which does not support - * an ADataSpace. + * Ignored by {@link ANDROID_BITMAP_FORMAT_A_8}, which does not support + * an {@link ADataSpace}. * * @param dataspace The {@link ADataSpace} to decode into. An ADataSpace * specifies how to interpret the colors. By default, @@ -170,10 +215,10 @@ int AImageDecoder_setUnpremultipliedRequired(AImageDecoder*, bool required) __IN * {@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 - * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER} for a null - * AImageDecoder or an integer that does not correspond to an - * ADataSpace value. + * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or + * {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER} for a null + * {@link AImageDecoder} or an integer that does not correspond to an + * {@link ADataSpace} value. */ int AImageDecoder_setDataSpace(AImageDecoder*, int32_t dataspace) __INTRODUCED_IN(30); @@ -191,10 +236,11 @@ int AImageDecoder_setDataSpace(AImageDecoder*, int32_t dataspace) __INTRODUCED_I * {@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 - * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER} if the AImageDecoder - * pointer is null, width or height is <= 0, or any existing crop is - * not contained by the image dimensions. + * @return an enum describing whether the call succeeded. + * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or + * {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER} if the {@link AImageDecoder} + * pointer is null, width or height is <= 0, or any existing crop is + * not contained by the new image dimensions. */ int AImageDecoder_setTargetSize(AImageDecoder*, int32_t width, int32_t height) __INTRODUCED_IN(30); @@ -213,10 +259,11 @@ int AImageDecoder_setTargetSize(AImageDecoder*, int32_t width, int32_t height) _ * 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 - * direction that the decoder can do most efficiently. + * in the direction that the decoder can do most efficiently. * @param height Out parameter for the height sampled by sampleSize, and rounded - * direction that the decoder can do most efficiently. - * @return ANDROID_IMAGE_DECODER result code. + * in the direction that the decoder can do most efficiently. + * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or + * {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER} for bad input. */ int AImageDecoder_computeSampledSize(const AImageDecoder*, int sampleSize, int32_t* width, int32_t* height) __INTRODUCED_IN(30); @@ -234,18 +281,21 @@ int AImageDecoder_computeSampledSize(const AImageDecoder*, int sampleSize, * 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 ANDROID_IMAGE_DECODER_BAD_PARAMETER. - * @return - {@link ANDROID_IMAGE_DECODER_SUCCESS} on success - * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER} if the AImageDecoder - * pointer is null or the crop is not contained by the image - * dimensions. + * returning {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER}. + * @return an enum describing whether the call succeeded. + * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or + * {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER} if the {@link AImageDecoder} + * pointer is null or the crop is not contained by the image + * dimensions. */ int AImageDecoder_setCrop(AImageDecoder*, ARect crop) __INTRODUCED_IN(30); +struct AImageDecoderHeaderInfo; /** - * Opaque handle for reading header info. + * Opaque handle for representing information about the encoded image. It can + * be passed to methods like {@link AImageDecoderHeaderInfo_getWidth} and + * {@link AImageDecoderHeaderInfo_getHeight}. */ -struct AImageDecoderHeaderInfo; typedef struct AImageDecoderHeaderInfo AImageDecoderHeaderInfo; /** @@ -258,12 +308,16 @@ const AImageDecoderHeaderInfo* AImageDecoder_getHeaderInfo( const AImageDecoder*) __INTRODUCED_IN(30); /** - * Report the native width of the encoded image. + * 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. */ int32_t AImageDecoderHeaderInfo_getWidth(const AImageDecoderHeaderInfo*) __INTRODUCED_IN(30); /** - * Report the native height of the encoded image. + * 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. */ int32_t AImageDecoderHeaderInfo_getHeight(const AImageDecoderHeaderInfo*) __INTRODUCED_IN(30); @@ -277,7 +331,7 @@ const char* AImageDecoderHeaderInfo_getMimeType( /** * Report the {@link AndroidBitmapFormat} the AImageDecoder will decode to - * by default. AImageDecoder will try to choose one that is sensible + * 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. */ @@ -285,18 +339,17 @@ int32_t AImageDecoderHeaderInfo_getAndroidBitmapFormat( const AImageDecoderHeaderInfo*) __INTRODUCED_IN(30); /** - * Report how the AImageDecoder will handle alpha by default. If the image + * 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}. - * - * For animated images only the opacity of the first frame is reported. + * this returns {@link ANDROID_BITMAP_FLAGS_ALPHA_PREMUL}, because + * {@link AImageDecoder_decodeImage} will premultiply pixels by default. */ int AImageDecoderHeaderInfo_getAlphaFlags( const AImageDecoderHeaderInfo*) __INTRODUCED_IN(30); /** - * Report the dataspace the AImageDecoder will decode to by default. + * Report the dataspace the {@link AImageDecoder} will decode to by default. * AImageDecoder will try to choose one that is sensible for the * image and the system. Note that this may not exactly match the ICC * profile (or other color information) stored in the encoded image. @@ -315,26 +368,35 @@ int32_t AImageDecoderHeaderInfo_getDataSpace( const AImageDecoderHeaderInfo*) __INTRODUCED_IN(30); /** - * Return the minimum stride that can be used, taking the specified - * (or default) (possibly scaled) width, crop rect and - * {@link AndroidBitmapFormat} into account. + * 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. */ size_t AImageDecoder_getMinimumStride(AImageDecoder*) __INTRODUCED_IN(30); /** - * Decode the image into pixels, using the settings of the AImageDecoder. + * Decode the image into pixels, using the settings of the {@link AImageDecoder}. * * @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 fit |size| bytes. + * 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}. + * {@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}. Must also be a multiple - * of the bytes per pixel of the {@link AndroidBitmapFormat}. + * {@link AImageDecoder_getMinimumStride}. * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success, or an error code * from the same enum describing the failure. + * {@link ANDROID_IMAGE_DECODER_INCOMPLETE} or + * {@link ANDROID_IMAGE_DECODER_ERROR} means that a partial image was + * decoded, and undecoded lines have been initialized to all zeroes. */ int AImageDecoder_decodeImage(AImageDecoder* decoder, void* pixels, size_t stride, -- cgit v1.2.3-59-g8ed1b From 8cee65ec1d67ee8ea0a40099a26e1f94c7b06feb Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Thu, 30 Jan 2020 14:20:42 -0500 Subject: AImageDecoder: update comments around dataspaces Bug: 135133301 Test: I5e8bdcdae6837db23c0f4ef08f931f3bebe0ce0d A companion change (I489f31fef79dec11e97c8e8fb9207adb77a3d0c7) makes AImageDecoder default to doing no color conversion. Update comments to reflect that. Change-Id: Icc3b0f101598ce98c458ff43597ee05b3662664c --- include/android/imagedecoder.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'include/android') diff --git a/include/android/imagedecoder.h b/include/android/imagedecoder.h index 6e5da52cb5..7437ab1093 100644 --- a/include/android/imagedecoder.h +++ b/include/android/imagedecoder.h @@ -349,20 +349,20 @@ int AImageDecoderHeaderInfo_getAlphaFlags( const AImageDecoderHeaderInfo*) __INTRODUCED_IN(30); /** - * Report the dataspace the {@link AImageDecoder} will decode to by default. - * AImageDecoder will try to choose one that is sensible for the - * image and the system. Note that this may not exactly match the ICC - * profile (or other color information) stored in the encoded image. + * Report the dataspace the AImageDecoder will decode to by default. * - * @return The {@link ADataSpace} most closely representing the way the colors - * are encoded (or {@link ADATASPACE_UNKNOWN} if there is not an - * approximate ADataSpace). This specifies how to interpret the colors + * By default, {@link AImageDecoder_decodeImage} will not do any color + * conversion. + * + * @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 - * ADATASPACE_UNKNOWN, even for Named ColorSpaces, if they have no - * corresponding ADataSpace. + * {@link ADATASPACE_UNKNOWN}, even for Named ColorSpaces, if they have + * no corresponding {@link ADataSpace}. */ int32_t AImageDecoderHeaderInfo_getDataSpace( const AImageDecoderHeaderInfo*) __INTRODUCED_IN(30); -- cgit v1.2.3-59-g8ed1b From 9cb2ffdb01895391be745e45b8b7078677099d35 Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Thu, 6 Feb 2020 11:16:54 -0500 Subject: Specify when AndroidBitmapInfo.flags were introduced Bug: 148954909 Test: Generate docs Change-Id: Ie9d65ed4ab108a9f756ee4e5ae431696be6500cc --- include/android/bitmap.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'include/android') diff --git a/include/android/bitmap.h b/include/android/bitmap.h index 571a5ca1ef..412fc6b53f 100644 --- a/include/android/bitmap.h +++ b/include/android/bitmap.h @@ -97,15 +97,21 @@ typedef struct { uint32_t stride; /** The bitmap pixel format. See {@link AndroidBitmapFormat} */ int32_t format; - /** Two bits are used to encode alpha. Use ANDROID_BITMAP_FLAGS_ALPHA_MASK - * and ANDROID_BITMAP_FLAGS_ALPHA_SHIFT to retrieve them. One bit is used - * to encode whether the Bitmap uses the HARDWARE Config. Use - * ANDROID_BITMAP_FLAGS_IS_HARDWARE to know.*/ + /** Bitfield containing information about the bitmap. + * + *

Two bits are used to encode alpha. Use {@link ANDROID_BITMAP_FLAGS_ALPHA_MASK} + * and {@link ANDROID_BITMAP_FLAGS_ALPHA_SHIFT} to retrieve them.

+ * + *

One bit is used to encode whether the Bitmap uses the HARDWARE Config. Use + * {@link ANDROID_BITMAP_FLAGS_IS_HARDWARE} to know.

+ * + *

These flags were introduced in API level 30.

+ */ 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, -- cgit v1.2.3-59-g8ed1b From bb5ffd2074fe150725eee7eb1f97d5814a2df249 Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Thu, 6 Feb 2020 11:45:16 -0500 Subject: AImageDecoder: respond to API review Bug: 148954890 Test: Generate docs List the formats supported. List the possible error codes that can be returned from each method and what it means. Change-Id: I192888c1d438db0308cc715ab7f4997543509e73 --- include/android/imagedecoder.h | 169 +++++++++++++++++++++++++++++++---------- 1 file changed, 128 insertions(+), 41 deletions(-) (limited to 'include/android') diff --git a/include/android/imagedecoder.h b/include/android/imagedecoder.h index 7437ab1093..3a87da0fee 100644 --- a/include/android/imagedecoder.h +++ b/include/android/imagedecoder.h @@ -20,9 +20,18 @@ * Functions for converting encoded images into RGBA pixels. * * Similar to the Java counterpart android.graphics.ImageDecoder, it can be used - * to decode images like PNG, JPEG, GIF, WEBP and HEIF. It has similar options - * for scaling, cropping, and choosing the output format. Unlike the Java API, - * which can create an android.graphics.Bitmap or + * to decode images in the following formats: + * - JPEG + * - PNG + * - GIF + * - WebP + * - BMP + * - ICO + * - WBMP + * - HEIF + * - Digital negatives (via the DNG SDK) + *

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 * Image decoder @@ -62,7 +71,7 @@ enum { */ ANDROID_IMAGE_DECODER_SUCCESS = 0, /** - * The input was incomplete. + * The input is incomplete. */ ANDROID_IMAGE_DECODER_INCOMPLETE = -1, /** @@ -80,7 +89,7 @@ enum { */ ANDROID_IMAGE_DECODER_INVALID_SCALE = -4, /** - * Some other parameter was bad. + * Some other parameter is invalid. */ ANDROID_IMAGE_DECODER_BAD_PARAMETER = -5, /** @@ -133,6 +142,19 @@ typedef struct AImageDecoder AImageDecoder; * 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); @@ -149,6 +171,19 @@ int AImageDecoder_createFromAAsset(struct AAsset* asset, AImageDecoder** outDeco * 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); @@ -163,7 +198,19 @@ int AImageDecoder_createFromFd(int fd, AImageDecoder** outDecoder) __INTRODUCED_ * 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 reason for the failure. + * 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); @@ -177,11 +224,18 @@ void AImageDecoder_delete(AImageDecoder* decoder) __INTRODUCED_IN(30); * Choose the desired output format. * * @param format {@link AndroidBitmapFormat} to use for the output. - * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} if the format is compatible - * with the image and {@link ANDROID_IMAGE_DECODER_INVALID_CONVERSION} - * otherwise. In the latter case, the {@link AImageDecoder} uses the - * format it was already planning to use (either its default - * or a previously successful setting from this function). + * @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); @@ -194,11 +248,15 @@ int AImageDecoder_setAndroidBitmapFormat(AImageDecoder*, * opaque image. * * @param unpremultipliedRequired Pass true to leave the pixels unpremultiplied. - * @return an enum describing whether the call succeeded. - * - {@link ANDROID_IMAGE_DECODER_SUCCESS} on success - * - {@link ANDROID_IMAGE_DECODER_INVALID_CONVERSION} if the conversion - * is not possible - * - {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER} for bad parameters + * @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); @@ -215,10 +273,13 @@ int AImageDecoder_setUnpremultipliedRequired(AImageDecoder*, * {@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 - * {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER} for a null - * {@link AImageDecoder} or an integer that does not correspond to an - * {@link ADataSpace} value. + * @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); @@ -236,11 +297,16 @@ int AImageDecoder_setDataSpace(AImageDecoder*, int32_t dataspace) __INTRODUCED_I * {@link AImageDecoder_getMinimumStride}, which will now return * a value based on this width. * @param height Height of the output (prior to cropping). - * @return an enum describing whether the call succeeded. - * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or - * {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER} if the {@link AImageDecoder} - * pointer is null, width or height is <= 0, or any existing crop is - * not contained by the new image dimensions. + * @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); @@ -262,8 +328,12 @@ int AImageDecoder_setTargetSize(AImageDecoder*, int32_t width, int32_t height) _ * 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 - * {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER} for bad input. + * @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); @@ -282,18 +352,21 @@ int AImageDecoder_computeSampledSize(const AImageDecoder*, int sampleSize, * 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 an enum describing whether the call succeeded. - * @return {@link ANDROID_IMAGE_DECODER_SUCCESS} on success or - * {@link ANDROID_IMAGE_DECODER_BAD_PARAMETER} if the {@link AImageDecoder} - * pointer is null or the crop is not contained by the image - * dimensions. + * @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. It can - * be passed to methods like {@link AImageDecoderHeaderInfo_getWidth} and + * 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; @@ -310,14 +383,16 @@ const AImageDecoderHeaderInfo* AImageDecoder_getHeaderInfo( /** * 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. + * used to choose a different size or {@link AImageDecoder_setCrop} is used to + * set a crop rect. */ 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. + * used to choose a different size or {@link AImageDecoder_setCrop} is used to + * set a crop rect. */ int32_t AImageDecoderHeaderInfo_getHeight(const AImageDecoderHeaderInfo*) __INTRODUCED_IN(30); @@ -392,11 +467,23 @@ size_t AImageDecoder_getMinimumStride(AImageDecoder*) __INTRODUCED_IN(30); * @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 an error code - * from the same enum describing the failure. - * {@link ANDROID_IMAGE_DECODER_INCOMPLETE} or - * {@link ANDROID_IMAGE_DECODER_ERROR} means that a partial image was - * decoded, and undecoded lines have been initialized to all zeroes. + * @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, -- cgit v1.2.3-59-g8ed1b From 4883c52b940bbfa4f396c8432a25bed5e5e6d51b Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Thu, 30 Jan 2020 15:10:11 -0500 Subject: Fix docs for bitmap.h Bug: 135133301 Test: Generate docs - Fix errors in bitmap documentation. - Add links where relevant. - Move comment in sensor.h so it will apply to the module, and not AHardwareBuffer. Change-Id: Iec00725522e74eccab9346665562081211a870eb --- include/android/bitmap.h | 26 +++++++++++++------------- include/android/sensor.h | 9 +++------ 2 files changed, 16 insertions(+), 19 deletions(-) (limited to 'include/android') diff --git a/include/android/bitmap.h b/include/android/bitmap.h index 412fc6b53f..727a4af2f9 100644 --- a/include/android/bitmap.h +++ b/include/android/bitmap.h @@ -81,8 +81,8 @@ enum { enum { /** If this bit is set in AndroidBitmapInfo.flags, the Bitmap uses the - * HARDWARE Config, and its AHardwareBuffer can be retrieved via - * AndroidBitmap_getHardwareBuffer. + * HARDWARE Config, and its {@link AHardwareBuffer} can be retrieved via + * {@link AndroidBitmap_getHardwareBuffer}. */ ANDROID_BITMAP_FLAGS_IS_HARDWARE = 1 << 31, }; @@ -120,10 +120,10 @@ int AndroidBitmap_getInfo(JNIEnv* env, jobject jbitmap, #if __ANDROID_API__ >= 30 /** - * Given a java bitmap object, return its ADataSpace. + * Given a java bitmap object, return its {@link ADataSpace}. * - * Note that ADataSpace only exposes a few values. This may return - * ADATASPACE_UNKNOWN, even for Named ColorSpaces, if they have no + * 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. */ int32_t AndroidBitmap_getDataSpace(JNIEnv* env, jobject jbitmap) __INTRODUCED_IN(30); @@ -206,17 +206,17 @@ typedef bool (*AndroidBitmap_CompressWriteFunc)(void* userContext, * @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 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. - * @parm 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. + * @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, @@ -235,11 +235,11 @@ struct AHardwareBuffer; * * @param bitmap Handle to an android.graphics.Bitmap. * @param outBuffer On success, is set to a pointer to the - * AHardwareBuffer associated with bitmap. This acquires + * {@link AHardwareBuffer} associated with bitmap. This acquires * a reference on the buffer, and the client must call - * AHardwareBuffer_release when finished with it. + * {@link AHardwareBuffer_release} when finished with it. * @return AndroidBitmap functions result code. - * ANDROID_BITMAP_RESULT_BAD_PARAMETER if bitmap is not a + * {@link ANDROID_BITMAP_RESULT_BAD_PARAMETER} if bitmap is not a * HARDWARE Bitmap. */ int AndroidBitmap_getHardwareBuffer(JNIEnv* env, jobject bitmap, diff --git a/include/android/sensor.h b/include/android/sensor.h index 12c00ad8a2..e63ac4b407 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 #include -- cgit v1.2.3-59-g8ed1b From d7a703c592bb8f57964f5b56b0a8111049458f81 Mon Sep 17 00:00:00 2001 From: Anthony Stange Date: Tue, 18 Feb 2020 12:02:22 -0500 Subject: Add hinge angle sensor enum docs Bug: 148954908 Test: N/A Change-Id: I1c75bdf8b0fcaad4128336dbe4515e10ff570235 --- include/android/sensor.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include/android') diff --git a/include/android/sensor.h b/include/android/sensor.h index e63ac4b407..eb407794d1 100644 --- a/include/android/sensor.h +++ b/include/android/sensor.h @@ -244,6 +244,9 @@ enum { 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, }; -- cgit v1.2.3-59-g8ed1b From 62a4cf8c48647de3442808264005e093ab7704f0 Mon Sep 17 00:00:00 2001 From: Steven Thomas Date: Fri, 31 Jan 2020 12:04:03 -0800 Subject: Add compatibility param to setFrameRate() api Add a compatiblity param to the setFrameRate() api, so the system has more info to decide the device frame rate when there are multiple competing preferences. I also changed the plumbing for setFrameRate() to go directly to surface flinger, instead of through buffer queue. We're trying to avoid changes to buffer queue code, to avoid disturbing the prebuilts. Bug: 137287430 Test: Added new cts tests to verify behavior of the compatibility param. cts-tradefed run commandAndExit cts-dev --module CtsGraphicsTestCases --test android.graphics.cts.SetFrameRateTest Test: /data/nativetest64/SurfaceFlinger_test/SurfaceFlinger_test --gtest_filter='SetFrameRateTest.*' Change-Id: Ibe75a778fb459d4138a1446c1b38b44798b56a99 --- include/android/surface_control.h | 9 ++- libs/gui/ISurfaceComposer.cpp | 66 ++++++++++++++++++++++ libs/gui/LayerState.cpp | 22 ++++++++ libs/gui/Surface.cpp | 16 ++++-- libs/gui/SurfaceComposerClient.cpp | 7 ++- libs/gui/include/gui/ISurfaceComposer.h | 7 +++ libs/gui/include/gui/LayerState.h | 15 ++++- libs/gui/include/gui/Surface.h | 2 +- libs/gui/include/gui/SurfaceComposerClient.h | 3 +- libs/gui/tests/Surface_test.cpp | 5 ++ libs/nativewindow/ANativeWindow.cpp | 6 +- libs/nativewindow/include/android/native_window.h | 29 +++++++++- libs/nativewindow/include/system/window.h | 6 +- libs/nativewindow/libnativewindow.map.txt | 2 +- services/surfaceflinger/BufferQueueLayer.cpp | 13 ----- services/surfaceflinger/BufferQueueLayer.h | 5 -- services/surfaceflinger/Layer.cpp | 13 +++++ services/surfaceflinger/Layer.h | 6 +- services/surfaceflinger/Scheduler/LayerHistory.cpp | 1 - services/surfaceflinger/SurfaceFlinger.cpp | 35 +++++++++++- services/surfaceflinger/SurfaceFlinger.h | 2 + .../surfaceflinger/tests/SetFrameRate_test.cpp | 14 +++-- 22 files changed, 236 insertions(+), 48 deletions(-) (limited to 'include/android') diff --git a/include/android/surface_control.h b/include/android/surface_control.h index eeb8330efd..c30dcfee09 100644 --- a/include/android/surface_control.h +++ b/include/android/surface_control.h @@ -425,12 +425,15 @@ void ASurfaceTransaction_setHdrMetadata_cta861_3(ASurfaceTransaction* transactio * 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) - __INTRODUCED_IN(30); + ASurfaceControl* surface_control, float frameRate, + int8_t compatibility) __INTRODUCED_IN(30); #endif // __ANDROID_API__ >= 30 diff --git a/libs/gui/ISurfaceComposer.cpp b/libs/gui/ISurfaceComposer.cpp index 2f27fd20fd..ce41eaba1d 100644 --- a/libs/gui/ISurfaceComposer.cpp +++ b/libs/gui/ISurfaceComposer.cpp @@ -1112,6 +1112,42 @@ public: } return NO_ERROR; } + + virtual status_t setFrameRate(const sp& surface, float frameRate, + int8_t compatibility) { + Parcel data, reply; + status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); + if (err != NO_ERROR) { + ALOGE("setFrameRate: failed writing interface token: %s (%d)", strerror(-err), -err); + return err; + } + + err = data.writeStrongBinder(IInterface::asBinder(surface)); + if (err != NO_ERROR) { + ALOGE("setFrameRate: failed writing strong binder: %s (%d)", strerror(-err), -err); + return err; + } + + err = data.writeFloat(frameRate); + if (err != NO_ERROR) { + ALOGE("setFrameRate: failed writing float: %s (%d)", strerror(-err), -err); + return err; + } + + err = data.writeByte(compatibility); + if (err != NO_ERROR) { + ALOGE("setFrameRate: failed writing byte: %s (%d)", strerror(-err), -err); + return err; + } + + err = remote()->transact(BnSurfaceComposer::SET_FRAME_RATE, data, &reply, + IBinder::FLAG_ONEWAY); + if (err != NO_ERROR) { + ALOGE("setFrameRate: failed to transact: %s (%d)", strerror(-err), err); + return err; + } + return NO_ERROR; + } }; // Out-of-line virtual method definition to trigger vtable emission in this @@ -1877,6 +1913,36 @@ status_t BnSurfaceComposer::onTransact( return setGlobalShadowSettings(ambientColor, spotColor, lightPosY, lightPosZ, lightRadius); } + case SET_FRAME_RATE: { + CHECK_INTERFACE(ISurfaceComposer, data, reply); + sp binder; + status_t err = data.readStrongBinder(&binder); + if (err != NO_ERROR) { + ALOGE("setFrameRate: failed to read strong binder: %s (%d)", strerror(-err), -err); + return err; + } + sp surface = interface_cast(binder); + if (!surface) { + ALOGE("setFrameRate: failed to cast to IGraphicBufferProducer: %s (%d)", + strerror(-err), -err); + return err; + } + float frameRate; + err = data.readFloat(&frameRate); + if (err != NO_ERROR) { + ALOGE("setFrameRate: failed to read float: %s (%d)", strerror(-err), -err); + return err; + } + int8_t compatibility; + err = data.readByte(&compatibility); + if (err != NO_ERROR) { + ALOGE("setFrameRate: failed to read byte: %s (%d)", strerror(-err), -err); + return err; + } + status_t result = setFrameRate(surface, frameRate, compatibility); + reply->writeInt32(result); + return NO_ERROR; + } default: { return BBinder::onTransact(code, data, reply, flags); } diff --git a/libs/gui/LayerState.cpp b/libs/gui/LayerState.cpp index 5547efc3ad..a9c9b7460b 100644 --- a/libs/gui/LayerState.cpp +++ b/libs/gui/LayerState.cpp @@ -24,6 +24,8 @@ #include #include +#include + namespace android { status_t layer_state_t::write(Parcel& output) const @@ -113,6 +115,7 @@ status_t layer_state_t::write(Parcel& output) const output.writeFloat(shadowRadius); output.writeInt32(frameRateSelectionPriority); output.writeFloat(frameRate); + output.writeByte(frameRateCompatibility); return NO_ERROR; } @@ -194,6 +197,7 @@ status_t layer_state_t::read(const Parcel& input) shadowRadius = input.readFloat(); frameRateSelectionPriority = input.readInt32(); frameRate = input.readFloat(); + frameRateCompatibility = input.readByte(); return NO_ERROR; } @@ -427,6 +431,7 @@ void layer_state_t::merge(const layer_state_t& other) { if (other.what & eFrameRateChanged) { what |= eFrameRateChanged; frameRate = other.frameRate; + frameRateCompatibility = other.frameRateCompatibility; } if ((other.what & what) != other.what) { ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? " @@ -474,4 +479,21 @@ void InputWindowCommands::read(const Parcel& input) { syncInputWindows = input.readBool(); } +bool ValidateFrameRate(float frameRate, int8_t compatibility, const char* inFunctionName) { + const char* functionName = inFunctionName != nullptr ? inFunctionName : "call"; + int floatClassification = std::fpclassify(frameRate); + if (frameRate < 0 || floatClassification == FP_INFINITE || floatClassification == FP_NAN) { + ALOGE("%s failed - invalid frame rate %f", functionName, frameRate); + return false; + } + + if (compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT && + compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE) { + ALOGE("%s failed - invalid compatibility value %d", functionName, compatibility); + return false; + } + + return true; +} + }; // namespace android diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp index 278cc593b7..f911e70ebf 100644 --- a/libs/gui/Surface.cpp +++ b/libs/gui/Surface.cpp @@ -43,6 +43,7 @@ #include #include +#include #include namespace android { @@ -1413,7 +1414,8 @@ int Surface::dispatchGetLastQueueDuration(va_list args) { int Surface::dispatchSetFrameRate(va_list args) { float frameRate = static_cast(va_arg(args, double)); - return setFrameRate(frameRate); + int8_t compatibility = static_cast(va_arg(args, int)); + return setFrameRate(frameRate, compatibility); } int Surface::dispatchAddCancelInterceptor(va_list args) { @@ -2222,11 +2224,15 @@ void Surface::ProducerListenerProxy::onBuffersDiscarded(const std::vectoronBuffersDiscarded(discardedBufs); } -status_t Surface::setFrameRate(float frameRate) { +status_t Surface::setFrameRate(float frameRate, int8_t compatibility) { ATRACE_CALL(); - ALOGV("Surface::setTargetFrameRate"); - Mutex::Autolock lock(mMutex); - return mGraphicBufferProducer->setFrameRate(frameRate); + ALOGV("Surface::setFrameRate"); + + if (!ValidateFrameRate(frameRate, compatibility, "Surface::setFrameRate")) { + return BAD_VALUE; + } + + return composerService()->setFrameRate(mGraphicBufferProducer, frameRate, compatibility); } }; // namespace android diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp index 7017b7c8f3..7f28c6c230 100644 --- a/libs/gui/SurfaceComposerClient.cpp +++ b/libs/gui/SurfaceComposerClient.cpp @@ -1402,14 +1402,19 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setShado } SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFrameRate( - const sp& sc, float frameRate) { + const sp& sc, float frameRate, int8_t compatibility) { layer_state_t* s = getLayerState(sc); if (!s) { mStatus = BAD_INDEX; return *this; } + if (!ValidateFrameRate(frameRate, compatibility, "Transaction::setFrameRate")) { + mStatus = BAD_VALUE; + return *this; + } s->what |= layer_state_t::eFrameRateChanged; s->frameRate = frameRate; + s->frameRateCompatibility = compatibility; return *this; } diff --git a/libs/gui/include/gui/ISurfaceComposer.h b/libs/gui/include/gui/ISurfaceComposer.h index e860f61c22..0659f0de06 100644 --- a/libs/gui/include/gui/ISurfaceComposer.h +++ b/libs/gui/include/gui/ISurfaceComposer.h @@ -500,6 +500,12 @@ public: virtual status_t setGlobalShadowSettings(const half4& ambientColor, const half4& spotColor, float lightPosY, float lightPosZ, float lightRadius) = 0; + + /* + * Sets the intended frame rate for a surface. See ANativeWindow_setFrameRate() for more info. + */ + virtual status_t setFrameRate(const sp& surface, float frameRate, + int8_t compatibility) = 0; }; // ---------------------------------------------------------------------------- @@ -557,6 +563,7 @@ public: SET_AUTO_LOW_LATENCY_MODE, GET_GAME_CONTENT_TYPE_SUPPORT, SET_GAME_CONTENT_TYPE, + SET_FRAME_RATE, // Always append new enum to the end. }; diff --git a/libs/gui/include/gui/LayerState.h b/libs/gui/include/gui/LayerState.h index 2d53b48475..7e3d5d50d3 100644 --- a/libs/gui/include/gui/LayerState.h +++ b/libs/gui/include/gui/LayerState.h @@ -20,8 +20,7 @@ #include #include -#include - +#include #include #include #include @@ -36,6 +35,7 @@ #include #include #include +#include namespace android { @@ -135,7 +135,8 @@ struct layer_state_t { colorSpaceAgnostic(false), shadowRadius(0.0f), frameRateSelectionPriority(-1), - frameRate(0.0f) { + frameRate(0.0f), + frameRateCompatibility(ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT) { matrix.dsdx = matrix.dtdy = 1.0f; matrix.dsdy = matrix.dtdx = 0.0f; hdrMetadata.validTypes = 0; @@ -221,7 +222,9 @@ struct layer_state_t { // Priority of the layer assigned by Window Manager. int32_t frameRateSelectionPriority; + // Layer frame rate and compatibility. See ANativeWindow_setFrameRate(). float frameRate; + int8_t frameRateCompatibility; }; struct ComposerState { @@ -292,6 +295,12 @@ static inline int compare_type(const DisplayState& lhs, const DisplayState& rhs) return compare_type(lhs.token, rhs.token); } +// Returns true if the frameRate and compatibility are valid values, false +// othwerise. If either of the params are invalid, an error log is printed, and +// functionName is added to the log to indicate which function call failed. +// functionName can be null. +bool ValidateFrameRate(float frameRate, int8_t compatibility, const char* functionName); + }; // namespace android #endif // ANDROID_SF_LAYER_STATE_H diff --git a/libs/gui/include/gui/Surface.h b/libs/gui/include/gui/Surface.h index 4a353fc659..ad7cbfe914 100644 --- a/libs/gui/include/gui/Surface.h +++ b/libs/gui/include/gui/Surface.h @@ -179,7 +179,7 @@ public: status_t getConsumerUsage(uint64_t* outUsage) const; // See IGraphicBufferProducer::setFrameRate - status_t setFrameRate(float frameRate); + status_t setFrameRate(float frameRate, int8_t compatibility); protected: virtual ~Surface(); diff --git a/libs/gui/include/gui/SurfaceComposerClient.h b/libs/gui/include/gui/SurfaceComposerClient.h index d0bb6a39ec..fe3dec5ee5 100644 --- a/libs/gui/include/gui/SurfaceComposerClient.h +++ b/libs/gui/include/gui/SurfaceComposerClient.h @@ -525,7 +525,8 @@ public: const Rect& source, const Rect& dst, int transform); Transaction& setShadowRadius(const sp& sc, float cornerRadius); - Transaction& setFrameRate(const sp& sc, float frameRate); + Transaction& setFrameRate(const sp& sc, float frameRate, + int8_t compatibility); status_t setDisplaySurface(const sp& token, const sp& bufferProducer); diff --git a/libs/gui/tests/Surface_test.cpp b/libs/gui/tests/Surface_test.cpp index 70fd888aaf..8c0f8f8de9 100644 --- a/libs/gui/tests/Surface_test.cpp +++ b/libs/gui/tests/Surface_test.cpp @@ -854,6 +854,11 @@ public: return NO_ERROR; } + status_t setFrameRate(const sp& /*surface*/, float /*frameRate*/, + int8_t /*compatibility*/) override { + return NO_ERROR; + } + protected: IBinder* onAsBinder() override { return nullptr; } diff --git a/libs/nativewindow/ANativeWindow.cpp b/libs/nativewindow/ANativeWindow.cpp index 98b76fd667..f09decf21a 100644 --- a/libs/nativewindow/ANativeWindow.cpp +++ b/libs/nativewindow/ANativeWindow.cpp @@ -158,11 +158,11 @@ int32_t ANativeWindow_getBuffersDataSpace(ANativeWindow* window) { return query(window, NATIVE_WINDOW_DATASPACE); } -int32_t ANativeWindow_setFrameRate(ANativeWindow* window, float frameRate) { - if (!window || !query(window, NATIVE_WINDOW_IS_VALID) || frameRate < 0) { +int32_t ANativeWindow_setFrameRate(ANativeWindow* window, float frameRate, int8_t compatibility) { + if (!window || !query(window, NATIVE_WINDOW_IS_VALID)) { return -EINVAL; } - return native_window_set_frame_rate(window, frameRate); + return native_window_set_frame_rate(window, frameRate, compatibility); } void ANativeWindow_tryAllocateBuffers(ANativeWindow* window) { diff --git a/libs/nativewindow/include/android/native_window.h b/libs/nativewindow/include/android/native_window.h index 4b426c518a..59aa6655b8 100644 --- a/libs/nativewindow/include/android/native_window.h +++ b/libs/nativewindow/include/android/native_window.h @@ -33,6 +33,7 @@ #ifndef ANDROID_NATIVE_WINDOW_H #define ANDROID_NATIVE_WINDOW_H +#include #include #include @@ -232,6 +233,24 @@ int32_t ANativeWindow_getBuffersDataSpace(ANativeWindow* window) __INTRODUCED_IN #if __ANDROID_API__ >= 30 +/* Parameter for ANativeWindow_setFrameRate */ +enum { + /** + * There are no inherent restrictions on the frame rate of this window. + */ + ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT = 0, + /** + * This window is being used to display content with an inherently fixed + * frame rate, e.g. a video that has a specific frame rate. When the system + * selects a frame rate other than what the app requested, the app will need + * to do pull down or use some other technique to adapt to the system's + * frame rate. The user experience is likely to be worse (e.g. more frame + * stuttering) than it would be if the system had chosen the app's requested + * frame rate. + */ + ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE = 1 +}; + /** * Sets the intended frame rate for this window. * @@ -257,9 +276,15 @@ int32_t ANativeWindow_getBuffersDataSpace(ANativeWindow* window) __INTRODUCED_IN * 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. * - * \return 0 for success, -EINVAL if the window or frame rate are invalid. + * \param compatibility The frame rate compatibility of this window. The + * compatibility value may influence the system's choice of display refresh + * rate. See the ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_* values for more info. + * + * \return 0 for success, -EINVAL if the window, frame rate, or compatibility + * value are invalid. */ -int32_t ANativeWindow_setFrameRate(ANativeWindow* window, float frameRate) __INTRODUCED_IN(30); +int32_t ANativeWindow_setFrameRate(ANativeWindow* window, float frameRate, int8_t compatibility) + __INTRODUCED_IN(30); /** * Provides a hint to the window that buffers should be preallocated ahead of diff --git a/libs/nativewindow/include/system/window.h b/libs/nativewindow/include/system/window.h index f686147a5f..0e28fb84ca 100644 --- a/libs/nativewindow/include/system/window.h +++ b/libs/nativewindow/include/system/window.h @@ -1015,8 +1015,10 @@ static inline int native_window_set_auto_prerotation(struct ANativeWindow* windo return window->perform(window, NATIVE_WINDOW_SET_AUTO_PREROTATION, autoPrerotation); } -static inline int native_window_set_frame_rate(struct ANativeWindow* window, float frameRate) { - return window->perform(window, NATIVE_WINDOW_SET_FRAME_RATE, (double)frameRate); +static inline int native_window_set_frame_rate(struct ANativeWindow* window, float frameRate, + int8_t compatibility) { + return window->perform(window, NATIVE_WINDOW_SET_FRAME_RATE, (double)frameRate, + (int)compatibility); } // ------------------------------------------------------------------------------------------------ diff --git a/libs/nativewindow/libnativewindow.map.txt b/libs/nativewindow/libnativewindow.map.txt index 154eb8eb52..e072e1145d 100644 --- a/libs/nativewindow/libnativewindow.map.txt +++ b/libs/nativewindow/libnativewindow.map.txt @@ -46,9 +46,9 @@ LIBNATIVEWINDOW { ANativeWindow_setBuffersTimestamp; # llndk ANativeWindow_setBuffersTransform; ANativeWindow_setDequeueTimeout; # apex # introduced=30 + ANativeWindow_setFrameRate; # introduced=30 ANativeWindow_setSharedBufferMode; # llndk ANativeWindow_setSwapInterval; # llndk - ANativeWindow_setFrameRate; # introduced=30 ANativeWindow_setUsage; # llndk ANativeWindow_tryAllocateBuffers; # introduced=30 ANativeWindow_unlockAndPost; diff --git a/services/surfaceflinger/BufferQueueLayer.cpp b/services/surfaceflinger/BufferQueueLayer.cpp index e65064bebf..f5a99cadd7 100644 --- a/services/surfaceflinger/BufferQueueLayer.cpp +++ b/services/surfaceflinger/BufferQueueLayer.cpp @@ -124,18 +124,6 @@ bool BufferQueueLayer::shouldPresentNow(nsecs_t expectedPresentTime) const { return isDue || !isPlausible; } -bool BufferQueueLayer::setFrameRate(FrameRate frameRate) { - float oldFrameRate = 0.f; - status_t result = mConsumer->getFrameRate(&oldFrameRate); - bool frameRateChanged = result < 0 || frameRate.rate != oldFrameRate; - mConsumer->setFrameRate(frameRate.rate); - return frameRateChanged; -} - -Layer::FrameRate BufferQueueLayer::getFrameRate() const { - return FrameRate(mLatchedFrameRate, Layer::FrameRateCompatibility::Default); -} - // ----------------------------------------------------------------------- // Interface implementation for BufferLayer // ----------------------------------------------------------------------- @@ -578,7 +566,6 @@ void BufferQueueLayer::gatherBufferInfo() { mBufferInfo.mTransformToDisplayInverse = mConsumer->getTransformToDisplayInverse(); float latchedFrameRate; mConsumer->getFrameRate(&latchedFrameRate); - mLatchedFrameRate = latchedFrameRate; } sp BufferQueueLayer::createClone() { diff --git a/services/surfaceflinger/BufferQueueLayer.h b/services/surfaceflinger/BufferQueueLayer.h index 626af4b6f1..5f7587c547 100644 --- a/services/surfaceflinger/BufferQueueLayer.h +++ b/services/surfaceflinger/BufferQueueLayer.h @@ -56,9 +56,6 @@ public: bool shouldPresentNow(nsecs_t expectedPresentTime) const override; - bool setFrameRate(FrameRate frameRate) override; - FrameRate getFrameRate() const override; - // ----------------------------------------------------------------------- // ----------------------------------------------------------------------- @@ -155,8 +152,6 @@ private: std::atomic mSidebandStreamChanged{false}; sp mContentsChangedListener; - - std::atomic mLatchedFrameRate = 0.f; }; } // namespace android diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp index da26a374db..d7647d76d3 100644 --- a/services/surfaceflinger/Layer.cpp +++ b/services/surfaceflinger/Layer.cpp @@ -26,6 +26,7 @@ #include "Layer.h" #include +#include #include #include #include @@ -2446,6 +2447,18 @@ void Layer::addChildToDrawing(const sp& layer) { layer->mDrawingParent = this; } +Layer::FrameRateCompatibility Layer::FrameRate::convertCompatibility(int8_t compatibility) { + switch (compatibility) { + case ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT: + return FrameRateCompatibility::Default; + case ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE: + return FrameRateCompatibility::ExactOrMultiple; + default: + LOG_ALWAYS_FATAL("Invalid frame rate compatibility value %d", compatibility); + return FrameRateCompatibility::Default; + } +} + // --------------------------------------------------------------------------- }; // namespace android diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h index 37ae340653..5d2144aed4 100644 --- a/services/surfaceflinger/Layer.h +++ b/services/surfaceflinger/Layer.h @@ -161,6 +161,10 @@ public: } bool operator!=(const FrameRate& other) const { return !(*this == other); } + + // Convert an ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_* value to a + // Layer::FrameRateCompatibility. Logs fatal if the compatibility value is invalid. + static FrameRateCompatibility convertCompatibility(int8_t compatibility); }; struct State { @@ -795,7 +799,7 @@ public: */ Rect getCroppedBufferSize(const Layer::State& s) const; - virtual bool setFrameRate(FrameRate frameRate); + bool setFrameRate(FrameRate frameRate); virtual FrameRate getFrameRate() const; protected: diff --git a/services/surfaceflinger/Scheduler/LayerHistory.cpp b/services/surfaceflinger/Scheduler/LayerHistory.cpp index b313777253..b851fc6ebb 100644 --- a/services/surfaceflinger/Scheduler/LayerHistory.cpp +++ b/services/surfaceflinger/Scheduler/LayerHistory.cpp @@ -179,4 +179,3 @@ void LayerHistory::clear() { mActiveLayersEnd = 0; } } // namespace android::scheduler::impl - diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index a98ff4fe7c..2701c3e6c9 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -34,6 +34,8 @@ #include #include +#include + #include #include @@ -58,6 +60,7 @@ #include #include #include +#include #include #include

To use:

    + *
  • Create a new thermal manager instance by calling the + * {@link AThermal_acquireManager} function.
  • + *
  • Get current thermal status with + * {@link AThermal_getCurrentThermalStatus}.
  • + *
  • Register a thermal status listener with + * {@link AThermal_registerThermalStatusListener}.
  • + *
  • Unregister a thermal status listener with + * {@link AThermal_unregisterThermalStatusListener}.
  • + *
  • Release the thermal manager instance with + * {@link AThermal_releaseManager}.

+ * + */ +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 int (*AThermal_StatusCallback)(void *data, AThermalStatus status); + +/** + * Acquire an instance of the thermal manager. This must be freed using + * {@link AThermal_releaseManager}. + * + * @return manager instance on success, nullptr on failure. + */ +AThermalManager* AThermal_acquireManager(); + +/** + * Release the thermal manager pointer acquired via + * {@link AThermal_acquireManager}. + * + * @param manager The manager to be released. + * + */ +void AThermal_releaseManager(AThermalManager *manager); + +/** + * Gets the current thermal status. + * + * @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); + +/** + * Register the thermal status listener for thermal status change. + * + * @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); + +/** + * Unregister the thermal status listener previously resgistered. + * + * @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); + + +#endif // __ANDROID_API__ >= 30 + +#ifdef __cplusplus +} +#endif + +#endif // _ANDROID_THERMAL_H + +/** @} */ diff --git a/include/powermanager/PowerManager.h b/include/powermanager/PowerManager.h index 3268b45716..9bac242a12 100644 --- a/include/powermanager/PowerManager.h +++ b/include/powermanager/PowerManager.h @@ -33,6 +33,17 @@ enum { USER_ACTIVITY_EVENT_LAST = USER_ACTIVITY_EVENT_ACCESSIBILITY, // Last valid event code. }; +/** Keep in sync with android.os.temprature and hardware/interfaces/thermal/2.0/types.hal */ +enum class ThermalStatus : uint32_t { + THERMAL_STATUS_NONE = 0, + THERMAL_STATUS_LIGHT = 1, + THERMAL_STATUS_MODERATE = 2, + THERMAL_STATUS_SEVERE = 3, + THERMAL_STATUS_CRITICAL = 4, + THERMAL_STATUS_EMERGENCY = 5, + THERMAL_STATUS_SHUTDOWN = 6, +}; + }; // namespace android #endif // ANDROID_POWERMANAGER_H diff --git a/services/powermanager/Android.bp b/services/powermanager/Android.bp index 7b3af70927..3e0f136dfb 100644 --- a/services/powermanager/Android.bp +++ b/services/powermanager/Android.bp @@ -1,11 +1,25 @@ cc_library_shared { name: "libpowermanager", - srcs: ["IPowerManager.cpp"], + srcs: [ + "IPowerManager.cpp", + "Temperature.cpp", + "CoolingDevice.cpp", + ":libpowermanager_aidl", + ], + + aidl: { + local_include_dirs: ["."], + include_dirs: [ + "frameworks/base/core/java/android/os", + ], + export_aidl_headers: true + }, shared_libs: [ "libutils", "libbinder", + "liblog" ], cflags: [ @@ -15,3 +29,22 @@ cc_library_shared { "-Wunreachable-code", ], } + +cc_test { + name: "thermalmanager-test", + srcs: ["IThermalManagerTest.cpp", + ], + cflags: [ + "-Wall", + "-Werror", + "-Wextra", + ], + shared_libs: [ + "libbase", + "libhidlbase", + "liblog", + "libpowermanager", + "libbinder", + "libutils", + ], +} diff --git a/services/powermanager/CoolingDevice.cpp b/services/powermanager/CoolingDevice.cpp new file mode 100644 index 0000000000..ebbc1b4197 --- /dev/null +++ b/services/powermanager/CoolingDevice.cpp @@ -0,0 +1,53 @@ +/* + * 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. + */ + +#define LOG_TAG "CoolingDevice" + +#include +#include +#include + +namespace android { +namespace os { + +status_t CoolingDevice::readFromParcel(const android::Parcel *parcel) { + if (parcel == nullptr) { + ALOGE("%s: Null parcel", __FUNCTION__); + return BAD_VALUE; + } + + parcel->readFloat(&mValue); + parcel->readUint32(&mType); + parcel->readString16(&mName); + + return OK; +} + +status_t CoolingDevice::writeToParcel(android::Parcel *parcel) const { + if (parcel == nullptr) { + ALOGE("%s: Null parcel", __FUNCTION__); + return BAD_VALUE; + } + + parcel->writeFloat(mValue); + parcel->writeUint32(mType); + parcel->writeString16(mName); + + return OK; +} + +} // namespace os +} // namespace android \ No newline at end of file diff --git a/services/powermanager/IThermalManagerTest.cpp b/services/powermanager/IThermalManagerTest.cpp new file mode 100644 index 0000000000..575b9ee1c4 --- /dev/null +++ b/services/powermanager/IThermalManagerTest.cpp @@ -0,0 +1,158 @@ +/* + * 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. + */ + +#define LOG_TAG "ThermalManagerTest" +//#define LOG_NDEBUG 0 + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace android; +using namespace android::os; +using namespace std::chrono_literals; + +class IThermalServiceTest : public testing::Test, + public BnThermalStatusListener{ + public: + IThermalServiceTest(); + void setThermalOverride(int level); + virtual binder::Status onStatusChange(int status) override; + int getStatusFromService(); + void SetUp() override; + void TearDown() override; + protected: + sp mThermalSvc; + std::condition_variable mCondition; + int mListenerStatus; + int mServiceStatus; + std::mutex mMutex; +}; + +IThermalServiceTest::IThermalServiceTest() + : mListenerStatus(0), + mServiceStatus(0) { +} + +void IThermalServiceTest::setThermalOverride(int level) { + std::string cmdStr = "cmd thermalservice override-status " + std::to_string(level); + system(cmdStr.c_str()); +} + +binder::Status IThermalServiceTest::onStatusChange(int status) { + std::unique_lock lock(mMutex); + mListenerStatus = status; + ALOGI("IThermalServiceTest::notifyListener %d", mListenerStatus); + mCondition.notify_all(); + return binder::Status::ok(); +} + +int IThermalServiceTest::getStatusFromService() { + int status; + binder::Status ret = mThermalSvc->getCurrentThermalStatus(&status); + if (ret.isOk()) { + return status; + } else { + return BAD_VALUE; + } +} + +void IThermalServiceTest::SetUp() { + setThermalOverride(0); + // use checkService() to avoid blocking if thermal service is not up yet + sp binder = + defaultServiceManager()->checkService(String16("thermalservice")); + EXPECT_NE(binder, nullptr); + mThermalSvc = interface_cast(binder); + EXPECT_NE(mThermalSvc, nullptr); + bool success = false; + binder::Status ret = mThermalSvc->registerThermalStatusListener(this, &success); + ASSERT_TRUE(success); + ASSERT_TRUE(ret.isOk()); + // Wait for listener called after registration, shouldn't timeout + std::unique_lock lock(mMutex); + EXPECT_NE(mCondition.wait_for(lock, 1s), std::cv_status::timeout); +} + +void IThermalServiceTest::TearDown() { + bool success = false; + binder::Status ret = mThermalSvc->unregisterThermalStatusListener(this, &success); + ASSERT_TRUE(success); + ASSERT_TRUE(ret.isOk()); +} + +class IThermalListenerTest : public IThermalServiceTest, public testing::WithParamInterface { + public: + static auto PrintParam(const testing::TestParamInfo &info) { + return std::to_string(info.param); + } +}; + +TEST_P(IThermalListenerTest, TestListener) { + int level = GetParam(); + std::unique_lock lock(mMutex); + // Set the override thermal status + setThermalOverride(level); + // Wait for listener called, shouldn't timeout + EXPECT_NE(mCondition.wait_for(lock, 1s), std::cv_status::timeout); + // Check the result + EXPECT_EQ(level, mListenerStatus); + ALOGI("Thermal listener status %d, expecting %d", mListenerStatus, level); +} + +INSTANTIATE_TEST_SUITE_P(TestListenerLevels, IThermalListenerTest, testing::Range( + static_cast(ThermalStatus::THERMAL_STATUS_LIGHT), + static_cast(ThermalStatus::THERMAL_STATUS_SHUTDOWN)), + IThermalListenerTest::PrintParam); + +class IThermalLevelTest : public IThermalServiceTest, public testing::WithParamInterface { + public: + static auto PrintParam(const testing::TestParamInfo &info) { + return std::to_string(info.param); + } +}; + +TEST_P(IThermalLevelTest, TestGetStatusLevel) { + int level = GetParam(); + setThermalOverride(level); + mServiceStatus = getStatusFromService(); + EXPECT_EQ(level, mServiceStatus); +} + +INSTANTIATE_TEST_SUITE_P(TestStatusLevels, IThermalLevelTest, testing::Range( + static_cast(ThermalStatus::THERMAL_STATUS_NONE), + static_cast(ThermalStatus::THERMAL_STATUS_SHUTDOWN)), + IThermalLevelTest::PrintParam); + +int main(int argc, char **argv) { + std::unique_ptr binderLoop; + binderLoop = std::make_unique( + [&] { IPCThreadState::self()->joinThreadPool(true); }); + + ::testing::InitGoogleTest(&argc, argv); + int status = RUN_ALL_TESTS(); + ALOGV("Test result = %d\n", status); + + return status; +} \ No newline at end of file diff --git a/services/powermanager/Temperature.cpp b/services/powermanager/Temperature.cpp new file mode 100644 index 0000000000..8ec0a87146 --- /dev/null +++ b/services/powermanager/Temperature.cpp @@ -0,0 +1,55 @@ +/* + * 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. + */ + +#define LOG_TAG "Temperature" + +#include +#include +#include + +namespace android { +namespace os { + +status_t Temperature::readFromParcel(const android::Parcel *parcel) { + if (parcel == nullptr) { + ALOGE("%s: Null parcel", __FUNCTION__); + return BAD_VALUE; + } + + parcel->readFloat(&mValue); + parcel->readInt32(&mType); + parcel->readString16(&mName); + parcel->readInt32(&mStatus); + + return OK; +} + +status_t Temperature::writeToParcel(android::Parcel *parcel) const { + if (parcel == nullptr) { + ALOGE("%s: Null parcel", __FUNCTION__); + return BAD_VALUE; + } + + parcel->writeFloat(mValue); + parcel->writeInt32(mType); + parcel->writeString16(mName); + parcel->writeInt32(mStatus); + + return OK; +} + +} // namespace os +} // namespace android \ No newline at end of file -- cgit v1.2.3-59-g8ed1b From fbcf9d77fe6321ba7e03d50f965e8c16ea4290c3 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Mon, 24 Feb 2020 15:26:37 -0800 Subject: Make bitmap.h C-compatible when __ANDROID_API__ >= 30 C requires a typedef for AHardwareBuffer. Fixes: frameworks/native/include/android/bitmap.h:246:9: error: must use 'struct' tag to refer to type 'AHardwareBuffer' Fixes: 150165785 Test: m checkbuild Change-Id: I6d475e91317ff7a9264144d4cd6c6c9b46d10196 --- include/android/bitmap.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include/android') diff --git a/include/android/bitmap.h b/include/android/bitmap.h index 727a4af2f9..2631b144af 100644 --- a/include/android/bitmap.h +++ b/include/android/bitmap.h @@ -227,6 +227,7 @@ int AndroidBitmap_compress(const AndroidBitmapInfo* info, AndroidBitmap_CompressWriteFunc fn) __INTRODUCED_IN(30); struct AHardwareBuffer; +typedef struct AHardwareBuffer AHardwareBuffer; /** * Retrieve the native object associated with a HARDWARE Bitmap. -- cgit v1.2.3-59-g8ed1b From 80826e0e14e547aba00ad558fb1d0c1d93e7cebc Mon Sep 17 00:00:00 2001 From: Chris Ye Date: Thu, 5 Mar 2020 15:14:21 -0800 Subject: Move the non-NDK APIs to powermanager internal directory. Move the header files with non-NDK APIs to be inside powermanager. Bug: 150878392 Change-Id: I34d0619a0fd3bc913ef79040207b5943add6b372 --- include/android/CoolingDevice.h | 49 -------------------- include/android/Temperature.h | 53 ---------------------- services/powermanager/Android.bp | 7 ++- .../powermanager/include/android/CoolingDevice.h | 49 ++++++++++++++++++++ .../powermanager/include/android/Temperature.h | 53 ++++++++++++++++++++++ 5 files changed, 108 insertions(+), 103 deletions(-) delete mode 100644 include/android/CoolingDevice.h delete mode 100644 include/android/Temperature.h create mode 100644 services/powermanager/include/android/CoolingDevice.h create mode 100644 services/powermanager/include/android/Temperature.h (limited to 'include/android') diff --git a/include/android/CoolingDevice.h b/include/android/CoolingDevice.h deleted file mode 100644 index 2f366be544..0000000000 --- a/include/android/CoolingDevice.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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. - */ - -#ifndef ANDROID_OS_COOLINGDEVICE_H -#define ANDROID_OS_COOLINGDEVICE_H - -#include -#include - -namespace android { -namespace os { - -/** - * CoolingDevice is a structure to encapsulate cooling device status. - */ -struct CoolingDevice : public android::Parcelable { - /** Current throttle state of the cooling device. */ - float mValue; - /** A cooling device type from ThermalHAL */ - uint32_t mType; - /** Name of this cooling device */ - String16 mName; - - CoolingDevice() - : mValue(0.0f), - mType(0), - mName("") { - } - virtual status_t readFromParcel(const android::Parcel* parcel) override; - virtual status_t writeToParcel(android::Parcel* parcel) const override; -}; - -} // namespace os -} // namespace android - -#endif /* ANDROID_OS_COOLINGDEVICE_H */ diff --git a/include/android/Temperature.h b/include/android/Temperature.h deleted file mode 100644 index 2e68ec4899..0000000000 --- a/include/android/Temperature.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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. - */ - -#ifndef ANDROID_OS_TEMPERATURE_H -#define ANDROID_OS_TEMPERATURE_H - -#include -#include - -namespace android { -namespace os { - -/** - * Temperature is a structure to encapsulate temperature status. - */ -struct Temperature : public android::Parcelable { - /** Temperature value */ - float mValue; - /** A Temperature type from ThermalHAL */ - int32_t mType; - /** Name of this Temperature */ - String16 mName; - /** The level of the sensor is currently in throttling */ - int32_t mStatus; - - Temperature() - : mValue(0.0f), - mType(0), - mName(""), - mStatus(0) { - } - - virtual status_t readFromParcel(const android::Parcel* parcel) override; - virtual status_t writeToParcel(android::Parcel* parcel) const override; -}; - -} // namespace os -} // namespace android - -#endif /* ANDROID_OS_TEMPERATURE_H */ diff --git a/services/powermanager/Android.bp b/services/powermanager/Android.bp index 3e0f136dfb..b0d3e3bde0 100644 --- a/services/powermanager/Android.bp +++ b/services/powermanager/Android.bp @@ -9,7 +9,7 @@ cc_library_shared { ], aidl: { - local_include_dirs: ["."], + local_include_dirs: ["include"], include_dirs: [ "frameworks/base/core/java/android/os", ], @@ -28,6 +28,11 @@ cc_library_shared { "-Wunused", "-Wunreachable-code", ], + + local_include_dirs: ["include"], + export_include_dirs: [ + "include", + ], } cc_test { diff --git a/services/powermanager/include/android/CoolingDevice.h b/services/powermanager/include/android/CoolingDevice.h new file mode 100644 index 0000000000..2f366be544 --- /dev/null +++ b/services/powermanager/include/android/CoolingDevice.h @@ -0,0 +1,49 @@ +/* + * 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. + */ + +#ifndef ANDROID_OS_COOLINGDEVICE_H +#define ANDROID_OS_COOLINGDEVICE_H + +#include +#include + +namespace android { +namespace os { + +/** + * CoolingDevice is a structure to encapsulate cooling device status. + */ +struct CoolingDevice : public android::Parcelable { + /** Current throttle state of the cooling device. */ + float mValue; + /** A cooling device type from ThermalHAL */ + uint32_t mType; + /** Name of this cooling device */ + String16 mName; + + CoolingDevice() + : mValue(0.0f), + mType(0), + mName("") { + } + virtual status_t readFromParcel(const android::Parcel* parcel) override; + virtual status_t writeToParcel(android::Parcel* parcel) const override; +}; + +} // namespace os +} // namespace android + +#endif /* ANDROID_OS_COOLINGDEVICE_H */ diff --git a/services/powermanager/include/android/Temperature.h b/services/powermanager/include/android/Temperature.h new file mode 100644 index 0000000000..2e68ec4899 --- /dev/null +++ b/services/powermanager/include/android/Temperature.h @@ -0,0 +1,53 @@ +/* + * 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. + */ + +#ifndef ANDROID_OS_TEMPERATURE_H +#define ANDROID_OS_TEMPERATURE_H + +#include +#include + +namespace android { +namespace os { + +/** + * Temperature is a structure to encapsulate temperature status. + */ +struct Temperature : public android::Parcelable { + /** Temperature value */ + float mValue; + /** A Temperature type from ThermalHAL */ + int32_t mType; + /** Name of this Temperature */ + String16 mName; + /** The level of the sensor is currently in throttling */ + int32_t mStatus; + + Temperature() + : mValue(0.0f), + mType(0), + mName(""), + mStatus(0) { + } + + virtual status_t readFromParcel(const android::Parcel* parcel) override; + virtual status_t writeToParcel(android::Parcel* parcel) const override; +}; + +} // namespace os +} // namespace android + +#endif /* ANDROID_OS_TEMPERATURE_H */ -- cgit v1.2.3-59-g8ed1b From 8e8cec4c48603621552db8dbd2c090847ff0b5e4 Mon Sep 17 00:00:00 2001 From: Chris Ye Date: Thu, 26 Mar 2020 14:14:58 -0700 Subject: AThermal_StatusCallback should return void AThermal_StatusCallback returns an int but it's totally ignored and undocumented, we should just make this a void function. Bug: 152509392 Change-Id: I044733f63007e942a6b1d04ce761891101b94e8f --- include/android/thermal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/android') diff --git a/include/android/thermal.h b/include/android/thermal.h index 0f4b4d9b8d..3247fa167b 100644 --- a/include/android/thermal.h +++ b/include/android/thermal.h @@ -109,7 +109,7 @@ typedef struct AThermalManager AThermalManager; * It's passed the updated thermal status as parameter, as well as the * pointer provided by the client that registered a callback. */ -typedef int (*AThermal_StatusCallback)(void *data, AThermalStatus status); +typedef void (*AThermal_StatusCallback)(void *data, AThermalStatus status); /** * Acquire an instance of the thermal manager. This must be freed using -- cgit v1.2.3-59-g8ed1b From 15b6f9c8961019debe63358b73572bd294b35349 Mon Sep 17 00:00:00 2001 From: Steven Thomas Date: Thu, 26 Mar 2020 13:44:28 -0700 Subject: Clean up some formatting problems in the setFrameRate ndk docs Bug: 152413112 Test: Unfortunately there's no convenient way to build the ndk docs locally, so we're just going to submit and see if the regenerated DAC docs look correct. I talked with Dan Albert on the ndk team about this, and he decided to reopen b/115644359 to see if we can get some easy way to build the ndk docs locally again, so we can verify minor formatting fixes like this. Change-Id: Ie29a19a386887df6305ee9a4447702126fed7972 --- include/android/surface_control.h | 8 ++++---- libs/nativewindow/include/android/native_window.h | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'include/android') diff --git a/include/android/surface_control.h b/include/android/surface_control.h index c30dcfee09..cbcf6ec5c0 100644 --- a/include/android/surface_control.h +++ b/include/android/surface_control.h @@ -409,7 +409,7 @@ void ASurfaceTransaction_setHdrMetadata_cta861_3(ASurfaceTransaction* transactio #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 @@ -421,9 +421,9 @@ void ASurfaceTransaction_setHdrMetadata_cta861_3(ASurfaceTransaction* transactio * * |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 *not* 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. + * the default behavior if this function isn't called. The frameRate param does not 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 diff --git a/libs/nativewindow/include/android/native_window.h b/libs/nativewindow/include/android/native_window.h index 59aa6655b8..25130e2a03 100644 --- a/libs/nativewindow/include/android/native_window.h +++ b/libs/nativewindow/include/android/native_window.h @@ -233,15 +233,15 @@ int32_t ANativeWindow_getBuffersDataSpace(ANativeWindow* window) __INTRODUCED_IN #if __ANDROID_API__ >= 30 -/* Parameter for ANativeWindow_setFrameRate */ -enum { +/** Compatibility value for ANativeWindow_setFrameRate. */ +enum ANativeWindow_FrameRateCompatibility { /** * There are no inherent restrictions on the frame rate of this window. */ ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT = 0, /** * This window is being used to display content with an inherently fixed - * frame rate, e.g. a video that has a specific frame rate. When the system + * frame rate, e.g.\ a video that has a specific frame rate. When the system * selects a frame rate other than what the app requested, the app will need * to do pull down or use some other technique to adapt to the system's * frame rate. The user experience is likely to be worse (e.g. more frame @@ -272,9 +272,9 @@ enum { * \param frameRate The intended frame rate of this window, 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 *not* 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. + * function isn't called. The frameRate param does not 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. * * \param compatibility The frame rate compatibility of this window. The * compatibility value may influence the system's choice of display refresh -- cgit v1.2.3-59-g8ed1b From 271de040ffc1371251a9741d2f347642a5de0995 Mon Sep 17 00:00:00 2001 From: Alec Mouri Date: Mon, 27 Apr 2020 22:38:19 -0700 Subject: Receive refresh rate callbacks from DMS AChoreographer will use DMS as the source of truth for these callbacks instead of SurfaceFlinger. Bug: 154874011 Test: ChoreographerNativeTest Tes: Manually verify that HWUI is processing refresh rate callbacks Change-Id: I961a7d1ab335800d3e260ba7564ddca9c0595cfc --- include/android/choreographer.h | 156 ++++++++++ libs/gui/DisplayEventDispatcher.cpp | 13 +- libs/gui/DisplayEventReceiver.cpp | 5 +- libs/gui/IDisplayEventConnection.cpp | 15 +- libs/gui/include/gui/DisplayEventDispatcher.h | 3 +- libs/gui/include/gui/DisplayEventReceiver.h | 5 +- libs/gui/include/gui/IDisplayEventConnection.h | 6 +- libs/nativedisplay/AChoreographer.cpp | 324 +++++++++++++++++---- libs/nativedisplay/Android.bp | 17 +- .../private/android/choreographer.h | 55 ++++ libs/nativedisplay/include/android/choreographer.h | 152 ---------- .../surfacetexture/surface_texture_platform.h | 16 +- libs/nativedisplay/libnativedisplay.map.txt | 17 ++ .../surfacetexture/surface_texture.cpp | 31 ++ services/surfaceflinger/Scheduler/EventThread.cpp | 27 +- services/surfaceflinger/Scheduler/EventThread.h | 11 +- .../tests/unittests/mock/MockEventThread.h | 2 +- 17 files changed, 585 insertions(+), 270 deletions(-) create mode 100644 include/android/choreographer.h create mode 100644 libs/nativedisplay/include-private/private/android/choreographer.h delete mode 100644 libs/nativedisplay/include/android/choreographer.h (limited to 'include/android') diff --git a/include/android/choreographer.h b/include/android/choreographer.h new file mode 100644 index 0000000000..c1c4a72cd3 --- /dev/null +++ b/include/android/choreographer.h @@ -0,0 +1,156 @@ +/* + * Copyright (C) 2015 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 Choreographer + * @{ + */ + +/** + * @file choreographer.h + */ + +#ifndef ANDROID_CHOREOGRAPHER_H +#define ANDROID_CHOREOGRAPHER_H + +#include +#include + +__BEGIN_DECLS + +struct AChoreographer; +typedef struct AChoreographer AChoreographer; + +/** + * Prototype of the function that is called when a new frame is being rendered. + * It's passed the time that the frame is being rendered as nanoseconds in the + * CLOCK_MONOTONIC time base, as well as the data pointer provided by the + * application that registered a callback. All callbacks that run as part of + * rendering a frame will observe the same frame time, so it should be used + * whenever events need to be synchronized (e.g. animations). + */ +typedef void (*AChoreographer_frameCallback)(long frameTimeNanos, void* data); + +/** + * Prototype of the function that is called when a new frame is being rendered. + * It's passed the time that the frame is being rendered as nanoseconds in the + * CLOCK_MONOTONIC time base, as well as the data pointer provided by the + * application that registered a callback. All callbacks that run as part of + * rendering a frame will observe the same frame time, so it should be used + * whenever events need to be synchronized (e.g. animations). + */ +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 + +/** + * Get the AChoreographer instance for the current thread. This must be called + * on an ALooper thread. + * + * Available since API level 24. + */ +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); + +/** + * Deprecated: Use AChoreographer_postFrameCallbackDelayed64 instead. + */ +void AChoreographer_postFrameCallbackDelayed(AChoreographer* choreographer, + AChoreographer_frameCallback callback, void* data, + long delayMillis) __INTRODUCED_IN(24) + __DEPRECATED_IN(29); + +#endif /* __ANDROID_API__ >= 24 */ + +#if __ANDROID_API__ >= 29 + +/** + * Power a callback to be run on the next frame. The data pointer provided will + * be passed to the callback function when it's called. + * + * Available since API level 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 + * data pointer provided will be passed to the callback function when it's + * called. + * + * Available since API level 29. + */ +void AChoreographer_postFrameCallbackDelayed64(AChoreographer* choreographer, + 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. + */ +void AChoreographer_registerRefreshRateCallback(AChoreographer* choreographer, + AChoreographer_refreshRateCallback, void* data); + +/** + * 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. + */ +void AChoreographer_unregisterRefreshRateCallback(AChoreographer* choreographer, + AChoreographer_refreshRateCallback, void* data); +#endif /* __ANDROID_API__ >= 30 */ + +__END_DECLS + +#endif // ANDROID_CHOREOGRAPHER_H + +/** @} */ diff --git a/libs/gui/DisplayEventDispatcher.cpp b/libs/gui/DisplayEventDispatcher.cpp index 15f966d062..b33bc9e556 100644 --- a/libs/gui/DisplayEventDispatcher.cpp +++ b/libs/gui/DisplayEventDispatcher.cpp @@ -36,10 +36,7 @@ static const size_t EVENT_BUFFER_SIZE = 100; DisplayEventDispatcher::DisplayEventDispatcher(const sp& looper, ISurfaceComposer::VsyncSource vsyncSource, ISurfaceComposer::ConfigChanged configChanged) - : mLooper(looper), - mReceiver(vsyncSource, configChanged), - mWaitingForVsync(false), - mConfigChangeFlag(configChanged) { + : mLooper(looper), mReceiver(vsyncSource, configChanged), mWaitingForVsync(false) { ALOGV("dispatcher %p ~ Initializing display event dispatcher.", this); } @@ -92,16 +89,12 @@ status_t DisplayEventDispatcher::scheduleVsync() { return OK; } -void DisplayEventDispatcher::toggleConfigEvents(ISurfaceComposer::ConfigChanged configChangeFlag) { - if (mConfigChangeFlag == configChangeFlag) { - return; - } - status_t status = mReceiver.toggleConfigEvents(configChangeFlag); +void DisplayEventDispatcher::requestLatestConfig() { + status_t status = mReceiver.requestLatestConfig(); if (status) { ALOGW("Failed enable config events, status=%d", status); return; } - mConfigChangeFlag = configChangeFlag; } int DisplayEventDispatcher::getFd() const { diff --git a/libs/gui/DisplayEventReceiver.cpp b/libs/gui/DisplayEventReceiver.cpp index fd6aaf8b46..1fed509003 100644 --- a/libs/gui/DisplayEventReceiver.cpp +++ b/libs/gui/DisplayEventReceiver.cpp @@ -79,10 +79,9 @@ status_t DisplayEventReceiver::requestNextVsync() { return NO_INIT; } -status_t DisplayEventReceiver::toggleConfigEvents( - ISurfaceComposer::ConfigChanged configChangeFlag) { +status_t DisplayEventReceiver::requestLatestConfig() { if (mEventConnection != nullptr) { - mEventConnection->toggleConfigEvents(configChangeFlag); + mEventConnection->requestLatestConfig(); return NO_ERROR; } return NO_INIT; diff --git a/libs/gui/IDisplayEventConnection.cpp b/libs/gui/IDisplayEventConnection.cpp index dda5acf8a7..aa74bfd3f8 100644 --- a/libs/gui/IDisplayEventConnection.cpp +++ b/libs/gui/IDisplayEventConnection.cpp @@ -26,8 +26,8 @@ enum class Tag : uint32_t { STEAL_RECEIVE_CHANNEL = IBinder::FIRST_CALL_TRANSACTION, SET_VSYNC_RATE, REQUEST_NEXT_VSYNC, - TOGGLE_CONFIG_EVENTS, - LAST = TOGGLE_CONFIG_EVENTS, + REQUEST_LATEST_CONFIG, + LAST = REQUEST_LATEST_CONFIG, }; } // Anonymous namespace @@ -55,10 +55,9 @@ public: Tag::REQUEST_NEXT_VSYNC); } - void toggleConfigEvents(ISurfaceComposer::ConfigChanged configChangeFlag) override { - callRemoteAsync(Tag::TOGGLE_CONFIG_EVENTS, - configChangeFlag); + void requestLatestConfig() override { + callRemoteAsync( + Tag::REQUEST_LATEST_CONFIG); } }; @@ -81,8 +80,8 @@ status_t BnDisplayEventConnection::onTransact(uint32_t code, const Parcel& data, return callLocal(data, reply, &IDisplayEventConnection::setVsyncRate); case Tag::REQUEST_NEXT_VSYNC: return callLocalAsync(data, reply, &IDisplayEventConnection::requestNextVsync); - case Tag::TOGGLE_CONFIG_EVENTS: - return callLocalAsync(data, reply, &IDisplayEventConnection::toggleConfigEvents); + case Tag::REQUEST_LATEST_CONFIG: + return callLocalAsync(data, reply, &IDisplayEventConnection::requestLatestConfig); } } diff --git a/libs/gui/include/gui/DisplayEventDispatcher.h b/libs/gui/include/gui/DisplayEventDispatcher.h index fcdf6bfa7e..f210c34196 100644 --- a/libs/gui/include/gui/DisplayEventDispatcher.h +++ b/libs/gui/include/gui/DisplayEventDispatcher.h @@ -31,7 +31,7 @@ public: status_t initialize(); void dispose(); status_t scheduleVsync(); - void toggleConfigEvents(ISurfaceComposer::ConfigChanged configChangeFlag); + void requestLatestConfig(); int getFd() const; virtual int handleEvent(int receiveFd, int events, void* data); @@ -42,7 +42,6 @@ private: sp mLooper; DisplayEventReceiver mReceiver; bool mWaitingForVsync; - ISurfaceComposer::ConfigChanged mConfigChangeFlag; virtual void dispatchVsync(nsecs_t timestamp, PhysicalDisplayId displayId, uint32_t count) = 0; virtual void dispatchHotplug(nsecs_t timestamp, PhysicalDisplayId displayId, diff --git a/libs/gui/include/gui/DisplayEventReceiver.h b/libs/gui/include/gui/DisplayEventReceiver.h index d9a0253781..8d49184caf 100644 --- a/libs/gui/include/gui/DisplayEventReceiver.h +++ b/libs/gui/include/gui/DisplayEventReceiver.h @@ -147,9 +147,10 @@ public: status_t requestNextVsync(); /* - * toggleConfigEvents() toggles delivery of config change events. + * requestLatestConfig() force-requests the current config for the primary + * display. */ - status_t toggleConfigEvents(ISurfaceComposer::ConfigChanged configChangeFlag); + status_t requestLatestConfig(); private: sp mEventConnection; diff --git a/libs/gui/include/gui/IDisplayEventConnection.h b/libs/gui/include/gui/IDisplayEventConnection.h index 8b35ef6486..674aafd81c 100644 --- a/libs/gui/include/gui/IDisplayEventConnection.h +++ b/libs/gui/include/gui/IDisplayEventConnection.h @@ -53,11 +53,9 @@ public: virtual void requestNextVsync() = 0; // Asynchronous /* - * togglesConfigEvents() configures whether or not display config changes - * should be propagated. + * requestLatestConfig() requests the config for the primary display. */ - virtual void toggleConfigEvents( - ISurfaceComposer::ConfigChanged configChangeFlag) = 0; // Asynchronous + virtual void requestLatestConfig() = 0; // Asynchronous }; class BnDisplayEventConnection : public SafeBnInterface { diff --git a/libs/nativedisplay/AChoreographer.cpp b/libs/nativedisplay/AChoreographer.cpp index 0ff33ac747..ea51245ac6 100644 --- a/libs/nativedisplay/AChoreographer.cpp +++ b/libs/nativedisplay/AChoreographer.cpp @@ -17,24 +17,63 @@ #define LOG_TAG "Choreographer" //#define LOG_NDEBUG 0 -#include +#include #include #include #include +#include +#include #include -#include #include #include +#include #include #include #include -namespace android { +namespace { +struct { + // Global JVM that is provided by zygote + JavaVM* jvm = nullptr; + struct { + jclass clazz; + jmethodID getInstance; + jmethodID registerNativeChoreographerForRefreshRateCallbacks; + jmethodID unregisterNativeChoreographerForRefreshRateCallbacks; + } displayManagerGlobal; +} gJni; + +// Gets the JNIEnv* for this thread, and performs one-off initialization if we +// have never retrieved a JNIEnv* pointer before. +JNIEnv* getJniEnv() { + if (gJni.jvm == nullptr) { + ALOGW("AChoreographer: No JVM provided!"); + return nullptr; + } + + JNIEnv* env = nullptr; + if (gJni.jvm->GetEnv((void**)&env, JNI_VERSION_1_4) != JNI_OK) { + ALOGD("Attaching thread to JVM for AChoreographer"); + JavaVMAttachArgs args = {JNI_VERSION_1_4, "AChoreographer_env", NULL}; + jint attachResult = gJni.jvm->AttachCurrentThreadAsDaemon(&env, (void*)&args); + if (attachResult != JNI_OK) { + ALOGE("Unable to attach thread. Error: %d", attachResult); + return nullptr; + } + } + if (env == nullptr) { + ALOGW("AChoreographer: No JNI env available!"); + } + return env; +} -static inline const char* toString(bool value) { +inline const char* toString(bool value) { return value ? "true" : "false"; } +} // namespace + +namespace android { struct FrameCallback { AChoreographer_frameCallback callback; @@ -52,24 +91,43 @@ struct FrameCallback { struct RefreshRateCallback { AChoreographer_refreshRateCallback callback; void* data; + bool firstCallbackFired = false; }; +class Choreographer; + +struct { + std::mutex lock; + std::vector ptrs GUARDED_BY(lock); + bool registeredToDisplayManager GUARDED_BY(lock) = false; + + std::atomic mLastKnownVsync = -1; +} gChoreographers; + class Choreographer : public DisplayEventDispatcher, public MessageHandler { public: - explicit Choreographer(const sp& looper); + explicit Choreographer(const sp& looper) EXCLUDES(gChoreographers.lock); void postFrameCallbackDelayed(AChoreographer_frameCallback cb, AChoreographer_frameCallback64 cb64, void* data, nsecs_t delay); - void registerRefreshRateCallback(AChoreographer_refreshRateCallback cb, void* data); + void registerRefreshRateCallback(AChoreographer_refreshRateCallback cb, void* data) + EXCLUDES(gChoreographers.lock); void unregisterRefreshRateCallback(AChoreographer_refreshRateCallback cb, void* data); + // Drains the queue of pending vsync periods and dispatches refresh rate + // updates to callbacks. + // The assumption is that this method is only called on a single + // processing thread, either by looper or by AChoreographer_handleEvents + void handleRefreshRateUpdates(); + void scheduleLatestConfigRequest(); enum { MSG_SCHEDULE_CALLBACKS = 0, - MSG_SCHEDULE_VSYNC = 1 + MSG_SCHEDULE_VSYNC = 1, + MSG_HANDLE_REFRESH_RATE_UPDATES = 2, }; virtual void handleMessage(const Message& message) override; static Choreographer* getForThread(); - virtual ~Choreographer() = default; + virtual ~Choreographer() override EXCLUDES(gChoreographers.lock); private: Choreographer(const Choreographer&) = delete; @@ -81,21 +139,17 @@ private: void scheduleCallbacks(); + std::mutex mLock; // Protected by mLock std::priority_queue mFrameCallbacks; - - // Protected by mLock std::vector mRefreshRateCallbacks; - nsecs_t mVsyncPeriod = 0; - mutable Mutex mLock; + nsecs_t mLatestVsyncPeriod = -1; const sp mLooper; const std::thread::id mThreadId; - const std::optional mInternalDisplayId; }; - static thread_local Choreographer* gChoreographer; Choreographer* Choreographer::getForThread() { if (gChoreographer == nullptr) { @@ -115,17 +169,47 @@ Choreographer* Choreographer::getForThread() { } Choreographer::Choreographer(const sp& looper) - : DisplayEventDispatcher(looper), + : DisplayEventDispatcher(looper, ISurfaceComposer::VsyncSource::eVsyncSourceApp, + ISurfaceComposer::ConfigChanged::eConfigChangedDispatch), mLooper(looper), - mThreadId(std::this_thread::get_id()), - mInternalDisplayId(SurfaceComposerClient::getInternalDisplayId()) {} + mThreadId(std::this_thread::get_id()) { + std::lock_guard _l(gChoreographers.lock); + gChoreographers.ptrs.push_back(this); +} + +Choreographer::~Choreographer() { + std::lock_guard _l(gChoreographers.lock); + gChoreographers.ptrs.erase(std::remove_if(gChoreographers.ptrs.begin(), + gChoreographers.ptrs.end(), + [=](Choreographer* c) { return c == this; }), + gChoreographers.ptrs.end()); + // Only poke DisplayManagerGlobal to unregister if we previously registered + // callbacks. + if (gChoreographers.ptrs.empty() && gChoreographers.registeredToDisplayManager) { + JNIEnv* env = getJniEnv(); + if (env == nullptr) { + ALOGW("JNI environment is unavailable, skipping choreographer cleanup"); + return; + } + jobject dmg = env->CallStaticObjectMethod(gJni.displayManagerGlobal.clazz, + gJni.displayManagerGlobal.getInstance); + if (dmg == nullptr) { + ALOGW("DMS is not initialized yet, skipping choreographer cleanup"); + } else { + env->CallVoidMethod(dmg, + gJni.displayManagerGlobal + .unregisterNativeChoreographerForRefreshRateCallbacks); + env->DeleteLocalRef(dmg); + } + } +} void Choreographer::postFrameCallbackDelayed( AChoreographer_frameCallback cb, AChoreographer_frameCallback64 cb64, void* data, nsecs_t delay) { nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC); FrameCallback callback{cb, cb64, data, now + delay}; { - AutoMutex _l{mLock}; + std::lock_guard _l{mLock}; mFrameCallbacks.push(callback); } if (callback.dueTime <= now) { @@ -150,37 +234,68 @@ void Choreographer::postFrameCallbackDelayed( } void Choreographer::registerRefreshRateCallback(AChoreographer_refreshRateCallback cb, void* data) { + std::lock_guard _l{mLock}; + for (const auto& callback : mRefreshRateCallbacks) { + // Don't re-add callbacks. + if (cb == callback.callback && data == callback.data) { + return; + } + } + mRefreshRateCallbacks.emplace_back( + RefreshRateCallback{.callback = cb, .data = data, .firstCallbackFired = false}); + bool needsRegistration = false; { - AutoMutex _l{mLock}; - for (const auto& callback : mRefreshRateCallbacks) { - // Don't re-add callbacks. - if (cb == callback.callback && data == callback.data) { - return; + std::lock_guard _l2(gChoreographers.lock); + needsRegistration = !gChoreographers.registeredToDisplayManager; + } + if (needsRegistration) { + JNIEnv* env = getJniEnv(); + jobject dmg = env->CallStaticObjectMethod(gJni.displayManagerGlobal.clazz, + gJni.displayManagerGlobal.getInstance); + if (env == nullptr) { + ALOGW("JNI environment is unavailable, skipping registeration"); + return; + } + if (dmg == nullptr) { + ALOGW("DMS is not initialized yet: skipping registration"); + return; + } else { + env->CallVoidMethod(dmg, + gJni.displayManagerGlobal + .registerNativeChoreographerForRefreshRateCallbacks, + reinterpret_cast(this)); + env->DeleteLocalRef(dmg); + { + std::lock_guard _l2(gChoreographers.lock); + gChoreographers.registeredToDisplayManager = true; } } - mRefreshRateCallbacks.emplace_back(RefreshRateCallback{cb, data}); - toggleConfigEvents(ISurfaceComposer::ConfigChanged::eConfigChangedDispatch); + } else { + scheduleLatestConfigRequest(); } } void Choreographer::unregisterRefreshRateCallback(AChoreographer_refreshRateCallback cb, void* data) { - { - AutoMutex _l{mLock}; - mRefreshRateCallbacks.erase(std::remove_if(mRefreshRateCallbacks.begin(), - mRefreshRateCallbacks.end(), - [&](const RefreshRateCallback& callback) { - return cb == callback.callback && - data == callback.data; - }), - mRefreshRateCallbacks.end()); - if (mRefreshRateCallbacks.empty()) { - toggleConfigEvents(ISurfaceComposer::ConfigChanged::eConfigChangedSuppress); - // If callbacks are empty then clear out the most recently seen - // vsync period so that when another callback is registered then the - // up-to-date refresh rate can be communicated to the app again. - mVsyncPeriod = 0; - } + std::lock_guard _l{mLock}; + mRefreshRateCallbacks.erase(std::remove_if(mRefreshRateCallbacks.begin(), + mRefreshRateCallbacks.end(), + [&](const RefreshRateCallback& callback) { + return cb == callback.callback && + data == callback.data; + }), + mRefreshRateCallbacks.end()); +} + +void Choreographer::scheduleLatestConfigRequest() { + if (mLooper != nullptr) { + Message m{MSG_HANDLE_REFRESH_RATE_UPDATES}; + mLooper->sendMessage(this, m); + } else { + // If the looper thread is detached from Choreographer, then refresh rate + // changes will be handled in AChoreographer_handlePendingEvents, so we + // need to redispatch a config from SF + requestLatestConfig(); } } @@ -188,7 +303,7 @@ void Choreographer::scheduleCallbacks() { const nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC); nsecs_t dueTime; { - AutoMutex _{mLock}; + std::lock_guard _l{mLock}; // If there are no pending callbacks then don't schedule a vsync if (mFrameCallbacks.empty()) { return; @@ -203,13 +318,35 @@ void Choreographer::scheduleCallbacks() { } } +void Choreographer::handleRefreshRateUpdates() { + std::vector callbacks{}; + const nsecs_t pendingPeriod = gChoreographers.mLastKnownVsync.load(); + const nsecs_t lastPeriod = mLatestVsyncPeriod; + if (pendingPeriod > 0) { + mLatestVsyncPeriod = pendingPeriod; + } + { + std::lock_guard _l{mLock}; + for (auto& cb : mRefreshRateCallbacks) { + callbacks.push_back(cb); + cb.firstCallbackFired = true; + } + } + + for (auto& cb : callbacks) { + if (!cb.firstCallbackFired || (pendingPeriod > 0 && pendingPeriod != lastPeriod)) { + cb.callback(pendingPeriod, cb.data); + } + } +} + // TODO(b/74619554): The PhysicalDisplayId is ignored because SF only emits VSYNC events for the // internal display and DisplayEventReceiver::requestNextVsync only allows requesting VSYNC for // the internal display implicitly. void Choreographer::dispatchVsync(nsecs_t timestamp, PhysicalDisplayId, uint32_t) { std::vector callbacks{}; { - AutoMutex _l{mLock}; + std::lock_guard _l{mLock}; nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC); while (!mFrameCallbacks.empty() && mFrameCallbacks.top().dueTime < now) { callbacks.push_back(mFrameCallbacks.top()); @@ -236,20 +373,29 @@ void Choreographer::dispatchHotplug(nsecs_t, PhysicalDisplayId displayId, bool c // display, so as such Choreographer does not support the notion of multiple // displays. When multi-display choreographer is properly supported, then // PhysicalDisplayId should no longer be ignored. -void Choreographer::dispatchConfigChanged(nsecs_t, PhysicalDisplayId, int32_t, +void Choreographer::dispatchConfigChanged(nsecs_t, PhysicalDisplayId displayId, int32_t configId, nsecs_t vsyncPeriod) { + ALOGV("choreographer %p ~ received config change event " + "(displayId=%" ANDROID_PHYSICAL_DISPLAY_ID_FORMAT ", configId=%d).", + this, displayId, configId); + + const nsecs_t lastPeriod = mLatestVsyncPeriod; + std::vector callbacks{}; { - AutoMutex _l{mLock}; - for (const auto& cb : mRefreshRateCallbacks) { - // Only perform the callback when the old refresh rate is different - // from the new refresh rate, so that we don't dispatch the callback - // on every single configuration change. - if (mVsyncPeriod != vsyncPeriod) { - cb.callback(vsyncPeriod, cb.data); - } + std::lock_guard _l{mLock}; + for (auto& cb : mRefreshRateCallbacks) { + callbacks.push_back(cb); + cb.firstCallbackFired = true; + } + } + + for (auto& cb : callbacks) { + if (!cb.firstCallbackFired || (vsyncPeriod > 0 && vsyncPeriod != lastPeriod)) { + cb.callback(vsyncPeriod, cb.data); } - mVsyncPeriod = vsyncPeriod; } + + mLatestVsyncPeriod = vsyncPeriod; } void Choreographer::handleMessage(const Message& message) { @@ -260,19 +406,80 @@ void Choreographer::handleMessage(const Message& message) { case MSG_SCHEDULE_VSYNC: scheduleVsync(); break; + case MSG_HANDLE_REFRESH_RATE_UPDATES: + handleRefreshRateUpdates(); + break; } } -} - -/* Glue for the NDK interface */ - +} // namespace android using namespace android; static inline Choreographer* AChoreographer_to_Choreographer(AChoreographer* choreographer) { return reinterpret_cast(choreographer); } +// Glue for private C api +namespace android { +void AChoreographer_signalRefreshRateCallbacks(nsecs_t vsyncPeriod) EXCLUDES(gChoreographers.lock) { + std::lock_guard _l(gChoreographers.lock); + gChoreographers.mLastKnownVsync.store(vsyncPeriod); + for (auto c : gChoreographers.ptrs) { + c->scheduleLatestConfigRequest(); + } +} + +void AChoreographer_initJVM(JNIEnv* env) { + env->GetJavaVM(&gJni.jvm); + // Now we need to find the java classes. + jclass dmgClass = env->FindClass("android/hardware/display/DisplayManagerGlobal"); + gJni.displayManagerGlobal.clazz = static_cast(env->NewGlobalRef(dmgClass)); + gJni.displayManagerGlobal.getInstance = + env->GetStaticMethodID(dmgClass, "getInstance", + "()Landroid/hardware/display/DisplayManagerGlobal;"); + gJni.displayManagerGlobal.registerNativeChoreographerForRefreshRateCallbacks = + env->GetMethodID(dmgClass, "registerNativeChoreographerForRefreshRateCallbacks", "()V"); + gJni.displayManagerGlobal.unregisterNativeChoreographerForRefreshRateCallbacks = + env->GetMethodID(dmgClass, "unregisterNativeChoreographerForRefreshRateCallbacks", + "()V"); +} + +AChoreographer* AChoreographer_routeGetInstance() { + return AChoreographer_getInstance(); +} +void AChoreographer_routePostFrameCallback(AChoreographer* choreographer, + AChoreographer_frameCallback callback, void* data) { + return AChoreographer_postFrameCallback(choreographer, callback, data); +} +void AChoreographer_routePostFrameCallbackDelayed(AChoreographer* choreographer, + AChoreographer_frameCallback callback, void* data, + long delayMillis) { + return AChoreographer_postFrameCallbackDelayed(choreographer, callback, data, delayMillis); +} +void AChoreographer_routePostFrameCallback64(AChoreographer* choreographer, + AChoreographer_frameCallback64 callback, void* data) { + return AChoreographer_postFrameCallback64(choreographer, callback, data); +} +void AChoreographer_routePostFrameCallbackDelayed64(AChoreographer* choreographer, + AChoreographer_frameCallback64 callback, + void* data, uint32_t delayMillis) { + return AChoreographer_postFrameCallbackDelayed64(choreographer, callback, data, delayMillis); +} +void AChoreographer_routeRegisterRefreshRateCallback(AChoreographer* choreographer, + AChoreographer_refreshRateCallback callback, + void* data) { + return AChoreographer_registerRefreshRateCallback(choreographer, callback, data); +} +void AChoreographer_routeUnregisterRefreshRateCallback(AChoreographer* choreographer, + AChoreographer_refreshRateCallback callback, + void* data) { + return AChoreographer_unregisterRefreshRateCallback(choreographer, callback, data); +} + +} // namespace android + +/* Glue for the NDK interface */ + static inline const Choreographer* AChoreographer_to_Choreographer( const AChoreographer* choreographer) { return reinterpret_cast(choreographer); @@ -343,5 +550,6 @@ void AChoreographer_handlePendingEvents(AChoreographer* choreographer, void* dat // Pass dummy fd and events args to handleEvent, since the underlying // DisplayEventDispatcher doesn't need them outside of validating that a // Looper instance didn't break, but these args circumvent those checks. - AChoreographer_to_Choreographer(choreographer)->handleEvent(-1, Looper::EVENT_INPUT, data); + Choreographer* impl = AChoreographer_to_Choreographer(choreographer); + impl->handleEvent(-1, Looper::EVENT_INPUT, data); } diff --git a/libs/nativedisplay/Android.bp b/libs/nativedisplay/Android.bp index c9565780e0..f56b3a2178 100644 --- a/libs/nativedisplay/Android.bp +++ b/libs/nativedisplay/Android.bp @@ -12,23 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -ndk_headers { - name: "libnativedisplay_ndk_headers", - from: "include/android", - to: "android", - srcs: ["include/android/*.h"], - license: "NOTICE", -} - cc_library_headers { name: "libnativedisplay_headers", - export_include_dirs: ["include"], + export_include_dirs: ["include",], } -cc_library { +cc_library_shared { name: "libnativedisplay", export_include_dirs: [ "include", + "include-private", ], clang: true, @@ -63,6 +56,10 @@ cc_library { "libnativehelper", ], + export_shared_lib_headers: [ + "libnativehelper", + ], + header_libs: [ "libnativedisplay_headers", ], diff --git a/libs/nativedisplay/include-private/private/android/choreographer.h b/libs/nativedisplay/include-private/private/android/choreographer.h new file mode 100644 index 0000000000..21649304bf --- /dev/null +++ b/libs/nativedisplay/include-private/private/android/choreographer.h @@ -0,0 +1,55 @@ +/* + * Copyright 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. + */ + +#pragma once + +#include +#include +#include + +namespace android { + +// Registers the global JVM for AChoreographer +void AChoreographer_initJVM(JNIEnv* env); + +// Signals all AChoregorapher* instances that a new vsync period is available +// for consumption by callbacks. +void AChoreographer_signalRefreshRateCallbacks(int64_t vsyncPeriod); + +// Trampoline functions allowing libandroid.so to define the NDK symbols without including +// the entirety of libnativedisplay as a whole static lib. As libnativedisplay +// maintains global state, libnativedisplay can never be directly statically +// linked so that global state won't be duplicated. This way libandroid.so can +// reroute the NDK methods into the implementations defined by libnativedisplay +AChoreographer* AChoreographer_routeGetInstance(); +void AChoreographer_routePostFrameCallback(AChoreographer* choreographer, + AChoreographer_frameCallback callback, void* data); +void AChoreographer_routePostFrameCallbackDelayed(AChoreographer* choreographer, + AChoreographer_frameCallback callback, void* data, + long delayMillis); +void AChoreographer_routePostFrameCallback64(AChoreographer* choreographer, + AChoreographer_frameCallback64 callback, void* data); +void AChoreographer_routePostFrameCallbackDelayed64(AChoreographer* choreographer, + AChoreographer_frameCallback64 callback, + void* data, uint32_t delayMillis); +void AChoreographer_routeRegisterRefreshRateCallback(AChoreographer* choreographer, + AChoreographer_refreshRateCallback callback, + void* data); +void AChoreographer_routeUnregisterRefreshRateCallback(AChoreographer* choreographer, + AChoreographer_refreshRateCallback callback, + void* data); + +} // namespace android diff --git a/libs/nativedisplay/include/android/choreographer.h b/libs/nativedisplay/include/android/choreographer.h deleted file mode 100644 index 5fd3de9f3c..0000000000 --- a/libs/nativedisplay/include/android/choreographer.h +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright (C) 2015 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 Choreographer - * @{ - */ - -/** - * @file choreographer.h - */ - -#ifndef ANDROID_CHOREOGRAPHER_H -#define ANDROID_CHOREOGRAPHER_H - -#include -#include - -__BEGIN_DECLS - -struct AChoreographer; -typedef struct AChoreographer AChoreographer; - -/** - * Prototype of the function that is called when a new frame is being rendered. - * It's passed the time that the frame is being rendered as nanoseconds in the - * CLOCK_MONOTONIC time base, as well as the data pointer provided by the - * application that registered a callback. All callbacks that run as part of - * rendering a frame will observe the same frame time, so it should be used - * whenever events need to be synchronized (e.g. animations). - */ -typedef void (*AChoreographer_frameCallback)(long frameTimeNanos, void* data); - -/** - * Prototype of the function that is called when a new frame is being rendered. - * It's passed the time that the frame is being rendered as nanoseconds in the - * CLOCK_MONOTONIC time base, as well as the data pointer provided by the - * application that registered a callback. All callbacks that run as part of - * rendering a frame will observe the same frame time, so it should be used - * whenever events need to be synchronized (e.g. animations). - */ -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 - -/** - * Get the AChoreographer instance for the current thread. This must be called - * on an ALooper thread. - * - * Available since API level 24. - */ -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); - -/** - * Deprecated: Use AChoreographer_postFrameCallbackDelayed64 instead. - */ -void AChoreographer_postFrameCallbackDelayed(AChoreographer* choreographer, - AChoreographer_frameCallback callback, void* data, - long delayMillis) __INTRODUCED_IN(24) __DEPRECATED_IN(29); - -#endif /* __ANDROID_API__ >= 24 */ - -#if __ANDROID_API__ >= 29 - -/** - * Power a callback to be run on the next frame. The data pointer provided will - * be passed to the callback function when it's called. - * - * Available since API level 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 - * data pointer provided will be passed to the callback function when it's - * called. - * - * Available since API level 29. - */ -void AChoreographer_postFrameCallbackDelayed64(AChoreographer* choreographer, - 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. - */ -void AChoreographer_registerRefreshRateCallback(AChoreographer* choreographer, - AChoreographer_refreshRateCallback, void* data); - -/** - * 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. - */ -void AChoreographer_unregisterRefreshRateCallback(AChoreographer* choreographer, - AChoreographer_refreshRateCallback, void* data); -#endif /* __ANDROID_API__ >= 30 */ - -__END_DECLS - -#endif // ANDROID_CHOREOGRAPHER_H - -/** @} */ diff --git a/libs/nativedisplay/include/surfacetexture/surface_texture_platform.h b/libs/nativedisplay/include/surfacetexture/surface_texture_platform.h index 6a94a771e8..e2d036bfb0 100644 --- a/libs/nativedisplay/include/surfacetexture/surface_texture_platform.h +++ b/libs/nativedisplay/include/surfacetexture/surface_texture_platform.h @@ -19,7 +19,7 @@ #include #include - +#include #include // This file provides a facade API on top of SurfaceTexture, which avoids using @@ -30,6 +30,20 @@ struct ASurfaceTexture; namespace android { +// Trampoline functions allowing libandroid.so to define the NDK symbols without including +// the entirety of libnativedisplay as a whole static lib. As libnativedisplay +// maintains global state, libnativedisplay can never be directly statically +// linked so that global state won't be duplicated. This way libandroid.so can +// reroute the NDK methods into the implementations defined by libnativedisplay +ANativeWindow* ASurfaceTexture_routeAcquireANativeWindow(ASurfaceTexture* st); +int ASurfaceTexture_routeAttachToGLContext(ASurfaceTexture* st, uint32_t texName); +int ASurfaceTexture_routeDetachFromGLContext(ASurfaceTexture* st); +void ASurfaceTexture_routeRelease(ASurfaceTexture* st); +int ASurfaceTexture_routeUpdateTexImage(ASurfaceTexture* st); +void ASurfaceTexture_routeGetTransformMatrix(ASurfaceTexture* st, float mtx[16]); +int64_t ASurfaceTexture_routeGetTimestamp(ASurfaceTexture* st); +ASurfaceTexture* ASurfaceTexture_routeFromSurfaceTexture(JNIEnv* env, jobject surfacetexture); + /** * ASurfaceTexture_getCurrentTextureTarget returns the texture target of the * current texture. diff --git a/libs/nativedisplay/libnativedisplay.map.txt b/libs/nativedisplay/libnativedisplay.map.txt index 483fb25cb7..fc59431d08 100644 --- a/libs/nativedisplay/libnativedisplay.map.txt +++ b/libs/nativedisplay/libnativedisplay.map.txt @@ -20,6 +20,15 @@ LIBNATIVEDISPLAY { LIBNATIVEDISPLAY_PLATFORM { global: extern "C++" { + android::AChoreographer_initJVM*; + android::AChoreographer_routeGetInstance*; + android::AChoreographer_routePostFrameCallback*; + android::AChoreographer_routePostFrameCallbackDelayed*; + android::AChoreographer_routePostFrameCallback64*; + android::AChoreographer_routePostFrameCallbackDelayed64*; + android::AChoreographer_routeRegisterRefreshRateCallback*; + android::AChoreographer_routeUnregisterRefreshRateCallback*; + android::AChoreographer_signalRefreshRateCallbacks*; android::ADisplay_acquirePhysicalDisplays*; android::ADisplay_release*; android::ADisplay_getMaxSupportedFps*; @@ -36,6 +45,14 @@ LIBNATIVEDISPLAY_PLATFORM { android::ASurfaceTexture_takeConsumerOwnership*; android::ASurfaceTexture_releaseConsumerOwnership*; android::ASurfaceTexture_dequeueBuffer*; + android::ASurfaceTexture_routeAcquireANativeWindow*; + android::ASurfaceTexture_routeAttachToGLContext*; + android::ASurfaceTexture_routeDetachFromGLContext*; + android::ASurfaceTexture_routeGetTimestamp*; + android::ASurfaceTexture_routeGetTransformMatrix*; + android::ASurfaceTexture_routeUpdateTexImage*; + android::ASurfaceTexture_routeFromSurfaceTexture*; + android::ASurfaceTexture_routeRelease*; android::SurfaceTexture*; }; ASurfaceTexture_acquireANativeWindow; diff --git a/libs/nativedisplay/surfacetexture/surface_texture.cpp b/libs/nativedisplay/surfacetexture/surface_texture.cpp index 1670fbba57..d1bcd8d1b1 100644 --- a/libs/nativedisplay/surfacetexture/surface_texture.cpp +++ b/libs/nativedisplay/surfacetexture/surface_texture.cpp @@ -149,6 +149,37 @@ int64_t ASurfaceTexture_getTimestamp(ASurfaceTexture* st) { // The following functions are private/unstable API. namespace android { +ANativeWindow* ASurfaceTexture_routeAcquireANativeWindow(ASurfaceTexture* st) { + return ASurfaceTexture_acquireANativeWindow(st); +} + +int ASurfaceTexture_routeAttachToGLContext(ASurfaceTexture* st, uint32_t texName) { + return ASurfaceTexture_attachToGLContext(st, texName); +} + +void ASurfaceTexture_routeRelease(ASurfaceTexture* st) { + return ASurfaceTexture_release(st); +} + +int ASurfaceTexture_routeDetachFromGLContext(ASurfaceTexture* st) { + return ASurfaceTexture_detachFromGLContext(st); +} + +int ASurfaceTexture_routeUpdateTexImage(ASurfaceTexture* st) { + return ASurfaceTexture_updateTexImage(st); +} + +void ASurfaceTexture_routeGetTransformMatrix(ASurfaceTexture* st, float mtx[16]) { + return ASurfaceTexture_getTransformMatrix(st, mtx); +} + +int64_t ASurfaceTexture_routeGetTimestamp(ASurfaceTexture* st) { + return ASurfaceTexture_getTimestamp(st); +} + +ASurfaceTexture* ASurfaceTexture_routeFromSurfaceTexture(JNIEnv* env, jobject surfacetexture) { + return ASurfaceTexture_fromSurfaceTexture(env, surfacetexture); +} unsigned int ASurfaceTexture_getCurrentTextureTarget(ASurfaceTexture* st) { return st->consumer->getCurrentTextureTarget(); diff --git a/services/surfaceflinger/Scheduler/EventThread.cpp b/services/surfaceflinger/Scheduler/EventThread.cpp index 5dedb6a1e7..cee36a121f 100644 --- a/services/surfaceflinger/Scheduler/EventThread.cpp +++ b/services/surfaceflinger/Scheduler/EventThread.cpp @@ -152,16 +152,9 @@ void EventThreadConnection::requestNextVsync() { mEventThread->requestNextVsync(this); } -void EventThreadConnection::toggleConfigEvents(ISurfaceComposer::ConfigChanged configChangeFlag) { - ATRACE_NAME("enableConfigEvents"); - mConfigChanged = configChangeFlag; - - // In principle it's possible for rapidly toggling config events to drop an - // event here, but it's unlikely in practice. - if (configChangeFlag == ISurfaceComposer::eConfigChangedDispatch) { - mForcedConfigChangeDispatch = true; - mEventThread->requestLatestConfig(); - } +void EventThreadConnection::requestLatestConfig() { + ATRACE_NAME("requestLatestConfig"); + mEventThread->requestLatestConfig(this); } status_t EventThreadConnection::postEvent(const DisplayEventReceiver::Event& event) { @@ -276,8 +269,12 @@ void EventThread::requestNextVsync(const sp& connection) } } -void EventThread::requestLatestConfig() { +void EventThread::requestLatestConfig(const sp& connection) { std::lock_guard lock(mMutex); + if (connection->mForcedConfigChangeDispatch) { + return; + } + connection->mForcedConfigChangeDispatch = true; auto pendingConfigChange = std::find_if(std::begin(mPendingEvents), std::end(mPendingEvents), [&](const DisplayEventReceiver::Event& event) { @@ -384,6 +381,10 @@ void EventThread::threadMain(std::unique_lock& lock) { vsyncRequested |= connection->vsyncRequest != VSyncRequest::None; if (event && shouldConsumeEvent(*event, connection)) { + if (event->header.type == DisplayEventReceiver::DISPLAY_EVENT_CONFIG_CHANGED && + connection->mForcedConfigChangeDispatch) { + connection->mForcedConfigChangeDispatch = false; + } consumers.push_back(connection); } @@ -459,8 +460,8 @@ bool EventThread::shouldConsumeEvent(const DisplayEventReceiver::Event& event, return true; case DisplayEventReceiver::DISPLAY_EVENT_CONFIG_CHANGED: { - const bool forcedDispatch = connection->mForcedConfigChangeDispatch.exchange(false); - return forcedDispatch || + const bool oneTimeDispatch = connection->mForcedConfigChangeDispatch; + return oneTimeDispatch || connection->mConfigChanged == ISurfaceComposer::eConfigChangedDispatch; } diff --git a/services/surfaceflinger/Scheduler/EventThread.h b/services/surfaceflinger/Scheduler/EventThread.h index 9e7086eb0c..64acbd72d0 100644 --- a/services/surfaceflinger/Scheduler/EventThread.h +++ b/services/surfaceflinger/Scheduler/EventThread.h @@ -81,19 +81,19 @@ public: status_t stealReceiveChannel(gui::BitTube* outChannel) override; status_t setVsyncRate(uint32_t rate) override; void requestNextVsync() override; // asynchronous - void toggleConfigEvents(ISurfaceComposer::ConfigChanged configChangeFlag) override; + void requestLatestConfig() override; // asynchronous // Called in response to requestNextVsync. const ResyncCallback resyncCallback; VSyncRequest vsyncRequest = VSyncRequest::None; - std::atomic mConfigChanged = + ISurfaceComposer::ConfigChanged mConfigChanged = ISurfaceComposer::ConfigChanged::eConfigChangedSuppress; // Store whether we need to force dispatching a config change separately - // if mConfigChanged ever changes before the config change is dispatched // then we still need to propagate an initial config to the app if we // haven't already. - std::atomic mForcedConfigChangeDispatch = false; + bool mForcedConfigChangeDispatch = false; private: virtual void onFirstRef(); @@ -129,11 +129,10 @@ public: virtual void setVsyncRate(uint32_t rate, const sp& connection) = 0; // Requests the next vsync. If resetIdleTimer is set to true, it resets the idle timer. virtual void requestNextVsync(const sp& connection) = 0; - // Dispatches the most recent configuration // Usage of this method assumes that only the primary internal display // supports multiple display configurations. - virtual void requestLatestConfig() = 0; + virtual void requestLatestConfig(const sp& connection) = 0; // Retrieves the number of event connections tracked by this EventThread. virtual size_t getEventThreadConnectionCount() = 0; @@ -154,7 +153,7 @@ public: status_t registerDisplayEventConnection(const sp& connection) override; void setVsyncRate(uint32_t rate, const sp& connection) override; void requestNextVsync(const sp& connection) override; - void requestLatestConfig() override; + void requestLatestConfig(const sp& connection) override; // called before the screen is turned off from main thread void onScreenReleased() override; diff --git a/services/surfaceflinger/tests/unittests/mock/MockEventThread.h b/services/surfaceflinger/tests/unittests/mock/MockEventThread.h index 50eb390471..054aaf8ae1 100644 --- a/services/surfaceflinger/tests/unittests/mock/MockEventThread.h +++ b/services/surfaceflinger/tests/unittests/mock/MockEventThread.h @@ -40,7 +40,7 @@ public: status_t(const sp &)); MOCK_METHOD2(setVsyncRate, void(uint32_t, const sp &)); MOCK_METHOD1(requestNextVsync, void(const sp &)); - MOCK_METHOD0(requestLatestConfig, void()); + MOCK_METHOD1(requestLatestConfig, void(const sp &)); MOCK_METHOD1(pauseVsyncCallback, void(bool)); MOCK_METHOD0(getEventThreadConnectionCount, size_t()); }; -- cgit v1.2.3-59-g8ed1b From 7be0e2def2d9cff2436511696838fcf0734b4da1 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Tue, 2 Jun 2020 13:05:04 -0700 Subject: API level 30 cleanup. Make sure that we have the __INTRODUCED_IN()s and -- more importantly -- the API levels recorded in the documentation. Bug: https://github.com/android/ndk/issues/1271 Test: treehugger Change-Id: I74752f19f165fd5c56b2dfd783298c2da1a926d6 --- include/android/bitmap.h | 8 ++++++++ include/android/choreographer.h | 10 ++++++++-- include/android/imagedecoder.h | 38 ++++++++++++++++++++++++++++++++++++++ include/android/thermal.h | 30 +++++++++++++++++++----------- 4 files changed, 73 insertions(+), 13 deletions(-) (limited to 'include/android') diff --git a/include/android/bitmap.h b/include/android/bitmap.h index 2631b144af..f19539913e 100644 --- a/include/android/bitmap.h +++ b/include/android/bitmap.h @@ -125,6 +125,8 @@ int AndroidBitmap_getInfo(JNIEnv* env, jobject jbitmap, * 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); @@ -189,6 +191,8 @@ enum AndroidBitmapCompressFormat { /** * 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. @@ -202,6 +206,8 @@ typedef bool (*AndroidBitmap_CompressWriteFunc)(void* userContext, /** * 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. @@ -234,6 +240,8 @@ typedef struct AHardwareBuffer AHardwareBuffer; * * 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 diff --git a/include/android/choreographer.h b/include/android/choreographer.h index c1c4a72cd3..bdf11e42ca 100644 --- a/include/android/choreographer.h +++ b/include/android/choreographer.h @@ -129,9 +129,12 @@ void AChoreographer_postFrameCallbackDelayed64(AChoreographer* choreographer, * * This api is thread-safe. Any thread is allowed to register a new refresh * rate callback for the choreographer instance. + * + * Available since API level 30. */ void AChoreographer_registerRefreshRateCallback(AChoreographer* choreographer, - AChoreographer_refreshRateCallback, void* data); + AChoreographer_refreshRateCallback, void* data) + __INTRODUCED_IN(30); /** * Unregisters a callback to be run when the display refresh rate changes, along @@ -144,9 +147,12 @@ void AChoreographer_registerRefreshRateCallback(AChoreographer* choreographer, * 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); + AChoreographer_refreshRateCallback, void* data) + __INTRODUCED_IN(30); #endif /* __ANDROID_API__ >= 30 */ __END_DECLS diff --git a/include/android/imagedecoder.h b/include/android/imagedecoder.h index 3a87da0fee..d7e6e4118f 100644 --- a/include/android/imagedecoder.h +++ b/include/android/imagedecoder.h @@ -133,6 +133,8 @@ 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}. @@ -162,6 +164,8 @@ int AImageDecoder_createFromAAsset(struct AAsset* asset, AImageDecoder** outDeco /** * 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}. @@ -190,6 +194,8 @@ int AImageDecoder_createFromFd(int fd, AImageDecoder** outDecoder) __INTRODUCED_ /** * 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. @@ -217,12 +223,16 @@ int AImageDecoder_createFromBuffer(const void* buffer, size_t length, /** * 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 @@ -247,6 +257,8 @@ int AImageDecoder_setAndroidBitmapFormat(AImageDecoder*, * 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. @@ -267,6 +279,8 @@ int AImageDecoder_setUnpremultipliedRequired(AImageDecoder*, * 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 @@ -292,6 +306,8 @@ int AImageDecoder_setDataSpace(AImageDecoder*, int32_t dataspace) __INTRODUCED_I * 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 @@ -319,6 +335,8 @@ int AImageDecoder_setTargetSize(AImageDecoder*, int32_t width, int32_t height) _ * 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 @@ -344,6 +362,8 @@ int AImageDecoder_computeSampledSize(const AImageDecoder*, int sampleSize, * 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 @@ -376,6 +396,8 @@ typedef struct AImageDecoderHeaderInfo AImageDecoderHeaderInfo; * * 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); @@ -385,6 +407,8 @@ const AImageDecoderHeaderInfo* AImageDecoder_getHeaderInfo( * 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); @@ -393,12 +417,16 @@ int32_t AImageDecoderHeaderInfo_getWidth(const AImageDecoderHeaderInfo*) __INTRO * 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( @@ -409,6 +437,8 @@ const char* AImageDecoderHeaderInfo_getMimeType( * 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); @@ -419,6 +449,8 @@ int32_t AImageDecoderHeaderInfo_getAndroidBitmapFormat( * {@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); @@ -429,6 +461,8 @@ int AImageDecoderHeaderInfo_getAlphaFlags( * 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 @@ -452,12 +486,16 @@ int32_t AImageDecoderHeaderInfo_getDataSpace( * * 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. diff --git a/include/android/thermal.h b/include/android/thermal.h index 3247fa167b..83582d6791 100644 --- a/include/android/thermal.h +++ b/include/android/thermal.h @@ -60,8 +60,6 @@ extern "C" { #endif -#if __ANDROID_API__ >= 30 - enum AThermalStatus { /** Error in thermal status. */ ATHERMAL_STATUS_ERROR = -1, @@ -111,36 +109,45 @@ typedef struct AThermalManager AThermalManager; */ 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(); + */ +AThermalManager* AThermal_acquireManager() __INTRODUCED_IN(30); /** * Release the thermal manager pointer acquired via * {@link AThermal_acquireManager}. * - * @param manager The manager to be released. + * Available since API level 30. * + * @param manager The manager to be released. */ -void AThermal_releaseManager(AThermalManager *manager); +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); + */ +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. @@ -152,11 +159,13 @@ AThermalStatus AThermal_getCurrentThermalStatus(AThermalManager *manager); * EPIPE if communication with the system service has failed. */ int AThermal_registerThermalStatusListener(AThermalManager *manager, - AThermal_StatusCallback callback, void *data); + 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. @@ -168,8 +177,7 @@ int AThermal_registerThermalStatusListener(AThermalManager *manager, * EPIPE if communication with the system service has failed. */ int AThermal_unregisterThermalStatusListener(AThermalManager *manager, - AThermal_StatusCallback callback, void *data); - + AThermal_StatusCallback callback, void *data) __INTRODUCED_IN(30); #endif // __ANDROID_API__ >= 30 -- cgit v1.2.3-59-g8ed1b From 7a7321260b862b44db1b56e89f484fb7144bb921 Mon Sep 17 00:00:00 2001 From: Nick Cook Date: Wed, 3 Jun 2020 22:55:05 +0000 Subject: docs: Fix ref doc links. See generated output in cl/314618386. Bug: 148938276 Test: m ndk Change-Id: I7374793e72e1f836c2ba1eeeebe09ccdcf58ce4b --- include/android/configuration.h | 122 ++++++++++++++++++++-------------------- 1 file changed, 61 insertions(+), 61 deletions(-) (limited to 'include/android') 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 - * port + * port * resource qualifier. */ ACONFIGURATION_ORIENTATION_PORT = 0x0001, /** * Orientation: value corresponding to the - * land + * land * resource qualifier. */ ACONFIGURATION_ORIENTATION_LAND = 0x0002, @@ -75,7 +75,7 @@ enum { ACONFIGURATION_TOUCHSCREEN_ANY = 0x0000, /** * Touchscreen: value corresponding to the - * notouch + * notouch * resource qualifier. */ ACONFIGURATION_TOUCHSCREEN_NOTOUCH = 0x0001, @@ -83,7 +83,7 @@ enum { ACONFIGURATION_TOUCHSCREEN_STYLUS = 0x0002, /** * Touchscreen: value corresponding to the - * finger + * finger * resource qualifier. */ ACONFIGURATION_TOUCHSCREEN_FINGER = 0x0003, @@ -92,43 +92,43 @@ enum { ACONFIGURATION_DENSITY_DEFAULT = 0, /** * Density: value corresponding to the - * ldpi + * ldpi * resource qualifier. */ ACONFIGURATION_DENSITY_LOW = 120, /** * Density: value corresponding to the - * mdpi + * mdpi * resource qualifier. */ ACONFIGURATION_DENSITY_MEDIUM = 160, /** * Density: value corresponding to the - * tvdpi + * tvdpi * resource qualifier. */ ACONFIGURATION_DENSITY_TV = 213, /** * Density: value corresponding to the - * hdpi + * hdpi * resource qualifier. */ ACONFIGURATION_DENSITY_HIGH = 240, /** * Density: value corresponding to the - * xhdpi + * xhdpi * resource qualifier. */ ACONFIGURATION_DENSITY_XHIGH = 320, /** * Density: value corresponding to the - * xxhdpi + * xxhdpi * resource qualifier. */ ACONFIGURATION_DENSITY_XXHIGH = 480, /** * Density: value corresponding to the - * xxxhdpi + * xxxhdpi * resource qualifier. */ ACONFIGURATION_DENSITY_XXXHIGH = 640, @@ -141,19 +141,19 @@ enum { ACONFIGURATION_KEYBOARD_ANY = 0x0000, /** * Keyboard: value corresponding to the - * nokeys + * nokeys * resource qualifier. */ ACONFIGURATION_KEYBOARD_NOKEYS = 0x0001, /** * Keyboard: value corresponding to the - * qwerty + * qwerty * resource qualifier. */ ACONFIGURATION_KEYBOARD_QWERTY = 0x0002, /** * Keyboard: value corresponding to the - * 12key + * 12key * resource qualifier. */ ACONFIGURATION_KEYBOARD_12KEY = 0x0003, @@ -162,25 +162,25 @@ enum { ACONFIGURATION_NAVIGATION_ANY = 0x0000, /** * Navigation: value corresponding to the - * nonav + * nonav * resource qualifier. */ ACONFIGURATION_NAVIGATION_NONAV = 0x0001, /** * Navigation: value corresponding to the - * dpad + * dpad * resource qualifier. */ ACONFIGURATION_NAVIGATION_DPAD = 0x0002, /** * Navigation: value corresponding to the - * trackball + * trackball * resource qualifier. */ ACONFIGURATION_NAVIGATION_TRACKBALL = 0x0003, /** * Navigation: value corresponding to the - * wheel + * wheel * resource qualifier. */ ACONFIGURATION_NAVIGATION_WHEEL = 0x0004, @@ -189,19 +189,19 @@ enum { ACONFIGURATION_KEYSHIDDEN_ANY = 0x0000, /** * Keyboard availability: value corresponding to the - * keysexposed + * keysexposed * resource qualifier. */ ACONFIGURATION_KEYSHIDDEN_NO = 0x0001, /** * Keyboard availability: value corresponding to the - * keyshidden + * keyshidden * resource qualifier. */ ACONFIGURATION_KEYSHIDDEN_YES = 0x0002, /** * Keyboard availability: value corresponding to the - * keyssoft + * keyssoft * resource qualifier. */ ACONFIGURATION_KEYSHIDDEN_SOFT = 0x0003, @@ -210,13 +210,13 @@ enum { ACONFIGURATION_NAVHIDDEN_ANY = 0x0000, /** * Navigation availability: value corresponding to the - * navexposed + * navexposed * resource qualifier. */ ACONFIGURATION_NAVHIDDEN_NO = 0x0001, /** * Navigation availability: value corresponding to the - * navhidden + * navhidden * 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 - * small + * small * resource qualifier. */ ACONFIGURATION_SCREENSIZE_SMALL = 0x01, /** * Screen size: value indicating the screen is at least * approximately 320x470 dp units, corresponding to the - * normal + * normal * resource qualifier. */ ACONFIGURATION_SCREENSIZE_NORMAL = 0x02, /** * Screen size: value indicating the screen is at least * approximately 480x640 dp units, corresponding to the - * large + * large * resource qualifier. */ ACONFIGURATION_SCREENSIZE_LARGE = 0x03, /** * Screen size: value indicating the screen is at least * approximately 720x960 dp units, corresponding to the - * xlarge + * xlarge * resource qualifier. */ ACONFIGURATION_SCREENSIZE_XLARGE = 0x04, @@ -256,13 +256,13 @@ enum { ACONFIGURATION_SCREENLONG_ANY = 0x00, /** * Screen layout: value that corresponds to the - * notlong + * notlong * resource qualifier. */ ACONFIGURATION_SCREENLONG_NO = 0x1, /** * Screen layout: value that corresponds to the - * long + * long * resource qualifier. */ ACONFIGURATION_SCREENLONG_YES = 0x2, @@ -275,13 +275,13 @@ enum { ACONFIGURATION_WIDE_COLOR_GAMUT_ANY = 0x00, /** * Wide color gamut: value that corresponds to - * no + * no * nowidecg resource qualifier specified. */ ACONFIGURATION_WIDE_COLOR_GAMUT_NO = 0x1, /** * Wide color gamut: value that corresponds to - * + * * widecg resource qualifier specified. */ ACONFIGURATION_WIDE_COLOR_GAMUT_YES = 0x2, @@ -290,13 +290,13 @@ enum { ACONFIGURATION_HDR_ANY = 0x00, /** * HDR: value that corresponds to - * + * * lowdr resource qualifier specified. */ ACONFIGURATION_HDR_NO = 0x1, /** * HDR: value that corresponds to - * + * * highdr resource qualifier specified. */ ACONFIGURATION_HDR_YES = 0x2, @@ -305,38 +305,38 @@ enum { ACONFIGURATION_UI_MODE_TYPE_ANY = 0x00, /** * UI mode: value that corresponds to - * no + * no * UI mode type resource qualifier specified. */ ACONFIGURATION_UI_MODE_TYPE_NORMAL = 0x01, /** * UI mode: value that corresponds to - * desk resource qualifier specified. + * desk resource qualifier specified. */ ACONFIGURATION_UI_MODE_TYPE_DESK = 0x02, /** * UI mode: value that corresponds to - * car resource qualifier specified. + * car resource qualifier specified. */ ACONFIGURATION_UI_MODE_TYPE_CAR = 0x03, /** * UI mode: value that corresponds to - * television resource qualifier specified. + * television resource qualifier specified. */ ACONFIGURATION_UI_MODE_TYPE_TELEVISION = 0x04, /** * UI mode: value that corresponds to - * appliance resource qualifier specified. + * appliance resource qualifier specified. */ ACONFIGURATION_UI_MODE_TYPE_APPLIANCE = 0x05, /** * UI mode: value that corresponds to - * watch resource qualifier specified. + * watch resource qualifier specified. */ ACONFIGURATION_UI_MODE_TYPE_WATCH = 0x06, /** * UI mode: value that corresponds to - * vr resource qualifier specified. + * vr 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 - * notnight resource qualifier specified. + * notnight resource qualifier specified. */ ACONFIGURATION_UI_MODE_NIGHT_NO = 0x1, /** * UI night mode: value that corresponds to - * night resource qualifier specified. + * night resource qualifier specified. */ ACONFIGURATION_UI_MODE_NIGHT_YES = 0x2, @@ -366,78 +366,78 @@ enum { ACONFIGURATION_LAYOUTDIR_ANY = 0x00, /** * Layout direction: value that corresponds to - * ldltr resource qualifier specified. + * ldltr resource qualifier specified. */ ACONFIGURATION_LAYOUTDIR_LTR = 0x01, /** * Layout direction: value that corresponds to - * ldrtl resource qualifier specified. + * ldrtl resource qualifier specified. */ ACONFIGURATION_LAYOUTDIR_RTL = 0x02, /** * Bit mask for - * mcc + * mcc * configuration. */ ACONFIGURATION_MCC = 0x0001, /** * Bit mask for - * mnc + * mnc * configuration. */ ACONFIGURATION_MNC = 0x0002, /** * Bit mask for - * locale + * locale * configuration. */ ACONFIGURATION_LOCALE = 0x0004, /** * Bit mask for - * touchscreen + * touchscreen * configuration. */ ACONFIGURATION_TOUCHSCREEN = 0x0008, /** * Bit mask for - * keyboard + * keyboard * configuration. */ ACONFIGURATION_KEYBOARD = 0x0010, /** * Bit mask for - * keyboardHidden + * keyboardHidden * configuration. */ ACONFIGURATION_KEYBOARD_HIDDEN = 0x0020, /** * Bit mask for - * navigation + * navigation * configuration. */ ACONFIGURATION_NAVIGATION = 0x0040, /** * Bit mask for - * orientation + * orientation * configuration. */ ACONFIGURATION_ORIENTATION = 0x0080, /** * Bit mask for - * density + * density * configuration. */ ACONFIGURATION_DENSITY = 0x0100, /** * Bit mask for - * screen size + * screen size * configuration. */ ACONFIGURATION_SCREEN_SIZE = 0x0200, /** * Bit mask for - * platform version + * platform version * configuration. */ ACONFIGURATION_VERSION = 0x0400, @@ -447,27 +447,27 @@ enum { ACONFIGURATION_SCREEN_LAYOUT = 0x0800, /** * Bit mask for - * ui mode + * ui mode * configuration. */ ACONFIGURATION_UI_MODE = 0x1000, /** * Bit mask for - * smallest screen width + * smallest screen width * configuration. */ ACONFIGURATION_SMALLEST_SCREEN_SIZE = 0x2000, /** * Bit mask for - * layout direction + * layout direction * configuration. */ ACONFIGURATION_LAYOUTDIR = 0x4000, ACONFIGURATION_SCREEN_ROUND = 0x8000, /** * Bit mask for - * wide color gamut - * and HDR configurations. + * wide color gamut + * and HDR configurations. */ ACONFIGURATION_COLOR_MODE = 0x10000, /** -- cgit v1.2.3-59-g8ed1b From f1cf6a632da354cff3d8aed54913e1ee2909908e Mon Sep 17 00:00:00 2001 From: Luke Huang Date: Sat, 20 Jun 2020 13:01:33 +0800 Subject: Update the documentation of ANDROID_RESOLV_NO_CACHE_STORE Make it up-to-date. Test: N/A Bug: 150371903 Change-Id: Ia1402a18d6d466ffbb0357127d7d45cf6c722550 --- include/android/multinetwork.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include/android') diff --git a/include/android/multinetwork.h b/include/android/multinetwork.h index 59b1deb595..c6d1c94c0a 100644 --- a/include/android/multinetwork.h +++ b/include/android/multinetwork.h @@ -126,8 +126,8 @@ enum ResNsendFlags : uint32_t { ANDROID_RESOLV_NO_RETRY = 1 << 0, /** - * Do not cache the result of the lookup. The lookup may return a result that is already - * in the cache, unless the ANDROID_RESOLV_NO_CACHE_LOOKUP flag is also specified. + * Don't lookup this request in the cache, and don't cache the result of the lookup. + * This flag implies {@link #ANDROID_RESOLV_NO_CACHE_LOOKUP}. */ ANDROID_RESOLV_NO_CACHE_STORE = 1 << 1, -- cgit v1.2.3-59-g8ed1b From 8fc3b0aa17398b8475866923008cf463b535bfb7 Mon Sep 17 00:00:00 2001 From: Nick Cook Date: Thu, 9 Jul 2020 19:29:25 +0000 Subject: docs: Clarify the lifetime of AHardwareBuffer_toHardwareBuffer in docs. See generated output in cl/320449087. Bug: 140885254 Test: m ndk Change-Id: I5b27dcedd5b0d20003b46c05c40a8c7c26dd9d28 --- include/android/hardware_buffer_jni.h | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'include/android') 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: + * + *

+ * 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().
+ * 
* * Available since API level 26. */ -- cgit v1.2.3-59-g8ed1b