2012-02-01 09:02:55 -08:00
|
|
|
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
2012-05-21 04:12:37 -07:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2012-02-01 09:02:55 -08:00
|
|
|
|
2012-04-05 08:28:50 -07:00
|
|
|
#include "AndroidLayerViewWrapper.h"
|
2012-05-15 15:30:15 -07:00
|
|
|
#include "AndroidBridge.h"
|
2012-03-13 21:15:11 -07:00
|
|
|
#include "nsDebug.h"
|
2012-02-01 09:02:55 -08:00
|
|
|
|
2012-05-15 15:30:15 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2012-03-13 21:15:11 -07:00
|
|
|
#define ASSERT_THREAD() \
|
2012-04-05 08:28:50 -07:00
|
|
|
NS_ASSERTION(pthread_self() == mThread, "Something is calling AndroidGLController from the wrong thread!")
|
2012-02-01 13:18:35 -08:00
|
|
|
|
2012-02-02 08:17:50 -08:00
|
|
|
static jfieldID jEGLSurfacePointerField = 0;
|
|
|
|
|
|
|
|
void AndroidEGLObject::Init(JNIEnv* aJEnv) {
|
|
|
|
jclass jClass;
|
|
|
|
jClass = reinterpret_cast<jclass>
|
2012-03-13 21:15:11 -07:00
|
|
|
(aJEnv->NewGlobalRef(aJEnv->FindClass("com/google/android/gles_jni/EGLSurfaceImpl")));
|
|
|
|
jEGLSurfacePointerField = aJEnv->GetFieldID(jClass, "mEGLSurface", "I");
|
2012-02-02 08:17:50 -08:00
|
|
|
}
|
2012-02-01 13:18:35 -08:00
|
|
|
|
2012-02-01 09:02:55 -08:00
|
|
|
jmethodID AndroidGLController::jSetGLVersionMethod = 0;
|
2012-04-02 12:43:21 -07:00
|
|
|
jmethodID AndroidGLController::jWaitForValidSurfaceMethod = 0;
|
2012-02-06 13:53:09 -08:00
|
|
|
jmethodID AndroidGLController::jProvideEGLSurfaceMethod = 0;
|
2012-02-01 09:02:55 -08:00
|
|
|
|
|
|
|
void
|
2012-04-05 08:28:50 -07:00
|
|
|
AndroidGLController::Init(JNIEnv* aJEnv)
|
2012-02-01 09:02:55 -08:00
|
|
|
{
|
2012-03-13 21:15:11 -07:00
|
|
|
jclass jClass = reinterpret_cast<jclass>(aJEnv->NewGlobalRef(aJEnv->FindClass("org/mozilla/gecko/gfx/GLController")));
|
2012-02-01 09:02:55 -08:00
|
|
|
|
|
|
|
jSetGLVersionMethod = aJEnv->GetMethodID(jClass, "setGLVersion", "(I)V");
|
2012-02-06 13:53:09 -08:00
|
|
|
jProvideEGLSurfaceMethod = aJEnv->GetMethodID(jClass, "provideEGLSurface",
|
|
|
|
"()Ljavax/microedition/khronos/egl/EGLSurface;");
|
2012-04-02 12:43:21 -07:00
|
|
|
jWaitForValidSurfaceMethod = aJEnv->GetMethodID(jClass, "waitForValidSurface", "()V");
|
2012-02-01 09:02:55 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AndroidGLController::Acquire(JNIEnv* aJEnv, jobject aJObj)
|
|
|
|
{
|
|
|
|
mJEnv = aJEnv;
|
2012-04-05 08:28:50 -07:00
|
|
|
mThread = pthread_self();
|
2012-02-01 09:02:55 -08:00
|
|
|
mJObj = aJEnv->NewGlobalRef(aJObj);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AndroidGLController::SetGLVersion(int aVersion)
|
|
|
|
{
|
2012-03-13 21:15:11 -07:00
|
|
|
ASSERT_THREAD();
|
2012-05-15 15:30:15 -07:00
|
|
|
AutoLocalJNIFrame jniFrame(mJEnv, 0);
|
2012-02-01 09:02:55 -08:00
|
|
|
mJEnv->CallVoidMethod(mJObj, jSetGLVersionMethod, aVersion);
|
|
|
|
}
|
|
|
|
|
2012-02-06 13:53:09 -08:00
|
|
|
EGLSurface
|
|
|
|
AndroidGLController::ProvideEGLSurface()
|
|
|
|
{
|
2012-03-13 21:15:11 -07:00
|
|
|
ASSERT_THREAD();
|
2012-05-15 15:30:15 -07:00
|
|
|
AutoLocalJNIFrame jniFrame(mJEnv);
|
2012-02-06 13:53:09 -08:00
|
|
|
jobject jObj = mJEnv->CallObjectMethod(mJObj, jProvideEGLSurfaceMethod);
|
2012-05-18 05:59:01 -07:00
|
|
|
if (jniFrame.CheckForException())
|
|
|
|
return NULL;
|
|
|
|
|
2012-02-06 13:53:09 -08:00
|
|
|
return reinterpret_cast<EGLSurface>(mJEnv->GetIntField(jObj, jEGLSurfacePointerField));
|
|
|
|
}
|
2012-04-02 12:43:21 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
AndroidGLController::WaitForValidSurface()
|
|
|
|
{
|
|
|
|
ASSERT_THREAD();
|
2012-05-15 15:30:15 -07:00
|
|
|
AutoLocalJNIFrame jniFrame(mJEnv, 0);
|
2012-04-02 12:43:21 -07:00
|
|
|
mJEnv->CallVoidMethod(mJObj, jWaitForValidSurfaceMethod);
|
|
|
|
}
|