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