Path: blob/21.2-virgl/include/android_stub/android/native_window.h
4547 views
/*1* Copyright (C) 2010 The Android Open Source Project2*3* Licensed under the Apache License, Version 2.0 (the "License");4* you may not use this file except in compliance with the License.5* You may obtain a copy of the License at6*7* http://www.apache.org/licenses/LICENSE-2.08*9* Unless required by applicable law or agreed to in writing, software10* distributed under the License is distributed on an "AS IS" BASIS,11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12* See the License for the specific language governing permissions and13* limitations under the License.14*/1516/**17* @defgroup ANativeWindow Native Window18*19* ANativeWindow represents the producer end of an image queue.20* It is the C counterpart of the android.view.Surface object in Java,21* and can be converted both ways. Depending on the consumer, images22* submitted to ANativeWindow can be shown on the display or sent to23* other consumers, such as video encoders.24* @{25*/2627/**28* @file native_window.h29* @brief API for accessing a native window.30*/3132#ifndef ANDROID_NATIVE_WINDOW_H33#define ANDROID_NATIVE_WINDOW_H3435#include <stdint.h>36#include <sys/cdefs.h>3738#include <android/data_space.h>39#include <android/hardware_buffer.h>40#include <android/rect.h>4142#ifdef __cplusplus43extern "C" {44#endif4546/**47* Legacy window pixel format names, kept for backwards compatibility.48* New code and APIs should use AHARDWAREBUFFER_FORMAT_*.49*/50enum ANativeWindow_LegacyFormat {51// NOTE: these values must match the values from graphics/common/x.x/types.hal5253/** Red: 8 bits, Green: 8 bits, Blue: 8 bits, Alpha: 8 bits. **/54WINDOW_FORMAT_RGBA_8888 = AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM,55/** Red: 8 bits, Green: 8 bits, Blue: 8 bits, Unused: 8 bits. **/56WINDOW_FORMAT_RGBX_8888 = AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM,57/** Red: 5 bits, Green: 6 bits, Blue: 5 bits. **/58WINDOW_FORMAT_RGB_565 = AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM,59};6061/**62* Transforms that can be applied to buffers as they are displayed to a window.63*64* Supported transforms are any combination of horizontal mirror, vertical65* mirror, and clockwise 90 degree rotation, in that order. Rotations of 18066* and 270 degrees are made up of those basic transforms.67*/68enum ANativeWindowTransform {69ANATIVEWINDOW_TRANSFORM_IDENTITY = 0x00,70ANATIVEWINDOW_TRANSFORM_MIRROR_HORIZONTAL = 0x01,71ANATIVEWINDOW_TRANSFORM_MIRROR_VERTICAL = 0x02,72ANATIVEWINDOW_TRANSFORM_ROTATE_90 = 0x04,7374ANATIVEWINDOW_TRANSFORM_ROTATE_180 = ANATIVEWINDOW_TRANSFORM_MIRROR_HORIZONTAL |75ANATIVEWINDOW_TRANSFORM_MIRROR_VERTICAL,76ANATIVEWINDOW_TRANSFORM_ROTATE_270 = ANATIVEWINDOW_TRANSFORM_ROTATE_180 |77ANATIVEWINDOW_TRANSFORM_ROTATE_90,78};7980struct ANativeWindow;81/**82* Opaque type that provides access to a native window.83*84* A pointer can be obtained using {@link ANativeWindow_fromSurface()}.85*/86typedef struct ANativeWindow ANativeWindow;8788/**89* Struct that represents a windows buffer.90*91* A pointer can be obtained using {@link ANativeWindow_lock()}.92*/93typedef struct ANativeWindow_Buffer {94/// The number of pixels that are shown horizontally.95int32_t width;9697/// The number of pixels that are shown vertically.98int32_t height;99100/// The number of *pixels* that a line in the buffer takes in101/// memory. This may be >= width.102int32_t stride;103104/// The format of the buffer. One of AHardwareBuffer_Format.105int32_t format;106107/// The actual bits.108void* bits;109110/// Do not touch.111uint32_t reserved[6];112} ANativeWindow_Buffer;113114/**115* Acquire a reference on the given {@link ANativeWindow} object. This prevents the object116* from being deleted until the reference is removed.117*/118void ANativeWindow_acquire(ANativeWindow* window);119120/**121* Remove a reference that was previously acquired with {@link ANativeWindow_acquire()}.122*/123void ANativeWindow_release(ANativeWindow* window);124125/**126* Return the current width in pixels of the window surface.127*128* \return negative value on error.129*/130int32_t ANativeWindow_getWidth(ANativeWindow* window);131132/**133* Return the current height in pixels of the window surface.134*135* \return a negative value on error.136*/137int32_t ANativeWindow_getHeight(ANativeWindow* window);138139/**140* Return the current pixel format (AHARDWAREBUFFER_FORMAT_*) of the window surface.141*142* \return a negative value on error.143*/144int32_t ANativeWindow_getFormat(ANativeWindow* window);145146/**147* Change the format and size of the window buffers.148*149* The width and height control the number of pixels in the buffers, not the150* dimensions of the window on screen. If these are different than the151* window's physical size, then its buffer will be scaled to match that size152* when compositing it to the screen. The width and height must be either both zero153* or both non-zero.154*155* For all of these parameters, if 0 is supplied then the window's base156* value will come back in force.157*158* \param width width of the buffers in pixels.159* \param height height of the buffers in pixels.160* \param format one of the AHardwareBuffer_Format constants.161* \return 0 for success, or a negative value on error.162*/163int32_t ANativeWindow_setBuffersGeometry(ANativeWindow* window,164int32_t width, int32_t height, int32_t format);165166/**167* Lock the window's next drawing surface for writing.168* inOutDirtyBounds is used as an in/out parameter, upon entering the169* function, it contains the dirty region, that is, the region the caller170* intends to redraw. When the function returns, inOutDirtyBounds is updated171* with the actual area the caller needs to redraw -- this region is often172* extended by {@link ANativeWindow_lock}.173*174* \return 0 for success, or a negative value on error.175*/176int32_t ANativeWindow_lock(ANativeWindow* window, ANativeWindow_Buffer* outBuffer,177ARect* inOutDirtyBounds);178179/**180* Unlock the window's drawing surface after previously locking it,181* posting the new buffer to the display.182*183* \return 0 for success, or a negative value on error.184*/185int32_t ANativeWindow_unlockAndPost(ANativeWindow* window);186187#if __ANDROID_API__ >= 26188189/**190* Set a transform that will be applied to future buffers posted to the window.191*192* Available since API level 26.193*194* \param transform combination of {@link ANativeWindowTransform} flags195* \return 0 for success, or -EINVAL if \p transform is invalid196*/197int32_t ANativeWindow_setBuffersTransform(ANativeWindow* window, int32_t transform) __INTRODUCED_IN(26);198199#endif // __ANDROID_API__ >= 26200201#if __ANDROID_API__ >= 28202203/**204* All buffers queued after this call will be associated with the dataSpace205* parameter specified.206*207* dataSpace specifies additional information about the buffer.208* For example, it can be used to convey the color space of the image data in209* the buffer, or it can be used to indicate that the buffers contain depth210* measurement data instead of color images. The default dataSpace is 0,211* ADATASPACE_UNKNOWN, unless it has been overridden by the producer.212*213* Available since API level 28.214*215* \param dataSpace data space of all buffers queued after this call.216* \return 0 for success, -EINVAL if window is invalid or the dataspace is not217* supported.218*/219int32_t ANativeWindow_setBuffersDataSpace(ANativeWindow* window, int32_t dataSpace) __INTRODUCED_IN(28);220221/**222* Get the dataspace of the buffers in window.223*224* Available since API level 28.225*226* \return the dataspace of buffers in window, ADATASPACE_UNKNOWN is returned if227* dataspace is unknown, or -EINVAL if window is invalid.228*/229int32_t ANativeWindow_getBuffersDataSpace(ANativeWindow* window) __INTRODUCED_IN(28);230231#endif // __ANDROID_API__ >= 28232233#if __ANDROID_API__ >= 30234235/** Compatibility value for ANativeWindow_setFrameRate. */236enum ANativeWindow_FrameRateCompatibility {237/**238* There are no inherent restrictions on the frame rate of this window. When239* the system selects a frame rate other than what the app requested, the240* app will be able to run at the system frame rate without requiring pull241* down. This value should be used when displaying game content, UIs, and242* anything that isn't video.243*/244ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT = 0,245/**246* This window is being used to display content with an inherently fixed247* frame rate, e.g.\ a video that has a specific frame rate. When the system248* selects a frame rate other than what the app requested, the app will need249* to do pull down or use some other technique to adapt to the system's250* frame rate. The user experience is likely to be worse (e.g. more frame251* stuttering) than it would be if the system had chosen the app's requested252* frame rate. This value should be used for video content.253*/254ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE = 1255};256257/**258* Sets the intended frame rate for this window.259*260* On devices that are capable of running the display at different refresh261* rates, the system may choose a display refresh rate to better match this262* window's frame rate. Usage of this API won't introduce frame rate throttling,263* or affect other aspects of the application's frame production264* pipeline. However, because the system may change the display refresh rate,265* calls to this function may result in changes to Choreographer callback266* timings, and changes to the time interval at which the system releases267* buffers back to the application.268*269* Note that this only has an effect for windows presented on the display. If270* this ANativeWindow is consumed by something other than the system compositor,271* e.g. a media codec, this call has no effect.272*273* Available since API level 30.274*275* \param frameRate The intended frame rate of this window, in frames per276* second. 0 is a special value that indicates the app will accept the system's277* choice for the display frame rate, which is the default behavior if this278* function isn't called. The frameRate param does <em>not</em> need to be a279* valid refresh rate for this device's display - e.g., it's fine to pass 30fps280* to a device that can only run the display at 60fps.281*282* \param compatibility The frame rate compatibility of this window. The283* compatibility value may influence the system's choice of display refresh284* rate. See the ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_* values for more info.285*286* \return 0 for success, -EINVAL if the window, frame rate, or compatibility287* value are invalid.288*/289int32_t ANativeWindow_setFrameRate(ANativeWindow* window, float frameRate, int8_t compatibility)290__INTRODUCED_IN(30);291292/**293* Provides a hint to the window that buffers should be preallocated ahead of294* time. Note that the window implementation is not guaranteed to preallocate295* any buffers, for instance if an implementation disallows allocation of new296* buffers, or if there is insufficient memory in the system to preallocate297* additional buffers298*299* Available since API level 30.300*/301void ANativeWindow_tryAllocateBuffers(ANativeWindow* window);302303#endif // __ANDROID_API__ >= 30304305#ifdef __cplusplus306};307#endif308309#endif // ANDROID_NATIVE_WINDOW_H310311/** @} */312313314