blob: 49f3847f5dc21377b1b3ede08a34348b6d828cfa [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;
David Lie7180e82011-04-08 18:45:45 -070090 const unsigned int readBytesPerPixel;
91
92 unsigned int captureSwap; // number of eglSwapBuffers to glReadPixels
93 unsigned int captureDraw; // number of glDrawArrays/Elements to glReadPixels
David Licbe4e5e2011-03-22 18:48:31 -070094
David Lifbfc7032011-03-21 16:25:58 -070095 GLFunctionBitfield expectResponse;
David Licbe4e5e2011-03-22 18:48:31 -070096
David Li5c425f22011-03-10 16:40:37 -080097 struct VertexAttrib {
98 GLenum type; // element data type
99 unsigned size; // number of data per element
100 unsigned stride; // calculated number of bytes between elements
101 const void * ptr;
102 unsigned elemSize; // calculated number of bytes per element
103 GLuint buffer; // buffer name
104 GLboolean normalized : 1;
105 GLboolean enabled : 1;
106 VertexAttrib() : type(0), size(0), stride(0), ptr(NULL), elemSize(0),
107 buffer(0), normalized(0), enabled(0) {}
108 } * vertexAttribs;
109 bool hasNonVBOAttribs; // whether any enabled vertexAttrib is user pointer
110
111 struct VBO {
112 const GLuint name;
113 const GLenum target;
114 VBO * next;
115 void * data; // malloc/free
116 unsigned size; // in bytes
117 VBO(const GLuint name, const GLenum target, VBO * head) : name(name),
118 target(target), next(head), data(NULL), size(0) {}
119 } * indexBuffers; // linked list of all index buffers
120 VBO * indexBuffer; // currently bound index buffer
121
122 GLuint program;
123 unsigned maxAttrib; // number of slots used by program
124
David Licbe4e5e2011-03-22 18:48:31 -0700125 DbgContext(const unsigned version, const gl_hooks_t * const hooks,
Mathias Agopian575e01c62011-09-13 18:15:50 -0700126 const unsigned MAX_VERTEX_ATTRIBS);
David Li5c425f22011-03-10 16:40:37 -0800127 ~DbgContext();
128
129 void Fetch(const unsigned index, std::string * const data) const;
David Licbe4e5e2011-03-22 18:48:31 -0700130 void Compress(const void * in_data, unsigned in_len, std::string * const outStr);
David Lie9f619f2011-04-14 11:20:22 -0700131 static unsigned char * Decompress(const void * in, const unsigned int inLen,
132 unsigned int * const outLen); // malloc/free
David Lif9bc1242011-03-22 18:42:03 -0700133 void * GetReadPixelsBuffer(const unsigned size);
134 bool IsReadPixelBuffer(const void * const ptr) {
135 return ptr == lzf_ref[lzf_readIndex];
136 }
David Licbe4e5e2011-03-22 18:48:31 -0700137 void CompressReadPixelBuffer(std::string * const outStr);
David Lie2ad4d02011-04-08 18:41:00 -0700138 char * GetBuffer(); // allocates lzf_buf if NULL
139 unsigned int GetBufferSize(); // allocates lzf_buf if NULL
David Lif9bc1242011-03-22 18:42:03 -0700140
David Li5c425f22011-03-10 16:40:37 -0800141 void glUseProgram(GLuint program);
142 void glEnableVertexAttribArray(GLuint index);
143 void glDisableVertexAttribArray(GLuint index);
David Licbe4e5e2011-03-22 18:48:31 -0700144 void glVertexAttribPointer(GLuint indx, GLint size, GLenum type,
145 GLboolean normalized, GLsizei stride, const GLvoid* ptr);
David Li5c425f22011-03-10 16:40:37 -0800146 void glBindBuffer(GLenum target, GLuint buffer);
147 void glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage);
148 void glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data);
149 void glDeleteBuffers(GLsizei n, const GLuint *buffers);
150};
151
David Li5c425f22011-03-10 16:40:37 -0800152DbgContext * getDbgContextThreadSpecific();
David Li5c425f22011-03-10 16:40:37 -0800153
David Li55c94cc2011-03-04 17:50:48 -0800154struct FunctionCall {
David Licbe4e5e2011-03-22 18:48:31 -0700155 virtual const int * operator()(gl_hooks_t::gl_t const * const _c,
156 glesv2debugger::Message & msg) = 0;
David Li55c94cc2011-03-04 17:50:48 -0800157 virtual ~FunctionCall() {}
158};
David Li28ca2ab2011-03-01 16:08:10 -0800159
David Li940c3f82011-03-10 19:07:42 -0800160// move these into DbgContext as static
David Li55c94cc2011-03-04 17:50:48 -0800161extern int timeMode; // SYSTEM_TIME_
162
163extern int clientSock, serverSock;
164
165unsigned GetBytesPerPixel(const GLenum format, const GLenum type);
166
David Li940c3f82011-03-10 19:07:42 -0800167// every Debug_gl* function calls this to send message to client and possibly receive commands
David Li55c94cc2011-03-04 17:50:48 -0800168int * MessageLoop(FunctionCall & functionCall, glesv2debugger::Message & msg,
David Lifbfc7032011-03-21 16:25:58 -0700169 const glesv2debugger::Message_Function function);
David Li940c3f82011-03-10 19:07:42 -0800170
David Li55c94cc2011-03-04 17:50:48 -0800171void Receive(glesv2debugger::Message & cmd);
172float Send(const glesv2debugger::Message & msg, glesv2debugger::Message & cmd);
David Lifbfc7032011-03-21 16:25:58 -0700173void SetProp(DbgContext * const dbg, const glesv2debugger::Message & cmd);
David Li291f5fe2011-03-21 17:42:50 -0700174const int * GenerateCall(DbgContext * const dbg, const glesv2debugger::Message & cmd,
David Licbe4e5e2011-03-22 18:48:31 -0700175 glesv2debugger::Message & msg, const int * const prevRet);
David Li28ca2ab2011-03-01 16:08:10 -0800176}; // namespace android {
David Lice30eb82011-03-28 10:39:28 -0700177
178#endif // #ifndef ANDROID_GLES2_DBG_HEADER_H