# Native Window

ANativeWindow represents the producer end of an image queue.

## Summary

Parcelable support for ANativeWindow.

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.

Can be used with libbinder_ndk

| ### Enumerations ||
|---|---|
| `https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ga7868428081f5aaedef70c3e52caf8c9b{ https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1gga7868428081f5aaedef70c3e52caf8c9baf2b3fa6a7e471c0b4df1c0be8592af7e = 0x00, https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1gga7868428081f5aaedef70c3e52caf8c9bae12d99648b63653ecae9568871c0d83a = 0x01, https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1gga7868428081f5aaedef70c3e52caf8c9baf2470b12da509988d5255a662f4959e6 = 0x02, https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1gga7868428081f5aaedef70c3e52caf8c9baa278c5390b3933bd23044ed60d66d08a = 0x04, https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1gga7868428081f5aaedef70c3e52caf8c9ba5f757fea86ed5a7148f8e18ee70673a1 = ANATIVEWINDOW_TRANSFORM_MIRROR_HORIZONTAL | ANATIVEWINDOW_TRANSFORM_MIRROR_VERTICAL, https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1gga7868428081f5aaedef70c3e52caf8c9ba4dfc1b7b64186a7a6b32906407269437 = ANATIVEWINDOW_TRANSFORM_ROTATE_180 | ANATIVEWINDOW_TRANSFORM_ROTATE_90 }` | enumTransforms that can be applied to buffers as they are displayed to a window. |
| `https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ga2ad7fa9012d03a45572c6d433f68f3af{ https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1gga2ad7fa9012d03a45572c6d433f68f3afac6bbf763ffa2b1b53ca9e745ce190058 = 0, https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1gga2ad7fa9012d03a45572c6d433f68f3afafb149b7bcec802a5c300b9e404f4ae77 = 1 }` | enumChange frame rate strategy value for ANativeWindow_setFrameRate. |
| `https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ga0a3c6e3081f4a31cabbfd3b08f1b3114{ https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1gga0a3c6e3081f4a31cabbfd3b08f1b3114abce87f7facf210cefac74e730948f492 = 0, https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1gga0a3c6e3081f4a31cabbfd3b08f1b3114ae05c70fbf9a5f252dc64cce7de58747e = 1, https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1gga0a3c6e3081f4a31cabbfd3b08f1b3114a99cd7da4a8169c238c4f4d73c9782bc5 = 2 }` | enumCompatibility value for ANativeWindow_setFrameRate. |
| `https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1gadd2252e6053a89185c99d3da298150c9{ https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ggadd2252e6053a89185c99d3da298150c9a6a165383340acce0b32c555dd2ac2c01 = AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM, https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ggadd2252e6053a89185c99d3da298150c9a5f83a97ccf64fc1554c220476e8aaf30 = AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM, https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ggadd2252e6053a89185c99d3da298150c9ab26fa9c38f169263b611a8b757bb0259 = AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM }` | enumLegacy window pixel format names, kept for backwards compatibility. |

| ### Typedefs ||
|---|---|
| `https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ga66956d540c2e3709e12156d195e64726` | typedef `struct https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ga66956d540c2e3709e12156d195e64726` Opaque type that provides access to a native window. |
| `https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1gad0983ca473ce36293baf5e51a14c3357` | typedef `struct https://developer.android.com/ndk/reference/struct/a-native-window-buffer#struct_a_native_window___buffer` Struct that represents a windows buffer. |

| ### Functions ||
|---|---|
| `https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1gaf7293644077b8b2e99ec146dffe8f6c8(https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ga66956d540c2e3709e12156d195e64726 *_Nonnull window)` | `void` Acquire a reference on the given [ANativeWindow](https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window) object. |
| `https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ga923864792cd755814167dd67826788a4(https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ga66956d540c2e3709e12156d195e64726 *_Nonnull window)` | `int32_t` Clears the frame rate which is set for this window. |
| `https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ga98a1669dd0dd08c83cb533e50be23e6f(https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ga66956d540c2e3709e12156d195e64726 *_Nonnull window)` | `int32_t` Get the dataspace of the buffers in window. |
| `https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ga473dd31e6519fec9ac3e9f8c7a9f153a(https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ga66956d540c2e3709e12156d195e64726 *_Nonnull window)` | `int32_t` Get the default dataspace of the buffers in window as set by the consumer. |
| `https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ga4c660fca3d2fca50d1a0bd7b0d376dbf(https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ga66956d540c2e3709e12156d195e64726 *_Nonnull window)` | `int32_t` Return the current pixel format (AHARDWAREBUFFER_FORMAT_\*) of the window surface. |
| `https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1gac34066284ae985affe47d18e636e731b(https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ga66956d540c2e3709e12156d195e64726 *_Nonnull window)` | `int32_t` Return the current height in pixels of the window surface. |
| `https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1gaa283a95975b17be9338c736c06fb300c(https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ga66956d540c2e3709e12156d195e64726 *_Nonnull window)` | `int32_t` Return the current width in pixels of the window surface. |
| `https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ga708a61911c6ff8a37e0efdab5faae49e(https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ga66956d540c2e3709e12156d195e64726 *_Nonnull window, bool *_Nonnull outEnabled)` | `int32_t` Check if CPU throttling is enabled. |
| `https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1gae08841e6125415ef4c23da62c9b2f9b8(https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ga66956d540c2e3709e12156d195e64726 *_Nonnull window, https://developer.android.com/ndk/reference/struct/a-native-window-buffer#struct_a_native_window___buffer *_Nonnull outBuffer, https://developer.android.com/ndk/reference/struct/a-rect#struct_a_rect *https://developer.android.com/ndk/reference/group/ndk-binder#group___ndk_binder_1ga0890a8f74983b96e76f6b8748543032d inOutDirtyBounds)` | `int32_t` Lock the window's next drawing surface for writing. |
| `https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ga057a06f573b6057a5d359b9582446845(const AParcel *_Nonnull parcel, https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ga66956d540c2e3709e12156d195e64726 *https://developer.android.com/ndk/reference/group/ndk-binder#group___ndk_binder_1ga0890a8f74983b96e76f6b8748543032d *_Nonnull outWindow)` | `https://developer.android.com/ndk/reference/group/ndk-binder#group___ndk_binder_1ga26845d019135385e22a356743fdf639f` Read an ANativeWindow from a AParcel. |
| `https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ga2f40296a5371c827539fa3a137ccef46(https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ga66956d540c2e3709e12156d195e64726 *_Nonnull window)` | `void` Remove a reference that was previously acquired with [ANativeWindow_acquire()](https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1gaf7293644077b8b2e99ec146dffe8f6c8). |
| `https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1gabba880a801181bc9d728135e8d22e23f(https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ga66956d540c2e3709e12156d195e64726 *_Nonnull window, int32_t dataSpace)` | `int32_t` All buffers queued after this call will be associated with the dataSpace parameter specified. |
| `https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ga155e5218b14386baed6cb833e5842108(https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ga66956d540c2e3709e12156d195e64726 *_Nonnull window, int32_t width, int32_t height, int32_t format)` | `int32_t` Change the format and size of the window buffers. |
| `https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ga96578d622f8d9e36f4299cfecb847857(https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ga66956d540c2e3709e12156d195e64726 *_Nonnull window, int32_t transform)` | `int32_t` Set a transform that will be applied to future buffers posted to the window. |
| `https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ga0e026ac6946f1daeca37048289f93846(https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ga66956d540c2e3709e12156d195e64726 *_Nonnull window, float frameRate, int8_t compatibility)` | `int32_t` Same as ANativeWindow_setFrameRateWithChangeStrategy(window, frameRate, compatibility, ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS). |
| `https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1gae0c291f4281907ef3f7d66d2216a16df(https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ga66956d540c2e3709e12156d195e64726 *_Nonnull window, float frameRate, int8_t compatibility, int8_t changeFrameRateStrategy)` | `int32_t` Sets the intended frame rate for this window. |
| `https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1gac9bb516e2f764dc151637df79087de2b(https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ga66956d540c2e3709e12156d195e64726 *_Nonnull window, bool enabled)` | `int32_t` Control CPU throttling for Vulkan/EGL producers. |
| `https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ga1de392838be26c3bca9adfbea8874170(https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ga66956d540c2e3709e12156d195e64726 *_Nonnull window)` | `void` Provides a hint to the window that buffers should be preallocated ahead of time. |
| `https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ga52a8c4087fd8856a91ed1136967ad573(https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ga66956d540c2e3709e12156d195e64726 *_Nonnull window)` | `int32_t` Unlock the window's drawing surface after previously locking it, posting the new buffer to the display. |
| `https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ga69d9599f7ec8a0f5817fe941a5f790d3(https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ga66956d540c2e3709e12156d195e64726 *_Nonnull window, AParcel *_Nonnull parcel)` | `https://developer.android.com/ndk/reference/group/ndk-binder#group___ndk_binder_1ga26845d019135385e22a356743fdf639f` Write an ANativeWindow to an AParcel. |

| ### Structs ||
|---|---|
| [ANativeWindow_Buffer](https://developer.android.com/ndk/reference/struct/a-native-window-buffer) | Struct that represents a windows buffer. |

## Enumerations

### ANativeWindowTransform

Declared in `android/native_window.h`

```
 ANativeWindowTransform
```
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.

| Properties ||
|---|---|
| `ANATIVEWINDOW_TRANSFORM_IDENTITY` |   |
| `ANATIVEWINDOW_TRANSFORM_MIRROR_HORIZONTAL` |   |
| `ANATIVEWINDOW_TRANSFORM_MIRROR_VERTICAL` |   |
| `ANATIVEWINDOW_TRANSFORM_ROTATE_180` |   |
| `ANATIVEWINDOW_TRANSFORM_ROTATE_270` |   |
| `ANATIVEWINDOW_TRANSFORM_ROTATE_90` |   |

### ANativeWindow_ChangeFrameRateStrategy

Declared in `android/native_window.h`

```
 ANativeWindow_ChangeFrameRateStrategy
```
Change frame rate strategy value for ANativeWindow_setFrameRate.

| Properties ||
|---|---|
| `ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS` | Change the frame rate even if the transition is going to be non-seamless, i.e. with visual interruptions for the user. |
| `ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS` | Change the frame rate only if the transition is going to be seamless. |

### ANativeWindow_FrameRateCompatibility

Declared in `android/native_window.h`

```
 ANativeWindow_FrameRateCompatibility
```
Compatibility value for ANativeWindow_setFrameRate.

| Properties ||
|---|---|
| `ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_AT_LEAST` | The window requests a frame rate that is at least the specified frame rate. This value should be used for UIs, animations, scrolling, and anything that is not a game or video. |
| `ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT` | 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. |
| `ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE` | 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_LegacyFormat

Declared in `android/native_window.h`

```
 ANativeWindow_LegacyFormat
```
Legacy window pixel format names, kept for backwards compatibility.

New code and APIs should use AHARDWAREBUFFER_FORMAT_\*.

| Properties ||
|---|---|
| `WINDOW_FORMAT_RGBA_8888` | Red: 8 bits, Green: 8 bits, Blue: 8 bits, Alpha: 8 bits. |
| `WINDOW_FORMAT_RGBX_8888` | Red: 8 bits, Green: 8 bits, Blue: 8 bits, Unused: 8 bits. |
| `WINDOW_FORMAT_RGB_565` | Red: 5 bits, Green: 6 bits, Blue: 5 bits. |

## Typedefs

### ANativeWindow

Declared in `android/native_window.h`

```
struct ANativeWindow ANativeWindow
```
Opaque type that provides access to a native window.

A pointer can be obtained using [ANativeWindow_fromSurface()](https://developer.android.com/ndk/reference/group/native-activity#group___native_activity_1ga774d0a87ec496b3940fcddccbc31fd9d).

### ANativeWindow_Buffer

Declared in `android/native_window.h`

```
struct ANativeWindow_Buffer ANativeWindow_Buffer
```
Struct that represents a windows buffer.

A pointer can be obtained using [ANativeWindow_lock()](https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1gae08841e6125415ef4c23da62c9b2f9b8).

## Functions

### ANativeWindow_acquire

Declared in `android/native_window.h`

```
void ANativeWindow_acquire(
  ANativeWindow *_Nonnull window
)
```
Acquire a reference on the given [ANativeWindow](https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window) object.

This prevents the object from being deleted until the reference is removed.

### ANativeWindow_clearFrameRate

Declared in `android/native_window.h`

```
int32_t ANativeWindow_clearFrameRate(
  ANativeWindow *_Nonnull window
)
```
Clears the frame rate which is set for this window.

This is equivalent to calling ANativeWindow_setFrameRateWithChangeStrategy(window, 0, compatibility, changeFrameRateStrategy).

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.

You can register for changes in the refresh rate using *AChoreographer_registerRefreshRateCallback*.

See [ANativeWindow_setFrameRateWithChangeStrategy()](https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1gae0c291f4281907ef3f7d66d2216a16df).

Available since API level 31.

<br />

Details Parameters `window` pointer to an ANativeWindow object. **Returns** 0 for success, -EINVAL if the window value is invalid.

### ANativeWindow_getBuffersDataSpace

Declared in `android/native_window.h`

```
int32_t ANativeWindow_getBuffersDataSpace(
  ANativeWindow *_Nonnull window
)
```
Get the dataspace of the buffers in window.

Available since API level 28.

<br />

| Details ||
|---|---|
| **Returns** | the dataspace of buffers in window, ADATASPACE_UNKNOWN is returned if dataspace is unknown, or -EINVAL if window is invalid. |

### ANativeWindow_getBuffersDefaultDataSpace

Declared in `android/native_window.h`

```
int32_t ANativeWindow_getBuffersDefaultDataSpace(
  ANativeWindow *_Nonnull window
)
```
Get the default dataspace of the buffers in window as set by the consumer.

Available since API level 34.

<br />

| Details ||
|---|---|
| **Returns** | the dataspace of buffers in window, ADATASPACE_UNKNOWN is returned if dataspace is unknown, or -EINVAL if window is invalid. |

### ANativeWindow_getFormat

Declared in `android/native_window.h`

```
int32_t ANativeWindow_getFormat(
  ANativeWindow *_Nonnull window
)
```
Return the current pixel format (AHARDWAREBUFFER_FORMAT_\*) of the window surface.

<br />

| Details ||
|---|---|
| **Returns** | a negative value on error. |

### ANativeWindow_getHeight

Declared in `android/native_window.h`

```
int32_t ANativeWindow_getHeight(
  ANativeWindow *_Nonnull window
)
```
Return the current height in pixels of the window surface.

<br />

| Details ||
|---|---|
| **Returns** | a negative value on error. |

### ANativeWindow_getWidth

Declared in `android/native_window.h`

```
int32_t ANativeWindow_getWidth(
  ANativeWindow *_Nonnull window
)
```
Return the current width in pixels of the window surface.

<br />

| Details ||
|---|---|
| **Returns** | negative value on error. |

### ANativeWindow_isProducerThrottlingEnabled

Declared in `android/native_window.h`

```
int32_t ANativeWindow_isProducerThrottlingEnabled(
  ANativeWindow *_Nonnull window,
  bool *_Nonnull outEnabled
)
```
Check if CPU throttling is enabled.

Available since API level 37.

<br />

Details Parameters `window` pointer to an ANativeWindow object. `outEnabled` pointer to a bool to store the result. **Returns** 0 if successful, -EINVAL if the window value is invalid

### ANativeWindow_lock

Declared in `android/native_window.h`

```
int32_t ANativeWindow_lock(
  ANativeWindow *_Nonnull window,
  ANativeWindow_Buffer *_Nonnull outBuffer,
  ARect *_Nullable inOutDirtyBounds
)
```
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 [ANativeWindow_lock](https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1gae08841e6125415ef4c23da62c9b2f9b8).

<br />

| Details ||
|---|---|
| **Returns** | 0 for success, or a negative value on error. |

### ANativeWindow_readFromParcel

Declared in `android/native_window_aidl.h`

```
binder_status_t ANativeWindow_readFromParcel(
  const AParcel *_Nonnull parcel,
  ANativeWindow *_Nullable *_Nonnull outWindow
)
```
Read an ANativeWindow from a AParcel.

The output buffer will have an initial reference acquired and will need to be released with ANativeWindow_release.

Available since API level 34.

<br />

| Details ||
|---|---|
| **Returns** | STATUS_OK on success STATUS_BAD_VALUE if the parcel or outBuffer is null, or if there's an issue deserializing (eg, corrupted parcel) STATUS_BAD_TYPE if the parcel's current data position is not that of an ANativeWindow type STATUS_NO_MEMORY if an allocation fails |

### ANativeWindow_release

Declared in `android/native_window.h`

```
void ANativeWindow_release(
  ANativeWindow *_Nonnull window
)
```
Remove a reference that was previously acquired with [ANativeWindow_acquire()](https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1gaf7293644077b8b2e99ec146dffe8f6c8).

### ANativeWindow_setBuffersDataSpace

Declared in `android/native_window.h`

```
int32_t ANativeWindow_setBuffersDataSpace(
  ANativeWindow *_Nonnull window,
  int32_t dataSpace
)
```
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.

<br />

Details Parameters `window` pointer to an ANativeWindow object. `dataSpace` data space of all buffers queued after this call. **Returns** 0 for success, -EINVAL if window is invalid or the dataspace is not supported.

### ANativeWindow_setBuffersGeometry

Declared in `android/native_window.h`

```
int32_t ANativeWindow_setBuffersGeometry(
  ANativeWindow *_Nonnull window,
  int32_t width,
  int32_t height,
  int32_t format
)
```
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.

<br />

Details Parameters `window` pointer to an ANativeWindow object. `width` width of the buffers in pixels. `height` height of the buffers in pixels. `format` one of the AHardwareBuffer_Format constants. **Returns** 0 for success, or a negative value on error.

### ANativeWindow_setBuffersTransform

Declared in `android/native_window.h`

```
int32_t ANativeWindow_setBuffersTransform(
  ANativeWindow *_Nonnull window,
  int32_t transform
)
```
Set a transform that will be applied to future buffers posted to the window.

Available since API level 26.

<br />

Details Parameters `window` pointer to an ANativeWindow object. `transform` combination of [ANativeWindowTransform](https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ga7868428081f5aaedef70c3e52caf8c9b) flags **Returns** 0 for success, or -EINVAL if `transform` is invalid

### ANativeWindow_setFrameRate

Declared in `android/native_window.h`

```
int32_t ANativeWindow_setFrameRate(
  ANativeWindow *_Nonnull window,
  float frameRate,
  int8_t compatibility
)
```
Same as ANativeWindow_setFrameRateWithChangeStrategy(window, frameRate, compatibility, ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS).

See [ANativeWindow_setFrameRateWithChangeStrategy()](https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1gae0c291f4281907ef3f7d66d2216a16df).

Available since API level 30.

### ANativeWindow_setFrameRateWithChangeStrategy

Declared in `android/native_window.h`

```
int32_t ANativeWindow_setFrameRateWithChangeStrategy(
  ANativeWindow *_Nonnull window,
  float frameRate,
  int8_t compatibility,
  int8_t changeFrameRateStrategy
)
```
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.

You can register for changes in the refresh rate using *AChoreographer_registerRefreshRateCallback*.

See [ANativeWindow_clearFrameRate()](https://developer.android.com/ndk/reference/group/a-native-window#group___a_native_window_1ga923864792cd755814167dd67826788a4).

Available since API level 31.

<br />

Details Parameters `window` pointer to an ANativeWindow object. `frameRate` The intended frame rate of this window, in frames per second. 0 is a special value that indicates the app will accept the system's choice for the display frame rate, which is the default behavior if this function isn't called. The frameRate param does *not* need to be a valid refresh rate for this device's display - e.g., it's fine to pass 30fps to a device that can only run the display at 60fps. `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. This parameter is ignored when frameRate is 0. `changeFrameRateStrategy` Whether display refresh rate transitions caused by this window 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. **Returns** 0 for success, -EINVAL if the window, frame rate, or compatibility value are invalid.

### ANativeWindow_setProducerThrottlingEnabled

Declared in `android/native_window.h`

```
int32_t ANativeWindow_setProducerThrottlingEnabled(
  ANativeWindow *_Nonnull window,
  bool enabled
)
```
Control CPU throttling for Vulkan/EGL producers.

By default Vulkan and EGL producers are CPU throttled when they queue a buffer and the consumer is still processing the previous buffer. In practice, it means that eglSwapBuffers() or vkPresentKHR() calls will stall the CPU until the GPU is done processing the previous frame. This API allows to disable this throttling while queueing a buffer.

While the default is to have throttling enabled, the more correct and efficient behavior is to have it disabled. Unfortunately, some Vulkan applications may inadvertently rely on this stall which effectively behaves as consumer/producer synchronization, albeit, inefficiently. It is therefore recommended to always disable throttling and perform proper synchronization in Vulkan.

If the CPU produces frames faster than the GPU, natural throttling will happen when a buffer is dequeued, based on the size of the queue. This typically happen during the first drawing in OpenGL ES and in vkAcquireNextImageKHR() in Vulkan.

This API has no effect in asynchronous mode, where throttling is always enabled.

Available since API level 37.

<br />

Details Parameters `window` pointer to an ANativeWindow object. `enabled` true to enable throttling, false to disable it. **Returns** 0 for success, -EINVAL if the window value is invalid.

### ANativeWindow_tryAllocateBuffers

Declared in `android/native_window.h`

```
void ANativeWindow_tryAllocateBuffers(
  ANativeWindow *_Nonnull window
)
```
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.

### ANativeWindow_unlockAndPost

Declared in `android/native_window.h`

```
int32_t ANativeWindow_unlockAndPost(
  ANativeWindow *_Nonnull window
)
```
Unlock the window's drawing surface after previously locking it, posting the new buffer to the display.

<br />

| Details ||
|---|---|
| **Returns** | 0 for success, or a negative value on error. |

### ANativeWindow_writeToParcel

Declared in `android/native_window_aidl.h`

```
binder_status_t ANativeWindow_writeToParcel(
  ANativeWindow *_Nonnull window,
  AParcel *_Nonnull parcel
)
```
Write an ANativeWindow to an AParcel.

Available since API level 34.

<br />

| Details ||
|---|---|
| **Returns** | STATUS_OK on success. STATUS_BAD_VALUE if either buffer or parcel is null, or if the ANativeWindow\* fails to serialize (eg, internally corrupted) STATUS_NO_MEMORY if the parcel runs out of space to store the buffer \& is unable to allocate more STATUS_FDS_NOT_ALLOWED if the parcel does not allow storing FDs |