gl2.cpp revision b1a39d67be99fe6c4545b25e10ac82a5dd1df634
1/* 2 ** Copyright 2007, The Android Open Source Project 3 ** 4 ** Licensed under the Apache License, Version 2.0 (the "License"); 5 ** you may not use this file except in compliance with the License. 6 ** You may obtain a copy of the License at 7 ** 8 ** http://www.apache.org/licenses/LICENSE-2.0 9 ** 10 ** Unless required by applicable law or agreed to in writing, software 11 ** distributed under the License is distributed on an "AS IS" BASIS, 12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 ** See the License for the specific language governing permissions and 14 ** limitations under the License. 15 */ 16 17#include <ctype.h> 18#include <string.h> 19#include <errno.h> 20 21#include <sys/ioctl.h> 22 23#include <GLES2/gl2.h> 24#include <GLES2/gl2ext.h> 25 26#include <cutils/log.h> 27#include <cutils/properties.h> 28 29#include "hooks.h" 30#include "egl_impl.h" 31 32using namespace android; 33 34// ---------------------------------------------------------------------------- 35// Actual GL entry-points 36// ---------------------------------------------------------------------------- 37 38#undef API_ENTRY 39#undef CALL_GL_API 40#undef CALL_GL_API_RETURN 41 42#if USE_FAST_TLS_KEY 43 44 #define API_ENTRY(_api) __attribute__((naked)) _api 45 46 #define CALL_GL_API(_api, ...) \ 47 asm volatile( \ 48 "mov r12, #0xFFFF0FFF \n" \ 49 "ldr r12, [r12, #-15] \n" \ 50 "ldr r12, [r12, %[tls]] \n" \ 51 "cmp r12, #0 \n" \ 52 "ldrne pc, [r12, %[api]] \n" \ 53 "bx lr \n" \ 54 : \ 55 : [tls] "J"(TLS_SLOT_OPENGL_API*4), \ 56 [api] "J"(__builtin_offsetof(gl_hooks_t, gl2._api)) \ 57 : \ 58 ); 59 60 #define CALL_GL_API_RETURN(_api, ...) \ 61 CALL_GL_API(_api, __VA_ARGS__) \ 62 return 0; // placate gcc's warnings. never reached. 63 64#else 65 66 #define API_ENTRY(_api) _api 67 68 #define CALL_GL_API(_api, ...) \ 69 gl_hooks_t::gl2_t const * const _c = &getGlThreadSpecific()->gl2; \ 70 _c->_api(__VA_ARGS__) 71 72 #define CALL_GL_API_RETURN(_api, ...) \ 73 gl_hooks_t::gl2_t const * const _c = &getGlThreadSpecific()->gl2; \ 74 return _c->_api(__VA_ARGS__) 75 76#endif 77 78 79extern "C" { 80#include "gl2_api.in" 81#include "gl2ext_api.in" 82} 83 84#undef API_ENTRY 85#undef CALL_GL_API 86#undef CALL_GL_API_RETURN 87 88 89/* 90 * These GL calls are special because they need to EGL to retrieve some 91 * informations before they can execute. 92 */ 93 94extern "C" void __glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image); 95extern "C" void __glEGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image); 96 97 98void glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image) 99{ 100 GLeglImageOES implImage = 101 (GLeglImageOES)egl_get_image_for_current_context((EGLImageKHR)image); 102 __glEGLImageTargetTexture2DOES(target, implImage); 103} 104 105void glEGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image) 106{ 107 GLeglImageOES implImage = 108 (GLeglImageOES)egl_get_image_for_current_context((EGLImageKHR)image); 109 __glEGLImageTargetRenderbufferStorageOES(target, image); 110} 111 112