diff options
Diffstat (limited to 'opengl/libs/EGL')
-rw-r--r-- | opengl/libs/EGL/Loader.cpp | 276 | ||||
-rw-r--r-- | opengl/libs/EGL/Loader.h | 90 | ||||
-rw-r--r-- | opengl/libs/EGL/egl.cpp | 397 | ||||
-rw-r--r-- | opengl/libs/EGL/egl_entries.in | 57 | ||||
-rw-r--r-- | opengl/libs/EGL/gpu.cpp | 217 | ||||
-rw-r--r-- | opengl/libs/EGL/hooks.cpp | 67 |
6 files changed, 724 insertions, 380 deletions
diff --git a/opengl/libs/EGL/Loader.cpp b/opengl/libs/EGL/Loader.cpp new file mode 100644 index 0000000..7f3f114 --- /dev/null +++ b/opengl/libs/EGL/Loader.cpp @@ -0,0 +1,276 @@ +/* + ** Copyright 2007, The Android Open Source Project + ** + ** Licensed under the Apache License, Version 2.0 (the "License"); + ** you may not use this file except in compliance with the License. + ** You may obtain a copy of the License at + ** + ** http://www.apache.org/licenses/LICENSE-2.0 + ** + ** Unless required by applicable law or agreed to in writing, software + ** distributed under the License is distributed on an "AS IS" BASIS, + ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ** See the License for the specific language governing permissions and + ** limitations under the License. + */ + +#include <ctype.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <errno.h> +#include <dlfcn.h> +#include <limits.h> + +#include <cutils/log.h> + +#include <EGL/egl.h> + +#include "hooks.h" +#include "egl_impl.h" + +#include "Loader.h" + +// ---------------------------------------------------------------------------- +namespace android { +// ---------------------------------------------------------------------------- + + +/* + * EGL drivers are called + * + * /system/lib/egl/lib{[EGL|GLESv1_CM|GLESv2] | GLES}_$TAG.so + * + */ + +ANDROID_SINGLETON_STATIC_INSTANCE( Loader ) + +// ---------------------------------------------------------------------------- + +Loader::driver_t::driver_t(void* gles) +{ + dso[0] = gles; + for (size_t i=1 ; i<NELEM(dso) ; i++) + dso[i] = 0; +} + +Loader::driver_t::~driver_t() +{ + for (size_t i=0 ; i<NELEM(dso) ; i++) { + if (dso[i]) { + dlclose(dso[i]); + dso[i] = 0; + } + } +} + +status_t Loader::driver_t::set(void* hnd, int32_t api) +{ + switch (api) { + case EGL: + dso[0] = hnd; + break; + case GLESv1_CM: + dso[1] = hnd; + break; + case GLESv2: + dso[2] = hnd; + break; + default: + return BAD_INDEX; + } + return NO_ERROR; +} + +// ---------------------------------------------------------------------------- + +Loader::entry_t::entry_t(int dpy, int impl, const char* tag) + : dpy(dpy), impl(impl), tag(tag) { +} + +// ---------------------------------------------------------------------------- + +Loader::Loader() +{ + char line[256]; + char tag[256]; + FILE* cfg = fopen("/system/lib/egl/egl.cfg", "r"); + if (cfg == NULL) { + // default config + LOGD("egl.cfg not found, using default config"); + gConfig.add( entry_t(0, 0, "android") ); + } else { + while (fgets(line, 256, cfg)) { + int dpy; + int impl; + if (sscanf(line, "%u %u %s", &dpy, &impl, tag) == 3) { + //LOGD(">>> %u %u %s", dpy, impl, tag); + gConfig.add( entry_t(dpy, impl, tag) ); + } + } + fclose(cfg); + } +} + +Loader::~Loader() +{ +} + +const char* Loader::getTag(int dpy, int impl) +{ + const Vector<entry_t>& cfgs(gConfig); + const size_t c = cfgs.size(); + for (size_t i=0 ; i<c ; i++) { + if (dpy == cfgs[i].dpy) + if (impl == cfgs[i].impl) + return cfgs[i].tag.string(); + } + return 0; +} + +void* Loader::open(EGLNativeDisplayType display, int impl, gl_hooks_t* hooks) +{ + /* + * TODO: if we don't find display/0, then use 0/0 + * (0/0 should always work) + */ + + void* dso; + char path[PATH_MAX]; + int index = int(display); + driver_t* hnd = 0; + const char* const format = "/system/lib/egl/lib%s_%s.so"; + + char const* tag = getTag(index, impl); + if (tag) { + snprintf(path, PATH_MAX, format, "GLES", tag); + dso = load_driver(path, hooks, EGL | GLESv1_CM | GLESv2); + if (dso) { + hnd = new driver_t(dso); + } else { + // Always load EGL first + snprintf(path, PATH_MAX, "lib%s_%s.so", "EGL", tag); + dso = load_driver(path, hooks, EGL); + if (dso) { + hnd = new driver_t(dso); + + // TODO: make this more automated + snprintf(path, PATH_MAX, format, "GLESv1_CM", tag); + hnd->set( load_driver(path, hooks, GLESv1_CM), GLESv1_CM ); + + snprintf(path, PATH_MAX, format, "GLESv2", tag); + hnd->set( load_driver(path, hooks, GLESv2), GLESv2 ); + } + } + } + + LOG_FATAL_IF(!index && !impl && !hnd, + "couldn't find the default OpenGL ES implementation " + "for default display"); + + return (void*)hnd; +} + +status_t Loader::close(void* driver) +{ + driver_t* hnd = (driver_t*)driver; + delete hnd; + return NO_ERROR; +} + +void Loader::init_api(void* dso, + char const * const * api, + __eglMustCastToProperFunctionPointerType* curr, + getProcAddressType getProcAddress) +{ + char scrap[256]; + while (*api) { + char const * name = *api; + __eglMustCastToProperFunctionPointerType f = + (__eglMustCastToProperFunctionPointerType)dlsym(dso, name); + if (f == NULL) { + // couldn't find the entry-point, use eglGetProcAddress() + f = getProcAddress(name); + } + if (f == NULL) { + // Try without the OES postfix + ssize_t index = ssize_t(strlen(name)) - 3; + if ((index>0 && (index<255)) && (!strcmp(name+index, "OES"))) { + strncpy(scrap, name, index); + scrap[index] = 0; + f = (__eglMustCastToProperFunctionPointerType)dlsym(dso, scrap); + //LOGD_IF(f, "found <%s> instead", scrap); + } + } + if (f == NULL) { + // Try with the OES postfix + ssize_t index = ssize_t(strlen(name)) - 3; + if ((index>0 && (index<252)) && (strcmp(name+index, "OES"))) { + strncpy(scrap, name, index); + scrap[index] = 0; + strcat(scrap, "OES"); + f = (__eglMustCastToProperFunctionPointerType)dlsym(dso, scrap); + //LOGD_IF(f, "found <%s> instead", scrap); + } + } + if (f == NULL) { + //LOGD("%s", name); + f = (__eglMustCastToProperFunctionPointerType)gl_unimplemented; + } + *curr++ = f; + api++; + } +} + +void *Loader::load_driver(const char* driver, gl_hooks_t* hooks, uint32_t mask) +{ + //LOGD("%s", driver); + void* dso = dlopen(driver, RTLD_NOW | RTLD_LOCAL); + LOGE_IF(!dso, "%s", dlerror()); + if (dso == 0) + return 0; + + if (mask & EGL) { + getProcAddress = (getProcAddressType)dlsym(dso, "eglGetProcAddress"); + + LOGE_IF(!getProcAddress, + "can't find eglGetProcAddress() in %s", driver); + + gl_hooks_t::egl_t* egl = &hooks->egl; + __eglMustCastToProperFunctionPointerType* curr = + (__eglMustCastToProperFunctionPointerType*)egl; + char const * const * api = egl_names; + while (*api) { + char const * name = *api; + __eglMustCastToProperFunctionPointerType f = + (__eglMustCastToProperFunctionPointerType)dlsym(dso, name); + if (f == NULL) { + // couldn't find the entry-point, use eglGetProcAddress() + f = getProcAddress(name); + if (f == NULL) { + f = (__eglMustCastToProperFunctionPointerType)0; + } + } + *curr++ = f; + api++; + } + } + + if (mask & GLESv1_CM) { + init_api(dso, gl_names, + (__eglMustCastToProperFunctionPointerType*)&hooks->gl, + getProcAddress); + } + + if (mask & GLESv2) { + init_api(dso, gl2_names, + (__eglMustCastToProperFunctionPointerType*)&hooks->gl2, + getProcAddress); + } + + return dso; +} + +// ---------------------------------------------------------------------------- +}; // namespace android +// ---------------------------------------------------------------------------- diff --git a/opengl/libs/EGL/Loader.h b/opengl/libs/EGL/Loader.h new file mode 100644 index 0000000..69f6dd5 --- /dev/null +++ b/opengl/libs/EGL/Loader.h @@ -0,0 +1,90 @@ +/* + ** Copyright 2009, The Android Open Source Project + ** + ** Licensed under the Apache License, Version 2.0 (the "License"); + ** you may not use this file except in compliance with the License. + ** You may obtain a copy of the License at + ** + ** http://www.apache.org/licenses/LICENSE-2.0 + ** + ** Unless required by applicable law or agreed to in writing, software + ** distributed under the License is distributed on an "AS IS" BASIS, + ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ** See the License for the specific language governing permissions and + ** limitations under the License. + */ + +#ifndef ANDROID_EGL_LOADER_H +#define ANDROID_EGL_LOADER_H + +#include <ctype.h> +#include <string.h> +#include <errno.h> + +#include <utils/Errors.h> +#include <utils/Singleton.h> +#include <utils/String8.h> +#include <utils/Vector.h> + +#include <EGL/egl.h> + +// ---------------------------------------------------------------------------- +namespace android { +// ---------------------------------------------------------------------------- + +struct gl_hooks_t; + +class Loader : public Singleton<Loader> +{ + friend class Singleton<Loader>; + + typedef __eglMustCastToProperFunctionPointerType (*getProcAddressType)( + const char*); + + enum { + EGL = 0x01, + GLESv1_CM = 0x02, + GLESv2 = 0x04 + }; + struct driver_t { + driver_t(void* gles); + ~driver_t(); + status_t set(void* hnd, int32_t api); + void* dso[3]; + }; + + struct entry_t { + entry_t() { } + entry_t(int dpy, int impl, const char* tag); + int dpy; + int impl; + String8 tag; + }; + + Vector<entry_t> gConfig; + getProcAddressType getProcAddress; + + const char* getTag(int dpy, int impl); + +public: + ~Loader(); + + void* open(EGLNativeDisplayType display, int impl, gl_hooks_t* hooks); + status_t close(void* driver); + +private: + Loader(); + void *load_driver(const char* driver, gl_hooks_t* hooks, uint32_t mask); + + static __attribute__((noinline)) + void init_api(void* dso, + char const * const * api, + __eglMustCastToProperFunctionPointerType* curr, + getProcAddressType getProcAddress); +}; + +// ---------------------------------------------------------------------------- +}; // namespace android +// ---------------------------------------------------------------------------- + +#endif /* ANDROID_EGL_LOADER_H */ diff --git a/opengl/libs/EGL/egl.cpp b/opengl/libs/EGL/egl.cpp index c6e0f50..c2003dd 100644 --- a/opengl/libs/EGL/egl.cpp +++ b/opengl/libs/EGL/egl.cpp @@ -14,9 +14,8 @@ ** limitations under the License. */ -#define LOG_TAG "libEGL" - #include <ctype.h> +#include <stdlib.h> #include <string.h> #include <errno.h> #include <dlfcn.h> @@ -37,11 +36,9 @@ #include <cutils/properties.h> #include <cutils/memory.h> -#include <utils/RefBase.h> - #include "hooks.h" #include "egl_impl.h" - +#include "Loader.h" #define MAKE_CONFIG(_impl, _index) ((EGLConfig)(((_impl)<<24) | (_index))) #define setError(_e, _r) setErrorEtc(__FUNCTION__, __LINE__, _e, _r) @@ -55,7 +52,16 @@ namespace android { static char const * const gVendorString = "Android"; static char const * const gVersionString = "1.31 Android META-EGL"; static char const * const gClientApiString = "OpenGL ES"; -static char const * const gExtensionString = ""; +static char const * const gExtensionString = + "EGL_KHR_image " + "EGL_KHR_image_base " + "EGL_KHR_image_pixmap " + "EGL_ANDROID_image_native_buffer " + "EGL_ANDROID_swap_rectangle " + "EGL_ANDROID_get_render_buffer " + ; + +// ---------------------------------------------------------------------------- template <int MAGIC> struct egl_object_t @@ -87,21 +93,15 @@ struct egl_display_t : public egl_object_t<'_dpy'> struct egl_surface_t : public egl_object_t<'_srf'> { egl_surface_t(EGLDisplay dpy, EGLSurface surface, - NativeWindowType window, int impl, egl_connection_t const* cnx) - : dpy(dpy), surface(surface), window(window), impl(impl), cnx(cnx) + int impl, egl_connection_t const* cnx) + : dpy(dpy), surface(surface), impl(impl), cnx(cnx) { // NOTE: window must be incRef'ed and connected already } ~egl_surface_t() { - if (window) { - if (window->disconnect) - window->disconnect(window); - window->decRef(window); - } } EGLDisplay dpy; EGLSurface surface; - NativeWindowType window; int impl; egl_connection_t const* cnx; }; @@ -121,6 +121,18 @@ struct egl_context_t : public egl_object_t<'_ctx'> egl_connection_t const* cnx; }; +struct egl_image_t : public egl_object_t<'_img'> +{ + egl_image_t(EGLDisplay dpy, EGLContext context) + : dpy(dpy), context(context) + { + memset(images, 0, sizeof(images)); + } + EGLDisplay dpy; + EGLConfig context; + EGLImageKHR images[IMPL_NUM_DRIVERS_IMPLEMENTATIONS]; +}; + struct tls_t { tls_t() : error(EGL_SUCCESS), ctx(0) { } @@ -128,32 +140,6 @@ struct tls_t EGLContext ctx; }; -static void gl_unimplemented() { - LOGE("called unimplemented OpenGL ES API"); -} - -// ---------------------------------------------------------------------------- -// GL / EGL hooks -// ---------------------------------------------------------------------------- - -#undef GL_ENTRY -#undef EGL_ENTRY -#define GL_ENTRY(_r, _api, ...) #_api, -#define EGL_ENTRY(_r, _api, ...) #_api, - -static char const * const gl_names[] = { - #include "gl_entries.in" - #include "glext_entries.in" - NULL -}; - -static char const * const egl_names[] = { - #include "egl_entries.in" - NULL -}; - -#undef GL_ENTRY -#undef EGL_ENTRY // ---------------------------------------------------------------------------- @@ -262,110 +248,8 @@ EGLContext getContext() { return tls->ctx; } - /*****************************************************************************/ -class ISurfaceComposer; -const sp<ISurfaceComposer>& getSurfaceFlinger(); -request_gpu_t* gpu_acquire(void* user); -int gpu_release(void*, request_gpu_t* gpu); - -static __attribute__((noinline)) -void *load_driver(const char* driver, gl_hooks_t* hooks) -{ - //LOGD("%s", driver); - char scrap[256]; - void* dso = dlopen(driver, RTLD_NOW | RTLD_LOCAL); - LOGE_IF(!dso, - "couldn't load <%s> library (%s)", - driver, dlerror()); - - if (dso) { - // first find the symbol for eglGetProcAddress - - typedef __eglMustCastToProperFunctionPointerType (*getProcAddressType)( - const char*); - - getProcAddressType getProcAddress = - (getProcAddressType)dlsym(dso, "eglGetProcAddress"); - - LOGE_IF(!getProcAddress, - "can't find eglGetProcAddress() in %s", driver); - - __eglMustCastToProperFunctionPointerType* curr; - char const * const * api; - - gl_hooks_t::egl_t* egl = &hooks->egl; - curr = (__eglMustCastToProperFunctionPointerType*)egl; - api = egl_names; - while (*api) { - char const * name = *api; - __eglMustCastToProperFunctionPointerType f = - (__eglMustCastToProperFunctionPointerType)dlsym(dso, name); - if (f == NULL) { - // couldn't find the entry-point, use eglGetProcAddress() - f = getProcAddress(name); - if (f == NULL) { - f = (__eglMustCastToProperFunctionPointerType)0; - } - } - *curr++ = f; - api++; - } - - gl_hooks_t::gl_t* gl = &hooks->gl; - curr = (__eglMustCastToProperFunctionPointerType*)gl; - api = gl_names; - while (*api) { - char const * name = *api; - __eglMustCastToProperFunctionPointerType f = - (__eglMustCastToProperFunctionPointerType)dlsym(dso, name); - if (f == NULL) { - // couldn't find the entry-point, use eglGetProcAddress() - f = getProcAddress(name); - } - if (f == NULL) { - // Try without the OES postfix - ssize_t index = ssize_t(strlen(name)) - 3; - if ((index>0 && (index<255)) && (!strcmp(name+index, "OES"))) { - strncpy(scrap, name, index); - scrap[index] = 0; - f = (__eglMustCastToProperFunctionPointerType)dlsym(dso, scrap); - //LOGD_IF(f, "found <%s> instead", scrap); - } - } - if (f == NULL) { - // Try with the OES postfix - ssize_t index = ssize_t(strlen(name)) - 3; - if ((index>0 && (index<252)) && (strcmp(name+index, "OES"))) { - strncpy(scrap, name, index); - scrap[index] = 0; - strcat(scrap, "OES"); - f = (__eglMustCastToProperFunctionPointerType)dlsym(dso, scrap); - //LOGD_IF(f, "found <%s> instead", scrap); - } - } - if (f == NULL) { - //LOGD("%s", name); - f = (__eglMustCastToProperFunctionPointerType)gl_unimplemented; - } - *curr++ = f; - api++; - } - - // hook this driver up with surfaceflinger if needed - register_gpu_t register_gpu = - (register_gpu_t)dlsym(dso, "oem_register_gpu"); - - if (register_gpu != NULL) { - if (getSurfaceFlinger() != 0) { - register_gpu(dso, gpu_acquire, gpu_release); - } - } - } - return dso; -} - template<typename T> static __attribute__((noinline)) int binarySearch( @@ -412,6 +296,18 @@ struct extention_map_t { }; static const extention_map_t gExtentionMap[] = { + { "eglLockSurfaceKHR", + (__eglMustCastToProperFunctionPointerType)&eglLockSurfaceKHR }, + { "eglUnlockSurfaceKHR", + (__eglMustCastToProperFunctionPointerType)&eglUnlockSurfaceKHR }, + { "eglCreateImageKHR", + (__eglMustCastToProperFunctionPointerType)&eglCreateImageKHR }, + { "eglDestroyImageKHR", + (__eglMustCastToProperFunctionPointerType)&eglDestroyImageKHR }, + { "eglSetSwapRectangleANDROID", + (__eglMustCastToProperFunctionPointerType)&eglSetSwapRectangleANDROID }, + { "eglGetRenderBufferANDROID", + (__eglMustCastToProperFunctionPointerType)&eglGetRenderBufferANDROID }, }; static extention_map_t gGLExtentionMap[MAX_NUMBER_OF_GL_EXTENSIONS]; @@ -429,6 +325,12 @@ static void(*findProcAddress(const char* name, // ---------------------------------------------------------------------------- +/* + * To "loose" the GPU, use something like + * gEGLImpl[IMPL_HARDWARE].hooks = &gHooks[IMPL_CONTEXT_LOST]; + * + */ + static int gl_context_lost() { setGlThreadSpecific(&gHooks[IMPL_CONTEXT_LOST]); return 0; @@ -491,6 +393,11 @@ egl_context_t* get_context(EGLContext context) { return egl_to_native_cast<egl_context_t>(context); } +static inline +egl_image_t* get_image(EGLImageKHR image) { + return egl_to_native_cast<egl_image_t>(image); +} + static egl_connection_t* validate_display_config( EGLDisplay dpy, EGLConfig config, egl_display_t const*& dp, int& impl, int& index) @@ -540,6 +447,24 @@ static EGLBoolean validate_display_surface(EGLDisplay dpy, EGLSurface surface) } +EGLImageKHR egl_get_image_for_current_context(EGLImageKHR image) +{ + EGLContext context = getContext(); + if (context == EGL_NO_CONTEXT || image == EGL_NO_IMAGE_KHR) + return EGL_NO_IMAGE_KHR; + + egl_context_t const * const c = get_context(context); + if (!c->isValid()) + return EGL_NO_IMAGE_KHR; + + egl_image_t const * const i = get_image(image); + if (!i->isValid()) + return EGL_NO_IMAGE_KHR; + + return i->images[c->impl]; +} + + EGLDisplay egl_init_displays(NativeDisplayType display) { if (sEarlyInitState) { @@ -554,12 +479,15 @@ EGLDisplay egl_init_displays(NativeDisplayType display) EGLDisplay dpy = EGLDisplay(uintptr_t(display) + 1LU); egl_display_t* d = &gDisplay[index]; + // get our driver loader + Loader& loader(Loader::getInstance()); + // dynamically load all our EGL implementations for that display // and call into the real eglGetGisplay() egl_connection_t* cnx = &gEGLImpl[IMPL_SOFTWARE]; if (cnx->dso == 0) { cnx->hooks = &gHooks[IMPL_SOFTWARE]; - cnx->dso = load_driver("libagl.so", cnx->hooks); + cnx->dso = loader.open(display, 0, cnx->hooks); } if (cnx->dso && d->dpys[IMPL_SOFTWARE]==EGL_NO_DISPLAY) { d->dpys[IMPL_SOFTWARE] = cnx->hooks->egl.eglGetDisplay(display); @@ -573,7 +501,7 @@ EGLDisplay egl_init_displays(NativeDisplayType display) property_get("debug.egl.hw", value, "1"); if (atoi(value) != 0) { cnx->hooks = &gHooks[IMPL_HARDWARE]; - cnx->dso = load_driver("libhgl.so", cnx->hooks); + cnx->dso = loader.open(display, 1, cnx->hooks); } else { LOGD("3D hardware acceleration is disabled"); } @@ -605,7 +533,8 @@ EGLDisplay egl_init_displays(NativeDisplayType display) if (d->dpys[IMPL_HARDWARE] == EGL_NO_DISPLAY) { LOGE("h/w accelerated eglGetDisplay() failed (%s)", egl_strerror(cnx->hooks->egl.eglGetError())); - dlclose((void*)cnx->dso); + + loader.close(cnx->dso); cnx->dso = 0; // in case of failure, we want to make sure we don't try again // as it's expensive. @@ -717,6 +646,8 @@ EGLBoolean eglTerminate(EGLDisplay dpy) if (android_atomic_dec(&dp->refs) != 1) return EGL_TRUE; + Loader& loader(Loader::getInstance()); + EGLBoolean res = EGL_FALSE; for (int i=0 ; i<IMPL_NUM_DRIVERS_IMPLEMENTATIONS ; i++) { egl_connection_t* const cnx = &gEGLImpl[i]; @@ -732,7 +663,8 @@ EGLBoolean eglTerminate(EGLDisplay dpy) free((void*)dp->queryString[i].extensions); dp->numConfigs[i] = 0; dp->dpys[i] = EGL_NO_DISPLAY; - dlclose((void*)cnx->dso); + + loader.close(cnx->dso); cnx->dso = 0; res = EGL_TRUE; } @@ -909,26 +841,12 @@ EGLSurface eglCreateWindowSurface( EGLDisplay dpy, EGLConfig config, int i=0, index=0; egl_connection_t* cnx = validate_display_config(dpy, config, dp, i, index); if (cnx) { - // window must be connected upon calling underlying - // eglCreateWindowSurface - if (window) { - window->incRef(window); - if (window->connect) - window->connect(window); - } - EGLSurface surface = cnx->hooks->egl.eglCreateWindowSurface( dp->dpys[i], dp->configs[i][index], window, attrib_list); if (surface != EGL_NO_SURFACE) { - egl_surface_t* s = new egl_surface_t(dpy, surface, window, i, cnx); + egl_surface_t* s = new egl_surface_t(dpy, surface, i, cnx); return s; } - - // something went wrong, disconnect and free window - // (will disconnect() automatically) - if (window) { - window->decRef(window); - } } return EGL_NO_SURFACE; } @@ -944,7 +862,7 @@ EGLSurface eglCreatePixmapSurface( EGLDisplay dpy, EGLConfig config, EGLSurface surface = cnx->hooks->egl.eglCreatePixmapSurface( dp->dpys[i], dp->configs[i][index], pixmap, attrib_list); if (surface != EGL_NO_SURFACE) { - egl_surface_t* s = new egl_surface_t(dpy, surface, NULL, i, cnx); + egl_surface_t* s = new egl_surface_t(dpy, surface, i, cnx); return s; } } @@ -961,7 +879,7 @@ EGLSurface eglCreatePbufferSurface( EGLDisplay dpy, EGLConfig config, EGLSurface surface = cnx->hooks->egl.eglCreatePbufferSurface( dp->dpys[i], dp->configs[i][index], attrib_list); if (surface != EGL_NO_SURFACE) { - egl_surface_t* s = new egl_surface_t(dpy, surface, NULL, i, cnx); + egl_surface_t* s = new egl_surface_t(dpy, surface, i, cnx); return s; } } @@ -1430,3 +1348,156 @@ EGLSurface eglCreatePbufferFromClientBuffer( } return setError(EGL_BAD_CONFIG, EGL_NO_SURFACE); } + +// ---------------------------------------------------------------------------- +// EGL_EGLEXT_VERSION 3 +// ---------------------------------------------------------------------------- + +EGLBoolean eglLockSurfaceKHR(EGLDisplay dpy, EGLSurface surface, + const EGLint *attrib_list) +{ + EGLBoolean result = EGL_FALSE; + if (!validate_display_surface(dpy, surface)) + return result; + + egl_display_t const * const dp = get_display(dpy); + egl_surface_t const * const s = get_surface(surface); + + if (s->cnx->hooks->egl.eglLockSurfaceKHR) { + result = s->cnx->hooks->egl.eglLockSurfaceKHR( + dp->dpys[s->impl], s->surface, attrib_list); + } + return result; +} + +EGLBoolean eglUnlockSurfaceKHR(EGLDisplay dpy, EGLSurface surface) +{ + EGLBoolean result = EGL_FALSE; + if (!validate_display_surface(dpy, surface)) + return result; + + egl_display_t const * const dp = get_display(dpy); + egl_surface_t const * const s = get_surface(surface); + + if (s->cnx->hooks->egl.eglUnlockSurfaceKHR) { + result = s->cnx->hooks->egl.eglUnlockSurfaceKHR( + dp->dpys[s->impl], s->surface); + } + return result; +} + +EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, + EGLClientBuffer buffer, const EGLint *attrib_list) +{ + if (ctx != EGL_NO_CONTEXT) { + if (!validate_display_context(dpy, ctx)) + return EGL_NO_IMAGE_KHR; + egl_display_t const * const dp = get_display(dpy); + egl_context_t * const c = get_context(ctx); + // since we have an EGLContext, we know which implementation to use + EGLImageKHR image = c->cnx->hooks->egl.eglCreateImageKHR( + dp->dpys[c->impl], c->context, target, buffer, attrib_list); + if (image == EGL_NO_IMAGE_KHR) + return image; + + egl_image_t* result = new egl_image_t(dpy, ctx); + result->images[c->impl] = image; + return (EGLImageKHR)result; + } else { + // EGL_NO_CONTEXT is a valid parameter + egl_display_t const * const dp = get_display(dpy); + if (dp == 0) { + return setError(EGL_BAD_DISPLAY, EGL_NO_IMAGE_KHR); + } + // since we don't have a way to know which implementation to call, + // we're calling all of them + + EGLImageKHR implImages[IMPL_NUM_DRIVERS_IMPLEMENTATIONS]; + bool success = false; + for (int i=0 ; i<IMPL_NUM_DRIVERS_IMPLEMENTATIONS ; i++) { + egl_connection_t* const cnx = &gEGLImpl[i]; + implImages[i] = EGL_NO_IMAGE_KHR; + if (cnx->dso) { + if (cnx->hooks->egl.eglCreateImageKHR) { + implImages[i] = cnx->hooks->egl.eglCreateImageKHR( + dp->dpys[i], ctx, target, buffer, attrib_list); + if (implImages[i] != EGL_NO_IMAGE_KHR) { + success = true; + } + } + } + } + if (!success) + return EGL_NO_IMAGE_KHR; + + egl_image_t* result = new egl_image_t(dpy, ctx); + memcpy(result->images, implImages, sizeof(implImages)); + return (EGLImageKHR)result; + } +} + +EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR img) +{ + egl_display_t const * const dp = get_display(dpy); + if (dp == 0) { + return setError(EGL_BAD_DISPLAY, EGL_FALSE); + } + + egl_image_t* image = get_image(img); + if (!image->isValid()) { + return setError(EGL_BAD_PARAMETER, EGL_FALSE); + } + + bool success = false; + for (int i=0 ; i<IMPL_NUM_DRIVERS_IMPLEMENTATIONS ; i++) { + egl_connection_t* const cnx = &gEGLImpl[i]; + if (image->images[i] != EGL_NO_IMAGE_KHR) { + if (cnx->dso) { + if (cnx->hooks->egl.eglCreateImageKHR) { + if (cnx->hooks->egl.eglDestroyImageKHR( + dp->dpys[i], image->images[i])) { + success = true; + } + } + } + } + } + if (!success) + return EGL_FALSE; + + delete image; + + return EGL_FALSE; +} + + +// ---------------------------------------------------------------------------- +// ANDROID extensions +// ---------------------------------------------------------------------------- + +EGLBoolean eglSetSwapRectangleANDROID(EGLDisplay dpy, EGLSurface draw, + EGLint left, EGLint top, EGLint width, EGLint height) +{ + if (!validate_display_surface(dpy, draw)) + return EGL_FALSE; + egl_display_t const * const dp = get_display(dpy); + egl_surface_t const * const s = get_surface(draw); + if (s->cnx->hooks->egl.eglSetSwapRectangleANDROID) { + return s->cnx->hooks->egl.eglSetSwapRectangleANDROID(dp->dpys[s->impl], + s->surface, left, top, width, height); + } + return EGL_FALSE; +} + +EGLClientBuffer eglGetRenderBufferANDROID(EGLDisplay dpy, EGLSurface draw) +{ + if (!validate_display_surface(dpy, draw)) + return 0; + egl_display_t const * const dp = get_display(dpy); + egl_surface_t const * const s = get_surface(draw); + if (s->cnx->hooks->egl.eglGetRenderBufferANDROID) { + return s->cnx->hooks->egl.eglGetRenderBufferANDROID(dp->dpys[s->impl], + s->surface); + } + return 0; +} diff --git a/opengl/libs/EGL/egl_entries.in b/opengl/libs/EGL/egl_entries.in new file mode 100644 index 0000000..5d89287 --- /dev/null +++ b/opengl/libs/EGL/egl_entries.in @@ -0,0 +1,57 @@ +EGL_ENTRY(EGLDisplay, eglGetDisplay, NativeDisplayType) +EGL_ENTRY(EGLBoolean, eglInitialize, EGLDisplay, EGLint*, EGLint*) +EGL_ENTRY(EGLBoolean, eglTerminate, EGLDisplay) +EGL_ENTRY(EGLBoolean, eglGetConfigs, EGLDisplay, EGLConfig*, EGLint, EGLint*) +EGL_ENTRY(EGLBoolean, eglChooseConfig, EGLDisplay, const EGLint *, EGLConfig *, EGLint, EGLint *) + +EGL_ENTRY(EGLBoolean, eglGetConfigAttrib, EGLDisplay, EGLConfig, EGLint, EGLint *) +EGL_ENTRY(EGLSurface, eglCreateWindowSurface, EGLDisplay, EGLConfig, NativeWindowType, const EGLint *) +EGL_ENTRY(EGLSurface, eglCreatePixmapSurface, EGLDisplay, EGLConfig, NativePixmapType, const EGLint *) +EGL_ENTRY(EGLSurface, eglCreatePbufferSurface, EGLDisplay, EGLConfig, const EGLint *) +EGL_ENTRY(EGLBoolean, eglDestroySurface, EGLDisplay, EGLSurface) +EGL_ENTRY(EGLBoolean, eglQuerySurface, EGLDisplay, EGLSurface, EGLint, EGLint *) +EGL_ENTRY(EGLContext, eglCreateContext, EGLDisplay, EGLConfig, EGLContext, const EGLint *) +EGL_ENTRY(EGLBoolean, eglDestroyContext, EGLDisplay, EGLContext) +EGL_ENTRY(EGLBoolean, eglMakeCurrent, EGLDisplay, EGLSurface, EGLSurface, EGLContext) +EGL_ENTRY(EGLContext, eglGetCurrentContext, void) +EGL_ENTRY(EGLSurface, eglGetCurrentSurface, EGLint) +EGL_ENTRY(EGLDisplay, eglGetCurrentDisplay, void) +EGL_ENTRY(EGLBoolean, eglQueryContext, EGLDisplay, EGLContext, EGLint, EGLint *) +EGL_ENTRY(EGLBoolean, eglWaitGL, void) +EGL_ENTRY(EGLBoolean, eglWaitNative, EGLint) +EGL_ENTRY(EGLBoolean, eglSwapBuffers, EGLDisplay, EGLSurface) +EGL_ENTRY(EGLBoolean, eglCopyBuffers, EGLDisplay, EGLSurface, NativePixmapType) +EGL_ENTRY(EGLint, eglGetError, void) +EGL_ENTRY(const char*, eglQueryString, EGLDisplay, EGLint) +EGL_ENTRY(__eglMustCastToProperFunctionPointerType, eglGetProcAddress, const char *) + +/* EGL 1.1 */ + +EGL_ENTRY(EGLBoolean, eglSurfaceAttrib, EGLDisplay, EGLSurface, EGLint, EGLint) +EGL_ENTRY(EGLBoolean, eglBindTexImage, EGLDisplay, EGLSurface, EGLint) +EGL_ENTRY(EGLBoolean, eglReleaseTexImage, EGLDisplay, EGLSurface, EGLint) +EGL_ENTRY(EGLBoolean, eglSwapInterval, EGLDisplay, EGLint) + +/* EGL 1.2 */ + +EGL_ENTRY(EGLBoolean, eglBindAPI, EGLenum) +EGL_ENTRY(EGLenum, eglQueryAPI, void) +EGL_ENTRY(EGLBoolean, eglWaitClient, void) +EGL_ENTRY(EGLBoolean, eglReleaseThread, void) +EGL_ENTRY(EGLSurface, eglCreatePbufferFromClientBuffer, EGLDisplay, EGLenum, EGLClientBuffer, EGLConfig, const EGLint *) + +/* EGL 1.3 */ + +/* EGL 1.4 */ + +/* EGL_EGLEXT_VERSION 3 */ + +EGL_ENTRY(EGLBoolean, eglLockSurfaceKHR, EGLDisplay, EGLSurface, const EGLint *) +EGL_ENTRY(EGLBoolean, eglUnlockSurfaceKHR, EGLDisplay, EGLSurface) +EGL_ENTRY(EGLImageKHR, eglCreateImageKHR, EGLDisplay, EGLContext, EGLenum, EGLClientBuffer, const EGLint *) +EGL_ENTRY(EGLBoolean, eglDestroyImageKHR, EGLDisplay, EGLImageKHR) + +/* ANDROID extensions */ + +EGL_ENTRY(EGLBoolean, eglSetSwapRectangleANDROID, EGLDisplay, EGLSurface, EGLint, EGLint, EGLint, EGLint) +EGL_ENTRY(EGLClientBuffer, eglGetRenderBufferANDROID, EGLDisplay, EGLSurface) diff --git a/opengl/libs/EGL/gpu.cpp b/opengl/libs/EGL/gpu.cpp deleted file mode 100644 index 4c902c8..0000000 --- a/opengl/libs/EGL/gpu.cpp +++ /dev/null @@ -1,217 +0,0 @@ -/* - ** Copyright 2007, The Android Open Source Project - ** - ** Licensed under the Apache License, Version 2.0 (the "License"); - ** you may not use this file except in compliance with the License. - ** You may obtain a copy of the License at - ** - ** http://www.apache.org/licenses/LICENSE-2.0 - ** - ** Unless required by applicable law or agreed to in writing, software - ** distributed under the License is distributed on an "AS IS" BASIS, - ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - ** See the License for the specific language governing permissions and - ** limitations under the License. - */ - -#define LOG_TAG "EGL" - -#include <ctype.h> -#include <string.h> -#include <errno.h> - -#include <sys/ioctl.h> - -#if HAVE_ANDROID_OS -#include <linux/android_pmem.h> -#endif - -#include <cutils/log.h> -#include <cutils/properties.h> - -#include <utils/IMemory.h> -#include <utils/threads.h> -#include <utils/IServiceManager.h> -#include <utils/IPCThreadState.h> -#include <utils/Parcel.h> - -#include <ui/EGLDisplaySurface.h> -#include <ui/ISurfaceComposer.h> - -#include "hooks.h" -#include "egl_impl.h" - -// ---------------------------------------------------------------------------- -namespace android { -// ---------------------------------------------------------------------------- - -/* - * we provide our own allocators for the GPU regions, these - * allocators go through surfaceflinger - */ - -static Mutex gRegionsLock; -static request_gpu_t gRegions; -static sp<ISurfaceComposer> gSurfaceManager; -GL_API ISurfaceComposer* GLES_localSurfaceManager = 0; - -extern egl_connection_t gEGLImpl[2]; - -const sp<ISurfaceComposer>& getSurfaceFlinger() -{ - Mutex::Autolock _l(gRegionsLock); - - /* - * There is a little bit of voodoo magic here. We want to access - * surfaceflinger for allocating GPU regions, however, when we are - * running as part of surfaceflinger, we want to bypass the - * service manager because surfaceflinger might not be registered yet. - * SurfaceFlinger will populate "GLES_localSurfaceManager" with its - * own address, so we can just use that. - */ - if (gSurfaceManager == 0) { - if (GLES_localSurfaceManager) { - // we're running in SurfaceFlinger's context - gSurfaceManager = GLES_localSurfaceManager; - } else { - // we're a remote process or not part of surfaceflinger, - // go through the service manager - sp<IServiceManager> sm = defaultServiceManager(); - if (sm != NULL) { - sp<IBinder> binder = sm->getService(String16("SurfaceFlinger")); - gSurfaceManager = interface_cast<ISurfaceComposer>(binder); - } - } - } - return gSurfaceManager; -} - -class GPURevokeRequester : public BnGPUCallback -{ -public: - virtual void gpuLost() { - LOGD("CONTEXT_LOST: Releasing GPU upon request from SurfaceFlinger."); - gEGLImpl[IMPL_HARDWARE].hooks = &gHooks[IMPL_CONTEXT_LOST]; - } -}; - -static sp<GPURevokeRequester> gRevokerCallback; - - -request_gpu_t* gpu_acquire(void* user) -{ - sp<ISurfaceComposer> server( getSurfaceFlinger() ); - - Mutex::Autolock _l(gRegionsLock); - if (server == NULL) { - return 0; - } - - ISurfaceComposer::gpu_info_t info; - - if (gRevokerCallback == 0) - gRevokerCallback = new GPURevokeRequester(); - - status_t err = server->requestGPU(gRevokerCallback, &info); - if (err != NO_ERROR) { - LOGD("requestGPU returned %d", err); - return 0; - } - - if (info.regs == 0) { - LOGD("requestGPU() failed"); - return 0; - } - - bool failed = false; - request_gpu_t* gpu = &gRegions; - memset(gpu, 0, sizeof(*gpu)); - - if (info.regs != 0) { - sp<IMemoryHeap> heap(info.regs->getMemory()); - if (heap != 0) { - int fd = heap->heapID(); - gpu->regs.fd = fd; - gpu->regs.base = info.regs->pointer(); - gpu->regs.size = info.regs->size(); - gpu->regs.user = info.regs.get(); -#if HAVE_ANDROID_OS - struct pmem_region region; - if (ioctl(fd, PMEM_GET_PHYS, ®ion) >= 0) - gpu->regs.phys = (void*)region.offset; -#endif - info.regs->incStrong(gpu); - } else { - LOGE("GPU register handle %p is invalid!", info.regs.get()); - failed = true; - } - } - - for (size_t i=0 ; i<info.count && !failed ; i++) { - sp<IMemory>& region(info.regions[i].region); - if (region != 0) { - sp<IMemoryHeap> heap(region->getMemory()); - if (heap != 0) { - const int fd = heap->heapID(); - gpu->gpu[i].fd = fd; - gpu->gpu[i].base = region->pointer(); - gpu->gpu[i].size = region->size(); - gpu->gpu[i].user = region.get(); - gpu->gpu[i].offset = info.regions[i].reserved; -#if HAVE_ANDROID_OS - struct pmem_region reg; - if (ioctl(fd, PMEM_GET_PHYS, ®) >= 0) - gpu->gpu[i].phys = (void*)reg.offset; -#endif - region->incStrong(gpu); - } else { - LOGE("GPU region handle [%d, %p] is invalid!", i, region.get()); - failed = true; - } - } - } - - if (failed) { - // something went wrong, clean up everything! - if (gpu->regs.user) { - static_cast<IMemory*>(gpu->regs.user)->decStrong(gpu); - for (size_t i=0 ; i<info.count ; i++) { - if (gpu->gpu[i].user) { - static_cast<IMemory*>(gpu->gpu[i].user)->decStrong(gpu); - } - } - } - } - - gpu->count = info.count; - return gpu; -} - -int gpu_release(void*, request_gpu_t* gpu) -{ - sp<IMemory> regs; - - { // scope for lock - Mutex::Autolock _l(gRegionsLock); - regs = static_cast<IMemory*>(gpu->regs.user); - gpu->regs.user = 0; - if (regs != 0) regs->decStrong(gpu); - - for (int i=0 ; i<gpu->count ; i++) { - sp<IMemory> r(static_cast<IMemory*>(gpu->gpu[i].user)); - gpu->gpu[i].user = 0; - if (r != 0) r->decStrong(gpu); - } - } - - // there is a special transaction to relinquish the GPU - // (it will happen automatically anyway if we don't do this) - Parcel data, reply; - // NOTE: this transaction does not require an interface token - regs->asBinder()->transact(1000, data, &reply); - return 1; -} - -// ---------------------------------------------------------------------------- -}; // namespace android -// ---------------------------------------------------------------------------- diff --git a/opengl/libs/EGL/hooks.cpp b/opengl/libs/EGL/hooks.cpp new file mode 100644 index 0000000..2246366 --- /dev/null +++ b/opengl/libs/EGL/hooks.cpp @@ -0,0 +1,67 @@ +/* + ** Copyright 2009, The Android Open Source Project + ** + ** Licensed under the Apache License, Version 2.0 (the "License"); + ** you may not use this file except in compliance with the License. + ** You may obtain a copy of the License at + ** + ** http://www.apache.org/licenses/LICENSE-2.0 + ** + ** Unless required by applicable law or agreed to in writing, software + ** distributed under the License is distributed on an "AS IS" BASIS, + ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ** See the License for the specific language governing permissions and + ** limitations under the License. + */ + +#include <ctype.h> +#include <stdlib.h> +#include <errno.h> + +#include <cutils/log.h> + +#include "hooks.h" + +// ---------------------------------------------------------------------------- +namespace android { +// ---------------------------------------------------------------------------- + +void gl_unimplemented() { + LOGE("called unimplemented OpenGL ES API"); +} + + +// ---------------------------------------------------------------------------- +// GL / EGL hooks +// ---------------------------------------------------------------------------- + +#undef GL_ENTRY +#undef EGL_ENTRY +#define GL_ENTRY(_r, _api, ...) #_api, +#define EGL_ENTRY(_r, _api, ...) #_api, + +char const * const gl_names[] = { + #include "GLES_CM/gl_entries.in" + #include "GLES_CM/glext_entries.in" + NULL +}; + +char const * const gl2_names[] = { + #include "GLES2/gl2_entries.in" + #include "GLES2/gl2ext_entries.in" + NULL +}; + +char const * const egl_names[] = { + #include "egl_entries.in" + NULL +}; + +#undef GL_ENTRY +#undef EGL_ENTRY + + +// ---------------------------------------------------------------------------- +}; // namespace android +// ---------------------------------------------------------------------------- + |