SurfaceView: Correct coordinate space in windowPositionLostRT.
am: 3387913237

Change-Id: I7f28aab013bd6fe213a90e293664cc59ee6d23cf
diff --git a/core/java/android/view/SurfaceView.java b/core/java/android/view/SurfaceView.java
index 77bcf5f..8a16d63 100644
--- a/core/java/android/view/SurfaceView.java
+++ b/core/java/android/view/SurfaceView.java
@@ -115,6 +115,7 @@
     final Rect mStableInsets = new Rect();
     final Rect mOutsets = new Rect();
     final Rect mBackdropFrame = new Rect();
+    final Rect mTmpRect = new Rect();
     final Configuration mConfiguration = new Configuration();
 
     static final int KEEP_SCREEN_ON_MSG = 1;
@@ -661,21 +662,21 @@
 
                 transformFromViewToWindowSpace(mLocation);
 
-                mWinFrame.set(mWindowSpaceLeft, mWindowSpaceTop,
+                mTmpRect.set(mWindowSpaceLeft, mWindowSpaceTop,
                         mLocation[0], mLocation[1]);
 
                 if (mTranslator != null) {
-                    mTranslator.translateRectInAppWindowToScreen(mWinFrame);
+                    mTranslator.translateRectInAppWindowToScreen(mTmpRect);
                 }
 
                 if (!isHardwareAccelerated() || !mRtHandlingPositionUpdates) {
                     try {
                         if (DEBUG) Log.d(TAG, String.format("%d updateWindowPosition UI, " +
                                 "postion = [%d, %d, %d, %d]", System.identityHashCode(this),
-                                mWinFrame.left, mWinFrame.top,
-                                mWinFrame.right, mWinFrame.bottom));
-                        mSession.repositionChild(mWindow, mWinFrame.left, mWinFrame.top,
-                                mWinFrame.right, mWinFrame.bottom, -1, mWinFrame);
+                                mTmpRect.left, mTmpRect.top,
+                                mTmpRect.right, mTmpRect.bottom));
+                        mSession.repositionChild(mWindow, mTmpRect.left, mTmpRect.top,
+                                mTmpRect.right, mTmpRect.bottom, -1, mTmpRect);
                     } catch (RemoteException ex) {
                         Log.e(TAG, "Exception from relayout", ex);
                     }
@@ -687,10 +688,10 @@
     private Rect mRTLastReportedPosition = new Rect();
 
     /**
-     * Called by native on RenderThread to update the window position
+     * Called by native by a Rendering Worker thread to update the window position
      * @hide
      */
-    public final void updateWindowPositionRT(long frameNumber,
+    public final void updateWindowPosition_renderWorker(long frameNumber,
             int left, int top, int right, int bottom) {
         IWindowSession session = mSession;
         MyWindow window = mWindow;
@@ -715,7 +716,7 @@
         }
         try {
             if (DEBUG) {
-                Log.d(TAG, String.format("%d updateWindowPosition RT, frameNr = %d, " +
+                Log.d(TAG, String.format("%d updateWindowPosition RenderWorker, frameNr = %d, " +
                         "postion = [%d, %d, %d, %d]", System.identityHashCode(this),
                         frameNumber, left, top, right, bottom));
             }
@@ -732,12 +733,12 @@
 
     /**
      * Called by native on RenderThread to notify that the window is no longer in the
-     * draw tree
+     * draw tree. UI thread is blocked at this point.
      * @hide
      */
-    public final void windowPositionLostRT(long frameNumber) {
+    public final void windowPositionLost_uiRtSync(long frameNumber) {
         if (DEBUG) {
-            Log.d(TAG, String.format("%d windowPositionLostRT RT, frameNr = %d",
+            Log.d(TAG, String.format("%d windowPositionLost, frameNr = %d",
                     System.identityHashCode(this), frameNumber));
         }
         IWindowSession session = mSession;
@@ -752,14 +753,18 @@
             // safely access other member variables at this time.
             // So do what the UI thread would have done if RT wasn't handling position
             // updates.
-            if (!mWinFrame.isEmpty() && !mWinFrame.equals(mRTLastReportedPosition)) {
+            mTmpRect.set(mLayout.x, mLayout.y,
+                    mLayout.x + mLayout.width,
+                    mLayout.y + mLayout.height);
+
+            if (!mTmpRect.isEmpty() && !mTmpRect.equals(mRTLastReportedPosition)) {
                 try {
                     if (DEBUG) Log.d(TAG, String.format("%d updateWindowPosition, " +
                             "postion = [%d, %d, %d, %d]", System.identityHashCode(this),
-                            mWinFrame.left, mWinFrame.top,
-                            mWinFrame.right, mWinFrame.bottom));
-                    session.repositionChild(window, mWinFrame.left, mWinFrame.top,
-                            mWinFrame.right, mWinFrame.bottom, frameNumber, mWinFrame);
+                            mTmpRect.left, mTmpRect.top,
+                            mTmpRect.right, mTmpRect.bottom));
+                    session.repositionChild(window, mTmpRect.left, mTmpRect.top,
+                            mTmpRect.right, mTmpRect.bottom, frameNumber, mWinFrame);
                 } catch (RemoteException ex) {
                     Log.e(TAG, "Exception from relayout", ex);
                 }
diff --git a/core/jni/android_view_RenderNode.cpp b/core/jni/android_view_RenderNode.cpp
index b0028e1..1bad5f8 100644
--- a/core/jni/android_view_RenderNode.cpp
+++ b/core/jni/android_view_RenderNode.cpp
@@ -721,9 +721,9 @@
 int register_android_view_RenderNode(JNIEnv* env) {
     jclass clazz = FindClassOrDie(env, "android/view/SurfaceView");
     gSurfaceViewPositionUpdateMethod = GetMethodIDOrDie(env, clazz,
-            "updateWindowPositionRT", "(JIIII)V");
+            "updateWindowPosition_renderWorker", "(JIIII)V");
     gSurfaceViewPositionLostMethod = GetMethodIDOrDie(env, clazz,
-            "windowPositionLostRT", "(J)V");
+            "windowPositionLost_uiRtSync", "(J)V");
     clazz = FindClassOrDie(env, "android/view/RenderNode");
     gOnRenderNodeDetached = GetMethodIDOrDie(env, clazz,
             "onRenderNodeDetached", "()V");