Bug 737553 - Fix null handling in DisplayPortCalculator. r=Cwiiis
authorKartikaya Gupta <kgupta@mozilla.com>
Fri, 30 Mar 2012 09:46:27 -0400
changeset 90727 ba83e928fec3f78c0c6cb70c11c1104c91c78b2a
parent 90726 d5a7628eed875905a4b3b8f7860c97a04dfb7355
child 90728 10cf1144522fe8588bd4a58f17509f53ff24f2e3
push id22382
push userbmo@edmorley.co.uk
push dateSat, 31 Mar 2012 21:44:34 +0000
treeherdermozilla-central@bbe5086163c9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersCwiiis
bugs737553
milestone14.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
Bug 737553 - Fix null handling in DisplayPortCalculator. r=Cwiiis
mobile/android/base/GeckoAppShell.java
mobile/android/base/gfx/DisplayPortCalculator.java
--- a/mobile/android/base/GeckoAppShell.java
+++ b/mobile/android/base/GeckoAppShell.java
@@ -1769,17 +1769,17 @@ public class GeckoAppShell
                     response = newResponse;
                 }
             }
 
             if (response != null)
                 return response;
 
         } catch (Exception e) {
-            Log.i(LOGTAG, "handleGeckoMessage throws " + e);
+            Log.e(LOGTAG, "handleGeckoMessage throws " + e, e);
         }
 
         return "";
     }
 
     public static void disableBatteryNotifications() {
         GeckoBatteryManager.disableNotifications();
     }
--- a/mobile/android/base/gfx/DisplayPortCalculator.java
+++ b/mobile/android/base/gfx/DisplayPortCalculator.java
@@ -7,25 +7,29 @@ package org.mozilla.gecko.gfx;
 
 import android.graphics.PointF;
 import android.graphics.RectF;
 import org.mozilla.gecko.FloatUtils;
 import org.mozilla.gecko.GeckoAppShell;
 
 final class DisplayPortCalculator {
     private static final String LOGTAG = "GeckoDisplayPortCalculator";
+    private static final PointF ZERO_VELOCITY = new PointF(0, 0);
 
     private static DisplayPortStrategy sStrategy = new FixedMarginStrategy();
 
     static DisplayPortMetrics calculate(ImmutableViewportMetrics metrics, PointF velocity) {
-        return sStrategy.calculate(metrics, velocity);
+        return sStrategy.calculate(metrics, (velocity == null ? ZERO_VELOCITY : velocity));
     }
 
     static boolean aboutToCheckerboard(ImmutableViewportMetrics metrics, PointF velocity, DisplayPortMetrics displayPort) {
-        return sStrategy.aboutToCheckerboard(metrics, velocity, displayPort);
+        if (displayPort == null) {
+            return true;
+        }
+        return sStrategy.aboutToCheckerboard(metrics, (velocity == null ? ZERO_VELOCITY : velocity), displayPort);
     }
 
     private interface DisplayPortStrategy {
         /** Calculates a displayport given a viewport and panning velocity. */
         public DisplayPortMetrics calculate(ImmutableViewportMetrics metrics, PointF velocity);
         /** Returns true if a checkerboard is about to be visible and we should not throttle drawing. */
         public boolean aboutToCheckerboard(ImmutableViewportMetrics metrics, PointF velocity, DisplayPortMetrics displayPort);
     }
@@ -121,20 +125,16 @@ final class DisplayPortCalculator {
             return new DisplayPortMetrics(metrics.viewportRectLeft - leftMargin,
                     metrics.viewportRectTop - topMargin,
                     metrics.viewportRectRight + rightMargin,
                     metrics.viewportRectBottom + bottomMargin,
                     metrics.zoomFactor);
         }
 
         public boolean aboutToCheckerboard(ImmutableViewportMetrics metrics, PointF velocity, DisplayPortMetrics displayPort) {
-            if (displayPort == null) {
-                return true;
-            }
-
             // Increase the size of the viewport (and clamp to page boundaries), and
             // intersect it with the tile's displayport to determine whether we're
             // close to checkerboarding.
             FloatSize pageSize = metrics.getPageSize();
             RectF adjustedViewport = RectUtils.expand(metrics.getViewport(), DANGER_ZONE_X, DANGER_ZONE_Y);
             if (adjustedViewport.top < 0) adjustedViewport.top = 0;
             if (adjustedViewport.left < 0) adjustedViewport.left = 0;
             if (adjustedViewport.right > pageSize.width) adjustedViewport.right = pageSize.width;
@@ -283,17 +283,17 @@ final class DisplayPortCalculator {
         private static final float DANGER_ZONE_MULTIPLIER = 0.10f; // must be less than (SIZE_MULTIPLIER - 1.0f) / 2
 
         public DisplayPortMetrics calculate(ImmutableViewportMetrics metrics, PointF velocity) {
             float baseWidth = metrics.getWidth() * SIZE_MULTIPLIER;
             float baseHeight = metrics.getHeight() * SIZE_MULTIPLIER;
 
             float width = baseWidth;
             float height = baseHeight;
-            if (velocity != null && velocity.length() > VELOCITY_EXPANSION_THRESHOLD) {
+            if (velocity.length() > VELOCITY_EXPANSION_THRESHOLD) {
                 // increase width and height based on the velocity, but maintaining aspect ratio.
                 float velocityFactor = Math.max(Math.abs(velocity.x) / width,
                                                 Math.abs(velocity.y) / height);
                 velocityFactor *= VELOCITY_MULTIPLIER;
 
                 width += (width * velocityFactor);
                 height += (height * velocityFactor);
             }
@@ -397,32 +397,28 @@ final class DisplayPortCalculator {
             if (velocity < 0) {
                 return amount * SLOW_SPLIT_FACTOR;
             } else {
                 return amount * (1.0f - SLOW_SPLIT_FACTOR);
             }
         }
 
         public boolean aboutToCheckerboard(ImmutableViewportMetrics metrics, PointF velocity, DisplayPortMetrics displayPort) {
-            if (displayPort == null) {
-                return true;
-            }
-
             // Expand the viewport based on our velocity (and clamp it to page boundaries).
             // Then intersect it with the last-requested displayport to determine whether we're
             // close to checkerboarding.
 
             float left = metrics.viewportRectLeft;
             float right = metrics.viewportRectRight;
             float top = metrics.viewportRectTop;
             float bottom = metrics.viewportRectBottom;
 
             // first we expand the viewport in the direction we're moving based on some
             // multiple of the current velocity.
-            if (velocity != null && velocity.length() > 0) {
+            if (velocity.length() > 0) {
                 if (velocity.x < 0) {
                     left += velocity.x * PREDICTION_VELOCITY_MULTIPLIER;
                 } else if (velocity.x > 0) {
                     right += velocity.x * PREDICTION_VELOCITY_MULTIPLIER;
                 }
 
                 if (velocity.y < 0) {
                     top += velocity.y * PREDICTION_VELOCITY_MULTIPLIER;