blob: 0623a5d9e497b757dd4a31c00145da0c2ee82a30 [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
17#include <stdlib.h>
18#include <ctype.h>
19#include <string.h>
20#include <errno.h>
21
David Li28ca2ab2011-03-01 16:08:10 -080022#include <GLES2/gl2.h>
23#include <GLES2/gl2ext.h>
24
25#include <cutils/log.h>
David Li55c94cc2011-03-04 17:50:48 -080026#include <utils/Timers.h>
David Li28ca2ab2011-03-01 16:08:10 -080027#include <../../../libcore/include/StaticAssert.h>
28
29#define EGL_TRACE 1
30#include "hooks.h"
31
David Li5c425f22011-03-10 16:40:37 -080032#include "glesv2dbg.h"
33
David Li28ca2ab2011-03-01 16:08:10 -080034#define GL_ENTRY(_r, _api, ...) _r Debug_##_api ( __VA_ARGS__ );
David Li5c425f22011-03-10 16:40:37 -080035#include "glesv2dbg_functions.h"
David Li28ca2ab2011-03-01 16:08:10 -080036
David Li55c94cc2011-03-04 17:50:48 -080037#include "debugger_message.pb.h"
David Li28ca2ab2011-03-01 16:08:10 -080038
39using namespace android;
David Li55c94cc2011-03-04 17:50:48 -080040using namespace com::android;
David Li28ca2ab2011-03-01 16:08:10 -080041
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 Li28ca2ab2011-03-01 16:08:10 -080051#undef assert
David Li5c425f22011-03-10 16:40:37 -080052#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 -080053//#undef LOGD
54//#define LOGD(...)
55
56namespace android
57{
David Li5c425f22011-03-10 16:40:37 -080058
59struct DbgContext {
David Li6a5ca482011-03-21 10:02:30 -070060private:
61 unsigned lzf_bufSize;
David Lif9bc1242011-03-22 18:42:03 -070062
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 Li6a5ca482011-03-21 10:02:30 -070068public:
David Lif9bc1242011-03-22 18:42:03 -070069 char * lzf_buf; // auto malloc/free; output of lzf_compress
70
David Li5c425f22011-03-10 16:40:37 -080071 const unsigned version; // 0 is GLES1, 1 is GLES2
72 const gl_hooks_t * const hooks;
73 const unsigned MAX_VERTEX_ATTRIBS;
David Lif9bc1242011-03-22 18:42:03 -070074
David Li5c425f22011-03-10 16:40:37 -080075 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 Li6a5ca482011-03-21 10:02:30 -0700107 unsigned Compress(const void * in_data, unsigned in_len); // compressed to lzf_buf
David Lif9bc1242011-03-22 18:42:03 -0700108 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 Li5c425f22011-03-10 16:40:37 -0800114 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
125DbgContext * getDbgContextThreadSpecific();
126#define DBGCONTEXT(ctx) DbgContext * const ctx = getDbgContextThreadSpecific();
127
David Li55c94cc2011-03-04 17:50:48 -0800128struct FunctionCall {
129 virtual const int * operator()(gl_hooks_t::gl_t const * const _c, glesv2debugger::Message & msg) = 0;
130 virtual ~FunctionCall() {}
131};
David Li28ca2ab2011-03-01 16:08:10 -0800132
David Li940c3f82011-03-10 19:07:42 -0800133// move these into DbgContext as static
David Li55c94cc2011-03-04 17:50:48 -0800134extern bool capture;
135extern int timeMode; // SYSTEM_TIME_
136
137extern int clientSock, serverSock;
138
139unsigned GetBytesPerPixel(const GLenum format, const GLenum type);
140
David Li940c3f82011-03-10 19:07:42 -0800141// every Debug_gl* function calls this to send message to client and possibly receive commands
David Li55c94cc2011-03-04 17:50:48 -0800142int * MessageLoop(FunctionCall & functionCall, glesv2debugger::Message & msg,
143 const bool expectResponse, const glesv2debugger::Message_Function function);
David Li940c3f82011-03-10 19:07:42 -0800144
David Li55c94cc2011-03-04 17:50:48 -0800145void Receive(glesv2debugger::Message & cmd);
146float Send(const glesv2debugger::Message & msg, glesv2debugger::Message & cmd);
147void SetProp(const glesv2debugger::Message & cmd);
David Li28ca2ab2011-03-01 16:08:10 -0800148}; // namespace android {