Merge heads.

This commit is contained in:
Ali Juma 2012-02-17 17:57:28 -05:00
commit 469a3738fe
6 changed files with 167 additions and 180 deletions

View File

@ -392,7 +392,8 @@ GLContext::InitWithPrefix(const char *prefix, bool trygl)
"Intel",
"NVIDIA",
"ATI",
"Qualcomm"
"Qualcomm",
"Imagination"
};
mVendor = VendorOther;
for (int i = 0; i < VendorOther; ++i) {
@ -404,7 +405,8 @@ GLContext::InitWithPrefix(const char *prefix, bool trygl)
glRendererString = (const char *)fGetString(LOCAL_GL_RENDERER);
const char *rendererMatchStrings[RendererOther] = {
"Adreno 200"
"Adreno 200",
"PowerVR SGX 540"
};
mRenderer = RendererOther;
for (int i = 0; i < RendererOther; ++i) {
@ -614,6 +616,27 @@ GLContext::CanUploadSubTextures()
return !(Renderer() == RendererAdreno200);
}
bool
GLContext::WantsSmallTiles()
{
#ifdef MOZ_WIDGET_ANDROID
// We must use small tiles for good performance if we can't use
// glTexSubImage2D() for some reason.
if (!CanUploadSubTextures())
return true;
// We can't use small tiles on the SGX 540, because of races in texture upload.
if (Renderer() == RendererSGX540)
return false;
// Don't use small tiles otherwise. (If we implement incremental texture upload,
// then we will want to revisit this.)
return false;
#else
return false;
#endif
}
// Common code for checking for both GL extensions and GLX extensions.
bool
GLContext::ListHasExtension(const GLubyte *extensions, const char *extension)
@ -866,7 +889,7 @@ TiledTextureImage::TiledTextureImage(GLContext* aGL,
, mUseNearestFilter(aUseNearestFilter)
, mTextureState(Created)
{
mTileSize = 256;//mGL->GetMaxTextureSize();
mTileSize = mGL->WantsSmallTiles() ? 256 : mGL->GetMaxTextureSize();
if (aSize != nsIntSize(0,0)) {
Resize(aSize);
}

View File

@ -695,11 +695,13 @@ public:
VendorNVIDIA,
VendorATI,
VendorQualcomm,
VendorImagination,
VendorOther
};
enum {
RendererAdreno200,
RendererSGX540,
RendererOther
};
@ -712,6 +714,7 @@ public:
}
bool CanUploadSubTextures();
bool WantsSmallTiles();
/**
* If this context wraps a double-buffered target, swap the back

View File

@ -48,133 +48,16 @@ import android.graphics.RectF;
import android.util.Log;
import android.view.View;
public class GeckoGLLayerClient extends GeckoLayerClient
implements FlexibleGLSurfaceView.Listener, VirtualLayer.Listener {
public class GeckoGLLayerClient extends GeckoLayerClient {
private static final String LOGTAG = "GeckoGLLayerClient";
private LayerRenderer mLayerRenderer;
private boolean mLayerRendererInitialized;
public GeckoGLLayerClient(Context context) {
super(context);
}
@Override
public Rect beginDrawing(int width, int height, int tileWidth, int tileHeight,
String metadata, boolean hasDirectTexture) {
Rect bufferRect = super.beginDrawing(width, height, tileWidth, tileHeight,
metadata, hasDirectTexture);
if (bufferRect == null) {
return null;
}
// Be sure to adjust the buffer size; if it's not at least as large as the viewport size,
// ViewportMetrics.getOptimumViewportOffset() gets awfully confused and severe display
// corruption results!
if (mBufferSize.width != width || mBufferSize.height != height) {
mBufferSize = new IntSize(width, height);
}
return bufferRect;
}
@Override
protected boolean handleDirectTextureChange(boolean hasDirectTexture) {
Log.e(LOGTAG, "### handleDirectTextureChange");
if (mTileLayer != null) {
return false;
}
Log.e(LOGTAG, "### Creating virtual layer");
VirtualLayer virtualLayer = new VirtualLayer();
virtualLayer.setListener(this);
virtualLayer.setSize(getBufferSize());
mLayerController.setRoot(virtualLayer);
mTileLayer = virtualLayer;
sendResizeEventIfNecessary(true);
return true;
}
@Override
public void setLayerController(LayerController layerController) {
super.setLayerController(layerController);
LayerView view = layerController.getView();
view.setListener(this);
mLayerRenderer = new LayerRenderer(view);
}
@Override
protected boolean shouldDrawProceed(int tileWidth, int tileHeight) {
Log.e(LOGTAG, "### shouldDrawProceed");
// Always draw.
return true;
}
@Override
protected void updateLayerAfterDraw(Rect updatedRect) {
Log.e(LOGTAG, "### updateLayerAfterDraw");
// Nothing to do.
}
@Override
protected IntSize getBufferSize() {
View view = mLayerController.getView();
IntSize size = new IntSize(view.getWidth(), view.getHeight());
Log.e(LOGTAG, "### getBufferSize " + size);
return size;
}
@Override
protected IntSize getTileSize() {
Log.e(LOGTAG, "### getTileSize " + getBufferSize());
return getBufferSize();
}
@Override
protected void tileLayerUpdated() {
// Set the new origin and resolution instantly.
mTileLayer.performUpdates(null);
}
@Override
public Bitmap getBitmap() {
Log.e(LOGTAG, "### getBitmap");
IntSize size = getBufferSize();
try {
return Bitmap.createBitmap(size.width, size.height, Bitmap.Config.RGB_565);
} catch (OutOfMemoryError oom) {
Log.e(LOGTAG, "Unable to create bitmap", oom);
return null;
}
}
public void dimensionsChanged(Point newOrigin, float newResolution) {
Log.e(LOGTAG, "### dimensionsChanged " + newOrigin + " " + newResolution);
}
/* Informs Gecko that the screen size has changed. */
@Override
protected void sendResizeEventIfNecessary(boolean force) {
Log.e(LOGTAG, "### sendResizeEventIfNecessary " + force);
IntSize newSize = getBufferSize();
if (!force && mScreenSize != null && mScreenSize.equals(newSize)) {
return;
}
mScreenSize = newSize;
Log.e(LOGTAG, "### Screen-size changed to " + mScreenSize);
GeckoEvent event = GeckoEvent.createSizeChangedEvent(mScreenSize.width, mScreenSize.height,
mScreenSize.width, mScreenSize.height,
mScreenSize.width, mScreenSize.height);
GeckoAppShell.sendEventToGecko(event);
}
/** For Gecko to use. */
/** This function is invoked by Gecko via JNI; be careful when modifying signature. */
public ViewTransform getViewTransform() {
Log.e(LOGTAG, "### getViewTransform()");
@ -194,29 +77,7 @@ public class GeckoGLLayerClient extends GeckoLayerClient
}
}
public void renderRequested() {
Log.e(LOGTAG, "### Render requested, scheduling composite");
GeckoAppShell.scheduleComposite();
}
public void compositionPauseRequested() {
Log.e(LOGTAG, "### Scheduling PauseComposition");
GeckoAppShell.schedulePauseComposition();
}
public void compositionResumeRequested() {
Log.e(LOGTAG, "### Scheduling ResumeComposition");
GeckoAppShell.scheduleResumeComposition();
}
public void surfaceChanged(int width, int height) {
compositionPauseRequested();
mLayerController.setViewportSize(new FloatSize(width, height));
compositionResumeRequested();
renderRequested();
}
/** For Gecko to use. */
/** This function is invoked by Gecko via JNI; be careful when modifying signature. */
public LayerRenderer.Frame createFrame() {
// Create the shaders and textures if necessary.
if (!mLayerRendererInitialized) {
@ -230,12 +91,12 @@ public class GeckoGLLayerClient extends GeckoLayerClient
return mLayerRenderer.createFrame(pageContext, screenContext);
}
/** For Gecko to use. */
/** This function is invoked by Gecko via JNI; be careful when modifying signature. */
public void activateProgram() {
mLayerRenderer.activateProgram();
}
/** For Gecko to use. */
/** This function is invoked by Gecko via JNI; be careful when modifying signature. */
public void deactivateProgram() {
mLayerRenderer.deactivateProgram();
}

View File

@ -48,21 +48,27 @@ import org.json.JSONObject;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.RectF;
import android.os.SystemClock;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public abstract class GeckoLayerClient implements GeckoEventListener {
public abstract class GeckoLayerClient implements GeckoEventListener,
FlexibleGLSurfaceView.Listener,
VirtualLayer.Listener {
private static final String LOGTAG = "GeckoLayerClient";
protected LayerController mLayerController;
protected LayerRenderer mLayerRenderer;
protected IntSize mScreenSize;
protected IntSize mWindowSize;
protected IntSize mBufferSize;
protected Layer mTileLayer;
@ -92,14 +98,6 @@ public abstract class GeckoLayerClient implements GeckoEventListener {
/* Used by robocop for testing purposes */
private DrawListener mDrawListener;
protected abstract boolean handleDirectTextureChange(boolean hasDirectTexture);
protected abstract boolean shouldDrawProceed(int tileWidth, int tileHeight);
protected abstract void updateLayerAfterDraw(Rect updatedRect);
protected abstract IntSize getBufferSize();
protected abstract IntSize getTileSize();
protected abstract void tileLayerUpdated();
public abstract Bitmap getBitmap();
public GeckoLayerClient(Context context) {
mScreenSize = new IntSize(0, 0);
mBufferSize = new IntSize(0, 0);
@ -118,8 +116,14 @@ public abstract class GeckoLayerClient implements GeckoEventListener {
GeckoAppShell.registerGeckoEventListener("Viewport:UpdateLater", this);
sendResizeEventIfNecessary();
LayerView view = layerController.getView();
view.setListener(this);
mLayerRenderer = new LayerRenderer(view);
}
/** This function is invoked by Gecko via JNI; be careful when modifying signature. */
public Rect beginDrawing(int width, int height, int tileWidth, int tileHeight,
String metadata, boolean hasDirectTexture) {
Log.e(LOGTAG, "### beginDrawing " + width + " " + height + " " + tileWidth + " " +
@ -193,10 +197,19 @@ public abstract class GeckoLayerClient implements GeckoEventListener {
}
mTileLayer.beginTransaction(mLayerController.getView());
// Be sure to adjust the buffer size; if it's not at least as large as the viewport size,
// ViewportMetrics.getOptimumViewportOffset() gets awfully confused and severe display
// corruption results!
if (mBufferSize.width != width || mBufferSize.height != height) {
mBufferSize = new IntSize(width, height);
}
return bufferRect;
}
/*
/** This function is invoked by Gecko via JNI; be careful when modifying signature.
*
* TODO: Would be cleaner if this took an android.graphics.Rect instead, but that would require
* a little more JNI magic.
*/
@ -251,29 +264,36 @@ public abstract class GeckoLayerClient implements GeckoEventListener {
/* Informs Gecko that the screen size has changed. */
protected void sendResizeEventIfNecessary(boolean force) {
Log.e(LOGTAG, "### sendResizeEventIfNecessary " + force);
Log.d(LOGTAG, "### sendResizeEventIfNecessary " + force);
DisplayMetrics metrics = new DisplayMetrics();
GeckoApp.mAppContext.getWindowManager().getDefaultDisplay().getMetrics(metrics);
// Return immediately if the screen size hasn't changed or the viewport
// size is zero (which indicates that the rendering surface hasn't been
// allocated yet).
boolean screenSizeChanged = (metrics.widthPixels != mScreenSize.width ||
metrics.heightPixels != mScreenSize.height);
boolean viewportSizeValid = (mLayerController != null &&
mLayerController.getViewportSize().isPositive());
if (!(force || (screenSizeChanged && viewportSizeValid))) {
IntSize newScreenSize = new IntSize(metrics.widthPixels, metrics.heightPixels);
IntSize newWindowSize = getBufferSize();
boolean screenSizeChanged = mScreenSize == null || !mScreenSize.equals(newScreenSize);
boolean windowSizeChanged = mWindowSize == null || !mWindowSize.equals(newWindowSize);
if (!force && !screenSizeChanged && !windowSizeChanged) {
return;
}
mScreenSize = new IntSize(metrics.widthPixels, metrics.heightPixels);
IntSize bufferSize = getBufferSize(), tileSize = getTileSize();
mScreenSize = newScreenSize;
mWindowSize = newWindowSize;
Log.e(LOGTAG, "### Screen-size changed to " + mScreenSize);
GeckoEvent event = GeckoEvent.createSizeChangedEvent(bufferSize.width, bufferSize.height,
metrics.widthPixels, metrics.heightPixels,
tileSize.width, tileSize.height);
if (screenSizeChanged) {
Log.i(LOGTAG, "### Screen-size changed to " + mScreenSize);
}
if (windowSizeChanged) {
Log.i(LOGTAG, "### Window-size changed to " + mWindowSize);
}
IntSize bufferSize = getBufferSize();
GeckoEvent event = GeckoEvent.createSizeChangedEvent(mWindowSize.width, mWindowSize.height, // Window (buffer) size
mScreenSize.width, mScreenSize.height, // Screen size
0, 0); // Tile-size (unused)
GeckoAppShell.sendEventToGecko(event);
}
@ -295,6 +315,62 @@ public abstract class GeckoLayerClient implements GeckoEventListener {
return Color.rgb(r, g, b);
}
protected boolean handleDirectTextureChange(boolean hasDirectTexture) {
Log.e(LOGTAG, "### handleDirectTextureChange");
if (mTileLayer != null) {
return false;
}
Log.e(LOGTAG, "### Creating virtual layer");
VirtualLayer virtualLayer = new VirtualLayer();
virtualLayer.setListener(this);
virtualLayer.setSize(getBufferSize());
mLayerController.setRoot(virtualLayer);
mTileLayer = virtualLayer;
sendResizeEventIfNecessary(true);
return true;
}
protected boolean shouldDrawProceed(int tileWidth, int tileHeight) {
Log.e(LOGTAG, "### shouldDrawProceed");
// Always draw.
return true;
}
protected void updateLayerAfterDraw(Rect updatedRect) {
Log.e(LOGTAG, "### updateLayerAfterDraw");
// Nothing to do.
}
protected IntSize getBufferSize() {
View view = mLayerController.getView();
IntSize size = new IntSize(view.getWidth(), view.getHeight());
Log.e(LOGTAG, "### getBufferSize " + size);
return size;
}
protected IntSize getTileSize() {
Log.e(LOGTAG, "### getTileSize " + getBufferSize());
return getBufferSize();
}
protected void tileLayerUpdated() {
// Set the new origin and resolution instantly.
mTileLayer.performUpdates(null);
}
public Bitmap getBitmap() {
Log.e(LOGTAG, "### getBitmap");
IntSize size = getBufferSize();
try {
return Bitmap.createBitmap(size.width, size.height, Bitmap.Config.RGB_565);
} catch (OutOfMemoryError oom) {
Log.e(LOGTAG, "Unable to create bitmap", oom);
return null;
}
}
public void render() {
adjustViewportWithThrottling();
}
@ -382,6 +458,37 @@ public abstract class GeckoLayerClient implements GeckoEventListener {
sendResizeEventIfNecessary(false);
}
/** Implementation of FlexibleGLSurfaceView.Listener */
public void renderRequested() {
Log.e(LOGTAG, "### Render requested, scheduling composite");
GeckoAppShell.scheduleComposite();
}
/** Implementation of FlexibleGLSurfaceView.Listener */
public void compositionPauseRequested() {
Log.e(LOGTAG, "### Scheduling PauseComposition");
GeckoAppShell.schedulePauseComposition();
}
/** Implementation of FlexibleGLSurfaceView.Listener */
public void compositionResumeRequested() {
Log.e(LOGTAG, "### Scheduling ResumeComposition");
GeckoAppShell.scheduleResumeComposition();
}
/** Implementation of FlexibleGLSurfaceView.Listener */
public void surfaceChanged(int width, int height) {
compositionPauseRequested();
mLayerController.setViewportSize(new FloatSize(width, height));
compositionResumeRequested();
renderRequested();
}
/** Implementation of VirtualLayer.Listener */
public void dimensionsChanged(Point newOrigin, float newResolution) {
Log.e(LOGTAG, "### dimensionsChanged " + newOrigin + " " + newResolution);
}
/** Used by robocop for testing purposes. Not for production use! This is called via reflection by robocop. */
public void setDrawListener(DrawListener listener) {
mDrawListener = listener;

View File

@ -2039,7 +2039,6 @@ Tab.prototype = {
}
ViewportHandler.setMetadataForDocument(this.browser.contentDocument, aMetadata);
this.updateViewportSize();
this.updateViewport(true);
},
/** Update viewport when the metadata or the window size changes. */

View File

@ -928,16 +928,10 @@ nsWindow::OnGlobalAndroidEvent(AndroidGeckoEvent *ae)
}
case AndroidGeckoEvent::SIZE_CHANGED: {
nsTArray<nsIntPoint> points = ae->Points();
NS_ASSERTION(points.Length() != 3, "Size changed does not have enough coordinates");
NS_ASSERTION(points.Length() == 3, "Size changed does not have enough coordinates");
#ifdef MOZ_JAVA_COMPOSITOR
int nw = points[1].x;
int nh = points[1].y;
#else
int nw = points[0].x;
int nh = points[0].y;
#endif
if (ae->Type() == AndroidGeckoEvent::FORCED_RESIZE || nw != gAndroidBounds.width ||
nh != gAndroidBounds.height) {