eglApi.cpp revision a894d082cfee8d12ee5913163a34ec5dc521d005
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 36518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include <utils/KeyedVector.h> 37518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include <utils/SortedVector.h> 38518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include <utils/String8.h> 391c8e95cf86f2182986385bc1ee85f13f425f3a3aJamie Gennis#include <utils/Trace.h> 40518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 4139c24a20bbc697630d2b92c251b70c04d6f9d00cMathias Agopian#include "../egl_impl.h" 4239c24a20bbc697630d2b92c251b70c04d6f9d00cMathias Agopian#include "../glestrace.h" 4339c24a20bbc697630d2b92c251b70c04d6f9d00cMathias Agopian#include "../hooks.h" 44518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 45518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include "egl_display.h" 46518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include "egl_object.h" 47518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include "egl_tls.h" 48ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian#include "egldefs.h" 49518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 50518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianusing namespace android; 51518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 52a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall// This extension has not been ratified yet, so can't be shipped. 53a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall// Implementation is incomplete and untested. 54a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall#define ENABLE_EGL_KHR_GL_COLORSPACE 0 55a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall 56518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 57518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 58e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopiannamespace android { 59e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 60518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstruct extention_map_t { 61518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian const char* name; 62518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian __eglMustCastToProperFunctionPointerType address; 63518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}; 64518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 65e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian/* 6621558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hall * This is the list of EGL extensions exposed to applications. 67e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian * 6821558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hall * Some of them (gBuiltinExtensionString) are implemented entirely in this EGL 6921558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hall * wrapper and are always available. 70e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian * 7121558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hall * The rest (gExtensionString) depend on support in the EGL driver, and are 7221558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hall * only available if the driver supports them. However, some of these must be 7321558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hall * supported because they are used by the Android system itself; these are 7421558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hall * listd as mandatory below and are required by the CDD. The system *assumes* 7521558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hall * the mandatory extensions are present and may not function properly if some 7621558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hall * are missing. 7721558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hall * 7821558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hall * NOTE: Both strings MUST have a single space as the last character. 79e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian */ 8021558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hallextern char const * const gBuiltinExtensionString = 8121558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hall "EGL_KHR_get_all_proc_addresses " 8221558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hall "EGL_ANDROID_presentation_time " 83a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza "EGL_KHR_swap_buffers_with_damage " 8421558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hall ; 85e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopianextern char const * const gExtensionString = 86e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian "EGL_KHR_image " // mandatory 87e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian "EGL_KHR_image_base " // mandatory 88e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian "EGL_KHR_image_pixmap " 89e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian "EGL_KHR_lock_surface " 90a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall#if (ENABLE_EGL_KHR_GL_COLORSPACE != 0) 91c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall "EGL_KHR_gl_colorspace " 92a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall#endif 93e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian "EGL_KHR_gl_texture_2D_image " 94e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian "EGL_KHR_gl_texture_cubemap_image " 95e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian "EGL_KHR_gl_renderbuffer_image " 96e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian "EGL_KHR_reusable_sync " 97e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian "EGL_KHR_fence_sync " 98f6d1c3930eeba6b089ba12fb82ecad1c6622e550Jamie Gennis "EGL_KHR_create_context " 99e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian "EGL_EXT_create_context_robustness " 100e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian "EGL_NV_system_time " 101e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian "EGL_ANDROID_image_native_buffer " // mandatory 1022bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian "EGL_KHR_wait_sync " // strongly recommended 103dbe9245e2e362b12e184cd33b9a27b0901f81244Jamie Gennis "EGL_ANDROID_recordable " // mandatory 104a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza "EGL_KHR_partial_update " // strongly recommended 105a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza "EGL_EXT_buffer_age " // strongly recommended with partial_update 106e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian ; 107e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 108e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian// extensions not exposed to applications but used by the ANDROID system 109e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian// "EGL_ANDROID_blob_cache " // strongly recommended 110e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian// "EGL_IMG_hibernate_process " // optional 111e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian// "EGL_ANDROID_native_fence_sync " // strongly recommended 112e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian// "EGL_ANDROID_framebuffer_target " // mandatory for HWC 1.1 113dbe9245e2e362b12e184cd33b9a27b0901f81244Jamie Gennis// "EGL_ANDROID_image_crop " // optional 114e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 115e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian/* 116e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian * EGL Extensions entry-points exposed to 3rd party applications 117e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian * (keep in sync with gExtensionString above) 118e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian * 119e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian */ 120e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopianstatic const extention_map_t sExtensionMap[] = { 121e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian // EGL_KHR_lock_surface 122518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian { "eglLockSurfaceKHR", 123518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian (__eglMustCastToProperFunctionPointerType)&eglLockSurfaceKHR }, 124518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian { "eglUnlockSurfaceKHR", 125518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian (__eglMustCastToProperFunctionPointerType)&eglUnlockSurfaceKHR }, 126e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 127e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian // EGL_KHR_image, EGL_KHR_image_base 128518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian { "eglCreateImageKHR", 129518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian (__eglMustCastToProperFunctionPointerType)&eglCreateImageKHR }, 130518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian { "eglDestroyImageKHR", 131518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian (__eglMustCastToProperFunctionPointerType)&eglDestroyImageKHR }, 132e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 133e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian // EGL_KHR_reusable_sync, EGL_KHR_fence_sync 134e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian { "eglCreateSyncKHR", 135e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian (__eglMustCastToProperFunctionPointerType)&eglCreateSyncKHR }, 136e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian { "eglDestroySyncKHR", 137e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian (__eglMustCastToProperFunctionPointerType)&eglDestroySyncKHR }, 138e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian { "eglClientWaitSyncKHR", 139e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian (__eglMustCastToProperFunctionPointerType)&eglClientWaitSyncKHR }, 140e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian { "eglSignalSyncKHR", 141e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian (__eglMustCastToProperFunctionPointerType)&eglSignalSyncKHR }, 142e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian { "eglGetSyncAttribKHR", 143e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian (__eglMustCastToProperFunctionPointerType)&eglGetSyncAttribKHR }, 144e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 145e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian // EGL_NV_system_time 1461c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang { "eglGetSystemTimeFrequencyNV", 1471c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang (__eglMustCastToProperFunctionPointerType)&eglGetSystemTimeFrequencyNV }, 1481c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang { "eglGetSystemTimeNV", 1491c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang (__eglMustCastToProperFunctionPointerType)&eglGetSystemTimeNV }, 150e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 1512bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian // EGL_KHR_wait_sync 1522bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian { "eglWaitSyncKHR", 1532bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian (__eglMustCastToProperFunctionPointerType)&eglWaitSyncKHR }, 154e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 155e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian // EGL_ANDROID_presentation_time 156e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian { "eglPresentationTimeANDROID", 157e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian (__eglMustCastToProperFunctionPointerType)&eglPresentationTimeANDROID }, 158a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza 159a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza // EGL_KHR_swap_buffers_with_damage 160a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza { "eglSwapBuffersWithDamageKHR", 161a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza (__eglMustCastToProperFunctionPointerType)&eglSwapBuffersWithDamageKHR }, 162a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza 163a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza // EGL_KHR_partial_update 164a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza { "eglSetDamageRegionKHR", 165a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza (__eglMustCastToProperFunctionPointerType)&eglSetDamageRegionKHR }, 166518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}; 167518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 168e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian/* 169e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian * These extensions entry-points should not be exposed to applications. 170e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian * They're used internally by the Android EGL layer. 171e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian */ 172e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian#define FILTER_EXTENSIONS(procname) \ 173e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian (!strcmp((procname), "eglSetBlobCacheFuncsANDROID") || \ 174e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian !strcmp((procname), "eglHibernateProcessIMG") || \ 175e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian !strcmp((procname), "eglAwakenProcessIMG") || \ 176e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian !strcmp((procname), "eglDupNativeFenceFDANDROID")) 177e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 178e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 179e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 180518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// accesses protected by sExtensionMapMutex 181518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic DefaultKeyedVector<String8, __eglMustCastToProperFunctionPointerType> sGLExtentionMap; 182518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic int sGLExtentionSlot = 0; 183518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic pthread_mutex_t sExtensionMapMutex = PTHREAD_MUTEX_INITIALIZER; 184518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 185518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic void(*findProcAddress(const char* name, 186518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian const extention_map_t* map, size_t n))() { 187518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian for (uint32_t i=0 ; i<n ; i++) { 188518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!strcmp(name, map[i].name)) { 189518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return map[i].address; 190518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 191518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 192518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return NULL; 193518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 194518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 195518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 196518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 197518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianextern void setGLHooksThreadSpecific(gl_hooks_t const *value); 198518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianextern EGLBoolean egl_init_drivers(); 199518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianextern const __eglMustCastToProperFunctionPointerType gExtensionForwarders[MAX_NUMBER_OF_GL_EXTENSIONS]; 200a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamyextern int getEGLDebugLevel(); 201a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamyextern void setEGLDebugLevel(int level); 202518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianextern gl_hooks_t gHooksTrace; 203e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 204518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} // namespace android; 205518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 206e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 207518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 208518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 209518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic inline void clearError() { egl_tls_t::clearError(); } 210518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic inline EGLContext getContext() { return egl_tls_t::getContext(); } 211518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 212518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 213518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 214518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLDisplay eglGetDisplay(EGLNativeDisplayType display) 215518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 216518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 217518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 218c3289c41e794117817895653300bd2cf7daa0a01Dan Stoza uintptr_t index = reinterpret_cast<uintptr_t>(display); 219518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (index >= NUM_DISPLAYS) { 220518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_PARAMETER, EGL_NO_DISPLAY); 221518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 222518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 223518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (egl_init_drivers() == EGL_FALSE) { 224518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_PARAMETER, EGL_NO_DISPLAY); 225518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 226518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 227518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLDisplay dpy = egl_display_t::getFromNativeDisplay(display); 228518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return dpy; 229518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 230518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 231518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 232518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// Initialization 233518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 234518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 235518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) 236518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 237518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 238518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 239b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_display_ptr dp = get_display(dpy); 240518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE); 241518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 242518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean res = dp->initialize(major, minor); 243518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 244518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return res; 245518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 246518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 247518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglTerminate(EGLDisplay dpy) 248518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 249518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // NOTE: don't unload the drivers b/c some APIs can be called 250518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // after eglTerminate() has been called. eglTerminate() only 251518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // terminates an EGLDisplay, not a EGL itself. 252518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 253518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 254518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 255b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_display_ptr dp = get_display(dpy); 256518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE); 257518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 258518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean res = dp->terminate(); 2594774338bd0ad1ebe42c311fd0c72f13786b5c800Jesse Hall 260518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return res; 261518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 262518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 263518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 264518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// configuration 265518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 266518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 267518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglGetConfigs( EGLDisplay dpy, 268518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLConfig *configs, 269518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint config_size, EGLint *num_config) 270518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 271518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 272518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 273b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 274518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 275518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 2767773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian if (num_config==0) { 2777773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian return setError(EGL_BAD_PARAMETER, EGL_FALSE); 278518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 279518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 2807773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian EGLBoolean res = EGL_FALSE; 2817773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian *num_config = 0; 2827773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian 2837773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian egl_connection_t* const cnx = &gEGLImpl; 2847773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian if (cnx->dso) { 2857773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian res = cnx->egl.eglGetConfigs( 2867773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian dp->disp.dpy, configs, config_size, num_config); 287518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 2887773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian 2897773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian return res; 290518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 291518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 292518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglChooseConfig( EGLDisplay dpy, const EGLint *attrib_list, 293518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLConfig *configs, EGLint config_size, 294518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint *num_config) 295518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 296518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 297518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 298b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 299518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 300518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 301518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (num_config==0) { 302518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_PARAMETER, EGL_FALSE); 303518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 304518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 305518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean res = EGL_FALSE; 306518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian *num_config = 0; 307518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 308ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 309ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->dso) { 3101cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy if (attrib_list) { 3111cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy char value[PROPERTY_VALUE_MAX]; 3121cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy property_get("debug.egl.force_msaa", value, "false"); 3131cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy 3141cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy if (!strcmp(value, "true")) { 3151cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy size_t attribCount = 0; 3161cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy EGLint attrib = attrib_list[0]; 3171cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy 3181cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy // Only enable MSAA if the context is OpenGL ES 2.0 and 319be3c3e4ecad501eecfe1f7a424a792f0f7f3f307Romain Guy // if no caveat is requested 3201cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy const EGLint *attribRendererable = NULL; 3211cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy const EGLint *attribCaveat = NULL; 3221cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy 3231cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy // Count the number of attributes and look for 324be3c3e4ecad501eecfe1f7a424a792f0f7f3f307Romain Guy // EGL_RENDERABLE_TYPE and EGL_CONFIG_CAVEAT 3251cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy while (attrib != EGL_NONE) { 3261cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy attrib = attrib_list[attribCount]; 3271cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy switch (attrib) { 3281cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy case EGL_RENDERABLE_TYPE: 3291cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy attribRendererable = &attrib_list[attribCount]; 3301cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy break; 3311cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy case EGL_CONFIG_CAVEAT: 3321cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy attribCaveat = &attrib_list[attribCount]; 3331cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy break; 3341cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy } 3351cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy attribCount++; 3361cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy } 3371cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy 3381cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy if (attribRendererable && attribRendererable[1] == EGL_OPENGL_ES2_BIT && 3391cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy (!attribCaveat || attribCaveat[1] != EGL_NONE)) { 3404774338bd0ad1ebe42c311fd0c72f13786b5c800Jesse Hall 3411cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy // Insert 2 extra attributes to force-enable MSAA 4x 3421cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy EGLint aaAttribs[attribCount + 4]; 3431cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy aaAttribs[0] = EGL_SAMPLE_BUFFERS; 3441cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy aaAttribs[1] = 1; 3451cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy aaAttribs[2] = EGL_SAMPLES; 3461cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy aaAttribs[3] = 4; 3471cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy 3481cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy memcpy(&aaAttribs[4], attrib_list, attribCount * sizeof(EGLint)); 3491cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy 3501cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy EGLint numConfigAA; 3511cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy EGLBoolean resAA = cnx->egl.eglChooseConfig( 3521cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy dp->disp.dpy, aaAttribs, configs, config_size, &numConfigAA); 3531cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy 3541cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy if (resAA == EGL_TRUE && numConfigAA > 0) { 3551cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy ALOGD("Enabling MSAA 4x"); 3561cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy *num_config = numConfigAA; 3571cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy return resAA; 3581cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy } 3591cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy } 3601cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy } 3611cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy } 3621cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy 3637773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian res = cnx->egl.eglChooseConfig( 3647773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian dp->disp.dpy, attrib_list, configs, config_size, num_config); 365518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 366518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return res; 367518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 368518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 369518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, 370518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint attribute, EGLint *value) 371518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 372518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 373518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 374b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_connection_t* cnx = NULL; 375b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display_connection(dpy, cnx); 376b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall if (!dp) return EGL_FALSE; 3774774338bd0ad1ebe42c311fd0c72f13786b5c800Jesse Hall 378518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return cnx->egl.eglGetConfigAttrib( 3797773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian dp->disp.dpy, config, attribute, value); 380518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 381518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 382518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 383518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// surfaces 384518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 385518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 386a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall// The EGL_KHR_gl_colorspace spec hasn't been ratified yet, so these haven't 387c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall// been added to the Khronos egl.h. 388c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall#define EGL_GL_COLORSPACE_KHR EGL_VG_COLORSPACE 389c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall#define EGL_GL_COLORSPACE_SRGB_KHR EGL_VG_COLORSPACE_sRGB 390c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall#define EGL_GL_COLORSPACE_LINEAR_KHR EGL_VG_COLORSPACE_LINEAR 391c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall 392c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall// Turn linear formats into corresponding sRGB formats when colorspace is 393c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall// EGL_GL_COLORSPACE_SRGB_KHR, or turn sRGB formats into corresponding linear 394c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall// formats when colorspace is EGL_GL_COLORSPACE_LINEAR_KHR. In any cases where 39582c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala// the modification isn't possible, the original dataSpace is returned. 39682c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvalastatic android_dataspace modifyBufferDataspace( android_dataspace dataSpace, 39782c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala EGLint colorspace) { 398c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall if (colorspace == EGL_GL_COLORSPACE_LINEAR_KHR) { 39982c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala return HAL_DATASPACE_SRGB_LINEAR; 400c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall } else if (colorspace == EGL_GL_COLORSPACE_SRGB_KHR) { 40182c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala return HAL_DATASPACE_SRGB; 402c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall } 40382c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala return dataSpace; 404c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall} 405c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall 406518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLSurface eglCreateWindowSurface( EGLDisplay dpy, EGLConfig config, 407518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian NativeWindowType window, 408518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian const EGLint *attrib_list) 409518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 410518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 411518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 412b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_connection_t* cnx = NULL; 413b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_display_ptr dp = validate_display_connection(dpy, cnx); 414b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall if (dp) { 415ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian EGLDisplay iDpy = dp->disp.dpy; 416518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 417d566ce3a26ce781ecdbc479aaba0e172b7c807a9Andy McFadden int result = native_window_api_connect(window, NATIVE_WINDOW_API_EGL); 418d566ce3a26ce781ecdbc479aaba0e172b7c807a9Andy McFadden if (result != OK) { 419d566ce3a26ce781ecdbc479aaba0e172b7c807a9Andy McFadden ALOGE("eglCreateWindowSurface: native_window_api_connect (win=%p) " 420d566ce3a26ce781ecdbc479aaba0e172b7c807a9Andy McFadden "failed (%#x) (already connected to another API?)", 421d566ce3a26ce781ecdbc479aaba0e172b7c807a9Andy McFadden window, result); 42277a9b4a6bd21188e2744ae9dcd8092c6837bff7cJonathan Hamilton return setError(EGL_BAD_ALLOC, EGL_NO_SURFACE); 42381a63350527cafce6929309533c58586878f10b5Mathias Agopian } 42481a63350527cafce6929309533c58586878f10b5Mathias Agopian 4250f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian // Set the native window's buffers format to match what this config requests. 426c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall // Whether to use sRGB gamma is not part of the EGLconfig, but is part 427c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall // of our native format. So if sRGB gamma is requested, we have to 428c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall // modify the EGLconfig's format before setting the native window's 429c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall // format. 430733a80754786d39cdc0fee09509b194472c320bcAlistair Strachan 4310f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian // by default, just pick RGBA_8888 4320f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian EGLint format = HAL_PIXEL_FORMAT_RGBA_8888; 43382c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala android_dataspace dataSpace = HAL_DATASPACE_UNKNOWN; 4340f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian 4350f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian EGLint a = 0; 4360f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_ALPHA_SIZE, &a); 4370f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian if (a > 0) { 4380f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian // alpha-channel requested, there's really only one suitable format 4390f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian format = HAL_PIXEL_FORMAT_RGBA_8888; 4400f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian } else { 4410f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian EGLint r, g, b; 4420f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian r = g = b = 0; 4430f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_RED_SIZE, &r); 4440f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_GREEN_SIZE, &g); 4450f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_BLUE_SIZE, &b); 4460f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian EGLint colorDepth = r + g + b; 4470f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian if (colorDepth <= 16) { 4480f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian format = HAL_PIXEL_FORMAT_RGB_565; 4490f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian } else { 4500f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian format = HAL_PIXEL_FORMAT_RGBX_8888; 4510f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian } 452c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall } 4530f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian 4540f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian // now select a corresponding sRGB format if needed 4550f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian if (attrib_list && dp->haveExtension("EGL_KHR_gl_colorspace")) { 4560f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian for (const EGLint* attr = attrib_list; *attr != EGL_NONE; attr += 2) { 4570f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian if (*attr == EGL_GL_COLORSPACE_KHR) { 458a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall if (ENABLE_EGL_KHR_GL_COLORSPACE) { 45982c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala dataSpace = modifyBufferDataspace(dataSpace, *(attr+1)); 460a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall } else { 461a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall // Normally we'd pass through unhandled attributes to 462a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall // the driver. But in case the driver implements this 463a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall // extension but we're disabling it, we want to prevent 464a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall // it getting through -- support will be broken without 465a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall // our help. 466a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall ALOGE("sRGB window surfaces not supported"); 467a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall return setError(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE); 468a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall } 469bee205fd58a27c10a0895de5339e76025d429d2bJamie Gennis } 470518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 471518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 472733a80754786d39cdc0fee09509b194472c320bcAlistair Strachan 473c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall if (format != 0) { 474c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall int err = native_window_set_buffers_format(window, format); 475c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall if (err != 0) { 476c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall ALOGE("error setting native window pixel format: %s (%d)", 477c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall strerror(-err), err); 47882c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL); 47982c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala return setError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE); 48082c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala } 48182c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala } 48282c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala 48382c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala if (dataSpace != 0) { 48482c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala int err = native_window_set_buffers_data_space(window, dataSpace); 48582c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala if (err != 0) { 48682c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala ALOGE("error setting native window pixel dataSpace: %s (%d)", 48782c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala strerror(-err), err); 488c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL); 489c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall return setError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE); 490c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall } 491c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall } 492518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 49359769469e4b9b2d8b12c020eb44b030b3927a50bJamie Gennis // the EGL spec requires that a new EGLSurface default to swap interval 49459769469e4b9b2d8b12c020eb44b030b3927a50bJamie Gennis // 1, so explicitly set that on the window here. 49559769469e4b9b2d8b12c020eb44b030b3927a50bJamie Gennis ANativeWindow* anw = reinterpret_cast<ANativeWindow*>(window); 49659769469e4b9b2d8b12c020eb44b030b3927a50bJamie Gennis anw->setSwapInterval(anw, 1); 49759769469e4b9b2d8b12c020eb44b030b3927a50bJamie Gennis 498518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLSurface surface = cnx->egl.eglCreateWindowSurface( 4997773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian iDpy, config, window, attrib_list); 500518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (surface != EGL_NO_SURFACE) { 501b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_surface_t* s = new egl_surface_t(dp.get(), config, window, 502b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall surface, cnx); 503518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return s; 504518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 50581a63350527cafce6929309533c58586878f10b5Mathias Agopian 50681a63350527cafce6929309533c58586878f10b5Mathias Agopian // EGLSurface creation failed 50781a63350527cafce6929309533c58586878f10b5Mathias Agopian native_window_set_buffers_format(window, 0); 50881a63350527cafce6929309533c58586878f10b5Mathias Agopian native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL); 509518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 510518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_NO_SURFACE; 511518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 512518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 513518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLSurface eglCreatePixmapSurface( EGLDisplay dpy, EGLConfig config, 514518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian NativePixmapType pixmap, 515518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian const EGLint *attrib_list) 516518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 517518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 518518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 519b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_connection_t* cnx = NULL; 520b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_display_ptr dp = validate_display_connection(dpy, cnx); 521b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall if (dp) { 522518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLSurface surface = cnx->egl.eglCreatePixmapSurface( 5237773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian dp->disp.dpy, config, pixmap, attrib_list); 524518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (surface != EGL_NO_SURFACE) { 525b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_surface_t* s = new egl_surface_t(dp.get(), config, NULL, 526b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall surface, cnx); 527518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return s; 528518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 529518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 530518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_NO_SURFACE; 531518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 532518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 533518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLSurface eglCreatePbufferSurface( EGLDisplay dpy, EGLConfig config, 534518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian const EGLint *attrib_list) 535518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 536518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 537518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 538b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_connection_t* cnx = NULL; 539b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_display_ptr dp = validate_display_connection(dpy, cnx); 540b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall if (dp) { 541518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLSurface surface = cnx->egl.eglCreatePbufferSurface( 5427773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian dp->disp.dpy, config, attrib_list); 543518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (surface != EGL_NO_SURFACE) { 544b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_surface_t* s = new egl_surface_t(dp.get(), config, NULL, 545b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall surface, cnx); 546518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return s; 547518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 548518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 549518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_NO_SURFACE; 550518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 5514774338bd0ad1ebe42c311fd0c72f13786b5c800Jesse Hall 552518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface) 553518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 554518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 555518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 556b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 557518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 558518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 559b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall SurfaceRef _s(dp.get(), surface); 5605b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 5615b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 562518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 563518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t * const s = get_surface(surface); 564ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian EGLBoolean result = s->cnx->egl.eglDestroySurface(dp->disp.dpy, s->surface); 565518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (result == EGL_TRUE) { 566518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian _s.terminate(); 567518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 568518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return result; 569518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 570518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 571518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglQuerySurface( EGLDisplay dpy, EGLSurface surface, 572518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint attribute, EGLint *value) 573518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 574518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 575518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 576b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 577518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 578518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 579b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall SurfaceRef _s(dp.get(), surface); 5805b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 5815b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 582518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 583518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * const s = get_surface(surface); 5847773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian return s->cnx->egl.eglQuerySurface( 5857773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian dp->disp.dpy, s->surface, attribute, value); 586518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 587518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 588e8696a40e09b24b634214684d18526187b316a2fJamie Gennisvoid EGLAPI eglBeginFrame(EGLDisplay dpy, EGLSurface surface) { 5891c8e95cf86f2182986385bc1ee85f13f425f3a3aJamie Gennis ATRACE_CALL(); 590e8696a40e09b24b634214684d18526187b316a2fJamie Gennis clearError(); 591e8696a40e09b24b634214684d18526187b316a2fJamie Gennis 592b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 593e8696a40e09b24b634214684d18526187b316a2fJamie Gennis if (!dp) { 594e8696a40e09b24b634214684d18526187b316a2fJamie Gennis return; 595e8696a40e09b24b634214684d18526187b316a2fJamie Gennis } 596e8696a40e09b24b634214684d18526187b316a2fJamie Gennis 597b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall SurfaceRef _s(dp.get(), surface); 598e8696a40e09b24b634214684d18526187b316a2fJamie Gennis if (!_s.get()) { 599e8696a40e09b24b634214684d18526187b316a2fJamie Gennis setError(EGL_BAD_SURFACE, EGL_FALSE); 600e8696a40e09b24b634214684d18526187b316a2fJamie Gennis return; 601e8696a40e09b24b634214684d18526187b316a2fJamie Gennis } 602e8696a40e09b24b634214684d18526187b316a2fJamie Gennis} 603e8696a40e09b24b634214684d18526187b316a2fJamie Gennis 604518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 605518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// Contexts 606518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 607518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 608518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config, 609518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLContext share_list, const EGLint *attrib_list) 610518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 611518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 612518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 613b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_connection_t* cnx = NULL; 614b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display_connection(dpy, cnx); 6150673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock if (dp) { 616518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (share_list != EGL_NO_CONTEXT) { 6170673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock if (!ContextRef(dp.get(), share_list).get()) { 6180673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock return setError(EGL_BAD_CONTEXT, EGL_NO_CONTEXT); 6190673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock } 620518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t* const c = get_context(share_list); 621518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian share_list = c->context; 622518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 623518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLContext context = cnx->egl.eglCreateContext( 6247773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian dp->disp.dpy, config, share_list, attrib_list); 625518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (context != EGL_NO_CONTEXT) { 626518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // figure out if it's a GLESv1 or GLESv2 627518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian int version = 0; 628518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (attrib_list) { 629518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian while (*attrib_list != EGL_NONE) { 630518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian GLint attr = *attrib_list++; 631518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian GLint value = *attrib_list++; 632518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (attr == EGL_CONTEXT_CLIENT_VERSION) { 633518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (value == 1) { 6347773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian version = egl_connection_t::GLESv1_INDEX; 6354774338bd0ad1ebe42c311fd0c72f13786b5c800Jesse Hall } else if (value == 2 || value == 3) { 6367773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian version = egl_connection_t::GLESv2_INDEX; 637518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 638518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 639518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian }; 640518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 641b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_context_t* c = new egl_context_t(dpy, context, config, cnx, 642b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall version); 6430469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#if EGL_TRACE 644a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy if (getEGLDebugLevel() > 0) 6450469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLTrace_eglCreateContext(version, c); 6460469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#endif 647518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return c; 648518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 649518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 650518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_NO_CONTEXT; 651518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 652518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 653518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx) 654518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 655518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 656518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 657b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 6585b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!dp) 6595b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return EGL_FALSE; 660518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 661b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall ContextRef _c(dp.get(), ctx); 6625b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_c.get()) 6635b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_CONTEXT, EGL_FALSE); 6644774338bd0ad1ebe42c311fd0c72f13786b5c800Jesse Hall 665518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t * const c = get_context(ctx); 666ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian EGLBoolean result = c->cnx->egl.eglDestroyContext(dp->disp.dpy, c->context); 667518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (result == EGL_TRUE) { 668518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian _c.terminate(); 669518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 670518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return result; 671518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 672518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 673518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglMakeCurrent( EGLDisplay dpy, EGLSurface draw, 674518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLSurface read, EGLContext ctx) 675518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 676518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 677518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 678b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_display_ptr dp = validate_display(dpy); 679518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE); 680518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 6815b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian // If ctx is not EGL_NO_CONTEXT, read is not EGL_NO_SURFACE, or draw is not 6825b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian // EGL_NO_SURFACE, then an EGL_NOT_INITIALIZED error is generated if dpy is 6835b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian // a valid but uninitialized display. 684518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if ( (ctx != EGL_NO_CONTEXT) || (read != EGL_NO_SURFACE) || 685518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian (draw != EGL_NO_SURFACE) ) { 686518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp->isReady()) return setError(EGL_NOT_INITIALIZED, EGL_FALSE); 687518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 688518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 689518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // get a reference to the object passed in 690b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall ContextRef _c(dp.get(), ctx); 691b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall SurfaceRef _d(dp.get(), draw); 692b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall SurfaceRef _r(dp.get(), read); 693518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 694518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // validate the context (if not EGL_NO_CONTEXT) 6955b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if ((ctx != EGL_NO_CONTEXT) && !_c.get()) { 696518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // EGL_NO_CONTEXT is valid 6970673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock return setError(EGL_BAD_CONTEXT, EGL_FALSE); 698518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 699518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 700518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // these are the underlying implementation's object 701518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLContext impl_ctx = EGL_NO_CONTEXT; 702518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLSurface impl_draw = EGL_NO_SURFACE; 703518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLSurface impl_read = EGL_NO_SURFACE; 704518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 705518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // these are our objects structs passed in 706518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t * c = NULL; 707518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * d = NULL; 708518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * r = NULL; 709518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 710518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // these are the current objects structs 711518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t * cur_c = get_context(getContext()); 7124774338bd0ad1ebe42c311fd0c72f13786b5c800Jesse Hall 713518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (ctx != EGL_NO_CONTEXT) { 714518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian c = get_context(ctx); 715518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian impl_ctx = c->context; 716518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } else { 717518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // no context given, use the implementation of the current context 7180673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock if (draw != EGL_NO_SURFACE || read != EGL_NO_SURFACE) { 7190673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock // calling eglMakeCurrent( ..., !=0, !=0, EGL_NO_CONTEXT); 7200673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock return setError(EGL_BAD_MATCH, EGL_FALSE); 7210673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock } 722518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (cur_c == NULL) { 723518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // no current context 724518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // not an error, there is just no current context. 725518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_TRUE; 726518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 727518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 728518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 729518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // retrieve the underlying implementation's draw EGLSurface 730518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (draw != EGL_NO_SURFACE) { 7310673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock if (!_d.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE); 732518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian d = get_surface(draw); 733518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian impl_draw = d->surface; 734518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 735518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 736518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // retrieve the underlying implementation's read EGLSurface 737518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (read != EGL_NO_SURFACE) { 7380673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock if (!_r.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE); 739518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian r = get_surface(read); 740518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian impl_read = r->surface; 741518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 742518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 743518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 744b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall EGLBoolean result = dp->makeCurrent(c, cur_c, 745fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian draw, read, ctx, 746fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian impl_draw, impl_read, impl_ctx); 747518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 748518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (result == EGL_TRUE) { 749fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian if (c) { 750518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian setGLHooksThreadSpecific(c->cnx->hooks[c->version]); 751518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_tls_t::setContext(ctx); 7520469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#if EGL_TRACE 753a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy if (getEGLDebugLevel() > 0) 75493a826f78f6313db791e6fc880439189897651b3Siva Velusamy GLTrace_eglMakeCurrent(c->version, c->cnx->hooks[c->version], ctx); 7550469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#endif 756518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian _c.acquire(); 757518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian _r.acquire(); 758518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian _d.acquire(); 759518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } else { 760518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian setGLHooksThreadSpecific(&gHooksNoContext); 761518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_tls_t::setContext(EGL_NO_CONTEXT); 762518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 7635fecea776a5f093c21ac1a0ad3552b847d4be23eMathias Agopian } else { 764e6f43ddce78d6846af12550ff9193c5c6fe5844bSteve Block // this will ALOGE the error 76563108c34ec181e923b68ee840bb7960f205466a7Mathias Agopian egl_connection_t* const cnx = &gEGLImpl; 76663108c34ec181e923b68ee840bb7960f205466a7Mathias Agopian result = setError(cnx->egl.eglGetError(), EGL_FALSE); 767518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 768518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return result; 769518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 770518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 771518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 772518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglQueryContext( EGLDisplay dpy, EGLContext ctx, 773518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint attribute, EGLint *value) 774518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 775518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 776518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 777b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 778518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 779518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 780b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall ContextRef _c(dp.get(), ctx); 781518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!_c.get()) return setError(EGL_BAD_CONTEXT, EGL_FALSE); 782518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 783518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t * const c = get_context(ctx); 7847773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian return c->cnx->egl.eglQueryContext( 7857773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian dp->disp.dpy, c->context, attribute, value); 786518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 787518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 788518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 789518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLContext eglGetCurrentContext(void) 790518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 791518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // could be called before eglInitialize(), but we wouldn't have a context 792518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // then, and this function would correctly return EGL_NO_CONTEXT. 793518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 794518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 795518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 796518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLContext ctx = getContext(); 797518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return ctx; 798518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 799518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 800518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLSurface eglGetCurrentSurface(EGLint readdraw) 801518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 802518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // could be called before eglInitialize(), but we wouldn't have a context 803518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // then, and this function would correctly return EGL_NO_SURFACE. 804518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 805518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 806518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 807518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLContext ctx = getContext(); 808518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (ctx) { 809518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t const * const c = get_context(ctx); 810518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!c) return setError(EGL_BAD_CONTEXT, EGL_NO_SURFACE); 811518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian switch (readdraw) { 812518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian case EGL_READ: return c->read; 8134774338bd0ad1ebe42c311fd0c72f13786b5c800Jesse Hall case EGL_DRAW: return c->draw; 814518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian default: return setError(EGL_BAD_PARAMETER, EGL_NO_SURFACE); 815518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 816518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 817518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_NO_SURFACE; 818518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 819518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 820518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLDisplay eglGetCurrentDisplay(void) 821518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 822518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // could be called before eglInitialize(), but we wouldn't have a context 823518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // then, and this function would correctly return EGL_NO_DISPLAY. 824518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 825518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 826518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 827518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLContext ctx = getContext(); 828518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (ctx) { 829518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t const * const c = get_context(ctx); 830518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!c) return setError(EGL_BAD_CONTEXT, EGL_NO_SURFACE); 831518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return c->dpy; 832518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 833518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_NO_DISPLAY; 834518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 835518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 836518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglWaitGL(void) 837518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 838518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 839518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 840ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 841ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (!cnx->dso) 842ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return setError(EGL_BAD_CONTEXT, EGL_FALSE); 843ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian 844ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return cnx->egl.eglWaitGL(); 845518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 846518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 847518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglWaitNative(EGLint engine) 848518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 849518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 850518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 851ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 852ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (!cnx->dso) 853ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return setError(EGL_BAD_CONTEXT, EGL_FALSE); 854ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian 855ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return cnx->egl.eglWaitNative(engine); 856518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 857518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 858518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLint eglGetError(void) 859518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 860ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian EGLint err = EGL_SUCCESS; 861ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 862ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->dso) { 863ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian err = cnx->egl.eglGetError(); 864518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 865ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (err == EGL_SUCCESS) { 866ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian err = egl_tls_t::getError(); 867ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian } 868ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return err; 869518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 870518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 871c0ec5e2333b6350480851b8b48f000c78ea3f88aMichael Chockstatic __eglMustCastToProperFunctionPointerType findBuiltinWrapper( 872c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall const char* procname) { 873c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall const egl_connection_t* cnx = &gEGLImpl; 874c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall void* proc = NULL; 875c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall 876c0ec5e2333b6350480851b8b48f000c78ea3f88aMichael Chock proc = dlsym(cnx->libEgl, procname); 877c0ec5e2333b6350480851b8b48f000c78ea3f88aMichael Chock if (proc) return (__eglMustCastToProperFunctionPointerType)proc; 878c0ec5e2333b6350480851b8b48f000c78ea3f88aMichael Chock 879c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall proc = dlsym(cnx->libGles2, procname); 880c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall if (proc) return (__eglMustCastToProperFunctionPointerType)proc; 881c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall 882c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall proc = dlsym(cnx->libGles1, procname); 883c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall if (proc) return (__eglMustCastToProperFunctionPointerType)proc; 884c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall 885c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall return NULL; 886c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall} 887c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall 888518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian__eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname) 889518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 890518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // eglGetProcAddress() could be the very first function called 891518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // in which case we must make sure we've initialized ourselves, this 892518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // happens the first time egl_get_display() is called. 893518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 894518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 895518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 896518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (egl_init_drivers() == EGL_FALSE) { 897518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian setError(EGL_BAD_PARAMETER, NULL); 898518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return NULL; 899518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 900518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 901e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian if (FILTER_EXTENSIONS(procname)) { 902aca51c06f38155f1435fbc6944d7fc0a9bf1e4e9Jamie Gennis return NULL; 903aca51c06f38155f1435fbc6944d7fc0a9bf1e4e9Jamie Gennis } 904aca51c06f38155f1435fbc6944d7fc0a9bf1e4e9Jamie Gennis 905518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian __eglMustCastToProperFunctionPointerType addr; 906e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian addr = findProcAddress(procname, sExtensionMap, NELEM(sExtensionMap)); 907518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (addr) return addr; 908518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 909c0ec5e2333b6350480851b8b48f000c78ea3f88aMichael Chock addr = findBuiltinWrapper(procname); 910c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall if (addr) return addr; 911aca51c06f38155f1435fbc6944d7fc0a9bf1e4e9Jamie Gennis 912518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // this protects accesses to sGLExtentionMap and sGLExtentionSlot 913518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian pthread_mutex_lock(&sExtensionMapMutex); 914518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 915518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian /* 916518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * Since eglGetProcAddress() is not associated to anything, it needs 917518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * to return a function pointer that "works" regardless of what 918518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * the current context is. 919518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * 920518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * For this reason, we return a "forwarder", a small stub that takes 921518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * care of calling the function associated with the context 922518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * currently bound. 923518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * 924518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * We first look for extensions we've already resolved, if we're seeing 925518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * this extension for the first time, we go through all our 926518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * implementations and call eglGetProcAddress() and record the 927518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * result in the appropriate implementation hooks and return the 928518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * address of the forwarder corresponding to that hook set. 929518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * 930518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian */ 931518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 932518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian const String8 name(procname); 933518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian addr = sGLExtentionMap.valueFor(name); 934518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian const int slot = sGLExtentionSlot; 935518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 936e6f43ddce78d6846af12550ff9193c5c6fe5844bSteve Block ALOGE_IF(slot >= MAX_NUMBER_OF_GL_EXTENSIONS, 937518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian "no more slots for eglGetProcAddress(\"%s\")", 938518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian procname); 939518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 9400469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#if EGL_TRACE 9410469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy gl_hooks_t *debugHooks = GLTrace_getGLHooks(); 9420469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#endif 9430469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 944518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!addr && (slot < MAX_NUMBER_OF_GL_EXTENSIONS)) { 945518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian bool found = false; 946ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian 947ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 948ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->dso && cnx->egl.eglGetProcAddress) { 949ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian // Extensions are independent of the bound context 95069d100762c7c26d8328f4bb61cfef026d3a69bbfluliuhui addr = 9517773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian cnx->hooks[egl_connection_t::GLESv1_INDEX]->ext.extensions[slot] = 9527773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian cnx->hooks[egl_connection_t::GLESv2_INDEX]->ext.extensions[slot] = 953518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#if EGL_TRACE 954ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian debugHooks->ext.extensions[slot] = 955ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian gHooksTrace.ext.extensions[slot] = 956518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#endif 957ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian cnx->egl.eglGetProcAddress(procname); 95869d100762c7c26d8328f4bb61cfef026d3a69bbfluliuhui if (addr) found = true; 959518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 960ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian 961518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (found) { 962518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian addr = gExtensionForwarders[slot]; 963518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian sGLExtentionMap.add(name, addr); 964518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian sGLExtentionSlot++; 965518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 966518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 967518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 968518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian pthread_mutex_unlock(&sExtensionMapMutex); 969518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return addr; 970518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 971518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 97228ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennisclass FrameCompletionThread : public Thread { 97328ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennispublic: 97428ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis 97528ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis static void queueSync(EGLSyncKHR sync) { 97628ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis static sp<FrameCompletionThread> thread(new FrameCompletionThread); 97728ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis static bool running = false; 97828ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis if (!running) { 97928ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis thread->run("GPUFrameCompletion"); 98028ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis running = true; 98128ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis } 98228ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis { 98328ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis Mutex::Autolock lock(thread->mMutex); 98428ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis ScopedTrace st(ATRACE_TAG, String8::format("kicked off frame %d", 98528ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis thread->mFramesQueued).string()); 98628ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis thread->mQueue.push_back(sync); 98728ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis thread->mCondition.signal(); 98828ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis thread->mFramesQueued++; 98928ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis ATRACE_INT("GPU Frames Outstanding", thread->mQueue.size()); 99028ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis } 99128ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis } 99228ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis 99328ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennisprivate: 99428ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis FrameCompletionThread() : mFramesQueued(0), mFramesCompleted(0) {} 99528ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis 99628ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis virtual bool threadLoop() { 99728ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis EGLSyncKHR sync; 99828ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis uint32_t frameNum; 99928ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis { 100028ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis Mutex::Autolock lock(mMutex); 100128ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis while (mQueue.isEmpty()) { 100228ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis mCondition.wait(mMutex); 100328ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis } 100428ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis sync = mQueue[0]; 100528ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis frameNum = mFramesCompleted; 100628ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis } 100728ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis EGLDisplay dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); 100828ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis { 100928ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis ScopedTrace st(ATRACE_TAG, String8::format("waiting for frame %d", 101028ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis frameNum).string()); 101128ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis EGLint result = eglClientWaitSyncKHR(dpy, sync, 0, EGL_FOREVER_KHR); 101228ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis if (result == EGL_FALSE) { 101328ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis ALOGE("FrameCompletion: error waiting for fence: %#x", eglGetError()); 101428ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis } else if (result == EGL_TIMEOUT_EXPIRED_KHR) { 101528ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis ALOGE("FrameCompletion: timeout waiting for fence"); 101628ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis } 101728ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis eglDestroySyncKHR(dpy, sync); 101828ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis } 101928ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis { 102028ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis Mutex::Autolock lock(mMutex); 102128ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis mQueue.removeAt(0); 102228ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis mFramesCompleted++; 102328ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis ATRACE_INT("GPU Frames Outstanding", mQueue.size()); 102428ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis } 102528ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis return true; 102628ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis } 102728ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis 102828ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis uint32_t mFramesQueued; 102928ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis uint32_t mFramesCompleted; 103028ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis Vector<EGLSyncKHR> mQueue; 103128ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis Condition mCondition; 103228ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis Mutex mMutex; 103328ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis}; 103428ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis 1035a894d082cfee8d12ee5913163a34ec5dc521d005Dan StozaEGLBoolean eglSwapBuffersWithDamageKHR(EGLDisplay dpy, EGLSurface draw, 1036a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza EGLint *rects, EGLint n_rects) 1037518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 10381c8e95cf86f2182986385bc1ee85f13f425f3a3aJamie Gennis ATRACE_CALL(); 1039518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1040518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1041b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1042518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1043518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1044b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall SurfaceRef _s(dp.get(), draw); 10455b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 10465b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 1047518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 10480469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#if EGL_TRACE 1049a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy gl_hooks_t const *trace_hooks = getGLTraceThreadSpecific(); 1050a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy if (getEGLDebugLevel() > 0) { 1051a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy if (trace_hooks == NULL) { 1052a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy if (GLTrace_start() < 0) { 1053a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy ALOGE("Disabling Tracer for OpenGL ES"); 1054a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy setEGLDebugLevel(0); 1055a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy } else { 1056a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy // switch over to the trace version of hooks 1057a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy EGLContext ctx = egl_tls_t::getContext(); 1058a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy egl_context_t * const c = get_context(ctx); 1059a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy if (c) { 1060a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy setGLHooksThreadSpecific(c->cnx->hooks[c->version]); 1061a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy GLTrace_eglMakeCurrent(c->version, c->cnx->hooks[c->version], ctx); 1062a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy } 1063a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy } 1064a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy } 1065a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy 10660469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLTrace_eglSwapBuffers(dpy, draw); 1067a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy } else if (trace_hooks != NULL) { 1068a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy // tracing is now disabled, so switch back to the non trace version 1069a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy EGLContext ctx = egl_tls_t::getContext(); 1070a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy egl_context_t * const c = get_context(ctx); 1071a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy if (c) setGLHooksThreadSpecific(c->cnx->hooks[c->version]); 1072a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy GLTrace_stop(); 1073a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy } 10740469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#endif 10750469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 1076518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * const s = get_surface(draw); 10777db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian 1078ed6d08b70d775852f4827471814c83eba3606aaaMathias Agopian if (CC_UNLIKELY(dp->traceGpuCompletion)) { 1079ed6d08b70d775852f4827471814c83eba3606aaaMathias Agopian EGLSyncKHR sync = eglCreateSyncKHR(dpy, EGL_SYNC_FENCE_KHR, NULL); 1080ed6d08b70d775852f4827471814c83eba3606aaaMathias Agopian if (sync != EGL_NO_SYNC_KHR) { 1081ed6d08b70d775852f4827471814c83eba3606aaaMathias Agopian FrameCompletionThread::queueSync(sync); 1082ed6d08b70d775852f4827471814c83eba3606aaaMathias Agopian } 1083ed6d08b70d775852f4827471814c83eba3606aaaMathias Agopian } 1084ed6d08b70d775852f4827471814c83eba3606aaaMathias Agopian 10857db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian if (CC_UNLIKELY(dp->finishOnSwap)) { 10867db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian uint32_t pixel; 10877db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian egl_context_t * const c = get_context( egl_tls_t::getContext() ); 10887db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian if (c) { 10897db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian // glReadPixels() ensures that the frame is complete 10907db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian s->cnx->hooks[c->version]->gl.glReadPixels(0,0,1,1, 10917db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian GL_RGBA,GL_UNSIGNED_BYTE,&pixel); 10927db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian } 10937db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian } 10947db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian 1095a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza if (n_rects == 0) { 1096a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza return s->cnx->egl.eglSwapBuffers(dp->disp.dpy, s->surface); 1097a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza } 1098a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza 1099a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza Vector<android_native_rect_t> androidRects; 1100a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza for (int r = 0; r < n_rects; ++r) { 1101a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza int offset = r * 4; 1102a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza int x = rects[offset]; 1103a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza int y = rects[offset + 1]; 1104a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza int width = rects[offset + 2]; 1105a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza int height = rects[offset + 3]; 1106a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza android_native_rect_t androidRect; 1107a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza androidRect.left = x; 1108a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza androidRect.top = y + height; 1109a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza androidRect.right = x + width; 1110a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza androidRect.bottom = y; 1111a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza androidRects.push_back(androidRect); 1112a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza } 1113a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza native_window_set_surface_damage(s->win.get(), androidRects.array(), 1114a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza androidRects.size()); 1115a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza 1116a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza if (s->cnx->egl.eglSwapBuffersWithDamageKHR) { 1117a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza return s->cnx->egl.eglSwapBuffersWithDamageKHR(dp->disp.dpy, s->surface, 1118a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza rects, n_rects); 1119a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza } else { 1120a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza return s->cnx->egl.eglSwapBuffers(dp->disp.dpy, s->surface); 1121a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza } 1122a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza} 1123a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza 1124a894d082cfee8d12ee5913163a34ec5dc521d005Dan StozaEGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) 1125a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza{ 1126a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza return eglSwapBuffersWithDamageKHR(dpy, surface, NULL, 0); 1127518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1128518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1129518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglCopyBuffers( EGLDisplay dpy, EGLSurface surface, 1130518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian NativePixmapType target) 1131518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1132518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1133518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1134b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1135518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1136518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1137b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall SurfaceRef _s(dp.get(), surface); 11385b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 11395b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 1140518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1141518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * const s = get_surface(surface); 1142ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return s->cnx->egl.eglCopyBuffers(dp->disp.dpy, s->surface, target); 1143518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1144518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1145518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianconst char* eglQueryString(EGLDisplay dpy, EGLint name) 1146518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1147518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1148518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1149b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1150518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return (const char *) NULL; 1151518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1152518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian switch (name) { 1153518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian case EGL_VENDOR: 11544b9511c16195a646242eff833b0af212933b6ecaMathias Agopian return dp->getVendorString(); 1155518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian case EGL_VERSION: 11564b9511c16195a646242eff833b0af212933b6ecaMathias Agopian return dp->getVersionString(); 1157518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian case EGL_EXTENSIONS: 11584b9511c16195a646242eff833b0af212933b6ecaMathias Agopian return dp->getExtensionString(); 1159518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian case EGL_CLIENT_APIS: 11604b9511c16195a646242eff833b0af212933b6ecaMathias Agopian return dp->getClientApiString(); 1161518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1162518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_PARAMETER, (const char *)0); 1163518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1164518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1165ca08833d5ea99130797e10ad68a651b50e99da74Mathias AgopianEGLAPI const char* eglQueryStringImplementationANDROID(EGLDisplay dpy, EGLint name) 1166ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian{ 1167ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian clearError(); 1168ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian 1169ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian const egl_display_ptr dp = validate_display(dpy); 1170ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian if (!dp) return (const char *) NULL; 1171ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian 1172ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian switch (name) { 1173ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian case EGL_VENDOR: 1174ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian return dp->disp.queryString.vendor; 1175ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian case EGL_VERSION: 1176ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian return dp->disp.queryString.version; 1177ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian case EGL_EXTENSIONS: 1178ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian return dp->disp.queryString.extensions; 1179ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian case EGL_CLIENT_APIS: 1180ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian return dp->disp.queryString.clientApi; 1181ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian } 1182ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian return setError(EGL_BAD_PARAMETER, (const char *)0); 1183ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian} 1184518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1185518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 1186518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// EGL 1.1 1187518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 1188518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1189518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglSurfaceAttrib( 1190518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value) 1191518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1192518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1193518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1194b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1195518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1196518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1197b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall SurfaceRef _s(dp.get(), surface); 11985b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 11995b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 1200518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1201518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * const s = get_surface(surface); 1202518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (s->cnx->egl.eglSurfaceAttrib) { 1203518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return s->cnx->egl.eglSurfaceAttrib( 1204ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian dp->disp.dpy, s->surface, attribute, value); 1205518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1206518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 1207518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1208518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1209518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglBindTexImage( 1210518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLDisplay dpy, EGLSurface surface, EGLint buffer) 1211518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1212518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1213518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1214b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1215518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1216518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1217b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall SurfaceRef _s(dp.get(), surface); 12185b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 12195b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 1220518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1221518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * const s = get_surface(surface); 1222518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (s->cnx->egl.eglBindTexImage) { 1223518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return s->cnx->egl.eglBindTexImage( 1224ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian dp->disp.dpy, s->surface, buffer); 1225518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1226518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 1227518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1228518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1229518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglReleaseTexImage( 1230518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLDisplay dpy, EGLSurface surface, EGLint buffer) 1231518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1232518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1233518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1234b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1235518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1236518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1237b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall SurfaceRef _s(dp.get(), surface); 12385b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 12395b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 1240518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1241518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * const s = get_surface(surface); 1242518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (s->cnx->egl.eglReleaseTexImage) { 1243518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return s->cnx->egl.eglReleaseTexImage( 1244ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian dp->disp.dpy, s->surface, buffer); 1245518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1246518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 1247518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1248518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1249518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint interval) 1250518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1251518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1252518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1253b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1254518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1255518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1256518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean res = EGL_TRUE; 1257ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 1258ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->dso && cnx->egl.eglSwapInterval) { 1259ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian res = cnx->egl.eglSwapInterval(dp->disp.dpy, interval); 1260518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1261ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian 1262518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return res; 1263518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1264518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1265518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1266518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 1267518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// EGL 1.2 1268518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 1269518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1270518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglWaitClient(void) 1271518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1272518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1273518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1274ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 1275ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (!cnx->dso) 1276ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return setError(EGL_BAD_CONTEXT, EGL_FALSE); 1277ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian 1278ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian EGLBoolean res; 1279ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->egl.eglWaitClient) { 1280ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian res = cnx->egl.eglWaitClient(); 1281ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian } else { 1282ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian res = cnx->egl.eglWaitGL(); 1283518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1284518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return res; 1285518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1286518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1287518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglBindAPI(EGLenum api) 1288518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1289518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1290518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1291518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (egl_init_drivers() == EGL_FALSE) { 1292518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_PARAMETER, EGL_FALSE); 1293518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1294518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1295518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // bind this API on all EGLs 1296518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean res = EGL_TRUE; 1297ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 1298ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->dso && cnx->egl.eglBindAPI) { 1299ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian res = cnx->egl.eglBindAPI(api); 1300518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1301518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return res; 1302518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1303518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1304518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLenum eglQueryAPI(void) 1305518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1306518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1307518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1308518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (egl_init_drivers() == EGL_FALSE) { 1309518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_PARAMETER, EGL_FALSE); 1310518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1311518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1312ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 1313ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->dso && cnx->egl.eglQueryAPI) { 1314ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return cnx->egl.eglQueryAPI(); 1315518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1316ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian 1317518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // or, it can only be OpenGL ES 1318518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_OPENGL_ES_API; 1319518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1320518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1321518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglReleaseThread(void) 1322518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1323518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1324518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 13254e620ddce344e946ced992f61a69c367ff92fe24Mathias Agopian#if EGL_TRACE 13264e620ddce344e946ced992f61a69c367ff92fe24Mathias Agopian if (getEGLDebugLevel() > 0) 13274e620ddce344e946ced992f61a69c367ff92fe24Mathias Agopian GLTrace_eglReleaseThread(); 13284e620ddce344e946ced992f61a69c367ff92fe24Mathias Agopian#endif 13294e620ddce344e946ced992f61a69c367ff92fe24Mathias Agopian 1330518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // If there is context bound to the thread, release it 1331fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian egl_display_t::loseCurrent(get_context(getContext())); 1332518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1333ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 1334ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->dso && cnx->egl.eglReleaseThread) { 1335ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian cnx->egl.eglReleaseThread(); 1336518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1337518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_tls_t::clearTLS(); 1338518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_TRUE; 1339518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1340518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1341518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLSurface eglCreatePbufferFromClientBuffer( 1342518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, 1343518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLConfig config, const EGLint *attrib_list) 1344518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1345518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1346518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1347b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_connection_t* cnx = NULL; 1348b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display_connection(dpy, cnx); 1349b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall if (!dp) return EGL_FALSE; 1350518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (cnx->egl.eglCreatePbufferFromClientBuffer) { 1351518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return cnx->egl.eglCreatePbufferFromClientBuffer( 13527773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian dp->disp.dpy, buftype, buffer, config, attrib_list); 1353518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1354518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_CONFIG, EGL_NO_SURFACE); 1355518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1356518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1357518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 1358518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// EGL_EGLEXT_VERSION 3 1359518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 1360518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1361518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglLockSurfaceKHR(EGLDisplay dpy, EGLSurface surface, 1362518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian const EGLint *attrib_list) 1363518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1364518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1365518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1366b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1367518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1368518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1369b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall SurfaceRef _s(dp.get(), surface); 13705b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 13715b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 1372518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1373518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * const s = get_surface(surface); 1374518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (s->cnx->egl.eglLockSurfaceKHR) { 1375518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return s->cnx->egl.eglLockSurfaceKHR( 1376ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian dp->disp.dpy, s->surface, attrib_list); 1377518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1378518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_DISPLAY, EGL_FALSE); 1379518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1380518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1381518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglUnlockSurfaceKHR(EGLDisplay dpy, EGLSurface surface) 1382518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1383518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1384518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1385b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1386518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1387518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1388b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall SurfaceRef _s(dp.get(), surface); 13895b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 13905b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 1391518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1392518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * const s = get_surface(surface); 1393518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (s->cnx->egl.eglUnlockSurfaceKHR) { 1394ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return s->cnx->egl.eglUnlockSurfaceKHR(dp->disp.dpy, s->surface); 1395518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1396518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_DISPLAY, EGL_FALSE); 1397518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1398518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1399518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, 1400518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLClientBuffer buffer, const EGLint *attrib_list) 1401518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1402518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1403518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1404b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1405518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_NO_IMAGE_KHR; 1406518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1407b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall ContextRef _c(dp.get(), ctx); 14087c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian egl_context_t * const c = _c.get(); 1409518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 14107c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian EGLImageKHR result = EGL_NO_IMAGE_KHR; 14117c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian egl_connection_t* const cnx = &gEGLImpl; 14127c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian if (cnx->dso && cnx->egl.eglCreateImageKHR) { 14137c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian result = cnx->egl.eglCreateImageKHR( 14147c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian dp->disp.dpy, 14157c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian c ? c->context : EGL_NO_CONTEXT, 14167c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian target, buffer, attrib_list); 1417518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 14187c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian return result; 1419518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1420518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1421518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR img) 1422518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1423518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1424518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1425b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1426518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1427518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1428646a5c593f9819dc5da6a1ec859bc70cb7ba096fSteven Holte EGLBoolean result = EGL_FALSE; 1429ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 14307c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian if (cnx->dso && cnx->egl.eglDestroyImageKHR) { 1431646a5c593f9819dc5da6a1ec859bc70cb7ba096fSteven Holte result = cnx->egl.eglDestroyImageKHR(dp->disp.dpy, img); 1432518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1433646a5c593f9819dc5da6a1ec859bc70cb7ba096fSteven Holte return result; 1434518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1435518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1436518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 1437518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// EGL_EGLEXT_VERSION 5 1438518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 1439518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1440518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1441518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLSyncKHR eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list) 1442518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1443518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1444518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1445b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1446518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_NO_SYNC_KHR; 1447518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1448518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLSyncKHR result = EGL_NO_SYNC_KHR; 14497c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian egl_connection_t* const cnx = &gEGLImpl; 14507c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian if (cnx->dso && cnx->egl.eglCreateSyncKHR) { 14517c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian result = cnx->egl.eglCreateSyncKHR(dp->disp.dpy, type, attrib_list); 1452518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 14537c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian return result; 1454518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1455518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1456518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync) 1457518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1458518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1459518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1460b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1461518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1462518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1463518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean result = EGL_FALSE; 14647c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian egl_connection_t* const cnx = &gEGLImpl; 14657c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian if (cnx->dso && cnx->egl.eglDestroySyncKHR) { 14667c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian result = cnx->egl.eglDestroySyncKHR(dp->disp.dpy, sync); 1467518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1468518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return result; 1469518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1470518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1471e9b3dfb7d5cc233747407381a51a081c335dc076Mathias AgopianEGLBoolean eglSignalSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode) { 1472e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian clearError(); 1473e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 1474e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian const egl_display_ptr dp = validate_display(dpy); 1475e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian if (!dp) return EGL_FALSE; 1476e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 1477e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian EGLBoolean result = EGL_FALSE; 1478e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian egl_connection_t* const cnx = &gEGLImpl; 1479e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian if (cnx->dso && cnx->egl.eglSignalSyncKHR) { 1480e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian result = cnx->egl.eglSignalSyncKHR( 1481e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian dp->disp.dpy, sync, mode); 1482e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian } 1483e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian return result; 1484e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian} 1485e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 14867c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias AgopianEGLint eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, 14877c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian EGLint flags, EGLTimeKHR timeout) 1488518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1489518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1490518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1491b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1492518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1493518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 14947c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian EGLBoolean result = EGL_FALSE; 14957c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian egl_connection_t* const cnx = &gEGLImpl; 14967c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian if (cnx->dso && cnx->egl.eglClientWaitSyncKHR) { 14977c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian result = cnx->egl.eglClientWaitSyncKHR( 14987c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian dp->disp.dpy, sync, flags, timeout); 1499518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 15007c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian return result; 1501518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1502518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 15037c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias AgopianEGLBoolean eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync, 15047c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian EGLint attribute, EGLint *value) 1505518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1506518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1507518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1508b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1509518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1510518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 15117c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian EGLBoolean result = EGL_FALSE; 15127c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian egl_connection_t* const cnx = &gEGLImpl; 15137c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian if (cnx->dso && cnx->egl.eglGetSyncAttribKHR) { 15147c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian result = cnx->egl.eglGetSyncAttribKHR( 15157c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian dp->disp.dpy, sync, attribute, value); 1516518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 15177c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian return result; 1518518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1519518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1520518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 15212bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian// EGL_EGLEXT_VERSION 15 1522518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 1523518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 15242bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias AgopianEGLint eglWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags) { 1525331841b96b92646c93c87627c03f77b892f711cdJamie Gennis clearError(); 1526331841b96b92646c93c87627c03f77b892f711cdJamie Gennis const egl_display_ptr dp = validate_display(dpy); 15272bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian if (!dp) return EGL_FALSE; 15282bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian EGLint result = EGL_FALSE; 1529331841b96b92646c93c87627c03f77b892f711cdJamie Gennis egl_connection_t* const cnx = &gEGLImpl; 15302bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian if (cnx->dso && cnx->egl.eglWaitSyncKHR) { 15312bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian result = cnx->egl.eglWaitSyncKHR(dp->disp.dpy, sync, flags); 1532331841b96b92646c93c87627c03f77b892f711cdJamie Gennis } 1533331841b96b92646c93c87627c03f77b892f711cdJamie Gennis return result; 1534331841b96b92646c93c87627c03f77b892f711cdJamie Gennis} 15351c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 15362bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian// ---------------------------------------------------------------------------- 15372bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian// ANDROID extensions 15382bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian// ---------------------------------------------------------------------------- 15392bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian 15402bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias AgopianEGLint eglDupNativeFenceFDANDROID(EGLDisplay dpy, EGLSyncKHR sync) 1541010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis{ 1542010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis clearError(); 1543010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis 1544010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis const egl_display_ptr dp = validate_display(dpy); 1545010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis if (!dp) return EGL_NO_NATIVE_FENCE_FD_ANDROID; 1546010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis 15472bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian EGLint result = EGL_NO_NATIVE_FENCE_FD_ANDROID; 1548010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis egl_connection_t* const cnx = &gEGLImpl; 15492bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian if (cnx->dso && cnx->egl.eglDupNativeFenceFDANDROID) { 15502bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian result = cnx->egl.eglDupNativeFenceFDANDROID(dp->disp.dpy, sync); 1551010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis } 1552010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis return result; 1553010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis} 1554010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis 15557284145d564fa8a422a8e564a38c730fb4a2962bAndy McFaddenEGLBoolean eglPresentationTimeANDROID(EGLDisplay dpy, EGLSurface surface, 15567284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden EGLnsecsANDROID time) 15577284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden{ 15587284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden clearError(); 15597284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden 15607284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden const egl_display_ptr dp = validate_display(dpy); 15617284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden if (!dp) { 15627284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden return EGL_FALSE; 15637284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden } 15647284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden 15657284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden SurfaceRef _s(dp.get(), surface); 15667284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden if (!_s.get()) { 15677284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden setError(EGL_BAD_SURFACE, EGL_FALSE); 15687284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden return EGL_FALSE; 15697284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden } 15707284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden 15717284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden egl_surface_t const * const s = get_surface(surface); 15727284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden native_window_set_buffers_timestamp(s->win.get(), time); 15737284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden 15747284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden return EGL_TRUE; 15757284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden} 15767284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden 15771c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang// ---------------------------------------------------------------------------- 15781c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang// NVIDIA extensions 15791c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang// ---------------------------------------------------------------------------- 15801c3d72a2291827fb15e2ef311a571c860e0dba41Jonas YangEGLuint64NV eglGetSystemTimeFrequencyNV() 15811c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang{ 15821c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang clearError(); 15831c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 15841c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang if (egl_init_drivers() == EGL_FALSE) { 15851c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang return setError(EGL_BAD_PARAMETER, EGL_FALSE); 15861c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang } 15871c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 15881c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang EGLuint64NV ret = 0; 1589ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 15901c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 1591ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->dso && cnx->egl.eglGetSystemTimeFrequencyNV) { 1592ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return cnx->egl.eglGetSystemTimeFrequencyNV(); 15931c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang } 15941c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 15950e8bbee5775d81c7bbc479b995496cac9238559fMathias Agopian return setErrorQuiet(EGL_BAD_DISPLAY, 0); 15961c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang} 15971c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 15981c3d72a2291827fb15e2ef311a571c860e0dba41Jonas YangEGLuint64NV eglGetSystemTimeNV() 15991c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang{ 16001c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang clearError(); 16011c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 16021c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang if (egl_init_drivers() == EGL_FALSE) { 16031c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang return setError(EGL_BAD_PARAMETER, EGL_FALSE); 16041c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang } 16051c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 16061c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang EGLuint64NV ret = 0; 1607ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 16081c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 1609ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->dso && cnx->egl.eglGetSystemTimeNV) { 1610ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return cnx->egl.eglGetSystemTimeNV(); 16111c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang } 16121c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 16130e8bbee5775d81c7bbc479b995496cac9238559fMathias Agopian return setErrorQuiet(EGL_BAD_DISPLAY, 0); 16141c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang} 1615a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza 1616a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza// ---------------------------------------------------------------------------- 1617a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza// Partial update extension 1618a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza// ---------------------------------------------------------------------------- 1619a894d082cfee8d12ee5913163a34ec5dc521d005Dan StozaEGLBoolean eglSetDamageRegionKHR(EGLDisplay dpy, EGLSurface surface, 1620a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza EGLint *rects, EGLint n_rects) 1621a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza{ 1622a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza clearError(); 1623a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza 1624a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza const egl_display_ptr dp = validate_display(dpy); 1625a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza if (!dp) { 1626a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza setError(EGL_BAD_DISPLAY, EGL_FALSE); 1627a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza return EGL_FALSE; 1628a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza } 1629a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza 1630a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza SurfaceRef _s(dp.get(), surface); 1631a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza if (!_s.get()) { 1632a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza setError(EGL_BAD_SURFACE, EGL_FALSE); 1633a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza return EGL_FALSE; 1634a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza } 1635a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza 1636a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza egl_surface_t const * const s = get_surface(surface); 1637a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza if (s->cnx->egl.eglSetDamageRegionKHR) { 1638a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza return s->cnx->egl.eglSetDamageRegionKHR(dp->disp.dpy, s->surface, 1639a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza rects, n_rects); 1640a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza } 1641a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza 1642a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza return EGL_FALSE; 1643a894d082cfee8d12ee5913163a34ec5dc521d005Dan Stoza} 1644