eglApi.cpp revision c2e41222bf02a6579763974f82d65875cfa43481
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 52518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 53518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 54e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopiannamespace android { 55e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 56518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstruct extention_map_t { 57518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian const char* name; 58518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian __eglMustCastToProperFunctionPointerType address; 59518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}; 60518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 61e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian/* 6221558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hall * This is the list of EGL extensions exposed to applications. 63e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian * 6421558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hall * Some of them (gBuiltinExtensionString) are implemented entirely in this EGL 6521558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hall * wrapper and are always available. 66e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian * 6721558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hall * The rest (gExtensionString) depend on support in the EGL driver, and are 6821558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hall * only available if the driver supports them. However, some of these must be 6921558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hall * supported because they are used by the Android system itself; these are 7021558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hall * listd as mandatory below and are required by the CDD. The system *assumes* 7121558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hall * the mandatory extensions are present and may not function properly if some 7221558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hall * are missing. 7321558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hall * 7421558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hall * NOTE: Both strings MUST have a single space as the last character. 75e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian */ 7621558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hallextern char const * const gBuiltinExtensionString = 7721558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hall "EGL_KHR_get_all_proc_addresses " 7821558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hall "EGL_ANDROID_presentation_time " 7921558daf691dbcdff4a41e659fd013273db4d0b7Jesse Hall ; 80e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopianextern char const * const gExtensionString = 81e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian "EGL_KHR_image " // mandatory 82e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian "EGL_KHR_image_base " // mandatory 83e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian "EGL_KHR_image_pixmap " 84e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian "EGL_KHR_lock_surface " 85c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall "EGL_KHR_gl_colorspace " 86e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian "EGL_KHR_gl_texture_2D_image " 87e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian "EGL_KHR_gl_texture_cubemap_image " 88e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian "EGL_KHR_gl_renderbuffer_image " 89e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian "EGL_KHR_reusable_sync " 90e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian "EGL_KHR_fence_sync " 91f6d1c3930eeba6b089ba12fb82ecad1c6622e550Jamie Gennis "EGL_KHR_create_context " 92e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian "EGL_EXT_create_context_robustness " 93e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian "EGL_NV_system_time " 94e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian "EGL_ANDROID_image_native_buffer " // mandatory 952bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian "EGL_KHR_wait_sync " // strongly recommended 96e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian ; 97e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 98e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian// extensions not exposed to applications but used by the ANDROID system 99e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian// "EGL_ANDROID_blob_cache " // strongly recommended 100e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian// "EGL_IMG_hibernate_process " // optional 101e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian// "EGL_ANDROID_native_fence_sync " // strongly recommended 102e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian// "EGL_ANDROID_framebuffer_target " // mandatory for HWC 1.1 103e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian// "EGL_ANDROID_recordable " // mandatory 104e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 105e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 106e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian/* 107e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian * EGL Extensions entry-points exposed to 3rd party applications 108e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian * (keep in sync with gExtensionString above) 109e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian * 110e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian */ 111e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopianstatic const extention_map_t sExtensionMap[] = { 112e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian // EGL_KHR_lock_surface 113518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian { "eglLockSurfaceKHR", 114518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian (__eglMustCastToProperFunctionPointerType)&eglLockSurfaceKHR }, 115518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian { "eglUnlockSurfaceKHR", 116518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian (__eglMustCastToProperFunctionPointerType)&eglUnlockSurfaceKHR }, 117e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 118e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian // EGL_KHR_image, EGL_KHR_image_base 119518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian { "eglCreateImageKHR", 120518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian (__eglMustCastToProperFunctionPointerType)&eglCreateImageKHR }, 121518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian { "eglDestroyImageKHR", 122518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian (__eglMustCastToProperFunctionPointerType)&eglDestroyImageKHR }, 123e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 124e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian // EGL_KHR_reusable_sync, EGL_KHR_fence_sync 125e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian { "eglCreateSyncKHR", 126e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian (__eglMustCastToProperFunctionPointerType)&eglCreateSyncKHR }, 127e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian { "eglDestroySyncKHR", 128e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian (__eglMustCastToProperFunctionPointerType)&eglDestroySyncKHR }, 129e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian { "eglClientWaitSyncKHR", 130e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian (__eglMustCastToProperFunctionPointerType)&eglClientWaitSyncKHR }, 131e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian { "eglSignalSyncKHR", 132e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian (__eglMustCastToProperFunctionPointerType)&eglSignalSyncKHR }, 133e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian { "eglGetSyncAttribKHR", 134e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian (__eglMustCastToProperFunctionPointerType)&eglGetSyncAttribKHR }, 135e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 136e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian // EGL_NV_system_time 1371c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang { "eglGetSystemTimeFrequencyNV", 1381c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang (__eglMustCastToProperFunctionPointerType)&eglGetSystemTimeFrequencyNV }, 1391c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang { "eglGetSystemTimeNV", 1401c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang (__eglMustCastToProperFunctionPointerType)&eglGetSystemTimeNV }, 141e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 1422bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian // EGL_KHR_wait_sync 1432bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian { "eglWaitSyncKHR", 1442bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian (__eglMustCastToProperFunctionPointerType)&eglWaitSyncKHR }, 145e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 146e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian // EGL_ANDROID_presentation_time 147e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian { "eglPresentationTimeANDROID", 148e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian (__eglMustCastToProperFunctionPointerType)&eglPresentationTimeANDROID }, 149518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}; 150518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 151e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian/* 152e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian * These extensions entry-points should not be exposed to applications. 153e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian * They're used internally by the Android EGL layer. 154e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian */ 155e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian#define FILTER_EXTENSIONS(procname) \ 156e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian (!strcmp((procname), "eglSetBlobCacheFuncsANDROID") || \ 157e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian !strcmp((procname), "eglHibernateProcessIMG") || \ 158e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian !strcmp((procname), "eglAwakenProcessIMG") || \ 159e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian !strcmp((procname), "eglDupNativeFenceFDANDROID")) 160e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 161e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 162e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 163518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// accesses protected by sExtensionMapMutex 164518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic DefaultKeyedVector<String8, __eglMustCastToProperFunctionPointerType> sGLExtentionMap; 165518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic int sGLExtentionSlot = 0; 166518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic pthread_mutex_t sExtensionMapMutex = PTHREAD_MUTEX_INITIALIZER; 167518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 168518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic void(*findProcAddress(const char* name, 169518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian const extention_map_t* map, size_t n))() { 170518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian for (uint32_t i=0 ; i<n ; i++) { 171518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!strcmp(name, map[i].name)) { 172518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return map[i].address; 173518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 174518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 175518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return NULL; 176518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 177518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 178518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 179518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 180518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianextern void setGLHooksThreadSpecific(gl_hooks_t const *value); 181518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianextern EGLBoolean egl_init_drivers(); 182518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianextern const __eglMustCastToProperFunctionPointerType gExtensionForwarders[MAX_NUMBER_OF_GL_EXTENSIONS]; 183a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamyextern int getEGLDebugLevel(); 184a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamyextern void setEGLDebugLevel(int level); 185518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianextern gl_hooks_t gHooksTrace; 186e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 187518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} // namespace android; 188518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 189e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 190518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 191518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 192518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic inline void clearError() { egl_tls_t::clearError(); } 193518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic inline EGLContext getContext() { return egl_tls_t::getContext(); } 194518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 195518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 196518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 197518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLDisplay eglGetDisplay(EGLNativeDisplayType display) 198518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 199518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 200518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 201518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian uint32_t index = uint32_t(display); 202518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (index >= NUM_DISPLAYS) { 203518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_PARAMETER, EGL_NO_DISPLAY); 204518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 205518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 206518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (egl_init_drivers() == EGL_FALSE) { 207518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_PARAMETER, EGL_NO_DISPLAY); 208518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 209518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 210518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLDisplay dpy = egl_display_t::getFromNativeDisplay(display); 211518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return dpy; 212518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 213518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 214518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 215518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// Initialization 216518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 217518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 218518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) 219518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 220518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 221518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 222b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_display_ptr dp = get_display(dpy); 223518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE); 224518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 225518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean res = dp->initialize(major, minor); 226518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 227518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return res; 228518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 229518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 230518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglTerminate(EGLDisplay dpy) 231518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 232518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // NOTE: don't unload the drivers b/c some APIs can be called 233518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // after eglTerminate() has been called. eglTerminate() only 234518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // terminates an EGLDisplay, not a EGL itself. 235518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 236518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 237518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 238b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_display_ptr dp = get_display(dpy); 239518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE); 240518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 241518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean res = dp->terminate(); 2424774338bd0ad1ebe42c311fd0c72f13786b5c800Jesse Hall 243518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return res; 244518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 245518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 246518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 247518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// configuration 248518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 249518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 250518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglGetConfigs( EGLDisplay dpy, 251518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLConfig *configs, 252518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint config_size, EGLint *num_config) 253518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 254518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 255518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 256b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 257518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 258518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 2597773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian if (num_config==0) { 2607773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian return setError(EGL_BAD_PARAMETER, EGL_FALSE); 261518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 262518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 2637773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian EGLBoolean res = EGL_FALSE; 2647773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian *num_config = 0; 2657773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian 2667773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian egl_connection_t* const cnx = &gEGLImpl; 2677773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian if (cnx->dso) { 2687773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian res = cnx->egl.eglGetConfigs( 2697773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian dp->disp.dpy, configs, config_size, num_config); 270518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 2717773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian 2727773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian return res; 273518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 274518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 275518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglChooseConfig( EGLDisplay dpy, const EGLint *attrib_list, 276518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLConfig *configs, EGLint config_size, 277518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint *num_config) 278518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 279518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 280518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 281b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 282518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 283518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 284518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (num_config==0) { 285518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_PARAMETER, EGL_FALSE); 286518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 287518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 288518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean res = EGL_FALSE; 289518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian *num_config = 0; 290518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 291ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 292ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->dso) { 2931cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy if (attrib_list) { 2941cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy char value[PROPERTY_VALUE_MAX]; 2951cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy property_get("debug.egl.force_msaa", value, "false"); 2961cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy 2971cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy if (!strcmp(value, "true")) { 2981cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy size_t attribCount = 0; 2991cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy EGLint attrib = attrib_list[0]; 3001cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy 3011cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy // Only enable MSAA if the context is OpenGL ES 2.0 and 302be3c3e4ecad501eecfe1f7a424a792f0f7f3f307Romain Guy // if no caveat is requested 3031cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy const EGLint *attribRendererable = NULL; 3041cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy const EGLint *attribCaveat = NULL; 3051cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy 3061cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy // Count the number of attributes and look for 307be3c3e4ecad501eecfe1f7a424a792f0f7f3f307Romain Guy // EGL_RENDERABLE_TYPE and EGL_CONFIG_CAVEAT 3081cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy while (attrib != EGL_NONE) { 3091cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy attrib = attrib_list[attribCount]; 3101cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy switch (attrib) { 3111cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy case EGL_RENDERABLE_TYPE: 3121cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy attribRendererable = &attrib_list[attribCount]; 3131cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy break; 3141cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy case EGL_CONFIG_CAVEAT: 3151cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy attribCaveat = &attrib_list[attribCount]; 3161cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy break; 3171cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy } 3181cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy attribCount++; 3191cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy } 3201cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy 3211cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy if (attribRendererable && attribRendererable[1] == EGL_OPENGL_ES2_BIT && 3221cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy (!attribCaveat || attribCaveat[1] != EGL_NONE)) { 3234774338bd0ad1ebe42c311fd0c72f13786b5c800Jesse Hall 3241cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy // Insert 2 extra attributes to force-enable MSAA 4x 3251cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy EGLint aaAttribs[attribCount + 4]; 3261cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy aaAttribs[0] = EGL_SAMPLE_BUFFERS; 3271cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy aaAttribs[1] = 1; 3281cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy aaAttribs[2] = EGL_SAMPLES; 3291cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy aaAttribs[3] = 4; 3301cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy 3311cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy memcpy(&aaAttribs[4], attrib_list, attribCount * sizeof(EGLint)); 3321cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy 3331cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy EGLint numConfigAA; 3341cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy EGLBoolean resAA = cnx->egl.eglChooseConfig( 3351cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy dp->disp.dpy, aaAttribs, configs, config_size, &numConfigAA); 3361cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy 3371cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy if (resAA == EGL_TRUE && numConfigAA > 0) { 3381cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy ALOGD("Enabling MSAA 4x"); 3391cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy *num_config = numConfigAA; 3401cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy return resAA; 3411cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy } 3421cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy } 3431cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy } 3441cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy } 3451cffc80f978c55f09203d9d9a905775b951ba59aRomain Guy 3467773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian res = cnx->egl.eglChooseConfig( 3477773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian dp->disp.dpy, attrib_list, configs, config_size, num_config); 348518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 349518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return res; 350518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 351518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 352518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, 353518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint attribute, EGLint *value) 354518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 355518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 356518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 357b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_connection_t* cnx = NULL; 358b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display_connection(dpy, cnx); 359b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall if (!dp) return EGL_FALSE; 3604774338bd0ad1ebe42c311fd0c72f13786b5c800Jesse Hall 361518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return cnx->egl.eglGetConfigAttrib( 3627773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian dp->disp.dpy, config, attribute, value); 363518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 364518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 365518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 366518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// surfaces 367518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 368518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 369c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall// The EGL_KHR_gl_colorspace spec hasn't been published yet, so these haven't 370c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall// been added to the Khronos egl.h. 371c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall#define EGL_GL_COLORSPACE_KHR EGL_VG_COLORSPACE 372c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall#define EGL_GL_COLORSPACE_SRGB_KHR EGL_VG_COLORSPACE_sRGB 373c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall#define EGL_GL_COLORSPACE_LINEAR_KHR EGL_VG_COLORSPACE_LINEAR 374c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall 375c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall// Turn linear formats into corresponding sRGB formats when colorspace is 376c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall// EGL_GL_COLORSPACE_SRGB_KHR, or turn sRGB formats into corresponding linear 377c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall// formats when colorspace is EGL_GL_COLORSPACE_LINEAR_KHR. In any cases where 378c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall// the modification isn't possible, the original format is returned. 379c2e41222bf02a6579763974f82d65875cfa43481Jesse Hallstatic int modifyFormatColorspace(int fmt, EGLint colorspace) { 380c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall if (colorspace == EGL_GL_COLORSPACE_LINEAR_KHR) { 381c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall switch (fmt) { 382c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall case HAL_PIXEL_FORMAT_sRGB_A_8888: return HAL_PIXEL_FORMAT_RGBA_8888; 383c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall case HAL_PIXEL_FORMAT_sRGB_888: return HAL_PIXEL_FORMAT_RGB_888; 384c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall } 385c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall } else if (colorspace == EGL_GL_COLORSPACE_SRGB_KHR) { 386c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall switch (fmt) { 387c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall case HAL_PIXEL_FORMAT_RGBA_8888: return HAL_PIXEL_FORMAT_sRGB_A_8888; 388c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall case HAL_PIXEL_FORMAT_RGBX_8888: return HAL_PIXEL_FORMAT_sRGB_A_8888; 389c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall case HAL_PIXEL_FORMAT_BGRA_8888: return HAL_PIXEL_FORMAT_sRGB_A_8888; 390c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall case HAL_PIXEL_FORMAT_RGB_888: return HAL_PIXEL_FORMAT_sRGB_888; 391c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall } 392c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall } 393c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall return fmt; 394c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall} 395c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall 396518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLSurface eglCreateWindowSurface( EGLDisplay dpy, EGLConfig config, 397518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian NativeWindowType window, 398518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian const EGLint *attrib_list) 399518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 400518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 401518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 402b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_connection_t* cnx = NULL; 403b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_display_ptr dp = validate_display_connection(dpy, cnx); 404b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall if (dp) { 405ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian EGLDisplay iDpy = dp->disp.dpy; 406518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 40781a63350527cafce6929309533c58586878f10b5Mathias Agopian if (native_window_api_connect(window, NATIVE_WINDOW_API_EGL) != OK) { 408e6f43ddce78d6846af12550ff9193c5c6fe5844bSteve Block ALOGE("EGLNativeWindowType %p already connected to another API", 40981a63350527cafce6929309533c58586878f10b5Mathias Agopian window); 41077a9b4a6bd21188e2744ae9dcd8092c6837bff7cJonathan Hamilton return setError(EGL_BAD_ALLOC, EGL_NO_SURFACE); 41181a63350527cafce6929309533c58586878f10b5Mathias Agopian } 41281a63350527cafce6929309533c58586878f10b5Mathias Agopian 413c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall // Set the native window's buffers format to match this config. 414c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall // Whether to use sRGB gamma is not part of the EGLconfig, but is part 415c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall // of our native format. So if sRGB gamma is requested, we have to 416c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall // modify the EGLconfig's format before setting the native window's 417c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall // format. 418c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall EGLint format; 419c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall if (!cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_NATIVE_VISUAL_ID, 420c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall &format)) { 421c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall ALOGE("eglGetConfigAttrib(EGL_NATIVE_VISUAL_ID) failed: %#x", 422c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall eglGetError()); 423c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall format = 0; 424c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall } 425c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall if (attrib_list) { 426c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall for (const EGLint* attr = attrib_list; *attr != EGL_NONE; 427c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall attr += 2) { 428c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall if (*attr == EGL_GL_COLORSPACE_KHR && 429c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall dp->haveExtension("EGL_KHR_gl_colorspace")) { 430c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall format = modifyFormatColorspace(format, *(attr+1)); 431bee205fd58a27c10a0895de5339e76025d429d2bJamie Gennis } 432518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 433518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 434c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall if (format != 0) { 435c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall int err = native_window_set_buffers_format(window, format); 436c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall if (err != 0) { 437c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall ALOGE("error setting native window pixel format: %s (%d)", 438c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall strerror(-err), err); 439c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL); 440c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall return setError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE); 441c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall } 442c2e41222bf02a6579763974f82d65875cfa43481Jesse Hall } 443518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 44459769469e4b9b2d8b12c020eb44b030b3927a50bJamie Gennis // the EGL spec requires that a new EGLSurface default to swap interval 44559769469e4b9b2d8b12c020eb44b030b3927a50bJamie Gennis // 1, so explicitly set that on the window here. 44659769469e4b9b2d8b12c020eb44b030b3927a50bJamie Gennis ANativeWindow* anw = reinterpret_cast<ANativeWindow*>(window); 44759769469e4b9b2d8b12c020eb44b030b3927a50bJamie Gennis anw->setSwapInterval(anw, 1); 44859769469e4b9b2d8b12c020eb44b030b3927a50bJamie Gennis 449518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLSurface surface = cnx->egl.eglCreateWindowSurface( 4507773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian iDpy, config, window, attrib_list); 451518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (surface != EGL_NO_SURFACE) { 452b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_surface_t* s = new egl_surface_t(dp.get(), config, window, 453b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall surface, cnx); 454518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return s; 455518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 45681a63350527cafce6929309533c58586878f10b5Mathias Agopian 45781a63350527cafce6929309533c58586878f10b5Mathias Agopian // EGLSurface creation failed 45881a63350527cafce6929309533c58586878f10b5Mathias Agopian native_window_set_buffers_format(window, 0); 45981a63350527cafce6929309533c58586878f10b5Mathias Agopian native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL); 460518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 461518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_NO_SURFACE; 462518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 463518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 464518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLSurface eglCreatePixmapSurface( EGLDisplay dpy, EGLConfig config, 465518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian NativePixmapType pixmap, 466518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian const EGLint *attrib_list) 467518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 468518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 469518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 470b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_connection_t* cnx = NULL; 471b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_display_ptr dp = validate_display_connection(dpy, cnx); 472b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall if (dp) { 473518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLSurface surface = cnx->egl.eglCreatePixmapSurface( 4747773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian dp->disp.dpy, config, pixmap, attrib_list); 475518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (surface != EGL_NO_SURFACE) { 476b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_surface_t* s = new egl_surface_t(dp.get(), config, NULL, 477b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall surface, cnx); 478518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return s; 479518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 480518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 481518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_NO_SURFACE; 482518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 483518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 484518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLSurface eglCreatePbufferSurface( EGLDisplay dpy, EGLConfig config, 485518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian const EGLint *attrib_list) 486518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 487518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 488518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 489b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_connection_t* cnx = NULL; 490b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_display_ptr dp = validate_display_connection(dpy, cnx); 491b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall if (dp) { 492518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLSurface surface = cnx->egl.eglCreatePbufferSurface( 4937773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian dp->disp.dpy, config, attrib_list); 494518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (surface != EGL_NO_SURFACE) { 495b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_surface_t* s = new egl_surface_t(dp.get(), config, NULL, 496b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall surface, cnx); 497518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return s; 498518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 499518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 500518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_NO_SURFACE; 501518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 5024774338bd0ad1ebe42c311fd0c72f13786b5c800Jesse Hall 503518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface) 504518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 505518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 506518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 507b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 508518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 509518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 510b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall SurfaceRef _s(dp.get(), surface); 5115b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 5125b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 513518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 514518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t * const s = get_surface(surface); 515ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian EGLBoolean result = s->cnx->egl.eglDestroySurface(dp->disp.dpy, s->surface); 516518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (result == EGL_TRUE) { 517518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian _s.terminate(); 518518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 519518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return result; 520518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 521518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 522518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglQuerySurface( EGLDisplay dpy, EGLSurface surface, 523518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint attribute, EGLint *value) 524518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 525518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 526518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 527b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 528518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 529518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 530b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall SurfaceRef _s(dp.get(), surface); 5315b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 5325b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 533518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 534518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * const s = get_surface(surface); 5357773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian return s->cnx->egl.eglQuerySurface( 5367773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian dp->disp.dpy, s->surface, attribute, value); 537518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 538518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 539e8696a40e09b24b634214684d18526187b316a2fJamie Gennisvoid EGLAPI eglBeginFrame(EGLDisplay dpy, EGLSurface surface) { 5401c8e95cf86f2182986385bc1ee85f13f425f3a3aJamie Gennis ATRACE_CALL(); 541e8696a40e09b24b634214684d18526187b316a2fJamie Gennis clearError(); 542e8696a40e09b24b634214684d18526187b316a2fJamie Gennis 543b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 544e8696a40e09b24b634214684d18526187b316a2fJamie Gennis if (!dp) { 545e8696a40e09b24b634214684d18526187b316a2fJamie Gennis return; 546e8696a40e09b24b634214684d18526187b316a2fJamie Gennis } 547e8696a40e09b24b634214684d18526187b316a2fJamie Gennis 548b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall SurfaceRef _s(dp.get(), surface); 549e8696a40e09b24b634214684d18526187b316a2fJamie Gennis if (!_s.get()) { 550e8696a40e09b24b634214684d18526187b316a2fJamie Gennis setError(EGL_BAD_SURFACE, EGL_FALSE); 551e8696a40e09b24b634214684d18526187b316a2fJamie Gennis return; 552e8696a40e09b24b634214684d18526187b316a2fJamie Gennis } 553e8696a40e09b24b634214684d18526187b316a2fJamie Gennis} 554e8696a40e09b24b634214684d18526187b316a2fJamie Gennis 555518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 556518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// Contexts 557518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 558518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 559518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config, 560518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLContext share_list, const EGLint *attrib_list) 561518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 562518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 563518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 564b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_connection_t* cnx = NULL; 565b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display_connection(dpy, cnx); 5660673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock if (dp) { 567518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (share_list != EGL_NO_CONTEXT) { 5680673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock if (!ContextRef(dp.get(), share_list).get()) { 5690673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock return setError(EGL_BAD_CONTEXT, EGL_NO_CONTEXT); 5700673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock } 571518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t* const c = get_context(share_list); 572518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian share_list = c->context; 573518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 574518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLContext context = cnx->egl.eglCreateContext( 5757773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian dp->disp.dpy, config, share_list, attrib_list); 576518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (context != EGL_NO_CONTEXT) { 577518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // figure out if it's a GLESv1 or GLESv2 578518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian int version = 0; 579518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (attrib_list) { 580518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian while (*attrib_list != EGL_NONE) { 581518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian GLint attr = *attrib_list++; 582518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian GLint value = *attrib_list++; 583518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (attr == EGL_CONTEXT_CLIENT_VERSION) { 584518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (value == 1) { 5857773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian version = egl_connection_t::GLESv1_INDEX; 5864774338bd0ad1ebe42c311fd0c72f13786b5c800Jesse Hall } else if (value == 2 || value == 3) { 5877773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian version = egl_connection_t::GLESv2_INDEX; 588518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 589518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 590518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian }; 591518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 592b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_context_t* c = new egl_context_t(dpy, context, config, cnx, 593b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall version); 5940469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#if EGL_TRACE 595a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy if (getEGLDebugLevel() > 0) 5960469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLTrace_eglCreateContext(version, c); 5970469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#endif 598518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return c; 599518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 600518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 601518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_NO_CONTEXT; 602518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 603518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 604518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx) 605518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 606518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 607518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 608b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 6095b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!dp) 6105b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return EGL_FALSE; 611518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 612b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall ContextRef _c(dp.get(), ctx); 6135b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_c.get()) 6145b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_CONTEXT, EGL_FALSE); 6154774338bd0ad1ebe42c311fd0c72f13786b5c800Jesse Hall 616518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t * const c = get_context(ctx); 617ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian EGLBoolean result = c->cnx->egl.eglDestroyContext(dp->disp.dpy, c->context); 618518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (result == EGL_TRUE) { 619518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian _c.terminate(); 620518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 621518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return result; 622518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 623518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 624518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglMakeCurrent( EGLDisplay dpy, EGLSurface draw, 625518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLSurface read, EGLContext ctx) 626518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 627518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 628518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 629b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_display_ptr dp = validate_display(dpy); 630518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE); 631518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 6325b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian // If ctx is not EGL_NO_CONTEXT, read is not EGL_NO_SURFACE, or draw is not 6335b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian // EGL_NO_SURFACE, then an EGL_NOT_INITIALIZED error is generated if dpy is 6345b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian // a valid but uninitialized display. 635518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if ( (ctx != EGL_NO_CONTEXT) || (read != EGL_NO_SURFACE) || 636518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian (draw != EGL_NO_SURFACE) ) { 637518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp->isReady()) return setError(EGL_NOT_INITIALIZED, EGL_FALSE); 638518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 639518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 640518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // get a reference to the object passed in 641b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall ContextRef _c(dp.get(), ctx); 642b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall SurfaceRef _d(dp.get(), draw); 643b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall SurfaceRef _r(dp.get(), read); 644518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 645518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // validate the context (if not EGL_NO_CONTEXT) 6465b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if ((ctx != EGL_NO_CONTEXT) && !_c.get()) { 647518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // EGL_NO_CONTEXT is valid 6480673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock return setError(EGL_BAD_CONTEXT, EGL_FALSE); 649518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 650518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 651518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // these are the underlying implementation's object 652518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLContext impl_ctx = EGL_NO_CONTEXT; 653518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLSurface impl_draw = EGL_NO_SURFACE; 654518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLSurface impl_read = EGL_NO_SURFACE; 655518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 656518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // these are our objects structs passed in 657518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t * c = NULL; 658518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * d = NULL; 659518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * r = NULL; 660518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 661518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // these are the current objects structs 662518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t * cur_c = get_context(getContext()); 6634774338bd0ad1ebe42c311fd0c72f13786b5c800Jesse Hall 664518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (ctx != EGL_NO_CONTEXT) { 665518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian c = get_context(ctx); 666518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian impl_ctx = c->context; 667518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } else { 668518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // no context given, use the implementation of the current context 6690673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock if (draw != EGL_NO_SURFACE || read != EGL_NO_SURFACE) { 6700673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock // calling eglMakeCurrent( ..., !=0, !=0, EGL_NO_CONTEXT); 6710673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock return setError(EGL_BAD_MATCH, EGL_FALSE); 6720673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock } 673518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (cur_c == NULL) { 674518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // no current context 675518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // not an error, there is just no current context. 676518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_TRUE; 677518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 678518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 679518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 680518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // retrieve the underlying implementation's draw EGLSurface 681518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (draw != EGL_NO_SURFACE) { 6820673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock if (!_d.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE); 683518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian d = get_surface(draw); 684518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian impl_draw = d->surface; 685518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 686518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 687518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // retrieve the underlying implementation's read EGLSurface 688518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (read != EGL_NO_SURFACE) { 6890673e1e2d77c673c2e9bc57616a02c3188b55ad1Michael Chock if (!_r.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE); 690518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian r = get_surface(read); 691518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian impl_read = r->surface; 692518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 693518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 694518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 695b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall EGLBoolean result = dp->makeCurrent(c, cur_c, 696fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian draw, read, ctx, 697fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian impl_draw, impl_read, impl_ctx); 698518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 699518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (result == EGL_TRUE) { 700fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian if (c) { 701518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian setGLHooksThreadSpecific(c->cnx->hooks[c->version]); 702518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_tls_t::setContext(ctx); 7030469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#if EGL_TRACE 704a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy if (getEGLDebugLevel() > 0) 70593a826f78f6313db791e6fc880439189897651b3Siva Velusamy GLTrace_eglMakeCurrent(c->version, c->cnx->hooks[c->version], ctx); 7060469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#endif 707518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian _c.acquire(); 708518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian _r.acquire(); 709518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian _d.acquire(); 710518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } else { 711518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian setGLHooksThreadSpecific(&gHooksNoContext); 712518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_tls_t::setContext(EGL_NO_CONTEXT); 713518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 7145fecea776a5f093c21ac1a0ad3552b847d4be23eMathias Agopian } else { 715e6f43ddce78d6846af12550ff9193c5c6fe5844bSteve Block // this will ALOGE the error 7165fecea776a5f093c21ac1a0ad3552b847d4be23eMathias Agopian result = setError(c->cnx->egl.eglGetError(), EGL_FALSE); 717518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 718518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return result; 719518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 720518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 721518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 722518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglQueryContext( EGLDisplay dpy, EGLContext ctx, 723518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint attribute, EGLint *value) 724518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 725518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 726518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 727b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 728518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 729518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 730b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall ContextRef _c(dp.get(), ctx); 731518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!_c.get()) return setError(EGL_BAD_CONTEXT, EGL_FALSE); 732518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 733518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t * const c = get_context(ctx); 7347773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian return c->cnx->egl.eglQueryContext( 7357773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian dp->disp.dpy, c->context, attribute, value); 736518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 737518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 738518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 739518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLContext eglGetCurrentContext(void) 740518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 741518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // could be called before eglInitialize(), but we wouldn't have a context 742518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // then, and this function would correctly return EGL_NO_CONTEXT. 743518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 744518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 745518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 746518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLContext ctx = getContext(); 747518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return ctx; 748518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 749518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 750518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLSurface eglGetCurrentSurface(EGLint readdraw) 751518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 752518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // could be called before eglInitialize(), but we wouldn't have a context 753518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // then, and this function would correctly return EGL_NO_SURFACE. 754518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 755518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 756518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 757518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLContext ctx = getContext(); 758518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (ctx) { 759518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t const * const c = get_context(ctx); 760518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!c) return setError(EGL_BAD_CONTEXT, EGL_NO_SURFACE); 761518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian switch (readdraw) { 762518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian case EGL_READ: return c->read; 7634774338bd0ad1ebe42c311fd0c72f13786b5c800Jesse Hall case EGL_DRAW: return c->draw; 764518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian default: return setError(EGL_BAD_PARAMETER, EGL_NO_SURFACE); 765518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 766518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 767518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_NO_SURFACE; 768518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 769518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 770518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLDisplay eglGetCurrentDisplay(void) 771518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 772518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // could be called before eglInitialize(), but we wouldn't have a context 773518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // then, and this function would correctly return EGL_NO_DISPLAY. 774518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 775518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 776518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 777518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLContext ctx = getContext(); 778518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (ctx) { 779518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t const * const c = get_context(ctx); 780518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!c) return setError(EGL_BAD_CONTEXT, EGL_NO_SURFACE); 781518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return c->dpy; 782518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 783518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_NO_DISPLAY; 784518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 785518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 786518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglWaitGL(void) 787518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 788518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 789518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 790ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 791ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (!cnx->dso) 792ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return setError(EGL_BAD_CONTEXT, EGL_FALSE); 793ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian 794ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return cnx->egl.eglWaitGL(); 795518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 796518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 797518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglWaitNative(EGLint engine) 798518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 799518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 800518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 801ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 802ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (!cnx->dso) 803ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return setError(EGL_BAD_CONTEXT, EGL_FALSE); 804ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian 805ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return cnx->egl.eglWaitNative(engine); 806518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 807518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 808518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLint eglGetError(void) 809518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 810ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian EGLint err = EGL_SUCCESS; 811ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 812ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->dso) { 813ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian err = cnx->egl.eglGetError(); 814518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 815ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (err == EGL_SUCCESS) { 816ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian err = egl_tls_t::getError(); 817ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian } 818ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return err; 819518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 820518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 821c07b52060acd627c8510c1a9151e0753fce76330Jesse Hallstatic __eglMustCastToProperFunctionPointerType findBuiltinGLWrapper( 822c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall const char* procname) { 823c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall const egl_connection_t* cnx = &gEGLImpl; 824c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall void* proc = NULL; 825c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall 826c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall proc = dlsym(cnx->libGles2, procname); 827c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall if (proc) return (__eglMustCastToProperFunctionPointerType)proc; 828c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall 829c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall proc = dlsym(cnx->libGles1, procname); 830c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall if (proc) return (__eglMustCastToProperFunctionPointerType)proc; 831c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall 832c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall return NULL; 833c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall} 834c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall 835518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian__eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname) 836518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 837518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // eglGetProcAddress() could be the very first function called 838518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // in which case we must make sure we've initialized ourselves, this 839518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // happens the first time egl_get_display() is called. 840518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 841518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 842518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 843518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (egl_init_drivers() == EGL_FALSE) { 844518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian setError(EGL_BAD_PARAMETER, NULL); 845518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return NULL; 846518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 847518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 848e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian if (FILTER_EXTENSIONS(procname)) { 849aca51c06f38155f1435fbc6944d7fc0a9bf1e4e9Jamie Gennis return NULL; 850aca51c06f38155f1435fbc6944d7fc0a9bf1e4e9Jamie Gennis } 851aca51c06f38155f1435fbc6944d7fc0a9bf1e4e9Jamie Gennis 852518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian __eglMustCastToProperFunctionPointerType addr; 853e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian addr = findProcAddress(procname, sExtensionMap, NELEM(sExtensionMap)); 854518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (addr) return addr; 855518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 856c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall addr = findBuiltinGLWrapper(procname); 857c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall if (addr) return addr; 858aca51c06f38155f1435fbc6944d7fc0a9bf1e4e9Jamie Gennis 859518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // this protects accesses to sGLExtentionMap and sGLExtentionSlot 860518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian pthread_mutex_lock(&sExtensionMapMutex); 861518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 862518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian /* 863518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * Since eglGetProcAddress() is not associated to anything, it needs 864518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * to return a function pointer that "works" regardless of what 865518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * the current context is. 866518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * 867518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * For this reason, we return a "forwarder", a small stub that takes 868518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * care of calling the function associated with the context 869518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * currently bound. 870518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * 871518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * We first look for extensions we've already resolved, if we're seeing 872518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * this extension for the first time, we go through all our 873518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * implementations and call eglGetProcAddress() and record the 874518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * result in the appropriate implementation hooks and return the 875518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * address of the forwarder corresponding to that hook set. 876518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * 877518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian */ 878518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 879518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian const String8 name(procname); 880518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian addr = sGLExtentionMap.valueFor(name); 881518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian const int slot = sGLExtentionSlot; 882518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 883e6f43ddce78d6846af12550ff9193c5c6fe5844bSteve Block ALOGE_IF(slot >= MAX_NUMBER_OF_GL_EXTENSIONS, 884518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian "no more slots for eglGetProcAddress(\"%s\")", 885518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian procname); 886518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 8870469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#if EGL_TRACE 8880469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy gl_hooks_t *debugHooks = GLTrace_getGLHooks(); 8890469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#endif 8900469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 891518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!addr && (slot < MAX_NUMBER_OF_GL_EXTENSIONS)) { 892518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian bool found = false; 893ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian 894ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 895ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->dso && cnx->egl.eglGetProcAddress) { 896ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian // Extensions are independent of the bound context 89769d100762c7c26d8328f4bb61cfef026d3a69bbfluliuhui addr = 8987773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian cnx->hooks[egl_connection_t::GLESv1_INDEX]->ext.extensions[slot] = 8997773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian cnx->hooks[egl_connection_t::GLESv2_INDEX]->ext.extensions[slot] = 900518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#if EGL_TRACE 901ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian debugHooks->ext.extensions[slot] = 902ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian gHooksTrace.ext.extensions[slot] = 903518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#endif 904ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian cnx->egl.eglGetProcAddress(procname); 90569d100762c7c26d8328f4bb61cfef026d3a69bbfluliuhui if (addr) found = true; 906518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 907ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian 908518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (found) { 909518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian addr = gExtensionForwarders[slot]; 910518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian sGLExtentionMap.add(name, addr); 911518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian sGLExtentionSlot++; 912518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 913518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 914518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 915518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian pthread_mutex_unlock(&sExtensionMapMutex); 916518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return addr; 917518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 918518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 91928ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennisclass FrameCompletionThread : public Thread { 92028ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennispublic: 92128ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis 92228ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis static void queueSync(EGLSyncKHR sync) { 92328ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis static sp<FrameCompletionThread> thread(new FrameCompletionThread); 92428ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis static bool running = false; 92528ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis if (!running) { 92628ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis thread->run("GPUFrameCompletion"); 92728ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis running = true; 92828ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis } 92928ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis { 93028ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis Mutex::Autolock lock(thread->mMutex); 93128ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis ScopedTrace st(ATRACE_TAG, String8::format("kicked off frame %d", 93228ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis thread->mFramesQueued).string()); 93328ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis thread->mQueue.push_back(sync); 93428ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis thread->mCondition.signal(); 93528ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis thread->mFramesQueued++; 93628ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis ATRACE_INT("GPU Frames Outstanding", thread->mQueue.size()); 93728ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis } 93828ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis } 93928ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis 94028ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennisprivate: 94128ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis FrameCompletionThread() : mFramesQueued(0), mFramesCompleted(0) {} 94228ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis 94328ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis virtual bool threadLoop() { 94428ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis EGLSyncKHR sync; 94528ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis uint32_t frameNum; 94628ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis { 94728ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis Mutex::Autolock lock(mMutex); 94828ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis while (mQueue.isEmpty()) { 94928ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis mCondition.wait(mMutex); 95028ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis } 95128ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis sync = mQueue[0]; 95228ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis frameNum = mFramesCompleted; 95328ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis } 95428ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis EGLDisplay dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); 95528ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis { 95628ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis ScopedTrace st(ATRACE_TAG, String8::format("waiting for frame %d", 95728ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis frameNum).string()); 95828ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis EGLint result = eglClientWaitSyncKHR(dpy, sync, 0, EGL_FOREVER_KHR); 95928ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis if (result == EGL_FALSE) { 96028ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis ALOGE("FrameCompletion: error waiting for fence: %#x", eglGetError()); 96128ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis } else if (result == EGL_TIMEOUT_EXPIRED_KHR) { 96228ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis ALOGE("FrameCompletion: timeout waiting for fence"); 96328ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis } 96428ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis eglDestroySyncKHR(dpy, sync); 96528ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis } 96628ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis { 96728ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis Mutex::Autolock lock(mMutex); 96828ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis mQueue.removeAt(0); 96928ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis mFramesCompleted++; 97028ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis ATRACE_INT("GPU Frames Outstanding", mQueue.size()); 97128ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis } 97228ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis return true; 97328ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis } 97428ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis 97528ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis uint32_t mFramesQueued; 97628ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis uint32_t mFramesCompleted; 97728ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis Vector<EGLSyncKHR> mQueue; 97828ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis Condition mCondition; 97928ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis Mutex mMutex; 98028ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis}; 98128ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis 982518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface draw) 983518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 9841c8e95cf86f2182986385bc1ee85f13f425f3a3aJamie Gennis ATRACE_CALL(); 985518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 986518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 987b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 988518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 989518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 990b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall SurfaceRef _s(dp.get(), draw); 9915b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 9925b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 993518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 9940469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#if EGL_TRACE 995a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy gl_hooks_t const *trace_hooks = getGLTraceThreadSpecific(); 996a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy if (getEGLDebugLevel() > 0) { 997a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy if (trace_hooks == NULL) { 998a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy if (GLTrace_start() < 0) { 999a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy ALOGE("Disabling Tracer for OpenGL ES"); 1000a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy setEGLDebugLevel(0); 1001a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy } else { 1002a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy // switch over to the trace version of hooks 1003a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy EGLContext ctx = egl_tls_t::getContext(); 1004a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy egl_context_t * const c = get_context(ctx); 1005a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy if (c) { 1006a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy setGLHooksThreadSpecific(c->cnx->hooks[c->version]); 1007a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy GLTrace_eglMakeCurrent(c->version, c->cnx->hooks[c->version], ctx); 1008a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy } 1009a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy } 1010a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy } 1011a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy 10120469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLTrace_eglSwapBuffers(dpy, draw); 1013a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy } else if (trace_hooks != NULL) { 1014a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy // tracing is now disabled, so switch back to the non trace version 1015a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy EGLContext ctx = egl_tls_t::getContext(); 1016a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy egl_context_t * const c = get_context(ctx); 1017a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy if (c) setGLHooksThreadSpecific(c->cnx->hooks[c->version]); 1018a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy GLTrace_stop(); 1019a73a97728befb5ba5ad647ab3b60058c4d536ba4Siva Velusamy } 10200469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#endif 10210469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 1022518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * const s = get_surface(draw); 10237db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian 1024ed6d08b70d775852f4827471814c83eba3606aaaMathias Agopian if (CC_UNLIKELY(dp->traceGpuCompletion)) { 1025ed6d08b70d775852f4827471814c83eba3606aaaMathias Agopian EGLSyncKHR sync = eglCreateSyncKHR(dpy, EGL_SYNC_FENCE_KHR, NULL); 1026ed6d08b70d775852f4827471814c83eba3606aaaMathias Agopian if (sync != EGL_NO_SYNC_KHR) { 1027ed6d08b70d775852f4827471814c83eba3606aaaMathias Agopian FrameCompletionThread::queueSync(sync); 1028ed6d08b70d775852f4827471814c83eba3606aaaMathias Agopian } 1029ed6d08b70d775852f4827471814c83eba3606aaaMathias Agopian } 1030ed6d08b70d775852f4827471814c83eba3606aaaMathias Agopian 10317db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian if (CC_UNLIKELY(dp->finishOnSwap)) { 10327db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian uint32_t pixel; 10337db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian egl_context_t * const c = get_context( egl_tls_t::getContext() ); 10347db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian if (c) { 10357db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian // glReadPixels() ensures that the frame is complete 10367db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian s->cnx->hooks[c->version]->gl.glReadPixels(0,0,1,1, 10377db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian GL_RGBA,GL_UNSIGNED_BYTE,&pixel); 10387db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian } 10397db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian } 10407db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian 1041ed6d08b70d775852f4827471814c83eba3606aaaMathias Agopian return s->cnx->egl.eglSwapBuffers(dp->disp.dpy, s->surface); 1042518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1043518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1044518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglCopyBuffers( EGLDisplay dpy, EGLSurface surface, 1045518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian NativePixmapType target) 1046518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1047518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1048518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1049b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1050518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1051518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1052b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall SurfaceRef _s(dp.get(), surface); 10535b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 10545b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 1055518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1056518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * const s = get_surface(surface); 1057ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return s->cnx->egl.eglCopyBuffers(dp->disp.dpy, s->surface, target); 1058518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1059518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1060518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianconst char* eglQueryString(EGLDisplay dpy, EGLint name) 1061518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1062518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1063518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1064b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1065518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return (const char *) NULL; 1066518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1067518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian switch (name) { 1068518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian case EGL_VENDOR: 10694b9511c16195a646242eff833b0af212933b6ecaMathias Agopian return dp->getVendorString(); 1070518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian case EGL_VERSION: 10714b9511c16195a646242eff833b0af212933b6ecaMathias Agopian return dp->getVersionString(); 1072518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian case EGL_EXTENSIONS: 10734b9511c16195a646242eff833b0af212933b6ecaMathias Agopian return dp->getExtensionString(); 1074518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian case EGL_CLIENT_APIS: 10754b9511c16195a646242eff833b0af212933b6ecaMathias Agopian return dp->getClientApiString(); 1076518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1077518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_PARAMETER, (const char *)0); 1078518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1079518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1080ca08833d5ea99130797e10ad68a651b50e99da74Mathias AgopianEGLAPI const char* eglQueryStringImplementationANDROID(EGLDisplay dpy, EGLint name) 1081ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian{ 1082ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian clearError(); 1083ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian 1084ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian const egl_display_ptr dp = validate_display(dpy); 1085ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian if (!dp) return (const char *) NULL; 1086ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian 1087ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian switch (name) { 1088ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian case EGL_VENDOR: 1089ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian return dp->disp.queryString.vendor; 1090ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian case EGL_VERSION: 1091ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian return dp->disp.queryString.version; 1092ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian case EGL_EXTENSIONS: 1093ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian return dp->disp.queryString.extensions; 1094ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian case EGL_CLIENT_APIS: 1095ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian return dp->disp.queryString.clientApi; 1096ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian } 1097ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian return setError(EGL_BAD_PARAMETER, (const char *)0); 1098ca08833d5ea99130797e10ad68a651b50e99da74Mathias Agopian} 1099518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1100518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 1101518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// EGL 1.1 1102518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 1103518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1104518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglSurfaceAttrib( 1105518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value) 1106518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1107518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1108518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1109b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1110518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1111518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1112b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall SurfaceRef _s(dp.get(), surface); 11135b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 11145b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 1115518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1116518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * const s = get_surface(surface); 1117518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (s->cnx->egl.eglSurfaceAttrib) { 1118518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return s->cnx->egl.eglSurfaceAttrib( 1119ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian dp->disp.dpy, s->surface, attribute, value); 1120518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1121518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 1122518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1123518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1124518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglBindTexImage( 1125518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLDisplay dpy, EGLSurface surface, EGLint buffer) 1126518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1127518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1128518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1129b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1130518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1131518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1132b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall SurfaceRef _s(dp.get(), surface); 11335b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 11345b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 1135518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1136518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * const s = get_surface(surface); 1137518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (s->cnx->egl.eglBindTexImage) { 1138518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return s->cnx->egl.eglBindTexImage( 1139ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian dp->disp.dpy, s->surface, buffer); 1140518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1141518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 1142518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1143518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1144518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglReleaseTexImage( 1145518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLDisplay dpy, EGLSurface surface, EGLint buffer) 1146518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1147518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1148518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1149b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1150518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1151518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1152b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall SurfaceRef _s(dp.get(), surface); 11535b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 11545b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 1155518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1156518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * const s = get_surface(surface); 1157518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (s->cnx->egl.eglReleaseTexImage) { 1158518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return s->cnx->egl.eglReleaseTexImage( 1159ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian dp->disp.dpy, s->surface, buffer); 1160518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1161518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 1162518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1163518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1164518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint interval) 1165518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1166518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1167518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1168b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1169518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1170518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1171518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean res = EGL_TRUE; 1172ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 1173ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->dso && cnx->egl.eglSwapInterval) { 1174ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian res = cnx->egl.eglSwapInterval(dp->disp.dpy, interval); 1175518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1176ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian 1177518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return res; 1178518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1179518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1180518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1181518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 1182518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// EGL 1.2 1183518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 1184518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1185518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglWaitClient(void) 1186518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1187518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1188518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1189ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 1190ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (!cnx->dso) 1191ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return setError(EGL_BAD_CONTEXT, EGL_FALSE); 1192ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian 1193ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian EGLBoolean res; 1194ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->egl.eglWaitClient) { 1195ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian res = cnx->egl.eglWaitClient(); 1196ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian } else { 1197ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian res = cnx->egl.eglWaitGL(); 1198518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1199518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return res; 1200518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1201518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1202518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglBindAPI(EGLenum api) 1203518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1204518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1205518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1206518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (egl_init_drivers() == EGL_FALSE) { 1207518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_PARAMETER, EGL_FALSE); 1208518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1209518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1210518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // bind this API on all EGLs 1211518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean res = EGL_TRUE; 1212ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 1213ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->dso && cnx->egl.eglBindAPI) { 1214ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian res = cnx->egl.eglBindAPI(api); 1215518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1216518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return res; 1217518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1218518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1219518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLenum eglQueryAPI(void) 1220518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1221518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1222518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1223518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (egl_init_drivers() == EGL_FALSE) { 1224518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_PARAMETER, EGL_FALSE); 1225518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1226518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1227ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 1228ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->dso && cnx->egl.eglQueryAPI) { 1229ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return cnx->egl.eglQueryAPI(); 1230518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1231ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian 1232518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // or, it can only be OpenGL ES 1233518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_OPENGL_ES_API; 1234518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1235518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1236518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglReleaseThread(void) 1237518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1238518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1239518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 12404e620ddce344e946ced992f61a69c367ff92fe24Mathias Agopian#if EGL_TRACE 12414e620ddce344e946ced992f61a69c367ff92fe24Mathias Agopian if (getEGLDebugLevel() > 0) 12424e620ddce344e946ced992f61a69c367ff92fe24Mathias Agopian GLTrace_eglReleaseThread(); 12434e620ddce344e946ced992f61a69c367ff92fe24Mathias Agopian#endif 12444e620ddce344e946ced992f61a69c367ff92fe24Mathias Agopian 1245518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // If there is context bound to the thread, release it 1246fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian egl_display_t::loseCurrent(get_context(getContext())); 1247518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1248ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 1249ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->dso && cnx->egl.eglReleaseThread) { 1250ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian cnx->egl.eglReleaseThread(); 1251518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1252518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_tls_t::clearTLS(); 1253518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_TRUE; 1254518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1255518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1256518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLSurface eglCreatePbufferFromClientBuffer( 1257518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, 1258518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLConfig config, const EGLint *attrib_list) 1259518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1260518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1261518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1262b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall egl_connection_t* cnx = NULL; 1263b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display_connection(dpy, cnx); 1264b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall if (!dp) return EGL_FALSE; 1265518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (cnx->egl.eglCreatePbufferFromClientBuffer) { 1266518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return cnx->egl.eglCreatePbufferFromClientBuffer( 12677773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian dp->disp.dpy, buftype, buffer, config, attrib_list); 1268518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1269518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_CONFIG, EGL_NO_SURFACE); 1270518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1271518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1272518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 1273518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// EGL_EGLEXT_VERSION 3 1274518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 1275518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1276518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglLockSurfaceKHR(EGLDisplay dpy, EGLSurface surface, 1277518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian const EGLint *attrib_list) 1278518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1279518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1280518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1281b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1282518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1283518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1284b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall SurfaceRef _s(dp.get(), surface); 12855b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 12865b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 1287518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1288518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * const s = get_surface(surface); 1289518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (s->cnx->egl.eglLockSurfaceKHR) { 1290518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return s->cnx->egl.eglLockSurfaceKHR( 1291ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian dp->disp.dpy, s->surface, attrib_list); 1292518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1293518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_DISPLAY, EGL_FALSE); 1294518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1295518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1296518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglUnlockSurfaceKHR(EGLDisplay dpy, EGLSurface surface) 1297518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1298518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1299518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1300b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1301518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1302518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1303b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall SurfaceRef _s(dp.get(), surface); 13045b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 13055b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 1306518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1307518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * const s = get_surface(surface); 1308518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (s->cnx->egl.eglUnlockSurfaceKHR) { 1309ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return s->cnx->egl.eglUnlockSurfaceKHR(dp->disp.dpy, s->surface); 1310518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1311518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_DISPLAY, EGL_FALSE); 1312518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1313518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1314518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, 1315518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLClientBuffer buffer, const EGLint *attrib_list) 1316518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1317518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1318518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1319b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1320518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_NO_IMAGE_KHR; 1321518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1322b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall ContextRef _c(dp.get(), ctx); 13237c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian egl_context_t * const c = _c.get(); 1324518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 13257c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian EGLImageKHR result = EGL_NO_IMAGE_KHR; 13267c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian egl_connection_t* const cnx = &gEGLImpl; 13277c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian if (cnx->dso && cnx->egl.eglCreateImageKHR) { 13287c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian result = cnx->egl.eglCreateImageKHR( 13297c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian dp->disp.dpy, 13307c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian c ? c->context : EGL_NO_CONTEXT, 13317c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian target, buffer, attrib_list); 1332518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 13337c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian return result; 1334518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1335518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1336518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR img) 1337518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1338518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1339518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1340b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1341518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1342518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1343646a5c593f9819dc5da6a1ec859bc70cb7ba096fSteven Holte EGLBoolean result = EGL_FALSE; 1344ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 13457c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian if (cnx->dso && cnx->egl.eglDestroyImageKHR) { 1346646a5c593f9819dc5da6a1ec859bc70cb7ba096fSteven Holte result = cnx->egl.eglDestroyImageKHR(dp->disp.dpy, img); 1347518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1348646a5c593f9819dc5da6a1ec859bc70cb7ba096fSteven Holte return result; 1349518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1350518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1351518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 1352518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// EGL_EGLEXT_VERSION 5 1353518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 1354518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1355518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1356518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLSyncKHR eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list) 1357518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1358518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1359518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1360b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1361518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_NO_SYNC_KHR; 1362518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1363518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLSyncKHR result = EGL_NO_SYNC_KHR; 13647c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian egl_connection_t* const cnx = &gEGLImpl; 13657c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian if (cnx->dso && cnx->egl.eglCreateSyncKHR) { 13667c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian result = cnx->egl.eglCreateSyncKHR(dp->disp.dpy, type, attrib_list); 1367518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 13687c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian return result; 1369518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1370518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1371518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync) 1372518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1373518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1374518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1375b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1376518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1377518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1378518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean result = EGL_FALSE; 13797c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian egl_connection_t* const cnx = &gEGLImpl; 13807c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian if (cnx->dso && cnx->egl.eglDestroySyncKHR) { 13817c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian result = cnx->egl.eglDestroySyncKHR(dp->disp.dpy, sync); 1382518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1383518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return result; 1384518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1385518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1386e9b3dfb7d5cc233747407381a51a081c335dc076Mathias AgopianEGLBoolean eglSignalSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode) { 1387e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian clearError(); 1388e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 1389e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian const egl_display_ptr dp = validate_display(dpy); 1390e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian if (!dp) return EGL_FALSE; 1391e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 1392e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian EGLBoolean result = EGL_FALSE; 1393e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian egl_connection_t* const cnx = &gEGLImpl; 1394e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian if (cnx->dso && cnx->egl.eglSignalSyncKHR) { 1395e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian result = cnx->egl.eglSignalSyncKHR( 1396e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian dp->disp.dpy, sync, mode); 1397e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian } 1398e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian return result; 1399e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian} 1400e9b3dfb7d5cc233747407381a51a081c335dc076Mathias Agopian 14017c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias AgopianEGLint eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, 14027c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian EGLint flags, EGLTimeKHR timeout) 1403518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1404518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1405518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1406b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1407518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1408518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 14097c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian EGLBoolean result = EGL_FALSE; 14107c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian egl_connection_t* const cnx = &gEGLImpl; 14117c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian if (cnx->dso && cnx->egl.eglClientWaitSyncKHR) { 14127c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian result = cnx->egl.eglClientWaitSyncKHR( 14137c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian dp->disp.dpy, sync, flags, timeout); 1414518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 14157c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian return result; 1416518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1417518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 14187c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias AgopianEGLBoolean eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync, 14197c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian EGLint attribute, EGLint *value) 1420518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1421518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1422518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1423b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall const egl_display_ptr dp = validate_display(dpy); 1424518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1425518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 14267c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian EGLBoolean result = EGL_FALSE; 14277c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian egl_connection_t* const cnx = &gEGLImpl; 14287c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian if (cnx->dso && cnx->egl.eglGetSyncAttribKHR) { 14297c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian result = cnx->egl.eglGetSyncAttribKHR( 14307c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian dp->disp.dpy, sync, attribute, value); 1431518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 14327c0441ac271f4e00a2d63eb3048c037ebffa90b9Mathias Agopian return result; 1433518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1434518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1435518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 14362bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian// EGL_EGLEXT_VERSION 15 1437518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 1438518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 14392bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias AgopianEGLint eglWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags) { 1440331841b96b92646c93c87627c03f77b892f711cdJamie Gennis clearError(); 1441331841b96b92646c93c87627c03f77b892f711cdJamie Gennis const egl_display_ptr dp = validate_display(dpy); 14422bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian if (!dp) return EGL_FALSE; 14432bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian EGLint result = EGL_FALSE; 1444331841b96b92646c93c87627c03f77b892f711cdJamie Gennis egl_connection_t* const cnx = &gEGLImpl; 14452bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian if (cnx->dso && cnx->egl.eglWaitSyncKHR) { 14462bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian result = cnx->egl.eglWaitSyncKHR(dp->disp.dpy, sync, flags); 1447331841b96b92646c93c87627c03f77b892f711cdJamie Gennis } 1448331841b96b92646c93c87627c03f77b892f711cdJamie Gennis return result; 1449331841b96b92646c93c87627c03f77b892f711cdJamie Gennis} 14501c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 14512bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian// ---------------------------------------------------------------------------- 14522bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian// ANDROID extensions 14532bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian// ---------------------------------------------------------------------------- 14542bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian 14552bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias AgopianEGLint eglDupNativeFenceFDANDROID(EGLDisplay dpy, EGLSyncKHR sync) 1456010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis{ 1457010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis clearError(); 1458010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis 1459010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis const egl_display_ptr dp = validate_display(dpy); 1460010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis if (!dp) return EGL_NO_NATIVE_FENCE_FD_ANDROID; 1461010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis 14622bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian EGLint result = EGL_NO_NATIVE_FENCE_FD_ANDROID; 1463010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis egl_connection_t* const cnx = &gEGLImpl; 14642bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian if (cnx->dso && cnx->egl.eglDupNativeFenceFDANDROID) { 14652bb716871cf8bfadfff1193ed798da3bffc1f8ecMathias Agopian result = cnx->egl.eglDupNativeFenceFDANDROID(dp->disp.dpy, sync); 1466010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis } 1467010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis return result; 1468010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis} 1469010dd4fb892aecf71e4631c22148fe57ef5b3958Jamie Gennis 14707284145d564fa8a422a8e564a38c730fb4a2962bAndy McFaddenEGLBoolean eglPresentationTimeANDROID(EGLDisplay dpy, EGLSurface surface, 14717284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden EGLnsecsANDROID time) 14727284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden{ 14737284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden clearError(); 14747284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden 14757284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden const egl_display_ptr dp = validate_display(dpy); 14767284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden if (!dp) { 14777284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden return EGL_FALSE; 14787284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden } 14797284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden 14807284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden SurfaceRef _s(dp.get(), surface); 14817284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden if (!_s.get()) { 14827284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden setError(EGL_BAD_SURFACE, EGL_FALSE); 14837284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden return EGL_FALSE; 14847284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden } 14857284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden 14867284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden egl_surface_t const * const s = get_surface(surface); 14877284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden native_window_set_buffers_timestamp(s->win.get(), time); 14887284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden 14897284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden return EGL_TRUE; 14907284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden} 14917284145d564fa8a422a8e564a38c730fb4a2962bAndy McFadden 14921c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang// ---------------------------------------------------------------------------- 14931c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang// NVIDIA extensions 14941c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang// ---------------------------------------------------------------------------- 14951c3d72a2291827fb15e2ef311a571c860e0dba41Jonas YangEGLuint64NV eglGetSystemTimeFrequencyNV() 14961c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang{ 14971c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang clearError(); 14981c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 14991c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang if (egl_init_drivers() == EGL_FALSE) { 15001c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang return setError(EGL_BAD_PARAMETER, EGL_FALSE); 15011c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang } 15021c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 15031c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang EGLuint64NV ret = 0; 1504ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 15051c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 1506ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->dso && cnx->egl.eglGetSystemTimeFrequencyNV) { 1507ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return cnx->egl.eglGetSystemTimeFrequencyNV(); 15081c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang } 15091c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 15100e8bbee5775d81c7bbc479b995496cac9238559fMathias Agopian return setErrorQuiet(EGL_BAD_DISPLAY, 0); 15111c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang} 15121c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 15131c3d72a2291827fb15e2ef311a571c860e0dba41Jonas YangEGLuint64NV eglGetSystemTimeNV() 15141c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang{ 15151c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang clearError(); 15161c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 15171c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang if (egl_init_drivers() == EGL_FALSE) { 15181c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang return setError(EGL_BAD_PARAMETER, EGL_FALSE); 15191c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang } 15201c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 15211c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang EGLuint64NV ret = 0; 1522ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 15231c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 1524ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->dso && cnx->egl.eglGetSystemTimeNV) { 1525ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return cnx->egl.eglGetSystemTimeNV(); 15261c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang } 15271c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 15280e8bbee5775d81c7bbc479b995496cac9238559fMathias Agopian return setErrorQuiet(EGL_BAD_DISPLAY, 0); 15291c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang} 1530