sync code with last improvements from OpenBSD

This commit is contained in:
purplerain 2023-08-28 05:57:34 +00:00
commit 88965415ff
Signed by: purplerain
GPG key ID: F42C07F07E2E35B7
26235 changed files with 29195616 additions and 0 deletions

View file

@ -0,0 +1,158 @@
/*
* Copyright 2018 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.
*/
/**
* @file data_space.h
*/
#ifndef ANDROID_DATA_SPACE_H
#define ANDROID_DATA_SPACE_H
#include <inttypes.h>
#include <sys/cdefs.h>
__BEGIN_DECLS
/**
* ADataSpace.
*/
enum ADataSpace {
/**
* Default-assumption data space, when not explicitly specified.
*
* It is safest to assume the buffer is an image with sRGB primaries and
* encoding ranges, but the consumer and/or the producer of the data may
* simply be using defaults. No automatic gamma transform should be
* expected, except for a possible display gamma transform when drawn to a
* screen.
*/
ADATASPACE_UNKNOWN = 0,
/**
* scRGB linear encoding:
*
* The red, green, and blue components are stored in extended sRGB space,
* but are linear, not gamma-encoded.
* The RGB primaries and the white point are the same as BT.709.
*
* The values are floating point.
* A pixel value of 1.0, 1.0, 1.0 corresponds to sRGB white (D65) at 80 nits.
* Values beyond the range [0.0 - 1.0] would correspond to other colors
* spaces and/or HDR content.
*/
ADATASPACE_SCRGB_LINEAR = 406913024, // STANDARD_BT709 | TRANSFER_LINEAR | RANGE_EXTENDED
/**
* sRGB gamma encoding:
*
* The red, green and blue components are stored in sRGB space, and
* converted to linear space when read, using the SRGB transfer function
* for each of the R, G and B components. When written, the inverse
* transformation is performed.
*
* The alpha component, if present, is always stored in linear space and
* is left unmodified when read or written.
*
* Use full range and BT.709 standard.
*/
ADATASPACE_SRGB = 142671872, // STANDARD_BT709 | TRANSFER_SRGB | RANGE_FULL
/**
* scRGB:
*
* The red, green, and blue components are stored in extended sRGB space,
* and gamma-encoded using the SRGB transfer function.
* The RGB primaries and the white point are the same as BT.709.
*
* The values are floating point.
* A pixel value of 1.0, 1.0, 1.0 corresponds to sRGB white (D65) at 80 nits.
* Values beyond the range [0.0 - 1.0] would correspond to other colors
* spaces and/or HDR content.
*/
ADATASPACE_SCRGB = 411107328, // STANDARD_BT709 | TRANSFER_SRGB | RANGE_EXTENDED
/**
* Display P3
*
* Use same primaries and white-point as DCI-P3
* but sRGB transfer function.
*/
ADATASPACE_DISPLAY_P3 = 143261696, // STANDARD_DCI_P3 | TRANSFER_SRGB | RANGE_FULL
/**
* ITU-R Recommendation 2020 (BT.2020)
*
* Ultra High-definition television
*
* Use full range, SMPTE 2084 (PQ) transfer and BT2020 standard
*/
ADATASPACE_BT2020_PQ = 163971072, // STANDARD_BT2020 | TRANSFER_ST2084 | RANGE_FULL
/**
* Adobe RGB
*
* Use full range, gamma 2.2 transfer and Adobe RGB primaries
* Note: Application is responsible for gamma encoding the data as
* a 2.2 gamma encoding is not supported in HW.
*/
ADATASPACE_ADOBE_RGB = 151715840, // STANDARD_ADOBE_RGB | TRANSFER_GAMMA2_2 | RANGE_FULL
/**
* ITU-R Recommendation 2020 (BT.2020)
*
* Ultra High-definition television
*
* Use full range, BT.709 transfer and BT2020 standard
*/
ADATASPACE_BT2020 = 147193856, // STANDARD_BT2020 | TRANSFER_SMPTE_170M | RANGE_FULL
/**
* ITU-R Recommendation 709 (BT.709)
*
* High-definition television
*
* Use limited range, BT.709 transfer and BT.709 standard.
*/
ADATASPACE_BT709 = 281083904, // STANDARD_BT709 | TRANSFER_SMPTE_170M | RANGE_LIMITED
/**
* SMPTE EG 432-1 and SMPTE RP 431-2.
*
* Digital Cinema DCI-P3
*
* Use full range, gamma 2.6 transfer and D65 DCI-P3 standard
* Note: Application is responsible for gamma encoding the data as
* a 2.6 gamma encoding is not supported in HW.
*/
ADATASPACE_DCI_P3 = 155844608, // STANDARD_DCI_P3 | TRANSFER_GAMMA2_6 | RANGE_FULL
/**
* sRGB linear encoding:
*
* The red, green, and blue components are stored in sRGB space, but
* are linear, not gamma-encoded.
* The RGB primaries and the white point are the same as BT.709.
*
* The values are encoded using the full range ([0,255] for 8-bit) for all
* components.
*/
ADATASPACE_SRGB_LINEAR = 138477568, // STANDARD_BT709 | TRANSFER_LINEAR | RANGE_FULL
};
__END_DECLS
#endif // ANDROID_DATA_SPACE_H

View file

@ -0,0 +1,542 @@
/*
* Copyright 2017 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.
*/
/**
* @file hardware_buffer.h
* @brief API for native hardware buffers.
*/
/**
* @defgroup AHardwareBuffer Native Hardware Buffer
*
* AHardwareBuffer objects represent chunks of memory that can be
* accessed by various hardware components in the system. It can be
* easily converted to the Java counterpart
* android.hardware.HardwareBuffer and passed between processes using
* Binder. All operations involving AHardwareBuffer and HardwareBuffer
* are zero-copy, i.e., passing AHardwareBuffer to another process
* creates a shared view of the same region of memory.
*
* AHardwareBuffers can be bound to EGL/OpenGL and Vulkan primitives.
* For EGL, use the extension function eglGetNativeClientBufferANDROID
* to obtain an EGLClientBuffer and pass it directly to
* eglCreateImageKHR. Refer to the EGL extensions
* EGL_ANDROID_get_native_client_buffer and
* EGL_ANDROID_image_native_buffer for more information. In Vulkan,
* the contents of the AHardwareBuffer can be accessed as external
* memory. See the VK_ANDROID_external_memory_android_hardware_buffer
* extension for details.
*
* @{
*/
#ifndef ANDROID_HARDWARE_BUFFER_H
#define ANDROID_HARDWARE_BUFFER_H
#include <inttypes.h>
#include <sys/cdefs.h>
#include <android/rect.h>
__BEGIN_DECLS
/**
* Buffer pixel formats.
*/
enum AHardwareBuffer_Format {
/**
* Corresponding formats:
* Vulkan: VK_FORMAT_R8G8B8A8_UNORM
* OpenGL ES: GL_RGBA8
*/
AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM = 1,
/**
* 32 bits per pixel, 8 bits per channel format where alpha values are
* ignored (always opaque).
* Corresponding formats:
* Vulkan: VK_FORMAT_R8G8B8A8_UNORM
* OpenGL ES: GL_RGB8
*/
AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM = 2,
/**
* Corresponding formats:
* Vulkan: VK_FORMAT_R8G8B8_UNORM
* OpenGL ES: GL_RGB8
*/
AHARDWAREBUFFER_FORMAT_R8G8B8_UNORM = 3,
/**
* Corresponding formats:
* Vulkan: VK_FORMAT_R5G6B5_UNORM_PACK16
* OpenGL ES: GL_RGB565
*/
AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM = 4,
/**
* Corresponding formats:
* Vulkan: VK_FORMAT_R16G16B16A16_SFLOAT
* OpenGL ES: GL_RGBA16F
*/
AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT = 0x16,
/**
* Corresponding formats:
* Vulkan: VK_FORMAT_A2B10G10R10_UNORM_PACK32
* OpenGL ES: GL_RGB10_A2
*/
AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM = 0x2b,
/**
* Opaque binary blob format.
* Must have height 1 and one layer, with width equal to the buffer
* size in bytes. Corresponds to Vulkan buffers and OpenGL buffer
* objects. Can be bound to the latter using GL_EXT_external_buffer.
*/
AHARDWAREBUFFER_FORMAT_BLOB = 0x21,
/**
* Corresponding formats:
* Vulkan: VK_FORMAT_D16_UNORM
* OpenGL ES: GL_DEPTH_COMPONENT16
*/
AHARDWAREBUFFER_FORMAT_D16_UNORM = 0x30,
/**
* Corresponding formats:
* Vulkan: VK_FORMAT_X8_D24_UNORM_PACK32
* OpenGL ES: GL_DEPTH_COMPONENT24
*/
AHARDWAREBUFFER_FORMAT_D24_UNORM = 0x31,
/**
* Corresponding formats:
* Vulkan: VK_FORMAT_D24_UNORM_S8_UINT
* OpenGL ES: GL_DEPTH24_STENCIL8
*/
AHARDWAREBUFFER_FORMAT_D24_UNORM_S8_UINT = 0x32,
/**
* Corresponding formats:
* Vulkan: VK_FORMAT_D32_SFLOAT
* OpenGL ES: GL_DEPTH_COMPONENT32F
*/
AHARDWAREBUFFER_FORMAT_D32_FLOAT = 0x33,
/**
* Corresponding formats:
* Vulkan: VK_FORMAT_D32_SFLOAT_S8_UINT
* OpenGL ES: GL_DEPTH32F_STENCIL8
*/
AHARDWAREBUFFER_FORMAT_D32_FLOAT_S8_UINT = 0x34,
/**
* Corresponding formats:
* Vulkan: VK_FORMAT_S8_UINT
* OpenGL ES: GL_STENCIL_INDEX8
*/
AHARDWAREBUFFER_FORMAT_S8_UINT = 0x35,
/**
* YUV 420 888 format.
* Must have an even width and height. Can be accessed in OpenGL
* shaders through an external sampler. Does not support mip-maps
* cube-maps or multi-layered textures.
*/
AHARDWAREBUFFER_FORMAT_Y8Cb8Cr8_420 = 0x23,
};
/**
* Buffer usage flags, specifying how the buffer will be accessed.
*/
enum AHardwareBuffer_UsageFlags {
/// The buffer will never be locked for direct CPU reads using the
/// AHardwareBuffer_lock() function. Note that reading the buffer
/// using OpenGL or Vulkan functions or memory mappings is still
/// allowed.
AHARDWAREBUFFER_USAGE_CPU_READ_NEVER = 0UL,
/// The buffer will sometimes be locked for direct CPU reads using
/// the AHardwareBuffer_lock() function. Note that reading the
/// buffer using OpenGL or Vulkan functions or memory mappings
/// does not require the presence of this flag.
AHARDWAREBUFFER_USAGE_CPU_READ_RARELY = 2UL,
/// The buffer will often be locked for direct CPU reads using
/// the AHardwareBuffer_lock() function. Note that reading the
/// buffer using OpenGL or Vulkan functions or memory mappings
/// does not require the presence of this flag.
AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN = 3UL,
/// CPU read value mask.
AHARDWAREBUFFER_USAGE_CPU_READ_MASK = 0xFUL,
/// The buffer will never be locked for direct CPU writes using the
/// AHardwareBuffer_lock() function. Note that writing the buffer
/// using OpenGL or Vulkan functions or memory mappings is still
/// allowed.
AHARDWAREBUFFER_USAGE_CPU_WRITE_NEVER = 0UL << 4,
/// The buffer will sometimes be locked for direct CPU writes using
/// the AHardwareBuffer_lock() function. Note that writing the
/// buffer using OpenGL or Vulkan functions or memory mappings
/// does not require the presence of this flag.
AHARDWAREBUFFER_USAGE_CPU_WRITE_RARELY = 2UL << 4,
/// The buffer will often be locked for direct CPU writes using
/// the AHardwareBuffer_lock() function. Note that writing the
/// buffer using OpenGL or Vulkan functions or memory mappings
/// does not require the presence of this flag.
AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN = 3UL << 4,
/// CPU write value mask.
AHARDWAREBUFFER_USAGE_CPU_WRITE_MASK = 0xFUL << 4,
/// The buffer will be read from by the GPU as a texture.
AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE = 1UL << 8,
/// The buffer will be written to by the GPU as a framebuffer attachment.
AHARDWAREBUFFER_USAGE_GPU_FRAMEBUFFER = 1UL << 9,
/**
* The buffer will be written to by the GPU as a framebuffer
* attachment.
*
* Note that the name of this flag is somewhat misleading: it does
* not imply that the buffer contains a color format. A buffer with
* depth or stencil format that will be used as a framebuffer
* attachment should also have this flag. Use the equivalent flag
* AHARDWAREBUFFER_USAGE_GPU_FRAMEBUFFER to avoid this confusion.
*/
AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT = AHARDWAREBUFFER_USAGE_GPU_FRAMEBUFFER,
/**
* The buffer will be used as a composer HAL overlay layer.
*
* This flag is currently only needed when using ASurfaceTransaction_setBuffer
* to set a buffer. In all other cases, the framework adds this flag
* internally to buffers that could be presented in a composer overlay.
* ASurfaceTransaction_setBuffer is special because it uses buffers allocated
* directly through AHardwareBuffer_allocate instead of buffers allocated
* by the framework.
*/
AHARDWAREBUFFER_USAGE_COMPOSER_OVERLAY = 1ULL << 11,
/**
* The buffer is protected from direct CPU access or being read by
* non-secure hardware, such as video encoders.
*
* This flag is incompatible with CPU read and write flags. It is
* mainly used when handling DRM video. Refer to the EGL extension
* EGL_EXT_protected_content and GL extension
* GL_EXT_protected_textures for more information on how these
* buffers are expected to behave.
*/
AHARDWAREBUFFER_USAGE_PROTECTED_CONTENT = 1UL << 14,
/// The buffer will be read by a hardware video encoder.
AHARDWAREBUFFER_USAGE_VIDEO_ENCODE = 1UL << 16,
/**
* The buffer will be used for direct writes from sensors.
* When this flag is present, the format must be AHARDWAREBUFFER_FORMAT_BLOB.
*/
AHARDWAREBUFFER_USAGE_SENSOR_DIRECT_DATA = 1UL << 23,
/**
* The buffer will be used as a shader storage or uniform buffer object.
* When this flag is present, the format must be AHARDWAREBUFFER_FORMAT_BLOB.
*/
AHARDWAREBUFFER_USAGE_GPU_DATA_BUFFER = 1UL << 24,
/**
* The buffer will be used as a cube map texture.
* When this flag is present, the buffer must have a layer count
* that is a multiple of 6. Note that buffers with this flag must be
* bound to OpenGL textures using the extension
* GL_EXT_EGL_image_storage instead of GL_KHR_EGL_image.
*/
AHARDWAREBUFFER_USAGE_GPU_CUBE_MAP = 1UL << 25,
/**
* The buffer contains a complete mipmap hierarchy.
* Note that buffers with this flag must be bound to OpenGL textures using
* the extension GL_EXT_EGL_image_storage instead of GL_KHR_EGL_image.
*/
AHARDWAREBUFFER_USAGE_GPU_MIPMAP_COMPLETE = 1UL << 26,
AHARDWAREBUFFER_USAGE_VENDOR_0 = 1ULL << 28,
AHARDWAREBUFFER_USAGE_VENDOR_1 = 1ULL << 29,
AHARDWAREBUFFER_USAGE_VENDOR_2 = 1ULL << 30,
AHARDWAREBUFFER_USAGE_VENDOR_3 = 1ULL << 31,
AHARDWAREBUFFER_USAGE_VENDOR_4 = 1ULL << 48,
AHARDWAREBUFFER_USAGE_VENDOR_5 = 1ULL << 49,
AHARDWAREBUFFER_USAGE_VENDOR_6 = 1ULL << 50,
AHARDWAREBUFFER_USAGE_VENDOR_7 = 1ULL << 51,
AHARDWAREBUFFER_USAGE_VENDOR_8 = 1ULL << 52,
AHARDWAREBUFFER_USAGE_VENDOR_9 = 1ULL << 53,
AHARDWAREBUFFER_USAGE_VENDOR_10 = 1ULL << 54,
AHARDWAREBUFFER_USAGE_VENDOR_11 = 1ULL << 55,
AHARDWAREBUFFER_USAGE_VENDOR_12 = 1ULL << 56,
AHARDWAREBUFFER_USAGE_VENDOR_13 = 1ULL << 57,
AHARDWAREBUFFER_USAGE_VENDOR_14 = 1ULL << 58,
AHARDWAREBUFFER_USAGE_VENDOR_15 = 1ULL << 59,
AHARDWAREBUFFER_USAGE_VENDOR_16 = 1ULL << 60,
AHARDWAREBUFFER_USAGE_VENDOR_17 = 1ULL << 61,
AHARDWAREBUFFER_USAGE_VENDOR_18 = 1ULL << 62,
AHARDWAREBUFFER_USAGE_VENDOR_19 = 1ULL << 63,
};
/**
* Buffer description. Used for allocating new buffers and querying
* parameters of existing ones.
*/
typedef struct AHardwareBuffer_Desc {
uint32_t width; ///< Width in pixels.
uint32_t height; ///< Height in pixels.
/**
* Number of images in an image array. AHardwareBuffers with one
* layer correspond to regular 2D textures. AHardwareBuffers with
* more than layer correspond to texture arrays. If the layer count
* is a multiple of 6 and the usage flag
* AHARDWAREBUFFER_USAGE_GPU_CUBE_MAP is present, the buffer is
* a cube map or a cube map array.
*/
uint32_t layers;
uint32_t format; ///< One of AHardwareBuffer_Format.
uint64_t usage; ///< Combination of AHardwareBuffer_UsageFlags.
uint32_t stride; ///< Row stride in pixels, ignored for AHardwareBuffer_allocate()
uint32_t rfu0; ///< Initialize to zero, reserved for future use.
uint64_t rfu1; ///< Initialize to zero, reserved for future use.
} AHardwareBuffer_Desc;
/**
* Holds data for a single image plane.
*/
typedef struct AHardwareBuffer_Plane {
void* data; ///< Points to first byte in plane
uint32_t pixelStride; ///< Distance in bytes from the color channel of one pixel to the next
uint32_t rowStride; ///< Distance in bytes from the first value of one row of the image to
/// the first value of the next row.
} AHardwareBuffer_Plane;
/**
* Holds all image planes that contain the pixel data.
*/
typedef struct AHardwareBuffer_Planes {
uint32_t planeCount; ///< Number of distinct planes
AHardwareBuffer_Plane planes[4]; ///< Array of image planes
} AHardwareBuffer_Planes;
/**
* Opaque handle for a native hardware buffer.
*/
typedef struct AHardwareBuffer AHardwareBuffer;
/**
* Allocates a buffer that matches the passed AHardwareBuffer_Desc.
*
* If allocation succeeds, the buffer can be used according to the
* usage flags specified in its description. If a buffer is used in ways
* 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.
*/
int AHardwareBuffer_allocate(const AHardwareBuffer_Desc* desc,
AHardwareBuffer** outBuffer) __INTRODUCED_IN(26);
/**
* Acquire a reference on the given AHardwareBuffer object.
*
* 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);
/**
* Lock the AHardwareBuffer for direct CPU access.
*
* This function can lock the buffer for either reading or writing.
* It may block if the hardware needs to finish rendering, if CPU caches
* need to be synchronized, or possibly for other implementation-
* specific reasons.
*
* The passed AHardwareBuffer must have one layer, otherwise the call
* will fail.
*
* If \a fence is not negative, it specifies a fence file descriptor on
* which to wait before locking the buffer. If it's negative, the caller
* is responsible for ensuring that writes to the buffer have completed
* before calling this function. Using this parameter is more efficient
* than waiting on the fence and then calling this function.
*
* The \a usage parameter may only specify AHARDWAREBUFFER_USAGE_CPU_*.
* If set, then outVirtualAddress is filled with the address of the
* buffer in virtual memory. The flags must also be compatible with
* usage flags specified at buffer creation: if a read flag is passed,
* the buffer must have been created with
* AHARDWAREBUFFER_USAGE_CPU_READ_RARELY or
* AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN. If a write flag is passed, it
* must have been created with AHARDWAREBUFFER_USAGE_CPU_WRITE_RARELY or
* AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN.
*
* If \a rect is not NULL, the caller promises to modify only data in
* the area specified by rect. If rect is NULL, the caller may modify
* the contents of the entire buffer. The content of the buffer outside
* of the specified rect is NOT modified by this call.
*
* It is legal for several different threads to lock a buffer for read
* access; none of the threads are blocked.
*
* Locking a buffer simultaneously for write or read/write is undefined,
* but will neither terminate the process nor block the caller.
* AHardwareBuffer_lock may return an error or leave the buffer's
* content in an indeterminate state.
*
* If the buffer has AHARDWAREBUFFER_FORMAT_BLOB, it is legal lock it
* for reading and writing in multiple threads and/or processes
* 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
* reason.
*/
int AHardwareBuffer_lock(AHardwareBuffer* buffer, uint64_t usage,
int32_t fence, const ARect* rect, void** outVirtualAddress) __INTRODUCED_IN(26);
/**
* Lock a potentially multi-planar AHardwareBuffer for direct CPU access.
*
* This function is similar to AHardwareBuffer_lock, but can lock multi-planar
* formats. The locked planes are returned in the \a outPlanes argument. Note,
* that multi-planar should not be confused with multi-layer images, which this
* locking function does not support.
*
* YUV formats are always represented by three separate planes of data, one for
* each color plane. The order of planes in the array is guaranteed such that
* plane #0 is always Y, plane #1 is always U (Cb), and plane #2 is always V
* (Cr). All other formats are represented by a single plane.
*
* Additional information always accompanies the buffers, describing the row
* stride and the pixel stride for each plane.
*
* In case the buffer cannot be locked, \a outPlanes will contain zero planes.
*
* 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
* reason.
*/
int AHardwareBuffer_lockPlanes(AHardwareBuffer* buffer, uint64_t usage,
int32_t fence, const ARect* rect, AHardwareBuffer_Planes* outPlanes) __INTRODUCED_IN(29);
/**
* Unlock the AHardwareBuffer from direct CPU access.
*
* Must be called after all changes to the buffer are completed by the
* caller. If \a fence is NULL, the function will block until all work
* is completed. Otherwise, \a fence will be set either to a valid file
* descriptor or to -1. The file descriptor will become signaled once
* the unlocking is complete and buffer contents are updated.
* The caller is responsible for closing the file descriptor once it's
* no longer needed. The value -1 indicates that unlocking has already
* 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.
*/
int AHardwareBuffer_unlock(AHardwareBuffer* buffer, int32_t* fence) __INTRODUCED_IN(26);
/**
* 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.
*/
int AHardwareBuffer_sendHandleToUnixSocket(const AHardwareBuffer* buffer, int socketFd) __INTRODUCED_IN(26);
/**
* 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.
*/
int AHardwareBuffer_recvHandleFromUnixSocket(int socketFd, AHardwareBuffer** outBuffer) __INTRODUCED_IN(26);
/**
* Test whether the given format and usage flag combination is
* allocatable.
*
* If this function returns true, it means that a buffer with the given
* description can be allocated on this implementation, unless resource
* exhaustion occurs. If this function returns false, it means that the
* allocation of the given description will never succeed.
*
* The return value of this function may depend on all fields in the
* description, except stride, which is always ignored. For example,
* 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.
*/
int AHardwareBuffer_isSupported(const AHardwareBuffer_Desc* desc) __INTRODUCED_IN(29);
/**
* Lock an AHardwareBuffer for direct CPU access.
*
* This function is the same as the above lock function, but passes back
* additional information about the bytes per pixel and the bytes per stride
* 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,
int32_t* outBytesPerPixel, int32_t* outBytesPerStride) __INTRODUCED_IN(29);
__END_DECLS
#endif // ANDROID_HARDWARE_BUFFER_H
/** @} */

View file

@ -0,0 +1,74 @@
/*
* Copyright 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.
*/
/**
* @file hdr_metadata.h
*/
#ifndef ANDROID_HDR_METADATA_H
#define ANDROID_HDR_METADATA_H
#include <inttypes.h>
#include <sys/cdefs.h>
__BEGIN_DECLS
/**
* These structures are used to define the display's capabilities for HDR content.
* They can be used to better tone map content to user's display.
*/
/**
* HDR metadata standards that are supported by Android.
*/
enum AHdrMetadataType : uint32_t {
HDR10_SMPTE2086 = 1,
HDR10_CTA861_3 = 2,
HDR10PLUS_SEI = 3,
};
/**
* Color is defined in CIE XYZ coordinates.
*/
struct AColor_xy {
float x;
float y;
};
/**
* SMPTE ST 2086 "Mastering Display Color Volume" static metadata
*/
struct AHdrMetadata_smpte2086 {
struct AColor_xy displayPrimaryRed;
struct AColor_xy displayPrimaryGreen;
struct AColor_xy displayPrimaryBlue;
struct AColor_xy whitePoint;
float maxLuminance;
float minLuminance;
};
/**
* CTA 861.3 "HDR Static Metadata Extension" static metadata
*/
struct AHdrMetadata_cta861_3 {
float maxContentLightLevel;
float maxFrameAverageLightLevel;
};
__END_DECLS
#endif // ANDROID_HDR_METADATA_H

View file

@ -0,0 +1,378 @@
/*
* Copyright (C) 2009 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
/**
* @addtogroup Logging
* @{
*/
/**
* \file
*
* Support routines to send messages to the Android log buffer,
* which can later be accessed through the `logcat` utility.
*
* Each log message must have
* - a priority
* - a log tag
* - some text
*
* The tag normally corresponds to the component that emits the log message,
* and should be reasonably small.
*
* Log message text may be truncated to less than an implementation-specific
* limit (1023 bytes).
*
* Note that a newline character ("\n") will be appended automatically to your
* log message, if not already there. It is not possible to send several
* messages and have them appear on a single line in logcat.
*
* Please use logging in moderation:
*
* - Sending log messages eats CPU and slow down your application and the
* system.
*
* - The circular log buffer is pretty small, so sending many messages
* will hide other important log messages.
*
* - In release builds, only send log messages to account for exceptional
* conditions.
*/
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <sys/cdefs.h>
#if !defined(__BIONIC__) && !defined(__INTRODUCED_IN)
#define __INTRODUCED_IN(x)
#endif
#ifdef __cplusplus
extern "C" {
#endif
/**
* Android log priority values, in increasing order of priority.
*/
typedef enum android_LogPriority {
/** For internal use only. */
ANDROID_LOG_UNKNOWN = 0,
/** The default priority, for internal use only. */
ANDROID_LOG_DEFAULT, /* only for SetMinPriority() */
/** Verbose logging. Should typically be disabled for a release apk. */
ANDROID_LOG_VERBOSE,
/** Debug logging. Should typically be disabled for a release apk. */
ANDROID_LOG_DEBUG,
/** Informational logging. Should typically be disabled for a release apk. */
ANDROID_LOG_INFO,
/** Warning logging. For use with recoverable failures. */
ANDROID_LOG_WARN,
/** Error logging. For use with unrecoverable failures. */
ANDROID_LOG_ERROR,
/** Fatal logging. For use when aborting. */
ANDROID_LOG_FATAL,
/** For internal use only. */
ANDROID_LOG_SILENT, /* only for SetMinPriority(); must be last */
} android_LogPriority;
/**
* Writes the constant string `text` to the log, with priority `prio` and tag
* `tag`.
*/
int __android_log_write(int prio, const char* tag, const char* text);
/**
* Writes a formatted string to the log, with priority `prio` and tag `tag`.
* The details of formatting are the same as for
* [printf(3)](http://man7.org/linux/man-pages/man3/printf.3.html).
*/
int __android_log_print(int prio, const char* tag, const char* fmt, ...)
__attribute__((__format__(printf, 3, 4)));
/**
* Equivalent to `__android_log_print`, but taking a `va_list`.
* (If `__android_log_print` is like `printf`, this is like `vprintf`.)
*/
int __android_log_vprint(int prio, const char* tag, const char* fmt, va_list ap)
__attribute__((__format__(printf, 3, 0)));
/**
* Writes an assertion failure to the log (as `ANDROID_LOG_FATAL`) and to
* stderr, before calling
* [abort(3)](http://man7.org/linux/man-pages/man3/abort.3.html).
*
* If `fmt` is non-null, `cond` is unused. If `fmt` is null, the string
* `Assertion failed: %s` is used with `cond` as the string argument.
* If both `fmt` and `cond` are null, a default string is provided.
*
* Most callers should use
* [assert(3)](http://man7.org/linux/man-pages/man3/assert.3.html) from
* `&lt;assert.h&gt;` instead, or the `__assert` and `__assert2` functions
* provided by bionic if more control is needed. They support automatically
* including the source filename and line number more conveniently than this
* function.
*/
void __android_log_assert(const char* cond, const char* tag, const char* fmt, ...)
__attribute__((__noreturn__)) __attribute__((__format__(printf, 3, 4)));
/**
* Identifies a specific log buffer for __android_log_buf_write()
* and __android_log_buf_print().
*/
typedef enum log_id {
LOG_ID_MIN = 0,
/** The main log buffer. This is the only log buffer available to apps. */
LOG_ID_MAIN = 0,
/** The radio log buffer. */
LOG_ID_RADIO = 1,
/** The event log buffer. */
LOG_ID_EVENTS = 2,
/** The system log buffer. */
LOG_ID_SYSTEM = 3,
/** The crash log buffer. */
LOG_ID_CRASH = 4,
/** The statistics log buffer. */
LOG_ID_STATS = 5,
/** The security log buffer. */
LOG_ID_SECURITY = 6,
/** The kernel log buffer. */
LOG_ID_KERNEL = 7,
LOG_ID_MAX,
/** Let the logging function choose the best log target. */
LOG_ID_DEFAULT = 0x7FFFFFFF
} log_id_t;
/**
* Writes the constant string `text` to the log buffer `id`,
* with priority `prio` and tag `tag`.
*
* Apps should use __android_log_write() instead.
*/
int __android_log_buf_write(int bufID, int prio, const char* tag, const char* text);
/**
* Writes a formatted string to log buffer `id`,
* with priority `prio` and tag `tag`.
* The details of formatting are the same as for
* [printf(3)](http://man7.org/linux/man-pages/man3/printf.3.html).
*
* Apps should use __android_log_print() instead.
*/
int __android_log_buf_print(int bufID, int prio, const char* tag, const char* fmt, ...)
__attribute__((__format__(printf, 4, 5)));
/**
* Logger data struct used for writing log messages to liblog via __android_log_write_logger_data()
* and sending log messages to user defined loggers specified in __android_log_set_logger().
*/
struct __android_log_message {
/** Must be set to sizeof(__android_log_message) and is used for versioning. */
size_t struct_size;
/** {@link log_id_t} values. */
int32_t buffer_id;
/** {@link android_LogPriority} values. */
int32_t priority;
/** The tag for the log message. */
const char* tag;
/** Optional file name, may be set to nullptr. */
const char* file;
/** Optional line number, ignore if file is nullptr. */
uint32_t line;
/** The log message itself. */
const char* message;
};
/**
* Prototype for the 'logger' function that is called for every log message.
*/
typedef void (*__android_logger_function)(const struct __android_log_message* log_message);
/**
* Prototype for the 'abort' function that is called when liblog will abort due to
* __android_log_assert() failures.
*/
typedef void (*__android_aborter_function)(const char* abort_message);
/**
* Writes the log message specified by log_message. log_message includes additional file name and
* line number information that a logger may use. log_message is versioned for backwards
* compatibility.
* This assumes that loggability has already been checked through __android_log_is_loggable().
* Higher level logging libraries, such as libbase, first check loggability, then format their
* buffers, then pass the message to liblog via this function, and therefore we do not want to
* duplicate the loggability check here.
*
* @param log_message the log message itself, see __android_log_message.
*
* Available since API level 30.
*/
void __android_log_write_log_message(struct __android_log_message* log_message) __INTRODUCED_IN(30);
/**
* Sets a user defined logger function. All log messages sent to liblog will be set to the
* function pointer specified by logger for processing. It is not expected that log messages are
* already terminated with a new line. This function should add new lines if required for line
* separation.
*
* @param logger the new function that will handle log messages.
*
* Available since API level 30.
*/
void __android_log_set_logger(__android_logger_function logger) __INTRODUCED_IN(30);
/**
* Writes the log message to logd. This is an __android_logger_function and can be provided to
* __android_log_set_logger(). It is the default logger when running liblog on a device.
*
* @param log_message the log message to write, see __android_log_message.
*
* Available since API level 30.
*/
void __android_log_logd_logger(const struct __android_log_message* log_message) __INTRODUCED_IN(30);
/**
* Writes the log message to stderr. This is an __android_logger_function and can be provided to
* __android_log_set_logger(). It is the default logger when running liblog on host.
*
* @param log_message the log message to write, see __android_log_message.
*
* Available since API level 30.
*/
void __android_log_stderr_logger(const struct __android_log_message* log_message)
__INTRODUCED_IN(30);
/**
* Sets a user defined aborter function that is called for __android_log_assert() failures. This
* user defined aborter function is highly recommended to abort and be noreturn, but is not strictly
* required to.
*
* @param aborter the new aborter function, see __android_aborter_function.
*
* Available since API level 30.
*/
void __android_log_set_aborter(__android_aborter_function aborter) __INTRODUCED_IN(30);
/**
* Calls the stored aborter function. This allows for other logging libraries to use the same
* aborter function by calling this function in liblog.
*
* @param abort_message an additional message supplied when aborting, for example this is used to
* call android_set_abort_message() in __android_log_default_aborter().
*
* Available since API level 30.
*/
void __android_log_call_aborter(const char* abort_message) __INTRODUCED_IN(30);
/**
* Sets android_set_abort_message() on device then aborts(). This is the default aborter.
*
* @param abort_message an additional message supplied when aborting. This functions calls
* android_set_abort_message() with its contents.
*
* Available since API level 30.
*/
void __android_log_default_aborter(const char* abort_message) __attribute__((noreturn))
__INTRODUCED_IN(30);
/**
* Use the per-tag properties "log.tag.<tagname>" along with the minimum priority from
* __android_log_set_minimum_priority() to determine if a log message with a given prio and tag will
* be printed. A non-zero result indicates yes, zero indicates false.
*
* If both a priority for a tag and a minimum priority are set by
* __android_log_set_minimum_priority(), then the lowest of the two values are to determine the
* minimum priority needed to log. If only one is set, then that value is used to determine the
* minimum priority needed. If none are set, then default_priority is used.
*
* @param prio the priority to test, takes android_LogPriority values.
* @param tag the tag to test.
* @param default_prio the default priority to use if no properties or minimum priority are set.
* @return an integer where 1 indicates that the message is loggable and 0 indicates that it is not.
*
* Available since API level 30.
*/
int __android_log_is_loggable(int prio, const char* tag, int default_prio) __INTRODUCED_IN(30);
/**
* Use the per-tag properties "log.tag.<tagname>" along with the minimum priority from
* __android_log_set_minimum_priority() to determine if a log message with a given prio and tag will
* be printed. A non-zero result indicates yes, zero indicates false.
*
* If both a priority for a tag and a minimum priority are set by
* __android_log_set_minimum_priority(), then the lowest of the two values are to determine the
* minimum priority needed to log. If only one is set, then that value is used to determine the
* minimum priority needed. If none are set, then default_priority is used.
*
* @param prio the priority to test, takes android_LogPriority values.
* @param tag the tag to test.
* @param len the length of the tag.
* @param default_prio the default priority to use if no properties or minimum priority are set.
* @return an integer where 1 indicates that the message is loggable and 0 indicates that it is not.
*
* Available since API level 30.
*/
int __android_log_is_loggable_len(int prio, const char* tag, size_t len, int default_prio)
__INTRODUCED_IN(30);
/**
* Sets the minimum priority that will be logged for this process.
*
* @param priority the new minimum priority to set, takes android_LogPriority values.
* @return the previous set minimum priority as android_LogPriority values, or
* ANDROID_LOG_DEFAULT if none was set.
*
* Available since API level 30.
*/
int32_t __android_log_set_minimum_priority(int32_t priority) __INTRODUCED_IN(30);
/**
* Gets the minimum priority that will be logged for this process. If none has been set by a
* previous __android_log_set_minimum_priority() call, this returns ANDROID_LOG_DEFAULT.
*
* @return the current minimum priority as android_LogPriority values, or
* ANDROID_LOG_DEFAULT if none is set.
*
* Available since API level 30.
*/
int32_t __android_log_get_minimum_priority(void) __INTRODUCED_IN(30);
/**
* Sets the default tag if no tag is provided when writing a log message. Defaults to
* getprogname(). This truncates tag to the maximum log message size, though appropriate tags
* should be much smaller.
*
* @param tag the new log tag.
*
* Available since API level 30.
*/
void __android_log_set_default_tag(const char* tag) __INTRODUCED_IN(30);
#ifdef __cplusplus
}
#endif
/** @} */

View file

@ -0,0 +1,300 @@
/*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @defgroup ANativeWindow Native Window
*
* ANativeWindow represents the producer end of an image queue.
* It is the C counterpart of the android.view.Surface object in Java,
* and can be converted both ways. Depending on the consumer, images
* submitted to ANativeWindow can be shown on the display or sent to
* other consumers, such as video encoders.
* @{
*/
/**
* @file native_window.h
* @brief API for accessing a native window.
*/
#ifndef ANDROID_NATIVE_WINDOW_H
#define ANDROID_NATIVE_WINDOW_H
#include <stdint.h>
#include <sys/cdefs.h>
#include <android/data_space.h>
#include <android/hardware_buffer.h>
#include <android/rect.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* Legacy window pixel format names, kept for backwards compatibility.
* New code and APIs should use AHARDWAREBUFFER_FORMAT_*.
*/
enum ANativeWindow_LegacyFormat {
// NOTE: these values must match the values from graphics/common/x.x/types.hal
/** Red: 8 bits, Green: 8 bits, Blue: 8 bits, Alpha: 8 bits. **/
WINDOW_FORMAT_RGBA_8888 = AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM,
/** Red: 8 bits, Green: 8 bits, Blue: 8 bits, Unused: 8 bits. **/
WINDOW_FORMAT_RGBX_8888 = AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM,
/** Red: 5 bits, Green: 6 bits, Blue: 5 bits. **/
WINDOW_FORMAT_RGB_565 = AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM,
};
/**
* Transforms that can be applied to buffers as they are displayed to a window.
*
* Supported transforms are any combination of horizontal mirror, vertical
* mirror, and clockwise 90 degree rotation, in that order. Rotations of 180
* and 270 degrees are made up of those basic transforms.
*/
enum ANativeWindowTransform {
ANATIVEWINDOW_TRANSFORM_IDENTITY = 0x00,
ANATIVEWINDOW_TRANSFORM_MIRROR_HORIZONTAL = 0x01,
ANATIVEWINDOW_TRANSFORM_MIRROR_VERTICAL = 0x02,
ANATIVEWINDOW_TRANSFORM_ROTATE_90 = 0x04,
ANATIVEWINDOW_TRANSFORM_ROTATE_180 = ANATIVEWINDOW_TRANSFORM_MIRROR_HORIZONTAL |
ANATIVEWINDOW_TRANSFORM_MIRROR_VERTICAL,
ANATIVEWINDOW_TRANSFORM_ROTATE_270 = ANATIVEWINDOW_TRANSFORM_ROTATE_180 |
ANATIVEWINDOW_TRANSFORM_ROTATE_90,
};
struct ANativeWindow;
/**
* Opaque type that provides access to a native window.
*
* A pointer can be obtained using {@link ANativeWindow_fromSurface()}.
*/
typedef struct ANativeWindow ANativeWindow;
/**
* Struct that represents a windows buffer.
*
* A pointer can be obtained using {@link ANativeWindow_lock()}.
*/
typedef struct ANativeWindow_Buffer {
/// The number of pixels that are shown horizontally.
int32_t width;
/// The number of pixels that are shown vertically.
int32_t height;
/// The number of *pixels* that a line in the buffer takes in
/// memory. This may be >= width.
int32_t stride;
/// The format of the buffer. One of AHardwareBuffer_Format.
int32_t format;
/// The actual bits.
void* bits;
/// Do not touch.
uint32_t reserved[6];
} ANativeWindow_Buffer;
/**
* Acquire a reference on the given {@link ANativeWindow} object. This prevents the object
* from being deleted until the reference is removed.
*/
void ANativeWindow_acquire(ANativeWindow* window);
/**
* Remove a reference that was previously acquired with {@link ANativeWindow_acquire()}.
*/
void ANativeWindow_release(ANativeWindow* window);
/**
* Return the current width in pixels of the window surface.
*
* \return negative value on error.
*/
int32_t ANativeWindow_getWidth(ANativeWindow* window);
/**
* Return the current height in pixels of the window surface.
*
* \return a negative value on error.
*/
int32_t ANativeWindow_getHeight(ANativeWindow* window);
/**
* Return the current pixel format (AHARDWAREBUFFER_FORMAT_*) of the window surface.
*
* \return a negative value on error.
*/
int32_t ANativeWindow_getFormat(ANativeWindow* window);
/**
* Change the format and size of the window buffers.
*
* The width and height control the number of pixels in the buffers, not the
* dimensions of the window on screen. If these are different than the
* window's physical size, then its buffer will be scaled to match that size
* when compositing it to the screen. The width and height must be either both zero
* or both non-zero.
*
* For all of these parameters, if 0 is supplied then the window's base
* value will come back in force.
*
* \param width width of the buffers in pixels.
* \param height height of the buffers in pixels.
* \param format one of the AHardwareBuffer_Format constants.
* \return 0 for success, or a negative value on error.
*/
int32_t ANativeWindow_setBuffersGeometry(ANativeWindow* window,
int32_t width, int32_t height, int32_t format);
/**
* Lock the window's next drawing surface for writing.
* inOutDirtyBounds is used as an in/out parameter, upon entering the
* function, it contains the dirty region, that is, the region the caller
* intends to redraw. When the function returns, inOutDirtyBounds is updated
* with the actual area the caller needs to redraw -- this region is often
* extended by {@link ANativeWindow_lock}.
*
* \return 0 for success, or a negative value on error.
*/
int32_t ANativeWindow_lock(ANativeWindow* window, ANativeWindow_Buffer* outBuffer,
ARect* inOutDirtyBounds);
/**
* Unlock the window's drawing surface after previously locking it,
* posting the new buffer to the display.
*
* \return 0 for success, or a negative value on error.
*/
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
*/
int32_t ANativeWindow_setBuffersTransform(ANativeWindow* window, int32_t transform) __INTRODUCED_IN(26);
/**
* All buffers queued after this call will be associated with the dataSpace
* parameter specified.
*
* dataSpace specifies additional information about the buffer.
* For example, it can be used to convey the color space of the image data in
* the buffer, or it can be used to indicate that the buffers contain depth
* 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.
*/
int32_t ANativeWindow_setBuffersDataSpace(ANativeWindow* window, int32_t dataSpace) __INTRODUCED_IN(28);
/**
* 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.
*/
int32_t ANativeWindow_getBuffersDataSpace(ANativeWindow* window) __INTRODUCED_IN(28);
/** Compatibility value for ANativeWindow_setFrameRate. */
enum ANativeWindow_FrameRateCompatibility {
/**
* There are no inherent restrictions on the frame rate of this window. When
* the system selects a frame rate other than what the app requested, the
* app will be able to run at the system frame rate without requiring pull
* down. This value should be used when displaying game content, UIs, and
* anything that isn't video.
*/
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. This value should be used for video content.
*/
ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE = 1
};
/**
* 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, in frames per
* second. 0 is a special value that indicates the app will accept the system's
* choice for the display frame rate, which is the default behavior if this
* function isn't called. The frameRate param does <em>not</em> need to be a
* valid refresh rate for this device's display - e.g., it's fine to pass 30fps
* to a device that can only run the display at 60fps.
*
* \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, int8_t compatibility)
__INTRODUCED_IN(30);
/**
* Provides a hint to the window that buffers should be preallocated ahead of
* time. Note that the window implementation is not guaranteed to preallocate
* any buffers, for instance if an implementation disallows allocation of new
* buffers, or if there is insufficient memory in the system to preallocate
* additional buffers
*
* Available since API level 30.
*/
void ANativeWindow_tryAllocateBuffers(ANativeWindow* window);
#ifdef __cplusplus
};
#endif
#endif // ANDROID_NATIVE_WINDOW_H
/** @} */

View file

@ -0,0 +1,65 @@
/*
* 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.
* 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 NativeActivity Native Activity
* @{
*/
/**
* @file rect.h
*/
#ifndef ANDROID_RECT_H
#define ANDROID_RECT_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* Rectangular window area.
*
* This is the NDK equivalent of the android.graphics.Rect class in Java. It is
* used with {@link ANativeActivityCallbacks::onContentRectChanged} event
* callback and the ANativeWindow_lock() function.
*
* In a valid ARect, left <= right and top <= bottom. ARect with left=0, top=10,
* right=1, bottom=11 contains only one pixel at x=0, y=10.
*/
typedef struct ARect {
#ifdef __cplusplus
typedef int32_t value_type;
#endif
/// Minimum X coordinate of the rectangle.
int32_t left;
/// Minimum Y coordinate of the rectangle.
int32_t top;
/// Maximum X coordinate of the rectangle.
int32_t right;
/// Maximum Y coordinate of the rectangle.
int32_t bottom;
} ARect;
#ifdef __cplusplus
};
#endif
#endif // ANDROID_RECT_H
/** @} */

View file

@ -0,0 +1,49 @@
/*
* sync.h
*
* Copyright 2012 Google, Inc
*
* 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 __SYS_CORE_SYNC_H
#define __SYS_CORE_SYNC_H
/* This file contains the legacy sync interface used by Android platform and
* device code. The direct contents will be removed over time as code
* transitions to using the updated interface in ndk/sync.h. When this file is
* empty other than the ndk/sync.h include, that file will be renamed to
* replace this one.
*
* New code should continue to include this file (#include <android/sync.h>)
* instead of ndk/sync.h so the eventual rename is seamless, but should only
* use the things declared in ndk/sync.h.
*
* This file used to be called sync/sync.h, but we renamed to that both the
* platform and NDK call it android/sync.h. A symlink from the old name to this
* one exists temporarily to avoid having to change all sync clients
* simultaneously. It will be removed when they've been updated, and probably
* after this change has been delivered to AOSP so that integrations don't
* break builds.
*/
#include "../ndk/sync.h"
__BEGIN_DECLS
/* timeout in msecs */
int sync_wait(int fd, int timeout);
__END_DECLS
#endif /* __SYS_CORE_SYNC_H */