Bug 735230 - Part 2: Add compositor pause/resume events to Gecko. r=kats

This commit is contained in:
Ali Juma 2012-03-28 18:00:32 -04:00
parent eac3276684
commit e7e968bb4b
7 changed files with 67 additions and 23 deletions

View File

@ -96,6 +96,8 @@ public class GeckoEvent {
private static final int SCREENSHOT = 25;
private static final int UNUSED2_EVENT = 26;
private static final int SCREENORIENTATION_CHANGED = 27;
private static final int COMPOSITOR_PAUSE = 28;
private static final int COMPOSITOR_RESUME = 29;
public static final int IME_COMPOSITION_END = 0;
public static final int IME_COMPOSITION_BEGIN = 1;
@ -186,6 +188,14 @@ public class GeckoEvent {
return event;
}
public static GeckoEvent createCompositorPauseEvent() {
return new GeckoEvent(COMPOSITOR_PAUSE);
}
public static GeckoEvent createCompositorResumeEvent() {
return new GeckoEvent(COMPOSITOR_RESUME);
}
private void initKeyEvent(KeyEvent k) {
mAction = k.getAction();
mTime = k.getEventTime();

View File

@ -1875,15 +1875,6 @@ AndroidBridge::IsTablet()
return env->CallStaticBooleanMethod(mGeckoAppShellClass, jIsTablet);
}
void
AndroidBridge::SetCompositorParent(mozilla::layers::CompositorParent* aCompositorParent,
::base::Thread* aCompositorThread)
{
#ifdef MOZ_JAVA_COMPOSITOR
nsWindow::SetCompositorParent(aCompositorParent, aCompositorThread);
#endif
}
void
AndroidBridge::SetFirstPaintViewport(float aOffsetX, float aOffsetY, float aZoom, float aPageWidth, float aPageHeight)
{

View File

@ -405,8 +405,6 @@ public:
void EnableNetworkNotifications();
void DisableNetworkNotifications();
void SetCompositorParent(mozilla::layers::CompositorParent* aCompositorParent,
base::Thread* aCompositorThread);
void SetFirstPaintViewport(float aOffsetX, float aOffsetY, float aZoom, float aPageWidth, float aPageHeight);
void SetPageSize(float aZoom, float aPageWidth, float aPageHeight);
void SyncViewportInfo(const nsIntRect& aDisplayPort, float aDisplayResolution, bool aLayersUpdated,

View File

@ -589,6 +589,8 @@ public:
SCREENSHOT = 25,
UNUSED2_EVENT = 26,
SCREENORIENTATION_CHANGED = 27,
COMPOSITOR_PAUSE = 28,
COMPOSITOR_RESUME = 29,
dummy_java_enum_list_end
};

View File

@ -616,6 +616,16 @@ nsAppShell::PostEvent(AndroidGeckoEvent *ae)
delete event;
}
}
} else if (ae->Type() == AndroidGeckoEvent::COMPOSITOR_PAUSE ||
ae->Type() == AndroidGeckoEvent::COMPOSITOR_RESUME) {
// Give priority to these events, but maintain their order wrt each other.
int i = 0;
while (i < mEventQueue.Length() &&
(mEventQueue[i]->Type() == AndroidGeckoEvent::COMPOSITOR_PAUSE ||
mEventQueue[i]->Type() == AndroidGeckoEvent::COMPOSITOR_RESUME)) {
i++;
}
mEventQueue.InsertElementAt(i, ae);
} else if (ae->Type() == AndroidGeckoEvent::SENSOR_EVENT) {
if (!mPendingSensorEvents)
mEventQueue.AppendElement(ae);

View File

@ -214,9 +214,9 @@ nsWindow::~nsWindow()
mRootAccessible = nsnull;
#endif
ALOG("nsWindow %p destructor", (void*)this);
AndroidBridge::Bridge()->SetCompositorParent(NULL, NULL);
#ifdef MOZ_JAVA_COMPOSITOR
SetCompositor(NULL, NULL, NULL);
#endif
}
bool
@ -772,21 +772,21 @@ nsWindow::GetLayerManager(PLayersChild*, LayersBackend, LayerManagerPersistence,
mLayerManager = CreateBasicLayerManager();
return mLayerManager;
}
#ifdef MOZ_JAVA_COMPOSITOR
bool useCompositor =
Preferences::GetBool("layers.offmainthreadcomposition.enabled", false);
if (useCompositor) {
CreateCompositor();
if (mLayerManager) {
AndroidBridge::Bridge()->SetCompositorParent(mCompositorParent, mCompositorThread);
SetCompositor(mCompositorParent, mCompositorChild, mCompositorThread);
return mLayerManager;
}
// If we get here, then off main thread compositing failed to initialize.
sFailedToCreateGLContext = true;
}
#endif
mUseAcceleratedRendering = GetShouldAccelerate();
if (!mUseAcceleratedRendering ||
@ -983,6 +983,31 @@ nsWindow::OnGlobalAndroidEvent(AndroidGeckoEvent *ae)
sValidSurface = false;
break;
#ifdef MOZ_JAVA_COMPOSITOR
case AndroidGeckoEvent::COMPOSITOR_PAUSE:
// The compositor gets paused when the app is about to go into the
// background. While the compositor is paused, we need to ensure that
// no layer tree updates (from draw events) occur, since the compositor
// cannot make a GL context current in order to process updates.
if (sCompositorChild) {
sCompositorChild->SendPause();
}
sCompositorPaused = true;
break;
case AndroidGeckoEvent::COMPOSITOR_RESUME:
// When we receive this, the compositor has already been told to
// resume. (It turns out that waiting till we reach here to tell
// the compositor to resume takes too long, resulting in a black
// flash.) This means it's now safe for layer updates to occur.
// Since we might have prevented one or more draw events from
// occurring while the compositor was paused, we need to schedule
// a draw event now.
sCompositorPaused = false;
win->RedrawAll();
break;
#endif
case AndroidGeckoEvent::GECKO_EVENT_SYNC:
AndroidBridge::Bridge()->AcknowledgeEventSync();
break;
@ -1135,8 +1160,8 @@ nsWindow::OnDraw(AndroidGeckoEvent *ae)
AndroidBridge::AutoLocalJNIFrame jniFrame;
#ifdef MOZ_JAVA_COMPOSITOR
// We haven't been given a window-size yet, so do nothing
if (gAndroidBounds.width <= 0 || gAndroidBounds.height <= 0) {
// We're paused, or we haven't been given a window-size yet, so do nothing
if (sCompositorPaused || gAndroidBounds.width <= 0 || gAndroidBounds.height <= 0) {
return;
}
@ -2275,13 +2300,17 @@ nsWindow::DrawWindowOverlay(LayerManager* aManager, nsIntRect aRect) {
// off-main-thread compositor fields and functions
nsRefPtr<mozilla::layers::CompositorParent> nsWindow::sCompositorParent = 0;
nsRefPtr<mozilla::layers::CompositorChild> nsWindow::sCompositorChild = 0;
base::Thread * nsWindow::sCompositorThread = 0;
bool nsWindow::sCompositorPaused = false;
void
nsWindow::SetCompositorParent(mozilla::layers::CompositorParent* aCompositorParent,
::base::Thread* aCompositorThread)
nsWindow::SetCompositor(mozilla::layers::CompositorParent* aCompositorParent,
mozilla::layers::CompositorChild* aCompositorChild,
::base::Thread* aCompositorThread)
{
sCompositorParent = aCompositorParent;
sCompositorChild = aCompositorChild;
sCompositorThread = aCompositorThread;
}

View File

@ -61,6 +61,7 @@ namespace mozilla {
namespace layers {
class CompositorParent;
class CompositorChild;
}
}
@ -188,8 +189,9 @@ public:
virtual void DrawWindowUnderlay(LayerManager* aManager, nsIntRect aRect);
virtual void DrawWindowOverlay(LayerManager* aManager, nsIntRect aRect);
static void SetCompositorParent(mozilla::layers::CompositorParent* aCompositorParent,
::base::Thread* aCompositorThread);
static void SetCompositor(mozilla::layers::CompositorParent* aCompositorParent,
mozilla::layers::CompositorChild* aCompositorChild,
::base::Thread* aCompositorThread);
static void ScheduleComposite();
static void SchedulePauseComposition();
static void ScheduleResumeComposition();
@ -265,6 +267,8 @@ private:
mozilla::AndroidLayerRendererFrame mLayerRendererFrame;
static nsRefPtr<mozilla::layers::CompositorParent> sCompositorParent;
static nsRefPtr<mozilla::layers::CompositorChild> sCompositorChild;
static bool sCompositorPaused;
static base::Thread *sCompositorThread;
#endif
};