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