| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | ** Copyright 2010, 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 | #if EGL_TRACE | 
|  | 18 |  | 
|  | 19 | #include <stdarg.h> | 
|  | 20 | #include <stdlib.h> | 
|  | 21 |  | 
|  | 22 | #include <EGL/egl.h> | 
|  | 23 | #include <EGL/eglext.h> | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 24 |  | 
|  | 25 | #include <cutils/log.h> | 
|  | 26 |  | 
| Romain Guy | 16928bf | 2012-10-18 16:16:10 -0700 | [diff] [blame] | 27 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS | 
|  | 28 | #include <utils/Trace.h> | 
|  | 29 |  | 
|  | 30 | #include <utils/CallStack.h> | 
|  | 31 |  | 
| Mathias Agopian | 1cadb25 | 2011-05-23 17:26:14 -0700 | [diff] [blame] | 32 | #include "egl_tls.h" | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 33 | #include "hooks.h" | 
|  | 34 |  | 
|  | 35 | // ---------------------------------------------------------------------------- | 
|  | 36 | namespace android { | 
|  | 37 | // ---------------------------------------------------------------------------- | 
|  | 38 |  | 
|  | 39 | struct GLenumString { | 
| Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 40 | // The GL_TIMEOUT_IGNORED "enum" doesn't fit in a GLenum, so use GLuint64 | 
|  | 41 | GLuint64 e; | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 42 | const char* s; | 
|  | 43 | }; | 
|  | 44 |  | 
|  | 45 | #undef GL_ENUM | 
|  | 46 | #define GL_ENUM(VAL,NAME) {VAL, #NAME}, | 
|  | 47 |  | 
|  | 48 | static GLenumString g_enumnames[] = { | 
|  | 49 | #include "enums.in" | 
|  | 50 | }; | 
|  | 51 | #undef GL_ENUM | 
|  | 52 |  | 
|  | 53 | static int compareGLEnum(const void* a, const void* b) { | 
|  | 54 | return ((const GLenumString*) a)->e - ((const GLenumString*) b)->e; | 
|  | 55 | } | 
|  | 56 |  | 
|  | 57 | static const char* GLEnumToString(GLenum e) { | 
|  | 58 | GLenumString key = {e, ""}; | 
|  | 59 | const GLenumString* result = (const GLenumString*) bsearch( | 
|  | 60 | &key, g_enumnames, | 
|  | 61 | sizeof(g_enumnames) / sizeof(g_enumnames[0]), | 
|  | 62 | sizeof(g_enumnames[0]), compareGLEnum); | 
|  | 63 | if (result) { | 
|  | 64 | return result->s; | 
|  | 65 | } | 
|  | 66 | return NULL; | 
|  | 67 | } | 
|  | 68 |  | 
| Jack Palevich | 6132b37 | 2010-10-27 15:34:11 -0700 | [diff] [blame] | 69 | static const char* GLbooleanToString(GLboolean arg) { | 
|  | 70 | return arg ? "GL_TRUE" : "GL_FALSE"; | 
|  | 71 | } | 
|  | 72 |  | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 73 | static GLenumString g_bitfieldNames[] = { | 
|  | 74 | {0x00004000, "GL_COLOR_BUFFER_BIT"}, | 
|  | 75 | {0x00000400, "GL_STENCIL_BUFFER_BIT"}, | 
|  | 76 | {0x00000100, "GL_DEPTH_BUFFER_BIT"} | 
|  | 77 | }; | 
|  | 78 |  | 
| Jack Palevich | 6132b37 | 2010-10-27 15:34:11 -0700 | [diff] [blame] | 79 | class StringBuilder { | 
|  | 80 | static const int lineSize = 500; | 
|  | 81 | char line[lineSize]; | 
|  | 82 | int line_index; | 
|  | 83 | public: | 
|  | 84 | StringBuilder() { | 
|  | 85 | line_index = 0; | 
|  | 86 | line[0] = '\0'; | 
|  | 87 | } | 
|  | 88 | void append(const char* fmt, ...) { | 
|  | 89 | va_list argp; | 
|  | 90 | va_start(argp, fmt); | 
|  | 91 | line_index += vsnprintf(line + line_index, lineSize-line_index, fmt, argp); | 
|  | 92 | va_end(argp); | 
|  | 93 | } | 
|  | 94 | const char* getString() { | 
|  | 95 | line_index = 0; | 
|  | 96 | line[lineSize-1] = '\0'; | 
|  | 97 | return line; | 
|  | 98 | } | 
|  | 99 | }; | 
|  | 100 |  | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 101 |  | 
|  | 102 | static void TraceGLShaderSource(GLuint shader, GLsizei count, | 
|  | 103 | const GLchar** string, const GLint* length) { | 
| Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 104 | ALOGD("const char* shaderSrc[] = {"); | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 105 | for (GLsizei i = 0; i < count; i++) { | 
|  | 106 | const char* comma = i < count-1 ? "," : ""; | 
|  | 107 | const GLchar* s = string[i]; | 
|  | 108 | if (length) { | 
|  | 109 | GLint len = length[i]; | 
| Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 110 | ALOGD("    \"%*s\"%s", len, s, comma); | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 111 | } else { | 
| Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 112 | ALOGD("    \"%s\"%s", s, comma); | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 113 | } | 
|  | 114 | } | 
| Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 115 | ALOGD("};"); | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 116 | if (length) { | 
| Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 117 | ALOGD("const GLint* shaderLength[] = {"); | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 118 | for (GLsizei i = 0; i < count; i++) { | 
|  | 119 | const char* comma = i < count-1 ? "," : ""; | 
|  | 120 | GLint len = length[i]; | 
| Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 121 | ALOGD("    \"%d\"%s", len, comma); | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 122 | } | 
| Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 123 | ALOGD("};"); | 
|  | 124 | ALOGD("glShaderSource(%u, %u, shaderSrc, shaderLength);", | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 125 | shader, count); | 
|  | 126 | } else { | 
| Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 127 | ALOGD("glShaderSource(%u, %u, shaderSrc, (const GLint*) 0);", | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 128 | shader, count); | 
|  | 129 | } | 
|  | 130 | } | 
|  | 131 |  | 
| Jack Palevich | 6132b37 | 2010-10-27 15:34:11 -0700 | [diff] [blame] | 132 | static void TraceValue(int elementCount, char type, | 
|  | 133 | GLsizei chunkCount, GLsizei chunkSize, const void* value) { | 
|  | 134 | StringBuilder stringBuilder; | 
|  | 135 | GLsizei count = chunkCount * chunkSize; | 
|  | 136 | bool isFloat = type == 'f'; | 
|  | 137 | const char* typeString = isFloat ? "GLfloat" : "GLint"; | 
| Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 138 | ALOGD("const %s value[] = {", typeString); | 
| Jack Palevich | 6132b37 | 2010-10-27 15:34:11 -0700 | [diff] [blame] | 139 | for (GLsizei i = 0; i < count; i++) { | 
|  | 140 | StringBuilder builder; | 
|  | 141 | builder.append("    "); | 
|  | 142 | for (int e = 0; e < elementCount; e++) { | 
|  | 143 | const char* comma = ", "; | 
|  | 144 | if (e == elementCount-1) { | 
|  | 145 | if (i == count - 1) { | 
|  | 146 | comma = ""; | 
|  | 147 | } else { | 
|  | 148 | comma = ","; | 
|  | 149 | } | 
|  | 150 | } | 
|  | 151 | if (isFloat) { | 
|  | 152 | builder.append("%g%s", * (GLfloat*) value, comma); | 
|  | 153 | value = (void*) (((GLfloat*) value) + 1); | 
|  | 154 | } else { | 
|  | 155 | builder.append("%d%s", * (GLint*) value, comma); | 
|  | 156 | value = (void*) (((GLint*) value) + 1); | 
|  | 157 | } | 
|  | 158 | } | 
| Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 159 | ALOGD("%s", builder.getString()); | 
| Jack Palevich | 6132b37 | 2010-10-27 15:34:11 -0700 | [diff] [blame] | 160 | if (chunkSize > 1 && i < count-1 | 
|  | 161 | && (i % chunkSize) == (chunkSize-1)) { | 
| Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 162 | ALOGD("%s", ""); // Print a blank line. | 
| Jack Palevich | 6132b37 | 2010-10-27 15:34:11 -0700 | [diff] [blame] | 163 | } | 
|  | 164 | } | 
| Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 165 | ALOGD("};"); | 
| Jack Palevich | 6132b37 | 2010-10-27 15:34:11 -0700 | [diff] [blame] | 166 | } | 
|  | 167 |  | 
|  | 168 | static void TraceUniformv(int elementCount, char type, | 
|  | 169 | GLuint location, GLsizei count, const void* value) { | 
|  | 170 | TraceValue(elementCount, type, count, 1, value); | 
| Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 171 | ALOGD("glUniform%d%c(%u, %u, value);", elementCount, type, location, count); | 
| Jack Palevich | 6132b37 | 2010-10-27 15:34:11 -0700 | [diff] [blame] | 172 | } | 
|  | 173 |  | 
|  | 174 | static void TraceUniformMatrix(int matrixSideLength, | 
|  | 175 | GLuint location, GLsizei count, GLboolean transpose, const void* value) { | 
|  | 176 | TraceValue(matrixSideLength, 'f', count, matrixSideLength, value); | 
| Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 177 | ALOGD("glUniformMatrix%dfv(%u, %u, %s, value);", matrixSideLength, location, count, | 
| Jack Palevich | 6132b37 | 2010-10-27 15:34:11 -0700 | [diff] [blame] | 178 | GLbooleanToString(transpose)); | 
|  | 179 | } | 
|  | 180 |  | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 181 | static void TraceGL(const char* name, int numArgs, ...) { | 
|  | 182 | va_list argp; | 
|  | 183 | va_start(argp, numArgs); | 
| Jack Palevich | 6132b37 | 2010-10-27 15:34:11 -0700 | [diff] [blame] | 184 | int nameLen = strlen(name); | 
|  | 185 |  | 
|  | 186 | // glShaderSource | 
|  | 187 | if (nameLen == 14 && strcmp(name, "glShaderSource") == 0) { | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 188 | va_arg(argp, const char*); | 
|  | 189 | GLuint shader = va_arg(argp, GLuint); | 
|  | 190 | va_arg(argp, const char*); | 
|  | 191 | GLsizei count = va_arg(argp, GLsizei); | 
|  | 192 | va_arg(argp, const char*); | 
|  | 193 | const GLchar** string = (const GLchar**) va_arg(argp, void*); | 
|  | 194 | va_arg(argp, const char*); | 
|  | 195 | const GLint* length = (const GLint*) va_arg(argp, void*); | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 196 | va_end(argp); | 
| Jack Palevich | 6132b37 | 2010-10-27 15:34:11 -0700 | [diff] [blame] | 197 | TraceGLShaderSource(shader, count, string, length); | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 198 | return; | 
|  | 199 | } | 
| Jack Palevich | 6132b37 | 2010-10-27 15:34:11 -0700 | [diff] [blame] | 200 |  | 
|  | 201 | // glUniformXXv | 
|  | 202 |  | 
|  | 203 | if (nameLen == 12 && strncmp(name, "glUniform", 9) == 0 && name[11] == 'v') { | 
|  | 204 | int elementCount = name[9] - '0'; // 1..4 | 
|  | 205 | char type = name[10]; // 'f' or 'i' | 
|  | 206 | va_arg(argp, const char*); | 
|  | 207 | GLuint location = va_arg(argp, GLuint); | 
|  | 208 | va_arg(argp, const char*); | 
|  | 209 | GLsizei count = va_arg(argp, GLsizei); | 
|  | 210 | va_arg(argp, const char*); | 
|  | 211 | const void* value = (const void*) va_arg(argp, void*); | 
|  | 212 | va_end(argp); | 
|  | 213 | TraceUniformv(elementCount, type, location, count, value); | 
|  | 214 | return; | 
|  | 215 | } | 
|  | 216 |  | 
|  | 217 | // glUniformMatrixXfv | 
|  | 218 |  | 
|  | 219 | if (nameLen == 18 && strncmp(name, "glUniformMatrix", 15) == 0 | 
|  | 220 | && name[16] == 'f' && name[17] == 'v') { | 
|  | 221 | int matrixSideLength = name[15] - '0'; // 2..4 | 
|  | 222 | va_arg(argp, const char*); | 
|  | 223 | GLuint location = va_arg(argp, GLuint); | 
|  | 224 | va_arg(argp, const char*); | 
|  | 225 | GLsizei count = va_arg(argp, GLsizei); | 
|  | 226 | va_arg(argp, const char*); | 
|  | 227 | GLboolean transpose = (GLboolean) va_arg(argp, int); | 
|  | 228 | va_arg(argp, const char*); | 
|  | 229 | const void* value = (const void*) va_arg(argp, void*); | 
|  | 230 | va_end(argp); | 
|  | 231 | TraceUniformMatrix(matrixSideLength, location, count, transpose, value); | 
|  | 232 | return; | 
|  | 233 | } | 
|  | 234 |  | 
|  | 235 | StringBuilder builder; | 
|  | 236 | builder.append("%s(", name); | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 237 | for (int i = 0; i < numArgs; i++) { | 
|  | 238 | if (i > 0) { | 
| Jack Palevich | 6132b37 | 2010-10-27 15:34:11 -0700 | [diff] [blame] | 239 | builder.append(", "); | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 240 | } | 
|  | 241 | const char* type = va_arg(argp, const char*); | 
|  | 242 | bool isPtr = type[strlen(type)-1] == '*' | 
|  | 243 | || strcmp(type, "GLeglImageOES") == 0; | 
|  | 244 | if (isPtr) { | 
|  | 245 | const void* arg = va_arg(argp, const void*); | 
| Jack Palevich | 6132b37 | 2010-10-27 15:34:11 -0700 | [diff] [blame] | 246 | builder.append("(%s) 0x%08x", type, (size_t) arg); | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 247 | } else if (strcmp(type, "GLbitfield") == 0) { | 
|  | 248 | size_t arg = va_arg(argp, size_t); | 
|  | 249 | bool first = true; | 
|  | 250 | for (size_t i = 0; i < sizeof(g_bitfieldNames) / sizeof(g_bitfieldNames[0]); i++) { | 
|  | 251 | const GLenumString* b = &g_bitfieldNames[i]; | 
|  | 252 | if (b->e & arg) { | 
|  | 253 | if (first) { | 
|  | 254 | first = false; | 
|  | 255 | } else { | 
| Jack Palevich | 6132b37 | 2010-10-27 15:34:11 -0700 | [diff] [blame] | 256 | builder.append(" | "); | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 257 | } | 
| Jack Palevich | 6132b37 | 2010-10-27 15:34:11 -0700 | [diff] [blame] | 258 | builder.append("%s", b->s); | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 259 | arg &= ~b->e; | 
|  | 260 | } | 
|  | 261 | } | 
|  | 262 | if (first || arg != 0) { | 
|  | 263 | if (!first) { | 
| Jack Palevich | 6132b37 | 2010-10-27 15:34:11 -0700 | [diff] [blame] | 264 | builder.append(" | "); | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 265 | } | 
| Jack Palevich | 6132b37 | 2010-10-27 15:34:11 -0700 | [diff] [blame] | 266 | builder.append("0x%08x", arg); | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 267 | } | 
|  | 268 | } else if (strcmp(type, "GLboolean") == 0) { | 
| Jack Palevich | 6132b37 | 2010-10-27 15:34:11 -0700 | [diff] [blame] | 269 | GLboolean arg = va_arg(argp, int); | 
|  | 270 | builder.append("%s", GLbooleanToString(arg)); | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 271 | } else if (strcmp(type, "GLclampf") == 0) { | 
|  | 272 | double arg = va_arg(argp, double); | 
| Jack Palevich | 6132b37 | 2010-10-27 15:34:11 -0700 | [diff] [blame] | 273 | builder.append("%g", arg); | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 274 | } else if (strcmp(type, "GLenum") == 0) { | 
|  | 275 | GLenum arg = va_arg(argp, int); | 
|  | 276 | const char* s = GLEnumToString(arg); | 
|  | 277 | if (s) { | 
| Jack Palevich | 6132b37 | 2010-10-27 15:34:11 -0700 | [diff] [blame] | 278 | builder.append("%s", s); | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 279 | } else { | 
| Jack Palevich | 6132b37 | 2010-10-27 15:34:11 -0700 | [diff] [blame] | 280 | builder.append("0x%x", arg); | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 281 | } | 
|  | 282 | } else if (strcmp(type, "GLfixed") == 0) { | 
|  | 283 | int arg = va_arg(argp, int); | 
| Jack Palevich | 6132b37 | 2010-10-27 15:34:11 -0700 | [diff] [blame] | 284 | builder.append("0x%08x", arg); | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 285 | } else if (strcmp(type, "GLfloat") == 0) { | 
|  | 286 | double arg = va_arg(argp, double); | 
| Jack Palevich | 6132b37 | 2010-10-27 15:34:11 -0700 | [diff] [blame] | 287 | builder.append("%g", arg); | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 288 | } else if (strcmp(type, "GLint") == 0) { | 
|  | 289 | int arg = va_arg(argp, int); | 
|  | 290 | const char* s = NULL; | 
|  | 291 | if (strcmp(name, "glTexParameteri") == 0) { | 
|  | 292 | s = GLEnumToString(arg); | 
|  | 293 | } | 
|  | 294 | if (s) { | 
| Jack Palevich | 6132b37 | 2010-10-27 15:34:11 -0700 | [diff] [blame] | 295 | builder.append("%s", s); | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 296 | } else { | 
| Jack Palevich | 6132b37 | 2010-10-27 15:34:11 -0700 | [diff] [blame] | 297 | builder.append("%d", arg); | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 298 | } | 
|  | 299 | } else if (strcmp(type, "GLintptr") == 0) { | 
|  | 300 | int arg = va_arg(argp, unsigned int); | 
| Jack Palevich | 6132b37 | 2010-10-27 15:34:11 -0700 | [diff] [blame] | 301 | builder.append("%u", arg); | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 302 | } else if (strcmp(type, "GLsizei") == 0) { | 
|  | 303 | int arg = va_arg(argp, size_t); | 
| Jack Palevich | 6132b37 | 2010-10-27 15:34:11 -0700 | [diff] [blame] | 304 | builder.append("%u", arg); | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 305 | } else if (strcmp(type, "GLsizeiptr") == 0) { | 
|  | 306 | int arg = va_arg(argp, size_t); | 
| Jack Palevich | 6132b37 | 2010-10-27 15:34:11 -0700 | [diff] [blame] | 307 | builder.append("%u", arg); | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 308 | } else if (strcmp(type, "GLuint") == 0) { | 
|  | 309 | int arg = va_arg(argp, unsigned int); | 
| Jack Palevich | 6132b37 | 2010-10-27 15:34:11 -0700 | [diff] [blame] | 310 | builder.append("%u", arg); | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 311 | } else { | 
| Jack Palevich | 6132b37 | 2010-10-27 15:34:11 -0700 | [diff] [blame] | 312 | builder.append("/* ??? %s */", type); | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 313 | break; | 
|  | 314 | } | 
|  | 315 | } | 
| Jack Palevich | 6132b37 | 2010-10-27 15:34:11 -0700 | [diff] [blame] | 316 | builder.append(");"); | 
| Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 317 | ALOGD("%s", builder.getString()); | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 318 | va_end(argp); | 
|  | 319 | } | 
|  | 320 |  | 
| Romain Guy | 16928bf | 2012-10-18 16:16:10 -0700 | [diff] [blame] | 321 | /////////////////////////////////////////////////////////////////////////// | 
|  | 322 | // Log trace | 
|  | 323 | /////////////////////////////////////////////////////////////////////////// | 
|  | 324 |  | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 325 | #undef TRACE_GL_VOID | 
|  | 326 | #undef TRACE_GL | 
|  | 327 |  | 
|  | 328 | #define TRACE_GL_VOID(_api, _args, _argList, ...)                         \ | 
|  | 329 | static void Tracing_ ## _api _args {                                      \ | 
|  | 330 | TraceGL(#_api, __VA_ARGS__);                                          \ | 
|  | 331 | gl_hooks_t::gl_t const * const _c = &getGLTraceThreadSpecific()->gl;  \ | 
|  | 332 | _c->_api _argList;                                                    \ | 
|  | 333 | } | 
|  | 334 |  | 
|  | 335 | #define TRACE_GL(_type, _api, _args, _argList, ...)                       \ | 
|  | 336 | static _type Tracing_ ## _api _args {                                     \ | 
| David Li | 2f5a655 | 2011-03-01 16:08:10 -0800 | [diff] [blame] | 337 | TraceGL(#_api, __VA_ARGS__);                                        \ | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 338 | gl_hooks_t::gl_t const * const _c = &getGLTraceThreadSpecific()->gl;  \ | 
|  | 339 | return _c->_api _argList;                                             \ | 
|  | 340 | } | 
|  | 341 |  | 
|  | 342 | extern "C" { | 
|  | 343 | #include "../trace.in" | 
|  | 344 | } | 
| David Li | 2f5a655 | 2011-03-01 16:08:10 -0800 | [diff] [blame] | 345 |  | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 346 | #undef TRACE_GL_VOID | 
|  | 347 | #undef TRACE_GL | 
|  | 348 |  | 
|  | 349 | #define GL_ENTRY(_r, _api, ...) Tracing_ ## _api, | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 350 | EGLAPI gl_hooks_t gHooksTrace = { | 
|  | 351 | { | 
|  | 352 | #include "entries.in" | 
|  | 353 | }, | 
|  | 354 | { | 
|  | 355 | {0} | 
|  | 356 | } | 
|  | 357 | }; | 
|  | 358 | #undef GL_ENTRY | 
|  | 359 |  | 
| David Li | 2f5a655 | 2011-03-01 16:08:10 -0800 | [diff] [blame] | 360 | #undef TRACE_GL_VOID | 
|  | 361 | #undef TRACE_GL | 
|  | 362 |  | 
| Romain Guy | 16928bf | 2012-10-18 16:16:10 -0700 | [diff] [blame] | 363 | /////////////////////////////////////////////////////////////////////////// | 
|  | 364 | // Systrace | 
|  | 365 | /////////////////////////////////////////////////////////////////////////// | 
|  | 366 |  | 
|  | 367 | #undef TRACE_GL_VOID | 
|  | 368 | #undef TRACE_GL | 
|  | 369 |  | 
|  | 370 | #define TRACE_GL_VOID(_api, _args, _argList, ...)                         \ | 
|  | 371 | static void Systrace_ ## _api _args {                                     \ | 
|  | 372 | ATRACE_NAME(#_api);                                                   \ | 
|  | 373 | gl_hooks_t::gl_t const * const _c = &getGLTraceThreadSpecific()->gl;  \ | 
|  | 374 | _c->_api _argList;                                                    \ | 
|  | 375 | } | 
|  | 376 |  | 
|  | 377 | #define TRACE_GL(_type, _api, _args, _argList, ...)                       \ | 
|  | 378 | static _type Systrace_ ## _api _args {                                    \ | 
|  | 379 | ATRACE_NAME(#_api);                                                   \ | 
|  | 380 | gl_hooks_t::gl_t const * const _c = &getGLTraceThreadSpecific()->gl;  \ | 
|  | 381 | return _c->_api _argList;                                             \ | 
|  | 382 | } | 
|  | 383 |  | 
|  | 384 | extern "C" { | 
|  | 385 | #include "../trace.in" | 
|  | 386 | } | 
|  | 387 |  | 
|  | 388 | #undef TRACE_GL_VOID | 
|  | 389 | #undef TRACE_GL | 
|  | 390 |  | 
|  | 391 | #define GL_ENTRY(_r, _api, ...) Systrace_ ## _api, | 
|  | 392 | EGLAPI gl_hooks_t gHooksSystrace = { | 
|  | 393 | { | 
|  | 394 | #include "entries.in" | 
|  | 395 | }, | 
|  | 396 | { | 
|  | 397 | {0} | 
|  | 398 | } | 
|  | 399 | }; | 
|  | 400 | #undef GL_ENTRY | 
|  | 401 |  | 
|  | 402 | /////////////////////////////////////////////////////////////////////////// | 
|  | 403 | // | 
|  | 404 | /////////////////////////////////////////////////////////////////////////// | 
|  | 405 |  | 
|  | 406 | #undef TRACE_GL_VOID | 
|  | 407 | #undef TRACE_GL | 
|  | 408 |  | 
|  | 409 | #define CHECK_ERROR(_c, _api)                                             \ | 
|  | 410 | GLenum status = GL_NO_ERROR;                                          \ | 
|  | 411 | bool error = false;                                                   \ | 
|  | 412 | while ((status = _c->glGetError()) != GL_NO_ERROR) {                  \ | 
|  | 413 | ALOGD("[" #_api "] 0x%x", status);                                \ | 
|  | 414 | error = true;                                                     \ | 
|  | 415 | }                                                                     \ | 
|  | 416 | if (error) {                                                          \ | 
|  | 417 | CallStack s;                                                      \ | 
|  | 418 | s.update();                                                       \ | 
| Igor Murashkin | 1f83633 | 2013-10-25 17:13:57 -0700 | [diff] [blame] | 419 | s.log("glGetError:" #_api);                                       \ | 
| Romain Guy | 16928bf | 2012-10-18 16:16:10 -0700 | [diff] [blame] | 420 | }                                                                     \ | 
|  | 421 |  | 
|  | 422 | #define TRACE_GL_VOID(_api, _args, _argList, ...)                         \ | 
|  | 423 | static void ErrorTrace_ ## _api _args {                                   \ | 
|  | 424 | gl_hooks_t::gl_t const * const _c = &getGLTraceThreadSpecific()->gl;  \ | 
|  | 425 | _c->_api _argList;                                                    \ | 
|  | 426 | CHECK_ERROR(_c, _api);                                                \ | 
|  | 427 | } | 
|  | 428 |  | 
|  | 429 | #define TRACE_GL(_type, _api, _args, _argList, ...)                       \ | 
|  | 430 | static _type ErrorTrace_ ## _api _args {                                  \ | 
|  | 431 | gl_hooks_t::gl_t const * const _c = &getGLTraceThreadSpecific()->gl;  \ | 
|  | 432 | _type _r = _c->_api _argList;                                         \ | 
|  | 433 | CHECK_ERROR(_c, _api);                                                \ | 
|  | 434 | return _r;                                                            \ | 
|  | 435 | } | 
|  | 436 |  | 
|  | 437 | extern "C" { | 
|  | 438 | #include "../trace.in" | 
|  | 439 | } | 
|  | 440 |  | 
|  | 441 | #undef TRACE_GL_VOID | 
|  | 442 | #undef TRACE_GL | 
|  | 443 |  | 
|  | 444 | #define GL_ENTRY(_r, _api, ...) ErrorTrace_ ## _api, | 
|  | 445 | EGLAPI gl_hooks_t gHooksErrorTrace = { | 
|  | 446 | { | 
|  | 447 | #include "entries.in" | 
|  | 448 | }, | 
|  | 449 | { | 
|  | 450 | {0} | 
|  | 451 | } | 
|  | 452 | }; | 
|  | 453 | #undef GL_ENTRY | 
|  | 454 | #undef CHECK_ERROR | 
|  | 455 |  | 
| David Li | 2f5a655 | 2011-03-01 16:08:10 -0800 | [diff] [blame] | 456 | #undef TRACE_GL_VOID | 
|  | 457 | #undef TRACE_GL | 
|  | 458 |  | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 459 | // ---------------------------------------------------------------------------- | 
|  | 460 | }; // namespace android | 
|  | 461 | // ---------------------------------------------------------------------------- | 
|  | 462 |  | 
|  | 463 | #endif // EGL_TRACE |