Bug 844275 - Move mCompositorCreated and associated methods from GeckoLayerClient to GLController. r=Cwiiis

This commit is contained in:
Kartikaya Gupta 2013-02-28 13:28:23 -05:00
Родитель e385c3c091
Коммит 26c808678c
3 изменённых файлов: 42 добавлений и 52 удалений

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

@ -5,6 +5,9 @@
package org.mozilla.gecko.gfx; package org.mozilla.gecko.gfx;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
import javax.microedition.khronos.egl.EGL10; import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLContext; import javax.microedition.khronos.egl.EGLContext;
@ -19,6 +22,10 @@ public class GLController {
private boolean mSurfaceValid; private boolean mSurfaceValid;
private int mWidth, mHeight; private int mWidth, mHeight;
/* This is written by the compositor thread (while the UI thread
* is blocked on it) and read by the UI thread. */
private volatile boolean mCompositorCreated;
private EGL10 mEGL; private EGL10 mEGL;
private EGLDisplay mEGLDisplay; private EGLDisplay mEGLDisplay;
private EGLConfig mEGLConfig; private EGLConfig mEGLConfig;
@ -46,7 +53,7 @@ public class GLController {
return; return;
} }
} }
mView.getListener().compositionResumeRequested(mWidth, mHeight); resumeCompositor(mWidth, mHeight);
} }
/* Wait until we are allowed to use EGL functions on the Surface backing /* Wait until we are allowed to use EGL functions on the Surface backing
@ -65,6 +72,18 @@ public class GLController {
synchronized void surfaceDestroyed() { synchronized void surfaceDestroyed() {
mSurfaceValid = false; mSurfaceValid = false;
notifyAll(); notifyAll();
// We need to coordinate with Gecko when pausing composition, to ensure
// that Gecko never executes a draw event while the compositor is paused.
// This is sent synchronously to make sure that we don't attempt to use
// any outstanding Surfaces after we call this (such as from a
// surfaceDestroyed notification), and to make sure that any in-flight
// Gecko draw events have been processed. When this returns, composition is
// definitely paused -- it'll synchronize with the Gecko event loop, which
// in turn will synchronize with the compositor thread.
if (mCompositorCreated) {
GeckoAppShell.sendEventToGeckoSync(GeckoEvent.createCompositorPauseEvent());
}
} }
synchronized void surfaceChanged(int newWidth, int newHeight) { synchronized void surfaceChanged(int newWidth, int newHeight) {
@ -74,6 +93,10 @@ public class GLController {
notifyAll(); notifyAll();
} }
void compositorCreated() {
mCompositorCreated = true;
}
public boolean hasValidSurface() { public boolean hasValidSurface() {
return mSurfaceValid; return mSurfaceValid;
} }
@ -147,6 +170,19 @@ public class GLController {
return "Error " + mEGL.eglGetError(); return "Error " + mEGL.eglGetError();
} }
void resumeCompositor(int width, int height) {
// Asking Gecko to resume the compositor takes too long (see
// https://bugzilla.mozilla.org/show_bug.cgi?id=735230#c23), so we
// resume the compositor directly. We still need to inform Gecko about
// the compositor resuming, so that Gecko knows that it can now draw.
// It is important to not notify Gecko until after the compositor has
// been resumed, otherwise Gecko may send updates that get dropped.
if (mCompositorCreated) {
GeckoAppShell.scheduleResumeComposition(width, height);
GeckoAppShell.sendEventToGecko(GeckoEvent.createCompositorResumeEvent());
}
}
public static class GLControllerException extends RuntimeException { public static class GLControllerException extends RuntimeException {
public static final long serialVersionUID = 1L; public static final long serialVersionUID = 1L;
@ -155,4 +191,3 @@ public class GLController {
} }
} }
} }

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

@ -67,9 +67,6 @@ public class GeckoLayerClient implements LayerView.Listener, PanZoomTarget
private boolean mLastProgressiveUpdateWasLowPrecision; private boolean mLastProgressiveUpdateWasLowPrecision;
private boolean mProgressiveUpdateWasInDanger; private boolean mProgressiveUpdateWasInDanger;
/* This is written by the compositor thread and read by the UI thread. */
private volatile boolean mCompositorCreated;
private boolean mForceRedraw; private boolean mForceRedraw;
/* The current viewport metrics. /* The current viewport metrics.
@ -107,7 +104,6 @@ public class GeckoLayerClient implements LayerView.Listener, PanZoomTarget
mProgressiveUpdateDisplayPort = new DisplayPortMetrics(); mProgressiveUpdateDisplayPort = new DisplayPortMetrics();
mLastProgressiveUpdateWasLowPrecision = false; mLastProgressiveUpdateWasLowPrecision = false;
mProgressiveUpdateWasInDanger = false; mProgressiveUpdateWasInDanger = false;
mCompositorCreated = false;
mForceRedraw = true; mForceRedraw = true;
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
@ -595,42 +591,13 @@ public class GeckoLayerClient implements LayerView.Listener, PanZoomTarget
} }
} }
/** Implementation of LayerView.Listener */
@Override
public void compositionPauseRequested() {
// We need to coordinate with Gecko when pausing composition, to ensure
// that Gecko never executes a draw event while the compositor is paused.
// This is sent synchronously to make sure that we don't attempt to use
// any outstanding Surfaces after we call this (such as from a
// surfaceDestroyed notification), and to make sure that any in-flight
// Gecko draw events have been processed. When this returns, composition is
// definitely paused -- it'll synchronize with the Gecko event loop, which
// in turn will synchronize with the compositor thread.
if (mCompositorCreated) {
GeckoAppShell.sendEventToGeckoSync(GeckoEvent.createCompositorPauseEvent());
}
}
/** Implementation of LayerView.Listener */
@Override
public void compositionResumeRequested(int width, int height) {
// Asking Gecko to resume the compositor takes too long (see
// https://bugzilla.mozilla.org/show_bug.cgi?id=735230#c23), so we
// resume the compositor directly. We still need to inform Gecko about
// the compositor resuming, so that Gecko knows that it can now draw.
if (mCompositorCreated) {
GeckoAppShell.scheduleResumeComposition(width, height);
GeckoAppShell.sendEventToGecko(GeckoEvent.createCompositorResumeEvent());
}
}
/** Implementation of LayerView.Listener */ /** Implementation of LayerView.Listener */
@Override @Override
public void sizeChanged(int width, int height) { public void sizeChanged(int width, int height) {
// We need to make sure a draw happens synchronously at this point, // We need to make sure a draw happens synchronously at this point,
// but resizing the surface before the SurfaceView has resized will // but resizing the surface before the SurfaceView has resized will
// cause a visible jump. // cause a visible jump.
compositionResumeRequested(mWindowSize.width, mWindowSize.height); mView.getGLController().resumeCompositor(mWindowSize.width, mWindowSize.height);
} }
/** Implementation of LayerView.Listener */ /** Implementation of LayerView.Listener */
@ -641,13 +608,7 @@ public class GeckoLayerClient implements LayerView.Listener, PanZoomTarget
// We need to make this call even when the compositor isn't currently // We need to make this call even when the compositor isn't currently
// paused (e.g. during an orientation change), to make the compositor // paused (e.g. during an orientation change), to make the compositor
// aware of the changed surface. // aware of the changed surface.
compositionResumeRequested(width, height); mView.getGLController().resumeCompositor(width, height);
}
/** Implementation of LayerView.Listener */
@Override
public void compositorCreated() {
mCompositorCreated = true;
} }
/** Implementation of PanZoomTarget */ /** Implementation of PanZoomTarget */

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

@ -390,10 +390,6 @@ public class LayerView extends FrameLayout {
private void onDestroyed() { private void onDestroyed() {
mGLController.surfaceDestroyed(); mGLController.surfaceDestroyed();
if (mListener != null) {
mListener.compositionPauseRequested();
}
} }
public Object getNativeWindow() { public Object getNativeWindow() {
@ -407,8 +403,9 @@ public class LayerView extends FrameLayout {
public static GLController registerCxxCompositor() { public static GLController registerCxxCompositor() {
try { try {
LayerView layerView = GeckoApp.mAppContext.getLayerView(); LayerView layerView = GeckoApp.mAppContext.getLayerView();
layerView.mListener.compositorCreated(); GLController controller = layerView.getGLController();
return layerView.getGLController(); controller.compositorCreated();
return controller;
} catch (Exception e) { } catch (Exception e) {
Log.e(LOGTAG, "Error registering compositor!", e); Log.e(LOGTAG, "Error registering compositor!", e);
return null; return null;
@ -416,10 +413,7 @@ public class LayerView extends FrameLayout {
} }
public interface Listener { public interface Listener {
void compositorCreated();
void renderRequested(); void renderRequested();
void compositionPauseRequested();
void compositionResumeRequested(int width, int height);
void sizeChanged(int width, int height); void sizeChanged(int width, int height);
void surfaceChanged(int width, int height); void surfaceChanged(int width, int height);
} }