From 66d5815ca7a4edc2caf0c4426b50368d68b0e9d6 Mon Sep 17 00:00:00 2001 From: IllusionMan1212 Date: Wed, 7 Aug 2024 13:07:15 +0200 Subject: [PATCH] finish top level android directory files --- set_abort_message.odin | 18 ++ sharedmem.odin | 77 ++++++ sharedmem_jni.odin | 24 ++ storage_manager.odin | 121 +++++++++ surface_control.odin | 523 +++++++++++++++++++++++++++++++++++++++ surface_texture.odin | 128 ++++++++++ surface_texture_jni.odin | 24 ++ sync.odin | 87 +++++++ system_fonts.odin | 86 +++++++ thermal.odin | 165 ++++++++++++ trace.odin | 72 ++++++ 11 files changed, 1325 insertions(+) create mode 100644 set_abort_message.odin create mode 100644 sharedmem.odin create mode 100644 sharedmem_jni.odin create mode 100644 storage_manager.odin create mode 100644 surface_control.odin create mode 100644 surface_texture.odin create mode 100644 surface_texture_jni.odin create mode 100644 sync.odin create mode 100644 system_fonts.odin create mode 100644 thermal.odin create mode 100644 trace.odin diff --git a/set_abort_message.odin b/set_abort_message.odin new file mode 100644 index 0000000..8890121 --- /dev/null +++ b/set_abort_message.odin @@ -0,0 +1,18 @@ +//+build android +package android + +foreign import android "system:android" + +foreign android { + /** + * android_set_abort_message() sets the abort message that will be shown + * by [debuggerd](https://source.android.com/devices/tech/debug/native-crash). + * This is meant for use by libraries that deliberately abort so that they can + * provide an explanation. It is used within bionic to implement assert() and + * all FORTIFY/fdsan aborts. + * + * Available since API level 21. + */ + + android_set_abort_message :: proc(__msg: cstring) --- +} diff --git a/sharedmem.odin b/sharedmem.odin new file mode 100644 index 0000000..c8d5ea5 --- /dev/null +++ b/sharedmem.odin @@ -0,0 +1,77 @@ +//+build android +package android + +foreign import android "system:android" + +foreign android { + /** + * Create a shared memory region. + * + * Create shared memory region and returns an file descriptor. The resulting file descriptor can be + * mmap'ed to process memory space with PROT_READ | PROT_WRITE | PROT_EXEC. Access to shared memory + * region can be restricted with {@link ASharedMemory_setProt}. + * + * Use close() to release the shared memory region. + * + * Use android.os.ParcelFileDescriptor + * to pass the file descriptor to another process. File descriptors may also be sent to other + * processes over a Unix domain socket with sendmsg and SCM_RIGHTS. See sendmsg(3) and + * cmsg(3) man pages for more information. + * + * If you intend to share this file descriptor with a child process after + * calling exec(3), note that you will need to use fcntl(2) with FD_SETFD + * to clear the FD_CLOEXEC flag for this to work on all versions of Android. + * + * Available since API level 26. + * + * \param name an optional name. + * \param size size of the shared memory region + * \return file descriptor that denotes the shared memory + * -1 and sets errno on failure, or -EINVAL if the error is that size was 0. + */ + ASharedMemory_create :: proc(name: cstring, size: uint) -> i32 --- + + /** + * Get the size of the shared memory region. + * + * Available since API level 26. + * + * \param fd file descriptor of the shared memory region + * \return size in bytes 0 if fd is not a valid shared memory file descriptor. + */ + ASharedMemory_getSize :: proc(fd: i32) -> uint --- + + /** + * Restrict access of shared memory region. + * + * This function restricts access of a shared memory region. Access can only be removed. The effect + * applies globally to all file descriptors in all processes across the system that refer to this + * shared memory region. Existing memory mapped regions are not affected. + * + * It is a common use case to create a shared memory region, map it read/write locally to intialize + * content, and then send the shared memory to another process with read only access. Code example + * as below (error handling omited). + * + * + * int fd = ASharedMemory_create("memory", 128) + * + * // By default it has PROT_READ | PROT_WRITE | PROT_EXEC. + * size_t memSize = ASharedMemory_getSize(fd) + * char *buffer = (char *) mmap(NULL, memSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0) + * + * strcpy(buffer, "This is an example.") // trivially initialize content + * + * // limit access to read only + * ASharedMemory_setProt(fd, PROT_READ) + * + * // share fd with another process here and the other process can only map with PROT_READ. + * + * Available since API level 26. + * + * \param fd file descriptor of the shared memory region. + * \param prot any bitwise-or'ed combination of PROT_READ, PROT_WRITE, PROT_EXEC denoting + * updated access. Note access can only be removed, but not added back. + * \return 0 for success, -1 and sets errno on failure. + */ + ASharedMemory_setProt :: proc(fd: i32, prot: i32) -> i32 --- +} diff --git a/sharedmem_jni.odin b/sharedmem_jni.odin new file mode 100644 index 0000000..f96fbd2 --- /dev/null +++ b/sharedmem_jni.odin @@ -0,0 +1,24 @@ +//+build android +package android + +foreign import android "system:android" + +foreign android { + /** + * Returns a dup'd FD from the given Java android.os.SharedMemory object. The returned file + * descriptor has all the same properties & capabilities as the FD returned from + * ASharedMemory_create(), however the protection flags will be the same as those of the + * android.os.SharedMemory object. + * + * Use close() to release the shared memory region. + * + * Available since API level 27. + * + * \param env The JNIEnv* pointer + * \param sharedMemory The Java android.os.SharedMemory object + * \return file descriptor that denotes the shared memory; -1 if the shared memory object is + * already closed, if the JNIEnv or jobject is NULL, or if there are too many open file + * descriptors (errno=EMFILE) + */ + ASharedMemory_dupFromJava :: proc(env: ^JNIEnv, sharedMemory: jobject) -> i32 --- +} diff --git a/storage_manager.odin b/storage_manager.odin new file mode 100644 index 0000000..1e5da94 --- /dev/null +++ b/storage_manager.odin @@ -0,0 +1,121 @@ +//+build android +package android + +foreign import android "system:android" + +/** + * The different states of a OBB storage passed to AStorageManager_obbCallbackFunc(). + */ +OBBState :: enum i32 { + /** + * The OBB container is now mounted and ready for use. Can be returned + * as the status for callbacks made during asynchronous OBB actions. + */ + MOUNTED = 1, + + /** + * The OBB container is now unmounted and not usable. Can be returned + * as the status for callbacks made during asynchronous OBB actions. + */ + UNMOUNTED = 2, + + /** + * There was an internal system error encountered while trying to + * mount the OBB. Can be returned as the status for callbacks made + * during asynchronous OBB actions. + */ + ERROR_INTERNAL = 20, + + /** + * The OBB could not be mounted by the system. Can be returned as the + * status for callbacks made during asynchronous OBB actions. + */ + ERROR_COULD_NOT_MOUNT = 21, + + /** + * The OBB could not be unmounted. This most likely indicates that a + * file is in use on the OBB. Can be returned as the status for + * callbacks made during asynchronous OBB actions. + */ + ERROR_COULD_NOT_UNMOUNT = 22, + + /** + * A call was made to unmount the OBB when it was not mounted. Can be + * returned as the status for callbacks made during asynchronous OBB + * actions. + */ + ERROR_NOT_MOUNTED = 23, + + /** + * The OBB has already been mounted. Can be returned as the status for + * callbacks made during asynchronous OBB actions. + */ + ERROR_ALREADY_MOUNTED = 24, + + /** + * The current application does not have permission to use this OBB. + * This could be because the OBB indicates it's owned by a different + * package. Can be returned as the status for callbacks made during + * asynchronous OBB actions. + */ + ERROR_PERMISSION_DENIED = 25, +} + +/** + * {@link AStorageManager} manages application OBB storage, a pointer + * can be obtained with AStorageManager_new(). + */ +AStorageManager :: struct{} + +/** +* Callback function for asynchronous calls made on OBB files. +* +* "state" is one of the following constants: +* - {@link AOBB_STATE_MOUNTED} +* - {@link AOBB_STATE_UNMOUNTED} +* - {@link AOBB_STATE_ERROR_INTERNAL} +* - {@link AOBB_STATE_ERROR_COULD_NOT_MOUNT} +* - {@link AOBB_STATE_ERROR_COULD_NOT_UNMOUNT} +* - {@link AOBB_STATE_ERROR_NOT_MOUNTED} +* - {@link AOBB_STATE_ERROR_ALREADY_MOUNTED} +* - {@link AOBB_STATE_ERROR_PERMISSION_DENIED} +*/ +AStorageManager_obbCallbackFunc :: #type proc "c" (filename: cstring, state: OBBState, data: rawptr) + +foreign android { + /** + * Obtains a new instance of AStorageManager. + */ + AStorageManager_new :: proc() -> ^AStorageManager --- + + /** + * Release AStorageManager instance. + */ + AStorageManager_delete :: proc(mgr: ^AStorageManager) --- + + /** + * Attempts to mount an OBB file. This is an asynchronous operation. + * + * Since API level 33, this function can only be used to mount unencrypted OBBs, + * i.e. the {@code key} parameter must be {@code null} or an empty string. Note + * that even before API level 33, mounting encrypted OBBs didn't work on many + * Android device implementations. Applications should not assume any particular + * behavior when {@code key} is nonempty. + */ + AStorageManager_mountObb :: proc(mgr: ^AStorageManager, filename: cstring, key: cstring, cb: AStorageManager_obbCallbackFunc, data: rawptr) --- + + /** + * Attempts to unmount an OBB file. This is an asynchronous operation. + */ + AStorageManager_unmountObb :: proc(mgr: ^AStorageManager, filename: cstring, force: i32, cb: AStorageManager_obbCallbackFunc, data: rawptr) --- + + /** + * Check whether an OBB is mounted. + */ + AStorageManager_isObbMounted :: proc(mgr: ^AStorageManager, filename: cstring) -> i32 --- + + /** + * Get the mounted path for an OBB. + */ + AStorageManager_getMountedObbPath :: proc(mgr: ^AStorageManager, filename: cstring) -> cstring --- +} diff --git a/surface_control.odin b/surface_control.odin new file mode 100644 index 0000000..434f4c4 --- /dev/null +++ b/surface_control.odin @@ -0,0 +1,523 @@ +//+build android +package android + +foreign import android "system:android" + +/** +* Parameter for ASurfaceTransaction_setVisibility(). +*/ +SurfaceTransactionVisibility :: enum i8 { + HIDE = 0, + SHOW = 1, +} + +/** +* Parameter for ASurfaceTransaction_setBufferTransparency(). +*/ +SurfaceTransactionTransparency :: enum i8 { + TRANSPARENT = 0, + TRANSLUCENT = 1, + OPAQUE = 2, +} + +/** + * The SurfaceControl API can be used to provide a hierarchy of surfaces for + * composition to the system compositor. ASurfaceControl represents a content node in + * this hierarchy. + */ +ASurfaceControl :: struct{} + +/** +* ASurfaceTransaction is a collection of updates to the surface tree that must +* be applied atomically. +*/ +ASurfaceTransaction :: struct{} + +/** +* An opaque handle returned during a callback that can be used to query general stats and stats for +* surfaces which were either removed or for which buffers were updated after this transaction was +* applied. +*/ +ASurfaceTransactionStats :: struct{} + +/** +* Since the transactions are applied asynchronously, the +* ASurfaceTransaction_OnComplete callback can be used to be notified when a frame +* including the updates in a transaction was presented. +* +* Buffers which are replaced or removed from the scene in the transaction invoking +* this callback may be reused after this point. +* +* \param context Optional context provided by the client that is passed into +* the callback. +* +* \param stats Opaque handle that can be passed to ASurfaceTransactionStats functions to query +* information about the transaction. The handle is only valid during the callback. +* +* THREADING +* The transaction completed callback can be invoked on any thread. +* +* Available since API level 29. +*/ +ASurfaceTransaction_OnComplete :: #type proc "c" (_context: rawptr, stats: ^ASurfaceTransactionStats) + +/** +* The ASurfaceTransaction_OnCommit callback is invoked when transaction is applied and the updates +* are ready to be presented. This callback will be invoked before the +* ASurfaceTransaction_OnComplete callback. +* +* This callback does not mean buffers have been released! It simply means that any new +* transactions applied will not overwrite the transaction for which we are receiving +* a callback and instead will be included in the next frame. If you are trying to avoid +* dropping frames (overwriting transactions), and unable to use timestamps (Which provide +* a more efficient solution), then this method provides a method to pace your transaction +* application. +* +* \param context Optional context provided by the client that is passed into the callback. +* +* \param stats Opaque handle that can be passed to ASurfaceTransactionStats functions to query +* information about the transaction. The handle is only valid during the callback. +* Present and release fences are not available for this callback. Querying them using +* ASurfaceTransactionStats_getPresentFenceFd and ASurfaceTransactionStats_getPreviousReleaseFenceFd +* will result in failure. +* +* THREADING +* The transaction committed callback can be invoked on any thread. +* +* Available since API level 31. +*/ +ASurfaceTransaction_OnCommit :: #type proc "c" (_context: rawptr, stats: ^ASurfaceTransactionStats) + +foreign android { + /** + * Creates an ASurfaceControl with either ANativeWindow or an ASurfaceControl as its parent. + * \a 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 + * null. + * + * The caller takes ownership of the ASurfaceControl returned and must release it + * using ASurfaceControl_release below. + * + * Available since API level 29. + */ + ASurfaceControl_createFromWindow :: proc(parent: ^ANativeWindow, debug_name: cstring) -> ^ASurfaceControl --- + + /** + * See ASurfaceControl_createFromWindow. + * + * Available since API level 29. + */ + ASurfaceControl_create :: proc(parent: ^ASurfaceControl, debug_name: cstring) -> ^ASurfaceControl --- + + /** + * Acquires a reference on the given ASurfaceControl object. This prevents the object + * from being deleted until the reference is removed. + * + * To release the reference, use the ASurfaceControl_release function. + * + * Available since API level 31. + */ + ASurfaceControl_acquire :: proc(surface_control: ^ASurfaceControl) --- + + /** + * Removes a reference that was previously acquired with one of the following functions: + * ASurfaceControl_createFromWindow + * ASurfaceControl_create + * ANativeWindow_acquire + * The surface and its children may remain on display as long as their parent remains on display. + * + * Available since API level 29. + */ + ASurfaceControl_release :: proc(surface_control: ^ASurfaceControl) --- + + /** + * The caller takes ownership of the transaction and must release it using + * ASurfaceTransaction_delete() below. + * + * Available since API level 29. + */ + ASurfaceTransaction_create :: proc() -> ^ASurfaceTransaction --- + + /** + * Destroys the \a transaction object. + * + * Available since API level 29. + */ + ASurfaceTransaction_delete :: proc(transaction: ^ASurfaceTransaction) --- + + /** + * Applies the updates accumulated in \a transaction. + * + * 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. + */ + ASurfaceTransaction_apply :: proc(transaction: ^ASurfaceTransaction) --- + + /** + * 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. + */ + ASurfaceTransactionStats_getLatchTime :: proc(surface_transaction_stats: ^ASurfaceTransactionStats) -> i64 --- + + /** + * 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. + * + * This query is not valid for ASurfaceTransaction_OnCommit callback. + * + * Available since API level 29. + */ + ASurfaceTransactionStats_getPresentFenceFd :: proc(surface_transaction_stats: ^ASurfaceTransactionStats) -> i32 --- + + /** + * \a outASurfaceControls returns an array of ASurfaceControl pointers that were updated during the + * transaction. Stats for the surfaces can be queried through ASurfaceTransactionStats functions. + * When the client is done using the array, it must release it by calling + * ASurfaceTransactionStats_releaseASurfaceControls. + * + * Available since API level 29. + * + * \a outASurfaceControlsSize returns the size of the ASurfaceControls array. + */ + ASurfaceTransactionStats_getASurfaceControls :: proc(surface_transaction_stats: ^ASurfaceTransactionStats, outASurfaceControls: ^^^ASurfaceControl, outASurfaceControlsSize: ^uint) --- + /** + * Releases the array of ASurfaceControls that were returned by + * ASurfaceTransactionStats_getASurfaceControls(). + * + * Available since API level 29. + */ + ASurfaceTransactionStats_releaseASurfaceControls :: proc(surface_controls: ^^ASurfaceControl) --- + + /** + * 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. + */ + ASurfaceTransactionStats_getAcquireTime :: proc(surface_transaction_stats: ^ASurfaceTransactionStats, surface_control: ^ASurfaceControl) -> i64 --- + + /** + * The returns the fence used to signal the release of the PREVIOUS buffer set on + * this surface. If this fence is valid (>=0), the PREVIOUS buffer has not yet been released and the + * fence will signal when the PREVIOUS buffer has been released. If the fence is -1 , the PREVIOUS + * buffer is already released. The recipient of the callback takes ownership of the + * previousReleaseFenceFd and is responsible for closing it. + * + * Each time a buffer is set through ASurfaceTransaction_setBuffer() on a transaction + * which is applied, the framework takes a ref on this buffer. The framework treats the + * addition of a buffer to a particular surface as a unique ref. When a transaction updates or + * removes a buffer from a surface, or removes the surface itself from the tree, this ref is + * guaranteed to be released in the OnComplete callback for this transaction. The + * ASurfaceControlStats provided in the callback for this surface may contain an optional fence + * which must be signaled before the ref is assumed to be released. + * + * The client must ensure that all pending refs on a buffer are released before attempting to reuse + * this buffer, otherwise synchronization errors may occur. + * + * This query is not valid for ASurfaceTransaction_OnCommit callback. + * + * Available since API level 29. + */ + ASurfaceTransactionStats_getPreviousReleaseFenceFd :: proc(surface_transaction_stats: ^ASurfaceTransactionStats, surface_control: ^ASurfaceControl) -> i32 --- + + /** + * 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. + */ + ASurfaceTransaction_setOnComplete :: proc(transaction: ^ASurfaceTransaction, _context: rawptr, func: ASurfaceTransaction_OnComplete) --- + + /** + * Sets the callback that will be invoked when the updates from this transaction are applied and are + * ready to be presented. This callback will be invoked before the ASurfaceTransaction_OnComplete + * callback. + * + * Available since API level 31. + */ + ASurfaceTransaction_setOnCommit :: proc(transaction: ^ASurfaceTransaction, _context: rawptr, func: ASurfaceTransaction_OnCommit) --- + + /** + * Reparents the \a surface_control from its old parent to the \a new_parent surface control. + * Any children of the reparented \a surface_control will remain children of the \a surface_control. + * + * The \a new_parent can be null. Surface controls with a null parent do not appear on the display. + * + * Available since API level 29. + */ + ASurfaceTransaction_reparent :: proc(transaction: ^ASurfaceTransaction, surface_control: ^ASurfaceControl, new_parent: ^ASurfaceControl) --- + + /** + * Updates the visibility of \a surface_control. If show is set to + * ASURFACE_TRANSACTION_VISIBILITY_HIDE, the \a surface_control and all surfaces in its subtree will + * be hidden. + * + * Available since API level 29. + */ + ASurfaceTransaction_setVisibility :: proc(transaction: ^ASurfaceTransaction, surface_control: ^ASurfaceControl, visibility: SurfaceTransactionVisibility) --- + + /** + * Updates the z order index for \a surface_control. Note that the z order for a surface + * is relative to other surfaces which are siblings of this surface. The behavior of sibilings with + * 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. + */ + ASurfaceTransaction_setZOrder :: proc(transaction: ^ASurfaceTransaction, surface_control: ^ASurfaceControl, z_order: i32) --- + + /** + * Updates the AHardwareBuffer displayed for \a surface_control. If not -1, the + * acquire_fence_fd should be a file descriptor that is signaled when all pending work + * for the buffer is complete and the buffer can be safely read. + * + * The frameworks takes ownership of the \a acquire_fence_fd passed and is responsible + * for closing it. + * + * Note that the buffer must be allocated with AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE + * as the surface control might be composited using the GPU. + * + * Available since API level 29. + */ + ASurfaceTransaction_setBuffer :: proc(transaction: ^ASurfaceTransaction, surface_control: ^ASurfaceControl, buffer: ^AHardwareBuffer, acquire_fence_fd: i32 = -1) --- + + /** + * Updates the color for \a surface_control. This will make the background color for the + * ASurfaceControl visible in transparent regions of the surface. Colors \a r, \a g, + * and \a b must be within the range that is valid for \a dataspace. \a dataspace and \a alpha + * will be the dataspace and alpha set for the background color layer. + * + * Available since API level 29. + */ + ASurfaceTransaction_setColor :: proc(transaction: ^ASurfaceTransaction, surface_control: ^ASurfaceControl, r: f32, g: f32, b: f32, alpha: f32, dataspace: ADataSpace) --- + + /** + * \param source The sub-rect within the buffer's content to be rendered inside the surface's area + * The surface's source rect is clipped by the bounds of its current buffer. The source rect's width + * and height must be > 0. + * + * \param destination Specifies the rect in the parent's space where this surface will be drawn. The post + * source rect bounds are scaled to fit the destination rect. The surface's destination rect is + * clipped by the bounds of its parent. The destination rect's width and height must be > 0. + * + * \param 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. + * + * @deprecated Use setCrop, setPosition, setBufferTransform, and setScale instead. Those functions + * provide well defined behavior and allows for more control by the apps. It also allows the caller + * to set different properties at different times, instead of having to specify all the desired + * properties at once. + */ + ASurfaceTransaction_setGeometry :: proc(transaction: ^ASurfaceTransaction, surface_control: ^ASurfaceControl, source: ^ARect, destination: ^ARect, transform: ANativeWindowTransform) --- + + /** + * Bounds the surface and its children to the bounds specified. The crop and buffer size will be + * used to determine the bounds of the surface. If no crop is specified and the surface has no + * buffer, the surface bounds is only constrained by the size of its parent bounds. + * + * \param crop The bounds of the crop to apply. + * + * Available since API level 31. + */ + ASurfaceTransaction_setCrop :: proc(transaction: ^ASurfaceTransaction, surface_control: ^ASurfaceControl, crop: ^ARect) --- + + /** + * Specifies the position in the parent's space where the surface will be drawn. + * + * \param x The x position to render the surface. + * \param y The y position to render the surface. + * + * Available since API level 31. + */ + ASurfaceTransaction_setPosition :: proc(transaction: ^ASurfaceTransaction, surface_control: ^ASurfaceControl, x: i32, y: i32) --- + + /** + * \param 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 transform use the + * NATIVE_WINDOW_TRANSFORM_* enum. + * + * Available since API level 31. + */ + ASurfaceTransaction_setBufferTransform :: proc(transaction: ^ASurfaceTransaction, surface_control: ^ASurfaceControl, transform: ANativeWindowTransform) --- + + /** + * Sets an x and y scale of a surface with (0, 0) as the centerpoint of the scale. + * + * \param xScale The scale in the x direction. Must be greater than 0. + * \param yScale The scale in the y direction. Must be greater than 0. + * + * Available since API level 31. + */ + ASurfaceTransaction_setScale :: proc(transaction: ^ASurfaceTransaction, surface_control: ^ASurfaceControl, xScale: f32, yScale: f32) --- + + /** + * 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. + */ + ASurfaceTransaction_setBufferTransparency :: proc(transaction: ^ASurfaceTransaction, surface_control: ^ASurfaceControl, transparency: SurfaceTransactionTransparency) --- + + /** + * 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. + */ + ASurfaceTransaction_setDamageRegion :: proc(transaction: ^ASurfaceTransaction, surface_control: ^ASurfaceControl, rects: [^]ARect , count: u32) --- + + /** + * Specifies a desiredPresentTime for the transaction. The framework will try to present + * the transaction at or after the time specified. + * + * Transactions will not be presented until all of their acquire fences have signaled even if the + * app requests an earlier present time. + * + * 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. + */ + ASurfaceTransaction_setDesiredPresentTime :: proc(transaction: ^ASurfaceTransaction, desiredPresentTime: i64) --- + + /** + * Sets the alpha for the buffer. It uses a premultiplied blending. + * + * The \a alpha must be between 0.0 and 1.0. + * + * Available since API level 29. + */ + ASurfaceTransaction_setBufferAlpha :: proc(transaction: ^ASurfaceTransaction, surface_control: ^ASurfaceControl, alpha: f32) --- + + /** + * 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. + */ + ASurfaceTransaction_setBufferDataSpace :: proc(transaction: ^ASurfaceTransaction, surface_control: ^ASurfaceControl, data_space: ADataSpace) --- + + /** + * SMPTE ST 2086 "Mastering Display Color Volume" static metadata + * + * When \a metadata is set to null, the framework does not use any smpte2086 metadata when rendering + * the surface's buffer. + * + * Available since API level 29. + */ + ASurfaceTransaction_setHdrMetadata_smpte2086 :: proc(transaction: ^ASurfaceTransaction, surface_control: ^ASurfaceControl, metadata: ^AHdrMetadata_smpte2086) --- + + /** + * Sets the CTA 861.3 "HDR Static Metadata Extension" static metadata on a surface. + * + * When \a 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. + */ + ASurfaceTransaction_setHdrMetadata_cta861_3 :: proc(transaction: ^ASurfaceTransaction, surface_control: ^ASurfaceControl, metadata: ^AHdrMetadata_cta861_3) --- + + /** + * Same as ASurfaceTransaction_setFrameRateWithChangeStrategy(transaction, surface_control, + * frameRate, compatibility, ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS). + * + * See ASurfaceTransaction_setFrameRateWithChangeStrategy(). + * + * Available since API level 30. + */ + ASurfaceTransaction_setFrameRate :: proc(transaction: ^ASurfaceTransaction, surface_control: ^ASurfaceControl, frameRate: f32, compatibility: ANativeWindow_FrameRateCompatibility) --- + + /** + * Sets the intended frame rate for \a 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. + * + * You can register for changes in the refresh rate using + * \a AChoreographer_registerRefreshRateCallback. + * + * \param 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. + * + * \param 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. This parameter is ignored when frameRate is 0. + * + * \param changeFrameRateStrategy Whether display refresh rate transitions caused by this + * surface should be seamless. A seamless transition is one that doesn't have any visual + * interruptions, such as a black screen for a second or two. See the + * ANATIVEWINDOW_CHANGE_FRAME_RATE_* values. This parameter is ignored when frameRate is 0. + * + * Available since API level 31. + */ + ASurfaceTransaction_setFrameRateWithChangeStrategy :: proc(transaction: ^ASurfaceTransaction, surface_control: ^ASurfaceControl, frameRate: f32, compatibility: ANativeWindow_FrameRateCompatibility, changeFrameRateStrategy: ANativeWindow_ChangeFrameRateStrategy) --- + + /** + * Indicate whether to enable backpressure for buffer submission to a given SurfaceControl. + * + * By default backpressure is disabled, which means submitting a buffer prior to receiving + * a callback for the previous buffer could lead to that buffer being "dropped". In cases + * where you are selecting for latency, this may be a desirable behavior! We had a new buffer + * ready, why shouldn't we show it? + * + * When back pressure is enabled, each buffer will be required to be presented + * before it is released and the callback delivered + * (absent the whole SurfaceControl being removed). + * + * Most apps are likely to have some sort of backpressure internally, e.g. you are + * waiting on the callback from frame N-2 before starting frame N. In high refresh + * rate scenarios there may not be much time between SurfaceFlinger completing frame + * N-1 (and therefore releasing buffer N-2) and beginning frame N. This means + * your app may not have enough time to respond in the callback. Using this flag + * and pushing buffers earlier for server side queuing will be advantageous + * in such cases. + * + * \param transaction The transaction in which to make the change. + * \param surface_control The ASurfaceControl on which to control buffer backpressure behavior. + * \param enableBackPressure Whether to enable back pressure. + * + * Available since API level 31. + */ + ASurfaceTransaction_setEnableBackPressure :: proc(transaction: ^ASurfaceTransaction, surface_control: ^ASurfaceControl, enableBackPressure: bool) --- + + /** + * Sets the frame timeline to use in SurfaceFlinger. + * + * A frame timeline should be chosen based on the frame deadline the application + * can meet when rendering the frame and the application's desired presentation time. + * By setting a frame timeline, SurfaceFlinger tries to present the frame at the corresponding + * expected presentation time. + * + * To receive frame timelines, a callback must be posted to Choreographer using + * AChoreographer_postVsyncCallback(). The \c vsyncId can then be extracted from the + * callback payload using AChoreographerFrameCallbackData_getFrameTimelineVsyncId(). + * + * \param vsyncId The vsync ID received from AChoreographer, setting the frame's presentation target + * to the corresponding expected presentation time and deadline from the frame to be rendered. A + * stale or invalid value will be ignored. + * + * Available since API level 33. + */ + ASurfaceTransaction_setFrameTimeline :: proc(transaction: ^ASurfaceTransaction, vsyncId: AVsyncId) --- +} diff --git a/surface_texture.odin b/surface_texture.odin new file mode 100644 index 0000000..bcbcde4 --- /dev/null +++ b/surface_texture.odin @@ -0,0 +1,128 @@ +//+build android +package android + +foreign import android "system:android" + +/** + * {@link ASurfaceTexture} is an opaque type to manage SurfaceTexture from native code + * + * {@link ASurfaceTexture} can be obtained from an android.graphics.SurfaceTexture object using + * ASurfaceTexture_fromSurfaceTexture(). + */ +ASurfaceTexture :: struct{} + +foreign android { + /** + * 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() + */ + ASurfaceTexture_release :: proc(st: ^ASurfaceTexture) --- + + /** + * 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 + * returned if \p st is null or if it's not an instance of android.graphics.SurfaceTexture + */ + ASurfaceTexture_acquireANativeWindow :: proc(st: ^ASurfaceTexture) -> ^ANativeWindow --- + + /** + * Attach the SurfaceTexture to the OpenGL ES context that is current on the calling thread. A + * new OpenGL ES texture object is created and populated with the SurfaceTexture image frame + * that was current at the time of the last call to {@link ASurfaceTexture_detachFromGLContext}. + * This new texture is bound to the GL_TEXTURE_EXTERNAL_OES texture target. + * + * This can be used to access the SurfaceTexture image contents from multiple OpenGL ES + * 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. + * \return 0 on success, negative posix error code otherwise (see ) + */ + ASurfaceTexture_attachToGLContext :: proc(st: ^ASurfaceTexture, texName: u32) -> i32 --- + + /** + * Detach the SurfaceTexture from the OpenGL ES context that owns the OpenGL ES texture object. + * This call must be made with the OpenGL ES context current on the calling thread. The OpenGL + * ES texture object will be deleted as a result of this call. After calling this method all + * calls to {@link ASurfaceTexture_updateTexImage} will fail until a successful call to + * {@link ASurfaceTexture_attachToGLContext} is made. + * + * This can be used to access the SurfaceTexture image contents from multiple OpenGL ES + * 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 ) + */ + ASurfaceTexture_detachFromGLContext :: proc(st: ^ASurfaceTexture) -> i32 --- + + /** + * Update the texture image to the most recent frame from the image stream. This may only be + * 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 ) + */ + ASurfaceTexture_updateTexImage :: proc(st: ^ASurfaceTexture) -> i32 --- + + /** + * Retrieve the 4x4 texture coordinate transform matrix associated with the texture image set by + * the most recent call to updateTexImage. + * + * This transform matrix maps 2D homogeneous texture coordinates of the form (s, t, 0, 1) with s + * and t in the inclusive range [0, 1] to the texture coordinate that should be used to sample + * that location from the texture. Sampling the texture outside of the range of this transform + * is undefined. + * + * 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. + */ + ASurfaceTexture_getTransformMatrix :: proc(st: ^ASurfaceTexture, mtx: [16]f32) --- + + /** + * Retrieve the timestamp associated with the texture image set by the most recent call to + * updateTexImage. + * + * This timestamp is in nanoseconds, and is normally monotonically increasing. The timestamp + * should be unaffected by time-of-day adjustments, and for a camera should be strictly + * monotonic but for a MediaPlayer may be reset when the position is set. The + * specific meaning and zero point of the timestamp depends on the source providing images to + * the SurfaceTexture. Unless otherwise specified by the image source, timestamps cannot + * generally be compared across SurfaceTexture instances, or across multiple program + * invocations. It is mostly useful for determining time offsets between subsequent frames. + * + * 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() + */ + ASurfaceTexture_getTimestamp :: proc(st: ^ASurfaceTexture) -> i64 --- +} diff --git a/surface_texture_jni.odin b/surface_texture_jni.odin new file mode 100644 index 0000000..e4a349c --- /dev/null +++ b/surface_texture_jni.odin @@ -0,0 +1,24 @@ +//+build android +package android + +foreign import android "system:android" + +foreign android { + /** + * Get a reference to the native ASurfaceTexture from the corresponding java object. + * + * The caller must keep a reference to the Java SurfaceTexture during the lifetime of the returned + * ASurfaceTexture. Failing to do so could result in the ASurfaceTexture to stop functioning + * 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_fromSurfaceTexture :: proc(env: ^JNIEnv, surfacetexture: jobject) -> ^ASurfaceTexture --- +} diff --git a/sync.odin b/sync.odin new file mode 100644 index 0000000..de65911 --- /dev/null +++ b/sync.odin @@ -0,0 +1,87 @@ +//+build android +package android + +foreign import android "system:android" + +/* Fences indicate the status of an asynchronous task. They are initially + * in unsignaled state (0), and make a one-time transition to either signaled + * (1) or error (< 0) state. A sync file is a collection of one or more fences; + * the sync file's status is error if any of its fences are in error state, + * signaled if all of the child fences are signaled, or unsignaled otherwise. + * + * Sync files are created by various device APIs in response to submitting + * tasks to the device. Standard file descriptor lifetime syscalls like dup() + * and close() are used to manage sync file lifetime. + * + * The poll(), ppoll(), or select() syscalls can be used to wait for the sync + * file to change status, or (with a timeout of zero) to check its status. + * + * The functions below provide a few additional sync-specific operations. + */ + +// TODO: move to sys/linux or sys/android or something idk. +sync_fence_info :: struct { + obj_name: [32]u8, + driver_name: [32]u8, + status: i32, + flags: u32, + timestamp_ns: u64, +} + +sync_file_info :: struct { + name: [32]u8, + status: i32, + flags: u32, + num_fences: u32, + pad: u32, + sync_fence_info: u64, +} + + +/** +* Get the array of fence infos from the sync file's info. +* +* The returned array is owned by the parent sync file info, and has +* info->num_fences entries. +* +* Available since API level 26. +*/ +sync_get_fence_info :: #force_inline proc(info: ^sync_file_info) -> ^sync_fence_info { + return cast(^sync_fence_info)(uintptr(info.sync_fence_info)) +} + +foreign android { + /** + * Merge two sync files. + * + * This produces a new sync file with the given name which has the union of the + * two original sync file's fences redundant fences may be removed. + * + * If one of the input sync files is signaled or invalid, then this function + * may behave like dup(): the new file descriptor refers to the valid/unsignaled + * sync file with its original name, rather than a new sync file. + * + * The original fences remain valid, and the caller is responsible for closing + * them. + * + * Available since API level 26. + */ + sync_merge :: proc(name: cstring, fd1: i32, fd2: i32) -> i32 --- + + /** + * Retrieve detailed information about a sync file and its fences. + * + * The returned sync_file_info must be freed by calling sync_file_info_free(). + * + * Available since API level 26. + */ + @(link_name="sync_file_info") + _sync_file_info :: proc(fd: i32) -> ^sync_file_info --- + + /** + * Free a struct sync_file_info structure + * + * Available since API level 26. + */ + sync_file_info_free :: proc(info: ^sync_file_info) --- +} diff --git a/system_fonts.odin b/system_fonts.odin new file mode 100644 index 0000000..4134ae3 --- /dev/null +++ b/system_fonts.odin @@ -0,0 +1,86 @@ +//+build android +package android + +foreign import android "system:android" + +/** + * @file system_fonts.h + * @brief Provides the system font configurations. + * + * These APIs provides the list of system installed font files with additional metadata about the + * font. + * + * The ASystemFontIterator_open method will give you an iterator which can iterate all system + * installed font files as shown in the following example. + * + * \code{.cpp} + * ASystemFontIterator* iterator = ASystemFontIterator_open(); + * ASystemFont* font = NULL; + * + * while ((font = ASystemFontIterator_next(iterator)) != nullptr) { + * // Look if the font is your desired one. + * if (ASystemFont_getWeight(font) == 400 && !ASystemFont_isItalic(font) + * && ASystemFont_getLocale(font) == NULL) { + * break; + * } + * ASystemFont_close(font); + * } + * ASystemFontIterator_close(iterator); + * + * int fd = open(ASystemFont_getFontFilePath(font), O_RDONLY); + * int collectionIndex = ASystemFont_getCollectionINdex(font); + * std::vector> variationSettings; + * for (size_t i = 0; i < ASystemFont_getAxisCount(font); ++i) { + * variationSettings.push_back(std::make_pair( + * ASystemFont_getAxisTag(font, i), + * ASystemFont_getAxisValue(font, i))); + * } + * ASystemFont_close(font); + * + * // Use this font for your text rendering engine. + * + * \endcode + * + * Available since API level 29. + */ + +/** + * ASystemFontIterator provides access to the system font configuration. + * + * ASystemFontIterator is an iterator for all available system font settings. + * This iterator is not a thread-safe object. Do not pass this iterator to other threads. + */ +ASystemFontIterator :: struct{} + +foreign android { + /** + * Create a system font iterator. + * + * Use ASystemFont_close() to close the iterator. + * + * Available since API level 29. + * + * \return a pointer for a newly allocated iterator, nullptr on failure. + */ + ASystemFontIterator_open :: proc() -> ^ASystemFontIterator --- + + /** + * 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. + */ + ASystemFontIterator_close :: proc(iterator: ^ASystemFontIterator) --- + + /** + * 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. + */ + ASystemFontIterator_next :: proc(iterator: ^ASystemFontIterator) -> ^AFont --- +} diff --git a/thermal.odin b/thermal.odin new file mode 100644 index 0000000..1dd1314 --- /dev/null +++ b/thermal.odin @@ -0,0 +1,165 @@ +//+build android +package android + +foreign import android "system:android" + +/** + * Thermal status used in function {@link AThermal_getCurrentThermalStatus} and + * {@link AThermal_StatusCallback}. + */ +AThermalStatus :: enum { + /** Error in thermal status. */ + ERROR = -1, + /** Not under throttling. */ + NONE = 0, + /** Light throttling where UX is not impacted. */ + LIGHT = 1, + /** Moderate throttling where UX is not largely impacted. */ + MODERATE = 2, + /** Severe throttling where UX is largely impacted. */ + SEVERE = 3, + /** Platform has done everything to reduce power. */ + CRITICAL = 4, + /** + * Key components in platform are shutting down due to thermal condition. + * Device functionalities will be limited. + */ + EMERGENCY = 5, + /** Need shutdown immediately. */ + SHUTDOWN = 6, +} + +/** + * An opaque type representing a handle to a thermal manager. + * An instance of thermal manager must be acquired prior to + * using thermal status APIs and must be released after use. + * + *

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}.

+ * + */ +AThermalManager :: struct{} + +/** + * 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. + */ +AThermal_StatusCallback :: #type proc "c" (data: rawptr, status: AThermalStatus) + +foreign android { + /** + * 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. + */ + AThermal_acquireManager :: proc() -> ^AThermalManager --- + + /** + * Release the thermal manager pointer acquired via + * {@link AThermal_acquireManager}. + * + * Available since API level 30. + * + * @param manager The manager to be released. + */ + AThermal_releaseManager :: proc(manager: ^AThermalManager) --- + + /** + * 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. + */ + AThermal_getCurrentThermalStatus :: proc(manager: ^AThermalManager) -> AThermalStatus --- + + /** + * Register the thermal status listener for thermal status change. + * + * Available since API level 30. + * + * @param manager The manager instance to use to register. + * Acquired via {@link AThermal_acquireManager}. + * @param callback The callback function to be called when thermal status updated. + * @param data The data pointer to be passed when callback is called. + * + * @return 0 on success + * EINVAL if the listener and data pointer were previously added and not removed. + * EPERM if the required permission is not held. + * EPIPE if communication with the system service has failed. + */ + AThermal_registerThermalStatusListener :: proc(manager: ^AThermalManager, callback: AThermal_StatusCallback, data: rawptr) -> i32 --- + + /** + * Unregister the thermal status listener previously resgistered. + * + * Available since API level 30. + * + * @param manager The manager instance to use to unregister. + * Acquired via {@link AThermal_acquireManager}. + * @param callback The callback function to be called when thermal status updated. + * @param data The data pointer to be passed when callback is called. + * + * @return 0 on success + * EINVAL if the listener and data pointer were not previously added. + * EPERM if the required permission is not held. + * EPIPE if communication with the system service has failed. + */ + AThermal_unregisterThermalStatusListener :: proc(manager: ^AThermalManager, callback: AThermal_StatusCallback, data: rawptr) -> i32 --- + + /** + * Provides an estimate of how much thermal headroom the device currently has before + * hitting severe throttling. + * + * Note that this only attempts to track the headroom of slow-moving sensors, such as + * the skin temperature sensor. This means that there is no benefit to calling this function + * more frequently than about once per second, and attempted to call significantly + * more frequently may result in the function returning {@code NaN}. + * + * In addition, in order to be able to provide an accurate forecast, the system does + * not attempt to forecast until it has multiple temperature samples from which to + * extrapolate. This should only take a few seconds from the time of the first call, + * but during this time, no forecasting will occur, and the current headroom will be + * returned regardless of the value of {@code forecastSeconds}. + * + * The value returned is a non-negative float that represents how much of the thermal envelope + * is in use (or is forecasted to be in use). A value of 1.0 indicates that the device is + * (or will be) throttled at {@link #ATHERMAL_STATUS_SEVERE}. Such throttling can affect the + * CPU, GPU, and other subsystems. Values may exceed 1.0, but there is no implied mapping + * to specific thermal levels beyond that point. This means that values greater than 1.0 + * may correspond to {@link #ATHERMAL_STATUS_SEVERE}, but may also represent heavier throttling. + * + * A value of 0.0 corresponds to a fixed distance from 1.0, but does not correspond to any + * particular thermal status or temperature. Values on (0.0, 1.0] may be expected to scale + * linearly with temperature, though temperature changes over time are typically not linear. + * Negative values will be clamped to 0.0 before returning. + * + * Available since API level 31. + * + * @param manager The manager instance to use. + * Acquired via {@link AThermal_acquireManager}. + * @param forecastSeconds how many seconds into the future to forecast. Given that device + * conditions may change at any time, forecasts from further in the + * future will likely be less accurate than forecasts in the near future. + * @return a value greater than equal to 0.0, where 1.0 indicates the SEVERE throttling threshold, + * as described above. Returns NaN if the device does not support this functionality or + * if this function is called significantly faster than once per second. + */ + AThermal_getThermalHeadroom :: proc(manager: ^AThermalManager, forecastSeconds: i32) -> f32 --- +} diff --git a/trace.odin b/trace.odin new file mode 100644 index 0000000..f017c6c --- /dev/null +++ b/trace.odin @@ -0,0 +1,72 @@ +//+build android +package android + +foreign import android "system:android" + +foreign android { + /** + * Returns true if tracing is enabled. Use this to avoid expensive computation only necessary + * when tracing is enabled. + * + * Available since API level 23. + */ + ATrace_isEnabled :: proc() -> bool --- + + /** + * Writes a tracing message to indicate that the given section of code has begun. This call must be + * followed by a corresponding call to {@link ATrace_endSection} on the same thread. + * + * Note: At this time the vertical bar character '|' and newline character '\\n' are used internally + * by the tracing mechanism. If \p sectionName contains these characters they will be replaced with a + * space character in the trace. + * + * Available since API level 23. + */ + ATrace_beginSection :: proc(sectionName: cstring) --- + + /** + * Writes a tracing message to indicate that a given section of code has ended. This call must be + * preceeded by a corresponding call to {@link ATrace_beginSection} on the same thread. Calling this method + * will mark the end of the most recently begun section of code, so care must be taken to ensure + * that {@link ATrace_beginSection}/{@link ATrace_endSection} pairs are properly nested and called from the same thread. + * + * Available since API level 23. + */ + ATrace_endSection :: proc() --- + + /** + * Writes a trace message to indicate that a given section of code has + * begun. Must be followed by a call to {@link ATrace_endAsyncSection} with the same + * methodName and cookie. Unlike {@link ATrace_beginSection} and {@link ATrace_endSection}, + * 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 + */ + ATrace_beginAsyncSection :: proc(sectionName: cstring, cookie: i32) --- + + /** + * Writes a trace message to indicate that the current method has ended. + * Must be called exactly once for each call to {@link ATrace_beginAsyncSection} + * using the same name and cookie. + * + * Available since API level 29. + * + * \param sectionName The method name to appear in the trace. + * \param cookie Unique identifier for distinguishing simultaneous events + */ + ATrace_endAsyncSection :: proc(sectionName: cstring, cookie: i32) --- + + /** + * 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. + */ + ATrace_setCounter :: proc(counterName: cstring, counterValue: i64) --- +}