Path: blob/21.2-virgl/src/egl/drivers/dri2/platform_android.h
4570 views
/*1* Copyright © 2021, Google Inc.2* Copyright (C) 2021, GlobalLogic Ukraine3*4* Permission is hereby granted, free of charge, to any person obtaining a5* copy of this software and associated documentation files (the "Software"),6* to deal in the Software without restriction, including without limitation7* the rights to use, copy, modify, merge, publish, distribute, sublicense,8* and/or sell copies of the Software, and to permit persons to whom the9* Software is furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice (including the next12* paragraph) shall be included in all copies or substantial portions of the13* Software.14*15* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL18* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER19* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING20* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS21* IN THE SOFTWARE.22*/2324#ifndef EGL_ANDROID_INCLUDED25#define EGL_ANDROID_INCLUDED2627#include <errno.h>28#include <stdbool.h>29#include <stdint.h>3031#include <GL/internal/dri_interface.h>3233#include "egl_dri2.h"3435#if ANDROID_API_LEVEL < 2636/* Shim layer to map ANativeWindow_* onto the legacy system internal APIs */37enum ANativeWindowQuery {38ANATIVEWINDOW_QUERY_MIN_UNDEQUEUED_BUFFERS = 3,39ANATIVEWINDOW_QUERY_DEFAULT_WIDTH = 6,40ANATIVEWINDOW_QUERY_DEFAULT_HEIGHT = 7,41};4243static inline void44ANativeWindow_acquire(struct ANativeWindow *window)45{46window->common.incRef(&window->common);47}4849static inline void50ANativeWindow_release(struct ANativeWindow *window)51{52window->common.decRef(&window->common);53}5455static inline int32_t56ANativeWindow_getFormat(struct ANativeWindow *window)57{58int32_t format = 0;59int res = window->query(window, NATIVE_WINDOW_FORMAT, &format);60return res < 0 ? res : format;61}6263static inline int64ANativeWindow_dequeueBuffer(struct ANativeWindow *window,65struct ANativeWindowBuffer **buffer,66int *fenceFd)67{68return window->dequeueBuffer(window, buffer, fenceFd);69}7071static inline int72ANativeWindow_queueBuffer(struct ANativeWindow *window,73struct ANativeWindowBuffer *buffer,74int fenceFd)75{76return window->queueBuffer(window, buffer, fenceFd);77}7879static inline int80ANativeWindow_cancelBuffer(struct ANativeWindow *window,81struct ANativeWindowBuffer *buffer,82int fenceFd)83{84return window->cancelBuffer(window, buffer, fenceFd);85}8687static inline int88ANativeWindow_setUsage(struct ANativeWindow *window, uint64_t usage)89{90return native_window_set_usage(window, usage);91}9293static inline int94ANativeWindow_setSharedBufferMode(struct ANativeWindow *window,95bool sharedBufferMode)96{97return native_window_set_shared_buffer_mode(window, sharedBufferMode);98}99100static inline int101ANativeWindow_setSwapInterval(struct ANativeWindow *window, int interval)102{103return window->setSwapInterval(window, interval);104}105106static inline int107ANativeWindow_query(const struct ANativeWindow *window,108enum ANativeWindowQuery what,109int *value)110{111switch (what) {112case ANATIVEWINDOW_QUERY_MIN_UNDEQUEUED_BUFFERS:113case ANATIVEWINDOW_QUERY_DEFAULT_WIDTH:114case ANATIVEWINDOW_QUERY_DEFAULT_HEIGHT:115break;116default:117return -EINVAL;118}119return window->query(window, (int)what, value);120}121#endif // ANDROID_API_LEVEL < 26122123struct buffer_info {124int width;125int height;126uint32_t drm_fourcc;127int num_planes;128int fds[4];129uint64_t modifier;130int offsets[4];131int pitches[4];132enum __DRIYUVColorSpace yuv_color_space;133enum __DRISampleRange sample_range;134enum __DRIChromaSiting horizontal_siting;135enum __DRIChromaSiting vertical_siting;136};137138#ifdef USE_IMAPPER4_METADATA_API139#ifdef __cplusplus140extern "C" {141#endif142extern int143mapper_metadata_get_buffer_info(struct ANativeWindowBuffer *buf,144struct buffer_info *out_buf_info);145#ifdef __cplusplus146}147#endif148#else149static inline int150mapper_metadata_get_buffer_info(struct ANativeWindowBuffer *buf,151struct buffer_info *out_buf_info) {152return -ENOTSUP;153}154#endif /* USE_IMAPPER4_METADATA_API */155156#endif /* EGL_ANDROID_INCLUDED */157158159