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