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

Commit 93a826f7 authored by Siva Velusamy's avatar Siva Velusamy
Browse files

gltrace: transport buffering and context management

This patch adds two improvements:
1. Protobuf messages are buffered and sent in chunks.
2. Multiple EGL contexts are handled properly: Corresponding
to each EGLContext, a GLTraceContext with a unique ID is created.
On eglMakeCurrent, the appropriate GLTraceContext is set and is
used while tracing subsequent GL Calls in that thread.

Change-Id: I34076376d3e5af205c87c7396ea47659844abd6e
parent 59511ad1
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -84,6 +84,9 @@ void initEglTraceLevel() {
    sEGLTraceLevel = propertyLevel > applicationLevel ? propertyLevel : applicationLevel;

    property_get("debug.egl.debug_proc", value, "");
    if (strlen(value) == 0)
        return;

    long pid = getpid();
    char procPath[128] = {};
    sprintf(procPath, "/proc/%ld/cmdline", pid);
@@ -91,9 +94,12 @@ void initEglTraceLevel() {
    if (file) {
        char cmdline[256] = {};
        if (fgets(cmdline, sizeof(cmdline) - 1, file)) {
            if (!strcmp(value, cmdline))
            if (!strncmp(value, cmdline, strlen(value))) {
                // set EGL debug if the "debug.egl.debug_proc" property
                // matches the prefix of this application's command line
                gEGLDebugLevel = 1;
            }
        }
        fclose(file);
    }

+1 −1
Original line number Diff line number Diff line
@@ -662,7 +662,7 @@ EGLBoolean eglMakeCurrent( EGLDisplay dpy, EGLSurface draw,
            egl_tls_t::setContext(ctx);
#if EGL_TRACE
            if (gEGLDebugLevel > 0)
                GLTrace_eglMakeCurrent(c->version, c->cnx->hooks[c->version]);
                GLTrace_eglMakeCurrent(c->version, c->cnx->hooks[c->version], ctx);
#endif
            _c.acquire();
            _r.acquire();
+752 −1128

File changed.

Preview size limit exceeded, changes collapsed.

+52 −6
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 */

#include <pthread.h>
#include <cutils/log.h>

extern "C" {
#include "liblzf/lzf.h"
@@ -42,12 +43,8 @@ void setGLTraceContext(GLTraceContext *c) {
    pthread_setspecific(sTLSKey, c);
}

void initContext(unsigned version, gl_hooks_t *hooks) {
void setupTraceContextThreadSpecific(GLTraceContext *context) {
    pthread_once(&sPthreadOnceKey, createTLSKey);

    GLTraceContext *context = new GLTraceContext();
    context->hooks = hooks;

    setGLTraceContext(context);
}

@@ -59,9 +56,47 @@ void releaseContext() {
    }
}

GLTraceContext::GLTraceContext() {
GLTraceState::GLTraceState(TCPStream *stream) {
    mTraceContextIds = 0;
    mStream = stream;
}

GLTraceState::~GLTraceState() {
    if (mStream) {
        mStream->closeStream();
        mStream = NULL;
    }
}

TCPStream *GLTraceState::getStream() {
    return mStream;
}

GLTraceContext *GLTraceState::createTraceContext(int version, EGLContext eglContext) {
    int id = __sync_fetch_and_add(&mTraceContextIds, 1);

    const size_t DEFAULT_BUFFER_SIZE = 8192;
    BufferedOutputStream *stream = new BufferedOutputStream(mStream, DEFAULT_BUFFER_SIZE);
    GLTraceContext *traceContext = new GLTraceContext(id, stream);
    mPerContextState[eglContext] = traceContext;

    return traceContext;
}

GLTraceContext *GLTraceState::getTraceContext(EGLContext c) {
    return mPerContextState[c];
}

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

    fbcontents = fbcompressed = NULL;
    fbcontentsSize = 0;
    mBufferedOutputStream = stream;
}

int GLTraceContext::getId() {
    return mId;
}

void GLTraceContext::resizeFBMemory(unsigned minSize) {
@@ -115,5 +150,16 @@ void GLTraceContext::getCompressedFB(void **fb, unsigned *fbsize, unsigned *fbwi
    *fbheight = viewport[3];
}

void GLTraceContext::traceGLMessage(GLMessage *msg) {
    mBufferedOutputStream->send(msg);

    GLMessage_Function func = msg->function();
    if (func == GLMessage::eglSwapBuffers
        || func == GLMessage::glDrawArrays
        || func == GLMessage::glDrawElements) {
        mBufferedOutputStream->flush();
    }
}

}; // namespace gltrace
}; // namespace android
+27 −3
Original line number Diff line number Diff line
@@ -17,7 +17,10 @@
#ifndef __GLTRACE_CONTEXT_H_
#define __GLTRACE_CONTEXT_H_

#include <map>

#include "hooks.h"
#include "gltrace_transport.h"

namespace android {
namespace gltrace {
@@ -26,24 +29,45 @@ using ::android::gl_hooks_t;

enum FBBinding {CURRENTLY_BOUND_FB, FB0};

/** GL Trace Context info associated with each EGLContext */
class GLTraceContext {
    int mId;                    /* unique context id */

    void *fbcontents;           /* memory area to read framebuffer contents */
    void *fbcompressed;         /* destination for lzf compressed framebuffer */
    unsigned fbcontentsSize;    /* size of fbcontents & fbcompressed buffers */

    BufferedOutputStream *mBufferedOutputStream; /* stream where trace info is sent */

    void resizeFBMemory(unsigned minSize);
public:
    gl_hooks_t *hooks;

    GLTraceContext();
    GLTraceContext(int id, BufferedOutputStream *stream);
    int getId();
    void getCompressedFB(void **fb, unsigned *fbsize,
                            unsigned *fbwidth, unsigned *fbheight,
                            FBBinding fbToRead);
    void traceGLMessage(GLMessage *msg);
};

/** Per process trace state. */
class GLTraceState {
    int mTraceContextIds;
    TCPStream *mStream;
    std::map<EGLContext, GLTraceContext*> mPerContextState;
public:
    GLTraceState(TCPStream *stream);
    ~GLTraceState();

    GLTraceContext *createTraceContext(int version, EGLContext c);
    GLTraceContext *getTraceContext(EGLContext c);

    TCPStream *getStream();
};

void setupTraceContextThreadSpecific(GLTraceContext *context);
GLTraceContext *getGLTraceContext();
void setGLTraceContext(GLTraceContext *c);
void initContext(unsigned version, gl_hooks_t *hooks);
void releaseContext();

};
Loading