gltrace_eglapi.cpp revision 93a826f78f6313db791e6fc880439189897651b3
1/* 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 <cutils/log.h> 19#include <cutils/properties.h> 20 21#include "hooks.h" 22#include "glestrace.h" 23 24#include "gltrace_context.h" 25#include "gltrace_egl.h" 26#include "gltrace_hooks.h" 27#include "gltrace_transport.h" 28 29namespace android { 30 31using gltrace::GLTraceState; 32using gltrace::GLTraceContext; 33using gltrace::TCPStream; 34 35static GLTraceState *sGLTraceState; 36 37void GLTrace_start() { 38 char value[PROPERTY_VALUE_MAX]; 39 40 property_get("debug.egl.debug_port", value, "5039"); 41 const unsigned short port = (unsigned short)atoi(value); 42 43 int clientSocket = gltrace::acceptClientConnection(port); 44 if (clientSocket < 0) { 45 LOGE("Error creating GLTrace server socket. Quitting application."); 46 exit(-1); 47 } 48 49 // create communication channel to the host 50 TCPStream *stream = new TCPStream(clientSocket); 51 52 // initialize tracing state 53 sGLTraceState = new GLTraceState(stream); 54} 55 56void GLTrace_stop() { 57 delete sGLTraceState; 58 sGLTraceState = NULL; 59} 60 61void GLTrace_eglCreateContext(int version, EGLContext c) { 62 // update trace state for new EGL context 63 GLTraceContext *traceContext = sGLTraceState->createTraceContext(version, c); 64 gltrace::setupTraceContextThreadSpecific(traceContext); 65 66 // trace command through to the host 67 gltrace::GLTrace_eglCreateContext(version, traceContext->getId()); 68} 69 70void GLTrace_eglMakeCurrent(const unsigned version, gl_hooks_t *hooks, EGLContext c) { 71 // setup per context state 72 GLTraceContext *traceContext = sGLTraceState->getTraceContext(c); 73 traceContext->hooks = hooks; 74 gltrace::setupTraceContextThreadSpecific(traceContext); 75 76 // trace command through to the host 77 gltrace::GLTrace_eglMakeCurrent(traceContext->getId()); 78} 79 80void GLTrace_eglReleaseThread() { 81 gltrace::releaseContext(); 82} 83 84void GLTrace_eglSwapBuffers(void *dpy, void *draw) { 85 gltrace::GLTrace_eglSwapBuffers(dpy, draw); 86} 87 88gl_hooks_t *GLTrace_getGLHooks() { 89 return gltrace::getGLHooks(); 90} 91 92} 93