Bug 1453501 - Immediately create Compositor on Android r=jchen,rbarker

Currently we don't create the Compositor until we have a valid surface
to render into. This causes a race that can result in us not being able
to display anything at all once a surface is provided and the compositor
is started. It seems the easiest thing to do right now is to avoid the
race by starting the Compositor immediately.

MozReview-Commit-ID: HkdVL3LBNZB
This commit is contained in:
James Willcox 2018-04-25 15:04:14 -05:00
parent 369ac65ffe
commit 9299e02cdf
3 changed files with 14 additions and 42 deletions

View File

@ -82,10 +82,6 @@ public class LayerSession {
@WrapForJNI(calledFrom = "ui", dispatchTo = "gecko")
public native void onBoundsChanged(int left, int top, int width, int height);
// Gecko thread creates compositor; blocks UI thread.
@WrapForJNI(calledFrom = "ui", dispatchTo = "proxy")
public native void createCompositor(int width, int height, Object surface);
// Gecko thread pauses compositor; blocks UI thread.
@WrapForJNI(calledFrom = "ui", dispatchTo = "current")
public native void syncPauseCompositor();
@ -163,7 +159,6 @@ public class LayerSession {
private CompositorController mController;
private boolean mAttachedCompositor;
private boolean mCalledCreateCompositor;
private boolean mCompositorReady;
private Surface mSurface;
@ -361,6 +356,8 @@ public class LayerSession {
// Leave mSurface alone because we'll need it later for onCompositorReady.
onSurfaceChanged(mSurface, mWidth, mHeight);
}
mCompositor.sendToolbarAnimatorMessage(IS_COMPOSITOR_CONTROLLER_OPEN);
}
/* package */ void onCompositorDetached() {
@ -373,7 +370,6 @@ public class LayerSession {
}
mAttachedCompositor = false;
mCalledCreateCompositor = false;
mCompositorReady = false;
}
@ -552,12 +548,6 @@ public class LayerSession {
return;
}
if (mAttachedCompositor && !mCalledCreateCompositor) {
mCompositor.createCompositor(width, height, surface);
mCompositor.sendToolbarAnimatorMessage(IS_COMPOSITOR_CONTROLLER_OPEN);
mCalledCreateCompositor = true;
}
// We have a valid surface but we're not attached or the compositor
// is not ready; save the surface for later when we're ready.
mSurface = surface;

View File

@ -823,19 +823,6 @@ class nsWindow::LayerViewSupport final
public:
typedef LayerSession::Compositor::Natives<LayerViewSupport> Base;
template<class Functor>
static void OnNativeCall(Functor&& aCall)
{
if (aCall.IsTarget(&LayerViewSupport::CreateCompositor)) {
// This call is blocking.
nsAppShell::SyncRunEvent(nsAppShell::LambdaEvent<Functor>(
mozilla::Move(aCall)), &LayerViewEvent::MakeEvent);
return;
}
MOZ_CRASH("Unexpected call");
}
static LayerViewSupport*
FromNative(const LayerSession::Compositor::LocalRef& instance)
{
@ -930,20 +917,6 @@ public:
mWindow->Resize(aLeft, aTop, aWidth, aHeight, /* repaint */ false);
}
void CreateCompositor(int32_t aWidth, int32_t aHeight,
jni::Object::Param aSurface)
{
MOZ_ASSERT(NS_IsMainThread());
if (!mWindow) {
return; // Already shut down.
}
mSurface = aSurface;
mWindow->CreateLayerManager(aWidth, aHeight);
mCompositorPaused = false;
}
void SyncPauseCompositor()
{
MOZ_ASSERT(AndroidBridge::IsJavaUiThread());
@ -1423,6 +1396,14 @@ nsWindow::Create(nsIWidget* aParent,
mParent = parent;
}
// A default size of 1x1 confuses MobileViewportManager, so
// use 0x0 instead. This is also a little more fitting since
// we don't yet have a surface yet (and therefore a valid size)
// and 0x0 is usually recognized as invalid.
Resize(0, 0, false);
CreateLayerManager();
#ifdef DEBUG_ANDROID_WIDGET
DumpWindows();
#endif
@ -1859,7 +1840,7 @@ nsWindow::GetLayerManager(PLayerTransactionChild*, LayersBackend, LayerManagerPe
}
void
nsWindow::CreateLayerManager(int aCompositorWidth, int aCompositorHeight)
nsWindow::CreateLayerManager()
{
if (mLayerManager) {
return;
@ -1875,7 +1856,8 @@ nsWindow::CreateLayerManager(int aCompositorWidth, int aCompositorHeight)
gfxPlatform::GetPlatform();
if (ShouldUseOffMainThreadCompositing()) {
CreateCompositor(aCompositorWidth, aCompositorHeight);
LayoutDeviceIntRect rect = GetBounds();
CreateCompositor(rect.Width(), rect.Height());
if (mLayerManager) {
return;
}

View File

@ -341,7 +341,7 @@ protected:
static void LogWindow(nsWindow *win, int index, int indent);
private:
void CreateLayerManager(int aCompositorWidth, int aCompositorHeight);
void CreateLayerManager();
void RedrawAll();
mozilla::layers::LayersId GetRootLayerId() const;