| 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 "mesa_interface.h" |
| 33 |
#include "egl_dri2.h" |
| 34 |
|
| 35 |
#if ANDROID_API_LEVEL < 26 |
| 36 |
/* Shim layer to map ANativeWindow_* onto the legacy system internal APIs */ |
| 37 |
enum ANativeWindowQuery { |
| 38 |
ANATIVEWINDOW_QUERY_MIN_UNDEQUEUED_BUFFERS = 3, |
| 39 |
ANATIVEWINDOW_QUERY_DEFAULT_WIDTH = 6, |
| 40 |
ANATIVEWINDOW_QUERY_DEFAULT_HEIGHT = 7, |
| 41 |
}; |
| 42 |
|
| 43 |
static inline void |
| 44 |
ANativeWindow_acquire(struct ANativeWindow *window) |
| 45 |
{ |
| 46 |
window->common.incRef(&window->common); |
| 47 |
} |
| 48 |
|
| 49 |
static inline void |
| 50 |
ANativeWindow_release(struct ANativeWindow *window) |
| 51 |
{ |
| 52 |
window->common.decRef(&window->common); |
| 53 |
} |
| 54 |
|
| 55 |
static inline int32_t |
| 56 |
ANativeWindow_getFormat(struct ANativeWindow *window) |
| 57 |
{ |
| 58 |
int32_t format = 0; |
| 59 |
int res = window->query(window, NATIVE_WINDOW_FORMAT, &format); |
| 60 |
return res < 0 ? res : format; |
| 61 |
} |
| 62 |
|
| 63 |
static inline int |
| 64 |
ANativeWindow_dequeueBuffer(struct ANativeWindow *window, |
| 65 |
struct ANativeWindowBuffer **buffer, int *fenceFd) |
| 66 |
{ |
| 67 |
return window->dequeueBuffer(window, buffer, fenceFd); |
| 68 |
} |
| 69 |
|
| 70 |
static inline int |
| 71 |
ANativeWindow_queueBuffer(struct ANativeWindow *window, |
| 72 |
struct ANativeWindowBuffer *buffer, int fenceFd) |
| 73 |
{ |
| 74 |
return window->queueBuffer(window, buffer, fenceFd); |
| 75 |
} |
| 76 |
|
| 77 |
static inline int |
| 78 |
ANativeWindow_cancelBuffer(struct ANativeWindow *window, |
| 79 |
struct ANativeWindowBuffer *buffer, int fenceFd) |
| 80 |
{ |
| 81 |
return window->cancelBuffer(window, buffer, fenceFd); |
| 82 |
} |
| 83 |
|
| 84 |
static inline int |
| 85 |
ANativeWindow_setUsage(struct ANativeWindow *window, uint64_t usage) |
| 86 |
{ |
| 87 |
return native_window_set_usage(window, usage); |
| 88 |
} |
| 89 |
|
| 90 |
static inline int |
| 91 |
ANativeWindow_setSharedBufferMode(struct ANativeWindow *window, |
| 92 |
bool sharedBufferMode) |
| 93 |
{ |
| 94 |
return native_window_set_shared_buffer_mode(window, sharedBufferMode); |
| 95 |
} |
| 96 |
|
| 97 |
static inline int |
| 98 |
ANativeWindow_setSwapInterval(struct ANativeWindow *window, int interval) |
| 99 |
{ |
| 100 |
return window->setSwapInterval(window, interval); |
| 101 |
} |
| 102 |
|
| 103 |
static inline int |
| 104 |
ANativeWindow_query(const struct ANativeWindow *window, |
| 105 |
enum ANativeWindowQuery what, int *value) |
| 106 |
{ |
| 107 |
switch (what) { |
| 108 |
case ANATIVEWINDOW_QUERY_MIN_UNDEQUEUED_BUFFERS: |
| 109 |
case ANATIVEWINDOW_QUERY_DEFAULT_WIDTH: |
| 110 |
case ANATIVEWINDOW_QUERY_DEFAULT_HEIGHT: |
| 111 |
break; |
| 112 |
default: |
| 113 |
return -EINVAL; |
| 114 |
} |
| 115 |
return window->query(window, (int)what, value); |
| 116 |
} |
| 117 |
#endif // ANDROID_API_LEVEL < 26 |
| 118 |
|
| 119 |
#endif /* EGL_ANDROID_INCLUDED */ |