Bug 1021085 - Fix up the Fennec code path as well. r=Cwiiis, a=2.0+
authorKartikaya Gupta <kgupta@mozilla.com>
Mon, 23 Jun 2014 08:42:53 -0400
changeset 207274 1fede0b2aa9869c0996fb64cb821ebb14fd805e1
parent 207273 0d72bf6d5c3cc4248d3a1fb3eeba301bf457956f
child 207275 5f7f6ee7fe2eb224e0b6a86c1a755640a0660038
push id3741
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 20:25:18 +0000
treeherdermozilla-beta@4d6f46f5af68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersCwiiis, 2
bugs1021085
milestone32.0a2
Bug 1021085 - Fix up the Fennec code path as well. r=Cwiiis, a=2.0+
gfx/layers/client/ClientLayerManager.cpp
gfx/layers/client/ClientLayerManager.h
gfx/layers/client/TiledContentClient.cpp
gfx/layers/client/TiledContentClient.h
mobile/android/base/gfx/ProgressiveUpdateData.java
widget/android/AndroidBridge.cpp
widget/android/AndroidBridge.h
widget/android/GeneratedJNIWrappers.cpp
widget/android/GeneratedJNIWrappers.h
--- a/gfx/layers/client/ClientLayerManager.cpp
+++ b/gfx/layers/client/ClientLayerManager.cpp
@@ -601,37 +601,40 @@ ClientLayerManager::GetBackendName(nsASt
     case LayersBackend::LAYERS_D3D10: aName.AssignLiteral("Direct3D 10"); return;
     case LayersBackend::LAYERS_D3D11: aName.AssignLiteral("Direct3D 11"); return;
     default: NS_RUNTIMEABORT("Invalid backend");
   }
 }
 
 bool
 ClientLayerManager::ProgressiveUpdateCallback(bool aHasPendingNewThebesContent,
-                                              ParentLayerRect& aCompositionBounds,
-                                              CSSToParentLayerScale& aZoom,
+                                              FrameMetrics& aMetrics,
                                               bool aDrawingCritical)
 {
-  aZoom.scale = 1.0;
 #ifdef MOZ_WIDGET_ANDROID
   Layer* primaryScrollable = GetPrimaryScrollableLayer();
   if (primaryScrollable) {
     const FrameMetrics& metrics = primaryScrollable->AsContainerLayer()->GetFrameMetrics();
 
     // This is derived from the code in
     // gfx/layers/ipc/CompositorParent.cpp::TransformShadowTree.
     CSSToLayerScale paintScale = metrics.LayersPixelsPerCSSPixel();
     const CSSRect& metricsDisplayPort =
       (aDrawingCritical && !metrics.mCriticalDisplayPort.IsEmpty()) ?
         metrics.mCriticalDisplayPort : metrics.mDisplayPort;
     LayerRect displayPort = (metricsDisplayPort + metrics.GetScrollOffset()) * paintScale;
 
-    return AndroidBridge::Bridge()->ProgressiveUpdateCallback(
+    ScreenPoint scrollOffset;
+    CSSToScreenScale zoom;
+    bool ret = AndroidBridge::Bridge()->ProgressiveUpdateCallback(
       aHasPendingNewThebesContent, displayPort, paintScale.scale, aDrawingCritical,
-      aCompositionBounds, aZoom);
+      scrollOffset, zoom);
+    aMetrics.SetScrollOffset(scrollOffset / zoom);
+    aMetrics.SetZoom(zoom);
+    return ret;
   }
 #endif
 
   return false;
 }
 
 ClientLayer::~ClientLayer()
 {
--- a/gfx/layers/client/ClientLayerManager.h
+++ b/gfx/layers/client/ClientLayerManager.h
@@ -131,30 +131,29 @@ public:
   { return mThebesLayerCallback; }
 
   void* GetThebesLayerCallbackData() const
   { return mThebesLayerCallbackData; }
 
   CompositorChild *GetRemoteRenderer();
 
   /**
-   * Called for each iteration of a progressive tile update. Fills
-   * aCompositionBounds and aZoom with the current scale and composition bounds
-   * being used to composite the layers in this manager, to determine what area
+   * Called for each iteration of a progressive tile update. Updates
+   * aMetrics with the current scroll offset and scale being used to composite
+   * the primary scrollable layer in this manager, to determine what area
    * intersects with the target composition bounds.
    * aDrawingCritical will be true if the current drawing operation is using
    * the critical displayport.
    * Returns true if the update should continue, or false if it should be
    * cancelled.
    * This is only called if gfxPlatform::UseProgressiveTilePainting() returns
    * true.
    */
   bool ProgressiveUpdateCallback(bool aHasPendingNewThebesContent,
-                                 ParentLayerRect& aCompositionBounds,
-                                 CSSToParentLayerScale& aZoom,
+                                 FrameMetrics& aMetrics,
                                  bool aDrawingCritical);
 
   bool InConstruction() { return mPhase == PHASE_CONSTRUCTION; }
 #ifdef DEBUG
   bool InDrawing() { return mPhase == PHASE_DRAWING; }
   bool InForward() { return mPhase == PHASE_FORWARD; }
 #endif
   bool InTransaction() { return mPhase != PHASE_NONE; }
--- a/gfx/layers/client/TiledContentClient.cpp
+++ b/gfx/layers/client/TiledContentClient.cpp
@@ -138,16 +138,31 @@ SharedFrameMetricsHelper::~SharedFrameMe
   MOZ_COUNT_DTOR(SharedFrameMetricsHelper);
 }
 
 static inline bool
 FuzzyEquals(float a, float b) {
   return (fabsf(a - b) < 1e-6);
 }
 
+static ViewTransform
+ComputeViewTransform(const FrameMetrics& aContentMetrics, const FrameMetrics& aCompositorMetrics)
+{
+  // This is basically the same code as AsyncPanZoomController::GetCurrentAsyncTransform
+  // but with aContentMetrics used in place of mLastContentPaintMetrics, because they
+  // should be equivalent, modulo race conditions while transactions are inflight.
+
+  LayerPoint translation = (aCompositorMetrics.GetScrollOffset() - aContentMetrics.GetScrollOffset())
+                         * aContentMetrics.LayersPixelsPerCSSPixel();
+  return ViewTransform(-translation,
+                       aCompositorMetrics.GetZoom()
+                     / aContentMetrics.mDevPixelsPerCSSPixel
+                     / aCompositorMetrics.GetParentResolution());
+}
+
 bool
 SharedFrameMetricsHelper::UpdateFromCompositorFrameMetrics(
     ContainerLayer* aLayer,
     bool aHasPendingNewThebesContent,
     bool aLowPrecision,
     ViewTransform& aViewTransform)
 {
   MOZ_ASSERT(aLayer);
@@ -211,32 +226,16 @@ SharedFrameMetricsHelper::UpdateFromComp
   // display-port in the pipeline.
   if (aLowPrecision && !aHasPendingNewThebesContent) {
     return true;
   }
 
   return false;
 }
 
-ViewTransform
-SharedFrameMetricsHelper::ComputeViewTransform(const FrameMetrics& aContentMetrics,
-                                               const FrameMetrics& aCompositorMetrics)
-{
-  // This is basically the same code as AsyncPanZoomController::GetCurrentAsyncTransform
-  // but with aContentMetrics used in place of mLastContentPaintMetrics, because they
-  // should be equivalent, modulo race conditions while transactions are inflight.
-
-  LayerPoint translation = (aCompositorMetrics.GetScrollOffset() - aContentMetrics.GetScrollOffset())
-                         * aContentMetrics.LayersPixelsPerCSSPixel();
-  return ViewTransform(-translation,
-                       aCompositorMetrics.GetZoom()
-                     / aContentMetrics.mDevPixelsPerCSSPixel
-                     / aCompositorMetrics.GetParentResolution());
-}
-
 bool
 SharedFrameMetricsHelper::AboutToCheckerboard(const FrameMetrics& aContentMetrics,
                                               const FrameMetrics& aCompositorMetrics)
 {
   CSSRect painted =
         (aContentMetrics.mCriticalDisplayPort.IsEmpty() ? aContentMetrics.mDisplayPort : aContentMetrics.mCriticalDisplayPort)
         + aContentMetrics.GetScrollOffset();
   // Inflate painted by some small epsilon to deal with rounding
@@ -962,19 +961,27 @@ ClientTiledLayerBuffer::ComputeProgressi
   ContainerLayer* scrollAncestor = nullptr;
   mThebesLayer->GetAncestorLayers(&scrollAncestor, nullptr);
 
   // 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.
   ViewTransform viewTransform;
 #if defined(MOZ_WIDGET_ANDROID)
-  bool abortPaint = mManager->ProgressiveUpdateCallback(!staleRegion.Contains(aInvalidRegion),
-                                                        viewTransform,
-                                                        !drawingLowPrecision);
+  FrameMetrics compositorMetrics = scrollAncestor->GetFrameMetrics();
+  bool abortPaint = false;
+  // On Android, only the primary scrollable layer is async-scrolled, and the only one
+  // that the Java-side code can provide details about. If we're tiling some other layer
+  // then we already have all the information we need about it.
+  if (scrollAncestor == mManager->GetPrimaryScrollableLayer()) {
+    abortPaint = mManager->ProgressiveUpdateCallback(!staleRegion.Contains(aInvalidRegion),
+                                                     compositorMetrics,
+                                                     !drawingLowPrecision);
+    viewTransform = ComputeViewTransform(scrollAncestor->GetFrameMetrics(), compositorMetrics);
+  }
 #else
   MOZ_ASSERT(mSharedFrameMetricsHelper);
 
   bool abortPaint =
     mSharedFrameMetricsHelper->UpdateFromCompositorFrameMetrics(
       scrollAncestor,
       !staleRegion.Contains(aInvalidRegion),
       drawingLowPrecision,
--- a/gfx/layers/client/TiledContentClient.h
+++ b/gfx/layers/client/TiledContentClient.h
@@ -316,23 +316,16 @@ public:
    * behind enough that continuing to draw it is wasted effort.
    */
   bool UpdateFromCompositorFrameMetrics(ContainerLayer* aLayer,
                                         bool aHasPendingNewThebesContent,
                                         bool aLowPrecision,
                                         ViewTransform& aViewTransform);
 
   /**
-   * Compute the APZ's async transform given the content-side and
-   * compositor-side metrics for the layer.
-   */
-  ViewTransform ComputeViewTransform(const FrameMetrics& aContentMetrics,
-                                     const FrameMetrics& aCompositorMetrics);
-
-  /**
    * Determines if the compositor's upcoming composition bounds has fallen
    * outside of the contents display port. If it has then the compositor
    * will start to checker board. Checker boarding is when the compositor
    * tries to composite a tile and it is not available. Historically
    * a tile with a checker board pattern was used. Now a blank tile is used.
    */
   bool AboutToCheckerboard(const FrameMetrics& aContentMetrics,
                            const FrameMetrics& aCompositorMetrics);
--- a/mobile/android/base/gfx/ProgressiveUpdateData.java
+++ b/mobile/android/base/gfx/ProgressiveUpdateData.java
@@ -12,22 +12,18 @@ import org.mozilla.gecko.mozglue.generat
  * callback function. It encompasses the current viewport and a boolean value
  * representing whether the front-end is interested in the current progressive
  * update continuing.
  */
 @WrapEntireClassForJNI
 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.y;
         this.scale = viewport.zoomFactor;
     }
 }
 
--- a/widget/android/AndroidBridge.cpp
+++ b/widget/android/AndroidBridge.cpp
@@ -1947,17 +1947,18 @@ AndroidBridge::IsContentDocumentDisplaye
 {
     if (!mLayerClient)
         return false;
 
     return mLayerClient->IsContentDocumentDisplayed();
 }
 
 bool
-AndroidBridge::ProgressiveUpdateCallback(bool aHasPendingNewThebesContent, const LayerRect& aDisplayPort, float aDisplayResolution, bool aDrawingCritical, ParentLayerRect& aCompositionBounds, CSSToParentLayerScale& aZoom)
+AndroidBridge::ProgressiveUpdateCallback(bool aHasPendingNewThebesContent, const LayerRect& aDisplayPort, float aDisplayResolution,
+                                         bool aDrawingCritical, ScreenPoint& aScrollOffset, CSSToScreenScale& aZoom)
 {
     mozilla::widget::android::GeckoLayerClient *client = mLayerClient;
     if (!client) {
         ALOG_BRIDGE("Exceptional Exit: %s", __PRETTY_FUNCTION__);
         return false;
     }
 
     jobject progressiveUpdateDataJObj = client->ProgressiveUpdateCallback(aHasPendingNewThebesContent,
@@ -1967,20 +1968,18 @@ AndroidBridge::ProgressiveUpdateCallback
                                                                    (float)aDisplayPort.height,
                                                                           aDisplayResolution,
                                                                          !aDrawingCritical);
 
     NS_ABORT_IF_FALSE(progressiveUpdateDataJObj, "No progressive update data!");
 
     ProgressiveUpdateData* progressiveUpdateData = ProgressiveUpdateData::Wrap(progressiveUpdateDataJObj);
 
-    aCompositionBounds.x = progressiveUpdateData->getx();
-    aCompositionBounds.y = progressiveUpdateData->gety();
-    aCompositionBounds.width = progressiveUpdateData->getwidth();
-    aCompositionBounds.height = progressiveUpdateData->getheight();
+    aScrollOffset.x = progressiveUpdateData->getx();
+    aScrollOffset.y = progressiveUpdateData->gety();
     aZoom.scale = progressiveUpdateData->getscale();
 
     bool ret = progressiveUpdateData->getabort();
     delete progressiveUpdateData;
 
     return ret;
 }
 
--- a/widget/android/AndroidBridge.h
+++ b/widget/android/AndroidBridge.h
@@ -195,17 +195,18 @@ public:
     bool GetThreadNameJavaProfiling(uint32_t aThreadId, nsCString & aResult);
     bool GetFrameNameJavaProfiling(uint32_t aThreadId, uint32_t aSampleId, uint32_t aFrameId, nsCString & aResult);
 
     nsresult CaptureThumbnail(nsIDOMWindow *window, int32_t bufW, int32_t bufH, int32_t tabId, jobject buffer, bool &shouldStore);
     void GetDisplayPort(bool aPageSizeUpdate, bool aIsBrowserContentDisplayed, int32_t tabId, nsIAndroidViewport* metrics, nsIAndroidDisplayport** displayPort);
     void ContentDocumentChanged();
     bool IsContentDocumentDisplayed();
 
-    bool ProgressiveUpdateCallback(bool aHasPendingNewThebesContent, const LayerRect& aDisplayPort, float aDisplayResolution, bool aDrawingCritical, mozilla::ParentLayerRect& aCompositionBounds, mozilla::CSSToParentLayerScale& aZoom);
+    bool ProgressiveUpdateCallback(bool aHasPendingNewThebesContent, const LayerRect& aDisplayPort, float aDisplayResolution, bool aDrawingCritical,
+                                   mozilla::ScreenPoint& aScrollOffset, mozilla::CSSToScreenScale& aZoom);
 
     void SetLayerClient(JNIEnv* env, jobject jobj);
     mozilla::widget::android::GeckoLayerClient* GetLayerClient() { return mLayerClient; }
 
     bool GetHandlersForURL(const nsAString& aURL,
                            nsIMutableArray* handlersArray = nullptr,
                            nsIHandlerApp **aDefaultApp = nullptr,
                            const nsAString& aAction = EmptyString());
--- a/widget/android/GeneratedJNIWrappers.cpp
+++ b/widget/android/GeneratedJNIWrappers.cpp
@@ -2026,31 +2026,27 @@ void NativePanZoomController::RequestCon
     env->CallVoidMethodA(wrapped_obj, jRequestContentRepaintWrapper, args);
     AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 jclass ProgressiveUpdateData::mProgressiveUpdateDataClass = 0;
 jmethodID ProgressiveUpdateData::jProgressiveUpdateData = 0;
 jmethodID ProgressiveUpdateData::jsetViewport = 0;
 jfieldID ProgressiveUpdateData::jabort = 0;
-jfieldID ProgressiveUpdateData::jheight = 0;
 jfieldID ProgressiveUpdateData::jscale = 0;
-jfieldID ProgressiveUpdateData::jwidth = 0;
 jfieldID ProgressiveUpdateData::jx = 0;
 jfieldID ProgressiveUpdateData::jy = 0;
 void ProgressiveUpdateData::InitStubs(JNIEnv *jEnv) {
     initInit();
 
     mProgressiveUpdateDataClass = getClassGlobalRef("org/mozilla/gecko/gfx/ProgressiveUpdateData");
     jProgressiveUpdateData = getMethod("<init>", "()V");
     jsetViewport = getMethod("setViewport", "(Lorg/mozilla/gecko/gfx/ImmutableViewportMetrics;)V");
     jabort = getField("abort", "Z");
-    jheight = getField("height", "F");
     jscale = getField("scale", "F");
-    jwidth = getField("width", "F");
     jx = getField("x", "F");
     jy = getField("y", "F");
 }
 
 ProgressiveUpdateData* ProgressiveUpdateData::Wrap(jobject obj) {
     JNIEnv *env = GetJNIForThread();
     ProgressiveUpdateData* ret = new ProgressiveUpdateData(obj, env);
     env->DeleteLocalRef(obj);
@@ -2085,46 +2081,26 @@ bool ProgressiveUpdateData::getabort() {
     return env->GetBooleanField(wrapped_obj, jabort);
 }
 
 void ProgressiveUpdateData::setabort(bool a0) {
     JNIEnv *env = GetJNIForThread();
     env->SetBooleanField(wrapped_obj, jabort, a0);
 }
 
-jfloat ProgressiveUpdateData::getheight() {
-    JNIEnv *env = GetJNIForThread();
-    return env->GetFloatField(wrapped_obj, jheight);
-}
-
-void ProgressiveUpdateData::setheight(jfloat a0) {
-    JNIEnv *env = GetJNIForThread();
-    env->SetFloatField(wrapped_obj, jheight, a0);
-}
-
 jfloat ProgressiveUpdateData::getscale() {
     JNIEnv *env = GetJNIForThread();
     return env->GetFloatField(wrapped_obj, jscale);
 }
 
 void ProgressiveUpdateData::setscale(jfloat a0) {
     JNIEnv *env = GetJNIForThread();
     env->SetFloatField(wrapped_obj, jscale, a0);
 }
 
-jfloat ProgressiveUpdateData::getwidth() {
-    JNIEnv *env = GetJNIForThread();
-    return env->GetFloatField(wrapped_obj, jwidth);
-}
-
-void ProgressiveUpdateData::setwidth(jfloat a0) {
-    JNIEnv *env = GetJNIForThread();
-    env->SetFloatField(wrapped_obj, jwidth, a0);
-}
-
 jfloat ProgressiveUpdateData::getx() {
     JNIEnv *env = GetJNIForThread();
     return env->GetFloatField(wrapped_obj, jx);
 }
 
 void ProgressiveUpdateData::setx(jfloat a0) {
     JNIEnv *env = GetJNIForThread();
     env->SetFloatField(wrapped_obj, jx, a0);
--- a/widget/android/GeneratedJNIWrappers.h
+++ b/widget/android/GeneratedJNIWrappers.h
@@ -375,34 +375,28 @@ class ProgressiveUpdateData : public Aut
 public:
     static void InitStubs(JNIEnv *jEnv);
     static ProgressiveUpdateData* Wrap(jobject obj);
     ProgressiveUpdateData(jobject obj, JNIEnv* env) : AutoGlobalWrappedJavaObject(obj, env) {};
     ProgressiveUpdateData();
     void setViewport(jobject a0);
     bool getabort();
     void setabort(bool a0);
-    jfloat getheight();
-    void setheight(jfloat a0);
     jfloat getscale();
     void setscale(jfloat a0);
-    jfloat getwidth();
-    void setwidth(jfloat a0);
     jfloat getx();
     void setx(jfloat a0);
     jfloat gety();
     void sety(jfloat a0);
 protected:
     static jclass mProgressiveUpdateDataClass;
     static jmethodID jProgressiveUpdateData;
     static jmethodID jsetViewport;
     static jfieldID jabort;
-    static jfieldID jheight;
     static jfieldID jscale;
-    static jfieldID jwidth;
     static jfieldID jx;
     static jfieldID jy;
 };
 
 class ViewTransform : public AutoGlobalWrappedJavaObject {
 public:
     static void InitStubs(JNIEnv *jEnv);
     static ViewTransform* Wrap(jobject obj);