The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17 | #include <ctype.h> |
| 18 | #include <string.h> |
| 19 | #include <errno.h> |
| 20 | |
| 21 | #include <sys/ioctl.h> |
| 22 | |
| 23 | #include <GLES/gl.h> |
| 24 | #include <GLES/glext.h> |
| 25 | |
| 26 | #include <cutils/log.h> |
| 27 | #include <cutils/properties.h> |
| 28 | |
| 29 | #include "hooks.h" |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 30 | #include "egl_impl.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | |
| 32 | using namespace android; |
| 33 | |
Mathias Agopian | 7d21a74 | 2009-10-08 15:58:11 -0700 | [diff] [blame] | 34 | // set this to 1 for crude GL debugging |
| 35 | #define CHECK_FOR_GL_ERRORS 0 |
| 36 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | // ---------------------------------------------------------------------------- |
| 38 | // extensions for the framework |
| 39 | // ---------------------------------------------------------------------------- |
| 40 | |
Mathias Agopian | d373c63 | 2009-05-08 15:35:17 -0700 | [diff] [blame] | 41 | extern "C" { |
| 42 | GL_API void GL_APIENTRY glColorPointerBounds(GLint size, GLenum type, GLsizei stride, |
| 43 | const GLvoid *ptr, GLsizei count); |
| 44 | GL_API void GL_APIENTRY glNormalPointerBounds(GLenum type, GLsizei stride, |
| 45 | const GLvoid *pointer, GLsizei count); |
| 46 | GL_API void GL_APIENTRY glTexCoordPointerBounds(GLint size, GLenum type, |
| 47 | GLsizei stride, const GLvoid *pointer, GLsizei count); |
| 48 | GL_API void GL_APIENTRY glVertexPointerBounds(GLint size, GLenum type, |
| 49 | GLsizei stride, const GLvoid *pointer, GLsizei count); |
| 50 | } |
| 51 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | void glColorPointerBounds(GLint size, GLenum type, GLsizei stride, |
| 53 | const GLvoid *ptr, GLsizei count) { |
| 54 | glColorPointer(size, type, stride, ptr); |
| 55 | } |
| 56 | void glNormalPointerBounds(GLenum type, GLsizei stride, |
| 57 | const GLvoid *pointer, GLsizei count) { |
| 58 | glNormalPointer(type, stride, pointer); |
| 59 | } |
| 60 | void glTexCoordPointerBounds(GLint size, GLenum type, |
| 61 | GLsizei stride, const GLvoid *pointer, GLsizei count) { |
| 62 | glTexCoordPointer(size, type, stride, pointer); |
| 63 | } |
| 64 | void glVertexPointerBounds(GLint size, GLenum type, |
| 65 | GLsizei stride, const GLvoid *pointer, GLsizei count) { |
| 66 | glVertexPointer(size, type, stride, pointer); |
| 67 | } |
| 68 | |
| 69 | // ---------------------------------------------------------------------------- |
| 70 | // Actual GL entry-points |
| 71 | // ---------------------------------------------------------------------------- |
| 72 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | #undef API_ENTRY |
| 74 | #undef CALL_GL_API |
| 75 | #undef CALL_GL_API_RETURN |
| 76 | |
Mathias Agopian | 7d21a74 | 2009-10-08 15:58:11 -0700 | [diff] [blame] | 77 | #if USE_FAST_TLS_KEY && !CHECK_FOR_GL_ERRORS |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | |
| 79 | #define API_ENTRY(_api) __attribute__((naked)) _api |
| 80 | |
| 81 | #define CALL_GL_API(_api, ...) \ |
| 82 | asm volatile( \ |
| 83 | "mov r12, #0xFFFF0FFF \n" \ |
| 84 | "ldr r12, [r12, #-15] \n" \ |
| 85 | "ldr r12, [r12, %[tls]] \n" \ |
| 86 | "cmp r12, #0 \n" \ |
| 87 | "ldrne pc, [r12, %[api]] \n" \ |
| 88 | "bx lr \n" \ |
| 89 | : \ |
| 90 | : [tls] "J"(TLS_SLOT_OPENGL_API*4), \ |
| 91 | [api] "J"(__builtin_offsetof(gl_hooks_t, gl._api)) \ |
| 92 | : \ |
| 93 | ); |
| 94 | |
| 95 | #define CALL_GL_API_RETURN(_api, ...) \ |
| 96 | CALL_GL_API(_api, __VA_ARGS__) \ |
| 97 | return 0; // placate gcc's warnings. never reached. |
| 98 | |
| 99 | #else |
| 100 | |
Mathias Agopian | 7d21a74 | 2009-10-08 15:58:11 -0700 | [diff] [blame] | 101 | #if CHECK_FOR_GL_ERRORS |
| 102 | |
| 103 | #define CHECK_GL_ERRORS(_api) \ |
| 104 | do { GLint err = glGetError(); \ |
| 105 | LOGE_IF(err != GL_NO_ERROR, "%s failed (0x%04X)", #_api, err); \ |
| 106 | } while(false); |
| 107 | |
| 108 | #else |
| 109 | |
| 110 | #define CHECK_GL_ERRORS(_api) do { } while(false); |
| 111 | |
| 112 | #endif |
| 113 | |
| 114 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | #define API_ENTRY(_api) _api |
| 116 | |
| 117 | #define CALL_GL_API(_api, ...) \ |
| 118 | gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \ |
Mathias Agopian | 7d21a74 | 2009-10-08 15:58:11 -0700 | [diff] [blame] | 119 | _c->_api(__VA_ARGS__); \ |
| 120 | CHECK_GL_ERRORS(_api) |
| 121 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 122 | #define CALL_GL_API_RETURN(_api, ...) \ |
| 123 | gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \ |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 | return _c->_api(__VA_ARGS__) |
| 125 | |
| 126 | #endif |
| 127 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 128 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 129 | extern "C" { |
| 130 | #include "gl_api.in" |
Mathias Agopian | b519abb | 2009-04-23 18:05:44 -0700 | [diff] [blame] | 131 | #include "glext_api.in" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | #undef API_ENTRY |
| 135 | #undef CALL_GL_API |
| 136 | #undef CALL_GL_API_RETURN |
| 137 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 138 | |
| 139 | /* |
| 140 | * These GL calls are special because they need to EGL to retrieve some |
| 141 | * informations before they can execute. |
| 142 | */ |
| 143 | |
| 144 | extern "C" void __glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image); |
| 145 | extern "C" void __glEGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image); |
| 146 | |
| 147 | |
| 148 | void glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image) |
| 149 | { |
| 150 | GLeglImageOES implImage = |
| 151 | (GLeglImageOES)egl_get_image_for_current_context((EGLImageKHR)image); |
| 152 | __glEGLImageTargetTexture2DOES(target, implImage); |
| 153 | } |
| 154 | |
| 155 | void glEGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image) |
| 156 | { |
| 157 | GLeglImageOES implImage = |
| 158 | (GLeglImageOES)egl_get_image_for_current_context((EGLImageKHR)image); |
| 159 | __glEGLImageTargetRenderbufferStorageOES(target, image); |
| 160 | } |
| 161 | |