1 /*
2  * Copyright (c) 2014-2016, NVIDIA CORPORATION. All rights reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20  * DEALINGS IN THE SOFTWARE.
21  */
22 
23 #ifndef WAYLAND_EGLSTREAM_SERVER_H
24 #define WAYLAND_EGLSTREAM_SERVER_H
25 
26 #include <wayland-server-protocol.h>
27 #include <EGL/egl.h>
28 #include <EGL/eglext.h>
29 #include "wayland-eglhandle.h"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 /*
36  * Forward declarations
37  */
38 struct wl_eglstream_display;
39 struct wl_eglstream;
40 
41 
42 /*
43  * wl_eglstream_display_bind()
44  *
45  * Creates and initializes a wl_eglstream_display connection associated to the
46  * given wl_display and EGLDisplay.
47  */
48 EGLBoolean
49 wl_eglstream_display_bind(WlEglPlatformData *data,
50                           struct wl_display *wlDisplay,
51                           EGLDisplay eglDisplay,
52                           const char *exts);
53 
54 /*
55  * wl_eglstream_display_unbind()
56  *
57  * Destroys the given wl_eglstream_display connection result of a previous
58  * wl_eglstream_display_bind() call.
59  */
60 void wl_eglstream_display_unbind(struct wl_eglstream_display *wlStreamDpy);
61 
62 /*
63  * wl_eglstream_display_get()
64  *
65  * Given an EGL display, returns its associated wl_eglstream_display connection.
66  */
67 struct wl_eglstream_display* wl_eglstream_display_get(EGLDisplay eglDisplay);
68 
69 /*
70  * wl_eglstream_display_get_stream()
71  *
72  * Given a generic wl_resource, returns its associated wl_eglstream.
73  */
74 struct wl_eglstream*
75 wl_eglstream_display_get_stream(struct wl_eglstream_display *wlStreamDpy,
76                                 struct wl_resource *resource);
77 
78 
79 /* wl_eglstream_display definition */
80 struct wl_eglstream_display {
81     WlEglPlatformData *data;
82 
83     struct wl_global  *global;
84     struct wl_display *wlDisplay;
85 
86     EGLDisplay eglDisplay;
87     struct {
88         int stream_attrib           : 1;
89         int stream_cross_process_fd : 1;
90         int stream_remote           : 1;
91         int stream_socket           : 1;
92         int stream_socket_inet      : 1;
93         int stream_socket_unix      : 1;
94         int stream_origin           : 1;
95     } exts;
96 
97     struct {
98         const char       *device_name;
99         struct wl_global *global;
100     } *drm;
101 
102     int caps_override               : 1;
103     int supported_caps;
104 
105     struct wl_buffer_interface wl_eglstream_interface;
106 
107     struct wl_list link;
108 };
109 
110 /* wl_eglstream definition */
111 struct wl_eglstream {
112     struct wl_resource          *resource;
113     struct wl_eglstream_display *wlStreamDpy;
114 
115     int width, height;
116 
117     EGLBoolean   fromFd;
118     EGLBoolean   isInet;
119     int          handle;
120     EGLStreamKHR eglStream;
121 
122     /*
123      * The following attribute encodes the default value for a
124      * stream's image inversion relative to wayland protocol
125      * convention. Vulkan apps will be set to 'true', while
126      * OpenGL apps will be set to 'false'.
127      * NOTE: EGL_NV_stream_origin is the authorative source of
128      * truth regarding a stream's frame orientation and should be
129      * queried for an accurate value. The following attribute is a
130      * 'best guess' fallback mechanism which should only be used
131      * when a query to EGL_NV_stream_origin fails.
132      */
133     EGLBoolean yInverted;
134 };
135 
136 #ifdef __cplusplus
137 }
138 #endif
139 
140 #endif
141