1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright (C) 2010 The Android Open Source Project 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 5bf215546Sopenharmony_ci * you may not use this file except in compliance with the License. 6bf215546Sopenharmony_ci * You may obtain a copy of the License at 7bf215546Sopenharmony_ci * 8bf215546Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 9bf215546Sopenharmony_ci * 10bf215546Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 11bf215546Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 12bf215546Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13bf215546Sopenharmony_ci * See the License for the specific language governing permissions and 14bf215546Sopenharmony_ci * limitations under the License. 15bf215546Sopenharmony_ci */ 16bf215546Sopenharmony_ci 17bf215546Sopenharmony_ci/** 18bf215546Sopenharmony_ci * @defgroup ANativeWindow Native Window 19bf215546Sopenharmony_ci * 20bf215546Sopenharmony_ci * ANativeWindow represents the producer end of an image queue. 21bf215546Sopenharmony_ci * It is the C counterpart of the android.view.Surface object in Java, 22bf215546Sopenharmony_ci * and can be converted both ways. Depending on the consumer, images 23bf215546Sopenharmony_ci * submitted to ANativeWindow can be shown on the display or sent to 24bf215546Sopenharmony_ci * other consumers, such as video encoders. 25bf215546Sopenharmony_ci * @{ 26bf215546Sopenharmony_ci */ 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_ci/** 29bf215546Sopenharmony_ci * @file native_window.h 30bf215546Sopenharmony_ci * @brief API for accessing a native window. 31bf215546Sopenharmony_ci */ 32bf215546Sopenharmony_ci 33bf215546Sopenharmony_ci#ifndef ANDROID_NATIVE_WINDOW_H 34bf215546Sopenharmony_ci#define ANDROID_NATIVE_WINDOW_H 35bf215546Sopenharmony_ci 36bf215546Sopenharmony_ci#include <stdint.h> 37bf215546Sopenharmony_ci#include <sys/cdefs.h> 38bf215546Sopenharmony_ci 39bf215546Sopenharmony_ci#include <android/data_space.h> 40bf215546Sopenharmony_ci#include <android/hardware_buffer.h> 41bf215546Sopenharmony_ci#include <android/rect.h> 42bf215546Sopenharmony_ci 43bf215546Sopenharmony_ci#ifdef __cplusplus 44bf215546Sopenharmony_ciextern "C" { 45bf215546Sopenharmony_ci#endif 46bf215546Sopenharmony_ci 47bf215546Sopenharmony_ci/** 48bf215546Sopenharmony_ci * Legacy window pixel format names, kept for backwards compatibility. 49bf215546Sopenharmony_ci * New code and APIs should use AHARDWAREBUFFER_FORMAT_*. 50bf215546Sopenharmony_ci */ 51bf215546Sopenharmony_cienum ANativeWindow_LegacyFormat { 52bf215546Sopenharmony_ci // NOTE: these values must match the values from graphics/common/x.x/types.hal 53bf215546Sopenharmony_ci 54bf215546Sopenharmony_ci /** Red: 8 bits, Green: 8 bits, Blue: 8 bits, Alpha: 8 bits. **/ 55bf215546Sopenharmony_ci WINDOW_FORMAT_RGBA_8888 = AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM, 56bf215546Sopenharmony_ci /** Red: 8 bits, Green: 8 bits, Blue: 8 bits, Unused: 8 bits. **/ 57bf215546Sopenharmony_ci WINDOW_FORMAT_RGBX_8888 = AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM, 58bf215546Sopenharmony_ci /** Red: 5 bits, Green: 6 bits, Blue: 5 bits. **/ 59bf215546Sopenharmony_ci WINDOW_FORMAT_RGB_565 = AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM, 60bf215546Sopenharmony_ci}; 61bf215546Sopenharmony_ci 62bf215546Sopenharmony_ci/** 63bf215546Sopenharmony_ci * Transforms that can be applied to buffers as they are displayed to a window. 64bf215546Sopenharmony_ci * 65bf215546Sopenharmony_ci * Supported transforms are any combination of horizontal mirror, vertical 66bf215546Sopenharmony_ci * mirror, and clockwise 90 degree rotation, in that order. Rotations of 180 67bf215546Sopenharmony_ci * and 270 degrees are made up of those basic transforms. 68bf215546Sopenharmony_ci */ 69bf215546Sopenharmony_cienum ANativeWindowTransform { 70bf215546Sopenharmony_ci ANATIVEWINDOW_TRANSFORM_IDENTITY = 0x00, 71bf215546Sopenharmony_ci ANATIVEWINDOW_TRANSFORM_MIRROR_HORIZONTAL = 0x01, 72bf215546Sopenharmony_ci ANATIVEWINDOW_TRANSFORM_MIRROR_VERTICAL = 0x02, 73bf215546Sopenharmony_ci ANATIVEWINDOW_TRANSFORM_ROTATE_90 = 0x04, 74bf215546Sopenharmony_ci 75bf215546Sopenharmony_ci ANATIVEWINDOW_TRANSFORM_ROTATE_180 = ANATIVEWINDOW_TRANSFORM_MIRROR_HORIZONTAL | 76bf215546Sopenharmony_ci ANATIVEWINDOW_TRANSFORM_MIRROR_VERTICAL, 77bf215546Sopenharmony_ci ANATIVEWINDOW_TRANSFORM_ROTATE_270 = ANATIVEWINDOW_TRANSFORM_ROTATE_180 | 78bf215546Sopenharmony_ci ANATIVEWINDOW_TRANSFORM_ROTATE_90, 79bf215546Sopenharmony_ci}; 80bf215546Sopenharmony_ci 81bf215546Sopenharmony_cistruct ANativeWindow; 82bf215546Sopenharmony_ci/** 83bf215546Sopenharmony_ci * Opaque type that provides access to a native window. 84bf215546Sopenharmony_ci * 85bf215546Sopenharmony_ci * A pointer can be obtained using {@link ANativeWindow_fromSurface()}. 86bf215546Sopenharmony_ci */ 87bf215546Sopenharmony_citypedef struct ANativeWindow ANativeWindow; 88bf215546Sopenharmony_ci 89bf215546Sopenharmony_ci/** 90bf215546Sopenharmony_ci * Struct that represents a windows buffer. 91bf215546Sopenharmony_ci * 92bf215546Sopenharmony_ci * A pointer can be obtained using {@link ANativeWindow_lock()}. 93bf215546Sopenharmony_ci */ 94bf215546Sopenharmony_citypedef struct ANativeWindow_Buffer { 95bf215546Sopenharmony_ci /// The number of pixels that are shown horizontally. 96bf215546Sopenharmony_ci int32_t width; 97bf215546Sopenharmony_ci 98bf215546Sopenharmony_ci /// The number of pixels that are shown vertically. 99bf215546Sopenharmony_ci int32_t height; 100bf215546Sopenharmony_ci 101bf215546Sopenharmony_ci /// The number of *pixels* that a line in the buffer takes in 102bf215546Sopenharmony_ci /// memory. This may be >= width. 103bf215546Sopenharmony_ci int32_t stride; 104bf215546Sopenharmony_ci 105bf215546Sopenharmony_ci /// The format of the buffer. One of AHardwareBuffer_Format. 106bf215546Sopenharmony_ci int32_t format; 107bf215546Sopenharmony_ci 108bf215546Sopenharmony_ci /// The actual bits. 109bf215546Sopenharmony_ci void* bits; 110bf215546Sopenharmony_ci 111bf215546Sopenharmony_ci /// Do not touch. 112bf215546Sopenharmony_ci uint32_t reserved[6]; 113bf215546Sopenharmony_ci} ANativeWindow_Buffer; 114bf215546Sopenharmony_ci 115bf215546Sopenharmony_ci/** 116bf215546Sopenharmony_ci * Acquire a reference on the given {@link ANativeWindow} object. This prevents the object 117bf215546Sopenharmony_ci * from being deleted until the reference is removed. 118bf215546Sopenharmony_ci */ 119bf215546Sopenharmony_civoid ANativeWindow_acquire(ANativeWindow* window); 120bf215546Sopenharmony_ci 121bf215546Sopenharmony_ci/** 122bf215546Sopenharmony_ci * Remove a reference that was previously acquired with {@link ANativeWindow_acquire()}. 123bf215546Sopenharmony_ci */ 124bf215546Sopenharmony_civoid ANativeWindow_release(ANativeWindow* window); 125bf215546Sopenharmony_ci 126bf215546Sopenharmony_ci/** 127bf215546Sopenharmony_ci * Return the current width in pixels of the window surface. 128bf215546Sopenharmony_ci * 129bf215546Sopenharmony_ci * \return negative value on error. 130bf215546Sopenharmony_ci */ 131bf215546Sopenharmony_ciint32_t ANativeWindow_getWidth(ANativeWindow* window); 132bf215546Sopenharmony_ci 133bf215546Sopenharmony_ci/** 134bf215546Sopenharmony_ci * Return the current height in pixels of the window surface. 135bf215546Sopenharmony_ci * 136bf215546Sopenharmony_ci * \return a negative value on error. 137bf215546Sopenharmony_ci */ 138bf215546Sopenharmony_ciint32_t ANativeWindow_getHeight(ANativeWindow* window); 139bf215546Sopenharmony_ci 140bf215546Sopenharmony_ci/** 141bf215546Sopenharmony_ci * Return the current pixel format (AHARDWAREBUFFER_FORMAT_*) of the window surface. 142bf215546Sopenharmony_ci * 143bf215546Sopenharmony_ci * \return a negative value on error. 144bf215546Sopenharmony_ci */ 145bf215546Sopenharmony_ciint32_t ANativeWindow_getFormat(ANativeWindow* window); 146bf215546Sopenharmony_ci 147bf215546Sopenharmony_ci/** 148bf215546Sopenharmony_ci * Change the format and size of the window buffers. 149bf215546Sopenharmony_ci * 150bf215546Sopenharmony_ci * The width and height control the number of pixels in the buffers, not the 151bf215546Sopenharmony_ci * dimensions of the window on screen. If these are different than the 152bf215546Sopenharmony_ci * window's physical size, then its buffer will be scaled to match that size 153bf215546Sopenharmony_ci * when compositing it to the screen. The width and height must be either both zero 154bf215546Sopenharmony_ci * or both non-zero. 155bf215546Sopenharmony_ci * 156bf215546Sopenharmony_ci * For all of these parameters, if 0 is supplied then the window's base 157bf215546Sopenharmony_ci * value will come back in force. 158bf215546Sopenharmony_ci * 159bf215546Sopenharmony_ci * \param width width of the buffers in pixels. 160bf215546Sopenharmony_ci * \param height height of the buffers in pixels. 161bf215546Sopenharmony_ci * \param format one of the AHardwareBuffer_Format constants. 162bf215546Sopenharmony_ci * \return 0 for success, or a negative value on error. 163bf215546Sopenharmony_ci */ 164bf215546Sopenharmony_ciint32_t ANativeWindow_setBuffersGeometry(ANativeWindow* window, 165bf215546Sopenharmony_ci int32_t width, int32_t height, int32_t format); 166bf215546Sopenharmony_ci 167bf215546Sopenharmony_ci/** 168bf215546Sopenharmony_ci * Lock the window's next drawing surface for writing. 169bf215546Sopenharmony_ci * inOutDirtyBounds is used as an in/out parameter, upon entering the 170bf215546Sopenharmony_ci * function, it contains the dirty region, that is, the region the caller 171bf215546Sopenharmony_ci * intends to redraw. When the function returns, inOutDirtyBounds is updated 172bf215546Sopenharmony_ci * with the actual area the caller needs to redraw -- this region is often 173bf215546Sopenharmony_ci * extended by {@link ANativeWindow_lock}. 174bf215546Sopenharmony_ci * 175bf215546Sopenharmony_ci * \return 0 for success, or a negative value on error. 176bf215546Sopenharmony_ci */ 177bf215546Sopenharmony_ciint32_t ANativeWindow_lock(ANativeWindow* window, ANativeWindow_Buffer* outBuffer, 178bf215546Sopenharmony_ci ARect* inOutDirtyBounds); 179bf215546Sopenharmony_ci 180bf215546Sopenharmony_ci/** 181bf215546Sopenharmony_ci * Unlock the window's drawing surface after previously locking it, 182bf215546Sopenharmony_ci * posting the new buffer to the display. 183bf215546Sopenharmony_ci * 184bf215546Sopenharmony_ci * \return 0 for success, or a negative value on error. 185bf215546Sopenharmony_ci */ 186bf215546Sopenharmony_ciint32_t ANativeWindow_unlockAndPost(ANativeWindow* window); 187bf215546Sopenharmony_ci 188bf215546Sopenharmony_ci/** 189bf215546Sopenharmony_ci * Set a transform that will be applied to future buffers posted to the window. 190bf215546Sopenharmony_ci * 191bf215546Sopenharmony_ci * Available since API level 26. 192bf215546Sopenharmony_ci * 193bf215546Sopenharmony_ci * \param transform combination of {@link ANativeWindowTransform} flags 194bf215546Sopenharmony_ci * \return 0 for success, or -EINVAL if \p transform is invalid 195bf215546Sopenharmony_ci */ 196bf215546Sopenharmony_ciint32_t ANativeWindow_setBuffersTransform(ANativeWindow* window, int32_t transform) __INTRODUCED_IN(26); 197bf215546Sopenharmony_ci 198bf215546Sopenharmony_ci/** 199bf215546Sopenharmony_ci * All buffers queued after this call will be associated with the dataSpace 200bf215546Sopenharmony_ci * parameter specified. 201bf215546Sopenharmony_ci * 202bf215546Sopenharmony_ci * dataSpace specifies additional information about the buffer. 203bf215546Sopenharmony_ci * For example, it can be used to convey the color space of the image data in 204bf215546Sopenharmony_ci * the buffer, or it can be used to indicate that the buffers contain depth 205bf215546Sopenharmony_ci * measurement data instead of color images. The default dataSpace is 0, 206bf215546Sopenharmony_ci * ADATASPACE_UNKNOWN, unless it has been overridden by the producer. 207bf215546Sopenharmony_ci * 208bf215546Sopenharmony_ci * Available since API level 28. 209bf215546Sopenharmony_ci * 210bf215546Sopenharmony_ci * \param dataSpace data space of all buffers queued after this call. 211bf215546Sopenharmony_ci * \return 0 for success, -EINVAL if window is invalid or the dataspace is not 212bf215546Sopenharmony_ci * supported. 213bf215546Sopenharmony_ci */ 214bf215546Sopenharmony_ciint32_t ANativeWindow_setBuffersDataSpace(ANativeWindow* window, int32_t dataSpace) __INTRODUCED_IN(28); 215bf215546Sopenharmony_ci 216bf215546Sopenharmony_ci/** 217bf215546Sopenharmony_ci * Get the dataspace of the buffers in window. 218bf215546Sopenharmony_ci * 219bf215546Sopenharmony_ci * Available since API level 28. 220bf215546Sopenharmony_ci * 221bf215546Sopenharmony_ci * \return the dataspace of buffers in window, ADATASPACE_UNKNOWN is returned if 222bf215546Sopenharmony_ci * dataspace is unknown, or -EINVAL if window is invalid. 223bf215546Sopenharmony_ci */ 224bf215546Sopenharmony_ciint32_t ANativeWindow_getBuffersDataSpace(ANativeWindow* window) __INTRODUCED_IN(28); 225bf215546Sopenharmony_ci 226bf215546Sopenharmony_ci/** Compatibility value for ANativeWindow_setFrameRate. */ 227bf215546Sopenharmony_cienum ANativeWindow_FrameRateCompatibility { 228bf215546Sopenharmony_ci /** 229bf215546Sopenharmony_ci * There are no inherent restrictions on the frame rate of this window. When 230bf215546Sopenharmony_ci * the system selects a frame rate other than what the app requested, the 231bf215546Sopenharmony_ci * app will be able to run at the system frame rate without requiring pull 232bf215546Sopenharmony_ci * down. This value should be used when displaying game content, UIs, and 233bf215546Sopenharmony_ci * anything that isn't video. 234bf215546Sopenharmony_ci */ 235bf215546Sopenharmony_ci ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT = 0, 236bf215546Sopenharmony_ci /** 237bf215546Sopenharmony_ci * This window is being used to display content with an inherently fixed 238bf215546Sopenharmony_ci * frame rate, e.g.\ a video that has a specific frame rate. When the system 239bf215546Sopenharmony_ci * selects a frame rate other than what the app requested, the app will need 240bf215546Sopenharmony_ci * to do pull down or use some other technique to adapt to the system's 241bf215546Sopenharmony_ci * frame rate. The user experience is likely to be worse (e.g. more frame 242bf215546Sopenharmony_ci * stuttering) than it would be if the system had chosen the app's requested 243bf215546Sopenharmony_ci * frame rate. This value should be used for video content. 244bf215546Sopenharmony_ci */ 245bf215546Sopenharmony_ci ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE = 1 246bf215546Sopenharmony_ci}; 247bf215546Sopenharmony_ci 248bf215546Sopenharmony_ci/** 249bf215546Sopenharmony_ci * Sets the intended frame rate for this window. 250bf215546Sopenharmony_ci * 251bf215546Sopenharmony_ci * On devices that are capable of running the display at different refresh 252bf215546Sopenharmony_ci * rates, the system may choose a display refresh rate to better match this 253bf215546Sopenharmony_ci * window's frame rate. Usage of this API won't introduce frame rate throttling, 254bf215546Sopenharmony_ci * or affect other aspects of the application's frame production 255bf215546Sopenharmony_ci * pipeline. However, because the system may change the display refresh rate, 256bf215546Sopenharmony_ci * calls to this function may result in changes to Choreographer callback 257bf215546Sopenharmony_ci * timings, and changes to the time interval at which the system releases 258bf215546Sopenharmony_ci * buffers back to the application. 259bf215546Sopenharmony_ci * 260bf215546Sopenharmony_ci * Note that this only has an effect for windows presented on the display. If 261bf215546Sopenharmony_ci * this ANativeWindow is consumed by something other than the system compositor, 262bf215546Sopenharmony_ci * e.g. a media codec, this call has no effect. 263bf215546Sopenharmony_ci * 264bf215546Sopenharmony_ci * Available since API level 30. 265bf215546Sopenharmony_ci * 266bf215546Sopenharmony_ci * \param frameRate The intended frame rate of this window, in frames per 267bf215546Sopenharmony_ci * second. 0 is a special value that indicates the app will accept the system's 268bf215546Sopenharmony_ci * choice for the display frame rate, which is the default behavior if this 269bf215546Sopenharmony_ci * function isn't called. The frameRate param does <em>not</em> need to be a 270bf215546Sopenharmony_ci * valid refresh rate for this device's display - e.g., it's fine to pass 30fps 271bf215546Sopenharmony_ci * to a device that can only run the display at 60fps. 272bf215546Sopenharmony_ci * 273bf215546Sopenharmony_ci * \param compatibility The frame rate compatibility of this window. The 274bf215546Sopenharmony_ci * compatibility value may influence the system's choice of display refresh 275bf215546Sopenharmony_ci * rate. See the ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_* values for more info. 276bf215546Sopenharmony_ci * 277bf215546Sopenharmony_ci * \return 0 for success, -EINVAL if the window, frame rate, or compatibility 278bf215546Sopenharmony_ci * value are invalid. 279bf215546Sopenharmony_ci */ 280bf215546Sopenharmony_ciint32_t ANativeWindow_setFrameRate(ANativeWindow* window, float frameRate, int8_t compatibility) 281bf215546Sopenharmony_ci __INTRODUCED_IN(30); 282bf215546Sopenharmony_ci 283bf215546Sopenharmony_ci/** 284bf215546Sopenharmony_ci * Provides a hint to the window that buffers should be preallocated ahead of 285bf215546Sopenharmony_ci * time. Note that the window implementation is not guaranteed to preallocate 286bf215546Sopenharmony_ci * any buffers, for instance if an implementation disallows allocation of new 287bf215546Sopenharmony_ci * buffers, or if there is insufficient memory in the system to preallocate 288bf215546Sopenharmony_ci * additional buffers 289bf215546Sopenharmony_ci * 290bf215546Sopenharmony_ci * Available since API level 30. 291bf215546Sopenharmony_ci */ 292bf215546Sopenharmony_civoid ANativeWindow_tryAllocateBuffers(ANativeWindow* window); 293bf215546Sopenharmony_ci 294bf215546Sopenharmony_ci#ifdef __cplusplus 295bf215546Sopenharmony_ci}; 296bf215546Sopenharmony_ci#endif 297bf215546Sopenharmony_ci 298bf215546Sopenharmony_ci#endif // ANDROID_NATIVE_WINDOW_H 299bf215546Sopenharmony_ci 300bf215546Sopenharmony_ci/** @} */ 301