Merge changes Ib302d79e,Ib4ee085f

* changes:
  SurfaceFlinger: set layer names on SurfaceTextures
  SurfaceTexture: add name support
diff --git a/libs/ui/Region.cpp b/libs/ui/Region.cpp
index 8dab291..5656088 100644
--- a/libs/ui/Region.cpp
+++ b/libs/ui/Region.cpp
@@ -482,6 +482,7 @@
     if (!rhs.isValid()) {
         LOGE("Region::boolean_operation(op=%d) invalid Rect={%d,%d,%d,%d}",
                 op, rhs.left, rhs.top, rhs.right, rhs.bottom);
+        return;
     }
 
 #if VALIDATE_WITH_CORECG || VALIDATE_REGIONS
diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.cpp b/services/surfaceflinger/DisplayHardware/HWComposer.cpp
index e707bdc..d2bba0b 100644
--- a/services/surfaceflinger/DisplayHardware/HWComposer.cpp
+++ b/services/surfaceflinger/DisplayHardware/HWComposer.cpp
@@ -176,7 +176,7 @@
                 mList->numHwLayers, mList->flags);
         result.append(buffer);
         result.append(
-                "    type   |   hints  |   flags  | tr | blend |  format  |     source rectangle      |      crop rectangle       name \n"
+                "    type   |   hints  |   flags  | tr | blend |  format  |       source crop         |           frame           name \n"
                 "-----------+----------+----------+----+-------+----------+---------------------------+--------------------------------\n");
         //      "  ________ | ________ | ________ | __ | _____ | ________ | [_____,_____,_____,_____] | [_____,_____,_____,_____]
         for (size_t i=0 ; i<mList->numHwLayers ; i++) {
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index aa16d23..41d7a90 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -376,11 +376,12 @@
             Layer::State& editDraw(mDrawingState);
             editDraw.requested_w = temp.requested_w;
             editDraw.requested_h = temp.requested_h;
-
-            // record the new size, form this point on, when the client request
-            // a buffer, it'll get the new size.
-            mSurfaceTexture->setDefaultBufferSize(temp.requested_w, temp.requested_h);
         }
+
+        // record the new size, form this point on, when the client request
+        // a buffer, it'll get the new size.
+        mSurfaceTexture->setDefaultBufferSize(temp.requested_w,
+                temp.requested_h);
     }
 
     if (temp.sequence != front.sequence) {
@@ -583,7 +584,7 @@
 uint32_t Layer::getTransformHint() const {
     uint32_t orientation = 0;
     if (!mFlinger->mDebugDisableTransformHint) {
-        orientation = getOrientation();
+        orientation = getPlaneOrientation();
         if (orientation & Transform::ROT_INVALID) {
             orientation = 0;
         }
diff --git a/services/surfaceflinger/LayerBase.cpp b/services/surfaceflinger/LayerBase.cpp
index e5ce814..7a47f62 100644
--- a/services/surfaceflinger/LayerBase.cpp
+++ b/services/surfaceflinger/LayerBase.cpp
@@ -45,6 +45,7 @@
       mFlinger(flinger), mFiltering(false),
       mNeedsFiltering(false), mInOverlay(false),
       mOrientation(0),
+      mPlaneOrientation(0),
       mTransactionFlags(0),
       mPremultipliedAlpha(true), mName("unnamed"), mDebug(false),
       mInvalidate(0)
@@ -256,6 +257,7 @@
 
     // cache a few things...
     mOrientation = tr.getOrientation();
+    mPlaneOrientation = planeTransform.getOrientation();
     mTransform = tr;
     mTransformedBounds = tr.makeBounds(w, h);
 }
diff --git a/services/surfaceflinger/LayerBase.h b/services/surfaceflinger/LayerBase.h
index 36d9539..7f62145 100644
--- a/services/surfaceflinger/LayerBase.h
+++ b/services/surfaceflinger/LayerBase.h
@@ -221,6 +221,7 @@
     inline  State&          currentState()          { return mCurrentState; }
 
     int32_t  getOrientation() const { return mOrientation; }
+    int32_t  getPlaneOrientation() const { return mPlaneOrientation; }
     
 protected:
     const GraphicPlane& graphicPlane(int dpy) const;
@@ -254,6 +255,7 @@
 protected:
                 // cached during validateVisibility()
                 int32_t         mOrientation;
+                int32_t         mPlaneOrientation;
                 Transform       mTransform;
                 GLfloat         mVertices[4][2];
                 Rect            mTransformedBounds;
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 09097ee..3f154ce 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -986,19 +986,20 @@
 
 void SurfaceFlinger::composeSurfaces(const Region& dirty)
 {
-    if (UNLIKELY(!mWormholeRegion.isEmpty())) {
+    const DisplayHardware& hw(graphicPlane(0).displayHardware());
+    HWComposer& hwc(hw.getHwComposer());
+
+    const size_t fbLayerCount = hwc.getLayerCount(HWC_FRAMEBUFFER);
+    if (UNLIKELY(fbLayerCount && !mWormholeRegion.isEmpty())) {
         // should never happen unless the window manager has a bug
         // draw something...
         drawWormhole();
     }
 
-    const DisplayHardware& hw(graphicPlane(0).displayHardware());
-    HWComposer& hwc(hw.getHwComposer());
-    hwc_layer_t* const cur(hwc.getLayers());
-
     /*
      * and then, render the layers targeted at the framebuffer
      */
+    hwc_layer_t* const cur(hwc.getLayers());
     const Vector< sp<LayerBase> >& layers(mVisibleLayersSortedByZ);
     size_t count = layers.size();
     for (size_t i=0 ; i<count ; i++) {