1 /*
2 * Copyright (c) 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
handleClientConn(void * data)23 void handleClientConn(void *data) {
24 int fd = (int)data;
25 EGLStreamKHR stream;
26 GLuint texId;
27
28 stream = eglCreateStreamFromFileDescriptorKHR(__eglDpy, fd);
29
30 glGenTextures(1, &texId);
31 glBindTexture(GL_TEXTURE_EXTERNAL_OES, texId);
32 eglStreamConsumerGLTextureExternalKHR(__eglDpy, stream);
33
34 sampleSurfaceListAppend(__surfaceList, stream, texId);
35
36 /* Rest of the client connection handling */
37 [...]
38 }
39
handleClientRepaint(void * data)40 void handleClientRepaint(void *data) {
41 int id = (int)data;
42
43 forall (surf, __surfaceList) {
44 if (surf->id == id) {
45 eglStreamConsumerAcquireKHR(__eglDpy, surf->stream);
46 break;
47 }
48 }
49
50 /* Rest of the client repaint handling */
51 [...]
52 }
53
main()54 int main() {
55 /* Window system setup */
56 __sampleDpy = sample_create_display("sample-display");
57
58 sample_listen_to_client_connections(__sampleDpy, handleClientConn);
59 sample_listen_to_client_repaints(__sampleDpy, handleClientRepaint);
60
61 /* Rest of the window system setup */
62 [...]
63
64 /* Native EGL setup (EGLDevice, GBM device, ...) */
65 __nativeDpy = /* Get native EGL display/device */
66
67 /* Get an EGLDisplay supporting EGLStreams that would allow creation of
68 scanout EGLSurfaces */
69 __eglDpy = eglGetPlatformDisplayEXT(EGL_PLATFORM_NATIVE, __nativeDpy, NULL);
70 eglInitialize(__eglDpy);
71
72 __eglSurf = /* Create a scanout EGLSurface on __eglDpy */;
73 __eglCtx = eglCreateContext(__eglDpy, <EGL config>, EGL_NO_CONTEXT, NULL);
74
75 eglMakeCurrent(__eglDpy, __eglSurf, __eglSurf, __eglCtx);
76
77 /* Rest of the EGL and OpenGL setup */
78 [...]
79
80 while (1) {
81 sample_dispatch_events(__sampleDpy);
82
83 /* Composite, repaint, ... */
84 [...]
85
86 forall (surf, __surfaceList) {
87 glBindTexture(GL_TEXTURE_EXTERNAL_OES, surf->texId);
88 /* Draw surface quad */
89 }
90
91 /* Rest of the repaint handling */
92 [...]
93
94 eglSwapBuffers(__eglDpy, eglSrf);
95 }
96
97 /* Cleanup */
98 [...]
99 }
100