1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  *
4  * Based on platform_android, which has
5  *
6  * Copyright © 2021, Google Inc.
7  * Copyright (C) 2021, GlobalLogic Ukraine
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a
10  * copy of this software and associated documentation files (the "Software"),
11  * to deal in the Software without restriction, including without limitation
12  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13  * and/or sell copies of the Software, and to permit persons to whom the
14  * Software is furnished to do so, subject to the following conditions:
15  *
16  * The above copyright notice and this permission notice (including the next
17  * paragraph) shall be included in all copies or substantial portions of the
18  * Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
23  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
26  * IN THE SOFTWARE.
27  */
28 
29 #ifndef EGL_OHOS_INCLUDED
30 #define EGL_OHOS_INCLUDED
31 
32 #include <errno.h>
33 #include <stdbool.h>
34 #include <stdint.h>
35 
36 #include <GL/internal/dri_interface.h>
37 
38 #include "egl_dri2.h"
39 #include "display_type.h"
40 #include "window.h"
41 
42 #define ANativeWindow NativeWindow
43 #define ANativeWindowBuffer NativeWindowBuffer
44 static inline void
ANativeWindow_acquire(struct ANativeWindow *window)45 ANativeWindow_acquire(struct ANativeWindow *window)
46 {
47    NativeObjectReference(window);
48 }
49 
50 static inline void
ANativeWindow_release(struct ANativeWindow *window)51 ANativeWindow_release(struct ANativeWindow *window)
52 {
53    NativeObjectReference(window);
54 }
55 
56 static inline int32_t
ANativeWindow_getFormat(struct ANativeWindow *window)57 ANativeWindow_getFormat(struct ANativeWindow *window)
58 {
59    int32_t format = PIXEL_FMT_RGBA_8888;
60    int32_t res = NativeWindowHandleOpt(window, GET_FORMAT, &format);
61    return res == 0 ? format : res;
62 }
63 
64 static inline int32_t
ANativeWindow_dequeueBuffer(struct ANativeWindow *window, struct ANativeWindowBuffer **buffer, int *fenceFd)65 ANativeWindow_dequeueBuffer(struct ANativeWindow *window,
66                             struct ANativeWindowBuffer **buffer,
67                             int *fenceFd)
68 {
69    return NativeWindowRequestBuffer(window, buffer, fenceFd);
70 }
71 
72 static inline int32_t
ANativeWindow_queueBuffer(struct ANativeWindow *window, struct ANativeWindowBuffer *buffer, int fenceFd)73 ANativeWindow_queueBuffer(struct ANativeWindow *window,
74                           struct ANativeWindowBuffer *buffer,
75                           int fenceFd)
76 {
77    struct Region dirty;
78    dirty.rectNumber = 0;
79    dirty.rects = NULL;
80    return NativeWindowFlushBuffer(window, buffer, fenceFd, dirty);
81 }
82 
83 static inline int32_t
ANativeWindow_cancelBuffer(struct ANativeWindow *window, struct ANativeWindowBuffer *buffer, int fenceFd)84 ANativeWindow_cancelBuffer(struct ANativeWindow *window,
85                            struct ANativeWindowBuffer *buffer,
86                            int fenceFd)
87 {
88    return NativeWindowCancelBuffer(window, buffer);
89 }
90 
91 static inline int32_t
ANativeWindow_setUsage(struct ANativeWindow *window, uint64_t usage)92 ANativeWindow_setUsage(struct ANativeWindow *window, uint64_t usage)
93 {
94    return NativeWindowHandleOpt(window, SET_USAGE, usage);
95 }
96 
97 struct buffer_info {
98    int width;
99    int height;
100    uint32_t drm_fourcc;
101    int num_planes;
102    int fds[4];
103    uint64_t modifier;
104    int offsets[4];
105    int pitches[4];
106    enum __DRIYUVColorSpace yuv_color_space;
107    enum __DRISampleRange sample_range;
108    enum __DRIChromaSiting horizontal_siting;
109    enum __DRIChromaSiting vertical_siting;
110 };
111 
112 #endif /* EGL_OHOS_INCLUDED */
113