blob: f2b1fa663598ee057012cda178a9a4cf38f899ad [file] [log] [blame]
David Li28ca2ab2011-03-01 16:08:10 -08001/*
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
David Lice30eb82011-03-28 10:39:28 -070017#ifndef ANDROID_GLES2_DBG_HEADER_H
18#define ANDROID_GLES2_DBG_HEADER_H
19
David Li28ca2ab2011-03-01 16:08:10 -080020#include <stdlib.h>
21#include <ctype.h>
22#include <string.h>
23#include <errno.h>
24
David Li28ca2ab2011-03-01 16:08:10 -080025#include <GLES2/gl2.h>
26#include <GLES2/gl2ext.h>
27
28#include <cutils/log.h>
David Li55c94cc2011-03-04 17:50:48 -080029#include <utils/Timers.h>
David Li28ca2ab2011-03-01 16:08:10 -080030
David Li28ca2ab2011-03-01 16:08:10 -080031#include "hooks.h"
32
David Li5c425f22011-03-10 16:40:37 -080033#include "glesv2dbg.h"
34
David Li28ca2ab2011-03-01 16:08:10 -080035#define GL_ENTRY(_r, _api, ...) _r Debug_##_api ( __VA_ARGS__ );
David Li5c425f22011-03-10 16:40:37 -080036#include "glesv2dbg_functions.h"
David Li28ca2ab2011-03-01 16:08:10 -080037
David Li55c94cc2011-03-04 17:50:48 -080038#include "debugger_message.pb.h"
David Li28ca2ab2011-03-01 16:08:10 -080039
40using namespace android;
David Li55c94cc2011-03-04 17:50:48 -080041using namespace com::android;
David Li28ca2ab2011-03-01 16:08:10 -080042
David Li28ca2ab2011-03-01 16:08:10 -080043#ifndef __location__
44#define __HIERALLOC_STRING_0__(s) #s
45#define __HIERALLOC_STRING_1__(s) __HIERALLOC_STRING_0__(s)
46#define __HIERALLOC_STRING_2__ __HIERALLOC_STRING_1__(__LINE__)
47#define __location__ __FILE__ ":" __HIERALLOC_STRING_2__
48#endif
49
David Li28ca2ab2011-03-01 16:08:10 -080050#undef assert
David Li5c425f22011-03-10 16:40:37 -080051#define assert(expr) if (!(expr)) { LOGD("\n*\n*\n* assert: %s at %s \n*\n*", #expr, __location__); int * x = 0; *x = 5; }
David Li28ca2ab2011-03-01 16:08:10 -080052//#undef LOGD
53//#define LOGD(...)
54
55namespace android
56{
David Li5c425f22011-03-10 16:40:37 -080057
David Licbe4e5e2011-03-22 18:48:31 -070058struct GLFunctionBitfield {
David Lifbfc7032011-03-21 16:25:58 -070059 unsigned char field [24]; // 8 * 24 = 192
David Licbe4e5e2011-03-22 18:48:31 -070060
61 void Bit(const glesv2debugger::Message_Function function, bool bit) {
David Lifbfc7032011-03-21 16:25:58 -070062 const unsigned byte = function / 8, mask = 1 << (function % 8);
63 if (bit)
64 field[byte] |= mask;
65 else
66 field[byte] &= ~mask;
67 }
David Licbe4e5e2011-03-22 18:48:31 -070068
69 bool Bit(const glesv2debugger::Message_Function function) const {
David Lifbfc7032011-03-21 16:25:58 -070070 const unsigned byte = function / 8, mask = 1 << (function % 8);
71 return field[byte] & mask;
72 }
73};
74
David Li5c425f22011-03-10 16:40:37 -080075struct DbgContext {
David Licbe4e5e2011-03-22 18:48:31 -070076 static const unsigned int LZF_CHUNK_SIZE = 256 * 1024;
David Lie9f619f2011-04-14 11:20:22 -070077
78private:
David Lie2ad4d02011-04-08 18:41:00 -070079 char * lzf_buf; // malloc / free; for lzf chunk compression and other uses
David Lif9bc1242011-03-22 18:42:03 -070080
81 // used as buffer and reference frame for ReadPixels; malloc/free
82 unsigned * lzf_ref [2];
83 unsigned lzf_readIndex; // 0 or 1
84 unsigned lzf_refSize, lzf_refBufSize; // bytes
85
David Li6a5ca482011-03-21 10:02:30 -070086public:
David Lie7180e82011-04-08 18:45:45 -070087 const unsigned int version; // 0 is GLES1, 1 is GLES2
David Li5c425f22011-03-10 16:40:37 -080088 const gl_hooks_t * const hooks;
David Lie7180e82011-04-08 18:45:45 -070089 const unsigned int MAX_VERTEX_ATTRIBS;
90 const GLenum readFormat, readType; // implementation supported glReadPixels
91 const unsigned int readBytesPerPixel;
92
93 unsigned int captureSwap; // number of eglSwapBuffers to glReadPixels
94 unsigned int captureDraw; // number of glDrawArrays/Elements to glReadPixels
David Licbe4e5e2011-03-22 18:48:31 -070095
David Lifbfc7032011-03-21 16:25:58 -070096 GLFunctionBitfield expectResponse;
David Licbe4e5e2011-03-22 18:48:31 -070097
David Li5c425f22011-03-10 16:40:37 -080098 struct VertexAttrib {
99 GLenum type; // element data type
100 unsigned size; // number of data per element
101 unsigned stride; // calculated number of bytes between elements
102 const void * ptr;
103 unsigned elemSize; // calculated number of bytes per element
104 GLuint buffer; // buffer name
105 GLboolean normalized : 1;
106 GLboolean enabled : 1;
107 VertexAttrib() : type(0), size(0), stride(0), ptr(NULL), elemSize(0),
108 buffer(0), normalized(0), enabled(0) {}
109 } * vertexAttribs;
110 bool hasNonVBOAttribs; // whether any enabled vertexAttrib is user pointer
111
112 struct VBO {
113 const GLuint name;
114 const GLenum target;
115 VBO * next;
116 void * data; // malloc/free
117 unsigned size; // in bytes
118 VBO(const GLuint name, const GLenum target, VBO * head) : name(name),
119 target(target), next(head), data(NULL), size(0) {}
120 } * indexBuffers; // linked list of all index buffers
121 VBO * indexBuffer; // currently bound index buffer
122
123 GLuint program;
124 unsigned maxAttrib; // number of slots used by program
125
David Licbe4e5e2011-03-22 18:48:31 -0700126 DbgContext(const unsigned version, const gl_hooks_t * const hooks,
David Lie7180e82011-04-08 18:45:45 -0700127 const unsigned MAX_VERTEX_ATTRIBS, const GLenum readFormat,
128 const GLenum readType);
David Li5c425f22011-03-10 16:40:37 -0800129 ~DbgContext();
130
131 void Fetch(const unsigned index, std::string * const data) const;
David Licbe4e5e2011-03-22 18:48:31 -0700132 void Compress(const void * in_data, unsigned in_len, std::string * const outStr);
David Lie9f619f2011-04-14 11:20:22 -0700133 static unsigned char * Decompress(const void * in, const unsigned int inLen,
134 unsigned int * const outLen); // malloc/free
David Lif9bc1242011-03-22 18:42:03 -0700135 void * GetReadPixelsBuffer(const unsigned size);
136 bool IsReadPixelBuffer(const void * const ptr) {
137 return ptr == lzf_ref[lzf_readIndex];
138 }
David Licbe4e5e2011-03-22 18:48:31 -0700139 void CompressReadPixelBuffer(std::string * const outStr);
David Lie2ad4d02011-04-08 18:41:00 -0700140 char * GetBuffer(); // allocates lzf_buf if NULL
141 unsigned int GetBufferSize(); // allocates lzf_buf if NULL
David Lif9bc1242011-03-22 18:42:03 -0700142
David Li5c425f22011-03-10 16:40:37 -0800143 void glUseProgram(GLuint program);
144 void glEnableVertexAttribArray(GLuint index);
145 void glDisableVertexAttribArray(GLuint index);
David Licbe4e5e2011-03-22 18:48:31 -0700146 void glVertexAttribPointer(GLuint indx, GLint size, GLenum type,
147 GLboolean normalized, GLsizei stride, const GLvoid* ptr);
David Li5c425f22011-03-10 16:40:37 -0800148 void glBindBuffer(GLenum target, GLuint buffer);
149 void glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage);
150 void glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data);
151 void glDeleteBuffers(GLsizei n, const GLuint *buffers);
152};
153
David Li5c425f22011-03-10 16:40:37 -0800154DbgContext * getDbgContextThreadSpecific();
David Li5c425f22011-03-10 16:40:37 -0800155
David Li55c94cc2011-03-04 17:50:48 -0800156struct FunctionCall {
David Licbe4e5e2011-03-22 18:48:31 -0700157 virtual const int * operator()(gl_hooks_t::gl_t const * const _c,
158 glesv2debugger::Message & msg) = 0;
David Li55c94cc2011-03-04 17:50:48 -0800159 virtual ~FunctionCall() {}
160};
David Li28ca2ab2011-03-01 16:08:10 -0800161
David Li940c3f82011-03-10 19:07:42 -0800162// move these into DbgContext as static
David Li55c94cc2011-03-04 17:50:48 -0800163extern int timeMode; // SYSTEM_TIME_
164
165extern int clientSock, serverSock;
166
167unsigned GetBytesPerPixel(const GLenum format, const GLenum type);
168
David Li940c3f82011-03-10 19:07:42 -0800169// every Debug_gl* function calls this to send message to client and possibly receive commands
David Li55c94cc2011-03-04 17:50:48 -0800170int * MessageLoop(FunctionCall & functionCall, glesv2debugger::Message & msg,
David Lifbfc7032011-03-21 16:25:58 -0700171 const glesv2debugger::Message_Function function);
David Li940c3f82011-03-10 19:07:42 -0800172
David Li55c94cc2011-03-04 17:50:48 -0800173void Receive(glesv2debugger::Message & cmd);
174float Send(const glesv2debugger::Message & msg, glesv2debugger::Message & cmd);
David Lifbfc7032011-03-21 16:25:58 -0700175void SetProp(DbgContext * const dbg, const glesv2debugger::Message & cmd);
David Li291f5fe2011-03-21 17:42:50 -0700176const int * GenerateCall(DbgContext * const dbg, const glesv2debugger::Message & cmd,
David Licbe4e5e2011-03-22 18:48:31 -0700177 glesv2debugger::Message & msg, const int * const prevRet);
David Li28ca2ab2011-03-01 16:08:10 -0800178}; // namespace android {
David Lice30eb82011-03-28 10:39:28 -0700179
180#endif // #ifndef ANDROID_GLES2_DBG_HEADER_H