Fix rendering issue with layers intersecting the clip rect.

Change-Id: Icbe35194fa219ef13ce639d33631235f8d7df3d7
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp
index 7cc4880..0545ea0 100644
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -289,8 +289,11 @@
     Rect bounds(left, top, right, bottom);
     mSnapshot->transform->mapRect(bounds);
 
-    LayerSize size(bounds.getWidth(), bounds.getHeight());
+    // Layers only make sense if they are in the framebuffer's bounds
+    bounds.intersect(*mSnapshot->clipRect);
+    if (bounds.isEmpty()) return;
 
+    LayerSize size(bounds.getWidth(), bounds.getHeight());
     Layer* layer = mCaches.layerCache.get(size);
     if (!layer) {
         return false;
@@ -525,6 +528,7 @@
     Patch* mesh = mCaches.patchCache.get(patch);
     mesh->updateVertices(bitmap, left, top, right, bottom,
             &patch->xDivs[0], &patch->yDivs[0], patch->numXDivs, patch->numYDivs);
+    mesh->dump();
 
     // Specify right and bottom as +1.0f from left/top to prevent scaling since the
     // patch mesh already defines the final size