Bug 1415994 - 5. Use LayerSession from GeckoSession; r=snorp

Make GeckoSession inherit from LayerSession, and connect its Compositor
to native code as part of the GeckoSession routine.

MozReview-Commit-ID: wQaH1A0a7z

--HG--
extra : rebase_source : ee4ae96e974d15c8cb9ad569ea9abf0ace4d0fa5
This commit is contained in:
Jim Chen 2017-11-14 18:18:35 -05:00
Родитель e029f5ee64
Коммит ff6c25061a
2 изменённых файлов: 52 добавлений и 52 удалений

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

@ -11,6 +11,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import org.mozilla.gecko.annotation.WrapForJNI;
import org.mozilla.gecko.gfx.LayerSession;
import org.mozilla.gecko.mozglue.JNIObject;
import org.mozilla.gecko.util.BundleEventListener;
import org.mozilla.gecko.util.EventCallback;
@ -31,7 +32,8 @@ import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
public class GeckoSession implements Parcelable {
public class GeckoSession extends LayerSession
implements Parcelable {
private static final String LOGTAG = "GeckoSession";
private static final boolean DEBUG = false;
@ -299,18 +301,20 @@ public class GeckoSession implements Parcelable {
}
@WrapForJNI(dispatchTo = "proxy")
static native void open(Window instance, EventDispatcher dispatcher,
GeckoBundle settings, String chromeUri,
int screenId, boolean privateMode);
public static native void open(Window instance, Compositor compositor,
EventDispatcher dispatcher,
GeckoBundle settings, String chromeUri,
int screenId, boolean privateMode);
@WrapForJNI(dispatchTo = "proxy")
@Override protected native void disposeNative();
@WrapForJNI(dispatchTo = "proxy")
native void close();
public native void close();
@WrapForJNI(dispatchTo = "proxy")
native void transfer(EventDispatcher dispatcher, GeckoBundle settings);
public native void transfer(Compositor compositor, EventDispatcher dispatcher,
GeckoBundle settings);
@WrapForJNI(calledFrom = "gecko")
private synchronized void onTransfer(final EventDispatcher dispatcher) {
@ -322,7 +326,7 @@ public class GeckoSession implements Parcelable {
}
@WrapForJNI(dispatchTo = "proxy")
native void attach(GeckoView view, Object compositor);
public native void attach(GeckoView view);
@WrapForJNI(calledFrom = "gecko")
private synchronized void onReady() {
@ -380,10 +384,11 @@ public class GeckoSession implements Parcelable {
if (mWindow != null) {
if (GeckoThread.isStateAtLeast(GeckoThread.State.PROFILE_READY)) {
mWindow.transfer(mEventDispatcher, mSettings.asBundle());
mWindow.transfer(mCompositor, mEventDispatcher, mSettings.asBundle());
} else {
GeckoThread.queueNativeCallUntil(GeckoThread.State.PROFILE_READY,
mWindow, "transfer",
Compositor.class, mCompositor,
EventDispatcher.class, mEventDispatcher,
GeckoBundle.class, mSettings.asBundle());
}
@ -483,13 +488,14 @@ public class GeckoSession implements Parcelable {
mWindow = new Window(mNativeQueue);
if (GeckoThread.isStateAtLeast(GeckoThread.State.PROFILE_READY)) {
Window.open(mWindow, mEventDispatcher, mSettings.asBundle(),
chromeUri, screenId, isPrivate);
Window.open(mWindow, mCompositor, mEventDispatcher,
mSettings.asBundle(), chromeUri, screenId, isPrivate);
} else {
GeckoThread.queueNativeCallUntil(
GeckoThread.State.PROFILE_READY,
Window.class, "open",
Window.class, mWindow,
Compositor.class, mCompositor,
EventDispatcher.class, mEventDispatcher,
GeckoBundle.class, mSettings.asBundle(),
String.class, chromeUri,
@ -503,12 +509,11 @@ public class GeckoSession implements Parcelable {
}
if (GeckoThread.isStateAtLeast(GeckoThread.State.PROFILE_READY)) {
mWindow.attach(view, view.getCompositor());
mWindow.attach(view);
} else {
GeckoThread.queueNativeCallUntil(GeckoThread.State.PROFILE_READY,
mWindow, "attach",
GeckoView.class, view,
Object.class, view.getCompositor());
GeckoView.class, view);
}
}

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

@ -279,6 +279,7 @@ public:
// Create and attach a window.
static void Open(const jni::Class::LocalRef& aCls,
GeckoSession::Window::Param aWindow,
jni::Object::Param aCompositor,
jni::Object::Param aDispatcher,
jni::Object::Param aSettings,
jni::String::Param aChromeURI,
@ -290,12 +291,13 @@ public:
// Transfer this nsWindow to new GeckoSession objects.
void Transfer(const GeckoSession::Window::LocalRef& inst,
jni::Object::Param aCompositor,
jni::Object::Param aDispatcher,
jni::Object::Param aSettings);
// Reattach this nsWindow to a new GeckoView.
void Attach(const GeckoSession::Window::LocalRef& inst,
jni::Object::Param aView, jni::Object::Param aCompositor);
jni::Object::Param aView);
void EnableEventDispatcher();
};
@ -1264,6 +1266,7 @@ nsWindow::GeckoViewSupport::~GeckoViewSupport()
/* static */ void
nsWindow::GeckoViewSupport::Open(const jni::Class::LocalRef& aCls,
GeckoSession::Window::Param aWindow,
jni::Object::Param aCompositor,
jni::Object::Param aDispatcher,
jni::Object::Param aSettings,
jni::String::Param aChromeURI,
@ -1287,12 +1290,11 @@ nsWindow::GeckoViewSupport::Open(const jni::Class::LocalRef& aCls,
}
}
// Prepare an nsIAndroidView to pass as argument to the window.
RefPtr<AndroidView> androidView = new AndroidView();
androidView->mEventDispatcher->Attach(
java::EventDispatcher::Ref::From(aDispatcher), nullptr);
if (aSettings) {
androidView->mSettings = java::GeckoBundle::Ref::From(aSettings);
}
androidView->mSettings = java::GeckoBundle::Ref::From(aSettings);
nsAutoCString chromeFlags("chrome,dialog=0,resizable,scrollbars");
if (aPrivateMode) {
@ -1312,10 +1314,15 @@ nsWindow::GeckoViewSupport::Open(const jni::Class::LocalRef& aCls,
window->SetScreenId(aScreenId);
// Attach a new GeckoView support object to the new window.
window->mGeckoViewSupport = mozilla::MakeUnique<GeckoViewSupport>(
window, (GeckoSession::Window::LocalRef(aCls.Env(), aWindow)));
GeckoSession::Window::LocalRef sessionWindow(aCls.Env(), aWindow);
window->mGeckoViewSupport =
mozilla::MakeUnique<GeckoViewSupport>(window, sessionWindow);
window->mGeckoViewSupport->mDOMWindow = pdomWindow;
window->mAndroidView = androidView;
// Attach other session support objects.
window->mGeckoViewSupport->Transfer(
sessionWindow, aCompositor, aDispatcher, aSettings);
// Attach a new GeckoEditable support object to the new window.
auto editable = GeckoEditable::New();
@ -1324,11 +1331,6 @@ nsWindow::GeckoViewSupport::Open(const jni::Class::LocalRef& aCls,
window->mEditable = editable;
window->mEditableSupport.Attach(editableChild, window, editableChild);
// Attach again using the new window.
androidView->mEventDispatcher->Attach(
java::EventDispatcher::Ref::From(aDispatcher), pdomWindow);
window->mAndroidView = androidView;
if (window->mWidgetListener) {
nsCOMPtr<nsIXULWindow> xulWindow(
window->mWidgetListener->GetXULWindow());
@ -1358,31 +1360,10 @@ nsWindow::GeckoViewSupport::Close()
void
nsWindow::GeckoViewSupport::Transfer(const GeckoSession::Window::LocalRef& inst,
jni::Object::Param aCompositor,
jni::Object::Param aDispatcher,
jni::Object::Param aSettings)
{
if (!window.mAndroidView) {
return;
}
window.mAndroidView->mEventDispatcher->Attach(
java::EventDispatcher::Ref::From(aDispatcher), mDOMWindow);
window.mAndroidView->mSettings = java::GeckoBundle::Ref::From(aSettings);
inst->OnTransfer(aDispatcher);
}
void
nsWindow::GeckoViewSupport::Attach(const GeckoSession::Window::LocalRef& inst,
jni::Object::Param aView,
jni::Object::Param aCompositor)
{
// Associate our previous GeckoEditable with the new GeckoView.
MOZ_ASSERT(window.mEditable);
window.mEditable->OnViewChange(aView);
// mNPZCSupport might have already been detached through the Java side calling
// NativePanZoomController.destroy().
if (window.mNPZCSupport) {
window.mNPZCSupport.Detach();
}
@ -1391,12 +1372,26 @@ nsWindow::GeckoViewSupport::Attach(const GeckoSession::Window::LocalRef& inst,
window.mLayerViewSupport.Detach();
}
if (aCompositor) {
auto compositor = LayerView::Compositor::LocalRef(
inst.Env(), LayerView::Compositor::Ref::From(aCompositor));
window.mLayerViewSupport.Attach(compositor, &window, compositor);
compositor->Reattach();
auto compositor = LayerSession::Compositor::LocalRef(
inst.Env(), LayerSession::Compositor::Ref::From(aCompositor));
window.mLayerViewSupport.Attach(compositor, &window, compositor);
if (window.mAndroidView) {
window.mAndroidView->mEventDispatcher->Attach(
java::EventDispatcher::Ref::From(aDispatcher), mDOMWindow);
window.mAndroidView->mSettings = java::GeckoBundle::Ref::From(aSettings);
}
inst->OnTransfer(aDispatcher);
}
void
nsWindow::GeckoViewSupport::Attach(const GeckoSession::Window::LocalRef& inst,
jni::Object::Param aView)
{
// Associate our previous GeckoEditable with the new GeckoView.
MOZ_ASSERT(window.mEditable);
window.mEditable->OnViewChange(aView);
}
void