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.EGLDisplay;
import javax.microedition.khronos.egl.EGLSurface; 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 { public class GLController {
private static final int EGL_CONTEXT_CLIENT_VERSION = 0x3098; private static final int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
private static final String LOGTAG = "GeckoGLController"; private static final String LOGTAG = "GeckoGLController";
private static GLController sInstance;
private LayerView mView; private LayerView mView;
private boolean mSurfaceValid; private boolean mSurfaceValid;
private int mWidth, mHeight; private int mWidth, mHeight;
@ -41,19 +53,15 @@ public class GLController {
EGL10.EGL_NONE EGL10.EGL_NONE
}; };
GLController(LayerView view) { private GLController() {
mView = view;
mSurfaceValid = false;
} }
/* This function is invoked by JNI */ static GLController getInstance(LayerView view) {
void resumeCompositorIfValid() { if (sInstance == null) {
synchronized (this) { sInstance = new GLController();
if (!mSurfaceValid) {
return;
} }
} sInstance.mView = view;
resumeCompositor(mWidth, mHeight); return sInstance;
} }
/* Wait until we are allowed to use EGL functions on the Surface backing /* 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) { public LayerView(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
mGLController = new GLController(this); mGLController = GLController.getInstance(this);
mPaintState = PAINT_START; mPaintState = PAINT_START;
mBackgroundColor = Color.WHITE; mBackgroundColor = Color.WHITE;
} }

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

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

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

@ -255,7 +255,7 @@ public:
bool GetShowPasswordSetting(); bool GetShowPasswordSetting();
// Switch Java to composite with the Gecko Compositor thread // 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); EGLSurface ProvideEGLSurface(bool waitUntilValid);
bool GetStaticStringField(const char *classID, const char *field, nsAString &result, JNIEnv* env = nullptr); 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::jWaitForValidSurfaceMethod = 0;
jmethodID AndroidGLController::jProvideEGLSurfaceMethod = 0; jmethodID AndroidGLController::jProvideEGLSurfaceMethod = 0;
jmethodID AndroidGLController::jResumeCompositorIfValidMethod = 0;
void void
AndroidGLController::Init(JNIEnv* aJEnv) AndroidGLController::Init(JNIEnv* aJEnv)
@ -37,7 +36,6 @@ AndroidGLController::Init(JNIEnv* aJEnv)
jProvideEGLSurfaceMethod = aJEnv->GetMethodID(jClass, "provideEGLSurface", jProvideEGLSurfaceMethod = aJEnv->GetMethodID(jClass, "provideEGLSurface",
"()Ljavax/microedition/khronos/egl/EGLSurface;"); "()Ljavax/microedition/khronos/egl/EGLSurface;");
jResumeCompositorIfValidMethod = aJEnv->GetMethodID(jClass, "resumeCompositorIfValid", "()V");
jWaitForValidSurfaceMethod = aJEnv->GetMethodID(jClass, "waitForValidSurface", "()V"); jWaitForValidSurfaceMethod = aJEnv->GetMethodID(jClass, "waitForValidSurface", "()V");
} }
@ -49,16 +47,6 @@ AndroidGLController::Acquire(JNIEnv* aJEnv, jobject aJObj)
mJObj = aJEnv->NewGlobalRef(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 EGLSurface
AndroidGLController::ProvideEGLSurface() AndroidGLController::ProvideEGLSurface()
{ {

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

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