eglApi.cpp revision c3289c41e794117817895653300bd2cf7daa0a01
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 " 8321558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hall ; 84e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopianextern char const * const gExtensionString = 85e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian "EGL_KHR_image " // mandatory 86e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian "EGL_KHR_image_base " // mandatory 87e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian "EGL_KHR_image_pixmap " 88e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian "EGL_KHR_lock_surface " 89a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall#if (ENABLE_EGL_KHR_GL_COLORSPACE != 0) 90c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall "EGL_KHR_gl_colorspace " 91a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall#endif 92e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian "EGL_KHR_gl_texture_2D_image " 93e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian "EGL_KHR_gl_texture_cubemap_image " 94e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian "EGL_KHR_gl_renderbuffer_image " 95e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian "EGL_KHR_reusable_sync " 96e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian "EGL_KHR_fence_sync " 97f6d1c3930eeba6b089ba12fb82ecad1c6622e550Jamie Gennis "EGL_KHR_create_context " 98e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian "EGL_EXT_create_context_robustness " 99e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian "EGL_NV_system_time " 100e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian "EGL_ANDROID_image_native_buffer " // mandatory 1012bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian "EGL_KHR_wait_sync " // strongly recommended 102dbe9245e2e362b12e184cd33b9a27b0901f81244Jamie Gennis "EGL_ANDROID_recordable " // mandatory 103e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian ; 104e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 105e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian// extensions not exposed to applications but used by the ANDROID system 106e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian// "EGL_ANDROID_blob_cache " // strongly recommended 107e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian// "EGL_IMG_hibernate_process " // optional 108e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian// "EGL_ANDROID_native_fence_sync " // strongly recommended 109e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian// "EGL_ANDROID_framebuffer_target " // mandatory for HWC 1.1 110dbe9245e2e362b12e184cd33b9a27b0901f81244Jamie Gennis// "EGL_ANDROID_image_crop " // optional 111e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 112e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian/* 113e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian * EGL Extensions entry-points exposed to 3rd party applications 114e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian * (keep in sync with gExtensionString above) 115e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian * 116e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian */ 117e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopianstatic const extention_map_t sExtensionMap[] = { 118e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian // EGL_KHR_lock_surface 119518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian { "eglLockSurfaceKHR", 120518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian (__eglMustCastToProperFunctionPointerType)&eglLockSurfaceKHR }, 121518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian { "eglUnlockSurfaceKHR", 122518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian (__eglMustCastToProperFunctionPointerType)&eglUnlockSurfaceKHR }, 123e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 124e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian // EGL_KHR_image, EGL_KHR_image_base 125518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian { "eglCreateImageKHR", 126518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian (__eglMustCastToProperFunctionPointerType)&eglCreateImageKHR }, 127518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian { "eglDestroyImageKHR", 128518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian (__eglMustCastToProperFunctionPointerType)&eglDestroyImageKHR }, 129e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 130e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian // EGL_KHR_reusable_sync, EGL_KHR_fence_sync 131e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian { "eglCreateSyncKHR", 132e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian (__eglMustCastToProperFunctionPointerType)&eglCreateSyncKHR }, 133e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian { "eglDestroySyncKHR", 134e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian (__eglMustCastToProperFunctionPointerType)&eglDestroySyncKHR }, 135e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian { "eglClientWaitSyncKHR", 136e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian (__eglMustCastToProperFunctionPointerType)&eglClientWaitSyncKHR }, 137e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian { "eglSignalSyncKHR", 138e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian (__eglMustCastToProperFunctionPointerType)&eglSignalSyncKHR }, 139e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian { "eglGetSyncAttribKHR", 140e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian (__eglMustCastToProperFunctionPointerType)&eglGetSyncAttribKHR }, 141e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 142e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian // EGL_NV_system_time 1431c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang { "eglGetSystemTimeFrequencyNV", 1441c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang (__eglMustCastToProperFunctionPointerType)&eglGetSystemTimeFrequencyNV }, 1451c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang { "eglGetSystemTimeNV", 1461c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang (__eglMustCastToProperFunctionPointerType)&eglGetSystemTimeNV }, 147e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 1482bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian // EGL_KHR_wait_sync 1492bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian { "eglWaitSyncKHR", 1502bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian (__eglMustCastToProperFunctionPointerType)&eglWaitSyncKHR }, 151e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 152e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian // EGL_ANDROID_presentation_time 153e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian { "eglPresentationTimeANDROID", 154e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian (__eglMustCastToProperFunctionPointerType)&eglPresentationTimeANDROID }, 155518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}; 156518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 157e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian/* 158e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian * These extensions entry-points should not be exposed to applications. 159e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian * They're used internally by the Android EGL layer. 160e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian */ 161e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian#define FILTER_EXTENSIONS(procname) \ 162e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian (!strcmp((procname), "eglSetBlobCacheFuncsANDROID") || \ 163e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian !strcmp((procname), "eglHibernateProcessIMG") || \ 164e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian !strcmp((procname), "eglAwakenProcessIMG") || \ 165e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian !strcmp((procname), "eglDupNativeFenceFDANDROID")) 166e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 167e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 168e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 169518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// accesses protected by sExtensionMapMutex 170518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic DefaultKeyedVector<String8, __eglMustCastToProperFunctionPointerType> sGLExtentionMap; 171518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic int sGLExtentionSlot = 0; 172518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic pthread_mutex_t sExtensionMapMutex = PTHREAD_MUTEX_INITIALIZER; 173518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 174518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic void(*findProcAddress(const char* name, 175518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian const extention_map_t* map, size_t n))() { 176518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian for (uint32_t i=0 ; i<n ; i++) { 177518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!strcmp(name, map[i].name)) { 178518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return map[i].address; 179518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 180518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 181518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return NULL; 182518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 183518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 184518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 185518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 186518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianextern void setGLHooksThreadSpecific(gl_hooks_t const *value); 187518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianextern EGLBoolean egl_init_drivers(); 188518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianextern const __eglMustCastToProperFunctionPointerType gExtensionForwarders[MAX_NUMBER_OF_GL_EXTENSIONS]; 189a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamyextern int getEGLDebugLevel(); 190a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamyextern void setEGLDebugLevel(int level); 191518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianextern gl_hooks_t gHooksTrace; 192e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 193518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} // namespace android; 194518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 195e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 196518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 197518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 198518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic inline void clearError() { egl_tls_t::clearError(); } 199518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic inline EGLContext getContext() { return egl_tls_t::getContext(); } 200518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 201518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 202518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 203518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLDisplay eglGetDisplay(EGLNativeDisplayType display) 204518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 205518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 206518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 207c3289c41e794117817895653300bd2cf7daa0a01Dan Stoza uintptr_t index = reinterpret_cast<uintptr_t>(display); 208518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (index >= NUM_DISPLAYS) { 209518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_PARAMETER, EGL_NO_DISPLAY); 210518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 211518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 212518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (egl_init_drivers() == EGL_FALSE) { 213518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_PARAMETER, EGL_NO_DISPLAY); 214518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 215518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 216518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLDisplay dpy = egl_display_t::getFromNativeDisplay(display); 217518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return dpy; 218518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 219518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 220518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 221518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// Initialization 222518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 223518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 224518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) 225518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 226518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 227518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 228b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_display_ptr dp = get_display(dpy); 229518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE); 230518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 231518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean res = dp->initialize(major, minor); 232518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 233518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return res; 234518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 235518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 236518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglTerminate(EGLDisplay dpy) 237518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 238518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // NOTE: don't unload the drivers b/c some APIs can be called 239518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // after eglTerminate() has been called. eglTerminate() only 240518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // terminates an EGLDisplay, not a EGL itself. 241518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 242518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 243518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 244b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_display_ptr dp = get_display(dpy); 245518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE); 246518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 247518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean res = dp->terminate(); 2484774338bd0ad1ebe42c311fd0c72f13786b5c800Jesse Hall 249518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return res; 250518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 251518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 252518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 253518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// configuration 254518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 255518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 256518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglGetConfigs( EGLDisplay dpy, 257518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLConfig *configs, 258518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint config_size, EGLint *num_config) 259518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 260518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 261518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 262b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 263518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 264518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 2657773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian if (num_config==0) { 2667773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian return setError(EGL_BAD_PARAMETER, EGL_FALSE); 267518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 268518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 2697773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian EGLBoolean res = EGL_FALSE; 2707773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian *num_config = 0; 2717773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian 2727773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian egl_connection_t* const cnx = &gEGLImpl; 2737773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian if (cnx->dso) { 2747773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian res = cnx->egl.eglGetConfigs( 2757773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian dp->disp.dpy, configs, config_size, num_config); 276518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 2777773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian 2787773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian return res; 279518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 280518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 281518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglChooseConfig( EGLDisplay dpy, const EGLint *attrib_list, 282518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLConfig *configs, EGLint config_size, 283518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint *num_config) 284518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 285518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 286518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 287b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 288518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 289518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 290518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (num_config==0) { 291518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_PARAMETER, EGL_FALSE); 292518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 293518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 294518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean res = EGL_FALSE; 295518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian *num_config = 0; 296518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 297ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 298ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->dso) { 2991cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy if (attrib_list) { 3001cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy char value[PROPERTY_VALUE_MAX]; 3011cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy property_get("debug.egl.force_msaa", value, "false"); 3021cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy 3031cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy if (!strcmp(value, "true")) { 3041cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy size_t attribCount = 0; 3051cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy EGLint attrib = attrib_list[0]; 3061cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy 3071cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy // Only enable MSAA if the context is OpenGL ES 2.0 and 308be3c3e4ecad501eecfe1f7a424a792f0f7f3f307Romain Guy // if no caveat is requested 3091cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy const EGLint *attribRendererable = NULL; 3101cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy const EGLint *attribCaveat = NULL; 3111cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy 3121cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy // Count the number of attributes and look for 313be3c3e4ecad501eecfe1f7a424a792f0f7f3f307Romain Guy // EGL_RENDERABLE_TYPE and EGL_CONFIG_CAVEAT 3141cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy while (attrib != EGL_NONE) { 3151cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy attrib = attrib_list[attribCount]; 3161cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy switch (attrib) { 3171cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy case EGL_RENDERABLE_TYPE: 3181cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy attribRendererable = &attrib_list[attribCount]; 3191cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy break; 3201cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy case EGL_CONFIG_CAVEAT: 3211cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy attribCaveat = &attrib_list[attribCount]; 3221cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy break; 3231cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy } 3241cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy attribCount++; 3251cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy } 3261cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy 3271cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy if (attribRendererable && attribRendererable[1] == EGL_OPENGL_ES2_BIT && 3281cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy (!attribCaveat || attribCaveat[1] != EGL_NONE)) { 3294774338bd0ad1ebe42c311fd0c72f13786b5c800Jesse Hall 3301cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy // Insert 2 extra attributes to force-enable MSAA 4x 3311cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy EGLint aaAttribs[attribCount + 4]; 3321cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy aaAttribs[0] = EGL_SAMPLE_BUFFERS; 3331cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy aaAttribs[1] = 1; 3341cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy aaAttribs[2] = EGL_SAMPLES; 3351cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy aaAttribs[3] = 4; 3361cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy 3371cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy memcpy(&aaAttribs[4], attrib_list, attribCount * sizeof(EGLint)); 3381cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy 3391cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy EGLint numConfigAA; 3401cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy EGLBoolean resAA = cnx->egl.eglChooseConfig( 3411cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy dp->disp.dpy, aaAttribs, configs, config_size, &numConfigAA); 3421cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy 3431cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy if (resAA == EGL_TRUE && numConfigAA > 0) { 3441cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy ALOGD("Enabling MSAA 4x"); 3451cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy *num_config = numConfigAA; 3461cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy return resAA; 3471cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy } 3481cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy } 3491cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy } 3501cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy } 3511cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy 3527773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian res = cnx->egl.eglChooseConfig( 3537773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian dp->disp.dpy, attrib_list, configs, config_size, num_config); 354518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 355518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return res; 356518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 357518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 358518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, 359518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint attribute, EGLint *value) 360518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 361518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 362518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 363b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_connection_t* cnx = NULL; 364b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display_connection(dpy, cnx); 365b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall if (!dp) return EGL_FALSE; 3664774338bd0ad1ebe42c311fd0c72f13786b5c800Jesse Hall 367518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return cnx->egl.eglGetConfigAttrib( 3687773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian dp->disp.dpy, config, attribute, value); 369518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 370518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 371518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 372518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// surfaces 373518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 374518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 375a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall// The EGL_KHR_gl_colorspace spec hasn't been ratified yet, so these haven't 376c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall// been added to the Khronos egl.h. 377c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall#define EGL_GL_COLORSPACE_KHR EGL_VG_COLORSPACE 378c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall#define EGL_GL_COLORSPACE_SRGB_KHR EGL_VG_COLORSPACE_sRGB 379c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall#define EGL_GL_COLORSPACE_LINEAR_KHR EGL_VG_COLORSPACE_LINEAR 380c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall 381c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall// Turn linear formats into corresponding sRGB formats when colorspace is 382c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall// EGL_GL_COLORSPACE_SRGB_KHR, or turn sRGB formats into corresponding linear 383c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall// formats when colorspace is EGL_GL_COLORSPACE_LINEAR_KHR. In any cases where 384c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall// the modification isn't possible, the original format is returned. 385c2e41222bf02a6579763974f82d65875cfa43481Jesse Hallstatic int modifyFormatColorspace(int fmt, EGLint colorspace) { 386c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall if (colorspace == EGL_GL_COLORSPACE_LINEAR_KHR) { 387c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall switch (fmt) { 388c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall case HAL_PIXEL_FORMAT_sRGB_A_8888: return HAL_PIXEL_FORMAT_RGBA_8888; 389bc2a90b024db82e3a277e5b366da17e00b21d98bJesse Hall case HAL_PIXEL_FORMAT_sRGB_X_8888: return HAL_PIXEL_FORMAT_RGBX_8888; 390c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall } 391c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall } else if (colorspace == EGL_GL_COLORSPACE_SRGB_KHR) { 392c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall switch (fmt) { 393c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall case HAL_PIXEL_FORMAT_RGBA_8888: return HAL_PIXEL_FORMAT_sRGB_A_8888; 394bc2a90b024db82e3a277e5b366da17e00b21d98bJesse Hall case HAL_PIXEL_FORMAT_RGBX_8888: return HAL_PIXEL_FORMAT_sRGB_X_8888; 395c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall } 396c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall } 397c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall return fmt; 398c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall} 399c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall 400518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLSurface eglCreateWindowSurface( EGLDisplay dpy, EGLConfig config, 401518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian NativeWindowType window, 402518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian const EGLint *attrib_list) 403518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 404518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 405518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 406b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_connection_t* cnx = NULL; 407b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_display_ptr dp = validate_display_connection(dpy, cnx); 408b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall if (dp) { 409ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian EGLDisplay iDpy = dp->disp.dpy; 410518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 411d566ce3a26ce781ecdbc479aaba0e172b7c807a9Andy McFadden int result = native_window_api_connect(window, NATIVE_WINDOW_API_EGL); 412d566ce3a26ce781ecdbc479aaba0e172b7c807a9Andy McFadden if (result != OK) { 413d566ce3a26ce781ecdbc479aaba0e172b7c807a9Andy McFadden ALOGE("eglCreateWindowSurface: native_window_api_connect (win=%p) " 414d566ce3a26ce781ecdbc479aaba0e172b7c807a9Andy McFadden "failed (%#x) (already connected to another API?)", 415d566ce3a26ce781ecdbc479aaba0e172b7c807a9Andy McFadden window, result); 41677a9b4a6bd21188e2744ae9dcd8092c6837bff7cJonathan Hamilton return setError(EGL_BAD_ALLOC, EGL_NO_SURFACE); 41781a63350527cafce6929309533c58586878f10b5Mathias Agopian } 41881a63350527cafce6929309533c58586878f10b5Mathias Agopian 4190f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian // Set the native window's buffers format to match what this config requests. 420c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall // Whether to use sRGB gamma is not part of the EGLconfig, but is part 421c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall // of our native format. So if sRGB gamma is requested, we have to 422c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall // modify the EGLconfig's format before setting the native window's 423c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall // format. 424f4486c6ea4bcb728ee0f38df7a8ec75c389d9d2eMathias Agopian#if WORKAROUND_BUG_10194508 425f4486c6ea4bcb728ee0f38df7a8ec75c389d9d2eMathias Agopian#warning "WORKAROUND_10194508 enabled" 426f4486c6ea4bcb728ee0f38df7a8ec75c389d9d2eMathias Agopian EGLint format; 427f4486c6ea4bcb728ee0f38df7a8ec75c389d9d2eMathias Agopian if (!cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_NATIVE_VISUAL_ID, 428f4486c6ea4bcb728ee0f38df7a8ec75c389d9d2eMathias Agopian &format)) { 429f4486c6ea4bcb728ee0f38df7a8ec75c389d9d2eMathias Agopian ALOGE("eglGetConfigAttrib(EGL_NATIVE_VISUAL_ID) failed: %#x", 430f4486c6ea4bcb728ee0f38df7a8ec75c389d9d2eMathias Agopian eglGetError()); 431f4486c6ea4bcb728ee0f38df7a8ec75c389d9d2eMathias Agopian format = 0; 432f4486c6ea4bcb728ee0f38df7a8ec75c389d9d2eMathias Agopian } 433f4486c6ea4bcb728ee0f38df7a8ec75c389d9d2eMathias Agopian if (attrib_list) { 434f4486c6ea4bcb728ee0f38df7a8ec75c389d9d2eMathias Agopian for (const EGLint* attr = attrib_list; *attr != EGL_NONE; 435f4486c6ea4bcb728ee0f38df7a8ec75c389d9d2eMathias Agopian attr += 2) { 436f4486c6ea4bcb728ee0f38df7a8ec75c389d9d2eMathias Agopian if (*attr == EGL_GL_COLORSPACE_KHR && 437f4486c6ea4bcb728ee0f38df7a8ec75c389d9d2eMathias Agopian dp->haveExtension("EGL_KHR_gl_colorspace")) { 438a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall if (ENABLE_EGL_KHR_GL_COLORSPACE) { 439a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall format = modifyFormatColorspace(format, *(attr+1)); 440a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall } else { 441a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall // Normally we'd pass through unhandled attributes to 442a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall // the driver. But in case the driver implements this 443a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall // extension but we're disabling it, we want to prevent 444a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall // it getting through -- support will be broken without 445a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall // our help. 446a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall ALOGE("sRGB window surfaces not supported"); 447a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall return setError(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE); 448a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall } 449f4486c6ea4bcb728ee0f38df7a8ec75c389d9d2eMathias Agopian } 450f4486c6ea4bcb728ee0f38df7a8ec75c389d9d2eMathias Agopian } 451f4486c6ea4bcb728ee0f38df7a8ec75c389d9d2eMathias Agopian } 452f4486c6ea4bcb728ee0f38df7a8ec75c389d9d2eMathias Agopian#else 4530f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian // by default, just pick RGBA_8888 4540f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian EGLint format = HAL_PIXEL_FORMAT_RGBA_8888; 4550f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian 4560f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian EGLint a = 0; 4570f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_ALPHA_SIZE, &a); 4580f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian if (a > 0) { 4590f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian // alpha-channel requested, there's really only one suitable format 4600f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian format = HAL_PIXEL_FORMAT_RGBA_8888; 4610f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian } else { 4620f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian EGLint r, g, b; 4630f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian r = g = b = 0; 4640f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_RED_SIZE, &r); 4650f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_GREEN_SIZE, &g); 4660f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_BLUE_SIZE, &b); 4670f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian EGLint colorDepth = r + g + b; 4680f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian if (colorDepth <= 16) { 4690f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian format = HAL_PIXEL_FORMAT_RGB_565; 4700f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian } else { 4710f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian format = HAL_PIXEL_FORMAT_RGBX_8888; 4720f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian } 473c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall } 4740f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian 4750f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian // now select a corresponding sRGB format if needed 4760f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian if (attrib_list && dp->haveExtension("EGL_KHR_gl_colorspace")) { 4770f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian for (const EGLint* attr = attrib_list; *attr != EGL_NONE; attr += 2) { 4780f288fcc9c1b2d23b1cff2f5c59689aef76b77aeMathias Agopian if (*attr == EGL_GL_COLORSPACE_KHR) { 479a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall if (ENABLE_EGL_KHR_GL_COLORSPACE) { 480a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall format = modifyFormatColorspace(format, *(attr+1)); 481a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall } else { 482a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall // Normally we'd pass through unhandled attributes to 483a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall // the driver. But in case the driver implements this 484a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall // extension but we're disabling it, we want to prevent 485a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall // it getting through -- support will be broken without 486a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall // our help. 487a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall ALOGE("sRGB window surfaces not supported"); 488a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall return setError(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE); 489a2ba428a22125558a129c6ba4001dfc2169de2feJesse Hall } 490bee205fd58a27c10a0895de5339e76025d429d2bJamie Gennis } 491518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 492518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 493f4486c6ea4bcb728ee0f38df7a8ec75c389d9d2eMathias Agopian#endif 494c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall if (format != 0) { 495c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall int err = native_window_set_buffers_format(window, format); 496c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall if (err != 0) { 497c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall ALOGE("error setting native window pixel format: %s (%d)", 498c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall strerror(-err), err); 499c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL); 500c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall return setError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE); 501c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall } 502c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall } 503518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 50459769469e4b9b2d8b12c020eb44b030b3927a50bJamie Gennis // the EGL spec requires that a new EGLSurface default to swap interval 50559769469e4b9b2d8b12c020eb44b030b3927a50bJamie Gennis // 1, so explicitly set that on the window here. 50659769469e4b9b2d8b12c020eb44b030b3927a50bJamie Gennis ANativeWindow* anw = reinterpret_cast<ANativeWindow*>(window); 50759769469e4b9b2d8b12c020eb44b030b3927a50bJamie Gennis anw->setSwapInterval(anw, 1); 50859769469e4b9b2d8b12c020eb44b030b3927a50bJamie Gennis 509518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLSurface surface = cnx->egl.eglCreateWindowSurface( 5107773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian iDpy, config, window, attrib_list); 511518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (surface != EGL_NO_SURFACE) { 512b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_surface_t* s = new egl_surface_t(dp.get(), config, window, 513b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall surface, cnx); 514518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return s; 515518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 51681a63350527cafce6929309533c58586878f10b5Mathias Agopian 51781a63350527cafce6929309533c58586878f10b5Mathias Agopian // EGLSurface creation failed 51881a63350527cafce6929309533c58586878f10b5Mathias Agopian native_window_set_buffers_format(window, 0); 51981a63350527cafce6929309533c58586878f10b5Mathias Agopian native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL); 520518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 521518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_NO_SURFACE; 522518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 523518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 524518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLSurface eglCreatePixmapSurface( EGLDisplay dpy, EGLConfig config, 525518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian NativePixmapType pixmap, 526518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian const EGLint *attrib_list) 527518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 528518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 529518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 530b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_connection_t* cnx = NULL; 531b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_display_ptr dp = validate_display_connection(dpy, cnx); 532b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall if (dp) { 533518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLSurface surface = cnx->egl.eglCreatePixmapSurface( 5347773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian dp->disp.dpy, config, pixmap, attrib_list); 535518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (surface != EGL_NO_SURFACE) { 536b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_surface_t* s = new egl_surface_t(dp.get(), config, NULL, 537b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall surface, cnx); 538518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return s; 539518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 540518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 541518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_NO_SURFACE; 542518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 543518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 544518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLSurface eglCreatePbufferSurface( EGLDisplay dpy, EGLConfig config, 545518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian const EGLint *attrib_list) 546518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 547518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 548518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 549b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_connection_t* cnx = NULL; 550b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_display_ptr dp = validate_display_connection(dpy, cnx); 551b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall if (dp) { 552518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLSurface surface = cnx->egl.eglCreatePbufferSurface( 5537773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian dp->disp.dpy, config, attrib_list); 554518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (surface != EGL_NO_SURFACE) { 555b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_surface_t* s = new egl_surface_t(dp.get(), config, NULL, 556b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall surface, cnx); 557518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return s; 558518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 559518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 560518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_NO_SURFACE; 561518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 5624774338bd0ad1ebe42c311fd0c72f13786b5c800Jesse Hall 563518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface) 564518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 565518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 566518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 567b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 568518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 569518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 570b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall SurfaceRef _s(dp.get(), surface); 5715b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 5725b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 573518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 574518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t * const s = get_surface(surface); 575ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian EGLBoolean result = s->cnx->egl.eglDestroySurface(dp->disp.dpy, s->surface); 576518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (result == EGL_TRUE) { 577518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian _s.terminate(); 578518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 579518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return result; 580518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 581518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 582518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglQuerySurface( EGLDisplay dpy, EGLSurface surface, 583518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint attribute, EGLint *value) 584518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 585518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 586518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 587b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 588518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 589518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 590b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall SurfaceRef _s(dp.get(), surface); 5915b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 5925b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 593518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 594518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * const s = get_surface(surface); 5957773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian return s->cnx->egl.eglQuerySurface( 5967773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian dp->disp.dpy, s->surface, attribute, value); 597518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 598518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 599e8696a40e09b24b634214684d18526187b316a2fJamie Gennisvoid EGLAPI eglBeginFrame(EGLDisplay dpy, EGLSurface surface) { 6001c8e95cf86f2182986385bc1ee85f13f425f3a3aJamie Gennis ATRACE_CALL(); 601e8696a40e09b24b634214684d18526187b316a2fJamie Gennis clearError(); 602e8696a40e09b24b634214684d18526187b316a2fJamie Gennis 603b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 604e8696a40e09b24b634214684d18526187b316a2fJamie Gennis if (!dp) { 605e8696a40e09b24b634214684d18526187b316a2fJamie Gennis return; 606e8696a40e09b24b634214684d18526187b316a2fJamie Gennis } 607e8696a40e09b24b634214684d18526187b316a2fJamie Gennis 608b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall SurfaceRef _s(dp.get(), surface); 609e8696a40e09b24b634214684d18526187b316a2fJamie Gennis if (!_s.get()) { 610e8696a40e09b24b634214684d18526187b316a2fJamie Gennis setError(EGL_BAD_SURFACE, EGL_FALSE); 611e8696a40e09b24b634214684d18526187b316a2fJamie Gennis return; 612e8696a40e09b24b634214684d18526187b316a2fJamie Gennis } 613e8696a40e09b24b634214684d18526187b316a2fJamie Gennis} 614e8696a40e09b24b634214684d18526187b316a2fJamie Gennis 615518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 616518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// Contexts 617518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 618518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 619518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config, 620518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLContext share_list, const EGLint *attrib_list) 621518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 622518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 623518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 624b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_connection_t* cnx = NULL; 625b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display_connection(dpy, cnx); 6260673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock if (dp) { 627518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (share_list != EGL_NO_CONTEXT) { 6280673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock if (!ContextRef(dp.get(), share_list).get()) { 6290673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock return setError(EGL_BAD_CONTEXT, EGL_NO_CONTEXT); 6300673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock } 631518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t* const c = get_context(share_list); 632518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian share_list = c->context; 633518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 634518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLContext context = cnx->egl.eglCreateContext( 6357773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian dp->disp.dpy, config, share_list, attrib_list); 636518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (context != EGL_NO_CONTEXT) { 637518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // figure out if it's a GLESv1 or GLESv2 638518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian int version = 0; 639518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (attrib_list) { 640518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian while (*attrib_list != EGL_NONE) { 641518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian GLint attr = *attrib_list++; 642518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian GLint value = *attrib_list++; 643518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (attr == EGL_CONTEXT_CLIENT_VERSION) { 644518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (value == 1) { 6457773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian version = egl_connection_t::GLESv1_INDEX; 6464774338bd0ad1ebe42c311fd0c72f13786b5c800Jesse Hall } else if (value == 2 || value == 3) { 6477773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian version = egl_connection_t::GLESv2_INDEX; 648518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 649518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 650518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian }; 651518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 652b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_context_t* c = new egl_context_t(dpy, context, config, cnx, 653b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall version); 6540469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#if EGL_TRACE 655a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy if (getEGLDebugLevel() > 0) 6560469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLTrace_eglCreateContext(version, c); 6570469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#endif 658518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return c; 659518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 660518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 661518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_NO_CONTEXT; 662518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 663518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 664518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx) 665518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 666518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 667518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 668b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 6695b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!dp) 6705b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return EGL_FALSE; 671518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 672b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall ContextRef _c(dp.get(), ctx); 6735b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_c.get()) 6745b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_CONTEXT, EGL_FALSE); 6754774338bd0ad1ebe42c311fd0c72f13786b5c800Jesse Hall 676518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t * const c = get_context(ctx); 677ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian EGLBoolean result = c->cnx->egl.eglDestroyContext(dp->disp.dpy, c->context); 678518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (result == EGL_TRUE) { 679518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian _c.terminate(); 680518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 681518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return result; 682518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 683518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 684518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglMakeCurrent( EGLDisplay dpy, EGLSurface draw, 685518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLSurface read, EGLContext ctx) 686518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 687518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 688518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 689b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_display_ptr dp = validate_display(dpy); 690518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE); 691518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 6925b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian // If ctx is not EGL_NO_CONTEXT, read is not EGL_NO_SURFACE, or draw is not 6935b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian // EGL_NO_SURFACE, then an EGL_NOT_INITIALIZED error is generated if dpy is 6945b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian // a valid but uninitialized display. 695518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if ( (ctx != EGL_NO_CONTEXT) || (read != EGL_NO_SURFACE) || 696518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian (draw != EGL_NO_SURFACE) ) { 697518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp->isReady()) return setError(EGL_NOT_INITIALIZED, EGL_FALSE); 698518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 699518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 700518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // get a reference to the object passed in 701b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall ContextRef _c(dp.get(), ctx); 702b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall SurfaceRef _d(dp.get(), draw); 703b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall SurfaceRef _r(dp.get(), read); 704518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 705518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // validate the context (if not EGL_NO_CONTEXT) 7065b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if ((ctx != EGL_NO_CONTEXT) && !_c.get()) { 707518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // EGL_NO_CONTEXT is valid 7080673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock return setError(EGL_BAD_CONTEXT, EGL_FALSE); 709518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 710518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 711518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // these are the underlying implementation's object 712518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLContext impl_ctx = EGL_NO_CONTEXT; 713518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLSurface impl_draw = EGL_NO_SURFACE; 714518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLSurface impl_read = EGL_NO_SURFACE; 715518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 716518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // these are our objects structs passed in 717518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t * c = NULL; 718518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * d = NULL; 719518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * r = NULL; 720518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 721518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // these are the current objects structs 722518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t * cur_c = get_context(getContext()); 7234774338bd0ad1ebe42c311fd0c72f13786b5c800Jesse Hall 724518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (ctx != EGL_NO_CONTEXT) { 725518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian c = get_context(ctx); 726518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian impl_ctx = c->context; 727518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } else { 728518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // no context given, use the implementation of the current context 7290673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock if (draw != EGL_NO_SURFACE || read != EGL_NO_SURFACE) { 7300673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock // calling eglMakeCurrent( ..., !=0, !=0, EGL_NO_CONTEXT); 7310673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock return setError(EGL_BAD_MATCH, EGL_FALSE); 7320673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock } 733518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (cur_c == NULL) { 734518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // no current context 735518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // not an error, there is just no current context. 736518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_TRUE; 737518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 738518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 739518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 740518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // retrieve the underlying implementation's draw EGLSurface 741518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (draw != EGL_NO_SURFACE) { 7420673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock if (!_d.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE); 743518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian d = get_surface(draw); 744518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian impl_draw = d->surface; 745518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 746518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 747518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // retrieve the underlying implementation's read EGLSurface 748518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (read != EGL_NO_SURFACE) { 7490673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock if (!_r.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE); 750518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian r = get_surface(read); 751518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian impl_read = r->surface; 752518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 753518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 754518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 755b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall EGLBoolean result = dp->makeCurrent(c, cur_c, 756fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian draw, read, ctx, 757fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian impl_draw, impl_read, impl_ctx); 758518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 759518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (result == EGL_TRUE) { 760fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian if (c) { 761518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian setGLHooksThreadSpecific(c->cnx->hooks[c->version]); 762518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_tls_t::setContext(ctx); 7630469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#if EGL_TRACE 764a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy if (getEGLDebugLevel() > 0) 76593a826f78f6313db791e6fc880439189897651b3Siva Velusamy GLTrace_eglMakeCurrent(c->version, c->cnx->hooks[c->version], ctx); 7660469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#endif 767518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian _c.acquire(); 768518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian _r.acquire(); 769518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian _d.acquire(); 770518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } else { 771518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian setGLHooksThreadSpecific(&gHooksNoContext); 772518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_tls_t::setContext(EGL_NO_CONTEXT); 773518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 7745fecea776a5f093c21ac1a0ad3552b847d4be23eMathias Agopian } else { 775e6f43ddce78d6846af12550ff9193c5c6fe5844bSteve Block // this will ALOGE the error 77663108c34ec181e923b68ee840bb7960f205466a7Mathias Agopian egl_connection_t* const cnx = &gEGLImpl; 77763108c34ec181e923b68ee840bb7960f205466a7Mathias Agopian result = setError(cnx->egl.eglGetError(), EGL_FALSE); 778518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 779518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return result; 780518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 781518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 782518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 783518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglQueryContext( EGLDisplay dpy, EGLContext ctx, 784518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint attribute, EGLint *value) 785518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 786518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 787518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 788b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 789518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 790518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 791b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall ContextRef _c(dp.get(), ctx); 792518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!_c.get()) return setError(EGL_BAD_CONTEXT, EGL_FALSE); 793518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 794518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t * const c = get_context(ctx); 7957773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian return c->cnx->egl.eglQueryContext( 7967773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian dp->disp.dpy, c->context, attribute, value); 797518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 798518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 799518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 800518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLContext eglGetCurrentContext(void) 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_CONTEXT. 804518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 805518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 806518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 807518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLContext ctx = getContext(); 808518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return ctx; 809518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 810518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 811518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLSurface eglGetCurrentSurface(EGLint readdraw) 812518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 813518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // could be called before eglInitialize(), but we wouldn't have a context 814518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // then, and this function would correctly return EGL_NO_SURFACE. 815518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 816518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 817518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 818518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLContext ctx = getContext(); 819518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (ctx) { 820518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t const * const c = get_context(ctx); 821518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!c) return setError(EGL_BAD_CONTEXT, EGL_NO_SURFACE); 822518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian switch (readdraw) { 823518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian case EGL_READ: return c->read; 8244774338bd0ad1ebe42c311fd0c72f13786b5c800Jesse Hall case EGL_DRAW: return c->draw; 825518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian default: return setError(EGL_BAD_PARAMETER, EGL_NO_SURFACE); 826518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 827518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 828518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_NO_SURFACE; 829518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 830518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 831518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLDisplay eglGetCurrentDisplay(void) 832518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 833518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // could be called before eglInitialize(), but we wouldn't have a context 834518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // then, and this function would correctly return EGL_NO_DISPLAY. 835518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 836518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 837518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 838518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLContext ctx = getContext(); 839518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (ctx) { 840518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t const * const c = get_context(ctx); 841518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!c) return setError(EGL_BAD_CONTEXT, EGL_NO_SURFACE); 842518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return c->dpy; 843518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 844518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_NO_DISPLAY; 845518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 846518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 847518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglWaitGL(void) 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.eglWaitGL(); 856518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 857518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 858518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglWaitNative(EGLint engine) 859518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 860518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 861518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 862ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 863ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (!cnx->dso) 864ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return setError(EGL_BAD_CONTEXT, EGL_FALSE); 865ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian 866ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return cnx->egl.eglWaitNative(engine); 867518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 868518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 869518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLint eglGetError(void) 870518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 871ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian EGLint err = EGL_SUCCESS; 872ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 873ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->dso) { 874ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian err = cnx->egl.eglGetError(); 875518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 876ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (err == EGL_SUCCESS) { 877ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian err = egl_tls_t::getError(); 878ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian } 879ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return err; 880518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 881518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 882c07b52060acd627c8510c1a9151e0753fce76330Jesse Hallstatic __eglMustCastToProperFunctionPointerType findBuiltinGLWrapper( 883c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall const char* procname) { 884c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall const egl_connection_t* cnx = &gEGLImpl; 885c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall void* proc = NULL; 886c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall 887c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall proc = dlsym(cnx->libGles2, procname); 888c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall if (proc) return (__eglMustCastToProperFunctionPointerType)proc; 889c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall 890c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall proc = dlsym(cnx->libGles1, procname); 891c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall if (proc) return (__eglMustCastToProperFunctionPointerType)proc; 892c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall 893c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall return NULL; 894c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall} 895c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall 896518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian__eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname) 897518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 898518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // eglGetProcAddress() could be the very first function called 899518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // in which case we must make sure we've initialized ourselves, this 900518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // happens the first time egl_get_display() is called. 901518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 902518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 903518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 904518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (egl_init_drivers() == EGL_FALSE) { 905518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian setError(EGL_BAD_PARAMETER, NULL); 906518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return NULL; 907518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 908518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 909e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian if (FILTER_EXTENSIONS(procname)) { 910aca51c06f38155f1435fbc6944d7fc0a9bf1e4e9Jamie Gennis return NULL; 911aca51c06f38155f1435fbc6944d7fc0a9bf1e4e9Jamie Gennis } 912aca51c06f38155f1435fbc6944d7fc0a9bf1e4e9Jamie Gennis 913518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian __eglMustCastToProperFunctionPointerType addr; 914e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian addr = findProcAddress(procname, sExtensionMap, NELEM(sExtensionMap)); 915518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (addr) return addr; 916518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 917c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall addr = findBuiltinGLWrapper(procname); 918c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall if (addr) return addr; 919aca51c06f38155f1435fbc6944d7fc0a9bf1e4e9Jamie Gennis 920518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // this protects accesses to sGLExtentionMap and sGLExtentionSlot 921518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian pthread_mutex_lock(&sExtensionMapMutex); 922518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 923518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian /* 924518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * Since eglGetProcAddress() is not associated to anything, it needs 925518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * to return a function pointer that "works" regardless of what 926518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * the current context is. 927518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * 928518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * For this reason, we return a "forwarder", a small stub that takes 929518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * care of calling the function associated with the context 930518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * currently bound. 931518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * 932518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * We first look for extensions we've already resolved, if we're seeing 933518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * this extension for the first time, we go through all our 934518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * implementations and call eglGetProcAddress() and record the 935518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * result in the appropriate implementation hooks and return the 936518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * address of the forwarder corresponding to that hook set. 937518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * 938518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian */ 939518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 940518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian const String8 name(procname); 941518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian addr = sGLExtentionMap.valueFor(name); 942518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian const int slot = sGLExtentionSlot; 943518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 944e6f43ddce78d6846af12550ff9193c5c6fe5844bSteve Block ALOGE_IF(slot >= MAX_NUMBER_OF_GL_EXTENSIONS, 945518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian "no more slots for eglGetProcAddress(\"%s\")", 946518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian procname); 947518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 9480469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#if EGL_TRACE 9490469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy gl_hooks_t *debugHooks = GLTrace_getGLHooks(); 9500469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#endif 9510469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 952518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!addr && (slot < MAX_NUMBER_OF_GL_EXTENSIONS)) { 953518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian bool found = false; 954ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian 955ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 956ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->dso && cnx->egl.eglGetProcAddress) { 957ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian // Extensions are independent of the bound context 95869d100762c7c26d8328f4bb61cfef026d3a69bbfluliuhui addr = 9597773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian cnx->hooks[egl_connection_t::GLESv1_INDEX]->ext.extensions[slot] = 9607773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian cnx->hooks[egl_connection_t::GLESv2_INDEX]->ext.extensions[slot] = 961518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#if EGL_TRACE 962ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian debugHooks->ext.extensions[slot] = 963ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian gHooksTrace.ext.extensions[slot] = 964518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#endif 965ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian cnx->egl.eglGetProcAddress(procname); 96669d100762c7c26d8328f4bb61cfef026d3a69bbfluliuhui if (addr) found = true; 967518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 968ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian 969518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (found) { 970518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian addr = gExtensionForwarders[slot]; 971518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian sGLExtentionMap.add(name, addr); 972518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian sGLExtentionSlot++; 973518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 974518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 975518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 976518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian pthread_mutex_unlock(&sExtensionMapMutex); 977518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return addr; 978518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 979518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 98028ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennisclass FrameCompletionThread : public Thread { 98128ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennispublic: 98228ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis 98328ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis static void queueSync(EGLSyncKHR sync) { 98428ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis static sp<FrameCompletionThread> thread(new FrameCompletionThread); 98528ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis static bool running = false; 98628ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis if (!running) { 98728ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis thread->run("GPUFrameCompletion"); 98828ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis running = true; 98928ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis } 99028ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis { 99128ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis Mutex::Autolock lock(thread->mMutex); 99228ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis ScopedTrace st(ATRACE_TAG, String8::format("kicked off frame %d", 99328ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis thread->mFramesQueued).string()); 99428ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis thread->mQueue.push_back(sync); 99528ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis thread->mCondition.signal(); 99628ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis thread->mFramesQueued++; 99728ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis ATRACE_INT("GPU Frames Outstanding", thread->mQueue.size()); 99828ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis } 99928ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis } 100028ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis 100128ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennisprivate: 100228ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis FrameCompletionThread() : mFramesQueued(0), mFramesCompleted(0) {} 100328ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis 100428ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis virtual bool threadLoop() { 100528ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis EGLSyncKHR sync; 100628ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis uint32_t frameNum; 100728ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis { 100828ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis Mutex::Autolock lock(mMutex); 100928ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis while (mQueue.isEmpty()) { 101028ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis mCondition.wait(mMutex); 101128ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis } 101228ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis sync = mQueue[0]; 101328ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis frameNum = mFramesCompleted; 101428ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis } 101528ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis EGLDisplay dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); 101628ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis { 101728ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis ScopedTrace st(ATRACE_TAG, String8::format("waiting for frame %d", 101828ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis frameNum).string()); 101928ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis EGLint result = eglClientWaitSyncKHR(dpy, sync, 0, EGL_FOREVER_KHR); 102028ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis if (result == EGL_FALSE) { 102128ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis ALOGE("FrameCompletion: error waiting for fence: %#x", eglGetError()); 102228ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis } else if (result == EGL_TIMEOUT_EXPIRED_KHR) { 102328ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis ALOGE("FrameCompletion: timeout waiting for fence"); 102428ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis } 102528ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis eglDestroySyncKHR(dpy, sync); 102628ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis } 102728ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis { 102828ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis Mutex::Autolock lock(mMutex); 102928ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis mQueue.removeAt(0); 103028ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis mFramesCompleted++; 103128ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis ATRACE_INT("GPU Frames Outstanding", mQueue.size()); 103228ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis } 103328ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis return true; 103428ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis } 103528ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis 103628ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis uint32_t mFramesQueued; 103728ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis uint32_t mFramesCompleted; 103828ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis Vector<EGLSyncKHR> mQueue; 103928ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis Condition mCondition; 104028ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis Mutex mMutex; 104128ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis}; 104228ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis 1043518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface draw) 1044518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 10451c8e95cf86f2182986385bc1ee85f13f425f3a3aJamie Gennis ATRACE_CALL(); 1046518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1047518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1048b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1049518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1050518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1051b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall SurfaceRef _s(dp.get(), draw); 10525b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 10535b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 1054518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 10550469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#if EGL_TRACE 1056a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy gl_hooks_t const *trace_hooks = getGLTraceThreadSpecific(); 1057a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy if (getEGLDebugLevel() > 0) { 1058a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy if (trace_hooks == NULL) { 1059a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy if (GLTrace_start() < 0) { 1060a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy ALOGE("Disabling Tracer for OpenGL ES"); 1061a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy setEGLDebugLevel(0); 1062a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy } else { 1063a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy // switch over to the trace version of hooks 1064a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy EGLContext ctx = egl_tls_t::getContext(); 1065a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy egl_context_t * const c = get_context(ctx); 1066a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy if (c) { 1067a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy setGLHooksThreadSpecific(c->cnx->hooks[c->version]); 1068a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy GLTrace_eglMakeCurrent(c->version, c->cnx->hooks[c->version], ctx); 1069a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy } 1070a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy } 1071a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy } 1072a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy 10730469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLTrace_eglSwapBuffers(dpy, draw); 1074a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy } else if (trace_hooks != NULL) { 1075a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy // tracing is now disabled, so switch back to the non trace version 1076a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy EGLContext ctx = egl_tls_t::getContext(); 1077a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy egl_context_t * const c = get_context(ctx); 1078a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy if (c) setGLHooksThreadSpecific(c->cnx->hooks[c->version]); 1079a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy GLTrace_stop(); 1080a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy } 10810469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#endif 10820469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 1083518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * const s = get_surface(draw); 10847db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian 1085ed6d08b70d775852f4827471814c83eba3606aaaMathias Agopian if (CC_UNLIKELY(dp->traceGpuCompletion)) { 1086ed6d08b70d775852f4827471814c83eba3606aaaMathias Agopian EGLSyncKHR sync = eglCreateSyncKHR(dpy, EGL_SYNC_FENCE_KHR, NULL); 1087ed6d08b70d775852f4827471814c83eba3606aaaMathias Agopian if (sync != EGL_NO_SYNC_KHR) { 1088ed6d08b70d775852f4827471814c83eba3606aaaMathias Agopian FrameCompletionThread::queueSync(sync); 1089ed6d08b70d775852f4827471814c83eba3606aaaMathias Agopian } 1090ed6d08b70d775852f4827471814c83eba3606aaaMathias Agopian } 1091ed6d08b70d775852f4827471814c83eba3606aaaMathias Agopian 10927db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian if (CC_UNLIKELY(dp->finishOnSwap)) { 10937db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian uint32_t pixel; 10947db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian egl_context_t * const c = get_context( egl_tls_t::getContext() ); 10957db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian if (c) { 10967db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian // glReadPixels() ensures that the frame is complete 10977db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian s->cnx->hooks[c->version]->gl.glReadPixels(0,0,1,1, 10987db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian GL_RGBA,GL_UNSIGNED_BYTE,&pixel); 10997db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian } 11007db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian } 11017db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian 1102ed6d08b70d775852f4827471814c83eba3606aaaMathias Agopian return s->cnx->egl.eglSwapBuffers(dp->disp.dpy, s->surface); 1103518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1104518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1105518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglCopyBuffers( EGLDisplay dpy, EGLSurface surface, 1106518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian NativePixmapType target) 1107518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1108518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1109518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1110b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1111518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1112518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1113b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall SurfaceRef _s(dp.get(), surface); 11145b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 11155b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 1116518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1117518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * const s = get_surface(surface); 1118ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return s->cnx->egl.eglCopyBuffers(dp->disp.dpy, s->surface, target); 1119518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1120518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1121518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianconst char* eglQueryString(EGLDisplay dpy, EGLint name) 1122518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1123518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1124518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1125b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1126518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return (const char *) NULL; 1127518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1128518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian switch (name) { 1129518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian case EGL_VENDOR: 11304b9511c16195a646242eff833b0af212933b6ecaMathias Agopian return dp->getVendorString(); 1131518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian case EGL_VERSION: 11324b9511c16195a646242eff833b0af212933b6ecaMathias Agopian return dp->getVersionString(); 1133518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian case EGL_EXTENSIONS: 11344b9511c16195a646242eff833b0af212933b6ecaMathias Agopian return dp->getExtensionString(); 1135518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian case EGL_CLIENT_APIS: 11364b9511c16195a646242eff833b0af212933b6ecaMathias Agopian return dp->getClientApiString(); 1137518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1138518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_PARAMETER, (const char *)0); 1139518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1140518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1141ca08833d5ea99130797e10ad68a651b50e99da74Mathias AgopianEGLAPI const char* eglQueryStringImplementationANDROID(EGLDisplay dpy, EGLint name) 1142ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian{ 1143ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian clearError(); 1144ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian 1145ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian const egl_display_ptr dp = validate_display(dpy); 1146ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian if (!dp) return (const char *) NULL; 1147ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian 1148ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian switch (name) { 1149ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian case EGL_VENDOR: 1150ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian return dp->disp.queryString.vendor; 1151ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian case EGL_VERSION: 1152ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian return dp->disp.queryString.version; 1153ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian case EGL_EXTENSIONS: 1154ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian return dp->disp.queryString.extensions; 1155ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian case EGL_CLIENT_APIS: 1156ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian return dp->disp.queryString.clientApi; 1157ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian } 1158ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian return setError(EGL_BAD_PARAMETER, (const char *)0); 1159ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian} 1160518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1161518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 1162518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// EGL 1.1 1163518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 1164518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1165518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglSurfaceAttrib( 1166518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value) 1167518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1168518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1169518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1170b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1171518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1172518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1173b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall SurfaceRef _s(dp.get(), surface); 11745b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 11755b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 1176518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1177518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * const s = get_surface(surface); 1178518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (s->cnx->egl.eglSurfaceAttrib) { 1179518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return s->cnx->egl.eglSurfaceAttrib( 1180ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian dp->disp.dpy, s->surface, attribute, value); 1181518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1182518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 1183518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1184518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1185518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglBindTexImage( 1186518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLDisplay dpy, EGLSurface surface, EGLint buffer) 1187518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1188518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1189518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1190b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1191518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1192518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1193b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall SurfaceRef _s(dp.get(), surface); 11945b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 11955b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 1196518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1197518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * const s = get_surface(surface); 1198518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (s->cnx->egl.eglBindTexImage) { 1199518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return s->cnx->egl.eglBindTexImage( 1200ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian dp->disp.dpy, s->surface, buffer); 1201518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1202518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 1203518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1204518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1205518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglReleaseTexImage( 1206518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLDisplay dpy, EGLSurface surface, EGLint buffer) 1207518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1208518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1209518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1210b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1211518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1212518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1213b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall SurfaceRef _s(dp.get(), surface); 12145b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 12155b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 1216518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1217518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * const s = get_surface(surface); 1218518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (s->cnx->egl.eglReleaseTexImage) { 1219518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return s->cnx->egl.eglReleaseTexImage( 1220ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian dp->disp.dpy, s->surface, buffer); 1221518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1222518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 1223518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1224518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1225518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint interval) 1226518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1227518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1228518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1229b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1230518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1231518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1232518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean res = EGL_TRUE; 1233ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 1234ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->dso && cnx->egl.eglSwapInterval) { 1235ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian res = cnx->egl.eglSwapInterval(dp->disp.dpy, interval); 1236518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1237ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian 1238518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return res; 1239518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1240518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1241518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1242518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 1243518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// EGL 1.2 1244518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 1245518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1246518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglWaitClient(void) 1247518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1248518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1249518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1250ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 1251ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (!cnx->dso) 1252ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return setError(EGL_BAD_CONTEXT, EGL_FALSE); 1253ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian 1254ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian EGLBoolean res; 1255ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->egl.eglWaitClient) { 1256ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian res = cnx->egl.eglWaitClient(); 1257ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian } else { 1258ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian res = cnx->egl.eglWaitGL(); 1259518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1260518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return res; 1261518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1262518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1263518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglBindAPI(EGLenum api) 1264518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1265518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1266518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1267518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (egl_init_drivers() == EGL_FALSE) { 1268518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_PARAMETER, EGL_FALSE); 1269518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1270518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1271518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // bind this API on all EGLs 1272518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean res = EGL_TRUE; 1273ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 1274ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->dso && cnx->egl.eglBindAPI) { 1275ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian res = cnx->egl.eglBindAPI(api); 1276518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1277518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return res; 1278518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1279518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1280518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLenum eglQueryAPI(void) 1281518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1282518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1283518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1284518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (egl_init_drivers() == EGL_FALSE) { 1285518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_PARAMETER, EGL_FALSE); 1286518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1287518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1288ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 1289ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->dso && cnx->egl.eglQueryAPI) { 1290ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return cnx->egl.eglQueryAPI(); 1291518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1292ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian 1293518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // or, it can only be OpenGL ES 1294518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_OPENGL_ES_API; 1295518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1296518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1297518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglReleaseThread(void) 1298518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1299518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1300518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 13014e620ddce344e946ced992f61a69c367ff92fe24Mathias Agopian#if EGL_TRACE 13024e620ddce344e946ced992f61a69c367ff92fe24Mathias Agopian if (getEGLDebugLevel() > 0) 13034e620ddce344e946ced992f61a69c367ff92fe24Mathias Agopian GLTrace_eglReleaseThread(); 13044e620ddce344e946ced992f61a69c367ff92fe24Mathias Agopian#endif 13054e620ddce344e946ced992f61a69c367ff92fe24Mathias Agopian 1306518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // If there is context bound to the thread, release it 1307fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian egl_display_t::loseCurrent(get_context(getContext())); 1308518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1309ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 1310ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->dso && cnx->egl.eglReleaseThread) { 1311ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian cnx->egl.eglReleaseThread(); 1312518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1313518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_tls_t::clearTLS(); 1314518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_TRUE; 1315518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1316518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1317518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLSurface eglCreatePbufferFromClientBuffer( 1318518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, 1319518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLConfig config, const EGLint *attrib_list) 1320518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1321518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1322518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1323b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_connection_t* cnx = NULL; 1324b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display_connection(dpy, cnx); 1325b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall if (!dp) return EGL_FALSE; 1326518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (cnx->egl.eglCreatePbufferFromClientBuffer) { 1327518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return cnx->egl.eglCreatePbufferFromClientBuffer( 13287773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian dp->disp.dpy, buftype, buffer, config, attrib_list); 1329518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1330518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_CONFIG, EGL_NO_SURFACE); 1331518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1332518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1333518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 1334518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// EGL_EGLEXT_VERSION 3 1335518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 1336518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1337518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglLockSurfaceKHR(EGLDisplay dpy, EGLSurface surface, 1338518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian const EGLint *attrib_list) 1339518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1340518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1341518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1342b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1343518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1344518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1345b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall SurfaceRef _s(dp.get(), surface); 13465b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 13475b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 1348518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1349518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * const s = get_surface(surface); 1350518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (s->cnx->egl.eglLockSurfaceKHR) { 1351518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return s->cnx->egl.eglLockSurfaceKHR( 1352ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian dp->disp.dpy, s->surface, attrib_list); 1353518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1354518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_DISPLAY, EGL_FALSE); 1355518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1356518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1357518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglUnlockSurfaceKHR(EGLDisplay dpy, EGLSurface surface) 1358518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1359518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1360518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1361b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1362518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1363518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1364b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall SurfaceRef _s(dp.get(), surface); 13655b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 13665b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 1367518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1368518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * const s = get_surface(surface); 1369518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (s->cnx->egl.eglUnlockSurfaceKHR) { 1370ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return s->cnx->egl.eglUnlockSurfaceKHR(dp->disp.dpy, s->surface); 1371518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1372518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_DISPLAY, EGL_FALSE); 1373518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1374518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1375518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, 1376518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLClientBuffer buffer, const EGLint *attrib_list) 1377518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1378518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1379518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1380b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1381518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_NO_IMAGE_KHR; 1382518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1383b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall ContextRef _c(dp.get(), ctx); 13847c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian egl_context_t * const c = _c.get(); 1385518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 13867c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian EGLImageKHR result = EGL_NO_IMAGE_KHR; 13877c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian egl_connection_t* const cnx = &gEGLImpl; 13887c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian if (cnx->dso && cnx->egl.eglCreateImageKHR) { 13897c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian result = cnx->egl.eglCreateImageKHR( 13907c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian dp->disp.dpy, 13917c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian c ? c->context : EGL_NO_CONTEXT, 13927c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian target, buffer, attrib_list); 1393518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 13947c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian return result; 1395518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1396518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1397518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR img) 1398518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1399518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1400518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1401b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1402518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1403518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1404646a5c593f9819dc5da6a1ec859bc70cb7ba096fSteven Holte EGLBoolean result = EGL_FALSE; 1405ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 14067c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian if (cnx->dso && cnx->egl.eglDestroyImageKHR) { 1407646a5c593f9819dc5da6a1ec859bc70cb7ba096fSteven Holte result = cnx->egl.eglDestroyImageKHR(dp->disp.dpy, img); 1408518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1409646a5c593f9819dc5da6a1ec859bc70cb7ba096fSteven Holte return result; 1410518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1411518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1412518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 1413518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// EGL_EGLEXT_VERSION 5 1414518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 1415518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1416518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1417518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLSyncKHR eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list) 1418518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1419518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1420518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1421b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1422518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_NO_SYNC_KHR; 1423518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1424518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLSyncKHR result = EGL_NO_SYNC_KHR; 14257c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian egl_connection_t* const cnx = &gEGLImpl; 14267c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian if (cnx->dso && cnx->egl.eglCreateSyncKHR) { 14277c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian result = cnx->egl.eglCreateSyncKHR(dp->disp.dpy, type, attrib_list); 1428518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 14297c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian return result; 1430518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1431518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1432518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync) 1433518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1434518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1435518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1436b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1437518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1438518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1439518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean result = EGL_FALSE; 14407c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian egl_connection_t* const cnx = &gEGLImpl; 14417c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian if (cnx->dso && cnx->egl.eglDestroySyncKHR) { 14427c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian result = cnx->egl.eglDestroySyncKHR(dp->disp.dpy, sync); 1443518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1444518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return result; 1445518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1446518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1447e9b3dfb7d5cc233747407381a51a081c335dc076Mathias AgopianEGLBoolean eglSignalSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode) { 1448e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian clearError(); 1449e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 1450e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian const egl_display_ptr dp = validate_display(dpy); 1451e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian if (!dp) return EGL_FALSE; 1452e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 1453e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian EGLBoolean result = EGL_FALSE; 1454e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian egl_connection_t* const cnx = &gEGLImpl; 1455e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian if (cnx->dso && cnx->egl.eglSignalSyncKHR) { 1456e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian result = cnx->egl.eglSignalSyncKHR( 1457e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian dp->disp.dpy, sync, mode); 1458e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian } 1459e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian return result; 1460e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian} 1461e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 14627c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias AgopianEGLint eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, 14637c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian EGLint flags, EGLTimeKHR timeout) 1464518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1465518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1466518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1467b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1468518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1469518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 14707c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian EGLBoolean result = EGL_FALSE; 14717c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian egl_connection_t* const cnx = &gEGLImpl; 14727c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian if (cnx->dso && cnx->egl.eglClientWaitSyncKHR) { 14737c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian result = cnx->egl.eglClientWaitSyncKHR( 14747c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian dp->disp.dpy, sync, flags, timeout); 1475518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 14767c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian return result; 1477518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1478518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 14797c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias AgopianEGLBoolean eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync, 14807c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian EGLint attribute, EGLint *value) 1481518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1482518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1483518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1484b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1485518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1486518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 14877c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian EGLBoolean result = EGL_FALSE; 14887c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian egl_connection_t* const cnx = &gEGLImpl; 14897c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian if (cnx->dso && cnx->egl.eglGetSyncAttribKHR) { 14907c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian result = cnx->egl.eglGetSyncAttribKHR( 14917c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian dp->disp.dpy, sync, attribute, value); 1492518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 14937c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian return result; 1494518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1495518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1496518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 14972bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian// EGL_EGLEXT_VERSION 15 1498518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 1499518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 15002bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias AgopianEGLint eglWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags) { 1501331841b96b92646c93c87627c03f77b892f711cdJamie Gennis clearError(); 1502331841b96b92646c93c87627c03f77b892f711cdJamie Gennis const egl_display_ptr dp = validate_display(dpy); 15032bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian if (!dp) return EGL_FALSE; 15042bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian EGLint result = EGL_FALSE; 1505331841b96b92646c93c87627c03f77b892f711cdJamie Gennis egl_connection_t* const cnx = &gEGLImpl; 15062bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian if (cnx->dso && cnx->egl.eglWaitSyncKHR) { 15072bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian result = cnx->egl.eglWaitSyncKHR(dp->disp.dpy, sync, flags); 1508331841b96b92646c93c87627c03f77b892f711cdJamie Gennis } 1509331841b96b92646c93c87627c03f77b892f711cdJamie Gennis return result; 1510331841b96b92646c93c87627c03f77b892f711cdJamie Gennis} 15111c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 15122bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian// ---------------------------------------------------------------------------- 15132bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian// ANDROID extensions 15142bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian// ---------------------------------------------------------------------------- 15152bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian 15162bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias AgopianEGLint eglDupNativeFenceFDANDROID(EGLDisplay dpy, EGLSyncKHR sync) 1517010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis{ 1518010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis clearError(); 1519010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis 1520010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis const egl_display_ptr dp = validate_display(dpy); 1521010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis if (!dp) return EGL_NO_NATIVE_FENCE_FD_ANDROID; 1522010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis 15232bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian EGLint result = EGL_NO_NATIVE_FENCE_FD_ANDROID; 1524010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis egl_connection_t* const cnx = &gEGLImpl; 15252bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian if (cnx->dso && cnx->egl.eglDupNativeFenceFDANDROID) { 15262bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian result = cnx->egl.eglDupNativeFenceFDANDROID(dp->disp.dpy, sync); 1527010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis } 1528010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis return result; 1529010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis} 1530010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis 15317284145d564fa8a422a8e564a38c730fb4a2962bAndy McFaddenEGLBoolean eglPresentationTimeANDROID(EGLDisplay dpy, EGLSurface surface, 15327284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden EGLnsecsANDROID time) 15337284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden{ 15347284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden clearError(); 15357284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden 15367284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden const egl_display_ptr dp = validate_display(dpy); 15377284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden if (!dp) { 15387284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden return EGL_FALSE; 15397284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden } 15407284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden 15417284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden SurfaceRef _s(dp.get(), surface); 15427284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden if (!_s.get()) { 15437284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden setError(EGL_BAD_SURFACE, EGL_FALSE); 15447284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden return EGL_FALSE; 15457284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden } 15467284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden 15477284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden egl_surface_t const * const s = get_surface(surface); 15487284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden native_window_set_buffers_timestamp(s->win.get(), time); 15497284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden 15507284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden return EGL_TRUE; 15517284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden} 15527284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden 15531c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang// ---------------------------------------------------------------------------- 15541c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang// NVIDIA extensions 15551c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang// ---------------------------------------------------------------------------- 15561c3d72a2291827fb15e2ef311a571c860e0dba41Jonas YangEGLuint64NV eglGetSystemTimeFrequencyNV() 15571c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang{ 15581c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang clearError(); 15591c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 15601c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang if (egl_init_drivers() == EGL_FALSE) { 15611c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang return setError(EGL_BAD_PARAMETER, EGL_FALSE); 15621c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang } 15631c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 15641c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang EGLuint64NV ret = 0; 1565ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 15661c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 1567ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->dso && cnx->egl.eglGetSystemTimeFrequencyNV) { 1568ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return cnx->egl.eglGetSystemTimeFrequencyNV(); 15691c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang } 15701c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 15710e8bbee5775d81c7bbc479b995496cac9238559fMathias Agopian return setErrorQuiet(EGL_BAD_DISPLAY, 0); 15721c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang} 15731c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 15741c3d72a2291827fb15e2ef311a571c860e0dba41Jonas YangEGLuint64NV eglGetSystemTimeNV() 15751c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang{ 15761c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang clearError(); 15771c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 15781c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang if (egl_init_drivers() == EGL_FALSE) { 15791c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang return setError(EGL_BAD_PARAMETER, EGL_FALSE); 15801c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang } 15811c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 15821c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang EGLuint64NV ret = 0; 1583ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 15841c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 1585ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->dso && cnx->egl.eglGetSystemTimeNV) { 1586ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return cnx->egl.eglGetSystemTimeNV(); 15871c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang } 15881c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 15890e8bbee5775d81c7bbc479b995496cac9238559fMathias Agopian return setErrorQuiet(EGL_BAD_DISPLAY, 0); 15901c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang} 1591