Bug 1238761 - Attach NativePanZoomController through GLController; r=snorp

This patch adds a way to attach a particular NativePanZoomController
instance held by LayerView to a particular nsWindow instance. Because
LayerView already calls GLController.SetLayerClient during
initialization, this patch renames it to attachToJava and modifies it to
accept an additional NPZC parameter. In the new AttachToJava
implementation, we create or reuse a NPZCSupport object and associate it
with the NPZC instance.
This commit is contained in:
Jim Chen 2016-01-15 13:05:45 -05:00
parent c5c166142e
commit ed32cfcb37
6 changed files with 45 additions and 28 deletions

View File

@ -69,9 +69,10 @@ public class GLController extends JNIObject {
@WrapForJNI @Override // JNIObject
protected native void disposeNative();
// Gecko thread sets its layer client instance; does not block UI thread.
// Gecko thread sets its Java instances; does not block UI thread.
@WrapForJNI
/* package */ native void setLayerClient(GeckoLayerClient layerClient);
/* package */ native void attachToJava(GeckoLayerClient layerClient,
NativePanZoomController npzc);
// Gecko thread creates compositor; blocks UI thread.
@WrapForJNI

View File

@ -433,11 +433,14 @@ public class LayerView extends ScrollView implements Tabs.OnTabsChangedListener
mGLController = glController;
glController.mView = this;
final NativePanZoomController npzc = AppConstants.MOZ_ANDROID_APZ ?
(NativePanZoomController) mPanZoomController : null;
if (GeckoThread.isStateAtLeast(GeckoThread.State.PROFILE_READY)) {
glController.setLayerClient(mLayerClient);
glController.attachToJava(mLayerClient, npzc);
} else {
GeckoThread.queueNativeCallUntil(GeckoThread.State.PROFILE_READY,
glController, "setLayerClient", mLayerClient);
glController, "attachToJava", mLayerClient, npzc);
}
}

View File

@ -239,6 +239,10 @@ class GLController::Natives : public mozilla::jni::NativeImpl<GLController, Impl
public:
static constexpr JNINativeMethod methods[] = {
mozilla::jni::MakeNativeMethod<GLController::AttachToJava_t>(
mozilla::jni::NativeStub<GLController::AttachToJava_t, Impl>
::template Wrap<&Impl::AttachToJava>),
mozilla::jni::MakeNativeMethod<GLController::CreateCompositor_t>(
mozilla::jni::NativeStub<GLController::CreateCompositor_t, Impl>
::template Wrap<&Impl::CreateCompositor>),
@ -251,10 +255,6 @@ public:
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>),

View File

@ -1242,6 +1242,9 @@ auto DisplayPortMetrics::Resolution() const -> float
constexpr char GLController::name[];
constexpr char GLController::AttachToJava_t::name[];
constexpr char GLController::AttachToJava_t::signature[];
constexpr char GLController::CreateCompositor_t::name[];
constexpr char GLController::CreateCompositor_t::signature[];
@ -1267,9 +1270,6 @@ 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[];

View File

@ -3349,6 +3349,23 @@ public:
protected:
GLController(jobject instance) : Class(instance) {}
public:
struct AttachToJava_t {
typedef GLController Owner;
typedef void ReturnType;
typedef void SetterType;
typedef mozilla::jni::Args<
mozilla::jni::Object::Param,
mozilla::jni::Object::Param> Args;
static constexpr char name[] = "attachToJava";
static constexpr char signature[] =
"(Lorg/mozilla/gecko/gfx/GeckoLayerClient;Lorg/mozilla/gecko/gfx/NativePanZoomController;)V";
static const bool isStatic = false;
static const bool isMultithreaded = false;
static const mozilla::jni::ExceptionMode exceptionMode =
mozilla::jni::ExceptionMode::ABORT;
};
public:
struct CreateCompositor_t {
typedef GLController Owner;
@ -3430,22 +3447,6 @@ public:
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;

View File

@ -742,6 +742,9 @@ public:
~GLControllerSupport()
{
if (window.mNPZCSupport) {
window.mNPZCSupport->DetachFromWindow();
}
mGLController->Destroy();
}
@ -803,7 +806,7 @@ private:
public:
using Base::DisposeNative;
void SetLayerClient(jni::Object::Param aClient)
void AttachToJava(jni::Object::Param aClient, jni::Object::Param aNPZC)
{
const auto& layerClient = GeckoLayerClient::Ref::From(aClient);
@ -825,6 +828,15 @@ public:
window.mCompositorParent->ForceIsFirstPaint();
}
}
#ifdef MOZ_ANDROID_APZ
MOZ_ASSERT(aNPZC);
auto npzc = NativePanZoomController::LocalRef(
jni::GetGeckoThreadEnv(),
NativePanZoomController::Ref::From(aNPZC));
NPZCSupport::AttachNative(
npzc, mozilla::MakeUnique<NPZCSupport>(&window, npzc));
#endif
}
void CreateCompositor(int32_t aWidth, int32_t aHeight)