Bug 740569 - Make the display port strategy preffable. r=Cwiiis
authorKartikaya Gupta <kgupta@mozilla.com>
Fri, 30 Mar 2012 09:57:39 -0400
changeset 90729 931fe44e63264f676c1e2811c6c0fd14882866ec
parent 90728 10cf1144522fe8588bd4a58f17509f53ff24f2e3
child 90730 301109c610001d73ee8ae4f6e256da897db162f1
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
bugs740569
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 740569 - Make the display port strategy preffable. r=Cwiiis
mobile/android/app/mobile.js
mobile/android/base/gfx/DisplayPortCalculator.java
mobile/android/base/gfx/GeckoLayerClient.java
--- a/mobile/android/app/mobile.js
+++ b/mobile/android/app/mobile.js
@@ -356,16 +356,20 @@ pref("places.frecency.downloadVisitBonus
 pref("places.frecency.permRedirectVisitBonus", 0);
 pref("places.frecency.tempRedirectVisitBonus", 0);
 pref("places.frecency.defaultVisitBonus", 0);
 pref("places.frecency.unvisitedBookmarkBonus", 140);
 pref("places.frecency.unvisitedTypedBonus", 200);
 
 // disable color management
 pref("gfx.color_management.mode", 0);
+#ifdef ANDROID
+// 0=fixed margin, 1=velocity bias, 2=dynamic resolution, 3=no margins
+pref("gfx.displayport.strategy", 0);
+#endif
 
 // don't allow JS to move and resize existing windows
 pref("dom.disable_window_move_resize", true);
 
 // prevent click image resizing for nsImageDocument
 pref("browser.enable_click_image_resizing", false);
 
 // open in tab preferences
--- a/mobile/android/base/gfx/DisplayPortCalculator.java
+++ b/mobile/android/base/gfx/DisplayPortCalculator.java
@@ -2,16 +2,17 @@
  * 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;
 
 import android.graphics.PointF;
 import android.graphics.RectF;
+import android.util.Log;
 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();
@@ -22,16 +23,40 @@ final class DisplayPortCalculator {
 
     static boolean aboutToCheckerboard(ImmutableViewportMetrics metrics, PointF velocity, DisplayPortMetrics displayPort) {
         if (displayPort == null) {
             return true;
         }
         return sStrategy.aboutToCheckerboard(metrics, (velocity == null ? ZERO_VELOCITY : velocity), displayPort);
     }
 
+    /**
+     * Set the active strategy to use.
+     * See the gfx.displayport.strategy pref in mobile/android/app/mobile.js to see the
+     * mapping between ints and strategies.
+     */
+    static void setStrategy(int strategy) {
+        switch (strategy) {
+            case 0:
+            default:
+                sStrategy = new FixedMarginStrategy();
+                break;
+            case 1:
+                sStrategy = new VelocityBiasStrategy();
+                break;
+            case 2:
+                sStrategy = new DynamicResolutionStrategy();
+                break;
+            case 3:
+                sStrategy = new NoMarginStrategy();
+                break;
+        }
+        Log.i(LOGTAG, "Set strategy " + sStrategy.getClass().getName());
+    }
+
     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);
     }
 
     /**
--- a/mobile/android/base/gfx/GeckoLayerClient.java
+++ b/mobile/android/base/gfx/GeckoLayerClient.java
@@ -38,32 +38,34 @@
 
 package org.mozilla.gecko.gfx;
 
 import org.mozilla.gecko.FloatUtils;
 import org.mozilla.gecko.GeckoApp;
 import org.mozilla.gecko.GeckoAppShell;
 import org.mozilla.gecko.GeckoEvent;
 import org.mozilla.gecko.GeckoEventResponder;
+import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
 import android.content.Context;
 import android.graphics.Bitmap;
 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;
 
 public class GeckoLayerClient implements GeckoEventResponder,
                                          FlexibleGLSurfaceView.Listener {
     private static final String LOGTAG = "GeckoLayerClient";
+    private static final String PREF_DISPLAYPORT_STRATEGY = "gfx.displayport.strategy";
 
     private LayerController mLayerController;
     private LayerRenderer mLayerRenderer;
     private boolean mLayerRendererInitialized;
 
     private IntSize mScreenSize;
     private IntSize mWindowSize;
     private DisplayPortMetrics mDisplayPort;
@@ -105,22 +107,24 @@ public class GeckoLayerClient implements
 
         mRootLayer = new VirtualLayer(new IntSize(view.getWidth(), view.getHeight()));
         mLayerRenderer = new LayerRenderer(view);
 
         GeckoAppShell.registerGeckoEventListener("Viewport:Update", this);
         GeckoAppShell.registerGeckoEventListener("Viewport:PageSize", this);
         GeckoAppShell.registerGeckoEventListener("Viewport:CalculateDisplayPort", this);
         GeckoAppShell.registerGeckoEventListener("Checkerboard:Toggle", this);
+        GeckoAppShell.registerGeckoEventListener("Preferences:Data", this);
 
         view.setListener(this);
         view.setLayerRenderer(mLayerRenderer);
         layerController.setRoot(mRootLayer);
 
         sendResizeEventIfNecessary(true);
+        GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Preferences:Get", "[ \"" + PREF_DISPLAYPORT_STRATEGY + "\" ]"));
     }
 
     DisplayPortMetrics getDisplayPort() {
         return mDisplayPort;
     }
 
     /* Informs Gecko that the screen size has changed. */
     private void sendResizeEventIfNecessary(boolean force) {
@@ -229,26 +233,31 @@ public class GeckoLayerClient implements
             if ("Viewport:Update".equals(event)) {
                 handleViewportMessage(message, ViewportMessageType.UPDATE);
             } else if ("Viewport:PageSize".equals(event)) {
                 handleViewportMessage(message, ViewportMessageType.PAGE_SIZE);
             } else if ("Viewport:CalculateDisplayPort".equals(event)) {
                 ImmutableViewportMetrics newMetrics = new ImmutableViewportMetrics(new ViewportMetrics(message));
                 mReturnDisplayPort = DisplayPortCalculator.calculate(newMetrics, null);
             } else if ("Checkerboard:Toggle".equals(event)) {
-                try {
-                    boolean showChecks = message.getBoolean("value");
-                    mLayerController.setCheckerboardShowChecks(showChecks);
-                    Log.i(LOGTAG, "Showing checks: " + showChecks);
-                } catch(JSONException ex) {
-                    Log.e(LOGTAG, "Error decoding JSON", ex);
+                boolean showChecks = message.getBoolean("value");
+                mLayerController.setCheckerboardShowChecks(showChecks);
+                Log.i(LOGTAG, "Showing checks: " + showChecks);
+            } else if ("Preferences:Data".equals(event)) {
+                JSONArray jsonPrefs = message.getJSONArray("preferences");
+                for (int i = jsonPrefs.length() - 1; i >= 0; i--) {
+                    JSONObject pref = jsonPrefs.getJSONObject(i);
+                    if (pref.getString("name").equals(PREF_DISPLAYPORT_STRATEGY)) {
+                        DisplayPortCalculator.setStrategy(pref.getInt("value"));
+                        GeckoAppShell.unregisterGeckoEventListener("Preferences:Data", this);
+                    }
                 }
             }
         } catch (JSONException e) {
-            Log.e(LOGTAG, "Unable to create viewport metrics in " + event + " handler", e);
+            Log.e(LOGTAG, "Error decoding JSON in " + event + " handler", e);
         }
     }
 
     /** Implementation of GeckoEventResponder. */
     public String getResponse() {
         // We are responding to the events handled in handleMessage() above with the
         // display port we calculated. Different messages will generate different
         // display ports and put them in mReturnDisplayPort, so we just return that.