blob: 75fc95c71304d71abc2d696e9e7748a97d491cdc [file] [log] [blame]
Jesse Hall47743382013-02-08 11:13:46 -08001/*
Mathias Agopianb1a39d62009-05-27 20:38:06 -07002 ** Copyright 2007, The Android Open Source Project
3 **
Jesse Hall47743382013-02-08 11:13:46 -08004 ** 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
Mathias Agopianb1a39d62009-05-27 20:38:06 -07007 **
Jesse Hall47743382013-02-08 11:13:46 -08008 ** http://www.apache.org/licenses/LICENSE-2.0
Mathias Agopianb1a39d62009-05-27 20:38:06 -07009 **
Jesse Hall47743382013-02-08 11:13:46 -080010 ** 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
Mathias Agopianb1a39d62009-05-27 20:38:06 -070014 ** 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
Mathias Agopianb1a39d62009-05-27 20:38:06 -070023#include <cutils/log.h>
24#include <cutils/properties.h>
25
Mathias Agopian39c24a22013-04-04 23:17:56 -070026#include "../hooks.h"
27#include "../egl_impl.h"
Mathias Agopianb1a39d62009-05-27 20:38:06 -070028
29using namespace android;
30
31// ----------------------------------------------------------------------------
32// Actual GL entry-points
33// ----------------------------------------------------------------------------
34
35#undef API_ENTRY
36#undef CALL_GL_API
37#undef CALL_GL_API_RETURN
38
Mathias Agopiane0ea89c2013-06-14 19:08:36 -070039#if defined(__arm__) && !USE_SLOW_BINDING
Duane Sand46b42532013-03-27 10:58:06 -070040
Elliott Hughes288870e2013-02-13 17:30:54 -080041 #define GET_TLS(reg) "mrc p15, 0, " #reg ", c13, c0, 3 \n"
Mathias Agopian673d2db2009-10-14 02:39:53 -070042
Mathias Agopiane0ea89c2013-06-14 19:08:36 -070043 #define API_ENTRY(_api) __attribute__((noinline)) _api
Mathias Agopianb1a39d62009-05-27 20:38:06 -070044
45 #define CALL_GL_API(_api, ...) \
46 asm volatile( \
Mathias Agopian673d2db2009-10-14 02:39:53 -070047 GET_TLS(r12) \
Mathias Agopianb1a39d62009-05-27 20:38:06 -070048 "ldr r12, [r12, %[tls]] \n" \
49 "cmp r12, #0 \n" \
50 "ldrne pc, [r12, %[api]] \n" \
Mathias Agopianb1a39d62009-05-27 20:38:06 -070051 : \
52 : [tls] "J"(TLS_SLOT_OPENGL_API*4), \
Mathias Agopian618fa102009-10-14 02:06:37 -070053 [api] "J"(__builtin_offsetof(gl_hooks_t, gl._api)) \
Mathias Agopianb1a39d62009-05-27 20:38:06 -070054 : \
55 );
Mathias Agopian673d2db2009-10-14 02:39:53 -070056
Mathias Agopiane0ea89c2013-06-14 19:08:36 -070057#elif defined(__mips__) && !USE_SLOW_BINDING
Duane Sand46b42532013-03-27 10:58:06 -070058
59 #define API_ENTRY(_api) __attribute__((noinline)) _api
60
61 #define CALL_GL_API(_api, ...) \
Jesse Hall441f6942013-03-30 23:22:19 -070062 register unsigned int _t0 asm("t0"); \
63 register unsigned int _fn asm("t1"); \
64 register unsigned int _tls asm("v1"); \
65 register unsigned int _v0 asm("v0"); \
Duane Sand46b42532013-03-27 10:58:06 -070066 asm volatile( \
67 ".set push\n\t" \
68 ".set noreorder\n\t" \
69 ".set mips32r2\n\t" \
70 "rdhwr %[tls], $29\n\t" \
71 "lw %[t0], %[OPENGL_API](%[tls])\n\t" \
72 "beqz %[t0], 1f\n\t" \
73 " move %[fn],$ra\n\t" \
74 "lw %[fn], %[API](%[t0])\n\t" \
75 "movz %[fn], $ra, %[fn]\n\t" \
76 "1:\n\t" \
77 "j %[fn]\n\t" \
78 " move %[v0], $0\n\t" \
79 ".set pop\n\t" \
Jesse Hall441f6942013-03-30 23:22:19 -070080 : [fn] "=c"(_fn), \
81 [tls] "=&r"(_tls), \
82 [t0] "=&r"(_t0), \
83 [v0] "=&r"(_v0) \
Duane Sand46b42532013-03-27 10:58:06 -070084 : [OPENGL_API] "I"(TLS_SLOT_OPENGL_API*4), \
85 [API] "I"(__builtin_offsetof(gl_hooks_t, gl._api)) \
86 : \
87 );
88
Mathias Agopianb1a39d62009-05-27 20:38:06 -070089#else
90
91 #define API_ENTRY(_api) _api
92
Romain Guy761eaed2010-08-09 20:48:09 -070093 #define CALL_GL_API(_api, ...) \
94 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \
Mathias Agopiane0ea89c2013-06-14 19:08:36 -070095 if (_c) return _c->_api(__VA_ARGS__);
Mathias Agopianb1a39d62009-05-27 20:38:06 -070096
97#endif
98
Mathias Agopiane0ea89c2013-06-14 19:08:36 -070099#define CALL_GL_API_RETURN(_api, ...) \
100 CALL_GL_API(_api, __VA_ARGS__) \
101 return 0;
102
103
Mathias Agopianb1a39d62009-05-27 20:38:06 -0700104
105extern "C" {
Jesse Hallbbbddb82014-05-13 21:13:14 -0700106#pragma GCC diagnostic ignored "-Wunused-parameter"
Jesse Hall4c0596f2014-05-13 16:48:35 -0700107#include "gl2_api.in"
Mathias Agopianb1a39d62009-05-27 20:38:06 -0700108#include "gl2ext_api.in"
Jesse Hallbbbddb82014-05-13 21:13:14 -0700109#pragma GCC diagnostic warning "-Wunused-parameter"
Mathias Agopianb1a39d62009-05-27 20:38:06 -0700110}
111
112#undef API_ENTRY
113#undef CALL_GL_API
114#undef CALL_GL_API_RETURN
115
Mathias Agopian48d438d2012-01-28 21:44:00 -0800116/*
117 * glGetString() is special because we expose some extensions in the wrapper
118 */
119
120extern "C" const GLubyte * __glGetString(GLenum name);
121
122const GLubyte * glGetString(GLenum name)
123{
124 const GLubyte * ret = egl_get_string_for_current_context(name);
125 if (ret == NULL) {
Mathias Agopiane0ea89c2013-06-14 19:08:36 -0700126 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl;
127 ret = _c->glGetString(name);
Mathias Agopian48d438d2012-01-28 21:44:00 -0800128 }
129 return ret;
130}