Path: blob/21.2-virgl/include/android_stub/vndk/window.h
4547 views
/*1* Copyright (C) 2017 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#ifndef ANDROID_VNDK_NATIVEWINDOW_ANATIVEWINDOW_H17#define ANDROID_VNDK_NATIVEWINDOW_ANATIVEWINDOW_H1819#include <nativebase/nativebase.h>2021// vndk is a superset of the NDK22#include <android/native_window.h>232425__BEGIN_DECLS2627/*28* Convert this ANativeWindowBuffer into a AHardwareBuffer29*/30AHardwareBuffer* ANativeWindowBuffer_getHardwareBuffer(ANativeWindowBuffer* anwb);3132/*****************************************************************************/3334/*35* Stores a value into one of the 4 available slots36* Retrieve the value with ANativeWindow_OemStorageGet()37*38* slot: 0 to 339*40* Returns 0 on success or -errno on error.41*/42int ANativeWindow_OemStorageSet(ANativeWindow* window, uint32_t slot, intptr_t value);434445/*46* Retrieves a value from one of the 4 available slots47* By default the returned value is 0 if it wasn't set by ANativeWindow_OemStorageSet()48*49* slot: 0 to 350*51* Returns 0 on success or -errno on error.52*/53int ANativeWindow_OemStorageGet(ANativeWindow* window, uint32_t slot, intptr_t* value);545556/*57* Set the swap interval for this surface.58*59* Returns 0 on success or -errno on error.60*/61int ANativeWindow_setSwapInterval(ANativeWindow* window, int interval);626364/*65* queries that can be used with ANativeWindow_query() and ANativeWindow_queryf()66*/67enum ANativeWindowQuery {68/* The minimum number of buffers that must remain un-dequeued after a buffer69* has been queued. This value applies only if set_buffer_count was used to70* override the number of buffers and if a buffer has since been queued.71* Users of the set_buffer_count ANativeWindow method should query this72* value before calling set_buffer_count. If it is necessary to have N73* buffers simultaneously dequeued as part of the steady-state operation,74* and this query returns M then N+M buffers should be requested via75* native_window_set_buffer_count.76*77* Note that this value does NOT apply until a single buffer has been78* queued. In particular this means that it is possible to:79*80* 1. Query M = min undequeued buffers81* 2. Set the buffer count to N + M82* 3. Dequeue all N + M buffers83* 4. Cancel M buffers84* 5. Queue, dequeue, queue, dequeue, ad infinitum85*/86ANATIVEWINDOW_QUERY_MIN_UNDEQUEUED_BUFFERS = 3,8788/*89* Default width of ANativeWindow buffers, these are the90* dimensions of the window buffers irrespective of the91* ANativeWindow_setBuffersDimensions() call and match the native window92* size.93*/94ANATIVEWINDOW_QUERY_DEFAULT_WIDTH = 6,95ANATIVEWINDOW_QUERY_DEFAULT_HEIGHT = 7,9697/*98* transformation that will most-likely be applied to buffers. This is only99* a hint, the actual transformation applied might be different.100*101* INTENDED USE:102*103* The transform hint can be used by a producer, for instance the GLES104* driver, to pre-rotate the rendering such that the final transformation105* in the composer is identity. This can be very useful when used in106* conjunction with the h/w composer HAL, in situations where it107* cannot handle arbitrary rotations.108*109* 1. Before dequeuing a buffer, the GL driver (or any other ANW client)110* queries the ANW for NATIVE_WINDOW_TRANSFORM_HINT.111*112* 2. The GL driver overrides the width and height of the ANW to113* account for NATIVE_WINDOW_TRANSFORM_HINT. This is done by querying114* NATIVE_WINDOW_DEFAULT_{WIDTH | HEIGHT}, swapping the dimensions115* according to NATIVE_WINDOW_TRANSFORM_HINT and calling116* native_window_set_buffers_dimensions().117*118* 3. The GL driver dequeues a buffer of the new pre-rotated size.119*120* 4. The GL driver renders to the buffer such that the image is121* already transformed, that is applying NATIVE_WINDOW_TRANSFORM_HINT122* to the rendering.123*124* 5. The GL driver calls native_window_set_transform to apply125* inverse transformation to the buffer it just rendered.126* In order to do this, the GL driver needs127* to calculate the inverse of NATIVE_WINDOW_TRANSFORM_HINT, this is128* done easily:129*130* int hintTransform, inverseTransform;131* query(..., NATIVE_WINDOW_TRANSFORM_HINT, &hintTransform);132* inverseTransform = hintTransform;133* if (hintTransform & HAL_TRANSFORM_ROT_90)134* inverseTransform ^= HAL_TRANSFORM_ROT_180;135*136*137* 6. The GL driver queues the pre-transformed buffer.138*139* 7. The composer combines the buffer transform with the display140* transform. If the buffer transform happens to cancel out the141* display transform then no rotation is needed.142*143*/144ANATIVEWINDOW_QUERY_TRANSFORM_HINT = 8,145146/*147* Returns the age of the contents of the most recently dequeued buffer as148* the number of frames that have elapsed since it was last queued. For149* example, if the window is double-buffered, the age of any given buffer in150* steady state will be 2. If the dequeued buffer has never been queued, its151* age will be 0.152*/153ANATIVEWINDOW_QUERY_BUFFER_AGE = 13,154155/* min swap interval supported by this compositor */156ANATIVEWINDOW_QUERY_MIN_SWAP_INTERVAL = 0x10000,157158/* max swap interval supported by this compositor */159ANATIVEWINDOW_QUERY_MAX_SWAP_INTERVAL = 0x10001,160161/* horizontal resolution in DPI. value is float, use queryf() */162ANATIVEWINDOW_QUERY_XDPI = 0x10002,163164/* vertical resolution in DPI. value is float, use queryf() */165ANATIVEWINDOW_QUERY_YDPI = 0x10003,166};167168typedef enum ANativeWindowQuery ANativeWindowQuery;169170/*171* hook used to retrieve information about the native window.172*173* Returns 0 on success or -errno on error.174*/175int ANativeWindow_query(const ANativeWindow* window, ANativeWindowQuery query, int* value);176int ANativeWindow_queryf(const ANativeWindow* window, ANativeWindowQuery query, float* value);177178179/*180* Hook called by EGL to acquire a buffer. This call may block if no181* buffers are available.182*183* The window holds a reference to the buffer between dequeueBuffer and184* either queueBuffer or cancelBuffer, so clients only need their own185* reference if they might use the buffer after queueing or canceling it.186* Holding a reference to a buffer after queueing or canceling it is only187* allowed if a specific buffer count has been set.188*189* The libsync fence file descriptor returned in the int pointed to by the190* fenceFd argument will refer to the fence that must signal before the191* dequeued buffer may be written to. A value of -1 indicates that the192* caller may access the buffer immediately without waiting on a fence. If193* a valid file descriptor is returned (i.e. any value except -1) then the194* caller is responsible for closing the file descriptor.195*196* Returns 0 on success or -errno on error.197*/198int ANativeWindow_dequeueBuffer(ANativeWindow* window, ANativeWindowBuffer** buffer, int* fenceFd);199200201/*202* Hook called by EGL when modifications to the render buffer are done.203* This unlocks and post the buffer.204*205* The window holds a reference to the buffer between dequeueBuffer and206* either queueBuffer or cancelBuffer, so clients only need their own207* reference if they might use the buffer after queueing or canceling it.208* Holding a reference to a buffer after queueing or canceling it is only209* allowed if a specific buffer count has been set.210*211* The fenceFd argument specifies a libsync fence file descriptor for a212* fence that must signal before the buffer can be accessed. If the buffer213* can be accessed immediately then a value of -1 should be used. The214* caller must not use the file descriptor after it is passed to215* queueBuffer, and the ANativeWindow implementation is responsible for216* closing it.217*218* Returns 0 on success or -errno on error.219*/220int ANativeWindow_queueBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer, int fenceFd);221222223/*224* Hook used to cancel a buffer that has been dequeued.225* No synchronization is performed between dequeue() and cancel(), so226* either external synchronization is needed, or these functions must be227* called from the same thread.228*229* The window holds a reference to the buffer between dequeueBuffer and230* either queueBuffer or cancelBuffer, so clients only need their own231* reference if they might use the buffer after queueing or canceling it.232* Holding a reference to a buffer after queueing or canceling it is only233* allowed if a specific buffer count has been set.234*235* The fenceFd argument specifies a libsync fence file decsriptor for a236* fence that must signal before the buffer can be accessed. If the buffer237* can be accessed immediately then a value of -1 should be used.238*239* Note that if the client has not waited on the fence that was returned240* from dequeueBuffer, that same fence should be passed to cancelBuffer to241* ensure that future uses of the buffer are preceded by a wait on that242* fence. The caller must not use the file descriptor after it is passed243* to cancelBuffer, and the ANativeWindow implementation is responsible for244* closing it.245*246* Returns 0 on success or -errno on error.247*/248int ANativeWindow_cancelBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer, int fenceFd);249250/*251* Sets the intended usage flags for the next buffers.252*253* usage: one of AHARDWAREBUFFER_USAGE_* constant254*255* By default (if this function is never called), a usage of256* AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE | AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT257* is assumed.258*259* Calling this function will usually cause following buffers to be260* reallocated.261*/262int ANativeWindow_setUsage(ANativeWindow* window, uint64_t usage);263264265/*266* Sets the number of buffers associated with this native window.267*/268int ANativeWindow_setBufferCount(ANativeWindow* window, size_t bufferCount);269270271/*272* All buffers dequeued after this call will have the dimensions specified.273* In particular, all buffers will have a fixed-size, independent from the274* native-window size. They will be scaled according to the scaling mode275* (see native_window_set_scaling_mode) upon window composition.276*277* If w and h are 0, the normal behavior is restored. That is, dequeued buffers278* following this call will be sized to match the window's size.279*280* Calling this function will reset the window crop to a NULL value, which281* disables cropping of the buffers.282*/283int ANativeWindow_setBuffersDimensions(ANativeWindow* window, uint32_t w, uint32_t h);284285286/*287* All buffers dequeued after this call will have the format specified.288* format: one of AHARDWAREBUFFER_FORMAT_* constant289*290* If the specified format is 0, the default buffer format will be used.291*/292int ANativeWindow_setBuffersFormat(ANativeWindow* window, int format);293294295/*296* All buffers queued after this call will be associated with the timestamp in nanosecond297* parameter specified. If the timestamp is set to NATIVE_WINDOW_TIMESTAMP_AUTO298* (the default), timestamps will be generated automatically when queueBuffer is299* called. The timestamp is measured in nanoseconds, and is normally monotonically300* increasing. The timestamp should be unaffected by time-of-day adjustments,301* and for a camera should be strictly monotonic but for a media player may be302* reset when the position is set.303*/304int ANativeWindow_setBuffersTimestamp(ANativeWindow* window, int64_t timestamp);305306307/*308* Enable/disable shared buffer mode309*/310int ANativeWindow_setSharedBufferMode(ANativeWindow* window, bool sharedBufferMode);311312313/*314* Enable/disable auto refresh when in shared buffer mode315*/316int ANativeWindow_setAutoRefresh(ANativeWindow* window, bool autoRefresh);317318/*319* Enable/disable the auto prerotation at buffer allocation when the buffer size320* is driven by the consumer.321*322* When buffer size is driven by the consumer and the transform hint specifies323* a 90 or 270 degree rotation, if auto prerotation is enabled, the width and324* height used for dequeueBuffer will be additionally swapped.325*/326int ANativeWindow_setAutoPrerotation(ANativeWindow* window, bool autoPrerotation);327328/*****************************************************************************/329330__END_DECLS331332#endif /* ANDROID_VNDK_NATIVEWINDOW_ANATIVEWINDOW_H */333334335