-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathwayland-eglsurface.h
206 lines (171 loc) · 7.48 KB
/
wayland-eglsurface.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*
* Copyright (c) 2014-2019, NVIDIA CORPORATION. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef WAYLAND_EGLSURFACE_H
#define WAYLAND_EGLSURFACE_H
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <pthread.h>
#include <wayland-client.h>
#include "wayland-egldisplay.h"
#include "wayland-eglutils.h"
#ifdef __cplusplus
extern "C" {
#endif
#define WL_EGL_STREAM_DAMAGE_BUFFER_N_FRAMES 3
#define WL_EGL_STREAM_DAMAGE_BUFFER_N_RECTS 32
typedef struct WlEglStreamImageRec {
/* Pointer back to the parent surface for use in Wayland callbacks */
struct WlEglSurfaceRec *surface;
/*
* Use an individual mutex to guard access to each image's data. This avoids
* sharing the surface lock between the app and buffer release event
* threads, resulting in simplified lock management and smaller critical
* sections.
*/
pthread_mutex_t mutex;
EGLImageKHR eglImage;
struct wl_buffer *buffer;
EGLBoolean attached;
struct wl_list acquiredLink;
} WlEglStreamImage;
typedef struct WlEglStreamDamageRec {
EGLuint64KHR frameNumber;
EGLint n_rects;
EGLint _padding;
EGLint rects[4 * WL_EGL_STREAM_DAMAGE_BUFFER_N_RECTS];
} WlEglStreamDamage;
typedef struct WlEglStreamDamageBufferRec {
volatile EGLint head;
volatile EGLint tail;
WlEglStreamDamage frames[WL_EGL_STREAM_DAMAGE_BUFFER_N_FRAMES];
} WlEglStreamDamageBuffer;
typedef struct WlEglSurfaceCtxRec {
EGLBoolean isOffscreen;
EGLSurface eglSurface;
EGLStreamKHR eglStream;
void *wlStreamResource;
EGLBoolean isAttached;
int useDamageThread;
pthread_t damageThreadId;
EGLSyncKHR damageThreadSync;
int damageThreadFlush;
int damageThreadShutdown;
EGLuint64KHR framesProduced;
EGLuint64KHR framesFinished;
EGLuint64KHR framesProcessed;
/*
* The double pointer is because of the need to allocate the data for each
* image slot separately to avoid clobbering the acquiredLink member
* whenever the streamImages arrary is resized with realloc().
*/
WlEglStreamImage **streamImages;
struct wl_list acquiredImages;
struct wl_buffer *currentBuffer;
uint32_t numStreamImages;
struct wl_list link;
WlEglStreamDamageBuffer damageBuffer;
} WlEglSurfaceCtx;
typedef struct WlEglSurfaceRec {
WlEglDisplay *wlEglDpy;
EGLConfig eglConfig;
EGLint *attribs;
EGLBoolean pendingSwapIntervalUpdate;
struct wl_egl_window *wlEglWin;
long int wlEglWinVer;
struct wl_surface *wlSurface;
int width, height;
int dx, dy;
WlEglSurfaceCtx ctx;
struct wl_list oldCtxList;
EGLint swapInterval;
EGLint fifoLength;
struct wl_callback *throttleCallback;
struct wl_event_queue *wlEventQueue;
/* Asynchronous wl_buffer.release event processing */
struct {
struct wl_event_queue *wlBufferEventQueue;
pthread_t bufferReleaseThreadId;
int bufferReleaseThreadPipe[2];
};
struct wl_list link;
EGLBoolean isSurfaceProducer;
/* The refCount is initialized to 1 during EGLSurface creation,
* gets incremented/decrementsd in wlEglSurfaceRef()/wlEglSurfaceUnref(),
* when we enter/exit from eglSwapBuffers().
*/
unsigned int refCount;
/*
* Set to EGL_TRUE before destroying the EGLSurface in eglDestroySurface().
*/
EGLBoolean isDestroyed;
/* The lock is used to serialize eglSwapBuffers()/eglDestroySurface(),
* Using wlExternalApiLock() for this requires that we release lock
* before dispatching frame sync events in wlEglWaitFrameSync().
*/
pthread_mutex_t mutexLock;
} WlEglSurface;
WL_EXPORT
EGLBoolean wlEglInitializeSurfaceExport(WlEglSurface *surface);
EGLSurface wlEglCreatePlatformWindowSurfaceHook(EGLDisplay dpy,
EGLConfig config,
void *nativeWin,
const EGLAttrib *attribs);
EGLSurface wlEglCreatePlatformPixmapSurfaceHook(EGLDisplay dpy,
EGLConfig config,
void *nativePixmap,
const EGLAttrib *attribs);
EGLSurface wlEglCreatePbufferSurfaceHook(EGLDisplay dpy,
EGLConfig config,
const EGLint *attribs);
EGLSurface wlEglCreateStreamProducerSurfaceHook(EGLDisplay dpy,
EGLConfig config,
EGLStreamKHR stream,
const EGLint *attribs);
EGLBoolean wlEglDestroySurfaceHook(EGLDisplay dpy, EGLSurface eglSurface);
EGLBoolean wlEglDestroyAllSurfaces(WlEglDisplay *display);
EGLBoolean wlEglIsWaylandWindowValid(struct wl_egl_window *window);
EGLBoolean wlEglIsWlEglSurfaceForDisplay(WlEglDisplay *display, WlEglSurface *wlEglSurface);
EGLBoolean wlEglQueryNativeResourceHook(EGLDisplay dpy,
void *nativeResource,
EGLint attribute,
int *value);
EGLBoolean wlEglSendDamageEvent(WlEglSurface *surface,
struct wl_event_queue *queue,
EGLint *rects,
EGLint n_rects);
void wlEglInitializeStreamDamageBuffer(WlEglStreamDamageBuffer *buffer);
EGLBoolean wlEglPutStreamDamage(WlEglStreamDamageBuffer *buffer,
EGLuint64KHR frameNumber,
EGLint *rects,
EGLint n_rects);
EGLBoolean wlEglGetStreamDamageForFrame(WlEglStreamDamageBuffer *buffer,
EGLuint64KHR frameNumber,
WlEglStreamDamage *damage);
void wlEglCreateFrameSync(WlEglSurface *surface);
EGLint wlEglWaitFrameSync(WlEglSurface *surface);
EGLBoolean wlEglSurfaceRef(WlEglDisplay *display, WlEglSurface *surface);
void wlEglSurfaceUnref(WlEglSurface *surface);
EGLint wlEglHandleImageStreamEvents(WlEglSurface *surface);
#ifdef __cplusplus
}
#endif
#endif