Bug 749063 - Replace shouldAbort with generic callback for progressive updates. r=bgirard

Replace ShouldAbortProgressiveUpdate with ProgressiveUpdateCallback, that
provides more contextual information about how the update will get used.
This commit is contained in:
Chris Lord 2012-10-15 09:33:34 +01:00
Родитель e3cd9c3213
Коммит b3c7e8e90c
10 изменённых файлов: 215 добавлений и 40 удалений

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

@ -1278,7 +1278,10 @@ BasicShadowLayerManager::SetIsFirstPaint()
}
bool
BasicShadowLayerManager::ShouldAbortProgressiveUpdate(bool aHasPendingNewThebesContent)
BasicShadowLayerManager::ProgressiveUpdateCallback(bool aHasPendingNewThebesContent,
gfx::Rect& aViewport,
float& aScaleX,
float& aScaleY)
{
#ifdef MOZ_WIDGET_ANDROID
Layer* primaryScrollable = GetPrimaryScrollableLayer();
@ -1295,8 +1298,9 @@ BasicShadowLayerManager::ShouldAbortProgressiveUpdate(bool aHasPendingNewThebesC
metrics.mDisplayPort.width * devPixelRatioX,
metrics.mDisplayPort.height * devPixelRatioY);
return AndroidBridge::Bridge()->ShouldAbortProgressiveUpdate(
aHasPendingNewThebesContent, displayPort, devPixelRatioX);
return AndroidBridge::Bridge()->ProgressiveUpdateCallback(
aHasPendingNewThebesContent, displayPort, devPixelRatioX,
aViewport, aScaleX, aScaleY);
}
#endif

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

@ -273,12 +273,19 @@ public:
void SetRepeatTransaction() { mRepeatTransaction = true; }
/**
* Determines if a progressive update should be cancelled. This is only called
* if gfxPlatform::UseProgressiveTilePainting() returns true.
* aHasPendingNewThebesContent is true if there is a Thebes layer update
* that will cause its valid region to expand.
* Called for each iteration of a progressive tile update. Fills
* aViewport, aScaleX and aScaleY with the current scale and viewport
* being used to composite the layers in this manager, to determine what area
* intersects with the target render rectangle.
* Returns true if the update should continue, or false if it should be
* cancelled.
* This is only called if gfxPlatform::UseProgressiveTilePainting() returns
* true.
*/
bool ShouldAbortProgressiveUpdate(bool aHasPendingNewThebesContent);
bool ProgressiveUpdateCallback(bool aHasPendingNewThebesContent,
gfx::Rect& aViewport,
float& aScaleX,
float& aScaleY);
private:
/**

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

@ -285,9 +285,12 @@ BasicTiledThebesLayer::PaintThebes(gfxContext* aContext,
regionToPaint.Sub(regionToPaint, staleRegion);
}
// Find out if we should just abort this paint, usually due to there being
// an incoming, more relevant paint.
if (BasicManager()->ShouldAbortProgressiveUpdate(hasNewContent)) {
// Find out the current view transform to determine which tiles to draw
// first, and see if we should just abort this paint. Aborting is usually
// caused by there being an incoming, more relevant paint.
gfx::Rect viewport;
float scaleX, scaleY;
if (BasicManager()->ProgressiveUpdateCallback(hasNewContent, viewport, scaleX, scaleY)) {
return;
}

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

@ -154,6 +154,7 @@ FENNEC_JAVA_FILES = \
gfx/NinePatchTileLayer.java \
gfx/PanningPerfAPI.java \
gfx/PointUtils.java \
gfx/ProgressiveUpdateData.java \
gfx/RectUtils.java \
gfx/ScreenshotLayer.java \
gfx/ScrollbarLayer.java \

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

@ -72,6 +72,9 @@ public class GeckoLayerClient
/* Used as a temporary ViewTransform by syncViewportInfo */
private final ViewTransform mCurrentViewTransform;
/* Used as the return value of progressiveUpdateCallback */
private final ProgressiveUpdateData mProgressiveUpdateData;
/* This is written by the compositor thread and read by the UI thread. */
private volatile boolean mCompositorCreated;
@ -109,6 +112,7 @@ public class GeckoLayerClient
mRecordDrawTimes = true;
mDrawTimingQueue = new DrawTimingQueue();
mCurrentViewTransform = new ViewTransform(0, 0, 1);
mProgressiveUpdateData = new ProgressiveUpdateData();
mCompositorCreated = false;
mForceRedraw = true;
@ -362,17 +366,21 @@ public class GeckoLayerClient
// to abort the current update and continue with any subsequent ones. This
// is useful for slow-to-render pages when the display-port starts lagging
// behind enough that continuing to draw it is wasted effort.
public boolean shouldAbortProgressiveUpdate(boolean aHasPendingNewThebesContent,
float x, float y, float width, float height, float resolution) {
// XXX Grab a local copy of the last display-port sent to Gecko to
// avoid races when accessing it.
public ProgressiveUpdateData progressiveUpdateCallback(boolean aHasPendingNewThebesContent,
float x, float y, float width, float height, float resolution) {
// Grab a local copy of the last display-port sent to Gecko and the
// current viewport metrics to avoid races when accessing them.
DisplayPortMetrics displayPort = mDisplayPort;
ImmutableViewportMetrics viewportMetrics = mViewportMetrics;
mProgressiveUpdateData.setViewport(viewportMetrics);
mProgressiveUpdateData.abort = false;
// Always abort updates if the resolution has changed. There's no use
// in drawing at the incorrect resolution.
if (!FloatUtils.fuzzyEquals(resolution, displayPort.resolution)) {
Log.d(LOGTAG, "Aborting draw due to resolution change");
return true;
mProgressiveUpdateData.abort = true;
return mProgressiveUpdateData;
}
// XXX All sorts of rounding happens inside Gecko that becomes hard to
@ -388,7 +396,7 @@ public class GeckoLayerClient
Math.abs(displayPort.getTop() - y) <= 1 &&
Math.abs(displayPort.getBottom() - (y + height)) <= 1 &&
Math.abs(displayPort.getRight() - (x + width)) <= 1) {
return false;
return mProgressiveUpdateData;
}
// Abort updates when the display-port no longer contains the visible
@ -396,14 +404,13 @@ public class GeckoLayerClient
// boundaries).
// XXX This makes the assumption that we never let the visible area of
// the page fall outside of the display-port.
// Grab a local copy of the viewport metrics to avoid races.
ImmutableViewportMetrics viewportMetrics = mViewportMetrics;
if (Math.max(viewportMetrics.viewportRectLeft, viewportMetrics.pageRectLeft) + 1 < x ||
Math.max(viewportMetrics.viewportRectTop, viewportMetrics.pageRectTop) + 1 < y ||
Math.min(viewportMetrics.viewportRectRight, viewportMetrics.pageRectRight) - 1 > x + width ||
Math.min(viewportMetrics.viewportRectBottom, viewportMetrics.pageRectBottom) - 1 > y + height) {
Log.d(LOGTAG, "Aborting update due to viewport not in display-port");
return true;
mProgressiveUpdateData.abort = true;
return mProgressiveUpdateData;
}
// There's no new content (where new content is considered to be an
@ -414,10 +421,11 @@ public class GeckoLayerClient
// is slow to draw.
if (!aHasPendingNewThebesContent) {
Log.d(LOGTAG, "Aborting update due to more relevant display-port in event queue");
return true;
mProgressiveUpdateData.abort = true;
return mProgressiveUpdateData;
}
return false;
return mProgressiveUpdateData;
}
/** Implementation of GeckoEventResponder/GeckoEventListener. */

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

@ -0,0 +1,30 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.gfx;
/**
* This is the data structure that's returned by the progressive tile update
* callback function. It encompasses the current viewport and a boolean value
* representing whether the front-end is interested in the current progressive
* update continuing.
*/
public class ProgressiveUpdateData {
public float x;
public float y;
public float width;
public float height;
public float scale;
public boolean abort;
public void setViewport(ImmutableViewportMetrics viewport) {
this.x = viewport.viewportRectLeft;
this.y = viewport.viewportRectTop;
this.width = viewport.viewportRectRight - this.x;
this.height = viewport.viewportRectBottom - this.x;
this.scale = viewport.zoomFactor;
}
}

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

@ -2527,13 +2527,13 @@ AndroidBridge::GetDisplayPort(bool aPageSizeUpdate, bool aIsBrowserContentDispla
}
bool
AndroidBridge::ShouldAbortProgressiveUpdate(bool aHasPendingNewThebesContent, const gfx::Rect& aDisplayPort, float aDisplayResolution)
AndroidBridge::ProgressiveUpdateCallback(bool aHasPendingNewThebesContent, const gfx::Rect& aDisplayPort, float aDisplayResolution, gfx::Rect& aViewport, float& aScaleX, float& aScaleY)
{
AndroidGeckoLayerClient *client = mLayerClient;
if (!client)
return false;
return client->ShouldAbortProgressiveUpdate(aHasPendingNewThebesContent, aDisplayPort, aDisplayResolution);
return client->ProgressiveUpdateCallback(aHasPendingNewThebesContent, aDisplayPort, aDisplayResolution, aViewport, aScaleX, aScaleY);
}
void

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

@ -156,7 +156,7 @@ public:
nsresult TakeScreenshot(nsIDOMWindow *window, int32_t srcX, int32_t srcY, int32_t srcW, int32_t srcH, int32_t dstY, int32_t dstX, int32_t dstW, int32_t dstH, int32_t bufW, int32_t bufH, int32_t tabId, int32_t token, jobject buffer);
nsresult GetDisplayPort(bool aPageSizeUpdate, bool aIsBrowserContentDisplayed, int32_t tabId, nsIAndroidViewport* metrics, nsIAndroidDisplayport** displayPort);
bool ShouldAbortProgressiveUpdate(bool aHasPendingNewThebesContent, const gfx::Rect& aDisplayPort, float aDisplayResolution);
bool ProgressiveUpdateCallback(bool aHasPendingNewThebesContent, const gfx::Rect& aDisplayPort, float aDisplayResolution, gfx::Rect& aViewport, float& aScaleX, float& aScaleY);
static void NotifyPaintedRect(float top, float left, float bottom, float right);

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

@ -84,7 +84,7 @@ jmethodID AndroidGeckoLayerClient::jGetDisplayPort = 0;
jmethodID AndroidGeckoLayerClient::jViewportCtor = 0;
jfieldID AndroidGeckoLayerClient::jDisplayportPosition = 0;
jfieldID AndroidGeckoLayerClient::jDisplayportResolution = 0;
jmethodID AndroidGeckoLayerClient::jShouldAbortProgressiveUpdate = 0;
jmethodID AndroidGeckoLayerClient::jProgressiveUpdateCallbackMethod = 0;
jclass AndroidLayerRendererFrame::jLayerRendererFrameClass = 0;
jmethodID AndroidLayerRendererFrame::jBeginDrawingMethod = 0;
@ -97,6 +97,14 @@ jfieldID AndroidViewTransform::jXField = 0;
jfieldID AndroidViewTransform::jYField = 0;
jfieldID AndroidViewTransform::jScaleField = 0;
jclass AndroidProgressiveUpdateData::jProgressiveUpdateDataClass = 0;
jfieldID AndroidProgressiveUpdateData::jXField = 0;
jfieldID AndroidProgressiveUpdateData::jYField = 0;
jfieldID AndroidProgressiveUpdateData::jWidthField = 0;
jfieldID AndroidProgressiveUpdateData::jHeightField = 0;
jfieldID AndroidProgressiveUpdateData::jScaleField = 0;
jfieldID AndroidProgressiveUpdateData::jShouldAbortField = 0;
jclass AndroidGeckoSurfaceView::jGeckoSurfaceViewClass = 0;
jmethodID AndroidGeckoSurfaceView::jBeginDrawingMethod = 0;
jmethodID AndroidGeckoSurfaceView::jEndDrawingMethod = 0;
@ -187,6 +195,7 @@ mozilla::InitAndroidJavaWrappers(JNIEnv *jEnv)
AndroidGeckoLayerClient::InitGeckoLayerClientClass(jEnv);
AndroidLayerRendererFrame::InitLayerRendererFrameClass(jEnv);
AndroidViewTransform::InitViewTransformClass(jEnv);
AndroidProgressiveUpdateData::InitProgressiveUpdateDataClass(jEnv);
AndroidGeckoSurfaceView::InitGeckoSurfaceViewClass(jEnv);
}
@ -345,7 +354,6 @@ AndroidGeckoLayerClient::InitGeckoLayerClientClass(JNIEnv *jEnv)
jActivateProgramMethod = getMethod("activateProgram", "()V");
jDeactivateProgramMethod = getMethod("deactivateProgram", "()V");
jGetDisplayPort = getMethod("getDisplayPort", "(ZZILorg/mozilla/gecko/gfx/ViewportMetrics;)Lorg/mozilla/gecko/gfx/DisplayPortMetrics;");
jShouldAbortProgressiveUpdate = getMethod("shouldAbortProgressiveUpdate", "(ZFFFFF)Z");
jViewportClass = GetClassGlobalRef(jEnv, "org/mozilla/gecko/gfx/ViewportMetrics");
jViewportCtor = GetMethodID(jEnv, jViewportClass, "<init>", "(FFFFFFFFFFFFF)V");
@ -353,6 +361,8 @@ AndroidGeckoLayerClient::InitGeckoLayerClientClass(JNIEnv *jEnv)
jDisplayportClass = GetClassGlobalRef(jEnv, "org/mozilla/gecko/gfx/DisplayPortMetrics");
jDisplayportPosition = GetFieldID(jEnv, jDisplayportClass, "mPosition", "Landroid/graphics/RectF;");
jDisplayportResolution = GetFieldID(jEnv, jDisplayportClass, "resolution", "F");
jProgressiveUpdateCallbackMethod = getMethod("progressiveUpdateCallback",
"(ZFFFFF)Lorg/mozilla/gecko/gfx/ProgressiveUpdateData;");
#endif
}
@ -386,6 +396,23 @@ AndroidViewTransform::InitViewTransformClass(JNIEnv *jEnv)
#endif
}
void
AndroidProgressiveUpdateData::InitProgressiveUpdateDataClass(JNIEnv *jEnv)
{
#ifdef MOZ_ANDROID_OMTC
initInit();
jProgressiveUpdateDataClass = getClassGlobalRef("org/mozilla/gecko/gfx/ProgressiveUpdateData");
jXField = getField("x", "F");
jYField = getField("y", "F");
jWidthField = getField("width", "F");
jHeightField = getField("height", "F");
jScaleField = getField("scale", "F");
jShouldAbortField = getField("abort", "Z");
#endif
}
#undef initInit
#undef initClassGlobalRef
#undef getField
@ -701,6 +728,13 @@ AndroidViewTransform::Init(jobject jobj)
wrapped_obj = jobj;
}
void
AndroidProgressiveUpdateData::Init(jobject jobj)
{
NS_ABORT_IF_FALSE(wrapped_obj == nullptr, "Init called on non-null wrapped_obj!");
wrapped_obj = jobj;
}
void
AndroidGeckoSurfaceView::Init(jobject jobj)
{
@ -815,9 +849,12 @@ AndroidGeckoLayerClient::SyncViewportInfo(const nsIntRect& aDisplayPort, float a
}
bool
AndroidGeckoLayerClient::ShouldAbortProgressiveUpdate(bool aHasPendingNewThebesContent,
const gfx::Rect& aDisplayPort,
float aDisplayResolution)
AndroidGeckoLayerClient::ProgressiveUpdateCallback(bool aHasPendingNewThebesContent,
const gfx::Rect& aDisplayPort,
float aDisplayResolution,
gfx::Rect& aViewport,
float& aScaleX,
float& aScaleY)
{
JNIEnv *env = AndroidBridge::GetJNIEnv();
if (!env)
@ -825,17 +862,28 @@ AndroidGeckoLayerClient::ShouldAbortProgressiveUpdate(bool aHasPendingNewThebesC
AutoLocalJNIFrame jniFrame(env);
bool ret = env->CallBooleanMethod(wrapped_obj, jShouldAbortProgressiveUpdate,
aHasPendingNewThebesContent,
(float)aDisplayPort.x,
(float)aDisplayPort.y,
(float)aDisplayPort.width,
(float)aDisplayPort.height,
aDisplayResolution);
jobject progressiveUpdateDataJObj = env->CallObjectMethod(wrapped_obj,
jProgressiveUpdateCallbackMethod,
aHasPendingNewThebesContent,
(float)aDisplayPort.x,
(float)aDisplayPort.y,
(float)aDisplayPort.width,
(float)aDisplayPort.height,
aDisplayResolution);
if (jniFrame.CheckForException())
return false;
return ret;
NS_ABORT_IF_FALSE(progressiveUpdateDataJObj, "No progressive update data!");
AndroidProgressiveUpdateData progressiveUpdateData(progressiveUpdateDataJObj);
aViewport.x = progressiveUpdateData.GetX(env);
aViewport.y = progressiveUpdateData.GetY(env);
aViewport.width = progressiveUpdateData.GetWidth(env);
aViewport.height = progressiveUpdateData.GetHeight(env);
aScaleX = aScaleY = progressiveUpdateData.GetScale(env);
return progressiveUpdateData.GetShouldAbort(env);
}
jobject ConvertToJavaViewportMetrics(JNIEnv* env, nsIAndroidViewport* metrics) {
@ -1080,6 +1128,54 @@ AndroidViewTransform::GetScale(JNIEnv *env)
return env->GetFloatField(wrapped_obj, jScaleField);
}
float
AndroidProgressiveUpdateData::GetX(JNIEnv *env)
{
if (!env)
return 0.0f;
return env->GetFloatField(wrapped_obj, jXField);
}
float
AndroidProgressiveUpdateData::GetY(JNIEnv *env)
{
if (!env)
return 0.0f;
return env->GetFloatField(wrapped_obj, jYField);
}
float
AndroidProgressiveUpdateData::GetWidth(JNIEnv *env)
{
if (!env)
return 0.0f;
return env->GetFloatField(wrapped_obj, jWidthField);
}
float
AndroidProgressiveUpdateData::GetHeight(JNIEnv *env)
{
if (!env)
return 0.0f;
return env->GetFloatField(wrapped_obj, jHeightField);
}
float
AndroidProgressiveUpdateData::GetScale(JNIEnv *env)
{
if (!env)
return 0.0f;
return env->GetFloatField(wrapped_obj, jScaleField);
}
bool
AndroidProgressiveUpdateData::GetShouldAbort(JNIEnv *env)
{
if (!env)
return false;
return env->GetBooleanField(wrapped_obj, jShouldAbortField);
}
void
AndroidRect::Init(JNIEnv *jenv, jobject jobj)
{

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

@ -200,6 +200,32 @@ private:
static jfieldID jScaleField;
};
class AndroidProgressiveUpdateData : public WrappedJavaObject {
public:
static void InitProgressiveUpdateDataClass(JNIEnv *jEnv);
void Init(jobject jobj);
AndroidProgressiveUpdateData() {}
AndroidProgressiveUpdateData(jobject jobj) { Init(jobj); }
float GetX(JNIEnv *env);
float GetY(JNIEnv *env);
float GetWidth(JNIEnv *env);
float GetHeight(JNIEnv *env);
float GetScale(JNIEnv *env);
bool GetShouldAbort(JNIEnv *env);
private:
static jclass jProgressiveUpdateDataClass;
static jfieldID jXField;
static jfieldID jYField;
static jfieldID jWidthField;
static jfieldID jHeightField;
static jfieldID jScaleField;
static jfieldID jShouldAbortField;
};
class AndroidLayerRendererFrame : public WrappedJavaObject {
public:
static void InitLayerRendererFrameClass(JNIEnv *jEnv);
@ -233,7 +259,7 @@ public:
void SetPageRect(const gfx::Rect& aCssPageRect);
void SyncViewportInfo(const nsIntRect& aDisplayPort, float aDisplayResolution, bool aLayersUpdated,
nsIntPoint& aScrollOffset, float& aScaleX, float& aScaleY);
bool ShouldAbortProgressiveUpdate(bool aHasPendingNewThebesContent, const gfx::Rect& aDisplayPort, float aDisplayResolution);
bool ProgressiveUpdateCallback(bool aHasPendingNewThebesContent, const gfx::Rect& aDisplayPort, float aDisplayResolution, gfx::Rect& aViewport, float& aScaleX, float& aScaleY);
bool CreateFrame(AutoLocalJNIFrame *jniFrame, AndroidLayerRendererFrame& aFrame);
bool ActivateProgram(AutoLocalJNIFrame *jniFrame);
bool DeactivateProgram(AutoLocalJNIFrame *jniFrame);
@ -248,7 +274,7 @@ protected:
static jmethodID jActivateProgramMethod;
static jmethodID jDeactivateProgramMethod;
static jmethodID jGetDisplayPort;
static jmethodID jShouldAbortProgressiveUpdate;
static jmethodID jProgressiveUpdateCallbackMethod;
public:
static jclass jViewportClass;