Extract a setOriginAndResolution method to VirtualLayer and drop the locking as it is not needed.
authorKartikaya Gupta <kgupta@mozilla.com>
Thu, 23 Feb 2012 16:29:22 -0500
changeset 89239 ce31a3b140a2366a0aae3d1ac080da006b4146ef
parent 89238 0ae1019c0ae3d4f6922658e632b656773d67c474
child 89240 7f5e93b0ba54fab0095c754f5c85cdcf036effb4
push id22242
push userkgupta@mozilla.com
push dateWed, 14 Mar 2012 15:19:09 +0000
treeherdermozilla-central@936ef50fa498 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone13.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Extract a setOriginAndResolution method to VirtualLayer and drop the locking as it is not needed.
mobile/android/base/gfx/GeckoLayerClient.java
mobile/android/base/gfx/VirtualLayer.java
--- a/mobile/android/base/gfx/GeckoLayerClient.java
+++ b/mobile/android/base/gfx/GeckoLayerClient.java
@@ -216,50 +216,44 @@ public class GeckoLayerClient implements
 
         /* Used by robocop for testing purposes */
         if (mDrawListener != null) {
             mDrawListener.drawFinished(x, y, width, height);
         }
     }
 
     private void updateViewport(boolean onlyUpdatePageSize) {
-        mRootLayer.beginTransaction(); // Called on gecko thread
-        try {
-            synchronized (mLayerController) {
-                // save and restore the viewport size stored in java; never let the
-                // JS-side viewport dimensions override the java-side ones because
-                // java is the One True Source of this information, and allowing JS
-                // to override can lead to race conditions where this data gets clobbered.
-                FloatSize viewportSize = mLayerController.getViewportSize();
-                mGeckoViewport = mNewGeckoViewport;
-                mGeckoViewport.setSize(viewportSize);
+        synchronized (mLayerController) {
+            // save and restore the viewport size stored in java; never let the
+            // JS-side viewport dimensions override the java-side ones because
+            // java is the One True Source of this information, and allowing JS
+            // to override can lead to race conditions where this data gets clobbered.
+            FloatSize viewportSize = mLayerController.getViewportSize();
+            mGeckoViewport = mNewGeckoViewport;
+            mGeckoViewport.setSize(viewportSize);
 
-                PointF origin = mGeckoViewport.getOrigin();
-                mRootLayer.setOrigin(PointUtils.round(origin));
-                mRootLayer.setResolution(mGeckoViewport.getZoomFactor());
+            PointF origin = mGeckoViewport.getOrigin();
+            mRootLayer.setOriginAndResolution(PointUtils.round(origin), mGeckoViewport.getZoomFactor());
 
-                // Set the new origin and resolution instantly.
-                mRootLayer.performUpdates(null);
+            // Set the new origin and resolution instantly.
+            mRootLayer.performUpdates(null);
 
-                Log.e(LOGTAG, "### updateViewport onlyUpdatePageSize=" + onlyUpdatePageSize +
-                      " getTileViewport " + mGeckoViewport);
+            Log.e(LOGTAG, "### updateViewport onlyUpdatePageSize=" + onlyUpdatePageSize +
+                  " getTileViewport " + mGeckoViewport);
 
-                if (onlyUpdatePageSize) {
-                    // Don't adjust page size when zooming unless zoom levels are
-                    // approximately equal.
-                    if (FloatUtils.fuzzyEquals(mLayerController.getZoomFactor(),
-                            mGeckoViewport.getZoomFactor()))
-                        mLayerController.setPageSize(mGeckoViewport.getPageSize());
-                } else {
-                    mLayerController.setViewportMetrics(mGeckoViewport);
-                    mLayerController.abortPanZoomAnimation();
-                }
+            if (onlyUpdatePageSize) {
+                // Don't adjust page size when zooming unless zoom levels are
+                // approximately equal.
+                if (FloatUtils.fuzzyEquals(mLayerController.getZoomFactor(),
+                        mGeckoViewport.getZoomFactor()))
+                    mLayerController.setPageSize(mGeckoViewport.getPageSize());
+            } else {
+                mLayerController.setViewportMetrics(mGeckoViewport);
+                mLayerController.abortPanZoomAnimation();
             }
-        } finally {
-            mRootLayer.endTransaction();
         }
     }
 
     /* Informs Gecko that the screen size has changed. */
     private void sendResizeEventIfNecessary(boolean force) {
         Log.d(LOGTAG, "### sendResizeEventIfNecessary " + force);
 
         DisplayMetrics metrics = new DisplayMetrics();
--- a/mobile/android/base/gfx/VirtualLayer.java
+++ b/mobile/android/base/gfx/VirtualLayer.java
@@ -33,26 +33,48 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 package org.mozilla.gecko.gfx;
 
+import android.graphics.Point;
+
 public class VirtualLayer extends Layer {
     private IntSize mSize;
 
     @Override
     public void draw(RenderContext context) {
         // No-op.
     }
 
     @Override
     public IntSize getSize() {
         return mSize;
     }
 
     public void setSize(IntSize size) {
         mSize = size;
     }
+
+    void setOriginAndResolution(Point newOrigin, float newResolution) {
+        // This is an optimized version of the following code:
+        // beginTransaction();
+        // try {
+        //     setOrigin(newOrigin);
+        //     setResolution(newResolution);
+        //     performUpdates(null);
+        // } finally {
+        //     endTransaction();
+        // }
+
+        // it is safe to drop the transaction lock in this instance (i.e. for the
+        // VirtualLayer that is just a shadow of what gecko is painting) because
+        // the origin and resolution of this layer are never used for anything
+        // meaningful.
+
+        mOrigin = newOrigin;
+        mResolution = newResolution;
+    }
 }