Bug 844275 - Make the GLController a singleton instance. r=Cwiiis

This commit is contained in:
Kartikaya Gupta 2013-02-28 13:28:23 -05:00
Родитель 26c808678c
Коммит a6d771029a
6 изменённых файлов: 22 добавлений и 33 удалений

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

@ -14,10 +14,22 @@ import javax.microedition.khronos.egl.EGLContext;
import javax.microedition.khronos.egl.EGLDisplay;
import javax.microedition.khronos.egl.EGLSurface;
/**
* This class is a singleton that tracks EGL and compositor things over
* the lifetime of Fennec running.
* We only ever create one C++ compositor over Fennec's lifetime, but
* most of the Java-side objects (e.g. LayerView, GeckoLayerClient,
* LayerRenderer) can all get destroyed and re-created if the GeckoApp
* activity is destroyed. This GLController is never destroyed, so that
* the mCompositorCreated field and other state variables are always
* accurate.
*/
public class GLController {
private static final int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
private static final String LOGTAG = "GeckoGLController";
private static GLController sInstance;
private LayerView mView;
private boolean mSurfaceValid;
private int mWidth, mHeight;
@ -41,19 +53,15 @@ public class GLController {
EGL10.EGL_NONE
};
GLController(LayerView view) {
mView = view;
mSurfaceValid = false;
private GLController() {
}
/* This function is invoked by JNI */
void resumeCompositorIfValid() {
synchronized (this) {
if (!mSurfaceValid) {
return;
}
static GLController getInstance(LayerView view) {
if (sInstance == null) {
sInstance = new GLController();
}
resumeCompositor(mWidth, mHeight);
sInstance.mView = view;
return sInstance;
}
/* Wait until we are allowed to use EGL functions on the Surface backing

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

@ -91,7 +91,7 @@ public class LayerView extends FrameLayout {
public LayerView(Context context, AttributeSet attrs) {
super(context, attrs);
mGLController = new GLController(this);
mGLController = GLController.getInstance(this);
mPaintState = PAINT_START;
mBackgroundColor = Color.WHITE;
}

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

@ -1099,7 +1099,6 @@ AndroidBridge::SetLayerClient(JNIEnv* env, jobject jobj)
mLayerClient = client;
if (resetting) {
RegisterCompositor(env, true);
// since we are re-linking the new java objects to Gecko, we need to get
// the viewport from the compositor (since the Java copy was thrown away)
// and we do that by setting the first-paint flag.
@ -1123,7 +1122,7 @@ AndroidBridge::ShowInputMethodPicker()
static AndroidGLController sController;
void
AndroidBridge::RegisterCompositor(JNIEnv *env, bool resetting)
AndroidBridge::RegisterCompositor(JNIEnv *env)
{
ALOG_BRIDGE("AndroidBridge::RegisterCompositor");
if (!env)
@ -1139,11 +1138,7 @@ AndroidBridge::RegisterCompositor(JNIEnv *env, bool resetting)
if (jniFrame.CheckForException())
return;
if (resetting) {
sController.Reacquire(env, glController);
} else {
sController.Acquire(env, glController);
}
sController.Acquire(env, glController);
}
EGLSurface

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

@ -255,7 +255,7 @@ public:
bool GetShowPasswordSetting();
// Switch Java to composite with the Gecko Compositor thread
void RegisterCompositor(JNIEnv* env = NULL, bool resetting = false);
void RegisterCompositor(JNIEnv* env = NULL);
EGLSurface ProvideEGLSurface(bool waitUntilValid);
bool GetStaticStringField(const char *classID, const char *field, nsAString &result, JNIEnv* env = nullptr);

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

@ -28,7 +28,6 @@ void AndroidEGLObject::Init(JNIEnv* aJEnv) {
jmethodID AndroidGLController::jWaitForValidSurfaceMethod = 0;
jmethodID AndroidGLController::jProvideEGLSurfaceMethod = 0;
jmethodID AndroidGLController::jResumeCompositorIfValidMethod = 0;
void
AndroidGLController::Init(JNIEnv* aJEnv)
@ -37,7 +36,6 @@ AndroidGLController::Init(JNIEnv* aJEnv)
jProvideEGLSurfaceMethod = aJEnv->GetMethodID(jClass, "provideEGLSurface",
"()Ljavax/microedition/khronos/egl/EGLSurface;");
jResumeCompositorIfValidMethod = aJEnv->GetMethodID(jClass, "resumeCompositorIfValid", "()V");
jWaitForValidSurfaceMethod = aJEnv->GetMethodID(jClass, "waitForValidSurface", "()V");
}
@ -49,16 +47,6 @@ AndroidGLController::Acquire(JNIEnv* aJEnv, jobject aJObj)
mJObj = aJEnv->NewGlobalRef(aJObj);
}
void
AndroidGLController::Reacquire(JNIEnv *aJEnv, jobject aJObj)
{
aJEnv->DeleteGlobalRef(mJObj);
mJObj = aJEnv->NewGlobalRef(aJObj);
AutoLocalJNIFrame jniFrame(aJEnv, 0);
aJEnv->CallVoidMethod(mJObj, jResumeCompositorIfValidMethod);
}
EGLSurface
AndroidGLController::ProvideEGLSurface()
{

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

@ -21,14 +21,12 @@ public:
static void Init(JNIEnv* aJEnv);
void Acquire(JNIEnv* aJEnv, jobject aJObj);
void Reacquire(JNIEnv* aJEnv, jobject aJObj);
EGLSurface ProvideEGLSurface();
void WaitForValidSurface();
private:
static jmethodID jWaitForValidSurfaceMethod;
static jmethodID jProvideEGLSurfaceMethod;
static jmethodID jResumeCompositorIfValidMethod;
// the JNIEnv for the compositor thread
JNIEnv* mJEnv;