Bug 852526 - Make sure the compositor starts unpaused and with a size. r=kats

This changes compositor creation so that we can specify an initial size and
makes sure the local variable in nsWindow reflects that the compositor starts
unpaused.
This commit is contained in:
Chris Lord 2013-03-20 22:45:07 +00:00
parent a9f2f659de
commit 202e1980aa
9 changed files with 57 additions and 16 deletions

View File

@ -37,6 +37,8 @@ import java.nio.ByteBuffer;
public class GeckoEvent {
private static final String LOGTAG = "GeckoEvent";
// Make sure to keep these values in sync with the enum in
// AndroidGeckoEvent in widget/android/AndroidJavaWrapper.h
private static final int NATIVE_POKE = 0;
private static final int KEY_EVENT = 1;
private static final int MOTION_EVENT = 2;
@ -58,9 +60,10 @@ public class GeckoEvent {
private static final int ACTIVITY_RESUMING = 24;
private static final int THUMBNAIL = 25;
private static final int SCREENORIENTATION_CHANGED = 27;
private static final int COMPOSITOR_PAUSE = 28;
private static final int COMPOSITOR_RESUME = 29;
private static final int NATIVE_GESTURE_EVENT = 30;
private static final int COMPOSITOR_CREATE = 28;
private static final int COMPOSITOR_PAUSE = 29;
private static final int COMPOSITOR_RESUME = 30;
private static final int NATIVE_GESTURE_EVENT = 31;
/**
* These DOM_KEY_LOCATION constants mirror the DOM KeyboardEvent's constants.
@ -148,6 +151,9 @@ public class GeckoEvent {
private ByteBuffer mBuffer;
private int mWidth;
private int mHeight;
private GeckoEvent(int evType) {
mType = evType;
}
@ -190,6 +196,13 @@ public class GeckoEvent {
return event;
}
public static GeckoEvent createCompositorCreateEvent(int width, int height) {
GeckoEvent event = new GeckoEvent(COMPOSITOR_CREATE);
event.mWidth = width;
event.mHeight = height;
return event;
}
public static GeckoEvent createCompositorPauseEvent() {
return new GeckoEvent(COMPOSITOR_PAUSE);
}

View File

@ -176,7 +176,7 @@ public class GLController {
// happen without needing to block anyhwere. Do it with a sync gecko event so that the
// android doesn't have a chance to destroy our surface in between.
if (mEGLSurface != null && GeckoThread.checkLaunchState(GeckoThread.LaunchState.GeckoRunning)) {
GeckoAppShell.sendEventToGeckoSync(GeckoEvent.createCompositorResumeEvent());
GeckoAppShell.sendEventToGeckoSync(GeckoEvent.createCompositorCreateEvent(mWidth, mHeight));
}
}

View File

@ -50,6 +50,8 @@ jfieldID AndroidGeckoEvent::jBandwidthField = 0;
jfieldID AndroidGeckoEvent::jCanBeMeteredField = 0;
jfieldID AndroidGeckoEvent::jScreenOrientationField = 0;
jfieldID AndroidGeckoEvent::jByteBufferField = 0;
jfieldID AndroidGeckoEvent::jWidthField = 0;
jfieldID AndroidGeckoEvent::jHeightField = 0;
jclass AndroidPoint::jPointClass = 0;
jfieldID AndroidPoint::jXField = 0;
@ -242,6 +244,8 @@ AndroidGeckoEvent::InitGeckoEventClass(JNIEnv *jEnv)
jCanBeMeteredField = getField("mCanBeMetered", "Z");
jScreenOrientationField = getField("mScreenOrientation", "S");
jByteBufferField = getField("mBuffer", "Ljava/nio/ByteBuffer;");
jWidthField = getField("mWidth", "I");
jHeightField = getField("mHeight", "I");
}
void
@ -629,6 +633,12 @@ AndroidGeckoEvent::Init(JNIEnv *jenv, jobject jobj)
break;
}
case COMPOSITOR_CREATE: {
mWidth = jenv->GetIntField(jobj, jWidthField);
mHeight = jenv->GetIntField(jobj, jHeightField);
break;
}
default:
break;
}

View File

@ -657,6 +657,8 @@ public:
bool CanBeMetered() { return mCanBeMetered; }
short ScreenOrientation() { return mScreenOrientation; }
RefCountedJavaObject* ByteBuffer() { return mByteBuffer; }
int Width() { return mWidth; }
int Height() { return mHeight; }
protected:
int mAction;
@ -686,6 +688,7 @@ protected:
bool mCanBeMetered;
short mScreenOrientation;
nsRefPtr<RefCountedJavaObject> mByteBuffer;
int mWidth, mHeight;
void ReadIntArray(nsTArray<int> &aVals,
JNIEnv *jenv,
@ -747,6 +750,9 @@ protected:
static jfieldID jScreenOrientationField;
static jfieldID jByteBufferField;
static jfieldID jWidthField;
static jfieldID jHeightField;
public:
enum {
NATIVE_POKE = 0,
@ -773,9 +779,10 @@ public:
ACTIVITY_RESUMING = 24,
THUMBNAIL = 25,
SCREENORIENTATION_CHANGED = 27,
COMPOSITOR_PAUSE = 28,
COMPOSITOR_RESUME = 29,
NATIVE_GESTURE_EVENT = 30,
COMPOSITOR_CREATE = 28,
COMPOSITOR_PAUSE = 29,
COMPOSITOR_RESUME = 30,
NATIVE_GESTURE_EVENT = 31,
dummy_java_enum_list_end
};

View File

@ -641,13 +641,15 @@ nsAppShell::PostEvent(AndroidGeckoEvent *ae)
}
break;
case AndroidGeckoEvent::COMPOSITOR_CREATE:
case AndroidGeckoEvent::COMPOSITOR_PAUSE:
case AndroidGeckoEvent::COMPOSITOR_RESUME:
// Give priority to these events, but maintain their order wrt each other.
{
uint32_t i = 0;
while (i < mEventQueue.Length() &&
(mEventQueue[i]->Type() == AndroidGeckoEvent::COMPOSITOR_PAUSE ||
(mEventQueue[i]->Type() == AndroidGeckoEvent::COMPOSITOR_CREATE ||
mEventQueue[i]->Type() == AndroidGeckoEvent::COMPOSITOR_PAUSE ||
mEventQueue[i]->Type() == AndroidGeckoEvent::COMPOSITOR_RESUME)) {
i++;
}

View File

@ -698,7 +698,7 @@ nsWindow::GetLayerManager(PLayersChild*, LayersBackend, LayerManagerPersistence,
}
void
nsWindow::CreateLayerManager()
nsWindow::CreateLayerManager(int aCompositorWidth, int aCompositorHeight)
{
if (mLayerManager) {
return;
@ -716,11 +716,12 @@ nsWindow::CreateLayerManager()
if (sLayerManager) {
return;
}
CreateCompositor();
CreateCompositor(aCompositorWidth, aCompositorHeight);
if (mLayerManager) {
// for OMTC create a single layer manager and compositor that will be
// used for all windows.
SetCompositor(mLayerManager, mCompositorParent, mCompositorChild);
sCompositorPaused = false;
return;
}
@ -875,6 +876,10 @@ nsWindow::OnGlobalAndroidEvent(AndroidGeckoEvent *ae)
}
break;
case AndroidGeckoEvent::COMPOSITOR_CREATE:
win->CreateLayerManager(ae->Width(), ae->Height());
break;
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
@ -887,8 +892,6 @@ nsWindow::OnGlobalAndroidEvent(AndroidGeckoEvent *ae)
break;
case AndroidGeckoEvent::COMPOSITOR_RESUME:
win->CreateLayerManager();
// 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

View File

@ -138,7 +138,6 @@ public:
LayersBackend aBackendHint = mozilla::layers::LAYERS_NONE,
LayerManagerPersistence aPersistence = LAYER_MANAGER_CURRENT,
bool* aAllowRetaining = nullptr);
void CreateLayerManager();
NS_IMETHOD ReparentNativeWidget(nsIWidget* aNewParent);
@ -223,6 +222,7 @@ private:
void DispatchGestureEvent(uint32_t msg, uint32_t direction, double delta,
const nsIntPoint &refPoint, uint64_t time);
void HandleSpecialKey(mozilla::AndroidGeckoEvent *ae);
void CreateLayerManager(int aCompositorWidth, int aCompositorHeight);
void RedrawAll();
mozilla::AndroidLayerRendererFrame mLayerRendererFrame;

View File

@ -862,15 +862,20 @@ nsBaseWidget::ComputeShouldAccelerate(bool aDefault)
}
void nsBaseWidget::CreateCompositor()
{
nsIntRect rect;
GetBounds(rect);
CreateCompositor(rect.width, rect.height);
}
void nsBaseWidget::CreateCompositor(int aWidth, int aHeight)
{
bool renderToEGLSurface = false;
#ifdef MOZ_ANDROID_OMTC
renderToEGLSurface = true;
#endif
nsIntRect rect;
GetBounds(rect);
mCompositorParent =
new CompositorParent(this, renderToEGLSurface, rect.width, rect.height);
new CompositorParent(this, renderToEGLSurface, aWidth, aHeight);
LayerManager* lm = CreateBasicLayerManager();
MessageLoop *childMessageLoop = CompositorParent::CompositorLoop();
mCompositorChild = new CompositorChild(lm);

View File

@ -111,6 +111,7 @@ public:
bool* aAllowRetaining = nullptr);
virtual void CreateCompositor();
virtual void CreateCompositor(int aWidth, int aHeight);
virtual void DrawWindowUnderlay(LayerManager* aManager, nsIntRect aRect) {}
virtual void DrawWindowOverlay(LayerManager* aManager, nsIntRect aRect) {}
virtual void UpdateThemeGeometries(const nsTArray<ThemeGeometry>& aThemeGeometries) {}