eglApi.cpp revision 7773c435bc5da8217433e1b242d3a6712a17b5f7
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" 47ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian#include "egldefs.h" 48518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 49518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianusing namespace android; 50518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 51518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 52518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 53bc2d79ed7ada6243f3690f94ab512c0ddcdbed12Mathias Agopian#define EGL_VERSION_HW_ANDROID 0x3143 54bc2d79ed7ada6243f3690f94ab512c0ddcdbed12Mathias Agopian 55518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstruct extention_map_t { 56518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian const char* name; 57518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian __eglMustCastToProperFunctionPointerType address; 58518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}; 59518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 60518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic const extention_map_t sExtentionMap[] = { 61518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian { "eglLockSurfaceKHR", 62518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian (__eglMustCastToProperFunctionPointerType)&eglLockSurfaceKHR }, 63518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian { "eglUnlockSurfaceKHR", 64518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian (__eglMustCastToProperFunctionPointerType)&eglUnlockSurfaceKHR }, 65518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian { "eglCreateImageKHR", 66518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian (__eglMustCastToProperFunctionPointerType)&eglCreateImageKHR }, 67518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian { "eglDestroyImageKHR", 68518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian (__eglMustCastToProperFunctionPointerType)&eglDestroyImageKHR }, 691c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang { "eglGetSystemTimeFrequencyNV", 701c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang (__eglMustCastToProperFunctionPointerType)&eglGetSystemTimeFrequencyNV }, 711c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang { "eglGetSystemTimeNV", 721c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang (__eglMustCastToProperFunctionPointerType)&eglGetSystemTimeNV }, 73518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}; 74518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 75518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// accesses protected by sExtensionMapMutex 76518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic DefaultKeyedVector<String8, __eglMustCastToProperFunctionPointerType> sGLExtentionMap; 77518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic int sGLExtentionSlot = 0; 78518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic pthread_mutex_t sExtensionMapMutex = PTHREAD_MUTEX_INITIALIZER; 79518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 80518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic void(*findProcAddress(const char* name, 81518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian const extention_map_t* map, size_t n))() { 82518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian for (uint32_t i=0 ; i<n ; i++) { 83518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!strcmp(name, map[i].name)) { 84518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return map[i].address; 85518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 86518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 87518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return NULL; 88518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 89518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 90518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 91518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 92518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopiannamespace android { 93518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianextern void setGLHooksThreadSpecific(gl_hooks_t const *value); 94518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianextern EGLBoolean egl_init_drivers(); 95518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianextern const __eglMustCastToProperFunctionPointerType gExtensionForwarders[MAX_NUMBER_OF_GL_EXTENSIONS]; 96518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianextern int gEGLDebugLevel; 97518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianextern gl_hooks_t gHooksTrace; 98518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} // namespace android; 99518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 100518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 101518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 102518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic inline void clearError() { egl_tls_t::clearError(); } 103518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic inline EGLContext getContext() { return egl_tls_t::getContext(); } 104518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 105518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 106518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 107518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLDisplay eglGetDisplay(EGLNativeDisplayType display) 108518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 109518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 110518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 111518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian uint32_t index = uint32_t(display); 112518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (index >= NUM_DISPLAYS) { 113518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_PARAMETER, EGL_NO_DISPLAY); 114518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 115518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 116518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (egl_init_drivers() == EGL_FALSE) { 117518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_PARAMETER, EGL_NO_DISPLAY); 118518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 119518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 120518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLDisplay dpy = egl_display_t::getFromNativeDisplay(display); 121518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return dpy; 122518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 123518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 124518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 125518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// Initialization 126518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 127518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 128518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) 129518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 130518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 131518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 132518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t * const dp = get_display(dpy); 133518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE); 134518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 135518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean res = dp->initialize(major, minor); 136518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 137518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return res; 138518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 139518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 140518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglTerminate(EGLDisplay dpy) 141518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 142518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // NOTE: don't unload the drivers b/c some APIs can be called 143518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // after eglTerminate() has been called. eglTerminate() only 144518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // terminates an EGLDisplay, not a EGL itself. 145518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 146518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 147518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 148518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t* const dp = get_display(dpy); 149518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE); 150518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 151518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean res = dp->terminate(); 152518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 153518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return res; 154518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 155518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 156518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 157518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// configuration 158518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 159518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 160518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglGetConfigs( EGLDisplay dpy, 161518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLConfig *configs, 162518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint config_size, EGLint *num_config) 163518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 164518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 165518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 166518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = validate_display(dpy); 167518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 168518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1697773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian if (num_config==0) { 1707773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian return setError(EGL_BAD_PARAMETER, EGL_FALSE); 171518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 172518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1737773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian EGLBoolean res = EGL_FALSE; 1747773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian *num_config = 0; 1757773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian 1767773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian egl_connection_t* const cnx = &gEGLImpl; 1777773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian if (cnx->dso) { 1787773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian res = cnx->egl.eglGetConfigs( 1797773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian dp->disp.dpy, configs, config_size, num_config); 180518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1817773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian 1827773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian return res; 183518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 184518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 185518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglChooseConfig( EGLDisplay dpy, const EGLint *attrib_list, 186518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLConfig *configs, EGLint config_size, 187518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint *num_config) 188518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 189518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 190518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 191518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = validate_display(dpy); 192518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 193518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 194518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (num_config==0) { 195518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_PARAMETER, EGL_FALSE); 196518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 197518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 198518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean res = EGL_FALSE; 199518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian *num_config = 0; 200518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 201ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 202ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->dso) { 2037773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian res = cnx->egl.eglChooseConfig( 2047773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian dp->disp.dpy, attrib_list, configs, config_size, num_config); 205518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 206518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return res; 207518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 208518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 209518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, 210518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint attribute, EGLint *value) 211518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 212518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 213518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 214518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const* dp = 0; 215518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_connection_t* cnx = validate_display_config(dpy, config, dp); 216518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!cnx) return EGL_FALSE; 217518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 218518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return cnx->egl.eglGetConfigAttrib( 2197773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian dp->disp.dpy, config, attribute, value); 220518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 221518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 222518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 223518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// surfaces 224518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 225518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 226518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLSurface eglCreateWindowSurface( EGLDisplay dpy, EGLConfig config, 227518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian NativeWindowType window, 228518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian const EGLint *attrib_list) 229518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 230518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 231518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 232518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const* dp = 0; 233518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_connection_t* cnx = validate_display_config(dpy, config, dp); 234518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (cnx) { 235ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian EGLDisplay iDpy = dp->disp.dpy; 236518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint format; 237518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 23881a63350527cafce6929309533c58586878f10b5Mathias Agopian if (native_window_api_connect(window, NATIVE_WINDOW_API_EGL) != OK) { 239e6f43ddce78d6846af12550ff9193c5c6fe5844bSteve Block ALOGE("EGLNativeWindowType %p already connected to another API", 24081a63350527cafce6929309533c58586878f10b5Mathias Agopian window); 24181a63350527cafce6929309533c58586878f10b5Mathias Agopian return setError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE); 24281a63350527cafce6929309533c58586878f10b5Mathias Agopian } 24381a63350527cafce6929309533c58586878f10b5Mathias Agopian 244518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // set the native window's buffers format to match this config 245518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (cnx->egl.eglGetConfigAttrib(iDpy, 2467773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian config, EGL_NATIVE_VISUAL_ID, &format)) { 247518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (format != 0) { 248bee205fd58a27c10a0895de5339e76025d429d2bJamie Gennis int err = native_window_set_buffers_format(window, format); 249bee205fd58a27c10a0895de5339e76025d429d2bJamie Gennis if (err != 0) { 250e6f43ddce78d6846af12550ff9193c5c6fe5844bSteve Block ALOGE("error setting native window pixel format: %s (%d)", 251bee205fd58a27c10a0895de5339e76025d429d2bJamie Gennis strerror(-err), err); 25281a63350527cafce6929309533c58586878f10b5Mathias Agopian native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL); 253bee205fd58a27c10a0895de5339e76025d429d2bJamie Gennis return setError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE); 254bee205fd58a27c10a0895de5339e76025d429d2bJamie Gennis } 255518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 256518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 257518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 25859769469e4b9b2d8b12c020eb44b030b3927a50bJamie Gennis // the EGL spec requires that a new EGLSurface default to swap interval 25959769469e4b9b2d8b12c020eb44b030b3927a50bJamie Gennis // 1, so explicitly set that on the window here. 26059769469e4b9b2d8b12c020eb44b030b3927a50bJamie Gennis ANativeWindow* anw = reinterpret_cast<ANativeWindow*>(window); 26159769469e4b9b2d8b12c020eb44b030b3927a50bJamie Gennis anw->setSwapInterval(anw, 1); 26259769469e4b9b2d8b12c020eb44b030b3927a50bJamie Gennis 263518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLSurface surface = cnx->egl.eglCreateWindowSurface( 2647773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian iDpy, config, window, attrib_list); 265518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (surface != EGL_NO_SURFACE) { 266ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_surface_t* s = new egl_surface_t(dpy, config, window, surface, cnx); 267518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return s; 268518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 26981a63350527cafce6929309533c58586878f10b5Mathias Agopian 27081a63350527cafce6929309533c58586878f10b5Mathias Agopian // EGLSurface creation failed 27181a63350527cafce6929309533c58586878f10b5Mathias Agopian native_window_set_buffers_format(window, 0); 27281a63350527cafce6929309533c58586878f10b5Mathias Agopian native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL); 273518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 274518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_NO_SURFACE; 275518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 276518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 277518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLSurface eglCreatePixmapSurface( EGLDisplay dpy, EGLConfig config, 278518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian NativePixmapType pixmap, 279518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian const EGLint *attrib_list) 280518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 281518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 282518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 283518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const* dp = 0; 284518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_connection_t* cnx = validate_display_config(dpy, config, dp); 285518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (cnx) { 286518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLSurface surface = cnx->egl.eglCreatePixmapSurface( 2877773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian dp->disp.dpy, config, pixmap, attrib_list); 288518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (surface != EGL_NO_SURFACE) { 289ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_surface_t* s = new egl_surface_t(dpy, config, NULL, surface, cnx); 290518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return s; 291518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 292518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 293518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_NO_SURFACE; 294518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 295518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 296518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLSurface eglCreatePbufferSurface( EGLDisplay dpy, EGLConfig config, 297518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian const EGLint *attrib_list) 298518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 299518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 300518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 301518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const* dp = 0; 302518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_connection_t* cnx = validate_display_config(dpy, config, dp); 303518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (cnx) { 304518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLSurface surface = cnx->egl.eglCreatePbufferSurface( 3057773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian dp->disp.dpy, config, attrib_list); 306518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (surface != EGL_NO_SURFACE) { 307ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_surface_t* s = new egl_surface_t(dpy, config, NULL, surface, cnx); 308518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return s; 309518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 310518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 311518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_NO_SURFACE; 312518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 313518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 314518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface) 315518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 316518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 317518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 318518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = validate_display(dpy); 319518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 320518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 321f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian SurfaceRef _s(dp, surface); 3225b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 3235b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 324518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 325518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t * const s = get_surface(surface); 326ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian EGLBoolean result = s->cnx->egl.eglDestroySurface(dp->disp.dpy, s->surface); 327518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (result == EGL_TRUE) { 328518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian _s.terminate(); 329518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 330518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return result; 331518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 332518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 333518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglQuerySurface( EGLDisplay dpy, EGLSurface surface, 334518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint attribute, EGLint *value) 335518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 336518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 337518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 338518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = validate_display(dpy); 339518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 340518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 341f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian SurfaceRef _s(dp, surface); 3425b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 3435b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 344518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 345518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * const s = get_surface(surface); 3467773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian return s->cnx->egl.eglQuerySurface( 3477773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian dp->disp.dpy, s->surface, attribute, value); 348518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 349518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 350e8696a40e09b24b634214684d18526187b316a2fJamie Gennisvoid EGLAPI eglBeginFrame(EGLDisplay dpy, EGLSurface surface) { 351e8696a40e09b24b634214684d18526187b316a2fJamie Gennis clearError(); 352e8696a40e09b24b634214684d18526187b316a2fJamie Gennis 353e8696a40e09b24b634214684d18526187b316a2fJamie Gennis egl_display_t const * const dp = validate_display(dpy); 354e8696a40e09b24b634214684d18526187b316a2fJamie Gennis if (!dp) { 355e8696a40e09b24b634214684d18526187b316a2fJamie Gennis return; 356e8696a40e09b24b634214684d18526187b316a2fJamie Gennis } 357e8696a40e09b24b634214684d18526187b316a2fJamie Gennis 358e8696a40e09b24b634214684d18526187b316a2fJamie Gennis SurfaceRef _s(dp, surface); 359e8696a40e09b24b634214684d18526187b316a2fJamie Gennis if (!_s.get()) { 360e8696a40e09b24b634214684d18526187b316a2fJamie Gennis setError(EGL_BAD_SURFACE, EGL_FALSE); 361e8696a40e09b24b634214684d18526187b316a2fJamie Gennis return; 362e8696a40e09b24b634214684d18526187b316a2fJamie Gennis } 363e8696a40e09b24b634214684d18526187b316a2fJamie Gennis 364e8696a40e09b24b634214684d18526187b316a2fJamie Gennis int64_t timestamp = systemTime(SYSTEM_TIME_MONOTONIC); 365e8696a40e09b24b634214684d18526187b316a2fJamie Gennis 366e8696a40e09b24b634214684d18526187b316a2fJamie Gennis egl_surface_t const * const s = get_surface(surface); 367e8696a40e09b24b634214684d18526187b316a2fJamie Gennis native_window_set_buffers_timestamp(s->win.get(), timestamp); 368e8696a40e09b24b634214684d18526187b316a2fJamie Gennis} 369e8696a40e09b24b634214684d18526187b316a2fJamie Gennis 370518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 371518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// Contexts 372518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 373518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 374518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config, 375518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLContext share_list, const EGLint *attrib_list) 376518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 377518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 378518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 379518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const* dp = 0; 380518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_connection_t* cnx = validate_display_config(dpy, config, dp); 381518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (cnx) { 382518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (share_list != EGL_NO_CONTEXT) { 383518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t* const c = get_context(share_list); 384518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian share_list = c->context; 385518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 386518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLContext context = cnx->egl.eglCreateContext( 3877773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian dp->disp.dpy, config, share_list, attrib_list); 388518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (context != EGL_NO_CONTEXT) { 389518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // figure out if it's a GLESv1 or GLESv2 390518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian int version = 0; 391518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (attrib_list) { 392518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian while (*attrib_list != EGL_NONE) { 393518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian GLint attr = *attrib_list++; 394518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian GLint value = *attrib_list++; 395518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (attr == EGL_CONTEXT_CLIENT_VERSION) { 396518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (value == 1) { 3977773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian version = egl_connection_t::GLESv1_INDEX; 398518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } else if (value == 2) { 3997773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian version = egl_connection_t::GLESv2_INDEX; 400518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 401518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 402518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian }; 403518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 404ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_context_t* c = new egl_context_t(dpy, context, config, cnx, version); 4050469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#if EGL_TRACE 4060469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy if (gEGLDebugLevel > 0) 4070469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLTrace_eglCreateContext(version, c); 4080469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#endif 409518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return c; 410518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 411518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 412518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_NO_CONTEXT; 413518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 414518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 415518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx) 416518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 417518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 418518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 419518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = validate_display(dpy); 4205b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!dp) 4215b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return EGL_FALSE; 422518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 423f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian ContextRef _c(dp, ctx); 4245b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_c.get()) 4255b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_CONTEXT, EGL_FALSE); 426518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 427518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t * const c = get_context(ctx); 428ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian EGLBoolean result = c->cnx->egl.eglDestroyContext(dp->disp.dpy, c->context); 429518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (result == EGL_TRUE) { 430518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian _c.terminate(); 431518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 432518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return result; 433518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 434518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 435518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglMakeCurrent( EGLDisplay dpy, EGLSurface draw, 436518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLSurface read, EGLContext ctx) 437518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 438518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 439518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 440518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = get_display(dpy); 441518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE); 442518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 4435b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian // If ctx is not EGL_NO_CONTEXT, read is not EGL_NO_SURFACE, or draw is not 4445b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian // EGL_NO_SURFACE, then an EGL_NOT_INITIALIZED error is generated if dpy is 4455b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian // a valid but uninitialized display. 446518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if ( (ctx != EGL_NO_CONTEXT) || (read != EGL_NO_SURFACE) || 447518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian (draw != EGL_NO_SURFACE) ) { 448518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp->isReady()) return setError(EGL_NOT_INITIALIZED, EGL_FALSE); 449518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 450518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 451518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // get a reference to the object passed in 452f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian ContextRef _c(dp, ctx); 453f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian SurfaceRef _d(dp, draw); 454f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian SurfaceRef _r(dp, read); 455518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 456518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // validate the context (if not EGL_NO_CONTEXT) 4575b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if ((ctx != EGL_NO_CONTEXT) && !_c.get()) { 458518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // EGL_NO_CONTEXT is valid 459518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_FALSE; 460518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 461518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 462518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // these are the underlying implementation's object 463518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLContext impl_ctx = EGL_NO_CONTEXT; 464518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLSurface impl_draw = EGL_NO_SURFACE; 465518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLSurface impl_read = EGL_NO_SURFACE; 466518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 467518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // these are our objects structs passed in 468518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t * c = NULL; 469518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * d = NULL; 470518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * r = NULL; 471518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 472518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // these are the current objects structs 473518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t * cur_c = get_context(getContext()); 474518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 475518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (ctx != EGL_NO_CONTEXT) { 476518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian c = get_context(ctx); 477518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian impl_ctx = c->context; 478518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } else { 479518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // no context given, use the implementation of the current context 480518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (cur_c == NULL) { 481518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // no current context 482518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (draw != EGL_NO_SURFACE || read != EGL_NO_SURFACE) { 483518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // calling eglMakeCurrent( ..., !=0, !=0, EGL_NO_CONTEXT); 484518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_MATCH, EGL_FALSE); 485518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 486518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // not an error, there is just no current context. 487518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_TRUE; 488518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 489518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 490518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 491518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // retrieve the underlying implementation's draw EGLSurface 492518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (draw != EGL_NO_SURFACE) { 493518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian d = get_surface(draw); 494518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian impl_draw = d->surface; 495518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 496518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 497518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // retrieve the underlying implementation's read EGLSurface 498518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (read != EGL_NO_SURFACE) { 499518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian r = get_surface(read); 500518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian impl_read = r->surface; 501518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 502518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 503518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 504fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian EGLBoolean result = const_cast<egl_display_t*>(dp)->makeCurrent(c, cur_c, 505fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian draw, read, ctx, 506fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian impl_draw, impl_read, impl_ctx); 507518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 508518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (result == EGL_TRUE) { 509fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian if (c) { 510518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian setGLHooksThreadSpecific(c->cnx->hooks[c->version]); 511518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_tls_t::setContext(ctx); 5120469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#if EGL_TRACE 5130469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy if (gEGLDebugLevel > 0) 51493a826f78f6313db791e6fc880439189897651b3Siva Velusamy GLTrace_eglMakeCurrent(c->version, c->cnx->hooks[c->version], ctx); 5150469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#endif 516518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian _c.acquire(); 517518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian _r.acquire(); 518518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian _d.acquire(); 519518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } else { 520518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian setGLHooksThreadSpecific(&gHooksNoContext); 521518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_tls_t::setContext(EGL_NO_CONTEXT); 522518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 5235fecea776a5f093c21ac1a0ad3552b847d4be23eMathias Agopian } else { 524e6f43ddce78d6846af12550ff9193c5c6fe5844bSteve Block // this will ALOGE the error 5255fecea776a5f093c21ac1a0ad3552b847d4be23eMathias Agopian result = setError(c->cnx->egl.eglGetError(), EGL_FALSE); 526518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 527518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return result; 528518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 529518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 530518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 531518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglQueryContext( EGLDisplay dpy, EGLContext ctx, 532518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint attribute, EGLint *value) 533518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 534518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 535518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 536518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = validate_display(dpy); 537518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 538518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 539f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian ContextRef _c(dp, ctx); 540518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!_c.get()) return setError(EGL_BAD_CONTEXT, EGL_FALSE); 541518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 542518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t * const c = get_context(ctx); 5437773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian return c->cnx->egl.eglQueryContext( 5447773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian dp->disp.dpy, c->context, attribute, value); 545518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 546518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 547518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 548518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLContext eglGetCurrentContext(void) 549518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 550518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // could be called before eglInitialize(), but we wouldn't have a context 551518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // then, and this function would correctly return EGL_NO_CONTEXT. 552518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 553518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 554518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 555518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLContext ctx = getContext(); 556518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return ctx; 557518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 558518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 559518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLSurface eglGetCurrentSurface(EGLint readdraw) 560518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 561518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // could be called before eglInitialize(), but we wouldn't have a context 562518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // then, and this function would correctly return EGL_NO_SURFACE. 563518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 564518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 565518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 566518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLContext ctx = getContext(); 567518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (ctx) { 568518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t const * const c = get_context(ctx); 569518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!c) return setError(EGL_BAD_CONTEXT, EGL_NO_SURFACE); 570518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian switch (readdraw) { 571518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian case EGL_READ: return c->read; 572518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian case EGL_DRAW: return c->draw; 573518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian default: return setError(EGL_BAD_PARAMETER, EGL_NO_SURFACE); 574518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 575518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 576518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_NO_SURFACE; 577518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 578518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 579518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLDisplay eglGetCurrentDisplay(void) 580518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 581518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // could be called before eglInitialize(), but we wouldn't have a context 582518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // then, and this function would correctly return EGL_NO_DISPLAY. 583518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 584518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 585518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 586518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLContext ctx = getContext(); 587518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (ctx) { 588518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t const * const c = get_context(ctx); 589518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!c) return setError(EGL_BAD_CONTEXT, EGL_NO_SURFACE); 590518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return c->dpy; 591518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 592518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_NO_DISPLAY; 593518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 594518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 595518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglWaitGL(void) 596518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 597518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 598518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 599ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 600ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (!cnx->dso) 601ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return setError(EGL_BAD_CONTEXT, EGL_FALSE); 602ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian 603ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return cnx->egl.eglWaitGL(); 604518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 605518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 606518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglWaitNative(EGLint engine) 607518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 608518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 609518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 610ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 611ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (!cnx->dso) 612ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return setError(EGL_BAD_CONTEXT, EGL_FALSE); 613ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian 614ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return cnx->egl.eglWaitNative(engine); 615518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 616518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 617518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLint eglGetError(void) 618518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 619ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian EGLint err = EGL_SUCCESS; 620ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 621ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->dso) { 622ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian err = cnx->egl.eglGetError(); 623518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 624ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (err == EGL_SUCCESS) { 625ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian err = egl_tls_t::getError(); 626ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian } 627ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return err; 628518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 629518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 630518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// Note: Similar implementations of these functions also exist in 631518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// gl2.cpp and gl.cpp, and are used by applications that call the 632518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// exported entry points directly. 633518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopiantypedef void (GL_APIENTRYP PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) (GLenum target, GLeglImageOES image); 634518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopiantypedef void (GL_APIENTRYP PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC) (GLenum target, GLeglImageOES image); 635518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 636518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES_impl = NULL; 637518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC glEGLImageTargetRenderbufferStorageOES_impl = NULL; 638518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 639518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic void glEGLImageTargetTexture2DOES_wrapper(GLenum target, GLeglImageOES image) 640518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 641518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian GLeglImageOES implImage = 642518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian (GLeglImageOES)egl_get_image_for_current_context((EGLImageKHR)image); 643518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian glEGLImageTargetTexture2DOES_impl(target, implImage); 644518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 645518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 646518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianstatic void glEGLImageTargetRenderbufferStorageOES_wrapper(GLenum target, GLeglImageOES image) 647518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 648518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian GLeglImageOES implImage = 649518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian (GLeglImageOES)egl_get_image_for_current_context((EGLImageKHR)image); 650518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian glEGLImageTargetRenderbufferStorageOES_impl(target, implImage); 651518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 652518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 653518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian__eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname) 654518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 655518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // eglGetProcAddress() could be the very first function called 656518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // in which case we must make sure we've initialized ourselves, this 657518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // happens the first time egl_get_display() is called. 658518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 659518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 660518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 661518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (egl_init_drivers() == EGL_FALSE) { 662518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian setError(EGL_BAD_PARAMETER, NULL); 663518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return NULL; 664518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 665518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 666aca51c06f38155f1435fbc6944d7fc0a9bf1e4e9Jamie Gennis // The EGL_ANDROID_blob_cache extension should not be exposed to 667aca51c06f38155f1435fbc6944d7fc0a9bf1e4e9Jamie Gennis // applications. It is used internally by the Android EGL layer. 668c42fcf05ce253d5342993b28c412be16e61efffbJamie Gennis if (!strcmp(procname, "eglSetBlobCacheFuncsANDROID")) { 669aca51c06f38155f1435fbc6944d7fc0a9bf1e4e9Jamie Gennis return NULL; 670aca51c06f38155f1435fbc6944d7fc0a9bf1e4e9Jamie Gennis } 671aca51c06f38155f1435fbc6944d7fc0a9bf1e4e9Jamie Gennis 672518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian __eglMustCastToProperFunctionPointerType addr; 673518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian addr = findProcAddress(procname, sExtentionMap, NELEM(sExtentionMap)); 674518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (addr) return addr; 675518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 676aca51c06f38155f1435fbc6944d7fc0a9bf1e4e9Jamie Gennis 677518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // this protects accesses to sGLExtentionMap and sGLExtentionSlot 678518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian pthread_mutex_lock(&sExtensionMapMutex); 679518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 680518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian /* 681518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * Since eglGetProcAddress() is not associated to anything, it needs 682518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * to return a function pointer that "works" regardless of what 683518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * the current context is. 684518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * 685518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * For this reason, we return a "forwarder", a small stub that takes 686518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * care of calling the function associated with the context 687518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * currently bound. 688518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * 689518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * We first look for extensions we've already resolved, if we're seeing 690518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * this extension for the first time, we go through all our 691518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * implementations and call eglGetProcAddress() and record the 692518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * result in the appropriate implementation hooks and return the 693518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * address of the forwarder corresponding to that hook set. 694518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * 695518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian */ 696518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 697518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian const String8 name(procname); 698518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian addr = sGLExtentionMap.valueFor(name); 699518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian const int slot = sGLExtentionSlot; 700518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 701e6f43ddce78d6846af12550ff9193c5c6fe5844bSteve Block ALOGE_IF(slot >= MAX_NUMBER_OF_GL_EXTENSIONS, 702518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian "no more slots for eglGetProcAddress(\"%s\")", 703518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian procname); 704518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 7050469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#if EGL_TRACE 7060469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy gl_hooks_t *debugHooks = GLTrace_getGLHooks(); 7070469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#endif 7080469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 709518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!addr && (slot < MAX_NUMBER_OF_GL_EXTENSIONS)) { 710518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian bool found = false; 711ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian 712ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 713ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->dso && cnx->egl.eglGetProcAddress) { 714ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian found = true; 715ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian // Extensions are independent of the bound context 7167773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian cnx->hooks[egl_connection_t::GLESv1_INDEX]->ext.extensions[slot] = 7177773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian cnx->hooks[egl_connection_t::GLESv2_INDEX]->ext.extensions[slot] = 718518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#if EGL_TRACE 719ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian debugHooks->ext.extensions[slot] = 720ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian gHooksTrace.ext.extensions[slot] = 721518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#endif 722ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian cnx->egl.eglGetProcAddress(procname); 723518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 724ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian 725518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (found) { 726518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian addr = gExtensionForwarders[slot]; 727518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 728518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!strcmp(procname, "glEGLImageTargetTexture2DOES")) { 729518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian glEGLImageTargetTexture2DOES_impl = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)addr; 730518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian addr = (__eglMustCastToProperFunctionPointerType)glEGLImageTargetTexture2DOES_wrapper; 731518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 732518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!strcmp(procname, "glEGLImageTargetRenderbufferStorageOES")) { 733518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian glEGLImageTargetRenderbufferStorageOES_impl = (PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC)addr; 734518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian addr = (__eglMustCastToProperFunctionPointerType)glEGLImageTargetRenderbufferStorageOES_wrapper; 735518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 736518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 737518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian sGLExtentionMap.add(name, addr); 738518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian sGLExtentionSlot++; 739518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 740518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 741518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 742518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian pthread_mutex_unlock(&sExtensionMapMutex); 743518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return addr; 744518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 745518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 746518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface draw) 747518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 748518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 749518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 750518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = validate_display(dpy); 751518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 752518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 753f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian SurfaceRef _s(dp, draw); 7545b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 7555b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 756518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 7570469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#if EGL_TRACE 7580469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy if (gEGLDebugLevel > 0) 7590469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLTrace_eglSwapBuffers(dpy, draw); 7600469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#endif 7610469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 762518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * const s = get_surface(draw); 763ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return s->cnx->egl.eglSwapBuffers(dp->disp.dpy, s->surface); 764518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 765518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 766518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglCopyBuffers( EGLDisplay dpy, EGLSurface surface, 767518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian NativePixmapType target) 768518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 769518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 770518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 771518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = validate_display(dpy); 772518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 773518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 774f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian SurfaceRef _s(dp, surface); 7755b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 7765b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 777518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 778518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * const s = get_surface(surface); 779ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return s->cnx->egl.eglCopyBuffers(dp->disp.dpy, s->surface, target); 780518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 781518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 782518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianconst char* eglQueryString(EGLDisplay dpy, EGLint name) 783518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 784518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 785518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 786518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = validate_display(dpy); 787518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return (const char *) NULL; 788518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 789518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian switch (name) { 790518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian case EGL_VENDOR: 7914b9511c16195a646242eff833b0af212933b6ecaMathias Agopian return dp->getVendorString(); 792518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian case EGL_VERSION: 7934b9511c16195a646242eff833b0af212933b6ecaMathias Agopian return dp->getVersionString(); 794518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian case EGL_EXTENSIONS: 7954b9511c16195a646242eff833b0af212933b6ecaMathias Agopian return dp->getExtensionString(); 796518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian case EGL_CLIENT_APIS: 7974b9511c16195a646242eff833b0af212933b6ecaMathias Agopian return dp->getClientApiString(); 798ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian case EGL_VERSION_HW_ANDROID: 799ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return dp->disp.queryString.version; 800518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 801518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_PARAMETER, (const char *)0); 802518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 803518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 804518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 805518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 806518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// EGL 1.1 807518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 808518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 809518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglSurfaceAttrib( 810518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value) 811518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 812518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 813518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 814518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = validate_display(dpy); 815518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 816518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 817f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian SurfaceRef _s(dp, surface); 8185b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 8195b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 820518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 821518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * const s = get_surface(surface); 822518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (s->cnx->egl.eglSurfaceAttrib) { 823518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return s->cnx->egl.eglSurfaceAttrib( 824ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian dp->disp.dpy, s->surface, attribute, value); 825518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 826518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 827518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 828518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 829518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglBindTexImage( 830518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLDisplay dpy, EGLSurface surface, EGLint buffer) 831518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 832518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 833518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 834518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = validate_display(dpy); 835518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 836518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 837f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian SurfaceRef _s(dp, surface); 8385b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 8395b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 840518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 841518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * const s = get_surface(surface); 842518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (s->cnx->egl.eglBindTexImage) { 843518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return s->cnx->egl.eglBindTexImage( 844ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian dp->disp.dpy, s->surface, buffer); 845518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 846518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 847518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 848518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 849518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglReleaseTexImage( 850518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLDisplay dpy, EGLSurface surface, EGLint buffer) 851518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 852518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 853518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 854518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = validate_display(dpy); 855518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 856518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 857f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian SurfaceRef _s(dp, surface); 8585b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 8595b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 860518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 861518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * const s = get_surface(surface); 862518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (s->cnx->egl.eglReleaseTexImage) { 863518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return s->cnx->egl.eglReleaseTexImage( 864ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian dp->disp.dpy, s->surface, buffer); 865518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 866518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 867518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 868518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 869518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint interval) 870518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 871518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 872518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 873518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = validate_display(dpy); 874518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 875518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 876518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean res = EGL_TRUE; 877ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 878ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->dso && cnx->egl.eglSwapInterval) { 879ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian res = cnx->egl.eglSwapInterval(dp->disp.dpy, interval); 880518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 881ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian 882518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return res; 883518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 884518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 885518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 886518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 887518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// EGL 1.2 888518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 889518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 890518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglWaitClient(void) 891518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 892518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 893518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 894ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 895ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (!cnx->dso) 896ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return setError(EGL_BAD_CONTEXT, EGL_FALSE); 897ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian 898ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian EGLBoolean res; 899ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->egl.eglWaitClient) { 900ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian res = cnx->egl.eglWaitClient(); 901ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian } else { 902ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian res = cnx->egl.eglWaitGL(); 903518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 904518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return res; 905518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 906518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 907518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglBindAPI(EGLenum api) 908518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 909518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 910518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 911518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (egl_init_drivers() == EGL_FALSE) { 912518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_PARAMETER, EGL_FALSE); 913518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 914518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 915518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // bind this API on all EGLs 916518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean res = EGL_TRUE; 917ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 918ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->dso && cnx->egl.eglBindAPI) { 919ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian res = cnx->egl.eglBindAPI(api); 920518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 921518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return res; 922518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 923518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 924518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLenum eglQueryAPI(void) 925518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 926518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 927518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 928518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (egl_init_drivers() == EGL_FALSE) { 929518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_PARAMETER, EGL_FALSE); 930518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 931518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 932ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 933ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->dso && cnx->egl.eglQueryAPI) { 934ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return cnx->egl.eglQueryAPI(); 935518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 936ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian 937518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // or, it can only be OpenGL ES 938518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_OPENGL_ES_API; 939518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 940518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 941518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglReleaseThread(void) 942518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 943518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 944518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 945518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // If there is context bound to the thread, release it 946fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian egl_display_t::loseCurrent(get_context(getContext())); 947518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 948ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 949ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->dso && cnx->egl.eglReleaseThread) { 950ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian cnx->egl.eglReleaseThread(); 951518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 952ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian 953518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_tls_t::clearTLS(); 9540469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#if EGL_TRACE 9550469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy if (gEGLDebugLevel > 0) 9560469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLTrace_eglReleaseThread(); 9570469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#endif 958518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_TRUE; 959518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 960518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 961518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLSurface eglCreatePbufferFromClientBuffer( 962518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, 963518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLConfig config, const EGLint *attrib_list) 964518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 965518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 966518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 967518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const* dp = 0; 968518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_connection_t* cnx = validate_display_config(dpy, config, dp); 969518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!cnx) return EGL_FALSE; 970518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (cnx->egl.eglCreatePbufferFromClientBuffer) { 971518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return cnx->egl.eglCreatePbufferFromClientBuffer( 9727773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian dp->disp.dpy, buftype, buffer, config, attrib_list); 973518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 974518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_CONFIG, EGL_NO_SURFACE); 975518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 976518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 977518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 978518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// EGL_EGLEXT_VERSION 3 979518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 980518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 981518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglLockSurfaceKHR(EGLDisplay dpy, EGLSurface surface, 982518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian const EGLint *attrib_list) 983518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 984518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 985518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 986518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = validate_display(dpy); 987518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 988518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 989f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian SurfaceRef _s(dp, surface); 9905b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 9915b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 992518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 993518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * const s = get_surface(surface); 994518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (s->cnx->egl.eglLockSurfaceKHR) { 995518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return s->cnx->egl.eglLockSurfaceKHR( 996ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian dp->disp.dpy, s->surface, attrib_list); 997518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 998518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_DISPLAY, EGL_FALSE); 999518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1000518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1001518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglUnlockSurfaceKHR(EGLDisplay dpy, EGLSurface surface) 1002518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1003518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1004518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1005518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = validate_display(dpy); 1006518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1007518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1008f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian SurfaceRef _s(dp, surface); 10095b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 10105b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_SURFACE, EGL_FALSE); 1011518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1012518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_surface_t const * const s = get_surface(surface); 1013518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (s->cnx->egl.eglUnlockSurfaceKHR) { 1014ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return s->cnx->egl.eglUnlockSurfaceKHR(dp->disp.dpy, s->surface); 1015518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1016518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return setError(EGL_BAD_DISPLAY, EGL_FALSE); 1017518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1018518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1019518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, 1020518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLClientBuffer buffer, const EGLint *attrib_list) 1021518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1022518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1023518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1024518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = validate_display(dpy); 1025518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_NO_IMAGE_KHR; 1026518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1027518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (ctx != EGL_NO_CONTEXT) { 1028f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian ContextRef _c(dp, ctx); 10295b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_c.get()) 10305b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_CONTEXT, EGL_NO_IMAGE_KHR); 1031518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t * const c = get_context(ctx); 1032518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // since we have an EGLContext, we know which implementation to use 1033518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLImageKHR image = c->cnx->egl.eglCreateImageKHR( 1034ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian dp->disp.dpy, c->context, target, buffer, attrib_list); 1035518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (image == EGL_NO_IMAGE_KHR) 1036518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return image; 1037518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1038518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_image_t* result = new egl_image_t(dpy, ctx); 1039ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian result->image = image; 1040518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return (EGLImageKHR)result; 1041518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } else { 1042518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // EGL_NO_CONTEXT is a valid parameter 1043518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1044518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian /* Since we don't have a way to know which implementation to call, 1045518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * we're calling all of them. If at least one of the implementation 1046518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * succeeded, this is a success. 1047518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian */ 1048518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1049518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLint currentError = eglGetError(); 1050518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1051ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian EGLImageKHR implImage = EGL_NO_IMAGE_KHR; 1052ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 1053ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->dso && cnx->egl.eglCreateImageKHR) { 1054ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian implImage = cnx->egl.eglCreateImageKHR( 1055ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian dp->disp.dpy, ctx, target, buffer, attrib_list); 1056518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1057518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1058ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (implImage == EGL_NO_IMAGE_KHR) { 1059518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // failure, if there was an error when we entered this function, 1060518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // the error flag must not be updated. 1061518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // Otherwise, the error is whatever happened in the implementation 1062518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // that faulted. 1063518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (currentError != EGL_SUCCESS) { 1064518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian setError(currentError, EGL_NO_IMAGE_KHR); 1065518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1066518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_NO_IMAGE_KHR; 1067518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } else { 1068518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // In case of success, we need to clear all error flags 1069518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // (especially those caused by the implementation that didn't 1070ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian // succeed). 1071518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian eglGetError(); 1072518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1073518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1074518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_image_t* result = new egl_image_t(dpy, ctx); 1075ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian result->image = implImage; 1076518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return (EGLImageKHR)result; 1077518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1078518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1079518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1080518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR img) 1081518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1082518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1083518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1084518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = validate_display(dpy); 1085518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1086518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1087f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian ImageRef _i(dp, img); 1088518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!_i.get()) return setError(EGL_BAD_PARAMETER, EGL_FALSE); 1089518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1090518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_image_t* image = get_image(img); 1091518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian bool success = false; 1092ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian 1093ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 1094ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (image->image != EGL_NO_IMAGE_KHR) { 1095ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->dso && cnx->egl.eglDestroyImageKHR) { 1096ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->egl.eglDestroyImageKHR( 1097ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian dp->disp.dpy, image->image)) { 1098ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian success = true; 1099518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1100518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1101518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1102ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian 1103518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!success) 1104518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_FALSE; 1105518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1106518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian _i.terminate(); 1107518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1108518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_TRUE; 1109518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1110518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1111518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 1112518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// EGL_EGLEXT_VERSION 5 1113518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 1114518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1115518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1116518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLSyncKHR eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list) 1117518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1118518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1119518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1120518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = validate_display(dpy); 1121518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_NO_SYNC_KHR; 1122518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1123518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLContext ctx = eglGetCurrentContext(); 1124f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian ContextRef _c(dp, ctx); 11255b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_c.get()) 11265b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_CONTEXT, EGL_NO_SYNC_KHR); 11275b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian 1128518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t * const c = get_context(ctx); 1129518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLSyncKHR result = EGL_NO_SYNC_KHR; 1130518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (c->cnx->egl.eglCreateSyncKHR) { 1131518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLSyncKHR sync = c->cnx->egl.eglCreateSyncKHR( 1132ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian dp->disp.dpy, type, attrib_list); 1133518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (sync == EGL_NO_SYNC_KHR) 1134518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return sync; 1135518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian result = (egl_sync_t*)new egl_sync_t(dpy, ctx, sync); 1136518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1137518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return (EGLSyncKHR)result; 1138518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1139518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1140518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync) 1141518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1142518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1143518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1144518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = validate_display(dpy); 1145518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1146518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1147f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian SyncRef _s(dp, sync); 1148518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!_s.get()) return setError(EGL_BAD_PARAMETER, EGL_FALSE); 1149518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_sync_t* syncObject = get_sync(sync); 1150518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1151518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLContext ctx = syncObject->context; 1152f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian ContextRef _c(dp, ctx); 11535b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_c.get()) 11545b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_CONTEXT, EGL_FALSE); 1155518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1156518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean result = EGL_FALSE; 1157518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t * const c = get_context(ctx); 1158518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (c->cnx->egl.eglDestroySyncKHR) { 1159518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian result = c->cnx->egl.eglDestroySyncKHR( 1160ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian dp->disp.dpy, syncObject->sync); 1161518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (result) 1162518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian _s.terminate(); 1163518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1164518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return result; 1165518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1166518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1167518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLint eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout) 1168518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1169518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1170518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1171518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = validate_display(dpy); 1172518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1173518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1174f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian SyncRef _s(dp, sync); 1175518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!_s.get()) return setError(EGL_BAD_PARAMETER, EGL_FALSE); 1176518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_sync_t* syncObject = get_sync(sync); 1177518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1178518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLContext ctx = syncObject->context; 1179f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian ContextRef _c(dp, ctx); 11805b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_c.get()) 11815b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_CONTEXT, EGL_FALSE); 1182518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1183518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t * const c = get_context(ctx); 1184518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (c->cnx->egl.eglClientWaitSyncKHR) { 1185518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return c->cnx->egl.eglClientWaitSyncKHR( 1186ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian dp->disp.dpy, syncObject->sync, flags, timeout); 1187518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1188518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1189518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_FALSE; 1190518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1191518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1192518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint *value) 1193518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian{ 1194518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian clearError(); 1195518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1196518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_display_t const * const dp = validate_display(dpy); 1197518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (!dp) return EGL_FALSE; 1198518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1199f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian SyncRef _s(dp, sync); 12005b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_s.get()) 12015b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_PARAMETER, EGL_FALSE); 1202518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 12035b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian egl_sync_t* syncObject = get_sync(sync); 1204518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLContext ctx = syncObject->context; 1205f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian ContextRef _c(dp, ctx); 12065b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (!_c.get()) 12075b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian return setError(EGL_BAD_CONTEXT, EGL_FALSE); 1208518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1209518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_context_t * const c = get_context(ctx); 1210518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (c->cnx->egl.eglGetSyncAttribKHR) { 1211518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return c->cnx->egl.eglGetSyncAttribKHR( 1212ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian dp->disp.dpy, syncObject->sync, attribute, value); 1213518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 1214518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1215518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_FALSE; 1216518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 1217518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 1218518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 1219518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ANDROID extensions 1220518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 1221518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 12224b9511c16195a646242eff833b0af212933b6ecaMathias Agopian/* ANDROID extensions entry-point go here */ 12231c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 12241c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang// ---------------------------------------------------------------------------- 12251c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang// NVIDIA extensions 12261c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang// ---------------------------------------------------------------------------- 12271c3d72a2291827fb15e2ef311a571c860e0dba41Jonas YangEGLuint64NV eglGetSystemTimeFrequencyNV() 12281c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang{ 12291c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang clearError(); 12301c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 12311c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang if (egl_init_drivers() == EGL_FALSE) { 12321c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang return setError(EGL_BAD_PARAMETER, EGL_FALSE); 12331c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang } 12341c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 12351c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang EGLuint64NV ret = 0; 1236ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 12371c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 1238ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->dso && cnx->egl.eglGetSystemTimeFrequencyNV) { 1239ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return cnx->egl.eglGetSystemTimeFrequencyNV(); 12401c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang } 12411c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 12420e8bbee5775d81c7bbc479b995496cac9238559fMathias Agopian return setErrorQuiet(EGL_BAD_DISPLAY, 0); 12431c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang} 12441c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 12451c3d72a2291827fb15e2ef311a571c860e0dba41Jonas YangEGLuint64NV eglGetSystemTimeNV() 12461c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang{ 12471c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang clearError(); 12481c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 12491c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang if (egl_init_drivers() == EGL_FALSE) { 12501c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang return setError(EGL_BAD_PARAMETER, EGL_FALSE); 12511c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang } 12521c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 12531c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang EGLuint64NV ret = 0; 1254ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 12551c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 1256ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->dso && cnx->egl.eglGetSystemTimeNV) { 1257ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian return cnx->egl.eglGetSystemTimeNV(); 12581c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang } 12591c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang 12600e8bbee5775d81c7bbc479b995496cac9238559fMathias Agopian return setErrorQuiet(EGL_BAD_DISPLAY, 0); 12611c3d72a2291827fb15e2ef311a571c860e0dba41Jonas Yang} 1262