David Li | 28ca2ab | 2011-03-01 16:08:10 -0800 | [diff] [blame] | 1 | /* |
| 2 | ** Copyright 2011, 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 <stdlib.h> |
| 18 | #include <ctype.h> |
| 19 | #include <string.h> |
| 20 | #include <errno.h> |
| 21 | |
David Li | 28ca2ab | 2011-03-01 16:08:10 -0800 | [diff] [blame] | 22 | #include <GLES2/gl2.h> |
| 23 | #include <GLES2/gl2ext.h> |
| 24 | |
| 25 | #include <cutils/log.h> |
David Li | 55c94cc | 2011-03-04 17:50:48 -0800 | [diff] [blame] | 26 | #include <utils/Timers.h> |
David Li | 28ca2ab | 2011-03-01 16:08:10 -0800 | [diff] [blame] | 27 | #include <../../../libcore/include/StaticAssert.h> |
| 28 | |
| 29 | #define EGL_TRACE 1 |
| 30 | #include "hooks.h" |
| 31 | |
David Li | 5c425f2 | 2011-03-10 16:40:37 -0800 | [diff] [blame] | 32 | #include "glesv2dbg.h" |
| 33 | |
David Li | 28ca2ab | 2011-03-01 16:08:10 -0800 | [diff] [blame] | 34 | #define GL_ENTRY(_r, _api, ...) _r Debug_##_api ( __VA_ARGS__ ); |
David Li | 5c425f2 | 2011-03-10 16:40:37 -0800 | [diff] [blame] | 35 | #include "glesv2dbg_functions.h" |
David Li | 28ca2ab | 2011-03-01 16:08:10 -0800 | [diff] [blame] | 36 | |
David Li | 55c94cc | 2011-03-04 17:50:48 -0800 | [diff] [blame] | 37 | #include "debugger_message.pb.h" |
David Li | 28ca2ab | 2011-03-01 16:08:10 -0800 | [diff] [blame] | 38 | |
| 39 | using namespace android; |
David Li | 55c94cc | 2011-03-04 17:50:48 -0800 | [diff] [blame] | 40 | using namespace com::android; |
David Li | 28ca2ab | 2011-03-01 16:08:10 -0800 | [diff] [blame] | 41 | |
| 42 | #define API_ENTRY(_api) Debug_##_api |
| 43 | |
| 44 | #ifndef __location__ |
| 45 | #define __HIERALLOC_STRING_0__(s) #s |
| 46 | #define __HIERALLOC_STRING_1__(s) __HIERALLOC_STRING_0__(s) |
| 47 | #define __HIERALLOC_STRING_2__ __HIERALLOC_STRING_1__(__LINE__) |
| 48 | #define __location__ __FILE__ ":" __HIERALLOC_STRING_2__ |
| 49 | #endif |
| 50 | |
David Li | 28ca2ab | 2011-03-01 16:08:10 -0800 | [diff] [blame] | 51 | #undef assert |
David Li | 5c425f2 | 2011-03-10 16:40:37 -0800 | [diff] [blame] | 52 | #define assert(expr) if (!(expr)) { LOGD("\n*\n*\n* assert: %s at %s \n*\n*", #expr, __location__); int * x = 0; *x = 5; } |
David Li | 28ca2ab | 2011-03-01 16:08:10 -0800 | [diff] [blame] | 53 | //#undef LOGD |
| 54 | //#define LOGD(...) |
| 55 | |
| 56 | namespace android |
| 57 | { |
David Li | 5c425f2 | 2011-03-10 16:40:37 -0800 | [diff] [blame] | 58 | |
| 59 | struct DbgContext { |
| 60 | const unsigned version; // 0 is GLES1, 1 is GLES2 |
| 61 | const gl_hooks_t * const hooks; |
| 62 | const unsigned MAX_VERTEX_ATTRIBS; |
| 63 | |
| 64 | struct VertexAttrib { |
| 65 | GLenum type; // element data type |
| 66 | unsigned size; // number of data per element |
| 67 | unsigned stride; // calculated number of bytes between elements |
| 68 | const void * ptr; |
| 69 | unsigned elemSize; // calculated number of bytes per element |
| 70 | GLuint buffer; // buffer name |
| 71 | GLboolean normalized : 1; |
| 72 | GLboolean enabled : 1; |
| 73 | VertexAttrib() : type(0), size(0), stride(0), ptr(NULL), elemSize(0), |
| 74 | buffer(0), normalized(0), enabled(0) {} |
| 75 | } * vertexAttribs; |
| 76 | bool hasNonVBOAttribs; // whether any enabled vertexAttrib is user pointer |
| 77 | |
| 78 | struct VBO { |
| 79 | const GLuint name; |
| 80 | const GLenum target; |
| 81 | VBO * next; |
| 82 | void * data; // malloc/free |
| 83 | unsigned size; // in bytes |
| 84 | VBO(const GLuint name, const GLenum target, VBO * head) : name(name), |
| 85 | target(target), next(head), data(NULL), size(0) {} |
| 86 | } * indexBuffers; // linked list of all index buffers |
| 87 | VBO * indexBuffer; // currently bound index buffer |
| 88 | |
| 89 | GLuint program; |
| 90 | unsigned maxAttrib; // number of slots used by program |
| 91 | |
| 92 | DbgContext(const unsigned version, const gl_hooks_t * const hooks, const unsigned MAX_VERTEX_ATTRIBS); |
| 93 | ~DbgContext(); |
| 94 | |
| 95 | void Fetch(const unsigned index, std::string * const data) const; |
| 96 | |
| 97 | void glUseProgram(GLuint program); |
| 98 | void glEnableVertexAttribArray(GLuint index); |
| 99 | void glDisableVertexAttribArray(GLuint index); |
| 100 | void glVertexAttribPointer(GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr); |
| 101 | void glBindBuffer(GLenum target, GLuint buffer); |
| 102 | void glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage); |
| 103 | void glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data); |
| 104 | void glDeleteBuffers(GLsizei n, const GLuint *buffers); |
| 105 | }; |
| 106 | |
| 107 | |
| 108 | DbgContext * getDbgContextThreadSpecific(); |
| 109 | #define DBGCONTEXT(ctx) DbgContext * const ctx = getDbgContextThreadSpecific(); |
| 110 | |
David Li | 55c94cc | 2011-03-04 17:50:48 -0800 | [diff] [blame] | 111 | struct FunctionCall { |
| 112 | virtual const int * operator()(gl_hooks_t::gl_t const * const _c, glesv2debugger::Message & msg) = 0; |
| 113 | virtual ~FunctionCall() {} |
| 114 | }; |
David Li | 28ca2ab | 2011-03-01 16:08:10 -0800 | [diff] [blame] | 115 | |
David Li | 5c425f2 | 2011-03-10 16:40:37 -0800 | [diff] [blame] | 116 | // move these into DbgContext |
David Li | 55c94cc | 2011-03-04 17:50:48 -0800 | [diff] [blame] | 117 | extern bool capture; |
| 118 | extern int timeMode; // SYSTEM_TIME_ |
| 119 | |
| 120 | extern int clientSock, serverSock; |
| 121 | |
| 122 | unsigned GetBytesPerPixel(const GLenum format, const GLenum type); |
| 123 | |
| 124 | int * MessageLoop(FunctionCall & functionCall, glesv2debugger::Message & msg, |
| 125 | const bool expectResponse, const glesv2debugger::Message_Function function); |
| 126 | void Receive(glesv2debugger::Message & cmd); |
| 127 | float Send(const glesv2debugger::Message & msg, glesv2debugger::Message & cmd); |
| 128 | void SetProp(const glesv2debugger::Message & cmd); |
David Li | 28ca2ab | 2011-03-01 16:08:10 -0800 | [diff] [blame] | 129 | }; // namespace android { |