Strip down GeckoLayerClient - scope down visibility of fields/methods, remove empty methods and dead code, and inline some one-liner methods.
authorKartikaya Gupta <kgupta@mozilla.com>
Wed, 22 Feb 2012 15:08:46 -0500
changeset 89219 ebf31251aa935308de49be00f2c795eafd66ac56
parent 89218 4f163dc55eb5f4b2eceddf2209e96d482a2e4471
child 89220 e48d0ef50574dcca9a64336c2d17afeeef417d21
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
Strip down GeckoLayerClient - scope down visibility of fields/methods, remove empty methods and dead code, and inline some one-liner methods.
mobile/android/base/gfx/GeckoLayerClient.java
--- a/mobile/android/base/gfx/GeckoLayerClient.java
+++ b/mobile/android/base/gfx/GeckoLayerClient.java
@@ -59,31 +59,31 @@ import android.view.View;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 public class GeckoLayerClient implements GeckoEventListener,
                                          FlexibleGLSurfaceView.Listener,
                                          VirtualLayer.Listener {
     private static final String LOGTAG = "GeckoLayerClient";
 
-    protected LayerController mLayerController;
+    private LayerController mLayerController;
     private LayerRenderer mLayerRenderer;
     private boolean mLayerRendererInitialized;
 
-    protected IntSize mScreenSize;
-    protected IntSize mWindowSize;
-    protected IntSize mBufferSize;
+    private IntSize mScreenSize;
+    private IntSize mWindowSize;
+    private IntSize mBufferSize;
 
-    protected Layer mTileLayer;
+    private Layer mTileLayer;
 
     /* The viewport that Gecko is currently displaying. */
-    protected ViewportMetrics mGeckoViewport;
+    private ViewportMetrics mGeckoViewport;
 
     /* The viewport that Gecko will display when drawing is finished */
-    protected ViewportMetrics mNewGeckoViewport;
+    private ViewportMetrics mNewGeckoViewport;
 
     private static final long MIN_VIEWPORT_CHANGE_DELAY = 25L;
     private long mLastViewportChangeTime;
     private boolean mPendingViewportAdjust;
     private boolean mViewportSizeChanged;
 
     // mUpdateViewportOnEndDraw is used to indicate that we received a
     // viewport update notification while drawing. therefore, when the
@@ -100,28 +100,28 @@ public class GeckoLayerClient implements
     private DrawListener mDrawListener;
 
     public GeckoLayerClient(Context context) {
         mScreenSize = new IntSize(0, 0);
         mBufferSize = new IntSize(0, 0);
     }
 
     /** Attaches the root layer to the layer controller so that Gecko appears. */
-    public void setLayerController(LayerController layerController) {
+    void setLayerController(LayerController layerController) {
         mLayerController = layerController;
 
         layerController.setRoot(mTileLayer);
         if (mGeckoViewport != null) {
             layerController.setViewportMetrics(mGeckoViewport);
         }
 
         GeckoAppShell.registerGeckoEventListener("Viewport:UpdateAndDraw", this);
         GeckoAppShell.registerGeckoEventListener("Viewport:UpdateLater", this);
 
-        sendResizeEventIfNecessary();
+        sendResizeEventIfNecessary(false);
 
         LayerView view = layerController.getView();
         view.setListener(this);
 
         mLayerRenderer = new LayerRenderer(view);
     }
 
     /** This function is invoked by Gecko via JNI; be careful when modifying signature. */
@@ -208,62 +208,61 @@ public class GeckoLayerClient implements
      * TODO: Would be cleaner if this took an android.graphics.Rect instead, but that would require
      * a little more JNI magic.
      */
     public void endDrawing(int x, int y, int width, int height) {
         synchronized (mLayerController) {
             try {
                 updateViewport(!mUpdateViewportOnEndDraw);
                 mUpdateViewportOnEndDraw = false;
-
-                Rect rect = new Rect(x, y, x + width, y + height);
-                updateLayerAfterDraw(rect);
             } finally {
                 mTileLayer.endTransaction();
             }
         }
         Log.i(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - endDrawing");
 
         /* Used by robocop for testing purposes */
         if (mDrawListener != null) {
             mDrawListener.drawFinished(x, y, width, height);
         }
     }
 
-    protected void updateViewport(boolean onlyUpdatePageSize) {
+    private void updateViewport(boolean onlyUpdatePageSize) {
         // 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 displayportOrigin = mGeckoViewport.getDisplayportOrigin();
         mTileLayer.setOrigin(PointUtils.round(displayportOrigin));
         mTileLayer.setResolution(mGeckoViewport.getZoomFactor());
 
-        this.tileLayerUpdated();
+        // Set the new origin and resolution instantly.
+        mTileLayer.performUpdates(null);
+
         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();
         }
     }
 
     /* Informs Gecko that the screen size has changed. */
-    protected void sendResizeEventIfNecessary(boolean force) {
+    private void sendResizeEventIfNecessary(boolean force) {
         Log.d(LOGTAG, "### sendResizeEventIfNecessary " + force);
 
         DisplayMetrics metrics = new DisplayMetrics();
         GeckoApp.mAppContext.getWindowManager().getDefaultDisplay().getMetrics(metrics);
 
         IntSize newScreenSize = new IntSize(metrics.widthPixels, metrics.heightPixels);
         IntSize newWindowSize = getBufferSize();
 
@@ -305,62 +304,43 @@ public class GeckoLayerClient implements
         }
 
         int r = Integer.parseInt(matcher.group(1));
         int g = Integer.parseInt(matcher.group(2));
         int b = Integer.parseInt(matcher.group(3));
         return Color.rgb(r, g, b);
     }
 
-    protected boolean handleDirectTextureChange(boolean hasDirectTexture) {
+    private boolean handleDirectTextureChange(boolean hasDirectTexture) {
         if (mTileLayer != null) {
             return false;
         }
 
         Log.e(LOGTAG, "### Creating virtual layer");
         VirtualLayer virtualLayer = new VirtualLayer();
         virtualLayer.setListener(this);
         virtualLayer.setSize(getBufferSize());
         mLayerController.setRoot(virtualLayer);
         mTileLayer = virtualLayer;
 
         sendResizeEventIfNecessary(true);
         return true;
     }
 
-    protected void updateLayerAfterDraw(Rect updatedRect) {
-        Log.e(LOGTAG, "### updateLayerAfterDraw");
-        // Nothing to do.
-    }
-
-    protected IntSize getBufferSize() {
+    private IntSize getBufferSize() {
         View view = mLayerController.getView();
         IntSize size = new IntSize(view.getWidth(), view.getHeight());
         Log.e(LOGTAG, "### getBufferSize " + size);
         return size;
     }
 
-    protected IntSize getTileSize() {
-        Log.e(LOGTAG, "### getTileSize " + getBufferSize());
-        return getBufferSize();
-    }
-
-    protected void tileLayerUpdated() {
-        // Set the new origin and resolution instantly.
-        mTileLayer.performUpdates(null);
-    }
-
     public Bitmap getBitmap() {
         return null;
     }
 
-    public void render() {
-        adjustViewportWithThrottling();
-    }
-
     private void adjustViewportWithThrottling() {
         if (!mLayerController.getRedrawHint())
             return;
 
         if (mPendingViewportAdjust)
             return;
 
         long timeDelta = System.currentTimeMillis() - mLastViewportChangeTime;
@@ -374,17 +354,17 @@ public class GeckoLayerClient implements
                 }, MIN_VIEWPORT_CHANGE_DELAY - timeDelta);
             mPendingViewportAdjust = true;
             return;
         }
 
         adjustViewport();
     }
 
-    public void viewportSizeChanged() {
+    void viewportSizeChanged() {
         mViewportSizeChanged = true;
     }
 
     private void adjustViewport() {
         ViewportMetrics viewportMetrics =
             new ViewportMetrics(mLayerController.getViewportMetrics());
 
         viewportMetrics.setViewport(viewportMetrics.getClampedViewport());
@@ -393,34 +373,35 @@ public class GeckoLayerClient implements
         if (mViewportSizeChanged) {
             mViewportSizeChanged = false;
             GeckoAppShell.viewSizeChanged();
         }
 
         mLastViewportChangeTime = System.currentTimeMillis();
     }
 
+    /** Implementation of GeckoEventListener. */
     public void handleMessage(String event, JSONObject message) {
         if ("Viewport:UpdateAndDraw".equals(event)) {
             Log.e(LOGTAG, "### Java side Viewport:UpdateAndDraw()!");
             mUpdateViewportOnEndDraw = true;
 
             // Redraw everything.
             Rect rect = new Rect(0, 0, mBufferSize.width, mBufferSize.height);
             GeckoAppShell.sendEventToGecko(GeckoEvent.createDrawEvent(rect));
         } else if ("Viewport:UpdateLater".equals(event)) {
             Log.e(LOGTAG, "### Java side Viewport:UpdateLater()!");
             mUpdateViewportOnEndDraw = true;
         }
     }
 
-    public void geometryChanged() {
+    void geometryChanged() {
         /* Let Gecko know if the screensize has changed */
-        sendResizeEventIfNecessary();
-        render();
+        sendResizeEventIfNecessary(false);
+        adjustViewportWithThrottling();
     }
 
     public int getWidth() {
         return mBufferSize.width;
     }
 
     public int getHeight() {
         return mBufferSize.height;
@@ -428,20 +409,16 @@ public class GeckoLayerClient implements
 
     public ViewportMetrics getGeckoViewportMetrics() {
         // Return a copy, as we modify this inside the Gecko thread
         if (mGeckoViewport != null)
             return new ViewportMetrics(mGeckoViewport);
         return null;
     }
 
-    private void sendResizeEventIfNecessary() {
-        sendResizeEventIfNecessary(false);
-    }
-
     /** This function is invoked by Gecko via JNI; be careful when modifying signature. */
     public ViewTransform getViewTransform() {
         Log.e(LOGTAG, "### getViewTransform()");
 
         // NB: We don't begin a transaction here because this can be called in a synchronous
         // manner between beginDrawing() and endDrawing(), and that will cause a deadlock.
 
         synchronized (mLayerController) {
@@ -475,16 +452,17 @@ public class GeckoLayerClient implements
     public void activateProgram() {
         mLayerRenderer.activateProgram();
     }
 
     /** This function is invoked by Gecko via JNI; be careful when modifying signature. */
     public void deactivateProgram() {
         mLayerRenderer.deactivateProgram();
     }
+
     /** Implementation of FlexibleGLSurfaceView.Listener */
     public void renderRequested() {
         Log.e(LOGTAG, "### Render requested, scheduling composite");
         GeckoAppShell.scheduleComposite();
     }
 
     /** Implementation of FlexibleGLSurfaceView.Listener */
     public void compositionPauseRequested() {