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 { |
David Li | 6a5ca48 | 2011-03-21 10:02:30 -0700 | [diff] [blame^] | 60 | private: |
| 61 | unsigned lzf_bufSize; |
| 62 | |
| 63 | public: |
| 64 | char * lzf_buf; |
| 65 | |
David Li | 5c425f2 | 2011-03-10 16:40:37 -0800 | [diff] [blame] | 66 | const unsigned version; // 0 is GLES1, 1 is GLES2 |
| 67 | const gl_hooks_t * const hooks; |
| 68 | const unsigned MAX_VERTEX_ATTRIBS; |
| 69 | |
| 70 | struct VertexAttrib { |
| 71 | GLenum type; // element data type |
| 72 | unsigned size; // number of data per element |
| 73 | unsigned stride; // calculated number of bytes between elements |
| 74 | const void * ptr; |
| 75 | unsigned elemSize; // calculated number of bytes per element |
| 76 | GLuint buffer; // buffer name |
| 77 | GLboolean normalized : 1; |
| 78 | GLboolean enabled : 1; |
| 79 | VertexAttrib() : type(0), size(0), stride(0), ptr(NULL), elemSize(0), |
| 80 | buffer(0), normalized(0), enabled(0) {} |
| 81 | } * vertexAttribs; |
| 82 | bool hasNonVBOAttribs; // whether any enabled vertexAttrib is user pointer |
| 83 | |
| 84 | struct VBO { |
| 85 | const GLuint name; |
| 86 | const GLenum target; |
| 87 | VBO * next; |
| 88 | void * data; // malloc/free |
| 89 | unsigned size; // in bytes |
| 90 | VBO(const GLuint name, const GLenum target, VBO * head) : name(name), |
| 91 | target(target), next(head), data(NULL), size(0) {} |
| 92 | } * indexBuffers; // linked list of all index buffers |
| 93 | VBO * indexBuffer; // currently bound index buffer |
| 94 | |
| 95 | GLuint program; |
| 96 | unsigned maxAttrib; // number of slots used by program |
| 97 | |
| 98 | DbgContext(const unsigned version, const gl_hooks_t * const hooks, const unsigned MAX_VERTEX_ATTRIBS); |
| 99 | ~DbgContext(); |
| 100 | |
| 101 | void Fetch(const unsigned index, std::string * const data) const; |
David Li | 6a5ca48 | 2011-03-21 10:02:30 -0700 | [diff] [blame^] | 102 | unsigned Compress(const void * in_data, unsigned in_len); // compressed to lzf_buf |
| 103 | |
David Li | 5c425f2 | 2011-03-10 16:40:37 -0800 | [diff] [blame] | 104 | void glUseProgram(GLuint program); |
| 105 | void glEnableVertexAttribArray(GLuint index); |
| 106 | void glDisableVertexAttribArray(GLuint index); |
| 107 | void glVertexAttribPointer(GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr); |
| 108 | void glBindBuffer(GLenum target, GLuint buffer); |
| 109 | void glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage); |
| 110 | void glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data); |
| 111 | void glDeleteBuffers(GLsizei n, const GLuint *buffers); |
| 112 | }; |
| 113 | |
| 114 | |
| 115 | DbgContext * getDbgContextThreadSpecific(); |
| 116 | #define DBGCONTEXT(ctx) DbgContext * const ctx = getDbgContextThreadSpecific(); |
| 117 | |
David Li | 55c94cc | 2011-03-04 17:50:48 -0800 | [diff] [blame] | 118 | struct FunctionCall { |
| 119 | virtual const int * operator()(gl_hooks_t::gl_t const * const _c, glesv2debugger::Message & msg) = 0; |
| 120 | virtual ~FunctionCall() {} |
| 121 | }; |
David Li | 28ca2ab | 2011-03-01 16:08:10 -0800 | [diff] [blame] | 122 | |
David Li | 940c3f8 | 2011-03-10 19:07:42 -0800 | [diff] [blame] | 123 | // move these into DbgContext as static |
David Li | 55c94cc | 2011-03-04 17:50:48 -0800 | [diff] [blame] | 124 | extern bool capture; |
| 125 | extern int timeMode; // SYSTEM_TIME_ |
| 126 | |
| 127 | extern int clientSock, serverSock; |
| 128 | |
| 129 | unsigned GetBytesPerPixel(const GLenum format, const GLenum type); |
| 130 | |
David Li | 940c3f8 | 2011-03-10 19:07:42 -0800 | [diff] [blame] | 131 | // every Debug_gl* function calls this to send message to client and possibly receive commands |
David Li | 55c94cc | 2011-03-04 17:50:48 -0800 | [diff] [blame] | 132 | int * MessageLoop(FunctionCall & functionCall, glesv2debugger::Message & msg, |
| 133 | const bool expectResponse, const glesv2debugger::Message_Function function); |
David Li | 940c3f8 | 2011-03-10 19:07:42 -0800 | [diff] [blame] | 134 | |
David Li | 55c94cc | 2011-03-04 17:50:48 -0800 | [diff] [blame] | 135 | void Receive(glesv2debugger::Message & cmd); |
| 136 | float Send(const glesv2debugger::Message & msg, glesv2debugger::Message & cmd); |
| 137 | void SetProp(const glesv2debugger::Message & cmd); |
David Li | 28ca2ab | 2011-03-01 16:08:10 -0800 | [diff] [blame] | 138 | }; // namespace android { |