1/* 2 * Copyright © 2021, Google Inc. 3 * Copyright (C) 2021, GlobalLogic Ukraine 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * and/or sell copies of the Software, and to permit persons to whom the 10 * Software is furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice (including the next 13 * paragraph) shall be included in all copies or substantial portions of the 14 * Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 22 * IN THE SOFTWARE. 23 */ 24 25#ifndef EGL_ANDROID_INCLUDED 26#define EGL_ANDROID_INCLUDED 27 28#include <errno.h> 29#include <stdbool.h> 30#include <stdint.h> 31 32#include <GL/internal/dri_interface.h> 33 34#include "egl_dri2.h" 35 36#if ANDROID_API_LEVEL < 26 37/* Shim layer to map ANativeWindow_* onto the legacy system internal APIs */ 38enum ANativeWindowQuery { 39 ANATIVEWINDOW_QUERY_MIN_UNDEQUEUED_BUFFERS = 3, 40 ANATIVEWINDOW_QUERY_DEFAULT_WIDTH = 6, 41 ANATIVEWINDOW_QUERY_DEFAULT_HEIGHT = 7, 42}; 43 44static inline void 45ANativeWindow_acquire(struct ANativeWindow *window) 46{ 47 window->common.incRef(&window->common); 48} 49 50static inline void 51ANativeWindow_release(struct ANativeWindow *window) 52{ 53 window->common.decRef(&window->common); 54} 55 56static inline int32_t 57ANativeWindow_getFormat(struct ANativeWindow *window) 58{ 59 int32_t format = 0; 60 int res = window->query(window, NATIVE_WINDOW_FORMAT, &format); 61 return res < 0 ? res : format; 62} 63 64static inline int 65ANativeWindow_dequeueBuffer(struct ANativeWindow *window, 66 struct ANativeWindowBuffer **buffer, 67 int *fenceFd) 68{ 69 return window->dequeueBuffer(window, buffer, fenceFd); 70} 71 72static inline int 73ANativeWindow_queueBuffer(struct ANativeWindow *window, 74 struct ANativeWindowBuffer *buffer, 75 int fenceFd) 76{ 77 return window->queueBuffer(window, buffer, fenceFd); 78} 79 80static inline int 81ANativeWindow_cancelBuffer(struct ANativeWindow *window, 82 struct ANativeWindowBuffer *buffer, 83 int fenceFd) 84{ 85 return window->cancelBuffer(window, buffer, fenceFd); 86} 87 88static inline int 89ANativeWindow_setUsage(struct ANativeWindow *window, uint64_t usage) 90{ 91 return native_window_set_usage(window, usage); 92} 93 94static inline int 95ANativeWindow_setSharedBufferMode(struct ANativeWindow *window, 96 bool sharedBufferMode) 97{ 98 return native_window_set_shared_buffer_mode(window, sharedBufferMode); 99} 100 101static inline int 102ANativeWindow_setSwapInterval(struct ANativeWindow *window, int interval) 103{ 104 return window->setSwapInterval(window, interval); 105} 106 107static inline int 108ANativeWindow_query(const struct ANativeWindow *window, 109 enum ANativeWindowQuery what, 110 int *value) 111{ 112 switch (what) { 113 case ANATIVEWINDOW_QUERY_MIN_UNDEQUEUED_BUFFERS: 114 case ANATIVEWINDOW_QUERY_DEFAULT_WIDTH: 115 case ANATIVEWINDOW_QUERY_DEFAULT_HEIGHT: 116 break; 117 default: 118 return -EINVAL; 119 } 120 return window->query(window, (int)what, value); 121} 122#endif // ANDROID_API_LEVEL < 26 123 124struct buffer_info { 125 int width; 126 int height; 127 uint32_t drm_fourcc; 128 int num_planes; 129 int fds[4]; 130 uint64_t modifier; 131 int offsets[4]; 132 int pitches[4]; 133 enum __DRIYUVColorSpace yuv_color_space; 134 enum __DRISampleRange sample_range; 135 enum __DRIChromaSiting horizontal_siting; 136 enum __DRIChromaSiting vertical_siting; 137}; 138 139#ifdef USE_IMAPPER4_METADATA_API 140#ifdef __cplusplus 141extern "C" { 142#endif 143extern int 144mapper_metadata_get_buffer_info(struct ANativeWindowBuffer *buf, 145 struct buffer_info *out_buf_info); 146#ifdef __cplusplus 147} 148#endif 149#else 150static inline int 151mapper_metadata_get_buffer_info(struct ANativeWindowBuffer *buf, 152 struct buffer_info *out_buf_info) { 153 return -ENOTSUP; 154} 155#endif /* USE_IMAPPER4_METADATA_API */ 156 157#endif /* EGL_ANDROID_INCLUDED */ 158