blob: b79cc0fa25bae0cd6e5c3ca280f6dfee85340534 [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 {
60 const unsigned version; // 0 is GLES1, 1 is GLES2
61 const gl_hooks_t * const hooks;
62 const unsigned MAX_VERTEX_ATTRIBS;
63
64 struct VertexAttrib {
65 GLenum type; // element data type
66 unsigned size; // number of data per element
67 unsigned stride; // calculated number of bytes between elements
68 const void * ptr;
69 unsigned elemSize; // calculated number of bytes per element
70 GLuint buffer; // buffer name
71 GLboolean normalized : 1;
72 GLboolean enabled : 1;
73 VertexAttrib() : type(0), size(0), stride(0), ptr(NULL), elemSize(0),
74 buffer(0), normalized(0), enabled(0) {}
75 } * vertexAttribs;
76 bool hasNonVBOAttribs; // whether any enabled vertexAttrib is user pointer
77
78 struct VBO {
79 const GLuint name;
80 const GLenum target;
81 VBO * next;
82 void * data; // malloc/free
83 unsigned size; // in bytes
84 VBO(const GLuint name, const GLenum target, VBO * head) : name(name),
85 target(target), next(head), data(NULL), size(0) {}
86 } * indexBuffers; // linked list of all index buffers
87 VBO * indexBuffer; // currently bound index buffer
88
89 GLuint program;
90 unsigned maxAttrib; // number of slots used by program
91
92 DbgContext(const unsigned version, const gl_hooks_t * const hooks, const unsigned MAX_VERTEX_ATTRIBS);
93 ~DbgContext();
94
95 void Fetch(const unsigned index, std::string * const data) const;
96
97 void glUseProgram(GLuint program);
98 void glEnableVertexAttribArray(GLuint index);
99 void glDisableVertexAttribArray(GLuint index);
100 void glVertexAttribPointer(GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr);
101 void glBindBuffer(GLenum target, GLuint buffer);
102 void glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage);
103 void glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data);
104 void glDeleteBuffers(GLsizei n, const GLuint *buffers);
105};
106
107
108DbgContext * getDbgContextThreadSpecific();
109#define DBGCONTEXT(ctx) DbgContext * const ctx = getDbgContextThreadSpecific();
110
David Li55c94cc2011-03-04 17:50:48 -0800111struct FunctionCall {
112 virtual const int * operator()(gl_hooks_t::gl_t const * const _c, glesv2debugger::Message & msg) = 0;
113 virtual ~FunctionCall() {}
114};
David Li28ca2ab2011-03-01 16:08:10 -0800115
David Li940c3f82011-03-10 19:07:42 -0800116// move these into DbgContext as static
David Li55c94cc2011-03-04 17:50:48 -0800117extern bool capture;
118extern int timeMode; // SYSTEM_TIME_
119
120extern int clientSock, serverSock;
121
122unsigned GetBytesPerPixel(const GLenum format, const GLenum type);
123
David Li940c3f82011-03-10 19:07:42 -0800124// every Debug_gl* function calls this to send message to client and possibly receive commands
David Li55c94cc2011-03-04 17:50:48 -0800125int * MessageLoop(FunctionCall & functionCall, glesv2debugger::Message & msg,
126 const bool expectResponse, const glesv2debugger::Message_Function function);
David Li940c3f82011-03-10 19:07:42 -0800127
David Li55c94cc2011-03-04 17:50:48 -0800128void Receive(glesv2debugger::Message & cmd);
129float Send(const glesv2debugger::Message & msg, glesv2debugger::Message & cmd);
130void SetProp(const glesv2debugger::Message & cmd);
David Li28ca2ab2011-03-01 16:08:10 -0800131}; // namespace android {