Bug 1227706 - Add native methods to GLController; r=snorp

One nsWindow will have one corresponding GLController, and using native
GLController methods instead of GeckoEvents lets us control the
compositor for each nsWindow separately.
This commit is contained in:
Jim Chen 2015-12-23 22:03:34 -05:00
parent 6125552fa3
commit 93813233b3
5 changed files with 179 additions and 15 deletions

View File

@ -5,11 +5,10 @@
package org.mozilla.gecko.gfx;
import org.mozilla.gecko.annotation.WrapForJNI;
import org.mozilla.gecko.AppConstants;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.GeckoThread;
import org.mozilla.gecko.annotation.WrapForJNI;
import org.mozilla.gecko.mozglue.JNIObject;
import org.mozilla.gecko.util.ThreadUtils;
import android.util.Log;
@ -30,7 +29,7 @@ import javax.microedition.khronos.egl.EGLSurface;
* the mCompositorCreated field and other state variables are always
* accurate.
*/
public class GLController {
public class GLController extends JNIObject {
private static final int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
private static final String LOGTAG = "GeckoGLController";
@ -69,6 +68,28 @@ public class GLController {
EGL10.EGL_NONE
};
@WrapForJNI @Override // JNIObject
protected native void disposeNative();
// Gecko thread sets its layer client instance; does not block UI thread.
@WrapForJNI
/* package */ native void setLayerClient(GeckoLayerClient layerClient);
// Gecko thread creates compositor; blocks UI thread.
@WrapForJNI
private native void createCompositor(int width, int height);
// Gecko thread pauses compositor; blocks UI thread.
@WrapForJNI
private native void pauseCompositor();
// UI thread resumes compositor and notifies Gecko thread; does not block UI thread.
@WrapForJNI
private native void syncResumeResizeCompositor(int width, int height);
@WrapForJNI
/* package */ native void syncInvalidateAndScheduleComposite();
private GLController() {
}
@ -99,7 +120,7 @@ public class GLController {
// definitely paused -- it'll synchronize with the Gecko event loop, which
// in turn will synchronize with the compositor thread.
if (mCompositorCreated) {
GeckoAppShell.sendEventToGeckoSync(GeckoEvent.createCompositorPauseEvent());
pauseCompositor();
}
}
@ -143,7 +164,7 @@ public class GLController {
// happen without needing to block anywhere. Do it with a synchronous Gecko event so that the
// Android doesn't have a chance to destroy our surface in between.
if (mView.getLayerClient().isGeckoReady()) {
GeckoAppShell.sendEventToGeckoSync(GeckoEvent.createCompositorCreateEvent(mWidth, mHeight));
createCompositor(mWidth, mHeight);
}
}
@ -270,8 +291,7 @@ public class GLController {
// It is important to not notify Gecko until after the compositor has
// been resumed, otherwise Gecko may send updates that get dropped.
if (mCompositorCreated) {
GeckoAppShell.scheduleResumeComposition(width, height);
GeckoAppShell.sendEventToGecko(GeckoEvent.createCompositorResumeEvent());
syncResumeResizeCompositor(width, height);
mView.requestRender();
}
}

View File

@ -753,13 +753,7 @@ class GeckoLayerClient implements LayerView.Listener, PanZoomTarget
/** Implementation of LayerView.Listener */
@Override
public void renderRequested() {
try {
GeckoAppShell.invalidateAndScheduleComposite();
} catch (UnsupportedOperationException uoe) {
// In some very rare cases this gets called before libxul is loaded,
// so catch and ignore the exception that will throw. See bug 837821
Log.d(LOGTAG, "Dropping renderRequested call before libxul load.");
}
mView.getGLController().syncInvalidateAndScheduleComposite();
}
/** Implementation of LayerView.Listener */

View File

@ -233,6 +233,41 @@ public:
template<class Impl>
constexpr JNINativeMethod PrefsHelper::Natives<Impl>::methods[];
template<class Impl>
class GLController::Natives : public mozilla::jni::NativeImpl<GLController, Impl>
{
public:
static constexpr JNINativeMethod methods[] = {
mozilla::jni::MakeNativeMethod<GLController::CreateCompositor_t>(
mozilla::jni::NativeStub<GLController::CreateCompositor_t, Impl>
::template Wrap<&Impl::CreateCompositor>),
mozilla::jni::MakeNativeMethod<GLController::DisposeNative_t>(
mozilla::jni::NativeStub<GLController::DisposeNative_t, Impl>
::template Wrap<&Impl::DisposeNative>),
mozilla::jni::MakeNativeMethod<GLController::PauseCompositor_t>(
mozilla::jni::NativeStub<GLController::PauseCompositor_t, Impl>
::template Wrap<&Impl::PauseCompositor>),
mozilla::jni::MakeNativeMethod<GLController::SetLayerClient_t>(
mozilla::jni::NativeStub<GLController::SetLayerClient_t, Impl>
::template Wrap<&Impl::SetLayerClient>),
mozilla::jni::MakeNativeMethod<GLController::SyncInvalidateAndScheduleComposite_t>(
mozilla::jni::NativeStub<GLController::SyncInvalidateAndScheduleComposite_t, Impl>
::template Wrap<&Impl::SyncInvalidateAndScheduleComposite>),
mozilla::jni::MakeNativeMethod<GLController::SyncResumeResizeCompositor_t>(
mozilla::jni::NativeStub<GLController::SyncResumeResizeCompositor_t, Impl>
::template Wrap<&Impl::SyncResumeResizeCompositor>)
};
};
template<class Impl>
constexpr JNINativeMethod GLController::Natives<Impl>::methods[];
template<class Impl>
class NativeJSContainer::Natives : public mozilla::jni::NativeImpl<NativeJSContainer, Impl>
{

View File

@ -1242,6 +1242,9 @@ auto DisplayPortMetrics::Resolution() const -> float
constexpr char GLController::name[];
constexpr char GLController::CreateCompositor_t::name[];
constexpr char GLController::CreateCompositor_t::signature[];
constexpr char GLController::CreateEGLSurfaceForCompositorWrapper_t::name[];
constexpr char GLController::CreateEGLSurfaceForCompositorWrapper_t::signature[];
@ -1250,6 +1253,21 @@ auto GLController::CreateEGLSurfaceForCompositorWrapper() const -> mozilla::jni:
return mozilla::jni::Method<CreateEGLSurfaceForCompositorWrapper_t>::Call(this, nullptr);
}
constexpr char GLController::DisposeNative_t::name[];
constexpr char GLController::DisposeNative_t::signature[];
constexpr char GLController::PauseCompositor_t::name[];
constexpr char GLController::PauseCompositor_t::signature[];
constexpr char GLController::SetLayerClient_t::name[];
constexpr char GLController::SetLayerClient_t::signature[];
constexpr char GLController::SyncInvalidateAndScheduleComposite_t::name[];
constexpr char GLController::SyncInvalidateAndScheduleComposite_t::signature[];
constexpr char GLController::SyncResumeResizeCompositor_t::name[];
constexpr char GLController::SyncResumeResizeCompositor_t::signature[];
constexpr char GeckoLayerClient::name[];
constexpr char GeckoLayerClient::ActivateProgram_t::name[];

View File

@ -3350,6 +3350,23 @@ public:
protected:
GLController(jobject instance) : Class(instance) {}
public:
struct CreateCompositor_t {
typedef GLController Owner;
typedef void ReturnType;
typedef void SetterType;
typedef mozilla::jni::Args<
int32_t,
int32_t> Args;
static constexpr char name[] = "createCompositor";
static constexpr char signature[] =
"(II)V";
static const bool isStatic = false;
static const bool isMultithreaded = false;
static const mozilla::jni::ExceptionMode exceptionMode =
mozilla::jni::ExceptionMode::ABORT;
};
public:
struct CreateEGLSurfaceForCompositorWrapper_t {
typedef GLController Owner;
@ -3367,6 +3384,86 @@ public:
auto CreateEGLSurfaceForCompositorWrapper() const -> mozilla::jni::Object::LocalRef;
public:
struct DisposeNative_t {
typedef GLController Owner;
typedef void ReturnType;
typedef void SetterType;
typedef mozilla::jni::Args<> Args;
static constexpr char name[] = "disposeNative";
static constexpr char signature[] =
"()V";
static const bool isStatic = false;
static const bool isMultithreaded = false;
static const mozilla::jni::ExceptionMode exceptionMode =
mozilla::jni::ExceptionMode::ABORT;
};
public:
struct PauseCompositor_t {
typedef GLController Owner;
typedef void ReturnType;
typedef void SetterType;
typedef mozilla::jni::Args<> Args;
static constexpr char name[] = "pauseCompositor";
static constexpr char signature[] =
"()V";
static const bool isStatic = false;
static const bool isMultithreaded = false;
static const mozilla::jni::ExceptionMode exceptionMode =
mozilla::jni::ExceptionMode::ABORT;
};
public:
struct SetLayerClient_t {
typedef GLController Owner;
typedef void ReturnType;
typedef void SetterType;
typedef mozilla::jni::Args<
mozilla::jni::Object::Param> Args;
static constexpr char name[] = "setLayerClient";
static constexpr char signature[] =
"(Lorg/mozilla/gecko/gfx/GeckoLayerClient;)V";
static const bool isStatic = false;
static const bool isMultithreaded = false;
static const mozilla::jni::ExceptionMode exceptionMode =
mozilla::jni::ExceptionMode::ABORT;
};
public:
struct SyncInvalidateAndScheduleComposite_t {
typedef GLController Owner;
typedef void ReturnType;
typedef void SetterType;
typedef mozilla::jni::Args<> Args;
static constexpr char name[] = "syncInvalidateAndScheduleComposite";
static constexpr char signature[] =
"()V";
static const bool isStatic = false;
static const bool isMultithreaded = false;
static const mozilla::jni::ExceptionMode exceptionMode =
mozilla::jni::ExceptionMode::ABORT;
};
public:
struct SyncResumeResizeCompositor_t {
typedef GLController Owner;
typedef void ReturnType;
typedef void SetterType;
typedef mozilla::jni::Args<
int32_t,
int32_t> Args;
static constexpr char name[] = "syncResumeResizeCompositor";
static constexpr char signature[] =
"(II)V";
static const bool isStatic = false;
static const bool isMultithreaded = false;
static const mozilla::jni::ExceptionMode exceptionMode =
mozilla::jni::ExceptionMode::ABORT;
};
public:
template<class Impl> class Natives;
};
class GeckoLayerClient : public mozilla::jni::Class<GeckoLayerClient>