Bug 1094729 - Part 1. Add utility function to convert Gecko's coords to Layer view coords. r=snorp
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Fri, 01 Jul 2016 15:37:37 +0900
changeset 348567 9ee0cce1cbe5d50a1fca200fa8bf2ec2a1003bf9
parent 348566 2e6d8283458c202a196842653838ed83384e3cbf
child 348568 30f12e33d4ea79d667788e327af851550ba594f9
push id1230
push userjlund@mozilla.com
push dateMon, 31 Oct 2016 18:13:35 +0000
treeherdermozilla-release@5e06e3766db2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1094729
milestone50.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 1094729 - Part 1. Add utility function to convert Gecko's coords to Layer view coords. r=snorp MozReview-Commit-ID: 7CzyHQkVVDz
mobile/android/base/java/org/mozilla/gecko/gfx/GeckoLayerClient.java
mobile/android/base/java/org/mozilla/gecko/gfx/LayerView.java
mobile/android/base/java/org/mozilla/gecko/gfx/PanZoomTarget.java
--- a/mobile/android/base/java/org/mozilla/gecko/gfx/GeckoLayerClient.java
+++ b/mobile/android/base/java/org/mozilla/gecko/gfx/GeckoLayerClient.java
@@ -13,16 +13,17 @@ import org.mozilla.gecko.gfx.LayerView.D
 import org.mozilla.gecko.Tab;
 import org.mozilla.gecko.Tabs;
 import org.mozilla.gecko.ZoomConstraints;
 import org.mozilla.gecko.EventDispatcher;
 import org.mozilla.gecko.util.FloatUtils;
 import org.mozilla.gecko.AppConstants;
 
 import android.content.Context;
+import android.graphics.Matrix;
 import android.graphics.PointF;
 import android.graphics.RectF;
 import android.os.SystemClock;
 import android.util.DisplayMetrics;
 import android.util.Log;
 import android.view.InputDevice;
 import android.view.MotionEvent;
 import org.json.JSONObject;
@@ -1162,16 +1163,36 @@ class GeckoLayerClient implements LayerV
         PointF layerPoint = new PointF(
                 ((viewPoint.x + origin.x) / zoom) - (geckoOrigin.x / geckoZoom),
                 ((viewPoint.y + origin.y) / zoom) - (geckoOrigin.y / geckoZoom));
 
         return layerPoint;
     }
 
     @Override
+    public Matrix getMatrixForLayerRectToViewRect() {
+        if (!mGeckoIsReady) {
+            return null;
+        }
+
+        ImmutableViewportMetrics viewportMetrics = mViewportMetrics;
+        PointF origin = viewportMetrics.getOrigin();
+        float zoom = viewportMetrics.zoomFactor;
+        ImmutableViewportMetrics geckoViewport = (AppConstants.MOZ_ANDROID_APZ ? mViewportMetrics : mGeckoViewport);
+        PointF geckoOrigin = geckoViewport.getOrigin();
+        float geckoZoom = geckoViewport.zoomFactor;
+
+        Matrix matrix = new Matrix();
+        matrix.postTranslate(geckoOrigin.x / geckoZoom, geckoOrigin.y / geckoZoom);
+        matrix.postScale(zoom, zoom);
+        matrix.postTranslate(-origin.x, -origin.y);
+        return matrix;
+    }
+
+    @Override
     public void setScrollingRootContent(boolean isRootContent) {
         mToolbarAnimator.setScrollingRootContent(isRootContent);
     }
 
     public void addDrawListener(DrawListener listener) {
         mDrawListeners.add(listener);
     }
 
--- a/mobile/android/base/java/org/mozilla/gecko/gfx/LayerView.java
+++ b/mobile/android/base/java/org/mozilla/gecko/gfx/LayerView.java
@@ -20,16 +20,17 @@ import org.mozilla.gecko.GeckoEvent;
 import org.mozilla.gecko.GeckoThread;
 import org.mozilla.gecko.Tab;
 import org.mozilla.gecko.Tabs;
 import org.mozilla.gecko.ZoomConstraints;
 
 import android.content.Context;
 import android.graphics.Canvas;
 import android.graphics.Color;
+import android.graphics.Matrix;
 import android.graphics.Point;
 import android.graphics.PointF;
 import android.graphics.Rect;
 import android.graphics.SurfaceTexture;
 import android.util.AttributeSet;
 import android.view.KeyEvent;
 import android.view.MotionEvent;
 import android.view.SurfaceHolder;
@@ -347,16 +348,20 @@ public class LayerView extends ScrollVie
             mPanZoomController.abortPanning();
         }
     }
 
     public PointF convertViewPointToLayerPoint(PointF viewPoint) {
         return mLayerClient.convertViewPointToLayerPoint(viewPoint);
     }
 
+    public Matrix getMatrixForLayerRectToViewRect() {
+        return mLayerClient.getMatrixForLayerRectToViewRect();
+    }
+
     int getBackgroundColor() {
         return mBackgroundColor;
     }
 
     @Override
     public void setBackgroundColor(int newColor) {
         mBackgroundColor = newColor;
         requestRender();
--- a/mobile/android/base/java/org/mozilla/gecko/gfx/PanZoomTarget.java
+++ b/mobile/android/base/java/org/mozilla/gecko/gfx/PanZoomTarget.java
@@ -2,18 +2,18 @@
  * 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 org.mozilla.gecko.ZoomConstraints;
 
+import android.graphics.Matrix;
 import android.graphics.PointF;
-import android.graphics.RectF;
 
 public interface PanZoomTarget {
     public ImmutableViewportMetrics getViewportMetrics();
     public ZoomConstraints getZoomConstraints();
     public FullScreenState getFullScreenState();
     public PointF getVisibleEndOfLayerView();
 
     public void setAnimationTarget(ImmutableViewportMetrics viewport);
@@ -23,10 +23,11 @@ public interface PanZoomTarget {
     /** This triggers an (asynchronous) viewport update/redraw. */
     public void forceRedraw(DisplayPortMetrics displayPort);
 
     public boolean post(Runnable action);
     public void postRenderTask(RenderTask task);
     public void removeRenderTask(RenderTask task);
     public Object getLock();
     public PointF convertViewPointToLayerPoint(PointF viewPoint);
+    public Matrix getMatrixForLayerRectToViewRect();
     public void setScrollingRootContent(boolean isRootContent);
 }