drm_hwcomposer: ground work for squashing

This patch rearranges things to make squashing possible.
The high-level changes:
  - A new Plan phase that happens in QueueComposition. This is where the
    overlay allocation is moved to. It's also the only safe time that
    the composition can try to plan squashing. This is because squashing
    depends on the exact ordering of compositions.
  - GLWorker now renders regions rather than layers. A region in this case is
    a clipping rectange and set of layers that are to be rendered in that
    rectangle. This is always what GLWorker did in the end, but now the work
    to seperate layers into regions is done externally. This was changed
    because the output of SquashState is a list of stable regions that need to
    be put through GLWorker

The Plan methods of the Compositions are responsible for updating per-display
SquashState and for allocation regions/layers to squashing, pre-composition, or
hardware overlay. Because of the drastic changes to how composition planning
works, it was necessary to bundle it with the GLWorker change.

This change also includes plenty of other refactorings that were deemed to
be too painful to try and seperate into another change.

Change-Id: Ie7bfe077067e936a0862a07cbe87b525eab8d4f8
diff --git a/drmcomposition.cpp b/drmcomposition.cpp
index 4b293ee..dadb053 100644
--- a/drmcomposition.cpp
+++ b/drmcomposition.cpp
@@ -75,14 +75,13 @@
     DrmCompositionDisplayLayersMap &map = maps[display_index];
     int display = map.display;
 
-    ret = composition_map_[display]->SetLayers(
-        map.layers.data(), map.layers.size(), &primary_planes_,
-        &overlay_planes_);
+    ret = composition_map_[display]->SetLayers(map.layers.data(),
+                                               map.layers.size());
     if (ret)
       return ret;
   }
 
-  return DisableUnusedPlanes();
+  return 0;
 }
 
 int DrmComposition::SetDpmsMode(int display, uint32_t dpms_mode) {
@@ -98,6 +97,23 @@
   return std::move(composition_map_[display]);
 }
 
+int DrmComposition::Plan(std::map<int, DrmDisplayCompositor> &compositor_map) {
+  int ret = 0;
+  for (DrmResources::ConnectorIter iter = drm_->begin_connectors();
+       iter != drm_->end_connectors(); ++iter) {
+    int display = (*iter)->display();
+    DrmDisplayComposition *comp = GetDisplayComposition(display);
+    ret = comp->Plan(compositor_map[display].squash_state(), &primary_planes_,
+                     &overlay_planes_);
+    if (ret) {
+      ALOGE("Failed to plan composition for dislay %d", display);
+      return ret;
+    }
+  }
+
+  return 0;
+}
+
 int DrmComposition::DisableUnusedPlanes() {
   for (DrmResources::ConnectorIter iter = drm_->begin_connectors();
        iter != drm_->end_connectors(); ++iter) {