Update layers based on the dirty region.
Bug #3413433

This helps Launcher when a widget updates during a scroll, or when interacting
with widgets on the workspace if layers are still turned on.

Change-Id: Ic7a42eb34f74f4ae988039754f815e2efd1d1e4f
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp
index 2960395..90d6ea1 100644
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -671,25 +671,7 @@
         finishDrawTexture();
 
 #if DEBUG_LAYERS_AS_REGIONS
-        uint32_t colors[] = {
-                0x7fff0000, 0x7f00ff00,
-                0x7f0000ff, 0x7fff00ff,
-        };
-
-        int offset = 0;
-        int32_t top = rects[0].top;
-        int i = 0;
-
-        for (size_t i = 0; i < count; i++) {
-            if (top != rects[i].top) {
-                offset ^= 0x2;
-                top = rects[i].top;
-            }
-
-            Rect r(rects[i].left, rects[i].top, rects[i].right, rects[i].bottom);
-            drawColorRect(r.left, r.top, r.right, r.bottom, colors[offset + (i & 0x1)],
-                    SkXfermode::kSrcOver_Mode);
-        }
+        drawRegionRects(layer->region);
 #endif
 
         layer->region.clear();
@@ -699,6 +681,32 @@
 #endif
 }
 
+void OpenGLRenderer::drawRegionRects(const Region& region) {
+#if DEBUG_LAYERS_AS_REGIONS
+    size_t count;
+    const android::Rect* rects = region.getArray(&count);
+
+    uint32_t colors[] = {
+            0x7fff0000, 0x7f00ff00,
+            0x7f0000ff, 0x7fff00ff,
+    };
+
+    int offset = 0;
+    int32_t top = rects[0].top;
+
+    for (size_t i = 0; i < count; i++) {
+        if (top != rects[i].top) {
+            offset ^= 0x2;
+            top = rects[i].top;
+        }
+
+        Rect r(rects[i].left, rects[i].top, rects[i].right, rects[i].bottom);
+        drawColorRect(r.left, r.top, r.right, r.bottom, colors[offset + (i & 0x1)],
+                SkXfermode::kSrcOver_Mode);
+    }
+#endif
+}
+
 void OpenGLRenderer::dirtyLayer(const float left, const float top,
         const float right, const float bottom, const mat4 transform) {
 #if RENDER_LAYERS_AS_REGIONS
@@ -1626,6 +1634,10 @@
                     GL_UNSIGNED_SHORT, layer->meshIndices);
 
             finishDrawTexture();
+
+#if DEBUG_LAYERS_AS_REGIONS
+            drawRegionRects(layer->region);
+#endif
         }
     }
 #else