Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1c5387e1 authored by Siva Velusamy's avatar Siva Velusamy
Browse files

gltrace: Send vertex attribute data after glDraw() call.

This patch enables tracing of vertex attribute data that
is specified using glVertexAttribPointer().

At the time the glVertexAttribPointer() call is made, we
only receive a pointer in client space, without any indication
of the size (# of attributes). This size is known only at
the time of the glDraw() call.

This patch generates a new message glVertexAttribPointerData()
when a draw call is issued that contains the vertex attribute
data.

A glDrawArrays() call directly gives the size of data to copy.
A glDrawElements() call gives the indices to copy. In such a
case, all data between the min & max indices drawn are copied
and sent to the host. To support glDrawElements() with an
element array buffer, this patch also adds state that maintains
a copy of all element array buffers.

Change-Id: I434da794a0aa9ada8e7474e219ffb1d79b183ecf
parent b5d3dd2c
Loading
Loading
Loading
Loading
+6 −7
Original line number Diff line number Diff line
@@ -6,10 +6,9 @@ genproto: gltrace.proto
	aprotoc --cpp_out=src --java_out=java gltrace.proto
	mv src/gltrace.pb.cc src/gltrace.pb.cpp

# NOTE: $OUT should be defined in the shell by doing a "lunch <config>"
# push updated files to device
push:
	adb push $(OUT)/system/lib/libGLESv2.so /system/lib/
	adb push $(OUT)/system/lib/libGLESv1_CM.so /system/lib/
	adb push $(OUT)/system/lib/libGLES_trace.so /system/lib/
	adb push $(OUT)/system/lib/libEGL.so /system/lib/
sync:
	adb root
	adb remount
	adb shell stop
	adb sync
	adb shell start
+1 −1
Original line number Diff line number Diff line
@@ -510,7 +510,7 @@ message GLMessage {
        eglGetSystemTimeNV = 2045;

        invalid = 3000;
        frameBufferContents = 3001;
        glVertexAttribPointerData = 3001;
    }

    // A GL call's return data and arguments are formatted into this DataType
+1 −1
Original line number Diff line number Diff line
@@ -1018,7 +1018,7 @@ const GLMessage_Function GLMessage::eglGetRenderBufferANDROID;
const GLMessage_Function GLMessage::eglGetSystemTimeFrequencyNV;
const GLMessage_Function GLMessage::eglGetSystemTimeNV;
const GLMessage_Function GLMessage::invalid;
const GLMessage_Function GLMessage::frameBufferContents;
const GLMessage_Function GLMessage::glVertexAttribPointerData;
const GLMessage_Function GLMessage::Function_MIN;
const GLMessage_Function GLMessage::Function_MAX;
const int GLMessage::Function_ARRAYSIZE;
+3 −3
Original line number Diff line number Diff line
@@ -535,11 +535,11 @@ enum GLMessage_Function {
  GLMessage_Function_eglGetSystemTimeFrequencyNV = 2044,
  GLMessage_Function_eglGetSystemTimeNV = 2045,
  GLMessage_Function_invalid = 3000,
  GLMessage_Function_frameBufferContents = 3001
  GLMessage_Function_glVertexAttribPointerData = 3001
};
bool GLMessage_Function_IsValid(int value);
const GLMessage_Function GLMessage_Function_Function_MIN = GLMessage_Function_glActiveTexture;
const GLMessage_Function GLMessage_Function_Function_MAX = GLMessage_Function_frameBufferContents;
const GLMessage_Function GLMessage_Function_Function_MAX = GLMessage_Function_glVertexAttribPointerData;
const int GLMessage_Function_Function_ARRAYSIZE = GLMessage_Function_Function_MAX + 1;

// ===================================================================
@@ -1351,7 +1351,7 @@ class GLMessage : public ::google::protobuf::MessageLite {
  static const Function eglGetSystemTimeFrequencyNV = GLMessage_Function_eglGetSystemTimeFrequencyNV;
  static const Function eglGetSystemTimeNV = GLMessage_Function_eglGetSystemTimeNV;
  static const Function invalid = GLMessage_Function_invalid;
  static const Function frameBufferContents = GLMessage_Function_frameBufferContents;
  static const Function glVertexAttribPointerData = GLMessage_Function_glVertexAttribPointerData;
  static inline bool Function_IsValid(int value) {
    return GLMessage_Function_IsValid(value);
  }
+75 −5
Original line number Diff line number Diff line
@@ -129,13 +129,14 @@ GLTraceContext *GLTraceState::getTraceContext(EGLContext c) {
    return mPerContextState[c];
}

GLTraceContext::GLTraceContext(int id, GLTraceState *state, BufferedOutputStream *stream) {
    mId = id;
    mState = state;

GLTraceContext::GLTraceContext(int id, GLTraceState *state, BufferedOutputStream *stream) :
    mId(id),
    mState(state),
    mBufferedOutputStream(stream),
    mElementArrayBuffers(DefaultKeyedVector<GLuint, ElementArrayBuffer*>(NULL))
{
    fbcontents = fbcompressed = NULL;
    fbcontentsSize = 0;
    mBufferedOutputStream = stream;
}

int GLTraceContext::getId() {
@@ -208,5 +209,74 @@ void GLTraceContext::traceGLMessage(GLMessage *msg) {
    }
}

void GLTraceContext::bindBuffer(GLuint bufferId, GLvoid *data, GLsizeiptr size) {
    // free previously bound buffer if any
    ElementArrayBuffer *oldBuffer = mElementArrayBuffers.valueFor(bufferId);
    if (oldBuffer != NULL) {
        delete oldBuffer;
    }

    mElementArrayBuffers.add(bufferId, new ElementArrayBuffer(data, size));
}

void GLTraceContext::getBuffer(GLuint bufferId, GLvoid **data, GLsizeiptr *size) {
    ElementArrayBuffer *buffer = mElementArrayBuffers.valueFor(bufferId);
    if (buffer == NULL) {
        *data = NULL;
        *size = 0;
    } else {
        *data = buffer->getBuffer();
        *size = buffer->getSize();
    }
}

void GLTraceContext::updateBufferSubData(GLuint bufferId, GLintptr offset, GLvoid *data,
                                                            GLsizeiptr size) {
    ElementArrayBuffer *buffer = mElementArrayBuffers.valueFor(bufferId);
    if (buffer != NULL) {
        buffer->updateSubBuffer(offset, data, size);
    }
}

void GLTraceContext::deleteBuffer(GLuint bufferId) {
    ElementArrayBuffer *buffer = mElementArrayBuffers.valueFor(bufferId);
    if (buffer != NULL) {
        delete buffer;
        mElementArrayBuffers.removeItem(bufferId);
    }
}

ElementArrayBuffer::ElementArrayBuffer(GLvoid *buf, GLsizeiptr size) {
    mBuf = malloc(size);
    mSize = size;

    if (buf != NULL) {
        memcpy(mBuf, buf, size);
    }
}

ElementArrayBuffer::~ElementArrayBuffer() {
    if (mBuf != NULL) {
        free(mBuf);
        mSize = 0;
    }

    mBuf = NULL;
}

void ElementArrayBuffer::updateSubBuffer(GLintptr offset, const GLvoid* data, GLsizeiptr size) {
    if (offset + size <= mSize) {
        memcpy((char*)mBuf + offset, data, size);
    }
}

GLvoid *ElementArrayBuffer::getBuffer() {
    return mBuf;
}

GLsizeiptr ElementArrayBuffer::getSize() {
    return mSize;
}

}; // namespace gltrace
}; // namespace android
Loading