eglApi.cpp revision e6f43ddce78d6846af12550ff9193c5c6fe5844b
1518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian/* 2518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ** Copyright 2007, The Android Open Source Project 3518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ** 4518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ** Licensed under the Apache License, Version 2.0 (the "License"); 5518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ** you may not use this file except in compliance with the License. 6518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ** You may obtain a copy of the License at 7518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ** 8518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ** http://www.apache.org/licenses/LICENSE-2.0 9518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ** 10518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ** Unless required by applicable law or agreed to in writing, software 11518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ** distributed under the License is distributed on an "AS IS" BASIS, 12518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ** See the License for the specific language governing permissions and 14518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ** limitations under the License. 15518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian */ 16518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 17518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include <ctype.h> 18518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include <stdlib.h> 19518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include <string.h> 20518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 21518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include <hardware/gralloc.h> 22518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include <system/window.h> 23518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 24518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include <EGL/egl.h> 25518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include <EGL/eglext.h> 26518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include <GLES/gl.h> 27518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include <GLES/glext.h> 28518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 29518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include <cutils/log.h> 30518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include <cutils/atomic.h> 31518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include <cutils/properties.h> 32518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include <cutils/memory.h> 33518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 34518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include <utils/KeyedVector.h> 35518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include <utils/SortedVector.h> 36518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include <utils/String8.h> 37518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 38518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include "egl_impl.h" 39518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include "egl_tls.h" 400469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#include "glestrace.h" 41518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include "hooks.h" 42518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 43518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include "egl_display.h" 44518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include "egl_impl.h" 45518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include "egl_object.h" 46518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include "egl_tls.h" 47518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 48518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianusing namespace android; 49518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 50518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 51518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 52bc2d79ed7ada6243f3690f94ab512c0ddcdbed12Mathias Agopian#define EGL_VERSION_HW_ANDROID 0x3143 53bc2d79ed7ada6243f3690f94ab512c0ddcdbed12Mathias Agopian 54518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstruct extention_map_t { 55518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian const char* name; 56518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian __eglMustCastToProperFunctionPointerType address; 57518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}; 58518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 59518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic const extention_map_t sExtentionMap[] = { 60518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian { "eglLockSurfaceKHR", 61518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian (__eglMustCastToProperFunctionPointerType)&eglLockSurfaceKHR }, 62518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian { "eglUnlockSurfaceKHR", 63518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian (__eglMustCastToProperFunctionPointerType)&eglUnlockSurfaceKHR }, 64518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian { "eglCreateImageKHR", 65518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian (__eglMustCastToProperFunctionPointerType)&eglCreateImageKHR }, 66518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian { "eglDestroyImageKHR", 67518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian (__eglMustCastToProperFunctionPointerType)&eglDestroyImageKHR }, 681c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang { "eglGetSystemTimeFrequencyNV", 691c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang (__eglMustCastToProperFunctionPointerType)&eglGetSystemTimeFrequencyNV }, 701c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang { "eglGetSystemTimeNV", 711c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang (__eglMustCastToProperFunctionPointerType)&eglGetSystemTimeNV }, 72518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}; 73518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 74518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// accesses protected by sExtensionMapMutex 75518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic DefaultKeyedVector<String8, __eglMustCastToProperFunctionPointerType> sGLExtentionMap; 76518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic int sGLExtentionSlot = 0; 77518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic pthread_mutex_t sExtensionMapMutex = PTHREAD_MUTEX_INITIALIZER; 78518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 79518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic void(*findProcAddress(const char* name, 80518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian const extention_map_t* map, size_t n))() { 81518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian for (uint32_t i=0 ; i<n ; i++) { 82518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!strcmp(name, map[i].name)) { 83518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return map[i].address; 84518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 85518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 86518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return NULL; 87518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 88518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 89518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 90518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 91518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopiantemplate<typename T> 92518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic __attribute__((noinline)) 93518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianint binarySearch(T const sortedArray[], int first, int last, T key) { 94518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian while (first <= last) { 95518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian int mid = (first + last) / 2; 96518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (sortedArray[mid] < key) { 97518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian first = mid + 1; 98518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } else if (key < sortedArray[mid]) { 99518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian last = mid - 1; 100518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } else { 101518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return mid; 102518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 103518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 104518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return -1; 105518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 106518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 107518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 108518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 109518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopiannamespace android { 110518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianextern void setGLHooksThreadSpecific(gl_hooks_t const *value); 111518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianextern EGLBoolean egl_init_drivers(); 112518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianextern const __eglMustCastToProperFunctionPointerType gExtensionForwarders[MAX_NUMBER_OF_GL_EXTENSIONS]; 113518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianextern int gEGLDebugLevel; 114518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianextern gl_hooks_t gHooksTrace; 115518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} // namespace android; 116518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 117518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 118518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 119518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic inline void clearError() { egl_tls_t::clearError(); } 120518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic inline EGLContext getContext() { return egl_tls_t::getContext(); } 121518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 122518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 123518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 124518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLDisplay eglGetDisplay(EGLNativeDisplayType display) 125518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 126518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 127518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 128518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian uint32_t index = uint32_t(display); 129518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (index >= NUM_DISPLAYS) { 130518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_PARAMETER, EGL_NO_DISPLAY); 131518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 132518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 133518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (egl_init_drivers() == EGL_FALSE) { 134518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_PARAMETER, EGL_NO_DISPLAY); 135518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 136518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 137518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLDisplay dpy = egl_display_t::getFromNativeDisplay(display); 138518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return dpy; 139518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 140518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 141518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 142518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// Initialization 143518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 144518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 145518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) 146518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 147518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 148518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 149518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t * const dp = get_display(dpy); 150518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE); 151518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 152518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean res = dp->initialize(major, minor); 153518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 154518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return res; 155518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 156518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 157518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglTerminate(EGLDisplay dpy) 158518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 159518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // NOTE: don't unload the drivers b/c some APIs can be called 160518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // after eglTerminate() has been called. eglTerminate() only 161518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // terminates an EGLDisplay, not a EGL itself. 162518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 163518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 164518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 165518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t* const dp = get_display(dpy); 166518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE); 167518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 168518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean res = dp->terminate(); 169518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 170518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return res; 171518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 172518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 173518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 174518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// configuration 175518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 176518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 177518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglGetConfigs( EGLDisplay dpy, 178518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLConfig *configs, 179518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint config_size, EGLint *num_config) 180518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 181518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 182518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 183518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = validate_display(dpy); 184518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 185518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 186518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian GLint numConfigs = dp->numTotalConfigs; 187518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!configs) { 188518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian *num_config = numConfigs; 189518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_TRUE; 190518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 191518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 192518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian GLint n = 0; 193518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian for (intptr_t i=0 ; i<dp->numTotalConfigs && config_size ; i++) { 194518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian *configs++ = EGLConfig(i); 195518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian config_size--; 196518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian n++; 197518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 198518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 199518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian *num_config = n; 200518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_TRUE; 201518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 202518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 203518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglChooseConfig( EGLDisplay dpy, const EGLint *attrib_list, 204518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLConfig *configs, EGLint config_size, 205518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint *num_config) 206518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 207518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 208518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 209518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = validate_display(dpy); 210518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 211518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 212518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (num_config==0) { 213518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_PARAMETER, EGL_FALSE); 214518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 215518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 216518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint n; 217518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean res = EGL_FALSE; 218518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian *num_config = 0; 219518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 220518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 221518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // It is unfortunate, but we need to remap the EGL_CONFIG_IDs, 222518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // to do this, we have to go through the attrib_list array once 223518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // to figure out both its size and if it contains an EGL_CONFIG_ID 224518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // key. If so, the full array is copied and patched. 225518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // NOTE: we assume that there can be only one occurrence 226518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // of EGL_CONFIG_ID. 227518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 228518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint patch_index = -1; 229518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian GLint attr; 230518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian size_t size = 0; 231518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (attrib_list) { 232518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian while ((attr=attrib_list[size]) != EGL_NONE) { 233518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (attr == EGL_CONFIG_ID) 234518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian patch_index = size; 235518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian size += 2; 236518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 237518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 238518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (patch_index >= 0) { 239518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian size += 2; // we need copy the sentinel as well 240518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint* new_list = (EGLint*)malloc(size*sizeof(EGLint)); 241518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (new_list == 0) 242518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_ALLOC, EGL_FALSE); 243518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian memcpy(new_list, attrib_list, size*sizeof(EGLint)); 244518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 245518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // patch the requested EGL_CONFIG_ID 246518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian bool found = false; 247518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLConfig ourConfig(0); 248518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint& configId(new_list[patch_index+1]); 249518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian for (intptr_t i=0 ; i<dp->numTotalConfigs ; i++) { 250518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (dp->configs[i].configId == configId) { 251518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ourConfig = EGLConfig(i); 252518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian configId = dp->configs[i].implConfigId; 253518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian found = true; 254518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian break; 255518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 256518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 257518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 258518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_connection_t* const cnx = &gEGLImpl[dp->configs[intptr_t(ourConfig)].impl]; 259518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (found && cnx->dso) { 260518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // and switch to the new list 261518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian attrib_list = const_cast<const EGLint *>(new_list); 262518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 263518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // At this point, the only configuration that can match is 264518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // dp->configs[i][index], however, we don't know if it would be 265518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // rejected because of the other attributes, so we do have to call 266518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // cnx->egl.eglChooseConfig() -- but we don't have to loop 267518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // through all the EGLimpl[]. 268518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // We also know we can only get a single config back, and we know 269518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // which one. 270518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 271518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian res = cnx->egl.eglChooseConfig( 272518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian dp->disp[ dp->configs[intptr_t(ourConfig)].impl ].dpy, 273518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian attrib_list, configs, config_size, &n); 274518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (res && n>0) { 275518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // n has to be 0 or 1, by construction, and we already know 276518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // which config it will return (since there can be only one). 277518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (configs) { 278518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian configs[0] = ourConfig; 279518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 280518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian *num_config = 1; 281518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 282518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 283518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 284518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian free(const_cast<EGLint *>(attrib_list)); 285518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return res; 286518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 287518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 288518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 289518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian for (int i=0 ; i<IMPL_NUM_IMPLEMENTATIONS ; i++) { 290518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_connection_t* const cnx = &gEGLImpl[i]; 291518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (cnx->dso) { 292518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (cnx->egl.eglChooseConfig( 293518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian dp->disp[i].dpy, attrib_list, configs, config_size, &n)) { 294518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (configs) { 295518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // now we need to convert these client EGLConfig to our 296518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // internal EGLConfig format. 297518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // This is done in O(n Log(n)) time. 298518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian for (int j=0 ; j<n ; j++) { 299518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_config_t key(i, configs[j]); 300518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian intptr_t index = binarySearch<egl_config_t>( 301518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian dp->configs, 0, dp->numTotalConfigs, key); 302518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (index >= 0) { 303518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian configs[j] = EGLConfig(index); 304518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } else { 305518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_CONFIG, EGL_FALSE); 306518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 307518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 308518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian configs += n; 309518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian config_size -= n; 310518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 311518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian *num_config += n; 312518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian res = EGL_TRUE; 313518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 314518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 315518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 316518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return res; 317518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 318518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 319518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, 320518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint attribute, EGLint *value) 321518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 322518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 323518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 324518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const* dp = 0; 325518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_connection_t* cnx = validate_display_config(dpy, config, dp); 326518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!cnx) return EGL_FALSE; 327518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 328518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (attribute == EGL_CONFIG_ID) { 329518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian *value = dp->configs[intptr_t(config)].configId; 330518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_TRUE; 331518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 332518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return cnx->egl.eglGetConfigAttrib( 333518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian dp->disp[ dp->configs[intptr_t(config)].impl ].dpy, 334518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian dp->configs[intptr_t(config)].config, attribute, value); 335518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 336518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 337518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 338518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// surfaces 339518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 340518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 341518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLSurface eglCreateWindowSurface( EGLDisplay dpy, EGLConfig config, 342518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian NativeWindowType window, 343518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian const EGLint *attrib_list) 344518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 345518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 346518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 347518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const* dp = 0; 348518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_connection_t* cnx = validate_display_config(dpy, config, dp); 349518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (cnx) { 350518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLDisplay iDpy = dp->disp[ dp->configs[intptr_t(config)].impl ].dpy; 351518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLConfig iConfig = dp->configs[intptr_t(config)].config; 352518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint format; 353518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 35481a63350527cafce6929309533c58586878f10b5Mathias Agopian if (native_window_api_connect(window, NATIVE_WINDOW_API_EGL) != OK) { 355e6f43ddce78d6846af12550ff9193c5c6fe5844bSteve Block ALOGE("EGLNativeWindowType %p already connected to another API", 35681a63350527cafce6929309533c58586878f10b5Mathias Agopian window); 35781a63350527cafce6929309533c58586878f10b5Mathias Agopian return setError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE); 35881a63350527cafce6929309533c58586878f10b5Mathias Agopian } 35981a63350527cafce6929309533c58586878f10b5Mathias Agopian 360518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // set the native window's buffers format to match this config 361518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (cnx->egl.eglGetConfigAttrib(iDpy, 362518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian iConfig, EGL_NATIVE_VISUAL_ID, &format)) { 363518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (format != 0) { 364bee205fd58a27c10a0895de5339e76025d429d2bJamie Gennis int err = native_window_set_buffers_format(window, format); 365bee205fd58a27c10a0895de5339e76025d429d2bJamie Gennis if (err != 0) { 366e6f43ddce78d6846af12550ff9193c5c6fe5844bSteve Block ALOGE("error setting native window pixel format: %s (%d)", 367bee205fd58a27c10a0895de5339e76025d429d2bJamie Gennis strerror(-err), err); 36881a63350527cafce6929309533c58586878f10b5Mathias Agopian native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL); 369bee205fd58a27c10a0895de5339e76025d429d2bJamie Gennis return setError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE); 370bee205fd58a27c10a0895de5339e76025d429d2bJamie Gennis } 371518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 372518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 373518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 37459769469e4b9b2d8b12c020eb44b030b3927a50bJamie Gennis // the EGL spec requires that a new EGLSurface default to swap interval 37559769469e4b9b2d8b12c020eb44b030b3927a50bJamie Gennis // 1, so explicitly set that on the window here. 37659769469e4b9b2d8b12c020eb44b030b3927a50bJamie Gennis ANativeWindow* anw = reinterpret_cast<ANativeWindow*>(window); 37759769469e4b9b2d8b12c020eb44b030b3927a50bJamie Gennis anw->setSwapInterval(anw, 1); 37859769469e4b9b2d8b12c020eb44b030b3927a50bJamie Gennis 379518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLSurface surface = cnx->egl.eglCreateWindowSurface( 380518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian iDpy, iConfig, window, attrib_list); 381518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (surface != EGL_NO_SURFACE) { 382518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t* s = new egl_surface_t(dpy, config, window, surface, 383518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian dp->configs[intptr_t(config)].impl, cnx); 384518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return s; 385518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 38681a63350527cafce6929309533c58586878f10b5Mathias Agopian 38781a63350527cafce6929309533c58586878f10b5Mathias Agopian // EGLSurface creation failed 38881a63350527cafce6929309533c58586878f10b5Mathias Agopian native_window_set_buffers_format(window, 0); 38981a63350527cafce6929309533c58586878f10b5Mathias Agopian native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL); 390518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 391518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_NO_SURFACE; 392518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 393518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 394518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLSurface eglCreatePixmapSurface( EGLDisplay dpy, EGLConfig config, 395518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian NativePixmapType pixmap, 396518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian const EGLint *attrib_list) 397518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 398518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 399518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 400518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const* dp = 0; 401518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_connection_t* cnx = validate_display_config(dpy, config, dp); 402518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (cnx) { 403518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLSurface surface = cnx->egl.eglCreatePixmapSurface( 404518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian dp->disp[ dp->configs[intptr_t(config)].impl ].dpy, 405518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian dp->configs[intptr_t(config)].config, pixmap, attrib_list); 406518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (surface != EGL_NO_SURFACE) { 407518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t* s = new egl_surface_t(dpy, config, NULL, surface, 408518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian dp->configs[intptr_t(config)].impl, cnx); 409518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return s; 410518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 411518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 412518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_NO_SURFACE; 413518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 414518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 415518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLSurface eglCreatePbufferSurface( EGLDisplay dpy, EGLConfig config, 416518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian const EGLint *attrib_list) 417518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 418518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 419518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 420518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const* dp = 0; 421518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_connection_t* cnx = validate_display_config(dpy, config, dp); 422518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (cnx) { 423518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLSurface surface = cnx->egl.eglCreatePbufferSurface( 424518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian dp->disp[ dp->configs[intptr_t(config)].impl ].dpy, 425518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian dp->configs[intptr_t(config)].config, attrib_list); 426518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (surface != EGL_NO_SURFACE) { 427518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t* s = new egl_surface_t(dpy, config, NULL, surface, 428518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian dp->configs[intptr_t(config)].impl, cnx); 429518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return s; 430518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 431518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 432518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_NO_SURFACE; 433518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 434518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 435518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface) 436518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 437518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 438518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 439518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = validate_display(dpy); 440518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 441518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 442f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian SurfaceRef _s(dp, surface); 4435b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 4445b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 445518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 446518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t * const s = get_surface(surface); 447518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean result = s->cnx->egl.eglDestroySurface( 448518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian dp->disp[s->impl].dpy, s->surface); 449518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (result == EGL_TRUE) { 450518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian _s.terminate(); 451518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 452518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return result; 453518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 454518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 455518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglQuerySurface( EGLDisplay dpy, EGLSurface surface, 456518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint attribute, EGLint *value) 457518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 458518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 459518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 460518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = validate_display(dpy); 461518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 462518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 463f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian SurfaceRef _s(dp, surface); 4645b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 4655b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 466518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 467518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * const s = get_surface(surface); 468518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean result(EGL_TRUE); 469518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (attribute == EGL_CONFIG_ID) { 470518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // We need to remap EGL_CONFIG_IDs 471518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian *value = dp->configs[intptr_t(s->config)].configId; 472518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } else { 473518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian result = s->cnx->egl.eglQuerySurface( 474518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian dp->disp[s->impl].dpy, s->surface, attribute, value); 475518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 476518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 477518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return result; 478518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 479518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 480518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 481518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// Contexts 482518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 483518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 484518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config, 485518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLContext share_list, const EGLint *attrib_list) 486518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 487518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 488518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 489518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const* dp = 0; 490518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_connection_t* cnx = validate_display_config(dpy, config, dp); 491518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (cnx) { 492518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (share_list != EGL_NO_CONTEXT) { 493518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t* const c = get_context(share_list); 494518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian share_list = c->context; 495518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 496518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLContext context = cnx->egl.eglCreateContext( 497518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian dp->disp[ dp->configs[intptr_t(config)].impl ].dpy, 498518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian dp->configs[intptr_t(config)].config, 499518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian share_list, attrib_list); 500518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (context != EGL_NO_CONTEXT) { 501518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // figure out if it's a GLESv1 or GLESv2 502518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian int version = 0; 503518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (attrib_list) { 504518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian while (*attrib_list != EGL_NONE) { 505518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian GLint attr = *attrib_list++; 506518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian GLint value = *attrib_list++; 507518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (attr == EGL_CONTEXT_CLIENT_VERSION) { 508518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (value == 1) { 509518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian version = GLESv1_INDEX; 510518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } else if (value == 2) { 511518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian version = GLESv2_INDEX; 512518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 513518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 514518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian }; 515518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 516518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t* c = new egl_context_t(dpy, context, config, 517518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian dp->configs[intptr_t(config)].impl, cnx, version); 5180469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#if EGL_TRACE 5190469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy if (gEGLDebugLevel > 0) 5200469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLTrace_eglCreateContext(version, c); 5210469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#endif 522518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return c; 523518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 524518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 525518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_NO_CONTEXT; 526518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 527518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 528518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx) 529518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 530518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 531518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 532518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = validate_display(dpy); 5335b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!dp) 5345b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return EGL_FALSE; 535518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 536f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian ContextRef _c(dp, ctx); 5375b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_c.get()) 5385b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_CONTEXT, EGL_FALSE); 539518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 540518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t * const c = get_context(ctx); 541518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean result = c->cnx->egl.eglDestroyContext( 542518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian dp->disp[c->impl].dpy, c->context); 543518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (result == EGL_TRUE) { 544518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian _c.terminate(); 545518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 546518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return result; 547518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 548518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 549518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic void loseCurrent(egl_context_t * cur_c) 550518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 551518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (cur_c) { 552518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t * cur_r = get_surface(cur_c->read); 553518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t * cur_d = get_surface(cur_c->draw); 554518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 555518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // by construction, these are either 0 or valid (possibly terminated) 556518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // it should be impossible for these to be invalid 557518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ContextRef _cur_c(cur_c); 558518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian SurfaceRef _cur_r(cur_r); 559518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian SurfaceRef _cur_d(cur_d); 560518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 561518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian cur_c->read = NULL; 562518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian cur_c->draw = NULL; 563518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 564518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian _cur_c.release(); 565518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian _cur_r.release(); 566518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian _cur_d.release(); 567518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 568518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 569518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 570518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglMakeCurrent( EGLDisplay dpy, EGLSurface draw, 571518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLSurface read, EGLContext ctx) 572518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 573518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 574518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 575518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = get_display(dpy); 576518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE); 577518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 5785b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian // If ctx is not EGL_NO_CONTEXT, read is not EGL_NO_SURFACE, or draw is not 5795b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian // EGL_NO_SURFACE, then an EGL_NOT_INITIALIZED error is generated if dpy is 5805b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian // a valid but uninitialized display. 581518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if ( (ctx != EGL_NO_CONTEXT) || (read != EGL_NO_SURFACE) || 582518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian (draw != EGL_NO_SURFACE) ) { 583518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp->isReady()) return setError(EGL_NOT_INITIALIZED, EGL_FALSE); 584518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 585518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 586518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // get a reference to the object passed in 587f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian ContextRef _c(dp, ctx); 588f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian SurfaceRef _d(dp, draw); 589f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian SurfaceRef _r(dp, read); 590518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 591518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // validate the context (if not EGL_NO_CONTEXT) 5925b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if ((ctx != EGL_NO_CONTEXT) && !_c.get()) { 593518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // EGL_NO_CONTEXT is valid 594518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_FALSE; 595518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 596518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 597518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // these are the underlying implementation's object 598518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLContext impl_ctx = EGL_NO_CONTEXT; 599518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLSurface impl_draw = EGL_NO_SURFACE; 600518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLSurface impl_read = EGL_NO_SURFACE; 601518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 602518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // these are our objects structs passed in 603518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t * c = NULL; 604518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * d = NULL; 605518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * r = NULL; 606518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 607518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // these are the current objects structs 608518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t * cur_c = get_context(getContext()); 609518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 610518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (ctx != EGL_NO_CONTEXT) { 611518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian c = get_context(ctx); 612518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian impl_ctx = c->context; 613518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } else { 614518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // no context given, use the implementation of the current context 615518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (cur_c == NULL) { 616518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // no current context 617518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (draw != EGL_NO_SURFACE || read != EGL_NO_SURFACE) { 618518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // calling eglMakeCurrent( ..., !=0, !=0, EGL_NO_CONTEXT); 619518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_MATCH, EGL_FALSE); 620518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 621518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // not an error, there is just no current context. 622518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_TRUE; 623518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 624518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 625518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 626518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // retrieve the underlying implementation's draw EGLSurface 627518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (draw != EGL_NO_SURFACE) { 628518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian d = get_surface(draw); 629518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // make sure the EGLContext and EGLSurface passed in are for 630518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // the same driver 631518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (c && d->impl != c->impl) 632518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_MATCH, EGL_FALSE); 633518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian impl_draw = d->surface; 634518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 635518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 636518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // retrieve the underlying implementation's read EGLSurface 637518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (read != EGL_NO_SURFACE) { 638518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian r = get_surface(read); 639518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // make sure the EGLContext and EGLSurface passed in are for 640518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // the same driver 641518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (c && r->impl != c->impl) 642518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_MATCH, EGL_FALSE); 643518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian impl_read = r->surface; 644518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 645518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 646518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean result; 647518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 648518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (c) { 649518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian result = c->cnx->egl.eglMakeCurrent( 650518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian dp->disp[c->impl].dpy, impl_draw, impl_read, impl_ctx); 651518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } else { 652518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian result = cur_c->cnx->egl.eglMakeCurrent( 653518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian dp->disp[cur_c->impl].dpy, impl_draw, impl_read, impl_ctx); 654518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 655518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 656518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (result == EGL_TRUE) { 657518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 658518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian loseCurrent(cur_c); 659518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 660518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (ctx != EGL_NO_CONTEXT) { 661518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian setGLHooksThreadSpecific(c->cnx->hooks[c->version]); 662518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_tls_t::setContext(ctx); 6630469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#if EGL_TRACE 6640469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy if (gEGLDebugLevel > 0) 66593a826f78f6313db791e6fc880439189897651b3Siva Velusamy GLTrace_eglMakeCurrent(c->version, c->cnx->hooks[c->version], ctx); 6660469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#endif 667518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian _c.acquire(); 668518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian _r.acquire(); 669518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian _d.acquire(); 670518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian c->read = read; 671518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian c->draw = draw; 672518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } else { 673518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian setGLHooksThreadSpecific(&gHooksNoContext); 674518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_tls_t::setContext(EGL_NO_CONTEXT); 675518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 6765fecea776a5f093c21ac1a0ad3552b847d4be23eMathias Agopian } else { 677e6f43ddce78d6846af12550ff9193c5c6fe5844bSteve Block // this will ALOGE the error 6785fecea776a5f093c21ac1a0ad3552b847d4be23eMathias Agopian result = setError(c->cnx->egl.eglGetError(), EGL_FALSE); 679518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 680518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return result; 681518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 682518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 683518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 684518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglQueryContext( EGLDisplay dpy, EGLContext ctx, 685518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint attribute, EGLint *value) 686518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 687518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 688518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 689518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = validate_display(dpy); 690518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 691518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 692f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian ContextRef _c(dp, ctx); 693518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!_c.get()) return setError(EGL_BAD_CONTEXT, EGL_FALSE); 694518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 695518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t * const c = get_context(ctx); 696518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 697518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean result(EGL_TRUE); 698518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (attribute == EGL_CONFIG_ID) { 699518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian *value = dp->configs[intptr_t(c->config)].configId; 700518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } else { 701518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // We need to remap EGL_CONFIG_IDs 702518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian result = c->cnx->egl.eglQueryContext( 703518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian dp->disp[c->impl].dpy, c->context, attribute, value); 704518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 705518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 706518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return result; 707518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 708518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 709518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLContext eglGetCurrentContext(void) 710518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 711518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // could be called before eglInitialize(), but we wouldn't have a context 712518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // then, and this function would correctly return EGL_NO_CONTEXT. 713518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 714518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 715518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 716518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLContext ctx = getContext(); 717518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return ctx; 718518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 719518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 720518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLSurface eglGetCurrentSurface(EGLint readdraw) 721518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 722518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // could be called before eglInitialize(), but we wouldn't have a context 723518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // then, and this function would correctly return EGL_NO_SURFACE. 724518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 725518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 726518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 727518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLContext ctx = getContext(); 728518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (ctx) { 729518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t const * const c = get_context(ctx); 730518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!c) return setError(EGL_BAD_CONTEXT, EGL_NO_SURFACE); 731518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian switch (readdraw) { 732518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian case EGL_READ: return c->read; 733518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian case EGL_DRAW: return c->draw; 734518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian default: return setError(EGL_BAD_PARAMETER, EGL_NO_SURFACE); 735518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 736518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 737518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_NO_SURFACE; 738518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 739518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 740518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLDisplay eglGetCurrentDisplay(void) 741518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 742518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // could be called before eglInitialize(), but we wouldn't have a context 743518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // then, and this function would correctly return EGL_NO_DISPLAY. 744518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 745518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 746518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 747518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLContext ctx = getContext(); 748518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (ctx) { 749518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t const * const c = get_context(ctx); 750518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!c) return setError(EGL_BAD_CONTEXT, EGL_NO_SURFACE); 751518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return c->dpy; 752518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 753518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_NO_DISPLAY; 754518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 755518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 756518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglWaitGL(void) 757518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 758518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // could be called before eglInitialize(), but we wouldn't have a context 759518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // then, and this function would return GL_TRUE, which isn't wrong. 760518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 761518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 762518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 763518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean res = EGL_TRUE; 764518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLContext ctx = getContext(); 765518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (ctx) { 766518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t const * const c = get_context(ctx); 767518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!c) return setError(EGL_BAD_CONTEXT, EGL_FALSE); 768518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (uint32_t(c->impl)>=2) 769518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_CONTEXT, EGL_FALSE); 770518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_connection_t* const cnx = &gEGLImpl[c->impl]; 771518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!cnx->dso) 772518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_CONTEXT, EGL_FALSE); 773518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian res = cnx->egl.eglWaitGL(); 774518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 775518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return res; 776518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 777518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 778518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglWaitNative(EGLint engine) 779518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 780518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // could be called before eglInitialize(), but we wouldn't have a context 781518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // then, and this function would return GL_TRUE, which isn't wrong. 782518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 783518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 784518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 785518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean res = EGL_TRUE; 786518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLContext ctx = getContext(); 787518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (ctx) { 788518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t const * const c = get_context(ctx); 789518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!c) return setError(EGL_BAD_CONTEXT, EGL_FALSE); 790518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (uint32_t(c->impl)>=2) 791518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_CONTEXT, EGL_FALSE); 792518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_connection_t* const cnx = &gEGLImpl[c->impl]; 793518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!cnx->dso) 794518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_CONTEXT, EGL_FALSE); 795518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian res = cnx->egl.eglWaitNative(engine); 796518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 797518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return res; 798518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 799518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 800518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLint eglGetError(void) 801518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 802518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint result = EGL_SUCCESS; 803518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint err; 804518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian for (int i=0 ; i<IMPL_NUM_IMPLEMENTATIONS ; i++) { 805518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian err = EGL_SUCCESS; 806518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_connection_t* const cnx = &gEGLImpl[i]; 807518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (cnx->dso) 808518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian err = cnx->egl.eglGetError(); 809518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (err!=EGL_SUCCESS && result==EGL_SUCCESS) 810518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian result = err; 811518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 812518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian err = egl_tls_t::getError(); 813518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (result == EGL_SUCCESS) 814518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian result = err; 815518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return result; 816518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 817518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 818518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// Note: Similar implementations of these functions also exist in 819518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// gl2.cpp and gl.cpp, and are used by applications that call the 820518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// exported entry points directly. 821518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopiantypedef void (GL_APIENTRYP PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) (GLenum target, GLeglImageOES image); 822518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopiantypedef void (GL_APIENTRYP PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC) (GLenum target, GLeglImageOES image); 823518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 824518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES_impl = NULL; 825518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC glEGLImageTargetRenderbufferStorageOES_impl = NULL; 826518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 827518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic void glEGLImageTargetTexture2DOES_wrapper(GLenum target, GLeglImageOES image) 828518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 829518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian GLeglImageOES implImage = 830518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian (GLeglImageOES)egl_get_image_for_current_context((EGLImageKHR)image); 831518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian glEGLImageTargetTexture2DOES_impl(target, implImage); 832518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 833518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 834518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic void glEGLImageTargetRenderbufferStorageOES_wrapper(GLenum target, GLeglImageOES image) 835518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 836518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian GLeglImageOES implImage = 837518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian (GLeglImageOES)egl_get_image_for_current_context((EGLImageKHR)image); 838518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian glEGLImageTargetRenderbufferStorageOES_impl(target, implImage); 839518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 840518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 841518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian__eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname) 842518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 843518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // eglGetProcAddress() could be the very first function called 844518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // in which case we must make sure we've initialized ourselves, this 845518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // happens the first time egl_get_display() is called. 846518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 847518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 848518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 849518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (egl_init_drivers() == EGL_FALSE) { 850518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian setError(EGL_BAD_PARAMETER, NULL); 851518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return NULL; 852518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 853518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 854aca51c06f38155f1435fbc6944d7fc0a9bf1e4e9Jamie Gennis // The EGL_ANDROID_blob_cache extension should not be exposed to 855aca51c06f38155f1435fbc6944d7fc0a9bf1e4e9Jamie Gennis // applications. It is used internally by the Android EGL layer. 856c42fcf05ce253d5342993b28c412be16e61efffbJamie Gennis if (!strcmp(procname, "eglSetBlobCacheFuncsANDROID")) { 857aca51c06f38155f1435fbc6944d7fc0a9bf1e4e9Jamie Gennis return NULL; 858aca51c06f38155f1435fbc6944d7fc0a9bf1e4e9Jamie Gennis } 859aca51c06f38155f1435fbc6944d7fc0a9bf1e4e9Jamie Gennis 860518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian __eglMustCastToProperFunctionPointerType addr; 861518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian addr = findProcAddress(procname, sExtentionMap, NELEM(sExtentionMap)); 862518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (addr) return addr; 863518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 864aca51c06f38155f1435fbc6944d7fc0a9bf1e4e9Jamie Gennis 865518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // this protects accesses to sGLExtentionMap and sGLExtentionSlot 866518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian pthread_mutex_lock(&sExtensionMapMutex); 867518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 868518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian /* 869518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * Since eglGetProcAddress() is not associated to anything, it needs 870518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * to return a function pointer that "works" regardless of what 871518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * the current context is. 872518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * 873518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * For this reason, we return a "forwarder", a small stub that takes 874518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * care of calling the function associated with the context 875518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * currently bound. 876518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * 877518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * We first look for extensions we've already resolved, if we're seeing 878518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * this extension for the first time, we go through all our 879518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * implementations and call eglGetProcAddress() and record the 880518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * result in the appropriate implementation hooks and return the 881518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * address of the forwarder corresponding to that hook set. 882518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * 883518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian */ 884518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 885518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian const String8 name(procname); 886518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian addr = sGLExtentionMap.valueFor(name); 887518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian const int slot = sGLExtentionSlot; 888518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 889e6f43ddce78d6846af12550ff9193c5c6fe5844bSteve Block ALOGE_IF(slot >= MAX_NUMBER_OF_GL_EXTENSIONS, 890518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian "no more slots for eglGetProcAddress(\"%s\")", 891518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian procname); 892518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 8930469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#if EGL_TRACE 8940469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy gl_hooks_t *debugHooks = GLTrace_getGLHooks(); 8950469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#endif 8960469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 897518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!addr && (slot < MAX_NUMBER_OF_GL_EXTENSIONS)) { 898518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian bool found = false; 899518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian for (int i=0 ; i<IMPL_NUM_IMPLEMENTATIONS ; i++) { 900518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_connection_t* const cnx = &gEGLImpl[i]; 901518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (cnx->dso && cnx->egl.eglGetProcAddress) { 902518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian found = true; 903518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // Extensions are independent of the bound context 904518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian cnx->hooks[GLESv1_INDEX]->ext.extensions[slot] = 905518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian cnx->hooks[GLESv2_INDEX]->ext.extensions[slot] = 906518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#if EGL_TRACE 9070469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy debugHooks->ext.extensions[slot] = gHooksTrace.ext.extensions[slot] = 908518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#endif 909518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian cnx->egl.eglGetProcAddress(procname); 910518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 911518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 912518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (found) { 913518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian addr = gExtensionForwarders[slot]; 914518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 915518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!strcmp(procname, "glEGLImageTargetTexture2DOES")) { 916518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian glEGLImageTargetTexture2DOES_impl = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)addr; 917518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian addr = (__eglMustCastToProperFunctionPointerType)glEGLImageTargetTexture2DOES_wrapper; 918518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 919518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!strcmp(procname, "glEGLImageTargetRenderbufferStorageOES")) { 920518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian glEGLImageTargetRenderbufferStorageOES_impl = (PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC)addr; 921518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian addr = (__eglMustCastToProperFunctionPointerType)glEGLImageTargetRenderbufferStorageOES_wrapper; 922518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 923518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 924518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian sGLExtentionMap.add(name, addr); 925518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian sGLExtentionSlot++; 926518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 927518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 928518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 929518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian pthread_mutex_unlock(&sExtensionMapMutex); 930518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return addr; 931518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 932518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 933518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface draw) 934518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 935518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 936518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 937518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = validate_display(dpy); 938518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 939518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 940f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian SurfaceRef _s(dp, draw); 9415b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 9425b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 943518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 9440469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#if EGL_TRACE 9450469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy if (gEGLDebugLevel > 0) 9460469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLTrace_eglSwapBuffers(dpy, draw); 9470469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#endif 9480469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 949518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * const s = get_surface(draw); 950518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return s->cnx->egl.eglSwapBuffers(dp->disp[s->impl].dpy, s->surface); 951518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 952518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 953518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglCopyBuffers( EGLDisplay dpy, EGLSurface surface, 954518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian NativePixmapType target) 955518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 956518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 957518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 958518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = validate_display(dpy); 959518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 960518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 961f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian SurfaceRef _s(dp, surface); 9625b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 9635b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 964518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 965518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * const s = get_surface(surface); 966518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return s->cnx->egl.eglCopyBuffers( 967518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian dp->disp[s->impl].dpy, s->surface, target); 968518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 969518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 970518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianconst char* eglQueryString(EGLDisplay dpy, EGLint name) 971518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 972518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 973518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 974518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = validate_display(dpy); 975518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return (const char *) NULL; 976518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 977518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian switch (name) { 978518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian case EGL_VENDOR: 9794b9511c16195a646242eff833b0af212933b6ecaMathias Agopian return dp->getVendorString(); 980518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian case EGL_VERSION: 9814b9511c16195a646242eff833b0af212933b6ecaMathias Agopian return dp->getVersionString(); 982518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian case EGL_EXTENSIONS: 9834b9511c16195a646242eff833b0af212933b6ecaMathias Agopian return dp->getExtensionString(); 984518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian case EGL_CLIENT_APIS: 9854b9511c16195a646242eff833b0af212933b6ecaMathias Agopian return dp->getClientApiString(); 986bc2d79ed7ada6243f3690f94ab512c0ddcdbed12Mathias Agopian case EGL_VERSION_HW_ANDROID: { 987bc2d79ed7ada6243f3690f94ab512c0ddcdbed12Mathias Agopian if (gEGLImpl[IMPL_HARDWARE].dso) { 988bc2d79ed7ada6243f3690f94ab512c0ddcdbed12Mathias Agopian return dp->disp[IMPL_HARDWARE].queryString.version; 989bc2d79ed7ada6243f3690f94ab512c0ddcdbed12Mathias Agopian } 990bc2d79ed7ada6243f3690f94ab512c0ddcdbed12Mathias Agopian return dp->disp[IMPL_SOFTWARE].queryString.version; 991bc2d79ed7ada6243f3690f94ab512c0ddcdbed12Mathias Agopian } 992518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 993518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_PARAMETER, (const char *)0); 994518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 995518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 996518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 997518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 998518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// EGL 1.1 999518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 1000518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1001518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglSurfaceAttrib( 1002518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value) 1003518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1004518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1005518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1006518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = validate_display(dpy); 1007518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1008518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1009f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian SurfaceRef _s(dp, surface); 10105b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 10115b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 1012518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1013518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * const s = get_surface(surface); 1014518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (s->cnx->egl.eglSurfaceAttrib) { 1015518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return s->cnx->egl.eglSurfaceAttrib( 1016518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian dp->disp[s->impl].dpy, s->surface, attribute, value); 1017518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1018518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 1019518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1020518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1021518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglBindTexImage( 1022518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLDisplay dpy, EGLSurface surface, EGLint buffer) 1023518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1024518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1025518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1026518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = validate_display(dpy); 1027518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1028518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1029f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian SurfaceRef _s(dp, surface); 10305b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 10315b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 1032518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1033518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * const s = get_surface(surface); 1034518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (s->cnx->egl.eglBindTexImage) { 1035518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return s->cnx->egl.eglBindTexImage( 1036518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian dp->disp[s->impl].dpy, s->surface, buffer); 1037518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1038518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 1039518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1040518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1041518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglReleaseTexImage( 1042518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLDisplay dpy, EGLSurface surface, EGLint buffer) 1043518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1044518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1045518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1046518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = validate_display(dpy); 1047518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1048518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1049f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian SurfaceRef _s(dp, surface); 10505b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 10515b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 1052518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1053518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * const s = get_surface(surface); 1054518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (s->cnx->egl.eglReleaseTexImage) { 1055518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return s->cnx->egl.eglReleaseTexImage( 1056518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian dp->disp[s->impl].dpy, s->surface, buffer); 1057518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1058518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 1059518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1060518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1061518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint interval) 1062518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1063518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1064518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1065518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = validate_display(dpy); 1066518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1067518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1068518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean res = EGL_TRUE; 1069518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian for (int i=0 ; i<IMPL_NUM_IMPLEMENTATIONS ; i++) { 1070518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_connection_t* const cnx = &gEGLImpl[i]; 1071518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (cnx->dso) { 1072518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (cnx->egl.eglSwapInterval) { 1073518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (cnx->egl.eglSwapInterval( 1074518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian dp->disp[i].dpy, interval) == EGL_FALSE) { 1075518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian res = EGL_FALSE; 1076518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1077518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1078518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1079518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1080518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return res; 1081518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1082518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1083518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1084518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 1085518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// EGL 1.2 1086518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 1087518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1088518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglWaitClient(void) 1089518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1090518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1091518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1092518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // could be called before eglInitialize(), but we wouldn't have a context 1093518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // then, and this function would return GL_TRUE, which isn't wrong. 1094518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean res = EGL_TRUE; 1095518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLContext ctx = getContext(); 1096518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (ctx) { 1097518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t const * const c = get_context(ctx); 1098518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!c) return setError(EGL_BAD_CONTEXT, EGL_FALSE); 1099518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (uint32_t(c->impl)>=2) 1100518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_CONTEXT, EGL_FALSE); 1101518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_connection_t* const cnx = &gEGLImpl[c->impl]; 1102518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!cnx->dso) 1103518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_CONTEXT, EGL_FALSE); 1104518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (cnx->egl.eglWaitClient) { 1105518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian res = cnx->egl.eglWaitClient(); 1106518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } else { 1107518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian res = cnx->egl.eglWaitGL(); 1108518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1109518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1110518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return res; 1111518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1112518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1113518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglBindAPI(EGLenum api) 1114518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1115518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1116518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1117518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (egl_init_drivers() == EGL_FALSE) { 1118518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_PARAMETER, EGL_FALSE); 1119518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1120518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1121518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // bind this API on all EGLs 1122518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean res = EGL_TRUE; 1123518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian for (int i=0 ; i<IMPL_NUM_IMPLEMENTATIONS ; i++) { 1124518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_connection_t* const cnx = &gEGLImpl[i]; 1125518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (cnx->dso) { 1126518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (cnx->egl.eglBindAPI) { 1127518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (cnx->egl.eglBindAPI(api) == EGL_FALSE) { 1128518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian res = EGL_FALSE; 1129518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1130518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1131518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1132518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1133518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return res; 1134518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1135518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1136518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLenum eglQueryAPI(void) 1137518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1138518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1139518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1140518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (egl_init_drivers() == EGL_FALSE) { 1141518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_PARAMETER, EGL_FALSE); 1142518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1143518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1144518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian for (int i=0 ; i<IMPL_NUM_IMPLEMENTATIONS ; i++) { 1145518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_connection_t* const cnx = &gEGLImpl[i]; 1146518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (cnx->dso) { 1147518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (cnx->egl.eglQueryAPI) { 1148518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // the first one we find is okay, because they all 1149518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // should be the same 1150518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return cnx->egl.eglQueryAPI(); 1151518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1152518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1153518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1154518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // or, it can only be OpenGL ES 1155518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_OPENGL_ES_API; 1156518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1157518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1158518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglReleaseThread(void) 1159518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1160518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1161518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1162518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // If there is context bound to the thread, release it 1163518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian loseCurrent(get_context(getContext())); 1164518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1165518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian for (int i=0 ; i<IMPL_NUM_IMPLEMENTATIONS ; i++) { 1166518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_connection_t* const cnx = &gEGLImpl[i]; 1167518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (cnx->dso) { 1168518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (cnx->egl.eglReleaseThread) { 1169518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian cnx->egl.eglReleaseThread(); 1170518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1171518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1172518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1173518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_tls_t::clearTLS(); 11740469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#if EGL_TRACE 11750469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy if (gEGLDebugLevel > 0) 11760469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLTrace_eglReleaseThread(); 11770469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#endif 1178518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_TRUE; 1179518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1180518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1181518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLSurface eglCreatePbufferFromClientBuffer( 1182518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, 1183518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLConfig config, const EGLint *attrib_list) 1184518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1185518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1186518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1187518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const* dp = 0; 1188518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_connection_t* cnx = validate_display_config(dpy, config, dp); 1189518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!cnx) return EGL_FALSE; 1190518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (cnx->egl.eglCreatePbufferFromClientBuffer) { 1191518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return cnx->egl.eglCreatePbufferFromClientBuffer( 1192518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian dp->disp[ dp->configs[intptr_t(config)].impl ].dpy, 1193518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian buftype, buffer, 1194518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian dp->configs[intptr_t(config)].config, attrib_list); 1195518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1196518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_CONFIG, EGL_NO_SURFACE); 1197518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1198518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1199518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 1200518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// EGL_EGLEXT_VERSION 3 1201518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 1202518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1203518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglLockSurfaceKHR(EGLDisplay dpy, EGLSurface surface, 1204518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian const EGLint *attrib_list) 1205518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1206518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1207518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1208518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = validate_display(dpy); 1209518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1210518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1211f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian SurfaceRef _s(dp, surface); 12125b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 12135b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 1214518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1215518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * const s = get_surface(surface); 1216518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (s->cnx->egl.eglLockSurfaceKHR) { 1217518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return s->cnx->egl.eglLockSurfaceKHR( 1218518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian dp->disp[s->impl].dpy, s->surface, attrib_list); 1219518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1220518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_DISPLAY, EGL_FALSE); 1221518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1222518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1223518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglUnlockSurfaceKHR(EGLDisplay dpy, EGLSurface surface) 1224518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1225518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1226518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1227518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = validate_display(dpy); 1228518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1229518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1230f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian SurfaceRef _s(dp, surface); 12315b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 12325b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 1233518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1234518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * const s = get_surface(surface); 1235518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (s->cnx->egl.eglUnlockSurfaceKHR) { 1236518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return s->cnx->egl.eglUnlockSurfaceKHR( 1237518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian dp->disp[s->impl].dpy, s->surface); 1238518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1239518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_DISPLAY, EGL_FALSE); 1240518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1241518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1242518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, 1243518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLClientBuffer buffer, const EGLint *attrib_list) 1244518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1245518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1246518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1247518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = validate_display(dpy); 1248518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_NO_IMAGE_KHR; 1249518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1250518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (ctx != EGL_NO_CONTEXT) { 1251f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian ContextRef _c(dp, ctx); 12525b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_c.get()) 12535b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_CONTEXT, EGL_NO_IMAGE_KHR); 1254518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t * const c = get_context(ctx); 1255518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // since we have an EGLContext, we know which implementation to use 1256518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLImageKHR image = c->cnx->egl.eglCreateImageKHR( 1257518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian dp->disp[c->impl].dpy, c->context, target, buffer, attrib_list); 1258518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (image == EGL_NO_IMAGE_KHR) 1259518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return image; 1260518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1261518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_image_t* result = new egl_image_t(dpy, ctx); 1262518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian result->images[c->impl] = image; 1263518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return (EGLImageKHR)result; 1264518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } else { 1265518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // EGL_NO_CONTEXT is a valid parameter 1266518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1267518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian /* Since we don't have a way to know which implementation to call, 1268518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * we're calling all of them. If at least one of the implementation 1269518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * succeeded, this is a success. 1270518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian */ 1271518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1272518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint currentError = eglGetError(); 1273518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1274518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLImageKHR implImages[IMPL_NUM_IMPLEMENTATIONS]; 1275518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian bool success = false; 1276518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian for (int i=0 ; i<IMPL_NUM_IMPLEMENTATIONS ; i++) { 1277518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_connection_t* const cnx = &gEGLImpl[i]; 1278518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian implImages[i] = EGL_NO_IMAGE_KHR; 1279518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (cnx->dso) { 1280518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (cnx->egl.eglCreateImageKHR) { 1281518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian implImages[i] = cnx->egl.eglCreateImageKHR( 1282518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian dp->disp[i].dpy, ctx, target, buffer, attrib_list); 1283518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (implImages[i] != EGL_NO_IMAGE_KHR) { 1284518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian success = true; 1285518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1286518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1287518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1288518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1289518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1290518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!success) { 1291518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // failure, if there was an error when we entered this function, 1292518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // the error flag must not be updated. 1293518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // Otherwise, the error is whatever happened in the implementation 1294518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // that faulted. 1295518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (currentError != EGL_SUCCESS) { 1296518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian setError(currentError, EGL_NO_IMAGE_KHR); 1297518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1298518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_NO_IMAGE_KHR; 1299518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } else { 1300518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // In case of success, we need to clear all error flags 1301518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // (especially those caused by the implementation that didn't 1302518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // succeed). TODO: we could avoid this if we knew this was 1303518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // a "full" success (all implementation succeeded). 1304518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian eglGetError(); 1305518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1306518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1307518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_image_t* result = new egl_image_t(dpy, ctx); 1308518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian memcpy(result->images, implImages, sizeof(implImages)); 1309518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return (EGLImageKHR)result; 1310518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1311518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1312518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1313518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR img) 1314518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1315518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1316518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1317518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = validate_display(dpy); 1318518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1319518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1320f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian ImageRef _i(dp, img); 1321518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!_i.get()) return setError(EGL_BAD_PARAMETER, EGL_FALSE); 1322518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1323518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_image_t* image = get_image(img); 1324518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian bool success = false; 1325518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian for (int i=0 ; i<IMPL_NUM_IMPLEMENTATIONS ; i++) { 1326518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_connection_t* const cnx = &gEGLImpl[i]; 1327518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (image->images[i] != EGL_NO_IMAGE_KHR) { 1328518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (cnx->dso) { 1329518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (cnx->egl.eglDestroyImageKHR) { 1330518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (cnx->egl.eglDestroyImageKHR( 1331518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian dp->disp[i].dpy, image->images[i])) { 1332518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian success = true; 1333518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1334518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1335518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1336518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1337518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1338518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!success) 1339518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_FALSE; 1340518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1341518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian _i.terminate(); 1342518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1343518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_TRUE; 1344518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1345518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1346518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 1347518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// EGL_EGLEXT_VERSION 5 1348518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 1349518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1350518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1351518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLSyncKHR eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list) 1352518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1353518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1354518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1355518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = validate_display(dpy); 1356518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_NO_SYNC_KHR; 1357518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1358518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLContext ctx = eglGetCurrentContext(); 1359f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian ContextRef _c(dp, ctx); 13605b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_c.get()) 13615b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_CONTEXT, EGL_NO_SYNC_KHR); 13625b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian 1363518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t * const c = get_context(ctx); 1364518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLSyncKHR result = EGL_NO_SYNC_KHR; 1365518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (c->cnx->egl.eglCreateSyncKHR) { 1366518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLSyncKHR sync = c->cnx->egl.eglCreateSyncKHR( 1367518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian dp->disp[c->impl].dpy, type, attrib_list); 1368518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (sync == EGL_NO_SYNC_KHR) 1369518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return sync; 1370518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian result = (egl_sync_t*)new egl_sync_t(dpy, ctx, sync); 1371518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1372518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return (EGLSyncKHR)result; 1373518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1374518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1375518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync) 1376518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1377518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1378518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1379518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = validate_display(dpy); 1380518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1381518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1382f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian SyncRef _s(dp, sync); 1383518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!_s.get()) return setError(EGL_BAD_PARAMETER, EGL_FALSE); 1384518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_sync_t* syncObject = get_sync(sync); 1385518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1386518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLContext ctx = syncObject->context; 1387f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian ContextRef _c(dp, ctx); 13885b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_c.get()) 13895b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_CONTEXT, EGL_FALSE); 1390518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1391518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean result = EGL_FALSE; 1392518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t * const c = get_context(ctx); 1393518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (c->cnx->egl.eglDestroySyncKHR) { 1394518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian result = c->cnx->egl.eglDestroySyncKHR( 1395518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian dp->disp[c->impl].dpy, syncObject->sync); 1396518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (result) 1397518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian _s.terminate(); 1398518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1399518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return result; 1400518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1401518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1402518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLint eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout) 1403518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1404518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1405518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1406518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = validate_display(dpy); 1407518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1408518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1409f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian SyncRef _s(dp, sync); 1410518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!_s.get()) return setError(EGL_BAD_PARAMETER, EGL_FALSE); 1411518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_sync_t* syncObject = get_sync(sync); 1412518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1413518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLContext ctx = syncObject->context; 1414f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian ContextRef _c(dp, ctx); 14155b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_c.get()) 14165b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_CONTEXT, EGL_FALSE); 1417518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1418518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t * const c = get_context(ctx); 1419518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (c->cnx->egl.eglClientWaitSyncKHR) { 1420518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return c->cnx->egl.eglClientWaitSyncKHR( 1421518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian dp->disp[c->impl].dpy, syncObject->sync, flags, timeout); 1422518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1423518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1424518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_FALSE; 1425518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1426518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1427518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint *value) 1428518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1429518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1430518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1431518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = validate_display(dpy); 1432518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1433518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1434f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian SyncRef _s(dp, sync); 14355b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 14365b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_PARAMETER, EGL_FALSE); 1437518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 14385b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian egl_sync_t* syncObject = get_sync(sync); 1439518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLContext ctx = syncObject->context; 1440f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian ContextRef _c(dp, ctx); 14415b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_c.get()) 14425b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_CONTEXT, EGL_FALSE); 1443518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1444518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t * const c = get_context(ctx); 1445518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (c->cnx->egl.eglGetSyncAttribKHR) { 1446518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return c->cnx->egl.eglGetSyncAttribKHR( 1447518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian dp->disp[c->impl].dpy, syncObject->sync, attribute, value); 1448518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1449518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1450518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_FALSE; 1451518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1452518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1453518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 1454518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ANDROID extensions 1455518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 1456518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 14574b9511c16195a646242eff833b0af212933b6ecaMathias Agopian/* ANDROID extensions entry-point go here */ 14581c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 14591c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang// ---------------------------------------------------------------------------- 14601c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang// NVIDIA extensions 14611c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang// ---------------------------------------------------------------------------- 14621c3d72a2291827fb15e2ef311a571c860e0dba41Jonas YangEGLuint64NV eglGetSystemTimeFrequencyNV() 14631c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang{ 14641c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang clearError(); 14651c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 14661c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang if (egl_init_drivers() == EGL_FALSE) { 14671c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang return setError(EGL_BAD_PARAMETER, EGL_FALSE); 14681c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang } 14691c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 14701c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang EGLuint64NV ret = 0; 14711c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang egl_connection_t* const cnx = &gEGLImpl[IMPL_HARDWARE]; 14721c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 14731c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang if (cnx->dso) { 14741c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang if (cnx->egl.eglGetSystemTimeFrequencyNV) { 14751c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang return cnx->egl.eglGetSystemTimeFrequencyNV(); 14761c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang } 14771c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang } 14781c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 14790e8bbee5775d81c7bbc479b995496cac9238559fMathias Agopian return setErrorQuiet(EGL_BAD_DISPLAY, 0); 14801c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang} 14811c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 14821c3d72a2291827fb15e2ef311a571c860e0dba41Jonas YangEGLuint64NV eglGetSystemTimeNV() 14831c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang{ 14841c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang clearError(); 14851c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 14861c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang if (egl_init_drivers() == EGL_FALSE) { 14871c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang return setError(EGL_BAD_PARAMETER, EGL_FALSE); 14881c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang } 14891c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 14901c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang EGLuint64NV ret = 0; 14911c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang egl_connection_t* const cnx = &gEGLImpl[IMPL_HARDWARE]; 14921c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 14931c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang if (cnx->dso) { 14941c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang if (cnx->egl.eglGetSystemTimeNV) { 14951c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang return cnx->egl.eglGetSystemTimeNV(); 14961c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang } 14971c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang } 14981c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 14990e8bbee5775d81c7bbc479b995496cac9238559fMathias Agopian return setErrorQuiet(EGL_BAD_DISPLAY, 0); 15001c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang} 1501