Add plumbing for new surface flinger display API.

Cleaned up the implementation of Surface and SurfaceSession
to use more consistent naming and structure.

Added JNI for all of the new surface flinger display API calls.

Enforced the requirement that all Surfaces created by
the window manager be named.

Updated the display manager service to use the new methods.

Change-Id: I2a658f1bfd0437e1c6f9d22df8d4ffcce7284ca2
diff --git a/services/java/com/android/server/display/DisplayDevice.java b/services/java/com/android/server/display/DisplayDevice.java
index 57002ff..4a6dd66 100644
--- a/services/java/com/android/server/display/DisplayDevice.java
+++ b/services/java/com/android/server/display/DisplayDevice.java
@@ -16,6 +16,8 @@
 
 package com.android.server.display;
 
+import android.os.IBinder;
+
 /**
  * Represents a physical display device such as the built-in display
  * an external monitor, or a WiFi display.
@@ -29,6 +31,14 @@
     public abstract DisplayAdapter getAdapter();
 
     /**
+     * Gets the Surface Flinger display token for this display.
+     *
+     * @return The display token, or null if the display is not being managed
+     * by Surface Flinger.
+     */
+    public abstract IBinder getDisplayToken();
+
+    /**
      * Gets information about the display device.
      *
      * @param outInfo The object to populate with the information.
diff --git a/services/java/com/android/server/display/DisplayManagerService.java b/services/java/com/android/server/display/DisplayManagerService.java
index 2ebad1d..1463780 100644
--- a/services/java/com/android/server/display/DisplayManagerService.java
+++ b/services/java/com/android/server/display/DisplayManagerService.java
@@ -22,6 +22,7 @@
 import android.hardware.display.DisplayManager;
 import android.hardware.display.IDisplayManager;
 import android.os.Binder;
+import android.os.IBinder;
 import android.os.SystemProperties;
 import android.view.Display;
 import android.view.DisplayInfo;
@@ -51,6 +52,7 @@
 
     private final ArrayList<DisplayAdapter> mDisplayAdapters = new ArrayList<DisplayAdapter>();
     private final DisplayInfo mDefaultDisplayInfo = new DisplayInfo();
+    private DisplayDevice mDefaultDisplayDevice;
 
     public DisplayManagerService(Context context) {
         mContext = context;
@@ -63,7 +65,7 @@
         if (mHeadless) {
             registerDisplayAdapter(new HeadlessDisplayAdapter(mContext));
         } else {
-            registerDisplayAdapter(new SurfaceFlingerDisplayAdapter(mContext));
+            registerDisplayAdapter(new LocalDisplayAdapter(mContext));
         }
     }
 
@@ -85,8 +87,31 @@
     }
 
     /**
+     * Set the new display orientation.
+     * @param displayId The logical display id.
+     * @param orientation One of the Surface.ROTATION_* constants.
+     */
+    public void setDisplayOrientation(int displayId, int orientation) {
+        synchronized (mLock) {
+            if (displayId != Display.DEFAULT_DISPLAY) {
+                throw new UnsupportedOperationException();
+            }
+
+            IBinder displayToken = mDefaultDisplayDevice.getDisplayToken();
+            if (displayToken != null) {
+                Surface.openTransaction();
+                try {
+                    Surface.setDisplayOrientation(displayToken, orientation);
+                } finally {
+                    Surface.closeTransaction();
+                }
+            }
+        }
+    }
+
+    /**
      * Save away new DisplayInfo data.
-     * @param displayId The local DisplayInfo to store the new data in.
+     * @param displayId The logical display id.
      * @param info The new data to be stored.
      */
     public void setDisplayInfo(int displayId, DisplayInfo info) {
@@ -119,6 +144,7 @@
         adapter.register(new DisplayAdapter.Listener() {
             @Override
             public void onDisplayDeviceAdded(DisplayDevice device) {
+                mDefaultDisplayDevice = device;
                 DisplayDeviceInfo deviceInfo = new DisplayDeviceInfo();
                 device.getInfo(deviceInfo);
                 copyDisplayInfoFromDeviceInfo(mDefaultDisplayInfo, deviceInfo);
diff --git a/services/java/com/android/server/display/HeadlessDisplayAdapter.java b/services/java/com/android/server/display/HeadlessDisplayAdapter.java
index 17c2360..f984c5d 100644
--- a/services/java/com/android/server/display/HeadlessDisplayAdapter.java
+++ b/services/java/com/android/server/display/HeadlessDisplayAdapter.java
@@ -17,6 +17,7 @@
 package com.android.server.display;
 
 import android.content.Context;
+import android.os.IBinder;
 import android.util.DisplayMetrics;
 
 /**
@@ -48,6 +49,11 @@
         }
 
         @Override
+        public IBinder getDisplayToken() {
+            return null;
+        }
+
+        @Override
         public void getInfo(DisplayDeviceInfo outInfo) {
             outInfo.name = mContext.getResources().getString(
                     com.android.internal.R.string.display_manager_built_in_display);
diff --git a/services/java/com/android/server/display/LocalDisplayAdapter.java b/services/java/com/android/server/display/LocalDisplayAdapter.java
new file mode 100644
index 0000000..fa77878
--- /dev/null
+++ b/services/java/com/android/server/display/LocalDisplayAdapter.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.display;
+
+import android.content.Context;
+import android.os.IBinder;
+import android.view.Surface;
+import android.view.Surface.PhysicalDisplayInfo;
+
+/**
+ * A display adapter for the local displays managed by Surface Flinger.
+ */
+public final class LocalDisplayAdapter extends DisplayAdapter {
+    private final Context mContext;
+    private final LocalDisplayDevice mDefaultDisplayDevice;
+
+    public LocalDisplayAdapter(Context context) {
+        mContext = context;
+
+        IBinder token = Surface.getBuiltInDisplay(Surface.BUILT_IN_DISPLAY_ID_MAIN);
+        mDefaultDisplayDevice = new LocalDisplayDevice(token);
+    }
+
+    @Override
+    public String getName() {
+        return "LocalDisplayAdapter";
+    }
+
+    @Override
+    public void register(Listener listener) {
+        listener.onDisplayDeviceAdded(mDefaultDisplayDevice);
+    }
+
+    private final class LocalDisplayDevice extends DisplayDevice {
+        private final IBinder mDisplayToken;
+
+        public LocalDisplayDevice(IBinder token) {
+            mDisplayToken = token;
+        }
+
+        @Override
+        public DisplayAdapter getAdapter() {
+            return LocalDisplayAdapter.this;
+        }
+
+        @Override
+        public IBinder getDisplayToken() {
+            return mDisplayToken;
+        }
+
+        @Override
+        public void getInfo(DisplayDeviceInfo outInfo) {
+            PhysicalDisplayInfo phys = new PhysicalDisplayInfo();
+            Surface.getDisplayInfo(mDisplayToken, phys);
+
+            outInfo.name = mContext.getResources().getString(
+                    com.android.internal.R.string.display_manager_built_in_display);
+            outInfo.width = phys.width;
+            outInfo.height = phys.height;
+            outInfo.refreshRate = phys.refreshRate;
+            outInfo.densityDpi = (int)(phys.density * 160 + 0.5f);
+            outInfo.xDpi = phys.xDpi;
+            outInfo.yDpi = phys.yDpi;
+        }
+    }
+}
diff --git a/services/java/com/android/server/display/SurfaceFlingerDisplayAdapter.java b/services/java/com/android/server/display/SurfaceFlingerDisplayAdapter.java
deleted file mode 100644
index 9531acb..0000000
--- a/services/java/com/android/server/display/SurfaceFlingerDisplayAdapter.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.server.display;
-
-import android.content.Context;
-
-/**
- * A display adapter for the displays managed by Surface Flinger.
- */
-public final class SurfaceFlingerDisplayAdapter extends DisplayAdapter {
-    private final Context mContext;
-    private final SurfaceFlingerDisplayDevice mDefaultDisplayDevice;
-
-    private static native void nativeGetDefaultDisplayDeviceInfo(DisplayDeviceInfo outInfo);
-
-    public SurfaceFlingerDisplayAdapter(Context context) {
-        mContext = context;
-        mDefaultDisplayDevice = new SurfaceFlingerDisplayDevice();
-    }
-
-    @Override
-    public String getName() {
-        return "SurfaceFlingerDisplayAdapter";
-    }
-
-    @Override
-    public void register(Listener listener) {
-        listener.onDisplayDeviceAdded(mDefaultDisplayDevice);
-    }
-
-    private final class SurfaceFlingerDisplayDevice extends DisplayDevice {
-        @Override
-        public DisplayAdapter getAdapter() {
-            return SurfaceFlingerDisplayAdapter.this;
-        }
-
-        @Override
-        public void getInfo(DisplayDeviceInfo outInfo) {
-            outInfo.name = mContext.getResources().getString(
-                    com.android.internal.R.string.display_manager_built_in_display);
-            nativeGetDefaultDisplayDeviceInfo(outInfo);
-        }
-    }
-}
diff --git a/services/java/com/android/server/power/ElectronBeam.java b/services/java/com/android/server/power/ElectronBeam.java
index aad5a9a..0c68997 100644
--- a/services/java/com/android/server/power/ElectronBeam.java
+++ b/services/java/com/android/server/power/ElectronBeam.java
@@ -481,8 +481,8 @@
         try {
             if (mSurface == null) {
                 try {
-                    mSurface = new Surface(mSurfaceSession, Process.myPid(),
-                            "ElectronBeam", mDisplayLayerStack, mDisplayWidth, mDisplayHeight,
+                    mSurface = new Surface(mSurfaceSession,
+                            "ElectronBeam", mDisplayWidth, mDisplayHeight,
                             PixelFormat.OPAQUE, Surface.OPAQUE | Surface.HIDDEN);
                 } catch (Surface.OutOfResourcesException ex) {
                     Slog.e(TAG, "Unable to create surface.", ex);
@@ -490,6 +490,7 @@
                 }
             }
 
+            mSurface.setLayerStack(mDisplayLayerStack);
             mSurface.setSize(mDisplayWidth, mDisplayHeight);
 
             switch (mDisplayRotation) {
diff --git a/services/java/com/android/server/wm/BlackFrame.java b/services/java/com/android/server/wm/BlackFrame.java
index 64d2602..5b77b20 100644
--- a/services/java/com/android/server/wm/BlackFrame.java
+++ b/services/java/com/android/server/wm/BlackFrame.java
@@ -43,14 +43,15 @@
             int w = r-l;
             int h = b-t;
             if (WindowManagerService.DEBUG_SURFACE_TRACE) {
-                surface = new WindowStateAnimator.SurfaceTrace(session, 0, "BlackSurface("
-                        + l + ", " + t + ")", layerStack,
-                        w, h, PixelFormat.OPAQUE, Surface.FX_SURFACE_DIM);
+                surface = new WindowStateAnimator.SurfaceTrace(session, "BlackSurface("
+                        + l + ", " + t + ")",
+                        w, h, PixelFormat.OPAQUE, Surface.FX_SURFACE_DIM | Surface.HIDDEN);
             } else {
-                surface = new Surface(session, 0, "BlackSurface", layerStack,
-                        w, h, PixelFormat.OPAQUE, Surface.FX_SURFACE_DIM);
+                surface = new Surface(session, "BlackSurface",
+                        w, h, PixelFormat.OPAQUE, Surface.FX_SURFACE_DIM | Surface.HIDDEN);
             }
             surface.setAlpha(1);
+            surface.setLayerStack(layerStack);
             surface.setLayer(layer);
             surface.show();
             if (WindowManagerService.SHOW_TRANSACTIONS ||
diff --git a/services/java/com/android/server/wm/DimAnimator.java b/services/java/com/android/server/wm/DimAnimator.java
index 81daac6..afcf339c 100644
--- a/services/java/com/android/server/wm/DimAnimator.java
+++ b/services/java/com/android/server/wm/DimAnimator.java
@@ -43,20 +43,21 @@
         if (mDimSurface == null) {
             try {
                 if (WindowManagerService.DEBUG_SURFACE_TRACE) {
-                    mDimSurface = new WindowStateAnimator.SurfaceTrace(session, 0,
+                    mDimSurface = new WindowStateAnimator.SurfaceTrace(session,
                         "DimAnimator",
-                        layerStack, 16, 16, PixelFormat.OPAQUE,
-                        Surface.FX_SURFACE_DIM);
+                        16, 16, PixelFormat.OPAQUE,
+                        Surface.FX_SURFACE_DIM | Surface.HIDDEN);
                 } else {
-                    mDimSurface = new Surface(session, 0,
-                        "DimAnimator",
-                        layerStack, 16, 16, PixelFormat.OPAQUE,
-                        Surface.FX_SURFACE_DIM);
+                    mDimSurface = new Surface(session, "DimAnimator",
+                        16, 16, PixelFormat.OPAQUE,
+                        Surface.FX_SURFACE_DIM | Surface.HIDDEN);
                 }
                 if (WindowManagerService.SHOW_TRANSACTIONS ||
                         WindowManagerService.SHOW_SURFACE_ALLOC) Slog.i(WindowManagerService.TAG,
                                 "  DIM " + mDimSurface + ": CREATE");
+                mDimSurface.setLayerStack(layerStack);
                 mDimSurface.setAlpha(0.0f);
+                mDimSurface.show();
             } catch (Exception e) {
                 Slog.e(WindowManagerService.TAG, "Exception creating Dim surface", e);
             }
@@ -212,4 +213,4 @@
             mDimTarget = dimTarget;
         }
     }
-}
\ No newline at end of file
+}
diff --git a/services/java/com/android/server/wm/DimSurface.java b/services/java/com/android/server/wm/DimSurface.java
index 4ab8ce1..ddbd70d 100644
--- a/services/java/com/android/server/wm/DimSurface.java
+++ b/services/java/com/android/server/wm/DimSurface.java
@@ -34,20 +34,21 @@
         if (mDimSurface == null) {
             try {
                 if (WindowManagerService.DEBUG_SURFACE_TRACE) {
-                    mDimSurface = new WindowStateAnimator.SurfaceTrace(session, 0,
+                    mDimSurface = new WindowStateAnimator.SurfaceTrace(session,
                         "DimSurface",
-                        layerStack, 16, 16, PixelFormat.OPAQUE,
-                        Surface.FX_SURFACE_DIM);
+                        16, 16, PixelFormat.OPAQUE,
+                        Surface.FX_SURFACE_DIM | Surface.HIDDEN);
                 } else {
-                    mDimSurface = new Surface(session, 0,
-                        "DimSurface",
-                        layerStack, 16, 16, PixelFormat.OPAQUE,
-                        Surface.FX_SURFACE_DIM);
+                    mDimSurface = new Surface(session, "DimSurface",
+                        16, 16, PixelFormat.OPAQUE,
+                        Surface.FX_SURFACE_DIM | Surface.HIDDEN);
                 }
                 if (WindowManagerService.SHOW_TRANSACTIONS ||
                         WindowManagerService.SHOW_SURFACE_ALLOC) Slog.i(WindowManagerService.TAG,
                                 "  DIM " + mDimSurface + ": CREATE");
+                mDimSurface.setLayerStack(layerStack);
                 mDimSurface.setAlpha(0.0f);
+                mDimSurface.show();
             } catch (Exception e) {
                 Slog.e(WindowManagerService.TAG, "Exception creating Dim surface", e);
             }
diff --git a/services/java/com/android/server/wm/ScreenRotationAnimation.java b/services/java/com/android/server/wm/ScreenRotationAnimation.java
index 7679413..acf3249 100644
--- a/services/java/com/android/server/wm/ScreenRotationAnimation.java
+++ b/services/java/com/android/server/wm/ScreenRotationAnimation.java
@@ -215,12 +215,12 @@
         try {
             try {
                 if (WindowManagerService.DEBUG_SURFACE_TRACE) {
-                    mSurface = new SurfaceTrace(session, 0, "FreezeSurface",
-                            mDisplay.getLayerStack(), mWidth, mHeight,
+                    mSurface = new SurfaceTrace(session, "FreezeSurface",
+                            mWidth, mHeight,
                             PixelFormat.OPAQUE, Surface.FX_SURFACE_SCREENSHOT | Surface.HIDDEN);
                 } else {
-                    mSurface = new Surface(session, 0, "FreezeSurface",
-                            mDisplay.getLayerStack(), mWidth, mHeight,
+                    mSurface = new Surface(session, "FreezeSurface",
+                            mWidth, mHeight,
                             PixelFormat.OPAQUE, Surface.FX_SURFACE_SCREENSHOT | Surface.HIDDEN);
                 }
                 if (!mSurface.isValid()) {
@@ -228,6 +228,7 @@
                     mSurface = null;
                     return;
                 }
+                mSurface.setLayerStack(mDisplay.getLayerStack());
                 mSurface.setLayer(FREEZE_LAYER + 1);
                 mSurface.setAlpha(0);
                 mSurface.show();
diff --git a/services/java/com/android/server/wm/StrictModeFlash.java b/services/java/com/android/server/wm/StrictModeFlash.java
index 775aa0f..90bbd08 100644
--- a/services/java/com/android/server/wm/StrictModeFlash.java
+++ b/services/java/com/android/server/wm/StrictModeFlash.java
@@ -37,14 +37,16 @@
 
     public StrictModeFlash(Display display, SurfaceSession session) {
         try {
-            mSurface = new Surface(session, 0, "StrictModeFlash", display.getLayerStack(),
-                1, 1, PixelFormat.TRANSLUCENT, 0);
+            mSurface = new Surface(session, "StrictModeFlash",
+                1, 1, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
         } catch (Surface.OutOfResourcesException e) {
             return;
         }
 
+        mSurface.setLayerStack(display.getLayerStack());
         mSurface.setLayer(WindowManagerService.TYPE_LAYER_MULTIPLIER * 101);  // one more than Watermark? arbitrary.
         mSurface.setPosition(0, 0);
+        mSurface.show();
         mDrawNeeded = true;
     }
 
diff --git a/services/java/com/android/server/wm/Watermark.java b/services/java/com/android/server/wm/Watermark.java
index 5901cc8..ac152c9 100644
--- a/services/java/com/android/server/wm/Watermark.java
+++ b/services/java/com/android/server/wm/Watermark.java
@@ -113,9 +113,9 @@
         mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
 
         try {
-            mSurface = new Surface(session, 0,
-                    "WatermarkSurface", mDisplay.getLayerStack(),
-                    1, 1, PixelFormat.TRANSLUCENT, 0);
+            mSurface = new Surface(session, "WatermarkSurface",
+                    1, 1, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
+            mSurface.setLayerStack(mDisplay.getLayerStack());
             mSurface.setLayer(WindowManagerService.TYPE_LAYER_MULTIPLIER*100);
             mSurface.setPosition(0, 0);
             mSurface.show();
@@ -174,4 +174,4 @@
             }
         }
     }
-}
\ No newline at end of file
+}
diff --git a/services/java/com/android/server/wm/WindowManagerService.java b/services/java/com/android/server/wm/WindowManagerService.java
index 42bc7ce..c1047a9 100755
--- a/services/java/com/android/server/wm/WindowManagerService.java
+++ b/services/java/com/android/server/wm/WindowManagerService.java
@@ -5847,7 +5847,8 @@
                     updateLayoutToAnimationLocked();
                 }
             }
-            Surface.setOrientation(0, rotation);
+            mDisplayManagerService.setDisplayOrientation(
+                    displayContent.getDisplayId(), rotation);
         } finally {
             if (!inTransaction) {
                 Surface.closeTransaction();
@@ -6711,9 +6712,9 @@
             synchronized (mWindowMap) {
                 try {
                     if (mDragState == null) {
-                        Surface surface = new Surface(session, callerPid, "drag surface",
-                                mDefaultDisplay.getLayerStack(),
+                        Surface surface = new Surface(session, "drag surface",
                                 width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
+                        surface.setLayerStack(mDefaultDisplay.getLayerStack());
                         if (SHOW_TRANSACTIONS) Slog.i(TAG, "  DRAG "
                                 + surface + ": CREATE");
                         outSurface.copyFrom(surface);
@@ -8342,10 +8343,11 @@
                 Rect dirty = new Rect(0, 0, mNextAppTransitionThumbnail.getWidth(),
                         mNextAppTransitionThumbnail.getHeight());
                 try {
-                    Surface surface = new Surface(mFxSession, Process.myPid(),
-                            "thumbnail anim", mDefaultDisplay.getLayerStack(),
+                    Surface surface = new Surface(mFxSession,
+                            "thumbnail anim",
                             dirty.width(), dirty.height(),
                             PixelFormat.TRANSLUCENT, Surface.HIDDEN);
+                    surface.setLayerStack(mDefaultDisplay.getLayerStack());
                     topOpeningApp.mAppAnimator.thumbnail = surface;
                     if (SHOW_TRANSACTIONS) Slog.i(TAG, "  THUMBNAIL "
                             + surface + ": CREATE");
diff --git a/services/java/com/android/server/wm/WindowStateAnimator.java b/services/java/com/android/server/wm/WindowStateAnimator.java
index 982f60d..1bda22a 100644
--- a/services/java/com/android/server/wm/WindowStateAnimator.java
+++ b/services/java/com/android/server/wm/WindowStateAnimator.java
@@ -481,9 +481,9 @@
         private String mName;
 
         public SurfaceTrace(SurfaceSession s,
-                       int pid, String name, int layerStack, int w, int h, int format, int flags)
+                       String name, int w, int h, int format, int flags)
                    throws OutOfResourcesException {
-            super(s, pid, name, layerStack, w, h, format, flags);
+            super(s, name, w, h, format, flags);
             mName = name != null ? name : "Not named";
             mSize.set(w, h);
             Slog.v(SURFACE_TAG, "ctor: " + this + ". Called by "
@@ -608,7 +608,7 @@
 
             mService.makeWindowFreezingScreenIfNeededLocked(mWin);
 
-            int flags = 0;
+            int flags = Surface.HIDDEN;
             final WindowManager.LayoutParams attrs = mWin.mAttrs;
 
             if ((attrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
@@ -652,14 +652,14 @@
                 }
                 if (DEBUG_SURFACE_TRACE) {
                     mSurface = new SurfaceTrace(
-                            mSession.mSurfaceSession, mSession.mPid,
+                            mSession.mSurfaceSession,
                             attrs.getTitle().toString(),
-                            mLayerStack, w, h, format, flags);
+                            w, h, format, flags);
                 } else {
                     mSurface = new Surface(
-                        mSession.mSurfaceSession, mSession.mPid,
+                        mSession.mSurfaceSession,
                         attrs.getTitle().toString(),
-                        mLayerStack, w, h, format, flags);
+                        w, h, format, flags);
                 }
                 mWin.mHasSurface = true;
                 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) Slog.i(TAG,
@@ -701,10 +701,10 @@
                     mSurfaceY = mWin.mFrame.top + mWin.mYOffset;
                     mSurface.setPosition(mSurfaceX, mSurfaceY);
                     mSurfaceLayer = mAnimLayer;
+                    mSurface.setLayerStack(mLayerStack);
                     mSurface.setLayer(mAnimLayer);
                     mSurface.setAlpha(0);
                     mSurfaceShown = false;
-                    mSurface.hide();
                 } catch (RuntimeException e) {
                     Slog.w(TAG, "Error creating surface in " + w, e);
                     mService.reclaimSomeSurfaceMemoryLocked(this, "create-init", true);