Bug 674753 - Add support for loading apitrace explicitly on Android - r=jrmuizel,bjacob

This commit is contained in:
George Wright 2012-02-29 16:55:46 -05:00
Родитель 72287d98e8
Коммит df4746de60
1 изменённых файлов: 60 добавлений и 11 удалений

Просмотреть файл

@ -39,6 +39,7 @@
*
* ***** END LICENSE BLOCK ***** */
#include "mozilla/Preferences.h"
#include "mozilla/Util.h"
#if defined(XP_UNIX)
@ -69,6 +70,12 @@
#include "AndroidBridge.h"
#endif
#include <android/log.h>
// We only need to explicitly dlopen egltrace
// on android as we can use LD_PRELOAD or other tricks
// on other platforms. We look for it in /data/local
// as that's writeable by all users
#define APITRACE_LIB "/data/local/egltrace.so"
#endif
#define EGL_LIB "libEGL.so"
@ -227,6 +234,38 @@ static EGLint gContextAttribsRobustness[] = {
LOCAL_EGL_NONE
};
static PRLibrary* LoadApitraceLibrary()
{
PRLibrary* sApitraceLibrary = NULL;
if (sApitraceLibrary)
return sApitraceLibrary;
#if defined(ANDROID)
nsCString logFile = Preferences::GetCString("gfx.apitrace.logfile");
if (logFile.IsEmpty()) {
logFile = "firefox.trace";
}
// The firefox process can't write to /data/local, but it can write
// to $GRE_HOME/
nsCAutoString logPath;
logPath.AppendPrintf("%s/%s", getenv("GRE_HOME"), logFile.get());
// apitrace uses the TRACE_FILE environment variable to determine where
// to log trace output to
printf_stderr("Logging GL tracing output to %s", logPath.get());
setenv("TRACE_FILE", logPath.get(), false);
printf_stderr("Attempting load of %s\n", APITRACE_LIB);
sApitraceLibrary = PR_LoadLibrary(APITRACE_LIB);
#endif
return sApitraceLibrary;
}
static int
next_power_of_two(int v)
{
@ -650,12 +689,17 @@ public:
#endif
if (!mEGLLibrary) {
mEGLLibrary = PR_LoadLibrary(EGL_LIB);
#if defined(XP_UNIX)
mEGLLibrary = LoadApitraceLibrary();
if (!mEGLLibrary) {
mEGLLibrary = PR_LoadLibrary(EGL_LIB1);
}
printf_stderr("Attempting load of %s\n", EGL_LIB);
mEGLLibrary = PR_LoadLibrary(EGL_LIB);
#if defined(XP_UNIX)
if (!mEGLLibrary) {
mEGLLibrary = PR_LoadLibrary(EGL_LIB1);
}
#endif
}
}
if (!mEGLLibrary) {
@ -1019,14 +1063,19 @@ public:
bool Init()
{
if (!OpenLibrary(GLES2_LIB)) {
#if defined(XP_UNIX)
if (!OpenLibrary(GLES2_LIB2)) {
NS_WARNING("Couldn't load EGL LIB.");
}
#if defined(ANDROID)
// We can't use LoadApitraceLibrary here because the GLContext
// expects its own handle to the GL library
if (!OpenLibrary(APITRACE_LIB))
#endif
return false;
}
if (!OpenLibrary(GLES2_LIB)) {
#if defined(XP_UNIX)
if (!OpenLibrary(GLES2_LIB2)) {
NS_WARNING("Couldn't load GLES2 LIB.");
return false;
}
#endif
}
bool current = MakeCurrent();
if (!current) {