eglApi.cpp revision aec8697fcaa8bb30e335f7850cffdd0364c35532
14774338bd0ad1ebe42c311fd0c72f13786b5c800Jesse Hall/*
2518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ** Copyright 2007, The Android Open Source Project
3518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian **
44774338bd0ad1ebe42c311fd0c72f13786b5c800Jesse Hall ** Licensed under the Apache License, Version 2.0 (the "License");
54774338bd0ad1ebe42c311fd0c72f13786b5c800Jesse Hall ** you may not use this file except in compliance with the License.
64774338bd0ad1ebe42c311fd0c72f13786b5c800Jesse Hall ** You may obtain a copy of the License at
7518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian **
84774338bd0ad1ebe42c311fd0c72f13786b5c800Jesse Hall **     http://www.apache.org/licenses/LICENSE-2.0
9518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian **
104774338bd0ad1ebe42c311fd0c72f13786b5c800Jesse Hall ** Unless required by applicable law or agreed to in writing, software
114774338bd0ad1ebe42c311fd0c72f13786b5c800Jesse Hall ** distributed under the License is distributed on an "AS IS" BASIS,
124774338bd0ad1ebe42c311fd0c72f13786b5c800Jesse Hall ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
134774338bd0ad1ebe42c311fd0c72f13786b5c800Jesse Hall ** See the License for the specific language governing permissions and
14518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ** limitations under the License.
15518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian */
16518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
171c8e95cf86f2182986385bc1ee85f13f425f3a3aJamie Gennis#define ATRACE_TAG ATRACE_TAG_GRAPHICS
181c8e95cf86f2182986385bc1ee85f13f425f3a3aJamie Gennis
19c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall#include <dlfcn.h>
20518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include <ctype.h>
21518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include <stdlib.h>
22518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include <string.h>
23518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
24518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include <hardware/gralloc.h>
25518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include <system/window.h>
26518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
27518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include <EGL/egl.h>
28518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include <EGL/eglext.h>
29518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
30518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include <cutils/log.h>
31518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include <cutils/atomic.h>
327db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian#include <cutils/compiler.h>
33518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include <cutils/properties.h>
34518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include <cutils/memory.h>
35518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
3605249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner#include <ui/GraphicBuffer.h>
3705249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner
38518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include <utils/KeyedVector.h>
39518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include <utils/SortedVector.h>
40518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include <utils/String8.h>
411c8e95cf86f2182986385bc1ee85f13f425f3a3aJamie Gennis#include <utils/Trace.h>
42518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
4339c24a20bbc697630d2b92c251b70c04d6f9d00cMathias Agopian#include "../egl_impl.h"
4439c24a20bbc697630d2b92c251b70c04d6f9d00cMathias Agopian#include "../hooks.h"
45518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
46518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include "egl_display.h"
47518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include "egl_object.h"
48518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include "egl_tls.h"
49ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian#include "egldefs.h"
50518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
51518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianusing namespace android;
52518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
53a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall// This extension has not been ratified yet, so can't be shipped.
54a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall// Implementation is incomplete and untested.
55a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall#define ENABLE_EGL_KHR_GL_COLORSPACE 0
56a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall
57518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ----------------------------------------------------------------------------
58518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
59e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopiannamespace android {
60e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian
61518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstruct extention_map_t {
62518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    const char* name;
63518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    __eglMustCastToProperFunctionPointerType address;
64518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian};
65518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
66e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian/*
6721558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hall * This is the list of EGL extensions exposed to applications.
68e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian *
6921558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hall * Some of them (gBuiltinExtensionString) are implemented entirely in this EGL
7021558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hall * wrapper and are always available.
71e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian *
7221558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hall * The rest (gExtensionString) depend on support in the EGL driver, and are
7321558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hall * only available if the driver supports them. However, some of these must be
7421558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hall * supported because they are used by the Android system itself; these are
7502b05da60a4669df44c9c0747ec262ec1862cf61Pablo Ceballos * listed as mandatory below and are required by the CDD. The system *assumes*
7621558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hall * the mandatory extensions are present and may not function properly if some
7721558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hall * are missing.
7821558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hall *
7921558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hall * NOTE: Both strings MUST have a single space as the last character.
80e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian */
8121558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hallextern char const * const gBuiltinExtensionString =
8221558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hall        "EGL_KHR_get_all_proc_addresses "
8321558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hall        "EGL_ANDROID_presentation_time "
84a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza        "EGL_KHR_swap_buffers_with_damage "
8505249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner        "EGL_ANDROID_create_native_client_buffer "
8602b05da60a4669df44c9c0747ec262ec1862cf61Pablo Ceballos        "EGL_ANDROID_front_buffer_auto_refresh "
8721558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hall        ;
88e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopianextern char const * const gExtensionString  =
89e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian        "EGL_KHR_image "                        // mandatory
90e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian        "EGL_KHR_image_base "                   // mandatory
91e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian        "EGL_KHR_image_pixmap "
92e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian        "EGL_KHR_lock_surface "
93a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall#if (ENABLE_EGL_KHR_GL_COLORSPACE != 0)
94c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall        "EGL_KHR_gl_colorspace "
95a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall#endif
96e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian        "EGL_KHR_gl_texture_2D_image "
97000d88f02680607f45f600dde4e53ebe5b3895abSeason Li        "EGL_KHR_gl_texture_3D_image "
98e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian        "EGL_KHR_gl_texture_cubemap_image "
99e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian        "EGL_KHR_gl_renderbuffer_image "
100e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian        "EGL_KHR_reusable_sync "
101e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian        "EGL_KHR_fence_sync "
102f6d1c3930eeba6b089ba12fb82ecad1c6622e550Jamie Gennis        "EGL_KHR_create_context "
103000d88f02680607f45f600dde4e53ebe5b3895abSeason Li        "EGL_KHR_config_attribs "
104000d88f02680607f45f600dde4e53ebe5b3895abSeason Li        "EGL_KHR_surfaceless_context "
105000d88f02680607f45f600dde4e53ebe5b3895abSeason Li        "EGL_KHR_stream "
106000d88f02680607f45f600dde4e53ebe5b3895abSeason Li        "EGL_KHR_stream_fifo "
107000d88f02680607f45f600dde4e53ebe5b3895abSeason Li        "EGL_KHR_stream_producer_eglsurface "
108000d88f02680607f45f600dde4e53ebe5b3895abSeason Li        "EGL_KHR_stream_consumer_gltexture "
109000d88f02680607f45f600dde4e53ebe5b3895abSeason Li        "EGL_KHR_stream_cross_process_fd "
110e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian        "EGL_EXT_create_context_robustness "
111e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian        "EGL_NV_system_time "
112e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian        "EGL_ANDROID_image_native_buffer "      // mandatory
1132bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian        "EGL_KHR_wait_sync "                    // strongly recommended
114dbe9245e2e362b12e184cd33b9a27b0901f81244Jamie Gennis        "EGL_ANDROID_recordable "               // mandatory
115a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza        "EGL_KHR_partial_update "               // strongly recommended
116a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza        "EGL_EXT_buffer_age "                   // strongly recommended with partial_update
117408e59f63aaaba30fb6db1477e985025dda085cdJesse Hall        "EGL_KHR_create_context_no_error "
118ceb9ee78bdc7b3a074d01380ce11432f88732094Pablo Ceballos        "EGL_KHR_mutable_render_buffer "
119f37864bc99576b851015f115613cc851a866dbf2Mika Isojärvi        "EGL_EXT_yuv_surface "
120aec8697fcaa8bb30e335f7850cffdd0364c35532Craig Donner        "EGL_EXT_protected_content "
121e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian        ;
122e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian
123e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian// extensions not exposed to applications but used by the ANDROID system
124e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian//      "EGL_ANDROID_blob_cache "               // strongly recommended
125e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian//      "EGL_IMG_hibernate_process "            // optional
126e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian//      "EGL_ANDROID_native_fence_sync "        // strongly recommended
127e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian//      "EGL_ANDROID_framebuffer_target "       // mandatory for HWC 1.1
128dbe9245e2e362b12e184cd33b9a27b0901f81244Jamie Gennis//      "EGL_ANDROID_image_crop "               // optional
129e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian
130e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian/*
131e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian * EGL Extensions entry-points exposed to 3rd party applications
132e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian * (keep in sync with gExtensionString above)
133e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian *
134e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian */
135e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopianstatic const extention_map_t sExtensionMap[] = {
136e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian    // EGL_KHR_lock_surface
137518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    { "eglLockSurfaceKHR",
138518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian            (__eglMustCastToProperFunctionPointerType)&eglLockSurfaceKHR },
139518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    { "eglUnlockSurfaceKHR",
140518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian            (__eglMustCastToProperFunctionPointerType)&eglUnlockSurfaceKHR },
141e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian
142e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian    // EGL_KHR_image, EGL_KHR_image_base
143518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    { "eglCreateImageKHR",
144518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian            (__eglMustCastToProperFunctionPointerType)&eglCreateImageKHR },
145518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    { "eglDestroyImageKHR",
146518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian            (__eglMustCastToProperFunctionPointerType)&eglDestroyImageKHR },
147e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian
148e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian    // EGL_KHR_reusable_sync, EGL_KHR_fence_sync
149e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian    { "eglCreateSyncKHR",
150e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian            (__eglMustCastToProperFunctionPointerType)&eglCreateSyncKHR },
151e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian    { "eglDestroySyncKHR",
152e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian            (__eglMustCastToProperFunctionPointerType)&eglDestroySyncKHR },
153e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian    { "eglClientWaitSyncKHR",
154e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian            (__eglMustCastToProperFunctionPointerType)&eglClientWaitSyncKHR },
155e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian    { "eglSignalSyncKHR",
156e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian            (__eglMustCastToProperFunctionPointerType)&eglSignalSyncKHR },
157e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian    { "eglGetSyncAttribKHR",
158e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian            (__eglMustCastToProperFunctionPointerType)&eglGetSyncAttribKHR },
159e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian
160e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian    // EGL_NV_system_time
1611c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang    { "eglGetSystemTimeFrequencyNV",
1621c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang            (__eglMustCastToProperFunctionPointerType)&eglGetSystemTimeFrequencyNV },
1631c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang    { "eglGetSystemTimeNV",
1641c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang            (__eglMustCastToProperFunctionPointerType)&eglGetSystemTimeNV },
165e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian
1662bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian    // EGL_KHR_wait_sync
1672bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian    { "eglWaitSyncKHR",
1682bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian            (__eglMustCastToProperFunctionPointerType)&eglWaitSyncKHR },
169e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian
170e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian    // EGL_ANDROID_presentation_time
171e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian    { "eglPresentationTimeANDROID",
172e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian            (__eglMustCastToProperFunctionPointerType)&eglPresentationTimeANDROID },
173a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza
174a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza    // EGL_KHR_swap_buffers_with_damage
175a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza    { "eglSwapBuffersWithDamageKHR",
176a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza            (__eglMustCastToProperFunctionPointerType)&eglSwapBuffersWithDamageKHR },
177a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza
17805249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner    // EGL_ANDROID_native_client_buffer
17905249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner    { "eglCreateNativeClientBufferANDROID",
18005249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner            (__eglMustCastToProperFunctionPointerType)&eglCreateNativeClientBufferANDROID },
18105249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner
182a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza    // EGL_KHR_partial_update
183a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza    { "eglSetDamageRegionKHR",
184a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza            (__eglMustCastToProperFunctionPointerType)&eglSetDamageRegionKHR },
185000d88f02680607f45f600dde4e53ebe5b3895abSeason Li
186000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    { "eglCreateStreamKHR",
187000d88f02680607f45f600dde4e53ebe5b3895abSeason Li            (__eglMustCastToProperFunctionPointerType)&eglCreateStreamKHR },
188000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    { "eglDestroyStreamKHR",
189000d88f02680607f45f600dde4e53ebe5b3895abSeason Li            (__eglMustCastToProperFunctionPointerType)&eglDestroyStreamKHR },
190000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    { "eglStreamAttribKHR",
191000d88f02680607f45f600dde4e53ebe5b3895abSeason Li            (__eglMustCastToProperFunctionPointerType)&eglStreamAttribKHR },
192000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    { "eglQueryStreamKHR",
193000d88f02680607f45f600dde4e53ebe5b3895abSeason Li            (__eglMustCastToProperFunctionPointerType)&eglQueryStreamKHR },
194000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    { "eglQueryStreamu64KHR",
195000d88f02680607f45f600dde4e53ebe5b3895abSeason Li            (__eglMustCastToProperFunctionPointerType)&eglQueryStreamu64KHR },
196000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    { "eglQueryStreamTimeKHR",
197000d88f02680607f45f600dde4e53ebe5b3895abSeason Li            (__eglMustCastToProperFunctionPointerType)&eglQueryStreamTimeKHR },
198000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    { "eglCreateStreamProducerSurfaceKHR",
199000d88f02680607f45f600dde4e53ebe5b3895abSeason Li            (__eglMustCastToProperFunctionPointerType)&eglCreateStreamProducerSurfaceKHR },
200000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    { "eglStreamConsumerGLTextureExternalKHR",
201000d88f02680607f45f600dde4e53ebe5b3895abSeason Li            (__eglMustCastToProperFunctionPointerType)&eglStreamConsumerGLTextureExternalKHR },
202000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    { "eglStreamConsumerAcquireKHR",
203000d88f02680607f45f600dde4e53ebe5b3895abSeason Li            (__eglMustCastToProperFunctionPointerType)&eglStreamConsumerAcquireKHR },
204000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    { "eglStreamConsumerReleaseKHR",
205000d88f02680607f45f600dde4e53ebe5b3895abSeason Li            (__eglMustCastToProperFunctionPointerType)&eglStreamConsumerReleaseKHR },
206000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    { "eglGetStreamFileDescriptorKHR",
207000d88f02680607f45f600dde4e53ebe5b3895abSeason Li            (__eglMustCastToProperFunctionPointerType)&eglGetStreamFileDescriptorKHR },
208000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    { "eglCreateStreamFromFileDescriptorKHR",
209000d88f02680607f45f600dde4e53ebe5b3895abSeason Li            (__eglMustCastToProperFunctionPointerType)&eglCreateStreamFromFileDescriptorKHR },
210518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian};
211518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
212e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian/*
213e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian * These extensions entry-points should not be exposed to applications.
214e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian * They're used internally by the Android EGL layer.
215e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian */
216e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian#define FILTER_EXTENSIONS(procname) \
217e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian        (!strcmp((procname), "eglSetBlobCacheFuncsANDROID") ||    \
218e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian         !strcmp((procname), "eglHibernateProcessIMG")      ||    \
219e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian         !strcmp((procname), "eglAwakenProcessIMG")         ||    \
220e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian         !strcmp((procname), "eglDupNativeFenceFDANDROID"))
221e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian
222e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian
223e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian
224518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// accesses protected by sExtensionMapMutex
225518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic DefaultKeyedVector<String8, __eglMustCastToProperFunctionPointerType> sGLExtentionMap;
226518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic int sGLExtentionSlot = 0;
227518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic pthread_mutex_t sExtensionMapMutex = PTHREAD_MUTEX_INITIALIZER;
228518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
229518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic void(*findProcAddress(const char* name,
230518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        const extention_map_t* map, size_t n))() {
231518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    for (uint32_t i=0 ; i<n ; i++) {
232518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        if (!strcmp(name, map[i].name)) {
233518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian            return map[i].address;
234518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        }
235518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
236518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    return NULL;
237518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
238518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
239518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ----------------------------------------------------------------------------
240518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
241518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianextern void setGLHooksThreadSpecific(gl_hooks_t const *value);
242518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianextern EGLBoolean egl_init_drivers();
243518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianextern const __eglMustCastToProperFunctionPointerType gExtensionForwarders[MAX_NUMBER_OF_GL_EXTENSIONS];
244518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianextern gl_hooks_t gHooksTrace;
245e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian
246518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} // namespace android;
247518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
248e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian
249518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ----------------------------------------------------------------------------
250518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
251518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic inline void clearError() { egl_tls_t::clearError(); }
252518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic inline EGLContext getContext() { return egl_tls_t::getContext(); }
253518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
254518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ----------------------------------------------------------------------------
255518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
256518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLDisplay eglGetDisplay(EGLNativeDisplayType display)
257518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{
258518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    clearError();
259518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
260c3289c41e794117817895653300bd2cf7daa0a01Dan Stoza    uintptr_t index = reinterpret_cast<uintptr_t>(display);
261518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (index >= NUM_DISPLAYS) {
262518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        return setError(EGL_BAD_PARAMETER, EGL_NO_DISPLAY);
263518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
264518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
265518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (egl_init_drivers() == EGL_FALSE) {
266518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        return setError(EGL_BAD_PARAMETER, EGL_NO_DISPLAY);
267518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
268518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
269518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    EGLDisplay dpy = egl_display_t::getFromNativeDisplay(display);
270518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    return dpy;
271518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
272518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
273518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ----------------------------------------------------------------------------
274518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// Initialization
275518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ----------------------------------------------------------------------------
276518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
277518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
278518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{
279518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    clearError();
280518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
281b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    egl_display_ptr dp = get_display(dpy);
282518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE);
283518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
284518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    EGLBoolean res = dp->initialize(major, minor);
285518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
286518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    return res;
287518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
288518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
289518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglTerminate(EGLDisplay dpy)
290518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{
291518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    // NOTE: don't unload the drivers b/c some APIs can be called
292518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    // after eglTerminate() has been called. eglTerminate() only
293518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    // terminates an EGLDisplay, not a EGL itself.
294518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
295518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    clearError();
296518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
297b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    egl_display_ptr dp = get_display(dpy);
298518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE);
299518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
300518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    EGLBoolean res = dp->terminate();
3014774338bd0ad1ebe42c311fd0c72f13786b5c800Jesse Hall
302518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    return res;
303518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
304518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
305518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ----------------------------------------------------------------------------
306518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// configuration
307518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ----------------------------------------------------------------------------
308518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
309518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglGetConfigs(   EGLDisplay dpy,
310518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian                            EGLConfig *configs,
311518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian                            EGLint config_size, EGLint *num_config)
312518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{
313518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    clearError();
314518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
315b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    const egl_display_ptr dp = validate_display(dpy);
316518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (!dp) return EGL_FALSE;
317518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
3187773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian    if (num_config==0) {
3197773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian        return setError(EGL_BAD_PARAMETER, EGL_FALSE);
320518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
321518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
3227773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian    EGLBoolean res = EGL_FALSE;
3237773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian    *num_config = 0;
3247773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian
3257773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian    egl_connection_t* const cnx = &gEGLImpl;
3267773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian    if (cnx->dso) {
3277773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian        res = cnx->egl.eglGetConfigs(
3287773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian                dp->disp.dpy, configs, config_size, num_config);
329518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
3307773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian
3317773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian    return res;
332518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
333518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
334518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglChooseConfig( EGLDisplay dpy, const EGLint *attrib_list,
335518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian                            EGLConfig *configs, EGLint config_size,
336518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian                            EGLint *num_config)
337518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{
338518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    clearError();
339518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
340b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    const egl_display_ptr dp = validate_display(dpy);
341518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (!dp) return EGL_FALSE;
342518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
343518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (num_config==0) {
344518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        return setError(EGL_BAD_PARAMETER, EGL_FALSE);
345518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
346518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
347518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    EGLBoolean res = EGL_FALSE;
348518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    *num_config = 0;
349518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
350ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian    egl_connection_t* const cnx = &gEGLImpl;
351ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian    if (cnx->dso) {
3521cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy        if (attrib_list) {
3531cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy            char value[PROPERTY_VALUE_MAX];
3541cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy            property_get("debug.egl.force_msaa", value, "false");
3551cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy
3561cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy            if (!strcmp(value, "true")) {
3571cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy                size_t attribCount = 0;
3581cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy                EGLint attrib = attrib_list[0];
3591cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy
3601cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy                // Only enable MSAA if the context is OpenGL ES 2.0 and
361be3c3e4ecad501eecfe1f7a424a792f0f7f3f307Romain Guy                // if no caveat is requested
3621cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy                const EGLint *attribRendererable = NULL;
3631cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy                const EGLint *attribCaveat = NULL;
3641cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy
3651cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy                // Count the number of attributes and look for
366be3c3e4ecad501eecfe1f7a424a792f0f7f3f307Romain Guy                // EGL_RENDERABLE_TYPE and EGL_CONFIG_CAVEAT
3671cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy                while (attrib != EGL_NONE) {
3681cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy                    attrib = attrib_list[attribCount];
3691cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy                    switch (attrib) {
3701cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy                        case EGL_RENDERABLE_TYPE:
3711cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy                            attribRendererable = &attrib_list[attribCount];
3721cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy                            break;
3731cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy                        case EGL_CONFIG_CAVEAT:
3741cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy                            attribCaveat = &attrib_list[attribCount];
3751cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy                            break;
3761cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy                    }
3771cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy                    attribCount++;
3781cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy                }
3791cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy
3801cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy                if (attribRendererable && attribRendererable[1] == EGL_OPENGL_ES2_BIT &&
3811cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy                        (!attribCaveat || attribCaveat[1] != EGL_NONE)) {
3824774338bd0ad1ebe42c311fd0c72f13786b5c800Jesse Hall
3831cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy                    // Insert 2 extra attributes to force-enable MSAA 4x
3841cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy                    EGLint aaAttribs[attribCount + 4];
3851cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy                    aaAttribs[0] = EGL_SAMPLE_BUFFERS;
3861cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy                    aaAttribs[1] = 1;
3871cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy                    aaAttribs[2] = EGL_SAMPLES;
3881cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy                    aaAttribs[3] = 4;
3891cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy
3901cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy                    memcpy(&aaAttribs[4], attrib_list, attribCount * sizeof(EGLint));
3911cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy
3921cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy                    EGLint numConfigAA;
3931cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy                    EGLBoolean resAA = cnx->egl.eglChooseConfig(
3941cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy                            dp->disp.dpy, aaAttribs, configs, config_size, &numConfigAA);
3951cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy
3961cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy                    if (resAA == EGL_TRUE && numConfigAA > 0) {
3971cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy                        ALOGD("Enabling MSAA 4x");
3981cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy                        *num_config = numConfigAA;
3991cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy                        return resAA;
4001cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy                    }
4011cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy                }
4021cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy            }
4031cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy        }
4041cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy
4057773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian        res = cnx->egl.eglChooseConfig(
4067773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian                dp->disp.dpy, attrib_list, configs, config_size, num_config);
407518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
408518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    return res;
409518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
410518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
411518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config,
412518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        EGLint attribute, EGLint *value)
413518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{
414518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    clearError();
415518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
416b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    egl_connection_t* cnx = NULL;
417b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    const egl_display_ptr dp = validate_display_connection(dpy, cnx);
418b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    if (!dp) return EGL_FALSE;
4194774338bd0ad1ebe42c311fd0c72f13786b5c800Jesse Hall
420518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    return cnx->egl.eglGetConfigAttrib(
4217773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian            dp->disp.dpy, config, attribute, value);
422518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
423518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
424518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ----------------------------------------------------------------------------
425518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// surfaces
426518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ----------------------------------------------------------------------------
427518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
428a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall// The EGL_KHR_gl_colorspace spec hasn't been ratified yet, so these haven't
429c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall// been added to the Khronos egl.h.
430c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall#define EGL_GL_COLORSPACE_KHR           EGL_VG_COLORSPACE
431c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall#define EGL_GL_COLORSPACE_SRGB_KHR      EGL_VG_COLORSPACE_sRGB
432c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall#define EGL_GL_COLORSPACE_LINEAR_KHR    EGL_VG_COLORSPACE_LINEAR
433c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall
434c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall// Turn linear formats into corresponding sRGB formats when colorspace is
435c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall// EGL_GL_COLORSPACE_SRGB_KHR, or turn sRGB formats into corresponding linear
436c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall// formats when colorspace is EGL_GL_COLORSPACE_LINEAR_KHR. In any cases where
43782c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala// the modification isn't possible, the original dataSpace is returned.
43882c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvalastatic android_dataspace modifyBufferDataspace( android_dataspace dataSpace,
43982c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala                                                EGLint colorspace) {
440c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall    if (colorspace == EGL_GL_COLORSPACE_LINEAR_KHR) {
44182c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala        return HAL_DATASPACE_SRGB_LINEAR;
442c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall    } else if (colorspace == EGL_GL_COLORSPACE_SRGB_KHR) {
44382c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala        return HAL_DATASPACE_SRGB;
444c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall    }
44582c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala    return dataSpace;
446c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall}
447c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall
448518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLSurface eglCreateWindowSurface(  EGLDisplay dpy, EGLConfig config,
449518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian                                    NativeWindowType window,
450518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian                                    const EGLint *attrib_list)
451518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{
452518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    clearError();
453518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
454b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    egl_connection_t* cnx = NULL;
455b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    egl_display_ptr dp = validate_display_connection(dpy, cnx);
456b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    if (dp) {
457ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian        EGLDisplay iDpy = dp->disp.dpy;
458518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
459d566ce3a26ce781ecdbc479aaba0e172b7c807a9Andy McFadden        int result = native_window_api_connect(window, NATIVE_WINDOW_API_EGL);
460d566ce3a26ce781ecdbc479aaba0e172b7c807a9Andy McFadden        if (result != OK) {
461d566ce3a26ce781ecdbc479aaba0e172b7c807a9Andy McFadden            ALOGE("eglCreateWindowSurface: native_window_api_connect (win=%p) "
462d566ce3a26ce781ecdbc479aaba0e172b7c807a9Andy McFadden                    "failed (%#x) (already connected to another API?)",
463d566ce3a26ce781ecdbc479aaba0e172b7c807a9Andy McFadden                    window, result);
46477a9b4a6bd21188e2744ae9dcd8092c6837bff7cJonathan Hamilton            return setError(EGL_BAD_ALLOC, EGL_NO_SURFACE);
46581a63350527cafce6929309533c58586878f10b5Mathias Agopian        }
46681a63350527cafce6929309533c58586878f10b5Mathias Agopian
4670f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian        // Set the native window's buffers format to match what this config requests.
468c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall        // Whether to use sRGB gamma is not part of the EGLconfig, but is part
469c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall        // of our native format. So if sRGB gamma is requested, we have to
470c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall        // modify the EGLconfig's format before setting the native window's
471c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall        // format.
472733a80754786d39cdc0fee09509b194472c320bcAlistair Strachan
4730f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian        // by default, just pick RGBA_8888
4740f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian        EGLint format = HAL_PIXEL_FORMAT_RGBA_8888;
47582c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala        android_dataspace dataSpace = HAL_DATASPACE_UNKNOWN;
4760f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian
4770f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian        EGLint a = 0;
4780f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian        cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_ALPHA_SIZE, &a);
4790f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian        if (a > 0) {
4800f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian            // alpha-channel requested, there's really only one suitable format
4810f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian            format = HAL_PIXEL_FORMAT_RGBA_8888;
4820f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian        } else {
4830f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian            EGLint r, g, b;
4840f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian            r = g = b = 0;
4850f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian            cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_RED_SIZE,   &r);
4860f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian            cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_GREEN_SIZE, &g);
4870f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian            cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_BLUE_SIZE,  &b);
4880f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian            EGLint colorDepth = r + g + b;
4890f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian            if (colorDepth <= 16) {
4900f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian                format = HAL_PIXEL_FORMAT_RGB_565;
4910f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian            } else {
4920f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian                format = HAL_PIXEL_FORMAT_RGBX_8888;
4930f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian            }
494c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall        }
4950f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian
4960f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian        // now select a corresponding sRGB format if needed
4970f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian        if (attrib_list && dp->haveExtension("EGL_KHR_gl_colorspace")) {
4980f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian            for (const EGLint* attr = attrib_list; *attr != EGL_NONE; attr += 2) {
4990f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian                if (*attr == EGL_GL_COLORSPACE_KHR) {
500a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall                    if (ENABLE_EGL_KHR_GL_COLORSPACE) {
50182c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala                        dataSpace = modifyBufferDataspace(dataSpace, *(attr+1));
502a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall                    } else {
503a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall                        // Normally we'd pass through unhandled attributes to
504a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall                        // the driver. But in case the driver implements this
505a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall                        // extension but we're disabling it, we want to prevent
506a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall                        // it getting through -- support will be broken without
507a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall                        // our help.
508a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall                        ALOGE("sRGB window surfaces not supported");
509a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall                        return setError(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE);
510a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall                    }
511bee205fd58a27c10a0895de5339e76025d429d2bJamie Gennis                }
512518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian            }
513518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        }
514733a80754786d39cdc0fee09509b194472c320bcAlistair Strachan
515c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall        if (format != 0) {
516c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall            int err = native_window_set_buffers_format(window, format);
517c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall            if (err != 0) {
518c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall                ALOGE("error setting native window pixel format: %s (%d)",
519c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall                        strerror(-err), err);
52082c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala                native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL);
52182c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala                return setError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
52282c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala            }
52382c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala        }
52482c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala
52582c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala        if (dataSpace != 0) {
52682c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala            int err = native_window_set_buffers_data_space(window, dataSpace);
52782c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala            if (err != 0) {
52882c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala                ALOGE("error setting native window pixel dataSpace: %s (%d)",
52982c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala                        strerror(-err), err);
530c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall                native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL);
531c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall                return setError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
532c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall            }
533c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall        }
534518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
53559769469e4b9b2d8b12c020eb44b030b3927a50bJamie Gennis        // the EGL spec requires that a new EGLSurface default to swap interval
53659769469e4b9b2d8b12c020eb44b030b3927a50bJamie Gennis        // 1, so explicitly set that on the window here.
53759769469e4b9b2d8b12c020eb44b030b3927a50bJamie Gennis        ANativeWindow* anw = reinterpret_cast<ANativeWindow*>(window);
53859769469e4b9b2d8b12c020eb44b030b3927a50bJamie Gennis        anw->setSwapInterval(anw, 1);
53959769469e4b9b2d8b12c020eb44b030b3927a50bJamie Gennis
540518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        EGLSurface surface = cnx->egl.eglCreateWindowSurface(
5417773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian                iDpy, config, window, attrib_list);
542518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        if (surface != EGL_NO_SURFACE) {
543b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall            egl_surface_t* s = new egl_surface_t(dp.get(), config, window,
544b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall                    surface, cnx);
545518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian            return s;
546518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        }
54781a63350527cafce6929309533c58586878f10b5Mathias Agopian
54881a63350527cafce6929309533c58586878f10b5Mathias Agopian        // EGLSurface creation failed
54981a63350527cafce6929309533c58586878f10b5Mathias Agopian        native_window_set_buffers_format(window, 0);
55081a63350527cafce6929309533c58586878f10b5Mathias Agopian        native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL);
551518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
552518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    return EGL_NO_SURFACE;
553518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
554518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
555518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLSurface eglCreatePixmapSurface(  EGLDisplay dpy, EGLConfig config,
556518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian                                    NativePixmapType pixmap,
557518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian                                    const EGLint *attrib_list)
558518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{
559518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    clearError();
560518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
561b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    egl_connection_t* cnx = NULL;
562b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    egl_display_ptr dp = validate_display_connection(dpy, cnx);
563b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    if (dp) {
564518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        EGLSurface surface = cnx->egl.eglCreatePixmapSurface(
5657773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian                dp->disp.dpy, config, pixmap, attrib_list);
566518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        if (surface != EGL_NO_SURFACE) {
567b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall            egl_surface_t* s = new egl_surface_t(dp.get(), config, NULL,
568b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall                    surface, cnx);
569518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian            return s;
570518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        }
571518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
572518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    return EGL_NO_SURFACE;
573518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
574518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
575518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLSurface eglCreatePbufferSurface( EGLDisplay dpy, EGLConfig config,
576518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian                                    const EGLint *attrib_list)
577518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{
578518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    clearError();
579518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
580b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    egl_connection_t* cnx = NULL;
581b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    egl_display_ptr dp = validate_display_connection(dpy, cnx);
582b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    if (dp) {
583518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        EGLSurface surface = cnx->egl.eglCreatePbufferSurface(
5847773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian                dp->disp.dpy, config, attrib_list);
585518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        if (surface != EGL_NO_SURFACE) {
586b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall            egl_surface_t* s = new egl_surface_t(dp.get(), config, NULL,
587b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall                    surface, cnx);
588518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian            return s;
589518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        }
590518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
591518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    return EGL_NO_SURFACE;
592518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
5934774338bd0ad1ebe42c311fd0c72f13786b5c800Jesse Hall
594518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface)
595518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{
596518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    clearError();
597518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
598b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    const egl_display_ptr dp = validate_display(dpy);
599518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (!dp) return EGL_FALSE;
600518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
601b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    SurfaceRef _s(dp.get(), surface);
6025b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian    if (!_s.get())
6035b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian        return setError(EGL_BAD_SURFACE, EGL_FALSE);
604518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
605518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    egl_surface_t * const s = get_surface(surface);
606ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian    EGLBoolean result = s->cnx->egl.eglDestroySurface(dp->disp.dpy, s->surface);
607518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (result == EGL_TRUE) {
608518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        _s.terminate();
609518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
610518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    return result;
611518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
612518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
613518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglQuerySurface( EGLDisplay dpy, EGLSurface surface,
614518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian                            EGLint attribute, EGLint *value)
615518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{
616518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    clearError();
617518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
618b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    const egl_display_ptr dp = validate_display(dpy);
619518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (!dp) return EGL_FALSE;
620518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
621b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    SurfaceRef _s(dp.get(), surface);
6225b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian    if (!_s.get())
6235b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian        return setError(EGL_BAD_SURFACE, EGL_FALSE);
624518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
625518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    egl_surface_t const * const s = get_surface(surface);
6267773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian    return s->cnx->egl.eglQuerySurface(
6277773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian            dp->disp.dpy, s->surface, attribute, value);
628518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
629518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
630e8696a40e09b24b634214684d18526187b316a2fJamie Gennisvoid EGLAPI eglBeginFrame(EGLDisplay dpy, EGLSurface surface) {
6311c8e95cf86f2182986385bc1ee85f13f425f3a3aJamie Gennis    ATRACE_CALL();
632e8696a40e09b24b634214684d18526187b316a2fJamie Gennis    clearError();
633e8696a40e09b24b634214684d18526187b316a2fJamie Gennis
634b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    const egl_display_ptr dp = validate_display(dpy);
635e8696a40e09b24b634214684d18526187b316a2fJamie Gennis    if (!dp) {
636e8696a40e09b24b634214684d18526187b316a2fJamie Gennis        return;
637e8696a40e09b24b634214684d18526187b316a2fJamie Gennis    }
638e8696a40e09b24b634214684d18526187b316a2fJamie Gennis
639b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    SurfaceRef _s(dp.get(), surface);
640e8696a40e09b24b634214684d18526187b316a2fJamie Gennis    if (!_s.get()) {
641e8696a40e09b24b634214684d18526187b316a2fJamie Gennis        setError(EGL_BAD_SURFACE, EGL_FALSE);
642e8696a40e09b24b634214684d18526187b316a2fJamie Gennis        return;
643e8696a40e09b24b634214684d18526187b316a2fJamie Gennis    }
644e8696a40e09b24b634214684d18526187b316a2fJamie Gennis}
645e8696a40e09b24b634214684d18526187b316a2fJamie Gennis
646518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ----------------------------------------------------------------------------
647518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// Contexts
648518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ----------------------------------------------------------------------------
649518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
650518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config,
651518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian                            EGLContext share_list, const EGLint *attrib_list)
652518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{
653518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    clearError();
654518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
655b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    egl_connection_t* cnx = NULL;
656b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    const egl_display_ptr dp = validate_display_connection(dpy, cnx);
6570673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock    if (dp) {
658518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        if (share_list != EGL_NO_CONTEXT) {
6590673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock            if (!ContextRef(dp.get(), share_list).get()) {
6600673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock                return setError(EGL_BAD_CONTEXT, EGL_NO_CONTEXT);
6610673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock            }
662518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian            egl_context_t* const c = get_context(share_list);
663518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian            share_list = c->context;
664518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        }
665518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        EGLContext context = cnx->egl.eglCreateContext(
6667773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian                dp->disp.dpy, config, share_list, attrib_list);
667518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        if (context != EGL_NO_CONTEXT) {
668518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian            // figure out if it's a GLESv1 or GLESv2
669518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian            int version = 0;
670518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian            if (attrib_list) {
671518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian                while (*attrib_list != EGL_NONE) {
672518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian                    GLint attr = *attrib_list++;
673518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian                    GLint value = *attrib_list++;
674518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian                    if (attr == EGL_CONTEXT_CLIENT_VERSION) {
675518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian                        if (value == 1) {
6767773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian                            version = egl_connection_t::GLESv1_INDEX;
6774774338bd0ad1ebe42c311fd0c72f13786b5c800Jesse Hall                        } else if (value == 2 || value == 3) {
6787773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian                            version = egl_connection_t::GLESv2_INDEX;
679518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian                        }
680518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian                    }
681518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian                };
682518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian            }
683b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall            egl_context_t* c = new egl_context_t(dpy, context, config, cnx,
684b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall                    version);
685518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian            return c;
686518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        }
687518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
688518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    return EGL_NO_CONTEXT;
689518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
690518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
691518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx)
692518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{
693518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    clearError();
694518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
695b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    const egl_display_ptr dp = validate_display(dpy);
6965b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian    if (!dp)
6975b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian        return EGL_FALSE;
698518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
699b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    ContextRef _c(dp.get(), ctx);
7005b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian    if (!_c.get())
7015b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian        return setError(EGL_BAD_CONTEXT, EGL_FALSE);
7024774338bd0ad1ebe42c311fd0c72f13786b5c800Jesse Hall
703518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    egl_context_t * const c = get_context(ctx);
704ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian    EGLBoolean result = c->cnx->egl.eglDestroyContext(dp->disp.dpy, c->context);
705518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (result == EGL_TRUE) {
706518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        _c.terminate();
707518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
708518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    return result;
709518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
710518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
711518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglMakeCurrent(  EGLDisplay dpy, EGLSurface draw,
712518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian                            EGLSurface read, EGLContext ctx)
713518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{
714518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    clearError();
715518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
716b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    egl_display_ptr dp = validate_display(dpy);
717518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE);
718518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
7195b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian    // If ctx is not EGL_NO_CONTEXT, read is not EGL_NO_SURFACE, or draw is not
7205b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian    // EGL_NO_SURFACE, then an EGL_NOT_INITIALIZED error is generated if dpy is
7215b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian    // a valid but uninitialized display.
722518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if ( (ctx != EGL_NO_CONTEXT) || (read != EGL_NO_SURFACE) ||
723518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian         (draw != EGL_NO_SURFACE) ) {
724518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        if (!dp->isReady()) return setError(EGL_NOT_INITIALIZED, EGL_FALSE);
725518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
726518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
727518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    // get a reference to the object passed in
728b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    ContextRef _c(dp.get(), ctx);
729b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    SurfaceRef _d(dp.get(), draw);
730b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    SurfaceRef _r(dp.get(), read);
731518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
732518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    // validate the context (if not EGL_NO_CONTEXT)
7335b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian    if ((ctx != EGL_NO_CONTEXT) && !_c.get()) {
734518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        // EGL_NO_CONTEXT is valid
7350673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock        return setError(EGL_BAD_CONTEXT, EGL_FALSE);
736518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
737518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
738518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    // these are the underlying implementation's object
739518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    EGLContext impl_ctx  = EGL_NO_CONTEXT;
740518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    EGLSurface impl_draw = EGL_NO_SURFACE;
741518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    EGLSurface impl_read = EGL_NO_SURFACE;
742518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
743518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    // these are our objects structs passed in
744518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    egl_context_t       * c = NULL;
745518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    egl_surface_t const * d = NULL;
746518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    egl_surface_t const * r = NULL;
747518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
748518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    // these are the current objects structs
749518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    egl_context_t * cur_c = get_context(getContext());
7504774338bd0ad1ebe42c311fd0c72f13786b5c800Jesse Hall
751518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (ctx != EGL_NO_CONTEXT) {
752518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        c = get_context(ctx);
753518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        impl_ctx = c->context;
754518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    } else {
755518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        // no context given, use the implementation of the current context
7560673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock        if (draw != EGL_NO_SURFACE || read != EGL_NO_SURFACE) {
7570673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock            // calling eglMakeCurrent( ..., !=0, !=0, EGL_NO_CONTEXT);
7580673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock            return setError(EGL_BAD_MATCH, EGL_FALSE);
7590673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock        }
760518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        if (cur_c == NULL) {
761518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian            // no current context
762518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian            // not an error, there is just no current context.
763518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian            return EGL_TRUE;
764518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        }
765518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
766518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
767518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    // retrieve the underlying implementation's draw EGLSurface
768518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (draw != EGL_NO_SURFACE) {
7690673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock        if (!_d.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE);
770518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        d = get_surface(draw);
771518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        impl_draw = d->surface;
772518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
773518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
774518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    // retrieve the underlying implementation's read EGLSurface
775518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (read != EGL_NO_SURFACE) {
7760673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock        if (!_r.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE);
777518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        r = get_surface(read);
778518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        impl_read = r->surface;
779518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
780518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
781518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
782b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    EGLBoolean result = dp->makeCurrent(c, cur_c,
783fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian            draw, read, ctx,
784fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian            impl_draw, impl_read, impl_ctx);
785518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
786518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (result == EGL_TRUE) {
787fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian        if (c) {
788518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian            setGLHooksThreadSpecific(c->cnx->hooks[c->version]);
789518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian            egl_tls_t::setContext(ctx);
790518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian            _c.acquire();
791518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian            _r.acquire();
792518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian            _d.acquire();
793518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        } else {
794518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian            setGLHooksThreadSpecific(&gHooksNoContext);
795518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian            egl_tls_t::setContext(EGL_NO_CONTEXT);
796518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        }
7975fecea776a5f093c21ac1a0ad3552b847d4be23eMathias Agopian    } else {
798e6f43ddce78d6846af12550ff9193c5c6fe5844bSteve Block        // this will ALOGE the error
79963108c34ec181e923b68ee840bb7960f205466a7Mathias Agopian        egl_connection_t* const cnx = &gEGLImpl;
80063108c34ec181e923b68ee840bb7960f205466a7Mathias Agopian        result = setError(cnx->egl.eglGetError(), EGL_FALSE);
801518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
802518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    return result;
803518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
804518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
805518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
806518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglQueryContext( EGLDisplay dpy, EGLContext ctx,
807518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian                            EGLint attribute, EGLint *value)
808518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{
809518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    clearError();
810518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
811b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    const egl_display_ptr dp = validate_display(dpy);
812518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (!dp) return EGL_FALSE;
813518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
814b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    ContextRef _c(dp.get(), ctx);
815518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (!_c.get()) return setError(EGL_BAD_CONTEXT, EGL_FALSE);
816518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
817518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    egl_context_t * const c = get_context(ctx);
8187773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian    return c->cnx->egl.eglQueryContext(
8197773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian            dp->disp.dpy, c->context, attribute, value);
820518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
821518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
822518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
823518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLContext eglGetCurrentContext(void)
824518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{
825518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    // could be called before eglInitialize(), but we wouldn't have a context
826518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    // then, and this function would correctly return EGL_NO_CONTEXT.
827518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
828518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    clearError();
829518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
830518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    EGLContext ctx = getContext();
831518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    return ctx;
832518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
833518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
834518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLSurface eglGetCurrentSurface(EGLint readdraw)
835518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{
836518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    // could be called before eglInitialize(), but we wouldn't have a context
837518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    // then, and this function would correctly return EGL_NO_SURFACE.
838518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
839518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    clearError();
840518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
841518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    EGLContext ctx = getContext();
842518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (ctx) {
843518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        egl_context_t const * const c = get_context(ctx);
844518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        if (!c) return setError(EGL_BAD_CONTEXT, EGL_NO_SURFACE);
845518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        switch (readdraw) {
846518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian            case EGL_READ: return c->read;
8474774338bd0ad1ebe42c311fd0c72f13786b5c800Jesse Hall            case EGL_DRAW: return c->draw;
848518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian            default: return setError(EGL_BAD_PARAMETER, EGL_NO_SURFACE);
849518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        }
850518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
851518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    return EGL_NO_SURFACE;
852518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
853518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
854518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLDisplay eglGetCurrentDisplay(void)
855518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{
856518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    // could be called before eglInitialize(), but we wouldn't have a context
857518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    // then, and this function would correctly return EGL_NO_DISPLAY.
858518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
859518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    clearError();
860518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
861518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    EGLContext ctx = getContext();
862518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (ctx) {
863518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        egl_context_t const * const c = get_context(ctx);
864518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        if (!c) return setError(EGL_BAD_CONTEXT, EGL_NO_SURFACE);
865518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        return c->dpy;
866518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
867518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    return EGL_NO_DISPLAY;
868518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
869518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
870518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglWaitGL(void)
871518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{
872518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    clearError();
873518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
874ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian    egl_connection_t* const cnx = &gEGLImpl;
875ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian    if (!cnx->dso)
876ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian        return setError(EGL_BAD_CONTEXT, EGL_FALSE);
877ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian
878ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian    return cnx->egl.eglWaitGL();
879518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
880518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
881518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglWaitNative(EGLint engine)
882518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{
883518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    clearError();
884518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
885ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian    egl_connection_t* const cnx = &gEGLImpl;
886ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian    if (!cnx->dso)
887ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian        return setError(EGL_BAD_CONTEXT, EGL_FALSE);
888ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian
889ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian    return cnx->egl.eglWaitNative(engine);
890518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
891518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
892518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLint eglGetError(void)
893518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{
894ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian    EGLint err = EGL_SUCCESS;
895ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian    egl_connection_t* const cnx = &gEGLImpl;
896ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian    if (cnx->dso) {
897ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian        err = cnx->egl.eglGetError();
898518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
899ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian    if (err == EGL_SUCCESS) {
900ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian        err = egl_tls_t::getError();
901ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian    }
902ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian    return err;
903518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
904518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
905c0ec5e2333b6350480851b8b48f000c78ea3f88aMichael Chockstatic __eglMustCastToProperFunctionPointerType findBuiltinWrapper(
906c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall        const char* procname) {
907c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall    const egl_connection_t* cnx = &gEGLImpl;
908c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall    void* proc = NULL;
909c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall
910c0ec5e2333b6350480851b8b48f000c78ea3f88aMichael Chock    proc = dlsym(cnx->libEgl, procname);
911c0ec5e2333b6350480851b8b48f000c78ea3f88aMichael Chock    if (proc) return (__eglMustCastToProperFunctionPointerType)proc;
912c0ec5e2333b6350480851b8b48f000c78ea3f88aMichael Chock
913c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall    proc = dlsym(cnx->libGles2, procname);
914c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall    if (proc) return (__eglMustCastToProperFunctionPointerType)proc;
915c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall
916c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall    proc = dlsym(cnx->libGles1, procname);
917c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall    if (proc) return (__eglMustCastToProperFunctionPointerType)proc;
918c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall
919c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall    return NULL;
920c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall}
921c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall
922518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian__eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname)
923518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{
924518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    // eglGetProcAddress() could be the very first function called
925518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    // in which case we must make sure we've initialized ourselves, this
926518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    // happens the first time egl_get_display() is called.
927518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
928518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    clearError();
929518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
930518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (egl_init_drivers() == EGL_FALSE) {
931518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        setError(EGL_BAD_PARAMETER, NULL);
932518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        return  NULL;
933518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
934518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
935e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian    if (FILTER_EXTENSIONS(procname)) {
936aca51c06f38155f1435fbc6944d7fc0a9bf1e4e9Jamie Gennis        return NULL;
937aca51c06f38155f1435fbc6944d7fc0a9bf1e4e9Jamie Gennis    }
938aca51c06f38155f1435fbc6944d7fc0a9bf1e4e9Jamie Gennis
939518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    __eglMustCastToProperFunctionPointerType addr;
940e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian    addr = findProcAddress(procname, sExtensionMap, NELEM(sExtensionMap));
941518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (addr) return addr;
942518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
943c0ec5e2333b6350480851b8b48f000c78ea3f88aMichael Chock    addr = findBuiltinWrapper(procname);
944c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall    if (addr) return addr;
945aca51c06f38155f1435fbc6944d7fc0a9bf1e4e9Jamie Gennis
946518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    // this protects accesses to sGLExtentionMap and sGLExtentionSlot
947518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    pthread_mutex_lock(&sExtensionMapMutex);
948518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
949518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        /*
950518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian         * Since eglGetProcAddress() is not associated to anything, it needs
951518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian         * to return a function pointer that "works" regardless of what
952518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian         * the current context is.
953518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian         *
954518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian         * For this reason, we return a "forwarder", a small stub that takes
955518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian         * care of calling the function associated with the context
956518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian         * currently bound.
957518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian         *
958518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian         * We first look for extensions we've already resolved, if we're seeing
959518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian         * this extension for the first time, we go through all our
960518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian         * implementations and call eglGetProcAddress() and record the
961518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian         * result in the appropriate implementation hooks and return the
962518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian         * address of the forwarder corresponding to that hook set.
963518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian         *
964518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian         */
965518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
966518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        const String8 name(procname);
967518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        addr = sGLExtentionMap.valueFor(name);
968518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        const int slot = sGLExtentionSlot;
969518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
970e6f43ddce78d6846af12550ff9193c5c6fe5844bSteve Block        ALOGE_IF(slot >= MAX_NUMBER_OF_GL_EXTENSIONS,
971518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian                "no more slots for eglGetProcAddress(\"%s\")",
972518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian                procname);
973518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
974518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        if (!addr && (slot < MAX_NUMBER_OF_GL_EXTENSIONS)) {
975518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian            bool found = false;
976ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian
977ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian            egl_connection_t* const cnx = &gEGLImpl;
978ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian            if (cnx->dso && cnx->egl.eglGetProcAddress) {
979ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian                // Extensions are independent of the bound context
98069d100762c7c26d8328f4bb61cfef026d3a69bbfluliuhui                addr =
9817773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian                cnx->hooks[egl_connection_t::GLESv1_INDEX]->ext.extensions[slot] =
9827773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian                cnx->hooks[egl_connection_t::GLESv2_INDEX]->ext.extensions[slot] =
983ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian                        cnx->egl.eglGetProcAddress(procname);
98469d100762c7c26d8328f4bb61cfef026d3a69bbfluliuhui                if (addr) found = true;
985518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian            }
986ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian
987518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian            if (found) {
988518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian                addr = gExtensionForwarders[slot];
989518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian                sGLExtentionMap.add(name, addr);
990518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian                sGLExtentionSlot++;
991518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian            }
992518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        }
993518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
994518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    pthread_mutex_unlock(&sExtensionMapMutex);
995518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    return addr;
996518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
997518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
99828ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennisclass FrameCompletionThread : public Thread {
99928ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennispublic:
100028ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis
100128ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis    static void queueSync(EGLSyncKHR sync) {
100228ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis        static sp<FrameCompletionThread> thread(new FrameCompletionThread);
100328ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis        static bool running = false;
100428ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis        if (!running) {
100528ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis            thread->run("GPUFrameCompletion");
100628ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis            running = true;
100728ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis        }
100828ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis        {
100928ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis            Mutex::Autolock lock(thread->mMutex);
101028ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis            ScopedTrace st(ATRACE_TAG, String8::format("kicked off frame %d",
101128ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis                    thread->mFramesQueued).string());
101228ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis            thread->mQueue.push_back(sync);
101328ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis            thread->mCondition.signal();
101428ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis            thread->mFramesQueued++;
101528ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis            ATRACE_INT("GPU Frames Outstanding", thread->mQueue.size());
101628ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis        }
101728ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis    }
101828ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis
101928ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennisprivate:
102028ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis    FrameCompletionThread() : mFramesQueued(0), mFramesCompleted(0) {}
102128ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis
102228ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis    virtual bool threadLoop() {
102328ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis        EGLSyncKHR sync;
102428ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis        uint32_t frameNum;
102528ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis        {
102628ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis            Mutex::Autolock lock(mMutex);
102728ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis            while (mQueue.isEmpty()) {
102828ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis                mCondition.wait(mMutex);
102928ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis            }
103028ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis            sync = mQueue[0];
103128ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis            frameNum = mFramesCompleted;
103228ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis        }
103328ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis        EGLDisplay dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
103428ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis        {
103528ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis            ScopedTrace st(ATRACE_TAG, String8::format("waiting for frame %d",
103628ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis                    frameNum).string());
103728ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis            EGLint result = eglClientWaitSyncKHR(dpy, sync, 0, EGL_FOREVER_KHR);
103828ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis            if (result == EGL_FALSE) {
103928ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis                ALOGE("FrameCompletion: error waiting for fence: %#x", eglGetError());
104028ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis            } else if (result == EGL_TIMEOUT_EXPIRED_KHR) {
104128ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis                ALOGE("FrameCompletion: timeout waiting for fence");
104228ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis            }
104328ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis            eglDestroySyncKHR(dpy, sync);
104428ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis        }
104528ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis        {
104628ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis            Mutex::Autolock lock(mMutex);
104728ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis            mQueue.removeAt(0);
104828ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis            mFramesCompleted++;
104928ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis            ATRACE_INT("GPU Frames Outstanding", mQueue.size());
105028ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis        }
105128ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis        return true;
105228ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis    }
105328ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis
105428ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis    uint32_t mFramesQueued;
105528ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis    uint32_t mFramesCompleted;
105628ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis    Vector<EGLSyncKHR> mQueue;
105728ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis    Condition mCondition;
105828ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis    Mutex mMutex;
105928ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis};
106028ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis
1061a894d082cfee8d12ee5913163a34ec5dc521d005Dan StozaEGLBoolean eglSwapBuffersWithDamageKHR(EGLDisplay dpy, EGLSurface draw,
1062a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza        EGLint *rects, EGLint n_rects)
1063518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{
10641c8e95cf86f2182986385bc1ee85f13f425f3a3aJamie Gennis    ATRACE_CALL();
1065518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    clearError();
1066518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1067b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    const egl_display_ptr dp = validate_display(dpy);
1068518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (!dp) return EGL_FALSE;
1069518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1070b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    SurfaceRef _s(dp.get(), draw);
10715b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian    if (!_s.get())
10725b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian        return setError(EGL_BAD_SURFACE, EGL_FALSE);
1073518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1074518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    egl_surface_t const * const s = get_surface(draw);
10757db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian
1076ed6d08b70d775852f4827471814c83eba3606aaaMathias Agopian    if (CC_UNLIKELY(dp->traceGpuCompletion)) {
1077ed6d08b70d775852f4827471814c83eba3606aaaMathias Agopian        EGLSyncKHR sync = eglCreateSyncKHR(dpy, EGL_SYNC_FENCE_KHR, NULL);
1078ed6d08b70d775852f4827471814c83eba3606aaaMathias Agopian        if (sync != EGL_NO_SYNC_KHR) {
1079ed6d08b70d775852f4827471814c83eba3606aaaMathias Agopian            FrameCompletionThread::queueSync(sync);
1080ed6d08b70d775852f4827471814c83eba3606aaaMathias Agopian        }
1081ed6d08b70d775852f4827471814c83eba3606aaaMathias Agopian    }
1082ed6d08b70d775852f4827471814c83eba3606aaaMathias Agopian
10837db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian    if (CC_UNLIKELY(dp->finishOnSwap)) {
10847db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian        uint32_t pixel;
10857db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian        egl_context_t * const c = get_context( egl_tls_t::getContext() );
10867db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian        if (c) {
10877db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian            // glReadPixels() ensures that the frame is complete
10887db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian            s->cnx->hooks[c->version]->gl.glReadPixels(0,0,1,1,
10897db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian                    GL_RGBA,GL_UNSIGNED_BYTE,&pixel);
10907db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian        }
10917db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian    }
10927db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian
1093a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza    if (n_rects == 0) {
1094a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza        return s->cnx->egl.eglSwapBuffers(dp->disp.dpy, s->surface);
1095a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza    }
1096a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza
1097a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza    Vector<android_native_rect_t> androidRects;
1098a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza    for (int r = 0; r < n_rects; ++r) {
1099a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza        int offset = r * 4;
1100a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza        int x = rects[offset];
1101a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza        int y = rects[offset + 1];
1102a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza        int width = rects[offset + 2];
1103a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza        int height = rects[offset + 3];
1104a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza        android_native_rect_t androidRect;
1105a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza        androidRect.left = x;
1106a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza        androidRect.top = y + height;
1107a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza        androidRect.right = x + width;
1108a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza        androidRect.bottom = y;
1109a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza        androidRects.push_back(androidRect);
1110a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza    }
1111a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza    native_window_set_surface_damage(s->win.get(), androidRects.array(),
1112a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza            androidRects.size());
1113a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza
1114a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza    if (s->cnx->egl.eglSwapBuffersWithDamageKHR) {
1115a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza        return s->cnx->egl.eglSwapBuffersWithDamageKHR(dp->disp.dpy, s->surface,
1116a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza                rects, n_rects);
1117a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza    } else {
1118a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza        return s->cnx->egl.eglSwapBuffers(dp->disp.dpy, s->surface);
1119a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza    }
1120a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza}
1121a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza
1122a894d082cfee8d12ee5913163a34ec5dc521d005Dan StozaEGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
1123a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza{
1124a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza    return eglSwapBuffersWithDamageKHR(dpy, surface, NULL, 0);
1125518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
1126518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1127518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglCopyBuffers(  EGLDisplay dpy, EGLSurface surface,
1128518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian                            NativePixmapType target)
1129518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{
1130518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    clearError();
1131518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1132b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    const egl_display_ptr dp = validate_display(dpy);
1133518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (!dp) return EGL_FALSE;
1134518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1135b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    SurfaceRef _s(dp.get(), surface);
11365b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian    if (!_s.get())
11375b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian        return setError(EGL_BAD_SURFACE, EGL_FALSE);
1138518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1139518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    egl_surface_t const * const s = get_surface(surface);
1140ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian    return s->cnx->egl.eglCopyBuffers(dp->disp.dpy, s->surface, target);
1141518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
1142518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1143518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianconst char* eglQueryString(EGLDisplay dpy, EGLint name)
1144518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{
1145518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    clearError();
1146518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1147b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    const egl_display_ptr dp = validate_display(dpy);
1148518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (!dp) return (const char *) NULL;
1149518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1150518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    switch (name) {
1151518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        case EGL_VENDOR:
11524b9511c16195a646242eff833b0af212933b6ecaMathias Agopian            return dp->getVendorString();
1153518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        case EGL_VERSION:
11544b9511c16195a646242eff833b0af212933b6ecaMathias Agopian            return dp->getVersionString();
1155518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        case EGL_EXTENSIONS:
11564b9511c16195a646242eff833b0af212933b6ecaMathias Agopian            return dp->getExtensionString();
1157518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        case EGL_CLIENT_APIS:
11584b9511c16195a646242eff833b0af212933b6ecaMathias Agopian            return dp->getClientApiString();
1159518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
1160518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    return setError(EGL_BAD_PARAMETER, (const char *)0);
1161518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
1162518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1163ca08833d5ea99130797e10ad68a651b50e99da74Mathias AgopianEGLAPI const char* eglQueryStringImplementationANDROID(EGLDisplay dpy, EGLint name)
1164ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian{
1165ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian    clearError();
1166ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian
1167ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian    const egl_display_ptr dp = validate_display(dpy);
1168ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian    if (!dp) return (const char *) NULL;
1169ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian
1170ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian    switch (name) {
1171ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian        case EGL_VENDOR:
1172ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian            return dp->disp.queryString.vendor;
1173ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian        case EGL_VERSION:
1174ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian            return dp->disp.queryString.version;
1175ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian        case EGL_EXTENSIONS:
1176ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian            return dp->disp.queryString.extensions;
1177ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian        case EGL_CLIENT_APIS:
1178ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian            return dp->disp.queryString.clientApi;
1179ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian    }
1180ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian    return setError(EGL_BAD_PARAMETER, (const char *)0);
1181ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian}
1182518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1183518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ----------------------------------------------------------------------------
1184518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// EGL 1.1
1185518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ----------------------------------------------------------------------------
1186518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1187518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglSurfaceAttrib(
1188518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value)
1189518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{
1190518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    clearError();
1191518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1192b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    const egl_display_ptr dp = validate_display(dpy);
1193518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (!dp) return EGL_FALSE;
1194518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1195b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    SurfaceRef _s(dp.get(), surface);
11965b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian    if (!_s.get())
11975b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian        return setError(EGL_BAD_SURFACE, EGL_FALSE);
1198518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1199518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    egl_surface_t const * const s = get_surface(surface);
1200ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos
120102b05da60a4669df44c9c0747ec262ec1862cf61Pablo Ceballos    if (attribute == EGL_FRONT_BUFFER_AUTO_REFRESH_ANDROID) {
1202f051ade9f0d880115b25cecf353a8c33812e4492Pablo Ceballos        int err = native_window_set_auto_refresh(s->win.get(),
1203f051ade9f0d880115b25cecf353a8c33812e4492Pablo Ceballos            value ? true : false);
1204f051ade9f0d880115b25cecf353a8c33812e4492Pablo Ceballos        return (err == NO_ERROR) ? EGL_TRUE :
1205f051ade9f0d880115b25cecf353a8c33812e4492Pablo Ceballos            setError(EGL_BAD_SURFACE, EGL_FALSE);
1206ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    }
1207ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos
1208518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (s->cnx->egl.eglSurfaceAttrib) {
1209518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        return s->cnx->egl.eglSurfaceAttrib(
1210ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian                dp->disp.dpy, s->surface, attribute, value);
1211518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
1212518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    return setError(EGL_BAD_SURFACE, EGL_FALSE);
1213518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
1214518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1215518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglBindTexImage(
1216518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        EGLDisplay dpy, EGLSurface surface, EGLint buffer)
1217518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{
1218518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    clearError();
1219518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1220b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    const egl_display_ptr dp = validate_display(dpy);
1221518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (!dp) return EGL_FALSE;
1222518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1223b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    SurfaceRef _s(dp.get(), surface);
12245b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian    if (!_s.get())
12255b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian        return setError(EGL_BAD_SURFACE, EGL_FALSE);
1226518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1227518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    egl_surface_t const * const s = get_surface(surface);
1228518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (s->cnx->egl.eglBindTexImage) {
1229518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        return s->cnx->egl.eglBindTexImage(
1230ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian                dp->disp.dpy, s->surface, buffer);
1231518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
1232518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    return setError(EGL_BAD_SURFACE, EGL_FALSE);
1233518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
1234518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1235518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglReleaseTexImage(
1236518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        EGLDisplay dpy, EGLSurface surface, EGLint buffer)
1237518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{
1238518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    clearError();
1239518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1240b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    const egl_display_ptr dp = validate_display(dpy);
1241518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (!dp) return EGL_FALSE;
1242518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1243b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    SurfaceRef _s(dp.get(), surface);
12445b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian    if (!_s.get())
12455b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian        return setError(EGL_BAD_SURFACE, EGL_FALSE);
1246518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1247518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    egl_surface_t const * const s = get_surface(surface);
1248518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (s->cnx->egl.eglReleaseTexImage) {
1249518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        return s->cnx->egl.eglReleaseTexImage(
1250ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian                dp->disp.dpy, s->surface, buffer);
1251518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
1252518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    return setError(EGL_BAD_SURFACE, EGL_FALSE);
1253518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
1254518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1255518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint interval)
1256518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{
1257518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    clearError();
1258518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1259b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    const egl_display_ptr dp = validate_display(dpy);
1260518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (!dp) return EGL_FALSE;
1261518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1262518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    EGLBoolean res = EGL_TRUE;
1263ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian    egl_connection_t* const cnx = &gEGLImpl;
1264ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian    if (cnx->dso && cnx->egl.eglSwapInterval) {
1265ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian        res = cnx->egl.eglSwapInterval(dp->disp.dpy, interval);
1266518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
1267ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian
1268518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    return res;
1269518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
1270518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1271518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1272518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ----------------------------------------------------------------------------
1273518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// EGL 1.2
1274518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ----------------------------------------------------------------------------
1275518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1276518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglWaitClient(void)
1277518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{
1278518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    clearError();
1279518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1280ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian    egl_connection_t* const cnx = &gEGLImpl;
1281ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian    if (!cnx->dso)
1282ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian        return setError(EGL_BAD_CONTEXT, EGL_FALSE);
1283ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian
1284ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian    EGLBoolean res;
1285ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian    if (cnx->egl.eglWaitClient) {
1286ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian        res = cnx->egl.eglWaitClient();
1287ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian    } else {
1288ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian        res = cnx->egl.eglWaitGL();
1289518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
1290518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    return res;
1291518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
1292518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1293518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglBindAPI(EGLenum api)
1294518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{
1295518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    clearError();
1296518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1297518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (egl_init_drivers() == EGL_FALSE) {
1298518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        return setError(EGL_BAD_PARAMETER, EGL_FALSE);
1299518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
1300518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1301518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    // bind this API on all EGLs
1302518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    EGLBoolean res = EGL_TRUE;
1303ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian    egl_connection_t* const cnx = &gEGLImpl;
1304ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian    if (cnx->dso && cnx->egl.eglBindAPI) {
1305ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian        res = cnx->egl.eglBindAPI(api);
1306518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
1307518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    return res;
1308518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
1309518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1310518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLenum eglQueryAPI(void)
1311518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{
1312518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    clearError();
1313518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1314518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (egl_init_drivers() == EGL_FALSE) {
1315518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        return setError(EGL_BAD_PARAMETER, EGL_FALSE);
1316518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
1317518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1318ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian    egl_connection_t* const cnx = &gEGLImpl;
1319ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian    if (cnx->dso && cnx->egl.eglQueryAPI) {
1320ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian        return cnx->egl.eglQueryAPI();
1321518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
1322ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian
1323518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    // or, it can only be OpenGL ES
1324518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    return EGL_OPENGL_ES_API;
1325518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
1326518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1327518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglReleaseThread(void)
1328518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{
1329518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    clearError();
1330518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1331518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    // If there is context bound to the thread, release it
1332fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian    egl_display_t::loseCurrent(get_context(getContext()));
1333518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1334ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian    egl_connection_t* const cnx = &gEGLImpl;
1335ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian    if (cnx->dso && cnx->egl.eglReleaseThread) {
1336ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian        cnx->egl.eglReleaseThread();
1337518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
1338518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    egl_tls_t::clearTLS();
1339518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    return EGL_TRUE;
1340518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
1341518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1342518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLSurface eglCreatePbufferFromClientBuffer(
1343518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian          EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer,
1344518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian          EGLConfig config, const EGLint *attrib_list)
1345518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{
1346518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    clearError();
1347518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1348b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    egl_connection_t* cnx = NULL;
1349b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    const egl_display_ptr dp = validate_display_connection(dpy, cnx);
1350b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    if (!dp) return EGL_FALSE;
1351518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (cnx->egl.eglCreatePbufferFromClientBuffer) {
1352518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        return cnx->egl.eglCreatePbufferFromClientBuffer(
13537773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian                dp->disp.dpy, buftype, buffer, config, attrib_list);
1354518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
1355518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    return setError(EGL_BAD_CONFIG, EGL_NO_SURFACE);
1356518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
1357518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1358518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ----------------------------------------------------------------------------
1359518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// EGL_EGLEXT_VERSION 3
1360518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ----------------------------------------------------------------------------
1361518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1362518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglLockSurfaceKHR(EGLDisplay dpy, EGLSurface surface,
1363518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        const EGLint *attrib_list)
1364518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{
1365518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    clearError();
1366518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1367b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    const egl_display_ptr dp = validate_display(dpy);
1368518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (!dp) return EGL_FALSE;
1369518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1370b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    SurfaceRef _s(dp.get(), surface);
13715b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian    if (!_s.get())
13725b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian        return setError(EGL_BAD_SURFACE, EGL_FALSE);
1373518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1374518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    egl_surface_t const * const s = get_surface(surface);
1375518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (s->cnx->egl.eglLockSurfaceKHR) {
1376518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        return s->cnx->egl.eglLockSurfaceKHR(
1377ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian                dp->disp.dpy, s->surface, attrib_list);
1378518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
1379518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    return setError(EGL_BAD_DISPLAY, EGL_FALSE);
1380518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
1381518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1382518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglUnlockSurfaceKHR(EGLDisplay dpy, EGLSurface surface)
1383518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{
1384518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    clearError();
1385518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1386b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    const egl_display_ptr dp = validate_display(dpy);
1387518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (!dp) return EGL_FALSE;
1388518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1389b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    SurfaceRef _s(dp.get(), surface);
13905b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian    if (!_s.get())
13915b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian        return setError(EGL_BAD_SURFACE, EGL_FALSE);
1392518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1393518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    egl_surface_t const * const s = get_surface(surface);
1394518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (s->cnx->egl.eglUnlockSurfaceKHR) {
1395ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian        return s->cnx->egl.eglUnlockSurfaceKHR(dp->disp.dpy, s->surface);
1396518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
1397518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    return setError(EGL_BAD_DISPLAY, EGL_FALSE);
1398518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
1399518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1400518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target,
1401518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian        EGLClientBuffer buffer, const EGLint *attrib_list)
1402518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{
1403518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    clearError();
1404518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1405b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    const egl_display_ptr dp = validate_display(dpy);
1406518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (!dp) return EGL_NO_IMAGE_KHR;
1407518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1408b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    ContextRef _c(dp.get(), ctx);
14097c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian    egl_context_t * const c = _c.get();
1410518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
14117c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian    EGLImageKHR result = EGL_NO_IMAGE_KHR;
14127c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian    egl_connection_t* const cnx = &gEGLImpl;
14137c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian    if (cnx->dso && cnx->egl.eglCreateImageKHR) {
14147c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian        result = cnx->egl.eglCreateImageKHR(
14157c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian                dp->disp.dpy,
14167c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian                c ? c->context : EGL_NO_CONTEXT,
14177c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian                target, buffer, attrib_list);
1418518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
14197c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian    return result;
1420518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
1421518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1422518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR img)
1423518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{
1424518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    clearError();
1425518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1426b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    const egl_display_ptr dp = validate_display(dpy);
1427518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (!dp) return EGL_FALSE;
1428518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1429646a5c593f9819dc5da6a1ec859bc70cb7ba096fSteven Holte    EGLBoolean result = EGL_FALSE;
1430ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian    egl_connection_t* const cnx = &gEGLImpl;
14317c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian    if (cnx->dso && cnx->egl.eglDestroyImageKHR) {
1432646a5c593f9819dc5da6a1ec859bc70cb7ba096fSteven Holte        result = cnx->egl.eglDestroyImageKHR(dp->disp.dpy, img);
1433518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
1434646a5c593f9819dc5da6a1ec859bc70cb7ba096fSteven Holte    return result;
1435518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
1436518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1437518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ----------------------------------------------------------------------------
1438518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// EGL_EGLEXT_VERSION 5
1439518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ----------------------------------------------------------------------------
1440518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1441518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1442518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLSyncKHR eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list)
1443518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{
1444518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    clearError();
1445518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1446b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    const egl_display_ptr dp = validate_display(dpy);
1447518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (!dp) return EGL_NO_SYNC_KHR;
1448518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1449518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    EGLSyncKHR result = EGL_NO_SYNC_KHR;
14507c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian    egl_connection_t* const cnx = &gEGLImpl;
14517c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian    if (cnx->dso && cnx->egl.eglCreateSyncKHR) {
14527c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian        result = cnx->egl.eglCreateSyncKHR(dp->disp.dpy, type, attrib_list);
1453518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
14547c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian    return result;
1455518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
1456518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1457518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync)
1458518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{
1459518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    clearError();
1460518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1461b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    const egl_display_ptr dp = validate_display(dpy);
1462518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (!dp) return EGL_FALSE;
1463518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1464518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    EGLBoolean result = EGL_FALSE;
14657c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian    egl_connection_t* const cnx = &gEGLImpl;
14667c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian    if (cnx->dso && cnx->egl.eglDestroySyncKHR) {
14677c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian        result = cnx->egl.eglDestroySyncKHR(dp->disp.dpy, sync);
1468518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
1469518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    return result;
1470518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
1471518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1472e9b3dfb7d5cc233747407381a51a081c335dc076Mathias AgopianEGLBoolean eglSignalSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode) {
1473e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian    clearError();
1474e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian
1475e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian    const egl_display_ptr dp = validate_display(dpy);
1476e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian    if (!dp) return EGL_FALSE;
1477e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian
1478e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian    EGLBoolean result = EGL_FALSE;
1479e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian    egl_connection_t* const cnx = &gEGLImpl;
1480e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian    if (cnx->dso && cnx->egl.eglSignalSyncKHR) {
1481e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian        result = cnx->egl.eglSignalSyncKHR(
1482e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian                dp->disp.dpy, sync, mode);
1483e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian    }
1484e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian    return result;
1485e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian}
1486e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian
14877c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias AgopianEGLint eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync,
14887c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian        EGLint flags, EGLTimeKHR timeout)
1489518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{
1490518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    clearError();
1491518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1492b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    const egl_display_ptr dp = validate_display(dpy);
1493518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (!dp) return EGL_FALSE;
1494518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
14957c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian    EGLBoolean result = EGL_FALSE;
14967c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian    egl_connection_t* const cnx = &gEGLImpl;
14977c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian    if (cnx->dso && cnx->egl.eglClientWaitSyncKHR) {
14987c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian        result = cnx->egl.eglClientWaitSyncKHR(
14997c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian                dp->disp.dpy, sync, flags, timeout);
1500518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
15017c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian    return result;
1502518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
1503518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
15047c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias AgopianEGLBoolean eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync,
15057c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian        EGLint attribute, EGLint *value)
1506518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{
1507518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    clearError();
1508518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1509b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall    const egl_display_ptr dp = validate_display(dpy);
1510518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    if (!dp) return EGL_FALSE;
1511518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
15127c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian    EGLBoolean result = EGL_FALSE;
15137c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian    egl_connection_t* const cnx = &gEGLImpl;
15147c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian    if (cnx->dso && cnx->egl.eglGetSyncAttribKHR) {
15157c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian        result = cnx->egl.eglGetSyncAttribKHR(
15167c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian                dp->disp.dpy, sync, attribute, value);
1517518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian    }
15187c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian    return result;
1519518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}
1520518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
1521000d88f02680607f45f600dde4e53ebe5b3895abSeason LiEGLStreamKHR eglCreateStreamKHR(EGLDisplay dpy, const EGLint *attrib_list)
1522000d88f02680607f45f600dde4e53ebe5b3895abSeason Li{
1523000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    clearError();
1524000d88f02680607f45f600dde4e53ebe5b3895abSeason Li
1525000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    const egl_display_ptr dp = validate_display(dpy);
1526000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    if (!dp) return EGL_NO_STREAM_KHR;
1527000d88f02680607f45f600dde4e53ebe5b3895abSeason Li
1528000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    EGLStreamKHR result = EGL_NO_STREAM_KHR;
1529000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    egl_connection_t* const cnx = &gEGLImpl;
1530000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    if (cnx->dso && cnx->egl.eglCreateStreamKHR) {
1531000d88f02680607f45f600dde4e53ebe5b3895abSeason Li        result = cnx->egl.eglCreateStreamKHR(
1532000d88f02680607f45f600dde4e53ebe5b3895abSeason Li                dp->disp.dpy, attrib_list);
1533000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    }
1534000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    return result;
1535000d88f02680607f45f600dde4e53ebe5b3895abSeason Li}
1536000d88f02680607f45f600dde4e53ebe5b3895abSeason Li
1537000d88f02680607f45f600dde4e53ebe5b3895abSeason LiEGLBoolean eglDestroyStreamKHR(EGLDisplay dpy, EGLStreamKHR stream)
1538000d88f02680607f45f600dde4e53ebe5b3895abSeason Li{
1539000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    clearError();
1540000d88f02680607f45f600dde4e53ebe5b3895abSeason Li
1541000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    const egl_display_ptr dp = validate_display(dpy);
1542000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    if (!dp) return EGL_FALSE;
1543000d88f02680607f45f600dde4e53ebe5b3895abSeason Li
1544000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    EGLBoolean result = EGL_FALSE;
1545000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    egl_connection_t* const cnx = &gEGLImpl;
1546000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    if (cnx->dso && cnx->egl.eglDestroyStreamKHR) {
1547000d88f02680607f45f600dde4e53ebe5b3895abSeason Li        result = cnx->egl.eglDestroyStreamKHR(
1548000d88f02680607f45f600dde4e53ebe5b3895abSeason Li                dp->disp.dpy, stream);
1549000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    }
1550000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    return result;
1551000d88f02680607f45f600dde4e53ebe5b3895abSeason Li}
1552000d88f02680607f45f600dde4e53ebe5b3895abSeason Li
1553000d88f02680607f45f600dde4e53ebe5b3895abSeason LiEGLBoolean eglStreamAttribKHR(EGLDisplay dpy, EGLStreamKHR stream,
1554000d88f02680607f45f600dde4e53ebe5b3895abSeason Li        EGLenum attribute, EGLint value)
1555000d88f02680607f45f600dde4e53ebe5b3895abSeason Li{
1556000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    clearError();
1557000d88f02680607f45f600dde4e53ebe5b3895abSeason Li
1558000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    const egl_display_ptr dp = validate_display(dpy);
1559000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    if (!dp) return EGL_FALSE;
1560000d88f02680607f45f600dde4e53ebe5b3895abSeason Li
1561000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    EGLBoolean result = EGL_FALSE;
1562000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    egl_connection_t* const cnx = &gEGLImpl;
1563000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    if (cnx->dso && cnx->egl.eglStreamAttribKHR) {
1564000d88f02680607f45f600dde4e53ebe5b3895abSeason Li        result = cnx->egl.eglStreamAttribKHR(
1565000d88f02680607f45f600dde4e53ebe5b3895abSeason Li                dp->disp.dpy, stream, attribute, value);
1566000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    }
1567000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    return result;
1568000d88f02680607f45f600dde4e53ebe5b3895abSeason Li}
1569000d88f02680607f45f600dde4e53ebe5b3895abSeason Li
1570000d88f02680607f45f600dde4e53ebe5b3895abSeason LiEGLBoolean eglQueryStreamKHR(EGLDisplay dpy, EGLStreamKHR stream,
1571000d88f02680607f45f600dde4e53ebe5b3895abSeason Li        EGLenum attribute, EGLint *value)
1572000d88f02680607f45f600dde4e53ebe5b3895abSeason Li{
1573000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    clearError();
1574000d88f02680607f45f600dde4e53ebe5b3895abSeason Li
1575000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    const egl_display_ptr dp = validate_display(dpy);
1576000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    if (!dp) return EGL_FALSE;
1577000d88f02680607f45f600dde4e53ebe5b3895abSeason Li
1578000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    EGLBoolean result = EGL_FALSE;
1579000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    egl_connection_t* const cnx = &gEGLImpl;
1580000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    if (cnx->dso && cnx->egl.eglQueryStreamKHR) {
1581000d88f02680607f45f600dde4e53ebe5b3895abSeason Li        result = cnx->egl.eglQueryStreamKHR(
1582000d88f02680607f45f600dde4e53ebe5b3895abSeason Li                dp->disp.dpy, stream, attribute, value);
1583000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    }
1584000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    return result;
1585000d88f02680607f45f600dde4e53ebe5b3895abSeason Li}
1586000d88f02680607f45f600dde4e53ebe5b3895abSeason Li
1587000d88f02680607f45f600dde4e53ebe5b3895abSeason LiEGLBoolean eglQueryStreamu64KHR(EGLDisplay dpy, EGLStreamKHR stream,
1588000d88f02680607f45f600dde4e53ebe5b3895abSeason Li        EGLenum attribute, EGLuint64KHR *value)
1589000d88f02680607f45f600dde4e53ebe5b3895abSeason Li{
1590000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    clearError();
1591000d88f02680607f45f600dde4e53ebe5b3895abSeason Li
1592000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    const egl_display_ptr dp = validate_display(dpy);
1593000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    if (!dp) return EGL_FALSE;
1594000d88f02680607f45f600dde4e53ebe5b3895abSeason Li
1595000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    EGLBoolean result = EGL_FALSE;
1596000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    egl_connection_t* const cnx = &gEGLImpl;
1597000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    if (cnx->dso && cnx->egl.eglQueryStreamu64KHR) {
1598000d88f02680607f45f600dde4e53ebe5b3895abSeason Li        result = cnx->egl.eglQueryStreamu64KHR(
1599000d88f02680607f45f600dde4e53ebe5b3895abSeason Li                dp->disp.dpy, stream, attribute, value);
1600000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    }
1601000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    return result;
1602000d88f02680607f45f600dde4e53ebe5b3895abSeason Li}
1603000d88f02680607f45f600dde4e53ebe5b3895abSeason Li
1604000d88f02680607f45f600dde4e53ebe5b3895abSeason LiEGLBoolean eglQueryStreamTimeKHR(EGLDisplay dpy, EGLStreamKHR stream,
1605000d88f02680607f45f600dde4e53ebe5b3895abSeason Li        EGLenum attribute, EGLTimeKHR *value)
1606000d88f02680607f45f600dde4e53ebe5b3895abSeason Li{
1607000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    clearError();
1608000d88f02680607f45f600dde4e53ebe5b3895abSeason Li
1609000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    const egl_display_ptr dp = validate_display(dpy);
1610000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    if (!dp) return EGL_FALSE;
1611000d88f02680607f45f600dde4e53ebe5b3895abSeason Li
1612000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    EGLBoolean result = EGL_FALSE;
1613000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    egl_connection_t* const cnx = &gEGLImpl;
1614000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    if (cnx->dso && cnx->egl.eglQueryStreamTimeKHR) {
1615000d88f02680607f45f600dde4e53ebe5b3895abSeason Li        result = cnx->egl.eglQueryStreamTimeKHR(
1616000d88f02680607f45f600dde4e53ebe5b3895abSeason Li                dp->disp.dpy, stream, attribute, value);
1617000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    }
1618000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    return result;
1619000d88f02680607f45f600dde4e53ebe5b3895abSeason Li}
1620000d88f02680607f45f600dde4e53ebe5b3895abSeason Li
1621000d88f02680607f45f600dde4e53ebe5b3895abSeason LiEGLSurface eglCreateStreamProducerSurfaceKHR(EGLDisplay dpy, EGLConfig config,
1622000d88f02680607f45f600dde4e53ebe5b3895abSeason Li        EGLStreamKHR stream, const EGLint *attrib_list)
1623000d88f02680607f45f600dde4e53ebe5b3895abSeason Li{
1624000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    clearError();
1625000d88f02680607f45f600dde4e53ebe5b3895abSeason Li
1626000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    egl_display_ptr dp = validate_display(dpy);
1627000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    if (!dp) return EGL_NO_SURFACE;
1628000d88f02680607f45f600dde4e53ebe5b3895abSeason Li
1629000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    egl_connection_t* const cnx = &gEGLImpl;
1630000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    if (cnx->dso && cnx->egl.eglCreateStreamProducerSurfaceKHR) {
1631000d88f02680607f45f600dde4e53ebe5b3895abSeason Li        EGLSurface surface = cnx->egl.eglCreateStreamProducerSurfaceKHR(
1632000d88f02680607f45f600dde4e53ebe5b3895abSeason Li                dp->disp.dpy, config, stream, attrib_list);
1633000d88f02680607f45f600dde4e53ebe5b3895abSeason Li        if (surface != EGL_NO_SURFACE) {
1634000d88f02680607f45f600dde4e53ebe5b3895abSeason Li            egl_surface_t* s = new egl_surface_t(dp.get(), config, NULL,
1635000d88f02680607f45f600dde4e53ebe5b3895abSeason Li                    surface, cnx);
1636000d88f02680607f45f600dde4e53ebe5b3895abSeason Li            return s;
1637000d88f02680607f45f600dde4e53ebe5b3895abSeason Li        }
1638000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    }
1639000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    return EGL_NO_SURFACE;
1640000d88f02680607f45f600dde4e53ebe5b3895abSeason Li}
1641000d88f02680607f45f600dde4e53ebe5b3895abSeason Li
1642000d88f02680607f45f600dde4e53ebe5b3895abSeason LiEGLBoolean eglStreamConsumerGLTextureExternalKHR(EGLDisplay dpy,
1643000d88f02680607f45f600dde4e53ebe5b3895abSeason Li        EGLStreamKHR stream)
1644000d88f02680607f45f600dde4e53ebe5b3895abSeason Li{
1645000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    clearError();
1646000d88f02680607f45f600dde4e53ebe5b3895abSeason Li
1647000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    const egl_display_ptr dp = validate_display(dpy);
1648000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    if (!dp) return EGL_FALSE;
1649000d88f02680607f45f600dde4e53ebe5b3895abSeason Li
1650000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    EGLBoolean result = EGL_FALSE;
1651000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    egl_connection_t* const cnx = &gEGLImpl;
1652000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    if (cnx->dso && cnx->egl.eglStreamConsumerGLTextureExternalKHR) {
1653000d88f02680607f45f600dde4e53ebe5b3895abSeason Li        result = cnx->egl.eglStreamConsumerGLTextureExternalKHR(
1654000d88f02680607f45f600dde4e53ebe5b3895abSeason Li                dp->disp.dpy, stream);
1655000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    }
1656000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    return result;
1657000d88f02680607f45f600dde4e53ebe5b3895abSeason Li}
1658000d88f02680607f45f600dde4e53ebe5b3895abSeason Li
1659000d88f02680607f45f600dde4e53ebe5b3895abSeason LiEGLBoolean eglStreamConsumerAcquireKHR(EGLDisplay dpy,
1660000d88f02680607f45f600dde4e53ebe5b3895abSeason Li        EGLStreamKHR stream)
1661000d88f02680607f45f600dde4e53ebe5b3895abSeason Li{
1662000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    clearError();
1663000d88f02680607f45f600dde4e53ebe5b3895abSeason Li
1664000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    const egl_display_ptr dp = validate_display(dpy);
1665000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    if (!dp) return EGL_FALSE;
1666000d88f02680607f45f600dde4e53ebe5b3895abSeason Li
1667000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    EGLBoolean result = EGL_FALSE;
1668000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    egl_connection_t* const cnx = &gEGLImpl;
1669000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    if (cnx->dso && cnx->egl.eglStreamConsumerAcquireKHR) {
1670000d88f02680607f45f600dde4e53ebe5b3895abSeason Li        result = cnx->egl.eglStreamConsumerAcquireKHR(
1671000d88f02680607f45f600dde4e53ebe5b3895abSeason Li                dp->disp.dpy, stream);
1672000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    }
1673000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    return result;
1674000d88f02680607f45f600dde4e53ebe5b3895abSeason Li}
1675000d88f02680607f45f600dde4e53ebe5b3895abSeason Li
1676000d88f02680607f45f600dde4e53ebe5b3895abSeason LiEGLBoolean eglStreamConsumerReleaseKHR(EGLDisplay dpy,
1677000d88f02680607f45f600dde4e53ebe5b3895abSeason Li        EGLStreamKHR stream)
1678000d88f02680607f45f600dde4e53ebe5b3895abSeason Li{
1679000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    clearError();
1680000d88f02680607f45f600dde4e53ebe5b3895abSeason Li
1681000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    const egl_display_ptr dp = validate_display(dpy);
1682000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    if (!dp) return EGL_FALSE;
1683000d88f02680607f45f600dde4e53ebe5b3895abSeason Li
1684000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    EGLBoolean result = EGL_FALSE;
1685000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    egl_connection_t* const cnx = &gEGLImpl;
1686000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    if (cnx->dso && cnx->egl.eglStreamConsumerReleaseKHR) {
1687000d88f02680607f45f600dde4e53ebe5b3895abSeason Li        result = cnx->egl.eglStreamConsumerReleaseKHR(
1688000d88f02680607f45f600dde4e53ebe5b3895abSeason Li                dp->disp.dpy, stream);
1689000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    }
1690000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    return result;
1691000d88f02680607f45f600dde4e53ebe5b3895abSeason Li}
1692000d88f02680607f45f600dde4e53ebe5b3895abSeason Li
1693000d88f02680607f45f600dde4e53ebe5b3895abSeason LiEGLNativeFileDescriptorKHR eglGetStreamFileDescriptorKHR(
1694000d88f02680607f45f600dde4e53ebe5b3895abSeason Li        EGLDisplay dpy, EGLStreamKHR stream)
1695000d88f02680607f45f600dde4e53ebe5b3895abSeason Li{
1696000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    clearError();
1697000d88f02680607f45f600dde4e53ebe5b3895abSeason Li
1698000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    const egl_display_ptr dp = validate_display(dpy);
1699000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    if (!dp) return EGL_NO_FILE_DESCRIPTOR_KHR;
1700000d88f02680607f45f600dde4e53ebe5b3895abSeason Li
1701000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    EGLNativeFileDescriptorKHR result = EGL_NO_FILE_DESCRIPTOR_KHR;
1702000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    egl_connection_t* const cnx = &gEGLImpl;
1703000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    if (cnx->dso && cnx->egl.eglGetStreamFileDescriptorKHR) {
1704000d88f02680607f45f600dde4e53ebe5b3895abSeason Li        result = cnx->egl.eglGetStreamFileDescriptorKHR(
1705000d88f02680607f45f600dde4e53ebe5b3895abSeason Li                dp->disp.dpy, stream);
1706000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    }
1707000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    return result;
1708000d88f02680607f45f600dde4e53ebe5b3895abSeason Li}
1709000d88f02680607f45f600dde4e53ebe5b3895abSeason Li
1710000d88f02680607f45f600dde4e53ebe5b3895abSeason LiEGLStreamKHR eglCreateStreamFromFileDescriptorKHR(
1711000d88f02680607f45f600dde4e53ebe5b3895abSeason Li        EGLDisplay dpy, EGLNativeFileDescriptorKHR file_descriptor)
1712000d88f02680607f45f600dde4e53ebe5b3895abSeason Li{
1713000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    clearError();
1714000d88f02680607f45f600dde4e53ebe5b3895abSeason Li
1715000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    const egl_display_ptr dp = validate_display(dpy);
1716000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    if (!dp) return EGL_NO_STREAM_KHR;
1717000d88f02680607f45f600dde4e53ebe5b3895abSeason Li
1718000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    EGLStreamKHR result = EGL_NO_STREAM_KHR;
1719000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    egl_connection_t* const cnx = &gEGLImpl;
1720000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    if (cnx->dso && cnx->egl.eglCreateStreamFromFileDescriptorKHR) {
1721000d88f02680607f45f600dde4e53ebe5b3895abSeason Li        result = cnx->egl.eglCreateStreamFromFileDescriptorKHR(
1722000d88f02680607f45f600dde4e53ebe5b3895abSeason Li                dp->disp.dpy, file_descriptor);
1723000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    }
1724000d88f02680607f45f600dde4e53ebe5b3895abSeason Li    return result;
1725000d88f02680607f45f600dde4e53ebe5b3895abSeason Li}
1726000d88f02680607f45f600dde4e53ebe5b3895abSeason Li
1727518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ----------------------------------------------------------------------------
17282bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian// EGL_EGLEXT_VERSION 15
1729518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ----------------------------------------------------------------------------
1730518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian
17312bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias AgopianEGLint eglWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags) {
1732331841b96b92646c93c87627c03f77b892f711cdJamie Gennis    clearError();
1733331841b96b92646c93c87627c03f77b892f711cdJamie Gennis    const egl_display_ptr dp = validate_display(dpy);
17342bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian    if (!dp) return EGL_FALSE;
17352bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian    EGLint result = EGL_FALSE;
1736331841b96b92646c93c87627c03f77b892f711cdJamie Gennis    egl_connection_t* const cnx = &gEGLImpl;
17372bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian    if (cnx->dso && cnx->egl.eglWaitSyncKHR) {
17382bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian        result = cnx->egl.eglWaitSyncKHR(dp->disp.dpy, sync, flags);
1739331841b96b92646c93c87627c03f77b892f711cdJamie Gennis    }
1740331841b96b92646c93c87627c03f77b892f711cdJamie Gennis    return result;
1741331841b96b92646c93c87627c03f77b892f711cdJamie Gennis}
17421c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang
17432bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian// ----------------------------------------------------------------------------
17442bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian// ANDROID extensions
17452bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian// ----------------------------------------------------------------------------
17462bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian
17472bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias AgopianEGLint eglDupNativeFenceFDANDROID(EGLDisplay dpy, EGLSyncKHR sync)
1748010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis{
1749010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis    clearError();
1750010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis
1751010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis    const egl_display_ptr dp = validate_display(dpy);
1752010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis    if (!dp) return EGL_NO_NATIVE_FENCE_FD_ANDROID;
1753010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis
17542bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian    EGLint result = EGL_NO_NATIVE_FENCE_FD_ANDROID;
1755010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis    egl_connection_t* const cnx = &gEGLImpl;
17562bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian    if (cnx->dso && cnx->egl.eglDupNativeFenceFDANDROID) {
17572bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian        result = cnx->egl.eglDupNativeFenceFDANDROID(dp->disp.dpy, sync);
1758010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis    }
1759010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis    return result;
1760010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis}
1761010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis
17627284145d564fa8a422a8e564a38c730fb4a2962bAndy McFaddenEGLBoolean eglPresentationTimeANDROID(EGLDisplay dpy, EGLSurface surface,
17637284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden        EGLnsecsANDROID time)
17647284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden{
17657284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden    clearError();
17667284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden
17677284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden    const egl_display_ptr dp = validate_display(dpy);
17687284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden    if (!dp) {
17697284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden        return EGL_FALSE;
17707284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden    }
17717284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden
17727284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden    SurfaceRef _s(dp.get(), surface);
17737284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden    if (!_s.get()) {
17747284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden        setError(EGL_BAD_SURFACE, EGL_FALSE);
17757284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden        return EGL_FALSE;
17767284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden    }
17777284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden
17787284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden    egl_surface_t const * const s = get_surface(surface);
17797284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden    native_window_set_buffers_timestamp(s->win.get(), time);
17807284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden
17817284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden    return EGL_TRUE;
17827284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden}
17837284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden
178405249fc2d0da542efa46acdb7b10a619a68538e1Craig DonnerEGLClientBuffer eglCreateNativeClientBufferANDROID(const EGLint *attrib_list)
178505249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner{
178605249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner    clearError();
178705249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner
178805249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner    int usage = 0;
178905249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner    uint32_t width = 0;
179005249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner    uint32_t height = 0;
179105249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner    uint32_t format = 0;
179205249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner    uint32_t red_size = 0;
179305249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner    uint32_t green_size = 0;
179405249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner    uint32_t blue_size = 0;
179505249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner    uint32_t alpha_size = 0;
179605249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner
179705249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner#define GET_POSITIVE_VALUE(case_name, target) \
179805249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner    case case_name: \
179905249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner        if (value > 0) { \
180005249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner            target = value; \
180105249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner        } else { \
180205249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner            return setError(EGL_BAD_PARAMETER, (EGLClientBuffer)0); \
180305249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner        } \
180405249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner        break
180505249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner
180605249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner    if (attrib_list) {
180705249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner        while (*attrib_list != EGL_NONE) {
180805249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner            GLint attr = *attrib_list++;
180905249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner            GLint value = *attrib_list++;
181005249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner            switch (attr) {
181105249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner                GET_POSITIVE_VALUE(EGL_WIDTH, width);
181205249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner                GET_POSITIVE_VALUE(EGL_HEIGHT, height);
181305249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner                GET_POSITIVE_VALUE(EGL_RED_SIZE, red_size);
181405249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner                GET_POSITIVE_VALUE(EGL_GREEN_SIZE, green_size);
181505249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner                GET_POSITIVE_VALUE(EGL_BLUE_SIZE, blue_size);
181605249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner                GET_POSITIVE_VALUE(EGL_ALPHA_SIZE, alpha_size);
181705249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner                case EGL_NATIVE_BUFFER_USAGE_ANDROID:
181805249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner                    if (value & EGL_NATIVE_BUFFER_USAGE_PROTECTED_BIT_ANDROID) {
181905249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner                        usage |= GRALLOC_USAGE_PROTECTED;
182005249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner                    }
18218cfae6dc5c7467642a307eb7e12e510210ef154cCraig Donner                    if (value & EGL_NATIVE_BUFFER_USAGE_RENDERBUFFER_BIT_ANDROID) {
182205249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner                        usage |= GRALLOC_USAGE_HW_RENDER;
182305249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner                    }
18248cfae6dc5c7467642a307eb7e12e510210ef154cCraig Donner                    if (value & EGL_NATIVE_BUFFER_USAGE_TEXTURE_BIT_ANDROID) {
182505249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner                        usage |= GRALLOC_USAGE_HW_TEXTURE;
182605249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner                    }
182705249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner                    // The buffer must be used for either a texture or a
182805249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner                    // renderbuffer.
18298cfae6dc5c7467642a307eb7e12e510210ef154cCraig Donner                    if ((value & EGL_NATIVE_BUFFER_USAGE_RENDERBUFFER_BIT_ANDROID) &&
18308cfae6dc5c7467642a307eb7e12e510210ef154cCraig Donner                        (value & EGL_NATIVE_BUFFER_USAGE_TEXTURE_BIT_ANDROID)) {
183105249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner                        return setError(EGL_BAD_PARAMETER, (EGLClientBuffer)0);
183205249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner                    }
183305249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner                    break;
183405249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner                default:
183505249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner                    return setError(EGL_BAD_PARAMETER, (EGLClientBuffer)0);
183605249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner            }
183705249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner        }
183805249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner    }
183905249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner#undef GET_POSITIVE_VALUE
184005249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner
184105249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner    // Validate format.
184205249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner    if (red_size == 8 && green_size == 8 && blue_size == 8) {
184305249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner        if (alpha_size == 8) {
184405249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner            format = HAL_PIXEL_FORMAT_RGBA_8888;
184505249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner        } else {
184605249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner            format = HAL_PIXEL_FORMAT_RGB_888;
184705249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner        }
184805249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner    } else if (red_size == 5 && green_size == 6 && blue_size == 5 &&
184905249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner               alpha_size == 0) {
185005249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner        format == HAL_PIXEL_FORMAT_RGB_565;
185105249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner    } else {
185205249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner        ALOGE("Invalid native pixel format { r=%d, g=%d, b=%d, a=%d }",
185305249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner                red_size, green_size, blue_size, alpha_size);
185405249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner        return setError(EGL_BAD_PARAMETER, (EGLClientBuffer)0);
185505249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner    }
185605249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner
185705249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner    GraphicBuffer* gBuffer = new GraphicBuffer(width, height, format, usage);
185805249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner    const status_t err = gBuffer->initCheck();
185905249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner    if (err != NO_ERROR) {
186005249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner        ALOGE("Unable to create native buffer { w=%d, h=%d, f=%d, u=%#x }: %#x",
186105249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner                width, height, format, usage, err);
186205249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner        // Destroy the buffer.
186305249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner        sp<GraphicBuffer> holder(gBuffer);
186405249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner        return setError(EGL_BAD_ALLOC, (EGLClientBuffer)0);
186505249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner    }
186605249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner    ALOGD("Created new native buffer %p { w=%d, h=%d, f=%d, u=%#x }",
186705249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner            gBuffer, width, height, format, usage);
186805249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner    return static_cast<EGLClientBuffer>(gBuffer->getNativeBuffer());
186905249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner}
187005249fc2d0da542efa46acdb7b10a619a68538e1Craig Donner
18711c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang// ----------------------------------------------------------------------------
18721c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang// NVIDIA extensions
18731c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang// ----------------------------------------------------------------------------
18741c3d72a2291827fb15e2ef311a571c860e0dba41Jonas YangEGLuint64NV eglGetSystemTimeFrequencyNV()
18751c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang{
18761c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang    clearError();
18771c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang
18781c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang    if (egl_init_drivers() == EGL_FALSE) {
18791c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang        return setError(EGL_BAD_PARAMETER, EGL_FALSE);
18801c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang    }
18811c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang
18821c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang    EGLuint64NV ret = 0;
1883ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian    egl_connection_t* const cnx = &gEGLImpl;
18841c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang
1885ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian    if (cnx->dso && cnx->egl.eglGetSystemTimeFrequencyNV) {
1886ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian        return cnx->egl.eglGetSystemTimeFrequencyNV();
18871c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang    }
18881c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang
18890e8bbee5775d81c7bbc479b995496cac9238559fMathias Agopian    return setErrorQuiet(EGL_BAD_DISPLAY, 0);
18901c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang}
18911c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang
18921c3d72a2291827fb15e2ef311a571c860e0dba41Jonas YangEGLuint64NV eglGetSystemTimeNV()
18931c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang{
18941c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang    clearError();
18951c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang
18961c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang    if (egl_init_drivers() == EGL_FALSE) {
18971c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang        return setError(EGL_BAD_PARAMETER, EGL_FALSE);
18981c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang    }
18991c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang
19001c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang    EGLuint64NV ret = 0;
1901ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian    egl_connection_t* const cnx = &gEGLImpl;
19021c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang
1903ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian    if (cnx->dso && cnx->egl.eglGetSystemTimeNV) {
1904ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian        return cnx->egl.eglGetSystemTimeNV();
19051c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang    }
19061c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang
19070e8bbee5775d81c7bbc479b995496cac9238559fMathias Agopian    return setErrorQuiet(EGL_BAD_DISPLAY, 0);
19081c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang}
1909a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza
1910a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza// ----------------------------------------------------------------------------
1911a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza// Partial update extension
1912a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza// ----------------------------------------------------------------------------
1913a894d082cfee8d12ee5913163a34ec5dc521d005Dan StozaEGLBoolean eglSetDamageRegionKHR(EGLDisplay dpy, EGLSurface surface,
1914a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza        EGLint *rects, EGLint n_rects)
1915a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza{
1916a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza    clearError();
1917a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza
1918a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza    const egl_display_ptr dp = validate_display(dpy);
1919a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza    if (!dp) {
1920a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza        setError(EGL_BAD_DISPLAY, EGL_FALSE);
1921a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza        return EGL_FALSE;
1922a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza    }
1923a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza
1924a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza    SurfaceRef _s(dp.get(), surface);
1925a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza    if (!_s.get()) {
1926a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza        setError(EGL_BAD_SURFACE, EGL_FALSE);
1927a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza        return EGL_FALSE;
1928a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza    }
1929a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza
1930a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza    egl_surface_t const * const s = get_surface(surface);
1931a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza    if (s->cnx->egl.eglSetDamageRegionKHR) {
1932a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza        return s->cnx->egl.eglSetDamageRegionKHR(dp->disp.dpy, s->surface,
1933a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza                rects, n_rects);
1934a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza    }
1935a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza
1936a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza    return EGL_FALSE;
1937a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza}
1938