gltrace_eglapi.cpp revision 93a826f78f6313db791e6fc880439189897651b3
10469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy/*
20469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy * Copyright 2011, The Android Open Source Project
30469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy *
40469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy * Licensed under the Apache License, Version 2.0 (the "License");
50469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy * you may not use this file except in compliance with the License.
60469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy * You may obtain a copy of the License at
70469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy *
80469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy *     http://www.apache.org/licenses/LICENSE-2.0
90469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy *
100469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy * Unless required by applicable law or agreed to in writing, software
110469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy * distributed under the License is distributed on an "AS IS" BASIS,
120469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
130469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy * See the License for the specific language governing permissions and
140469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy * limitations under the License.
150469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy */
160469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy
170469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#include <stdlib.h>
180469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#include <cutils/log.h>
190469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#include <cutils/properties.h>
200469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy
210469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#include "hooks.h"
220469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#include "glestrace.h"
230469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy
240469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#include "gltrace_context.h"
250469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#include "gltrace_egl.h"
260469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#include "gltrace_hooks.h"
270469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#include "gltrace_transport.h"
280469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy
290469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamynamespace android {
300469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy
3193a826f78f6313db791e6fc880439189897651b3Siva Velusamyusing gltrace::GLTraceState;
3293a826f78f6313db791e6fc880439189897651b3Siva Velusamyusing gltrace::GLTraceContext;
3393a826f78f6313db791e6fc880439189897651b3Siva Velusamyusing gltrace::TCPStream;
340469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy
3593a826f78f6313db791e6fc880439189897651b3Siva Velusamystatic GLTraceState *sGLTraceState;
360469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy
370469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamyvoid GLTrace_start() {
380469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy    char value[PROPERTY_VALUE_MAX];
390469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy
400469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy    property_get("debug.egl.debug_port", value, "5039");
410469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy    const unsigned short port = (unsigned short)atoi(value);
420469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy
4393a826f78f6313db791e6fc880439189897651b3Siva Velusamy    int clientSocket = gltrace::acceptClientConnection(port);
4493a826f78f6313db791e6fc880439189897651b3Siva Velusamy    if (clientSocket < 0) {
4593a826f78f6313db791e6fc880439189897651b3Siva Velusamy        LOGE("Error creating GLTrace server socket. Quitting application.");
4693a826f78f6313db791e6fc880439189897651b3Siva Velusamy        exit(-1);
4793a826f78f6313db791e6fc880439189897651b3Siva Velusamy    }
4893a826f78f6313db791e6fc880439189897651b3Siva Velusamy
4993a826f78f6313db791e6fc880439189897651b3Siva Velusamy    // create communication channel to the host
5093a826f78f6313db791e6fc880439189897651b3Siva Velusamy    TCPStream *stream = new TCPStream(clientSocket);
5193a826f78f6313db791e6fc880439189897651b3Siva Velusamy
5293a826f78f6313db791e6fc880439189897651b3Siva Velusamy    // initialize tracing state
5393a826f78f6313db791e6fc880439189897651b3Siva Velusamy    sGLTraceState = new GLTraceState(stream);
540469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy}
550469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy
560469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamyvoid GLTrace_stop() {
5793a826f78f6313db791e6fc880439189897651b3Siva Velusamy    delete sGLTraceState;
5893a826f78f6313db791e6fc880439189897651b3Siva Velusamy    sGLTraceState = NULL;
590469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy}
600469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy
6193a826f78f6313db791e6fc880439189897651b3Siva Velusamyvoid GLTrace_eglCreateContext(int version, EGLContext c) {
6293a826f78f6313db791e6fc880439189897651b3Siva Velusamy    // update trace state for new EGL context
6393a826f78f6313db791e6fc880439189897651b3Siva Velusamy    GLTraceContext *traceContext = sGLTraceState->createTraceContext(version, c);
6493a826f78f6313db791e6fc880439189897651b3Siva Velusamy    gltrace::setupTraceContextThreadSpecific(traceContext);
6593a826f78f6313db791e6fc880439189897651b3Siva Velusamy
6693a826f78f6313db791e6fc880439189897651b3Siva Velusamy    // trace command through to the host
6793a826f78f6313db791e6fc880439189897651b3Siva Velusamy    gltrace::GLTrace_eglCreateContext(version, traceContext->getId());
6893a826f78f6313db791e6fc880439189897651b3Siva Velusamy}
6993a826f78f6313db791e6fc880439189897651b3Siva Velusamy
7093a826f78f6313db791e6fc880439189897651b3Siva Velusamyvoid GLTrace_eglMakeCurrent(const unsigned version, gl_hooks_t *hooks, EGLContext c) {
7193a826f78f6313db791e6fc880439189897651b3Siva Velusamy    // setup per context state
7293a826f78f6313db791e6fc880439189897651b3Siva Velusamy    GLTraceContext *traceContext = sGLTraceState->getTraceContext(c);
7393a826f78f6313db791e6fc880439189897651b3Siva Velusamy    traceContext->hooks = hooks;
7493a826f78f6313db791e6fc880439189897651b3Siva Velusamy    gltrace::setupTraceContextThreadSpecific(traceContext);
7593a826f78f6313db791e6fc880439189897651b3Siva Velusamy
7693a826f78f6313db791e6fc880439189897651b3Siva Velusamy    // trace command through to the host
7793a826f78f6313db791e6fc880439189897651b3Siva Velusamy    gltrace::GLTrace_eglMakeCurrent(traceContext->getId());
7893a826f78f6313db791e6fc880439189897651b3Siva Velusamy}
7993a826f78f6313db791e6fc880439189897651b3Siva Velusamy
8093a826f78f6313db791e6fc880439189897651b3Siva Velusamyvoid GLTrace_eglReleaseThread() {
8193a826f78f6313db791e6fc880439189897651b3Siva Velusamy    gltrace::releaseContext();
820469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy}
830469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy
840469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamyvoid GLTrace_eglSwapBuffers(void *dpy, void *draw) {
850469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy    gltrace::GLTrace_eglSwapBuffers(dpy, draw);
860469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy}
870469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy
8893a826f78f6313db791e6fc880439189897651b3Siva Velusamygl_hooks_t *GLTrace_getGLHooks() {
8993a826f78f6313db791e6fc880439189897651b3Siva Velusamy    return gltrace::getGLHooks();
9093a826f78f6313db791e6fc880439189897651b3Siva Velusamy}
9193a826f78f6313db791e6fc880439189897651b3Siva Velusamy
920469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy}
93